diff --git a/marine-examples/sqlite/.fluence/aqua/services.aqua b/marine-examples/sqlite/.fluence/aqua/services.aqua new file mode 100644 index 0000000..743cb2c --- /dev/null +++ b/marine-examples/sqlite/.fluence/aqua/services.aqua @@ -0,0 +1,6 @@ +service SqliteTest("sqlite_test"): + sql_repl() + test1(age: i64) + test2(age: i64) + test3() + test_last_rowid() -> i64 diff --git a/marine-examples/sqlite/.fluence/aqua/workers.aqua b/marine-examples/sqlite/.fluence/aqua/workers.aqua new file mode 100644 index 0000000..e69de29 diff --git a/marine-examples/sqlite/.fluence/modules/sqlite3.tar.gz_d35d7a28b1a8a55e87df96578d70ad46/module.yaml b/marine-examples/sqlite/.fluence/modules/sqlite3.tar.gz_d35d7a28b1a8a55e87df96578d70ad46/module.yaml new file mode 100644 index 0000000..5bbda46 --- /dev/null +++ b/marine-examples/sqlite/.fluence/modules/sqlite3.tar.gz_d35d7a28b1a8a55e87df96578d70ad46/module.yaml @@ -0,0 +1,6 @@ +# yaml-language-server: $schema=../../schemas/module.yaml.json +version: 0 +type: compiled +name: sqlite3 +volumes: + sites: ./tmp diff --git a/marine-examples/sqlite/.fluence/modules/sqlite3.tar.gz_d35d7a28b1a8a55e87df96578d70ad46/sqlite3.wasm b/marine-examples/sqlite/.fluence/modules/sqlite3.tar.gz_d35d7a28b1a8a55e87df96578d70ad46/sqlite3.wasm new file mode 100644 index 0000000..32a7440 Binary files /dev/null and b/marine-examples/sqlite/.fluence/modules/sqlite3.tar.gz_d35d7a28b1a8a55e87df96578d70ad46/sqlite3.wasm differ diff --git a/marine-examples/sqlite/.fluence/project-secrets.yaml b/marine-examples/sqlite/.fluence/project-secrets.yaml new file mode 100644 index 0000000..8e4293f --- /dev/null +++ b/marine-examples/sqlite/.fluence/project-secrets.yaml @@ -0,0 +1,8 @@ +# yaml-language-server: $schema=schemas/project-secrets.yaml.json + +# Defines project's secret keys that are used only in the scope of this particular Fluence project. You can manage project's keys using commands from `fluence key` group of commands + +# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/project-secrets.md + +version: 0 +keyPairs: [] diff --git a/marine-examples/sqlite/.fluence/schemas/fluence.yaml.json b/marine-examples/sqlite/.fluence/schemas/fluence.yaml.json new file mode 100644 index 0000000..b7d5437 --- /dev/null +++ b/marine-examples/sqlite/.fluence/schemas/fluence.yaml.json @@ -0,0 +1,464 @@ +{ + "type": "object", + "properties": { + "services": { + "title": "Services", + "description": "A map with service names as keys and Service configs as values. You can have any number of services listed here (According to JSON schema they are called 'additionalProperties') as long as service name keys start with a lowercase letter and contain only letters numbers and underscores. You can use `fluence service add` command to add a service to this config", + "type": "object", + "additionalProperties": { + "title": "Service config", + "description": "Service names as keys (must start with a lowercase letter and contain only letters numbers and underscores) and Service config (defines where the service is and how to deploy it) as values", + "type": "object", + "properties": { + "get": { + "type": "string", + "description": "Path to service directory or URL to the tar.gz archive with the service" + }, + "overrideModules": { + "type": "object", + "title": "Overrides", + "description": "A map of modules to override", + "additionalProperties": { + "type": "object", + "title": "Module overrides", + "description": "Module names as keys and overrides for the module config as values", + "properties": { + "get": { + "type": "string", + "nullable": true, + "description": "Path to module directory or URL to the tar.gz archive with the module" + }, + "maxHeapSize": { + "type": "string", + "nullable": true, + "description": "Max size of the heap that a module can allocate in format: [number][whitespace?][specificator?] where ? is an optional field and specificator is one from the following (case-insensitive):\n\nK, Kb - kilobyte\n\nKi, KiB - kibibyte\n\nM, Mb - megabyte\n\nMi, MiB - mebibyte\n\nG, Gb - gigabyte\n\nGi, GiB - gibibyte\n\nCurrent limit is 4 GiB" + }, + "loggerEnabled": { + "type": "boolean", + "nullable": true, + "description": "Set true to allow module to use the Marine SDK logger" + }, + "loggingMask": { + "type": "number", + "nullable": true, + "description": "Used for logging management. Example:\n```rust\nconst TARGET_MAP: [(&str, i64); 4] = [\n(\"instruction\", 1 << 1),\n(\"data_cache\", 1 << 2),\n(\"next_peer_pks\", 1 << 3),\n(\"subtree_complete\", 1 << 4),\n];\npub fn main() {\nuse std::collections::HashMap;\nuse std::iter::FromIterator;\n\nlet target_map = HashMap::from_iter(TARGET_MAP.iter().cloned());\n\nmarine_rs_sdk::WasmLoggerBuilder::new()\n .with_target_map(target_map)\n .build()\n .unwrap();\n}\n#[marine]\npub fn foo() {\nlog::info!(target: \"instruction\", \"this will print if (loggingMask & 1) != 0\");\nlog::info!(target: \"data_cache\", \"this will print if (loggingMask & 2) != 0\");\n}\n```\n" + }, + "volumes": { + "type": "object", + "nullable": true, + "required": [], + "title": "Volumes", + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file" + }, + "envs": { + "type": "object", + "title": "Environment variables", + "nullable": true, + "required": [], + "description": "environment variables accessible by a particular module with standard Rust env API like this: std::env::var(IPFS_ADDR_ENV_NAME).\n\nPlease note that Marine adds three additional environment variables. Module environment variables could be examined with repl" + }, + "mountedBinaries": { + "title": "Mounted binaries", + "type": "object", + "nullable": true, + "required": [], + "description": "A map of binary executable files that module is allowed to call. Example: curl: /usr/bin/curl" + } + }, + "required": [], + "nullable": true + }, + "nullable": true, + "required": [] + }, + "deploy": { + "type": "array", + "title": "Deployment list", + "nullable": true, + "description": "List of deployments for the particular service", + "items": { + "type": "object", + "title": "Deployment", + "description": "A small config for a particular deployment. You can have specific overrides for each and specific deployment properties like count, etc.", + "properties": { + "keyPairName": { + "type": "string", + "nullable": true, + "description": "The name of the Key Pair to use. It is resolved in the following order (from the lowest to the highest priority):\n1. \"defaultKeyPairName\" property from user-secrets.yaml\n1. \"defaultKeyPairName\" property from project-secrets.yaml\n1. \"keyPairName\" property from the top level of fluence.yaml\n1. \"keyPairName\" property from the \"services\" level of fluence.yaml\n1. \"keyPairName\" property from the individual \"deploy\" property item level of fluence.yaml" + }, + "deployId": { + "type": "string", + "description": "This id can be used in Aqua to access actually deployed peer and service ids. The ID must start with a lowercase letter and contain only letters, numbers, and underscores." + }, + "count": { + "type": "number", + "minimum": 1, + "nullable": true, + "description": "Number of services to deploy. Default: 1 or if \"peerIds\" property is provided - exactly the number of peerIds" + }, + "peerId": { + "type": "string", + "nullable": true, + "description": "Peer id or peer id name to deploy to. Default: Peer ids from the \"relay\" property of fluence.yaml are selected for each deploy. Named peerIds can be listed in \"peerIds\" property of fluence.yaml)" + }, + "peerIds": { + "type": "array", + "items": { + "type": "string" + }, + "nullable": true, + "title": "Peer ids", + "description": "Peer ids or peer id names to deploy to. Overrides \"peerId\" property. Named peerIds can be listed in \"peerIds\" property of fluence.yaml)" + }, + "overrideModules": { + "type": "object", + "title": "Overrides", + "description": "A map of modules to override", + "additionalProperties": { + "type": "object", + "title": "Module overrides", + "description": "Module names as keys and overrides for the module config as values", + "properties": { + "get": { + "type": "string", + "nullable": true, + "description": "Path to module directory or URL to the tar.gz archive with the module" + }, + "maxHeapSize": { + "type": "string", + "nullable": true, + "description": "Max size of the heap that a module can allocate in format: [number][whitespace?][specificator?] where ? is an optional field and specificator is one from the following (case-insensitive):\n\nK, Kb - kilobyte\n\nKi, KiB - kibibyte\n\nM, Mb - megabyte\n\nMi, MiB - mebibyte\n\nG, Gb - gigabyte\n\nGi, GiB - gibibyte\n\nCurrent limit is 4 GiB" + }, + "loggerEnabled": { + "type": "boolean", + "nullable": true, + "description": "Set true to allow module to use the Marine SDK logger" + }, + "loggingMask": { + "type": "number", + "nullable": true, + "description": "Used for logging management. Example:\n```rust\nconst TARGET_MAP: [(&str, i64); 4] = [\n(\"instruction\", 1 << 1),\n(\"data_cache\", 1 << 2),\n(\"next_peer_pks\", 1 << 3),\n(\"subtree_complete\", 1 << 4),\n];\npub fn main() {\nuse std::collections::HashMap;\nuse std::iter::FromIterator;\n\nlet target_map = HashMap::from_iter(TARGET_MAP.iter().cloned());\n\nmarine_rs_sdk::WasmLoggerBuilder::new()\n .with_target_map(target_map)\n .build()\n .unwrap();\n}\n#[marine]\npub fn foo() {\nlog::info!(target: \"instruction\", \"this will print if (loggingMask & 1) != 0\");\nlog::info!(target: \"data_cache\", \"this will print if (loggingMask & 2) != 0\");\n}\n```\n" + }, + "volumes": { + "type": "object", + "nullable": true, + "required": [], + "title": "Volumes", + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file" + }, + "envs": { + "type": "object", + "title": "Environment variables", + "nullable": true, + "required": [], + "description": "environment variables accessible by a particular module with standard Rust env API like this: std::env::var(IPFS_ADDR_ENV_NAME).\n\nPlease note that Marine adds three additional environment variables. Module environment variables could be examined with repl" + }, + "mountedBinaries": { + "title": "Mounted binaries", + "type": "object", + "nullable": true, + "required": [], + "description": "A map of binary executable files that module is allowed to call. Example: curl: /usr/bin/curl" + } + }, + "required": [], + "nullable": true + }, + "nullable": true, + "required": [] + } + }, + "required": [ + "deployId" + ] + } + }, + "keyPairName": { + "type": "string", + "nullable": true, + "description": "The name of the Key Pair to use. It is resolved in the following order (from the lowest to the highest priority):\n1. \"defaultKeyPairName\" property from user-secrets.yaml\n1. \"defaultKeyPairName\" property from project-secrets.yaml\n1. \"keyPairName\" property from the top level of fluence.yaml\n1. \"keyPairName\" property from the \"services\" level of fluence.yaml\n1. \"keyPairName\" property from the individual \"deploy\" property item level of fluence.yaml" + } + }, + "required": [ + "get" + ] + }, + "required": [], + "nullable": true + }, + "relays": { + "title": "Relays", + "description": "List of Fluence Peer multi addresses or a name of the network. This multi addresses are used for connecting to the Fluence network when deploying. Peer ids from these addresses are also used for deploying in case if you don't specify \"peerId\" or \"peerIds\" property in the deployment config. Default: kras", + "type": [ + "string", + "array", + "null" + ], + "oneOf": [ + { + "type": "string", + "title": "Network name", + "enum": [ + "kras", + "stage", + "testnet" + ] + }, + { + "type": "array", + "title": "Multi addresses", + "items": { + "type": "string" + }, + "minItems": 1 + } + ], + "nullable": true + }, + "peerIds": { + "title": "Peer ids", + "description": "A map of named peerIds. Example:\n\nMY_PEER: 12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS", + "type": "object", + "nullable": true, + "required": [], + "additionalProperties": { + "type": "string", + "description": "Peer id names as keys and the actual peer ids as values" + } + }, + "keyPairName": { + "type": "string", + "nullable": true, + "description": "The name of the Key Pair to use. It is resolved in the following order (from the lowest to the highest priority):\n1. \"defaultKeyPairName\" property from user-secrets.yaml\n1. \"defaultKeyPairName\" property from project-secrets.yaml\n1. \"keyPairName\" property from the top level of fluence.yaml\n1. \"keyPairName\" property from the \"services\" level of fluence.yaml\n1. \"keyPairName\" property from the individual \"deploy\" property item level of fluence.yaml" + }, + "version": { + "type": "number", + "const": 2 + }, + "dependencies": { + "type": "object", + "title": "Dependencies", + "nullable": true, + "description": "(For advanced users) Overrides for the project dependencies", + "properties": { + "npm": { + "type": "object", + "title": "npm dependencies", + "nullable": true, + "description": "A map of npm dependency versions. CLI ensures dependencies are installed each time you run aqua", + "required": [] + }, + "cargo": { + "type": "object", + "title": "Cargo dependencies", + "nullable": true, + "description": "A map of cargo dependency versions. CLI ensures dependencies are installed each time you run commands that depend on Marine or Marine REPL", + "required": [] + } + }, + "required": [] + }, + "aquaInputPath": { + "type": "string", + "nullable": true, + "description": "Path to the aqua file or directory with aqua files that you want to compile by default. Must be relative to the project root dir" + }, + "aquaOutputTSPath": { + "type": "string", + "nullable": true, + "description": "Path to the default compilation target dir from aqua to ts. Must be relative to the project root dir" + }, + "aquaOutputJSPath": { + "type": "string", + "nullable": true, + "description": "Path to the default compilation target dir from aqua to js. Must be relative to the project root dir. Overrides 'aquaOutputTSPath' property" + }, + "appTSPath": { + "type": "string", + "nullable": true, + "description": "Path to the directory where you want to generate app.ts after deployment. If you run registerApp() function in your typescript code after initializing FluenceJS client you will be able to access ids of the deployed services in aqua" + }, + "appJSPath": { + "type": "string", + "nullable": true, + "description": "Path to the directory where you want to generate app.js after deployment. If you run registerApp() function in your javascript code after initializing FluenceJS client you will be able to access ids of the deployed services in aqua" + }, + "hosts": { + "description": "A map of objects with worker names as keys, each object defines a list of peer IDs to host the worker on", + "type": "object", + "nullable": true, + "additionalProperties": { + "type": "object", + "properties": { + "peerIds": { + "type": "array", + "description": "An array of peer IDs to deploy on", + "items": { + "type": "string" + } + } + }, + "required": [ + "peerIds" + ] + }, + "required": [] + }, + "workers": { + "nullable": true, + "description": "A Map with worker names as keys and worker configs as values", + "type": "object", + "additionalProperties": { + "type": "object", + "description": "Worker config", + "properties": { + "services": { + "description": "An array of service names to include in this worker. Service names must be listed in fluence.yaml", + "type": "array", + "items": { + "type": "string" + }, + "nullable": true + }, + "spells": { + "description": "An array of spell names to include in this worker. Spell names must be listed in fluence.yaml", + "type": "array", + "items": { + "type": "string" + }, + "nullable": true + } + }, + "required": [] + }, + "required": [] + }, + "deals": { + "description": "A map of objects with worker names as keys, each object defines a deal", + "type": "object", + "nullable": true, + "additionalProperties": { + "type": "object", + "properties": { + "minWorkers": { + "type": "number", + "description": "Required workers to activate the deal", + "default": 1, + "nullable": true, + "minimum": 1 + }, + "targetWorkers": { + "type": "number", + "description": "Max workers in the deal", + "default": 3, + "nullable": true, + "minimum": 1 + } + }, + "required": [] + }, + "required": [] + }, + "chainNetwork": { + "type": "string", + "description": "The network in which the transactions will be carried out", + "enum": [ + "local", + "testnet" + ], + "default": "testnet", + "nullable": true + }, + "spells": { + "type": "object", + "nullable": true, + "description": "A map with spell names as keys and spell configs as values", + "additionalProperties": { + "type": "object", + "description": "Spell config", + "properties": { + "get": { + "type": "string", + "description": "Path to spell" + }, + "version": { + "type": "number", + "const": 0 + }, + "aquaFilePath": { + "type": "string", + "description": "Path to Aqua file which contains an Aqua function that you want to use as a spell", + "nullable": true + }, + "function": { + "type": "string", + "description": "Name of the Aqua function that you want to use as a spell", + "nullable": true + }, + "initArgs": { + "type": "object", + "description": "A map of Aqua function arguments names as keys and arguments values as values. They will be passed to the spell function and will be stored in the key-value storage for this particular spell.", + "nullable": true + }, + "clock": { + "type": "object", + "nullable": true, + "description": "Trigger the spell execution periodically. If you want to disable this property by overriding it in fluence.yaml - pass empty config for it like this: `clock: {}`", + "properties": { + "periodSec": { + "type": "number", + "description": "How often the spell will be executed. If set to 0, the spell will be executed only once. If this value not provided at all - the spell will never be executed", + "minimum": 0, + "maximum": 3153600000, + "nullable": true + }, + "startTimestamp": { + "type": "string", + "description": "An ISO timestamp when the periodic execution should start. If this property or `startDelaySec` not specified, periodic execution will start immediately. If it is set to 0 - the spell will never be executed", + "nullable": true + }, + "endTimestamp": { + "type": "string", + "description": "An ISO timestamp when the periodic execution should end. If this property or `endDelaySec` not specified, periodic execution will never end. If it is in the past at the moment of spell creation on Rust peer - the spell will never be executed", + "nullable": true + }, + "startDelaySec": { + "type": "number", + "description": "How long to wait before the first execution in seconds. If this property or `startTimestamp` not specified, periodic execution will start immediately. WARNING! Currently your computer's clock is used to determine a final timestamp that is sent to the server. This property conflicts with `startTimestamp`. You can specify only one of them", + "nullable": true, + "minimum": 0, + "maximum": 4294967295 + }, + "endDelaySec": { + "type": "number", + "description": "How long to wait before the last execution in seconds. If this property or `endTimestamp` not specified, periodic execution will never end. WARNING! Currently your computer's clock is used to determine a final timestamp that is sent to the server. If it is in the past at the moment of spell creation - the spell will never be executed. This property conflicts with `endTimestamp`. You can specify only one of them", + "nullable": true, + "minimum": 0, + "maximum": 4294967295 + } + }, + "required": [] + } + }, + "required": [ + "get" + ] + }, + "required": [] + }, + "aquaImports": { + "type": "array", + "description": "A list of path to be considered by aqua compiler to be used as imports. First dependency in the list has the highest priority. Priority of imports is considered in the following order: imports from --import flags, imports from aquaImports property in fluence.yaml, project's .fluence/aqua dir, npm dependencies from fluence.yaml, npm dependencies from user's .fluence/config.yaml, npm dependencies recommended by fluence", + "items": { + "type": "string" + }, + "nullable": true + } + }, + "required": [ + "version" + ], + "$id": "https://fluence.dev/schemas/fluence.yaml", + "title": "fluence.yaml", + "description": "Defines Fluence Project, most importantly - what exactly you want to deploy and how. You can use `fluence init` command to generate a template for new Fluence project" +} diff --git a/marine-examples/sqlite/.fluence/schemas/module.yaml.json b/marine-examples/sqlite/.fluence/schemas/module.yaml.json new file mode 100644 index 0000000..1ac8895 --- /dev/null +++ b/marine-examples/sqlite/.fluence/schemas/module.yaml.json @@ -0,0 +1,66 @@ +{ + "type": "object", + "$id": "https://fluence.dev/schemas/module.yaml", + "title": "module.yaml", + "description": "Defines [Marine Module](https://fluence.dev/docs/build/concepts/#modules). You can use `fluence module new` command to generate a template for new module", + "properties": { + "name": { + "type": "string", + "description": "\"name\" property from the Cargo.toml (for module type \"rust\") or name of the precompiled .wasm file (for module type \"compiled\")" + }, + "type": { + "type": "string", + "enum": [ + "rust", + "compiled" + ], + "nullable": true, + "default": "compiled", + "description": "Module type \"compiled\" is for the precompiled modules. Module type \"rust\" is for the source code written in rust which can be compiled into a Marine module" + }, + "maxHeapSize": { + "type": "string", + "nullable": true, + "description": "Max size of the heap that a module can allocate in format: [number][whitespace?][specificator?] where ? is an optional field and specificator is one from the following (case-insensitive):\n\nK, Kb - kilobyte\n\nKi, KiB - kibibyte\n\nM, Mb - megabyte\n\nMi, MiB - mebibyte\n\nG, Gb - gigabyte\n\nGi, GiB - gibibyte\n\nCurrent limit is 4 GiB" + }, + "loggerEnabled": { + "type": "boolean", + "nullable": true, + "description": "Set true to allow module to use the Marine SDK logger" + }, + "loggingMask": { + "type": "number", + "nullable": true, + "description": "Used for logging management. Example:\n```rust\nconst TARGET_MAP: [(&str, i64); 4] = [\n(\"instruction\", 1 << 1),\n(\"data_cache\", 1 << 2),\n(\"next_peer_pks\", 1 << 3),\n(\"subtree_complete\", 1 << 4),\n];\npub fn main() {\nuse std::collections::HashMap;\nuse std::iter::FromIterator;\n\nlet target_map = HashMap::from_iter(TARGET_MAP.iter().cloned());\n\nmarine_rs_sdk::WasmLoggerBuilder::new()\n .with_target_map(target_map)\n .build()\n .unwrap();\n}\n#[marine]\npub fn foo() {\nlog::info!(target: \"instruction\", \"this will print if (loggingMask & 1) != 0\");\nlog::info!(target: \"data_cache\", \"this will print if (loggingMask & 2) != 0\");\n}\n```\n" + }, + "volumes": { + "type": "object", + "nullable": true, + "required": [], + "title": "Volumes", + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file" + }, + "envs": { + "type": "object", + "title": "Environment variables", + "nullable": true, + "required": [], + "description": "environment variables accessible by a particular module with standard Rust env API like this: std::env::var(IPFS_ADDR_ENV_NAME).\n\nPlease note that Marine adds three additional environment variables. Module environment variables could be examined with repl" + }, + "mountedBinaries": { + "title": "Mounted binaries", + "type": "object", + "nullable": true, + "required": [], + "description": "A map of binary executable files that module is allowed to call. Example: curl: /usr/bin/curl" + }, + "version": { + "type": "number", + "const": 0 + } + }, + "required": [ + "version", + "name" + ] +} diff --git a/marine-examples/sqlite/.fluence/schemas/project-secrets.yaml.json b/marine-examples/sqlite/.fluence/schemas/project-secrets.yaml.json new file mode 100644 index 0000000..6e92594 --- /dev/null +++ b/marine-examples/sqlite/.fluence/schemas/project-secrets.yaml.json @@ -0,0 +1,42 @@ +{ + "$id": "https://fluence.dev/schemas/project-secrets.yaml", + "title": "project-secrets.yaml", + "type": "object", + "description": "Defines project's secret keys that are used only in the scope of this particular Fluence project. You can manage project's keys using commands from `fluence key` group of commands", + "properties": { + "keyPairs": { + "title": "Key Pairs", + "description": "Key Pairs available for the particular project", + "type": "array", + "items": { + "title": "Key Pair", + "type": "object", + "properties": { + "secretKey": { + "type": "string" + }, + "name": { + "type": "string" + } + }, + "required": [ + "secretKey", + "name" + ] + } + }, + "defaultKeyPairName": { + "type": "string", + "nullable": true, + "description": "Key pair with this name will be used for the deployment by default. You can override it with flags or by using keyPair properties in fluence.yaml" + }, + "version": { + "type": "number", + "const": 0 + } + }, + "required": [ + "version", + "keyPairs" + ] +} diff --git a/marine-examples/sqlite/.fluence/schemas/service.yaml.json b/marine-examples/sqlite/.fluence/schemas/service.yaml.json new file mode 100644 index 0000000..7f24ba2 --- /dev/null +++ b/marine-examples/sqlite/.fluence/schemas/service.yaml.json @@ -0,0 +1,129 @@ +{ + "type": "object", + "$id": "https://fluence.dev/schemas/service.yaml", + "title": "service.yaml", + "description": "Defines a [Marine service](https://fluence.dev/docs/build/concepts/#services), most importantly the modules that the service consists of. You can use `fluence service new` command to generate a template for new service", + "properties": { + "name": { + "type": "string", + "description": "Service name. Currently it is used for the service name only when you add service to fluence.yaml using \"add\" command. But this name can be overridden to any other with the --name flag or manually in fluence.yaml" + }, + "modules": { + "title": "Modules", + "description": "Service must have a facade module. Each module properties can be overridden by the same properties in the service config", + "type": "object", + "additionalProperties": { + "type": "object", + "title": "Module", + "properties": { + "get": { + "type": "string", + "description": "Either path to the module directory or URL to the tar.gz archive which contains the content of the module directory" + }, + "maxHeapSize": { + "type": "string", + "nullable": true, + "description": "Max size of the heap that a module can allocate in format: [number][whitespace?][specificator?] where ? is an optional field and specificator is one from the following (case-insensitive):\n\nK, Kb - kilobyte\n\nKi, KiB - kibibyte\n\nM, Mb - megabyte\n\nMi, MiB - mebibyte\n\nG, Gb - gigabyte\n\nGi, GiB - gibibyte\n\nCurrent limit is 4 GiB" + }, + "loggerEnabled": { + "type": "boolean", + "nullable": true, + "description": "Set true to allow module to use the Marine SDK logger" + }, + "loggingMask": { + "type": "number", + "nullable": true, + "description": "Used for logging management. Example:\n```rust\nconst TARGET_MAP: [(&str, i64); 4] = [\n(\"instruction\", 1 << 1),\n(\"data_cache\", 1 << 2),\n(\"next_peer_pks\", 1 << 3),\n(\"subtree_complete\", 1 << 4),\n];\npub fn main() {\nuse std::collections::HashMap;\nuse std::iter::FromIterator;\n\nlet target_map = HashMap::from_iter(TARGET_MAP.iter().cloned());\n\nmarine_rs_sdk::WasmLoggerBuilder::new()\n .with_target_map(target_map)\n .build()\n .unwrap();\n}\n#[marine]\npub fn foo() {\nlog::info!(target: \"instruction\", \"this will print if (loggingMask & 1) != 0\");\nlog::info!(target: \"data_cache\", \"this will print if (loggingMask & 2) != 0\");\n}\n```\n" + }, + "volumes": { + "type": "object", + "nullable": true, + "required": [], + "title": "Volumes", + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file" + }, + "envs": { + "type": "object", + "title": "Environment variables", + "nullable": true, + "required": [], + "description": "environment variables accessible by a particular module with standard Rust env API like this: std::env::var(IPFS_ADDR_ENV_NAME).\n\nPlease note that Marine adds three additional environment variables. Module environment variables could be examined with repl" + }, + "mountedBinaries": { + "title": "Mounted binaries", + "type": "object", + "nullable": true, + "required": [], + "description": "A map of binary executable files that module is allowed to call. Example: curl: /usr/bin/curl" + } + }, + "required": [ + "get" + ] + }, + "properties": { + "facade": { + "type": "object", + "title": "Module", + "properties": { + "get": { + "type": "string", + "description": "Either path to the module directory or URL to the tar.gz archive which contains the content of the module directory" + }, + "maxHeapSize": { + "type": "string", + "nullable": true, + "description": "Max size of the heap that a module can allocate in format: [number][whitespace?][specificator?] where ? is an optional field and specificator is one from the following (case-insensitive):\n\nK, Kb - kilobyte\n\nKi, KiB - kibibyte\n\nM, Mb - megabyte\n\nMi, MiB - mebibyte\n\nG, Gb - gigabyte\n\nGi, GiB - gibibyte\n\nCurrent limit is 4 GiB" + }, + "loggerEnabled": { + "type": "boolean", + "nullable": true, + "description": "Set true to allow module to use the Marine SDK logger" + }, + "loggingMask": { + "type": "number", + "nullable": true, + "description": "Used for logging management. Example:\n```rust\nconst TARGET_MAP: [(&str, i64); 4] = [\n(\"instruction\", 1 << 1),\n(\"data_cache\", 1 << 2),\n(\"next_peer_pks\", 1 << 3),\n(\"subtree_complete\", 1 << 4),\n];\npub fn main() {\nuse std::collections::HashMap;\nuse std::iter::FromIterator;\n\nlet target_map = HashMap::from_iter(TARGET_MAP.iter().cloned());\n\nmarine_rs_sdk::WasmLoggerBuilder::new()\n .with_target_map(target_map)\n .build()\n .unwrap();\n}\n#[marine]\npub fn foo() {\nlog::info!(target: \"instruction\", \"this will print if (loggingMask & 1) != 0\");\nlog::info!(target: \"data_cache\", \"this will print if (loggingMask & 2) != 0\");\n}\n```\n" + }, + "volumes": { + "type": "object", + "nullable": true, + "required": [], + "title": "Volumes", + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file" + }, + "envs": { + "type": "object", + "title": "Environment variables", + "nullable": true, + "required": [], + "description": "environment variables accessible by a particular module with standard Rust env API like this: std::env::var(IPFS_ADDR_ENV_NAME).\n\nPlease note that Marine adds three additional environment variables. Module environment variables could be examined with repl" + }, + "mountedBinaries": { + "title": "Mounted binaries", + "type": "object", + "nullable": true, + "required": [], + "description": "A map of binary executable files that module is allowed to call. Example: curl: /usr/bin/curl" + } + }, + "required": [ + "get" + ] + } + }, + "required": [ + "facade" + ] + }, + "version": { + "type": "number", + "const": 0 + } + }, + "required": [ + "version", + "name", + "modules" + ] +} diff --git a/marine-examples/sqlite/.fluence/tmp/Config.toml b/marine-examples/sqlite/.fluence/tmp/Config.toml new file mode 100644 index 0000000..32c2cbe --- /dev/null +++ b/marine-examples/sqlite/.fluence/tmp/Config.toml @@ -0,0 +1,10 @@ +[[module]] +name = "sqlite3" +load_from = "/Users/bebo/localdev/examples/marine-examples/sqlite/.fluence/modules/sqlite3.tar.gz_d35d7a28b1a8a55e87df96578d70ad46/sqlite3.wasm" + +[module.wasi.mapped_dirs] +sites = "./tmp" + +[[module]] +name = "sqlite_test" +load_from = "/Users/bebo/localdev/examples/marine-examples/sqlite/target/wasm32-wasi/release/sqlite_test.wasm" diff --git a/marine-examples/sqlite/.gitignore b/marine-examples/sqlite/.gitignore index 10ceb5d..dc5547c 100644 --- a/marine-examples/sqlite/.gitignore +++ b/marine-examples/sqlite/.gitignore @@ -5,3 +5,12 @@ **/**.bk /artifacts keypair.json + +# recommended by Fluence Labs: +.idea +.fluence +**/node_modules +**/target/ +.vscode/settings.json +src/ts/src/aqua +src/js/src/aqua diff --git a/marine-examples/sqlite/Cargo.toml b/marine-examples/sqlite/Cargo.toml index 36e3d2e..b919a21 100644 --- a/marine-examples/sqlite/Cargo.toml +++ b/marine-examples/sqlite/Cargo.toml @@ -1,17 +1,2 @@ -[package] -name = "wasm-sqlite-test" -version = "0.1.0" -authors = ["Fluence Labs"] -edition = "2018" -publish = false - -[[bin]] -name = "sqlite_test" -path = "src/main.rs" - -[dependencies] -marine-rs-sdk = "0.7.1" -marine-sqlite-connector = "0.5.1" - -[dev-dependencies] -marine-rs-sdk-test = "0.9.1" +[workspace] +members = [ "service/modules/sqlite_test" ] diff --git a/marine-examples/sqlite/Config.toml b/marine-examples/sqlite/Config.toml deleted file mode 100644 index 5fbb61d..0000000 --- a/marine-examples/sqlite/Config.toml +++ /dev/null @@ -1,11 +0,0 @@ -modules_dir = "artifacts/" - -[[module]] -name = "sqlite3" -max_heap_size = "100 KiB" -logger_enabled = false - -[[module]] -name = "sqlite_test" -max_heap_size = "10 KiB" -logger_enabled = false \ No newline at end of file diff --git a/marine-examples/sqlite/build.sh b/marine-examples/sqlite/build.sh deleted file mode 100755 index 0b63cef..0000000 --- a/marine-examples/sqlite/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -o errexit -o nounset -o pipefail - -# This script builds all subprojects and puts all created Wasm modules in one dir -cargo update --aggressive -marine build --release - -mkdir -p artifacts -rm -f artifacts/*.wasm -cp target/wasm32-wasi/release/sqlite_test.wasm artifacts/ -wget https://github.com/fluencelabs/sqlite/releases/download/v0.17.1_w/sqlite3.wasm -mv sqlite3.wasm artifacts/ diff --git a/marine-examples/sqlite/cli_048_dependencies.txt b/marine-examples/sqlite/cli_048_dependencies.txt new file mode 100644 index 0000000..7d42f27 --- /dev/null +++ b/marine-examples/sqlite/cli_048_dependencies.txt @@ -0,0 +1,23 @@ +Using version 0.21.3 of mrepl defined at /Users/bebo/.fluence/config.yaml instead of the recommended version 0.21.0. You may want to consider adding it to your project's fluence config. You can reset it to the recommended version by running `fluence dep r -g` +rust-peer version: fluencelabs/rust-peer:0.1.8 +rust toolchain: nightly-2022-12-01-x86_64 +npm dependencies that can be overridden with 'fluence dependency npm install @': + "@fluencelabs/aqua-lib": 0.7.0 + "@fluencelabs/aqua": 0.10.4 + "@fluencelabs/registry": 0.8.3 + "@fluencelabs/spell": 0.4.0 +cargo dependencies that can be overridden with 'fluence dependency cargo install @': + marine: 0.14.0 + mrepl: 0.21.3 +internal dependencies: + "@fluencelabs/aqua-api": ^0.10.3 + "@fluencelabs/deal-aurora": ^0.1.8 + "@fluencelabs/fluence-network-environment": ^1.0.14 + "@fluencelabs/js-client.api": ^0.11.6 + "@fluencelabs/js-client.node": ^0.6.8 +js-client.node dependencies: + "@fluencelabs/js-peer": 0.8.7 + "@fluencelabs/interfaces": 0.7.5 + "@fluencelabs/avm": 0.35.4 + "@fluencelabs/marine-js": 0.3.45 + diff --git a/marine-examples/sqlite/fluence.yaml b/marine-examples/sqlite/fluence.yaml new file mode 100644 index 0000000..6ae3bb0 --- /dev/null +++ b/marine-examples/sqlite/fluence.yaml @@ -0,0 +1,26 @@ +# yaml-language-server: $schema=.fluence/schemas/fluence.yaml.json + +# Defines Fluence Project, most importantly - what exactly you want to deploy and how. You can use `fluence init` command to generate a template for new Fluence project + +# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/fluence.md + +version: 2 +aquaInputPath: src/aqua/main.aqua +workers: + defaultWorker: + services: [ sqlite_test ] +deals: + defaultWorker: + minWorkers: 1 + targetWorkers: 3 +hosts: + defaultWorker: + peerIds: + - 12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt +relays: kras +dependencies: + cargo: + mrepl: 0.21.3 +services: + sqlite_test: + get: service diff --git a/marine-examples/sqlite/module-exports/sqlite.tar.gz b/marine-examples/sqlite/module-exports/sqlite.tar.gz deleted file mode 100644 index bad910b..0000000 Binary files a/marine-examples/sqlite/module-exports/sqlite.tar.gz and /dev/null differ diff --git a/marine-examples/sqlite/package_modules.sh b/marine-examples/sqlite/package_modules.sh deleted file mode 100755 index 0e8d5fb..0000000 --- a/marine-examples/sqlite/package_modules.sh +++ /dev/null @@ -1,19 +0,0 @@ -mkdir -p module-exports/modules/sqlite -sh ./build.sh - -cd module-exports -cp ../artifacts/sqlite3.wasm modules/sqlite/ - -file="modules/sqlite/module.yaml" -cat > $file <<- EOF -version: 0 -name: sqlite -loggerEnabled: true -EOF - - -tar -czvf sqlite.tar.gz modules -rm -r modules -cd ../ - -cargo clean diff --git a/marine-examples/sqlite/service/modules/sqlite_test/Cargo.toml b/marine-examples/sqlite/service/modules/sqlite_test/Cargo.toml new file mode 100644 index 0000000..6d71945 --- /dev/null +++ b/marine-examples/sqlite/service/modules/sqlite_test/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "sqlite_test" +version = "0.1.0" +edition = "2018" + +[[bin]] +name = "sqlite_test" +path = "src/main.rs" + +[dependencies] +marine-rs-sdk = "0.7.1" +marine-sqlite-connector = "0.8.0" + +[dev-dependencies] +marine-rs-sdk-test = "0.9.0" diff --git a/marine-examples/sqlite/service/modules/sqlite_test/module.yaml b/marine-examples/sqlite/service/modules/sqlite_test/module.yaml new file mode 100644 index 0000000..df6fa6e --- /dev/null +++ b/marine-examples/sqlite/service/modules/sqlite_test/module.yaml @@ -0,0 +1,9 @@ +# yaml-language-server: $schema=../../../.fluence/schemas/module.yaml.json + +# Defines [Marine Module](https://fluence.dev/docs/build/concepts/#modules). You can use `fluence module new` command to generate a template for new module + +# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/module.md + +version: 0 +type: rust +name: sqlite_test diff --git a/marine-examples/sqlite/src/main.rs b/marine-examples/sqlite/service/modules/sqlite_test/src/main.rs similarity index 89% rename from marine-examples/sqlite/src/main.rs rename to marine-examples/sqlite/service/modules/sqlite_test/src/main.rs index e8e41bb..2e7c2df 100644 --- a/marine-examples/sqlite/src/main.rs +++ b/marine-examples/sqlite/service/modules/sqlite_test/src/main.rs @@ -1,18 +1,3 @@ -/* - * Copyright 2020 Fluence Labs Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ use marine_rs_sdk::marine; use marine_rs_sdk::module_manifest; use std::io::{self, Write}; @@ -194,8 +179,9 @@ pub fn test_last_rowid() -> i64 { mod tests { use marine_rs_sdk_test::marine_test; - #[marine_test(config_path = "../Config.toml", modules_dir = "../artifacts")] + // #[marine_test(config_path = "../Config.toml", modules_dir = "../artifacts")] + #[marine_test(config_path = "../../.fluence/Config.toml", modules_dir = "../artifacts")] fn test(sqlite_test: marine_test_env::sqlite_test::ModuleInterface) { assert!(sqlite_test.test_last_rowid() > 0); } -} +} \ No newline at end of file diff --git a/marine-examples/sqlite/service/service.yaml b/marine-examples/sqlite/service/service.yaml new file mode 100644 index 0000000..e0a9853 --- /dev/null +++ b/marine-examples/sqlite/service/service.yaml @@ -0,0 +1,13 @@ +# yaml-language-server: $schema=../.fluence/schemas/service.yaml.json + +# Defines a [Marine service](https://fluence.dev/docs/build/concepts/#services), most importantly the modules that the service consists of. You can use `fluence service new` command to generate a template for new service + +# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/service.md + +version: 0 +name: sqlite_test +modules: + facade: + get: modules/sqlite_test + sqlite3: + get: https://github.com/fluencelabs/sqlite/releases/download/sqlite-wasm-v0.18.1/sqlite3.tar.gz diff --git a/marine-examples/url-downloader/.fluence/aqua/services.aqua b/marine-examples/url-downloader/.fluence/aqua/services.aqua new file mode 100644 index 0000000..39d6277 --- /dev/null +++ b/marine-examples/url-downloader/.fluence/aqua/services.aqua @@ -0,0 +1,4 @@ +service UrlDownloader("url_downloader"): + get(file_name: string) -> []u8 + get_n_save(url: string, file_name: string) -> string + put(file_name: string, file_content: []u8) -> string diff --git a/marine-examples/url-downloader/.fluence/aqua/workers.aqua b/marine-examples/url-downloader/.fluence/aqua/workers.aqua new file mode 100644 index 0000000..942fa4c --- /dev/null +++ b/marine-examples/url-downloader/.fluence/aqua/workers.aqua @@ -0,0 +1,18 @@ +data GetWorkersInfoDealsDefaultWorker: + installationSpells: ?u8 + definition: string + timestamp: string + dealIdOriginal: string + dealId: string + chainNetwork: string + chainNetworkId: f64 + +data GetWorkersInfoDeals: + defaultWorker: GetWorkersInfoDealsDefaultWorker + +data GetWorkersInfo: + deals: GetWorkersInfoDeals + hosts: ?u8 + +func getWorkersInfo() -> GetWorkersInfo: + <- GetWorkersInfo(deals=GetWorkersInfoDeals(defaultWorker=GetWorkersInfoDealsDefaultWorker(installationSpells=nil,definition="bafkreihndikxxxvl6r2alrfzh7awwywiolyklkwxzmzoyfcolvlxho2zuy",timestamp="2023-04-04T00:29:31.854Z",dealIdOriginal="0xd0c75aEEA62bc0ABf16F5f01361277CC8287AB0E",dealId="d0c75aeea62bc0abf16f5f01361277cc8287ab0e",chainNetwork="testnet",chainNetworkId=80001.0)),hosts=nil) diff --git a/marine-examples/url-downloader/.fluence/project-secrets.yaml b/marine-examples/url-downloader/.fluence/project-secrets.yaml new file mode 100644 index 0000000..8e4293f --- /dev/null +++ b/marine-examples/url-downloader/.fluence/project-secrets.yaml @@ -0,0 +1,8 @@ +# yaml-language-server: $schema=schemas/project-secrets.yaml.json + +# Defines project's secret keys that are used only in the scope of this particular Fluence project. You can manage project's keys using commands from `fluence key` group of commands + +# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/project-secrets.md + +version: 0 +keyPairs: [] diff --git a/marine-examples/url-downloader/.fluence/schemas/fluence-lock.yaml.json b/marine-examples/url-downloader/.fluence/schemas/fluence-lock.yaml.json new file mode 100644 index 0000000..3977930 --- /dev/null +++ b/marine-examples/url-downloader/.fluence/schemas/fluence-lock.yaml.json @@ -0,0 +1,29 @@ +{ + "type": "object", + "$id": "https://fluence.dev/schemas/fluence-lock.yaml", + "title": "fluence-lock.yaml", + "description": "Defines a lock file for Fluence Project dependencies. When dependencies are installed - their exact versions are saved here.", + "properties": { + "npm": { + "type": "object", + "title": "npm dependencies", + "description": "A map of the exact npm dependency versions. CLI ensures dependencies are installed each time you run aqua", + "required": [], + "nullable": true + }, + "cargo": { + "type": "object", + "title": "Cargo dependencies", + "description": "A map of the exact cargo dependency versions. CLI ensures dependencies are installed each time you run commands that depend on Marine or Marine REPL", + "required": [], + "nullable": true + }, + "version": { + "type": "number", + "const": 0 + } + }, + "required": [ + "version" + ] +} diff --git a/marine-examples/url-downloader/.fluence/schemas/fluence.yaml.json b/marine-examples/url-downloader/.fluence/schemas/fluence.yaml.json new file mode 100644 index 0000000..ad9c9b2 --- /dev/null +++ b/marine-examples/url-downloader/.fluence/schemas/fluence.yaml.json @@ -0,0 +1,474 @@ +{ + "type": "object", + "properties": { + "services": { + "title": "Services", + "description": "A map with service names as keys and Service configs as values. You can have any number of services listed here (According to JSON schema they are called 'additionalProperties') as long as service name keys start with a lowercase letter and contain only letters numbers and underscores. You can use `fluence service add` command to add a service to this config", + "type": "object", + "additionalProperties": { + "title": "Service config", + "description": "Service names as keys (must start with a lowercase letter and contain only letters numbers and underscores) and Service config (defines where the service is and how to deploy it) as values", + "type": "object", + "properties": { + "get": { + "type": "string", + "description": "Path to service directory or URL to the tar.gz archive with the service" + }, + "overrideModules": { + "type": "object", + "title": "Overrides", + "description": "A map of modules to override", + "additionalProperties": { + "type": "object", + "title": "Module overrides", + "description": "Module names as keys and overrides for the module config as values", + "properties": { + "get": { + "type": "string", + "nullable": true, + "description": "Path to module directory or URL to the tar.gz archive with the module" + }, + "maxHeapSize": { + "type": "string", + "nullable": true, + "description": "Max size of the heap that a module can allocate in format: [number][whitespace?][specificator?] where ? is an optional field and specificator is one from the following (case-insensitive):\n\nK, Kb - kilobyte\n\nKi, KiB - kibibyte\n\nM, Mb - megabyte\n\nMi, MiB - mebibyte\n\nG, Gb - gigabyte\n\nGi, GiB - gibibyte\n\nCurrent limit is 4 GiB" + }, + "loggerEnabled": { + "type": "boolean", + "nullable": true, + "description": "Set true to allow module to use the Marine SDK logger" + }, + "loggingMask": { + "type": "number", + "nullable": true, + "description": "Used for logging management. Example:\n```rust\nconst TARGET_MAP: [(&str, i64); 4] = [\n(\"instruction\", 1 << 1),\n(\"data_cache\", 1 << 2),\n(\"next_peer_pks\", 1 << 3),\n(\"subtree_complete\", 1 << 4),\n];\npub fn main() {\nuse std::collections::HashMap;\nuse std::iter::FromIterator;\n\nlet target_map = HashMap::from_iter(TARGET_MAP.iter().cloned());\n\nmarine_rs_sdk::WasmLoggerBuilder::new()\n .with_target_map(target_map)\n .build()\n .unwrap();\n}\n#[marine]\npub fn foo() {\nlog::info!(target: \"instruction\", \"this will print if (loggingMask & 1) != 0\");\nlog::info!(target: \"data_cache\", \"this will print if (loggingMask & 2) != 0\");\n}\n```\n" + }, + "volumes": { + "type": "object", + "nullable": true, + "required": [], + "title": "Volumes", + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)" + }, + "preopenedFiles": { + "type": "array", + "title": "Preopened files", + "description": "A list of files and directories that this module could access with WASI", + "items": { + "type": "string" + }, + "nullable": true + }, + "envs": { + "type": "object", + "title": "Environment variables", + "nullable": true, + "required": [], + "description": "environment variables accessible by a particular module with standard Rust env API like this: std::env::var(IPFS_ADDR_ENV_NAME).\n\nPlease note that Marine adds three additional environment variables. Module environment variables could be examined with repl" + }, + "mountedBinaries": { + "title": "Mounted binaries", + "type": "object", + "nullable": true, + "required": [], + "description": "A map of binary executable files that module is allowed to call. Example: curl: /usr/bin/curl" + } + }, + "required": [], + "nullable": true + }, + "nullable": true, + "required": [] + }, + "deploy": { + "type": "array", + "title": "Deployment list", + "nullable": true, + "description": "List of deployments for the particular service", + "items": { + "type": "object", + "title": "Deployment", + "description": "A small config for a particular deployment. You can have specific overrides for each and specific deployment properties like count, etc.", + "properties": { + "keyPairName": { + "type": "string", + "nullable": true, + "description": "The name of the Key Pair to use. It is resolved in the following order (from the lowest to the highest priority):\n1. \"defaultKeyPairName\" property from user-secrets.yaml\n1. \"defaultKeyPairName\" property from project-secrets.yaml\n1. \"keyPairName\" property from the top level of fluence.yaml\n1. \"keyPairName\" property from the \"services\" level of fluence.yaml\n1. \"keyPairName\" property from the individual \"deploy\" property item level of fluence.yaml" + }, + "deployId": { + "type": "string", + "description": "This id can be used in Aqua to access actually deployed peer and service ids. The ID must start with a lowercase letter and contain only letters, numbers, and underscores." + }, + "count": { + "type": "number", + "minimum": 1, + "nullable": true, + "description": "Number of services to deploy. Default: 1 or if \"peerIds\" property is provided - exactly the number of peerIds" + }, + "peerId": { + "type": "string", + "nullable": true, + "description": "Peer id or peer id name to deploy to. Default: Peer ids from the \"relay\" property of fluence.yaml are selected for each deploy. Named peerIds can be listed in \"peerIds\" property of fluence.yaml)" + }, + "peerIds": { + "type": "array", + "items": { + "type": "string" + }, + "nullable": true, + "title": "Peer ids", + "description": "Peer ids or peer id names to deploy to. Overrides \"peerId\" property. Named peerIds can be listed in \"peerIds\" property of fluence.yaml)" + }, + "overrideModules": { + "type": "object", + "title": "Overrides", + "description": "A map of modules to override", + "additionalProperties": { + "type": "object", + "title": "Module overrides", + "description": "Module names as keys and overrides for the module config as values", + "properties": { + "get": { + "type": "string", + "nullable": true, + "description": "Path to module directory or URL to the tar.gz archive with the module" + }, + "maxHeapSize": { + "type": "string", + "nullable": true, + "description": "Max size of the heap that a module can allocate in format: [number][whitespace?][specificator?] where ? is an optional field and specificator is one from the following (case-insensitive):\n\nK, Kb - kilobyte\n\nKi, KiB - kibibyte\n\nM, Mb - megabyte\n\nMi, MiB - mebibyte\n\nG, Gb - gigabyte\n\nGi, GiB - gibibyte\n\nCurrent limit is 4 GiB" + }, + "loggerEnabled": { + "type": "boolean", + "nullable": true, + "description": "Set true to allow module to use the Marine SDK logger" + }, + "loggingMask": { + "type": "number", + "nullable": true, + "description": "Used for logging management. Example:\n```rust\nconst TARGET_MAP: [(&str, i64); 4] = [\n(\"instruction\", 1 << 1),\n(\"data_cache\", 1 << 2),\n(\"next_peer_pks\", 1 << 3),\n(\"subtree_complete\", 1 << 4),\n];\npub fn main() {\nuse std::collections::HashMap;\nuse std::iter::FromIterator;\n\nlet target_map = HashMap::from_iter(TARGET_MAP.iter().cloned());\n\nmarine_rs_sdk::WasmLoggerBuilder::new()\n .with_target_map(target_map)\n .build()\n .unwrap();\n}\n#[marine]\npub fn foo() {\nlog::info!(target: \"instruction\", \"this will print if (loggingMask & 1) != 0\");\nlog::info!(target: \"data_cache\", \"this will print if (loggingMask & 2) != 0\");\n}\n```\n" + }, + "volumes": { + "type": "object", + "nullable": true, + "required": [], + "title": "Volumes", + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)" + }, + "preopenedFiles": { + "type": "array", + "title": "Preopened files", + "description": "A list of files and directories that this module could access with WASI", + "items": { + "type": "string" + }, + "nullable": true + }, + "envs": { + "type": "object", + "title": "Environment variables", + "nullable": true, + "required": [], + "description": "environment variables accessible by a particular module with standard Rust env API like this: std::env::var(IPFS_ADDR_ENV_NAME).\n\nPlease note that Marine adds three additional environment variables. Module environment variables could be examined with repl" + }, + "mountedBinaries": { + "title": "Mounted binaries", + "type": "object", + "nullable": true, + "required": [], + "description": "A map of binary executable files that module is allowed to call. Example: curl: /usr/bin/curl" + } + }, + "required": [], + "nullable": true + }, + "nullable": true, + "required": [] + } + }, + "required": [ + "deployId" + ] + } + }, + "keyPairName": { + "type": "string", + "nullable": true, + "description": "The name of the Key Pair to use. It is resolved in the following order (from the lowest to the highest priority):\n1. \"defaultKeyPairName\" property from user-secrets.yaml\n1. \"defaultKeyPairName\" property from project-secrets.yaml\n1. \"keyPairName\" property from the top level of fluence.yaml\n1. \"keyPairName\" property from the \"services\" level of fluence.yaml\n1. \"keyPairName\" property from the individual \"deploy\" property item level of fluence.yaml" + } + }, + "required": [ + "get" + ] + }, + "required": [], + "nullable": true + }, + "relays": { + "title": "Relays", + "description": "List of Fluence Peer multi addresses or a name of the network. This multi addresses are used for connecting to the Fluence network when deploying. Peer ids from these addresses are also used for deploying in case if you don't specify \"peerId\" or \"peerIds\" property in the deployment config. Default: kras", + "type": [ + "string", + "array", + "null" + ], + "oneOf": [ + { + "type": "string", + "title": "Network name", + "enum": [ + "kras", + "stage", + "testnet" + ] + }, + { + "type": "array", + "title": "Multi addresses", + "items": { + "type": "string" + }, + "minItems": 1 + } + ], + "nullable": true + }, + "peerIds": { + "title": "Peer ids", + "description": "A map of named peerIds. Example:\n\nMY_PEER: 12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS", + "type": "object", + "nullable": true, + "required": [], + "additionalProperties": { + "type": "string", + "description": "Peer id names as keys and the actual peer ids as values" + } + }, + "keyPairName": { + "type": "string", + "nullable": true, + "description": "The name of the Key Pair to use. It is resolved in the following order (from the lowest to the highest priority):\n1. \"defaultKeyPairName\" property from user-secrets.yaml\n1. \"defaultKeyPairName\" property from project-secrets.yaml\n1. \"keyPairName\" property from the top level of fluence.yaml\n1. \"keyPairName\" property from the \"services\" level of fluence.yaml\n1. \"keyPairName\" property from the individual \"deploy\" property item level of fluence.yaml" + }, + "version": { + "type": "number", + "const": 2 + }, + "dependencies": { + "type": "object", + "title": "Dependencies", + "nullable": true, + "description": "A map of dependency versions", + "properties": { + "npm": { + "type": "object", + "title": "npm dependencies", + "nullable": true, + "description": "A map of npm dependency versions. CLI ensures dependencies are installed each time you run aqua", + "required": [] + }, + "cargo": { + "type": "object", + "title": "Cargo dependencies", + "nullable": true, + "description": "A map of cargo dependency versions. CLI ensures dependencies are installed each time you run commands that depend on Marine or Marine REPL", + "required": [] + } + }, + "required": [] + }, + "aquaInputPath": { + "type": "string", + "nullable": true, + "description": "Path to the aqua file or directory with aqua files that you want to compile by default. Must be relative to the project root dir" + }, + "aquaOutputTSPath": { + "type": "string", + "nullable": true, + "description": "Path to the default compilation target dir from aqua to ts. Must be relative to the project root dir" + }, + "aquaOutputJSPath": { + "type": "string", + "nullable": true, + "description": "Path to the default compilation target dir from aqua to js. Must be relative to the project root dir. Overrides 'aquaOutputTSPath' property" + }, + "appTSPath": { + "type": "string", + "nullable": true, + "description": "Path to the directory where you want to generate app.ts after deployment. If you run registerApp() function in your typescript code after initializing FluenceJS client you will be able to access ids of the deployed services in aqua" + }, + "appJSPath": { + "type": "string", + "nullable": true, + "description": "Path to the directory where you want to generate app.js after deployment. If you run registerApp() function in your javascript code after initializing FluenceJS client you will be able to access ids of the deployed services in aqua" + }, + "hosts": { + "description": "A map of objects with worker names as keys, each object defines a list of peer IDs to host the worker on", + "type": "object", + "nullable": true, + "additionalProperties": { + "type": "object", + "properties": { + "peerIds": { + "type": "array", + "description": "An array of peer IDs to deploy on", + "items": { + "type": "string" + } + } + }, + "required": [ + "peerIds" + ] + }, + "required": [] + }, + "workers": { + "nullable": true, + "description": "A Map with worker names as keys and worker configs as values", + "type": "object", + "additionalProperties": { + "type": "object", + "description": "Worker config", + "properties": { + "services": { + "description": "An array of service names to include in this worker. Service names must be listed in fluence.yaml", + "type": "array", + "items": { + "type": "string" + }, + "nullable": true + }, + "spells": { + "description": "An array of spell names to include in this worker. Spell names must be listed in fluence.yaml", + "type": "array", + "items": { + "type": "string" + }, + "nullable": true + } + }, + "required": [] + }, + "required": [] + }, + "deals": { + "description": "A map of objects with worker names as keys, each object defines a deal", + "type": "object", + "nullable": true, + "additionalProperties": { + "type": "object", + "properties": { + "minWorkers": { + "type": "number", + "description": "Required workers to activate the deal", + "default": 1, + "nullable": true, + "minimum": 1 + }, + "targetWorkers": { + "type": "number", + "description": "Max workers in the deal", + "default": 3, + "nullable": true, + "minimum": 1 + } + }, + "required": [] + }, + "required": [] + }, + "chainNetwork": { + "type": "string", + "description": "The network in which the transactions will be carried out", + "enum": [ + "local", + "testnet" + ], + "default": "testnet", + "nullable": true + }, + "spells": { + "type": "object", + "nullable": true, + "description": "A map with spell names as keys and spell configs as values", + "additionalProperties": { + "type": "object", + "description": "Spell config", + "properties": { + "get": { + "type": "string", + "description": "Path to spell" + }, + "version": { + "type": "number", + "const": 0 + }, + "aquaFilePath": { + "type": "string", + "description": "Path to Aqua file which contains an Aqua function that you want to use as a spell", + "nullable": true + }, + "function": { + "type": "string", + "description": "Name of the Aqua function that you want to use as a spell", + "nullable": true + }, + "initArgs": { + "type": "object", + "description": "A map of Aqua function arguments names as keys and arguments values as values. They will be passed to the spell function and will be stored in the key-value storage for this particular spell.", + "nullable": true + }, + "clock": { + "type": "object", + "nullable": true, + "description": "Trigger the spell execution periodically. If you want to disable this property by overriding it in fluence.yaml - pass empty config for it like this: `clock: {}`", + "properties": { + "periodSec": { + "type": "number", + "description": "How often the spell will be executed. If set to 0, the spell will be executed only once. If this value not provided at all - the spell will never be executed", + "minimum": 0, + "maximum": 3153600000, + "nullable": true + }, + "startTimestamp": { + "type": "string", + "description": "An ISO timestamp when the periodic execution should start. If this property or `startDelaySec` not specified, periodic execution will start immediately. If it is set to 0 - the spell will never be executed", + "nullable": true + }, + "endTimestamp": { + "type": "string", + "description": "An ISO timestamp when the periodic execution should end. If this property or `endDelaySec` not specified, periodic execution will never end. If it is in the past at the moment of spell creation on Rust peer - the spell will never be executed", + "nullable": true + }, + "startDelaySec": { + "type": "number", + "description": "How long to wait before the first execution in seconds. If this property or `startTimestamp` not specified, periodic execution will start immediately. WARNING! Currently your computer's clock is used to determine a final timestamp that is sent to the server. This property conflicts with `startTimestamp`. You can specify only one of them", + "nullable": true, + "minimum": 0, + "maximum": 4294967295 + }, + "endDelaySec": { + "type": "number", + "description": "How long to wait before the last execution in seconds. If this property or `endTimestamp` not specified, periodic execution will never end. WARNING! Currently your computer's clock is used to determine a final timestamp that is sent to the server. If it is in the past at the moment of spell creation - the spell will never be executed. This property conflicts with `endTimestamp`. You can specify only one of them", + "nullable": true, + "minimum": 0, + "maximum": 4294967295 + } + }, + "required": [] + } + }, + "required": [ + "get" + ] + }, + "required": [] + } + }, + "required": [ + "version" + ], + "$id": "https://fluence.dev/schemas/fluence.yaml", + "title": "fluence.yaml", + "description": "Defines Fluence Project, most importantly - what exactly you want to deploy and how. You can use `fluence init` command to generate a template for new Fluence project" +} diff --git a/marine-examples/url-downloader/.fluence/schemas/module.yaml.json b/marine-examples/url-downloader/.fluence/schemas/module.yaml.json new file mode 100644 index 0000000..910e6e2 --- /dev/null +++ b/marine-examples/url-downloader/.fluence/schemas/module.yaml.json @@ -0,0 +1,75 @@ +{ + "type": "object", + "$id": "https://fluence.dev/schemas/module.yaml", + "title": "module.yaml", + "description": "Defines [Marine Module](https://fluence.dev/docs/build/concepts/#modules). You can use `fluence module new` command to generate a template for new module", + "properties": { + "name": { + "type": "string", + "description": "\"name\" property from the Cargo.toml (for module type \"rust\") or name of the precompiled .wasm file (for module type \"compiled\")" + }, + "type": { + "type": "string", + "enum": [ + "rust", + "compiled" + ], + "nullable": true, + "default": "compiled", + "description": "Module type \"compiled\" is for the precompiled modules. Module type \"rust\" is for the source code written in rust which can be compiled into a Marine module" + }, + "maxHeapSize": { + "type": "string", + "nullable": true, + "description": "Max size of the heap that a module can allocate in format: [number][whitespace?][specificator?] where ? is an optional field and specificator is one from the following (case-insensitive):\n\nK, Kb - kilobyte\n\nKi, KiB - kibibyte\n\nM, Mb - megabyte\n\nMi, MiB - mebibyte\n\nG, Gb - gigabyte\n\nGi, GiB - gibibyte\n\nCurrent limit is 4 GiB" + }, + "loggerEnabled": { + "type": "boolean", + "nullable": true, + "description": "Set true to allow module to use the Marine SDK logger" + }, + "loggingMask": { + "type": "number", + "nullable": true, + "description": "Used for logging management. Example:\n```rust\nconst TARGET_MAP: [(&str, i64); 4] = [\n(\"instruction\", 1 << 1),\n(\"data_cache\", 1 << 2),\n(\"next_peer_pks\", 1 << 3),\n(\"subtree_complete\", 1 << 4),\n];\npub fn main() {\nuse std::collections::HashMap;\nuse std::iter::FromIterator;\n\nlet target_map = HashMap::from_iter(TARGET_MAP.iter().cloned());\n\nmarine_rs_sdk::WasmLoggerBuilder::new()\n .with_target_map(target_map)\n .build()\n .unwrap();\n}\n#[marine]\npub fn foo() {\nlog::info!(target: \"instruction\", \"this will print if (loggingMask & 1) != 0\");\nlog::info!(target: \"data_cache\", \"this will print if (loggingMask & 2) != 0\");\n}\n```\n" + }, + "volumes": { + "type": "object", + "nullable": true, + "required": [], + "title": "Volumes", + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)" + }, + "preopenedFiles": { + "type": "array", + "title": "Preopened files", + "description": "A list of files and directories that this module could access with WASI", + "items": { + "type": "string" + }, + "nullable": true + }, + "envs": { + "type": "object", + "title": "Environment variables", + "nullable": true, + "required": [], + "description": "environment variables accessible by a particular module with standard Rust env API like this: std::env::var(IPFS_ADDR_ENV_NAME).\n\nPlease note that Marine adds three additional environment variables. Module environment variables could be examined with repl" + }, + "mountedBinaries": { + "title": "Mounted binaries", + "type": "object", + "nullable": true, + "required": [], + "description": "A map of binary executable files that module is allowed to call. Example: curl: /usr/bin/curl" + }, + "version": { + "type": "number", + "const": 0 + } + }, + "required": [ + "version", + "name" + ] +} diff --git a/marine-examples/url-downloader/.fluence/schemas/project-secrets.yaml.json b/marine-examples/url-downloader/.fluence/schemas/project-secrets.yaml.json new file mode 100644 index 0000000..6e92594 --- /dev/null +++ b/marine-examples/url-downloader/.fluence/schemas/project-secrets.yaml.json @@ -0,0 +1,42 @@ +{ + "$id": "https://fluence.dev/schemas/project-secrets.yaml", + "title": "project-secrets.yaml", + "type": "object", + "description": "Defines project's secret keys that are used only in the scope of this particular Fluence project. You can manage project's keys using commands from `fluence key` group of commands", + "properties": { + "keyPairs": { + "title": "Key Pairs", + "description": "Key Pairs available for the particular project", + "type": "array", + "items": { + "title": "Key Pair", + "type": "object", + "properties": { + "secretKey": { + "type": "string" + }, + "name": { + "type": "string" + } + }, + "required": [ + "secretKey", + "name" + ] + } + }, + "defaultKeyPairName": { + "type": "string", + "nullable": true, + "description": "Key pair with this name will be used for the deployment by default. You can override it with flags or by using keyPair properties in fluence.yaml" + }, + "version": { + "type": "number", + "const": 0 + } + }, + "required": [ + "version", + "keyPairs" + ] +} diff --git a/marine-examples/url-downloader/.fluence/schemas/service.yaml.json b/marine-examples/url-downloader/.fluence/schemas/service.yaml.json new file mode 100644 index 0000000..dc51e68 --- /dev/null +++ b/marine-examples/url-downloader/.fluence/schemas/service.yaml.json @@ -0,0 +1,147 @@ +{ + "type": "object", + "$id": "https://fluence.dev/schemas/service.yaml", + "title": "service.yaml", + "description": "Defines a [Marine service](https://fluence.dev/docs/build/concepts/#services), most importantly the modules that the service consists of. You can use `fluence service new` command to generate a template for new service", + "properties": { + "name": { + "type": "string", + "description": "Service name. Currently it is used for the service name only when you add service to fluence.yaml using \"add\" command. But this name can be overridden to any other with the --name flag or manually in fluence.yaml" + }, + "modules": { + "title": "Modules", + "description": "Service must have a facade module. Each module properties can be overridden by the same properties in the service config", + "type": "object", + "additionalProperties": { + "type": "object", + "title": "Module", + "properties": { + "get": { + "type": "string", + "description": "Either path to the module directory or URL to the tar.gz archive which contains the content of the module directory" + }, + "maxHeapSize": { + "type": "string", + "nullable": true, + "description": "Max size of the heap that a module can allocate in format: [number][whitespace?][specificator?] where ? is an optional field and specificator is one from the following (case-insensitive):\n\nK, Kb - kilobyte\n\nKi, KiB - kibibyte\n\nM, Mb - megabyte\n\nMi, MiB - mebibyte\n\nG, Gb - gigabyte\n\nGi, GiB - gibibyte\n\nCurrent limit is 4 GiB" + }, + "loggerEnabled": { + "type": "boolean", + "nullable": true, + "description": "Set true to allow module to use the Marine SDK logger" + }, + "loggingMask": { + "type": "number", + "nullable": true, + "description": "Used for logging management. Example:\n```rust\nconst TARGET_MAP: [(&str, i64); 4] = [\n(\"instruction\", 1 << 1),\n(\"data_cache\", 1 << 2),\n(\"next_peer_pks\", 1 << 3),\n(\"subtree_complete\", 1 << 4),\n];\npub fn main() {\nuse std::collections::HashMap;\nuse std::iter::FromIterator;\n\nlet target_map = HashMap::from_iter(TARGET_MAP.iter().cloned());\n\nmarine_rs_sdk::WasmLoggerBuilder::new()\n .with_target_map(target_map)\n .build()\n .unwrap();\n}\n#[marine]\npub fn foo() {\nlog::info!(target: \"instruction\", \"this will print if (loggingMask & 1) != 0\");\nlog::info!(target: \"data_cache\", \"this will print if (loggingMask & 2) != 0\");\n}\n```\n" + }, + "volumes": { + "type": "object", + "nullable": true, + "required": [], + "title": "Volumes", + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)" + }, + "preopenedFiles": { + "type": "array", + "title": "Preopened files", + "description": "A list of files and directories that this module could access with WASI", + "items": { + "type": "string" + }, + "nullable": true + }, + "envs": { + "type": "object", + "title": "Environment variables", + "nullable": true, + "required": [], + "description": "environment variables accessible by a particular module with standard Rust env API like this: std::env::var(IPFS_ADDR_ENV_NAME).\n\nPlease note that Marine adds three additional environment variables. Module environment variables could be examined with repl" + }, + "mountedBinaries": { + "title": "Mounted binaries", + "type": "object", + "nullable": true, + "required": [], + "description": "A map of binary executable files that module is allowed to call. Example: curl: /usr/bin/curl" + } + }, + "required": [ + "get" + ] + }, + "properties": { + "facade": { + "type": "object", + "title": "Module", + "properties": { + "get": { + "type": "string", + "description": "Either path to the module directory or URL to the tar.gz archive which contains the content of the module directory" + }, + "maxHeapSize": { + "type": "string", + "nullable": true, + "description": "Max size of the heap that a module can allocate in format: [number][whitespace?][specificator?] where ? is an optional field and specificator is one from the following (case-insensitive):\n\nK, Kb - kilobyte\n\nKi, KiB - kibibyte\n\nM, Mb - megabyte\n\nMi, MiB - mebibyte\n\nG, Gb - gigabyte\n\nGi, GiB - gibibyte\n\nCurrent limit is 4 GiB" + }, + "loggerEnabled": { + "type": "boolean", + "nullable": true, + "description": "Set true to allow module to use the Marine SDK logger" + }, + "loggingMask": { + "type": "number", + "nullable": true, + "description": "Used for logging management. Example:\n```rust\nconst TARGET_MAP: [(&str, i64); 4] = [\n(\"instruction\", 1 << 1),\n(\"data_cache\", 1 << 2),\n(\"next_peer_pks\", 1 << 3),\n(\"subtree_complete\", 1 << 4),\n];\npub fn main() {\nuse std::collections::HashMap;\nuse std::iter::FromIterator;\n\nlet target_map = HashMap::from_iter(TARGET_MAP.iter().cloned());\n\nmarine_rs_sdk::WasmLoggerBuilder::new()\n .with_target_map(target_map)\n .build()\n .unwrap();\n}\n#[marine]\npub fn foo() {\nlog::info!(target: \"instruction\", \"this will print if (loggingMask & 1) != 0\");\nlog::info!(target: \"data_cache\", \"this will print if (loggingMask & 2) != 0\");\n}\n```\n" + }, + "volumes": { + "type": "object", + "nullable": true, + "required": [], + "title": "Volumes", + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)" + }, + "preopenedFiles": { + "type": "array", + "title": "Preopened files", + "description": "A list of files and directories that this module could access with WASI", + "items": { + "type": "string" + }, + "nullable": true + }, + "envs": { + "type": "object", + "title": "Environment variables", + "nullable": true, + "required": [], + "description": "environment variables accessible by a particular module with standard Rust env API like this: std::env::var(IPFS_ADDR_ENV_NAME).\n\nPlease note that Marine adds three additional environment variables. Module environment variables could be examined with repl" + }, + "mountedBinaries": { + "title": "Mounted binaries", + "type": "object", + "nullable": true, + "required": [], + "description": "A map of binary executable files that module is allowed to call. Example: curl: /usr/bin/curl" + } + }, + "required": [ + "get" + ] + } + }, + "required": [ + "facade" + ] + }, + "version": { + "type": "number", + "const": 0 + } + }, + "required": [ + "version", + "name", + "modules" + ] +} diff --git a/marine-examples/url-downloader/.fluence/schemas/workers.yaml.json b/marine-examples/url-downloader/.fluence/schemas/workers.yaml.json new file mode 100644 index 0000000..eb35275 --- /dev/null +++ b/marine-examples/url-downloader/.fluence/schemas/workers.yaml.json @@ -0,0 +1,131 @@ +{ + "$id": "https://fluence.dev/schemas/workers.yaml", + "title": "workers.yaml", + "type": "object", + "description": "A result of app deployment. This file is created automatically after successful deployment using `fluence workers deploy` command", + "properties": { + "version": { + "type": "number", + "const": 0 + }, + "deals": { + "type": "object", + "description": "A map of created deals", + "additionalProperties": { + "type": "object", + "properties": { + "installation_spells": { + "type": "array", + "description": "A list of installation spells", + "items": { + "type": "object", + "properties": { + "host_id": { + "type": "string" + }, + "spell_id": { + "type": "string" + }, + "worker_id": { + "type": "string" + } + }, + "required": [ + "host_id", + "spell_id", + "worker_id" + ] + } + }, + "definition": { + "type": "string" + }, + "timestamp": { + "type": "string", + "description": "ISO timestamp of the time when the worker was deployed" + }, + "dealId": { + "type": "string" + }, + "dealIdOriginal": { + "type": "string" + }, + "chainNetwork": { + "type": "string", + "enum": [ + "local", + "testnet" + ] + }, + "chainNetworkId": { + "type": "number" + } + }, + "required": [ + "installation_spells", + "timestamp", + "definition", + "dealId", + "dealIdOriginal", + "chainNetwork", + "chainNetworkId" + ] + }, + "required": [], + "nullable": true + }, + "hosts": { + "type": "object", + "description": "A map of deployed workers", + "additionalProperties": { + "type": "object", + "properties": { + "installation_spells": { + "type": "array", + "description": "A list of installation spells", + "items": { + "type": "object", + "properties": { + "host_id": { + "type": "string" + }, + "spell_id": { + "type": "string" + }, + "worker_id": { + "type": "string" + } + }, + "required": [ + "host_id", + "spell_id", + "worker_id" + ] + } + }, + "definition": { + "type": "string" + }, + "timestamp": { + "type": "string", + "description": "ISO timestamp of the time when the worker was deployed" + }, + "relayId": { + "type": "string" + } + }, + "required": [ + "installation_spells", + "timestamp", + "definition", + "relayId" + ] + }, + "required": [], + "nullable": true + } + }, + "required": [ + "version" + ] +} diff --git a/marine-examples/url-downloader/.fluence/tmp/Config.toml b/marine-examples/url-downloader/.fluence/tmp/Config.toml new file mode 100644 index 0000000..3f0eb62 --- /dev/null +++ b/marine-examples/url-downloader/.fluence/tmp/Config.toml @@ -0,0 +1,23 @@ +[[module]] +name = "local_storage" +load_from = "/Users/bebo/localdev/examples/marine-examples/url-downloader/target/wasm32-wasi/release/local_storage.wasm" +logger_enabled = true + + [module.wasi] + preopened_files = [ "./tmp" ] + + [module.wasi.mapped_dirs] + sites = "./tmp" + +[[module]] +name = "curl_adapter" +load_from = "/Users/bebo/localdev/examples/marine-examples/url-downloader/target/wasm32-wasi/release/curl_adapter.wasm" +logger_enabled = true + + [module.mounted_binaries] + curl = "/usr/bin/curl" + +[[module]] +name = "url_downloader" +load_from = "/Users/bebo/localdev/examples/marine-examples/url-downloader/target/wasm32-wasi/release/url_downloader.wasm" +logger_enabled = true diff --git a/marine-examples/url-downloader/.fluence/workers.yaml b/marine-examples/url-downloader/.fluence/workers.yaml new file mode 100644 index 0000000..bffc3f5 --- /dev/null +++ b/marine-examples/url-downloader/.fluence/workers.yaml @@ -0,0 +1,16 @@ +# yaml-language-server: $schema=schemas/workers.yaml.json + +# A result of app deployment. This file is created automatically after successful deployment using `fluence workers deploy` command + +# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/workers.md + +version: 0 +deals: + defaultWorker: + installation_spells: [] + definition: bafkreihndikxxxvl6r2alrfzh7awwywiolyklkwxzmzoyfcolvlxho2zuy + timestamp: 2023-04-04T00:29:31.854Z + dealIdOriginal: "0xd0c75aEEA62bc0ABf16F5f01361277CC8287AB0E" + dealId: d0c75aeea62bc0abf16f5f01361277cc8287ab0e + chainNetwork: testnet + chainNetworkId: 80001 diff --git a/marine-examples/url-downloader/.fluence/workers.yaml.bsk b/marine-examples/url-downloader/.fluence/workers.yaml.bsk new file mode 100644 index 0000000..a2288b9 --- /dev/null +++ b/marine-examples/url-downloader/.fluence/workers.yaml.bsk @@ -0,0 +1,16 @@ +# yaml-language-server: $schema=schemas/workers.yaml.json + +# A result of app deployment. This file is created automatically after successful deployment using `fluence workers deploy` command + +# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/workers.md + +version: 0 +deals: + defaultWorker: + installation_spells: [] + definition: bafkreigvh7cxlf5nkisqqxq6alpoj32l44ttxkfxafa6agp2u344kl3k4m + timestamp: 2023-04-03T22:37:49.594Z + dealIdOriginal: "0xEA6f3D3177c40123C7B8B1d89440F1DdcfA6014B" + dealId: ea6f3d3177c40123c7b8b1d89440f1ddcfa6014b + chainNetwork: testnet + chainNetworkId: 80001 diff --git a/marine-examples/url-downloader/.gitignore b/marine-examples/url-downloader/.gitignore new file mode 100644 index 0000000..b1402ef --- /dev/null +++ b/marine-examples/url-downloader/.gitignore @@ -0,0 +1,9 @@ +.idea +.DS_Store +.fluence +**/node_modules +**/target/ +.repl_history +.vscode/settings.json +src/ts/src/aqua +src/js/src/aqua \ No newline at end of file diff --git a/marine-examples/url-downloader/Cargo.toml b/marine-examples/url-downloader/Cargo.toml new file mode 100644 index 0000000..5cf45bc --- /dev/null +++ b/marine-examples/url-downloader/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] +members = [ + "service/modules/url_downloader", + "service/modules/local_storage", + "service/modules/curl_adapter" +] diff --git a/marine-examples/url-downloader/Config.toml b/marine-examples/url-downloader/Config.toml deleted file mode 100644 index d22508b..0000000 --- a/marine-examples/url-downloader/Config.toml +++ /dev/null @@ -1,21 +0,0 @@ -modules_dir = "artifacts/" - -[[module]] - name = "local_storage" - logger_enabled = true - - [module.wasi] - preopened_files = ["./sites"] - # this is where files will be stored - mapped_dirs = { "sites" = "./sites" } - -[[module]] - name = "curl_adapter" - logger_enabled = true - - [module.mounted_binaries] - curl = "/usr/bin/curl" - -[[module]] - name = "facade" - logger_enabled = true diff --git a/marine-examples/url-downloader/artifacts/curl_adapter.json b/marine-examples/url-downloader/artifacts/curl_adapter.json deleted file mode 100644 index 5e9aa5f..0000000 --- a/marine-examples/url-downloader/artifacts/curl_adapter.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "curl_adapter", - "mounted_binaries": - { - "curl": "/usr/bin/curl" - }, - "mem_page_count": 1, - "preopened_files": [ - "/tmp" - ], - "mapped_dirs": { - "tmp": "./tmp" - }, - "logger_enabled": true -} diff --git a/marine-examples/url-downloader/artifacts/facade.json b/marine-examples/url-downloader/artifacts/facade.json deleted file mode 100644 index 180ed7e..0000000 --- a/marine-examples/url-downloader/artifacts/facade.json +++ /dev/null @@ -1 +0,0 @@ -{"name": "facade"} diff --git a/marine-examples/url-downloader/artifacts/local_storage.json b/marine-examples/url-downloader/artifacts/local_storage.json deleted file mode 100644 index c4c3ad2..0000000 --- a/marine-examples/url-downloader/artifacts/local_storage.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "local_storage", - "preopenedFiles": [ - "/tmp" - ], - "mappedDirs": { - "sites": "/tmp" - }, - "mountedBinaries": { - "curl": "/usr/bin/curl" - } -} diff --git a/marine-examples/url-downloader/build.sh b/marine-examples/url-downloader/build.sh deleted file mode 100755 index 2d8702a..0000000 --- a/marine-examples/url-downloader/build.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -set -o errexit -o nounset -o pipefail - -# This script builds all subprojects and puts all created Wasm modules in one dir -( - cd local_storage - cargo update --aggressive - marine build --release -) -( - cd curl_adapter - cargo update --aggressive - marine build --release -) -( - cd facade - cargo update --aggressive - marine build --release -) - -mkdir -p sites -mkdir -p artifacts -rm -f artifacts/*.wasm -cp local_storage/target/wasm32-wasi/release/local_storage.wasm artifacts/ -cp curl_adapter/target/wasm32-wasi/release/curl_adapter.wasm artifacts/ -cp facade/target/wasm32-wasi/release/facade.wasm artifacts/ diff --git a/marine-examples/url-downloader/deploy.sh b/marine-examples/url-downloader/deploy.sh deleted file mode 100755 index ae5f477..0000000 --- a/marine-examples/url-downloader/deploy.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash -set -o errexit -o nounset -o pipefail - -function is_installed { - if command -v "$1" >/dev/null 2>&1; then - echo "${1} is installed" - else - echo "${1} not found, please install it" - echo "exiting..." - exit 1 - fi -} - -echo "building wasm modules..." -# build wasms -./build.sh - -( - is_installed jq - is_installed aqua - - echo "generating keys..." - - SK=$(aqua key create | jq -r ."secretKey") - - echo "deploying the url-downloader service" - - aqua remote deploy_service \ - --addr /dns4/kras-05.fluence.dev/tcp/19001/wss/p2p/12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS \ - --config-path deployment_cfg.json \ - --sk ${SK} \ - --service url-downloader -) diff --git a/marine-examples/url-downloader/deploy_separate.sh b/marine-examples/url-downloader/deploy_separate.sh deleted file mode 100755 index 99caf57..0000000 --- a/marine-examples/url-downloader/deploy_separate.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -set -o errexit -o nounset -o pipefail - -./build.sh - -echo "Deploying storage" -( - aqua remote deploy_service \ - --addr /dns4/kras-05.fluence.dev/tcp/19001/wss/p2p/12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS \ - --config-path deployment_cfg.json \ - --service local-storage -) - -echo "\n\nDeploying curl" -( - aqua remote deploy_service \ - --addr /dns4/kras-05.fluence.dev/tcp/19001/wss/p2p/12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS \ - --config-path deployment_cfg.json \ - --service curl-adapter -) diff --git a/marine-examples/url-downloader/deployment_cfg.json b/marine-examples/url-downloader/deployment_cfg.json deleted file mode 100644 index 3eb30fb..0000000 --- a/marine-examples/url-downloader/deployment_cfg.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "url-downloader": { - "name": "url-downloader", - "modules": [ - { - "name": "curl_adapter", - "path": "./artifacts/curl_adapter.wasm", - "mounted_binaries": [["curl", "/usr/bin/curl"]], - "logger_enabled": true - }, - { - "name": "local_storage", - "path": "./artifacts/local_storage.wasm", - "preopened_files": ["/tmp"], - "mapped_dirs": [["sites", "/tmp"]], - "logger_enabled": true - }, - { - "name": "url_dowloader", - "path": "./artifacts/facade.wasm", - "logger_enabled": true - } - ] - }, - "local-storage": { - "modules": [ - { - "name": "local_storage", - "path": "./artifacts/local_storage.wasm", - "preopened_files": ["/tmp"], - "mapped_dirs": [["sites", "/tmp"]], - "logger_enabled": true - } - ] - }, - "curl-adapter": { - "modules": [ - { - "name": "curl_adapter", - "path": "./artifacts/curl_adapter.wasm", - "mounted_binaries": [["curl", "/usr/bin/curl"]], - "logger_enabled": true - } - ] - } -} diff --git a/marine-examples/url-downloader/deployment_data.txt b/marine-examples/url-downloader/deployment_data.txt deleted file mode 100644 index 77ef84a..0000000 --- a/marine-examples/url-downloader/deployment_data.txt +++ /dev/null @@ -1,23 +0,0 @@ - aqua remote deploy_service \ - --addr /dns4/kras-06.fluence.dev/tcp/19001/wss/p2p/12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr \ - --config-path deployment_cfg.json \ - --service url-downloader - -Your peerId: 12D3KooWRPELv7DNPJvd7uG79etrvzN7VUaQGUt58qBWu4c58UHb -"Going to upload a module..." -2022.02.16 08:12:50 [INFO] created ipfs client to /ip4/161.35.212.85/tcp/5001 -2022.02.16 08:12:50 [INFO] connected to ipfs -2022.02.16 08:12:51 [INFO] file uploaded -"Going to upload a module..." -2022.02.16 08:12:51 [INFO] created ipfs client to /ip4/161.35.212.85/tcp/5001 -2022.02.16 08:12:51 [INFO] connected to ipfs -2022.02.16 08:12:53 [INFO] file uploaded -"Going to upload a module..." -2022.02.16 08:12:53 [INFO] created ipfs client to /ip4/161.35.212.85/tcp/5001 -2022.02.16 08:12:53 [INFO] connected to ipfs -2022.02.16 08:12:55 [INFO] file uploaded -"Now time to make a blueprint..." -"Blueprint id:" -"0c6b16c004adadb5b239f97029c050e1728258aea2c7c117c6c31e326cbd0fea" -"And your service id is:" -"e693d1c3-3fbc-4ccd-8eae-1ba9c767e2f5" \ No newline at end of file diff --git a/marine-examples/url-downloader/fluence-lock.yaml b/marine-examples/url-downloader/fluence-lock.yaml new file mode 100644 index 0000000..69232f2 --- /dev/null +++ b/marine-examples/url-downloader/fluence-lock.yaml @@ -0,0 +1,12 @@ +# yaml-language-server: $schema=.fluence/schemas/fluence-lock.yaml.json + +# Defines a lock file for Fluence Project dependencies. When dependencies are installed - their exact versions are saved here. + +# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/fluence-lock.md + +version: 0 +npm: + "@fluencelabs/aqua": 0.10.3 + "@fluencelabs/aqua-lib": 0.6.0 + "@fluencelabs/spell": 0.5.7 + "@fluencelabs/registry": 0.8.2 diff --git a/marine-examples/url-downloader/fluence.yaml b/marine-examples/url-downloader/fluence.yaml new file mode 100644 index 0000000..877e387 --- /dev/null +++ b/marine-examples/url-downloader/fluence.yaml @@ -0,0 +1,32 @@ +# yaml-language-server: $schema=.fluence/schemas/fluence.yaml.json + +# Defines Fluence Project, most importantly - what exactly you want to deploy and how. You can use `fluence init` command to generate a template for new Fluence project + +# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/fluence.md + +version: 2 +aquaInputPath: src/aqua/main.aqua +dependencies: + npm: + "@fluencelabs/aqua": 0.10.3 + "@fluencelabs/aqua-lib": 0.6.0 + "@fluencelabs/spell": 0.5.7 + "@fluencelabs/registry": 0.8.2 + cargo: + marine: 0.14.0 + mrepl: 0.21.2 +workers: + defaultWorker: + services: [ url_downloader ] +deals: + defaultWorker: + minWorkers: 1 + targetWorkers: 3 +hosts: + defaultWorker: + peerIds: + - 12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr +relays: kras +services: + url_downloader: + get: service diff --git a/marine-examples/url-downloader/old-air/compose.air b/marine-examples/url-downloader/old-air/compose.air deleted file mode 100644 index b568a53..0000000 --- a/marine-examples/url-downloader/old-air/compose.air +++ /dev/null @@ -1,13 +0,0 @@ -(xor - (seq - (seq - (seq - (call relay (curl "download") ["https://fluence.network/img/svg/logo_new.svg"] contents) - (call relay (storage "put") ["logo.svg" contents.$.stdout!] ret_code) - ) - (call relay (storage "get") ["logo.svg"] bytes) - ) - (call %init_peer_id% (returnService "run") [ret_code bytes]) - ) - (call %init_peer_id% (returnService "run") [%last_error%]) -) diff --git a/marine-examples/url-downloader/old-air/download.air b/marine-examples/url-downloader/old-air/download.air deleted file mode 100644 index d8a1334..0000000 --- a/marine-examples/url-downloader/old-air/download.air +++ /dev/null @@ -1,10 +0,0 @@ -(xor - (seq - (seq - (call relay (service "get_n_save") ["https://fluence.network/img/svg/logo_new.svg" "logo.svg"] ret_code) - (call relay (service "load_file") ["logo.svg"] bytes) - ) - (call %init_peer_id% (returnService "run") [ret_code bytes]) - ) - (call %init_peer_id% (returnService "run") [%last_error%]) -) diff --git a/marine-examples/url-downloader/package_modules.sh b/marine-examples/url-downloader/package_modules.sh deleted file mode 100755 index 0c76a13..0000000 --- a/marine-examples/url-downloader/package_modules.sh +++ /dev/null @@ -1,62 +0,0 @@ - -mkdir -p module-exports/modules/curl_adapter -mkdir -p module-exports/modules/facade -mkdir -p module-exports/modules/local_storage -sh ./build.sh - -cd module-exports -cp ../curl_adapter/target/wasm32-wasi/release/curl_adapter.wasm modules/curl_adapter/ -cp ../facade/target/wasm32-wasi/release/facade.wasm modules/facade/ -cp ../local_storage/target/wasm32-wasi/release/local_storage.wasm modules/local_storage/ - -file="service.yaml" -cat > $file <<- EOF -version: 0 -name: urlDownloader -modules: - facade: - get: modules/facade - localStorage: - get: modules/local_storage - curlAdapter: - get: modules/curl_adapter -EOF - - -file="modules/curl_adapter/module.yaml" -cat > $file <<- EOF -version: 0 -name: curl_adapter -loggerEnabled: true -mountedBinaries: - curl: /usr/bin/curl -EOF - -file="modules/local_storage/module.yaml" -cat > $file <<- EOF -version: 0 -name: local_storage -loggerEnabled: true -volumes: - sites: ./tmp -EOF - -file="modules/facade/module.yaml" -cat > $file <<- EOF -version: 0 -name: facade -loggerEnabled: true -EOF - - -tar -czf url_downloader.tar.gz modules service.yaml -rm -r modules -rm service.yaml - -cd ../facade -cargo clean -pwd -cd ../curl_adapter -cargo clean -cd ../local_storage -cargo clean diff --git a/marine-examples/url-downloader/repl_config.toml b/marine-examples/url-downloader/repl_config.toml deleted file mode 100644 index 6701450..0000000 --- a/marine-examples/url-downloader/repl_config.toml +++ /dev/null @@ -1,21 +0,0 @@ -modules_dir = "artifacts/" - -[[module]] -name = "local_storage" -logger_enabled = true - -[module.wasi] -preopened_files = ["."] -# this is where files will be stored -mapped_dirs = { "sites" = "." } - -[[module]] -name = "curl_adapter" -logger_enabled = true - -[module.mounted_binaries] -curl = "/usr/bin/curl" - -[[module]] -name = "facade" -logger_enabled = true diff --git a/marine-examples/url-downloader/curl_adapter/Cargo.toml b/marine-examples/url-downloader/service/modules/curl_adapter/Cargo.toml similarity index 80% rename from marine-examples/url-downloader/curl_adapter/Cargo.toml rename to marine-examples/url-downloader/service/modules/curl_adapter/Cargo.toml index 614a847..88c6f94 100644 --- a/marine-examples/url-downloader/curl_adapter/Cargo.toml +++ b/marine-examples/url-downloader/service/modules/curl_adapter/Cargo.toml @@ -1,14 +1,16 @@ [package] name = "curl_adapter" version = "0.1.0" -authors = ["Fluence Labs"] edition = "2018" -publish = false [[bin]] -path = "src/main.rs" name = "curl_adapter" +path = "src/main.rs" [dependencies] marine-rs-sdk = { version = "0.7.1", features = ["logger"] } log = "0.4.8" + + +[dev-dependencies] +marine-rs-sdk-test = "0.9.0" diff --git a/marine-examples/url-downloader/service/modules/curl_adapter/module.yaml b/marine-examples/url-downloader/service/modules/curl_adapter/module.yaml new file mode 100644 index 0000000..8808fb1 --- /dev/null +++ b/marine-examples/url-downloader/service/modules/curl_adapter/module.yaml @@ -0,0 +1,11 @@ +# yaml-language-server: $schema=../../../.fluence/schemas/module.yaml.json + +# Defines [Marine Module](https://fluence.dev/docs/build/concepts/#modules). You can use `fluence module new` command to generate a template for new module + +# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/module.md +version: 0 +type: rust +name: curl_adapter +loggerEnabled: true +mountedBinaries: + curl: /usr/bin/curl diff --git a/marine-examples/url-downloader/curl_adapter/src/main.rs b/marine-examples/url-downloader/service/modules/curl_adapter/src/main.rs similarity index 53% rename from marine-examples/url-downloader/curl_adapter/src/main.rs rename to marine-examples/url-downloader/service/modules/curl_adapter/src/main.rs index 8b279f7..db16079 100644 --- a/marine-examples/url-downloader/curl_adapter/src/main.rs +++ b/marine-examples/url-downloader/service/modules/curl_adapter/src/main.rs @@ -1,19 +1,3 @@ -/* - * Copyright 2021 Fluence Labs Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #![allow(improper_ctypes)] use marine_rs_sdk::marine; diff --git a/marine-examples/url-downloader/local_storage/Cargo.toml b/marine-examples/url-downloader/service/modules/local_storage/Cargo.toml similarity index 52% rename from marine-examples/url-downloader/local_storage/Cargo.toml rename to marine-examples/url-downloader/service/modules/local_storage/Cargo.toml index b8e4d22..686aa35 100644 --- a/marine-examples/url-downloader/local_storage/Cargo.toml +++ b/marine-examples/url-downloader/service/modules/local_storage/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "local_storage" version = "0.1.0" -authors = ["Fluence Labs"] edition = "2018" -publish = false [[bin]] name = "local_storage" path = "src/main.rs" [dependencies] -marine-rs-sdk = { version = "0.7.1", features = ["logger"] } -wasm-tracing-allocator = "0.1.1" +marine-rs-sdk = "0.7.1" log = "0.4.8" + +[dev-dependencies] +marine-rs-sdk-test = "0.9.0" diff --git a/marine-examples/url-downloader/service/modules/local_storage/module.yaml b/marine-examples/url-downloader/service/modules/local_storage/module.yaml new file mode 100644 index 0000000..a3dd8ab --- /dev/null +++ b/marine-examples/url-downloader/service/modules/local_storage/module.yaml @@ -0,0 +1,12 @@ +# yaml-language-server: $schema=../../../.fluence/schemas/module.yaml.json + +# Defines [Marine Module](https://fluence.dev/docs/build/concepts/#modules). You can use `fluence module new` command to generate a template for new module + +# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/module.md + +version: 0 +type: rust +name: local_storage +loggerEnabled: true +volumes: + sites: ./tmp diff --git a/marine-examples/url-downloader/local_storage/src/main.rs b/marine-examples/url-downloader/service/modules/local_storage/src/main.rs similarity index 64% rename from marine-examples/url-downloader/local_storage/src/main.rs rename to marine-examples/url-downloader/service/modules/local_storage/src/main.rs index 4ba7fde..5e5a1c4 100644 --- a/marine-examples/url-downloader/local_storage/src/main.rs +++ b/marine-examples/url-downloader/service/modules/local_storage/src/main.rs @@ -1,19 +1,3 @@ -/* - * Copyright 2021 Fluence Labs Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - use marine_rs_sdk::marine; use marine_rs_sdk::module_manifest; use marine_rs_sdk::WasmLoggerBuilder; @@ -51,4 +35,4 @@ pub fn get(file_name: String) -> Vec { let tmp_filepath = format!("{}{}", SITES_DIR, file_name); fs::read(tmp_filepath).unwrap_or_else(|_| b"error while reading file".to_vec()) -} +} \ No newline at end of file diff --git a/marine-examples/url-downloader/facade/Cargo.toml b/marine-examples/url-downloader/service/modules/url_downloader/Cargo.toml similarity index 60% rename from marine-examples/url-downloader/facade/Cargo.toml rename to marine-examples/url-downloader/service/modules/url_downloader/Cargo.toml index 123a336..b867ebe 100644 --- a/marine-examples/url-downloader/facade/Cargo.toml +++ b/marine-examples/url-downloader/service/modules/url_downloader/Cargo.toml @@ -1,15 +1,17 @@ [package] -name = "facade" +name = "url_downloader" version = "0.1.0" -authors = ["Fluence Labs"] edition = "2018" -publish = false [[bin]] -name = "facade" +name = "url_downloader" path = "src/main.rs" [dependencies] marine-rs-sdk = { version = "0.7.1", features = ["logger"] } anyhow = "1.0.31" -log = "0.4.8" \ No newline at end of file +log = "0.4.8" + + +[dev-dependencies] +marine-rs-sdk-test = "0.9.0" diff --git a/marine-examples/url-downloader/service/modules/url_downloader/module.yaml b/marine-examples/url-downloader/service/modules/url_downloader/module.yaml new file mode 100644 index 0000000..f871b49 --- /dev/null +++ b/marine-examples/url-downloader/service/modules/url_downloader/module.yaml @@ -0,0 +1,10 @@ +# yaml-language-server: $schema=../../../.fluence/schemas/module.yaml.json + +# Defines [Marine Module](https://fluence.dev/docs/build/concepts/#modules). You can use `fluence module new` command to generate a template for new module + +# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/module.md + +version: 0 +type: rust +name: url_downloader +loggerEnabled: true diff --git a/marine-examples/url-downloader/facade/src/main.rs b/marine-examples/url-downloader/service/modules/url_downloader/src/main.rs similarity index 62% rename from marine-examples/url-downloader/facade/src/main.rs rename to marine-examples/url-downloader/service/modules/url_downloader/src/main.rs index 548a92e..34dce14 100644 --- a/marine-examples/url-downloader/facade/src/main.rs +++ b/marine-examples/url-downloader/service/modules/url_downloader/src/main.rs @@ -1,18 +1,3 @@ -/* - * Copyright 2021 Fluence Labs Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ #![allow(improper_ctypes)] use marine_rs_sdk::marine; @@ -37,6 +22,16 @@ pub fn get_n_save(url: String, file_name: String) -> String { String::from("Ok") } +#[marine] +pub fn put(file_name: String, file_content: Vec) -> String { + file_put(file_name, file_content) +} + +#[marine] +pub fn get(file_name: String) -> Vec { + file_get(file_name) +} + /// Importing `curl` module #[marine] #[link(wasm_import_module = "curl_adapter")] @@ -53,4 +48,4 @@ extern "C" { #[link_name = "put"] pub fn file_put(name: String, file_content: Vec) -> String; -} +} \ No newline at end of file diff --git a/marine-examples/url-downloader/service/service.yaml b/marine-examples/url-downloader/service/service.yaml new file mode 100644 index 0000000..dd3caff --- /dev/null +++ b/marine-examples/url-downloader/service/service.yaml @@ -0,0 +1,15 @@ +# yaml-language-server: $schema=../.fluence/schemas/service.yaml.json + +# Defines a [Marine service](https://fluence.dev/docs/build/concepts/#services), most importantly the modules that the service consists of. You can use `fluence service new` command to generate a template for new service + +# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/service.md + +version: 0 +name: url_downloader +modules: + facade: + get: modules/url_downloader + local_storage: + get: modules/local_storage + curl_adapter: + get: modules/curl_adapter diff --git a/marine-examples/url-downloader/src/aqua/main.aqua b/marine-examples/url-downloader/src/aqua/main.aqua new file mode 100644 index 0000000..4a5551d --- /dev/null +++ b/marine-examples/url-downloader/src/aqua/main.aqua @@ -0,0 +1,52 @@ +import "workers.aqua" +import "services.aqua" +import "@fluencelabs/aqua-lib/builtin.aqua" +import "@fluencelabs/registry/subnetwork.aqua" +import Registry, Record from "@fluencelabs/registry/registry-service.aqua" +import "@fluencelabs/spell/spell_service.aqua" + +export get_and_save, put, put_all, get, worker_n + + +func getWorkers() -> []Record: + workersInfo <- getWorkersInfo() + dealId = workersInfo.deals.defaultWorker.dealId + on HOST_PEER_ID: + workersOp <- resolveSubnetwork(dealId) + <- workersOp! + +func worker_n() -> u32: + workers <- getWorkers() + <- workers.length + +func get_and_save(url: string, fname: string) -> string: + workers <- getWorkers() + w = workers[8] + on w.metadata.peer_id via w.metadata.relay_id: + res = UrlDownloader.get_n_save(url, fname) + <- res + +func put_all(file_name: string, file_content: []u8) -> []string: + res: *string + workers <- getWorkers() + for w <- workers: + on w.metadata.peer_id via w.metadata.relay_id: + try: + res <- UrlDownloader.put(file_name, file_content) + catch e: + res <<- "failed to execute" + <- res + +func put(file_name: string, file_content: []u8) -> string: + workers <- getWorkers() + w = workers[1] + on w.metadata.peer_id via w.metadata.relay_id: + res <- UrlDownloader.put(file_name, file_content) + <- res + +func get(file_name: string) -> []u8: + workers <- getWorkers() + w = workers[5] + on w.metadata.peer_id via w.metadata.relay_id: + res <- UrlDownloader.get(file_name) + <- res \ No newline at end of file diff --git a/marine-examples/url-downloader/src/package.json b/marine-examples/url-downloader/src/package.json new file mode 100644 index 0000000..8d9919b --- /dev/null +++ b/marine-examples/url-downloader/src/package.json @@ -0,0 +1,19 @@ +{ + "name": "@fluencelabs/url-downloader", + "version": "0.0.1", + "description": "", + "main": "src/index.js", + "type": "module", + "scripts": { + "compile": "fluence aqua -i aqua/ -o aqua-compiled/ --js" + }, + "bin": {}, + "files": [ + "src/*", + "aqua/*", + "aqua-compiled/*" + ], + "author": "Fluence Labs", + "license": "Apache-2.0", + "dependencies": {} +}