Skip to content

Commit 5891029

Browse files
committed
Rough implementation
1 parent f30de15 commit 5891029

24 files changed

+1764
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## API Report File for "@firebase/functions-exp"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
import { FirebaseApp } from '@firebase/app-types-exp';
8+
import { FirebaseFunctions } from '@firebase/functions-types-exp';
9+
import { HttpsCallable } from '@firebase/functions-types-exp';
10+
import { HttpsCallableOptions } from '@firebase/functions-types-exp';
11+
12+
// @public
13+
export function getFunctions(app: FirebaseApp, region?: string): FirebaseFunctions;
14+
15+
// @public
16+
export function httpsCallable(functionsInstance: FirebaseFunctions, name: string, options?: HttpsCallableOptions): HttpsCallable;
17+
18+
// @public
19+
export function useFunctionsEmulator(functionsInstance: FirebaseFunctions, origin: string): void;
20+
21+
22+
// (No @packageDocumentation comment for this package)
23+
24+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
extends: '../../config/.eslintrc.js',
3+
parserOptions: {
4+
project: 'tsconfig.json',
5+
// to make vscode-eslint work with monorepo
6+
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
7+
tsconfigRootDir: __dirname
8+
}
9+
};

packages-exp/functions-exp/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# `@firebase/functions`
2+
3+
This is the Firebase Functions component of the Firebase JS SDK.
4+
5+
**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../../config/api-extractor.json",
3+
// Point it to your entry point d.ts file.
4+
"mainEntryPointFilePath": "<projectFolder>/dist/src/index.d.ts",
5+
"dtsRollup": {
6+
"enabled": true,
7+
"untrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>.d.ts",
8+
"publicTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-public.d.ts"
9+
}
10+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @license
3+
* Copyright 2017 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
const karmaBase = require('../../config/karma.base');
19+
20+
const files = [`src/**/*.test.ts`];
21+
22+
module.exports = function(config) {
23+
const karmaConfig = Object.assign({}, karmaBase, {
24+
// files to load into karma
25+
files,
26+
// frameworks to use
27+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
28+
frameworks: ['mocha']
29+
});
30+
31+
config.set(karmaConfig);
32+
};
33+
34+
module.exports.files = files;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "@firebase/functions-exp",
3+
"version": "0.0.800",
4+
"description": "",
5+
"private": true,
6+
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
7+
"main": "dist/index.node.cjs.js",
8+
"browser": "dist/index.cjs.js",
9+
"module": "dist/index.esm.js",
10+
"esm2017": "dist/index.esm2017.js",
11+
"files": [
12+
"dist"
13+
],
14+
"scripts": {
15+
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
16+
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
17+
"build": "rollup -c",
18+
"build:deps": "lerna run --scope @firebase/'{app,functions}' --include-dependencies build",
19+
"dev": "rollup -c -w",
20+
"test": "yarn type-check && run-p lint test:browser test:node",
21+
"test:ci": "node ../../scripts/run_tests_in_ci.js",
22+
"type-check": "tsc -p . --noEmit",
23+
"test:browser": "karma start --single-run",
24+
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
25+
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'src/{,!(browser)/**/}*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js",
26+
"test:emulator": "env FIREBASE_FUNCTIONS_EMULATOR_ORIGIN=http://localhost:5005 run-p test:node",
27+
"prepare": "yarn build",
28+
"api-report": "api-extractor run --local --verbose",
29+
"predoc": "node ../../scripts/exp/remove-exp.js temp",
30+
"doc": "api-documenter markdown --input temp --output docs",
31+
"build:doc": "yarn build && yarn doc"
32+
},
33+
"license": "Apache-2.0",
34+
"peerDependencies": {
35+
"@firebase/app-exp": "0.x",
36+
"@firebase/app-exp-types": "0.x"
37+
},
38+
"devDependencies": {
39+
"@firebase/messaging": "0.6.14",
40+
"rollup": "2.7.6",
41+
"rollup-plugin-typescript2": "0.27.0",
42+
"typescript": "3.8.3"
43+
},
44+
"repository": {
45+
"directory": "packages/functions",
46+
"type": "git",
47+
"url": "https://github.com/firebase/firebase-js-sdk.git"
48+
},
49+
"bugs": {
50+
"url": "https://github.com/firebase/firebase-js-sdk/issues"
51+
},
52+
"typings": "dist/index.d.ts",
53+
"dependencies": {
54+
"@firebase/component": "0.1.10",
55+
"@firebase/functions-types": "0.3.16",
56+
"@firebase/messaging-types": "0.4.4",
57+
"isomorphic-fetch": "2.2.1",
58+
"tslib": "1.11.1"
59+
},
60+
"nyc": {
61+
"extension": [
62+
".ts"
63+
],
64+
"reportDir": "./coverage/node"
65+
}
66+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* @license
3+
* Copyright 2018 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import json from 'rollup-plugin-json';
19+
import typescriptPlugin from 'rollup-plugin-typescript2';
20+
import typescript from 'typescript';
21+
import pkg from './package.json';
22+
23+
const deps = Object.keys(
24+
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
25+
);
26+
27+
/**
28+
* ES5 Builds
29+
*/
30+
const es5BuildPlugins = [
31+
typescriptPlugin({
32+
typescript
33+
}),
34+
json()
35+
];
36+
37+
const es5Builds = [
38+
/**
39+
* Browser Builds
40+
*/
41+
{
42+
input: 'src/index.ts',
43+
output: [
44+
{ file: pkg.browser, format: 'cjs', sourcemap: true },
45+
{ file: pkg.module, format: 'es', sourcemap: true }
46+
],
47+
plugins: es5BuildPlugins,
48+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
49+
},
50+
/**
51+
* Node.js Build
52+
*/
53+
{
54+
input: 'src/index.node.ts',
55+
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
56+
plugins: es5BuildPlugins,
57+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
58+
}
59+
];
60+
61+
const es2017BuildPlugins = [
62+
typescriptPlugin({
63+
typescript,
64+
tsconfigOverride: {
65+
compilerOptions: {
66+
target: 'es2017'
67+
}
68+
}
69+
}),
70+
json({ preferConst: true })
71+
];
72+
73+
/**
74+
* ES2017 Builds
75+
*/
76+
const es2017Builds = [
77+
{
78+
/**
79+
* Browser Build
80+
*/
81+
input: 'src/index.ts',
82+
output: {
83+
file: pkg.esm2017,
84+
format: 'es',
85+
sourcemap: true
86+
},
87+
plugins: es2017BuildPlugins,
88+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
89+
}
90+
];
91+
92+
export default [...es5Builds, ...es2017Builds];

