@yandex-cloud/nodejs-sdk
Version:
Yandex.Cloud NodeJS SDK
127 lines (126 loc) • 4.88 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiKey = exports.protobufPackage = void 0;
/* eslint-disable */
const typeRegistry_1 = require("../../../../typeRegistry");
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const timestamp_1 = require("../../../../google/protobuf/timestamp");
exports.protobufPackage = "yandex.cloud.iam.v1";
const baseApiKey = {
$type: "yandex.cloud.iam.v1.ApiKey",
id: "",
serviceAccountId: "",
description: "",
};
exports.ApiKey = {
$type: "yandex.cloud.iam.v1.ApiKey",
encode(message, writer = minimal_1.default.Writer.create()) {
if (message.id !== "") {
writer.uint32(10).string(message.id);
}
if (message.serviceAccountId !== "") {
writer.uint32(18).string(message.serviceAccountId);
}
if (message.createdAt !== undefined) {
timestamp_1.Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(26).fork()).ldelim();
}
if (message.description !== "") {
writer.uint32(34).string(message.description);
}
return writer;
},
decode(input, length) {
const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = Object.assign({}, baseApiKey);
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.id = reader.string();
break;
case 2:
message.serviceAccountId = reader.string();
break;
case 3:
message.createdAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
break;
case 4:
message.description = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object) {
const message = Object.assign({}, baseApiKey);
message.id =
object.id !== undefined && object.id !== null ? String(object.id) : "";
message.serviceAccountId =
object.serviceAccountId !== undefined && object.serviceAccountId !== null
? String(object.serviceAccountId)
: "";
message.createdAt =
object.createdAt !== undefined && object.createdAt !== null
? fromJsonTimestamp(object.createdAt)
: undefined;
message.description =
object.description !== undefined && object.description !== null
? String(object.description)
: "";
return message;
},
toJSON(message) {
const obj = {};
message.id !== undefined && (obj.id = message.id);
message.serviceAccountId !== undefined &&
(obj.serviceAccountId = message.serviceAccountId);
message.createdAt !== undefined &&
(obj.createdAt = message.createdAt.toISOString());
message.description !== undefined &&
(obj.description = message.description);
return obj;
},
fromPartial(object) {
var _a, _b, _c, _d;
const message = Object.assign({}, baseApiKey);
message.id = (_a = object.id) !== null && _a !== void 0 ? _a : "";
message.serviceAccountId = (_b = object.serviceAccountId) !== null && _b !== void 0 ? _b : "";
message.createdAt = (_c = object.createdAt) !== null && _c !== void 0 ? _c : undefined;
message.description = (_d = object.description) !== null && _d !== void 0 ? _d : "";
return message;
},
};
typeRegistry_1.messageTypeRegistry.set(exports.ApiKey.$type, exports.ApiKey);
function toTimestamp(date) {
const seconds = date.getTime() / 1000;
const nanos = (date.getTime() % 1000) * 1000000;
return { $type: "google.protobuf.Timestamp", seconds, nanos };
}
function fromTimestamp(t) {
let millis = t.seconds * 1000;
millis += t.nanos / 1000000;
return new Date(millis);
}
function fromJsonTimestamp(o) {
if (o instanceof Date) {
return o;
}
else if (typeof o === "string") {
return new Date(o);
}
else {
return fromTimestamp(timestamp_1.Timestamp.fromJSON(o));
}
}
if (minimal_1.default.util.Long !== long_1.default) {
minimal_1.default.util.Long = long_1.default;
minimal_1.default.configure();
}