-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from karthik2804/add_redis_templates
- Loading branch information
Showing
21 changed files
with
280 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
dist | ||
target | ||
.spin/ | ||
dist.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"version": 1, | ||
"project": { | ||
"worlds": [ | ||
"spin-redis" | ||
] | ||
}, | ||
"packages": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[application.trigger.redis] | ||
address = "{{redis-address}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
dist | ||
target | ||
.spin/ | ||
dist.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"version": 1, | ||
"project": { | ||
"worlds": [ | ||
"spin-redis" | ||
] | ||
}, | ||
"packages": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[application.trigger.redis] | ||
address = "{{redis-address}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } |