mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 11:59:00 +00:00
34
src/api/demo/.gitignore
vendored
Normal file
34
src/api/demo/.gitignore
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
34
src/api/demo/README.md
Normal file
34
src/api/demo/README.md
Normal file
@@ -0,0 +1,34 @@
|
||||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
|
||||
|
||||
## Getting Started
|
||||
|
||||
First, run the development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
```
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||
|
||||
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
|
||||
|
||||
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
|
||||
|
||||
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
|
||||
|
||||
## Learn More
|
||||
|
||||
To learn more about Next.js, take a look at the following resources:
|
||||
|
||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||
|
||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
|
||||
|
||||
## Deploy on Vercel
|
||||
|
||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||
|
||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
|
||||
77
src/api/demo/lib/api.ts
Normal file
77
src/api/demo/lib/api.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import * as Schema from "../../schema";
|
||||
import { ByteBuffer } from "peechy";
|
||||
|
||||
export interface WebAssemblyModule {
|
||||
init(): number;
|
||||
transform(a: number): number;
|
||||
malloc(a: number): number;
|
||||
calloc(a: number): number;
|
||||
realloc(a: number): number;
|
||||
free(a: number): number;
|
||||
}
|
||||
|
||||
export class ESDev {
|
||||
static has_initialized = false;
|
||||
static wasm_source: WebAssembly.WebAssemblyInstantiatedSource = null;
|
||||
static wasm_exports: WebAssemblyModule;
|
||||
static memory: WebAssembly.Memory;
|
||||
static memory_array: Uint8Array;
|
||||
static async init(url) {
|
||||
if (typeof SharedArrayBuffer !== "undefined") {
|
||||
ESDev.memory = new WebAssembly.Memory({
|
||||
initial: 1500,
|
||||
maximum: 3000,
|
||||
shared: true,
|
||||
});
|
||||
} else {
|
||||
ESDev.memory = new WebAssembly.Memory({
|
||||
initial: 1500,
|
||||
maximum: 3000,
|
||||
});
|
||||
}
|
||||
ESDev.memory_array = new Uint8Array(ESDev.memory.buffer);
|
||||
ESDev.wasm_source = await globalThis.WebAssembly.instantiateStreaming(
|
||||
fetch(url),
|
||||
{
|
||||
js: {
|
||||
mem: ESDev.memory,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
ESDev.wasm_exports = ESDev.wasm_source.instance.exports as any;
|
||||
ESDev.wasm_exports.init();
|
||||
console.log("WASM loaded.");
|
||||
ESDev.has_initialized = true;
|
||||
}
|
||||
|
||||
static transform(content: string, file_name: string) {
|
||||
if (!ESDev.has_initialized) {
|
||||
throw "Please run await ESDev.init(wasm_url) before using this.";
|
||||
}
|
||||
|
||||
const bb = new ByteBuffer(
|
||||
new Uint8Array(content.length + file_name.length)
|
||||
);
|
||||
bb.length = 0;
|
||||
|
||||
Schema.encodeTransform(
|
||||
{
|
||||
contents: content,
|
||||
path: file_name,
|
||||
},
|
||||
bb
|
||||
);
|
||||
const data = bb.toUint8Array();
|
||||
const ptr = ESDev.wasm_exports.malloc(data.byteLength);
|
||||
ESDev.memory_array.set(data, ptr);
|
||||
debugger;
|
||||
const resp_ptr = ESDev.wasm_exports.transform(ptr);
|
||||
var _bb = new ByteBuffer(ESDev.memory_array.subarray(resp_ptr));
|
||||
const response = Schema.decodeTransformResponse(_bb);
|
||||
ESDev.wasm_exports.free(resp_ptr);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
globalThis.ESDev = ESDev;
|
||||
16
src/api/demo/package.json
Normal file
16
src/api/demo/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "demo",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "10.2.0",
|
||||
"peechy": "0.3.6",
|
||||
"react": "17.0.2",
|
||||
"react-dom": "17.0.2"
|
||||
}
|
||||
}
|
||||
7
src/api/demo/pages/_app.js
Normal file
7
src/api/demo/pages/_app.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import '../styles/globals.css'
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return <Component {...pageProps} />
|
||||
}
|
||||
|
||||
export default MyApp
|
||||
5
src/api/demo/pages/api/hello.js
Normal file
5
src/api/demo/pages/api/hello.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
|
||||
export default (req, res) => {
|
||||
res.status(200).json({ name: 'John Doe' })
|
||||
}
|
||||
69
src/api/demo/pages/index.js
Normal file
69
src/api/demo/pages/index.js
Normal file
@@ -0,0 +1,69 @@
|
||||
import Head from "next/head";
|
||||
import Image from "next/image";
|
||||
import styles from "../styles/Home.module.css";
|
||||
import "../lib/api.ts";
|
||||
export default function Home() {
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<Head>
|
||||
<title>Create Next App</title>
|
||||
<meta name="description" content="Generated by create next app" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
|
||||
<main className={styles.main}>
|
||||
<h1 className={styles.title}>
|
||||
Welcome to <a href="https://nextjs.org">Next.js!</a>
|
||||
</h1>
|
||||
|
||||
<p className={styles.description}>
|
||||
Get started by editing{" "}
|
||||
<code className={styles.code}>pages/index.js</code>
|
||||
</p>
|
||||
|
||||
<div className={styles.grid}>
|
||||
<a href="https://nextjs.org/docs" className={styles.card}>
|
||||
<h2>Documentation →</h2>
|
||||
<p>Find in-depth information about Next.js features and API.</p>
|
||||
</a>
|
||||
|
||||
<a href="https://nextjs.org/learn" className={styles.card}>
|
||||
<h2>Learn →</h2>
|
||||
<p>Learn about Next.js in an interactive course with quizzes!</p>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="https://github.com/vercel/next.js/tree/master/examples"
|
||||
className={styles.card}
|
||||
>
|
||||
<h2>Examples →</h2>
|
||||
<p>Discover and deploy boilerplate example Next.js projects.</p>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
|
||||
className={styles.card}
|
||||
>
|
||||
<h2>Deploy →</h2>
|
||||
<p>
|
||||
Instantly deploy your Next.js site to a public URL with Vercel.
|
||||
</p>
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer className={styles.footer}>
|
||||
<a
|
||||
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Powered by{" "}
|
||||
<span className={styles.logo}>
|
||||
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
|
||||
</span>
|
||||
</a>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
1915
src/api/demo/pnpm-lock.yaml
generated
Normal file
1915
src/api/demo/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
BIN
src/api/demo/public/favicon.ico
Normal file
BIN
src/api/demo/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
4
src/api/demo/public/vercel.svg
Normal file
4
src/api/demo/public/vercel.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<svg width="283" height="64" viewBox="0 0 283 64" fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M141.04 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.46 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM248.72 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.45 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM200.24 34c0 6 3.92 10 10 10 4.12 0 7.21-1.87 8.8-4.92l7.68 4.43c-3.18 5.3-9.14 8.49-16.48 8.49-11.05 0-19-7.2-19-18s7.96-18 19-18c7.34 0 13.29 3.19 16.48 8.49l-7.68 4.43c-1.59-3.05-4.68-4.92-8.8-4.92-6.07 0-10 4-10 10zm82.48-29v46h-9V5h9zM36.95 0L73.9 64H0L36.95 0zm92.38 5l-27.71 48L73.91 5H84.3l17.32 30 17.32-30h10.39zm58.91 12v9.69c-1-.29-2.06-.49-3.2-.49-5.81 0-10 4-10 10V51h-9V17h9v9.2c0-5.08 5.91-9.2 13.2-9.2z" fill="#000"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
121
src/api/demo/styles/Home.module.css
Normal file
121
src/api/demo/styles/Home.module.css
Normal file
@@ -0,0 +1,121 @@
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
padding: 0 0.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.main {
|
||||
padding: 5rem 0;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.footer {
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
border-top: 1px solid #eaeaea;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.footer a {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.title a {
|
||||
color: #0070f3;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.title a:hover,
|
||||
.title a:focus,
|
||||
.title a:active {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin: 0;
|
||||
line-height: 1.15;
|
||||
font-size: 4rem;
|
||||
}
|
||||
|
||||
.title,
|
||||
.description {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.description {
|
||||
line-height: 1.5;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.code {
|
||||
background: #fafafa;
|
||||
border-radius: 5px;
|
||||
padding: 0.75rem;
|
||||
font-size: 1.1rem;
|
||||
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
|
||||
Bitstream Vera Sans Mono, Courier New, monospace;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
max-width: 800px;
|
||||
margin-top: 3rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
margin: 1rem;
|
||||
padding: 1.5rem;
|
||||
text-align: left;
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
border: 1px solid #eaeaea;
|
||||
border-radius: 10px;
|
||||
transition: color 0.15s ease, border-color 0.15s ease;
|
||||
width: 45%;
|
||||
}
|
||||
|
||||
.card:hover,
|
||||
.card:focus,
|
||||
.card:active {
|
||||
color: #0070f3;
|
||||
border-color: #0070f3;
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
margin: 0 0 1rem 0;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.card p {
|
||||
margin: 0;
|
||||
font-size: 1.25rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 1em;
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.grid {
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
16
src/api/demo/styles/globals.css
Normal file
16
src/api/demo/styles/globals.css
Normal file
@@ -0,0 +1,16 @@
|
||||
html,
|
||||
body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
|
||||
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
|
||||
}
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
188
src/api/schema.d.ts
vendored
Normal file
188
src/api/schema.d.ts
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
import type { ByteBuffer } from "peechy";
|
||||
|
||||
type byte = number;
|
||||
type float = number;
|
||||
type int = number;
|
||||
type alphanumeric = string;
|
||||
type uint = number;
|
||||
type int8 = number;
|
||||
type lowp = number;
|
||||
type int16 = number;
|
||||
type int32 = number;
|
||||
type float32 = number;
|
||||
type uint16 = number;
|
||||
type uint32 = number;
|
||||
export enum Loader {
|
||||
jsx = 1,
|
||||
js = 2,
|
||||
ts = 3,
|
||||
tsx = 4,
|
||||
css = 5,
|
||||
file = 6,
|
||||
json = 7,
|
||||
}
|
||||
export const LoaderKeys = {
|
||||
1: "jsx",
|
||||
jsx: "jsx",
|
||||
2: "js",
|
||||
js: "js",
|
||||
3: "ts",
|
||||
ts: "ts",
|
||||
4: "tsx",
|
||||
tsx: "tsx",
|
||||
5: "css",
|
||||
css: "css",
|
||||
6: "file",
|
||||
file: "file",
|
||||
7: "json",
|
||||
json: "json",
|
||||
};
|
||||
export enum JSXRuntime {
|
||||
automatic = 1,
|
||||
classic = 2,
|
||||
}
|
||||
export const JSXRuntimeKeys = {
|
||||
1: "automatic",
|
||||
automatic: "automatic",
|
||||
2: "classic",
|
||||
classic: "classic",
|
||||
};
|
||||
export enum TransformResponseStatus {
|
||||
success = 1,
|
||||
fail = 2,
|
||||
}
|
||||
export const TransformResponseStatusKeys = {
|
||||
1: "success",
|
||||
success: "success",
|
||||
2: "fail",
|
||||
fail: "fail",
|
||||
};
|
||||
export enum MessageKind {
|
||||
err = 1,
|
||||
warn = 2,
|
||||
note = 3,
|
||||
debug = 4,
|
||||
}
|
||||
export const MessageKindKeys = {
|
||||
1: "err",
|
||||
err: "err",
|
||||
2: "warn",
|
||||
warn: "warn",
|
||||
3: "note",
|
||||
note: "note",
|
||||
4: "debug",
|
||||
debug: "debug",
|
||||
};
|
||||
export interface JSX {
|
||||
factory: string;
|
||||
runtime: JSXRuntime;
|
||||
fragment: string;
|
||||
production: boolean;
|
||||
import_source: string;
|
||||
react_fast_refresh: boolean;
|
||||
loader_keys: string[];
|
||||
loader_values: Loader[];
|
||||
}
|
||||
|
||||
export interface TransformOptions {
|
||||
jsx: JSX;
|
||||
ts: boolean;
|
||||
base_path: string;
|
||||
define_keys: string[];
|
||||
define_values: string[];
|
||||
}
|
||||
|
||||
export interface FileHandle {
|
||||
path: string;
|
||||
size: uint;
|
||||
fd: uint;
|
||||
}
|
||||
|
||||
export interface Transform {
|
||||
handle?: FileHandle;
|
||||
path?: string;
|
||||
contents?: string;
|
||||
loader?: Loader;
|
||||
options?: TransformOptions;
|
||||
}
|
||||
|
||||
export interface OutputFile {
|
||||
data: Uint8Array;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface TransformResponse {
|
||||
status: TransformResponseStatus;
|
||||
files: OutputFile[];
|
||||
errors: Message[];
|
||||
}
|
||||
|
||||
export interface Location {
|
||||
file: string;
|
||||
namespace: string;
|
||||
line: int32;
|
||||
column: int32;
|
||||
line_text: string;
|
||||
suggestion: string;
|
||||
offset: uint;
|
||||
}
|
||||
|
||||
export interface MessageData {
|
||||
text?: string;
|
||||
location?: Location;
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
kind: MessageKind;
|
||||
data: MessageData;
|
||||
notes: MessageData[];
|
||||
}
|
||||
|
||||
export interface Log {
|
||||
warnings: uint32;
|
||||
errors: uint32;
|
||||
msgs: Message[];
|
||||
}
|
||||
|
||||
export declare function encodeJSX(message: JSX, bb: ByteBuffer): void;
|
||||
export declare function decodeJSX(buffer: ByteBuffer): JSX;
|
||||
export declare function encodeTransformOptions(
|
||||
message: TransformOptions,
|
||||
bb: ByteBuffer
|
||||
): void;
|
||||
export declare function decodeTransformOptions(
|
||||
buffer: ByteBuffer
|
||||
): TransformOptions;
|
||||
export declare function encodeFileHandle(
|
||||
message: FileHandle,
|
||||
bb: ByteBuffer
|
||||
): void;
|
||||
export declare function decodeFileHandle(buffer: ByteBuffer): FileHandle;
|
||||
export declare function encodeTransform(
|
||||
message: Transform,
|
||||
bb: ByteBuffer
|
||||
): void;
|
||||
export declare function decodeTransform(buffer: ByteBuffer): Transform;
|
||||
export declare function encodeOutputFile(
|
||||
message: OutputFile,
|
||||
bb: ByteBuffer
|
||||
): void;
|
||||
export declare function decodeOutputFile(buffer: ByteBuffer): OutputFile;
|
||||
export declare function encodeTransformResponse(
|
||||
message: TransformResponse,
|
||||
bb: ByteBuffer
|
||||
): void;
|
||||
export declare function decodeTransformResponse(
|
||||
buffer: ByteBuffer
|
||||
): TransformResponse;
|
||||
export declare function encodeLocation(message: Location, bb: ByteBuffer): void;
|
||||
export declare function decodeLocation(buffer: ByteBuffer): Location;
|
||||
export declare function encodeMessageData(
|
||||
message: MessageData,
|
||||
bb: ByteBuffer
|
||||
): void;
|
||||
export declare function decodeMessageData(buffer: ByteBuffer): MessageData;
|
||||
export declare function encodeMessage(message: Message, bb: ByteBuffer): void;
|
||||
export declare function decodeMessage(buffer: ByteBuffer): Message;
|
||||
export declare function encodeLog(message: Log, bb: ByteBuffer): void;
|
||||
export declare function decodeLog(buffer: ByteBuffer): Log;
|
||||
631
src/api/schema.js
Normal file
631
src/api/schema.js
Normal file
@@ -0,0 +1,631 @@
|
||||
const Loader = {
|
||||
"1": 1,
|
||||
"2": 2,
|
||||
"3": 3,
|
||||
"4": 4,
|
||||
"5": 5,
|
||||
"6": 6,
|
||||
"7": 7,
|
||||
"jsx": 1,
|
||||
"js": 2,
|
||||
"ts": 3,
|
||||
"tsx": 4,
|
||||
"css": 5,
|
||||
"file": 6,
|
||||
"json": 7
|
||||
};
|
||||
const LoaderKeys = {
|
||||
"1": "jsx",
|
||||
"2": "js",
|
||||
"3": "ts",
|
||||
"4": "tsx",
|
||||
"5": "css",
|
||||
"6": "file",
|
||||
"7": "json",
|
||||
"jsx": "jsx",
|
||||
"js": "js",
|
||||
"ts": "ts",
|
||||
"tsx": "tsx",
|
||||
"css": "css",
|
||||
"file": "file",
|
||||
"json": "json"
|
||||
};
|
||||
const JSXRuntime = {
|
||||
"1": 1,
|
||||
"2": 2,
|
||||
"automatic": 1,
|
||||
"classic": 2
|
||||
};
|
||||
const JSXRuntimeKeys = {
|
||||
"1": "automatic",
|
||||
"2": "classic",
|
||||
"automatic": "automatic",
|
||||
"classic": "classic"
|
||||
};
|
||||
|
||||
function decodeJSX(bb) {
|
||||
var result = {};
|
||||
|
||||
result["factory"] = bb.readString();
|
||||
result["runtime"] = JSXRuntime[bb.readByte()];
|
||||
result["fragment"] = bb.readString();
|
||||
result["production"] = !!bb.readByte();
|
||||
result["import_source"] = bb.readString();
|
||||
result["react_fast_refresh"] = !!bb.readByte();
|
||||
var length = bb.readVarUint();
|
||||
var values = result["loader_keys"] = Array(length);
|
||||
for (var i = 0; i < length; i++) values[i] = bb.readString();
|
||||
var length = bb.readVarUint();
|
||||
var values = result["loader_values"] = Array(length);
|
||||
for (var i = 0; i < length; i++) values[i] = Loader[bb.readByte()];
|
||||
return result;
|
||||
}
|
||||
|
||||
function encodeJSX(message, bb) {
|
||||
|
||||
var value = message["factory"];
|
||||
if (value != null) {
|
||||
bb.writeString(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"factory\"");
|
||||
}
|
||||
|
||||
var value = message["runtime"];
|
||||
if (value != null) {
|
||||
var encoded = JSXRuntime[value];
|
||||
if (encoded === void 0) throw new Error("Invalid value " + JSON.stringify(value) + " for enum \"JSXRuntime\"");
|
||||
bb.writeByte(encoded);
|
||||
} else {
|
||||
throw new Error("Missing required field \"runtime\"");
|
||||
}
|
||||
|
||||
var value = message["fragment"];
|
||||
if (value != null) {
|
||||
bb.writeString(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"fragment\"");
|
||||
}
|
||||
|
||||
var value = message["production"];
|
||||
if (value != null) {
|
||||
bb.writeByte(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"production\"");
|
||||
}
|
||||
|
||||
var value = message["import_source"];
|
||||
if (value != null) {
|
||||
bb.writeString(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"import_source\"");
|
||||
}
|
||||
|
||||
var value = message["react_fast_refresh"];
|
||||
if (value != null) {
|
||||
bb.writeByte(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"react_fast_refresh\"");
|
||||
}
|
||||
|
||||
var value = message["loader_keys"];
|
||||
if (value != null) {
|
||||
var values = value, n = values.length;
|
||||
bb.writeVarUint(n);
|
||||
for (var i = 0; i < n; i++) {
|
||||
value = values[i];
|
||||
bb.writeString(value);
|
||||
}
|
||||
} else {
|
||||
throw new Error("Missing required field \"loader_keys\"");
|
||||
}
|
||||
|
||||
var value = message["loader_values"];
|
||||
if (value != null) {
|
||||
var values = value, n = values.length;
|
||||
bb.writeVarUint(n);
|
||||
for (var i = 0; i < n; i++) {
|
||||
value = values[i];
|
||||
var encoded = Loader[value];
|
||||
if (encoded === void 0) throw new Error("Invalid value " + JSON.stringify(value) + " for enum \"Loader\"");
|
||||
bb.writeByte(encoded);
|
||||
}
|
||||
} else {
|
||||
throw new Error("Missing required field \"loader_values\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function decodeTransformOptions(bb) {
|
||||
var result = {};
|
||||
|
||||
result["jsx"] = decodeJSX(bb);
|
||||
result["ts"] = !!bb.readByte();
|
||||
result["base_path"] = bb.readString();
|
||||
var length = bb.readVarUint();
|
||||
var values = result["define_keys"] = Array(length);
|
||||
for (var i = 0; i < length; i++) values[i] = bb.readString();
|
||||
var length = bb.readVarUint();
|
||||
var values = result["define_values"] = Array(length);
|
||||
for (var i = 0; i < length; i++) values[i] = bb.readString();
|
||||
return result;
|
||||
}
|
||||
|
||||
function encodeTransformOptions(message, bb) {
|
||||
|
||||
var value = message["jsx"];
|
||||
if (value != null) {
|
||||
encodeJSX(value, bb);
|
||||
} else {
|
||||
throw new Error("Missing required field \"jsx\"");
|
||||
}
|
||||
|
||||
var value = message["ts"];
|
||||
if (value != null) {
|
||||
bb.writeByte(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"ts\"");
|
||||
}
|
||||
|
||||
var value = message["base_path"];
|
||||
if (value != null) {
|
||||
bb.writeString(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"base_path\"");
|
||||
}
|
||||
|
||||
var value = message["define_keys"];
|
||||
if (value != null) {
|
||||
var values = value, n = values.length;
|
||||
bb.writeVarUint(n);
|
||||
for (var i = 0; i < n; i++) {
|
||||
value = values[i];
|
||||
bb.writeString(value);
|
||||
}
|
||||
} else {
|
||||
throw new Error("Missing required field \"define_keys\"");
|
||||
}
|
||||
|
||||
var value = message["define_values"];
|
||||
if (value != null) {
|
||||
var values = value, n = values.length;
|
||||
bb.writeVarUint(n);
|
||||
for (var i = 0; i < n; i++) {
|
||||
value = values[i];
|
||||
bb.writeString(value);
|
||||
}
|
||||
} else {
|
||||
throw new Error("Missing required field \"define_values\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function decodeFileHandle(bb) {
|
||||
var result = {};
|
||||
|
||||
result["path"] = bb.readString();
|
||||
result["size"] = bb.readVarUint();
|
||||
result["fd"] = bb.readVarUint();
|
||||
return result;
|
||||
}
|
||||
|
||||
function encodeFileHandle(message, bb) {
|
||||
|
||||
var value = message["path"];
|
||||
if (value != null) {
|
||||
bb.writeString(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"path\"");
|
||||
}
|
||||
|
||||
var value = message["size"];
|
||||
if (value != null) {
|
||||
bb.writeVarUint(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"size\"");
|
||||
}
|
||||
|
||||
var value = message["fd"];
|
||||
if (value != null) {
|
||||
bb.writeVarUint(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"fd\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function decodeTransform(bb) {
|
||||
var result = {};
|
||||
|
||||
while (true) {
|
||||
switch (bb.readVarUint()) {
|
||||
case 0:
|
||||
return result;
|
||||
|
||||
case 1:
|
||||
result["handle"] = decodeFileHandle(bb);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
result["path"] = bb.readString();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
result["contents"] = bb.readString();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
result["loader"] = Loader[bb.readByte()];
|
||||
break;
|
||||
|
||||
case 5:
|
||||
result["options"] = decodeTransformOptions(bb);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error("Attempted to parse invalid message");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function encodeTransform(message, bb) {
|
||||
|
||||
var value = message["handle"];
|
||||
if (value != null) {
|
||||
bb.writeVarUint(1);
|
||||
encodeFileHandle(value, bb);
|
||||
}
|
||||
|
||||
var value = message["path"];
|
||||
if (value != null) {
|
||||
bb.writeVarUint(2);
|
||||
bb.writeString(value);
|
||||
}
|
||||
|
||||
var value = message["contents"];
|
||||
if (value != null) {
|
||||
bb.writeVarUint(3);
|
||||
bb.writeString(value);
|
||||
}
|
||||
|
||||
var value = message["loader"];
|
||||
if (value != null) {
|
||||
bb.writeVarUint(4);
|
||||
var encoded = Loader[value];
|
||||
if (encoded === void 0) throw new Error("Invalid value " + JSON.stringify(value) + " for enum \"Loader\"");
|
||||
bb.writeByte(encoded);
|
||||
}
|
||||
|
||||
var value = message["options"];
|
||||
if (value != null) {
|
||||
bb.writeVarUint(5);
|
||||
encodeTransformOptions(value, bb);
|
||||
}
|
||||
bb.writeVarUint(0);
|
||||
|
||||
}
|
||||
const TransformResponseStatus = {
|
||||
"1": 1,
|
||||
"2": 2,
|
||||
"success": 1,
|
||||
"fail": 2
|
||||
};
|
||||
const TransformResponseStatusKeys = {
|
||||
"1": "success",
|
||||
"2": "fail",
|
||||
"success": "success",
|
||||
"fail": "fail"
|
||||
};
|
||||
|
||||
function decodeOutputFile(bb) {
|
||||
var result = {};
|
||||
|
||||
result["data"] = bb.readByteArray();
|
||||
result["path"] = bb.readString();
|
||||
return result;
|
||||
}
|
||||
|
||||
function encodeOutputFile(message, bb) {
|
||||
|
||||
var value = message["data"];
|
||||
if (value != null) {
|
||||
bb.writeByteArray(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"data\"");
|
||||
}
|
||||
|
||||
var value = message["path"];
|
||||
if (value != null) {
|
||||
bb.writeString(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"path\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function decodeTransformResponse(bb) {
|
||||
var result = {};
|
||||
|
||||
result["status"] = TransformResponseStatus[bb.readVarUint()];
|
||||
var length = bb.readVarUint();
|
||||
var values = result["files"] = Array(length);
|
||||
for (var i = 0; i < length; i++) values[i] = decodeOutputFile(bb);
|
||||
var length = bb.readVarUint();
|
||||
var values = result["errors"] = Array(length);
|
||||
for (var i = 0; i < length; i++) values[i] = decodeMessage(bb);
|
||||
return result;
|
||||
}
|
||||
|
||||
function encodeTransformResponse(message, bb) {
|
||||
|
||||
var value = message["status"];
|
||||
if (value != null) {
|
||||
var encoded = TransformResponseStatus[value];
|
||||
if (encoded === void 0) throw new Error("Invalid value " + JSON.stringify(value) + " for enum \"TransformResponseStatus\"");
|
||||
bb.writeVarUint(encoded);
|
||||
} else {
|
||||
throw new Error("Missing required field \"status\"");
|
||||
}
|
||||
|
||||
var value = message["files"];
|
||||
if (value != null) {
|
||||
var values = value, n = values.length;
|
||||
bb.writeVarUint(n);
|
||||
for (var i = 0; i < n; i++) {
|
||||
value = values[i];
|
||||
encodeOutputFile(value, bb);
|
||||
}
|
||||
} else {
|
||||
throw new Error("Missing required field \"files\"");
|
||||
}
|
||||
|
||||
var value = message["errors"];
|
||||
if (value != null) {
|
||||
var values = value, n = values.length;
|
||||
bb.writeVarUint(n);
|
||||
for (var i = 0; i < n; i++) {
|
||||
value = values[i];
|
||||
encodeMessage(value, bb);
|
||||
}
|
||||
} else {
|
||||
throw new Error("Missing required field \"errors\"");
|
||||
}
|
||||
|
||||
}
|
||||
const MessageKind = {
|
||||
"1": 1,
|
||||
"2": 2,
|
||||
"3": 3,
|
||||
"4": 4,
|
||||
"err": 1,
|
||||
"warn": 2,
|
||||
"note": 3,
|
||||
"debug": 4
|
||||
};
|
||||
const MessageKindKeys = {
|
||||
"1": "err",
|
||||
"2": "warn",
|
||||
"3": "note",
|
||||
"4": "debug",
|
||||
"err": "err",
|
||||
"warn": "warn",
|
||||
"note": "note",
|
||||
"debug": "debug"
|
||||
};
|
||||
|
||||
function decodeLocation(bb) {
|
||||
var result = {};
|
||||
|
||||
result["file"] = bb.readString();
|
||||
result["namespace"] = bb.readString();
|
||||
result["line"] = bb.readInt32();
|
||||
result["column"] = bb.readInt32();
|
||||
result["line_text"] = bb.readString();
|
||||
result["suggestion"] = bb.readString();
|
||||
result["offset"] = bb.readVarUint();
|
||||
return result;
|
||||
}
|
||||
|
||||
function encodeLocation(message, bb) {
|
||||
|
||||
var value = message["file"];
|
||||
if (value != null) {
|
||||
bb.writeString(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"file\"");
|
||||
}
|
||||
|
||||
var value = message["namespace"];
|
||||
if (value != null) {
|
||||
bb.writeString(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"namespace\"");
|
||||
}
|
||||
|
||||
var value = message["line"];
|
||||
if (value != null) {
|
||||
bb.writeInt32(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"line\"");
|
||||
}
|
||||
|
||||
var value = message["column"];
|
||||
if (value != null) {
|
||||
bb.writeInt32(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"column\"");
|
||||
}
|
||||
|
||||
var value = message["line_text"];
|
||||
if (value != null) {
|
||||
bb.writeString(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"line_text\"");
|
||||
}
|
||||
|
||||
var value = message["suggestion"];
|
||||
if (value != null) {
|
||||
bb.writeString(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"suggestion\"");
|
||||
}
|
||||
|
||||
var value = message["offset"];
|
||||
if (value != null) {
|
||||
bb.writeVarUint(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"offset\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function decodeMessageData(bb) {
|
||||
var result = {};
|
||||
|
||||
while (true) {
|
||||
switch (bb.readVarUint()) {
|
||||
case 0:
|
||||
return result;
|
||||
|
||||
case 1:
|
||||
result["text"] = bb.readString();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
result["location"] = decodeLocation(bb);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error("Attempted to parse invalid message");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function encodeMessageData(message, bb) {
|
||||
|
||||
var value = message["text"];
|
||||
if (value != null) {
|
||||
bb.writeVarUint(1);
|
||||
bb.writeString(value);
|
||||
}
|
||||
|
||||
var value = message["location"];
|
||||
if (value != null) {
|
||||
bb.writeVarUint(2);
|
||||
encodeLocation(value, bb);
|
||||
}
|
||||
bb.writeVarUint(0);
|
||||
|
||||
}
|
||||
|
||||
function decodeMessage(bb) {
|
||||
var result = {};
|
||||
|
||||
result["kind"] = MessageKind[bb.readVarUint()];
|
||||
result["data"] = decodeMessageData(bb);
|
||||
var length = bb.readVarUint();
|
||||
var values = result["notes"] = Array(length);
|
||||
for (var i = 0; i < length; i++) values[i] = decodeMessageData(bb);
|
||||
return result;
|
||||
}
|
||||
|
||||
function encodeMessage(message, bb) {
|
||||
|
||||
var value = message["kind"];
|
||||
if (value != null) {
|
||||
var encoded = MessageKind[value];
|
||||
if (encoded === void 0) throw new Error("Invalid value " + JSON.stringify(value) + " for enum \"MessageKind\"");
|
||||
bb.writeVarUint(encoded);
|
||||
} else {
|
||||
throw new Error("Missing required field \"kind\"");
|
||||
}
|
||||
|
||||
var value = message["data"];
|
||||
if (value != null) {
|
||||
encodeMessageData(value, bb);
|
||||
} else {
|
||||
throw new Error("Missing required field \"data\"");
|
||||
}
|
||||
|
||||
var value = message["notes"];
|
||||
if (value != null) {
|
||||
var values = value, n = values.length;
|
||||
bb.writeVarUint(n);
|
||||
for (var i = 0; i < n; i++) {
|
||||
value = values[i];
|
||||
encodeMessageData(value, bb);
|
||||
}
|
||||
} else {
|
||||
throw new Error("Missing required field \"notes\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function decodeLog(bb) {
|
||||
var result = {};
|
||||
|
||||
result["warnings"] = bb.readUint32();
|
||||
result["errors"] = bb.readUint32();
|
||||
var length = bb.readVarUint();
|
||||
var values = result["msgs"] = Array(length);
|
||||
for (var i = 0; i < length; i++) values[i] = decodeMessage(bb);
|
||||
return result;
|
||||
}
|
||||
|
||||
function encodeLog(message, bb) {
|
||||
|
||||
var value = message["warnings"];
|
||||
if (value != null) {
|
||||
bb.writeUint32(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"warnings\"");
|
||||
}
|
||||
|
||||
var value = message["errors"];
|
||||
if (value != null) {
|
||||
bb.writeUint32(value);
|
||||
} else {
|
||||
throw new Error("Missing required field \"errors\"");
|
||||
}
|
||||
|
||||
var value = message["msgs"];
|
||||
if (value != null) {
|
||||
var values = value, n = values.length;
|
||||
bb.writeVarUint(n);
|
||||
for (var i = 0; i < n; i++) {
|
||||
value = values[i];
|
||||
encodeMessage(value, bb);
|
||||
}
|
||||
} else {
|
||||
throw new Error("Missing required field \"msgs\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Loader }
|
||||
export { LoaderKeys }
|
||||
export { JSXRuntime }
|
||||
export { JSXRuntimeKeys }
|
||||
export { decodeJSX }
|
||||
export { encodeJSX }
|
||||
export { decodeTransformOptions }
|
||||
export { encodeTransformOptions }
|
||||
export { decodeFileHandle }
|
||||
export { encodeFileHandle }
|
||||
export { decodeTransform }
|
||||
export { encodeTransform }
|
||||
export { TransformResponseStatus }
|
||||
export { TransformResponseStatusKeys }
|
||||
export { decodeOutputFile }
|
||||
export { encodeOutputFile }
|
||||
export { decodeTransformResponse }
|
||||
export { encodeTransformResponse }
|
||||
export { MessageKind }
|
||||
export { MessageKindKeys }
|
||||
export { decodeLocation }
|
||||
export { encodeLocation }
|
||||
export { decodeMessageData }
|
||||
export { encodeMessageData }
|
||||
export { decodeMessage }
|
||||
export { encodeMessage }
|
||||
export { decodeLog }
|
||||
export { encodeLog }
|
||||
107
src/api/schema.peechy
Normal file
107
src/api/schema.peechy
Normal file
@@ -0,0 +1,107 @@
|
||||
package Api;
|
||||
|
||||
smol Loader {
|
||||
jsx = 1;
|
||||
js = 2;
|
||||
ts = 3;
|
||||
tsx = 4;
|
||||
css = 5;
|
||||
file = 6;
|
||||
json = 7;
|
||||
}
|
||||
|
||||
|
||||
smol JSXRuntime {
|
||||
automatic = 1;
|
||||
classic = 2;
|
||||
}
|
||||
|
||||
struct JSX {
|
||||
string factory;
|
||||
JSXRuntime runtime;
|
||||
string fragment;
|
||||
bool production;
|
||||
|
||||
// Probably react
|
||||
string import_source;
|
||||
|
||||
bool react_fast_refresh;
|
||||
|
||||
string[] loader_keys;
|
||||
Loader[] loader_values;
|
||||
}
|
||||
|
||||
|
||||
struct TransformOptions {
|
||||
JSX jsx;
|
||||
bool ts;
|
||||
|
||||
string base_path;
|
||||
string[] define_keys;
|
||||
string[] define_values;
|
||||
}
|
||||
|
||||
struct FileHandle {
|
||||
string path;
|
||||
uint size;
|
||||
uint fd;
|
||||
}
|
||||
|
||||
message Transform {
|
||||
FileHandle handle = 1;
|
||||
string path = 2;
|
||||
string contents = 3;
|
||||
|
||||
Loader loader = 4;
|
||||
TransformOptions options = 5;
|
||||
}
|
||||
|
||||
enum TransformResponseStatus {
|
||||
success = 1;
|
||||
fail = 2;
|
||||
}
|
||||
|
||||
struct OutputFile {
|
||||
byte[] data;
|
||||
string path;
|
||||
}
|
||||
|
||||
struct TransformResponse {
|
||||
TransformResponseStatus status;
|
||||
OutputFile[] files;
|
||||
Message[] errors;
|
||||
}
|
||||
|
||||
enum MessageKind {
|
||||
err = 1;
|
||||
warn =2;
|
||||
note = 3;
|
||||
debug = 4;
|
||||
}
|
||||
|
||||
struct Location {
|
||||
string file;
|
||||
string namespace;
|
||||
int32 line;
|
||||
int32 column;
|
||||
string line_text;
|
||||
string suggestion;
|
||||
uint offset;
|
||||
}
|
||||
|
||||
message MessageData {
|
||||
string text = 1;
|
||||
Location location = 2;
|
||||
}
|
||||
|
||||
struct Message {
|
||||
MessageKind kind;
|
||||
MessageData data;
|
||||
MessageData[] notes;
|
||||
}
|
||||
|
||||
struct Log {
|
||||
uint32 warnings;
|
||||
uint32 errors;
|
||||
Message[] msgs;
|
||||
}
|
||||
166
src/api/schema.ts
Normal file
166
src/api/schema.ts
Normal file
@@ -0,0 +1,166 @@
|
||||
import type {ByteBuffer} from "peechy";
|
||||
|
||||
type byte = number;
|
||||
type float = number;
|
||||
type int = number;
|
||||
type alphanumeric = string;
|
||||
type uint = number;
|
||||
type int8 = number;
|
||||
type lowp = number;
|
||||
type int16 = number;
|
||||
type int32 = number;
|
||||
type float32 = number;
|
||||
type uint16 = number;
|
||||
type uint32 = number;
|
||||
export enum Loader {
|
||||
jsx = 1,
|
||||
js = 2,
|
||||
ts = 3,
|
||||
tsx = 4,
|
||||
css = 5,
|
||||
file = 6,
|
||||
json = 7
|
||||
}
|
||||
export const LoaderKeys = {
|
||||
1: "jsx",
|
||||
jsx: "jsx",
|
||||
2: "js",
|
||||
js: "js",
|
||||
3: "ts",
|
||||
ts: "ts",
|
||||
4: "tsx",
|
||||
tsx: "tsx",
|
||||
5: "css",
|
||||
css: "css",
|
||||
6: "file",
|
||||
file: "file",
|
||||
7: "json",
|
||||
json: "json"
|
||||
}
|
||||
export enum JSXRuntime {
|
||||
automatic = 1,
|
||||
classic = 2
|
||||
}
|
||||
export const JSXRuntimeKeys = {
|
||||
1: "automatic",
|
||||
automatic: "automatic",
|
||||
2: "classic",
|
||||
classic: "classic"
|
||||
}
|
||||
export enum TransformResponseStatus {
|
||||
success = 1,
|
||||
fail = 2
|
||||
}
|
||||
export const TransformResponseStatusKeys = {
|
||||
1: "success",
|
||||
success: "success",
|
||||
2: "fail",
|
||||
fail: "fail"
|
||||
}
|
||||
export enum MessageKind {
|
||||
err = 1,
|
||||
warn = 2,
|
||||
note = 3,
|
||||
debug = 4
|
||||
}
|
||||
export const MessageKindKeys = {
|
||||
1: "err",
|
||||
err: "err",
|
||||
2: "warn",
|
||||
warn: "warn",
|
||||
3: "note",
|
||||
note: "note",
|
||||
4: "debug",
|
||||
debug: "debug"
|
||||
}
|
||||
export interface JSX {
|
||||
factory: string;
|
||||
runtime: JSXRuntime;
|
||||
fragment: string;
|
||||
production: boolean;
|
||||
import_source: string;
|
||||
react_fast_refresh: boolean;
|
||||
loader_keys: string[];
|
||||
loader_values: Loader[];
|
||||
}
|
||||
|
||||
export interface TransformOptions {
|
||||
jsx: JSX;
|
||||
ts: boolean;
|
||||
base_path: string;
|
||||
define_keys: string[];
|
||||
define_values: string[];
|
||||
}
|
||||
|
||||
export interface FileHandle {
|
||||
path: string;
|
||||
size: uint;
|
||||
fd: uint;
|
||||
}
|
||||
|
||||
export interface Transform {
|
||||
handle?: FileHandle;
|
||||
path?: string;
|
||||
contents?: string;
|
||||
loader?: Loader;
|
||||
options?: TransformOptions;
|
||||
}
|
||||
|
||||
export interface OutputFile {
|
||||
data: Uint8Array;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface TransformResponse {
|
||||
status: TransformResponseStatus;
|
||||
files: OutputFile[];
|
||||
errors: Message[];
|
||||
}
|
||||
|
||||
export interface Location {
|
||||
file: string;
|
||||
namespace: string;
|
||||
line: int32;
|
||||
column: int32;
|
||||
line_text: string;
|
||||
suggestion: string;
|
||||
offset: uint;
|
||||
}
|
||||
|
||||
export interface MessageData {
|
||||
text?: string;
|
||||
location?: Location;
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
kind: MessageKind;
|
||||
data: MessageData;
|
||||
notes: MessageData[];
|
||||
}
|
||||
|
||||
export interface Log {
|
||||
warnings: uint32;
|
||||
errors: uint32;
|
||||
msgs: Message[];
|
||||
}
|
||||
|
||||
export declare function encodeJSX(message: JSX, bb: ByteBuffer): void;
|
||||
export declare function decodeJSX(buffer: ByteBuffer): JSX;
|
||||
export declare function encodeTransformOptions(message: TransformOptions, bb: ByteBuffer): void;
|
||||
export declare function decodeTransformOptions(buffer: ByteBuffer): TransformOptions;
|
||||
export declare function encodeFileHandle(message: FileHandle, bb: ByteBuffer): void;
|
||||
export declare function decodeFileHandle(buffer: ByteBuffer): FileHandle;
|
||||
export declare function encodeTransform(message: Transform, bb: ByteBuffer): void;
|
||||
export declare function decodeTransform(buffer: ByteBuffer): Transform;
|
||||
export declare function encodeOutputFile(message: OutputFile, bb: ByteBuffer): void;
|
||||
export declare function decodeOutputFile(buffer: ByteBuffer): OutputFile;
|
||||
export declare function encodeTransformResponse(message: TransformResponse, bb: ByteBuffer): void;
|
||||
export declare function decodeTransformResponse(buffer: ByteBuffer): TransformResponse;
|
||||
export declare function encodeLocation(message: Location, bb: ByteBuffer): void;
|
||||
export declare function decodeLocation(buffer: ByteBuffer): Location;
|
||||
export declare function encodeMessageData(message: MessageData, bb: ByteBuffer): void;
|
||||
export declare function decodeMessageData(buffer: ByteBuffer): MessageData;
|
||||
export declare function encodeMessage(message: Message, bb: ByteBuffer): void;
|
||||
export declare function decodeMessage(buffer: ByteBuffer): Message;
|
||||
export declare function encodeLog(message: Log, bb: ByteBuffer): void;
|
||||
export declare function decodeLog(buffer: ByteBuffer): Log;
|
||||
739
src/api/schema.zig
Normal file
739
src/api/schema.zig
Normal file
@@ -0,0 +1,739 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub const Api = struct {
|
||||
pub const Loader = enum(u8) {
|
||||
_none,
|
||||
/// jsx
|
||||
jsx,
|
||||
|
||||
/// js
|
||||
js,
|
||||
|
||||
/// ts
|
||||
ts,
|
||||
|
||||
/// tsx
|
||||
tsx,
|
||||
|
||||
/// css
|
||||
css,
|
||||
|
||||
/// file
|
||||
file,
|
||||
|
||||
/// json
|
||||
json,
|
||||
|
||||
_,
|
||||
|
||||
pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void {
|
||||
return try std.json.stringify(@tagName(self), opts, o);
|
||||
}
|
||||
};
|
||||
|
||||
pub const JsxRuntime = enum(u8) {
|
||||
_none,
|
||||
/// automatic
|
||||
automatic,
|
||||
|
||||
/// classic
|
||||
classic,
|
||||
|
||||
_,
|
||||
|
||||
pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void {
|
||||
return try std.json.stringify(@tagName(self), opts, o);
|
||||
}
|
||||
};
|
||||
|
||||
pub const Jsx = struct {
|
||||
/// factory
|
||||
factory: []u8,
|
||||
|
||||
/// runtime
|
||||
runtime: JsxRuntime,
|
||||
|
||||
/// fragment
|
||||
fragment: []u8,
|
||||
|
||||
/// production
|
||||
production: bool = false,
|
||||
|
||||
/// import_source
|
||||
import_source: []u8,
|
||||
|
||||
/// react_fast_refresh
|
||||
react_fast_refresh: bool = false,
|
||||
|
||||
/// loader_keys
|
||||
loader_keys: [][]u8,
|
||||
|
||||
/// loader_values
|
||||
loader_values: []Loader,
|
||||
|
||||
pub fn decode(allocator: *std.mem.Allocator, reader: anytype) anyerror!Jsx {
|
||||
var obj = std.mem.zeroes(Jsx);
|
||||
try update(&obj, allocator, reader);
|
||||
return obj;
|
||||
}
|
||||
pub fn update(result: *Jsx, allocator: *std.mem.Allocator, reader: anytype) anyerror!void {
|
||||
var length: usize = 0;
|
||||
length = try reader.readIntNative(u32);
|
||||
if (result.factory.len != length) {
|
||||
result.factory = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.factory);
|
||||
result.runtime = try reader.readEnum(JsxRuntime, .Little);
|
||||
length = try reader.readIntNative(u32);
|
||||
if (result.fragment.len != length) {
|
||||
result.fragment = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.fragment);
|
||||
result.production = (try reader.readByte()) == @as(u8, 1);
|
||||
length = try reader.readIntNative(u32);
|
||||
if (result.import_source.len != length) {
|
||||
result.import_source = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.import_source);
|
||||
result.react_fast_refresh = (try reader.readByte()) == @as(u8, 1);
|
||||
{
|
||||
var array_count = try reader.readIntNative(u32);
|
||||
if (array_count != result.loader_keys.len) {
|
||||
result.loader_keys = try allocator.alloc([]u8, array_count);
|
||||
}
|
||||
length = try reader.readIntNative(u32);
|
||||
for (result.loader_keys) |content, j| {
|
||||
if (result.loader_keys[j].len != length) {
|
||||
result.loader_keys[j] = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.loader_keys[j]);
|
||||
}
|
||||
}
|
||||
length = try reader.readIntNative(u32);
|
||||
result.loader_values = try allocator.alloc(Loader, length);
|
||||
{
|
||||
var j: usize = 0;
|
||||
while (j < length) : (j += 1) {
|
||||
result.loader_values[j] = try reader.readEnum(Loader, .Little);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
pub fn encode(result: *const @This(), writer: anytype) anyerror!void {
|
||||
var n: usize = 0;
|
||||
try writer.writeIntNative(u32, @intCast(u32, result.factory.len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(result.factory));
|
||||
|
||||
try writer.writeIntNative(@TypeOf(@enumToInt(result.runtime)), @enumToInt(result.runtime));
|
||||
|
||||
try writer.writeIntNative(u32, @intCast(u32, result.fragment.len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(result.fragment));
|
||||
|
||||
try writer.writeByte(@boolToInt(result.production));
|
||||
|
||||
try writer.writeIntNative(u32, @intCast(u32, result.import_source.len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(result.import_source));
|
||||
|
||||
try writer.writeByte(@boolToInt(result.react_fast_refresh));
|
||||
|
||||
n = result.loader_keys.len;
|
||||
_ = try writer.writeIntNative(u32, @intCast(u32, n));
|
||||
{
|
||||
var j: usize = 0;
|
||||
while (j < n) : (j += 1) {
|
||||
_ = try writer.writeIntNative(u32, @intCast(u32, result.loader_keys[j].len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(result.loader_keys[j]));
|
||||
}
|
||||
}
|
||||
|
||||
n = result.loader_values.len;
|
||||
_ = try writer.writeIntNative(u32, @intCast(u32, n));
|
||||
{
|
||||
var j: usize = 0;
|
||||
while (j < n) : (j += 1) {
|
||||
try writer.writeByte(@enumToInt(result.loader_values[j]));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
pub const TransformOptions = struct {
|
||||
/// jsx
|
||||
jsx: Jsx,
|
||||
|
||||
/// ts
|
||||
ts: bool = false,
|
||||
|
||||
/// base_path
|
||||
base_path: []u8,
|
||||
|
||||
/// define_keys
|
||||
define_keys: [][]u8,
|
||||
|
||||
/// define_values
|
||||
define_values: [][]u8,
|
||||
|
||||
pub fn decode(allocator: *std.mem.Allocator, reader: anytype) anyerror!TransformOptions {
|
||||
var obj = std.mem.zeroes(TransformOptions);
|
||||
try update(&obj, allocator, reader);
|
||||
return obj;
|
||||
}
|
||||
pub fn update(result: *TransformOptions, allocator: *std.mem.Allocator, reader: anytype) anyerror!void {
|
||||
var length: usize = 0;
|
||||
result.jsx = try Jsx.decode(allocator, reader);
|
||||
result.ts = (try reader.readByte()) == @as(u8, 1);
|
||||
length = try reader.readIntNative(u32);
|
||||
if (result.base_path.len != length) {
|
||||
result.base_path = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.base_path);
|
||||
{
|
||||
var array_count = try reader.readIntNative(u32);
|
||||
if (array_count != result.define_keys.len) {
|
||||
result.define_keys = try allocator.alloc([]u8, array_count);
|
||||
}
|
||||
length = try reader.readIntNative(u32);
|
||||
for (result.define_keys) |content, j| {
|
||||
if (result.define_keys[j].len != length) {
|
||||
result.define_keys[j] = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.define_keys[j]);
|
||||
}
|
||||
}
|
||||
{
|
||||
var array_count = try reader.readIntNative(u32);
|
||||
if (array_count != result.define_values.len) {
|
||||
result.define_values = try allocator.alloc([]u8, array_count);
|
||||
}
|
||||
length = try reader.readIntNative(u32);
|
||||
for (result.define_values) |content, j| {
|
||||
if (result.define_values[j].len != length) {
|
||||
result.define_values[j] = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.define_values[j]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
pub fn encode(result: *const @This(), writer: anytype) anyerror!void {
|
||||
var n: usize = 0;
|
||||
try result.jsx.encode(writer);
|
||||
|
||||
try writer.writeByte(@boolToInt(result.ts));
|
||||
|
||||
try writer.writeIntNative(u32, @intCast(u32, result.base_path.len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(result.base_path));
|
||||
|
||||
n = result.define_keys.len;
|
||||
_ = try writer.writeIntNative(u32, @intCast(u32, n));
|
||||
{
|
||||
var j: usize = 0;
|
||||
while (j < n) : (j += 1) {
|
||||
_ = try writer.writeIntNative(u32, @intCast(u32, result.define_keys[j].len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(result.define_keys[j]));
|
||||
}
|
||||
}
|
||||
|
||||
n = result.define_values.len;
|
||||
_ = try writer.writeIntNative(u32, @intCast(u32, n));
|
||||
{
|
||||
var j: usize = 0;
|
||||
while (j < n) : (j += 1) {
|
||||
_ = try writer.writeIntNative(u32, @intCast(u32, result.define_values[j].len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(result.define_values[j]));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
pub const FileHandle = struct {
|
||||
/// path
|
||||
path: []u8,
|
||||
|
||||
/// size
|
||||
size: u32 = 0,
|
||||
|
||||
/// fd
|
||||
fd: u32 = 0,
|
||||
|
||||
pub fn decode(allocator: *std.mem.Allocator, reader: anytype) anyerror!FileHandle {
|
||||
var obj = std.mem.zeroes(FileHandle);
|
||||
try update(&obj, allocator, reader);
|
||||
return obj;
|
||||
}
|
||||
pub fn update(result: *FileHandle, allocator: *std.mem.Allocator, reader: anytype) anyerror!void {
|
||||
var length: usize = 0;
|
||||
length = try reader.readIntNative(u32);
|
||||
if (result.path.len != length) {
|
||||
result.path = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.path);
|
||||
_ = try reader.readAll(std.mem.asBytes(&result.size));
|
||||
_ = try reader.readAll(std.mem.asBytes(&result.fd));
|
||||
return;
|
||||
}
|
||||
|
||||
pub fn encode(result: *const @This(), writer: anytype) anyerror!void {
|
||||
try writer.writeIntNative(u32, @intCast(u32, result.path.len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(result.path));
|
||||
|
||||
try writer.writeIntNative(u32, result.size);
|
||||
|
||||
try writer.writeIntNative(u32, result.fd);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
pub const Transform = struct {
|
||||
/// handle
|
||||
handle: ?FileHandle = null,
|
||||
|
||||
/// path
|
||||
path: ?[]u8 = null,
|
||||
|
||||
/// contents
|
||||
contents: ?[]u8 = null,
|
||||
|
||||
/// loader
|
||||
loader: ?Loader = null,
|
||||
|
||||
/// options
|
||||
options: ?TransformOptions = null,
|
||||
|
||||
pub fn decode(allocator: *std.mem.Allocator, reader: anytype) anyerror!Transform {
|
||||
var obj = std.mem.zeroes(Transform);
|
||||
try update(&obj, allocator, reader);
|
||||
return obj;
|
||||
}
|
||||
pub fn update(result: *Transform, allocator: *std.mem.Allocator, reader: anytype) anyerror!void {
|
||||
var length: usize = 0;
|
||||
while (true) {
|
||||
const field_type: u8 = try reader.readByte();
|
||||
switch (field_type) {
|
||||
0 => {
|
||||
return;
|
||||
},
|
||||
|
||||
1 => {
|
||||
result.handle = try FileHandle.decode(allocator, reader);
|
||||
},
|
||||
2 => {
|
||||
length = try reader.readIntNative(u32);
|
||||
if ((result.path orelse &([_]u8{})).len != length) {
|
||||
result.path = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.path.?);
|
||||
},
|
||||
3 => {
|
||||
length = try reader.readIntNative(u32);
|
||||
if ((result.contents orelse &([_]u8{})).len != length) {
|
||||
result.contents = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.contents.?);
|
||||
},
|
||||
4 => {
|
||||
result.loader = try reader.readEnum(Loader, .Little);
|
||||
},
|
||||
5 => {
|
||||
result.options = try TransformOptions.decode(allocator, reader);
|
||||
},
|
||||
else => {
|
||||
return error.InvalidMessage;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn encode(result: *const @This(), writer: anytype) anyerror!void {
|
||||
if (result.handle) |handle| {
|
||||
try writer.writeByte(1);
|
||||
try handle.encode(writer);
|
||||
}
|
||||
|
||||
if (result.path) |path| {
|
||||
try writer.writeByte(2);
|
||||
try writer.writeIntNative(u32, @intCast(u32, path.len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(path));
|
||||
}
|
||||
|
||||
if (result.contents) |contents| {
|
||||
try writer.writeByte(3);
|
||||
try writer.writeIntNative(u32, @intCast(u32, contents.len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(contents));
|
||||
}
|
||||
|
||||
if (result.loader) |loader| {
|
||||
try writer.writeByte(4);
|
||||
try writer.writeIntNative(@TypeOf(@enumToInt(result.loader orelse unreachable)), @enumToInt(result.loader orelse unreachable));
|
||||
}
|
||||
|
||||
if (result.options) |options| {
|
||||
try writer.writeByte(5);
|
||||
try options.encode(writer);
|
||||
}
|
||||
try writer.writeByte(0);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
pub const TransformResponseStatus = enum(u32) {
|
||||
_none,
|
||||
/// success
|
||||
success,
|
||||
|
||||
/// fail
|
||||
fail,
|
||||
|
||||
_,
|
||||
|
||||
pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void {
|
||||
return try std.json.stringify(@tagName(self), opts, o);
|
||||
}
|
||||
};
|
||||
|
||||
pub const OutputFile = struct {
|
||||
/// data
|
||||
data: []u8,
|
||||
|
||||
/// path
|
||||
path: []u8,
|
||||
|
||||
pub fn decode(allocator: *std.mem.Allocator, reader: anytype) anyerror!OutputFile {
|
||||
var obj = std.mem.zeroes(OutputFile);
|
||||
try update(&obj, allocator, reader);
|
||||
return obj;
|
||||
}
|
||||
pub fn update(result: *OutputFile, allocator: *std.mem.Allocator, reader: anytype) anyerror!void {
|
||||
var length: usize = 0;
|
||||
_ = try reader.readAll(result.data);
|
||||
length = try reader.readIntNative(u32);
|
||||
if (result.path.len != length) {
|
||||
result.path = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.path);
|
||||
return;
|
||||
}
|
||||
|
||||
pub fn encode(result: *const @This(), writer: anytype) anyerror!void {
|
||||
try writer.writeAll(result.data);
|
||||
|
||||
try writer.writeIntNative(u32, @intCast(u32, result.path.len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(result.path));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
pub const TransformResponse = struct {
|
||||
/// status
|
||||
status: TransformResponseStatus,
|
||||
|
||||
/// files
|
||||
files: []OutputFile,
|
||||
|
||||
/// errors
|
||||
errors: []Message,
|
||||
|
||||
pub fn decode(allocator: *std.mem.Allocator, reader: anytype) anyerror!TransformResponse {
|
||||
var obj = std.mem.zeroes(TransformResponse);
|
||||
try update(&obj, allocator, reader);
|
||||
return obj;
|
||||
}
|
||||
pub fn update(result: *TransformResponse, allocator: *std.mem.Allocator, reader: anytype) anyerror!void {
|
||||
var length: usize = 0;
|
||||
result.status = try reader.readEnum(TransformResponseStatus, .Little);
|
||||
length = try reader.readIntNative(u32);
|
||||
result.files = try allocator.alloc(OutputFile, length);
|
||||
{
|
||||
var j: usize = 0;
|
||||
while (j < length) : (j += 1) {
|
||||
result.files[j] = try OutputFile.decode(allocator, reader);
|
||||
}
|
||||
}
|
||||
length = try reader.readIntNative(u32);
|
||||
result.errors = try allocator.alloc(Message, length);
|
||||
{
|
||||
var j: usize = 0;
|
||||
while (j < length) : (j += 1) {
|
||||
result.errors[j] = try Message.decode(allocator, reader);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
pub fn encode(result: *const @This(), writer: anytype) anyerror!void {
|
||||
var n: usize = 0;
|
||||
try writer.writeIntNative(@TypeOf(@enumToInt(result.status)), @enumToInt(result.status));
|
||||
|
||||
n = result.files.len;
|
||||
_ = try writer.writeIntNative(u32, @intCast(u32, n));
|
||||
{
|
||||
var j: usize = 0;
|
||||
while (j < n) : (j += 1) {
|
||||
try result.files[j].encode(writer);
|
||||
}
|
||||
}
|
||||
|
||||
n = result.errors.len;
|
||||
_ = try writer.writeIntNative(u32, @intCast(u32, n));
|
||||
{
|
||||
var j: usize = 0;
|
||||
while (j < n) : (j += 1) {
|
||||
try result.errors[j].encode(writer);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
pub const MessageKind = enum(u32) {
|
||||
_none,
|
||||
/// err
|
||||
err,
|
||||
|
||||
/// warn
|
||||
warn,
|
||||
|
||||
/// note
|
||||
note,
|
||||
|
||||
/// debug
|
||||
debug,
|
||||
|
||||
_,
|
||||
|
||||
pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void {
|
||||
return try std.json.stringify(@tagName(self), opts, o);
|
||||
}
|
||||
};
|
||||
|
||||
pub const Location = struct {
|
||||
/// file
|
||||
file: []u8,
|
||||
|
||||
/// namespace
|
||||
namespace: []u8,
|
||||
|
||||
/// line
|
||||
line: i32 = 0,
|
||||
|
||||
/// column
|
||||
column: i32 = 0,
|
||||
|
||||
/// line_text
|
||||
line_text: []u8,
|
||||
|
||||
/// suggestion
|
||||
suggestion: []u8,
|
||||
|
||||
/// offset
|
||||
offset: u32 = 0,
|
||||
|
||||
pub fn decode(allocator: *std.mem.Allocator, reader: anytype) anyerror!Location {
|
||||
var obj = std.mem.zeroes(Location);
|
||||
try update(&obj, allocator, reader);
|
||||
return obj;
|
||||
}
|
||||
pub fn update(result: *Location, allocator: *std.mem.Allocator, reader: anytype) anyerror!void {
|
||||
var length: usize = 0;
|
||||
length = try reader.readIntNative(u32);
|
||||
if (result.file.len != length) {
|
||||
result.file = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.file);
|
||||
length = try reader.readIntNative(u32);
|
||||
if (result.namespace.len != length) {
|
||||
result.namespace = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.namespace);
|
||||
_ = try reader.readAll(std.mem.asBytes(&result.line));
|
||||
_ = try reader.readAll(std.mem.asBytes(&result.column));
|
||||
length = try reader.readIntNative(u32);
|
||||
if (result.line_text.len != length) {
|
||||
result.line_text = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.line_text);
|
||||
length = try reader.readIntNative(u32);
|
||||
if (result.suggestion.len != length) {
|
||||
result.suggestion = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.suggestion);
|
||||
_ = try reader.readAll(std.mem.asBytes(&result.offset));
|
||||
return;
|
||||
}
|
||||
|
||||
pub fn encode(result: *const @This(), writer: anytype) anyerror!void {
|
||||
try writer.writeIntNative(u32, @intCast(u32, result.file.len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(result.file));
|
||||
|
||||
try writer.writeIntNative(u32, @intCast(u32, result.namespace.len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(result.namespace));
|
||||
|
||||
try writer.writeIntNative(i32, result.line);
|
||||
|
||||
try writer.writeIntNative(i32, result.column);
|
||||
|
||||
try writer.writeIntNative(u32, @intCast(u32, result.line_text.len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(result.line_text));
|
||||
|
||||
try writer.writeIntNative(u32, @intCast(u32, result.suggestion.len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(result.suggestion));
|
||||
|
||||
try writer.writeIntNative(u32, result.offset);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
pub const MessageData = struct {
|
||||
/// text
|
||||
text: ?[]u8 = null,
|
||||
|
||||
/// location
|
||||
location: ?Location = null,
|
||||
|
||||
pub fn decode(allocator: *std.mem.Allocator, reader: anytype) anyerror!MessageData {
|
||||
var obj = std.mem.zeroes(MessageData);
|
||||
try update(&obj, allocator, reader);
|
||||
return obj;
|
||||
}
|
||||
pub fn update(result: *MessageData, allocator: *std.mem.Allocator, reader: anytype) anyerror!void {
|
||||
var length: usize = 0;
|
||||
while (true) {
|
||||
const field_type: u8 = try reader.readByte();
|
||||
switch (field_type) {
|
||||
0 => {
|
||||
return;
|
||||
},
|
||||
|
||||
1 => {
|
||||
length = try reader.readIntNative(u32);
|
||||
if ((result.text orelse &([_]u8{})).len != length) {
|
||||
result.text = try allocator.alloc(u8, length);
|
||||
}
|
||||
_ = try reader.readAll(result.text.?);
|
||||
},
|
||||
2 => {
|
||||
result.location = try Location.decode(allocator, reader);
|
||||
},
|
||||
else => {
|
||||
return error.InvalidMessage;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn encode(result: *const @This(), writer: anytype) anyerror!void {
|
||||
if (result.text) |text| {
|
||||
try writer.writeByte(1);
|
||||
try writer.writeIntNative(u32, @intCast(u32, text.len));
|
||||
try writer.writeAll(std.mem.sliceAsBytes(text));
|
||||
}
|
||||
|
||||
if (result.location) |location| {
|
||||
try writer.writeByte(2);
|
||||
try location.encode(writer);
|
||||
}
|
||||
try writer.writeByte(0);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
pub const Message = struct {
|
||||
/// kind
|
||||
kind: MessageKind,
|
||||
|
||||
/// data
|
||||
data: MessageData,
|
||||
|
||||
/// notes
|
||||
notes: []MessageData,
|
||||
|
||||
pub fn decode(allocator: *std.mem.Allocator, reader: anytype) anyerror!Message {
|
||||
var obj = std.mem.zeroes(Message);
|
||||
try update(&obj, allocator, reader);
|
||||
return obj;
|
||||
}
|
||||
pub fn update(result: *Message, allocator: *std.mem.Allocator, reader: anytype) anyerror!void {
|
||||
var length: usize = 0;
|
||||
result.kind = try reader.readEnum(MessageKind, .Little);
|
||||
result.data = try MessageData.decode(allocator, reader);
|
||||
length = try reader.readIntNative(u32);
|
||||
result.notes = try allocator.alloc(MessageData, length);
|
||||
{
|
||||
var j: usize = 0;
|
||||
while (j < length) : (j += 1) {
|
||||
result.notes[j] = try MessageData.decode(allocator, reader);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
pub fn encode(result: *const @This(), writer: anytype) anyerror!void {
|
||||
var n: usize = 0;
|
||||
try writer.writeIntNative(@TypeOf(@enumToInt(result.kind)), @enumToInt(result.kind));
|
||||
|
||||
try result.data.encode(writer);
|
||||
|
||||
n = result.notes.len;
|
||||
_ = try writer.writeIntNative(u32, @intCast(u32, n));
|
||||
{
|
||||
var j: usize = 0;
|
||||
while (j < n) : (j += 1) {
|
||||
try result.notes[j].encode(writer);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
pub const Log = struct {
|
||||
/// warnings
|
||||
warnings: u32 = 0,
|
||||
|
||||
/// errors
|
||||
errors: u32 = 0,
|
||||
|
||||
/// msgs
|
||||
msgs: []Message,
|
||||
|
||||
pub fn decode(allocator: *std.mem.Allocator, reader: anytype) anyerror!Log {
|
||||
var obj = std.mem.zeroes(Log);
|
||||
try update(&obj, allocator, reader);
|
||||
return obj;
|
||||
}
|
||||
pub fn update(result: *Log, allocator: *std.mem.Allocator, reader: anytype) anyerror!void {
|
||||
var length: usize = 0;
|
||||
_ = try reader.readAll(std.mem.asBytes(&result.warnings));
|
||||
_ = try reader.readAll(std.mem.asBytes(&result.errors));
|
||||
length = try reader.readIntNative(u32);
|
||||
result.msgs = try allocator.alloc(Message, length);
|
||||
{
|
||||
var j: usize = 0;
|
||||
while (j < length) : (j += 1) {
|
||||
result.msgs[j] = try Message.decode(allocator, reader);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
pub fn encode(result: *const @This(), writer: anytype) anyerror!void {
|
||||
var n: usize = 0;
|
||||
try writer.writeIntNative(u32, result.warnings);
|
||||
|
||||
try writer.writeIntNative(u32, result.errors);
|
||||
|
||||
n = result.msgs.len;
|
||||
_ = try writer.writeIntNative(u32, @intCast(u32, n));
|
||||
{
|
||||
var j: usize = 0;
|
||||
while (j < n) : (j += 1) {
|
||||
try result.msgs[j].encode(writer);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user