@zlayer/sdk 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "root": true,
3
+ "env": {
4
+ "node": true,
5
+ "es2022": true
6
+ },
7
+ "parser": "@typescript-eslint/parser",
8
+ "parserOptions": {
9
+ "ecmaVersion": "latest",
10
+ "sourceType": "module",
11
+ "project": "./tsconfig.json"
12
+ },
13
+ "plugins": ["@typescript-eslint"],
14
+ "extends": [
15
+ "eslint:recommended",
16
+ "plugin:@typescript-eslint/recommended",
17
+ "plugin:@typescript-eslint/recommended-requiring-type-checking"
18
+ ],
19
+ "rules": {
20
+ "@typescript-eslint/explicit-function-return-type": "warn",
21
+ "@typescript-eslint/no-unused-vars": [
22
+ "error",
23
+ {
24
+ "argsIgnorePattern": "^_",
25
+ "varsIgnorePattern": "^_"
26
+ }
27
+ ],
28
+ "@typescript-eslint/no-explicit-any": "error",
29
+ "@typescript-eslint/strict-boolean-expressions": "warn",
30
+ "no-console": "warn",
31
+ "prefer-const": "error",
32
+ "eqeqeq": ["error", "always"]
33
+ },
34
+ "ignorePatterns": ["dist/", "node_modules/", "src/bindings/"]
35
+ }
package/.prettierrc ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true,
4
+ "tabWidth": 2,
5
+ "trailingComma": "es5",
6
+ "printWidth": 100,
7
+ "bracketSpacing": true,
8
+ "arrowParens": "always",
9
+ "endOfLine": "lf"
10
+ }
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # ZLayer TypeScript SDK
2
+
3
+ The ZLayer Plugin Development Kit (PDK) for TypeScript enables you to build WebAssembly plugins that run in the ZLayer runtime.
4
+
5
+ ## Requirements
6
+
7
+ - Node.js 20.0.0 or later
8
+ - npm or pnpm
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @zlayer/sdk
14
+ ```
15
+
16
+ Or with pnpm:
17
+
18
+ ```bash
19
+ pnpm add @zlayer/sdk
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ 1. **Initialize a new plugin project:**
25
+
26
+ ```bash
27
+ mkdir my-plugin && cd my-plugin
28
+ npm init -y
29
+ npm install @zlayer/sdk
30
+ ```
31
+
32
+ 2. **Create your plugin entry point:**
33
+
34
+ ```typescript
35
+ // src/index.ts
36
+ import { VERSION } from '@zlayer/sdk';
37
+
38
+ console.log(`Using ZLayer SDK v${VERSION}`);
39
+
40
+ // Your plugin implementation here
41
+ ```
42
+
43
+ 3. **Build to WebAssembly:**
44
+
45
+ ```bash
46
+ npm run build
47
+ ```
48
+
49
+ ## Project Structure
50
+
51
+ ```
52
+ my-plugin/
53
+ ├── src/
54
+ │ └── index.ts # Plugin entry point
55
+ ├── dist/ # Compiled JavaScript output
56
+ ├── package.json
57
+ └── tsconfig.json
58
+ ```
59
+
60
+ ## Generating WIT Bindings
61
+
62
+ The SDK uses [jco](https://github.com/bytecodealliance/jco) to generate TypeScript bindings from WIT (WebAssembly Interface Types) definitions.
63
+
64
+ To regenerate bindings from the ZLayer WIT definitions:
65
+
66
+ ```bash
67
+ npm run generate
68
+ ```
69
+
70
+ This will read the WIT files from `../wit/zlayer` and output TypeScript bindings to `src/bindings/`.
71
+
72
+ ## Available Scripts
73
+
74
+ | Script | Description |
75
+ |--------|-------------|
76
+ | `npm run build` | Compile TypeScript to JavaScript |
77
+ | `npm run generate` | Generate WIT bindings using jco |
78
+ | `npm run clean` | Remove the dist directory |
79
+ | `npm run test` | Run tests with Vitest |
80
+ | `npm run lint` | Lint source files with ESLint |
81
+ | `npm run format` | Format source files with Prettier |
82
+
83
+ ## Configuration
84
+
85
+ ### TypeScript
86
+
87
+ The SDK is configured for ES2022 with NodeNext module resolution. See `tsconfig.json` for full configuration.
88
+
89
+ ### ESLint
90
+
91
+ ESLint is configured with TypeScript support. See `.eslintrc.json` for rules.
92
+
93
+ ### Prettier
94
+
95
+ Prettier is configured for consistent code formatting. See `.prettierrc` for options.
96
+
97
+ ## Examples
98
+
99
+ Check the `examples/` directory for sample plugin implementations.
100
+
101
+ ## Host Capabilities
102
+
103
+ Plugins built with this SDK can access ZLayer host capabilities through the generated WIT bindings:
104
+
105
+ - **HTTP Requests** - Make outbound HTTP requests
106
+ - **Key-Value Storage** - Persist data across plugin invocations
107
+ - **Logging** - Structured logging to the host
108
+ - **Configuration** - Access plugin configuration
109
+ - **Events** - Subscribe to and emit events
110
+
111
+ ## Building for Production
112
+
113
+ For production builds, ensure you:
114
+
115
+ 1. Run the full build process:
116
+ ```bash
117
+ npm run clean && npm run build
118
+ ```
119
+
120
+ 2. Test your plugin:
121
+ ```bash
122
+ npm run test
123
+ ```
124
+
125
+ 3. Lint and format:
126
+ ```bash
127
+ npm run lint && npm run format
128
+ ```
129
+
130
+ ## License
131
+
132
+ MIT