Skip to content

Commit d597774

Browse files
refactor(ts): use es imports and exports (#307)
1 parent 7eaa5f0 commit d597774

11 files changed

Lines changed: 44 additions & 56 deletions

File tree

handwritten/logging/src/entry.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
'use strict';
18-
1917
import {Service} from '@google-cloud/common-grpc';
2018
// tslint:disable-next-line variable-name
2119
const EventId = require('eventid');
@@ -85,7 +83,7 @@ const eventId = new EventId();
8583
class Entry {
8684
metadata;
8785
data;
88-
constructor(metadata, data) {
86+
constructor(metadata?, data?) {
8987
/**
9088
* @name Entry#metadata
9189
* @type {object}
@@ -174,4 +172,4 @@ class Entry {
174172
* @name module:@google-cloud/logging.Entry
175173
* @see Entry
176174
*/
177-
module.exports.Entry = Entry;
175+
export {Entry};

handwritten/logging/src/index.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
'use strict';
18-
19-
import * as arrify from 'arrify';
2017
import * as common from '@google-cloud/common-grpc';
21-
import {promisifyAll} from '@google-cloud/promisify';
2218
import {paginator} from '@google-cloud/paginator';
2319
import {replaceProjectIdToken} from '@google-cloud/projectify';
20+
import {promisifyAll} from '@google-cloud/promisify';
21+
import * as arrify from 'arrify';
2422
import * as extend from 'extend';
2523
import {GoogleAuth} from 'google-auth-library';
2624
import * as is from 'is';
25+
2726
const pumpify = require('pumpify');
2827
import * as streamEvents from 'stream-events';
2928
import * as through from 'through2';
@@ -36,9 +35,9 @@ export {HttpRequest};
3635
const PKG = require('../../package.json');
3736
const v2 = require('./v2');
3837

39-
const {Entry} = require('./entry');
40-
const {Log} = require('./log');
41-
const {Sink} = require('./sink');
38+
import {Entry} from './entry';
39+
import {Log} from './log';
40+
import {Sink} from './sink';
4241

4342
/**
4443
* @namespace google
@@ -913,7 +912,7 @@ promisifyAll(Logging, {
913912
* @see Entry
914913
* @type {Constructor}
915914
*/
916-
module.exports.Entry = Entry;
915+
export {Entry};
917916

918917
/**
919918
* {@link Log} class.
@@ -922,7 +921,7 @@ module.exports.Entry = Entry;
922921
* @see Log
923922
* @type {Constructor}
924923
*/
925-
module.exports.Log = Log;
924+
export {Log};
926925

927926
/**
928927
* {@link Sink} class.
@@ -931,7 +930,7 @@ module.exports.Log = Log;
931930
* @see Sink
932931
* @type {Constructor}
933932
*/
934-
module.exports.Sink = Sink;
933+
export {Sink};
935934

936935
/**
937936
* The default export of the `@google-cloud/logging` package is the

handwritten/logging/src/log.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17-
'use strict';
18-
19-
import * as arrify from 'arrify';
2017
import {promisifyAll} from '@google-cloud/promisify';
18+
import * as arrify from 'arrify';
2119
import * as extend from 'extend';
2220
import * as is from 'is';
2321

2422
import {getDefaultResource} from './metadata';
2523

2624
const snakeCaseKeys = require('snakecase-keys');
2725

28-
const {Entry} = require('./entry');
26+
import {Entry} from './entry';
2927

3028
/**
3129
* A log is a named collection of entries, each entry representing a timestamped
@@ -204,7 +202,7 @@ class Log {
204202
* region_tag:logging_delete_log
205203
* Another example:
206204
*/
207-
delete(gaxOptions, callback) {
205+
delete(gaxOptions, callback?) {
208206
if (is.fn(gaxOptions)) {
209207
callback = gaxOptions;
210208
gaxOptions = {};
@@ -387,7 +385,7 @@ class Log {
387385
* const entries = data[0];
388386
* });
389387
*/
390-
getEntries(options, callback) {
388+
getEntries(options, callback?) {
391389
if (is.function(options))
392390
{
393391
callback = options;
@@ -633,7 +631,7 @@ class Log {
633631
* region_tag:logging_write_log_entry_advanced
634632
* Another example:
635633
*/
636-
write(entry, options, callback) {
634+
write(entry, options?, callback?) {
637635
const self = this;
638636
if (is.fn(options)) {
639637
callback = options;
@@ -753,4 +751,4 @@ class Log {
753751
* @name module:@google-cloud/logging.Log
754752
* @see Log
755753
*/
756-
module.exports.Log = Log;
754+
export {Log};

handwritten/logging/src/metadata.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
'use strict';
18-
1917
import * as fs from 'fs';
2018
import * as gcpMetadata from 'gcp-metadata';
2119
import {GoogleAuth} from 'google-auth-library';

handwritten/logging/src/sink.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
'use strict';
18-
1917
import * as common from '@google-cloud/common-grpc';
2018
import {promisifyAll} from '@google-cloud/promisify';
2119
import * as extend from 'extend';
@@ -93,7 +91,7 @@ class Sink {
9391
* region_tag:logging_create_sink
9492
* Another example:
9593
*/
96-
create(config, callback) {
94+
create(config, callback?) {
9795
this.logging.createSink(this.name, config, callback);
9896
}
9997

@@ -257,7 +255,7 @@ class Sink {
257255
* const apiResponse = data[0];
258256
* });
259257
*/
260-
setFilter(filter, callback) {
258+
setFilter(filter, callback?) {
261259
this.setMetadata(
262260
{
263261
filter,
@@ -311,7 +309,7 @@ class Sink {
311309
* region_tag:logging_update_sink
312310
* Another example:
313311
*/
314-
setMetadata(metadata, callback) {
312+
setMetadata(metadata, callback?) {
315313
const self = this;
316314
callback = callback || common.util.noop;
317315
this.getMetadata((err, currentMetadata, apiResponse) => {
@@ -353,4 +351,4 @@ promisifyAll(Sink);
353351
* @name module:@google-cloud/logging.Sink
354352
* @see Sink
355353
*/
356-
module.exports.Sink = Sink;
354+
export {Sink};

handwritten/logging/system-test/logging.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ describe('Logging', () => {
9292
describe('sinks', () => {
9393
it('should create a sink with a Bucket destination', async () => {
9494
const sink = logging.sink(generateName());
95-
const [_, apiResponse] = await sink.create({
95+
// tslint:disable-next-line no-any
96+
const [_, apiResponse] = await (sink as any).create({
9697
destination: bucket,
9798
});
9899
const destination = 'storage.googleapis.com/' + bucket.name;
@@ -101,11 +102,13 @@ describe('Logging', () => {
101102

102103
it('should create a sink with a Dataset destination', async () => {
103104
const sink = logging.sink(generateName());
104-
const [_, apiResponse] = await sink.create(
105-
{
106-
destination: dataset,
107-
},
108-
);
105+
// tslint:disable-next-line no-any
106+
const [_, apiResponse] = await (sink as any)
107+
.create(
108+
{
109+
destination: dataset,
110+
},
111+
);
109112

110113
const destination = `bigquery.googleapis.com/datasets/${dataset.id}`;
111114

@@ -118,7 +121,8 @@ describe('Logging', () => {
118121

119122
it('should create a sink with a Topic destination', async () => {
120123
const sink = logging.sink(generateName());
121-
const [_, apiResponse] = await sink.create({destination: topic});
124+
// tslint:disable-next-line no-any
125+
const [_, apiResponse] = await (sink as any).create({destination: topic});
122126
const destination = 'pubsub.googleapis.com/' + topic.name;
123127

124128
// The projectId may have been replaced depending on how the system
@@ -138,12 +142,14 @@ describe('Logging', () => {
138142

139143
it('should set metadata', async () => {
140144
const metadata = {filter: FILTER};
141-
const [apiResponse] = await sink.setMetadata(metadata);
145+
// tslint:disable-next-line no-any
146+
const [apiResponse] = await (sink as any).setMetadata(metadata);
142147
assert.strictEqual(apiResponse.filter, FILTER);
143148
});
144149

145150
it('should set a filter', async () => {
146-
const [apiResponse] = await sink.setFilter(FILTER);
151+
// tslint:disable-next-line no-any
152+
const [apiResponse] = await (sink as any).setFilter(FILTER);
147153
assert.strictEqual(apiResponse.filter, FILTER);
148154
});
149155
});

handwritten/logging/test/entry.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
'use strict';
18-
17+
import {Service, util} from '@google-cloud/common-grpc';
1918
import * as assert from 'assert';
2019
import * as extend from 'extend';
21-
import {Service, util} from '@google-cloud/common-grpc';
2220
import * as proxyquire from 'proxyquire';
2321

2422
class FakeGrpcService {

handwritten/logging/test/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
'use strict';
18-
17+
import {util} from '@google-cloud/common-grpc';
1918
import * as arrify from 'arrify';
2019
import * as assert from 'assert';
2120
import * as extend from 'extend';
2221
import * as proxyquire from 'proxyquire';
2322
import * as through from 'through2';
24-
import {util} from '@google-cloud/common-grpc';
23+
2524
const {v2} = require('../src');
2625
const PKG = require('../../package.json');
2726

handwritten/logging/test/log.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
'use strict';
18-
17+
import {util} from '@google-cloud/common-grpc';
18+
import * as promisify from '@google-cloud/promisify';
1919
import * as assert from 'assert';
2020
import * as extend from 'extend';
2121
import * as proxyquire from 'proxyquire';
22-
import {util} from '@google-cloud/common-grpc';
23-
import * as promisify from '@google-cloud/promisify';
2422

2523
let promisifed = false;
2624
const fakePromisify = extend({}, promisify, {
@@ -33,7 +31,7 @@ const fakePromisify = extend({}, promisify, {
3331
},
3432
});
3533

36-
const {Entry} = require('../src');
34+
import {Entry} from '../src';
3735

3836
const originalGetDefaultResource = async () => {
3937
return 'very-fake-resource';

handwritten/logging/test/metadata.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
'use strict';
18-
1917
import * as assert from 'assert';
2018
import BigNumber from 'bignumber.js';
2119
import * as extend from 'extend';

0 commit comments

Comments
 (0)