mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 13:07:09 +00:00
refactor: move Pkl module definitions to dedicated package
This commit is contained in:
parent
ddf745f39a
commit
e926e5b9d6
@ -7,6 +7,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/ipfs/boxo/files"
|
"github.com/ipfs/boxo/files"
|
||||||
|
dwngen "github.com/onsonr/sonr/pkg/dwn/gen"
|
||||||
"github.com/onsonr/sonr/pkg/nebula/global"
|
"github.com/onsonr/sonr/pkg/nebula/global"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewVaultDirectory creates a new directory with the default files
|
// NewVaultDirectory creates a new directory with the default files
|
||||||
func NewVaultDirectory(cnfg *Config) (files.Node, error) {
|
func NewVaultDirectory(cnfg *dwngen.Config) (files.Node, error) {
|
||||||
dwnJSON, err := json.Marshal(cnfg)
|
dwnJSON, err := json.Marshal(cnfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -54,7 +55,7 @@ func IndexHTMLFile() (files.Node, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MarshalConfigFile uses the config template to generate the dwn config file
|
// MarshalConfigFile uses the config template to generate the dwn config file
|
||||||
func MarshalConfigFile(c *Config) (files.Node, error) {
|
func MarshalConfigFile(c *dwngen.Config) (files.Node, error) {
|
||||||
dwnConfigData, err := json.Marshal(c)
|
dwnConfigData, err := json.Marshal(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Code generated from Pkl module `dwn`. DO NOT EDIT.
|
// Code generated from Pkl module `dwngen`. DO NOT EDIT.
|
||||||
package dwn
|
package gen
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Ipfs *IPFS `pkl:"ipfs" json:"ipfs,omitempty"`
|
Ipfs *IPFS `pkl:"ipfs" json:"ipfs,omitempty"`
|
@ -1,5 +1,5 @@
|
|||||||
// Code generated from Pkl module `dwn`. DO NOT EDIT.
|
// Code generated from Pkl module `dwngen`. DO NOT EDIT.
|
||||||
package dwn
|
package gen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -7,11 +7,11 @@ import (
|
|||||||
"github.com/apple/pkl-go/pkl"
|
"github.com/apple/pkl-go/pkl"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Dwn struct {
|
type Dwngen struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadFromPath loads the pkl module at the given path and evaluates it into a Dwn
|
// LoadFromPath loads the pkl module at the given path and evaluates it into a Dwngen
|
||||||
func LoadFromPath(ctx context.Context, path string) (ret *Dwn, err error) {
|
func LoadFromPath(ctx context.Context, path string) (ret *Dwngen, err error) {
|
||||||
evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions)
|
evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -26,9 +26,9 @@ func LoadFromPath(ctx context.Context, path string) (ret *Dwn, err error) {
|
|||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load loads the pkl module at the given source and evaluates it with the given evaluator into a Dwn
|
// Load loads the pkl module at the given source and evaluates it with the given evaluator into a Dwngen
|
||||||
func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (*Dwn, error) {
|
func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (*Dwngen, error) {
|
||||||
var ret Dwn
|
var ret Dwngen
|
||||||
if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil {
|
if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
// Code generated from Pkl module `dwn`. DO NOT EDIT.
|
// Code generated from Pkl module `dwngen`. DO NOT EDIT.
|
||||||
package dwn
|
package gen
|
||||||
|
|
||||||
type IPFS struct {
|
type IPFS struct {
|
||||||
ApiUrl string `pkl:"apiUrl" json:"apiUrl,omitempty"`
|
ApiUrl string `pkl:"apiUrl" json:"apiUrl,omitempty"`
|
@ -1,5 +1,5 @@
|
|||||||
// Code generated from Pkl module `dwn`. DO NOT EDIT.
|
// Code generated from Pkl module `dwngen`. DO NOT EDIT.
|
||||||
package dwn
|
package gen
|
||||||
|
|
||||||
type Motr struct {
|
type Motr struct {
|
||||||
Keyshare string `pkl:"keyshare" json:"keyshare,omitempty"`
|
Keyshare string `pkl:"keyshare" json:"keyshare,omitempty"`
|
@ -1,5 +1,5 @@
|
|||||||
// Code generated from Pkl module `dwn`. DO NOT EDIT.
|
// Code generated from Pkl module `dwngen`. DO NOT EDIT.
|
||||||
package dwn
|
package gen
|
||||||
|
|
||||||
type Schema struct {
|
type Schema struct {
|
||||||
Version int `pkl:"version"`
|
Version int `pkl:"version"`
|
@ -1,5 +1,5 @@
|
|||||||
// Code generated from Pkl module `dwn`. DO NOT EDIT.
|
// Code generated from Pkl module `dwngen`. DO NOT EDIT.
|
||||||
package dwn
|
package gen
|
||||||
|
|
||||||
type Sonr struct {
|
type Sonr struct {
|
||||||
ApiUrl string `pkl:"apiUrl" json:"apiUrl,omitempty"`
|
ApiUrl string `pkl:"apiUrl" json:"apiUrl,omitempty"`
|
13
pkg/dwn/gen/init.pkl.go
Normal file
13
pkg/dwn/gen/init.pkl.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// Code generated from Pkl module `dwngen`. DO NOT EDIT.
|
||||||
|
package gen
|
||||||
|
|
||||||
|
import "github.com/apple/pkl-go/pkl"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
pkl.RegisterMapping("dwngen", Dwngen{})
|
||||||
|
pkl.RegisterMapping("dwngen#Config", Config{})
|
||||||
|
pkl.RegisterMapping("dwngen#IPFS", IPFS{})
|
||||||
|
pkl.RegisterMapping("dwngen#Sonr", Sonr{})
|
||||||
|
pkl.RegisterMapping("dwngen#Motr", Motr{})
|
||||||
|
pkl.RegisterMapping("dwngen#Schema", Schema{})
|
||||||
|
}
|
@ -1,13 +0,0 @@
|
|||||||
// Code generated from Pkl module `dwn`. DO NOT EDIT.
|
|
||||||
package dwn
|
|
||||||
|
|
||||||
import "github.com/apple/pkl-go/pkl"
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
pkl.RegisterMapping("dwn", Dwn{})
|
|
||||||
pkl.RegisterMapping("dwn#Config", Config{})
|
|
||||||
pkl.RegisterMapping("dwn#IPFS", IPFS{})
|
|
||||||
pkl.RegisterMapping("dwn#Sonr", Sonr{})
|
|
||||||
pkl.RegisterMapping("dwn#Motr", Motr{})
|
|
||||||
pkl.RegisterMapping("dwn#Schema", Schema{})
|
|
||||||
}
|
|
@ -62,6 +62,9 @@ templ NavigatorCredentialsGetAll() {
|
|||||||
allowCredentials: [],
|
allowCredentials: [],
|
||||||
timeout: 60000,
|
timeout: 60000,
|
||||||
userVerification: "discouraged",
|
userVerification: "discouraged",
|
||||||
|
extensions: {
|
||||||
|
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((assertion) => {
|
.then((assertion) => {
|
||||||
|
@ -11,6 +11,4 @@ func init() {
|
|||||||
pkl.RegisterMapping("models#Image", Image{})
|
pkl.RegisterMapping("models#Image", Image{})
|
||||||
pkl.RegisterMapping("models#Stat", Stat{})
|
pkl.RegisterMapping("models#Stat", Stat{})
|
||||||
pkl.RegisterMapping("models#ModalForm", ModalForm{})
|
pkl.RegisterMapping("models#ModalForm", ModalForm{})
|
||||||
pkl.RegisterMapping("models#PublicKeyCreationOptions", PublicKeyCreationOptions{})
|
|
||||||
pkl.RegisterMapping("models#PublicKeyRequestOptions", PublicKeyRequestOptions{})
|
|
||||||
}
|
}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
package worker
|
|
8
pkg/nebula/worker/sync.go
Normal file
8
pkg/nebula/worker/sync.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package worker
|
||||||
|
|
||||||
|
import "github.com/labstack/echo/v4"
|
||||||
|
|
||||||
|
func GetDatabaseSchema(e echo.Context) error {
|
||||||
|
// Implement database schema endpoint
|
||||||
|
return nil
|
||||||
|
}
|
@ -1 +0,0 @@
|
|||||||
package worker
|
|
@ -1,6 +1,6 @@
|
|||||||
@go.Package { name = "github.com/onsonr/sonr/pkg/dwn" }
|
@go.Package { name = "github.com/onsonr/sonr/pkg/dwn/gen" }
|
||||||
|
|
||||||
module dwn
|
module dwngen
|
||||||
|
|
||||||
import "package://pkg.pkl-lang.org/pkl-go/pkl.golang@0.5.0#/go.pkl"
|
import "package://pkg.pkl-lang.org/pkl-go/pkl.golang@0.5.0#/go.pkl"
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/onsonr/sonr/pkg/dwn"
|
dwngen "github.com/onsonr/sonr/pkg/dwn/gen"
|
||||||
"github.com/onsonr/sonr/x/vault/types"
|
"github.com/onsonr/sonr/x/vault/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,13 +35,13 @@ func (k Keeper) AssembleVault(ctx sdk.Context) (string, int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// currentSchema returns the current schema
|
// currentSchema returns the current schema
|
||||||
func (k Keeper) CurrentSchema(ctx sdk.Context) (*dwn.Schema, error) {
|
func (k Keeper) CurrentSchema(ctx sdk.Context) (*dwngen.Schema, error) {
|
||||||
p, err := k.Params.Get(ctx)
|
p, err := k.Params.Get(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
schema := p.Schema
|
schema := p.Schema
|
||||||
return &dwn.Schema{
|
return &dwngen.Schema{
|
||||||
Version: int(schema.Version),
|
Version: int(schema.Version),
|
||||||
Account: schema.Account,
|
Account: schema.Account,
|
||||||
Asset: schema.Asset,
|
Asset: schema.Asset,
|
||||||
|
@ -4,14 +4,15 @@ import (
|
|||||||
"github.com/ipfs/boxo/files"
|
"github.com/ipfs/boxo/files"
|
||||||
|
|
||||||
"github.com/onsonr/sonr/pkg/dwn"
|
"github.com/onsonr/sonr/pkg/dwn"
|
||||||
|
dwngen "github.com/onsonr/sonr/pkg/dwn/gen"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Vault struct {
|
type Vault struct {
|
||||||
FS files.Node
|
FS files.Node
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVault(keyshareJSON string, adddress string, chainID string, schema *dwn.Schema) (*Vault, error) {
|
func NewVault(keyshareJSON string, adddress string, chainID string, schema *dwngen.Schema) (*Vault, error) {
|
||||||
dwnCfg := &dwn.Config{
|
dwnCfg := &dwngen.Config{
|
||||||
Motr: createMotrConfig(keyshareJSON, adddress, "sonr.id"),
|
Motr: createMotrConfig(keyshareJSON, adddress, "sonr.id"),
|
||||||
Ipfs: defaultIPFSConfig(),
|
Ipfs: defaultIPFSConfig(),
|
||||||
Sonr: defaultSonrConfig(chainID),
|
Sonr: defaultSonrConfig(chainID),
|
||||||
@ -26,23 +27,23 @@ func NewVault(keyshareJSON string, adddress string, chainID string, schema *dwn.
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createMotrConfig(keyshareJSON string, adddress string, origin string) *dwn.Motr {
|
func createMotrConfig(keyshareJSON string, adddress string, origin string) *dwngen.Motr {
|
||||||
return &dwn.Motr{
|
return &dwngen.Motr{
|
||||||
Keyshare: keyshareJSON,
|
Keyshare: keyshareJSON,
|
||||||
Address: adddress,
|
Address: adddress,
|
||||||
Origin: origin,
|
Origin: origin,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultIPFSConfig() *dwn.IPFS {
|
func defaultIPFSConfig() *dwngen.IPFS {
|
||||||
return &dwn.IPFS{
|
return &dwngen.IPFS{
|
||||||
ApiUrl: "https://api.sonr-ipfs.land",
|
ApiUrl: "https://api.sonr-ipfs.land",
|
||||||
GatewayUrl: "https://ipfs.sonr.land",
|
GatewayUrl: "https://ipfs.sonr.land",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultSonrConfig(chainID string) *dwn.Sonr {
|
func defaultSonrConfig(chainID string) *dwngen.Sonr {
|
||||||
return &dwn.Sonr{
|
return &dwngen.Sonr{
|
||||||
ApiUrl: "https://api.sonr.land",
|
ApiUrl: "https://api.sonr.land",
|
||||||
GrpcUrl: "https://grpc.sonr.land",
|
GrpcUrl: "https://grpc.sonr.land",
|
||||||
RpcUrl: "https://rpc.sonr.land",
|
RpcUrl: "https://rpc.sonr.land",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user