deepspace 0.23.1 → 0.23.2

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/worker.js CHANGED
@@ -1072,7 +1072,7 @@ var BUILT_IN_TOOLS = [
1072
1072
  description: `Query records from a collection with optional filtering, ordering, and pagination. Returns at most \`limit\` records (default ${DEFAULT_QUERY_LIMIT}). Large result sets are capped at ~30KB: an oversized page is truncated to the leading records that fit and flagged with \`{ truncated, returned, total }\`, so narrow with a \`where\` filter (or page via \`orderBy\` + \`limit\`) to see the rest.`,
1073
1073
  params: {
1074
1074
  collection: { type: "string", description: "Collection name to query", required: true },
1075
- where: { type: "object", description: "Filter object with field=value equality conditions", required: false },
1075
+ where: { type: "object", description: "Filter object with field=value equality conditions; every key must be recordId, createdBy, or a schema column (an unknown key is refused, not ignored)", required: false },
1076
1076
  orderBy: { type: "string", description: 'Field to order by (or "createdAt"/"updatedAt")', required: false },
1077
1077
  orderDir: { type: "string", description: 'Order direction: "asc" or "desc" (default: "desc")', required: false },
1078
1078
  limit: { type: "number", description: `Maximum number of records to return (default: ${DEFAULT_QUERY_LIMIT}). Oversized pages are still capped at ~30KB and truncated with returned/total flags.`, required: false }
@@ -1573,19 +1573,7 @@ function deleteRecord(ctx, collection, recordId, userId, userRole, skipUserRbac
1573
1573
  notifyTeamMembershipChange(ctx, collection, record);
1574
1574
  return { success: true, data: { deleted: true } };
1575
1575
  }
1576
- function deleteWhere(ctx, collection, where, limit, userId, userRole, skipUserRbac = false) {
1577
- const resolved = resolveCollection(ctx, collection);
1578
- if (!resolved.ok) return { success: false, error: resolved.error };
1579
- const schema = resolved.schema;
1580
- if (!schema) {
1581
- return {
1582
- success: false,
1583
- error: `records.deleteWhere: collection "${collection}" has no schema, so it has no filterable fields \u2014 delete its rows by recordId with records.delete`
1584
- };
1585
- }
1586
- if (!where || typeof where !== "object" || Array.isArray(where) || Object.keys(where).length === 0) {
1587
- return { success: false, error: "Missing required param: where (must match at least one field)" };
1588
- }
1576
+ function refuseUnknownWhere(collection, schema, where) {
1589
1577
  const columns = (schema.columns ?? []).map(resolveColumn);
1590
1578
  const filterable = ["recordId", "createdBy", ...columns.map((c) => c.name)];
1591
1579
  const unknown = Object.keys(where).filter(
@@ -1604,6 +1592,23 @@ function deleteWhere(ctx, collection, where, limit, userId, userRole, skipUserRb
1604
1592
  error: `where values must be primitives (equality only): ${nonPrimitive.map(([k]) => k).join(", ")}`
1605
1593
  };
1606
1594
  }
1595
+ return null;
1596
+ }
1597
+ function deleteWhere(ctx, collection, where, limit, userId, userRole, skipUserRbac = false) {
1598
+ const resolved = resolveCollection(ctx, collection);
1599
+ if (!resolved.ok) return { success: false, error: resolved.error };
1600
+ const schema = resolved.schema;
1601
+ if (!schema) {
1602
+ return {
1603
+ success: false,
1604
+ error: `records.deleteWhere: collection "${collection}" has no schema, so it has no filterable fields \u2014 delete its rows by recordId with records.delete`
1605
+ };
1606
+ }
1607
+ if (!where || typeof where !== "object" || Array.isArray(where) || Object.keys(where).length === 0) {
1608
+ return { success: false, error: "Missing required param: where (must match at least one field)" };
1609
+ }
1610
+ const whereRefusal = refuseUnknownWhere(collection, schema, where);
1611
+ if (whereRefusal) return whereRefusal;
1607
1612
  if (limit !== void 0 && !(typeof limit === "number" && Number.isFinite(limit))) {
1608
1613
  return { success: false, error: "limit must be a finite number" };
1609
1614
  }
@@ -2510,9 +2515,20 @@ async function executeTool(ctx, toolName, params, userId, userRole, skipUserRbac
2510
2515
  if (!collection) return { success: false, error: "Missing required param: collection" };
2511
2516
  const resolved = resolveCollection(ctx, collection);
2512
2517
  if (!resolved.ok) return { success: false, error: resolved.error };
2518
+ const where = params.where;
2519
+ if (where && typeof where === "object" && Object.keys(where).length > 0) {
2520
+ if (!resolved.schema) {
2521
+ return {
2522
+ success: false,
2523
+ error: `records.query: collection "${collection}" has no schema, so it has no filterable fields \u2014 query it without \`where\``
2524
+ };
2525
+ }
2526
+ const refusal = refuseUnknownWhere(collection, resolved.schema, where);
2527
+ if (refusal) return refusal;
2528
+ }
2513
2529
  const query = {
2514
2530
  collection,
2515
- where: params.where,
2531
+ where,
2516
2532
  orderBy: params.orderBy,
2517
2533
  orderDir: params.orderDir,
2518
2534
  limit: params.limit