Skip to content

Commit

Permalink
Merge pull request apache#29942 [Typescript] upgrade prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwb authored Jan 8, 2024
2 parents c9e036e + 992e4fd commit 6350339
Show file tree
Hide file tree
Showing 54 changed files with 570 additions and 552 deletions.
25 changes: 14 additions & 11 deletions sdks/typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdks/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"istanbul": "^0.4.5",
"js-yaml": "^4.1.0",
"mocha": "^9.1.3",
"prettier": "^2.5.1",
"prettier": "^3.1.1",
"typedoc": "^0.23.23",
"typescript": "4.7"
},
Expand Down
6 changes: 3 additions & 3 deletions sdks/typescript/src/apache_beam/coders/coders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class CoderRegistry {

registerConstructor(
urn: string,
constructor: (...args: unknown[]) => Coder<unknown>
constructor: (...args: unknown[]) => Coder<unknown>,
) {
this.internal_registry[urn] = constructor;
}
Expand Down Expand Up @@ -142,7 +142,7 @@ export interface Coder<T> {
function writeByteCallback(
val: number,
buf: { [x: string]: number },
pos: number
pos: number,
) {
buf[pos] = val & 0xff;
}
Expand All @@ -162,7 +162,7 @@ export function writeRawByte(b: unknown, writer: HackedWriter) {
function writeBytesCallback(
val: number[],
buf: { [x: string]: number },
pos: number
pos: number,
) {
for (let i = 0; i < val.length; ++i) {
buf[pos + i] = val[i];
Expand Down
29 changes: 16 additions & 13 deletions sdks/typescript/src/apache_beam/coders/required_coders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export class IterableCoder<T> implements Coder<Iterable<T>> {
}
for (var i = 0; i < count; i++) {
result.push(
this.elementCoder.decode(reader, Context.needsDelimiters)
this.elementCoder.decode(reader, Context.needsDelimiters),
);
}
}
Expand Down Expand Up @@ -369,7 +369,7 @@ export class LengthPrefixedCoder<T> implements Coder<T> {
decode(reader: Reader, context: Context): T {
return this.elementCoder.decode(
new Reader(reader.bytes()),
Context.wholeStream
Context.wholeStream,
);
}
}
Expand All @@ -384,7 +384,10 @@ export class FullWindowedValueCoder<T, W extends Window>
static URN: string = "beam:coder:windowed_value:v1";
windowIterableCoder: IterableCoder<W>; // really W

constructor(public elementCoder: Coder<T>, public windowCoder: Coder<W>) {
constructor(
public elementCoder: Coder<T>,
public windowCoder: Coder<W>,
) {
this.windowIterableCoder = new IterableCoder(windowCoder);
}

Expand All @@ -405,29 +408,29 @@ export class FullWindowedValueCoder<T, W extends Window>
InstantCoder.INSTANCE.encode(
windowedValue.timestamp,
writer,
Context.needsDelimiters
Context.needsDelimiters,
);
this.windowIterableCoder.encode(
<Array<W>>windowedValue.windows,
writer,
Context.needsDelimiters
Context.needsDelimiters,
); // Windows.
PaneInfoCoder.INSTANCE.encode(
windowedValue.pane,
writer,
Context.needsDelimiters
Context.needsDelimiters,
);
this.elementCoder.encode(windowedValue.value, writer, context);
}

decode(reader: Reader, context: Context): WindowedValue<T> {
const timestamp = InstantCoder.INSTANCE.decode(
reader,
Context.needsDelimiters
Context.needsDelimiters,
);
const windows = this.windowIterableCoder.decode(
reader,
Context.needsDelimiters
Context.needsDelimiters,
);
const pane = PaneInfoCoder.INSTANCE.decode(reader, Context.needsDelimiters);
const value = this.elementCoder.decode(reader, context);
Expand Down Expand Up @@ -472,8 +475,8 @@ export class InstantCoder implements Coder<Instant> {
decode(reader: Reader, context: Context): Instant {
const shiftedMillis = Long.fromBytesBE(
Array.from(
reader.buf.slice(reader.pos, reader.pos + InstantCoder.INSTANT_BYTES)
)
reader.buf.slice(reader.pos, reader.pos + InstantCoder.INSTANT_BYTES),
),
);
reader.pos += InstantCoder.INSTANT_BYTES;
return shiftedMillis.add(Long.MIN_VALUE);
Expand Down Expand Up @@ -503,7 +506,7 @@ export class PaneInfoCoder implements Coder<PaneInfo> {
static INSTANCE = new PaneInfoCoder();
static ONE_AND_ONLY_FIRING = PaneInfoCoder.INSTANCE.decode(
new Reader(new Uint8Array([0x09])),
null!
null!,
);

private static decodeTiming(timingNumber): Timing {
Expand All @@ -520,7 +523,7 @@ export class PaneInfoCoder implements Coder<PaneInfo> {
throw new Error(
"Timing number 0b" +
timingNumber.toString(2) +
" has more than two bits of info"
" has more than two bits of info",
);
}
}
Expand Down Expand Up @@ -635,7 +638,7 @@ export class PaneInfoCoder implements Coder<PaneInfo> {

toProto(pipelineContext: ProtoContext): runnerApi.Coder {
throw new Error(
"No proto encoding for PaneInfoCoder, always part of WindowedValue codec"
"No proto encoding for PaneInfoCoder, always part of WindowedValue codec",
);
}
}
Expand Down
24 changes: 12 additions & 12 deletions sdks/typescript/src/apache_beam/coders/row_coder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export class RowCoder implements Coder<any> {
default:
throw new Error(
`Encountered a type that is not currently supported by RowCoder: ${JSON.stringify(
f.type
)}`
f.type,
)}`,
);
}
return obj;
Expand Down Expand Up @@ -265,14 +265,14 @@ export class RowCoder implements Coder<any> {
return new BoolCoder();
default:
throw new Error(
`Encountered an Atomic type that is not currently supported by RowCoder: ${atomicType}`
`Encountered an Atomic type that is not currently supported by RowCoder: ${atomicType}`,
);
}
break;
case "arrayType":
if (typeInfo.arrayType.elementType !== undefined) {
return new IterableCoder(
this.getCoderFromType(typeInfo.arrayType.elementType)
this.getCoderFromType(typeInfo.arrayType.elementType),
);
} else {
throw new Error("ElementType missing on ArrayType");
Expand All @@ -290,14 +290,14 @@ export class RowCoder implements Coder<any> {
const logicalTypeInfo = logicalTypes.get(typeInfo.logicalType.urn);
if (logicalTypeInfo !== undefined) {
const reprCoder = this.getCoderFromType(
typeInfo.logicalType.representation!
typeInfo.logicalType.representation!,
);
return {
encode: (element: any, writer: Writer, context: Context) =>
reprCoder.encode(
logicalTypeInfo.toRepr(element),
writer,
context
context,
),
decode: (reader: Reader, context: Context) =>
logicalTypeInfo.fromRepr(reprCoder.decode(reader, context)),
Expand All @@ -312,8 +312,8 @@ export class RowCoder implements Coder<any> {
default:
throw new Error(
`Encountered a type that is not currently supported by RowCoder: ${JSON.stringify(
t
)}`
t,
)}`,
);
}
}
Expand Down Expand Up @@ -342,7 +342,7 @@ export class RowCoder implements Coder<any> {
let encPosx = schema.fields.map((f: Field) => f.encodingPosition);
if (encPosx.length !== this.encodingPositions.length) {
throw new Error(
`Schema with id ${this.schema.id} has encoding_positions_set=True, but not all fields have encoding_position set`
`Schema with id ${this.schema.id} has encoding_positions_set=True, but not all fields have encoding_position set`,
);
}
// Checking if positions are in {0, ..., length-1}
Expand All @@ -352,7 +352,7 @@ export class RowCoder implements Coder<any> {
}

this.hasNullableFields = this.schema.fields.some(
(f: Field) => f.type?.nullable
(f: Field) => f.type?.nullable,
);
this.components = this.encodingPositions
.map((i) => this.schema.fields[i])
Expand Down Expand Up @@ -409,7 +409,7 @@ export class RowCoder implements Coder<any> {
if (attr === null || attr === undefined) {
if (!this.fieldNullable[i]) {
throw new Error(
`Attempted to encode null for non-nullable field \"${this.schema.fields[i].name}\".`
`Attempted to encode null for non-nullable field \"${this.schema.fields[i].name}\".`,
);
}
} else {
Expand Down Expand Up @@ -472,7 +472,7 @@ export class RowCoder implements Coder<any> {
obj = this.addFieldOfType(
obj,
this.schema.fields[i],
sortedComponents[i]
sortedComponents[i],
);
});

Expand Down
2 changes: 1 addition & 1 deletion sdks/typescript/src/apache_beam/coders/standard_coders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,5 @@ globalRegistry().register(IntervalWindowCoder.URN, IntervalWindowCoder);
import { requireForSerialization } from "../serialization";
requireForSerialization(
"apache-beam/coders/standard_coders",
exports as Record<string, unknown>
exports as Record<string, unknown>,
);
2 changes: 1 addition & 1 deletion sdks/typescript/src/apache_beam/examples/wordcount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function main() {
"And the earth was without form, and void; and darkness was upon the face of the deep.",
"And the Spirit of God moved upon the face of the waters.",
"And God said, Let there be light: and there was light.",
])
]),
);

lines.apply(wordCount).map(console.log);
Expand Down
4 changes: 2 additions & 2 deletions sdks/typescript/src/apache_beam/examples/wordcount_sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ async function main() {
.apply(beam.withRowCoder({ word: "str" }))
.applyAsync(
sqlTransform(
"SELECT word, count(*) as c from PCOLLECTION group by word"
)
"SELECT word, count(*) as c from PCOLLECTION group by word",
),
);

filtered.map(console.log);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function main() {
// python apache_beam/runners/portability/local_job_service_main.py --port 3333
await new PortableRunner("localhost:3333").run(async (root) => {
const lines = await root.applyAsync(
textio.readFromText("gs://dataflow-samples/shakespeare/kinglear.txt")
textio.readFromText("gs://dataflow-samples/shakespeare/kinglear.txt"),
);

lines.apply(wordCount).map(console.log);
Expand Down
12 changes: 6 additions & 6 deletions sdks/typescript/src/apache_beam/internal/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function jsEnvironment(
urn: string,
payload: Uint8Array,
resourceHints: { [key: string]: Uint8Array } = {},
artifacts: runnerApi.ArtifactInformation[] = []
artifacts: runnerApi.ArtifactInformation[] = [],
): runnerApi.Environment {
return {
urn: urn,
Expand All @@ -55,7 +55,7 @@ export function jsEnvironment(
function asNewEnvironment(
env: runnerApi.Environment,
urn: string,
payload: Uint8Array
payload: Uint8Array,
) {
return {
urn: urn,
Expand All @@ -69,7 +69,7 @@ function asNewEnvironment(

export function asExternalEnvironment(
env: runnerApi.Environment,
address: string
address: string,
) {
return asNewEnvironment(
env,
Expand All @@ -80,17 +80,17 @@ export function asExternalEnvironment(
authentication: null!,
},
params: {},
})
}),
);
}

export function asDockerEnvironment(
env: runnerApi.Environment,
containerImage: string
containerImage: string,
) {
return asNewEnvironment(
env,
"beam:env:docker:v1",
runnerApi.DockerPayload.toBinary({ containerImage: containerImage })
runnerApi.DockerPayload.toBinary({ containerImage: containerImage }),
);
}
Loading

0 comments on commit 6350339

Please sign in to comment.