Skip to content

Commit

Permalink
feat: add types
Browse files Browse the repository at this point in the history
Takes the types from [@types/protocol-buffers-schema](https://www.npmjs.com/package/@types/protocol-buffers-schema)
and adds them to this module.

It swaps node `Buffer`s for `Uint8Array`s in the interfaces because
this module doesn't use any `Buffer` features that aren't available
on `Uint8Array`s which makes it a bit kinder to the browser.
  • Loading branch information
achingbrain committed Jan 25, 2021
1 parent 5de5b21 commit a1a4954
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

import { Schema } from "./types";
declare namespace parse {
function parse(buffer: string | Uint8Array): Schema;
function stringify(schema: Schema): string;
}

declare function parse(buffer: string | Uint8Array): Schema;

export = parse;
9 changes: 9 additions & 0 deletions parse.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Schema } from "./types";
declare namespace parse {
function parse(buffer: string | Uint8Array): Schema;
function stringify(schema: Schema): string;
}

declare function parse(buffer: string | Uint8Array): Schema;

export = parse;
Empty file added stringify.d.ts
Empty file.
5 changes: 5 additions & 0 deletions tokenize.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Schema } from "./types";

declare function tokenize(schema: Schema): string[];

export = tokenize;
82 changes: 82 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
export interface Option {
[key: string]: string | boolean;
}

export interface Options {
[key: string]: string | boolean | Option | Option[];
}

export interface Enum {
name: string;
values: {
[key: string]: {
value: number;
options: Options;
};
};
options: Options;
}

export interface FieldOptions {
[key: string]: string;
}

export interface Field {
name: string;
type: string;
tag: number;
map: {
from: string;
to: string;
};
oneof: null | string;
required: boolean;
repeated: boolean;
options: FieldOptions;
}

export interface Message {
name: string;
enums: Enum[];
extends: Extend[];
extensions: Extension[];
messages: Message[];
options: Options;
fields: Field[];
}

export interface Extend {
name: string;
message: Message;
}

export interface Extension {
from: number;
to: number;
}

export interface Service {
name: string;
methods: Method[];
options: Options;
}

export interface Method {
name: string;
input_type: string;
output_type: string;
client_streaming: boolean;
server_streaming: boolean;
options: Options;
}

export interface Schema {
syntax: number;
package: null | string;
imports: string[];
enums: Enum[];
messages: Message[];
options: Options;
extends: Extend[];
services?: Service[];
}

0 comments on commit a1a4954

Please sign in to comment.