diff --git a/CHANGELOG.md b/CHANGELOG.md index 699ab4ad..df153c54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ In previous releases, the name "Hypermode" was used for all three._ - Fix AssemblyScript build failure when no Git repo is present [#475](https://github.com/hypermodeinc/modus/pull/475) - Disable AWS Bedrock support temporarily [#479](https://github.com/hypermodeinc/modus/pull/479) - Update SDK releases [#480](https://github.com/hypermodeinc/modus/pull/480) +- Add metadata shared library [#482](https://github.com/hypermodeinc/modus/pull/482) ## 2024-10-02 - Version 0.12.7 diff --git a/runtime/plugins/metadata/builder.go b/lib/metadata/builder.go similarity index 100% rename from runtime/plugins/metadata/builder.go rename to lib/metadata/builder.go diff --git a/lib/metadata/extras.go b/lib/metadata/extras.go new file mode 100644 index 00000000..8617f74b --- /dev/null +++ b/lib/metadata/extras.go @@ -0,0 +1,30 @@ +/* + * Copyright 2024 Hypermode Inc. + * Licensed under the terms of the Apache License, Version 2.0 + * See the LICENSE file that accompanied this code for further details. + * + * SPDX-FileCopyrightText: 2024 Hypermode Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +package metadata + +import ( + "github.com/hypermodeinc/modus/lib/wasmextractor" +) + +func GetMetadataFromWasm(wasm []byte) (*Metadata, error) { + customSections, err := getCustomSections(wasm) + if err != nil { + return nil, err + } + return GetMetadata(customSections) +} + +func getCustomSections(wasm []byte) (map[string][]byte, error) { + info, err := wasmextractor.ExtractWasmInfo(wasm) + if err != nil { + return nil, err + } + return info.CustomSections, nil +} diff --git a/lib/metadata/go.mod b/lib/metadata/go.mod new file mode 100644 index 00000000..62d49ab2 --- /dev/null +++ b/lib/metadata/go.mod @@ -0,0 +1,25 @@ +module github.com/hypermodeinc/modus/lib/metadata + +go 1.23.0 + +require github.com/hypermodeinc/modus/lib/wasmextractor v0.0.0 + +replace github.com/hypermodeinc/modus/lib/wasmextractor => ../wasmextractor + +require ( + github.com/hypermodeinc/modus/runtime v0.13.0-test.3 + github.com/tidwall/gjson v1.18.0 +) + +require ( + github.com/getsentry/sentry-go v0.29.1 // indirect + github.com/go-viper/mapstructure/v2 v2.2.1 // indirect + github.com/goccy/go-json v0.10.3 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/spf13/cast v1.7.0 // indirect + github.com/tetratelabs/wazero v1.8.1 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.1 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.18.0 // indirect +) diff --git a/lib/metadata/go.sum b/lib/metadata/go.sum new file mode 100644 index 00000000..aec9e595 --- /dev/null +++ b/lib/metadata/go.sum @@ -0,0 +1,49 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/getsentry/sentry-go v0.29.1 h1:DyZuChN8Hz3ARxGVV8ePaNXh1dQ7d76AiB117xcREwA= +github.com/getsentry/sentry-go v0.29.1/go.mod h1:x3AtIzN01d6SiWkderzaH28Tm0lgkafpJ5Bm3li39O0= +github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= +github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= +github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= +github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= +github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hypermodeinc/modus/runtime v0.13.0-test.3 h1:C+B+10Bn+axzpChzIzt9+A1Pgqa18QnGmaH2E5Wz4ng= +github.com/hypermodeinc/modus/runtime v0.13.0-test.3/go.mod h1:n5QMRjrF3yDnKDEUg2dv8NbCpy0M1Gzq701S0Rl0J/s= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= +github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w= +github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.8.1 h1:NrcgVbWfkWvVc4UtT4LRLDf91PsOzDzefMdwhLfA550= +github.com/tetratelabs/wazero v1.8.1/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs= +github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= +github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= +github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/runtime/plugins/metadata/metadata.go b/lib/metadata/metadata.go similarity index 100% rename from runtime/plugins/metadata/metadata.go rename to lib/metadata/metadata.go diff --git a/runtime/plugins/metadata/reader.go b/lib/metadata/reader.go similarity index 92% rename from runtime/plugins/metadata/reader.go rename to lib/metadata/reader.go index c42eab50..afe5c643 100644 --- a/runtime/plugins/metadata/reader.go +++ b/lib/metadata/reader.go @@ -32,7 +32,7 @@ func GetMetadata(wasmCustomSections map[string][]byte) (*Metadata, error) { } func getPluginMetadataVersion(wasmCustomSections map[string][]byte) (byte, error) { - verData, found := wasmCustomSections["hypermode_version"] + verData, found := wasmCustomSections["modus_metadata_version"] if !found || len(verData) != 1 { return 0, errors.New("failed to parse plugin metadata version") } @@ -41,7 +41,7 @@ func getPluginMetadataVersion(wasmCustomSections map[string][]byte) (byte, error } func getPluginMetadata(wasmCustomSections map[string][]byte) (*Metadata, error) { - metadataJson, found := wasmCustomSections["hypermode_meta"] + metadataJson, found := wasmCustomSections["modus_metadata"] if !found { return nil, ErrMetadataNotFound } diff --git a/lib/wasmextractor/wasmextractor.go b/lib/wasmextractor/wasmextractor.go index d40b2223..91e9a097 100644 --- a/lib/wasmextractor/wasmextractor.go +++ b/lib/wasmextractor/wasmextractor.go @@ -17,8 +17,9 @@ import ( ) type WasmInfo struct { - Imports []WasmItem - Exports []WasmItem + Imports []WasmItem + Exports []WasmItem + CustomSections map[string][]byte } type WasmItem struct { @@ -74,7 +75,9 @@ func ExtractWasmInfo(wasmBytes []byte) (*WasmInfo, error) { return nil, err } - info := &WasmInfo{} + info := &WasmInfo{ + CustomSections: make(map[string][]byte), + } offset := 8 for offset < len(wasmBytes) { sectionID := wasmBytes[offset] @@ -84,6 +87,11 @@ func ExtractWasmInfo(wasmBytes []byte) (*WasmInfo, error) { offset += n switch sectionID { + case 0: // Custom section + nameLen, n := binary.Uvarint(wasmBytes[offset:]) + name := string(wasmBytes[offset+n : offset+n+int(nameLen)]) + data := wasmBytes[offset+n+int(nameLen) : offset+int(size)] + info.CustomSections[name] = data case 2: // Import section info.Imports = readImports(wasmBytes[offset : offset+int(size)]) diff --git a/runtime/functions/fninfo.go b/runtime/functions/fninfo.go index e5a00e4f..b3a4ff34 100644 --- a/runtime/functions/fninfo.go +++ b/runtime/functions/fninfo.go @@ -10,9 +10,9 @@ package functions import ( + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" "github.com/hypermodeinc/modus/runtime/plugins" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" ) type FunctionInfo interface { diff --git a/runtime/functions/helpers.go b/runtime/functions/helpers.go index 97fe77e9..0bbb2d2d 100644 --- a/runtime/functions/helpers.go +++ b/runtime/functions/helpers.go @@ -12,7 +12,7 @@ package functions import ( "fmt" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" + "github.com/hypermodeinc/modus/lib/metadata" ) func CreateParametersMap(fn *metadata.Function, paramValues ...any) (map[string]any, error) { diff --git a/runtime/go.mod b/runtime/go.mod index f9da3f22..8e307e97 100644 --- a/runtime/go.mod +++ b/runtime/go.mod @@ -4,14 +4,21 @@ go 1.23.0 require github.com/hypermodeinc/modus/lib/manifest v0.0.0 +require github.com/hypermodeinc/modus/lib/metadata v0.0.0 + +require github.com/hypermodeinc/modus/lib/wasmextractor v0.0.0 // indirect + replace github.com/hypermodeinc/modus/lib/manifest => ../lib/manifest +replace github.com/hypermodeinc/modus/lib/metadata => ../lib/metadata + +replace github.com/hypermodeinc/modus/lib/wasmextractor => ../lib/wasmextractor + require ( github.com/OneOfOne/xxhash v1.2.8 github.com/archdx/zerolog-sentry v1.8.4 github.com/aws/aws-sdk-go-v2 v1.32.2 github.com/aws/aws-sdk-go-v2/config v1.27.43 - github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.19.2 github.com/aws/aws-sdk-go-v2/service/s3 v1.65.3 github.com/aws/aws-sdk-go-v2/service/sts v1.32.2 github.com/buger/jsonparser v1.1.1 diff --git a/runtime/go.sum b/runtime/go.sum index 8ea28598..04e23230 100644 --- a/runtime/go.sum +++ b/runtime/go.sum @@ -31,8 +31,6 @@ github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvK github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.21 h1:7edmS3VOBDhK00b/MwGtGglCm7hhwNYnjJs/PgFdMQE= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.21/go.mod h1:Q9o5h4HoIWG8XfzxqiuK/CGUbepCJ8uTlaE3bAbxytQ= -github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.19.2 h1:mG1XmnVc8qspnTIawXsmWTQMFjAVk3oc+rqj08ECf8M= -github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.19.2/go.mod h1:wS7FzQ5CEjVx5R+2/p4VJzwVVZYK3xmU3kVUfMu/tbc= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 h1:TToQNkvGguu209puTojY/ozlqy2d/SFNcoLIqTFi42g= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0/go.mod h1:0jp+ltwkf+SwG2fm/PKo8t4y8pJSgOCO4D8Lz3k0aHQ= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.2 h1:4FMHqLfk0efmTqhXVRL5xYRqlEBNBiRI7N6w4jsEdd4= diff --git a/runtime/graphql/engine/engine.go b/runtime/graphql/engine/engine.go index 04ddc252..7dd58618 100644 --- a/runtime/graphql/engine/engine.go +++ b/runtime/graphql/engine/engine.go @@ -16,11 +16,11 @@ import ( "context" "strings" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/config" "github.com/hypermodeinc/modus/runtime/graphql/datasource" "github.com/hypermodeinc/modus/runtime/graphql/schemagen" "github.com/hypermodeinc/modus/runtime/logger" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" "github.com/hypermodeinc/modus/runtime/wasmhost" diff --git a/runtime/graphql/schemagen/schemagen.go b/runtime/graphql/schemagen/schemagen.go index 87c4c1bd..0b0ef212 100644 --- a/runtime/graphql/schemagen/schemagen.go +++ b/runtime/graphql/schemagen/schemagen.go @@ -18,9 +18,9 @@ import ( "sort" "strings" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" "github.com/hypermodeinc/modus/runtime/languages" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" ) diff --git a/runtime/graphql/schemagen/schemagen_as_test.go b/runtime/graphql/schemagen/schemagen_as_test.go index a8b69921..e9a28f20 100644 --- a/runtime/graphql/schemagen/schemagen_as_test.go +++ b/runtime/graphql/schemagen/schemagen_as_test.go @@ -16,9 +16,9 @@ import ( "testing" "github.com/hypermodeinc/modus/lib/manifest" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/languages" "github.com/hypermodeinc/modus/runtime/manifestdata" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" "github.com/stretchr/testify/require" diff --git a/runtime/graphql/schemagen/schemagen_go_test.go b/runtime/graphql/schemagen/schemagen_go_test.go index 760e27aa..82281ac9 100644 --- a/runtime/graphql/schemagen/schemagen_go_test.go +++ b/runtime/graphql/schemagen/schemagen_go_test.go @@ -15,9 +15,9 @@ import ( "testing" "github.com/hypermodeinc/modus/lib/manifest" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/languages" "github.com/hypermodeinc/modus/runtime/manifestdata" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" "github.com/stretchr/testify/require" diff --git a/runtime/integration_tests/testdata/postgresql-example.wasm b/runtime/integration_tests/testdata/postgresql-example.wasm index fb90aba0..efde4ee0 100644 Binary files a/runtime/integration_tests/testdata/postgresql-example.wasm and b/runtime/integration_tests/testdata/postgresql-example.wasm differ diff --git a/runtime/langsupport/executionplan.go b/runtime/langsupport/executionplan.go index 1aedaea4..64a38f33 100644 --- a/runtime/langsupport/executionplan.go +++ b/runtime/langsupport/executionplan.go @@ -14,7 +14,7 @@ import ( "fmt" "runtime/debug" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/utils" wasm "github.com/tetratelabs/wazero/api" diff --git a/runtime/langsupport/language.go b/runtime/langsupport/language.go index c834b5d3..415dc6c0 100644 --- a/runtime/langsupport/language.go +++ b/runtime/langsupport/language.go @@ -10,7 +10,7 @@ package langsupport import ( - "github.com/hypermodeinc/modus/runtime/plugins/metadata" + "github.com/hypermodeinc/modus/lib/metadata" wasm "github.com/tetratelabs/wazero/api" ) diff --git a/runtime/langsupport/planner.go b/runtime/langsupport/planner.go index 73ffbd37..ae6aba7a 100644 --- a/runtime/langsupport/planner.go +++ b/runtime/langsupport/planner.go @@ -12,7 +12,7 @@ package langsupport import ( "context" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" + "github.com/hypermodeinc/modus/lib/metadata" wasm "github.com/tetratelabs/wazero/api" ) diff --git a/runtime/langsupport/typeinfo.go b/runtime/langsupport/typeinfo.go index 6e69a2bb..a7a7ba48 100644 --- a/runtime/langsupport/typeinfo.go +++ b/runtime/langsupport/typeinfo.go @@ -13,7 +13,7 @@ import ( "context" "reflect" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" + "github.com/hypermodeinc/modus/lib/metadata" ) type TypeInfo interface { diff --git a/runtime/languages/assemblyscript/handler_arrays.go b/runtime/languages/assemblyscript/handler_arrays.go index 1c613681..b8ea48dc 100644 --- a/runtime/languages/assemblyscript/handler_arrays.go +++ b/runtime/languages/assemblyscript/handler_arrays.go @@ -15,8 +15,8 @@ import ( "fmt" "reflect" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" ) diff --git a/runtime/languages/assemblyscript/handler_classes.go b/runtime/languages/assemblyscript/handler_classes.go index a043b4ac..4f38eb35 100644 --- a/runtime/languages/assemblyscript/handler_classes.go +++ b/runtime/languages/assemblyscript/handler_classes.go @@ -15,8 +15,8 @@ import ( "reflect" "strings" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" ) diff --git a/runtime/languages/assemblyscript/handler_dates.go b/runtime/languages/assemblyscript/handler_dates.go index 7d364e63..eb0ecc6b 100644 --- a/runtime/languages/assemblyscript/handler_dates.go +++ b/runtime/languages/assemblyscript/handler_dates.go @@ -15,8 +15,8 @@ import ( "fmt" "time" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" ) diff --git a/runtime/languages/assemblyscript/handler_maps.go b/runtime/languages/assemblyscript/handler_maps.go index 8f693fa2..7bbea5f7 100644 --- a/runtime/languages/assemblyscript/handler_maps.go +++ b/runtime/languages/assemblyscript/handler_maps.go @@ -15,9 +15,9 @@ import ( "fmt" "reflect" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" "github.com/hypermodeinc/modus/runtime/languages/assemblyscript/hash" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" ) diff --git a/runtime/languages/assemblyscript/handler_objects.go b/runtime/languages/assemblyscript/handler_objects.go index 1e7a4160..e5e7529a 100644 --- a/runtime/languages/assemblyscript/handler_objects.go +++ b/runtime/languages/assemblyscript/handler_objects.go @@ -15,9 +15,9 @@ import ( "fmt" "reflect" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" "github.com/hypermodeinc/modus/runtime/logger" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" ) diff --git a/runtime/languages/assemblyscript/handler_primitivearrays.go b/runtime/languages/assemblyscript/handler_primitivearrays.go index f8f178c0..0dcefd13 100644 --- a/runtime/languages/assemblyscript/handler_primitivearrays.go +++ b/runtime/languages/assemblyscript/handler_primitivearrays.go @@ -14,9 +14,9 @@ import ( "errors" "fmt" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" "github.com/hypermodeinc/modus/runtime/langsupport/primitives" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" ) diff --git a/runtime/languages/assemblyscript/handler_typedarrays.go b/runtime/languages/assemblyscript/handler_typedarrays.go index 61bc77d6..24aadd4b 100644 --- a/runtime/languages/assemblyscript/handler_typedarrays.go +++ b/runtime/languages/assemblyscript/handler_typedarrays.go @@ -14,9 +14,9 @@ import ( "errors" "fmt" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" "github.com/hypermodeinc/modus/runtime/langsupport/primitives" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" "golang.org/x/exp/constraints" diff --git a/runtime/languages/assemblyscript/planner.go b/runtime/languages/assemblyscript/planner.go index cb0c2d8a..fb70d2cd 100644 --- a/runtime/languages/assemblyscript/planner.go +++ b/runtime/languages/assemblyscript/planner.go @@ -13,8 +13,8 @@ import ( "context" "fmt" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" wasm "github.com/tetratelabs/wazero/api" diff --git a/runtime/languages/assemblyscript/testdata/build/testdata.wasm b/runtime/languages/assemblyscript/testdata/build/testdata.wasm index 8bded93a..f304b3bc 100644 Binary files a/runtime/languages/assemblyscript/testdata/build/testdata.wasm and b/runtime/languages/assemblyscript/testdata/build/testdata.wasm differ diff --git a/runtime/languages/assemblyscript/tests/special_test.go b/runtime/languages/assemblyscript/tests/special_test.go index 244ff68f..cf8afbd8 100644 --- a/runtime/languages/assemblyscript/tests/special_test.go +++ b/runtime/languages/assemblyscript/tests/special_test.go @@ -14,7 +14,7 @@ import ( "strings" "testing" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/utils" wasm "github.com/tetratelabs/wazero/api" diff --git a/runtime/languages/golang/handler_maps.go b/runtime/languages/golang/handler_maps.go index 0288f1b3..aeef56b3 100644 --- a/runtime/languages/golang/handler_maps.go +++ b/runtime/languages/golang/handler_maps.go @@ -15,8 +15,8 @@ import ( "fmt" "reflect" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" ) diff --git a/runtime/languages/golang/handler_pointers.go b/runtime/languages/golang/handler_pointers.go index 16384918..9647dc1f 100644 --- a/runtime/languages/golang/handler_pointers.go +++ b/runtime/languages/golang/handler_pointers.go @@ -14,8 +14,8 @@ import ( "errors" "fmt" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" ) diff --git a/runtime/languages/golang/handler_primitiveslices.go b/runtime/languages/golang/handler_primitiveslices.go index 036a3bdc..5597f352 100644 --- a/runtime/languages/golang/handler_primitiveslices.go +++ b/runtime/languages/golang/handler_primitiveslices.go @@ -15,9 +15,9 @@ import ( "fmt" "time" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" "github.com/hypermodeinc/modus/runtime/langsupport/primitives" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" ) diff --git a/runtime/languages/golang/handler_slices.go b/runtime/languages/golang/handler_slices.go index fd1bd52f..642dfd81 100644 --- a/runtime/languages/golang/handler_slices.go +++ b/runtime/languages/golang/handler_slices.go @@ -14,8 +14,8 @@ import ( "errors" "reflect" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" ) diff --git a/runtime/languages/golang/handler_structs.go b/runtime/languages/golang/handler_structs.go index 5f2f15f0..92af4851 100644 --- a/runtime/languages/golang/handler_structs.go +++ b/runtime/languages/golang/handler_structs.go @@ -15,9 +15,9 @@ import ( "reflect" "strings" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" "github.com/hypermodeinc/modus/runtime/logger" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" ) diff --git a/runtime/languages/golang/planner.go b/runtime/languages/golang/planner.go index c9cc44e8..50fdcd96 100644 --- a/runtime/languages/golang/planner.go +++ b/runtime/languages/golang/planner.go @@ -13,8 +13,8 @@ import ( "context" "fmt" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" wasm "github.com/tetratelabs/wazero/api" diff --git a/runtime/languages/golang/testdata/build/testdata.wasm b/runtime/languages/golang/testdata/build/testdata.wasm index 1846630b..089e32c5 100644 Binary files a/runtime/languages/golang/testdata/build/testdata.wasm and b/runtime/languages/golang/testdata/build/testdata.wasm differ diff --git a/runtime/languages/golang/typeinfo.go b/runtime/languages/golang/typeinfo.go index caed6a39..ffa40c48 100644 --- a/runtime/languages/golang/typeinfo.go +++ b/runtime/languages/golang/typeinfo.go @@ -19,8 +19,8 @@ import ( "time" "unsafe" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" ) diff --git a/runtime/pluginmanager/events.go b/runtime/pluginmanager/events.go index ac9b51e6..82cd63ed 100644 --- a/runtime/pluginmanager/events.go +++ b/runtime/pluginmanager/events.go @@ -13,7 +13,7 @@ import ( "context" "sync" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" + "github.com/hypermodeinc/modus/lib/metadata" ) type PluginLoadedCallback = func(ctx context.Context, md *metadata.Metadata) error diff --git a/runtime/pluginmanager/loader.go b/runtime/pluginmanager/loader.go index f20141dc..d9193e27 100644 --- a/runtime/pluginmanager/loader.go +++ b/runtime/pluginmanager/loader.go @@ -13,10 +13,10 @@ import ( "context" "fmt" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/db" "github.com/hypermodeinc/modus/runtime/logger" "github.com/hypermodeinc/modus/runtime/plugins" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/storage" "github.com/hypermodeinc/modus/runtime/utils" "github.com/hypermodeinc/modus/runtime/wasmhost" @@ -72,7 +72,7 @@ func loadPlugin(ctx context.Context, filename string) error { } // Get the metadata for the plugin. - md, err := metadata.GetMetadataFromCompiledModule(cm) + md, err := metadata.GetMetadataFromWasm(bytes) if err == metadata.ErrMetadataNotFound { logger.Error(ctx). Bool("user_visible", true). diff --git a/runtime/plugins/metadata/extras.go b/runtime/plugins/metadata/extras.go deleted file mode 100644 index b18e9db8..00000000 --- a/runtime/plugins/metadata/extras.go +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2024 Hypermode Inc. - * Licensed under the terms of the Apache License, Version 2.0 - * See the LICENSE file that accompanied this code for further details. - * - * SPDX-FileCopyrightText: 2024 Hypermode Inc. - * SPDX-License-Identifier: Apache-2.0 - */ - -package metadata - -import "github.com/tetratelabs/wazero" - -func GetMetadataFromCompiledModule(cm wazero.CompiledModule) (*Metadata, error) { - customSections := getCustomSections(cm) - return GetMetadata(customSections) -} - -func getCustomSections(cm wazero.CompiledModule) map[string][]byte { - sections := cm.CustomSections() - data := make(map[string][]byte, len(sections)) - - for _, s := range sections { - data[s.Name()] = s.Data() - } - - return data -} diff --git a/runtime/plugins/plugins.go b/runtime/plugins/plugins.go index d812dd3e..45bf1a34 100644 --- a/runtime/plugins/plugins.go +++ b/runtime/plugins/plugins.go @@ -13,9 +13,9 @@ import ( "context" "fmt" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/langsupport" "github.com/hypermodeinc/modus/runtime/languages" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" "github.com/tetratelabs/wazero" diff --git a/runtime/testutils/testutils.go b/runtime/testutils/testutils.go index ceeb5d9e..4ee94891 100644 --- a/runtime/testutils/testutils.go +++ b/runtime/testutils/testutils.go @@ -17,11 +17,11 @@ import ( "reflect" "testing" + "github.com/hypermodeinc/modus/lib/metadata" "github.com/hypermodeinc/modus/runtime/functions" "github.com/hypermodeinc/modus/runtime/langsupport" "github.com/hypermodeinc/modus/runtime/logger" "github.com/hypermodeinc/modus/runtime/plugins" - "github.com/hypermodeinc/modus/runtime/plugins/metadata" "github.com/hypermodeinc/modus/runtime/utils" "github.com/hypermodeinc/modus/runtime/wasmhost" ) @@ -88,7 +88,7 @@ func NewWasmTestFixture(wasmFilePath string, customTypes map[string]reflect.Type panic(err) } - md, err := metadata.GetMetadataFromCompiledModule(cm) + md, err := metadata.GetMetadataFromWasm(content) if err != nil { panic(err) } diff --git a/sdk/assemblyscript/src/transform/src/metadata.ts b/sdk/assemblyscript/src/transform/src/metadata.ts index dd4244d4..271b4880 100644 --- a/sdk/assemblyscript/src/transform/src/metadata.ts +++ b/sdk/assemblyscript/src/transform/src/metadata.ts @@ -77,11 +77,11 @@ export class Metadata { this.fnImports = fnImports; module.addCustomSection( - "hypermode_version", + "modus_metadata_version", Uint8Array.from([METADATA_VERSION]), ); - module.addCustomSection("hypermode_meta", encoder.encode(json)); + module.addCustomSection("modus_metadata", encoder.encode(json)); } logResults() { diff --git a/sdk/go/tools/modus-go-build/wasm/wasm.go b/sdk/go/tools/modus-go-build/wasm/wasm.go index 9c0538c9..089f028e 100644 --- a/sdk/go/tools/modus-go-build/wasm/wasm.go +++ b/sdk/go/tools/modus-go-build/wasm/wasm.go @@ -31,8 +31,8 @@ func WriteMetadata(config *config.Config, meta *metadata.Metadata) error { wasmFilePath := filepath.Join(config.OutputDir, config.WasmFileName) return writeCustomSections(wasmFilePath, map[string][]byte{ - "hypermode_version": {metadata.MetadataVersion}, - "hypermode_meta": metaJson, + "modus_metadata_version": {metadata.MetadataVersion}, + "modus_metadata": metaJson, }) }