index-light.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. "use strict";
  2. var protobuf = module.exports = require("./index-minimal");
  3. protobuf.build = "light";
  4. /**
  5. * A node-style callback as used by {@link load} and {@link Root#load}.
  6. * @typedef LoadCallback
  7. * @type {function}
  8. * @param {Error|null} error Error, if any, otherwise `null`
  9. * @param {Root} [root] Root, if there hasn't been an error
  10. * @returns {undefined}
  11. */
  12. /**
  13. * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
  14. * @param {string|string[]} filename One or multiple files to load
  15. * @param {Root} root Root namespace, defaults to create a new one if omitted.
  16. * @param {LoadCallback} callback Callback function
  17. * @returns {undefined}
  18. * @see {@link Root#load}
  19. */
  20. function load(filename, root, callback) {
  21. if (typeof root === "function") {
  22. callback = root;
  23. root = new protobuf.Root();
  24. } else if (!root)
  25. root = new protobuf.Root();
  26. return root.load(filename, callback);
  27. }
  28. /**
  29. * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
  30. * @name load
  31. * @function
  32. * @param {string|string[]} filename One or multiple files to load
  33. * @param {LoadCallback} callback Callback function
  34. * @returns {undefined}
  35. * @see {@link Root#load}
  36. * @variation 2
  37. */
  38. // function load(filename:string, callback:LoadCallback):undefined
  39. /**
  40. * Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.
  41. * @name load
  42. * @function
  43. * @param {string|string[]} filename One or multiple files to load
  44. * @param {Root} [root] Root namespace, defaults to create a new one if omitted.
  45. * @returns {Promise<Root>} Promise
  46. * @see {@link Root#load}
  47. * @variation 3
  48. */
  49. // function load(filename:string, [root:Root]):Promise<Root>
  50. protobuf.load = load;
  51. /**
  52. * Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).
  53. * @param {string|string[]} filename One or multiple files to load
  54. * @param {Root} [root] Root namespace, defaults to create a new one if omitted.
  55. * @returns {Root} Root namespace
  56. * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
  57. * @see {@link Root#loadSync}
  58. */
  59. function loadSync(filename, root) {
  60. if (!root)
  61. root = new protobuf.Root();
  62. return root.loadSync(filename);
  63. }
  64. protobuf.loadSync = loadSync;
  65. // Serialization
  66. protobuf.encoder = require("./encoder");
  67. protobuf.decoder = require("./decoder");
  68. protobuf.verifier = require("./verifier");
  69. protobuf.converter = require("./converter");
  70. // Reflection
  71. protobuf.ReflectionObject = require("./object");
  72. protobuf.Namespace = require("./namespace");
  73. protobuf.Root = require("./root");
  74. protobuf.Enum = require("./enum");
  75. protobuf.Type = require("./type");
  76. protobuf.Field = require("./field");
  77. protobuf.OneOf = require("./oneof");
  78. protobuf.MapField = require("./mapfield");
  79. protobuf.Service = require("./service");
  80. protobuf.Method = require("./method");
  81. // Runtime
  82. protobuf.Message = require("./message");
  83. protobuf.wrappers = require("./wrappers");
  84. // Utility
  85. protobuf.types = require("./types");
  86. protobuf.util = require("./util");
  87. // Set up possibly cyclic reflection dependencies
  88. protobuf.ReflectionObject._configure(protobuf.Root);
  89. protobuf.Namespace._configure(protobuf.Type, protobuf.Service, protobuf.Enum);
  90. protobuf.Root._configure(protobuf.Type);
  91. protobuf.Field._configure(protobuf.Type);