weave-typescript 0.15.0 → 0.17.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 +99 -1
- package/dist/weaveapi/atc/v1/service.pb.js +921 -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/inspection_sql.d.ts +139 -0
- package/dist/weavesql/atcdb/inspection_sql.js +316 -0
- 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
|
@@ -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 {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listRunSnapshotsQuery = exports.deleteSnapshotQuery = exports.loadSnapshotQuery = exports.upsertSnapshotQuery = void 0;
|
|
4
|
+
exports.upsertSnapshot = upsertSnapshot;
|
|
5
|
+
exports.loadSnapshot = loadSnapshot;
|
|
6
|
+
exports.deleteSnapshot = deleteSnapshot;
|
|
7
|
+
exports.listRunSnapshots = listRunSnapshots;
|
|
8
|
+
exports.upsertSnapshotQuery = `-- name: UpsertSnapshot :one
|
|
9
|
+
INSERT INTO atc.event_snapshots (
|
|
10
|
+
tenant_id,
|
|
11
|
+
run_id,
|
|
12
|
+
sequence,
|
|
13
|
+
snapshot_type,
|
|
14
|
+
data
|
|
15
|
+
) VALUES (
|
|
16
|
+
$1,
|
|
17
|
+
$2,
|
|
18
|
+
$3,
|
|
19
|
+
$4,
|
|
20
|
+
$5
|
|
21
|
+
)
|
|
22
|
+
ON CONFLICT (tenant_id, run_id, snapshot_type)
|
|
23
|
+
DO UPDATE
|
|
24
|
+
SET
|
|
25
|
+
sequence = CASE
|
|
26
|
+
WHEN EXCLUDED.sequence > atc.event_snapshots.sequence THEN EXCLUDED.sequence
|
|
27
|
+
ELSE atc.event_snapshots.sequence
|
|
28
|
+
END,
|
|
29
|
+
data = CASE
|
|
30
|
+
WHEN EXCLUDED.sequence > atc.event_snapshots.sequence THEN EXCLUDED.data
|
|
31
|
+
ELSE atc.event_snapshots.data
|
|
32
|
+
END
|
|
33
|
+
RETURNING tenant_id, run_id, sequence, snapshot_type, data, created_at`;
|
|
34
|
+
async function upsertSnapshot(client, args) {
|
|
35
|
+
const result = await client.query({
|
|
36
|
+
text: exports.upsertSnapshotQuery,
|
|
37
|
+
values: [args.tenantId, args.runId, args.sequence, args.snapshotType, args.data],
|
|
38
|
+
rowMode: "array"
|
|
39
|
+
});
|
|
40
|
+
if (result.rows.length !== 1) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const row = result.rows[0];
|
|
44
|
+
return {
|
|
45
|
+
tenantId: row[0],
|
|
46
|
+
runId: row[1],
|
|
47
|
+
sequence: row[2],
|
|
48
|
+
snapshotType: row[3],
|
|
49
|
+
data: row[4],
|
|
50
|
+
createdAt: row[5]
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.loadSnapshotQuery = `-- name: LoadSnapshot :one
|
|
54
|
+
SELECT
|
|
55
|
+
tenant_id,
|
|
56
|
+
run_id,
|
|
57
|
+
sequence,
|
|
58
|
+
snapshot_type,
|
|
59
|
+
data,
|
|
60
|
+
created_at
|
|
61
|
+
FROM atc.event_snapshots
|
|
62
|
+
WHERE tenant_id = $1
|
|
63
|
+
AND run_id = $2
|
|
64
|
+
AND snapshot_type = $3`;
|
|
65
|
+
async function loadSnapshot(client, args) {
|
|
66
|
+
const result = await client.query({
|
|
67
|
+
text: exports.loadSnapshotQuery,
|
|
68
|
+
values: [args.tenantId, args.runId, args.snapshotType],
|
|
69
|
+
rowMode: "array"
|
|
70
|
+
});
|
|
71
|
+
if (result.rows.length !== 1) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const row = result.rows[0];
|
|
75
|
+
return {
|
|
76
|
+
tenantId: row[0],
|
|
77
|
+
runId: row[1],
|
|
78
|
+
sequence: row[2],
|
|
79
|
+
snapshotType: row[3],
|
|
80
|
+
data: row[4],
|
|
81
|
+
createdAt: row[5]
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
exports.deleteSnapshotQuery = `-- name: DeleteSnapshot :exec
|
|
85
|
+
DELETE FROM atc.event_snapshots
|
|
86
|
+
WHERE tenant_id = $1
|
|
87
|
+
AND run_id = $2
|
|
88
|
+
AND snapshot_type = $3`;
|
|
89
|
+
async function deleteSnapshot(client, args) {
|
|
90
|
+
await client.query({
|
|
91
|
+
text: exports.deleteSnapshotQuery,
|
|
92
|
+
values: [args.tenantId, args.runId, args.snapshotType],
|
|
93
|
+
rowMode: "array"
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
exports.listRunSnapshotsQuery = `-- name: ListRunSnapshots :many
|
|
97
|
+
SELECT
|
|
98
|
+
tenant_id,
|
|
99
|
+
run_id,
|
|
100
|
+
sequence,
|
|
101
|
+
snapshot_type,
|
|
102
|
+
data,
|
|
103
|
+
created_at
|
|
104
|
+
FROM atc.event_snapshots
|
|
105
|
+
WHERE tenant_id = $1
|
|
106
|
+
AND run_id = $2
|
|
107
|
+
ORDER BY snapshot_type ASC`;
|
|
108
|
+
async function listRunSnapshots(client, args) {
|
|
109
|
+
const result = await client.query({
|
|
110
|
+
text: exports.listRunSnapshotsQuery,
|
|
111
|
+
values: [args.tenantId, args.runId],
|
|
112
|
+
rowMode: "array"
|
|
113
|
+
});
|
|
114
|
+
return result.rows.map(row => {
|
|
115
|
+
return {
|
|
116
|
+
tenantId: row[0],
|
|
117
|
+
runId: row[1],
|
|
118
|
+
sequence: row[2],
|
|
119
|
+
snapshotType: row[3],
|
|
120
|
+
data: row[4],
|
|
121
|
+
createdAt: row[5]
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { QueryArrayConfig, QueryArrayResult } from "pg";
|
|
2
|
+
interface Client {
|
|
3
|
+
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
|
|
4
|
+
}
|
|
5
|
+
export declare const insertTeamQuery = "-- name: InsertTeam :one\nINSERT INTO atc.teams (\n id,\n tenant_id,\n parent_id,\n name,\n team_type,\n metadata\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6\n)\nRETURNING id, tenant_id, parent_id, name, team_type, metadata, created_at, updated_at";
|
|
6
|
+
export interface InsertTeamArgs {
|
|
7
|
+
id: string;
|
|
8
|
+
tenantId: string;
|
|
9
|
+
parentId: string | null;
|
|
10
|
+
name: string;
|
|
11
|
+
teamType: string;
|
|
12
|
+
metadata: any;
|
|
13
|
+
}
|
|
14
|
+
export interface InsertTeamRow {
|
|
15
|
+
id: string;
|
|
16
|
+
tenantId: string;
|
|
17
|
+
parentId: string | null;
|
|
18
|
+
name: string;
|
|
19
|
+
teamType: string;
|
|
20
|
+
metadata: any;
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
}
|
|
24
|
+
export declare function insertTeam(client: Client, args: InsertTeamArgs): Promise<InsertTeamRow | null>;
|
|
25
|
+
export declare const getTeamQuery = "-- name: GetTeam :one\nSELECT id, tenant_id, parent_id, name, team_type, metadata, created_at, updated_at\nFROM atc.teams\nWHERE tenant_id = $1\n AND id = $2";
|
|
26
|
+
export interface GetTeamArgs {
|
|
27
|
+
tenantId: string;
|
|
28
|
+
id: string;
|
|
29
|
+
}
|
|
30
|
+
export interface GetTeamRow {
|
|
31
|
+
id: string;
|
|
32
|
+
tenantId: string;
|
|
33
|
+
parentId: string | null;
|
|
34
|
+
name: string;
|
|
35
|
+
teamType: string;
|
|
36
|
+
metadata: any;
|
|
37
|
+
createdAt: Date;
|
|
38
|
+
updatedAt: Date;
|
|
39
|
+
}
|
|
40
|
+
export declare function getTeam(client: Client, args: GetTeamArgs): Promise<GetTeamRow | null>;
|
|
41
|
+
export declare const listChildTeamsQuery = "-- name: ListChildTeams :many\nSELECT id, tenant_id, parent_id, name, team_type, metadata, created_at, updated_at\nFROM atc.teams\nWHERE tenant_id = $1\n AND parent_id = $2\nORDER BY name ASC";
|
|
42
|
+
export interface ListChildTeamsArgs {
|
|
43
|
+
tenantId: string;
|
|
44
|
+
parentId: string | null;
|
|
45
|
+
}
|
|
46
|
+
export interface ListChildTeamsRow {
|
|
47
|
+
id: string;
|
|
48
|
+
tenantId: string;
|
|
49
|
+
parentId: string | null;
|
|
50
|
+
name: string;
|
|
51
|
+
teamType: string;
|
|
52
|
+
metadata: any;
|
|
53
|
+
createdAt: Date;
|
|
54
|
+
updatedAt: Date;
|
|
55
|
+
}
|
|
56
|
+
export declare function listChildTeams(client: Client, args: ListChildTeamsArgs): Promise<ListChildTeamsRow[]>;
|
|
57
|
+
export declare const listTeamAncestorsQuery = "-- name: ListTeamAncestors :many\nWITH RECURSIVE ancestors AS (\n SELECT\n id,\n tenant_id,\n parent_id,\n name,\n team_type,\n metadata,\n created_at,\n updated_at,\n 0 AS depth\n FROM atc.teams AS team\n WHERE team.tenant_id = $1\n AND team.id = $2\n\n UNION ALL\n\n SELECT\n team.id,\n team.tenant_id,\n team.parent_id,\n team.name,\n team.team_type,\n team.metadata,\n team.created_at,\n team.updated_at,\n ancestors.depth + 1\n FROM atc.teams AS team\n JOIN ancestors\n ON team.tenant_id = ancestors.tenant_id\n AND team.id = ancestors.parent_id\n)\nSELECT\n id,\n tenant_id,\n parent_id,\n name,\n team_type,\n metadata,\n created_at,\n updated_at\nFROM ancestors\nORDER BY depth ASC";
|
|
58
|
+
export interface ListTeamAncestorsArgs {
|
|
59
|
+
tenantId: string;
|
|
60
|
+
teamId: string;
|
|
61
|
+
}
|
|
62
|
+
export interface ListTeamAncestorsRow {
|
|
63
|
+
id: string;
|
|
64
|
+
tenantId: string;
|
|
65
|
+
parentId: string | null;
|
|
66
|
+
name: string;
|
|
67
|
+
teamType: string;
|
|
68
|
+
metadata: any;
|
|
69
|
+
createdAt: Date;
|
|
70
|
+
updatedAt: Date;
|
|
71
|
+
}
|
|
72
|
+
export declare function listTeamAncestors(client: Client, args: ListTeamAncestorsArgs): Promise<ListTeamAncestorsRow[]>;
|
|
73
|
+
export declare const upsertTeamBudgetQuery = "-- name: UpsertTeamBudget :one\nINSERT INTO atc.team_budgets (\n tenant_id,\n team_id,\n period_start,\n period_end,\n max_cost_cents,\n max_compute,\n max_tool_calls\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7\n)\nON CONFLICT (tenant_id, team_id, period_start)\nDO UPDATE SET\n period_end = EXCLUDED.period_end,\n max_cost_cents = EXCLUDED.max_cost_cents,\n max_compute = EXCLUDED.max_compute,\n max_tool_calls = EXCLUDED.max_tool_calls\nRETURNING tenant_id, team_id, period_start, period_end, max_cost_cents, max_compute, max_tool_calls, created_at";
|
|
74
|
+
export interface UpsertTeamBudgetArgs {
|
|
75
|
+
tenantId: string;
|
|
76
|
+
teamId: string;
|
|
77
|
+
periodStart: Date;
|
|
78
|
+
periodEnd: Date;
|
|
79
|
+
maxCostCents: string;
|
|
80
|
+
maxCompute: string;
|
|
81
|
+
maxToolCalls: string;
|
|
82
|
+
}
|
|
83
|
+
export interface UpsertTeamBudgetRow {
|
|
84
|
+
tenantId: string;
|
|
85
|
+
teamId: string;
|
|
86
|
+
periodStart: Date;
|
|
87
|
+
periodEnd: Date;
|
|
88
|
+
maxCostCents: string;
|
|
89
|
+
maxCompute: string;
|
|
90
|
+
maxToolCalls: string;
|
|
91
|
+
createdAt: Date;
|
|
92
|
+
}
|
|
93
|
+
export declare function upsertTeamBudget(client: Client, args: UpsertTeamBudgetArgs): Promise<UpsertTeamBudgetRow | null>;
|
|
94
|
+
export declare const getTeamBudgetQuery = "-- name: GetTeamBudget :one\nSELECT tenant_id, team_id, period_start, period_end, max_cost_cents, max_compute, max_tool_calls, created_at\nFROM atc.team_budgets\nWHERE tenant_id = $1\n AND team_id = $2\n AND period_start <= $3\n AND period_end > $3";
|
|
95
|
+
export interface GetTeamBudgetArgs {
|
|
96
|
+
tenantId: string;
|
|
97
|
+
teamId: string;
|
|
98
|
+
atTime: Date;
|
|
99
|
+
}
|
|
100
|
+
export interface GetTeamBudgetRow {
|
|
101
|
+
tenantId: string;
|
|
102
|
+
teamId: string;
|
|
103
|
+
periodStart: Date;
|
|
104
|
+
periodEnd: Date;
|
|
105
|
+
maxCostCents: string;
|
|
106
|
+
maxCompute: string;
|
|
107
|
+
maxToolCalls: string;
|
|
108
|
+
createdAt: Date;
|
|
109
|
+
}
|
|
110
|
+
export declare function getTeamBudget(client: Client, args: GetTeamBudgetArgs): Promise<GetTeamBudgetRow | null>;
|
|
111
|
+
export {};
|