@bounded-sh/core 0.0.39 → 0.0.41
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/client/operations.d.ts +3 -1
- package/dist/index.js +44 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -238,13 +238,15 @@ export type RunExpressionResult = {
|
|
|
238
238
|
operation?: string;
|
|
239
239
|
result?: any;
|
|
240
240
|
}[];
|
|
241
|
+
/** Server-reported failure for this row (e.g. undeclared query, execution error). */
|
|
242
|
+
error?: string;
|
|
241
243
|
};
|
|
242
244
|
export declare function runQuery(absolutePath: string, queryName: string, queryArgs: any, opts?: RunQueryOptions): Promise<any>;
|
|
243
245
|
export declare function runQueryMany(many: {
|
|
244
246
|
absolutePath: string;
|
|
245
247
|
queryName: string;
|
|
246
248
|
queryArgs: any;
|
|
247
|
-
}[], opts?: RunQueryOptions): Promise<any>;
|
|
249
|
+
}[], opts?: RunQueryOptions): Promise<any[]>;
|
|
248
250
|
export declare function runExpression(expression: string, queryArgs: any, options?: RunExpressionOptions): Promise<RunExpressionResult>;
|
|
249
251
|
export declare function runExpressionMany(many: {
|
|
250
252
|
expression: string;
|
package/dist/index.js
CHANGED
|
@@ -5032,10 +5032,28 @@ async function getMany(paths, opts = {}) {
|
|
|
5032
5032
|
return results;
|
|
5033
5033
|
}
|
|
5034
5034
|
async function runQuery(absolutePath, queryName, queryArgs, opts) {
|
|
5035
|
-
|
|
5036
|
-
|
|
5035
|
+
var _a;
|
|
5036
|
+
const rows = await runQueryManyRows([{ absolutePath, queryName, queryArgs }], opts);
|
|
5037
|
+
const row = rows[0];
|
|
5038
|
+
// The worker disambiguates a computed null from a failed/undeclared query
|
|
5039
|
+
// with a per-row `error` string — surface it instead of returning undefined.
|
|
5040
|
+
if ((row === null || row === void 0 ? void 0 : row.error) != null) {
|
|
5041
|
+
const err = new Error(String(row.error));
|
|
5042
|
+
err.isQueryError = true;
|
|
5043
|
+
err.queryName = queryName;
|
|
5044
|
+
err.path = absolutePath;
|
|
5045
|
+
throw err;
|
|
5046
|
+
}
|
|
5047
|
+
return (_a = row === null || row === void 0 ? void 0 : row.result) !== null && _a !== void 0 ? _a : null;
|
|
5037
5048
|
}
|
|
5038
5049
|
async function runQueryMany(many, opts) {
|
|
5050
|
+
// Batch shape stays an array of result values (errored rows map to null) so
|
|
5051
|
+
// existing callers keep working; use runQuery for per-row error surfacing.
|
|
5052
|
+
const rows = await runQueryManyRows(many, opts);
|
|
5053
|
+
return rows.map((row) => { var _a; return (_a = row === null || row === void 0 ? void 0 : row.result) !== null && _a !== void 0 ? _a : null; });
|
|
5054
|
+
}
|
|
5055
|
+
async function runQueryManyRows(many, opts) {
|
|
5056
|
+
var _a, _b, _c, _d;
|
|
5039
5057
|
try {
|
|
5040
5058
|
let queries = [];
|
|
5041
5059
|
for (const { absolutePath, queryName, queryArgs } of many) {
|
|
@@ -5047,7 +5065,16 @@ async function runQueryMany(many, opts) {
|
|
|
5047
5065
|
queries.push({ path: normalizedPath, queryName, queryArgs });
|
|
5048
5066
|
}
|
|
5049
5067
|
const response = await makeApiRequest('POST', 'queries', { queries }, opts === null || opts === void 0 ? void 0 : opts._overrides);
|
|
5050
|
-
|
|
5068
|
+
// makeApiRequest returns `{ data: <httpBody> }`, and the worker's httpBody
|
|
5069
|
+
// is `{ data: { queries: [...] }, status }` — so the rows are double-nested
|
|
5070
|
+
// at response.data.data.queries. (Reading response.data.queries here is
|
|
5071
|
+
// undefined → "Cannot read properties of undefined".) Tolerate both shapes,
|
|
5072
|
+
// same as getMany does for items/batch.
|
|
5073
|
+
const rows = (_c = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.queries) !== null && _c !== void 0 ? _c : (_d = response.data) === null || _d === void 0 ? void 0 : _d.queries;
|
|
5074
|
+
if (!Array.isArray(rows)) {
|
|
5075
|
+
throw new Error(`queries endpoint returned an unexpected response shape (status ${response.status})`);
|
|
5076
|
+
}
|
|
5077
|
+
return rows;
|
|
5051
5078
|
}
|
|
5052
5079
|
catch (error) {
|
|
5053
5080
|
throw error;
|
|
@@ -5059,6 +5086,7 @@ async function runExpression(expression, queryArgs, options) {
|
|
|
5059
5086
|
return results[0];
|
|
5060
5087
|
}
|
|
5061
5088
|
async function runExpressionMany(many) {
|
|
5089
|
+
var _a, _b, _c, _d;
|
|
5062
5090
|
try {
|
|
5063
5091
|
let queries = [];
|
|
5064
5092
|
let overrides = undefined;
|
|
@@ -5070,13 +5098,25 @@ async function runExpressionMany(many) {
|
|
|
5070
5098
|
queries.push({ queryArgs, expression, returnType });
|
|
5071
5099
|
}
|
|
5072
5100
|
const response = await makeApiRequest('POST', 'queries', { queries }, overrides);
|
|
5101
|
+
// Same double-nesting as runQueryMany: the worker's httpBody is
|
|
5102
|
+
// { data: { queries: [...] }, status } under makeApiRequest's own
|
|
5103
|
+
// { data: <httpBody> } wrapper. Tolerate both shapes.
|
|
5104
|
+
const rows = (_c = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.queries) !== null && _c !== void 0 ? _c : (_d = response.data) === null || _d === void 0 ? void 0 : _d.queries;
|
|
5105
|
+
if (!Array.isArray(rows)) {
|
|
5106
|
+
throw new Error(`queries endpoint returned an unexpected response shape (status ${response.status})`);
|
|
5107
|
+
}
|
|
5073
5108
|
// Map results - trace is automatically included by server for non-mainnet networks
|
|
5074
|
-
return
|
|
5109
|
+
return rows.map((queryResult) => {
|
|
5075
5110
|
const result = { result: queryResult.result };
|
|
5076
5111
|
// Include trace if present (server includes it for non-mainnet networks)
|
|
5077
5112
|
if (queryResult.trace) {
|
|
5078
5113
|
result.trace = queryResult.trace;
|
|
5079
5114
|
}
|
|
5115
|
+
// Pass through the server's per-row failure so callers can distinguish
|
|
5116
|
+
// a computed null from a failed row.
|
|
5117
|
+
if (queryResult.error != null) {
|
|
5118
|
+
result.error = String(queryResult.error);
|
|
5119
|
+
}
|
|
5080
5120
|
return result;
|
|
5081
5121
|
});
|
|
5082
5122
|
}
|