Skip to content

Commit 9da7a14

Browse files
Salakarlaurenzlong
authored andcommitted
chore(*): Setup Travis configuration (#87)
1 parent eb28499 commit 9da7a14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+702
-507
lines changed

.prettierignore

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package.json
22
extension.yaml
3-
webpack.config.js
3+
package-lock.json
4+
45
**/node_modules/**
56

67
# generated files
78
README.md
8-
POSTINSTALL.md
9-
PREINSTALL.md
109
**/functions/lib/**
1110
**/dist/**
11+
12+
# extension install md files
13+
# - excluded as prettier escapes variables e.g. `${PROJECT_ID}` becomes `\${PROJECT_ID}`
14+
POSTINSTALL.md
15+
PREINSTALL.md

.prettierrc.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
trailingComma: es5
1616
arrowParens: always
1717
overrides:
18-
- files: "*.yaml"
18+
- files: "*.{yml,yaml}"
1919
options:
2020
proseWrap: always

.travis.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: node_js
2+
3+
node_js:
4+
- 8
5+
- 10
6+
- 12
7+
8+
stages:
9+
- validate
10+
- test
11+
12+
jobs:
13+
include:
14+
- stage: validate
15+
name: "TypeScript Compile"
16+
script: npm run clean && npm run build
17+
- stage: validate
18+
name: "Prettier Format Check"
19+
script: npm run lint
20+
- stage: test
21+
script: npm run test-coverage

auth-mailchimp-sync/jest.config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ module.exports = {
66
rootDir: "./",
77
preset: "ts-jest",
88
globalSetup: "./jest.setup.js",
9-
globalTeardown: "./jest.teardown.js"
9+
globalTeardown: "./jest.teardown.js",
1010
};
11-
12-

auth-mailchimp-sync/tsconfig.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33
"compilerOptions": {
44
"outDir": "functions/lib"
55
},
6-
"include": [
7-
"functions/src"
8-
]
6+
"include": ["functions/src"]
97
}

delete-user-data/functions/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ const clearFirestoreData = async (firestorePaths: string, uid: string) => {
118118
const paths = extractUserPaths(firestorePaths, uid);
119119
const promises = paths.map(async (path) => {
120120
try {
121-
const isRecursive = config.firestoreDeleteMode === 'recursive';
121+
const isRecursive = config.firestoreDeleteMode === "recursive";
122122

123123
if (!isRecursive) {
124124
const firestore = admin.firestore();
125125
logs.firestorePathDeleting(path, false);
126126

127127
// Wrapping in transaction to allow for automatic retries (#48)
128-
await firestore.runTransaction((transaction => {
128+
await firestore.runTransaction((transaction) => {
129129
transaction.delete(firestore.doc(path));
130130
return Promise.resolve();
131-
}));
131+
});
132132
logs.firestorePathDeleted(path, false);
133133
} else {
134134
logs.firestorePathDeleting(path, true);

delete-user-data/functions/src/logs.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,19 @@ export const firestoreNotConfigured = () => {
3333
};
3434

3535
export const firestorePathDeleted = (path: string, recursive: boolean) => {
36-
console.log(`Deleted: '${path}' from Cloud Firestore ${recursive ? 'with recursive delete' : ''}`);
36+
console.log(
37+
`Deleted: '${path}' from Cloud Firestore ${
38+
recursive ? "with recursive delete" : ""
39+
}`
40+
);
3741
};
3842

3943
export const firestorePathDeleting = (path: string, recursive: boolean) => {
40-
console.log(`Deleting: '${path}' from Cloud Firestore ${recursive ? 'with recursive delete' : ''}`);
44+
console.log(
45+
`Deleting: '${path}' from Cloud Firestore ${
46+
recursive ? "with recursive delete" : ""
47+
}`
48+
);
4149
};
4250

4351
export const firestorePathError = (path: string, err: Error) => {
@@ -69,7 +77,10 @@ export const rtdbPathDeleting = (path: string) => {
6977
};
7078

7179
export const rtdbPathError = (path: string, err: Error) => {
72-
console.error(`Error when deleting: '${path}' from the Realtime Database`, err);
80+
console.error(
81+
`Error when deleting: '${path}' from the Realtime Database`,
82+
err
83+
);
7384
};
7485

7586
export const start = () => {

delete-user-data/jest.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const packageJson = require('./package.json');
1+
const packageJson = require("./package.json");
22

33
module.exports = {
44
name: packageJson.name,
55
displayName: packageJson.name,
6-
rootDir: './',
7-
preset: 'ts-jest',
6+
rootDir: "./",
7+
preset: "ts-jest",
88
};

delete-user-data/tsconfig.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33
"compilerOptions": {
44
"outDir": "functions/lib"
55
},
6-
"include": [
7-
"functions/src"
8-
]
6+
"include": ["functions/src"]
97
}

firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/index.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
*/
1616

1717
import * as bigquery from "@google-cloud/bigquery";
18-
import {
19-
firestoreToBQTable,
20-
} from "./schema";
18+
import { firestoreToBQTable } from "./schema";
2119
import { latestConsistentSnapshotView } from "./snapshot";
2220

23-
import { ChangeType, FirestoreEventHistoryTracker, FirestoreDocumentChangeEvent } from "../tracker";
21+
import {
22+
ChangeType,
23+
FirestoreEventHistoryTracker,
24+
FirestoreDocumentChangeEvent,
25+
} from "../tracker";
2426
import * as logs from "../logs";
2527
import { BigQuery } from "@google-cloud/bigquery";
2628

@@ -38,7 +40,8 @@ export interface FirestoreBigQueryEventHistoryTrackerConfig {
3840
* - View: Latest view {@link FirestoreBigQueryEventHistoryTracker#rawLatestView}.
3941
* If any subsequent data export fails, it will attempt to reinitialize.
4042
*/
41-
export class FirestoreBigQueryEventHistoryTracker implements FirestoreEventHistoryTracker {
43+
export class FirestoreBigQueryEventHistoryTracker
44+
implements FirestoreEventHistoryTracker {
4245
bq: bigquery.BigQuery;
4346
initialized: boolean = false;
4447

@@ -49,7 +52,7 @@ export class FirestoreBigQueryEventHistoryTracker implements FirestoreEventHisto
4952
async record(events: FirestoreDocumentChangeEvent[]) {
5053
await this.initialize();
5154

52-
const rows = events.map(event => {
55+
const rows = events.map((event) => {
5356
// This must match firestoreToBQTable().
5457
return {
5558
timestamp: event.timestamp,
@@ -132,7 +135,7 @@ export class FirestoreBigQueryEventHistoryTracker implements FirestoreEventHisto
132135
logs.bigQueryTableCreated(changelogName);
133136
}
134137
return table;
135-
};
138+
}
136139

137140
/**
138141
* Creates the latest snapshot view, which returns only latest operations
@@ -146,7 +149,10 @@ export class FirestoreBigQueryEventHistoryTracker implements FirestoreEventHisto
146149
if (viewExists) {
147150
logs.bigQueryViewAlreadyExists(view.id, dataset.id);
148151
} else {
149-
const latestSnapshot = latestConsistentSnapshotView(this.config.datasetId, this.rawChangeLogTableName());
152+
const latestSnapshot = latestConsistentSnapshotView(
153+
this.config.datasetId,
154+
this.rawChangeLogTableName()
155+
);
150156
logs.bigQueryViewCreating(this.rawLatestView(), latestSnapshot.query);
151157
const options = {
152158
friendlyName: this.rawLatestView(),
@@ -166,4 +172,3 @@ export class FirestoreBigQueryEventHistoryTracker implements FirestoreEventHisto
166172
return `${this.config.tableId}_raw_latest`;
167173
}
168174
}
169-

firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/schema.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,18 @@ const bigQueryField = (
4747

4848
// These field types form the basis of the `raw` data table
4949
export const dataField = bigQueryField("data", "STRING", "NULLABLE");
50-
export const documentNameField = bigQueryField("document_name", "STRING", "REQUIRED");
50+
export const documentNameField = bigQueryField(
51+
"document_name",
52+
"STRING",
53+
"REQUIRED"
54+
);
5155
export const eventIdField = bigQueryField("event_id", "STRING", "REQUIRED");
5256
export const operationField = bigQueryField("operation", "STRING", "REQUIRED");
53-
export const timestampField = bigQueryField("timestamp", "TIMESTAMP", "REQUIRED");
57+
export const timestampField = bigQueryField(
58+
"timestamp",
59+
"TIMESTAMP",
60+
"REQUIRED"
61+
);
5462

5563
// These field types are used for the Firestore GeoPoint data type
5664
export const latitudeField = bigQueryField("latitude", "NUMERIC");
@@ -74,5 +82,5 @@ export const firestoreToBQTable = (): BigQueryField[] => [
7482
eventIdField,
7583
documentNameField,
7684
operationField,
77-
dataField
85+
dataField,
7886
];

firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/snapshot.ts

+22-17
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,30 @@
1717
import * as sqlFormatter from "sql-formatter";
1818

1919
import * as logs from "../logs";
20-
import {
21-
firestoreToBQTable,
22-
timestampField,
23-
} from "./schema";
20+
import { firestoreToBQTable, timestampField } from "./schema";
2421

25-
const excludeFields: string[] = [
26-
"document_name",
27-
];
22+
const excludeFields: string[] = ["document_name"];
2823

2924
export const latestConsistentSnapshotView = (
3025
datasetId: string,
31-
tableName: string,
26+
tableName: string
3227
) => ({
33-
query: buildLatestSnapshotViewQuery(datasetId, tableName, timestampField.name,
28+
query: buildLatestSnapshotViewQuery(
29+
datasetId,
30+
tableName,
31+
timestampField.name,
3432
firestoreToBQTable()
35-
.map(field => field.name)
36-
.filter(name => excludeFields.indexOf(name) == -1)),
33+
.map((field) => field.name)
34+
.filter((name) => excludeFields.indexOf(name) == -1)
35+
),
3736
useLegacySql: false,
3837
});
3938

4039
export function buildLatestSnapshotViewQuery(
4140
datasetId: string,
4241
tableName: string,
4342
timestampColumnName: string,
44-
groupByColumns: string[],
43+
groupByColumns: string[]
4544
): string {
4645
if (datasetId === "" || tableName === "" || timestampColumnName === "") {
4746
throw Error(`Missing some query parameters!`);
@@ -58,23 +57,29 @@ export function buildLatestSnapshotViewQuery(
5857
-- event_id: The id of the event that triggered the cloud function mirrored the event.
5958
-- data: A raw JSON payload of the current state of the document.
6059
SELECT
61-
document_name${groupByColumns.length > 0 ? `,`: ``}
60+
document_name${groupByColumns.length > 0 ? `,` : ``}
6261
${groupByColumns.join(",")}
6362
FROM (
6463
SELECT
6564
document_name,
66-
${groupByColumns.map(columnName =>
67-
`FIRST_VALUE(${columnName})
65+
${groupByColumns
66+
.map(
67+
(columnName) =>
68+
`FIRST_VALUE(${columnName})
6869
OVER(PARTITION BY document_name ORDER BY ${timestampColumnName} DESC)
69-
AS ${columnName}`).join(',')}${groupByColumns.length > 0 ? `,`: ``}
70+
AS ${columnName}`
71+
)
72+
.join(",")}${groupByColumns.length > 0 ? `,` : ``}
7073
FIRST_VALUE(operation)
7174
OVER(PARTITION BY document_name ORDER BY ${timestampColumnName} DESC) = "DELETE"
7275
AS is_deleted
7376
FROM \`${process.env.PROJECT_ID}.${datasetId}.${tableName}\`
7477
ORDER BY document_name, ${timestampColumnName} DESC
7578
)
7679
WHERE NOT is_deleted
77-
GROUP BY document_name${groupByColumns.length > 0 ? `, `: ``}${groupByColumns.join(",")}`
80+
GROUP BY document_name${
81+
groupByColumns.length > 0 ? `, ` : ``
82+
}${groupByColumns.join(",")}`
7883
);
7984
return query;
8085
}

firestore-bigquery-export/firestore-bigquery-change-tracker/src/logs.ts

+19-9
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,25 @@ export const bigQueryDatasetExists = (datasetId: string) => {
3434

3535
export const bigQueryErrorRecordingDocumentChange = (e: Error) => {
3636
console.error(`Error recording document changes.`, e);
37-
}
37+
};
3838

3939
export const bigQueryLatestSnapshotViewQueryCreated = (query: string) => {
4040
console.log(`BigQuery latest snapshot view query:\n${query}`);
41-
}
41+
};
4242

4343
export const bigQuerySchemaViewCreated = (name: string) => {
4444
console.log(`BigQuery created schema view ${name}\n`);
45-
}
45+
};
4646

47-
export const bigQueryTableAlreadyExists = (tableName: string, datasetName: string) => {
48-
console.log(`BigQuery table with name ${tableName} already ` +
49-
`exists in dataset ${datasetName}!`);
50-
}
47+
export const bigQueryTableAlreadyExists = (
48+
tableName: string,
49+
datasetName: string
50+
) => {
51+
console.log(
52+
`BigQuery table with name ${tableName} already ` +
53+
`exists in dataset ${datasetName}!`
54+
);
55+
};
5156

5257
export const bigQueryTableCreated = (tableName: string) => {
5358
console.log(`Created BigQuery table: ${tableName}`);
@@ -93,8 +98,13 @@ export const bigQueryViewCreating = (viewName: string, query: string) => {
9398
console.log(`Creating BigQuery view: ${viewName}\nQuery:\n${query}`);
9499
};
95100

96-
export const bigQueryViewAlreadyExists = (viewName: string, datasetName: string) => {
97-
console.log(`View with id ${viewName} already exists in dataset ${datasetName}.`);
101+
export const bigQueryViewAlreadyExists = (
102+
viewName: string,
103+
datasetName: string
104+
) => {
105+
console.log(
106+
`View with id ${viewName} already exists in dataset ${datasetName}.`
107+
);
98108
};
99109

100110
export const bigQueryViewUpdated = (viewName: string) => {

0 commit comments

Comments
 (0)