packages-exp/functions-exp/src/api.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { _registerComponent, _getProvider } from '@firebase/app-exp';
2+
import { FirebaseApp, _FirebaseAppInternal } from '@firebase/app-types-exp';
3+
import { _FirebaseNamespace } from '@firebase/app-types/private';
4+
import {
5+
FirebaseFunctions,
6+
HttpsCallable,
7+
HttpsCallableOptions
8+
} from '@firebase/functions-types-exp';
9+
import { FUNCTIONS_TYPE } from './config';
10+
11+
import { Service } from './service';
12+
import { Provider } from '@firebase/component';
13+
14+
/**
15+
* Returns a Functions instance for the given app.
16+
* @param app - The FirebaseApp to use.
17+
* @param region - The region to call functions in.
18+
* @public
19+
*/
20+
export function getFunctions(
21+
app: FirebaseApp,
22+
region?: string
23+
): FirebaseFunctions {
24+
// Dependencies
25+
const functionsProvider: Provider<'functions'> = _getProvider(
26+
app,
27+
FUNCTIONS_TYPE
28+
);
29+
const functionsInstance = functionsProvider.getImmediate();
30+
if (region) {
31+
(functionsInstance as Service).setRegion(region);
32+
}
33+
return functionsInstance;
34+
}
35+
36+
/**
37+
* Changes this instance to point to a Cloud Functions emulator running
38+
* locally. See https://firebase.google.com/docs/functions/local-emulator
39+
*
40+
* @param origin - The origin of the local emulator, such as
41+
* "http://localhost:5005".
42+
* @public
43+
*/
44+
export function useFunctionsEmulator(
45+
functionsInstance: FirebaseFunctions,
46+
origin: string
47+
): void {
48+
return functionsInstance.useFunctionsEmulator(origin);
49+
}
50+
51+
/**
52+
* Returns a reference to the callable https trigger with the given name.
53+
* @param name - The name of the trigger.
54+
* @public
55+
*/
56+
export function httpsCallable(
57+
functionsInstance: FirebaseFunctions,
58+
name: string,
59+
options?: HttpsCallableOptions
60+
): HttpsCallable {
61+
return functionsInstance.httpsCallable(name, options);
62+
}

0 commit comments

Comments
 (0)