@vtxdeo/protocol 1.2.6

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/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # @vtxdeo/protocol
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@vtx/protocol.svg)](https://www.npmjs.com/package/@vtx/protocol)
4
+
5
+ **Official WIT interface definitions for VTX Project plugins.**
6
+
7
+ This package contains the raw `vtx.wit` definitions required to compile JavaScript/TypeScript code into VTX-compatible WebAssembly components.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @vtx/protocol --save-dev
13
+
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ### 1. Programmatic Usage (Build Scripts)
19
+
20
+ This package exports the absolute path to the `vtx.wit` file.
21
+
22
+ ```javascript
23
+ import { witPath, witDir } from '@vtx/protocol';
24
+ // or: const { witPath } = require('@vtx/protocol');
25
+
26
+ console.log(witPath);
27
+ // Output example: /Users/dev/project/node_modules/@vtx/protocol/wit/vtx.wit
28
+
29
+ ```
30
+
31
+ ### 2. Using with `jco` (CLI)
32
+
33
+ You can use the path directly in your CLI commands to componentize your application:
34
+
35
+ ```bash
36
+ # Example: Transpile JS to Component
37
+ jco componentize app.js \
38
+ --wit "$(node -p "require('@vtx/protocol').witPath")" \
39
+ --world plugin \
40
+ --out plugin.wasm
41
+
42
+ ```
43
+
44
+ ### 3. Using with `componentize-js` (API)
45
+
46
+ ```javascript
47
+ import { componentize } from '@bytecodealliance/componentize-js';
48
+ import { witPath } from '@vtx/protocol';
49
+ import { readFile } from 'node:fs/promises';
50
+
51
+ const source = await readFile('app.js', 'utf8');
52
+
53
+ const { component } = await componentize(source, {
54
+ witPath: witPath, // Pass the path directly
55
+ world: 'plugin',
56
+ });
57
+
58
+ ```
59
+
60
+ ## Versioning
61
+
62
+ The version of this package matches the version of the `vtx:api` WIT definition.
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ witPath: path.join(__dirname, 'wit', 'vtx.wit'),
5
+ witDir: path.join(__dirname, 'wit')
6
+ };
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@vtxdeo/protocol",
3
+ "version": "1.2.6",
4
+ "description": "WIT definitions for VTX plugins",
5
+ "main": "index.js",
6
+ "files": [
7
+ "index.js",
8
+ "wit/"
9
+ ],
10
+ "scripts": {
11
+ "prepublishOnly": "cp -r ../../wit ./"
12
+ }
13
+ }
package/wit/vtx.wit ADDED
@@ -0,0 +1,77 @@
1
+ package vtx:api@1.2.6;
2
+
3
+ interface sql {
4
+ variant db-value {
5
+ text(string),
6
+ integer(s64),
7
+ real(f64),
8
+ null-val,
9
+ }
10
+
11
+ execute: func(statement: string, params: list<db-value>) -> result<u64, string>;
12
+
13
+ query-json: func(statement: string, params: list<db-value>) -> result<string, string>;
14
+ }
15
+
16
+ interface stream-io {
17
+ resource buffer {
18
+ size: func() -> u64;
19
+
20
+ read: func(offset: u64, max-bytes: u64) -> list<u8>;
21
+ }
22
+
23
+ open-file: func(uuid: string) -> result<buffer, string>;
24
+
25
+ create-memory-buffer: func(data: list<u8>) -> buffer;
26
+ }
27
+
28
+ interface auth-types {
29
+ record user-context {
30
+ user-id: string,
31
+ username: string,
32
+ groups: list<string>,
33
+ metadata: string,
34
+ }
35
+ }
36
+
37
+ interface types {
38
+ use stream-io.{buffer};
39
+ use auth-types.{user-context};
40
+
41
+ record http-request {
42
+ method: string,
43
+ path: string,
44
+ query: string,
45
+ }
46
+
47
+ record http-response {
48
+ status: u16,
49
+ body: option<buffer>,
50
+ }
51
+
52
+ record manifest {
53
+ id: string,
54
+ name: string,
55
+ version: string,
56
+ description: string,
57
+ entrypoint: string,
58
+ }
59
+ }
60
+
61
+ world plugin {
62
+ use types.{http-request, http-response, manifest};
63
+ use auth-types.{user-context};
64
+
65
+ import stream-io;
66
+ import sql;
67
+
68
+ export handle: func(req: http-request) -> http-response;
69
+
70
+ export get-migrations: func() -> list<string>;
71
+
72
+ export get-manifest: func() -> manifest;
73
+
74
+ export get-resources: func() -> list<string>;
75
+
76
+ export authenticate: func(headers: list<tuple<string, string>>) -> result<user-context, u16>;
77
+ }