Skip to content

Commit

Permalink
feat(easy-mongo): stages added includes with builder pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
robgeurden committed Aug 16, 2023
1 parent bf0efbd commit fa72d1a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/easy-mongo/src/Stages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const stages = {
ifNotEmpty(includes, es => ({ $project: es.reduce((a: Filter, b: Filter) => ({ ...a, ...(isString(b) ? { [b]: 1 } : b) }), {}) })),
exclude: (...excludes: (string | Record<string, 0>)[]): Optional<Filter> =>
ifNotEmpty(excludes, es => ({ $project: es.reduce((a: Filter, b: Filter) => ({ ...a, ...(isString(b) ? { [b]: 0 } : b) }), {}) })),
includer: (includes: Record<string, (string | Record<string, 1>)[]>) => new IncludeBuilder(includes),
includes: (includes: Record<string, (string | Record<string, 1>)[]>) => new IncludeBuilder(includes),
},
replaceWith: {
replaceWith: (f?: Filter): Optional<Filter> => ifDefined(f, { $replaceWith: f }),
Expand Down
6 changes: 3 additions & 3 deletions packages/easy-mongo/test/Stages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,16 @@ describe('Stages', () => {
});

// Project
const { include, exclude, includer } = stages.project;
const { include, exclude, includes } = stages.project;

test('projection include', () => {
expect(include()).toBeUndefined();
expect(include({})).toStrictEqual({ $project: {} });
expect(include('content', { color: 1 })).toStrictEqual({ $project: { content: 1, color: 1 } });
});

test('includer', () => {
const i = includer({ basic: ['name', 'description'], extended: ['name', 'description', 'specs'] });
test('includes', () => {
const i = includes({ basic: ['name', 'description'], extended: ['name', 'description', 'specs'] });
expect(i.from()).toBeUndefined();
expect(i.from({ i: 'unknown' })).toBeUndefined();
expect(i.from({ i: 'unknown' }, 'unknown2')).toBeUndefined();
Expand Down

0 comments on commit fa72d1a

Please sign in to comment.