Skip to content

Commit

Permalink
Merge branch 'master' into dl-entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
taeold authored Aug 29, 2024
2 parents 934263c + 3a78784 commit 284da5d
Show file tree
Hide file tree
Showing 20 changed files with 378 additions and 152 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
- Future Extensions support (#1590)
- Fix retry in event triggered functions. (#1463)
- Expose retry configuration in v2 RTDB trigger (#1588)
- Fix CORS options for v2 callable functions (#1564)
- Remove invalid `enforceAppCheck` option for v2 onRequest trigger (#1477)
446 changes: 316 additions & 130 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebase-functions",
"version": "5.0.1",
"version": "5.1.0",
"description": "Firebase SDK for Cloud Functions",
"keywords": [
"firebase",
Expand Down
2 changes: 1 addition & 1 deletion scripts/publish-container/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14
FROM node:20

# Install dependencies
RUN apt-get update && \
Expand Down
34 changes: 34 additions & 0 deletions spec/v2/providers/database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,40 @@ describe("database", () => {
},
});
});

it("should supply retry", () => {
const func = database.onChangedOperation(
database.writtenEventType,
{
ref: "/foo/{path=**}/{bar}/",
instance: "my-instance",
region: "us-central1",
cpu: "gcf_gen1",
minInstances: 2,
retry: true,
},
() => 2
);

expect(func.__endpoint).to.deep.equal({
...MINIMAL_V2_ENDPOINT,
platform: "gcfv2",
cpu: "gcf_gen1",
minInstances: 2,
region: ["us-central1"],
labels: {},
eventTrigger: {
eventType: database.writtenEventType,
eventFilters: {
instance: "my-instance",
},
eventFilterPathPatterns: {
ref: "foo/{path=**}/{bar}",
},
retry: true,
},
});
});
});

describe("onOperation", () => {
Expand Down
11 changes: 7 additions & 4 deletions src/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ function removeCircular(obj: any, refs: any[] = []): any {
* @public
*/
export function write(entry: LogEntry) {
const ctx = traceContext.getStore();
if (ctx?.traceId) {
entry[
"logging.googleapis.com/trace"
] = `projects/${process.env.GCLOUD_PROJECT}/traces/${ctx.traceId}`;
}

UNPATCHED_CONSOLE[CONSOLE_SEVERITY[entry.severity]](JSON.stringify(removeCircular(entry)));
}

Expand Down Expand Up @@ -147,17 +154,13 @@ function entryFromArgs(severity: LogSeverity, args: any[]): LogEntry {
if (lastArg && typeof lastArg === "object" && lastArg.constructor === Object) {
entry = args.pop();
}
const ctx = traceContext.getStore();

// mimic `console.*` behavior, see https://nodejs.org/api/console.html#console_console_log_data_args
let message = format(...args);
if (severity === "ERROR" && !args.find((arg) => arg instanceof Error)) {
message = new Error(message).stack || message;
}
const out: LogEntry = {
"logging.googleapis.com/trace": ctx?.traceId
? `projects/${process.env.GCLOUD_PROJECT}/traces/${ctx.traceId}`
: undefined,
...entry,
severity,
};
Expand Down
3 changes: 1 addition & 2 deletions src/params/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ export const storageBucket: Param<string> = new InternalExpression(

/**
* Declares a secret param, that will persist values only in Cloud Secret Manager.
* Secrets are stored interally as bytestrings. Use `ParamOptions.as` to provide type
* Secrets are stored internally as bytestrings. Use `ParamOptions.as` to provide type
* hinting during parameter resolution.
*
* @param name The name of the environment variable to use to load the parameter.
* @param options Configuration options for the parameter.
* @returns A parameter with a `string` return type for `.value`.
*/
export function defineSecret(name: string): SecretParam {
Expand Down
2 changes: 1 addition & 1 deletion src/params/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ type ParamValueType = "string" | "list" | "boolean" | "int" | "float" | "secret"
/** Create a select input from a series of values. */
export function select<T>(options: T[]): SelectInput<T>;

/** Create a select input from a map of labels to vaues. */
/** Create a select input from a map of labels to values. */
export function select<T>(optionsWithLabels: Record<string, T>): SelectInput<T>;

/** Create a select input from a series of values or a map of labels to values */
Expand Down
2 changes: 1 addition & 1 deletion src/v1/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function resetCache(): void {
* Store and retrieve project configuration data such as third-party API
* keys or other settings. You can set configuration values using the
* Firebase CLI as described in
* [Environment Configuration](/docs/functions/config-env).
* https://firebase.google.com/docs/functions/config-env.
*/
export function config(): Record<string, any> {
// K_CONFIGURATION is only set in GCFv2
Expand Down
2 changes: 1 addition & 1 deletion src/v2/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export interface GlobalOptions {
* The minimum timeout for a 2nd gen function is 1s. The maximum timeout for a
* function depends on the type of function: Event handling functions have a
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
* maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
* maximum timeout of 3,600s (1 hour). Task queue functions have a maximum
* timeout of 1,800s (30 minutes).
*/
timeoutSeconds?: number | Expression<number> | ResetValue;
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/alerts/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export function getEndpointAnnotation(
eventFilters: {
alerttype: alertType,
},
retry: !!opts.retry,
retry: opts.retry ?? false,
},
};
if (appId) {
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export function makeEndpoint(
eventType,
eventFilters,
eventFilterPathPatterns,
retry: false,
retry: opts.retry ?? false,
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/eventarc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export function onCustomEventPublished<T = any>(
eventTrigger: {
eventType: opts.eventType,
eventFilters: {},
retry: false,
retry: opts.retry ?? false,
channel,
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ export function makeEndpoint(
eventType,
eventFilters,
eventFilterPathPatterns,
retry: !!opts.retry,
retry: opts.retry ?? false,
},
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/v2/providers/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export { Request, CallableRequest, FunctionsErrorCode, HttpsError };
/**
* Options that can be set on an onRequest HTTPS function.
*/
export interface HttpsOptions extends Omit<GlobalOptions, "region"> {
export interface HttpsOptions extends Omit<GlobalOptions, "region" | "enforceAppCheck"> {
/**
* If true, do not deploy or emulate this function.
*/
Expand Down Expand Up @@ -375,7 +375,7 @@ export function onCall<T = any, Return = any | Promise<any>>(
// on the origin header of the request. If there is only one element in the
// array, this is unnecessary.
if (Array.isArray(origin) && origin.length === 1) {
origin = origin[1];
origin = origin[0];
}

// onCallHandler sniffs the function length to determine which API to present.
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export function onMessagePublished<T = any>(
eventTrigger: {
eventType: "google.cloud.pubsub.topic.v1.messagePublished",
eventFilters: { topic },
retry: false,
retry: opts.retry ?? false,
},
};
copyIfPresent(endpoint.eventTrigger, opts, "retry", "retry");
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/remoteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function onConfigUpdated(
eventTrigger: {
eventType,
eventFilters: {},
retry: !!optsOrHandler.retry,
retry: optsOrHandler.retry ?? false,
},
};
func.__endpoint = ep;
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ export function onOperation(
eventTrigger: {
eventType,
eventFilters: { bucket },
retry: false,
retry: opts.retry ?? false,
},
};
copyIfPresent(endpoint.eventTrigger, opts, "retry", "retry");
Expand Down
1 change: 1 addition & 0 deletions src/v2/providers/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export function onTaskDispatched<Args = any>(
convertInvoker
);
convertIfPresent(func.__endpoint.taskQueueTrigger, opts, "invoker", "invoker", convertInvoker);
copyIfPresent(func.__endpoint.taskQueueTrigger, opts, "retry", "retry");

func.__requiredAPIs = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/testLab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export function onTestMatrixCompleted(
eventTrigger: {
eventType,
eventFilters: {},
retry: !!optsOrHandler.retry,
retry: optsOrHandler.retry ?? false,
},
};
func.__endpoint = ep;
Expand Down

0 comments on commit 284da5d

Please sign in to comment.