Skip to content

Commit

Permalink
refactor: add operators with addOperators in context constructor (#391)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Nowack <maxnowack@users.noreply.github.com>
  • Loading branch information
maxnowack and maxnowack committed Oct 19, 2023
1 parent d17d517 commit 054bcb1
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from "./types";
import {
assert,
cloneDeep,
has,
isArray,
isFunction,
Expand All @@ -20,7 +19,6 @@ import {
isObjectLike,
isOperator,
isString,
merge,
resolve
} from "./util";

Expand Down Expand Up @@ -338,27 +336,23 @@ type PipelineOps = Record<string, PipelineOperator>;
type WindowOps = Record<string, WindowOperator>;

export class Context {
private readonly operators: ContextMap;
private readonly operators: ContextMap = {
[OperatorType.ACCUMULATOR]: {},
[OperatorType.EXPRESSION]: {},
[OperatorType.PIPELINE]: {},
[OperatorType.PROJECTION]: {},
[OperatorType.QUERY]: {},
[OperatorType.WINDOW]: {}
};

private constructor(ops: ContextMap) {
this.operators = cloneDeep(ops) as typeof ops;
for (const [type, operators] of Object.entries(ops)) {
this.addOperators(type as OperatorType, operators as OperatorMap);
}
}

static init(ops: ContextMap = {}): Context {
return new Context(
merge(
{
[OperatorType.ACCUMULATOR]: {},
[OperatorType.EXPRESSION]: {},
[OperatorType.PIPELINE]: {},
[OperatorType.PROJECTION]: {},
[OperatorType.QUERY]: {},
[OperatorType.WINDOW]: {}
},
ops,
{ skipValidation: true }
)
);
return new Context(ops);
}

static from(ctx: Context): Context {
Expand Down

0 comments on commit 054bcb1

Please sign in to comment.