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/server.js CHANGED
@@ -111,7 +111,7 @@ var BUILT_IN_TOOLS = [
111
111
  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.`,
112
112
  params: {
113
113
  collection: { type: "string", description: "Collection name to query", required: true },
114
- where: { type: "object", description: "Filter object with field=value equality conditions", required: false },
114
+ 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 },
115
115
  orderBy: { type: "string", description: 'Field to order by (or "createdAt"/"updatedAt")', required: false },
116
116
  orderDir: { type: "string", description: 'Order direction: "asc" or "desc" (default: "desc")', required: false },
117
117
  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 }
@@ -3836,19 +3836,7 @@ function deleteRecord(ctx, collection, recordId, userId, userRole, skipUserRbac
3836
3836
  notifyTeamMembershipChange(ctx, collection, record);
3837
3837
  return { success: true, data: { deleted: true } };
3838
3838
  }
3839
- function deleteWhere(ctx, collection, where, limit, userId, userRole, skipUserRbac = false) {
3840
- const resolved = resolveCollection(ctx, collection);
3841
- if (!resolved.ok) return { success: false, error: resolved.error };
3842
- const schema = resolved.schema;
3843
- if (!schema) {
3844
- return {
3845
- success: false,
3846
- error: `records.deleteWhere: collection "${collection}" has no schema, so it has no filterable fields \u2014 delete its rows by recordId with records.delete`
3847
- };
3848
- }
3849
- if (!where || typeof where !== "object" || Array.isArray(where) || Object.keys(where).length === 0) {
3850
- return { success: false, error: "Missing required param: where (must match at least one field)" };
3851
- }
3839
+ function refuseUnknownWhere(collection, schema, where) {
3852
3840
  const columns = (schema.columns ?? []).map(resolveColumn);
3853
3841
  const filterable = ["recordId", "createdBy", ...columns.map((c) => c.name)];
3854
3842
  const unknown = Object.keys(where).filter(
@@ -3867,6 +3855,23 @@ function deleteWhere(ctx, collection, where, limit, userId, userRole, skipUserRb
3867
3855
  error: `where values must be primitives (equality only): ${nonPrimitive.map(([k]) => k).join(", ")}`
3868
3856
  };
3869
3857
  }
3858
+ return null;
3859
+ }
3860
+ function deleteWhere(ctx, collection, where, limit, userId, userRole, skipUserRbac = false) {
3861
+ const resolved = resolveCollection(ctx, collection);
3862
+ if (!resolved.ok) return { success: false, error: resolved.error };
3863
+ const schema = resolved.schema;
3864
+ if (!schema) {
3865
+ return {
3866
+ success: false,
3867
+ error: `records.deleteWhere: collection "${collection}" has no schema, so it has no filterable fields \u2014 delete its rows by recordId with records.delete`
3868
+ };
3869
+ }
3870
+ if (!where || typeof where !== "object" || Array.isArray(where) || Object.keys(where).length === 0) {
3871
+ return { success: false, error: "Missing required param: where (must match at least one field)" };
3872
+ }
3873
+ const whereRefusal = refuseUnknownWhere(collection, schema, where);
3874
+ if (whereRefusal) return whereRefusal;
3870
3875
  if (limit !== void 0 && !(typeof limit === "number" && Number.isFinite(limit))) {
3871
3876
  return { success: false, error: "limit must be a finite number" };
3872
3877
  }
@@ -4773,9 +4778,20 @@ async function executeTool(ctx, toolName, params, userId, userRole, skipUserRbac
4773
4778
  if (!collection) return { success: false, error: "Missing required param: collection" };
4774
4779
  const resolved = resolveCollection(ctx, collection);
4775
4780
  if (!resolved.ok) return { success: false, error: resolved.error };
4781
+ const where = params.where;
4782
+ if (where && typeof where === "object" && Object.keys(where).length > 0) {
4783
+ if (!resolved.schema) {
4784
+ return {
4785
+ success: false,
4786
+ error: `records.query: collection "${collection}" has no schema, so it has no filterable fields \u2014 query it without \`where\``
4787
+ };
4788
+ }
4789
+ const refusal = refuseUnknownWhere(collection, resolved.schema, where);
4790
+ if (refusal) return refusal;
4791
+ }
4776
4792
  const query = {
4777
4793
  collection,
4778
- where: params.where,
4794
+ where,
4779
4795
  orderBy: params.orderBy,
4780
4796
  orderDir: params.orderDir,
4781
4797
  limit: params.limit