Skip to content

Commit

Permalink
fix(core): creating ref on projection item with string value overwrit…
Browse files Browse the repository at this point in the history
…es it

fixes: #11
  • Loading branch information
binier committed Sep 30, 2020
1 parent d7bbaf7 commit 2729736
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/edge/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type GenericRawProjection<T> = ObjectOrValue<
Ref | string | boolean | 0 | 1 | T
>;
export type GenericProjection<T> = {
[name: string]: Ref | string | false | T;
[name: string]: Ref | false | T;
};

export function capitalize(s: string) {
Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/edge/edge-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ import {
import { DirectiveBuilder } from '../directive';
import { Ref } from '../ref';
import { Runnable } from '../types';
import { FieldBuilder, BuildFieldArgs } from '../field';
import {
FieldBuilder,
CustomFieldBuilder,
BuildFieldArgs,
} from '../field';
import { AggregationBuilder } from '../aggregation';

type OpBuilders = OperatorBuilder | LogicalOperatorBuilder;
export type RawProjection = GenericRawProjection<
EdgeBuilder | FieldBuilder | AggregationBuilder
>;
export type Projection = GenericProjection<
EdgeBuilder | FieldBuilder | AggregationBuilder
EdgeBuilder | FieldBuilder | CustomFieldBuilder | AggregationBuilder
>;

export interface NameGenerators {
Expand Down Expand Up @@ -83,6 +87,9 @@ export class EdgeBuilder extends FieldBuilder {
if (existing) return r;
v = new FieldBuilder(undefined);
}
if (typeof v === 'string')
v = new CustomFieldBuilder(v);

if (
typeof v !== 'object'
|| v instanceof Ref
Expand All @@ -100,7 +107,6 @@ export class EdgeBuilder extends FieldBuilder {

if (
!existing
|| typeof existing === 'string'
|| existing instanceof Ref
|| existing instanceof AggregationBuilder
) {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/field/custom-field-builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { FieldBuilder } from './field-builder';

export class CustomFieldBuilder extends FieldBuilder {
}
1 change: 1 addition & 0 deletions packages/core/src/field/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './field-builder';
export * from './field';
export * from './custom-field-builder';

0 comments on commit 2729736

Please sign in to comment.