Skip to content

Commit a6e9bc8

Browse files
authored
Add documentation to many public members and populate the example dir (GoogleCloudPlatform#226)
Should increase the score of the package Prepare to release v0.4.1
1 parent 00a5b43 commit a6e9bc8

File tree

10 files changed

+72
-3
lines changed

10 files changed

+72
-3
lines changed

functions_framework/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## 0.4.1-dev
3+
## 0.4.1
44

55
- Improve package documentation.
66

functions_framework/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ properly format your code.
8686

8787
## Licensing
8888

89-
Apache 2.0; see [`LICENSE`](LICENSE) for details.
89+
Apache 2.0; see [`LICENSE`][license] for details.
9090

9191
<!-- Repo links -->
9292
[ff_dart]: https://github.com/GoogleCloudPlatform/functions-framework-dart
@@ -123,3 +123,4 @@ https://github.com/GoogleCloudPlatform/functions-framework-dart/actions?query=wo
123123
[cloud run quickstart]: https://github.com/GoogleCloudPlatform/functions-framework-dart/blob/main/docs/quickstarts/03-quickstart-cloudrun.md
124124
[quickstarts]: https://github.com/GoogleCloudPlatform/functions-framework-dart/tree/main/docs/quickstarts
125125
[contributing]: https://github.com/GoogleCloudPlatform/functions-framework-dart/blob/main/CONTRIBUTING.md
126+
[license]: https://github.com/GoogleCloudPlatform/functions-framework-dart/blob/main/functions_framework/LICENSE
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Functions Framework Examples
2+
3+
For usage examples, see
4+
https://github.com/GoogleCloudPlatform/functions-framework-dart/tree/main/examples

functions_framework/lib/functions_framework.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

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 functions_framework;
26+
1527
export 'src/bad_request_exception.dart' show BadRequestException;
1628
export 'src/cloud_event.dart' show CloudEvent;
1729
export 'src/cloud_function.dart' show CloudFunction;

functions_framework/lib/serve.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
/// Provides the features needed to *execute* Cloud Functions.
16+
///
17+
/// Typically, this library is imported in `bin/server.dart` or similar.
18+
///
19+
/// While it's possible to use this library from hand-written code, you should
20+
/// use
21+
/// [package:functions_framework_builder](https://pub.dev/packages/functions_framework_builder)
22+
/// to generate server code instead.
23+
library serve;
24+
1525
import 'dart:async';
1626
import 'dart:io';
1727

functions_framework/lib/src/cloud_event.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import 'package:json_annotation/json_annotation.dart';
1616

1717
part 'cloud_event.g.dart';
1818

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.
1923
@JsonSerializable(includeIfNull: false, checked: true)
2024
class CloudEvent {
2125
@JsonKey(required: true)

functions_framework/lib/src/log_severity.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import 'request_context.dart';
16+
import 'typedefs.dart';
17+
18+
/// Allows logging at a specified severity.
19+
///
20+
/// Can be used as the second parameter in functions shaped like
21+
/// [HandlerWithLogger]. Also exposed by [RequestContext].
22+
///
23+
/// Compatible with the
24+
/// [log severities](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity)
25+
/// support by Google Cloud.
1526
abstract class RequestLogger {
1627
const RequestLogger();
1728

functions_framework/lib/src/request_context.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@
1515
import 'package:meta/meta.dart';
1616
import 'package:shelf/shelf.dart';
1717

18+
import 'cloud_event.dart';
1819
import 'log_severity.dart';
1920
import 'logging.dart';
2021

22+
/// Provides access to a [RequestLogger], the source [Request] and response
23+
/// headers for a typed function handler.
24+
///
25+
/// Can be used as an optional second parameter in a function definition that
26+
/// accepts a [CloudEvent] or a custom type.
2127
class RequestContext {
2228
final RequestLogger logger;
2329

functions_framework/lib/src/typedefs.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,43 @@ import 'cloud_event.dart';
2020
import 'log_severity.dart';
2121
import 'request_context.dart';
2222

23+
/// The shape of a handler for [CloudEvent] types.
2324
typedef CloudEventHandler = FutureOr<void> Function(CloudEvent request);
2425

26+
/// The shape of a handler for [CloudEvent] types while also providing a
27+
/// [RequestContext].
2528
typedef CloudEventWithContextHandler = FutureOr<void> Function(
2629
CloudEvent request,
2730
RequestContext context,
2831
);
2932

33+
/// The shape of a handler that supports a custom [RequestType] and
34+
/// [ResponseType].
35+
///
36+
/// The [RequestType] must be either a type compatible with a JSON literal or
37+
/// have a `fromJson` constructor with a single, positional parameter that is
38+
/// compatible with a JSON literal.
39+
///
40+
/// The [ResponseType] must be either a type compatible with a JSON literal or
41+
/// have a `toJson()` function with a returns type compatible with a JSON
42+
/// literal.
3043
typedef JsonHandler<RequestType, ResponseType> = FutureOr<ResponseType>
3144
Function(RequestType request);
3245

46+
/// The shape of a handler that supports a custom [RequestType] and
47+
/// [ResponseType] and while also providing a [RequestContext].
48+
///
49+
/// See [JsonHandler] for the type requirements for [RequestType] and
50+
/// [ResponseType].
3351
typedef JsonWithContextHandler<RequestType, ResponseType>
3452
= FutureOr<ResponseType> Function(
3553
RequestType request,
3654
RequestContext context,
3755
);
3856

57+
/// The shape of a basic handler that follows the
58+
/// [package:shelf](https://pub.dev/packages/shelf) [Handler] pattern while also
59+
/// providing a [RequestLogger].
3960
typedef HandlerWithLogger = FutureOr<Response> Function(
4061
Request request,
4162
RequestLogger logger,

functions_framework/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: functions_framework
2-
version: 0.4.1-dev
2+
version: 0.4.1
33
description: >-
44
FaaS (Function as a service) framework for writing portable Dart functions
55
repository: https://github.com/GoogleCloudPlatform/functions-framework-dart

0 commit comments

Comments
 (0)