Skip to content

Commit

Permalink
Create package exports (#906)
Browse files Browse the repository at this point in the history
* Create version packages

* Changelog

* Make exports list always use explicit file names
  • Loading branch information
inlined authored Jul 8, 2021
1 parent 4028acc commit 33a68ea
Show file tree
Hide file tree
Showing 40 changed files with 118 additions and 104 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Adds support for setting user labels on functions via `runWith()`.
- Adds support for FIREBASE_CONFIG env as the name of a JSON file
- Formalize module exports. Loggers can now be accessed at 'firebase-functions/logger' and 'firebase-functions/logger/compat'
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"exports": {
".": "./lib/index.js",
"./v1": "./lib/v1/index.js",
"./logger": "./lib/logger/index.js",
"./logger/compat": "./lib/logger/compat.js",
"./lib/logger": "./lib/logger/index.js",
"./lib/logger/compat": "./lib/logger/compat.js"
},
"publishConfig": {
"registry": "https://wombat-dressing-room.appspot.com"
},
Expand Down
2 changes: 1 addition & 1 deletion spec/apps.spec.ts → spec/v1/apps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// SOFTWARE.

import { expect } from 'chai';
import { apps as appsNamespace } from '../src/apps';
import { apps as appsNamespace } from '../../src/v1/apps';

import * as firebase from 'firebase-admin';
import * as _ from 'lodash';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
EventContext,
makeCloudFunction,
MakeCloudFunctionArgs,
} from '../src/cloud-functions';
} from '../../src/v1/cloud-functions';

