Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add templates for redis #286

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/http-js/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"@fermyon/knitwit": "https://github.com/fermyon/knitwit"
},
"dependencies": {
"@fermyon/spin-sdk": "^2.0.0"
"@fermyon/spin-sdk": "^2.1.0"
}
}
2 changes: 1 addition & 1 deletion templates/http-ts/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"@fermyon/knitwit": "https://github.com/fermyon/knitwit"
},
"dependencies": {
"@fermyon/spin-sdk": "^2.0.0"
"@fermyon/spin-sdk": "^2.1.0"
}
}
5 changes: 5 additions & 0 deletions templates/redis-js/content/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
target
.spin/
dist.js
9 changes: 9 additions & 0 deletions templates/redis-js/content/knitwit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 1,
"project": {
"worlds": [
"spin-redis"
]
},
"packages": {}
}
23 changes: 23 additions & 0 deletions templates/redis-js/content/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "{{project-name | kebab_case}}",
"version": "1.0.0",
"description": "{{project-description}}",
"main": "index.js",
"scripts": {
"build": "npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -d combined-wit -n combined -o target/{{project-name | kebab_case}}.wasm",
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "knitwit"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"mkdirp": "^3.0.1",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"@fermyon/knitwit": "https://github.com/fermyon/knitwit"
},
"dependencies": {
"@fermyon/spin-sdk": "^2.1.0"
}
}
21 changes: 21 additions & 0 deletions templates/redis-js/content/spin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
spin_manifest_version = 2

[application]
name = "{{project-name | kebab_case}}"
version = "0.1.0"
authors = ["{{authors}}"]
description = "{{project-description}}"

[application.trigger.redis]
address = "{{redis-address}}"

[[trigger.redis]]
channel = "{{redis-channel}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "target/{{project-name | kebab_case}}.wasm"
exclude_files = ["**/node_modules"]
[component.{{project-name | kebab_case}}.build]
command = "npm run build"
watch = ["src/**/*.ts", "package.json"]
11 changes: 11 additions & 0 deletions templates/redis-js/content/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { RedisHandler } from "@fermyon/spin-sdk";

const decoder = new TextDecoder();

export class MyRedisHandler extends RedisHandler {
async handleMessage(msg) {
console.log("Received message:", decoder.decode(msg));
}
}

export const inboundRedis = new MyRedisHandler();
23 changes: 23 additions & 0 deletions templates/redis-js/content/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const path = require('path');
const SpinSdkPlugin = require("@fermyon/spin-sdk/plugins/webpack")

module.exports = {
entry: './src/index.js',
experiments: {
outputModule: true,
},
output: {
path: path.resolve(__dirname, './'),
filename: 'dist.js',
module: true,
library: {
type: "module",
}
},
plugins: [
new SpinSdkPlugin()
],
optimization: {
minimize: false
},
};
2 changes: 2 additions & 0 deletions templates/redis-js/metadata/snippets/application-trigger.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[application.trigger.redis]
address = "{{redis-address}}"
10 changes: 10 additions & 0 deletions templates/redis-js/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[[trigger.redis]]
channel = "{{redis-channel}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "{{ output-path }}/target/{{project-name | kebab_case}}.wasm"
allowed_outbound_hosts = []
[component.{{project-name | kebab_case}}.build]
command = "npm run build"
workdir = "{{ output-path }}"
19 changes: 19 additions & 0 deletions templates/redis-js/metadata/spin-template.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
manifest_version = "1"
id = "redis-js"
description = "Redis message handler using JavaScript"
tags = ["redis", "js"]

[add_component]
skip_files = ["spin.toml"]
[add_component.snippets]
component = "component.txt"
application_trigger = "application-trigger.txt"
[add_component.conditions.address_exists]
condition = { manifest_entry_exists = "application.trigger.redis" }
skip_parameters = ["redis-address"]
skip_snippets = ["application_trigger"]

