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,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTeamBudgetQuery = exports.upsertTeamBudgetQuery = exports.listTeamAncestorsQuery = exports.listChildTeamsQuery = exports.getTeamQuery = exports.insertTeamQuery = void 0;
|
|
4
|
+
exports.insertTeam = insertTeam;
|
|
5
|
+
exports.getTeam = getTeam;
|
|
6
|
+
exports.listChildTeams = listChildTeams;
|
|
7
|
+
exports.listTeamAncestors = listTeamAncestors;
|
|
8
|
+
exports.upsertTeamBudget = upsertTeamBudget;
|
|
9
|
+
exports.getTeamBudget = getTeamBudget;
|
|
10
|
+
exports.insertTeamQuery = `-- name: InsertTeam :one
|
|
11
|
+
INSERT INTO atc.teams (
|
|
12
|
+
id,
|
|
13
|
+
tenant_id,
|
|
14
|
+
parent_id,
|
|
15
|
+
name,
|
|
16
|
+
team_type,
|
|
17
|
+
metadata
|
|
18
|
+
) VALUES (
|
|
19
|
+
$1,
|
|
20
|
+
$2,
|
|
21
|
+
$3,
|
|
22
|
+
$4,
|
|
23
|
+
$5,
|
|
24
|
+
$6
|
|
25
|
+
)
|
|
26
|
+
RETURNING id, tenant_id, parent_id, name, team_type, metadata, created_at, updated_at`;
|
|
27
|
+
async function insertTeam(client, args) {
|
|
28
|
+
const result = await client.query({
|
|
29
|
+
text: exports.insertTeamQuery,
|
|
30
|
+
values: [args.id, args.tenantId, args.parentId, args.name, args.teamType, args.metadata],
|
|
31
|
+
rowMode: "array"
|
|
32
|
+
});
|
|
33
|
+
if (result.rows.length !== 1) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const row = result.rows[0];
|
|
37
|
+
return {
|
|
38
|
+
id: row[0],
|
|
39
|
+
tenantId: row[1],
|
|
40
|
+
parentId: row[2],
|
|
41
|
+
name: row[3],
|
|
42
|
+
teamType: row[4],
|
|
43
|
+
metadata: row[5],
|
|
44
|
+
createdAt: row[6],
|
|
45
|
+
updatedAt: row[7]
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.getTeamQuery = `-- name: GetTeam :one
|
|
49
|
+
SELECT id, tenant_id, parent_id, name, team_type, metadata, created_at, updated_at
|
|
50
|
+
FROM atc.teams
|
|
51
|
+
WHERE tenant_id = $1
|
|
52
|
+
AND id = $2`;
|
|
53
|
+
async function getTeam(client, args) {
|
|
54
|
+
const result = await client.query({
|
|
55
|
+
text: exports.getTeamQuery,
|
|
56
|
+
values: [args.tenantId, args.id],
|
|
57
|
+
rowMode: "array"
|
|
58
|
+
});
|
|
59
|
+
if (result.rows.length !== 1) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const row = result.rows[0];
|
|
63
|
+
return {
|
|
64
|
+
id: row[0],
|
|
65
|
+
tenantId: row[1],
|
|
66
|
+
parentId: row[2],
|
|
67
|
+
name: row[3],
|
|
68
|
+
teamType: row[4],
|
|
69
|
+
metadata: row[5],
|
|
70
|
+
createdAt: row[6],
|
|
71
|
+
updatedAt: row[7]
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
exports.listChildTeamsQuery = `-- name: ListChildTeams :many
|
|
75
|
+
SELECT id, tenant_id, parent_id, name, team_type, metadata, created_at, updated_at
|
|
76
|
+
FROM atc.teams
|
|
77
|
+
WHERE tenant_id = $1
|
|
78
|
+
AND parent_id = $2
|
|
79
|
+
ORDER BY name ASC`;
|
|
80
|
+
async function listChildTeams(client, args) {
|
|
81
|
+
const result = await client.query({
|
|
82
|
+
text: exports.listChildTeamsQuery,
|
|
83
|
+
values: [args.tenantId, args.parentId],
|
|
84
|
+
rowMode: "array"
|
|
85
|
+
});
|
|
86
|
+
return result.rows.map(row => {
|
|
87
|
+
return {
|
|
88
|
+
id: row[0],
|
|
89
|
+
tenantId: row[1],
|
|
90
|
+
parentId: row[2],
|
|
91
|
+
name: row[3],
|
|
92
|
+
teamType: row[4],
|
|
93
|
+
metadata: row[5],
|
|
94
|
+
createdAt: row[6],
|
|
95
|
+
updatedAt: row[7]
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
exports.listTeamAncestorsQuery = `-- name: ListTeamAncestors :many
|
|
100
|
+
WITH RECURSIVE ancestors AS (
|
|
101
|
+
SELECT
|
|
102
|
+
id,
|
|
103
|
+
tenant_id,
|
|
104
|
+
parent_id,
|
|
105
|
+
name,
|
|
106
|
+
team_type,
|
|
107
|
+
metadata,
|
|
108
|
+
created_at,
|
|
109
|
+
updated_at,
|
|
110
|
+
0 AS depth
|
|
111
|
+
FROM atc.teams AS team
|
|
112
|
+
WHERE team.tenant_id = $1
|
|
113
|
+
AND team.id = $2
|
|
114
|
+
|
|
115
|
+
UNION ALL
|
|
116
|
+
|
|
117
|
+
SELECT
|
|
118
|
+
team.id,
|
|
119
|
+
team.tenant_id,
|
|
120
|
+
team.parent_id,
|
|
121
|
+
team.name,
|
|
122
|
+
team.team_type,
|
|
123
|
+
team.metadata,
|
|
124
|
+
team.created_at,
|
|
125
|
+
team.updated_at,
|
|
126
|
+
ancestors.depth + 1
|
|
127
|
+
FROM atc.teams AS team
|
|
128
|
+
JOIN ancestors
|
|
129
|
+
ON team.tenant_id = ancestors.tenant_id
|
|
130
|
+
AND team.id = ancestors.parent_id
|
|
131
|
+
)
|
|
132
|
+
SELECT
|
|
133
|
+
id,
|
|
134
|
+
tenant_id,
|
|
135
|
+
parent_id,
|
|
136
|
+
name,
|
|
137
|
+
team_type,
|
|
138
|
+
metadata,
|
|
139
|
+
created_at,
|
|
140
|
+
updated_at
|
|
141
|
+
FROM ancestors
|
|
142
|
+
ORDER BY depth ASC`;
|
|
143
|
+
async function listTeamAncestors(client, args) {
|
|
144
|
+
const result = await client.query({
|
|
145
|
+
text: exports.listTeamAncestorsQuery,
|
|
146
|
+
values: [args.tenantId, args.teamId],
|
|
147
|
+
rowMode: "array"
|
|
148
|
+
});
|
|
149
|
+
return result.rows.map(row => {
|
|
150
|
+
return {
|
|
151
|
+
id: row[0],
|
|
152
|
+
tenantId: row[1],
|
|
153
|
+
parentId: row[2],
|
|
154
|
+
name: row[3],
|
|
155
|
+
teamType: row[4],
|
|
156
|
+
metadata: row[5],
|
|
157
|
+
createdAt: row[6],
|
|
158
|
+
updatedAt: row[7]
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
exports.upsertTeamBudgetQuery = `-- name: UpsertTeamBudget :one
|
|
163
|
+
INSERT INTO atc.team_budgets (
|
|
164
|
+
tenant_id,
|
|
165
|
+
team_id,
|
|
166
|
+
period_start,
|
|
167
|
+
period_end,
|
|
168
|
+
max_cost_cents,
|
|
169
|
+
max_compute,
|
|
170
|
+
max_tool_calls
|
|
171
|
+
) VALUES (
|
|
172
|
+
$1,
|
|
173
|
+
$2,
|
|
174
|
+
$3,
|
|
175
|
+
$4,
|
|
176
|
+
$5,
|
|
177
|
+
$6,
|
|
178
|
+
$7
|
|
179
|
+
)
|
|
180
|
+
ON CONFLICT (tenant_id, team_id, period_start)
|
|
181
|
+
DO UPDATE SET
|
|
182
|
+
period_end = EXCLUDED.period_end,
|
|
183
|
+
max_cost_cents = EXCLUDED.max_cost_cents,
|
|
184
|
+
max_compute = EXCLUDED.max_compute,
|
|
185
|
+
max_tool_calls = EXCLUDED.max_tool_calls
|
|
186
|
+
RETURNING tenant_id, team_id, period_start, period_end, max_cost_cents, max_compute, max_tool_calls, created_at`;
|
|
187
|
+
async function upsertTeamBudget(client, args) {
|
|
188
|
+
const result = await client.query({
|
|
189
|
+
text: exports.upsertTeamBudgetQuery,
|
|
190
|
+
values: [args.tenantId, args.teamId, args.periodStart, args.periodEnd, args.maxCostCents, args.maxCompute, args.maxToolCalls],
|
|
191
|
+
rowMode: "array"
|
|
192
|
+
});
|
|
193
|
+
if (result.rows.length !== 1) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
const row = result.rows[0];
|
|
197
|
+
return {
|
|
198
|
+
tenantId: row[0],
|
|
199
|
+
teamId: row[1],
|
|
200
|
+
periodStart: row[2],
|
|
201
|
+
periodEnd: row[3],
|
|
202
|
+
maxCostCents: row[4],
|
|
203
|
+
maxCompute: row[5],
|
|
204
|
+
maxToolCalls: row[6],
|
|
205
|
+
createdAt: row[7]
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
exports.getTeamBudgetQuery = `-- name: GetTeamBudget :one
|
|
209
|
+
SELECT tenant_id, team_id, period_start, period_end, max_cost_cents, max_compute, max_tool_calls, created_at
|
|
210
|
+
FROM atc.team_budgets
|
|
211
|
+
WHERE tenant_id = $1
|
|
212
|
+
AND team_id = $2
|
|
213
|
+
AND period_start <= $3
|
|
214
|
+
AND period_end > $3`;
|
|
215
|
+
async function getTeamBudget(client, args) {
|
|
216
|
+
const result = await client.query({
|
|
217
|
+
text: exports.getTeamBudgetQuery,
|
|
218
|
+
values: [args.tenantId, args.teamId, args.atTime],
|
|
219
|
+
rowMode: "array"
|
|
220
|
+
});
|
|
221
|
+
if (result.rows.length !== 1) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
const row = result.rows[0];
|
|
225
|
+
return {
|
|
226
|
+
tenantId: row[0],
|
|
227
|
+
teamId: row[1],
|
|
228
|
+
periodStart: row[2],
|
|
229
|
+
periodEnd: row[3],
|
|
230
|
+
maxCostCents: row[4],
|
|
231
|
+
maxCompute: row[5],
|
|
232
|
+
maxToolCalls: row[6],
|
|
233
|
+
createdAt: row[7]
|
|
234
|
+
};
|
|
235
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { QueryArrayConfig, QueryArrayResult } from "pg";
|
|
2
|
+
interface Client {
|
|
3
|
+
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
|
|
4
|
+
}
|
|
5
|
+
export declare const insertWorkflowTemplateQuery = "-- name: InsertWorkflowTemplate :one\nINSERT INTO atc.workflow_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 InsertWorkflowTemplateArgs {
|
|
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 InsertWorkflowTemplateRow {
|
|
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 insertWorkflowTemplate(client: Client, args: InsertWorkflowTemplateArgs): Promise<InsertWorkflowTemplateRow | null>;
|
|
33
|
+
export declare const getWorkflowTemplateQuery = "-- name: GetWorkflowTemplate :one\nSELECT id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at\nFROM atc.workflow_templates\nWHERE tenant_id = $1\n AND id = $2";
|
|
34
|
+
export interface GetWorkflowTemplateArgs {
|
|
35
|
+
tenantId: string;
|
|
36
|
+
id: string;
|
|
37
|
+
}
|
|
38
|
+
export interface GetWorkflowTemplateRow {
|
|
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 getWorkflowTemplate(client: Client, args: GetWorkflowTemplateArgs): Promise<GetWorkflowTemplateRow | null>;
|
|
53
|
+
export declare const getWorkflowTemplateByNameQuery = "-- name: GetWorkflowTemplateByName :one\nSELECT id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at\nFROM atc.workflow_templates\nWHERE tenant_id = $1\n AND name = $2\nORDER BY version DESC\nLIMIT 1";
|
|
54
|
+
export interface GetWorkflowTemplateByNameArgs {
|
|
55
|
+
tenantId: string;
|
|
56
|
+
name: string;
|
|
57
|
+
}
|
|
58
|
+
export interface GetWorkflowTemplateByNameRow {
|
|
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 getWorkflowTemplateByName(client: Client, args: GetWorkflowTemplateByNameArgs): Promise<GetWorkflowTemplateByNameRow | null>;
|
|
73
|
+
export declare const listWorkflowTemplatesQuery = "-- name: ListWorkflowTemplates :many\nSELECT id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at\nFROM atc.workflow_templates\nWHERE tenant_id = $1\nORDER BY name ASC, version DESC";
|
|
74
|
+
export interface ListWorkflowTemplatesArgs {
|
|
75
|
+
tenantId: string;
|
|
76
|
+
}
|
|
77
|
+
export interface ListWorkflowTemplatesRow {
|
|
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 listWorkflowTemplates(client: Client, args: ListWorkflowTemplatesArgs): Promise<ListWorkflowTemplatesRow[]>;
|
|
92
|
+
export declare const updateWorkflowTemplateQuery = "-- name: UpdateWorkflowTemplate :one\nUPDATE atc.workflow_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 UpdateWorkflowTemplateArgs {
|
|
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 UpdateWorkflowTemplateRow {
|
|
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 updateWorkflowTemplate(client: Client, args: UpdateWorkflowTemplateArgs): Promise<UpdateWorkflowTemplateRow | null>;
|
|
116
|
+
export declare const deleteWorkflowTemplateQuery = "-- name: DeleteWorkflowTemplate :exec\nDELETE FROM atc.workflow_templates\nWHERE tenant_id = $1\n AND id = $2";
|
|
117
|
+
export interface DeleteWorkflowTemplateArgs {
|
|
118
|
+
tenantId: string;
|
|
119
|
+
id: string;
|
|
120
|
+
}
|
|
121
|
+
export declare function deleteWorkflowTemplate(client: Client, args: DeleteWorkflowTemplateArgs): Promise<void>;
|
|
122
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteWorkflowTemplateQuery = exports.updateWorkflowTemplateQuery = exports.listWorkflowTemplatesQuery = exports.getWorkflowTemplateByNameQuery = exports.getWorkflowTemplateQuery = exports.insertWorkflowTemplateQuery = void 0;
|
|
4
|
+
exports.insertWorkflowTemplate = insertWorkflowTemplate;
|
|
5
|
+
exports.getWorkflowTemplate = getWorkflowTemplate;
|
|
6
|
+
exports.getWorkflowTemplateByName = getWorkflowTemplateByName;
|
|
7
|
+
exports.listWorkflowTemplates = listWorkflowTemplates;
|
|
8
|
+
exports.updateWorkflowTemplate = updateWorkflowTemplate;
|
|
9
|
+
exports.deleteWorkflowTemplate = deleteWorkflowTemplate;
|
|
10
|
+
exports.insertWorkflowTemplateQuery = `-- name: InsertWorkflowTemplate :one
|
|
11
|
+
INSERT INTO atc.workflow_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 insertWorkflowTemplate(client, args) {
|
|
36
|
+
const result = await client.query({
|
|
37
|
+
text: exports.insertWorkflowTemplateQuery,
|
|
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.getWorkflowTemplateQuery = `-- name: GetWorkflowTemplate :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.workflow_templates
|
|
63
|
+
WHERE tenant_id = $1
|
|
64
|
+
AND id = $2`;
|
|
65
|
+
async function getWorkflowTemplate(client, args) {
|
|
66
|
+
const result = await client.query({
|
|
67
|
+
text: exports.getWorkflowTemplateQuery,
|
|
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.getWorkflowTemplateByNameQuery = `-- name: GetWorkflowTemplateByName :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.workflow_templates
|
|
93
|
+
WHERE tenant_id = $1
|
|
94
|
+
AND name = $2
|
|
95
|
+
ORDER BY version DESC
|
|
96
|
+
LIMIT 1`;
|
|
97
|
+
async function getWorkflowTemplateByName(client, args) {
|
|
98
|
+
const result = await client.query({
|
|
99
|
+
text: exports.getWorkflowTemplateByNameQuery,
|
|
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.listWorkflowTemplatesQuery = `-- name: ListWorkflowTemplates :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.workflow_templates
|
|
125
|
+
WHERE tenant_id = $1
|
|
126
|
+
ORDER BY name ASC, version DESC`;
|
|
127
|
+
async function listWorkflowTemplates(client, args) {
|
|
128
|
+
const result = await client.query({
|
|
129
|
+
text: exports.listWorkflowTemplatesQuery,
|
|
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.updateWorkflowTemplateQuery = `-- name: UpdateWorkflowTemplate :one
|
|
151
|
+
UPDATE atc.workflow_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 updateWorkflowTemplate(client, args) {
|
|
163
|
+
const result = await client.query({
|
|
164
|
+
text: exports.updateWorkflowTemplateQuery,
|
|
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.deleteWorkflowTemplateQuery = `-- name: DeleteWorkflowTemplate :exec
|
|
188
|
+
DELETE FROM atc.workflow_templates
|
|
189
|
+
WHERE tenant_id = $1
|
|
190
|
+
AND id = $2`;
|
|
191
|
+
async function deleteWorkflowTemplate(client, args) {
|
|
192
|
+
await client.query({
|
|
193
|
+
text: exports.deleteWorkflowTemplateQuery,
|
|
194
|
+
values: [args.tenantId, args.id],
|
|
195
|
+
rowMode: "array"
|
|
196
|
+
});
|
|
197
|
+
}
|