pw_status: add typescript enumeration

Change-Id: Ie1eadb087bcfef6b2e44c63d9f274d071f237bdd
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/57325
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Jared Weinstein <jaredweinstein@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
This commit is contained in:
Jared Weinstein 2021-08-13 12:57:45 -07:00 committed by CQ Bot Account
parent ff4b74215a
commit ef588a3530
4 changed files with 63 additions and 1 deletions

View File

@ -165,6 +165,9 @@ function that corresponds with the status code.
// the authentication and try again.
pw::Status::Unauthenticated()
.. note::
Status enumerations are also supported for Python and Typescript.
.. attention::
Some code may use all-caps status values such as ``Status::UNKNOWN`` instead

View File

@ -25,7 +25,6 @@ class Status(enum.Enum):
NOT_FOUND = 5
ALREADY_EXISTS = 6
PERMISSION_DENIED = 7
UNAUTHENTICATED = 16
RESOURCE_EXHAUSTED = 8
FAILED_PRECONDITION = 9
ABORTED = 10
@ -34,6 +33,7 @@ class Status(enum.Enum):
INTERNAL = 13
UNAVAILABLE = 14
DATA_LOSS = 15
UNAUTHENTICATED = 16
def ok(self) -> bool:
return self is self.OK

24
pw_status/ts/BUILD.bazel Normal file
View File

@ -0,0 +1,24 @@
# Copyright 2021 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
load("@npm//@bazel/typescript:index.bzl", "ts_library")
package(default_visibility = ["//visibility:public"])
ts_library(
name = "pw_status",
srcs = [
"status.ts",
],
)

35
pw_status/ts/status.ts Normal file
View File

@ -0,0 +1,35 @@
// Copyright 2021 The Pigweed Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
/** Pigweed Status class; mirrors pw::Status. */
enum Status {
OK = 0,
CANCELLED = 1,
UNKNOWN = 2,
INVALID_ARGUMENT = 3,
DEADLINE_EXCEEDED = 4,
NOT_FOUND = 5,
ALREADY_EXISTS = 6,
PERMISSION_DENIED = 7,
RESOURCE_EXHAUSTED = 8,
FAILED_PRECONDITION = 9,
ABORTED = 10,
OUT_OF_RANGE = 11,
UNIMPLEMENTED = 12,
INTERNAL = 13,
UNAVAILABLE = 14,
DATA_LOSS = 15,
UNAUTHENTICATED = 16
}