Skip to content

Commit

Permalink
Merge pull request #1 from dylibso/fixes
Browse files Browse the repository at this point in the history
Some minor fixes to the template, porting over old changes
  • Loading branch information
mhmd-azeez authored Jul 11, 2024
2 parents 334cd1a + b9f484b commit 88d6a56
Show file tree
Hide file tree
Showing 26 changed files with 465 additions and 8,838 deletions.
258 changes: 146 additions & 112 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,127 +47,161 @@ func CopyFile(src, dst string) error {
func main() {
schemaCtx := `
{
"project": {"name": "hello", "description": "a new plugin that does something", "appId": "app_1234", "extensionPointId": "ext_1234" },
"schema": {
"exports": [
{
"name": "voidFunc",
"description": "This demonstrates how you can create an export with\nno inputs or outputs.\n",
"input": { "name": "" },
"output": { "name": "" }
"project": {"name": "hello", "description": "a new plugin that does something", "appId": "app_1234", "extensionPointId": "ext_1234" },
"schema": {
"exports": [
{
"name": "voidFunc",
"description": "This demonstrates how you can create an export with\nno inputs or outputs.\n"
},
{
"name": "primitiveTypeFunc",
"input": {
"type": "string",
"contentType": "text/plain; charset=UTF-8",
"description": "A string passed into plugin input"
},
{
"name": "primitiveTypeFunc",
"input": {
"output": {
"type": "boolean",
"contentType": "application/json",
"description": "A boolean encoded as json"
},
"codeSamples": [
{
"lang": "typescript",
"label": "Test if a string has more than one character.\nCode samples show up in documentation and inline in docstrings\n",
"source": "function primitiveTypeFunc(input: string): boolean {\n return input.length > 1\n}\n"
}
],
"description": "This demonstrates how you can accept or return primtive types.\nThis function takes a utf8 string and returns a json encoded boolean\n"
},
{
"name": "referenceTypeFunc",
"input": {
"$ref": "#/schemas/Fruit"
},
"output": {
"$ref": "#/schemas/ComplexObject"
},
"description": "This demonstrates how you can accept or return references to schema types.\nAnd it shows how you can define an enum to be used as a property or input/output.\n"
}
],
"imports": [
{
"name": "eatAFruit",
"input": {
"$ref": "#/schemas/Fruit"
},
"output": {
"type": "boolean",
"contentType": "application/json",
"description": "boolean encoded as json"
},
"description": "This is a host function. Right now host functions can only be the type (i64) -> i64.\nWe will support more in the future. Much of the same rules as exports apply.\n"
},
{
"name": "kv_read",
"input": {
"type": "string",
"contentType": "text/plain; charset=UTF-8",
"description": "the key"
},
"output": {
"type": "buffer",
"description": "the raw byte values at key"
},
"description": "kvread"
},
{
"name": "kv_write",
"input": {
"$ref": "#/schemas/WriteParams"
},
"description": "kvwrite"
}
],
"schemas": [
{
"name": "WriteParams",
"properties": [
{
"name": "key",
"type": "string",
"contentType": "text/plain; charset=UTF-8",
"description": "A string passed into plugin input"
"description": "key"
},
"output": {
"type": "boolean",
"contentType": "application/json",
"description": "A boolean encoded as json"
},
"codeSamples": [
{
"lang": "typescript",
"label": "Test if a string has more than one character.\nCode samples show up in documentation and inline in docstrings\n",
"source": "function primitiveTpeFunc(input: string): boolean {\n return input.length > 1\n}\n"
}
],
"description": "This demonstrates how you can accept or return primtive types.\nThis function takes a utf8 string and returns a json encoded boolean\n"
},
{
"name": "referenceTypeFunc",
"input": {
"$ref": "#/schemas/Fruit"
{
"name": "value",
"type": "buffer",
"description": "value"
}
],
"contentType": "application/json",
"description": "Parameters to write to kv store"
},
{
"enum": [
"apple",
"orange",
"banana",
"strawberry"
],
"name": "Fruit",
"description": "A set of available fruits you can consume"
},
{
"enum": [
"blinky",
"pinky",
"inky",
"clyde"
],
"name": "GhostGang",
"description": "A set of all the enemies of pac-man"
},
{
"name": "ComplexObject",
"required": [
"ghost",
"aBoolean",
"aString",
"anInt"
],
"properties": [
{
"$ref": "#/schemas/GhostGang",
"name": "ghost",
"description": "I can override the description for the property here"
},
"output": {
"$ref": "#/schemas/ComplexObject"
{
"name": "aBoolean",
"type": "boolean",
"description": "A boolean prop"
},
"description": "This demonstrates how you can accept or return references to schema types.\nAnd it shows how you can define an enum to be used as a property or input/output.\n"
}
],
"imports": [
{
"name": "eatAFruit",
"input": {
"$ref": "#/schemas/Fruit"
{
"name": "aString",
"type": "string",
"description": "An string prop"
},
"output": {
"type": "boolean",
"contentType": "application/json",
"description": "boolean encoded as json"
{
"name": "anInt",
"type": "integer",
"format": "int32",
"description": "An int prop"
},
"description": "This is a host function. Right now host functions can only be the type (i64) -> i64.\nWe will support more in the future. Much of the same rules as exports apply.\n"
}
],
"schemas": [
{
"enum": [
"apple",
"orange",
"banana",
"strawberry"
],
"name": "Fruit",
"description": "A set of available fruits you can consume"
},
{
"enum": [
"blinky",
"pinky",
"inky",
"clyde"
],
"name": "GhostGang",
"description": "A set of all the enemies of pac-man"
},
{
"name": "ComplexObject",
"required": [
"ghost",
"aBoolean",
"aString",
"anInt"
],
"properties": [
{
"$ref": "#/schemas/GhostGang",
"name": "ghost",
"description": "I can override the description for the property here"
},
{
"name": "aBoolean",
"type": "boolean",
"description": "A boolean prop"
},
{
"name": "aString",
"type": "integer",
"format": "int32",
"description": "An int prop"
},
{
"name": "anInt",
"type": "integer",
"format": "int32",
"description": "An int prop"
},
{
"name": "anOptionalDate",
"type": "string",
"format": "date-time",
"description": "A datetime object, we will automatically serialize and deserialize\nthis for you.\n"
}
],
"contentType": "application/json",
"description": "A complex json object"
}
],
"version": "v1-draft"
{
"name": "anOptionalDate",
"type": "string",
"format": "date-time",
"description": "A datetime object, we will automatically serialize and deserialize\nthis for you.\n"
}
],
"contentType": "application/json",
"description": "A complex json object"
}
],
"version": "v1-draft"
}
}
`

manifest := extism.Manifest{
Expand Down
8 changes: 4 additions & 4 deletions output/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions output/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"description": "a new plugin that does something",
"main": "src/index.ts",
"scripts": {
"build": "tsc --noEmit && node esbuild.js && extism-js dist/index.js -i src/index.d.ts -o dist/plugin.wasm",
"format": "prettier --write \"src/**/*.{ts,tsx}\""
"build": "npx tsc --noEmit && node esbuild.js && extism-js dist/index.js -i src/index.d.ts -o dist/plugin.wasm",
"format": "npx prettier --write \"src/**/*.{ts,tsx}\""
},
"keywords": [],
"author": "",
"license": "BSD-3-Clause",
"private": true,
"license": "UNLICENSED",
"devDependencies": {
"@extism/js-pdk": "^1.0.1",
"esbuild": "^0.19.6",
Expand Down
10 changes: 9 additions & 1 deletion output/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
declare module 'main' {
declare module "main" {
export function voidFunc(): I32;
export function primitiveTypeFunc(): I32;
export function referenceTypeFunc(): I32;
}

declare module "extism:host" {
interface user {
eatAFruit(ptr: I64): I64;
kv_read(ptr: I64): I64;
kv_write(ptr: I64): I64;
}
}
43 changes: 17 additions & 26 deletions output/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
import * as main from "./main"

import {
Fruit,
GhostGang,
ComplexObject,
} from './pdk'
import * as main from "./main";

import { WriteParams, Fruit, GhostGang, ComplexObject } from "./pdk";

export function voidFunc(): number {
main.voidFuncImpl()


return 0
main.voidFuncImpl();

return 0;
}

export function primitiveTypeFunc(): number {
const input = Host.inputString()
const output = main.primitiveTypeFuncImpl(input)
Host.outputString(JSON.stringify(output))
return 0
const input = Host.inputString();

const output = main.primitiveTypeFuncImpl(input);

Host.outputString(JSON.stringify(output));

return 0;
}

export function referenceTypeFunc(): number {
const input = Host.inputString() as Fruit

const output = main.referenceTypeFuncImpl(input)

Host.outputString(JSON.stringify(output))

return 0
}
const input = Host.inputString() as Fruit;

const output = main.referenceTypeFuncImpl(input);

Host.outputString(JSON.stringify(output));

return 0;
}
Loading

0 comments on commit 88d6a56

Please sign in to comment.