Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/objectql/src/protocol-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ describe('ObjectStackProtocolImplementation - Data Operations', () => {
// ═══════════════════════════════════════════════════════════════

describe('findData', () => {
it('normalizes $search/$searchFields (OData) to bare search/searchFields, not implicit filters', async () => {
await protocol.findData({ object: 'showcase_account', query: { $search: 'retail', $searchFields: ['name', 'industry'] } });
const opts = mockEngine.find.mock.calls[0][1];
expect(opts.search).toBe('retail');
expect(opts.searchFields).toEqual(['name', 'industry']);
expect(opts.$search).toBeUndefined();
expect(opts.$searchFields).toBeUndefined();
// critical: must NOT fall through to the implicit-filter pass as where.$search
expect(opts.where?.$search).toBeUndefined();
expect(opts.where?.searchFields).toBeUndefined();
});

it('should normalize $expand (OData) string to expand Record', async () => {
await protocol.findData({ object: 'order_item', query: { $expand: 'order,product' } });

Expand Down
4 changes: 3 additions & 1 deletion packages/objectql/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,8 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
['$orderby', 'orderBy'],
['$select', 'select'],
['$count', 'count'],
['$search', 'search'],
['$searchFields', 'searchFields'],
] as const) {
if (options[dollar] != null && options[bare] == null) {
options[bare] = options[dollar];
Expand Down Expand Up @@ -2133,7 +2135,7 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
'expand',
'distinct', 'count',
'aggregations', 'groupBy',
'search', 'context', 'cursor',
'search', 'searchFields', 'context', 'cursor',
]);
if (!options.where) {
const implicitFilters: Record<string, unknown> = {};
Expand Down
Loading