describe('makeCloudFunction', () => {
const cloudFunctionArgs: MakeCloudFunctionArgs<any> = {
Expand Down
2 changes: 1 addition & 1 deletion spec/config.spec.ts → spec/v1/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as fs from 'fs';
import * as mockRequire from 'mock-require';
import Sinon = require('sinon');

import * as config from '../src/config';
import * as config from '../../src/v1/config';

describe('config()', () => {
let readFileSync: Sinon.SinonStub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import { expect } from 'chai';

import * as functions from '../src/index';
import * as functions from '../../src/v1';

describe('FunctionBuilder', () => {
before(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// SOFTWARE.

/* tslint:disable:max-line-length */
import { AnalyticsEvent } from '../../src/providers/analytics';
import { AnalyticsEvent } from '../../../src/v1/providers/analytics';

// A payload, as it might arrive over the wire. Every possible field is filled out at least once.
export const fullPayload = JSON.parse(`{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

import { expect } from 'chai';

import { Event, EventContext } from '../../src/cloud-functions';
import * as functions from '../../src/index';
import * as analytics from '../../src/providers/analytics';
import * as functions from '../../../src/v1';
import { Event, EventContext } from '../../../src/v1/cloud-functions';
import * as analytics from '../../../src/v1/providers/analytics';
import * as analytics_spec_input from './analytics.spec.input';

describe('Analytics Functions', () => {
Expand Down
10 changes: 7 additions & 3 deletions spec/providers/auth.spec.ts → spec/v1/providers/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
import { expect } from 'chai';
import * as firebase from 'firebase-admin';

import { CloudFunction, Event, EventContext } from '../../src/cloud-functions';
import * as functions from '../../src/index';
import * as auth from '../../src/providers/auth';
import * as functions from '../../../src/index';
import {
CloudFunction,
Event,
EventContext,
} from '../../../src/v1/cloud-functions';
import * as auth from '../../../src/v1/providers/auth';

describe('Auth Functions', () => {
const event: Event = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
// SOFTWARE.

import { expect } from 'chai';
import { apps as appsNamespace } from '../../src/apps';
import * as config from '../../src/config';
import * as functions from '../../src/index';
import * as database from '../../src/providers/database';
import { applyChange } from '../../src/utils';
import { apps as appsNamespace } from '../../../src/v1/apps';
import * as config from '../../../src/v1/config';
import * as functions from '../../../src/v1/index';
import * as database from '../../../src/v1/providers/database';
import { applyChange } from '../../../src/v1/utils';

describe('Database Functions', () => {
describe('DatabaseBuilder', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import { expect } from 'chai';
import * as admin from 'firebase-admin';
import * as _ from 'lodash';

import * as functions from '../../src/index';
import * as firestore from '../../src/providers/firestore';
import * as functions from '../../../src/index';
import * as firestore from '../../../src/v1/providers/firestore';

describe('Firestore Functions', () => {
function constructValue(fields: any) {
Expand Down
10 changes: 5 additions & 5 deletions spec/providers/https.spec.ts → spec/v1/providers/https.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import { expect } from 'chai';
import * as express from 'express';
import * as firebase from 'firebase-admin';
import * as _ from 'lodash';
import { apps as appsNamespace } from '../../src/apps';
import * as functions from '../../src/index';
import * as https from '../../src/providers/https';
import * as mocks from '../fixtures/credential/key.json';
import * as functions from '../../../src/index';
import { apps as appsNamespace } from '../../../src/v1/apps';
import * as https from '../../../src/v1/providers/https';
import * as mocks from '../../fixtures/credential/key.json';
import {
expectedResponseHeaders,
generateAppCheckToken,
Expand All @@ -36,7 +36,7 @@ import {
mockFetchPublicKeys,
MockRequest,
mockRequest,
} from '../fixtures/mockrequest';
} from '../../fixtures/mockrequest';

describe('CloudHttpsBuilder', () => {
describe('#onRequest', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
// SOFTWARE.

import { expect } from 'chai';
import { Event } from '../../src/index';
import * as functions from '../../src/index';
import * as pubsub from '../../src/providers/pubsub';
import { Event } from '../../../src/index';
import * as functions from '../../../src/index';
import * as pubsub from '../../../src/v1/providers/pubsub';

describe('Pubsub Functions', () => {
describe('pubsub.Message', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import { expect } from 'chai';
import * as _ from 'lodash';

import * as functions from '../../../src/index';
import {
CloudFunction,
Event,
EventContext,
TriggerAnnotated,
} from '../../src/cloud-functions';
import * as functions from '../../src/index';
import * as remoteConfig from '../../src/providers/remoteConfig';
} from '../../../src/v1/cloud-functions';
import * as remoteConfig from '../../../src/v1/providers/remoteConfig';

describe('RemoteConfig Functions', () => {
function constructVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
// SOFTWARE.

import { expect } from 'chai';
import * as config from '../../src/config';
import { Event, EventContext } from '../../src/index';
import * as functions from '../../src/index';
import * as storage from '../../src/providers/storage';
import { Event, EventContext } from '../../../src/v1';
import * as functions from '../../../src/v1';
import * as config from '../../../src/v1/config';
import * as storage from '../../../src/v1/providers/storage';

describe('Storage Functions', () => {
describe('ObjectBuilder', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import { expect } from 'chai';

import * as testLab from '../../src/providers/testLab';
import * as testLab from '../../../src/v1/providers/testLab';

describe('Test Lab Functions', () => {
describe('#onComplete', () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/setup.spec.ts → spec/v1/setup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// SOFTWARE.

import { expect } from 'chai';
import { setup } from '../src/setup';
import { setup } from '../../src/v1/setup';

describe('setup()', () => {
afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion spec/utils.spec.ts → spec/v1/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// SOFTWARE.

import { expect } from 'chai';
import { applyChange } from '../src/utils';
import { applyChange } from '../../src/v1/utils';

describe('utils', () => {
describe('.applyChange(from: any, to: any): any', () => {
Expand Down
63 changes: 1 addition & 62 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1 @@
// The MIT License (MIT)
//
// Copyright (c) 2017 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

// Providers:
import * as analytics from './providers/analytics';
import * as auth from './providers/auth';
import * as database from './providers/database';
import * as firestore from './providers/firestore';
import * as https from './providers/https';
import * as pubsub from './providers/pubsub';
import * as remoteConfig from './providers/remoteConfig';
import * as storage from './providers/storage';
import * as testLab from './providers/testLab';

import * as apps from './apps';
import { handler } from './handler-builder';
import * as logger from './logger';
import { setup } from './setup';

const app = apps.apps();

export {
analytics,
app,
auth,
database,
firestore,
handler,
https,
pubsub,
remoteConfig,
storage,
testLab,
logger,
};

// Exported root types:
export * from './cloud-functions';
export * from './config';
export * from './function-builder';
export * from './function-configuration';

setup();
export * from './v1';
2 changes: 1 addition & 1 deletion src/logger.ts → src/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CONSOLE_SEVERITY,
SUPPORTS_STRUCTURED_LOGS,
UNPATCHED_CONSOLE,
} from './logger/common';
} from './common';

/**
* `LogSeverity` indicates the detailed severity of the log entry. See [LogSeverity](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity).
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/cloud-functions.ts → src/v1/cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

import { Request, Response } from 'express';
import * as _ from 'lodash';
import { warn } from '../logger';
import {
DEFAULT_FAILURE_POLICY,
DeploymentOptions,
FailurePolicy,
Schedule,
} from './function-configuration';
import { warn } from './logger';
export { Request, Response };

/** @hidden */
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
62 changes: 62 additions & 0 deletions src/v1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// The MIT License (MIT)
//
// Copyright (c) 2017 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

// Providers:
import * as analytics from './providers/analytics';
import * as auth from './providers/auth';
import * as database from './providers/database';
import * as firestore from './providers/firestore';
import * as https from './providers/https';
import * as pubsub from './providers/pubsub';
import * as remoteConfig from './providers/remoteConfig';
import * as storage from './providers/storage';
import * as testLab from './providers/testLab';

import * as logger from '../logger';
import * as apps from './apps';
import { handler } from './handler-builder';
import { setup } from './setup';

const app = apps.apps();

export {
analytics,
app,
auth,
database,
firestore,
handler,
https,
pubsub,
remoteConfig,
storage,
testLab,
logger,
};

// Exported root types:
export * from './cloud-functions';
export * from './config';
export * from './function-builder';
export * from './function-configuration';

setup();
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/providers/database.ts → src/v1/providers/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import * as firebase from 'firebase-admin';
import * as _ from 'lodash';
import { joinPath, normalizePath, pathParts } from '../../utilities/path';
import { apps } from '../apps';
import {
Change,
Expand All @@ -32,7 +33,6 @@ import {
} from '../cloud-functions';
import { firebaseConfig } from '../config';
import { DeploymentOptions } from '../function-configuration';
import { joinPath, normalizePath, pathParts } from '../utilities/path';
import { applyChange } from '../utils';

/** @hidden */
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/providers/https.ts → src/v1/providers/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import * as express from 'express';
import * as firebase from 'firebase-admin';
import * as _ from 'lodash';

import { error, info, warn } from '../../logger';
import { apps } from '../apps';
import { HttpsFunction, optionsToTrigger, Runnable } from '../cloud-functions';
import { DeploymentOptions } from '../function-configuration';
import { error, info, warn } from '../logger';

/** @hidden */
export interface Request extends express.Request {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 33a68ea

Please sign in to comment.