Skip to content

Commit 46cd776

Browse files
committed
explicit exports for esm usage
1 parent d6d61e3 commit 46cd776

File tree

3 files changed

+1345
-41
lines changed

3 files changed

+1345
-41
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
coverage
3+
.DS_Store

index.js

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
1-
const inherits = require('util').inherits;
2-
3-
const VError = require('verror').VError;
4-
5-
const codes = {
6-
Ok: 0,
7-
Cancelled: 1,
8-
Unknown: 2,
9-
InvalidArgument: 3,
10-
DeadlineExceeded: 4,
11-
NotFound: 5,
12-
AlreadyExists: 6,
13-
PermissionDenied: 7,
14-
ResourceExhausted: 8,
15-
FailedPrecondition: 9,
16-
Aborted: 10,
17-
OutOfRange: 11,
18-
Unimplemented: 12,
19-
Internal: 13,
20-
Unavailable: 14,
21-
DataLoss: 15,
22-
Unauthenticated: 16
23-
};
24-
25-
constructErrors();
26-
27-
function constructErrors() {
28-
for (let name of Object.keys(codes)) {
29-
let className = name + 'Error';
30-
let code = codes[name];
31-
32-
exports[className] = constructError(className, code);
33-
}
34-
}
1+
const inherits = require("util").inherits;
2+
3+
const VError = require("verror").VError;
4+
5+
module.exports.OkError = constructError("OkError", 0);
6+
module.exports.CancelledError = constructError("CancelledError", 1);
7+
module.exports.UnknownError = constructError("UnknownError", 2);
8+
module.exports.InvalidArgumentError = constructError("InvalidArgumentError", 3);
9+
module.exports.DeadlineExceededError = constructError(
10+
"DeadlineExceededError",
11+
4
12+
);
13+
module.exports.NotFoundError = constructError("NotFoundError", 5);
14+
module.exports.AlreadyExistsError = constructError("AlreadyExistsError", 6);
15+
module.exports.PermissionDeniedError = constructError(
16+
"PermissionDeniedError",
17+
7
18+
);
19+
module.exports.ResourceExhaustedError = constructError(
20+
"ResourceExhaustedError",
21+
8
22+
);
23+
module.exports.FailedPreconditionError = constructError(
24+
"FailedPreconditionError",
25+
9
26+
);
27+
module.exports.AbortedError = constructError("AbortedError", 10);
28+
module.exports.OutOfRangeError = constructError("OutOfRangeError", 11);
29+
module.exports.UnimplementedError = constructError("UnimplementedError", 12);
30+
module.exports.InternalError = constructError("InternalError", 13);
31+
module.exports.UnavailableError = constructError("UnavailableError", 14);
32+
module.exports.DataLossError = constructError("DataLossError", 15);
33+
module.exports.UnauthenticatedError = constructError(
34+
"UnauthenticatedError",
35+
16
36+
);
3537

3638
function constructError(className, code) {
3739
function GRPCError(...args) {
@@ -41,11 +43,11 @@ function constructError(className, code) {
4143
this.code = code;
4244

4345
// redefine the error name
44-
Object.defineProperty(this, 'name', {
46+
Object.defineProperty(this, "name", {
4547
enumerable: false,
4648
configurable: true,
4749
value: className,
48-
writable: true
50+
writable: true,
4951
});
5052
}
5153

0 commit comments

Comments
 (0)