Skip to content

Commit 4babd29

Browse files
committed
Add new useEmulator method
1 parent d4176a1 commit 4babd29

File tree

3 files changed

+56
-40
lines changed

3 files changed

+56
-40
lines changed

common/api-review/functions-exp.api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function getFunctions(app: FirebaseApp, regionOrCustomDomain?: string): F
1616
export function httpsCallable(functionsInstance: Functions, name: string, options?: HttpsCallableOptions): HttpsCallable;
1717

1818
// @public
19-
export function useFunctionsEmulator(functionsInstance: Functions, origin: string): void;
19+
export function useFunctionsEmulator(functionsInstance: Functions, host: string, port: number): void;
2020

2121

2222
// (No @packageDocumentation comment for this package)

packages-exp/functions-compat/src/service.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import { FirebaseFunctions, HttpsCallable } from '@firebase/functions-types';
2424
import { HttpsCallableOptions, Functions } from '@firebase/functions-types-exp';
2525
import { FirebaseApp } from '@firebase/app-types';
26+
import { FirebaseError } from '@firebase/util';
2627

2728
export class FunctionsService implements FirebaseFunctions {
2829
private _functionsInstance: Functions;
@@ -45,7 +46,33 @@ export class FunctionsService implements FirebaseFunctions {
4546
httpsCallable(name: string, options?: HttpsCallableOptions): HttpsCallable {
4647
return httpsCallableExp(this._functionsInstance, name, options);
4748
}
49+
/**
50+
* Deprecated in pre-modularized repo, does not exist in modularized
51+
* functions package, need to convert to "host" and "port" args that
52+
* `useFunctionsEmulatorExp` takes.
53+
* @deprecated
54+
*/
4855
useFunctionsEmulator(origin: string): void {
49-
return useFunctionsEmulatorExp(this._functionsInstance, origin);
56+
const match = origin.match('[a-zA-Z]+://([a-zA-Z0-9.-]+)(?::([0-9]+))?');
57+
if (match == null) {
58+
throw new FirebaseError(
59+
'functions',
60+
'No origin provided to useFunctionsEmulator()'
61+
);
62+
}
63+
if (match[2] == null) {
64+
throw new FirebaseError(
65+
'functions',
66+
'Port missing in origin provided to useFunctionsEmulator()'
67+
);
68+
}
69+
return useFunctionsEmulatorExp(
70+
this._functionsInstance,
71+
match[1],
72+
Number(match[2])
73+
);
74+
}
75+
useEmulator(host: string, port: number): void {
76+
return useFunctionsEmulatorExp(this._functionsInstance, host, port);
5077
}
5178
}

yarn.lock

+27-38
Original file line numberDiff line numberDiff line change
@@ -1153,21 +1153,6 @@
11531153
unique-filename "^1.1.1"
11541154
which "^1.3.1"
11551155

1156-
"@firebase/[email protected]":
1157-
version "0.1.18"
1158-
resolved "https://registry.npmjs.org/@firebase/component/-/component-0.1.18.tgz#28e69e54b79953376283464cb0543bde4c104140"
1159-
integrity sha512-c8gd1k/e0sbBTR0xkLIYUN8nVkA0zWxcXGIvdfYtGEsNw6n7kh5HkcxKXOPB8S7bcPpqZkGgBIfvd94IyG2gaQ==
1160-
dependencies:
1161-
"@firebase/util" "0.3.1"
1162-
tslib "^1.11.1"
1163-
1164-
"@firebase/[email protected]":
1165-
version "0.3.1"
1166-
resolved "https://registry.npmjs.org/@firebase/util/-/util-0.3.1.tgz#8c95152a00121bd31fb7c1fc6520ca208976e384"
1167-
integrity sha512-zjVd9rfL08dRRdZILFn1RZTHb1euCcnD9N/9P56gdBcm2bvT5XsCC4G6t5toQBpE/H/jYe5h6MZMqfLu3EQLXw==
1168-
dependencies:
1169-
tslib "^1.11.1"
1170-
11711156
"@google-cloud/common@^3.3.0":
11721157
version "3.4.0"
11731158
resolved "https://registry.npmjs.org/@google-cloud/common/-/common-3.4.0.tgz#8951d0dc94c9dfd8af2b49ed125984dc71f1de6b"
@@ -9113,7 +9098,7 @@ is-stream-ended@^0.1.4:
91139098
resolved "https://registry.npmjs.org/is-stream-ended/-/is-stream-ended-0.1.4.tgz#f50224e95e06bce0e356d440a4827cd35b267eda"
91149099
integrity sha512-xj0XPvmr7bQFTvirqnFr50o0hQIh6ZItDqloxt5aJrR4NQsYeSsyFQERYGCAzfindAcnKjINnwEEgLx4IqVzQw==
91159100

9116-
is-stream@^1.0.0, is-stream@^1.0.1, is-stream@^1.1.0:
9101+
is-stream@^1.0.0, is-stream@^1.1.0:
91179102
version "1.1.0"
91189103
resolved "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
91199104
integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ=
@@ -9254,14 +9239,6 @@ isobject@^3.0.0, isobject@^3.0.1:
92549239
resolved "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
92559240
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=
92569241

9257-
9258-
version "2.2.1"
9259-
resolved "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
9260-
integrity sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=
9261-
dependencies:
9262-
node-fetch "^1.0.1"
9263-
whatwg-fetch ">=0.10.0"
9264-
92659242
isstream@~0.1.2:
92669243
version "0.1.2"
92679244
resolved "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
@@ -11283,14 +11260,6 @@ [email protected], node-fetch@^2.3.0, node-fetch@^2.5.0, node-fetch@^2.6.0, node-
1128311260
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
1128411261
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
1128511262

11286-
node-fetch@^1.0.1:
11287-
version "1.7.3"
11288-
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
11289-
integrity sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==
11290-
dependencies:
11291-
encoding "^0.1.11"
11292-
is-stream "^1.0.1"
11293-
1129411263
node-forge@^0.10.0:
1129511264
version "0.10.0"
1129611265
resolved "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz#32dea2afb3e9926f02ee5ce8794902691a676bf3"
@@ -13349,6 +13318,13 @@ [email protected]:
1334913318
dependencies:
1335013319
fs-extra "^5.0.0"
1335113320

13321+
13322+
version "4.0.0"
13323+
resolved "https://registry.npmjs.org/rollup-plugin-json/-/rollup-plugin-json-4.0.0.tgz#a18da0a4b30bf5ca1ee76ddb1422afbb84ae2b9e"
13324+
integrity sha512-hgb8N7Cgfw5SZAkb3jf0QXii6QX/FOkiIq2M7BAQIEydjHvTyxXHQiIzZaTFgx1GK0cRCHOCBHIyEkkLdWKxow==
13325+
dependencies:
13326+
rollup-pluginutils "^2.5.0"
13327+
1335213328
1335313329
version "2.2.0"
1335413330
resolved "https://registry.npmjs.org/rollup-plugin-license/-/rollup-plugin-license-2.2.0.tgz#0d19139bbe44dda500fbf15530af07c91949e348"
@@ -13390,6 +13366,17 @@ [email protected]:
1339013366
serialize-javascript "^4.0.0"
1339113367
terser "^5.0.0"
1339213368

13369+
13370+
version "0.27.2"
13371+
resolved "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.27.2.tgz#871a7f5d2a774f9cef50d25da868eec72acc2ed8"
13372+
integrity sha512-zarMH2F8oT/NO6p20gl/jkts+WxyzOlhOIUwUU/EDx5e6ewdDPS/flwLj5XFuijUCr64bZwqKuRVwCPdXXYefQ==
13373+
dependencies:
13374+
"@rollup/pluginutils" "^3.1.0"
13375+
find-cache-dir "^3.3.1"
13376+
fs-extra "8.1.0"
13377+
resolve "1.17.0"
13378+
tslib "2.0.1"
13379+
1339313380
1339413381
version "0.27.3"
1339513382
resolved "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.27.3.tgz#cd9455ac026d325b20c5728d2cc54a08a771b68b"
@@ -13411,13 +13398,20 @@ [email protected]:
1341113398
serialize-javascript "^2.1.2"
1341213399
uglify-js "^3.4.9"
1341313400

13414-
rollup-pluginutils@^2.6.0:
13401+
rollup-pluginutils@^2.5.0, rollup-pluginutils@^2.6.0:
1341513402
version "2.8.2"
1341613403
resolved "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e"
1341713404
integrity sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==
1341813405
dependencies:
1341913406
estree-walker "^0.6.1"
1342013407

13408+
13409+
version "2.26.7"
13410+
resolved "https://registry.npmjs.org/rollup/-/rollup-2.26.7.tgz#6188b38238cb198bef9f0d09f390c330ef766d27"
13411+
integrity sha512-3/aXJ+ibw2fqj6KBX4ioYcx8s3kseYXzyxLR6Xmm7Zakzd7WNvn9XDUahBCQ/oPVHmVO9gEeIYKHgFaZWqsJzg==
13412+
optionalDependencies:
13413+
fsevents "~2.1.2"
13414+
1342113415
1342213416
version "2.29.0"
1342313417
resolved "https://registry.npmjs.org/rollup/-/rollup-2.29.0.tgz#0c5c5968530b21ca0e32f8b94b7cd9346cfb0eec"
@@ -15878,11 +15872,6 @@ [email protected]:
1587815872
resolved "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f"
1587915873
integrity sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==
1588015874

15881-
whatwg-fetch@>=0.10.0:
15882-
version "3.4.1"
15883-
resolved "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.4.1.tgz#e5f871572d6879663fa5674c8f833f15a8425ab3"
15884-
integrity sha512-sofZVzE1wKwO+EYPbWfiwzaKovWiZXf4coEzjGP9b2GBVgQRLQUZ2QcuPpQExGDAW5GItpEm6Tl4OU5mywnAoQ==
15885-
1588615875
whatwg-mimetype@^2.3.0:
1588715876
version "2.3.0"
1588815877
resolved "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"

0 commit comments

Comments
 (0)