@lumifai/harness-tool-pack-postgres 0.0.1
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/README.md +84 -0
- package/dist/cast-types.d.ts +1 -0
- package/dist/cast-types.js +24 -0
- package/dist/cast-types.js.map +1 -0
- package/dist/catalog-cache.d.ts +9 -0
- package/dist/catalog-cache.js +49 -0
- package/dist/catalog-cache.js.map +1 -0
- package/dist/catalog.d.ts +45 -0
- package/dist/catalog.js +221 -0
- package/dist/catalog.js.map +1 -0
- package/dist/constants.d.ts +45 -0
- package/dist/constants.js +94 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +29 -0
- package/dist/errors.js.map +1 -0
- package/dist/identifiers.d.ts +1 -0
- package/dist/identifiers.js +21 -0
- package/dist/identifiers.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/insert-compiler.d.ts +21 -0
- package/dist/insert-compiler.js +126 -0
- package/dist/insert-compiler.js.map +1 -0
- package/dist/insert-executor.d.ts +25 -0
- package/dist/insert-executor.js +101 -0
- package/dist/insert-executor.js.map +1 -0
- package/dist/insert-language.d.ts +56 -0
- package/dist/insert-language.js +218 -0
- package/dist/insert-language.js.map +1 -0
- package/dist/postgres.d.ts +39 -0
- package/dist/postgres.js +503 -0
- package/dist/postgres.js.map +1 -0
- package/dist/query-compiler.d.ts +16 -0
- package/dist/query-compiler.js +504 -0
- package/dist/query-compiler.js.map +1 -0
- package/dist/query-executor.d.ts +27 -0
- package/dist/query-executor.js +223 -0
- package/dist/query-executor.js.map +1 -0
- package/dist/query-language.d.ts +208 -0
- package/dist/query-language.js +500 -0
- package/dist/query-language.js.map +1 -0
- package/dist/workspace-file.d.ts +6 -0
- package/dist/workspace-file.js +47 -0
- package/dist/workspace-file.js.map +1 -0
- package/package.json +43 -0
- package/skills/postgres/SKILL.md +144 -0
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryResultSchema = exports.schemaDetailsInputSchema = exports.previewInputSchema = exports.queryPlanSchema = void 0;
|
|
4
|
+
exports.isSetOpBody = isSetOpBody;
|
|
5
|
+
exports.isAggregateStarArg = isAggregateStarArg;
|
|
6
|
+
exports.stripNullProperties = stripNullProperties;
|
|
7
|
+
exports.parseQueryPlan = parseQueryPlan;
|
|
8
|
+
exports.assertInputShapeComplexity = assertInputShapeComplexity;
|
|
9
|
+
exports.countExprNodes = countExprNodes;
|
|
10
|
+
exports.countSelectBodyNodes = countSelectBodyNodes;
|
|
11
|
+
exports.countQueryPlanNodes = countQueryPlanNodes;
|
|
12
|
+
exports.assertQueryPlanComplexity = assertQueryPlanComplexity;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const constants_1 = require("./constants");
|
|
15
|
+
const errors_1 = require("./errors");
|
|
16
|
+
const identifierSchema = zod_1.z
|
|
17
|
+
.string()
|
|
18
|
+
.min(1)
|
|
19
|
+
.max(63)
|
|
20
|
+
.regex(/^[a-zA-Z_][a-zA-Z0-9_]*$/);
|
|
21
|
+
const functionNameSchema = zod_1.z
|
|
22
|
+
.string()
|
|
23
|
+
.min(1)
|
|
24
|
+
.max(127)
|
|
25
|
+
.refine((value) => {
|
|
26
|
+
const parts = value.split('.');
|
|
27
|
+
return ((parts.length === 1 || parts.length === 2) &&
|
|
28
|
+
parts.every((part) => part.length <= 63 && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(part)));
|
|
29
|
+
}, 'Use a function name or schema-qualified function name.');
|
|
30
|
+
const literalValueSchema = zod_1.z.union([
|
|
31
|
+
zod_1.z.string().max(10_000),
|
|
32
|
+
zod_1.z.number().finite(),
|
|
33
|
+
zod_1.z.boolean(),
|
|
34
|
+
zod_1.z.null(),
|
|
35
|
+
]);
|
|
36
|
+
function isSetOpBody(body) {
|
|
37
|
+
return 'kind' in body && body.kind === 'set';
|
|
38
|
+
}
|
|
39
|
+
function isAggregateStarArg(arg) {
|
|
40
|
+
return arg === undefined || arg.kind === 'star';
|
|
41
|
+
}
|
|
42
|
+
const aggregateStarArgSchema = zod_1.z.object({
|
|
43
|
+
kind: zod_1.z.literal('star'),
|
|
44
|
+
table: identifierSchema.optional(),
|
|
45
|
+
});
|
|
46
|
+
// Plain z.union instead of z.discriminatedUnion: OpenAI function schemas reject
|
|
47
|
+
// `oneOf` (which discriminatedUnion serializes to); union serializes to `anyOf`.
|
|
48
|
+
const exprSchema = zod_1.z.lazy(() => zod_1.z.union([
|
|
49
|
+
zod_1.z.object({ kind: zod_1.z.literal('literal'), value: literalValueSchema }),
|
|
50
|
+
zod_1.z.object({
|
|
51
|
+
kind: zod_1.z.literal('column'),
|
|
52
|
+
table: identifierSchema.optional(),
|
|
53
|
+
column: identifierSchema,
|
|
54
|
+
}),
|
|
55
|
+
zod_1.z.object({
|
|
56
|
+
kind: zod_1.z.literal('comparison'),
|
|
57
|
+
op: zod_1.z.enum(constants_1.COMPARISON_OPERATORS),
|
|
58
|
+
left: exprSchema,
|
|
59
|
+
right: exprSchema,
|
|
60
|
+
}),
|
|
61
|
+
zod_1.z.object({
|
|
62
|
+
kind: zod_1.z.literal('logical'),
|
|
63
|
+
op: zod_1.z.enum(['and', 'or']),
|
|
64
|
+
terms: zod_1.z.array(exprSchema).min(1).max(32),
|
|
65
|
+
}),
|
|
66
|
+
zod_1.z.object({ kind: zod_1.z.literal('not'), term: exprSchema }),
|
|
67
|
+
zod_1.z.object({
|
|
68
|
+
kind: zod_1.z.literal('is_null'),
|
|
69
|
+
expr: exprSchema,
|
|
70
|
+
negated: zod_1.z.boolean().optional(),
|
|
71
|
+
}),
|
|
72
|
+
zod_1.z.object({
|
|
73
|
+
kind: zod_1.z.literal('between'),
|
|
74
|
+
expr: exprSchema,
|
|
75
|
+
lower: exprSchema,
|
|
76
|
+
upper: exprSchema,
|
|
77
|
+
negated: zod_1.z.boolean().optional(),
|
|
78
|
+
}),
|
|
79
|
+
zod_1.z.object({
|
|
80
|
+
kind: zod_1.z.literal('in_list'),
|
|
81
|
+
expr: exprSchema,
|
|
82
|
+
values: zod_1.z.array(literalValueSchema).min(1).max(constants_1.DEFAULT_MAX_IN_LIST_SIZE),
|
|
83
|
+
negated: zod_1.z.boolean().optional(),
|
|
84
|
+
}),
|
|
85
|
+
zod_1.z.object({
|
|
86
|
+
kind: zod_1.z.literal('in_subquery'),
|
|
87
|
+
expr: exprSchema,
|
|
88
|
+
query: selectBodySchema,
|
|
89
|
+
negated: zod_1.z.boolean().optional(),
|
|
90
|
+
}),
|
|
91
|
+
zod_1.z.object({
|
|
92
|
+
kind: zod_1.z.literal('exists'),
|
|
93
|
+
query: selectBodySchema,
|
|
94
|
+
negated: zod_1.z.boolean().optional(),
|
|
95
|
+
}),
|
|
96
|
+
zod_1.z.object({
|
|
97
|
+
kind: zod_1.z.literal('function'),
|
|
98
|
+
name: functionNameSchema,
|
|
99
|
+
args: zod_1.z.array(exprSchema).max(16),
|
|
100
|
+
}),
|
|
101
|
+
zod_1.z
|
|
102
|
+
.object({
|
|
103
|
+
kind: zod_1.z.literal('aggregate'),
|
|
104
|
+
fn: zod_1.z.enum(constants_1.AGGREGATE_FUNCTIONS),
|
|
105
|
+
arg: zod_1.z.union([exprSchema, aggregateStarArgSchema]).optional(),
|
|
106
|
+
distinct: zod_1.z.boolean().optional(),
|
|
107
|
+
})
|
|
108
|
+
.superRefine((value, ctx) => {
|
|
109
|
+
const isStar = value.arg === undefined || value.arg.kind === 'star';
|
|
110
|
+
if (isStar && value.fn !== 'count') {
|
|
111
|
+
ctx.addIssue({
|
|
112
|
+
code: 'custom',
|
|
113
|
+
path: ['arg'],
|
|
114
|
+
message: `Aggregate "${value.fn}" requires a column or expression argument; only "count" supports COUNT(*).`,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (isStar && value.distinct) {
|
|
118
|
+
ctx.addIssue({
|
|
119
|
+
code: 'custom',
|
|
120
|
+
path: ['distinct'],
|
|
121
|
+
message: 'DISTINCT requires an explicit argument; COUNT(DISTINCT *) is not valid.',
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
zod_1.z.object({
|
|
126
|
+
kind: zod_1.z.literal('case'),
|
|
127
|
+
clauses: zod_1.z
|
|
128
|
+
.array(zod_1.z.object({
|
|
129
|
+
when: exprSchema,
|
|
130
|
+
then: exprSchema,
|
|
131
|
+
}))
|
|
132
|
+
.min(1)
|
|
133
|
+
.max(16),
|
|
134
|
+
else: exprSchema.optional(),
|
|
135
|
+
}),
|
|
136
|
+
zod_1.z.object({
|
|
137
|
+
kind: zod_1.z.literal('cast'),
|
|
138
|
+
expr: exprSchema,
|
|
139
|
+
to: zod_1.z.string().min(1).max(64),
|
|
140
|
+
}),
|
|
141
|
+
zod_1.z.object({
|
|
142
|
+
kind: zod_1.z.literal('scalar_subquery'),
|
|
143
|
+
query: selectBodySchema,
|
|
144
|
+
}),
|
|
145
|
+
zod_1.z
|
|
146
|
+
.object({
|
|
147
|
+
kind: zod_1.z.literal('window'),
|
|
148
|
+
fn: zod_1.z.enum(constants_1.WINDOW_FUNCTIONS),
|
|
149
|
+
arg: exprSchema.optional(),
|
|
150
|
+
partition_by: zod_1.z.array(exprSchema).max(8).optional(),
|
|
151
|
+
order_by: zod_1.z.array(orderBySchema).max(8).optional(),
|
|
152
|
+
})
|
|
153
|
+
.superRefine((value, ctx) => {
|
|
154
|
+
const noArgFns = new Set(['row_number', 'rank', 'dense_rank']);
|
|
155
|
+
if (noArgFns.has(value.fn) && value.arg !== undefined) {
|
|
156
|
+
ctx.addIssue({
|
|
157
|
+
code: 'custom',
|
|
158
|
+
path: ['arg'],
|
|
159
|
+
message: `Window function "${value.fn}" does not accept an argument.`,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (!noArgFns.has(value.fn) && value.fn !== 'count' && value.arg === undefined) {
|
|
163
|
+
ctx.addIssue({
|
|
164
|
+
code: 'custom',
|
|
165
|
+
path: ['arg'],
|
|
166
|
+
message: `Window function "${value.fn}" requires an argument.`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}),
|
|
170
|
+
]));
|
|
171
|
+
const orderBySchema = zod_1.z.lazy(() => zod_1.z.object({
|
|
172
|
+
expr: exprSchema,
|
|
173
|
+
direction: zod_1.z.enum(['asc', 'desc']).optional(),
|
|
174
|
+
nulls: zod_1.z.enum(['first', 'last']).optional(),
|
|
175
|
+
}));
|
|
176
|
+
/** Expression kinds that may appear bare in `select` and get wrapped. */
|
|
177
|
+
const BARE_SELECT_EXPR_KINDS = new Set([
|
|
178
|
+
'literal',
|
|
179
|
+
'comparison',
|
|
180
|
+
'logical',
|
|
181
|
+
'not',
|
|
182
|
+
'is_null',
|
|
183
|
+
'between',
|
|
184
|
+
'in_list',
|
|
185
|
+
'in_subquery',
|
|
186
|
+
'exists',
|
|
187
|
+
'function',
|
|
188
|
+
'aggregate',
|
|
189
|
+
'case',
|
|
190
|
+
'cast',
|
|
191
|
+
'scalar_subquery',
|
|
192
|
+
'window',
|
|
193
|
+
]);
|
|
194
|
+
/**
|
|
195
|
+
* Models often place expressions (e.g. a count aggregate) directly in `select`
|
|
196
|
+
* instead of wrapping them in an `expression` item. Wrap them transparently.
|
|
197
|
+
* A bare column expr is detected by its `column` property, which the select
|
|
198
|
+
* item form does not have.
|
|
199
|
+
*/
|
|
200
|
+
function wrapBareSelectExpr(input) {
|
|
201
|
+
if (input === null || typeof input !== 'object' || Array.isArray(input)) {
|
|
202
|
+
return input;
|
|
203
|
+
}
|
|
204
|
+
const record = input;
|
|
205
|
+
const kind = record.kind;
|
|
206
|
+
if (typeof kind !== 'string') {
|
|
207
|
+
return input;
|
|
208
|
+
}
|
|
209
|
+
if (BARE_SELECT_EXPR_KINDS.has(kind)) {
|
|
210
|
+
return { kind: 'expression', expr: input };
|
|
211
|
+
}
|
|
212
|
+
if (kind === 'column' && 'column' in record && !('expr' in record)) {
|
|
213
|
+
return { kind: 'expression', expr: input };
|
|
214
|
+
}
|
|
215
|
+
return input;
|
|
216
|
+
}
|
|
217
|
+
const selectItemSchema = zod_1.z.preprocess(wrapBareSelectExpr, zod_1.z.union([
|
|
218
|
+
zod_1.z.object({
|
|
219
|
+
kind: zod_1.z.literal('column'),
|
|
220
|
+
expr: exprSchema,
|
|
221
|
+
alias: identifierSchema.optional(),
|
|
222
|
+
}),
|
|
223
|
+
zod_1.z.object({
|
|
224
|
+
kind: zod_1.z.literal('star'),
|
|
225
|
+
table: identifierSchema.optional(),
|
|
226
|
+
}),
|
|
227
|
+
zod_1.z.object({
|
|
228
|
+
kind: zod_1.z.literal('expression'),
|
|
229
|
+
expr: exprSchema,
|
|
230
|
+
alias: identifierSchema.optional(),
|
|
231
|
+
}),
|
|
232
|
+
]));
|
|
233
|
+
const relationRefSchema = zod_1.z.object({
|
|
234
|
+
schema: identifierSchema
|
|
235
|
+
.optional()
|
|
236
|
+
.describe('Physical schema name. Omit to reference a CTE from the same query.'),
|
|
237
|
+
name: identifierSchema,
|
|
238
|
+
alias: identifierSchema.optional(),
|
|
239
|
+
});
|
|
240
|
+
const joinSchema = zod_1.z.object({
|
|
241
|
+
type: zod_1.z.enum(constants_1.JOIN_TYPES),
|
|
242
|
+
relation: relationRefSchema,
|
|
243
|
+
on: exprSchema,
|
|
244
|
+
});
|
|
245
|
+
const cteSchema = zod_1.z.lazy(() => zod_1.z.object({
|
|
246
|
+
name: identifierSchema,
|
|
247
|
+
query: selectBodySchema,
|
|
248
|
+
}));
|
|
249
|
+
const selectBodySchema = zod_1.z.lazy(() => zod_1.z
|
|
250
|
+
.object({
|
|
251
|
+
with: zod_1.z.array(cteSchema).max(constants_1.DEFAULT_MAX_CTES).optional(),
|
|
252
|
+
distinct: zod_1.z.boolean().optional(),
|
|
253
|
+
select: zod_1.z.array(selectItemSchema).min(1).max(constants_1.DEFAULT_MAX_SELECT_ITEMS),
|
|
254
|
+
from: relationRefSchema,
|
|
255
|
+
joins: zod_1.z.array(joinSchema).max(constants_1.DEFAULT_MAX_JOINS).optional(),
|
|
256
|
+
where: exprSchema.optional(),
|
|
257
|
+
group_by: zod_1.z.array(exprSchema).max(constants_1.DEFAULT_MAX_SELECT_ITEMS).optional(),
|
|
258
|
+
having: exprSchema.optional(),
|
|
259
|
+
order_by: zod_1.z.array(orderBySchema).max(constants_1.DEFAULT_MAX_SELECT_ITEMS).optional(),
|
|
260
|
+
})
|
|
261
|
+
.strict());
|
|
262
|
+
const setOpBodySchema = zod_1.z.object({
|
|
263
|
+
kind: zod_1.z.literal('set'),
|
|
264
|
+
op: zod_1.z.enum(constants_1.SET_OPERATIONS),
|
|
265
|
+
left: selectBodySchema,
|
|
266
|
+
right: selectBodySchema,
|
|
267
|
+
});
|
|
268
|
+
const queryBodySchema = zod_1.z.union([selectBodySchema, setOpBodySchema]);
|
|
269
|
+
const queryPlanObjectSchema = zod_1.z
|
|
270
|
+
.object({
|
|
271
|
+
version: zod_1.z.literal(constants_1.QUERY_PLAN_VERSION),
|
|
272
|
+
query: queryBodySchema,
|
|
273
|
+
limit: zod_1.z.number().int().min(1).max(constants_1.MAX_POSTGRES_QUERY_LIMIT).optional(),
|
|
274
|
+
offset: zod_1.z.number().int().min(0).max(1_000_000).optional(),
|
|
275
|
+
})
|
|
276
|
+
.strict();
|
|
277
|
+
const previewInputObjectSchema = zod_1.z
|
|
278
|
+
.object({
|
|
279
|
+
schema: identifierSchema.describe('PostgreSQL schema name'),
|
|
280
|
+
relation: identifierSchema.describe('Table or view name'),
|
|
281
|
+
columns: zod_1.z.array(identifierSchema).min(1).max(32).optional(),
|
|
282
|
+
where: exprSchema.optional(),
|
|
283
|
+
order_by: zod_1.z.array(orderBySchema).max(4).optional(),
|
|
284
|
+
limit: zod_1.z.number().int().min(1).max(constants_1.MAX_PREVIEW_LIMIT).optional(),
|
|
285
|
+
})
|
|
286
|
+
.strict();
|
|
287
|
+
/**
|
|
288
|
+
* LLMs routinely emit `null` for omitted optional properties. Drop them so
|
|
289
|
+
* `.optional()` fields accept the input. The only property where `null` is
|
|
290
|
+
* meaningful is a literal expression's `value`, which is preserved.
|
|
291
|
+
*/
|
|
292
|
+
function stripNullProperties(input) {
|
|
293
|
+
if (Array.isArray(input)) {
|
|
294
|
+
return input.map(stripNullProperties);
|
|
295
|
+
}
|
|
296
|
+
if (input !== null && typeof input === 'object') {
|
|
297
|
+
const result = {};
|
|
298
|
+
for (const [key, value] of Object.entries(input)) {
|
|
299
|
+
if (value === null && key !== 'value') {
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
result[key] = stripNullProperties(value);
|
|
303
|
+
}
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
return input;
|
|
307
|
+
}
|
|
308
|
+
function withInputShapePreflight(schema) {
|
|
309
|
+
return zod_1.z.preprocess((input) => {
|
|
310
|
+
assertInputShapeComplexity(input);
|
|
311
|
+
return stripNullProperties(input);
|
|
312
|
+
}, schema);
|
|
313
|
+
}
|
|
314
|
+
exports.queryPlanSchema = withInputShapePreflight(queryPlanObjectSchema);
|
|
315
|
+
exports.previewInputSchema = withInputShapePreflight(previewInputObjectSchema);
|
|
316
|
+
exports.schemaDetailsInputSchema = zod_1.z
|
|
317
|
+
.object({
|
|
318
|
+
schemas: zod_1.z.array(identifierSchema).min(1).max(16),
|
|
319
|
+
include_indexes: zod_1.z.boolean().optional(),
|
|
320
|
+
cursor: zod_1.z.string().optional(),
|
|
321
|
+
page_size: zod_1.z.number().int().min(1).max(50).optional(),
|
|
322
|
+
})
|
|
323
|
+
.strict();
|
|
324
|
+
function parseQueryPlan(input) {
|
|
325
|
+
return exports.queryPlanSchema.parse(input);
|
|
326
|
+
}
|
|
327
|
+
function assertInputShapeComplexity(input) {
|
|
328
|
+
const pending = [{ value: input, depth: 0 }];
|
|
329
|
+
let nodes = 0;
|
|
330
|
+
while (pending.length > 0) {
|
|
331
|
+
const current = pending.pop();
|
|
332
|
+
nodes += 1;
|
|
333
|
+
if (current.depth > constants_1.MAX_QUERY_INPUT_DEPTH || nodes > constants_1.MAX_QUERY_INPUT_NODES) {
|
|
334
|
+
throw new errors_1.PostgresToolError('COMPLEXITY_EXCEEDED', 'Query input is too deeply or broadly nested.', {
|
|
335
|
+
hint: `Input shape is limited to ${constants_1.MAX_QUERY_INPUT_DEPTH} levels and ${constants_1.MAX_QUERY_INPUT_NODES} nodes.`,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
if (Array.isArray(current.value)) {
|
|
339
|
+
for (const value of current.value) {
|
|
340
|
+
pending.push({ value, depth: current.depth + 1 });
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else if (current.value !== null && typeof current.value === 'object') {
|
|
344
|
+
for (const value of Object.values(current.value)) {
|
|
345
|
+
pending.push({ value, depth: current.depth + 1 });
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function countExprNodes(expr, depth = 1) {
|
|
351
|
+
let nodes = 1;
|
|
352
|
+
let maxDepth = depth;
|
|
353
|
+
const visit = (node, currentDepth) => {
|
|
354
|
+
nodes += 1;
|
|
355
|
+
maxDepth = Math.max(maxDepth, currentDepth);
|
|
356
|
+
switch (node.kind) {
|
|
357
|
+
case 'comparison':
|
|
358
|
+
visit(node.left, currentDepth + 1);
|
|
359
|
+
visit(node.right, currentDepth + 1);
|
|
360
|
+
break;
|
|
361
|
+
case 'logical':
|
|
362
|
+
for (const term of node.terms) {
|
|
363
|
+
visit(term, currentDepth + 1);
|
|
364
|
+
}
|
|
365
|
+
break;
|
|
366
|
+
case 'not':
|
|
367
|
+
visit(node.term, currentDepth + 1);
|
|
368
|
+
break;
|
|
369
|
+
case 'is_null':
|
|
370
|
+
case 'cast':
|
|
371
|
+
visit(node.expr, currentDepth + 1);
|
|
372
|
+
break;
|
|
373
|
+
case 'between':
|
|
374
|
+
visit(node.expr, currentDepth + 1);
|
|
375
|
+
visit(node.lower, currentDepth + 1);
|
|
376
|
+
visit(node.upper, currentDepth + 1);
|
|
377
|
+
break;
|
|
378
|
+
case 'in_list':
|
|
379
|
+
visit(node.expr, currentDepth + 1);
|
|
380
|
+
break;
|
|
381
|
+
case 'in_subquery':
|
|
382
|
+
visit(node.expr, currentDepth + 1);
|
|
383
|
+
nodes += countSelectBodyNodes(node.query).nodes;
|
|
384
|
+
break;
|
|
385
|
+
case 'exists':
|
|
386
|
+
case 'scalar_subquery':
|
|
387
|
+
nodes += countSelectBodyNodes(node.query).nodes;
|
|
388
|
+
break;
|
|
389
|
+
case 'function':
|
|
390
|
+
for (const arg of node.args) {
|
|
391
|
+
visit(arg, currentDepth + 1);
|
|
392
|
+
}
|
|
393
|
+
break;
|
|
394
|
+
case 'aggregate':
|
|
395
|
+
if (!isAggregateStarArg(node.arg)) {
|
|
396
|
+
visit(node.arg, currentDepth + 1);
|
|
397
|
+
}
|
|
398
|
+
break;
|
|
399
|
+
case 'case':
|
|
400
|
+
for (const clause of node.clauses) {
|
|
401
|
+
visit(clause.when, currentDepth + 1);
|
|
402
|
+
visit(clause.then, currentDepth + 1);
|
|
403
|
+
}
|
|
404
|
+
if (node.else) {
|
|
405
|
+
visit(node.else, currentDepth + 1);
|
|
406
|
+
}
|
|
407
|
+
break;
|
|
408
|
+
case 'window':
|
|
409
|
+
if (node.arg) {
|
|
410
|
+
visit(node.arg, currentDepth + 1);
|
|
411
|
+
}
|
|
412
|
+
for (const part of node.partition_by ?? []) {
|
|
413
|
+
visit(part, currentDepth + 1);
|
|
414
|
+
}
|
|
415
|
+
for (const item of node.order_by ?? []) {
|
|
416
|
+
visit(item.expr, currentDepth + 1);
|
|
417
|
+
}
|
|
418
|
+
break;
|
|
419
|
+
default:
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
visit(expr, depth);
|
|
424
|
+
return { nodes, depth: maxDepth };
|
|
425
|
+
}
|
|
426
|
+
function countSelectBodyNodes(body) {
|
|
427
|
+
let nodes = 1;
|
|
428
|
+
let depth = 1;
|
|
429
|
+
const addExpr = (expr) => {
|
|
430
|
+
const counted = countExprNodes(expr);
|
|
431
|
+
nodes += counted.nodes;
|
|
432
|
+
depth = Math.max(depth, counted.depth);
|
|
433
|
+
};
|
|
434
|
+
for (const item of body.select) {
|
|
435
|
+
if (item.kind !== 'star') {
|
|
436
|
+
addExpr(item.expr);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
if (body.where) {
|
|
440
|
+
addExpr(body.where);
|
|
441
|
+
}
|
|
442
|
+
for (const expr of body.group_by ?? []) {
|
|
443
|
+
addExpr(expr);
|
|
444
|
+
}
|
|
445
|
+
if (body.having) {
|
|
446
|
+
addExpr(body.having);
|
|
447
|
+
}
|
|
448
|
+
for (const item of body.order_by ?? []) {
|
|
449
|
+
addExpr(item.expr);
|
|
450
|
+
}
|
|
451
|
+
for (const join of body.joins ?? []) {
|
|
452
|
+
nodes += 1;
|
|
453
|
+
addExpr(join.on);
|
|
454
|
+
}
|
|
455
|
+
for (const cte of body.with ?? []) {
|
|
456
|
+
const counted = countSelectBodyNodes(cte.query);
|
|
457
|
+
nodes += counted.nodes + 1;
|
|
458
|
+
depth = Math.max(depth, counted.depth + 1);
|
|
459
|
+
}
|
|
460
|
+
return { nodes, depth };
|
|
461
|
+
}
|
|
462
|
+
function countQueryPlanNodes(plan) {
|
|
463
|
+
const body = plan.query;
|
|
464
|
+
if (isSetOpBody(body)) {
|
|
465
|
+
const left = countSelectBodyNodes(body.left);
|
|
466
|
+
const right = countSelectBodyNodes(body.right);
|
|
467
|
+
return {
|
|
468
|
+
nodes: left.nodes + right.nodes + 1,
|
|
469
|
+
depth: Math.max(left.depth, right.depth),
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
return countSelectBodyNodes(body);
|
|
473
|
+
}
|
|
474
|
+
function assertQueryPlanComplexity(plan, limits = {}) {
|
|
475
|
+
const maxDepth = limits.maxDepth ?? constants_1.DEFAULT_MAX_EXPRESSION_DEPTH;
|
|
476
|
+
const maxNodes = limits.maxNodes ?? constants_1.DEFAULT_MAX_QUERY_NODES;
|
|
477
|
+
const { nodes, depth } = countQueryPlanNodes(plan);
|
|
478
|
+
if (depth > maxDepth) {
|
|
479
|
+
throw new errors_1.PostgresToolError('COMPLEXITY_EXCEEDED', `Query expression depth ${depth} exceeds limit ${maxDepth}.`);
|
|
480
|
+
}
|
|
481
|
+
if (nodes > maxNodes) {
|
|
482
|
+
throw new errors_1.PostgresToolError('COMPLEXITY_EXCEEDED', `Query node count ${nodes} exceeds limit ${maxNodes}.`);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
exports.queryResultSchema = zod_1.z.object({
|
|
486
|
+
columns: zod_1.z.array(zod_1.z.object({
|
|
487
|
+
name: zod_1.z.string(),
|
|
488
|
+
type: zod_1.z.string(),
|
|
489
|
+
})),
|
|
490
|
+
rows: zod_1.z.array(zod_1.z.array(zod_1.z.unknown())),
|
|
491
|
+
returned_count: zod_1.z.number().int().nonnegative(),
|
|
492
|
+
has_more: zod_1.z.boolean(),
|
|
493
|
+
limit: zod_1.z.number().int().positive(),
|
|
494
|
+
truncation: zod_1.z.object({
|
|
495
|
+
rows: zod_1.z.boolean(),
|
|
496
|
+
bytes: zod_1.z.boolean(),
|
|
497
|
+
cells: zod_1.z.boolean(),
|
|
498
|
+
}),
|
|
499
|
+
});
|
|
500
|
+
//# sourceMappingURL=query-language.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-language.js","sourceRoot":"","sources":["../src/query-language.ts"],"names":[],"mappings":";;;AAiJA,kCAEC;AAED,gDAIC;AA2RD,kDAiBC;AAwBD,wCAEC;AAED,gEA4BC;AAED,wCA8EC;AAED,oDA4CC;AAED,kDAYC;AAED,8DAwBC;AAnqBD,6BAAwB;AAExB,2CAiBqB;AACrB,qCAA6C;AAE7C,MAAM,gBAAgB,GAAG,OAAC;KACvB,MAAM,EAAE;KACR,GAAG,CAAC,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AAC,WAAW,EAAE;IAC9C,QAAQ,EAAE,OAAC,CAAC,OAAO,EAAE;IACrB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAClC,UAAU,EAAE,OAAC,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,OAAC,CAAC,OAAO,EAAE;QACjB,KAAK,EAAE,OAAC,CAAC,OAAO,EAAE;QAClB,KAAK,EAAE,OAAC,CAAC,OAAO,EAAE;KACnB,CAAC;CACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ToolExecutionContext } from '@mastra/core/tools';
|
|
2
|
+
export declare function normalizeWorkspaceFilePath(path: string): string;
|
|
3
|
+
export declare function readWorkspaceCsvText(context: ToolExecutionContext, path: string, maxBytes: number): Promise<{
|
|
4
|
+
normalizedPath: string;
|
|
5
|
+
content: string;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeWorkspaceFilePath = normalizeWorkspaceFilePath;
|
|
4
|
+
exports.readWorkspaceCsvText = readWorkspaceCsvText;
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
function normalizeWorkspaceFilePath(path) {
|
|
7
|
+
const trimmed = path.trim();
|
|
8
|
+
if (!trimmed.startsWith('/')) {
|
|
9
|
+
throw new errors_1.PostgresToolError('INVALID_INPUT', `Path must be absolute within the workspace: ${path}`, {
|
|
10
|
+
path: 'source.path',
|
|
11
|
+
hint: 'Use a workspace path such as /data/rows.csv.',
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return trimmed;
|
|
15
|
+
}
|
|
16
|
+
async function readWorkspaceCsvText(context, path, maxBytes) {
|
|
17
|
+
const normalizedPath = normalizeWorkspaceFilePath(path);
|
|
18
|
+
const filesystem = context.workspace?.filesystem;
|
|
19
|
+
if (!filesystem?.readFile) {
|
|
20
|
+
throw new errors_1.PostgresToolError('CONFIGURATION_ERROR', `Postgres insert requires a workspace filesystem to read ${normalizedPath}.`, { path: 'source.path' });
|
|
21
|
+
}
|
|
22
|
+
if (typeof filesystem.stat === 'function') {
|
|
23
|
+
const stats = await filesystem.stat(normalizedPath);
|
|
24
|
+
const size = typeof stats === 'object' && stats !== null && 'size' in stats
|
|
25
|
+
? Number(stats.size)
|
|
26
|
+
: Number.NaN;
|
|
27
|
+
if (Number.isFinite(size) && size > maxBytes) {
|
|
28
|
+
throw new errors_1.PostgresToolError('COMPLEXITY_EXCEEDED', `CSV file ${normalizedPath} is ${size} bytes, exceeding the ${maxBytes} byte limit.`, {
|
|
29
|
+
path: 'source.path',
|
|
30
|
+
hint: 'Split the CSV or raise maxInsertCsvBytes on the tool pack.',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const fileContent = await filesystem.readFile(normalizedPath, {
|
|
35
|
+
encoding: 'utf8',
|
|
36
|
+
});
|
|
37
|
+
const content = typeof fileContent === 'string' ? fileContent : fileContent.toString('utf8');
|
|
38
|
+
const byteLength = Buffer.byteLength(content, 'utf8');
|
|
39
|
+
if (byteLength > maxBytes) {
|
|
40
|
+
throw new errors_1.PostgresToolError('COMPLEXITY_EXCEEDED', `CSV file ${normalizedPath} is ${byteLength} bytes, exceeding the ${maxBytes} byte limit.`, {
|
|
41
|
+
path: 'source.path',
|
|
42
|
+
hint: 'Split the CSV or raise maxInsertCsvBytes on the tool pack.',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return { normalizedPath, content };
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=workspace-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-file.js","sourceRoot":"","sources":["../src/workspace-file.ts"],"names":[],"mappings":";;AAIA,gEAaC;AAED,oDAkDC;AAnED,qCAA6C;AAE7C,SAAgB,0BAA0B,CAAC,IAAY;I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D;aACnE,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,cAAc,EAAE;QAC5D,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC7F,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACtD,IAAI,UAAU,GAAG,QAAQ,EAAE,CAAC;QAC1B,MAAM,IAAI,0BAAiB,CACzB,qBAAqB,EACrB,YAAY,cAAc,OAAO,UAAU,yBAAyB,QAAQ,cAAc,EAC1F;YACE,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,4DAA4D;SACnE,CACF,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC;AACrC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lumifai/harness-tool-pack-postgres",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "UNLICENSED",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=22.13.0"
|
|
7
|
+
},
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"!dist/**/*.test.*",
|
|
22
|
+
"skills"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@mastra/core": "1.50.1",
|
|
26
|
+
"csv-parse": "^7.0.0",
|
|
27
|
+
"pg": "^8.16.3",
|
|
28
|
+
"pg-cursor": "^2.21.0",
|
|
29
|
+
"pg-sql2": "^5.0.1",
|
|
30
|
+
"@lumifai/harness-tool-packs": "0.0.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/pg": "^8.15.5",
|
|
34
|
+
"@types/pg-cursor": "^2.7.2"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"registry": "https://registry.npmjs.org/"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc -p tsconfig.json"
|
|
42
|
+
}
|
|
43
|
+
}
|