Skip to content

Commit

Permalink
Mark all eval methods as internal
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Feb 25, 2025
1 parent 8210f93 commit d06e474
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions grafast/grafast/src/steps/__inputDynamicScalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ export class __InputDynamicScalarStep<
return converted;
};

/** @internal */
eval(): TLeaf {
const variableValues = this.variableNames.map((variableName, i) =>
this.getDep<__TrackedValueStep>(i).eval(),
);
return this.valueFromValues(variableValues);
}

/** @internal */
evalIs(expectedValue: undefined | null | 0): boolean {
if (
expectedValue === undefined ||
Expand Down
3 changes: 3 additions & 0 deletions grafast/grafast/src/steps/__inputList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class __InputListStep<
return itemPlan;
}

/** @internal */
eval(): any[] | null {
if (this.inputValues?.kind === "NullValue") {
return null;
Expand All @@ -113,6 +114,7 @@ export class __InputListStep<
return list;
}

/** @internal */
evalIs(value: null | undefined | 0): boolean {
if (value === undefined) {
return this.inputValues === value;
Expand All @@ -125,6 +127,7 @@ export class __InputListStep<
}
}

/** @internal */
evalLength(): number | null {
if (this.inputValues === undefined) {
return null;
Expand Down
5 changes: 5 additions & 0 deletions grafast/grafast/src/steps/__inputObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class __InputObjectStep<
return step;
}

/** @internal */
eval(): any {
if (this.inputValues?.kind === "NullValue") {
return null;
Expand All @@ -140,6 +141,7 @@ export class __InputObjectStep<
return resultValues;
}

/** @internal */
evalIs(value: null | undefined | 0): boolean {
if (value === undefined) {
return this.inputValues === value;
Expand All @@ -156,6 +158,7 @@ export class __InputObjectStep<
}
}

/** @internal */
evalIsEmpty(): boolean {
return (
this.inputValues?.kind === "ObjectValue" &&
Expand All @@ -164,6 +167,7 @@ export class __InputObjectStep<
}

// Written without consulting spec.
/** @internal */
evalHas(attrName: string): boolean {
if (!this.inputValues) {
return false;
Expand All @@ -177,6 +181,7 @@ export class __InputObjectStep<
return !this.inputFields[attrName].step.evalIs(undefined);
}

/** @internal */
evalKeys(): ReadonlyArray<keyof TInputType & string> | null {
if (this.inputValues === undefined) {
return null;
Expand Down
2 changes: 2 additions & 0 deletions grafast/grafast/src/steps/__inputStaticLeaf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ export class __InputStaticLeafStep<TLeaf = any> extends UnbatchedStep<TLeaf> {
return constant(this.coercedValue, false);
}

/** @internal */
eval(): TLeaf {
return this.coercedValue;
}

/** @internal */
evalIs(expectedValue: unknown): boolean {
return this.coercedValue === expectedValue;
}
Expand Down
11 changes: 11 additions & 0 deletions grafast/grafast/src/steps/__trackedValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ export class __TrackedValueStep<
* **WARNING**: avoid using this where possible, it causes OpPlans to split.
*
* **WARNING**: this is the most expensive eval, if you need to eval, prefer evalIs, evalHas, etc instead.
*
* @internal
*/
eval(): TData | undefined {
const { path, value } = this;
Expand All @@ -311,6 +313,8 @@ export class __TrackedValueStep<
* Should only be used on scalars.
*
* **WARNING**: avoid using this where possible, it causes OpPlans to split.
*
* @internal
*/
evalIs(expectedValue: unknown): boolean {
const { value, path } = this;
Expand All @@ -324,6 +328,7 @@ export class __TrackedValueStep<
return pass;
}

/** @internal */
evalIsEmpty() {
const { value, path } = this;
const isEmpty =
Expand All @@ -344,6 +349,8 @@ export class __TrackedValueStep<
* check will always return the same (boolean) result.
*
* **WARNING**: avoid using this where possible, it causes OpPlans to split.
*
* @internal
*/
evalHas(key: string): boolean {
const { value, path } = this;
Expand Down Expand Up @@ -372,6 +379,8 @@ export class __TrackedValueStep<
* check will always return the same result.
*
* **WARNING**: avoid using this where possible, it causes OpPlans to split.
*
* @internal
*/
evalKeys(): ReadonlyArray<keyof TData & string> | null {
const { value, path } = this;
Expand Down Expand Up @@ -417,6 +426,8 @@ export class __TrackedValueStep<
* the same length.
*
* **WARNING**: avoid using this where possible, it causes OpPlans to split.
*
* @internal
*/
evalLength(): number | null {
const { value, path } = this;
Expand Down
5 changes: 5 additions & 0 deletions grafast/grafast/src/steps/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ export class ConstantStep<TData> extends UnbatchedStep<TData> {
return arrayOfLength(count, this.data);
}

/** @internal */
eval() {
return this.data;
}

/** @internal */
evalIs(value: any) {
return this.data === value;
}

/** @internal */
evalIsEmpty() {
return (
typeof this.data === "object" &&
Expand All @@ -87,10 +90,12 @@ export class ConstantStep<TData> extends UnbatchedStep<TData> {
);
}

/** @internal */
evalLength() {
return Array.isArray(this.data) ? this.data.length : null;
}

/** @internal */
evalKeys(): ReadonlyArray<keyof TData & string> | null {
if (this.data == null || typeof this.data !== "object") {
return null;
Expand Down

0 comments on commit d06e474

Please sign in to comment.