Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The `firebase_js_interop` package provides direct access to the Firebase JS SDKs

The process for adding new interop code is as follows:

1. Find the relevant code in the JS SDK
1. Find the relevant code in the [JS SDK](https://github.com/firebase/firebase-functions/tree/master/src)
2. Create any necessary intermediary folders in `firebase_js_interop`. Implementations live in `lib/src/{js_sdk}/**`.
3. Create a dart file with the same name as the typescript file, replacing `.ts` with `.dart`
4. Copy the license text from the typescript file to the dart file
Expand Down
5 changes: 5 additions & 0 deletions lib/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export 'src/functions/common/options.dart';
export 'src/functions/v2/providers/firestore.dart';
export 'src/functions/v2/providers/https.dart';
export 'src/functions/v2/providers/identity.dart';
export 'src/functions/v2/providers/scheduler.dart';
export 'src/functions/v2/core.dart';

/// Access to Firebase Functions components
Expand All @@ -22,4 +23,8 @@ abstract final class FirebaseFunctions {
/// Access to the Firebase Functions Identity methods
static FirebaseFunctionsIdentity get identity =>
require('firebase-functions/v2/identity') as FirebaseFunctionsIdentity;

/// Access to the Firebase Functions Schedule methods
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Access to the Firebase Functions Schedule methods
/// Access to the Firebase Functions Scheduler methods

static FirebaseFunctionsSchedule get schedule =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static FirebaseFunctionsSchedule get schedule =>
static FirebaseFunctionsScheduler get scheduler =>

require('firebase-functions/v2/scheduler') as FirebaseFunctionsSchedule;
}
100 changes: 100 additions & 0 deletions lib/src/functions/v2/providers/scheduler.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// The MIT License (MIT)
//
// Copyright (c) 2022 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.

import 'dart:js_interop';

export 'package:firebase_js_interop/src/functions/common/providers/https.dart';

/// Options that can be set on a schedule function.
extension type ScheduleOptions._(JSObject _) implements JSObject {
/// The schedule in Unix Crontab or AppEngine syntax.
external JSAny? get schedule;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
external JSAny? get schedule;
external String get schedule;


/// The timezone that the schedule executes in.
external JSAny? get timeZone;

/// The number of retry attempts for a failed run.
external JSAny? get retryCount;

/// The time limit for retrying.
external JSAny? get maxRetrySeconds;

/// The minimum time to wait before retrying.
external JSAny? get minBackoffSeconds;

/// The maximum time to wait before retrying.
external JSAny? get maxBackoffSeconds;

/// The time between retries will double maxDoublings times.
external JSAny? get maxDoublings;

/// Constructor
external ScheduleOptions({
JSAny? schedule,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
JSAny? schedule,
String schedule,

JSAny? timeZone,
JSAny? retryCount,
JSAny? maxRetrySeconds,
JSAny? minBackoffSeconds,
JSAny? maxBackoffSeconds,
JSAny? maxDoublings,
});
}

/// Event passed to a scheduled function handler.
extension type ScheduledEvent._(JSObject _) implements JSObject {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be above ScheduleOptions as it is in the source file

/// The Cloud Scheduler job name.
external String? get jobName;

/// The schedule time in RFC3339 UTC "Zulu" format.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc string does not match the source. All doc strings need checked for this since ChatGPT generated this.

external String get scheduleTime;

/// Constructor
external ScheduledEvent({
String? jobName,
String? scheduleTime,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
String? scheduleTime,
String scheduleTime,

});
}

/// The Cloud Function type for Schedule triggers.
extension type ScheduleFunction._(JSObject _) implements JSObject {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type declaration is unnecessary since Dart doesn't need to do anything with it

external JSObject get requiredAPIs;
external JSFunction run(ScheduledEvent event);

/// Constructor
external ScheduleFunction({
JSObject requiredAPIs,
JSFunction? run,
});
}

/// The Firebase Functions Schedule namespace
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The Firebase Functions Schedule namespace
/// The Firebase Functions Scheduler namespace

extension type FirebaseFunctionsSchedule._(JSObject _) implements JSObject {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
extension type FirebaseFunctionsSchedule._(JSObject _) implements JSObject {
extension type FirebaseFunctionsScheduler._(JSObject _) implements JSObject {

/// Handles scheduled function invocations.
/// @param options - Options to set on the schedule function
/// @param handler - A function to execute when triggered
/// @returns A function that you can export and deploy
external JSFunction onSchedule(
JSObject optionsOrSchedule, [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
JSObject optionsOrSchedule, [
JSAny args, [

JSObject does not include primitives

// (ScheduledEvent event) => FutureOr<void>
JSFunction handler,
]);
}
Loading