Skip to content

Commit

Permalink
feat(core/operator/uid): accept ref
Browse files Browse the repository at this point in the history
  • Loading branch information
binier committed Aug 6, 2020
1 parent 48c2a5e commit b8e28df
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/core/src/operators/operators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { OperatorBuilder, OpBuilderValue, Subject } from '../operator';
import { UidLike, Uid } from '../uid';
import { ParamBuilder } from '../param';
import { RefAble, isRefAble } from '../ref';

type UidArg<T extends 'uid' | 'uid[]'> = UidLike | ParamBuilder<T>;

Expand All @@ -14,10 +15,16 @@ export const type = (type: string) =>
export const has = (subject: Subject) =>
new OperatorBuilder({ name: 'has', subject });

export const uid = (...uids: UidArg<'uid' | 'uid[]'>[]) =>
export const uid = (...uids: (UidArg<'uid' | 'uid[]'> | RefAble)[]) =>
new OperatorBuilder({
name: 'uid',
value: uids.map(x => x instanceof ParamBuilder ? x : new Uid(x)),
value: uids.map(x => {
if (x instanceof ParamBuilder)
return x;
if (isRefAble(x))
return x.ref();
return new Uid(x);
}),
});

/**
Expand Down

0 comments on commit b8e28df

Please sign in to comment.