Skip to content

Commit

Permalink
chore(deps): update dependency gts to v1 (googleapis#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
renovate[bot] authored and JustinBeckwith committed May 3, 2019
1 parent 7477cd7 commit 7a94c1e
Show file tree
Hide file tree
Showing 26 changed files with 3,462 additions and 2,928 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"eslint-config-prettier": "^4.0.0",
"eslint-plugin-node": "^9.0.0",
"eslint-plugin-prettier": "^3.0.0",
"gts": "^0.9.0",
"gts": "^1.0.0",
"intelli-espower-loader": "^1.0.1",
"jsdoc": "^3.5.5",
"jsdoc-baseline": "git+https://github.com/hegemonic/jsdoc-baseline.git",
Expand Down
65 changes: 35 additions & 30 deletions src/app-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export class AppProfile {
} else {
throw new Error(`AppProfile id '${id}' is not formatted correctly.
Please use the format 'my-app-profile' or '${
instance.name}/appProfiles/my-app-profile'.`);
instance.name
}/appProfiles/my-app-profile'.`);
}
} else {
name = `${instance.name}/appProfiles/${id}`;
Expand Down Expand Up @@ -108,11 +109,12 @@ Please use the format 'my-app-profile' or '${
};
if (is.boolean(options.allowTransactionalWrites)) {
appProfile.singleClusterRouting.allowTransactionalWrites =
options.allowTransactionalWrites;
options.allowTransactionalWrites;
}
} else {
throw new Error(
'An app profile routing policy can only contain "any" or a `Cluster`.');
'An app profile routing policy can only contain "any" or a `Cluster`.'
);
}
}

Expand Down Expand Up @@ -172,13 +174,14 @@ Please use the format 'my-app-profile' or '${
}

this.bigtable.request(
{
client: 'BigtableInstanceAdminClient',
method: 'deleteAppProfile',
reqOpts,
gaxOpts: options.gaxOptions,
},
callback);
{
client: 'BigtableInstanceAdminClient',
method: 'deleteAppProfile',
reqOpts,
gaxOpts: options.gaxOptions,
},
callback
);
}