[parameters]
project-description = { type = "string", prompt = "Description", default = "" }
redis-address = { type = "string", prompt = "Redis address", default = "redis://localhost:6379" }
redis-channel = { type = "string", prompt = "Redis channel" }
5 changes: 5 additions & 0 deletions templates/redis-ts/content/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
target
.spin/
dist.js
9 changes: 9 additions & 0 deletions templates/redis-ts/content/knitwit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 1,
"project": {
"worlds": [
"spin-redis"
]
},
"packages": {}
}
25 changes: 25 additions & 0 deletions templates/redis-ts/content/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "{{project-name | kebab_case}}",
"version": "1.0.0",
"description": "{{project-description}}",
"main": "index.js",
"scripts": {
"build": "npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -d combined-wit -n combined -o target/{{project-name | kebab_case}}.wasm",
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "knitwit"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"mkdirp": "^3.0.1",
"ts-loader": "^9.4.1",
"typescript": "^4.8.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"@fermyon/knitwit": "https://github.com/fermyon/knitwit"
},
"dependencies": {
"@fermyon/spin-sdk": "^2.1.0"
}
}
21 changes: 21 additions & 0 deletions templates/redis-ts/content/spin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
spin_manifest_version = 2

[application]
name = "{{project-name | kebab_case}}"
version = "0.1.0"
authors = ["{{authors}}"]
description = "{{project-description}}"

[application.trigger.redis]
address = "{{redis-address}}"

[[trigger.redis]]
channel = "{{redis-channel}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "target/{{project-name | kebab_case}}.wasm"
exclude_files = ["**/node_modules"]
[component.{{project-name | kebab_case}}.build]
command = "npm run build"
watch = ["src/**/*.ts", "package.json"]
11 changes: 11 additions & 0 deletions templates/redis-ts/content/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { RedisHandler } from "@fermyon/spin-sdk";

const decoder = new TextDecoder();

export class MyRedisHandler extends RedisHandler {
async handleMessage(msg: Uint8Array): Promise<void> {
console.log("Received message:", decoder.decode(msg));
}
}

export const inboundRedis = new MyRedisHandler()
18 changes: 18 additions & 0 deletions templates/redis-ts/content/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "es6",
"target": "es2020",
"jsx": "react",
"skipLibCheck": true,
"lib": [
"ES2015",
"WebWorker"
],
"allowJs": true,
"strict": true,
"noImplicitReturns": true,
"moduleResolution": "node"
}
}
35 changes: 35 additions & 0 deletions templates/redis-ts/content/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const path = require('path');
const SpinSdkPlugin = require("@fermyon/spin-sdk/plugins/webpack")

module.exports = {
entry: './src/index.ts',
experiments: {
outputModule: true,
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
path: path.resolve(__dirname, './'),
filename: 'dist.js',
module: true,
library: {
type: "module",
}
},
plugins: [
new SpinSdkPlugin()
],
optimization: {
minimize: false
},
};
2 changes: 2 additions & 0 deletions templates/redis-ts/metadata/snippets/application-trigger.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[application.trigger.redis]
address = "{{redis-address}}"
10 changes: 10 additions & 0 deletions templates/redis-ts/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[[trigger.redis]]
channel = "{{redis-channel}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "{{ output-path }}/target/{{project-name | kebab_case}}.wasm"
allowed_outbound_hosts = []
[component.{{project-name | kebab_case}}.build]
command = "npm run build"
workdir = "{{ output-path }}"
19 changes: 19 additions & 0 deletions templates/redis-ts/metadata/spin-template.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
manifest_version = "1"
id = "redis-ts"
description = "Redis message handler using TypeScript"
tags = ["redis", "ts"]

[add_component]
skip_files = ["spin.toml"]
[add_component.snippets]
component = "component.txt"
application_trigger = "application-trigger.txt"
[add_component.conditions.address_exists]
condition = { manifest_entry_exists = "application.trigger.redis" }
skip_parameters = ["redis-address"]
skip_snippets = ["application_trigger"]

[parameters]
project-description = { type = "string", prompt = "Description", default = "" }
redis-address = { type = "string", prompt = "Redis address", default = "redis://localhost:6379" }
redis-channel = { type = "string", prompt = "Redis channel" }
Loading