├── README.md ├── .gitignore ├── examples ├── fullstack │ ├── frontend │ │ ├── linux │ │ │ ├── .gitignore │ │ │ ├── main.cc │ │ │ ├── flutter │ │ │ │ ├── generated_plugin_registrant.cc │ │ │ │ ├── generated_plugin_registrant.h │ │ │ │ └── generated_plugins.cmake │ │ │ └── my_application.h │ │ ├── assets │ │ │ └── config │ │ │ │ └── dev.json │ │ ├── macos │ │ │ ├── Flutter │ │ │ │ ├── Flutter-Debug.xcconfig │ │ │ │ ├── Flutter-Release.xcconfig │ │ │ │ └── GeneratedPluginRegistrant.swift │ │ │ ├── Runner │ │ │ │ ├── Configs │ │ │ │ │ ├── Debug.xcconfig │ │ │ │ │ ├── Release.xcconfig │ │ │ │ │ ├── Warnings.xcconfig │ │ │ │ │ └── AppInfo.xcconfig │ │ │ │ ├── Assets.xcassets │ │ │ │ │ └── AppIcon.appiconset │ │ │ │ │ │ ├── app_icon_16.png │ │ │ │ │ │ ├── app_icon_32.png │ │ │ │ │ │ ├── app_icon_64.png │ │ │ │ │ │ ├── app_icon_1024.png │ │ │ │ │ │ ├── app_icon_128.png │ │ │ │ │ │ ├── app_icon_256.png │ │ │ │ │ │ ├── app_icon_512.png │ │ │ │ │ │ └── Contents.json │ │ │ │ ├── AppDelegate.swift │ │ │ │ ├── Release.entitlements │ │ │ │ ├── MainFlutterWindow.swift │ │ │ │ ├── DebugProfile.entitlements │ │ │ │ └── Info.plist │ │ │ ├── .gitignore │ │ │ ├── Runner.xcworkspace │ │ │ │ ├── contents.xcworkspacedata │ │ │ │ └── xcshareddata │ │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ └── Runner.xcodeproj │ │ │ │ └── project.xcworkspace │ │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ ├── web │ │ │ ├── favicon.png │ │ │ ├── icons │ │ │ │ ├── Icon-192.png │ │ │ │ └── Icon-512.png │ │ │ └── manifest.json │ │ ├── windows │ │ │ ├── runner │ │ │ │ ├── resources │ │ │ │ │ └── app_icon.ico │ │ │ │ ├── resource.h │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── utils.h │ │ │ │ ├── runner.exe.manifest │ │ │ │ ├── run_loop.h │ │ │ │ ├── flutter_window.h │ │ │ │ ├── main.cpp │ │ │ │ └── utils.cpp │ │ │ ├── flutter │ │ │ │ ├── generated_plugin_registrant.cc │ │ │ │ ├── generated_plugin_registrant.h │ │ │ │ └── generated_plugins.cmake │ │ │ └── .gitignore │ │ ├── mono_pkg.yaml │ │ ├── pubspec.yaml │ │ ├── test │ │ │ └── widget_test.dart │ │ ├── lib │ │ │ ├── views │ │ │ │ └── history_page.dart │ │ │ ├── services │ │ │ │ ├── api_types.g.dart │ │ │ │ ├── api_types.dart │ │ │ │ └── api.dart │ │ │ ├── config.dart │ │ │ ├── main.dart │ │ │ └── models │ │ │ │ └── app_model.dart │ │ └── .gitignore │ ├── backend │ │ ├── .dockerignore │ │ ├── mono_pkg.yaml │ │ ├── .gitignore │ │ ├── pubspec.yaml │ │ ├── Makefile │ │ ├── Dockerfile │ │ ├── lib │ │ │ ├── api_types.g.dart │ │ │ ├── api_types.dart │ │ │ └── functions.dart │ │ ├── test │ │ │ └── function_test.dart │ │ └── bin │ │ │ └── server.dart │ ├── images │ │ └── flutter_demo.png │ └── frontend-cli │ │ ├── mono_pkg.yaml │ │ ├── .gitignore │ │ ├── pubspec.yaml │ │ ├── README.md │ │ └── lib │ │ ├── api_types.g.dart │ │ └── api_types.dart ├── hello │ ├── .dockerignore │ ├── mono_pkg.yaml │ ├── .gitignore │ ├── Makefile │ ├── pubspec.yaml │ ├── Dockerfile │ ├── lib │ │ └── functions.dart │ ├── bin │ │ └── server.dart │ └── test │ │ └── function_test.dart ├── json │ ├── .dockerignore │ ├── mono_pkg.yaml │ ├── .gitignore │ ├── pubspec.yaml │ ├── Makefile │ ├── Dockerfile │ ├── lib │ │ └── functions.g.dart │ └── bin │ │ └── server.dart ├── raw_cloudevent │ ├── .dockerignore │ ├── mono_pkg.yaml │ ├── .gitignore │ ├── pubspec.yaml │ ├── sample │ │ └── data.json │ ├── Dockerfile │ ├── lib │ │ └── functions.dart │ ├── bin │ │ └── server.dart │ └── tool │ │ ├── binary_mode_request.dart │ │ └── structured_mode_request.dart └── protobuf_firestore │ ├── .dockerignore │ ├── lib │ ├── src │ │ ├── function_types.dart │ │ └── google │ │ │ ├── analysis_options.yaml │ │ │ ├── type │ │ │ ├── latlng.pbenum.dart │ │ │ ├── latlng.pbserver.dart │ │ │ └── latlng.pbjson.dart │ │ │ ├── protobuf │ │ │ ├── timestamp.pbenum.dart │ │ │ ├── struct.pbserver.dart │ │ │ ├── timestamp.pbserver.dart │ │ │ ├── timestamp.pbjson.dart │ │ │ └── struct.pbenum.dart │ │ │ └── events │ │ │ └── cloud │ │ │ └── firestore │ │ │ └── v1 │ │ │ ├── data.pbenum.dart │ │ │ ├── events.pbenum.dart │ │ │ ├── data.pbserver.dart │ │ │ └── events.pbserver.dart │ └── functions.dart │ ├── mono_pkg.yaml │ ├── .gitignore │ ├── test │ ├── decode_test.dart │ └── test_shared.dart │ ├── pubspec.yaml │ ├── sample │ └── data.json │ ├── tool │ └── regenerate_protos.sh │ ├── Dockerfile │ └── bin │ └── server.dart ├── dartfn ├── dart_test.yaml ├── lib │ ├── src │ │ ├── version.dart │ │ ├── generators │ │ │ ├── json.dart │ │ │ ├── helloworld.dart │ │ │ └── cloudevent.dart │ │ ├── generators.dart │ │ ├── printer.dart │ │ └── cli │ │ │ ├── http_utils.dart │ │ │ ├── console.dart │ │ │ ├── terminal.dart │ │ │ └── command.dart │ └── functions_framework_tool.dart ├── templates │ ├── json │ │ ├── .dockerignore │ │ ├── .gitignore │ │ ├── mono_pkg.yaml │ │ ├── Makefile │ │ ├── pubspec.yaml │ │ ├── analysis_options.yaml │ │ ├── Dockerfile │ │ ├── lib │ │ │ └── functions.g.dart │ │ ├── test │ │ │ └── function_test.dart │ │ └── bin │ │ │ └── server.dart │ ├── cloudevent │ │ ├── .dockerignore │ │ ├── .gitignore │ │ ├── mono_pkg.yaml │ │ ├── Makefile │ │ ├── pubspec.yaml │ │ ├── lib │ │ │ └── functions.dart │ │ ├── sample │ │ │ └── data.json │ │ ├── analysis_options.yaml │ │ ├── Dockerfile │ │ ├── tool │ │ │ ├── binary_mode_request.dart │ │ │ └── structured_mode_request.dart │ │ ├── bin │ │ │ └── server.dart │ │ └── test │ │ │ └── src │ │ │ └── test_utils.dart │ └── helloworld │ │ ├── .dockerignore │ │ ├── .gitignore │ │ ├── lib │ │ └── functions.dart │ │ ├── mono_pkg.yaml │ │ ├── Makefile │ │ ├── pubspec.yaml │ │ ├── analysis_options.yaml │ │ ├── Dockerfile │ │ ├── test │ │ └── function_test.dart │ │ └── bin │ │ └── server.dart ├── .gitignore ├── analysis_options.yaml ├── mono_pkg.yaml ├── build.yaml ├── pubspec.yaml ├── tool │ ├── builder │ │ └── builder.dart │ └── bashcmds ├── test │ ├── ensure_build_test.dart │ ├── generators_test.dart │ └── mock_test.dart ├── CHANGELOG.md └── bin │ └── dartfn.dart ├── functions_framework ├── dart_test.yaml ├── example │ └── readme.md ├── build.yaml ├── mono_pkg.yaml ├── .gitignore ├── pubspec.yaml ├── test │ └── ensure_build_test.dart └── lib │ ├── src │ ├── cloud_function.dart │ ├── targets │ │ └── http_targets.dart │ ├── function_target.dart │ ├── run.dart │ ├── request_context.dart │ └── cloud_event.dart │ └── functions_framework.dart ├── integration_test ├── dart_test.yaml ├── .gitignore ├── mono_pkg.yaml ├── pubspec.yaml ├── lib │ └── src │ │ ├── utils.dart │ │ ├── pub_sub_types.g.dart │ │ ├── json_handlers.dart │ │ ├── pub_sub_types.dart │ │ └── conformance_handlers.dart └── test │ ├── ensure_build_test.dart │ └── logging_test.dart ├── google_cloud ├── .gitignore ├── CHANGELOG.md ├── tool │ ├── fix_pubspec.dart │ └── docker_test_script.sh ├── mono_pkg.yaml ├── pubspec.yaml ├── test │ └── src │ │ ├── listen_port_print.dart │ │ ├── project_id_print.dart │ │ └── terminate_print.dart ├── Dockerfile ├── lib │ ├── src │ │ ├── bad_configuration_exception.dart │ │ ├── constants.dart │ │ └── bad_request_exception.dart │ └── google_cloud.dart └── README.md ├── docs ├── quickstarts │ └── assets │ │ └── helloworld-browser.png └── README.md ├── functions_framework_builder ├── analysis_options.yaml ├── mono_pkg.yaml ├── build.yaml ├── .gitignore ├── README.md ├── test │ └── test_examples │ │ ├── freezed_style_json_mixin_handler.dart │ │ ├── complex_target_name_handlers.dart │ │ ├── valid_json_type_handlers.dart │ │ ├── valid_cloud_event_handlers.dart │ │ ├── valid_custom_type_handlers.dart │ │ └── valid_shelf_handlers.dart ├── lib │ └── src │ │ ├── analyzer_utils.dart │ │ └── constants.dart └── pubspec.yaml ├── AUTHORS ├── .github ├── dependabot.yml ├── workflows │ ├── publish.yaml │ ├── no-response.yml │ └── conformance.yml └── no-response.yml ├── pubspec.yaml ├── mono_repo.yaml ├── analysis_options.yaml └── Dockerfile /README.md: -------------------------------------------------------------------------------- 1 | functions_framework/README.md -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .dart_tool 2 | pubspec.lock 3 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /dartfn/dart_test.yaml: -------------------------------------------------------------------------------- 1 | tags: 2 | presubmit-only: 3 | skip: "Should only be run during presubmit" 4 | -------------------------------------------------------------------------------- /dartfn/lib/src/version.dart: -------------------------------------------------------------------------------- 1 | // Generated code. Do not modify. 2 | const packageVersion = '0.4.7-wip'; 3 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/assets/config/dev.json: -------------------------------------------------------------------------------- 1 | { 2 | "greetingUrl": "http://localhost:8080" 3 | } 4 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /functions_framework/dart_test.yaml: -------------------------------------------------------------------------------- 1 | tags: 2 | presubmit-only: 3 | skip: "Should only be run during presubmit" 4 | -------------------------------------------------------------------------------- /integration_test/dart_test.yaml: -------------------------------------------------------------------------------- 1 | tags: 2 | presubmit-only: 3 | skip: "Should only be run during presubmit" 4 | -------------------------------------------------------------------------------- /examples/hello/.dockerignore: -------------------------------------------------------------------------------- 1 | .dart_tool/ 2 | .dockerignore 3 | .git/ 4 | .github/ 5 | .gitignore 6 | .idea/ 7 | Dockerfile 8 | -------------------------------------------------------------------------------- /examples/json/.dockerignore: -------------------------------------------------------------------------------- 1 | .dart_tool/ 2 | .dockerignore 3 | .git/ 4 | .github/ 5 | .gitignore 6 | .idea/ 7 | Dockerfile 8 | -------------------------------------------------------------------------------- /dartfn/templates/json/.dockerignore: -------------------------------------------------------------------------------- 1 | .dart_tool/ 2 | .dockerignore 3 | .git/ 4 | .github/ 5 | .gitignore 6 | .idea/ 7 | Dockerfile 8 | -------------------------------------------------------------------------------- /examples/fullstack/backend/.dockerignore: -------------------------------------------------------------------------------- 1 | .dart_tool/ 2 | .dockerignore 3 | .git/ 4 | .github/ 5 | .gitignore 6 | .idea/ 7 | Dockerfile 8 | -------------------------------------------------------------------------------- /examples/raw_cloudevent/.dockerignore: -------------------------------------------------------------------------------- 1 | .dart_tool/ 2 | .dockerignore 3 | .git/ 4 | .github/ 5 | .gitignore 6 | .idea/ 7 | Dockerfile 8 | -------------------------------------------------------------------------------- /dartfn/templates/cloudevent/.dockerignore: -------------------------------------------------------------------------------- 1 | .dart_tool/ 2 | .dockerignore 3 | .git/ 4 | .github/ 5 | .gitignore 6 | .idea/ 7 | Dockerfile 8 | -------------------------------------------------------------------------------- /dartfn/templates/helloworld/.dockerignore: -------------------------------------------------------------------------------- 1 | .dart_tool/ 2 | .dockerignore 3 | .git/ 4 | .github/ 5 | .gitignore 6 | .idea/ 7 | Dockerfile 8 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/.dockerignore: -------------------------------------------------------------------------------- 1 | .dart_tool/ 2 | .dockerignore 3 | .git/ 4 | .github/ 5 | .gitignore 6 | .idea/ 7 | Dockerfile 8 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/xcuserdata/ 7 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /dartfn/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | pubspec.lock 6 | -------------------------------------------------------------------------------- /google_cloud/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | pubspec.lock 6 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/functions-framework-dart/HEAD/examples/fullstack/frontend/web/favicon.png -------------------------------------------------------------------------------- /examples/fullstack/images/flutter_demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/functions-framework-dart/HEAD/examples/fullstack/images/flutter_demo.png -------------------------------------------------------------------------------- /integration_test/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | pubspec.lock 6 | -------------------------------------------------------------------------------- /dartfn/templates/json/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | pubspec.lock 6 | -------------------------------------------------------------------------------- /docs/quickstarts/assets/helloworld-browser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/functions-framework-dart/HEAD/docs/quickstarts/assets/helloworld-browser.png -------------------------------------------------------------------------------- /dartfn/templates/cloudevent/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | pubspec.lock 6 | -------------------------------------------------------------------------------- /dartfn/templates/helloworld/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | pubspec.lock 6 | -------------------------------------------------------------------------------- /google_cloud/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.2.1-wip 2 | 3 | - Require `package:http` `^1.0.0`. 4 | - Require Dart 3.5 5 | 6 | ## 0.2.0 7 | 8 | - First release replacing `package:gcp`. 9 | -------------------------------------------------------------------------------- /dartfn/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # https://dart.dev/guides/language/analysis-options 2 | include: ../analysis_options.yaml 3 | 4 | analyzer: 5 | exclude: 6 | - 'templates/**' 7 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/functions-framework-dart/HEAD/examples/fullstack/frontend/web/icons/Icon-192.png -------------------------------------------------------------------------------- /examples/fullstack/frontend/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/functions-framework-dart/HEAD/examples/fullstack/frontend/web/icons/Icon-512.png -------------------------------------------------------------------------------- /functions_framework/example/readme.md: -------------------------------------------------------------------------------- 1 | # Functions Framework Examples 2 | 3 | For usage examples, see 4 | https://github.com/GoogleCloudPlatform/functions-framework-dart/tree/main/examples 5 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/functions-framework-dart/HEAD/examples/fullstack/frontend/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/function_types.dart: -------------------------------------------------------------------------------- 1 | export 'google/events/cloud/firestore/v1/data.pb.dart'; 2 | export 'google/protobuf/struct.pbenum.dart' show NullValue; 3 | export 'google/protobuf/timestamp.pb.dart'; 4 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/google/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # https://dart.dev/guides/language/analysis-options 2 | analyzer: 3 | errors: 4 | inference_failure_on_collection_literal: ignore 5 | require_trailing_commas: ignore 6 | -------------------------------------------------------------------------------- /functions_framework_builder/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # https://dart.dev/guides/language/analysis-options 2 | include: ../analysis_options.yaml 3 | 4 | analyzer: 5 | errors: 6 | # analyzer deprecations 7 | deprecated_member_use: ignore 8 | -------------------------------------------------------------------------------- /dartfn/templates/helloworld/lib/functions.dart: -------------------------------------------------------------------------------- 1 | import 'package:functions_framework/functions_framework.dart'; 2 | import 'package:shelf/shelf.dart'; 3 | 4 | @CloudFunction() 5 | Response function(Request request) => Response.ok('Hello, World!'); 6 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/fullstack/frontend-cli/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | 3 | stages: 4 | - analyze_format: 5 | - group: 6 | - format 7 | - analyze: --fatal-infos 8 | sdk: dev 9 | - analyze: 10 | sdk: pubspec 11 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/functions-framework-dart/HEAD/examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/functions-framework-dart/HEAD/examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/functions-framework-dart/HEAD/examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/functions-framework-dart/HEAD/examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/functions-framework-dart/HEAD/examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/functions-framework-dart/HEAD/examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/functions-framework-dart/HEAD/examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | 9 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 10 | } 11 | -------------------------------------------------------------------------------- /functions_framework/build.yaml: -------------------------------------------------------------------------------- 1 | # Read about `build.yaml` at https://pub.dev/packages/build_config 2 | targets: 3 | $default: 4 | builders: 5 | source_gen|combining_builder: 6 | options: 7 | ignore_for_file: 8 | - require_trailing_commas 9 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void fl_register_plugins(FlPluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void RegisterPlugins(flutter::PluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /examples/hello/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | 3 | stages: 4 | - analyze_format: 5 | - group: 6 | - format 7 | - analyze: --fatal-infos 8 | sdk: dev 9 | - analyze: 10 | sdk: pubspec 11 | - unit_test: 12 | - test: 13 | sdk: dev 14 | -------------------------------------------------------------------------------- /examples/json/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | 3 | stages: 4 | - analyze_format: 5 | - group: 6 | - format 7 | - analyze: --fatal-infos 8 | sdk: dev 9 | - analyze: 10 | sdk: pubspec 11 | - unit_test: 12 | - test: 13 | sdk: dev 14 | -------------------------------------------------------------------------------- /dartfn/templates/json/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | 3 | stages: 4 | - analyze_format: 5 | - group: 6 | - format 7 | - analyze: --fatal-infos 8 | sdk: dev 9 | - analyze: 10 | sdk: pubspec 11 | - unit_test: 12 | - test: 13 | sdk: dev 14 | -------------------------------------------------------------------------------- /examples/fullstack/backend/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | 3 | stages: 4 | - analyze_format: 5 | - group: 6 | - format 7 | - analyze: --fatal-infos 8 | sdk: dev 9 | - analyze: 10 | sdk: pubspec 11 | - unit_test: 12 | - test: 13 | sdk: dev 14 | -------------------------------------------------------------------------------- /examples/raw_cloudevent/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | 3 | stages: 4 | - analyze_format: 5 | - group: 6 | - format 7 | - analyze: --fatal-infos 8 | sdk: dev 9 | - analyze: 10 | sdk: pubspec 11 | - unit_test: 12 | - test: 13 | sdk: dev 14 | -------------------------------------------------------------------------------- /dartfn/templates/cloudevent/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | 3 | stages: 4 | - analyze_format: 5 | - group: 6 | - format 7 | - analyze: --fatal-infos 8 | sdk: dev 9 | - analyze: 10 | sdk: pubspec 11 | - unit_test: 12 | - test: 13 | sdk: dev 14 | -------------------------------------------------------------------------------- /dartfn/templates/helloworld/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | 3 | stages: 4 | - analyze_format: 5 | - group: 6 | - format 7 | - analyze: --fatal-infos 8 | sdk: dev 9 | - analyze: 10 | sdk: pubspec 11 | - unit_test: 12 | - test: 13 | sdk: dev 14 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | 3 | stages: 4 | - analyze_format: 5 | - group: 6 | - format 7 | - analyze: --fatal-infos 8 | sdk: dev 9 | - analyze: 10 | sdk: pubspec 11 | - unit_test: 12 | - test: 13 | sdk: dev 14 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @NSApplicationMain 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /functions_framework_builder/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | sdk: 3 | - pubspec 4 | - dev 5 | 6 | stages: 7 | - analyze_format: 8 | - group: 9 | - format 10 | - analyze: --fatal-infos 11 | sdk: dev 12 | - analyze: 13 | sdk: pubspec 14 | - unit_test: 15 | - test 16 | -------------------------------------------------------------------------------- /functions_framework/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | 3 | stages: 4 | - analyze_format: 5 | - group: 6 | - format 7 | - analyze: --fatal-infos 8 | sdk: dev 9 | - analyze: 10 | sdk: pubspec 11 | - unit_test: 12 | - test: --run-skipped -t presubmit-only 13 | sdk: dev 14 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | 3 | stages: 4 | - analyze_format: 5 | - group: 6 | - format 7 | - analyze: --fatal-infos 8 | sdk: stable # main - debug this! 9 | # Need to figure why main/master doesn't work! 10 | # - group: 11 | # - analyze 12 | # sdk: stable 13 | # 14 | -------------------------------------------------------------------------------- /integration_test/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | stages: 3 | - analyze_format: 4 | - group: 5 | - format 6 | - analyze: --fatal-infos 7 | sdk: dev 8 | - analyze: 9 | sdk: dev 10 | - unit_test: 11 | - test: 12 | sdk: [dev, pubspec] 13 | - test: --run-skipped -t presubmit-only 14 | sdk: [dev] 15 | -------------------------------------------------------------------------------- /dartfn/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | sdk: 3 | - dev 4 | - pubspec 5 | 6 | stages: 7 | - analyze_format: 8 | - group: 9 | - format 10 | - analyze: --fatal-infos 11 | sdk: dev 12 | - analyze: 13 | sdk: pubspec 14 | - unit_test: 15 | - test 16 | - test: --run-skipped -t presubmit-only 17 | sdk: dev 18 | -------------------------------------------------------------------------------- /functions_framework_builder/build.yaml: -------------------------------------------------------------------------------- 1 | builders: 2 | function_framework_builder: 3 | import: package:functions_framework_builder/builder.dart 4 | builder_factories: 5 | - functionsFrameworkBuilder 6 | build_extensions: 7 | 'lib/functions.dart': 8 | - bin/server.dart 9 | auto_apply: dependents 10 | build_to: source 11 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/hello/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | pubspec.lock 6 | 7 | # Standard files for Cloud Functions conformance tests 8 | # https://github.com/GoogleCloudPlatform/functions-framework-conformance 9 | function_output.json 10 | serverlog_stderr.txt 11 | serverlog_stdout.txt 12 | -------------------------------------------------------------------------------- /examples/json/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | pubspec.lock 6 | 7 | # Standard files for Cloud Functions conformance tests 8 | # https://github.com/GoogleCloudPlatform/functions-framework-conformance 9 | function_output.json 10 | serverlog_stderr.txt 11 | serverlog_stdout.txt 12 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # Below is a list of people and organizations that have contributed 2 | # to the Dart project. Names should be added to the list like so: 3 | # 4 | # Name/Organization 5 | 6 | Google Inc. 7 | 8 | Tony Pujals 9 | Grant Timmerman 10 | Andrew Lorenzen 11 | Kevin Moore 12 | -------------------------------------------------------------------------------- /functions_framework/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | pubspec.lock 6 | 7 | # Standard files for Cloud Functions conformance tests 8 | # https://github.com/GoogleCloudPlatform/functions-framework-conformance 9 | function_output.json 10 | serverlog_stderr.txt 11 | serverlog_stdout.txt 12 | -------------------------------------------------------------------------------- /examples/raw_cloudevent/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | pubspec.lock 6 | 7 | # Standard files for Cloud Functions conformance tests 8 | # https://github.com/GoogleCloudPlatform/functions-framework-conformance 9 | function_output.json 10 | serverlog_stderr.txt 11 | serverlog_stdout.txt 12 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.network.client 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | pubspec.lock 6 | 7 | # Standard files for Cloud Functions conformance tests 8 | # https://github.com/GoogleCloudPlatform/functions-framework-conformance 9 | function_output.json 10 | serverlog_stderr.txt 11 | serverlog_stdout.txt 12 | -------------------------------------------------------------------------------- /functions_framework_builder/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | pubspec.lock 6 | 7 | # Standard files for Cloud Functions conformance tests 8 | # https://github.com/GoogleCloudPlatform/functions-framework-conformance 9 | function_output.json 10 | serverlog_stderr.txt 11 | serverlog_stdout.txt 12 | -------------------------------------------------------------------------------- /examples/fullstack/frontend-cli/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | pubspec.lock 6 | 7 | # Standard files for Cloud Functions conformance tests 8 | # https://github.com/GoogleCloudPlatform/functions-framework-conformance 9 | function_output.json 10 | serverlog_stderr.txt 11 | serverlog_stdout.txt 12 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/test/decode_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:example_protobuf_firestore/src/function_types.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import 'test_shared.dart'; 5 | 6 | void main() { 7 | test('validate protobuf decode', () { 8 | final instance = DocumentEventData.fromBuffer(protobytes); 9 | 10 | expect(instance.toProto3Json(), jsonOutput); 11 | }); 12 | } 13 | -------------------------------------------------------------------------------- /examples/fullstack/backend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://dart.dev/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | 6 | build/ 7 | pubspec.lock 8 | 9 | # Standard files for Cloud Functions conformance tests 10 | # https://github.com/GoogleCloudPlatform/functions-framework-conformance 11 | function_output.json 12 | serverlog_stderr.txt 13 | serverlog_stdout.txt 14 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Dependabot configuration file. 2 | # See https://docs.github.com/en/code-security/dependabot/dependabot-version-updates 3 | version: 2 4 | 5 | updates: 6 | - package-ecosystem: github-actions 7 | directory: / 8 | schedule: 9 | interval: monthly 10 | labels: 11 | - autosubmit 12 | groups: 13 | dependencies: 14 | patterns: 15 | - "*" 16 | -------------------------------------------------------------------------------- /examples/fullstack/frontend-cli/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: frontend_cli 2 | publish_to: none 3 | 4 | resolution: workspace 5 | environment: 6 | sdk: ^3.6.0 7 | 8 | executables: 9 | greet: 10 | 11 | dependencies: 12 | http: ^1.0.0 13 | io: ^1.0.0 14 | json_annotation: ^4.9.0 15 | 16 | dev_dependencies: 17 | build_runner: ^2.2.1 18 | dart_flutter_team_lints: ^3.0.0 19 | json_serializable: ^6.6.0 20 | test: ^1.21.6 21 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /examples/raw_cloudevent/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example_raw_cloudevent_function 2 | publish_to: none 3 | 4 | resolution: workspace 5 | environment: 6 | sdk: ^3.6.0 7 | 8 | dependencies: 9 | functions_framework: ^0.4.0 10 | shelf: ^1.0.0 11 | 12 | dev_dependencies: 13 | build_runner: ^2.0.0 14 | dart_flutter_team_lints: ^3.0.0 15 | functions_framework_builder: ^0.4.1 16 | http: ^1.0.0 17 | test: ^1.16.6 18 | test_process: ^2.0.0 19 | -------------------------------------------------------------------------------- /.github/workflows/publish.yaml: -------------------------------------------------------------------------------- 1 | # A CI configuration to auto-publish pub packages. 2 | 3 | name: Publish 4 | 5 | on: 6 | pull_request: 7 | branches: [ main ] 8 | types: [opened, synchronize, reopened, labeled, unlabeled] 9 | push: 10 | tags: [ '[A-z]+-v[0-9]+.[0-9]+.[0-9]+' ] 11 | 12 | jobs: 13 | publish: 14 | if: ${{ github.repository_owner == 'GoogleCloudPlatform' }} 15 | uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main 16 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example_protobuf_firestore 2 | publish_to: none 3 | 4 | resolution: workspace 5 | environment: 6 | sdk: ^3.6.0 7 | 8 | dependencies: 9 | functions_framework: ^0.4.3 10 | protobuf: ^4.0.0 11 | shelf: ^1.4.0 12 | 13 | dev_dependencies: 14 | build_runner: ^2.2.1 15 | dart_flutter_team_lints: ^3.0.0 16 | functions_framework_builder: ^0.4.10 17 | http: ^1.0.0 18 | test: ^1.21.6 19 | test_process: ^2.0.0 20 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/google/type/latlng.pbenum.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: google/type/latlng.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names, library_prefixes 9 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 10 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 11 | -------------------------------------------------------------------------------- /examples/fullstack/backend/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: backend 2 | publish_to: none 3 | 4 | resolution: workspace 5 | environment: 6 | sdk: ^3.6.0 7 | 8 | dependencies: 9 | functions_framework: ^0.4.0 10 | json_annotation: ^4.9.0 11 | shelf: ^1.0.0 12 | 13 | dev_dependencies: 14 | build_runner: ^2.2.1 15 | dart_flutter_team_lints: ^3.0.0 16 | functions_framework_builder: ^0.4.7 17 | http: ^1.0.0 18 | json_serializable: ^6.6.0 19 | test: ^1.21.6 20 | test_process: ^2.0.0 21 | -------------------------------------------------------------------------------- /examples/json/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example_json_function 2 | publish_to: none 3 | 4 | resolution: workspace 5 | environment: 6 | sdk: ^3.6.0 7 | 8 | dependencies: 9 | functions_framework: ^0.4.0 10 | json_annotation: ^4.9.0 11 | shelf: ^1.0.0 12 | 13 | dev_dependencies: 14 | build_runner: ^2.2.1 15 | dart_flutter_team_lints: ^3.0.0 16 | functions_framework_builder: ^0.4.7 17 | http: ^1.0.0 18 | json_serializable: ^6.6.0 19 | test: ^1.21.6 20 | test_process: ^2.0.0 21 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/google/protobuf/timestamp.pbenum.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: google/protobuf/timestamp.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names, library_prefixes 9 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 10 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 11 | -------------------------------------------------------------------------------- /examples/hello/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean 2 | 3 | FUNCTION_TARGET = function 4 | PORT = 8080 5 | 6 | # bin/server.dart is the generated target for lib/functions.dart 7 | bin/server.dart: 8 | dart run build_runner build --delete-conflicting-outputs 9 | 10 | build: bin/server.dart 11 | 12 | test: clean build 13 | dart test 14 | 15 | clean: 16 | dart run build_runner clean 17 | rm -rf bin/server.dart 18 | 19 | run: build 20 | dart run bin/server.dart --port=$(PORT) --target=$(FUNCTION_TARGET) 21 | -------------------------------------------------------------------------------- /examples/json/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean 2 | 3 | FUNCTION_TARGET = function 4 | PORT = 8080 5 | 6 | # bin/server.dart is the generated target for lib/functions.dart 7 | bin/server.dart: 8 | dart run build_runner build --delete-conflicting-outputs 9 | 10 | build: bin/server.dart 11 | 12 | test: clean build 13 | dart test 14 | 15 | clean: 16 | dart run build_runner clean 17 | rm -rf bin/server.dart 18 | 19 | run: build 20 | dart run bin/server.dart --port=$(PORT) --target=$(FUNCTION_TARGET) 21 | -------------------------------------------------------------------------------- /dartfn/templates/json/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean 2 | 3 | FUNCTION_TARGET = function 4 | PORT = 8080 5 | 6 | # bin/server.dart is the generated target for lib/functions.dart 7 | bin/server.dart: 8 | dart run build_runner build --delete-conflicting-outputs 9 | 10 | build: bin/server.dart 11 | 12 | test: clean build 13 | dart test 14 | 15 | clean: 16 | dart run build_runner clean 17 | rm -rf bin/server.dart 18 | 19 | run: build 20 | dart run bin/server.dart --port=$(PORT) --target=$(FUNCTION_TARGET) 21 | -------------------------------------------------------------------------------- /google_cloud/tool/fix_pubspec.dart: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env dart 2 | 3 | import 'dart:io'; 4 | 5 | // Removes the `workspace` property from the pubspec so it can be used via 6 | // Docker. 7 | // Work-around for https://github.com/dart-lang/pub/issues/4357 8 | void main(List args) { 9 | final file = File('pubspec.yaml'); 10 | final content = file.readAsStringSync().replaceAll(_content, ''); 11 | file.writeAsStringSync(content); 12 | } 13 | 14 | const _content = r'''resolution: workspace 15 | '''; 16 | -------------------------------------------------------------------------------- /dartfn/templates/cloudevent/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean 2 | 3 | FUNCTION_TARGET = function 4 | PORT = 8080 5 | 6 | # bin/server.dart is the generated target for lib/functions.dart 7 | bin/server.dart: 8 | dart run build_runner build --delete-conflicting-outputs 9 | 10 | build: bin/server.dart 11 | 12 | test: clean build 13 | dart test 14 | 15 | clean: 16 | dart run build_runner clean 17 | rm -rf bin/server.dart 18 | 19 | run: build 20 | dart run bin/server.dart --port=$(PORT) --target=$(FUNCTION_TARGET) 21 | -------------------------------------------------------------------------------- /dartfn/templates/helloworld/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean 2 | 3 | FUNCTION_TARGET = function 4 | PORT = 8080 5 | 6 | # bin/server.dart is the generated target for lib/functions.dart 7 | bin/server.dart: 8 | dart run build_runner build --delete-conflicting-outputs 9 | 10 | build: bin/server.dart 11 | 12 | test: clean build 13 | dart test 14 | 15 | clean: 16 | dart run build_runner clean 17 | rm -rf bin/server.dart 18 | 19 | run: build 20 | dart run bin/server.dart --port=$(PORT) --target=$(FUNCTION_TARGET) 21 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/linux/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController.init() 7 | let windowFrame = self.frame 8 | self.contentViewController = flutterViewController 9 | self.setFrame(windowFrame, display: true) 10 | 11 | RegisterGeneratedPlugins(registry: flutterViewController) 12 | 13 | super.awakeFromNib() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/google/events/cloud/firestore/v1/data.pbenum.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: google/events/cloud/firestore/v1/data.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names, library_prefixes 9 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 10 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 11 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: ffd_workspace # Can be anything 2 | environment: 3 | sdk: ^3.6.0 4 | 5 | publish_to: none 6 | 7 | dev_dependencies: 8 | dart_flutter_team_lints: ^3.2.0 9 | workspace: 10 | - dartfn 11 | - examples/fullstack/backend 12 | - examples/fullstack/frontend-cli 13 | - examples/hello 14 | - examples/json 15 | - examples/protobuf_firestore 16 | - examples/raw_cloudevent 17 | - functions_framework 18 | - functions_framework_builder 19 | - google_cloud 20 | - integration_test 21 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/google/events/cloud/firestore/v1/events.pbenum.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: google/events/cloud/firestore/v1/events.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names, library_prefixes 9 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 10 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 11 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | com.apple.security.network.client 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dartfn/templates/helloworld/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: __projectName__ 2 | description: A sample "Hello, World!" Functions Framework project. 3 | # version: 0.1.0 4 | # homepage: https://www.example.com 5 | publish_to: none 6 | 7 | environment: 8 | sdk: ^3.6.0 9 | 10 | dependencies: 11 | functions_framework: ^0.4.0 12 | shelf: ^1.0.0 13 | 14 | dev_dependencies: 15 | build_runner: ^2.0.0 16 | functions_framework_builder: ^0.4.1 17 | http: ^1.0.0 18 | dart_flutter_team_lints: ^3.0.0 19 | test: ^1.16.6 20 | test_process: ^2.0.0 21 | -------------------------------------------------------------------------------- /dartfn/templates/cloudevent/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: __projectName__ 2 | description: A sample Functions Framework project for handling a cloudevent. 3 | # version: 0.1.0 4 | # homepage: https://www.example.com 5 | publish_to: none 6 | 7 | environment: 8 | sdk: ^3.6.0 9 | 10 | dependencies: 11 | functions_framework: ^0.4.0 12 | shelf: ^1.0.0 13 | 14 | dev_dependencies: 15 | build_runner: ^2.0.0 16 | functions_framework_builder: ^0.4.1 17 | http: ^1.0.0 18 | dart_flutter_team_lints: ^3.0.0 19 | test: ^1.16.6 20 | test_process: ^2.0.0 21 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /google_cloud/mono_pkg.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | stages: 3 | - analyze_format: 4 | - group: 5 | - format 6 | - analyze: --fatal-infos 7 | sdk: dev 8 | - analyze: 9 | sdk: pubspec 10 | - unit_test: 11 | - test: 12 | os: [windows, macos, linux] 13 | sdk: dev 14 | # All OSes tested on oldest supported SDK 15 | - test: 16 | os: [linux, macos] # weird crash on windows – try to update when beyond 2.18 17 | sdk: pubspec 18 | - command: ./tool/docker_test_script.sh 19 | sdk: pubspec 20 | -------------------------------------------------------------------------------- /functions_framework_builder/README.md: -------------------------------------------------------------------------------- 1 | # Functions Framework Builder for Dart 2 | 3 | An open source FaaS (Function as a Service) framework for writing portable Dart 4 | functions, brought to you by the Google Dart and Cloud Functions teams. 5 | 6 | This is the builder package for the Functions Framework for Dart. Please 7 | see [GoogleCloudPlatform/functions-framework-dart] for more information. 8 | 9 | 10 | [GoogleCloudPlatform/functions-framework-dart]: 11 | https://github.com/GoogleCloudPlatform/functions-framework-dart 12 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: fullstack_demo_frontend 2 | publish_to: 'none' 3 | 4 | environment: 5 | sdk: ^3.6.0 6 | 7 | dependencies: 8 | cupertino_icons: ^1.0.2 9 | flutter: 10 | sdk: flutter 11 | http: ^1.0.0 12 | json_annotation: ^4.9.0 13 | provider: ^6.0.0 14 | 15 | dev_dependencies: 16 | build_runner: ^2.2.1 17 | dart_flutter_team_lints: ^3.0.0 18 | flutter_test: 19 | sdk: flutter 20 | json_serializable: ^6.6.0 21 | 22 | flutter: 23 | assets: 24 | - assets/config/ 25 | uses-material-design: true 26 | -------------------------------------------------------------------------------- /functions_framework_builder/test/test_examples/freezed_style_json_mixin_handler.dart: -------------------------------------------------------------------------------- 1 | import 'package:functions_framework/functions_framework.dart'; 2 | 3 | mixin class JsonType { 4 | Map toJson() => throw UnimplementedError(); 5 | } 6 | 7 | class MixedInType with JsonType { 8 | // ignore: avoid_unused_constructor_parameters 9 | factory MixedInType.fromJson(Map json) => 10 | throw UnimplementedError(); 11 | } 12 | 13 | @CloudFunction() 14 | MixedInType syncFunction(MixedInType request) => throw UnimplementedError(); 15 | -------------------------------------------------------------------------------- /dartfn/templates/cloudevent/lib/functions.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:io'; 3 | 4 | import 'package:functions_framework/functions_framework.dart'; 5 | 6 | const _encoder = JsonEncoder(); 7 | 8 | @CloudFunction() 9 | void function(CloudEvent event, RequestContext context) { 10 | context.logger 11 | .info('[CloudEvent] source: ${event.source}, subject: ${event.subject}'); 12 | stderr.writeln( 13 | _encoder.convert( 14 | { 15 | 'message': event, 16 | 'severity': LogSeverity.info, 17 | }, 18 | ), 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/google/type/latlng.pbserver.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: google/type/latlng.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names 9 | // ignore_for_file: deprecated_member_use_from_same_package, library_prefixes 10 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 11 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 12 | 13 | export 'latlng.pb.dart'; 14 | -------------------------------------------------------------------------------- /functions_framework_builder/lib/src/analyzer_utils.dart: -------------------------------------------------------------------------------- 1 | import 'package:analyzer/dart/element/element.dart'; 2 | import 'package:analyzer/dart/element/type.dart'; 3 | 4 | extension DartTypeExtension on DartType { 5 | String toStringNonNullable() => getDisplayString().dropQuestion(); 6 | } 7 | 8 | extension ElementExtension on Element { 9 | String toStringNonNullable() => getDisplayString().dropQuestion(); 10 | } 11 | 12 | extension on String { 13 | String dropQuestion() { 14 | if (endsWith('?')) return substring(0, length - 1); 15 | return this; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/google/protobuf/struct.pbserver.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: google/protobuf/struct.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names 9 | // ignore_for_file: deprecated_member_use_from_same_package, library_prefixes 10 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 11 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 12 | 13 | export 'struct.pb.dart'; 14 | -------------------------------------------------------------------------------- /examples/fullstack/backend/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean 2 | 3 | FUNCTION_TARGET = function 4 | PORT = 8080 5 | 6 | # bin/server.dart is the generated target for lib/functions.dart 7 | bin/server.dart: lib/functions.dart 8 | dart run build_runner build --delete-conflicting-outputs 9 | 10 | build: bin/server.dart 11 | 12 | test: clean build 13 | dart test 14 | 15 | clean: 16 | rm -rf bin/server.dart 17 | 18 | run: build 19 | # strip available updates and 'Got dependencies' 20 | @dart pub get | sed '/^[ G]/d' 21 | dart run bin/server.dart --port=$(PORT) --target=$(FUNCTION_TARGET) 22 | 23 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/test/widget_test.dart: -------------------------------------------------------------------------------- 1 | // This is a basic Flutter widget test. 2 | // 3 | // To perform an interaction with a widget in your test, use the WidgetTester 4 | // utility that Flutter provides. For example, you can send tap and scroll 5 | // gestures. You can also use WidgetTester to find child widgets in the widget 6 | // tree, read text, and verify that the values of widget properties are correct. 7 | 8 | import 'package:flutter_test/flutter_test.dart'; 9 | 10 | void main() { 11 | testWidgets('', (WidgetTester tester) async { 12 | // TODO 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /examples/hello/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: hello_world_function 2 | version: 0.4.0 3 | description: Dart Functions Framework simple function example. 4 | repository: https://github.com/GoogleCloudPlatform/functions-framework-dart 5 | publish_to: none 6 | 7 | resolution: workspace 8 | environment: 9 | sdk: ^3.6.0 10 | 11 | dependencies: 12 | functions_framework: ^0.4.0 13 | shelf: ^1.0.0 14 | 15 | dev_dependencies: 16 | build_runner: ^2.0.0 17 | dart_flutter_team_lints: ^3.0.0 18 | functions_framework_builder: ^0.4.1 19 | http: ^1.0.0 20 | test: ^1.16.6 21 | test_process: ^2.0.0 22 | -------------------------------------------------------------------------------- /dartfn/build.yaml: -------------------------------------------------------------------------------- 1 | # Read about `build.yaml` at https://pub.dev/packages/build_config 2 | targets: 3 | $default: 4 | sources: 5 | include: 6 | - $package$ 7 | - pubspec.yaml 8 | - lib/** 9 | - templates/** 10 | - tool/** 11 | builders: 12 | dartfn: 13 | generate_for: 14 | - lib/src/generators/*.dart 15 | enabled: true 16 | 17 | builders: 18 | dartfn: 19 | import: "tool/builder/builder.dart" 20 | builder_factories: ["builder"] 21 | build_extensions: {".dart": [".g.dart"]} 22 | build_to: source 23 | -------------------------------------------------------------------------------- /dartfn/templates/json/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: __projectName__ 2 | description: A sample Functions Framework project for handling JSON. 3 | # version: 0.1.0 4 | # homepage: https://www.example.com 5 | publish_to: none 6 | 7 | environment: 8 | sdk: ^3.6.0 9 | 10 | dependencies: 11 | functions_framework: ^0.4.0 12 | json_annotation: ^4.9.0 13 | shelf: ^1.0.0 14 | 15 | dev_dependencies: 16 | build_runner: ^2.2.1 17 | functions_framework_builder: ^0.4.7 18 | http: ^1.0.0 19 | json_serializable: ^6.6.0 20 | dart_flutter_team_lints: ^3.0.0 21 | test: ^1.21.6 22 | test_process: ^2.0.0 23 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/google/protobuf/timestamp.pbserver.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: google/protobuf/timestamp.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names 9 | // ignore_for_file: deprecated_member_use_from_same_package, library_prefixes 10 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 11 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 12 | 13 | export 'timestamp.pb.dart'; 14 | -------------------------------------------------------------------------------- /integration_test/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: hello_world_function_test 2 | publish_to: none 3 | 4 | resolution: workspace 5 | environment: 6 | sdk: ^3.6.0 7 | 8 | dependencies: 9 | functions_framework: ^0.4.3+1 10 | json_annotation: ^4.9.0 11 | shelf: ^1.4.0 12 | 13 | dev_dependencies: 14 | build_runner: ^2.2.1 15 | build_verify: ^3.0.0 16 | dart_flutter_team_lints: ^3.0.0 17 | functions_framework_builder: ^0.4.10 18 | google_cloud: ^0.2.1-wip 19 | http: ^1.0.0 20 | http_parser: ^4.0.0 21 | io: ^1.0.3 22 | json_serializable: ^6.6.0 23 | test: ^1.21.6 24 | test_process: ^2.0.0 25 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/google/events/cloud/firestore/v1/data.pbserver.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: google/events/cloud/firestore/v1/data.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names 9 | // ignore_for_file: deprecated_member_use_from_same_package, library_prefixes 10 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 11 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 12 | 13 | export 'data.pb.dart'; 14 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/google/events/cloud/firestore/v1/events.pbserver.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: google/events/cloud/firestore/v1/events.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names 9 | // ignore_for_file: deprecated_member_use_from_same_package, library_prefixes 10 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 11 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 12 | 13 | export 'events.pb.dart'; 14 | -------------------------------------------------------------------------------- /examples/raw_cloudevent/sample/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "specversion": "1.0", 3 | "type": "google.cloud.pubsub.topic.publish", 4 | "time": "2020-09-05T03:56:24.000Z", 5 | "id": "1234-1234-1234", 6 | "source": "urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66", 7 | "subject": "STRUCTURED_MODE_CLOUDEVENT_SAMPLE", 8 | "data": { 9 | "subscription": "projects/my-project/subscriptions/my-subscription", 10 | "message": { 11 | "@type": "type.googleapis.com/google.pubsub.v1.PubsubMessage", 12 | "attributes": { 13 | "attr1":"attr1-value" 14 | }, 15 | "data": "dGVzdCBtZXNzYWdlIDM=" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /google_cloud/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: google_cloud 2 | description: >- 3 | Utilities for running Dart code correctly on the Google Cloud Platform. 4 | version: 0.2.1-wip 5 | repository: https://github.com/GoogleCloudPlatform/functions-framework-dart/tree/main/google_cloud 6 | 7 | resolution: workspace 8 | environment: 9 | sdk: ^3.6.0 10 | 11 | dependencies: 12 | collection: ^1.17.0 13 | http: ^1.0.0 14 | io: ^1.0.3 15 | shelf: ^1.4.0 16 | stack_trace: ^1.11.0 17 | 18 | dev_dependencies: 19 | dart_flutter_team_lints: ^3.0.0 20 | googleapis: ^14.0.0 21 | googleapis_auth: ^2.0.0 22 | test: ^1.22.0 23 | test_process: ^2.0.3 24 | -------------------------------------------------------------------------------- /dartfn/templates/cloudevent/sample/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "specversion": "1.0", 3 | "type": "google.cloud.pubsub.topic.publish", 4 | "time": "2020-09-05T03:56:24.000Z", 5 | "id": "1234-1234-1234", 6 | "source": "urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66", 7 | "subject": "STRUCTURED_MODE_CLOUDEVENT_SAMPLE", 8 | "data": { 9 | "subscription": "projects/my-project/subscriptions/my-subscription", 10 | "message": { 11 | "@type": "type.googleapis.com/google.pubsub.v1.PubsubMessage", 12 | "attributes": { 13 | "attr1":"attr1-value" 14 | }, 15 | "data": "dGVzdCBtZXNzYWdlIDM=" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/sample/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "specversion": "1.0", 3 | "type": "google.cloud.pubsub.topic.publish", 4 | "time": "2020-09-05T03:56:24.000Z", 5 | "id": "1234-1234-1234", 6 | "source": "urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66", 7 | "subject": "STRUCTURED_MODE_CLOUDEVENT_SAMPLE", 8 | "data": { 9 | "subscription": "projects/my-project/subscriptions/my-subscription", 10 | "message": { 11 | "@type": "type.googleapis.com/google.pubsub.v1.PubsubMessage", 12 | "attributes": { 13 | "attr1":"attr1-value" 14 | }, 15 | "data": "dGVzdCBtZXNzYWdlIDM=" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /google_cloud/tool/docker_test_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 6 | ${__dir}/fix_pubspec.dart 7 | 8 | image="$(docker build -q .)" 9 | echo Image created: "$image" 10 | container=$(docker run -d -p 8080:8080 --rm "$image") 11 | echo Container started: "$container" 12 | sleep 1 13 | # TODO: the current example assumes much configuration we don't have for CI yet 14 | # dart run test test/docker_test.dart -t presubmit-only --run-skipped || EXIT_CODE=$? 15 | echo Container killed "$(docker kill "$container")" 16 | echo Image deleted "$(docker rmi "$image")" 17 | exit ${EXIT_CODE} 18 | -------------------------------------------------------------------------------- /examples/fullstack/frontend-cli/README.md: -------------------------------------------------------------------------------- 1 | # frontend-cli 2 | 3 | Call the demo greeting `backend` with a simple command-line app. 4 | 5 | ## Usage 6 | 7 | A simple usage example: 8 | 9 | With the `backend` running on `localhost:8080` 10 | 11 | ```shell 12 | dart bin/greet.dart YOUR-NAME 13 | ``` 14 | 15 | With the `backend` hosted on another host (Cloud Run): 16 | 17 | ```shell 18 | export GREETING_URL=https://greeting-EXAMPLE.run.app 19 | dart bin/greet.dart YOUR-NAME 20 | ``` 21 | 22 | Activate the app locally so you can just run the `greet` command: 23 | 24 | ```shell 25 | dart pub global activate --source path . 26 | greet YOUR-NAME 27 | ``` 28 | -------------------------------------------------------------------------------- /mono_repo.yaml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/mono_repo.dart 2 | 3 | # TODO: need to fix the logic here! 4 | #self_validate: analyze_format 5 | 6 | merge_stages: 7 | - analyze_format 8 | - unit_test 9 | 10 | github: 11 | on: 12 | push: 13 | branches: 14 | - main 15 | pull_request: 16 | schedule: 17 | # Setting just `cron` keeps the defaults for `push` and `pull_request` 18 | - cron: '0 0 * * 0' # “At 00:00 (UTC) on Sunday.” 19 | 20 | workflows: 21 | lint: 22 | name: Dart Lint CI 23 | stages: 24 | - analyze_format 25 | unit: 26 | name: Dart Unit CI 27 | stages: 28 | - unit_test 29 | -------------------------------------------------------------------------------- /dartfn/templates/json/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # Defines a default set of lint rules enforced for 2 | # projects at Google. For details and rationale, 3 | # see https://pub.dev/packages/lints. 4 | include: package:lints/recommended.yaml 5 | 6 | # For lint rules and documentation, see http://dart-lang.github.io/linter/lints. 7 | # Uncomment to specify additional rules. 8 | # linter: 9 | # rules: 10 | # - camel_case_types 11 | 12 | analyzer: 13 | # exclude: 14 | # - path/to/excluded/files/** 15 | 16 | # This is here to fix CI analysis. Will be removed at generation. 17 | # Search source code for details 18 | linter: 19 | rules: 20 | lowercase_with_underscores: 'no' 21 | -------------------------------------------------------------------------------- /dartfn/templates/cloudevent/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # Defines a default set of lint rules enforced for 2 | # projects at Google. For details and rationale, 3 | # see https://pub.dev/packages/lints. 4 | include: package:lints/recommended.yaml 5 | 6 | # For lint rules and documentation, see http://dart-lang.github.io/linter/lints. 7 | # Uncomment to specify additional rules. 8 | # linter: 9 | # rules: 10 | # - camel_case_types 11 | 12 | analyzer: 13 | # exclude: 14 | # - path/to/excluded/files/** 15 | 16 | # This is here to fix CI analysis. Will be removed at generation. 17 | # Search source code for details 18 | linter: 19 | rules: 20 | lowercase_with_underscores: 'no' 21 | -------------------------------------------------------------------------------- /dartfn/templates/helloworld/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # Defines a default set of lint rules enforced for 2 | # projects at Google. For details and rationale, 3 | # see https://pub.dev/packages/lints. 4 | include: package:lints/recommended.yaml 5 | 6 | # For lint rules and documentation, see http://dart-lang.github.io/linter/lints. 7 | # Uncomment to specify additional rules. 8 | # linter: 9 | # rules: 10 | # - camel_case_types 11 | 12 | analyzer: 13 | # exclude: 14 | # - path/to/excluded/files/** 15 | 16 | # This is here to fix CI analysis. Will be removed at generation. 17 | # Search source code for details 18 | linter: 19 | rules: 20 | lowercase_with_underscores: 'no' 21 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Configs/Warnings.xcconfig: -------------------------------------------------------------------------------- 1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings 2 | GCC_WARN_UNDECLARED_SELECTOR = YES 3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES 4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE 5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 6 | CLANG_WARN_PRAGMA_PACK = YES 7 | CLANG_WARN_STRICT_PROTOTYPES = YES 8 | CLANG_WARN_COMMA = YES 9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES 10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES 11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES 12 | GCC_WARN_SHADOW = YES 13 | CLANG_WARN_UNREACHABLE_CODE = YES 14 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "short_name": "frontend", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Configs/AppInfo.xcconfig: -------------------------------------------------------------------------------- 1 | // Application-level settings for the Runner target. 2 | // 3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the 4 | // future. If not, the values below would default to using the project name when this becomes a 5 | // 'flutter create' template. 6 | 7 | // The application's name. By default this is also the title of the Flutter window. 8 | PRODUCT_NAME = frontend 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.frontend 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2021 com.example. All rights reserved. 15 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(runner LANGUAGES CXX) 3 | 4 | add_executable(${BINARY_NAME} WIN32 5 | "flutter_window.cpp" 6 | "main.cpp" 7 | "run_loop.cpp" 8 | "utils.cpp" 9 | "win32_window.cpp" 10 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 11 | "Runner.rc" 12 | "runner.exe.manifest" 13 | ) 14 | apply_standard_settings(${BINARY_NAME}) 15 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 16 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 17 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 18 | add_dependencies(${BINARY_NAME} flutter_assemble) 19 | -------------------------------------------------------------------------------- /.github/no-response.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-no-response - https://github.com/probot/no-response 2 | 3 | # Number of days of inactivity before an issue is closed for lack of response. 4 | daysUntilClose: 21 5 | 6 | # Label requiring a response. 7 | responseRequiredLabel: "kind/question" 8 | 9 | # Comment to post when closing an Issue for lack of response. 10 | closeComment: >- 11 | Without additional information, we are unfortunately not sure how to 12 | resolve this issue. We are therefore reluctantly going to close this 13 | bug for now. Please don't hesitate to comment on the bug if you have 14 | any more information for us; we will reopen it right away! 15 | 16 | Thanks for your contribution. 17 | -------------------------------------------------------------------------------- /functions_framework_builder/lib/src/constants.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | const functionsLibraryPrefix = 'function_library'; 16 | -------------------------------------------------------------------------------- /dartfn/lib/functions_framework_tool.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | export 'src/generators.dart'; 16 | export 'src/printer.dart'; 17 | export 'src/version.dart'; 18 | -------------------------------------------------------------------------------- /functions_framework/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: functions_framework 2 | version: 0.4.4-wip 3 | description: >- 4 | FaaS (Function as a service) framework for writing portable Dart functions 5 | repository: https://github.com/GoogleCloudPlatform/functions-framework-dart 6 | 7 | resolution: workspace 8 | environment: 9 | sdk: ^3.6.0 10 | 11 | dependencies: 12 | args: ^2.0.0 13 | collection: ^1.17.0 14 | google_cloud: ^0.2.0 15 | http: ">=0.13.5 <2.0.0" 16 | http_parser: ^4.0.0 17 | io: ^1.0.3 18 | json_annotation: ^4.9.0 19 | meta: ^1.7.0 20 | shelf: ^1.4.0 21 | stack_trace: ^1.11.0 22 | 23 | dev_dependencies: 24 | build_runner: ^2.2.1 25 | build_verify: ^3.0.0 26 | dart_flutter_team_lints: ^3.0.0 27 | json_serializable: ^6.9.0 28 | test: ^1.21.6 29 | -------------------------------------------------------------------------------- /integration_test/lib/src/utils.dart: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | import 'dart:convert'; 14 | 15 | String encodeJsonPretty(Object? object) => 16 | const JsonEncoder.withIndent(' ').convert(object); 17 | -------------------------------------------------------------------------------- /examples/hello/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM dart:stable AS build 2 | 3 | # Resolve app dependencies. 4 | WORKDIR /app 5 | COPY pubspec.* ./ 6 | RUN dart pub get 7 | 8 | # Copy app source code and AOT compile it. 9 | COPY . . 10 | # Ensure packages are still up-to-date if anything has changed 11 | RUN dart pub get --offline 12 | RUN dart pub run build_runner build --delete-conflicting-outputs 13 | RUN dart compile exe bin/server.dart -o bin/server 14 | 15 | # Build minimal serving image from AOT-compiled `/server` and required system 16 | # libraries and configuration files stored in `/runtime/` from the build stage. 17 | FROM scratch 18 | COPY --from=build /runtime/ / 19 | COPY --from=build /app/bin/server /app/bin/ 20 | 21 | # Start server. 22 | EXPOSE 8080 23 | CMD ["/app/bin/server"] 24 | -------------------------------------------------------------------------------- /examples/json/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM dart:stable AS build 2 | 3 | # Resolve app dependencies. 4 | WORKDIR /app 5 | COPY pubspec.* ./ 6 | RUN dart pub get 7 | 8 | # Copy app source code and AOT compile it. 9 | COPY . . 10 | # Ensure packages are still up-to-date if anything has changed 11 | RUN dart pub get --offline 12 | RUN dart pub run build_runner build --delete-conflicting-outputs 13 | RUN dart compile exe bin/server.dart -o bin/server 14 | 15 | # Build minimal serving image from AOT-compiled `/server` and required system 16 | # libraries and configuration files stored in `/runtime/` from the build stage. 17 | FROM scratch 18 | COPY --from=build /runtime/ / 19 | COPY --from=build /app/bin/server /app/bin/ 20 | 21 | # Start server. 22 | EXPOSE 8080 23 | CMD ["/app/bin/server"] 24 | -------------------------------------------------------------------------------- /google_cloud/test/src/listen_port_print.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | import 'package:google_cloud/google_cloud.dart'; 15 | 16 | void main() { 17 | print(listenPort()); 18 | } 19 | -------------------------------------------------------------------------------- /examples/fullstack/backend/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM dart:stable AS build 2 | 3 | # Resolve app dependencies. 4 | WORKDIR /app 5 | COPY pubspec.* ./ 6 | RUN dart pub get 7 | 8 | # Copy app source code and AOT compile it. 9 | COPY . . 10 | # Ensure packages are still up-to-date if anything has changed 11 | RUN dart pub get --offline 12 | RUN dart pub run build_runner build --delete-conflicting-outputs 13 | RUN dart compile exe bin/server.dart -o bin/server 14 | 15 | # Build minimal serving image from AOT-compiled `/server` and required system 16 | # libraries and configuration files stored in `/runtime/` from the build stage. 17 | FROM scratch 18 | COPY --from=build /runtime/ / 19 | COPY --from=build /app/bin/server /app/bin/ 20 | 21 | # Start server. 22 | EXPOSE 8080 23 | CMD ["/app/bin/server"] 24 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/tool/regenerate_protos.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ ! -d "$GOOGLEAPIS" ]; then 4 | echo "Please set the GOOGLEAPIS environment variable to your clone of https://github.com/googleapis/googleapis." 5 | exit -1 6 | fi 7 | 8 | if [ ! -d "$GOOGLE_CLOUD_EVENTS" ]; then 9 | echo "Please set the GOOGLE_CLOUD_EVENTS environment variable to your clone of https://github.com/googleapis/google-cloudevents." 10 | exit -1 11 | fi 12 | 13 | protoc \ 14 | -I$GOOGLEAPIS \ 15 | -I$GOOGLE_CLOUD_EVENTS/proto \ 16 | --dart_out="lib/src" \ 17 | google/events/cloud/firestore/v1/data.proto \ 18 | google/events/cloud/firestore/v1/events.proto \ 19 | google/protobuf/struct.proto \ 20 | google/protobuf/timestamp.proto \ 21 | google/type/latlng.proto 22 | 23 | dart format lib/src/google 24 | -------------------------------------------------------------------------------- /google_cloud/test/src/project_id_print.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | import 'package:google_cloud/google_cloud.dart'; 15 | 16 | Future main() async { 17 | print(await computeProjectId()); 18 | } 19 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/lib/views/history_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:provider/provider.dart'; 3 | 4 | import '../models/app_model.dart'; 5 | 6 | class HistoryPage extends StatelessWidget { 7 | @override 8 | Widget build(BuildContext context) { 9 | final model = context.watch(); 10 | return Scaffold( 11 | appBar: AppBar( 12 | title: const Text('History'), 13 | ), 14 | body: ListView.builder( 15 | itemCount: model.pastGreetings.length, 16 | itemBuilder: (context, index) { 17 | final greeting = model.pastGreetings[index]; 18 | return ListTile( 19 | title: Text('${greeting.salutation}, ${greeting.name}'), 20 | ); 21 | }, 22 | ), 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM dart:stable AS build 2 | 3 | # Resolve app dependencies. 4 | WORKDIR /app 5 | COPY pubspec.* ./ 6 | RUN dart pub get 7 | 8 | # Copy app source code and AOT compile it. 9 | COPY . . 10 | # Ensure packages are still up-to-date if anything has changed 11 | RUN dart pub get --offline 12 | RUN dart pub run build_runner build --delete-conflicting-outputs 13 | RUN dart compile exe bin/server.dart -o bin/server 14 | 15 | # Build minimal serving image from AOT-compiled `/server` and required system 16 | # libraries and configuration files stored in `/runtime/` from the build stage. 17 | FROM scratch 18 | COPY --from=build /runtime/ / 19 | COPY --from=build /app/bin/server /app/bin/ 20 | 21 | # Start server. 22 | EXPOSE 8080 23 | ENTRYPOINT ["/app/bin/server", "--signature-type=cloudevent"] 24 | -------------------------------------------------------------------------------- /examples/raw_cloudevent/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM dart:stable AS build 2 | 3 | # Resolve app dependencies. 4 | WORKDIR /app 5 | COPY pubspec.* ./ 6 | RUN dart pub get 7 | 8 | # Copy app source code and AOT compile it. 9 | COPY . . 10 | # Ensure packages are still up-to-date if anything has changed 11 | RUN dart pub get --offline 12 | RUN dart pub run build_runner build --delete-conflicting-outputs 13 | RUN dart compile exe bin/server.dart -o bin/server 14 | 15 | # Build minimal serving image from AOT-compiled `/server` and required system 16 | # libraries and configuration files stored in `/runtime/` from the build stage. 17 | FROM scratch 18 | COPY --from=build /runtime/ / 19 | COPY --from=build /app/bin/server /app/bin/ 20 | 21 | # Start server. 22 | EXPOSE 8080 23 | ENTRYPOINT ["/app/bin/server", "--signature-type=cloudevent"] 24 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Functions Framework for Dart 2 | 3 | These docs will help you get started with the [Functions Framework for Dart], 4 | an open source **FaaS** (Function as a Service) framework that lets you write 5 | and deploy lightweight, event-driven functions. 6 | 7 | ## Contents 8 | 9 | [Introduction](01-introduction.md) 10 | 11 | ### Setting up 12 | 13 | [Install dartfn](quickstarts/00-install-dartfn.md) 14 | 15 | ### Quickstarts 16 | 17 | [Quickstart: Dart](quickstarts/01-quickstart-dart.md) 18 | [Quickstart: Docker](quickstarts/02-quickstart-docker.md) 19 | [Quickstart: Cloud Run](quickstarts/03-quickstart-cloudrun.md) 20 | 21 | --- 22 | [[next]](01-introduction.md) 23 | 24 | 25 | [functions framework for dart]: 26 | https://github.com/GoogleCloudPlatform/functions-framework-dart 27 | -------------------------------------------------------------------------------- /dartfn/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: dartfn 2 | description: > 3 | A tools package for managing FaaS (Function as a service) portable Dart functions projects 4 | # After changing the version, run `pub run build_runner build`. 5 | version: 0.4.7-wip 6 | homepage: https://github.com/GoogleCloudPlatform/functions-framework-dart 7 | 8 | resolution: workspace 9 | environment: 10 | sdk: ^3.6.0 11 | 12 | executables: 13 | dartfn: 14 | 15 | dependencies: 16 | args: ^2.1.1 17 | collection: ^1.15.0 18 | http: ^1.0.0 19 | io: ^1.0.0 20 | path: ^1.8.0 21 | 22 | dev_dependencies: 23 | build: ^2.1.0 24 | build_config: ^1.0.0 25 | build_runner: ^2.1.0 26 | build_verify: ^3.0.0 27 | build_version: ^2.1.1 28 | dart_flutter_team_lints: ^3.0.0 29 | glob: ^2.0.0 30 | grinder: ^0.9.0 31 | source_gen: '>=1.0.0 <3.0.0' 32 | test: ^1.16.6 33 | yaml: ^3.1.0 34 | -------------------------------------------------------------------------------- /google_cloud/test/src/terminate_print.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | import 'package:google_cloud/google_cloud.dart'; 15 | 16 | Future main() async { 17 | print('waiting for termination'); 18 | await waitForTerminate(); 19 | print('done!'); 20 | } 21 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /dartfn/templates/json/Dockerfile: -------------------------------------------------------------------------------- 1 | # Official Dart image: https://hub.docker.com/_/dart 2 | # Specify the Dart SDK base image version using dart: (ex: dart:2.14) 3 | FROM dart:stable AS build 4 | 5 | # Resolve app dependencies. 6 | WORKDIR /app 7 | COPY pubspec.* ./ 8 | RUN dart pub get 9 | 10 | # Copy app source code and AOT compile it. 11 | COPY . . 12 | # Ensure packages are still up-to-date if anything has changed 13 | RUN dart pub get --offline 14 | RUN dart pub run build_runner build --delete-conflicting-outputs 15 | RUN dart compile exe bin/server.dart -o bin/server 16 | 17 | # Build minimal serving image from AOT-compiled `/server` and required system 18 | # libraries and configuration files stored in `/runtime/` from the build stage. 19 | FROM scratch 20 | COPY --from=build /runtime/ / 21 | COPY --from=build /app/bin/server /app/bin/ 22 | 23 | # Start server. 24 | EXPOSE 8080 25 | ENTRYPOINT ["/app/bin/server"] 26 | -------------------------------------------------------------------------------- /dartfn/templates/helloworld/Dockerfile: -------------------------------------------------------------------------------- 1 | # Official Dart image: https://hub.docker.com/_/dart 2 | # Specify the Dart SDK base image version using dart: (ex: dart:2.14) 3 | FROM dart:stable AS build 4 | 5 | # Resolve app dependencies. 6 | WORKDIR /app 7 | COPY pubspec.* ./ 8 | RUN dart pub get 9 | 10 | # Copy app source code and AOT compile it. 11 | COPY . . 12 | # Ensure packages are still up-to-date if anything has changed 13 | RUN dart pub get --offline 14 | RUN dart pub run build_runner build --delete-conflicting-outputs 15 | RUN dart compile exe bin/server.dart -o bin/server 16 | 17 | # Build minimal serving image from AOT-compiled `/server` and required system 18 | # libraries and configuration files stored in `/runtime/` from the build stage. 19 | FROM scratch 20 | COPY --from=build /runtime/ / 21 | COPY --from=build /app/bin/server /app/bin/ 22 | 23 | # Start server. 24 | EXPOSE 8080 25 | ENTRYPOINT ["/app/bin/server"] 26 | -------------------------------------------------------------------------------- /functions_framework_builder/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: functions_framework_builder 2 | version: 0.4.11-wip 3 | description: Builder for package:functions_framework 4 | repository: https://github.com/GoogleCloudPlatform/functions-framework-dart 5 | 6 | resolution: workspace 7 | environment: 8 | sdk: ^3.6.0 9 | 10 | dependencies: 11 | analyzer: '>=6.9.0 <8.0.0' 12 | build: ^2.3.1 13 | build_config: ^1.0.0 14 | collection: ^1.17.0 15 | dart_style: '>=2.3.7 <4.0.0' 16 | # There is a tight version constraint because the builder has a strict 17 | # dependency on all features exposed. 18 | functions_framework: '>=0.4.0 <0.4.5' 19 | glob: ^2.0.0 20 | meta: ^1.7.0 21 | path: ^1.8.0 22 | shelf: ^1.0.0 23 | source_gen: '>=1.4.0 <3.0.0' 24 | source_helper: ^1.3.3 25 | 26 | dev_dependencies: 27 | build_test: ^2.1.2 28 | dart_flutter_team_lints: ^3.0.0 29 | package_config: ^2.0.0 30 | stream_transform: ^2.0.0 31 | test: ^1.21.6 32 | -------------------------------------------------------------------------------- /dartfn/tool/builder/builder.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:build/build.dart'; 16 | import 'package:source_gen/source_gen.dart'; 17 | 18 | import 'src/code_generator.dart'; 19 | 20 | Builder builder([BuilderOptions? _]) => PartBuilder( 21 | [ 22 | DataGenerator(), 23 | ], 24 | '.g.dart', 25 | ); 26 | -------------------------------------------------------------------------------- /dartfn/templates/cloudevent/Dockerfile: -------------------------------------------------------------------------------- 1 | # Official Dart image: https://hub.docker.com/_/dart 2 | # Specify the Dart SDK base image version using dart: (ex: dart:2.14) 3 | FROM dart:stable AS build 4 | 5 | # resolve app dependencies. 6 | WORKDIR /app 7 | COPY pubspec.* ./ 8 | RUN dart pub get 9 | 10 | # copy app source code and aot compile it. 11 | COPY . . 12 | # ensure packages are still up-to-date if anything has changed 13 | RUN dart pub get --offline 14 | RUN dart pub run build_runner build --delete-conflicting-outputs 15 | RUN dart compile exe bin/server.dart -o bin/server 16 | 17 | # build minimal serving image from aot-compiled `/server` and required system 18 | # libraries and configuration files stored in `/runtime/` from the build stage. 19 | FROM scratch 20 | COPY --from=build /runtime/ / 21 | COPY --from=build /app/bin/server /app/bin/ 22 | 23 | # start server. 24 | EXPOSE 8080 25 | ENTRYPOINT ["/app/bin/server", "--signature-type=cloudevent"] 26 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | **/ios/Flutter/.last_build_id 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .pub-cache/ 30 | pubspec.lock 31 | 32 | # Web related 33 | lib/generated_plugin_registrant.dart 34 | 35 | # Symbolication related 36 | app.*.symbols 37 | 38 | # Obfuscation related 39 | app.*.map.json 40 | 41 | # Android Studio will place build artifacts here 42 | /android/app/debug 43 | /android/app/profile 44 | /android/app/release 45 | 46 | assets/config/prod.json 47 | -------------------------------------------------------------------------------- /google_cloud/Dockerfile: -------------------------------------------------------------------------------- 1 | # Corresponds to the sample app in example/ 2 | # Can be deployed directly to Cloud Run via `gcloud run deploy` 3 | 4 | # Official Dart image: https://hub.docker.com/_/dart 5 | # Specify the Dart SDK base image version using dart: (ex: dart:2.12) 6 | FROM dart:stable AS build 7 | 8 | # Resolve app dependencies. 9 | WORKDIR /app 10 | COPY pubspec.* ./ 11 | RUN dart pub get 12 | 13 | # Copy app source code and AOT compile it. 14 | COPY . . 15 | # Ensure packages are still up-to-date if anything has changed 16 | RUN dart pub get --offline 17 | RUN dart compile exe example/example.dart -o example/server 18 | 19 | # Build minimal serving image from AOT-compiled `/server` and required system 20 | # libraries and configuration files stored in `/runtime/` from the build stage. 21 | FROM scratch 22 | COPY --from=build /runtime/ / 23 | COPY --from=build /app/example/server /app/example/ 24 | 25 | # Start server. 26 | EXPOSE 8080 27 | CMD ["/app/example/server"] 28 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # https://dart.dev/guides/language/analysis-options 2 | include: package:dart_flutter_team_lints/analysis_options.yaml 3 | 4 | analyzer: 5 | language: 6 | strict-casts: true 7 | strict-inference: true 8 | strict-raw-types: true 9 | 10 | linter: 11 | rules: 12 | - avoid_bool_literals_in_conditional_expressions 13 | - avoid_classes_with_only_static_members 14 | - avoid_private_typedef_functions 15 | - avoid_redundant_argument_values 16 | - avoid_returning_null 17 | - avoid_returning_this 18 | - avoid_unused_constructor_parameters 19 | - avoid_void_async 20 | - cancel_subscriptions 21 | - cascade_invocations 22 | - join_return_with_assignment 23 | - literal_only_boolean_expressions 24 | - missing_whitespace_between_adjacent_strings 25 | - no_runtimeType_toString 26 | - prefer_const_declarations 27 | - prefer_expression_function_bodies 28 | - prefer_final_locals 29 | - require_trailing_commas 30 | - use_string_buffers 31 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /dartfn/test/ensure_build_test.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | @Tags(['presubmit-only']) 16 | library; 17 | 18 | import 'package:build_verify/build_verify.dart'; 19 | import 'package:test/test.dart'; 20 | 21 | void main() { 22 | test( 23 | 'ensure_build', 24 | () => expectBuildClean(packageRelativeDirectory: 'dartfn'), 25 | timeout: const Timeout.factor(2), 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /google_cloud/lib/src/bad_configuration_exception.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// Thrown if a service is configured incorrectly. 16 | class BadConfigurationException implements Exception { 17 | final String message; 18 | final String? details; 19 | 20 | BadConfigurationException(this.message, {this.details}); 21 | 22 | @override 23 | String toString() => 'BadConfiguration: $message'; 24 | } 25 | -------------------------------------------------------------------------------- /integration_test/test/ensure_build_test.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | @Tags(['presubmit-only']) 16 | library; 17 | 18 | import 'package:build_verify/build_verify.dart'; 19 | import 'package:test/test.dart'; 20 | 21 | void main() { 22 | test( 23 | 'ensure_build', 24 | () => expectBuildClean(packageRelativeDirectory: 'integration_test'), 25 | timeout: const Timeout.factor(2), 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /functions_framework/test/ensure_build_test.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | @Tags(['presubmit-only']) 16 | library; 17 | 18 | import 'package:build_verify/build_verify.dart'; 19 | import 'package:test/test.dart'; 20 | 21 | void main() { 22 | test( 23 | 'ensure_build', 24 | () => expectBuildClean(packageRelativeDirectory: 'functions_framework'), 25 | timeout: const Timeout.factor(2), 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /examples/json/lib/functions.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'functions.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | GreetingRequest _$GreetingRequestFromJson(Map json) => 10 | GreetingRequest( 11 | name: json['name'] as String?, 12 | ); 13 | 14 | Map _$GreetingRequestToJson(GreetingRequest instance) => 15 | { 16 | 'name': instance.name, 17 | }; 18 | 19 | GreetingResponse _$GreetingResponseFromJson(Map json) => 20 | GreetingResponse( 21 | salutation: json['salutation'] as String, 22 | name: json['name'] as String, 23 | ); 24 | 25 | Map _$GreetingResponseToJson(GreetingResponse instance) => 26 | { 27 | 'salutation': instance.salutation, 28 | 'name': instance.name, 29 | }; 30 | -------------------------------------------------------------------------------- /dartfn/lib/src/generators/json.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import '../stagehand/common.dart' as common; 16 | 17 | part 'json.g.dart'; 18 | 19 | /// A generator for a pub library. 20 | class JsonFunctionGenerator extends common.DefaultGenerator { 21 | JsonFunctionGenerator() 22 | : super( 23 | 'json', 24 | 'A sample Functions Framework project for handling JSON.', 25 | _data, 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /dartfn/templates/json/lib/functions.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'functions.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | GreetingRequest _$GreetingRequestFromJson(Map json) => 10 | GreetingRequest( 11 | name: json['name'] as String?, 12 | ); 13 | 14 | Map _$GreetingRequestToJson(GreetingRequest instance) => 15 | { 16 | 'name': instance.name, 17 | }; 18 | 19 | GreetingResponse _$GreetingResponseFromJson(Map json) => 20 | GreetingResponse( 21 | salutation: json['salutation'] as String, 22 | name: json['name'] as String, 23 | ); 24 | 25 | Map _$GreetingResponseToJson(GreetingResponse instance) => 26 | { 27 | 'salutation': instance.salutation, 28 | 'name': instance.name, 29 | }; 30 | -------------------------------------------------------------------------------- /dartfn/templates/helloworld/test/function_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:http/http.dart'; 4 | import 'package:test/test.dart'; 5 | import 'package:test_process/test_process.dart'; 6 | 7 | const defaultTimeout = Timeout(Duration(seconds: 3)); 8 | 9 | void main() { 10 | test('defaults', () async { 11 | final proc = await TestProcess.start('dart', ['bin/server.dart']); 12 | 13 | await expectLater( 14 | proc.stdout, 15 | emitsThrough('Listening on :8080'), 16 | ); 17 | 18 | final response = await get(Uri.parse('http://localhost:8080')); 19 | expect(response.statusCode, 200); 20 | expect(response.body, 'Hello, World!'); 21 | 22 | await expectLater( 23 | proc.stdout, 24 | emitsThrough(endsWith('GET [200] /')), 25 | ); 26 | 27 | proc.signal(ProcessSignal.sigterm); 28 | await proc.shouldExit(0); 29 | 30 | await expectLater( 31 | proc.stdout, 32 | emitsThrough('Received signal SIGTERM - closing'), 33 | ); 34 | }, timeout: defaultTimeout); 35 | } 36 | -------------------------------------------------------------------------------- /examples/fullstack/backend/lib/api_types.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'api_types.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | GreetingRequest _$GreetingRequestFromJson(Map json) => 10 | GreetingRequest( 11 | name: json['name'] as String?, 12 | ); 13 | 14 | Map _$GreetingRequestToJson(GreetingRequest instance) => 15 | { 16 | 'name': instance.name, 17 | }; 18 | 19 | GreetingResponse _$GreetingResponseFromJson(Map json) => 20 | GreetingResponse( 21 | salutation: json['salutation'] as String, 22 | name: json['name'] as String, 23 | ); 24 | 25 | Map _$GreetingResponseToJson(GreetingResponse instance) => 26 | { 27 | 'salutation': instance.salutation, 28 | 'name': instance.name, 29 | }; 30 | -------------------------------------------------------------------------------- /dartfn/lib/src/generators/helloworld.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import '../stagehand/common.dart' as common; 16 | 17 | part 'helloworld.g.dart'; 18 | 19 | /// A generator for a pub library. 20 | class HelloWorldGenerator extends common.DefaultGenerator { 21 | HelloWorldGenerator() 22 | : super( 23 | 'helloworld', 24 | 'A sample "Hello, World!" Functions Framework project.', 25 | _data, 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /examples/fullstack/frontend-cli/lib/api_types.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'api_types.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | GreetingRequest _$GreetingRequestFromJson(Map json) => 10 | GreetingRequest( 11 | name: json['name'] as String?, 12 | ); 13 | 14 | Map _$GreetingRequestToJson(GreetingRequest instance) => 15 | { 16 | 'name': instance.name, 17 | }; 18 | 19 | GreetingResponse _$GreetingResponseFromJson(Map json) => 20 | GreetingResponse( 21 | salutation: json['salutation'] as String, 22 | name: json['name'] as String, 23 | ); 24 | 25 | Map _$GreetingResponseToJson(GreetingResponse instance) => 26 | { 27 | 'salutation': instance.salutation, 28 | 'name': instance.name, 29 | }; 30 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/lib/services/api_types.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'api_types.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | GreetingRequest _$GreetingRequestFromJson(Map json) => 10 | GreetingRequest( 11 | name: json['name'] as String?, 12 | ); 13 | 14 | Map _$GreetingRequestToJson(GreetingRequest instance) => 15 | { 16 | 'name': instance.name, 17 | }; 18 | 19 | GreetingResponse _$GreetingResponseFromJson(Map json) => 20 | GreetingResponse( 21 | salutation: json['salutation'] as String, 22 | name: json['name'] as String, 23 | ); 24 | 25 | Map _$GreetingResponseToJson(GreetingResponse instance) => 26 | { 27 | 'salutation': instance.salutation, 28 | 'name': instance.name, 29 | }; 30 | -------------------------------------------------------------------------------- /dartfn/templates/cloudevent/tool/binary_mode_request.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:http/http.dart'; 4 | 5 | FutureOr main() async { 6 | const requestUrl = 'http://localhost:8080'; 7 | 8 | const headers = { 9 | 'content-type': 'application/json', 10 | 'ce-specversion': '1.0', 11 | 'ce-type': 'google.cloud.pubsub.topic.publish', 12 | 'ce-time': '2020-09-05T03:56:24Z', 13 | 'ce-id': '1234-1234-1234', 14 | 'ce-source': 'urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66', 15 | 'ce-subject': 'BINARY_MODE_CLOUDEVENT_SAMPLE', 16 | }; 17 | 18 | const body = r''' 19 | { 20 | "subscription": "projects/my-project/subscriptions/my-subscription", 21 | "message": { 22 | "@type": "type.googleapis.com/google.pubsub.v1.PubsubMessage", 23 | "attributes": { 24 | "attr1":"attr1-value" 25 | }, 26 | "data": "dGVzdCBtZXNzYWdlIDM=" 27 | } 28 | }'''; 29 | 30 | final response = 31 | await post(Uri.parse(requestUrl), headers: headers, body: body); 32 | print('response.statusCode: ${response.statusCode}'); 33 | } 34 | -------------------------------------------------------------------------------- /dartfn/lib/src/generators/cloudevent.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import '../stagehand/common.dart' as common; 16 | 17 | part 'cloudevent.g.dart'; 18 | 19 | /// A generator for a pub library. 20 | class CloudEventFunctionGenerator extends common.DefaultGenerator { 21 | CloudEventFunctionGenerator() 22 | : super( 23 | 'cloudevent', 24 | 'A sample Functions Framework project for handling a cloudevent.', 25 | _data, 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /dartfn/templates/cloudevent/tool/structured_mode_request.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:http/http.dart'; 4 | 5 | FutureOr main() async { 6 | const requestUrl = 'http://localhost:8080'; 7 | 8 | const headers = { 9 | 'content-type': 'application/json', 10 | }; 11 | 12 | const body = r''' 13 | { 14 | "specversion": "1.0", 15 | "type": "google.cloud.pubsub.topic.publish", 16 | "time": "2020-09-05T03:56:24.000Z", 17 | "id": "1234-1234-1234", 18 | "source": "urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66", 19 | "subject": "STRUCTURED_MODE_CLOUDEVENT_SAMPLE", 20 | "data": { 21 | "subscription": "projects/my-project/subscriptions/my-subscription", 22 | "message": { 23 | "@type": "type.googleapis.com/google.pubsub.v1.PubsubMessage", 24 | "attributes": { 25 | "attr1":"attr1-value" 26 | }, 27 | "data": "dGVzdCBtZXNzYWdlIDM=" 28 | } 29 | } 30 | }'''; 31 | 32 | final response = 33 | await post(Uri.parse(requestUrl), headers: headers, body: body); 34 | print('response.statusCode: ${response.statusCode}'); 35 | } 36 | -------------------------------------------------------------------------------- /examples/raw_cloudevent/lib/functions.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:convert'; 16 | import 'dart:io'; 17 | 18 | import 'package:functions_framework/functions_framework.dart'; 19 | 20 | const _encoder = JsonEncoder.withIndent(' '); 21 | 22 | @CloudFunction() 23 | void function(CloudEvent event, RequestContext context) { 24 | context.logger 25 | .info('[CloudEvent] source: ${event.source}, subject: ${event.subject}'); 26 | stderr.writeln(_encoder.convert(event)); 27 | } 28 | -------------------------------------------------------------------------------- /google_cloud/lib/src/constants.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// The standard environment variable for specifying the port a service should 16 | /// listen on. 17 | const portEnvironmentKey = 'PORT'; 18 | 19 | /// The default port a service should listen on if [portEnvironmentKey] is not 20 | /// set. 21 | const defaultListenPort = 8080; 22 | 23 | /// Standard header used by 24 | /// [Cloud Trace](https://cloud.google.com/trace/docs/setup). 25 | const cloudTraceContextHeader = 'x-cloud-trace-context'; 26 | -------------------------------------------------------------------------------- /dartfn/lib/src/generators.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'generators/cloudevent.dart'; 16 | import 'generators/helloworld.dart'; 17 | import 'generators/json.dart'; 18 | import 'stagehand/stagehand.dart'; 19 | 20 | /// A sorted list of Dart Functions Framework project generators. 21 | final List generators = [ 22 | HelloWorldGenerator(), 23 | JsonFunctionGenerator(), 24 | CloudEventFunctionGenerator(), 25 | ]..sort(); 26 | 27 | Generator getGenerator(String id) => generators.singleWhere((g) => g.id == id); 28 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/google/type/latlng.pbjson.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: google/type/latlng.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names, library_prefixes 9 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 10 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 11 | 12 | import 'dart:convert' as $convert; 13 | import 'dart:core' as $core; 14 | import 'dart:typed_data' as $typed_data; 15 | 16 | @$core.Deprecated('Use latLngDescriptor instead') 17 | const LatLng$json = { 18 | '1': 'LatLng', 19 | '2': [ 20 | {'1': 'latitude', '3': 1, '4': 1, '5': 1, '10': 'latitude'}, 21 | {'1': 'longitude', '3': 2, '4': 1, '5': 1, '10': 'longitude'}, 22 | ], 23 | }; 24 | 25 | /// Descriptor for `LatLng`. Decode as a `google.protobuf.DescriptorProto`. 26 | final $typed_data.Uint8List latLngDescriptor = $convert.base64Decode( 27 | 'CgZMYXRMbmcSGgoIbGF0aXR1ZGUYASABKAFSCGxhdGl0dWRlEhwKCWxvbmdpdHVkZRgCIAEoAV' 28 | 'IJbG9uZ2l0dWRl'); 29 | -------------------------------------------------------------------------------- /examples/hello/lib/functions.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:functions_framework/functions_framework.dart'; 16 | import 'package:shelf/shelf.dart'; 17 | 18 | @CloudFunction() 19 | Response function(Request request) => Response.ok('Hello, World!'); 20 | 21 | // Overriding the default 'function' also works, but you will need 22 | // to ensure to set the FUNCTION_TARGET environment variable for the 23 | // process to 'handleGet' as well. 24 | //@CloudFunction() 25 | //Response handleGet(Request request) => Response.ok('Hello, World!'); 26 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/google/protobuf/timestamp.pbjson.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: google/protobuf/timestamp.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names, library_prefixes 9 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 10 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 11 | 12 | import 'dart:convert' as $convert; 13 | import 'dart:core' as $core; 14 | import 'dart:typed_data' as $typed_data; 15 | 16 | @$core.Deprecated('Use timestampDescriptor instead') 17 | const Timestamp$json = { 18 | '1': 'Timestamp', 19 | '2': [ 20 | {'1': 'seconds', '3': 1, '4': 1, '5': 3, '10': 'seconds'}, 21 | {'1': 'nanos', '3': 2, '4': 1, '5': 5, '10': 'nanos'}, 22 | ], 23 | }; 24 | 25 | /// Descriptor for `Timestamp`. Decode as a `google.protobuf.DescriptorProto`. 26 | final $typed_data.Uint8List timestampDescriptor = $convert.base64Decode( 27 | 'CglUaW1lc3RhbXASGAoHc2Vjb25kcxgBIAEoA1IHc2Vjb25kcxIUCgVuYW5vcxgCIAEoBVIFbm' 28 | 'Fub3M='); 29 | -------------------------------------------------------------------------------- /examples/hello/bin/server.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | // Copyright 2021 Google LLC 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | import 'package:functions_framework/serve.dart'; 17 | import 'package:hello_world_function/functions.dart' as function_library; 18 | 19 | Future main(List args) async { 20 | await serve(args, _nameToFunctionTarget); 21 | } 22 | 23 | FunctionTarget? _nameToFunctionTarget(String name) => switch (name) { 24 | 'function' => FunctionTarget.http( 25 | function_library.function, 26 | ), 27 | _ => null 28 | }; 29 | -------------------------------------------------------------------------------- /dartfn/templates/helloworld/bin/server.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | // Copyright 2021 Google LLC 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | import 'package:__projectName__/functions.dart' as function_library; 17 | import 'package:functions_framework/serve.dart'; 18 | 19 | Future main(List args) async { 20 | await serve(args, _nameToFunctionTarget); 21 | } 22 | 23 | FunctionTarget? _nameToFunctionTarget(String name) => switch (name) { 24 | 'function' => FunctionTarget.http( 25 | function_library.function, 26 | ), 27 | _ => null 28 | }; 29 | -------------------------------------------------------------------------------- /dartfn/templates/cloudevent/bin/server.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | // Copyright 2021 Google LLC 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | import 'package:__projectName__/functions.dart' as function_library; 17 | import 'package:functions_framework/serve.dart'; 18 | 19 | Future main(List args) async { 20 | await serve(args, _nameToFunctionTarget); 21 | } 22 | 23 | FunctionTarget? _nameToFunctionTarget(String name) => switch (name) { 24 | 'function' => FunctionTarget.cloudEventWithContext( 25 | function_library.function, 26 | ), 27 | _ => null 28 | }; 29 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/bin/server.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | // Copyright 2021 Google LLC 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | import 'package:example_protobuf_firestore/functions.dart' as function_library; 17 | import 'package:functions_framework/serve.dart'; 18 | 19 | Future main(List args) async { 20 | await serve(args, _nameToFunctionTarget); 21 | } 22 | 23 | FunctionTarget? _nameToFunctionTarget(String name) => switch (name) { 24 | 'function' => FunctionTarget.cloudEventWithContext( 25 | function_library.function, 26 | ), 27 | _ => null 28 | }; 29 | -------------------------------------------------------------------------------- /examples/raw_cloudevent/bin/server.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | // Copyright 2021 Google LLC 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | import 'package:example_raw_cloudevent_function/functions.dart' 17 | as function_library; 18 | import 'package:functions_framework/serve.dart'; 19 | 20 | Future main(List args) async { 21 | await serve(args, _nameToFunctionTarget); 22 | } 23 | 24 | FunctionTarget? _nameToFunctionTarget(String name) => switch (name) { 25 | 'function' => FunctionTarget.cloudEventWithContext( 26 | function_library.function, 27 | ), 28 | _ => null 29 | }; 30 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | $(PRODUCT_COPYRIGHT) 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/windows/runner/run_loop.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_RUN_LOOP_H_ 2 | #define RUNNER_RUN_LOOP_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | // A runloop that will service events for Flutter instances as well 10 | // as native messages. 11 | class RunLoop { 12 | public: 13 | RunLoop(); 14 | ~RunLoop(); 15 | 16 | // Prevent copying 17 | RunLoop(RunLoop const&) = delete; 18 | RunLoop& operator=(RunLoop const&) = delete; 19 | 20 | // Runs the run loop until the application quits. 21 | void Run(); 22 | 23 | // Registers the given Flutter instance for event servicing. 24 | void RegisterFlutterInstance( 25 | flutter::FlutterEngine* flutter_instance); 26 | 27 | // Unregisters the given Flutter instance from event servicing. 28 | void UnregisterFlutterInstance( 29 | flutter::FlutterEngine* flutter_instance); 30 | 31 | private: 32 | using TimePoint = std::chrono::steady_clock::time_point; 33 | 34 | // Processes all currently pending messages for registered Flutter instances. 35 | TimePoint ProcessFlutterMessages(); 36 | 37 | std::set flutter_instances_; 38 | }; 39 | 40 | #endif // RUNNER_RUN_LOOP_H_ 41 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Official Dart image: https://hub.docker.com/_/dart 2 | # Specify the Dart SDK base image version using dart: (ex: dart:2.12) 3 | FROM dart:stable AS build 4 | 5 | # cache deps 6 | WORKDIR /app 7 | COPY ./functions_framework/pubspec.yaml /app/functions_framework/ 8 | COPY ./functions_framework_builder/pubspec.yaml /app/functions_framework_builder/ 9 | COPY ./google_cloud/pubspec.yaml /app/google_cloud/ 10 | COPY ./integration_test/pubspec.yaml /app/integration_test/ 11 | 12 | WORKDIR /app/integration_test 13 | RUN dart pub get 14 | 15 | # As long as pubspecs haven't changed, all deps should be cached and only 16 | # new image layers from here on need to get rebuild for modified sources. 17 | COPY . .. 18 | RUN dart pub get --offline 19 | 20 | RUN dart pub run build_runner build --delete-conflicting-outputs 21 | RUN dart compile exe bin/server.dart -o bin/server 22 | 23 | ######################## 24 | # Build minimal serving image from AOT-compiled `/server` and required system 25 | # libraries and configuration files stored in `/runtime/` from the build stage. 26 | FROM scratch 27 | COPY --from=build /runtime/ / 28 | COPY --from=build /app/integration_test/bin/server /app/bin/ 29 | EXPOSE 8080 30 | ENTRYPOINT ["/app/bin/server"] 31 | -------------------------------------------------------------------------------- /functions_framework/lib/src/cloud_function.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:meta/meta_meta.dart'; 16 | import 'package:shelf/shelf.dart'; 17 | 18 | /// Use as an annotation on [Function]s that will be exposed as endpoints. 19 | /// 20 | /// Can only be used on public, top-level functions that are compatible with 21 | /// [Handler] from `package:shelf`. 22 | @Target({TargetKind.function}) 23 | class CloudFunction { 24 | /// The name used to register the function in the function framework. 25 | /// 26 | /// If `null`, the name of the [Function] is used. 27 | final String? target; 28 | 29 | const CloudFunction({this.target}); 30 | } 31 | -------------------------------------------------------------------------------- /google_cloud/README.md: -------------------------------------------------------------------------------- 1 | [![pub package](https://img.shields.io/pub/v/google_cloud.svg)](https://pub.dev/packages/google_cloud) 2 | [![package publisher](https://img.shields.io/pub/publisher/google_cloud.svg)](https://pub.dev/packages/google_cloud/publisher) 3 | 4 | > NOTE: This is a **community-supported project**, meaning there is no official 5 | > level of support. The code is not covered by any SLA or deprecation policy. 6 | > 7 | > Feel free to start a [discussion] to share thoughts or open [issues] for bugs 8 | > and feature requests. 9 | 10 | Utilities for running Dart code correctly on the Google Cloud Platform. 11 | 12 | Features include: 13 | 14 | - Accessing the configured listening port. 15 | - Accessing the configured Google Cloud [project ID]. 16 | - Support [structured logging]. 17 | 18 | Expect more features in the future. 19 | 20 | [project id]: 21 | https://cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects 22 | [issues]: https://github.com/GoogleCloudPlatform/functions-framework-dart/issues 23 | [discussion]: 24 | https://github.com/GoogleCloudPlatform/functions-framework-dart/discussions 25 | [structured logging]: 26 | https://cloud.google.com/functions/docs/monitoring/logging#writing_structured_logs 27 | -------------------------------------------------------------------------------- /dartfn/test/generators_test.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:dartfn/src/generators.dart'; 16 | import 'package:dartfn/src/stagehand/stagehand.dart'; 17 | import 'package:test/test.dart'; 18 | 19 | void main() { 20 | group('generators', () { 21 | for (var generator in generators) { 22 | test(generator.id, () => validate(getGenerator(generator.id))); 23 | } 24 | }); 25 | } 26 | 27 | void validate(Generator generator) { 28 | expect(generator.id, isNot(contains(' '))); 29 | expect(generator.description, endsWith('.')); 30 | expect(generator.entrypoint, isNotNull); 31 | expect(generator.getInstallInstructions(), isNotNull); 32 | } 33 | -------------------------------------------------------------------------------- /functions_framework_builder/test/test_examples/complex_target_name_handlers.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:functions_framework/functions_framework.dart'; 16 | 17 | @CloudFunction(target: "'single quotes'") 18 | void function1(CloudEvent request) => throw UnimplementedError(); 19 | 20 | @CloudFunction(target: '"double quotes"') 21 | void function2(CloudEvent request) => throw UnimplementedError(); 22 | 23 | @CloudFunction(target: r'$dollar signs$') 24 | void function3(CloudEvent request) => throw UnimplementedError(); 25 | 26 | @CloudFunction(target: 'white space\t\n\r\nall over') 27 | void function4(CloudEvent request) => throw UnimplementedError(); 28 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "run_loop.h" 10 | #include "win32_window.h" 11 | 12 | // A window that does nothing but host a Flutter view. 13 | class FlutterWindow : public Win32Window { 14 | public: 15 | // Creates a new FlutterWindow driven by the |run_loop|, hosting a 16 | // Flutter view running |project|. 17 | explicit FlutterWindow(RunLoop* run_loop, 18 | const flutter::DartProject& project); 19 | virtual ~FlutterWindow(); 20 | 21 | protected: 22 | // Win32Window: 23 | bool OnCreate() override; 24 | void OnDestroy() override; 25 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 26 | LPARAM const lparam) noexcept override; 27 | 28 | private: 29 | // The run loop driving events for this window. 30 | RunLoop* run_loop_; 31 | 32 | // The project to run. 33 | flutter::DartProject project_; 34 | 35 | // The Flutter instance hosted by this window. 36 | std::unique_ptr flutter_controller_; 37 | }; 38 | 39 | #endif // RUNNER_FLUTTER_WINDOW_H_ 40 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/functions.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:convert'; 16 | import 'dart:io'; 17 | 18 | import 'package:functions_framework/functions_framework.dart'; 19 | 20 | import 'src/function_types.dart'; 21 | 22 | @CloudFunction() 23 | void function(CloudEvent event, RequestContext context) { 24 | context.logger.info('event subject: ${event.subject}'); 25 | context.logger.debug(jsonEncode(context.request.headers)); 26 | context.responseHeaders['x-data-runtime-types'] = 27 | event.data.runtimeType.toString(); 28 | 29 | final instance = DocumentEventData.fromBuffer(event.data as List); 30 | stderr.writeln(jsonEncode(instance.toProto3Json())); 31 | } 32 | -------------------------------------------------------------------------------- /integration_test/lib/src/pub_sub_types.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'pub_sub_types.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | PubSub _$PubSubFromJson(Map json) => PubSub( 10 | PubSubMessage.fromJson(json['message'] as Map), 11 | json['subscription'] as String, 12 | ); 13 | 14 | Map _$PubSubToJson(PubSub instance) => { 15 | 'message': instance.message, 16 | 'subscription': instance.subscription, 17 | }; 18 | 19 | PubSubMessage _$PubSubMessageFromJson(Map json) => 20 | PubSubMessage( 21 | json['data'] as String, 22 | json['messageId'] as String, 23 | DateTime.parse(json['publishTime'] as String), 24 | Map.from(json['attributes'] as Map), 25 | ); 26 | 27 | Map _$PubSubMessageToJson(PubSubMessage instance) => 28 | { 29 | 'data': instance.data, 30 | 'attributes': instance.attributes, 31 | 'messageId': instance.messageId, 32 | 'publishTime': instance.publishTime.toIso8601String(), 33 | }; 34 | -------------------------------------------------------------------------------- /functions_framework_builder/test/test_examples/valid_json_type_handlers.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:async'; 16 | 17 | import 'package:functions_framework/functions_framework.dart'; 18 | 19 | @CloudFunction() 20 | void syncFunction(num request) => throw UnimplementedError(); 21 | 22 | @CloudFunction() 23 | Future asyncFunction(num request) => throw UnimplementedError(); 24 | 25 | @CloudFunction() 26 | FutureOr futureOrFunction(num request) => throw UnimplementedError(); 27 | 28 | @CloudFunction() 29 | void extraParam(num request, [int? other]) => throw UnimplementedError(); 30 | 31 | @CloudFunction() 32 | void optionalParam([num? request, int? other]) => throw UnimplementedError(); 33 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/test/test_shared.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | /// This is a Firestore update record in protobuf 4 | final protobytes = base64Decode( 5 | 'CoIBClFwcm9qZWN0cy9kYXJ0LXJlZGlyZWN0b3IvZGF0YWJhc2VzLyhkZWZhdWx0KS9kb2N1bWVu' 6 | 'dHMvdXNlcnMvZ2hYTnRlUElGbWRET0JIM2lFTUgSEQoEbmFtZRIJigEGbHVjaWE0GgwI6+KupAYQ' 7 | 'iMa2qgIiDAjF1sukBhCY2qvFARKCAQpRcHJvamVjdHMvZGFydC1yZWRpcmVjdG9yL2RhdGFiYXNl' 8 | 'cy8oZGVmYXVsdCkvZG9jdW1lbnRzL3VzZXJzL2doWE50ZVBJRm1kRE9CSDNpRU1IEhEKBG5hbWUS' 9 | 'CYoBBmx1Y2lhMxoMCOvirqQGEIjGtqoCIgwI8o60pAYQmJa6igMaBgoEbmFtZQ==', 10 | ); 11 | 12 | const jsonOutput = { 13 | 'value': { 14 | 'name': 15 | 'projects/dart-redirector/databases/(default)/documents/users/ghXNtePIFmdDOBH3iEMH', 16 | 'fields': { 17 | 'name': {'stringValue': 'lucia4'}, 18 | }, 19 | 'createTime': '2023-06-16T00:48:43.625845Z', 20 | 'updateTime': '2023-06-21T12:21:25.413855Z', 21 | }, 22 | 'oldValue': { 23 | 'name': 24 | 'projects/dart-redirector/databases/(default)/documents/users/ghXNtePIFmdDOBH3iEMH', 25 | 'fields': { 26 | 'name': {'stringValue': 'lucia3'}, 27 | }, 28 | 'createTime': '2023-06-16T00:48:43.625845Z', 29 | 'updateTime': '2023-06-17T01:08:02.827231Z', 30 | }, 31 | 'updateMask': { 32 | 'fieldPaths': ['name'], 33 | }, 34 | }; 35 | -------------------------------------------------------------------------------- /functions_framework_builder/test/test_examples/valid_cloud_event_handlers.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:async'; 16 | 17 | import 'package:functions_framework/functions_framework.dart'; 18 | 19 | @CloudFunction() 20 | void syncFunction(CloudEvent request) => throw UnimplementedError(); 21 | 22 | @CloudFunction() 23 | Future asyncFunction(CloudEvent request) => throw UnimplementedError(); 24 | 25 | @CloudFunction() 26 | FutureOr futureOrFunction(CloudEvent request) => 27 | throw UnimplementedError(); 28 | 29 | @CloudFunction() 30 | void optionalParam([CloudEvent? request]) => throw UnimplementedError(); 31 | 32 | @CloudFunction() 33 | void objectParam(Object request) => throw UnimplementedError(); 34 | -------------------------------------------------------------------------------- /examples/protobuf_firestore/lib/src/google/protobuf/struct.pbenum.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: google/protobuf/struct.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names, library_prefixes 9 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 10 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 11 | 12 | import 'dart:core' as $core; 13 | 14 | import 'package:protobuf/protobuf.dart' as $pb; 15 | 16 | /// `NullValue` is a singleton enumeration to represent the null value for the 17 | /// `Value` type union. 18 | /// 19 | /// The JSON representation for `NullValue` is JSON `null`. 20 | class NullValue extends $pb.ProtobufEnum { 21 | /// Null value. 22 | static const NullValue NULL_VALUE = 23 | NullValue._(0, _omitEnumNames ? '' : 'NULL_VALUE'); 24 | 25 | static const $core.List values = [ 26 | NULL_VALUE, 27 | ]; 28 | 29 | static final $core.Map<$core.int, NullValue> _byValue = 30 | $pb.ProtobufEnum.initByValue(values); 31 | static NullValue? valueOf($core.int value) => _byValue[value]; 32 | 33 | const NullValue._(super.v, super.n); 34 | } 35 | 36 | const _omitEnumNames = $core.bool.fromEnvironment('protobuf.omit_enum_names'); 37 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/lib/config.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:convert'; 16 | 17 | import 'package:flutter/services.dart'; 18 | 19 | enum Environment { 20 | dev, 21 | prod, 22 | } 23 | 24 | class Config { 25 | final String greetingsUrl; 26 | 27 | Config({required this.greetingsUrl}); 28 | 29 | static Future load(Environment env) async { 30 | final file = 'assets/config/${env.name}.json'; 31 | final data = await rootBundle.loadString(file); 32 | final json = jsonDecode(data) as Map; 33 | return Config(greetingsUrl: json['greetingUrl'] as String); 34 | } 35 | 36 | static Future parse(String environment) async { 37 | final env = Environment.values.byName(environment); 38 | return await load(env); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /functions_framework/lib/src/targets/http_targets.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:async'; 16 | 17 | import 'package:google_cloud/google_cloud.dart'; 18 | import 'package:shelf/shelf.dart'; 19 | 20 | import '../function_target.dart'; 21 | import '../typedefs.dart'; 22 | 23 | class HttpFunctionTarget extends FunctionTarget { 24 | final Handler _function; 25 | 26 | @override 27 | FutureOr handler(Request request) => _function(request); 28 | 29 | HttpFunctionTarget(this._function); 30 | } 31 | 32 | class HttpWithLoggerFunctionTarget extends FunctionTarget { 33 | final HandlerWithLogger _function; 34 | 35 | @override 36 | FutureOr handler(Request request) => 37 | _function(request, currentLogger); 38 | 39 | HttpWithLoggerFunctionTarget(this._function); 40 | } 41 | -------------------------------------------------------------------------------- /dartfn/lib/src/printer.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | typedef PrintFunc = void Function(Object obj); 16 | 17 | /// Printer provides a basic interface for user-facing tool output & logs. 18 | class Printer { 19 | final PrintFunc stdout; 20 | final PrintFunc stderr; 21 | 22 | Printer([PrintFunc? stdout, PrintFunc? stderr]) 23 | : stdout = stdout ?? print, 24 | stderr = stderr ?? stdout ?? print; 25 | 26 | Printer.fromPrinter(Printer printer) 27 | : stdout = printer.stdout, 28 | stderr = printer.stderr; 29 | 30 | void write([Object? obj]) { 31 | stdout(obj ?? ''); 32 | } 33 | 34 | void info(Object obj) { 35 | stdout(obj); 36 | } 37 | 38 | void warning(Object obj) { 39 | stdout(obj); 40 | } 41 | 42 | void error(Object obj) { 43 | stderr(obj); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/lib/main.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:flutter/material.dart'; 16 | import 'package:provider/provider.dart'; 17 | 18 | import 'config.dart'; 19 | import 'models/app_model.dart'; 20 | import 'views/home_page.dart'; 21 | 22 | Future main() async { 23 | WidgetsFlutterBinding.ensureInitialized(); 24 | const env = String.fromEnvironment('ENV', defaultValue: 'dev'); 25 | final config = await Config.parse(env); 26 | 27 | runApp( 28 | ChangeNotifierProvider( 29 | create: (context) => AppModel(config), 30 | child: App(), 31 | ), 32 | ); 33 | } 34 | 35 | class App extends StatelessWidget { 36 | @override 37 | Widget build(BuildContext context) => MaterialApp( 38 | theme: ThemeData.dark(), 39 | home: HomePage(), 40 | ); 41 | } 42 | -------------------------------------------------------------------------------- /dartfn/lib/src/cli/http_utils.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:convert'; 16 | 17 | import 'package:http/http.dart' as http; 18 | 19 | Future _getPubInfo(String appName) async { 20 | final pubInfo = Uri.https('pub.dev', '/packages/$appName.json'); 21 | return await http.get(pubInfo); 22 | } 23 | 24 | List _getPubVersions(http.Response resp) => 25 | ((jsonDecode(resp.body) as Map)['versions'] as List).cast(); 26 | 27 | /// Check pub.dev for newer versions. 28 | Future checkPubForLaterVersion(String appName, String version) async => 29 | Future(() async { 30 | final resp = await _getPubInfo(appName); 31 | final versions = _getPubVersions(resp); 32 | return (version != versions.last) ? versions.last : null; 33 | }).catchError((e) => null); 34 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "run_loop.h" 7 | #include "utils.h" 8 | 9 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 10 | _In_ wchar_t *command_line, _In_ int show_command) { 11 | // Attach to console when present (e.g., 'flutter run') or create a 12 | // new console when running with a debugger. 13 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 14 | CreateAndAttachConsole(); 15 | } 16 | 17 | // Initialize COM, so that it is available for use in the library and/or 18 | // plugins. 19 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 20 | 21 | RunLoop run_loop; 22 | 23 | flutter::DartProject project(L"data"); 24 | 25 | std::vector command_line_arguments = 26 | GetCommandLineArguments(); 27 | 28 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 29 | 30 | FlutterWindow window(&run_loop, project); 31 | Win32Window::Point origin(10, 10); 32 | Win32Window::Size size(1280, 720); 33 | if (!window.CreateAndShow(L"frontend", origin, size)) { 34 | return EXIT_FAILURE; 35 | } 36 | window.SetQuitOnClose(true); 37 | 38 | run_loop.Run(); 39 | 40 | ::CoUninitialize(); 41 | return EXIT_SUCCESS; 42 | } 43 | -------------------------------------------------------------------------------- /integration_test/lib/src/json_handlers.dart: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | import 'dart:async'; 14 | 15 | import 'package:functions_framework/functions_framework.dart'; 16 | 17 | import 'pub_sub_types.dart'; 18 | 19 | @CloudFunction() 20 | void pubSubHandler(PubSub pubSub, RequestContext context) { 21 | print('subscription: ${pubSub.subscription}'); 22 | context.logger.info('subscription: ${pubSub.subscription}'); 23 | context.responseHeaders['subscription'] = pubSub.subscription; 24 | context.responseHeaders['multi'] = ['item1', 'item2']; 25 | } 26 | 27 | @CloudFunction() 28 | FutureOr jsonHandler( 29 | Map request, 30 | RequestContext context, 31 | ) { 32 | print('Keys: ${request.keys.join(', ')}'); 33 | context.responseHeaders['key_count'] = request.keys.length.toString(); 34 | context.responseHeaders['multi'] = ['item1', 'item2']; 35 | return request.isEmpty; 36 | } 37 | -------------------------------------------------------------------------------- /dartfn/templates/json/test/function_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:io'; 3 | 4 | import 'package:http/http.dart'; 5 | import 'package:test/test.dart'; 6 | import 'package:test_process/test_process.dart'; 7 | 8 | import 'package:__projectName__/functions.dart'; 9 | 10 | const defaultTimeout = Timeout(Duration(seconds: 3)); 11 | 12 | void main() { 13 | test('defaults', () async { 14 | final proc = await TestProcess.start('dart', ['bin/server.dart']); 15 | 16 | await expectLater( 17 | proc.stdout, 18 | emitsThrough('Listening on :8080'), 19 | ); 20 | 21 | const body = ''' 22 | { 23 | "name": "World" 24 | }'''; 25 | 26 | const headers = {'content-type': 'application/json'}; 27 | 28 | final response = await post( 29 | Uri.parse('http://localhost:8080'), 30 | headers: headers, 31 | body: body, 32 | ); 33 | expect(response.statusCode, 200); 34 | 35 | final data = json.decode(response.body) as Map; 36 | final actualResponse = GreetingResponse.fromJson(data); 37 | 38 | final expectedResponse = 39 | GreetingResponse(salutation: 'Hello', name: 'World'); 40 | 41 | expect(actualResponse, expectedResponse); 42 | 43 | proc.signal(ProcessSignal.sigterm); 44 | await proc.shouldExit(0); 45 | 46 | await expectLater( 47 | proc.stdout, 48 | emitsThrough('Received signal SIGTERM - closing'), 49 | ); 50 | }, timeout: defaultTimeout); 51 | } 52 | -------------------------------------------------------------------------------- /google_cloud/lib/google_cloud.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | export 'src/bad_configuration_exception.dart' show BadConfigurationException; 16 | export 'src/bad_request_exception.dart' show BadRequestException; 17 | export 'src/constants.dart' 18 | show cloudTraceContextHeader, defaultListenPort, portEnvironmentKey; 19 | export 'src/gcp_project.dart' 20 | show 21 | computeProjectId, 22 | gcpProjectIdEnvironmentVariables, 23 | projectIdFromEnvironment, 24 | projectIdFromMetadataServer; 25 | export 'src/log_severity.dart' show LogSeverity, RequestLogger; 26 | export 'src/logging.dart' 27 | show 28 | badRequestMiddleware, 29 | cloudLoggingMiddleware, 30 | createLoggingMiddleware, 31 | currentLogger; 32 | export 'src/serve.dart' show listenPort, serveHandler; 33 | export 'src/terminate.dart' show waitForTerminate; 34 | -------------------------------------------------------------------------------- /.github/workflows/no-response.yml: -------------------------------------------------------------------------------- 1 | # A workflow to close issues where the author hasn't responded to a request for 2 | # more information; see https://github.com/actions/stale. 3 | 4 | name: No Response 5 | 6 | # Run as a daily cron. 7 | on: 8 | schedule: 9 | # Every day at 8am 10 | - cron: '0 8 * * *' 11 | 12 | # All permissions not specified are set to 'none'. 13 | permissions: 14 | issues: write 15 | pull-requests: write 16 | 17 | jobs: 18 | no-response: 19 | runs-on: ubuntu-latest 20 | if: ${{ github.repository_owner == 'GoogleCloudPlatform' }} 21 | steps: 22 | - uses: actions/stale@5f858e3efba33a5ca4407a664cc011ad407f2008 23 | with: 24 | # Don't automatically mark inactive issues+PRs as stale. 25 | days-before-stale: -1 26 | # Close needs-info issues and PRs after 14 days of inactivity. 27 | days-before-close: 14 28 | stale-issue-label: "needs-info" 29 | close-issue-message: > 30 | Without additional information we're not able to resolve this issue. 31 | Feel free to add more info or respond to any questions above and we 32 | can reopen the case. Thanks for your contribution! 33 | stale-pr-label: "needs-info" 34 | close-pr-message: > 35 | Without additional information we're not able to resolve this PR. 36 | Feel free to add more info or respond to any questions above. 37 | Thanks for your contribution! 38 | -------------------------------------------------------------------------------- /examples/fullstack/backend/lib/api_types.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:json_annotation/json_annotation.dart'; 16 | 17 | part 'api_types.g.dart'; 18 | 19 | @JsonSerializable() 20 | class GreetingRequest { 21 | final String? name; 22 | 23 | GreetingRequest({this.name}); 24 | 25 | factory GreetingRequest.fromJson(Map json) => 26 | _$GreetingRequestFromJson(json); 27 | 28 | Map toJson() => _$GreetingRequestToJson(this); 29 | } 30 | 31 | @JsonSerializable() 32 | class GreetingResponse { 33 | final String salutation; 34 | final String name; 35 | 36 | GreetingResponse({required this.salutation, required this.name}); 37 | 38 | factory GreetingResponse.fromJson(Map json) => 39 | _$GreetingResponseFromJson(json); 40 | 41 | Map toJson() => _$GreetingResponseToJson(this); 42 | } 43 | -------------------------------------------------------------------------------- /examples/fullstack/frontend-cli/lib/api_types.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:json_annotation/json_annotation.dart'; 16 | 17 | part 'api_types.g.dart'; 18 | 19 | @JsonSerializable() 20 | class GreetingRequest { 21 | final String? name; 22 | 23 | GreetingRequest({this.name}); 24 | 25 | factory GreetingRequest.fromJson(Map json) => 26 | _$GreetingRequestFromJson(json); 27 | 28 | Map toJson() => _$GreetingRequestToJson(this); 29 | } 30 | 31 | @JsonSerializable() 32 | class GreetingResponse { 33 | final String salutation; 34 | final String name; 35 | 36 | GreetingResponse({required this.salutation, required this.name}); 37 | 38 | factory GreetingResponse.fromJson(Map json) => 39 | _$GreetingResponseFromJson(json); 40 | 41 | Map toJson() => _$GreetingResponseToJson(this); 42 | } 43 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/lib/services/api_types.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:json_annotation/json_annotation.dart'; 16 | 17 | part 'api_types.g.dart'; 18 | 19 | @JsonSerializable() 20 | class GreetingRequest { 21 | final String? name; 22 | 23 | GreetingRequest({this.name}); 24 | 25 | factory GreetingRequest.fromJson(Map json) => 26 | _$GreetingRequestFromJson(json); 27 | 28 | Map toJson() => _$GreetingRequestToJson(this); 29 | } 30 | 31 | @JsonSerializable() 32 | class GreetingResponse { 33 | final String salutation; 34 | final String name; 35 | 36 | GreetingResponse({required this.salutation, required this.name}); 37 | 38 | factory GreetingResponse.fromJson(Map json) => 39 | _$GreetingResponseFromJson(json); 40 | 41 | Map toJson() => _$GreetingResponseToJson(this); 42 | } 43 | -------------------------------------------------------------------------------- /dartfn/tool/bashcmds: -------------------------------------------------------------------------------- 1 | # Helper commands to source into your bash environment during development 2 | 3 | scriptdir="$PWD/$(dirname $(echo ${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}))" 4 | pubdir="${scriptdir}/.." 5 | bindir="${pubdir}/bin" 6 | 7 | if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; then 8 | echo "This bash shell script (${BASH_SOURCE[0]}) is meant to be sourced in, not executed. Try:" 9 | echo " source bashcmds" 10 | echo "or from the repo root:" 11 | echo " source tools/bashcmds" 12 | exit 1; 13 | fi 14 | 15 | # dart build - generates encoded templates from source 16 | function db() { 17 | (cd $pubdir; dart run build_runner build --delete-conflicting-outputs "$@") 18 | } 19 | 20 | # run -> dart run bin/dartfn 21 | function run() { 22 | dart run "${bindir}/dartfn.dart" "$@" 23 | } 24 | 25 | # activate 26 | function da() { 27 | local p=${1:-$pubdir} 28 | dart pub global activate --overwrite -s path $p 29 | } 30 | 31 | # deactivate 32 | function dx() { 33 | dart pub global deactivate dartfn 34 | } 35 | 36 | # reset env 37 | function clean() { 38 | unset -f db 39 | unset -f run 40 | unset -f da 41 | unset -f dx 42 | unset -f clean 43 | } 44 | 45 | # print help 46 | function dh() { 47 | echo "db - (re)build bin/dartfn with updated templates" 48 | echo "run - run updated bin/dartfn" 49 | echo "da - activate bin/dartfn" 50 | echo "dx - deactivate bin/dartfn" 51 | echo "clean - remove these commands from the environment" 52 | echo "dh - print this help" 53 | } 54 | 55 | dh 56 | -------------------------------------------------------------------------------- /functions_framework/lib/functions_framework.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// Provides the features needed to *define* Cloud Functions. 16 | /// 17 | /// ```dart 18 | /// // lib/functions.dart 19 | /// import 'package:functions_framework/functions_framework.dart'; 20 | /// import 'package:shelf/shelf.dart'; 21 | /// 22 | /// @CloudFunction() 23 | /// Response function(Request request) => Response.ok('Hello, World!'); 24 | /// ``` 25 | library; 26 | 27 | export 'package:google_cloud/google_cloud.dart' 28 | show BadRequestException, LogSeverity, RequestLogger; 29 | 30 | export 'src/cloud_event.dart' show CloudEvent; 31 | export 'src/cloud_function.dart' show CloudFunction; 32 | export 'src/request_context.dart' show RequestContext; 33 | export 'src/typedefs.dart' 34 | show 35 | CloudEventHandler, 36 | CloudEventWithContextHandler, 37 | HandlerWithLogger, 38 | JsonHandler, 39 | JsonWithContextHandler; 40 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/lib/models/app_model.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:flutter/material.dart'; 16 | 17 | import '../config.dart'; 18 | import '../services/api.dart'; 19 | import '../services/api_types.dart'; 20 | 21 | class AppModel with ChangeNotifier { 22 | final Config _config; 23 | late Greeting _greeting; 24 | 25 | String? name; 26 | String? salutation; 27 | 28 | List pastGreetings = []; 29 | 30 | AppModel(this._config) { 31 | _greeting = Greeting(_config.greetingsUrl); 32 | } 33 | 34 | Future greet(String? name) async { 35 | try { 36 | final greetingResponse = await _greeting.getGreeting(name); 37 | pastGreetings.add(greetingResponse); 38 | this.name = greetingResponse.name; 39 | salutation = greetingResponse.salutation; 40 | notifyListeners(); 41 | } on Exception catch (e) { 42 | // TODO: actual error handling strategy 43 | print(e); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /functions_framework_builder/test/test_examples/valid_custom_type_handlers.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:async'; 16 | 17 | import 'package:functions_framework/functions_framework.dart'; 18 | 19 | @CloudFunction() 20 | void syncFunction(JsonType request) => throw UnimplementedError(); 21 | 22 | @CloudFunction() 23 | Future asyncFunction(JsonType request) => throw UnimplementedError(); 24 | 25 | @CloudFunction() 26 | FutureOr futureOrFunction(JsonType request) => throw UnimplementedError(); 27 | 28 | @CloudFunction() 29 | void extraParam(JsonType request, [int? other]) => throw UnimplementedError(); 30 | 31 | @CloudFunction() 32 | void optionalParam([JsonType? request, int? other]) => 33 | throw UnimplementedError(); 34 | 35 | class JsonType { 36 | // ignore: avoid_unused_constructor_parameters 37 | factory JsonType.fromJson(Map json) => 38 | throw UnimplementedError(); 39 | 40 | Map toJson() => throw UnimplementedError(); 41 | } 42 | -------------------------------------------------------------------------------- /examples/fullstack/backend/test/function_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:io'; 3 | 4 | import 'package:backend/functions.dart'; 5 | import 'package:http/http.dart'; 6 | import 'package:test/test.dart'; 7 | import 'package:test_process/test_process.dart'; 8 | 9 | const defaultTimeout = Timeout(Duration(seconds: 3)); 10 | 11 | void main() { 12 | test('defaults', timeout: defaultTimeout, () async { 13 | final proc = await TestProcess.start('dart', ['bin/server.dart']); 14 | 15 | await expectLater( 16 | proc.stdout, 17 | emitsThrough('Listening on :8080'), 18 | ); 19 | 20 | const body = ''' 21 | { 22 | "name": "World" 23 | }'''; 24 | 25 | const headers = {'content-type': 'application/json'}; 26 | 27 | final response = await post( 28 | Uri.parse('http://localhost:8080'), 29 | headers: headers, 30 | body: body, 31 | ); 32 | expect(response.statusCode, 200); 33 | 34 | final data = json.decode(response.body) as Map; 35 | final actualResponse = GreetingResponse.fromJson(data); 36 | 37 | // Use any salutation from the list of salutations 38 | final expectedResponse = 39 | GreetingResponse(salutation: salutations[0], name: 'World'); 40 | 41 | expect(salutations, contains(actualResponse.salutation)); 42 | expect(actualResponse.name, expectedResponse.name); 43 | 44 | proc.signal(ProcessSignal.sigterm); 45 | await proc.shouldExit(0); 46 | 47 | await expectLater( 48 | proc.stdout, 49 | emitsThrough('Received signal SIGTERM - closing'), 50 | ); 51 | }); 52 | } 53 | -------------------------------------------------------------------------------- /functions_framework/lib/src/function_target.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:async'; 16 | 17 | import 'package:shelf/shelf.dart'; 18 | 19 | import 'function_config.dart'; 20 | import 'targets/cloud_event_targets.dart'; 21 | import 'targets/http_targets.dart'; 22 | import 'typedefs.dart'; 23 | 24 | export 'targets/json_targets.dart'; 25 | 26 | abstract class FunctionTarget { 27 | FunctionType get type => FunctionType.http; 28 | 29 | FunctionTarget(); 30 | 31 | factory FunctionTarget.http(Handler function) = HttpFunctionTarget; 32 | 33 | factory FunctionTarget.httpWithLogger( 34 | HandlerWithLogger function, 35 | ) = HttpWithLoggerFunctionTarget; 36 | 37 | factory FunctionTarget.cloudEvent( 38 | CloudEventHandler function, 39 | ) = CloudEventFunctionTarget; 40 | 41 | factory FunctionTarget.cloudEventWithContext( 42 | CloudEventWithContextHandler function, 43 | ) = CloudEventWithContextFunctionTarget; 44 | 45 | FutureOr handler(Request request); 46 | } 47 | -------------------------------------------------------------------------------- /functions_framework/lib/src/run.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:async'; 16 | import 'dart:io'; 17 | 18 | import 'package:shelf/shelf.dart'; 19 | import 'package:shelf/shelf_io.dart' as shelf_io; 20 | 21 | Future run( 22 | int port, 23 | Handler handler, 24 | Future shutdownSignal, 25 | Middleware loggingMiddleware, 26 | ) async { 27 | final server = await shelf_io.serve( 28 | loggingMiddleware 29 | .addMiddleware(_forbiddenAssetMiddleware) 30 | .addHandler(handler), 31 | InternetAddress.anyIPv4, 32 | port, 33 | ); 34 | print('Listening on :${server.port}'); 35 | 36 | final force = await shutdownSignal; 37 | await server.close(force: force); 38 | } 39 | 40 | const _forbiddenAssets = {'robots.txt', 'favicon.ico'}; 41 | 42 | Handler _forbiddenAssetMiddleware(Handler innerHandler) => (Request request) { 43 | if (_forbiddenAssets.contains(request.url.path)) { 44 | return Response.notFound('Not found.'); 45 | } 46 | return innerHandler(request); 47 | }; 48 | -------------------------------------------------------------------------------- /functions_framework/lib/src/request_context.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:google_cloud/google_cloud.dart'; 16 | import 'package:meta/meta.dart'; 17 | import 'package:shelf/shelf.dart'; 18 | 19 | import 'cloud_event.dart'; 20 | 21 | /// Provides access to a [RequestLogger], the source [Request] and response 22 | /// headers for a typed function handler. 23 | /// 24 | /// Can be used as an optional second parameter in a function definition that 25 | /// accepts a [CloudEvent] or a custom type. 26 | class RequestContext { 27 | final RequestLogger logger; 28 | 29 | /// Access to the source [Request] object. 30 | /// 31 | /// Accessing `read` or `readAsString` will throw an error because the body 32 | /// of the [Request] has already been read. 33 | final Request request; 34 | 35 | final responseHeaders = */ Object>{}; 36 | 37 | RequestContext._(this.request) : logger = currentLogger; 38 | } 39 | 40 | @internal 41 | RequestContext contextForRequest(Request request) => RequestContext._(request); 42 | -------------------------------------------------------------------------------- /dartfn/lib/src/cli/console.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import '../printer.dart'; 16 | import 'terminal.dart'; 17 | 18 | /// Console provides input and output support for the tool running in a 19 | /// terminal. 20 | class Console extends ConsoleBase with ConsolePrinter, ConsoleInput { 21 | Console([Printer? out]) : super(out ?? TerminalPrinter()); 22 | 23 | @override 24 | PrintFunc get stderr => out.stdout; 25 | 26 | @override 27 | PrintFunc get stdout => out.stderr; 28 | } 29 | 30 | abstract class ConsoleBase { 31 | final Printer out; 32 | 33 | ConsoleBase(this.out); 34 | } 35 | 36 | mixin ConsolePrinter on ConsoleBase implements Printer { 37 | @override 38 | void write([Object? obj]) { 39 | out.write(obj); 40 | } 41 | 42 | @override 43 | void info(Object obj) { 44 | out.info(obj); 45 | } 46 | 47 | @override 48 | void warning(Object obj) { 49 | out.warning(obj); 50 | } 51 | 52 | @override 53 | void error(Object obj) { 54 | out.error(obj); 55 | } 56 | } 57 | 58 | mixin ConsoleInput on ConsoleBase {} 59 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "app_icon_16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "app_icon_32.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "app_icon_32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "app_icon_64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "app_icon_128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "app_icon_256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "app_icon_256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "app_icon_512.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "app_icon_512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "app_icon_1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /examples/hello/test/function_test.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:io'; 16 | 17 | import 'package:http/http.dart'; 18 | import 'package:test/test.dart'; 19 | import 'package:test_process/test_process.dart'; 20 | 21 | const defaultTimeout = Timeout(Duration(seconds: 3)); 22 | 23 | void main() { 24 | test('defaults', timeout: defaultTimeout, () async { 25 | final proc = await TestProcess.start('dart', ['bin/server.dart']); 26 | 27 | await expectLater( 28 | proc.stdout, 29 | emitsThrough('Listening on :8080'), 30 | ); 31 | 32 | final response = await get(Uri.parse('http://localhost:8080')); 33 | expect(response.statusCode, 200); 34 | expect(response.body, 'Hello, World!'); 35 | 36 | await expectLater( 37 | proc.stdout, 38 | emitsThrough(endsWith('GET [200] /')), 39 | ); 40 | 41 | proc.signal(ProcessSignal.sigterm); 42 | await proc.shouldExit(0); 43 | 44 | await expectLater( 45 | proc.stdout, 46 | emitsThrough('Received signal SIGTERM - closing'), 47 | ); 48 | }); 49 | } 50 | -------------------------------------------------------------------------------- /dartfn/lib/src/cli/terminal.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import '../printer.dart'; 16 | 17 | /// TerminalPrinter is a printer for writing decorated/colorized output to a 18 | /// terminal for the CLI. 19 | class TerminalPrinter extends Printer { 20 | TerminalPrinter([ 21 | PrintFunc super.stdout = print, 22 | PrintFunc super.stderr = print, 23 | ]); 24 | 25 | TerminalPrinter.fromPrinter(super.printer) : super.fromPrinter(); 26 | 27 | @override 28 | void write([Object? obj]) { 29 | stdout(obj ?? ''); 30 | } 31 | 32 | @override 33 | void info(Object obj) { 34 | stdout(obj); 35 | } 36 | 37 | @override 38 | void warning(Object obj) { 39 | stdout('Warning! $obj'); 40 | } 41 | 42 | @override 43 | void error(Object obj) { 44 | if (obj is Exception) { 45 | try { 46 | // ignore: avoid_dynamic_calls 47 | obj = (obj as dynamic).message as Object; 48 | // ignore: avoid_catching_errors 49 | } on NoSuchMethodError { 50 | // ok 51 | } 52 | } 53 | stderr('Error: $obj'); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /integration_test/lib/src/pub_sub_types.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:convert'; 16 | import 'dart:typed_data'; 17 | 18 | import 'package:json_annotation/json_annotation.dart'; 19 | 20 | part 'pub_sub_types.g.dart'; 21 | 22 | @JsonSerializable() 23 | class PubSub { 24 | final PubSubMessage message; 25 | final String subscription; 26 | 27 | PubSub(this.message, this.subscription); 28 | 29 | factory PubSub.fromJson(Map json) => _$PubSubFromJson(json); 30 | 31 | Map toJson() => _$PubSubToJson(this); 32 | } 33 | 34 | @JsonSerializable() 35 | class PubSubMessage { 36 | final String data; 37 | final Map attributes; 38 | final String messageId; 39 | final DateTime publishTime; 40 | 41 | Uint8List dataBytes() => base64Decode(data); 42 | 43 | PubSubMessage(this.data, this.messageId, this.publishTime, this.attributes); 44 | 45 | factory PubSubMessage.fromJson(Map json) => 46 | _$PubSubMessageFromJson(json); 47 | 48 | Map toJson() => _$PubSubMessageToJson(this); 49 | } 50 | -------------------------------------------------------------------------------- /examples/raw_cloudevent/tool/binary_mode_request.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:async'; 16 | 17 | import 'package:http/http.dart'; 18 | 19 | FutureOr main() async { 20 | const requestUrl = 'http://localhost:8080'; 21 | 22 | const headers = { 23 | 'content-type': 'application/json', 24 | 'ce-specversion': '1.0', 25 | 'ce-type': 'google.cloud.pubsub.topic.publish', 26 | 'ce-time': '2020-09-05T03:56:24Z', 27 | 'ce-id': '1234-1234-1234', 28 | 'ce-source': 'urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66', 29 | 'ce-subject': 'BINARY_MODE_CLOUDEVENT_SAMPLE', 30 | }; 31 | 32 | const body = r''' 33 | { 34 | "subscription": "projects/my-project/subscriptions/my-subscription", 35 | "message": { 36 | "@type": "type.googleapis.com/google.pubsub.v1.PubsubMessage", 37 | "attributes": { 38 | "attr1":"attr1-value" 39 | }, 40 | "data": "dGVzdCBtZXNzYWdlIDM=" 41 | } 42 | }'''; 43 | 44 | final response = 45 | await post(Uri.parse(requestUrl), headers: headers, body: body); 46 | print('response.statusCode: ${response.statusCode}'); 47 | } 48 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/lib/services/api.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:convert'; 16 | import 'dart:io'; 17 | 18 | import 'package:http/http.dart' as http; 19 | 20 | import 'api_types.dart'; 21 | 22 | class Greeting { 23 | late Uri _uri; 24 | 25 | Greeting(String uri) { 26 | _uri = Uri.parse(uri); 27 | } 28 | 29 | // TODO: better strategy for surfacing errors, http statuscodes 30 | Future getGreeting(String? name) async { 31 | final greetingRequest = GreetingRequest(name: name); 32 | 33 | final body = jsonEncode(greetingRequest.toJson()); 34 | 35 | final res = await http.post( 36 | _uri, 37 | headers: {'content-type': 'application/json'}, 38 | body: body, 39 | ); 40 | 41 | if (res.statusCode == HttpStatus.ok) { 42 | final greetingResponse = GreetingResponse.fromJson( 43 | jsonDecode(res.body) as Map, 44 | ); 45 | return greetingResponse; 46 | } 47 | 48 | throw Exception( 49 | 'Error: unexpected HTTP status code: ${res.statusCode.toString()}', 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/raw_cloudevent/tool/structured_mode_request.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:async'; 16 | 17 | import 'package:http/http.dart'; 18 | 19 | FutureOr main() async { 20 | const requestUrl = 'http://localhost:8080'; 21 | 22 | const headers = { 23 | 'content-type': 'application/json', 24 | }; 25 | 26 | const body = r''' 27 | { 28 | "specversion": "1.0", 29 | "type": "google.cloud.pubsub.topic.publish", 30 | "time": "2020-09-05T03:56:24.000Z", 31 | "id": "1234-1234-1234", 32 | "source": "urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66", 33 | "subject": "STRUCTURED_MODE_CLOUDEVENT_SAMPLE", 34 | "data": { 35 | "subscription": "projects/my-project/subscriptions/my-subscription", 36 | "message": { 37 | "@type": "type.googleapis.com/google.pubsub.v1.PubsubMessage", 38 | "attributes": { 39 | "attr1":"attr1-value" 40 | }, 41 | "data": "dGVzdCBtZXNzYWdlIDM=" 42 | } 43 | } 44 | }'''; 45 | 46 | final response = 47 | await post(Uri.parse(requestUrl), headers: headers, body: body); 48 | print('response.statusCode: ${response.statusCode}'); 49 | } 50 | -------------------------------------------------------------------------------- /dartfn/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.4.7-wip 2 | 3 | - Use latest `dart_flutter_team_lints` version. 4 | - Require Dart 3.5 5 | 6 | ## 0.4.6 7 | 8 | - Ignore file cleanup. 9 | - Require Dart 3.0 10 | - Support `package:http` v1 11 | 12 | ## 0.4.5 13 | 14 | - Fix generated code in `couldevent` template. 15 | 16 | ## 0.4.4 17 | 18 | - Add missing `package:lints` dependency. 19 | ([#296](https://github.com/GoogleCloudPlatform/functions-framework-dart/issues/296)) 20 | - Add reference to Dart docs on what files to ignore in generated `.gitignore` 21 | files. 22 | ([#297](https://github.com/GoogleCloudPlatform/functions-framework-dart/issues/297)) 23 | - Add default `analysis_options.yaml` file to `cloudevent` template. 24 | 25 | ## 0.4.3 26 | 27 | - Fix template Dockerfiles 28 | ([#268](https://github.com/GoogleCloudPlatform/functions-framework-dart/issues/268)) 29 | 30 | ## 0.4.2 31 | 32 | - Update templates to use official Dart Docker images. 33 | - Update templates to use `package:lints`. 34 | 35 | ## 0.4.1 36 | 37 | - Require Dart 2.12 38 | - Support the latest `package:json_serializable` in the JSON template. 39 | 40 | ## 0.4.0 41 | 42 | - Updated templates for functions_framework 0.4.0 43 | 44 | ## 0.3.1 45 | 46 | - Renamed the package to `dartfn` so `dart pub global activate dartfn` works. 47 | 48 | ## 0.3.0 49 | 50 | The first version is `0.3.0` to align with the rest of published Functions 51 | Framework packages. This package is intended to support tools for working with 52 | Functions Framework projects. In this early iteration, a CLI tool (`dartfn`) is 53 | provided with a `generate` command for scaffolding new projects into an empty 54 | directory. Three initial generator templates are available (`helloworld`, 55 | `json`, and `cloudevent`). 56 | -------------------------------------------------------------------------------- /examples/fullstack/backend/lib/functions.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:math'; 16 | 17 | import 'package:functions_framework/functions_framework.dart'; 18 | 19 | import 'api_types.dart'; 20 | 21 | // Export api_types so builder can use them when generating `bin/server.dart`. 22 | export 'api_types.dart'; 23 | 24 | @CloudFunction() 25 | GreetingResponse function(GreetingRequest request, RequestContext context) { 26 | final name = request.name ?? 'World'; 27 | final response = 28 | GreetingResponse(salutation: _randomSalutation(), name: name); 29 | context.logger.info('greetingResponse: ${response.toJson()}'); 30 | return response; 31 | } 32 | 33 | String _randomSalutation() => salutations[_random.nextInt(salutations.length)]; 34 | 35 | final _random = Random(); 36 | 37 | const salutations = [ 38 | '안녕하세요', // annyeonghaseyo 39 | 'こんにちは', // Kon'nichiwa 40 | '你好', // Nǐ hǎo 41 | 'Привет', // Privet 42 | 'สวัสดี', // S̄wạs̄dī 43 | 'Aloha', 44 | 'Bonjour', 45 | 'Hello', 46 | 'Ciao', 47 | 'Dzień dobry', 48 | 'Hola', 49 | 'Hallo', 50 | 'Kon’nichiwa', 51 | 'Namaste', 52 | 'Salam', 53 | 'Shalom', 54 | 'Tena koutou', 55 | ]; 56 | -------------------------------------------------------------------------------- /integration_test/test/logging_test.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:test/test.dart'; 16 | import 'package:test_process/test_process.dart'; 17 | 18 | import 'src/test_utils.dart'; 19 | 20 | Future _startServerTest() => startServerTest( 21 | arguments: [ 22 | '--target', 23 | 'loggingHandler', 24 | ], 25 | expectedListeningPort: 0, 26 | ); 27 | 28 | void main() { 29 | test('test all log severities', () async { 30 | final proc = await _startServerTest(); 31 | 32 | final requestUrl = 'http://localhost:$autoPort/'; 33 | final response = await get(requestUrl); 34 | expect(response.statusCode, 200); 35 | expect(response.body, ''); 36 | 37 | await finishServerTest( 38 | proc, 39 | requestOutput: emitsInOrder( 40 | [ 41 | 'default', 42 | 'DEBUG: debug', 43 | 'INFO: info', 44 | 'NOTICE: notice', 45 | 'WARNING: warning', 46 | 'ERROR: error', 47 | 'CRITICAL: critical', 48 | 'ALERT: alert', 49 | 'EMERGENCY: emergency', 50 | endsWith('GET [200] /'), 51 | ], 52 | ), 53 | ); 54 | }); 55 | } 56 | -------------------------------------------------------------------------------- /integration_test/lib/src/conformance_handlers.dart: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | import 'dart:convert'; 14 | import 'dart:io'; 15 | 16 | import 'package:functions_framework/functions_framework.dart'; 17 | import 'package:shelf/shelf.dart'; 18 | 19 | import 'utils.dart'; 20 | 21 | @CloudFunction() 22 | Future conformanceHttp(Request request) async { 23 | final content = await request.readAsString(); 24 | 25 | File('function_output.json').writeAsStringSync( 26 | content, 27 | ); 28 | 29 | final buffer = StringBuffer() 30 | ..writeln('Hello, conformance test!') 31 | ..writeln('HEADERS') 32 | ..writeln(encodeJsonPretty(request.headers)) 33 | ..writeln('BODY') 34 | ..writeln(encodeJsonPretty(jsonDecode(content))); 35 | 36 | final output = buffer.toString(); 37 | print(output); 38 | return Response.ok(output); 39 | } 40 | 41 | @CloudFunction() 42 | void conformanceCloudEvent(CloudEvent event) { 43 | final eventEncoded = encodeJsonPretty(event); 44 | File('function_output.json').writeAsStringSync( 45 | eventEncoded, 46 | ); 47 | 48 | final buffer = StringBuffer() 49 | ..writeln('Hello, conformance test!') 50 | ..writeln('EVENT') 51 | ..writeln(eventEncoded); 52 | 53 | print(buffer.toString()); 54 | } 55 | -------------------------------------------------------------------------------- /dartfn/templates/json/bin/server.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | // Copyright 2021 Google LLC 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | import 'package:__projectName__/functions.dart' as function_library; 17 | import 'package:functions_framework/serve.dart'; 18 | 19 | Future main(List args) async { 20 | await serve(args, _nameToFunctionTarget); 21 | } 22 | 23 | FunctionTarget? _nameToFunctionTarget(String name) => switch (name) { 24 | 'function' => JsonFunctionTarget( 25 | function_library.function, 26 | (json) { 27 | if (json is Map) { 28 | try { 29 | return function_library.GreetingRequest.fromJson(json); 30 | } catch (e, stack) { 31 | throw BadRequestException( 32 | 400, 33 | 'There was an error parsing the provided JSON data.', 34 | innerError: e, 35 | innerStack: stack, 36 | ); 37 | } 38 | } 39 | throw BadRequestException( 40 | 400, 41 | 'The provided JSON is not the expected type ' 42 | '`Map`.', 43 | ); 44 | }, 45 | ), 46 | _ => null 47 | }; 48 | -------------------------------------------------------------------------------- /examples/json/bin/server.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | // Copyright 2021 Google LLC 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | import 'package:example_json_function/functions.dart' as function_library; 17 | import 'package:functions_framework/serve.dart'; 18 | 19 | Future main(List args) async { 20 | await serve(args, _nameToFunctionTarget); 21 | } 22 | 23 | FunctionTarget? _nameToFunctionTarget(String name) => switch (name) { 24 | 'function' => JsonFunctionTarget( 25 | function_library.function, 26 | (json) { 27 | if (json is Map) { 28 | try { 29 | return function_library.GreetingRequest.fromJson(json); 30 | } catch (e, stack) { 31 | throw BadRequestException( 32 | 400, 33 | 'There was an error parsing the provided JSON data.', 34 | innerError: e, 35 | innerStack: stack, 36 | ); 37 | } 38 | } 39 | throw BadRequestException( 40 | 400, 41 | 'The provided JSON is not the expected type ' 42 | '`Map`.', 43 | ); 44 | }, 45 | ), 46 | _ => null 47 | }; 48 | -------------------------------------------------------------------------------- /examples/fullstack/backend/bin/server.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | // Copyright 2021 Google LLC 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | import 'package:backend/functions.dart' as function_library; 17 | import 'package:functions_framework/serve.dart'; 18 | 19 | Future main(List args) async { 20 | await serve(args, _nameToFunctionTarget); 21 | } 22 | 23 | FunctionTarget? _nameToFunctionTarget(String name) => switch (name) { 24 | 'function' => JsonWithContextFunctionTarget( 25 | function_library.function, 26 | (json) { 27 | if (json is Map) { 28 | try { 29 | return function_library.GreetingRequest.fromJson(json); 30 | } catch (e, stack) { 31 | throw BadRequestException( 32 | 400, 33 | 'There was an error parsing the provided JSON data.', 34 | innerError: e, 35 | innerStack: stack, 36 | ); 37 | } 38 | } 39 | throw BadRequestException( 40 | 400, 41 | 'The provided JSON is not the expected type ' 42 | '`Map`.', 43 | ); 44 | }, 45 | ), 46 | _ => null 47 | }; 48 | -------------------------------------------------------------------------------- /google_cloud/lib/src/bad_request_exception.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:shelf/shelf.dart'; 16 | 17 | import 'logging.dart'; 18 | 19 | /// When thrown in a [Handler], configured with [badRequestMiddleware] or 20 | /// similar, causes a response with [statusCode] to be returned. 21 | /// 22 | /// [statusCode] must be >= `400` and <= `499`. 23 | /// 24 | /// [message] is used as the body of the response send to the requester. 25 | /// 26 | /// If provided, [innerError] and [innerStack] can be used to provide additional 27 | /// debugging information which is included in logs, but not sent to the 28 | /// requester. 29 | class BadRequestException implements Exception { 30 | final int statusCode; 31 | final String message; 32 | final Object? innerError; 33 | final StackTrace? innerStack; 34 | 35 | BadRequestException( 36 | this.statusCode, 37 | this.message, { 38 | this.innerError, 39 | this.innerStack, 40 | }) : assert(message.isNotEmpty) { 41 | if (statusCode < 400 || statusCode > 499) { 42 | throw ArgumentError.value( 43 | statusCode, 44 | 'statusCode', 45 | 'Must be between 400 and 499', 46 | ); 47 | } 48 | } 49 | 50 | @override 51 | String toString() => '$message ($statusCode)'; 52 | } 53 | -------------------------------------------------------------------------------- /dartfn/lib/src/cli/command.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:io' as io; 16 | 17 | import 'package:args/command_runner.dart' as cr; 18 | 19 | import '../stagehand/stagehand.dart'; 20 | import 'console.dart'; 21 | 22 | abstract class Command extends cr.Command { 23 | final CommandContext context; 24 | 25 | Command(this.context); 26 | 27 | void write([Object? obj]) { 28 | context.console.write(obj); 29 | } 30 | 31 | void info(Object obj) { 32 | context.console.info(obj); 33 | } 34 | 35 | void warning(Object obj) { 36 | context.console.warning(obj); 37 | } 38 | 39 | void error(Object obj) { 40 | context.console.error(obj); 41 | } 42 | } 43 | 44 | class CommandContext { 45 | final AppInfo app; 46 | final Console console; 47 | final GeneratorConfig generator; 48 | 49 | CommandContext({ 50 | required this.app, 51 | required this.console, 52 | required this.generator, 53 | }); 54 | } 55 | 56 | class AppInfo { 57 | final String name; 58 | final String version; 59 | 60 | AppInfo(this.name, this.version); 61 | } 62 | 63 | class GeneratorConfig { 64 | final List generators; 65 | final io.Directory cwd; 66 | final GeneratorTarget? target; 67 | 68 | GeneratorConfig({required this.generators, required this.cwd, this.target}); 69 | } 70 | -------------------------------------------------------------------------------- /dartfn/test/mock_test.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:async'; 16 | import 'dart:convert'; 17 | 18 | import 'package:dartfn/src/generators.dart'; 19 | import 'package:dartfn/src/stagehand/stagehand.dart'; 20 | import 'package:test/test.dart'; 21 | 22 | void main() { 23 | for (var generator in generators) { 24 | test(generator.id, () => _testGenerator(getGenerator(generator.id))); 25 | } 26 | } 27 | 28 | Future _testGenerator(Generator generator) async { 29 | expect(generator.id, isNotNull); 30 | 31 | final target = MockTarget(); 32 | 33 | // Assert that we can generate the template. 34 | await generator.generate('foo', target); 35 | 36 | // Run some basic validation on the generated results. 37 | expect(target.getFileContentsAsString('.gitignore'), isNotNull); 38 | expect(target.getFileContentsAsString('pubspec.yaml'), isNotNull); 39 | } 40 | 41 | class MockTarget extends GeneratorTarget { 42 | final Map> _files = {}; 43 | 44 | @override 45 | Future createFile(String path, List contents) async { 46 | _files[path] = contents; 47 | } 48 | 49 | bool hasFile(String path) => _files.containsKey(path); 50 | 51 | String? getFileContentsAsString(String path) { 52 | if (!hasFile(path)) return null; 53 | return utf8.decode(_files[path]!); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /functions_framework_builder/test/test_examples/valid_shelf_handlers.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // ignore_for_file: library_private_types_in_public_api 16 | 17 | import 'dart:async'; 18 | 19 | import 'package:functions_framework/functions_framework.dart'; 20 | import 'package:shelf/shelf.dart'; 21 | 22 | @CloudFunction() 23 | Response syncFunction(Request request) => throw UnimplementedError(); 24 | 25 | @CloudFunction() 26 | Future asyncFunction(Request request) => throw UnimplementedError(); 27 | 28 | @CloudFunction() 29 | FutureOr futureOrFunction(Request request) => 30 | throw UnimplementedError(); 31 | 32 | @CloudFunction() 33 | Response extraParam(Request request, [int? other]) => 34 | throw UnimplementedError(); 35 | 36 | @CloudFunction() 37 | Response optionalParam([Request? request, int? other]) => 38 | throw UnimplementedError(); 39 | 40 | @CloudFunction() 41 | _MyResponse customResponse(Request request) => throw UnimplementedError(); 42 | 43 | @CloudFunction() 44 | Future<_MyResponse> customResponseAsync(Request request) => 45 | throw UnimplementedError(); 46 | 47 | @CloudFunction() 48 | FutureOr<_MyResponse> customResponseFutureOr(Request request) => 49 | throw UnimplementedError(); 50 | 51 | abstract class _MyResponse extends Response { 52 | _MyResponse(super.statusCode); 53 | } 54 | -------------------------------------------------------------------------------- /examples/fullstack/frontend/windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr); 51 | if (target_length == 0) { 52 | return std::string(); 53 | } 54 | std::string utf8_string; 55 | utf8_string.resize(target_length); 56 | int converted_length = ::WideCharToMultiByte( 57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 58 | -1, utf8_string.data(), 59 | target_length, nullptr, nullptr); 60 | if (converted_length == 0) { 61 | return std::string(); 62 | } 63 | return utf8_string; 64 | } 65 | -------------------------------------------------------------------------------- /dartfn/bin/dartfn.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'dart:async'; 16 | import 'dart:io' as io; 17 | 18 | import 'package:args/command_runner.dart'; 19 | import 'package:dartfn/functions_framework_tool.dart' as tool; 20 | import 'package:dartfn/src/cli/app.dart' as cli; 21 | import 'package:io/io.dart' show ExitCode; 22 | 23 | // Initialize the CLI app with a list of generators and a terminal printer. 24 | // Process args and/or execute a subcommand. Always exit immediately when the 25 | // command returns, regardless of any pending async I/O tasks (such as fetching 26 | // logs or updating analytics); don't let CLI hang in an unexpected way from the 27 | // user's perspective before returning to the shell prompt. 28 | // Normal (expected) errors are handled by the CLI app and displayed to the 29 | // user; only print errors and a stacktrace for problems indicating there is 30 | // something wrong with the app itself. 31 | FutureOr main(List args) async { 32 | final app = cli.App(tool.generators, cli.TerminalPrinter()); 33 | 34 | try { 35 | await app.run(args); 36 | return io.exitCode = 0; 37 | } catch (e, st) { 38 | if (e is UsageException) { 39 | return io.exitCode = ExitCode.usage.code; 40 | } else { 41 | print('Unexpected error: $e\n$st'); 42 | return io.exitCode = ExitCode.software.code; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /functions_framework/lib/src/cloud_event.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import 'package:json_annotation/json_annotation.dart'; 16 | 17 | part 'cloud_event.g.dart'; 18 | 19 | /// Represents [CloudEvents](https://cloudevents.io/) data. 20 | /// 21 | /// Use this as the parameter in a function you wish to use as a handler for 22 | /// CloudEvents. 23 | @JsonSerializable(includeIfNull: false, checked: true) 24 | class CloudEvent { 25 | @JsonKey(required: true) 26 | final String id; 27 | @JsonKey(required: true) 28 | final Uri source; 29 | 30 | @JsonKey(name: 'specversion', required: true) 31 | final String specVersion; 32 | @JsonKey(required: true) 33 | final String type; 34 | 35 | @JsonKey(name: 'datacontenttype') 36 | final String? dataContentType; 37 | final Object? data; 38 | 39 | @JsonKey(name: 'dataschema') 40 | final Uri? dataSchema; 41 | final String? subject; 42 | final DateTime? time; 43 | 44 | CloudEvent({ 45 | required this.id, 46 | required this.source, 47 | required this.specVersion, 48 | required this.type, 49 | this.data, 50 | this.dataContentType, 51 | this.dataSchema, 52 | this.subject, 53 | this.time, 54 | }); 55 | 56 | factory CloudEvent.fromJson(Map json) => 57 | _$CloudEventFromJson(json); 58 | 59 | Map toJson() => _$CloudEventToJson(this); 60 | } 61 | -------------------------------------------------------------------------------- /.github/workflows/conformance.yml: -------------------------------------------------------------------------------- 1 | name: Dart Conformance CI 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | schedule: 8 | - cron: "0 0 * * 0" 9 | defaults: 10 | run: 11 | shell: bash 12 | env: 13 | PUB_ENVIRONMENT: bot.github 14 | 15 | jobs: 16 | conformance: 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Cache Pub hosted dependencies 20 | uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 21 | with: 22 | path: "~/.pub-cache/hosted" 23 | key: "os:ubuntu-latest;pub-cache-hosted;dart:2.10.0;" 24 | restore-keys: | 25 | os:ubuntu-latest;pub-cache-hosted 26 | os:ubuntu-latest 27 | 28 | - name: Setup Go 29 | uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 30 | with: 31 | go-version: '^1.16' 32 | 33 | - uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c 34 | with: 35 | sdk: stable 36 | - run: dart --version 37 | 38 | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 39 | - run: dart pub upgrade 40 | working-directory: integration_test 41 | 42 | - name: Run HTTP conformance tests 43 | uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.8.7 44 | with: 45 | functionType: 'http' 46 | useBuildpacks: false 47 | # Coordinate changes here with the documentation in `CONTRIBUTING.MD` 48 | cmd: '"dart integration_test/bin/server.dart --target conformanceHttp"' 49 | startDelay: 3 50 | 51 | - name: Run CloudEvent conformance tests 52 | uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.8.7 53 | with: 54 | functionType: 'cloudevent' 55 | useBuildpacks: false 56 | # Coordinate changes here with the documentation in `CONTRIBUTING.MD` 57 | cmd: '"dart integration_test/bin/server.dart --target conformanceCloudEvent --signature-type cloudevent"' 58 | validateMapping: false 59 | startDelay: 3 60 | -------------------------------------------------------------------------------- /dartfn/templates/cloudevent/test/src/test_utils.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:test/test.dart'; 4 | import 'package:test_process/test_process.dart'; 5 | 6 | const defaultPort = 8080; 7 | 8 | final _listeningPattern = RegExp(r'Listening on :(\d+)'); 9 | 10 | late int _autoPort; 11 | 12 | int get autoPort => _autoPort; 13 | 14 | Future startServerTest({ 15 | bool shouldFail = false, 16 | int expectedListeningPort = defaultPort, 17 | Map? env, 18 | Iterable arguments = const [], 19 | }) async { 20 | if (expectedListeningPort == 0) { 21 | expect(arguments, isNot(contains('--port'))); 22 | if (env != null) { 23 | expect(env, isNot(contains('PORT'))); 24 | } 25 | } 26 | final args = [ 27 | 'bin/server.dart', 28 | ...arguments, 29 | if (expectedListeningPort == 0) ...['--port', '0'], 30 | ]; 31 | final proc = await TestProcess.start('dart', args, environment: env); 32 | 33 | if (!shouldFail) { 34 | final output = await proc.stdout.next; 35 | final match = _listeningPattern.firstMatch(output)!; 36 | _autoPort = int.parse(match[1]!); 37 | if (expectedListeningPort == 0) { 38 | expect(_autoPort, greaterThan(0)); 39 | } else { 40 | expect(_autoPort, expectedListeningPort); 41 | } 42 | } 43 | 44 | return proc; 45 | } 46 | 47 | Future finishServerTest( 48 | TestProcess proc, { 49 | ProcessSignal signal = ProcessSignal.sigterm, 50 | Object? requestOutput, 51 | }) async { 52 | requestOutput ??= finishedPattern('GET', 200); 53 | await expectLater( 54 | proc.stdout, 55 | requestOutput is StreamMatcher 56 | ? requestOutput 57 | : emitsThrough(requestOutput), 58 | ); 59 | proc.signal(signal); 60 | await proc.shouldExit(0); 61 | await expectLater( 62 | proc.stdout, 63 | emitsThrough('Received signal $signal - closing'), 64 | ); 65 | } 66 | 67 | RegExp finishedPattern(String method, int statusCode) => 68 | RegExp('$method.+[${statusCode.toString()}]'); 69 | --------------------------------------------------------------------------------