/**
Expand Down Expand Up @@ -259,21 +262,22 @@ Please use the format 'my-app-profile' or '${
}

this.bigtable.request(
{
client: 'BigtableInstanceAdminClient',
method: 'getAppProfile',
reqOpts: {
name: this.name,
},
gaxOpts: gaxOptions,
{
client: 'BigtableInstanceAdminClient',
method: 'getAppProfile',
reqOpts: {
name: this.name,
},
(...args) => {
if (args[1]) {
this.metadata = args[1];
}
gaxOpts: gaxOptions,
},
(...args) => {
if (args[1]) {
this.metadata = args[1];
}

callback(...args);
});
callback(...args);
}
);
}

/**
Expand Down Expand Up @@ -323,13 +327,14 @@ Please use the format 'my-app-profile' or '${
}

this.bigtable.request(
{
client: 'BigtableInstanceAdminClient',
method: 'updateAppProfile',
reqOpts,
gaxOpts: gaxOptions,
},
callback);
{
client: 'BigtableInstanceAdminClient',
method: 'updateAppProfile',
reqOpts,
gaxOpts: gaxOptions,
},
callback
);
}
}

Expand Down
153 changes: 92 additions & 61 deletions src/chunktransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ import {Transform, TransformOptions} from 'stream';

import {Bytes, Mutation} from './mutation';

export type Value = string|number|boolean|Uint8Array;
export type Value = string | number | boolean | Uint8Array;

export interface Chunk {
rowContents: Value;
commitRow: boolean;
resetRow: boolean;
rowKey?: string|Uint8Array;
rowKey?: string | Uint8Array;
familyName?: {value: string};
qualifier?: Qualifier|{value: Value};
timestampMicros?: number|Long;
qualifier?: Qualifier | {value: Value};
timestampMicros?: number | Long;
labels?: string[];
value?: string|Buffer;
value?: string | Buffer;
valueSize?: number;
}
export interface Data {
Expand All @@ -39,9 +39,9 @@ interface Family {
[qualifier: string]: Qualifier[];
}
export interface Qualifier {
value?: string|Buffer;
value?: string | Buffer;
labels?: string[];
timestamp?: number|Long;
timestamp?: number | Long;
size?: number;
}
export interface Row {
Expand All @@ -50,7 +50,7 @@ export interface Row {
}
export interface TransformErrorProps {
message: string;
chunk: Chunk|null;
chunk: Chunk | null;
}

class TransformError extends Error {
Expand Down Expand Up @@ -88,7 +88,7 @@ export class ChunkTransformer extends Transform {
qualifiers?: Qualifier[];
qualifier?: Qualifier;
constructor(options: TransformOptions = {}) {
options.objectMode = true; // forcing object mode
options.objectMode = true; // forcing object mode
super(options);
this.options = options;
this._destroyed = false;
Expand All @@ -103,10 +103,12 @@ export class ChunkTransformer extends Transform {
*/
_flush(cb: Function): void {
if (typeof this.row!.key !== 'undefined') {
this.destroy(new TransformError({
message: 'Response ended with pending row without commit',
chunk: null,
}));
this.destroy(
new TransformError({
message: 'Response ended with pending row without commit',
chunk: null,
})
);
return;
}
cb();
Expand Down Expand Up @@ -149,10 +151,12 @@ export class ChunkTransformer extends Transform {
}
}
if (data.lastScannedRowKey && data.lastScannedRowKey.length > 0) {
this.lastRowKey =
Mutation.convertFromBytes(data.lastScannedRowKey as Bytes, {
userOptions: this.options,
});
this.lastRowKey = Mutation.convertFromBytes(
data.lastScannedRowKey as Bytes,
{
userOptions: this.options,
}
);
}
next();
}
Expand Down Expand Up @@ -200,10 +204,12 @@ export class ChunkTransformer extends Transform {
*/
validateValueSizeAndCommitRow(chunk: Chunk): void {
if (chunk.valueSize! > 0 && chunk.commitRow) {
this.destroy(new TransformError({
message: 'A row cannot be have a value size and be a commit row',
chunk,
}));
this.destroy(
new TransformError({
message: 'A row cannot be have a value size and be a commit row',
chunk,
})
);
}
}

Expand All @@ -213,14 +219,19 @@ export class ChunkTransformer extends Transform {
* @param {chunk} chunk chunk to validate for resetrow
*/
validateResetRow(chunk: Chunk): void {
const containsData = (chunk.rowKey && chunk.rowKey.length !== 0) ||
chunk.familyName || chunk.qualifier ||
(chunk.value && chunk.value.length !== 0) || chunk.timestampMicros! > 0;
const containsData =
(chunk.rowKey && chunk.rowKey.length !== 0) ||
chunk.familyName ||
chunk.qualifier ||
(chunk.value && chunk.value.length !== 0) ||
chunk.timestampMicros! > 0;
if (chunk.resetRow && containsData) {
this.destroy(new TransformError({
message: 'A reset should have no data',
chunk,
}));
this.destroy(
new TransformError({
message: 'A reset should have no data',
chunk,
})
);
}
}

Expand All @@ -230,16 +241,18 @@ export class ChunkTransformer extends Transform {
* @param {chunk} chunk chunk to validate
* @param {newRowKey} newRowKey newRowKey of the new row
*/
validateNewRow(chunk: Chunk, newRowKey: string|Buffer): void {
validateNewRow(chunk: Chunk, newRowKey: string | Buffer): void {
const row = this.row;
const lastRowKey = this.lastRowKey;
let errorMessage: string|undefined;
let errorMessage: string | undefined;

if (typeof row!.key !== 'undefined') {
errorMessage = 'A new row cannot have existing state';
} else if (
typeof chunk.rowKey === 'undefined' || chunk.rowKey.length === 0 ||
newRowKey.length === 0) {
typeof chunk.rowKey === 'undefined' ||
chunk.rowKey.length === 0 ||
newRowKey.length === 0
) {
errorMessage = 'A row key must be set';
} else if (chunk.resetRow) {
errorMessage = 'A new row cannot be reset';
Expand Down Expand Up @@ -269,21 +282,31 @@ export class ChunkTransformer extends Transform {
userOptions: this.options,
});
const oldRowKey = row!.key || '';
if (newRowKey && chunk.rowKey && (newRowKey as string).length !== 0 &&
newRowKey.toString() !== oldRowKey.toString()) {
this.destroy(new TransformError({
message: 'A commit is required between row keys',
chunk,
}));
if (
newRowKey &&
chunk.rowKey &&
(newRowKey as string).length !== 0 &&
newRowKey.toString() !== oldRowKey.toString()
) {
this.destroy(
new TransformError({
message: 'A commit is required between row keys',
chunk,
})
);
return;
}
}
if (chunk.familyName &&
(chunk.qualifier === null || chunk.qualifier === undefined)) {
this.destroy(new TransformError({
message: 'A qualifier must be specified',
chunk,
}));
if (
chunk.familyName &&
(chunk.qualifier === null || chunk.qualifier === undefined)
) {
this.destroy(
new TransformError({
message: 'A qualifier must be specified',
chunk,
})
);
return;
}
this.validateResetRow(chunk);
Expand Down Expand Up @@ -335,11 +358,13 @@ export class ChunkTransformer extends Transform {
row!.key = newRowKey;
row!.data = {} as Data;
this.family = row!.data![chunk.familyName.value] = {} as Family;
const qualifierName =
Mutation.convertFromBytes(chunk.qualifier.value as Bytes, {
userOptions: this.options,
});
this.qualifiers = this.family[qualifierName as {} as string] = [];
const qualifierName = Mutation.convertFromBytes(
chunk.qualifier.value as Bytes,
{
userOptions: this.options,
}
);
this.qualifiers = this.family[(qualifierName as {}) as string] = [];
this.qualifier = {
value: Mutation.convertFromBytes(chunk.value! as Bytes, {
userOptions: this.options,
Expand All @@ -366,15 +391,17 @@ export class ChunkTransformer extends Transform {
const row = this.row;
if (chunk.familyName) {
this.family = row!.data![chunk.familyName.value] =
row!.data![chunk.familyName.value] || {};
row!.data![chunk.familyName.value] || {};
}
if (chunk.qualifier) {
const qualifierName =
Mutation.convertFromBytes(chunk.qualifier.value as Bytes, {
userOptions: this.options,
}) as string;
const qualifierName = Mutation.convertFromBytes(
chunk.qualifier.value as Bytes,
{
userOptions: this.options,
}
) as string;
this.qualifiers = this.family![qualifierName] =
this.family![qualifierName] || [];
this.family![qualifierName] || [];
}
this.qualifier = {
value: Mutation.convertFromBytes(chunk.value! as Bytes, {
Expand All @@ -398,13 +425,17 @@ export class ChunkTransformer extends Transform {
if (chunk.resetRow) {
return this.reset();
}
const chunkQualifierValue =
Mutation.convertFromBytes(chunk.value! as Bytes, {
userOptions: this.options,
});
const chunkQualifierValue = Mutation.convertFromBytes(
chunk.value! as Bytes,
{
userOptions: this.options,
}
);

if (chunkQualifierValue instanceof Buffer &&
this.qualifier!.value instanceof Buffer) {
if (
chunkQualifierValue instanceof Buffer &&
this.qualifier!.value instanceof Buffer
) {
this.qualifier!.value = Buffer.concat([
this.qualifier!.value,
chunkQualifierValue,
Expand Down
Loading

0 comments on commit 7a94c1e

Please sign in to comment.