Skip to content

Commit

Permalink
chore: remove callback wrapper usages
Browse files Browse the repository at this point in the history
  • Loading branch information
guilgaly authored and notdryft committed Jun 24, 2024
1 parent 44adc42 commit c990523
Show file tree
Hide file tree
Showing 31 changed files with 202 additions and 430 deletions.
13 changes: 5 additions & 8 deletions js/core/src/body.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { CoreDsl as JvmCoreDsl } from "@gatling.io/jvm-types";

import { Wrapper } from "./common";
import { wrapByteArrayCallback, wrapCallback } from "./gatlingJvm/callbacks";
import { Expression, Session, underlyingSessionTo } from "./session";

import JvmBody = io.gatling.javaapi.core.Body;
Expand Down Expand Up @@ -51,9 +50,7 @@ export interface StringBodyFunction {

export const StringBody: StringBodyFunction = (string: Expression<string>): Body.WithString =>
wrapBodyWithString(
typeof string === "function"
? JvmCoreDsl.StringBody(wrapCallback(underlyingSessionTo(string)))
: JvmCoreDsl.StringBody(string)
typeof string === "function" ? JvmCoreDsl.StringBody(underlyingSessionTo(string)) : JvmCoreDsl.StringBody(string)
);

export interface RawFileBodyFunction {
Expand Down Expand Up @@ -83,7 +80,7 @@ export interface RawFileBodyFunction {
export const RawFileBody: RawFileBodyFunction = (filePath: Expression<string>): Body.WithBytes =>
wrapBodyWithBytes(
typeof filePath === "function"
? JvmCoreDsl.RawFileBody(wrapCallback(underlyingSessionTo(filePath)))
? JvmCoreDsl.RawFileBody(underlyingSessionTo(filePath))
: JvmCoreDsl.RawFileBody(filePath)
);

Expand Down Expand Up @@ -116,7 +113,7 @@ export interface ElFileBodyFunction {
export const ElFileBody: ElFileBodyFunction = (filePath: Expression<string>): Body.WithString =>
wrapBodyWithString(
typeof filePath === "function"
? JvmCoreDsl.ElFileBody(wrapCallback(underlyingSessionTo(filePath)))
? JvmCoreDsl.ElFileBody(underlyingSessionTo(filePath))
: JvmCoreDsl.ElFileBody(filePath)
);

Expand Down Expand Up @@ -165,7 +162,7 @@ export interface PebbleFileBodyFunction {
export const PebbleFileBody: PebbleFileBodyFunction = (filePath: Expression<string>): Body.WithString =>
wrapBodyWithString(
typeof filePath === "function"
? JvmCoreDsl.PebbleFileBody(wrapCallback(underlyingSessionTo(filePath)))
? JvmCoreDsl.PebbleFileBody(underlyingSessionTo(filePath))
: JvmCoreDsl.PebbleFileBody(filePath)
);

Expand Down Expand Up @@ -204,7 +201,7 @@ export interface ByteArrayBodyFunction {
export const ByteArrayBody: ByteArrayBodyFunction = (bytes: string | Expression<number[]>): Body.WithBytes =>
wrapBodyWithBytes(
typeof bytes === "function"
? JvmCoreDsl.ByteArrayBody(wrapByteArrayCallback(underlyingSessionTo(bytes)))
? JvmCoreDsl.ByteArrayBody(underlyingSessionTo(bytes))
: typeof bytes === "string"
? JvmCoreDsl.ByteArrayBody(bytes)
: JvmCoreDsl.ByteArrayBody(bytes)
Expand Down
41 changes: 15 additions & 26 deletions js/core/src/checks/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CoreDsl as JvmCoreDsl } from "@gatling.io/jvm-types";

import { wrapByteArray, wrapByteArrayCallback, wrapCallback } from "../gatlingJvm/callbacks";
import { Expression, Session, SessionTo, underlyingSessionTo } from "../session";
import { CheckBuilderCaptureGroup, wrapCheckBuilderCaptureGroup } from "./captureGroup";
import { wrapCheckBuilderFinal } from "./final";
Expand Down Expand Up @@ -49,14 +48,14 @@ export const bodyBytes = (): CheckBuilderFind<number[]> => ({
is: (expected: number[] | SessionTo<number[]>) =>
wrapCheckBuilderFinal(
typeof expected === "function"
? JvmCoreDsl.bodyBytes().is(wrapByteArrayCallback(underlyingSessionTo(expected)))
: JvmCoreDsl.bodyBytes().is(wrapByteArray(expected))
? JvmCoreDsl.bodyBytes().is(underlyingSessionTo(expected))
: JvmCoreDsl.bodyBytes().is(expected)
),
not: (expected: number[] | SessionTo<number[]>) =>
wrapCheckBuilderFinal(
typeof expected === "function"
? JvmCoreDsl.bodyBytes().not(wrapByteArrayCallback(underlyingSessionTo(expected)))
: JvmCoreDsl.bodyBytes().not(wrapByteArray(expected))
? JvmCoreDsl.bodyBytes().not(underlyingSessionTo(expected))
: JvmCoreDsl.bodyBytes().not(expected)
)
});

Expand Down Expand Up @@ -122,7 +121,7 @@ export interface SubstringFunction {
export const substring: SubstringFunction = (pattern: string | SessionTo<string>): CheckBuilderMultipleFind<number> =>
wrapCheckBuilderMultipleFind(
(typeof pattern === "function"
? JvmCoreDsl.substring(wrapCallback(underlyingSessionTo(pattern)))
? JvmCoreDsl.substring(underlyingSessionTo(pattern))
: JvmCoreDsl.substring(pattern)) as JvmCheckBuilderMultipleFind<number>
);

Expand Down Expand Up @@ -195,9 +194,9 @@ export interface XpathFunction {
export const xpath: XpathFunction = (path: string | SessionTo<string>, namespaces?: Record<string, string>) => {
if (typeof path === "function") {
if (namespaces !== undefined) {
return wrapCheckBuilderMultipleFind(JvmCoreDsl.xpath(wrapCallback(underlyingSessionTo(path)), namespaces)); // TODO change type of java.util.Map in java2typescript
return wrapCheckBuilderMultipleFind(JvmCoreDsl.xpath(underlyingSessionTo(path), namespaces)); // TODO change type of java.util.Map in java2typescript
} else {
return wrapCheckBuilderMultipleFind(JvmCoreDsl.xpath(wrapCallback(underlyingSessionTo(path))));
return wrapCheckBuilderMultipleFind(JvmCoreDsl.xpath(underlyingSessionTo(path)));
}
} else {
if (namespaces !== undefined) {
Expand Down Expand Up @@ -275,9 +274,9 @@ export interface CssFunction {
export const css: CssFunction = (selector: string | SessionTo<string>, nodeAttribute?: string) => {
if (typeof selector === "function") {
if (nodeAttribute !== undefined) {
return wrapCheckBuilderMultipleFind(JvmCoreDsl.css(wrapCallback(underlyingSessionTo(selector)), nodeAttribute));
return wrapCheckBuilderMultipleFind(JvmCoreDsl.css(underlyingSessionTo(selector), nodeAttribute));
} else {
return wrapCheckBuilderMultipleFind(JvmCoreDsl.css(wrapCallback(underlyingSessionTo(selector))));
return wrapCheckBuilderMultipleFind(JvmCoreDsl.css(underlyingSessionTo(selector)));
}
} else {
if (nodeAttribute !== undefined) {
Expand Down Expand Up @@ -324,7 +323,7 @@ export interface FormFunction {
export const form: FormFunction = (selector: string | SessionTo<string>) =>
wrapCheckBuilderMultipleFind(
(typeof selector === "function"
? JvmCoreDsl.form(wrapCallback(underlyingSessionTo(selector)))
? JvmCoreDsl.form(underlyingSessionTo(selector))
: JvmCoreDsl.form(selector)) as JvmCheckBuilderMultipleFind<any> // TODO change type of java.util.Map in java2typescript
);

Expand Down Expand Up @@ -360,9 +359,7 @@ export interface JsonPathFunction {

export const jsonPath: JsonPathFunction = (path: Expression<string>): CheckBuilderJsonOfTypeMultipleFind =>
wrapCheckBuilderJsonOfTypeMultipleFind(
typeof path === "function"
? JvmCoreDsl.jsonPath(wrapCallback(underlyingSessionTo(path)))
: JvmCoreDsl.jsonPath(path)
typeof path === "function" ? JvmCoreDsl.jsonPath(underlyingSessionTo(path)) : JvmCoreDsl.jsonPath(path)
);

export interface JmesPathFunction {
Expand Down Expand Up @@ -395,9 +392,7 @@ export interface JmesPathFunction {

export const jmesPath: JmesPathFunction = (path: Expression<string>): CheckBuilderJsonOfTypeFind =>
wrapCheckBuilderJsonOfTypeFind(
typeof path === "function"
? JvmCoreDsl.jmesPath(wrapCallback(underlyingSessionTo(path)))
: JvmCoreDsl.jmesPath(path)
typeof path === "function" ? JvmCoreDsl.jmesPath(underlyingSessionTo(path)) : JvmCoreDsl.jmesPath(path)
);

export interface JsonpJsonPathFunction {
Expand Down Expand Up @@ -432,9 +427,7 @@ export interface JsonpJsonPathFunction {

export const jsonpJsonPath: JsonpJsonPathFunction = (path: Expression<string>): CheckBuilderJsonOfTypeMultipleFind =>
wrapCheckBuilderJsonOfTypeMultipleFind(
typeof path === "function"
? JvmCoreDsl.jsonpJsonPath(wrapCallback(underlyingSessionTo(path)))
: JvmCoreDsl.jsonpJsonPath(path)
typeof path === "function" ? JvmCoreDsl.jsonpJsonPath(underlyingSessionTo(path)) : JvmCoreDsl.jsonpJsonPath(path)
);

export interface JsonpJmesPathFunction {
Expand Down Expand Up @@ -469,9 +462,7 @@ export interface JsonpJmesPathFunction {

export const jsonpJmesPath: JsonpJmesPathFunction = (path: Expression<string>): CheckBuilderJsonOfTypeFind =>
wrapCheckBuilderJsonOfTypeFind(
typeof path === "function"
? JvmCoreDsl.jsonpJmesPath(wrapCallback(underlyingSessionTo(path)))
: JvmCoreDsl.jsonpJmesPath(path)
typeof path === "function" ? JvmCoreDsl.jsonpJmesPath(underlyingSessionTo(path)) : JvmCoreDsl.jsonpJmesPath(path)
);

export interface RegexFunction {
Expand Down Expand Up @@ -508,9 +499,7 @@ export interface RegexFunction {

export const regex: RegexFunction = (pattern: Expression<string>): CheckBuilderCaptureGroup =>
wrapCheckBuilderCaptureGroup(
typeof pattern === "function"
? JvmCoreDsl.regex(wrapCallback(underlyingSessionTo(pattern)))
: JvmCoreDsl.regex(pattern)
typeof pattern === "function" ? JvmCoreDsl.regex(underlyingSessionTo(pattern)) : JvmCoreDsl.regex(pattern)
);

/**
Expand Down
31 changes: 11 additions & 20 deletions js/core/src/checks/validate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { wrapBiCallback, wrapCallback } from "../gatlingJvm/callbacks";
import { Session, SessionTo, underlyingSessionTo, underlyingXWithSessionTo } from "../session";
import { CheckBuilderFinal, wrapCheckBuilderFinal } from "./final";

Expand Down Expand Up @@ -276,38 +275,38 @@ export interface CheckBuilderValidate<X> extends CheckBuilderFinal {

export const wrapCheckBuilderValidate = <X>(_underlying: JvmCheckBuilderValidate<X>): CheckBuilderValidate<X> => ({
...wrapCheckBuilderFinal(_underlying),
transform: <X2>(f: (x: X) => X2) => wrapCheckBuilderValidate(_underlying.transform(wrapCallback(f))),
transform: <X2>(f: (x: X) => X2) => wrapCheckBuilderValidate(_underlying.transform(f)),
transformWithSession: <X2>(f: (x: X, session: Session) => X2) =>
wrapCheckBuilderValidate(_underlying.transformWithSession(wrapBiCallback(underlyingXWithSessionTo(f)))),
wrapCheckBuilderValidate(_underlying.transformWithSession(underlyingXWithSessionTo(f))),
withDefault: (value: X | SessionTo<X>) =>
wrapCheckBuilderValidate(
typeof value === "function"
? _underlying.withDefault(wrapCallback(underlyingSessionTo(value as SessionTo<X>)))
? _underlying.withDefault(underlyingSessionTo(value as SessionTo<X>))
: _underlying.withDefault(value)
),
withDefaultEL: (value: string) => wrapCheckBuilderValidate(_underlying.withDefaultEl(value)),
validate: (name: string, f: (x: X, session: Session) => X) =>
wrapCheckBuilderFinal(_underlying.validate(name, wrapBiCallback(underlyingXWithSessionTo(f)))),
wrapCheckBuilderFinal(_underlying.validate(name, underlyingXWithSessionTo(f))),
is: (expected: X | SessionTo<X>) =>
wrapCheckBuilderFinal(
typeof expected === "function"
? _underlying.is(wrapCallback(underlyingSessionTo(expected as SessionTo<X>)))
? _underlying.is(underlyingSessionTo(expected as SessionTo<X>))
: _underlying.is(expected)
),
isEL: (expected: string) => wrapCheckBuilderFinal(_underlying.isEL(expected)),
isNull: (): CheckBuilderFinal => wrapCheckBuilderFinal(_underlying.isNull()),
not: (expected: X | SessionTo<X>) =>
wrapCheckBuilderFinal(
typeof expected === "function"
? _underlying.not(wrapCallback(underlyingSessionTo(expected as SessionTo<X>)))
? _underlying.not(underlyingSessionTo(expected as SessionTo<X>))
: _underlying.not(expected)
),
notEL: (expected: string) => wrapCheckBuilderFinal(_underlying.notEL(expected)),
notNull: (): CheckBuilderFinal => wrapCheckBuilderFinal(_underlying.notNull()),
in: (expected: X | SessionTo<X[]>, ...rest: X[]) =>
wrapCheckBuilderFinal(
typeof expected === "function"
? _underlying.in(wrapCallback(underlyingSessionTo(expected as SessionTo<X[]>)))
? _underlying.in(underlyingSessionTo(expected as SessionTo<X[]>))
: _underlying.in([expected, ...rest])
),
inEL: (expected: string) => wrapCheckBuilderFinal(_underlying.inEL(expected)),
Expand All @@ -316,30 +315,22 @@ export const wrapCheckBuilderValidate = <X>(_underlying: JvmCheckBuilderValidate
optional: () => wrapCheckBuilderFinal(_underlying.optional()),
lt: (value: X | SessionTo<X>) =>
wrapCheckBuilderFinal(
typeof value === "function"
? _underlying.lt(wrapCallback(underlyingSessionTo(value as SessionTo<X>)))
: _underlying.lt(value)
typeof value === "function" ? _underlying.lt(underlyingSessionTo(value as SessionTo<X>)) : _underlying.lt(value)
),
ltEL: (value: string) => wrapCheckBuilderFinal(_underlying.ltEL(value)),
lte: (value: X | SessionTo<X>) =>
wrapCheckBuilderFinal(
typeof value === "function"
? _underlying.lte(wrapCallback(underlyingSessionTo(value as SessionTo<X>)))
: _underlying.lte(value)
typeof value === "function" ? _underlying.lte(underlyingSessionTo(value as SessionTo<X>)) : _underlying.lte(value)
),
lteEL: (value: string) => wrapCheckBuilderFinal(_underlying.lteEL(value)),
gt: (value: X | SessionTo<X>) =>
wrapCheckBuilderFinal(
typeof value === "function"
? _underlying.gt(wrapCallback(underlyingSessionTo(value as SessionTo<X>)))
: _underlying.gt(value)
typeof value === "function" ? _underlying.gt(underlyingSessionTo(value as SessionTo<X>)) : _underlying.gt(value)
),
gtEL: (value: string) => wrapCheckBuilderFinal(_underlying.gtEL(value)),
gte: (value: X | SessionTo<X>) =>
wrapCheckBuilderFinal(
typeof value === "function"
? _underlying.gte(wrapCallback(underlyingSessionTo(value as SessionTo<X>)))
: _underlying.gte(value)
typeof value === "function" ? _underlying.gte(underlyingSessionTo(value as SessionTo<X>)) : _underlying.gte(value)
),
gteEL: (value: string) => wrapCheckBuilderFinal(_underlying.gteEL(value))
});
7 changes: 3 additions & 4 deletions js/core/src/feeders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import JvmFeederBuilder = io.gatling.javaapi.core.FeederBuilder;
import JvmFeederBuilderFileBased = io.gatling.javaapi.core.FeederBuilder$FileBased;
import JvmFeederBuilderBatchable = io.gatling.javaapi.core.FeederBuilder$Batchable;

import { wrapBiCallback } from "./gatlingJvm/callbacks";
import { Wrapper } from "./common";

export interface FeederBuilder<T> extends Wrapper<JvmFeederBuilder<T>> {
Expand Down Expand Up @@ -83,7 +82,7 @@ const wrapFeederBuilder = <T>(_underlying: JvmFeederBuilder<T>): FeederBuilder<T
random: () => wrapFeederBuilder(_underlying.random()),
shuffle: () => wrapFeederBuilder(_underlying.shuffle()),
circular: () => wrapFeederBuilder(_underlying.circular()),
transform: (f: (name: string, value: T) => unknown) => wrapFeederBuilder(_underlying.transform(wrapBiCallback(f))),
transform: (f: (name: string, value: T) => unknown) => wrapFeederBuilder(_underlying.transform(f)),
recordsCount: () => _underlying.recordsCount(),
shard: () => wrapFeederBuilder(_underlying.shard())
});
Expand All @@ -105,7 +104,7 @@ export const wrapFileBasedFeederBuilder = <T>(
random: () => wrapFileBasedFeederBuilder(_underlying.random()),
shuffle: () => wrapFileBasedFeederBuilder(_underlying.shuffle()),
circular: () => wrapFileBasedFeederBuilder(_underlying.circular()),
transform: (f: (name: string, value: T) => unknown) => wrapFeederBuilder(_underlying.transform(wrapBiCallback(f))),
transform: (f: (name: string, value: T) => unknown) => wrapFeederBuilder(_underlying.transform(f)),
recordsCount: () => _underlying.recordsCount(),
shard: () => wrapFileBasedFeederBuilder(_underlying.shard()),
unzip: () => wrapFileBasedFeederBuilder(_underlying.unzip())
Expand Down Expand Up @@ -144,7 +143,7 @@ const wrapBatchableFeederBuilder = <T>(_underlying: JvmFeederBuilderBatchable<T>
random: () => wrapBatchableFeederBuilder(_underlying.random()),
shuffle: () => wrapBatchableFeederBuilder(_underlying.shuffle()),
circular: () => wrapBatchableFeederBuilder(_underlying.circular()),
transform: (f: (name: string, value: T) => unknown) => wrapFeederBuilder(_underlying.transform(wrapBiCallback(f))),
transform: (f: (name: string, value: T) => unknown) => wrapFeederBuilder(_underlying.transform(f)),
recordsCount: () => _underlying.recordsCount(),
shard: () => wrapBatchableFeederBuilder(_underlying.shard()),
unzip: () => wrapBatchableFeederBuilder(_underlying.unzip()),
Expand Down
29 changes: 0 additions & 29 deletions js/core/src/gatlingJvm/callbacks.ts

This file was deleted.

4 changes: 1 addition & 3 deletions js/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import "@gatling.io/jvm-types";
import JvmSetUp = io.gatling.javaapi.core.Simulation$SetUp;

import * as jvm from "./gatlingJvm/app";
import { wrapCallback } from "./gatlingJvm/callbacks";
import { PauseType, toJvmPauseType } from "./structure/pauses";
import { Duration, toJvmDuration } from "./utils/duration";
import { SessionTo, underlyingSessionTo } from "./session";
Expand All @@ -12,7 +11,6 @@ import { ProtocolBuilder } from "./protocol";
import { ThrottleStep } from "./throttling";

// FIXME no export *
export * from "./gatlingJvm/callbacks";
export * from "./utils/duration";
export * from "./assertions";
export * from "./body";
Expand Down Expand Up @@ -138,7 +136,7 @@ const wrapSetUp = (jvmSetUp: JvmSetUp): SetUp => ({
disablePauses: () => wrapSetUp(jvmSetUp.disablePauses()),
constantPauses: () => wrapSetUp(jvmSetUp.constantPauses()),
exponentialPauses: () => wrapSetUp(jvmSetUp.exponentialPauses()),
customPauses: (f) => wrapSetUp(jvmSetUp.customPauses(wrapCallback(underlyingSessionTo(f)))),
customPauses: (f) => wrapSetUp(jvmSetUp.customPauses(underlyingSessionTo(f))),
uniformPauses: (plusOrMinus) => wrapSetUp(jvmSetUp.uniformPauses(toJvmDuration(plusOrMinus))),
normalPausesWithStdDevDuration: (stdDevDuration) =>
wrapSetUp(jvmSetUp.normalPausesWithStdDevDuration(toJvmDuration(stdDevDuration))),
Expand Down
3 changes: 1 addition & 2 deletions js/core/src/population.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { wrapCallback } from "./gatlingJvm/callbacks";
import { Duration, toJvmDuration } from "./utils/duration";
import { PauseType, toJvmPauseType } from "./structure/pauses";
import { Wrapper } from "./common";
Expand Down Expand Up @@ -98,7 +97,7 @@ export const wrapPopulationBuilder = (_underlying: JvmPopulationBuilder): Popula
disablePauses: () => wrapPopulationBuilder(_underlying.disablePauses()),
constantPauses: () => wrapPopulationBuilder(_underlying.constantPauses()),
exponentialPauses: () => wrapPopulationBuilder(_underlying.exponentialPauses()),
customPauses: (f) => wrapPopulationBuilder(_underlying.customPauses(wrapCallback(underlyingSessionTo(f)))),
customPauses: (f) => wrapPopulationBuilder(_underlying.customPauses(underlyingSessionTo(f))),
uniformPauses: (plusOrMinus) => wrapPopulationBuilder(_underlying.uniformPauses(toJvmDuration(plusOrMinus))),
pauses: (pauseType) => wrapPopulationBuilder(_underlying.pauses(toJvmPauseType(pauseType))),
throttle: (...throttleSteps) => wrapPopulationBuilder(_underlying.throttle(throttleSteps.map((t) => t._underlying))),
Expand Down
3 changes: 1 addition & 2 deletions js/core/src/session.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { wrapByteArray } from "./gatlingJvm/callbacks";
import { asJava } from "./gatlingJvm/collections";
import { Duration, toJvmDuration } from "./utils/duration";
import { Wrapper } from "./common";
Expand Down Expand Up @@ -131,7 +130,7 @@ export const wrapSession = (_underlying: JvmSession): Session => ({
set: (key: string, value: any): Session => {
return wrapSession(_underlying.set(key, asJava(value)));
},
setByteArray: (key: string, value: number[]): Session => wrapSession(_underlying.set(key, wrapByteArray(value))),
setByteArray: (key: string, value: number[]): Session => wrapSession(_underlying.set(key, value)),
setAll: (newAttributes: Record<string, any>): Session => {
let session = _underlying;
for (const key in newAttributes) {
Expand Down
Loading

0 comments on commit c990523

Please sign in to comment.