Skip to content

Commit

Permalink
feat: move generation into src
Browse files Browse the repository at this point in the history
  • Loading branch information
Sceat committed Aug 9, 2024
1 parent 25ac6d2 commit e501d67
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 133 deletions.
2 changes: 1 addition & 1 deletion buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ version: v1
plugins:
- plugin: es
opt: target=js
out: generated
out: src/generated
237 changes: 142 additions & 95 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
{
"name": "@aresrpg/aresrpg-protocol",
"version": "5.0.6",
"main": "src/index.js",
"type": "module",
"typings": "types/src/index.d.ts",
"scripts": {
"proto": "npx buf generate proto",
"lint": "eslint . && prettier . --check && npm run typecheck",
"typecheck": "tsc --build",
"format": "prettier . --write && eslint . --fix",
"postversion": "git push --follow-tags"
},
"engines": {
"node": ">=21.0.0"
},
"exports": {
".": {
"import": "./src/index.js",
"types": "./types/index.d.ts"
},
"./types": "./types.d.ts"
},
"dependencies": {
"@bufbuild/buf": "^1.35.1",
"@bufbuild/buf": "^1.36.0",
"@bufbuild/protobuf": "^2.0.0",
"@bufbuild/protoc-gen-es": "^2.0.0",
"spiralloop": "^1.0.2"
Expand All @@ -23,7 +31,6 @@
"keywords": [],
"author": "sceat",
"license": "ISC",
"types": "src/types.d.ts",
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/eslint-parser": "7.25.1",
Expand All @@ -36,7 +43,7 @@
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "^6.6.0",
"husky": "^4.3.8",
"lint-staged": "15.2.7",
"lint-staged": "15.2.8",
"prettier": "3.3.3",
"typescript": "5.5.4"
},
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PassThrough } from 'stream'

import { fromBinary, fromJson, toBinary, toJson } from '@bufbuild/protobuf'

import * as Packets from '../generated/ares_pb.js'
import * as Packets from './generated/ares_pb.js'

export function create_client({ socket_write, socket_end }) {
const controller = new AbortController()
Expand All @@ -16,7 +16,7 @@ export function create_client({ socket_write, socket_end }) {
return {
controller,
stream,
/** @type {import("./types.js").send} */
/** @type {import("../types.js").send} */
send(raw_type, data) {
const type = raw_type.slice(7)
try {
Expand Down
20 changes: 10 additions & 10 deletions src/types.d.ts → types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type EventMap = Record<string, any>
type Await<T> = T extends Promise<infer U> ? U : T
type EventName<T extends EventMap> = string & keyof T
type EventListener<T> = (arg: T) => void
export type EventMap = Record<string, any>
export type Await<T> = T extends Promise<infer U> ? U : T
export type EventName<T extends EventMap> = string & keyof T
export type EventListener<T> = (arg: T) => void

export interface TypedEmitter<T extends EventMap> {
on<K extends EventName<T>>(eventName: K, listener: EventListener<T[K]>): this
Expand Down Expand Up @@ -29,13 +29,13 @@ export interface TypedEmitter<T extends EventMap> {
removeAllListeners(): this
}

type Position = {
export type Position = {
x: number
y: number
z: number
}

type Entity = {
export type Entity = {
id: string
name: string
type: string
Expand All @@ -54,13 +54,13 @@ type Entity = {
effects: string[]
}

type EntityGroup = {
export type EntityGroup = {
id: string
position: Position
entities: Entity[]
}

type Fight = {
export type Fight = {
id: string
team1: Entity[]
team2: Entity[]
Expand All @@ -75,7 +75,7 @@ type Fight = {
start_time: number
}

type Packets = {
export type Packets = {
packet: { type: string; payload: any }
'packet/signatureRequest': { payload: string } // server -> client
'packet/signatureResponse': { bytes: string; signature: string; zk: boolean } // client -> server
Expand All @@ -101,7 +101,7 @@ type Packets = {
'packet/requestResponse': { id: string; message: string } // server <-> client
}

type Packet = {
export type Packet = {
[K in keyof Packets]: { type: K; payload: Packets[K] }
}[keyof Packets]

Expand Down
4 changes: 2 additions & 2 deletions types/src/index.d.ts → types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export function create_client({ socket_write, socket_end }: {
}): {
controller: AbortController;
stream: PassThrough;
/** @type {import("./types.js").send} */
send<T extends keyof import("./types.js").Packets>(type: T, payload: import("./types.js").Packets[T]): void;
/** @type {import("../types.js").send} */
send<T extends keyof import("../types.js").Packets>(type: T, payload: import("../types.js").Packets[T]): void;
/** @type {(message: string) => void} */
end(message: string): void;
on_end: (handler: any) => any;
Expand Down
17 changes: 0 additions & 17 deletions types/src/chunk.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion types/src/create_spell.d.ts

This file was deleted.

0 comments on commit e501d67

Please sign in to comment.