-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): implement
Field
primitive
- Loading branch information
Showing
10 changed files
with
128 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Field } from './field'; | ||
|
||
export interface BuildFieldArgs { | ||
name?: string; | ||
} | ||
|
||
export class FieldBuilder { | ||
protected _name: string; | ||
protected _varName?: string; | ||
|
||
constructor(name: string) { | ||
this._name = name; | ||
} | ||
|
||
/** @internal */ | ||
get varName() { | ||
return this._varName; | ||
} | ||
|
||
/** @internal */ | ||
asVar(varName: string) { | ||
this._varName = varName; | ||
return this; | ||
} | ||
|
||
merge(field: FieldBuilder) { | ||
if (field._name) this._name = field._name; | ||
if (field._varName) this._varName = field._varName; | ||
return this; | ||
} | ||
|
||
build< | ||
A extends BuildFieldArgs | ||
>(args: Partial<A> = {}): Field { | ||
return new Field({ | ||
name: this._name || args.name, | ||
varName: this.varName, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export interface FieldArgs { | ||
name: string; | ||
varName?: string; | ||
} | ||
|
||
export class Field { | ||
protected name: string; | ||
protected varName?: string; | ||
|
||
constructor(args: FieldArgs) { | ||
this.name = args.name; | ||
this.varName = args.varName; | ||
} | ||
|
||
toString() { | ||
if (this.varName) | ||
return `${this.varName} as ${this.name}`; | ||
return this.name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './field-builder'; | ||
export * from './field'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters