Skip to content

Commit 8c8d6c4

Browse files
committed
feat: enhance filter handling in ObjectStackProtocol and import SeedLoaderConfigSchema in SeedLoaderService
1 parent 727f9e0 commit 8c8d6c4

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

packages/objectql/src/protocol.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,33 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
346346
else if (options[key] === 'false') options[key] = false;
347347
}
348348

349-
// Handle OData style $filter if present, or flat filters
350-
// This is a naive implementation, a real OData parser is needed for complex scenarios.
349+
// Flat field filters: REST-style query params like ?id=abc&status=open
350+
// After extracting all known query parameters, any remaining keys are
351+
// treated as implicit field-level equality filters. This is the standard
352+
// REST convention used by the client when serializing simple filter maps
353+
// (e.g. `{ filters: { id: "..." } }` → `?id=...`).
354+
const knownParams = new Set([
355+
'top', 'skip', 'limit', 'offset',
356+
'sort', 'orderBy',
357+
'select', 'fields',
358+
'filter', 'filters', '$filter',
359+
'populate', 'expand', '$expand',
360+
'distinct', 'count',
361+
'aggregations', 'groupBy',
362+
'search', 'context',
363+
]);
364+
if (!options.filter) {
365+
const implicitFilters: Record<string, unknown> = {};
366+
for (const key of Object.keys(options)) {
367+
if (!knownParams.has(key)) {
368+
implicitFilters[key] = options[key];
369+
delete options[key];
370+
}
371+
}
372+
if (Object.keys(implicitFilters).length > 0) {
373+
options.filter = implicitFilters;
374+
}
375+
}
351376

352377
const records = await this.engine.find(request.object, options);
353378
return {

packages/runtime/src/seed-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
DatasetLoadResult,
1414
Dataset,
1515
} from '@objectstack/spec/data';
16+
import { SeedLoaderConfigSchema } from '@objectstack/spec/data';
1617

1718
interface Logger {
1819
info(message: string, meta?: Record<string, any>): void;
@@ -152,7 +153,6 @@ export class SeedLoaderService implements ISeedLoaderService {
152153
}
153154

154155
async validate(datasets: Dataset[], config?: SeedLoaderConfigInput): Promise<SeedLoaderResult> {
155-
const { SeedLoaderConfigSchema } = await import('@objectstack/spec/data');
156156
const parsedConfig = SeedLoaderConfigSchema.parse({ ...config, dryRun: true });
157157
return this.load({ datasets, config: parsedConfig });
158158
}

0 commit comments

Comments
 (0)