123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- "use strict";
- module.exports = common;
- var commonRe = /\/|\./;
- /**
- * Provides common type definitions.
- * Can also be used to provide additional google types or your own custom types.
- * @param {string} name Short name as in `google/protobuf/[name].proto` or full file name
- * @param {Object.<string,*>} json JSON definition within `google.protobuf` if a short name, otherwise the file's root definition
- * @returns {undefined}
- * @property {INamespace} google/protobuf/any.proto Any
- * @property {INamespace} google/protobuf/duration.proto Duration
- * @property {INamespace} google/protobuf/empty.proto Empty
- * @property {INamespace} google/protobuf/field_mask.proto FieldMask
- * @property {INamespace} google/protobuf/struct.proto Struct, Value, NullValue and ListValue
- * @property {INamespace} google/protobuf/timestamp.proto Timestamp
- * @property {INamespace} google/protobuf/wrappers.proto Wrappers
- * @example
- * // manually provides descriptor.proto (assumes google/protobuf/ namespace and .proto extension)
- * protobuf.common("descriptor", descriptorJson);
- *
- * // manually provides a custom definition (uses my.foo namespace)
- * protobuf.common("my/foo/bar.proto", myFooBarJson);
- */
- function common(name, json) {
- if (!commonRe.test(name)) {
- name = "google/protobuf/" + name + ".proto";
- json = { nested: { google: { nested: { protobuf: { nested: json } } } } };
- }
- common[name] = json;
- }
- // Not provided because of limited use (feel free to discuss or to provide yourself):
- //
- // google/protobuf/descriptor.proto
- // google/protobuf/source_context.proto
- // google/protobuf/type.proto
- //
- // Stripped and pre-parsed versions of these non-bundled files are instead available as part of
- // the repository or package within the google/protobuf directory.
- common("any", {
- /**
- * Properties of a google.protobuf.Any message.
- * @interface IAny
- * @type {Object}
- * @property {string} [typeUrl]
- * @property {Uint8Array} [bytes]
- * @memberof common
- */
- Any: {
- fields: {
- type_url: {
- type: "string",
- id: 1
- },
- value: {
- type: "bytes",
- id: 2
- }
- }
- }
- });
- var timeType;
- common("duration", {
- /**
- * Properties of a google.protobuf.Duration message.
- * @interface IDuration
- * @type {Object}
- * @property {number|Long} [seconds]
- * @property {number} [nanos]
- * @memberof common
- */
- Duration: timeType = {
- fields: {
- seconds: {
- type: "int64",
- id: 1
- },
- nanos: {
- type: "int32",
- id: 2
- }
- }
- }
- });
- common("timestamp", {
- /**
- * Properties of a google.protobuf.Timestamp message.
- * @interface ITimestamp
- * @type {Object}
- * @property {number|Long} [seconds]
- * @property {number} [nanos]
- * @memberof common
- */
- Timestamp: timeType
- });
- common("empty", {
- /**
- * Properties of a google.protobuf.Empty message.
- * @interface IEmpty
- * @memberof common
- */
- Empty: {
- fields: {}
- }
- });
- common("struct", {
- /**
- * Properties of a google.protobuf.Struct message.
- * @interface IStruct
- * @type {Object}
- * @property {Object.<string,IValue>} [fields]
- * @memberof common
- */
- Struct: {
- fields: {
- fields: {
- keyType: "string",
- type: "Value",
- id: 1
- }
- }
- },
- /**
- * Properties of a google.protobuf.Value message.
- * @interface IValue
- * @type {Object}
- * @property {string} [kind]
- * @property {0} [nullValue]
- * @property {number} [numberValue]
- * @property {string} [stringValue]
- * @property {boolean} [boolValue]
- * @property {IStruct} [structValue]
- * @property {IListValue} [listValue]
- * @memberof common
- */
- Value: {
- oneofs: {
- kind: {
- oneof: [
- "nullValue",
- "numberValue",
- "stringValue",
- "boolValue",
- "structValue",
- "listValue"
- ]
- }
- },
- fields: {
- nullValue: {
- type: "NullValue",
- id: 1
- },
- numberValue: {
- type: "double",
- id: 2
- },
- stringValue: {
- type: "string",
- id: 3
- },
- boolValue: {
- type: "bool",
- id: 4
- },
- structValue: {
- type: "Struct",
- id: 5
- },
- listValue: {
- type: "ListValue",
- id: 6
- }
- }
- },
- NullValue: {
- values: {
- NULL_VALUE: 0
- }
- },
- /**
- * Properties of a google.protobuf.ListValue message.
- * @interface IListValue
- * @type {Object}
- * @property {Array.<IValue>} [values]
- * @memberof common
- */
- ListValue: {
- fields: {
- values: {
- rule: "repeated",
- type: "Value",
- id: 1
- }
- }
- }
- });
- common("wrappers", {
- /**
- * Properties of a google.protobuf.DoubleValue message.
- * @interface IDoubleValue
- * @type {Object}
- * @property {number} [value]
- * @memberof common
- */
- DoubleValue: {
- fields: {
- value: {
- type: "double",
- id: 1
- }
- }
- },
- /**
- * Properties of a google.protobuf.FloatValue message.
- * @interface IFloatValue
- * @type {Object}
- * @property {number} [value]
- * @memberof common
- */
- FloatValue: {
- fields: {
- value: {
- type: "float",
- id: 1
- }
- }
- },
- /**
- * Properties of a google.protobuf.Int64Value message.
- * @interface IInt64Value
- * @type {Object}
- * @property {number|Long} [value]
- * @memberof common
- */
- Int64Value: {
- fields: {
- value: {
- type: "int64",
- id: 1
- }
- }
- },
- /**
- * Properties of a google.protobuf.UInt64Value message.
- * @interface IUInt64Value
- * @type {Object}
- * @property {number|Long} [value]
- * @memberof common
- */
- UInt64Value: {
- fields: {
- value: {
- type: "uint64",
- id: 1
- }
- }
- },
- /**
- * Properties of a google.protobuf.Int32Value message.
- * @interface IInt32Value
- * @type {Object}
- * @property {number} [value]
- * @memberof common
- */
- Int32Value: {
- fields: {
- value: {
- type: "int32",
- id: 1
- }
- }
- },
- /**
- * Properties of a google.protobuf.UInt32Value message.
- * @interface IUInt32Value
- * @type {Object}
- * @property {number} [value]
- * @memberof common
- */
- UInt32Value: {
- fields: {
- value: {
- type: "uint32",
- id: 1
- }
- }
- },
- /**
- * Properties of a google.protobuf.BoolValue message.
- * @interface IBoolValue
- * @type {Object}
- * @property {boolean} [value]
- * @memberof common
- */
- BoolValue: {
- fields: {
- value: {
- type: "bool",
- id: 1
- }
- }
- },
- /**
- * Properties of a google.protobuf.StringValue message.
- * @interface IStringValue
- * @type {Object}
- * @property {string} [value]
- * @memberof common
- */
- StringValue: {
- fields: {
- value: {
- type: "string",
- id: 1
- }
- }
- },
- /**
- * Properties of a google.protobuf.BytesValue message.
- * @interface IBytesValue
- * @type {Object}
- * @property {Uint8Array} [value]
- * @memberof common
- */
- BytesValue: {
- fields: {
- value: {
- type: "bytes",
- id: 1
- }
- }
- }
- });
- common("field_mask", {
- /**
- * Properties of a google.protobuf.FieldMask message.
- * @interface IDoubleValue
- * @type {Object}
- * @property {number} [value]
- * @memberof common
- */
- FieldMask: {
- fields: {
- paths: {
- rule: "repeated",
- type: "string",
- id: 1
- }
- }
- }
- });
- /**
- * Gets the root definition of the specified common proto file.
- *
- * Bundled definitions are:
- * - google/protobuf/any.proto
- * - google/protobuf/duration.proto
- * - google/protobuf/empty.proto
- * - google/protobuf/field_mask.proto
- * - google/protobuf/struct.proto
- * - google/protobuf/timestamp.proto
- * - google/protobuf/wrappers.proto
- *
- * @param {string} file Proto file name
- * @returns {INamespace|null} Root definition or `null` if not defined
- */
- common.get = function get(file) {
- return common[file] || null;
- };
|