diff --git a/Makefile b/Makefile index 5a3e3ce..d07d42b 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,14 @@ generate: install protoc --experimental_allow_proto3_optional \ --rust_out=proto/v1/src \ --go_out=proto/v1/go \ + --php_out=proto/v1/php \ proto/v1/api.proto +generate-php: install + protoc --experimental_allow_proto3_optional \ + --php_out=proto/v1/php \ + proto/v1/module-no-option.proto + generate-web-list-mods-response: cd scripts/protobuf-list-modules-response && cargo run --release -- $(take) mv scripts/protobuf-list-modules-response/ListModulesResponse.pb api/ diff --git a/proto/v1/module-no-option.proto b/proto/v1/module-no-option.proto new file mode 100644 index 0000000..4836743 --- /dev/null +++ b/proto/v1/module-no-option.proto @@ -0,0 +1,77 @@ +syntax = "proto3"; + +import "google/protobuf/timestamp.proto"; + +// Used to type the arguments and return types from wasm elements such as import +// and export functions. +enum ValType { + I32 = 0; + I64 = 1; + F32 = 2; + F64 = 3; + V128 = 4; + FuncRef = 5; + ExternRef = 6; +} + +// Contained by an import or export element within a wasm binary. +message Function { + repeated ValType params = 1; + repeated ValType results = 2; + string name = 3; +} + +// A function and module namespace that is defined outside of the current +// module, and referenced & called by the current module. +message Import { + string module_name = 1; + Function func = 2; +} + +// A function that is defined inside the current module, made available to +// outside modules / environments. +message Export { Function func = 1; } + +// The language (or most similar match) used to produce a wasm module. +enum SourceLanguage { + Unknown = 0; + Rust = 1; + Go = 2; + C = 3; + Cpp = 4; + AssemblyScript = 5; + Swift = 6; + JavaScript = 7; + Haskell = 8; + Zig = 9; +} + +// Details about a wasm module, either extracted directly from the binary, or +// inferred somehow. +message Module { + // ID for this module, generated by the database. + int64 id = 1; + // sha256 hash of the modules raw bytes + string hash = 3; + // function imports called by the module (see: + // + repeated Import imports = 4; + // function exports provided by the module (see: + // + repeated Export exports = 5; + // size in bytes of the module + uint64 size = 6; + // path or locator to the module + string location = 7; + // programming language used to produce this module + SourceLanguage source_language = 8; + // arbitrary metadata provided by the operator of this module + map metadata = 9; + // timestamp when this module was loaded and stored + google.protobuf.Timestamp inserted_at = 10; + // the interned strings stored in the wasm binary (panic/abort messages, etc.) + repeated string strings = 11; + // function hashes + map function_hashes = 15; +} + diff --git a/proto/v1/php/Export.php b/proto/v1/php/Export.php new file mode 100644 index 0000000..0a213b2 --- /dev/null +++ b/proto/v1/php/Export.php @@ -0,0 +1,59 @@ +Export + */ +class Export extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field .Function func = 1; + */ + protected $func = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \PBFunction $func + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Proto\V1\ModuleNoOption::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field .Function func = 1; + * @return \PBFunction + */ + public function getFunc() + { + return $this->func; + } + + /** + * Generated from protobuf field .Function func = 1; + * @param \PBFunction $var + * @return $this + */ + public function setFunc($var) + { + GPBUtil::checkMessage($var, \PBFunction::class); + $this->func = $var; + + return $this; + } + +} + diff --git a/proto/v1/php/GPBMetadata/Proto/V1/ModuleNoOption.php b/proto/v1/php/GPBMetadata/Proto/V1/ModuleNoOption.php new file mode 100644 index 0000000..668fae8 --- /dev/null +++ b/proto/v1/php/GPBMetadata/Proto/V1/ModuleNoOption.php @@ -0,0 +1,25 @@ +internalAddGeneratedFile(hex2bin( + "0adb060a1f70726f746f2f76312f6d6f64756c652d6e6f2d6f7074696f6e2e70726f746f224d0a0846756e6374696f6e12180a06706172616d7318012003280e32082e56616c5479706512190a07726573756c747318022003280e32082e56616c54797065120c0a046e616d6518032001280922360a06496d706f727412130a0b6d6f64756c655f6e616d6518012001280912170a0466756e6318022001280b32092e46756e6374696f6e22210a064578706f727412170a0466756e6318012001280b32092e46756e6374696f6e22a9030a064d6f64756c65120a0a026964180120012803120c0a046861736818032001280912180a07696d706f72747318042003280b32072e496d706f727412180a076578706f72747318052003280b32072e4578706f7274120c0a0473697a6518062001280412100a086c6f636174696f6e18072001280912280a0f736f757263655f6c616e677561676518082001280e320f2e536f757263654c616e677561676512270a086d6574616461746118092003280b32152e4d6f64756c652e4d65746164617461456e747279122f0a0b696e7365727465645f6174180a2001280b321a2e676f6f676c652e70726f746f6275662e54696d657374616d70120f0a07737472696e6773180b2003280912340a0f66756e6374696f6e5f686173686573180f2003280b321b2e4d6f64756c652e46756e6374696f6e486173686573456e7472791a2f0a0d4d65746164617461456e747279120b0a036b6579180120012809120d0a0576616c75651802200128093a0238011a350a1346756e6374696f6e486173686573456e747279120b0a036b6579180120012809120d0a0576616c75651802200128093a0238012a530a0756616c5479706512070a03493332100012070a03493634100112070a03463332100212070a03463634100312080a04563132381004120b0a0746756e635265661005120d0a0945787465726e52656610062a84010a0e536f757263654c616e6775616765120b0a07556e6b6e6f776e100012080a0452757374100112060a02476f100212050a0143100312070a03437070100412120a0e417373656d626c79536372697074100512090a0553776966741006120e0a0a4a6176615363726970741007120b0a074861736b656c6c100812070a035a69671009620670726f746f33" + ), true); + + static::$is_initialized = true; + } +} + diff --git a/proto/v1/php/Import.php b/proto/v1/php/Import.php new file mode 100644 index 0000000..077d707 --- /dev/null +++ b/proto/v1/php/Import.php @@ -0,0 +1,86 @@ +Import + */ +class Import extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field string module_name = 1; + */ + protected $module_name = ''; + /** + * Generated from protobuf field .Function func = 2; + */ + protected $func = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $module_name + * @type \PBFunction $func + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Proto\V1\ModuleNoOption::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field string module_name = 1; + * @return string + */ + public function getModuleName() + { + return $this->module_name; + } + + /** + * Generated from protobuf field string module_name = 1; + * @param string $var + * @return $this + */ + public function setModuleName($var) + { + GPBUtil::checkString($var, True); + $this->module_name = $var; + + return $this; + } + + /** + * Generated from protobuf field .Function func = 2; + * @return \PBFunction + */ + public function getFunc() + { + return $this->func; + } + + /** + * Generated from protobuf field .Function func = 2; + * @param \PBFunction $var + * @return $this + */ + public function setFunc($var) + { + GPBUtil::checkMessage($var, \PBFunction::class); + $this->func = $var; + + return $this; + } + +} + diff --git a/proto/v1/php/Module.php b/proto/v1/php/Module.php new file mode 100644 index 0000000..9e5f36d --- /dev/null +++ b/proto/v1/php/Module.php @@ -0,0 +1,414 @@ +Module + */ +class Module extends \Google\Protobuf\Internal\Message +{ + /** + * ID for this module, generated by the database. + * + * Generated from protobuf field int64 id = 1; + */ + protected $id = 0; + /** + * sha256 hash of the modules raw bytes + * + * Generated from protobuf field string hash = 3; + */ + protected $hash = ''; + /** + * function imports called by the module (see: + * + * + * Generated from protobuf field repeated .Import imports = 4; + */ + private $imports; + /** + * function exports provided by the module (see: + * + * + * Generated from protobuf field repeated .Export exports = 5; + */ + private $exports; + /** + * size in bytes of the module + * + * Generated from protobuf field uint64 size = 6; + */ + protected $size = 0; + /** + * path or locator to the module + * + * Generated from protobuf field string location = 7; + */ + protected $location = ''; + /** + * programming language used to produce this module + * + * Generated from protobuf field .SourceLanguage source_language = 8; + */ + protected $source_language = 0; + /** + * arbitrary metadata provided by the operator of this module + * + * Generated from protobuf field map metadata = 9; + */ + private $metadata; + /** + * timestamp when this module was loaded and stored + * + * Generated from protobuf field .google.protobuf.Timestamp inserted_at = 10; + */ + protected $inserted_at = null; + /** + * the interned strings stored in the wasm binary (panic/abort messages, etc.) + * + * Generated from protobuf field repeated string strings = 11; + */ + private $strings; + /** + * function hashes + * + * Generated from protobuf field map function_hashes = 15; + */ + private $function_hashes; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int|string $id + * ID for this module, generated by the database. + * @type string $hash + * sha256 hash of the modules raw bytes + * @type \Import[]|\Google\Protobuf\Internal\RepeatedField $imports + * function imports called by the module (see: + * + * @type \Export[]|\Google\Protobuf\Internal\RepeatedField $exports + * function exports provided by the module (see: + * + * @type int|string $size + * size in bytes of the module + * @type string $location + * path or locator to the module + * @type int $source_language + * programming language used to produce this module + * @type array|\Google\Protobuf\Internal\MapField $metadata + * arbitrary metadata provided by the operator of this module + * @type \Google\Protobuf\Timestamp $inserted_at + * timestamp when this module was loaded and stored + * @type string[]|\Google\Protobuf\Internal\RepeatedField $strings + * the interned strings stored in the wasm binary (panic/abort messages, etc.) + * @type array|\Google\Protobuf\Internal\MapField $function_hashes + * function hashes + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Proto\V1\ModuleNoOption::initOnce(); + parent::__construct($data); + } + + /** + * ID for this module, generated by the database. + * + * Generated from protobuf field int64 id = 1; + * @return int|string + */ + public function getId() + { + return $this->id; + } + + /** + * ID for this module, generated by the database. + * + * Generated from protobuf field int64 id = 1; + * @param int|string $var + * @return $this + */ + public function setId($var) + { + GPBUtil::checkInt64($var); + $this->id = $var; + + return $this; + } + + /** + * sha256 hash of the modules raw bytes + * + * Generated from protobuf field string hash = 3; + * @return string + */ + public function getHash() + { + return $this->hash; + } + + /** + * sha256 hash of the modules raw bytes + * + * Generated from protobuf field string hash = 3; + * @param string $var + * @return $this + */ + public function setHash($var) + { + GPBUtil::checkString($var, True); + $this->hash = $var; + + return $this; + } + + /** + * function imports called by the module (see: + * + * + * Generated from protobuf field repeated .Import imports = 4; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getImports() + { + return $this->imports; + } + + /** + * function imports called by the module (see: + * + * + * Generated from protobuf field repeated .Import imports = 4; + * @param \Import[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setImports($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Import::class); + $this->imports = $arr; + + return $this; + } + + /** + * function exports provided by the module (see: + * + * + * Generated from protobuf field repeated .Export exports = 5; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getExports() + { + return $this->exports; + } + + /** + * function exports provided by the module (see: + * + * + * Generated from protobuf field repeated .Export exports = 5; + * @param \Export[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setExports($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Export::class); + $this->exports = $arr; + + return $this; + } + + /** + * size in bytes of the module + * + * Generated from protobuf field uint64 size = 6; + * @return int|string + */ + public function getSize() + { + return $this->size; + } + + /** + * size in bytes of the module + * + * Generated from protobuf field uint64 size = 6; + * @param int|string $var + * @return $this + */ + public function setSize($var) + { + GPBUtil::checkUint64($var); + $this->size = $var; + + return $this; + } + + /** + * path or locator to the module + * + * Generated from protobuf field string location = 7; + * @return string + */ + public function getLocation() + { + return $this->location; + } + + /** + * path or locator to the module + * + * Generated from protobuf field string location = 7; + * @param string $var + * @return $this + */ + public function setLocation($var) + { + GPBUtil::checkString($var, True); + $this->location = $var; + + return $this; + } + + /** + * programming language used to produce this module + * + * Generated from protobuf field .SourceLanguage source_language = 8; + * @return int + */ + public function getSourceLanguage() + { + return $this->source_language; + } + + /** + * programming language used to produce this module + * + * Generated from protobuf field .SourceLanguage source_language = 8; + * @param int $var + * @return $this + */ + public function setSourceLanguage($var) + { + GPBUtil::checkEnum($var, \SourceLanguage::class); + $this->source_language = $var; + + return $this; + } + + /** + * arbitrary metadata provided by the operator of this module + * + * Generated from protobuf field map metadata = 9; + * @return \Google\Protobuf\Internal\MapField + */ + public function getMetadata() + { + return $this->metadata; + } + + /** + * arbitrary metadata provided by the operator of this module + * + * Generated from protobuf field map metadata = 9; + * @param array|\Google\Protobuf\Internal\MapField $var + * @return $this + */ + public function setMetadata($var) + { + $arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::STRING); + $this->metadata = $arr; + + return $this; + } + + /** + * timestamp when this module was loaded and stored + * + * Generated from protobuf field .google.protobuf.Timestamp inserted_at = 10; + * @return \Google\Protobuf\Timestamp + */ + public function getInsertedAt() + { + return $this->inserted_at; + } + + /** + * timestamp when this module was loaded and stored + * + * Generated from protobuf field .google.protobuf.Timestamp inserted_at = 10; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setInsertedAt($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->inserted_at = $var; + + return $this; + } + + /** + * the interned strings stored in the wasm binary (panic/abort messages, etc.) + * + * Generated from protobuf field repeated string strings = 11; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getStrings() + { + return $this->strings; + } + + /** + * the interned strings stored in the wasm binary (panic/abort messages, etc.) + * + * Generated from protobuf field repeated string strings = 11; + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setStrings($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->strings = $arr; + + return $this; + } + + /** + * function hashes + * + * Generated from protobuf field map function_hashes = 15; + * @return \Google\Protobuf\Internal\MapField + */ + public function getFunctionHashes() + { + return $this->function_hashes; + } + + /** + * function hashes + * + * Generated from protobuf field map function_hashes = 15; + * @param array|\Google\Protobuf\Internal\MapField $var + * @return $this + */ + public function setFunctionHashes($var) + { + $arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::STRING); + $this->function_hashes = $arr; + + return $this; + } + +} + diff --git a/proto/v1/php/PBFunction.php b/proto/v1/php/PBFunction.php new file mode 100644 index 0000000..d34141d --- /dev/null +++ b/proto/v1/php/PBFunction.php @@ -0,0 +1,112 @@ +Function + */ +class PBFunction extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field repeated .ValType params = 1; + */ + private $params; + /** + * Generated from protobuf field repeated .ValType results = 2; + */ + private $results; + /** + * Generated from protobuf field string name = 3; + */ + protected $name = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int[]|\Google\Protobuf\Internal\RepeatedField $params + * @type int[]|\Google\Protobuf\Internal\RepeatedField $results + * @type string $name + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Proto\V1\ModuleNoOption::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field repeated .ValType params = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getParams() + { + return $this->params; + } + + /** + * Generated from protobuf field repeated .ValType params = 1; + * @param int[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setParams($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::ENUM, \ValType::class); + $this->params = $arr; + + return $this; + } + + /** + * Generated from protobuf field repeated .ValType results = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getResults() + { + return $this->results; + } + + /** + * Generated from protobuf field repeated .ValType results = 2; + * @param int[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setResults($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::ENUM, \ValType::class); + $this->results = $arr; + + return $this; + } + + /** + * Generated from protobuf field string name = 3; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field string name = 3; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/proto/v1/php/SourceLanguage.php b/proto/v1/php/SourceLanguage.php new file mode 100644 index 0000000..c6e610d --- /dev/null +++ b/proto/v1/php/SourceLanguage.php @@ -0,0 +1,86 @@ +SourceLanguage + */ +class SourceLanguage +{ + /** + * Generated from protobuf enum Unknown = 0; + */ + const Unknown = 0; + /** + * Generated from protobuf enum Rust = 1; + */ + const Rust = 1; + /** + * Generated from protobuf enum Go = 2; + */ + const Go = 2; + /** + * Generated from protobuf enum C = 3; + */ + const C = 3; + /** + * Generated from protobuf enum Cpp = 4; + */ + const Cpp = 4; + /** + * Generated from protobuf enum AssemblyScript = 5; + */ + const AssemblyScript = 5; + /** + * Generated from protobuf enum Swift = 6; + */ + const Swift = 6; + /** + * Generated from protobuf enum JavaScript = 7; + */ + const JavaScript = 7; + /** + * Generated from protobuf enum Haskell = 8; + */ + const Haskell = 8; + /** + * Generated from protobuf enum Zig = 9; + */ + const Zig = 9; + + private static $valueToName = [ + self::Unknown => 'Unknown', + self::Rust => 'Rust', + self::Go => 'Go', + self::C => 'C', + self::Cpp => 'Cpp', + self::AssemblyScript => 'AssemblyScript', + self::Swift => 'Swift', + self::JavaScript => 'JavaScript', + self::Haskell => 'Haskell', + self::Zig => 'Zig', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + diff --git a/proto/v1/php/ValType.php b/proto/v1/php/ValType.php new file mode 100644 index 0000000..813cbd5 --- /dev/null +++ b/proto/v1/php/ValType.php @@ -0,0 +1,72 @@ +ValType + */ +class ValType +{ + /** + * Generated from protobuf enum I32 = 0; + */ + const I32 = 0; + /** + * Generated from protobuf enum I64 = 1; + */ + const I64 = 1; + /** + * Generated from protobuf enum F32 = 2; + */ + const F32 = 2; + /** + * Generated from protobuf enum F64 = 3; + */ + const F64 = 3; + /** + * Generated from protobuf enum V128 = 4; + */ + const V128 = 4; + /** + * Generated from protobuf enum FuncRef = 5; + */ + const FuncRef = 5; + /** + * Generated from protobuf enum ExternRef = 6; + */ + const ExternRef = 6; + + private static $valueToName = [ + self::I32 => 'I32', + self::I64 => 'I64', + self::F32 => 'F32', + self::F64 => 'F64', + self::V128 => 'V128', + self::FuncRef => 'FuncRef', + self::ExternRef => 'ExternRef', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} +