Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
65eaba5
added tutorial introduction and incomplete project setup (both untested)
krisbitney Oct 23, 2023
6651568
added create wraps tutorial - project setup
krisbitney Oct 24, 2023
84590f1
updated project setup to be multi-language
krisbitney Oct 25, 2023
0cf7167
updated project manifest section of new create wraps tutorial
krisbitney Oct 25, 2023
7937e02
lots of progress in schema-and-codegen.md
krisbitney Oct 25, 2023
3d7dfb2
finished draft of schema-and-codegen.md
krisbitney Oct 26, 2023
2e578a5
improved page transitions in new create wraps tutorial
krisbitney Oct 26, 2023
f235988
improved page transitions by adding "next steps" sections to new crea…
krisbitney Oct 26, 2023
8440c33
added "first method" section
krisbitney Oct 27, 2023
6ab448a
completed import-and-subinvoke section of new create wraps tutorial
krisbitney Oct 30, 2023
18b4361
fixed navigation in import-and-subinvoke section of new create wraps …
krisbitney Oct 30, 2023
b19c48b
partially completed interfaces-and-plugins.mdx
krisbitney Oct 30, 2023
a79d4d4
added to interfaces-and-plugins.mdx
krisbitney Oct 30, 2023
ad033e5
finished interfaces-and-plugins.mdx page of new create wraps tutorial
krisbitney Oct 31, 2023
81e8e24
finished integration-testing.mdx page of new create wraps tutorial
krisbitney Oct 31, 2023
ac9b6b9
added deployment page of new create wraps tutorial
krisbitney Oct 31, 2023
44d50d2
fixed typos
krisbitney Oct 31, 2023
d685bad
removed build manifest from tutorial wraps
krisbitney Oct 31, 2023
9eae6ed
removed old create wraps tutorial
krisbitney Oct 31, 2023
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"npm-run-all": "^4.1.5",
"onchange": "^7.1.0",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
"typescript": "^4.7.4",
"polywrap": "0.12.1"
},
"browserslist": {
"production": [
Expand Down
28 changes: 19 additions & 9 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,30 @@ const sidebars = {
type: 'category',
label: 'Create Wraps',
items: [
'tutorials/create-wraps/introduction',
{
type: 'category',
label: 'Tutorial',
label: 'Part One',
items: [
'tutorials/create-wraps/tutorial/project-setup',
'tutorials/create-wraps/tutorial/project-folder',
'tutorials/create-wraps/tutorial/build-deploy-test',
'tutorials/create-wraps/tutorial/adding-new-methods',
'tutorials/create-wraps/tutorial/writing-tests-with-workflows',
'tutorials/create-wraps/tutorial/deploy-locally-and-test',
'tutorials/create-wraps/part-one/project-setup',
'tutorials/create-wraps/part-one/project-manifest',
'tutorials/create-wraps/part-one/schema-and-codegen',
'tutorials/create-wraps/part-one/first-method',
'tutorials/create-wraps/part-one/import-and-subinvoke',
'tutorials/create-wraps/part-one/interfaces-and-plugins',
'tutorials/create-wraps/part-one/integration-testing',
'tutorials/create-wraps/part-one/deployment'
]
},
'tutorials/create-wraps/polywrap-manifest',
'tutorials/create-wraps/default-plugins'
{
type: 'category',
label: 'Part Two',
items: [
'tutorials/create-wraps/part-two/polywrap-manifest',
'tutorials/create-wraps/part-two/default-plugins',
'tutorials/create-wraps/part-two/writing-tests-with-workflows'
]
}
],
},
{
Expand Down
5 changes: 5 additions & 0 deletions snippets/create-wraps-tutorial/assemblyscript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
node_modules
wrap
.polywrap
workflows/output.json
1 change: 1 addition & 0 deletions snippets/create-wraps-tutorial/assemblyscript/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.15.0
16 changes: 16 additions & 0 deletions snippets/create-wraps-tutorial/assemblyscript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Polywrap Wasm Wrapper Template
A simple starter template for an AssemblyScript Wasm wrapper. For more information on how this project works, and a step by step on how to extend its behavior, see the documentation [here](https://docs.polywrap.io/).

# How To Run

## Install Dependencies
`nvm install && nvm use`
`yarn`

## Codegen & Build
`yarn codegen`
`yarn build`

## Test
`yarn test:e2e`
`yarn test:workflow`
15 changes: 15 additions & 0 deletions snippets/create-wraps-tutorial/assemblyscript/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
collectCoverage: false,
preset: "ts-jest",
testEnvironment: "node",
testMatch: ["**/__tests__/**/?(*.)+(spec|test).[jt]s?(x)"],
globals: {
"ts-jest": {
tsconfig: "tsconfig.json",
diagnostics: false,
},
},
testPathIgnorePatterns: [
"/.polywrap/"
],
};
28 changes: 28 additions & 0 deletions snippets/create-wraps-tutorial/assemblyscript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "template-wasm-as",
"description": "Polywrap AssemblyScript Wrapper Template",
"private": true,
"version": "0.12.1",
"scripts": {
"codegen": "npx polywrap codegen",
"build": "npx polywrap build",
"test:env:up": "npx polywrap infra up --modules=eth-ens-ipfs",
"test:env:down": "npx polywrap infra down --modules=eth-ens-ipfs",
"deploy": "npx polywrap deploy",
"test": "yarn test:e2e && yarn test:workflow",
"test:e2e": "yarn test:e2e:codegen && jest --passWithNoTests --runInBand --verbose",
"test:e2e:codegen": "npx polywrap codegen -m ./src/__tests__/types/polywrap.app.yaml -g ./src/__tests__/types/wrap",
"test:workflow": "npx polywrap test -o ./workflows/output.json"
},
"devDependencies": {
"@types/jest": "26.0.8",
"jest": "26.6.3",
"polywrap": "0.12.1",
"ts-jest": "26.5.4",
"typescript": "4.9.5"
},
"dependencies": {
"@polywrap/wasm-as": "0.12.1",
"assemblyscript": "0.19.23"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
format: "0.1"
stages:
ipfs_deploy:
package: ipfs
uri: fs/./build
config:
gatewayUri: "https://ipfs.wrappers.io"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
format: 0.1.0
readme: ./README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import { Module } into Sha3 from "wrapscan.io/polywrap/sha3@1.0.0"
#import { Module } into Http from "wrapscan.io/polywrap/http@1.0"

type Module {
obscure(data: [String!]!, chaosLevel: Int): String!
enlighten(question: String!, apiKey: String!): String!
}
10 changes: 10 additions & 0 deletions snippets/create-wraps-tutorial/assemblyscript/polywrap.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: template-wasm-rs
format: 0.1.0
validation: "./workflows/validator.cue"
jobs:
sampleMethod:
steps:
- uri: fs/build
method: sampleMethod
args:
arg: "polywrap"
9 changes: 9 additions & 0 deletions snippets/create-wraps-tutorial/assemblyscript/polywrap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
format: 0.3.0
project:
name: template-wasm-as
type: wasm/assemblyscript
source:
module: ./src/index.ts
schema: ./polywrap.graphql
extensions:
docs: ./polywrap.docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as App from "../types/wrap";
import path from "path";

jest.setTimeout(60000);

describe("Oracle Wrap End to End Tests", () => {

let oracle: App.Oracle;
let wrapperUri: string;
let apiKey: string = process.env.PPLX_API_KEY || "";

beforeAll(() => {
const wrapperPath: string = path.join(__dirname, "..", "..", "..");
wrapperUri = `fs/${wrapperPath}/build`;
oracle = new App.Oracle(undefined, undefined, wrapperUri)
})

it("calls obscure", async () => {
const result = await oracle.obscure({
data: ["Hello", "World"],
chaosLevel: 3
});

if (!result.ok) throw result.error;
expect(typeof result.value === "string").toBeTruthy();
expect(result.value.length).toEqual(128);
});

it("calls enlighten", async () => {
const question = "What is the meaning of life?";
const result = await oracle.enlighten({ question, apiKey });

if (!result.ok) throw result.error;
expect(typeof result.value === "string").toBeTruthy();
});
});

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
format: 0.3.0
project:
name: sample-typescript-type-generation
type: app/typescript
source:
schema: ./schema.graphql
import_abis:
- uri: "wrap://ens/sample.eth"
abi: "../../../build/wrap.info"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#import * into Oracle from "wrap://ens/sample.eth"
71 changes: 71 additions & 0 deletions snippets/create-wraps-tutorial/assemblyscript/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {
Args_enlighten,
Args_obscure,
Http_Module,
Http_Request,
Http_Response,
Http_ResponseType,
ModuleBase,
Sha3_Module
} from './wrap';

export class Module extends ModuleBase {
obscure(args: Args_obscure): string {
// handle default values
const chaosLevel: i32 = (args.chaosLevel == null || args.chaosLevel!!.unwrap() < 1)
? 1
: args.chaosLevel!!.unwrap();

let obscured: string = "";
for (let i = 0; i < args.data.length; ++i) {
let data = args.data[i];
for (let j = 0; j < chaosLevel; ++j) {
data = Sha3_Module.keccak_256({ message: data }).expect("hash failed");
}
obscured += data;
}
return obscured;
}

enlighten(args: Args_enlighten): string {
const request: Http_Request = {
headers: new Map<string, string>()
.set('accept', 'application/json')
.set('content-type', 'application/json')
.set("Authorization", `Bearer ${args.apiKey}`),
responseType: Http_ResponseType.TEXT,
body: `{
"model": "mistral-7b-instruct",
"messages": [
{
"role": "system",
"content": "Be precise and concise."
},
{
"role": "user",
"content": "${args.question}"
}
]
}`
};

const response: Http_Response | null = Http_Module.post({
url: "https://api.perplexity.ai/chat/completions",
request,
}).unwrap();

if (response == null) {
throw new Error("request failed with null response");
}

if (response.status != 200) {
throw new Error(`request failed with status ${response.status}`);
}

if (response.body == null) {
throw new Error("request failed with null body");
}

return response.body!!;
}
}
12 changes: 12 additions & 0 deletions snippets/create-wraps-tutorial/assemblyscript/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "assemblyscript/std/assembly.json",
"compilerOptions": {
"outDir": "build"
},
"include": [
"./src/**/*.ts",
],
"exclude": [
"./src/__tests__/e2e/**/*.ts"
]
}
28 changes: 28 additions & 0 deletions snippets/create-wraps-tutorial/assemblyscript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"lib": [
"es2020",
"es2015",
"es5",
"dom"
],
"esModuleInterop": true,
"outDir": "build",
"moduleResolution": "node",
"declaration": true,
"preserveSymlinks": true,
"preserveWatchOutput": true,
"pretty": false,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"module": "commonjs",
"sourceMap": true,
"target": "es5",
"resolveJsonModule": true,
"strictNullChecks": true
},
"typeAcquisition": { "include": ["jest"] },
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package e2e

sampleMethod: {
$0: {
data: {
value: "polywrap"
},
error?: _|_,
}
}

Loading