initial commit

This commit is contained in:
2025-09-01 22:12:29 +02:00
parent b1873f9c1d
commit 02a54f61c0
5598 changed files with 903558 additions and 0 deletions

152
server/node_modules/proto3-json-serializer/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,152 @@
# Changelog
## [2.0.2](https://github.com/googleapis/proto3-json-serializer-nodejs/compare/v2.0.1...v2.0.2) (2024-05-22)
### Bug Fixes
* Properly convert repeated int64 and maps of int64 ([#96](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/96)) ([1ec05fb](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/1ec05fb59edfdff7531b9372dcfe14c0fe36562c))
## [2.0.1](https://github.com/googleapis/proto3-json-serializer-nodejs/compare/v2.0.0...v2.0.1) (2024-01-16)
### Bug Fixes
* **deps:** Update dependency google-proto-files to v4 ([#82](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/82)) ([72623e0](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/72623e04e1043353ef952178714ced733001a06d))
* **deps:** Update protobufjs to 7.2.5 ([a0f5c83](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/a0f5c833cba654949ec5e624fad1849020cf899d))
## [2.0.0](https://github.com/googleapis/proto3-json-serializer-nodejs/compare/v1.1.1...v2.0.0) (2023-08-07)
### ⚠ BREAKING CHANGES
* require Node 14 ([#72](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/72))
### Miscellaneous Chores
* Require Node 14 ([#72](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/72)) ([8681834](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/8681834d8bc204c40857e299570e1e5df4bc5618))
## [1.1.1](https://github.com/googleapis/proto3-json-serializer-nodejs/compare/v1.1.0...v1.1.1) (2023-04-25)
### Bug Fixes
* Repeated field can be null in JSON ([#66](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/66)) ([f81d3ab](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/f81d3ab202e2a674be73db8a9b74d3eecf3bbed4))
## [1.1.0](https://github.com/googleapis/proto3-json-serializer-nodejs/compare/v1.0.3...v1.1.0) (2022-08-26)
### Features
* option to serialize enum values as numbers ([#60](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/60)) ([456b771](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/456b771d5fef06d914c6e201fd9f17251e55d4d9))
### Bug Fixes
* remove pip install statements ([#1546](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/1546)) ([#58](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/58)) ([741d070](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/741d0704f49332dd5d66206fcdf2111464fb8759))
## [1.0.3](https://github.com/googleapis/proto3-json-serializer-nodejs/compare/v1.0.2...v1.0.3) (2022-07-10)
### Bug Fixes
* **deps:** update dependency protobufjs to v7 ([#56](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/56)) ([038fea5](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/038fea537c8809dc272c2352b832b5301c7b79d2))
## [1.0.2](https://github.com/googleapis/proto3-json-serializer-nodejs/compare/v1.0.1...v1.0.2) (2022-06-15)
### Bug Fixes
* **deps:** update dependency google-proto-files to v3 ([#53](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/53)) ([40fd527](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/40fd527109838a21887f7a5058406244acabe938))
## [1.0.1](https://github.com/googleapis/proto3-json-serializer-nodejs/compare/v1.0.0...v1.0.1) (2022-06-03)
### Bug Fixes
* **deps:** bump protobuf.js to ^6.11.3 ([#46](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/46)) ([af8a14a](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/af8a14a35c04cbef49bff806b7d906287d1d2c0d))
## [1.0.0](https://github.com/googleapis/proto3-json-serializer-nodejs/compare/v0.1.9...v1.0.0) (2022-05-12)
### ⚠ BREAKING CHANGES
* make Node 12 minimum language version (#38)
### Features
* make Node 12 minimum language version ([#38](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/38)) ([658d29e](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/658d29e531c2d04d4007e5843aa62d9d8ee0dae8))
### [0.1.9](https://github.com/googleapis/proto3-json-serializer-nodejs/compare/v0.1.8...v0.1.9) (2022-05-11)
### Bug Fixes
* do not use Node.js assert ([#37](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/37)) ([dccfeca](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/dccfeca6f3bbeec29d88319f375a734ec48aadf7))
### [0.1.8](https://github.com/googleapis/proto3-json-serializer-nodejs/compare/v0.1.7...v0.1.8) (2022-01-21)
### Bug Fixes
* timestamp without millisecond ([#30](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/30)) ([a55d0b6](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/a55d0b6f98f6d1c8b7d971d0a583bbd82ea66983))
### [0.1.7](https://github.com/googleapis/proto3-json-serializer-nodejs/compare/v0.1.6...v0.1.7) (2022-01-14)
### Bug Fixes
* keep nano second precision when maps between JSON and proto3 ([#28](https://github.com/googleapis/proto3-json-serializer-nodejs/issues/28)) ([eaa01ce](https://github.com/googleapis/proto3-json-serializer-nodejs/commit/eaa01ce92c4eefa816d1d6f8ef6ed11bd2a6364b))
### [0.1.6](https://www.github.com/googleapis/proto3-json-serializer-nodejs/compare/v0.1.5...v0.1.6) (2021-11-15)
### Bug Fixes
* **deps:** protobufjs is a dependency for the types ([#23](https://www.github.com/googleapis/proto3-json-serializer-nodejs/issues/23)) ([06470c1](https://www.github.com/googleapis/proto3-json-serializer-nodejs/commit/06470c1df501439ec3f8bc546cd23d798604f3bd))
### [0.1.5](https://www.github.com/googleapis/proto3-json-serializer-nodejs/compare/v0.1.4...v0.1.5) (2021-10-26)
### Bug Fixes
* JSON accept special string for NaN, Infinity ([#19](https://www.github.com/googleapis/proto3-json-serializer-nodejs/issues/19)) ([01a345b](https://www.github.com/googleapis/proto3-json-serializer-nodejs/commit/01a345b7b1d62ee65a8673737975980d274fa22a))
### [0.1.4](https://www.github.com/googleapis/proto3-json-serializer-nodejs/compare/v0.1.3...v0.1.4) (2021-09-20)
### Bug Fixes
* do not emit empty lists to JSON ([#15](https://www.github.com/googleapis/proto3-json-serializer-nodejs/issues/15)) ([af9dfd6](https://www.github.com/googleapis/proto3-json-serializer-nodejs/commit/af9dfd65efb84cfb31af0faca805f53b0ffa9874))
### [0.1.3](https://www.github.com/googleapis/proto3-json-serializer-nodejs/compare/v0.1.2...v0.1.3) (2021-08-18)
### Bug Fixes
* do not fail for unknown enum values ([#11](https://www.github.com/googleapis/proto3-json-serializer-nodejs/issues/11)) ([ff9f0f1](https://www.github.com/googleapis/proto3-json-serializer-nodejs/commit/ff9f0f1881b1aafacd693b4e24eaee9e56aff79c))
### [0.1.2](https://www.github.com/googleapis/proto3-json-serializer-nodejs/compare/v0.1.1...v0.1.2) (2021-08-17)
### Bug Fixes
* use imported protobufjs in toproto3json.ts ([#9](https://www.github.com/googleapis/proto3-json-serializer-nodejs/issues/9)) ([f6c86c7](https://www.github.com/googleapis/proto3-json-serializer-nodejs/commit/f6c86c777d567d8430b09dea3282e52af24d890f))
### [0.1.1](https://www.github.com/googleapis/proto3-json-serializer-nodejs/compare/v0.1.0...v0.1.1) (2021-08-04)
### Bug Fixes
* accept and return strings for int64 and uint64 ([#7](https://www.github.com/googleapis/proto3-json-serializer-nodejs/issues/7)) ([35689ec](https://www.github.com/googleapis/proto3-json-serializer-nodejs/commit/35689ecee55dbe6e4cf3327c535514d7fcb8332d))
## 0.1.0 (2021-08-03)
### ⚠ BREAKING CHANGES
* proto3 JSON serializer and deserializer (#2)
### Features
* proto3 JSON serializer and deserializer ([#2](https://www.github.com/googleapis/proto3-json-serializer-nodejs/issues/2)) ([96255a7](https://www.github.com/googleapis/proto3-json-serializer-nodejs/commit/96255a77c7714f33cae547db9160615d7f80a233))

202
server/node_modules/proto3-json-serializer/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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
http://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.

97
server/node_modules/proto3-json-serializer/README.md generated vendored Normal file
View File

@@ -0,0 +1,97 @@
# proto3 JSON serializer for TypeScript / JavaScript
This library implements proto3 JSON serialization and deserialization for
[protobuf.js](https://www.npmjs.com/package/protobufjs) protobuf objects
according to the [spec](https://developers.google.com/protocol-buffers/docs/proto3#json).
Note that the spec requires special representation of some `google.protobuf.*` types
(`Value`, `Struct`, `Timestamp`, `Duration`, etc.), so you cannot just use `.toObject()`
since the result won't be understood by protobuf in other languages. Hence this module.
JavaScript:
```js
const serializer = require('proto3-json-serializer');
```
TypeScript:
```ts
import * as serializer from 'proto3-json-serializer';
```
## Serialization: protobuf.js object to proto3 JSON
```js
const root = protobuf.loadSync('test.proto');
const Type = root.lookupType('test.Message');
const message = Type.fromObject({...});
const serialized = serializer.toProto3JSON(message);
```
Serialization works with any object created by calling `.create()`, `.decode()`, or `.fromObject()`
for a loaded protobuf type. It relies on the `$type` field so it will not work with a static object.
## Deserialization: proto3 JSON to protobuf.js object
To deserialize an object from proto3 JSON, we must know its type (as returned by `root.lookupType('...')`).
Pass this type as the first parameter to `.fromProto3JSON`:
```js
const root = protobuf.loadSync('test.proto');
const Type = root.lookupType('test.Message');
const json = {...};
const deserialized = serializer.fromProto3JSON(Type, json);
```
## Complete example
```js
const assert = require('assert');
const path = require('path');
const protobuf = require('protobufjs');
const serializer = require('proto3-json-serializer');
// We'll take sample protos from google-proto-files but the code will work with any protos
const protos = require('google-proto-files');
// Load some proto file
const rpcProtos = protos.getProtoPath('rpc');
const root = protobuf.loadSync([
path.join(rpcProtos, 'status.proto'),
path.join(rpcProtos, 'error_details.proto'),
]);
const Status = root.lookupType('google.rpc.Status');
// If you have a protobuf object that follows proto3 JSON syntax
// https://developers.google.com/protocol-buffers/docs/proto3#json
// (this is an example of google.rpc.Status message in JSON)
const json = {
code: 3,
message: 'Test error message',
details: [
{
'@type': 'google.rpc.BadRequest',
fieldViolations: [
{
field: 'field',
description: 'must not be null',
},
],
},
],
};
// You can deserialize it into a protobuf.js object:
const deserialized = serializer.fromProto3JSON(Status, json);
console.log(deserialized);
// And serialize it back
const serialized = serializer.toProto3JSON(deserialized);
assert.deepStrictEqual(serialized, json);
```
## Disclaimer
This is not an officially supported Google project.

View File

@@ -0,0 +1,16 @@
/// <reference types="node" />
import * as protobuf from 'protobufjs';
import { ToProto3JSONOptions } from './toproto3json';
import { JSONObject, JSONValue } from './types';
export interface Any {
type_url: string;
value: Buffer | Uint8Array;
}
export declare function googleProtobufAnyToProto3JSON(obj: protobuf.Message & Any, options?: ToProto3JSONOptions): JSONObject;
export declare function googleProtobufAnyFromProto3JSON(root: protobuf.Root, json: JSONValue): {
type_url: string;
value: null;
} | {
type_url: string;
value: string;
};

View File

@@ -0,0 +1,95 @@
"use strict";
// Copyright 2021 Google LLC
//
// 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
//
// http://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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.googleProtobufAnyFromProto3JSON = exports.googleProtobufAnyToProto3JSON = void 0;
const fromproto3json_1 = require("./fromproto3json");
const toproto3json_1 = require("./toproto3json");
// https://github.com/protocolbuffers/protobuf/blob/ba3836703b4a9e98e474aea2bac8c5b49b6d3b5c/python/google/protobuf/json_format.py#L850
const specialJSON = new Set([
'google.protobuf.Any',
'google.protobuf.Duration',
'google.protobuf.FieldMask',
'google.protobuf.ListValue',
'google.protobuf.Struct',
'google.protobuf.Timestamp',
'google.protobuf.Value',
]);
function googleProtobufAnyToProto3JSON(obj, options) {
// https://developers.google.com/protocol-buffers/docs/proto3#json
// If the Any contains a value that has a special JSON mapping, it will be converted as follows:
// {"@type": xxx, "value": yyy}.
// Otherwise, the value will be converted into a JSON object, and the "@type" field will be inserted
// to indicate the actual data type.
const typeName = obj.type_url.replace(/^.*\//, '');
let type;
try {
type = obj.$type.root.lookupType(typeName);
}
catch (err) {
throw new Error(`googleProtobufAnyToProto3JSON: cannot find type ${typeName}: ${err}`);
}
const valueMessage = type.decode(obj.value);
const valueProto3JSON = (0, toproto3json_1.toProto3JSON)(valueMessage, options);
if (specialJSON.has(typeName)) {
return {
'@type': obj.type_url,
value: valueProto3JSON,
};
}
valueProto3JSON['@type'] = obj.type_url;
return valueProto3JSON;
}
exports.googleProtobufAnyToProto3JSON = googleProtobufAnyToProto3JSON;
function googleProtobufAnyFromProto3JSON(root, json) {
// Not all possible JSON values can hold Any, only real objects.
if (json === null || typeof json !== 'object' || Array.isArray(json)) {
throw new Error('googleProtobufAnyFromProto3JSON: must be an object to decode google.protobuf.Any');
}
const typeUrl = json['@type'];
if (!typeUrl || typeof typeUrl !== 'string') {
throw new Error('googleProtobufAnyFromProto3JSON: JSON serialization of google.protobuf.Any must contain @type field');
}
const typeName = typeUrl.replace(/^.*\//, '');
let type;
try {
type = root.lookupType(typeName);
}
catch (err) {
throw new Error(`googleProtobufAnyFromProto3JSON: cannot find type ${typeName}: ${err}`);
}
let value = json;
if (specialJSON.has(typeName)) {
if (!('value' in json)) {
throw new Error(`googleProtobufAnyFromProto3JSON: JSON representation of google.protobuf.Any with type ${typeName} must contain the value field`);
}
value = json.value;
}
const valueMessage = (0, fromproto3json_1.fromProto3JSON)(type, value);
if (valueMessage === null) {
return {
type_url: typeUrl,
value: null,
};
}
const uint8array = type.encode(valueMessage).finish();
const buffer = Buffer.from(uint8array, 0, uint8array.byteLength);
const base64 = buffer.toString('base64');
return {
type_url: typeUrl,
value: base64,
};
}
exports.googleProtobufAnyFromProto3JSON = googleProtobufAnyFromProto3JSON;
//# sourceMappingURL=any.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"any.js","sourceRoot":"","sources":["../../typescript/src/any.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAMjC,qDAAgD;AAChD,iDAAiE;AAGjE,uIAAuI;AACvI,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,qBAAqB;IACrB,0BAA0B;IAC1B,2BAA2B;IAC3B,2BAA2B;IAC3B,wBAAwB;IACxB,2BAA2B;IAC3B,uBAAuB;CACxB,CAAC,CAAC;AAOH,SAAgB,6BAA6B,CAC3C,GAA2B,EAC3B,OAA6B;IAE7B,kEAAkE;IAClE,gGAAgG;IAChG,gCAAgC;IAChC,oGAAoG;IACpG,oCAAoC;IAEpC,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACnD,IAAI,IAAmB,CAAC;IACxB,IAAI;QACF,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;KAC5C;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,mDAAmD,QAAQ,KAAK,GAAG,EAAE,CACtE,CAAC;KACH;IACD,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5C,MAAM,eAAe,GAAG,IAA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C,KAAK,CAAC;KACpB;IAED,MAAM,YAAY,GAAG,IAAA,+BAAc,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACjD,IAAI,YAAY,KAAK,IAAI,EAAE;QACzB,OAAO;YACL,QAAQ,EAAE,OAAO;YACjB,KAAK,EAAE,IAAI;SACZ,CAAC;KACH;IAED,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,EAAE,CAAC;IACtD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;IACjE,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAEzC,OAAO;QACL,QAAQ,EAAE,OAAO;QACjB,KAAK,EAAE,MAAM;KACd,CAAC;AACJ,CAAC;AAtDD,0EAsDC"}

View File

@@ -0,0 +1,3 @@
/// <reference types="node" />
export declare function bytesToProto3JSON(obj: Buffer | Uint8Array): string;
export declare function bytesFromProto3JSON(json: string): Buffer;

View File

@@ -0,0 +1,30 @@
"use strict";
// Copyright 2021 Google LLC
//
// 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
//
// http://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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.bytesFromProto3JSON = exports.bytesToProto3JSON = void 0;
function bytesToProto3JSON(obj) {
if (Buffer.isBuffer(obj)) {
return obj.toString('base64');
}
else {
return Buffer.from(obj.buffer, 0, obj.byteLength).toString('base64');
}
}
exports.bytesToProto3JSON = bytesToProto3JSON;
function bytesFromProto3JSON(json) {
return Buffer.from(json, 'base64');
}
exports.bytesFromProto3JSON = bytesFromProto3JSON;
//# sourceMappingURL=bytes.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../typescript/src/bytes.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAEjC,SAAgB,iBAAiB,CAAC,GAAwB;IACxD,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACxB,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KAC/B;SAAM;QACL,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KACtE;AACH,CAAC;AAND,8CAMC;AAED,SAAgB,mBAAmB,CAAC,IAAY;IAC9C,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC;AAFD,kDAEC"}

View File

@@ -0,0 +1,10 @@
import * as protobuf from 'protobufjs';
import { FromObjectValue } from './types';
export interface Duration {
seconds: number;
nanos?: number;
}
export declare function googleProtobufDurationToProto3JSON(obj: protobuf.Message & Duration): string;
export declare function googleProtobufDurationFromProto3JSON(json: string): {
[key: string]: FromObjectValue;
};

View File

@@ -0,0 +1,55 @@
"use strict";
// Copyright 2021 Google LLC
//
// 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
//
// http://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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.googleProtobufDurationFromProto3JSON = exports.googleProtobufDurationToProto3JSON = void 0;
function googleProtobufDurationToProto3JSON(obj) {
// seconds is an instance of Long so it won't be undefined
let durationSeconds = obj.seconds.toString();
if (typeof obj.nanos === 'number' && obj.nanos > 0) {
// nanosStr should contain 3, 6, or 9 fractional digits.
const nanosStr = obj.nanos
.toString()
.padStart(9, '0')
.replace(/^((?:\d\d\d)+?)(?:0*)$/, '$1');
durationSeconds += '.' + nanosStr;
}
durationSeconds += 's';
return durationSeconds;
}
exports.googleProtobufDurationToProto3JSON = googleProtobufDurationToProto3JSON;
function googleProtobufDurationFromProto3JSON(json) {
const match = json.match(/^(\d*)(?:\.(\d*))?s$/);
if (!match) {
throw new Error(`googleProtobufDurationFromProto3JSON: incorrect value ${json} passed as google.protobuf.Duration`);
}
let seconds = 0;
let nanos = 0;
if (typeof match[1] === 'string' && match[1].length > 0) {
seconds = parseInt(match[1]);
}
if (typeof match[2] === 'string' && match[2].length > 0) {
nanos = parseInt(match[2].padEnd(9, '0'));
}
const result = {};
if (seconds !== 0) {
result.seconds = seconds;
}
if (nanos !== 0) {
result.nanos = nanos;
}
return result;
}
exports.googleProtobufDurationFromProto3JSON = googleProtobufDurationFromProto3JSON;
//# sourceMappingURL=duration.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"duration.js","sourceRoot":"","sources":["../../typescript/src/duration.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAUjC,SAAgB,kCAAkC,CAChD,GAAgC;IAEhC,0DAA0D;IAC1D,IAAI,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC7C,IAAI,OAAO,GAAG,CAAC,KAA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,KAAK,CAAC;KACtB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AA3BD,oFA2BC"}

View File

@@ -0,0 +1,4 @@
import * as protobuf from 'protobufjs';
import { JSONValue } from './types';
export declare function resolveEnumValueToString(enumType: protobuf.Enum, enumValue: JSONValue): string | number;
export declare function resolveEnumValueToNumber(enumType: protobuf.Enum, enumValue: JSONValue): string | number;

View File

@@ -0,0 +1,52 @@
"use strict";
// Copyright 2021 Google LLC
//
// 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
//
// http://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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveEnumValueToNumber = exports.resolveEnumValueToString = void 0;
function resolveEnumValueToString(enumType, enumValue) {
// for unknown enum values, do not fail and try to do the best we could.
// protobuf.js fromObject() will likely ignore unknown values, but at least
// we won't fail.
if (typeof enumValue === 'number') {
const value = enumType.valuesById[enumValue];
if (typeof value === 'undefined') {
// unknown value, cannot convert to string, returning number as is
return enumValue;
}
return value;
}
if (typeof enumValue === 'string') {
// for strings, just accept what we got
return enumValue;
}
throw new Error('resolveEnumValueToString: enum value must be a string or a number');
}
exports.resolveEnumValueToString = resolveEnumValueToString;
function resolveEnumValueToNumber(enumType, enumValue) {
if (typeof enumValue === 'number') {
// return as is
return enumValue;
}
if (typeof enumValue === 'string') {
const num = enumType.values[enumValue];
if (typeof num === 'undefined') {
// unknown value, cannot convert to number, returning string as is
return enumValue;
}
return num;
}
throw new Error('resolveEnumValueToNumber: enum value must be a string or a number');
}
exports.resolveEnumValueToNumber = resolveEnumValueToNumber;
//# sourceMappingURL=enum.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../typescript/src/enum.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAKjC,SAAgB,wBAAwB,CACtC,QAAuB,EACvB,SAAoB;IAEpB,wEAAwE;IACxE,2EAA2E;IAC3E,iBAAiB;IACjB,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;YAChC,kEAAkE;YAClE,OAAO,SAAS,CAAC;SAClB;QACD,OAAO,KAAK,CAAC;KACd;IACD,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QACjC,uCAAuC;QACvC,OAAO,SAAS,CAAC;KAClB;IACD,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;AACJ,CAAC;AAtBD,4DAsBC;AAED,SAAgB,wBAAwB,CACtC,QAAuB,EACvB,SAAoB;IAEpB,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QACjC,eAAe;QACf,OAAO,SAAS,CAAC;KAClB;IACD,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QACjC,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACvC,IAAI,OAAO,GAAG,KAAK,WAAW,EAAE;YAC9B,kEAAkE;YAClE,OAAO,SAAS,CAAC;SAClB;QACD,OAAO,GAAG,CAAC;KACZ;IACD,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;AACJ,CAAC;AAnBD,4DAmBC"}

View File

@@ -0,0 +1,8 @@
import * as protobuf from 'protobufjs';
export interface FieldMask {
paths: string[];
}
export declare function googleProtobufFieldMaskToProto3JSON(obj: protobuf.Message & FieldMask): string;
export declare function googleProtobufFieldMaskFromProto3JSON(json: string): {
paths: string[];
};

View File

@@ -0,0 +1,27 @@
"use strict";
// Copyright 2021 Google LLC
//
// 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
//
// http://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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.googleProtobufFieldMaskFromProto3JSON = exports.googleProtobufFieldMaskToProto3JSON = void 0;
function googleProtobufFieldMaskToProto3JSON(obj) {
return obj.paths.join(',');
}
exports.googleProtobufFieldMaskToProto3JSON = googleProtobufFieldMaskToProto3JSON;
function googleProtobufFieldMaskFromProto3JSON(json) {
return {
paths: json.split(','),
};
}
exports.googleProtobufFieldMaskFromProto3JSON = googleProtobufFieldMaskFromProto3JSON;
//# sourceMappingURL=fieldmask.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"fieldmask.js","sourceRoot":"","sources":["../../typescript/src/fieldmask.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAQjC,SAAgB,mCAAmC,CACjD,GAAiC;IAEjC,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC;AAJD,kFAIC;AAED,SAAgB,qCAAqC,CAAC,IAAY;IAChE,OAAO;QACL,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;KACvB,CAAC;AACJ,CAAC;AAJD,sFAIC"}

View File

@@ -0,0 +1,4 @@
import * as protobuf from 'protobufjs';
import { FromObjectValue, JSONValue } from './types';
export declare function fromProto3JSONToInternalRepresentation(type: protobuf.Type | protobuf.Enum | string, json: JSONValue): FromObjectValue;
export declare function fromProto3JSON(type: protobuf.Type, json: JSONValue): protobuf.Message<{}> | null;

View File

@@ -0,0 +1,163 @@
"use strict";
// Copyright 2021 Google LLC
//
// 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
//
// http://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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromProto3JSON = exports.fromProto3JSONToInternalRepresentation = void 0;
const any_1 = require("./any");
const bytes_1 = require("./bytes");
const enum_1 = require("./enum");
const value_1 = require("./value");
const util_1 = require("./util");
const duration_1 = require("./duration");
const timestamp_1 = require("./timestamp");
const wrappers_1 = require("./wrappers");
const fieldmask_1 = require("./fieldmask");
function fromProto3JSONToInternalRepresentation(type, json) {
const fullyQualifiedTypeName = typeof type === 'string' ? type : (0, util_1.getFullyQualifiedTypeName)(type);
if (typeof type !== 'string' && 'values' in type) {
// type is an Enum
if (fullyQualifiedTypeName === '.google.protobuf.NullValue') {
return 'NULL_VALUE';
}
return (0, enum_1.resolveEnumValueToString)(type, json);
}
if (typeof type !== 'string') {
type.resolveAll();
}
if (typeof type === 'string') {
return json;
}
// Types that require special handling according to
// https://developers.google.com/protocol-buffers/docs/proto3#json
// Types that can have meaningful "null" value
if (fullyQualifiedTypeName === '.google.protobuf.Value') {
return (0, value_1.googleProtobufValueFromProto3JSON)(json);
}
if (util_1.wrapperTypes.has(fullyQualifiedTypeName)) {
if ((json !== null && typeof json === 'object') || Array.isArray(json)) {
throw new Error(`fromProto3JSONToInternalRepresentation: JSON representation for ${fullyQualifiedTypeName} expects a string, a number, or a boolean, but got ${typeof json}`);
}
return (0, wrappers_1.wrapperFromProto3JSON)(fullyQualifiedTypeName, json);
}
if (json === null) {
return null;
}
// Types that cannot be "null"
if (fullyQualifiedTypeName === '.google.protobuf.Any') {
return (0, any_1.googleProtobufAnyFromProto3JSON)(type.root, json);
}
if (fullyQualifiedTypeName === '.google.protobuf.Struct') {
if (typeof json !== 'object') {
throw new Error(`fromProto3JSONToInternalRepresentation: google.protobuf.Struct must be an object but got ${typeof json}`);
}
if (Array.isArray(json)) {
throw new Error('fromProto3JSONToInternalRepresentation: google.protobuf.Struct must be an object but got an array');
}
return (0, value_1.googleProtobufStructFromProto3JSON)(json);
}
if (fullyQualifiedTypeName === '.google.protobuf.ListValue') {
if (!Array.isArray(json)) {
throw new Error(`fromProto3JSONToInternalRepresentation: google.protobuf.ListValue must be an array but got ${typeof json}`);
}
return (0, value_1.googleProtobufListValueFromProto3JSON)(json);
}
if (fullyQualifiedTypeName === '.google.protobuf.Duration') {
if (typeof json !== 'string') {
throw new Error(`fromProto3JSONToInternalRepresentation: google.protobuf.Duration must be a string but got ${typeof json}`);
}
return (0, duration_1.googleProtobufDurationFromProto3JSON)(json);
}
if (fullyQualifiedTypeName === '.google.protobuf.Timestamp') {
if (typeof json !== 'string') {
throw new Error(`fromProto3JSONToInternalRepresentation: google.protobuf.Timestamp must be a string but got ${typeof json}`);
}
return (0, timestamp_1.googleProtobufTimestampFromProto3JSON)(json);
}
if (fullyQualifiedTypeName === '.google.protobuf.FieldMask') {
if (typeof json !== 'string') {
throw new Error(`fromProto3JSONToInternalRepresentation: google.protobuf.FieldMask must be a string but got ${typeof json}`);
}
return (0, fieldmask_1.googleProtobufFieldMaskFromProto3JSON)(json);
}
const result = {};
for (const [key, value] of Object.entries(json)) {
const field = type.fields[key];
if (!field) {
continue;
}
const resolvedType = field.resolvedType;
const fieldType = field.type;
if (field.repeated) {
if (value === null) {
result[key] = [];
}
else {
if (!Array.isArray(value)) {
throw new Error(`fromProto3JSONToInternalRepresentation: expected an array for field ${key}`);
}
result[key] = value.map(element => fromProto3JSONToInternalRepresentation(resolvedType || fieldType, element));
}
}
else if (field.map) {
const map = {};
for (const [mapKey, mapValue] of Object.entries(value)) {
map[mapKey] = fromProto3JSONToInternalRepresentation(resolvedType || fieldType, mapValue);
}
result[key] = map;
}
else if (fieldType.match(/^(?:(?:(?:u?int|fixed)(?:32|64))|float|double)$/)) {
if (typeof value !== 'number' && typeof value !== 'string') {
throw new Error(`fromProto3JSONToInternalRepresentation: field ${key} of type ${field.type} cannot contain value ${value}`);
}
result[key] = value;
}
else if (fieldType === 'string') {
if (typeof value !== 'string') {
throw new Error(`fromProto3JSONToInternalRepresentation: field ${key} of type ${field.type} cannot contain value ${value}`);
}
result[key] = value;
}
else if (fieldType === 'bool') {
if (typeof value !== 'boolean') {
throw new Error(`fromProto3JSONToInternalRepresentation: field ${key} of type ${field.type} cannot contain value ${value}`);
}
result[key] = value;
}
else if (fieldType === 'bytes') {
if (typeof value !== 'string') {
throw new Error(`fromProto3JSONToInternalRepresentation: field ${key} of type ${field.type} cannot contain value ${value}`);
}
result[key] = (0, bytes_1.bytesFromProto3JSON)(value);
}
else {
// Message type
(0, util_1.assert)(resolvedType !== null, `Expected to be able to resolve type for field ${field.name}`);
const deserializedValue = fromProto3JSONToInternalRepresentation(resolvedType, value);
result[key] = deserializedValue;
}
}
return result;
}
exports.fromProto3JSONToInternalRepresentation = fromProto3JSONToInternalRepresentation;
function fromProto3JSON(type, json) {
const internalRepr = fromProto3JSONToInternalRepresentation(type, json);
if (internalRepr === null) {
return null;
}
// We only expect a real object here sine all special cases should be already resolved. Everything else is an internal error
(0, util_1.assert)(typeof internalRepr === 'object' && !Array.isArray(internalRepr), `fromProto3JSON: expected an object, not ${json}`);
return type.fromObject(internalRepr);
}
exports.fromProto3JSON = fromProto3JSON;
//# sourceMappingURL=fromproto3json.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"fromproto3json.js","sourceRoot":"","sources":["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eAAe;YACf,IAAA,aAAM,EACJ,YAAY,KAAK,IAAI,EACrB,iDAAiD,KAAK,CAAC,IAAI,EAAE,CAC9D,CAAC;YACF,MAAM,iBAAiB,GAAG,sCAAsC,CAC9D,YAAa,EACb,KAAK,CACN,CAAC;YACF,MAAM,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC;SACjC;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AApLD,wFAoLC;AAED,SAAgB,cAAc,CAAC,IAAmB,EAAE,IAAe;IACjE,MAAM,YAAY,GAAG,sCAAsC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACxE,IAAI,YAAY,KAAK,IAAI,EAAE;QACzB,OAAO,IAAI,CAAC;KACb;IACD,4HAA4H;IAC5H,IAAA,aAAM,EACJ,OAAO,YAAY,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAChE,2CAA2C,IAAI,EAAE,CAClD,CAAC;IACF,OAAO,IAAI,CAAC,UAAU,CAAC,YAAkB,CAAC,CAAC;AAC7C,CAAC;AAXD,wCAWC"}

View File

@@ -0,0 +1,3 @@
export { JSONObject, JSONValue } from './types';
export { toProto3JSON, ToProto3JSONOptions } from './toproto3json';
export { fromProto3JSON } from './fromproto3json';

View File

@@ -0,0 +1,21 @@
"use strict";
// Copyright 2021 Google LLC
//
// 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
//
// http://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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromProto3JSON = exports.toProto3JSON = void 0;
var toproto3json_1 = require("./toproto3json");
Object.defineProperty(exports, "toProto3JSON", { enumerable: true, get: function () { return toproto3json_1.toProto3JSON; } });
var fromproto3json_1 = require("./fromproto3json");
Object.defineProperty(exports, "fromProto3JSON", { enumerable: true, get: function () { return fromproto3json_1.fromProto3JSON; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../typescript/src/index.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAGjC,+CAAiE;AAAzD,4GAAA,YAAY,OAAA;AACpB,mDAAgD;AAAxC,gHAAA,cAAc,OAAA"}

View File

@@ -0,0 +1,10 @@
import * as protobuf from 'protobufjs';
import { FromObjectValue } from './types';
export interface Timestamp {
seconds: number;
nanos?: number;
}
export declare function googleProtobufTimestampToProto3JSON(obj: protobuf.Message & Timestamp): string;
export declare function googleProtobufTimestampFromProto3JSON(json: string): {
[key: string]: FromObjectValue;
};

View File

@@ -0,0 +1,57 @@
"use strict";
// Copyright 2021 Google LLC
//
// 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
//
// http://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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.googleProtobufTimestampFromProto3JSON = exports.googleProtobufTimestampToProto3JSON = void 0;
function googleProtobufTimestampToProto3JSON(obj) {
var _a;
// seconds is an instance of Long so it won't be undefined
const durationSeconds = obj.seconds;
const date = new Date(durationSeconds * 1000).toISOString();
// Pad leading zeros if nano string length is less than 9.
let nanos = (_a = obj.nanos) === null || _a === void 0 ? void 0 : _a.toString().padStart(9, '0');
// Trim the unsignificant zeros and keep 3, 6, or 9 decimal digits.
while (nanos && nanos.length > 3 && nanos.endsWith('000')) {
nanos = nanos.slice(0, -3);
}
return date.replace(/(?:\.\d{0,9})/, '.' + nanos);
}
exports.googleProtobufTimestampToProto3JSON = googleProtobufTimestampToProto3JSON;
function googleProtobufTimestampFromProto3JSON(json) {
const match = json.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?/);
if (!match) {
throw new Error(`googleProtobufDurationFromProto3JSON: incorrect value ${json} passed as google.protobuf.Duration`);
}
const date = new Date(json);
const millisecondsSinceEpoch = date.getTime();
const seconds = Math.floor(millisecondsSinceEpoch / 1000);
// The fractional seconds in the JSON timestamps can go up to 9 digits (i.e. up to 1 nanosecond resolution).
// However, Javascript Date object represent any date and time to millisecond precision.
// To keep the precision, we extract the fractional seconds and append 0 until the length is equal to 9.
let nanos = 0;
const secondsFromDate = json.split('.')[1];
if (secondsFromDate) {
nanos = parseInt(secondsFromDate.slice(0, -1).padEnd(9, '0'));
}
const result = {};
if (seconds !== 0) {
result.seconds = seconds;
}
if (nanos !== 0) {
result.nanos = nanos;
}
return result;
}
exports.googleProtobufTimestampFromProto3JSON = googleProtobufTimestampFromProto3JSON;
//# sourceMappingURL=timestamp.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"timestamp.js","sourceRoot":"","sources":["../../typescript/src/timestamp.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAUjC,SAAgB,mCAAmC,CACjD,GAAiC;;IAEjC,0DAA0D;IAC1D,MAAM,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC;IACpC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC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ACnC,IAAI,OAAO,KAAK,CAAC,EAAE;QACjB,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;KAC1B;IACD,IAAI,KAAK,KAAK,CAAC,EAAE;QACf,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;KACtB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AA1BD,sFA0BC"}

View File

@@ -0,0 +1,6 @@
import * as protobuf from 'protobufjs';
import { JSONValue } from './types';
export interface ToProto3JSONOptions {
numericEnums: boolean;
}
export declare function toProto3JSON(obj: protobuf.Message, options?: ToProto3JSONOptions): JSONValue;

View File

@@ -0,0 +1,143 @@
"use strict";
// Copyright 2021 Google LLC
//
// 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
//
// http://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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.toProto3JSON = void 0;
const any_1 = require("./any");
const bytes_1 = require("./bytes");
const util_1 = require("./util");
const enum_1 = require("./enum");
const value_1 = require("./value");
const duration_1 = require("./duration");
const timestamp_1 = require("./timestamp");
const wrappers_1 = require("./wrappers");
const fieldmask_1 = require("./fieldmask");
// Convert a single value, which might happen to be an instance of Long, to JSONValue
function convertSingleValue(value) {
var _a;
if (typeof value === 'object') {
if (((_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'Long') {
return value.toString();
}
throw new Error(`toProto3JSON: don't know how to convert value ${value}`);
}
return value;
}
function toProto3JSON(obj, options) {
const objType = obj.$type;
if (!objType) {
throw new Error('Cannot serialize object to proto3 JSON since its .$type is unknown. Use Type.fromObject(obj) before calling toProto3JSON.');
}
objType.resolveAll();
const typeName = (0, util_1.getFullyQualifiedTypeName)(objType);
// Types that require special handling according to
// https://developers.google.com/protocol-buffers/docs/proto3#json
if (typeName === '.google.protobuf.Any') {
return (0, any_1.googleProtobufAnyToProto3JSON)(obj, options);
}
if (typeName === '.google.protobuf.Value') {
return (0, value_1.googleProtobufValueToProto3JSON)(obj);
}
if (typeName === '.google.protobuf.Struct') {
return (0, value_1.googleProtobufStructToProto3JSON)(obj);
}
if (typeName === '.google.protobuf.ListValue') {
return (0, value_1.googleProtobufListValueToProto3JSON)(obj);
}
if (typeName === '.google.protobuf.Duration') {
return (0, duration_1.googleProtobufDurationToProto3JSON)(obj);
}
if (typeName === '.google.protobuf.Timestamp') {
return (0, timestamp_1.googleProtobufTimestampToProto3JSON)(obj);
}
if (typeName === '.google.protobuf.FieldMask') {
return (0, fieldmask_1.googleProtobufFieldMaskToProto3JSON)(obj);
}
if (util_1.wrapperTypes.has(typeName)) {
return (0, wrappers_1.wrapperToProto3JSON)(obj);
}
const result = {};
for (const [key, value] of Object.entries(obj)) {
const field = objType.fields[key];
const fieldResolvedType = field.resolvedType;
const fieldFullyQualifiedTypeName = fieldResolvedType
? (0, util_1.getFullyQualifiedTypeName)(fieldResolvedType)
: null;
if (value === null) {
result[key] = null;
continue;
}
if (Array.isArray(value)) {
if (value.length === 0) {
// ignore repeated fields with no values
continue;
}
// if the repeated value has a complex type, convert it to proto3 JSON, otherwise use as is
result[key] = value.map(fieldResolvedType
? element => {
return toProto3JSON(element, options);
}
: convertSingleValue);
continue;
}
if (field.map) {
const map = {};
for (const [mapKey, mapValue] of Object.entries(value)) {
// if the map value has a complex type, convert it to proto3 JSON, otherwise use as is
map[mapKey] = fieldResolvedType
? toProto3JSON(mapValue, options)
: convertSingleValue(mapValue);
}
result[key] = map;
continue;
}
if (fieldFullyQualifiedTypeName === '.google.protobuf.NullValue') {
result[key] = null;
continue;
}
if (fieldResolvedType && 'values' in fieldResolvedType && value !== null) {
if (options === null || options === void 0 ? void 0 : options.numericEnums) {
result[key] = (0, enum_1.resolveEnumValueToNumber)(fieldResolvedType, value);
}
else {
result[key] = (0, enum_1.resolveEnumValueToString)(fieldResolvedType, value);
}
continue;
}
if (fieldResolvedType) {
result[key] = toProto3JSON(value, options);
continue;
}
if (typeof value === 'string' ||
typeof value === 'number' ||
typeof value === 'boolean' ||
value === null) {
if (typeof value === 'number' && !Number.isFinite(value)) {
result[key] = value.toString();
continue;
}
result[key] = value;
continue;
}
if (Buffer.isBuffer(value) || value instanceof Uint8Array) {
result[key] = (0, bytes_1.bytesToProto3JSON)(value);
continue;
}
result[key] = convertSingleValue(value);
continue;
}
return result;
}
exports.toProto3JSON = toProto3JSON;
//# sourceMappingURL=toproto3json.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"toproto3json.js","sourceRoot":"","sources":["../../typescript/src/toproto3json.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAIjC,+BAAyD;AACzD,mCAA0C;AAC1C,iCAA+D;AAC/D,iCAA0E;AAC1E,mCAOiB;AACjB,yCAAwE;AACxE,2CAA2E;AAC3E,yCAMoB;AACpB,2CAA2E;AAM3E,qFAAqF;AACrF,SAAS,kBAAkB,CAAC,KAAyB;;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,IAAI,CAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,0CAAE,IAAI,MAAK,MAAM,EAAE;YACvC,OAAQ,KAAkB,CAAC,QAAQ,EAAE,CAAC;SACvC;QACD,MAAM,IAAI,KAAK,CAAC,iDAAiD,KAAK,EAAE,CAAC,CAAC;KAC3E;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAgB,YAAY,CAC1B,GAAqB,EACrB,OAA6B;IAE7B,MAAM,OAAO,GAAG,GAAG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AI,EAAE;YACxE,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,EAAE;gBACzB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAA,+BAAwB,EAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;aAClE;iBAAM;gBACL,MAAM,CAAC,GAAG,CAAC,GAAG,IAAA,+BAAwB,EAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;aAClE;YACD,SAAS;SACV;QACD,IAAI,iBAAiB,EAAE;YACrB,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAC3C,SAAS;SACV;QACD,IACE,OAAO,KAAK,KAAK,QAAQ;YACzB,OAAO,KAAK,KAAK,QAAQ;YACzB,OAAO,KAAK,KAAK,SAAS;YAC1B,KAAK,KAAK,IAAI,EACd;YACA,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;gBACxD,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;gBAC/B,SAAS;aACV;YACD,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACpB,SAAS;SACV;QACD,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,YAAY,UAAU,EAAE;YACzD,MAAM,CAAC,GAAG,CAAC,GAAG,IAAA,yBAAiB,EAAC,KAAK,CAAC,CAAC;YACvC,SAAS;SACV;QACD,MAAM,CAAC,GAAG,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACxC,SAAS;KACV;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAxID,oCAwIC"}

View File

@@ -0,0 +1,13 @@
/// <reference types="node" />
export type JSONValue = string | number | boolean | null | JSONValue[] | {
[key: string]: JSONValue;
};
export interface JSONObject {
[key: string]: JSONValue;
}
export type FromObjectValue = string | number | boolean | null | FromObjectValue[] | Buffer | Uint8Array | {
[key: string]: FromObjectValue;
};
export interface LongStub {
toString: () => string;
}

View File

@@ -0,0 +1,16 @@
"use strict";
// Copyright 2021 Google LLC
//
// 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
//
// http://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.
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../typescript/src/types.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC"}

View File

@@ -0,0 +1,3 @@
export declare function getFullyQualifiedTypeName(type: protobuf.Type | protobuf.Namespace | protobuf.Enum): string;
export declare const wrapperTypes: Set<string>;
export declare function assert(assertion: boolean, message: string): void;

View File

@@ -0,0 +1,44 @@
"use strict";
// Copyright 2021 Google LLC
//
// 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
//
// http://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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.assert = exports.wrapperTypes = exports.getFullyQualifiedTypeName = void 0;
function getFullyQualifiedTypeName(type) {
// We assume that the protobuf package tree cannot have cycles.
let fullyQualifiedTypeName = '';
while (type.parent) {
fullyQualifiedTypeName = `.${type.name}${fullyQualifiedTypeName}`;
type = type.parent;
}
return fullyQualifiedTypeName;
}
exports.getFullyQualifiedTypeName = getFullyQualifiedTypeName;
exports.wrapperTypes = new Set([
'.google.protobuf.DoubleValue',
'.google.protobuf.FloatValue',
'.google.protobuf.Int64Value',
'.google.protobuf.UInt64Value',
'.google.protobuf.Int32Value',
'.google.protobuf.UInt32Value',
'.google.protobuf.BoolValue',
'.google.protobuf.StringValue',
'.google.protobuf.BytesValue',
]);
function assert(assertion, message) {
if (!assertion) {
throw new Error(message);
}
}
exports.assert = assert;
//# sourceMappingURL=util.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../typescript/src/util.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAEjC,SAAgB,yBAAyB,CACvC,IAAwD;IAExD,+DAA+D;IAC/D,IAAI,sBAAsB,GAAG,EAAE,CAAC;IAChC,OAAO,IAAI,CAAC,MAAM,EAAE;QAClB,sBAAsB,GAAG,IAAI,IAAI,CAAC,IAAI,GAAG,sBAAsB,EAAE,CAAC;QAClE,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;KACpB;IACD,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAVD,8DAUC;AAEY,QAAA,YAAY,GAAG,IAAI,GAAG,CAAC;IAClC,8BAA8B;IAC9B,6BAA6B;IAC7B,6BAA6B;IAC7B,8BAA8B;IAC9B,6BAA6B;IAC7B,8BAA8B;IAC9B,4BAA4B;IAC5B,8BAA8B;IAC9B,6BAA6B;CAC9B,CAAC,CAAC;AAEH,SAAgB,MAAM,CAAC,SAAkB,EAAE,OAAe;IACxD,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC1B;AACH,CAAC;AAJD,wBAIC"}

View File

@@ -0,0 +1,23 @@
import { FromObjectValue, JSONObject, JSONValue } from './types';
export interface Struct {
fields: {
[key: string]: Value;
};
}
export interface ListValue {
values: Array<Value>;
}
export interface Value {
nullValue?: 0;
numberValue?: number;
stringValue?: string;
boolValue?: boolean;
listValue?: ListValue;
structValue?: Struct;
}
export declare function googleProtobufStructToProto3JSON(obj: protobuf.Message & Struct): JSONObject;
export declare function googleProtobufListValueToProto3JSON(obj: protobuf.Message & ListValue): JSONValue[];
export declare function googleProtobufValueToProto3JSON(obj: protobuf.Message & Value): JSONValue;
export declare function googleProtobufStructFromProto3JSON(json: JSONObject): FromObjectValue;
export declare function googleProtobufListValueFromProto3JSON(json: JSONValue[]): FromObjectValue;
export declare function googleProtobufValueFromProto3JSON(json: JSONValue): FromObjectValue;

View File

@@ -0,0 +1,104 @@
"use strict";
// Copyright 2021 Google LLC
//
// 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
//
// http://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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.googleProtobufValueFromProto3JSON = exports.googleProtobufListValueFromProto3JSON = exports.googleProtobufStructFromProto3JSON = exports.googleProtobufValueToProto3JSON = exports.googleProtobufListValueToProto3JSON = exports.googleProtobufStructToProto3JSON = void 0;
const util_1 = require("./util");
function googleProtobufStructToProto3JSON(obj) {
const result = {};
const fields = obj.fields;
for (const [key, value] of Object.entries(fields)) {
result[key] = googleProtobufValueToProto3JSON(value);
}
return result;
}
exports.googleProtobufStructToProto3JSON = googleProtobufStructToProto3JSON;
function googleProtobufListValueToProto3JSON(obj) {
(0, util_1.assert)(Array.isArray(obj.values), 'ListValue internal representation must contain array of values');
return obj.values.map(googleProtobufValueToProto3JSON);
}
exports.googleProtobufListValueToProto3JSON = googleProtobufListValueToProto3JSON;
function googleProtobufValueToProto3JSON(obj) {
if (Object.prototype.hasOwnProperty.call(obj, 'nullValue')) {
return null;
}
if (Object.prototype.hasOwnProperty.call(obj, 'numberValue') &&
typeof obj.numberValue === 'number') {
if (!Number.isFinite(obj.numberValue)) {
return obj.numberValue.toString();
}
return obj.numberValue;
}
if (Object.prototype.hasOwnProperty.call(obj, 'stringValue') &&
typeof obj.stringValue === 'string') {
return obj.stringValue;
}
if (Object.prototype.hasOwnProperty.call(obj, 'boolValue') &&
typeof obj.boolValue === 'boolean') {
return obj.boolValue;
}
if (Object.prototype.hasOwnProperty.call(obj, 'structValue') &&
typeof obj.structValue === 'object') {
return googleProtobufStructToProto3JSON(obj.structValue);
}
if (Object.prototype.hasOwnProperty.call(obj, 'listValue') &&
typeof obj === 'object' &&
typeof obj.listValue === 'object') {
return googleProtobufListValueToProto3JSON(obj.listValue);
}
// Assuming empty Value to be null
return null;
}
exports.googleProtobufValueToProto3JSON = googleProtobufValueToProto3JSON;
function googleProtobufStructFromProto3JSON(json) {
const fields = {};
for (const [key, value] of Object.entries(json)) {
fields[key] = googleProtobufValueFromProto3JSON(value);
}
return { fields };
}
exports.googleProtobufStructFromProto3JSON = googleProtobufStructFromProto3JSON;
function googleProtobufListValueFromProto3JSON(json) {
return {
values: json.map(element => googleProtobufValueFromProto3JSON(element)),
};
}
exports.googleProtobufListValueFromProto3JSON = googleProtobufListValueFromProto3JSON;
function googleProtobufValueFromProto3JSON(json) {
if (json === null) {
return { nullValue: 'NULL_VALUE' };
}
if (typeof json === 'number') {
return { numberValue: json };
}
if (typeof json === 'string') {
return { stringValue: json };
}
if (typeof json === 'boolean') {
return { boolValue: json };
}
if (Array.isArray(json)) {
return {
listValue: googleProtobufListValueFromProto3JSON(json),
};
}
if (typeof json === 'object') {
return {
structValue: googleProtobufStructFromProto3JSON(json),
};
}
throw new Error(`googleProtobufValueFromProto3JSON: incorrect parameter type: ${typeof json}`);
}
exports.googleProtobufValueFromProto3JSON = googleProtobufValueFromProto3JSON;
//# sourceMappingURL=value.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../typescript/src/value.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAEjC,iCAA8B;AAsB9B,SAAgB,gCAAgC,CAC9C,GAA8B;IAE9B,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjD,MAAM,CAAC,GAAG,CAAC,GAAG,+BAA+B,CAC3C,KAAiC,CAClC,CAAC;KACH;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAXD,4EAWC;AAED,SAAgB,mCAAmC,CACjD,GAAiC;IAEjC,IAAA,aAAM,EACJ,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EACzB,gEAAgE,CACjE,CAAC;IACF,OAAQ,GAAG,CAAC,MAA0C,CAAC,GAAG,CACxD,+BAA+B,CAChC,CAAC;AACJ,CAAC;AAVD,kFAUC;AAED,SAAgB,+BAA+B,CAC7C,GAA6B;IAE7B,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE;QAC1D,OAAO,IAAI,CAAC;KACb;IAED,IACE,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,a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C,MAAM,CAAC,GAAG,CAAC,GAAG,iCAAiC,CAAC,KAAK,CAAC,CAAC;KACxD;IACD,OAAO,EAAC,MAAM,EAAC,CAAC;AAClB,CAAC;AARD,gFAQC;AAED,SAAgB,qCAAqC,CACnD,IAAiB;IAEjB,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,iCAAiC,CAAC,OAAO,CAAC,CAAC;KACxE,CAAC;AACJ,CAAC;AAND,sFAMC;AAED,SAAgB,iCAAiC,CAC/C,IAAe;IAEf,IAAI,IAAI,KAAK,IAAI,EAAE;QACjB,OAAO,EAAC,SAAS,EAAE,YAAY,EAAC,CAAC;KAClC;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,EAAC,WAAW,EAAE,IAAI,EAAC,CAAC;KAC5B;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,EAAC,WAAW,EAAE,IAAI,EAAC,CAAC;KAC5B;IAED,IAAI,OAAO,IAAI,KAAK,SAAS,EAAE;QAC7B,OAAO,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC;KAC1B;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACvB,OAAO;YACL,SAAS,EAAE,qCAAqC,CAAC,IAAI,CAAC;SACvD,CAAC;KACH;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO;YACL,WAAW,EAAE,kCAAkC,CAAC,IAAI,CAAC;SACtD,CAAC;KACH;IAED,MAAM,IAAI,KAAK,CACb,gEAAgE,OAAO,IAAI,EAAE,CAC9E,CAAC;AACJ,CAAC;AAlCD,8EAkCC"}

View File

@@ -0,0 +1,21 @@
/// <reference types="node" />
export interface NumberValue {
value: number | object;
}
export interface StringValue {
value: string;
}
export interface BoolValue {
value: boolean;
}
export interface BytesValue {
value: Buffer | Uint8Array;
}
export declare function wrapperToProto3JSON(obj: protobuf.Message & (NumberValue | StringValue | BoolValue | BytesValue)): string | number | boolean | null;
export declare function wrapperFromProto3JSON(typeName: string, json: number | string | boolean | null): {
value: null;
} | {
value: Buffer;
} | {
value: string | number | boolean;
};

View File

@@ -0,0 +1,56 @@
"use strict";
// Copyright 2021 Google LLC
//
// 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
//
// http://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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapperFromProto3JSON = exports.wrapperToProto3JSON = void 0;
const bytes_1 = require("./bytes");
const util_1 = require("./util");
function wrapperToProto3JSON(obj) {
if (!Object.prototype.hasOwnProperty.call(obj, 'value')) {
return null;
}
if (Buffer.isBuffer(obj.value) || obj.value instanceof Uint8Array) {
return (0, bytes_1.bytesToProto3JSON)(obj.value);
}
if (typeof obj.value === 'object') {
(0, util_1.assert)(obj.value.constructor.name === 'Long', `wrapperToProto3JSON: expected to see a number, a string, a boolean, or a Long, but got ${obj.value}`);
return obj.value.toString();
}
// JSON accept special string values "NaN", "Infinity", and "-Infinity".
if (typeof obj.value === 'number' && !Number.isFinite(obj.value)) {
return obj.value.toString();
}
return obj.value;
}
exports.wrapperToProto3JSON = wrapperToProto3JSON;
function wrapperFromProto3JSON(typeName, json) {
if (json === null) {
return {
value: null,
};
}
if (typeName === '.google.protobuf.BytesValue') {
if (typeof json !== 'string') {
throw new Error(`numberWrapperFromProto3JSON: expected to get a string for google.protobuf.BytesValue but got ${typeof json}`);
}
return {
value: (0, bytes_1.bytesFromProto3JSON)(json),
};
}
return {
value: json,
};
}
exports.wrapperFromProto3JSON = wrapperFromProto3JSON;
//# sourceMappingURL=wrappers.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"wrappers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;KACH;IACD,IAAI,QAAQ,KAAK,6BAA6B,EAAE;QAC9C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YAC5B,MAAM,IAAI,KAAK,CACb,gGAAgG,OAAO,IAAI,EAAE,CAC9G,CAAC;SACH;QACD,OAAO;YACL,KAAK,EAAE,IAAA,2BAAmB,EAAC,IAAI,CAAC;SACjC,CAAC;KACH;IACD,OAAO;QACL,KAAK,EAAE,IAAI;KACZ,CAAC;AACJ,CAAC;AAtBD,sDAsBC"}

View File

@@ -0,0 +1,59 @@
{
"name": "proto3-json-serializer",
"version": "2.0.2",
"repository": "googleapis/proto3-json-serializer-nodejs",
"description": "Support for proto3 JSON serialiazation/deserialization for protobuf.js",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"files": [
"build/src"
],
"license": "Apache-2.0",
"keywords": [
"protobufjs",
"protobuf.js",
"protobuf",
"proto3",
"json",
"serialization",
"deserialization"
],
"scripts": {
"test": "c8 node_modules/mocha/bin/mocha build/test/unit",
"system-test": "mocha build/test/system",
"lint": "gts lint",
"clean": "gts clean",
"compile": "tsc",
"fix": "gts fix",
"prepare": "npm run compile",
"pretest": "npm run compile",
"posttest": "npm run lint",
"compile-test-protos": "cd test-fixtures/proto && pbjs -t json test.proto > test.json",
"docs": "jsdoc -c .jsdoc.js",
"docs-test": "linkinator docs",
"predocs-test": "npm run docs",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
"prelint": "cd samples && npm link ../ && npm install"
},
"dependencies": {
"protobufjs": "^7.2.5"
},
"devDependencies": {
"@types/mocha": "^9.0.0",
"@types/node": "^20.0.0",
"c8": "^9.0.0",
"google-proto-files": "^4.0.0",
"gts": "^5.0.0",
"jsdoc": "^4.0.0",
"jsdoc-fresh": "^3.0.0",
"jsdoc-region-tag": "^3.0.0",
"linkinator": "^5.0.0",
"mocha": "^9.2.2",
"pack-n-play": "^2.0.0",
"protobufjs-cli": "^1.1.2",
"typescript": "^4.6.4"
},
"engines": {
"node": ">=14.0.0"
}
}