-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFirestore.js
86 lines (81 loc) · 3.18 KB
/
Firestore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const { Firestore: CloudFirestore } = require("@google-cloud/firestore");
/**
* Create Firestore connection
*/
class Firestore {
/**
* @constructor
*/
constructor() {
this.connection;
}
/**
* Set firestore settings
* @param {Object} settings - Firestore settings
*
* @param {string} [settings.projectId] - The project ID from the Google Developer's Console, e.g.
* 'grape-spaceship-123'. We will also check the environment variable
* GCLOUD_PROJECT for your project ID. Can be omitted in environments that
* support {@link https://cloud.google.com/docs/authentication Application
* Default Credentials}
*
* @param {string} [settings.host] - The hostname to connect to
*
* @param {number} [settings.port] - The port to connect to
*
* @param {string} [settings.keyFilename] - Local file containing the Service Account credentials as downloaded from
* the Google Developers Console. Can be omitted in environments that
* support {@link https://cloud.google.com/docs/authentication Application
* Default Credentials}. To configure Firestore with custom credentials, use
* the `credentials` property to provide the `client_email` and
* `private_key` of your service account.
*
* @param {{client_email?: string; private_key?: string}} [settings.credentials] - The 'client_email' and 'private_key' properties of the service account
* to use with your Firestore project. Can be omitted in environments that
* support {@link https://cloud.google.com/docs/authentication Application
* Default Credentials}. If your credentials are stored in a JSON file, you
* can specify a `keyFilename` instead.
*
* @param {boolean} [settings.ssl] - Whether to use SSL when connecting
*
* @param {number} [settings.maxIdleChannels] - The maximum number of idle GRPC channels to keep. A smaller number of idle
* channels reduces memory usage but increases request latency for clients
* with fluctuating request rates. If set to 0, shuts down all GRPC channels
* when the client becomes idle. Defaults to 1.
*
* @param {boolean} [settings.useBigInt] - Whether to use `BigInt` for integer types when deserializing Firestore
* Documents. Regardless of magnitude, all integer values are returned as
* `BigInt` to match the precision of the Firestore backend. Floating point
* numbers continue to use JavaScript's `number` type.
*
* @param {boolean} [settings.ignoreUndefinedProperties] - Whether to skip nested properties that are set to `undefined` during
* object serialization. If set to `true`, these properties are skipped
* and not written to Firestore. If set `false` or omitted, the SDK throws
* an exception when it encounters properties of type `undefined`.
*/
setting(
settings = {
projectId,
host,
port,
keyFilename,
credentials,
ssl,
maxIdleChannels,
useBigInt,
ignoreUndefinedProperties,
}
) {
this.connection = new CloudFirestore(settings);
}
/**
* Get Firestore connection
*/
get conn() {
if (!this.connection) {
this.connection = new CloudFirestore();
}
return this.connection;
}
}
module.exports = new Firestore();