Skip to content

Commit 7eb8f86

Browse files
committed
feat(cli): allow directly passing path to capnp files
1 parent 7107a56 commit 7eb8f86

File tree

8 files changed

+160
-128
lines changed

8 files changed

+160
-128
lines changed

.prettierignore

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
CHANGELOG.md
2+
pnpm-lock.yaml
3+
14
test/fixtures/*.*
2-
playground/*.{js,ts}
5+
6+
playground/*.ts
37
playground/*.d.ts
4-
CHANGELOG.md
8+
playground/*.js
9+

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ This project is a rework<sup>1</sup> of [jdiaz5513/capnp-ts](https://github.com/
4646
Run the following to compile a schema file into typeScript/javascript source code:
4747

4848
```shell
49+
npx capnp-es --ts --dts --js path/to/myschema.capnp
50+
# or pipe
4951
capnpc -o- path/to/myschema.capnp | npx capnp-es --ts --dts --js
5052
```
5153

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"lint": "eslint . && prettier -c .",
3939
"lint:fix": "automd && eslint . --fix && prettier -w .",
4040
"prepack": "pnpm build",
41-
"play": "capnpc -o- playground/addressbook.capnp | pnpm capnp-es --ts",
41+
"play": "pnpm capnp-es --ts --js --dts playground/*.capnp",
4242
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
4343
"test": "pnpm lint && vitest run --coverage && pnpm test:types",
4444
"test:types": "tsc --noEmit --skipLibCheck"

playground/addressbook.d.ts

+84-78
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,94 @@
11
import * as capnp from "capnp-es";
22
export declare const _capnpFileId: bigint;
3-
export declare enum Person_PhoneNumber_Type {
4-
MOBILE = 0,
5-
HOME = 1,
6-
WORK = 2
7-
}
3+
export declare const Person_PhoneNumber_Type: {
4+
readonly MOBILE: 0;
5+
readonly HOME: 1;
6+
readonly WORK: 2;
7+
};
8+
export type Person_PhoneNumber_Type = (typeof Person_PhoneNumber_Type)[keyof typeof Person_PhoneNumber_Type];
89
export declare class Person_PhoneNumber extends capnp.Struct {
9-
static readonly Type: typeof Person_PhoneNumber_Type;
10-
static readonly _capnp: {
11-
displayName: string;
12-
id: string;
13-
size: capnp.ObjectSize;
14-
};
15-
getNumber(): string;
16-
setNumber(value: string): void;
17-
getType(): Person_PhoneNumber_Type;
18-
setType(value: Person_PhoneNumber_Type): void;
19-
toString(): string;
20-
}
21-
export declare enum Person_Employment_Which {
22-
UNEMPLOYED = 0,
23-
EMPLOYER = 1,
24-
SCHOOL = 2,
25-
SELF_EMPLOYED = 3
10+
static readonly Type: {
11+
readonly MOBILE: 0;
12+
readonly HOME: 1;
13+
readonly WORK: 2;
14+
};
15+
static readonly _capnp: {
16+
displayName: string;
17+
id: string;
18+
size: capnp.ObjectSize;
19+
};
20+
getNumber(): string;
21+
setNumber(value: string): void;
22+
getType(): Person_PhoneNumber_Type;
23+
setType(value: Person_PhoneNumber_Type): void;
24+
toString(): string;
2625
}
26+
export declare const Person_Employment_Which: {
27+
readonly UNEMPLOYED: 0;
28+
readonly EMPLOYER: 1;
29+
readonly SCHOOL: 2;
30+
readonly SELF_EMPLOYED: 3;
31+
};
32+
export type Person_Employment_Which = (typeof Person_Employment_Which)[keyof typeof Person_Employment_Which];
2733
export declare class Person_Employment extends capnp.Struct {
28-
static readonly UNEMPLOYED = Person_Employment_Which.UNEMPLOYED;
29-
static readonly EMPLOYER = Person_Employment_Which.EMPLOYER;
30-
static readonly SCHOOL = Person_Employment_Which.SCHOOL;
31-
static readonly SELF_EMPLOYED = Person_Employment_Which.SELF_EMPLOYED;
32-
static readonly _capnp: {
33-
displayName: string;
34-
id: string;
35-
size: capnp.ObjectSize;
36-
};
37-
isUnemployed(): boolean;
38-
setUnemployed(): void;
39-
getEmployer(): string;
40-
isEmployer(): boolean;
41-
setEmployer(value: string): void;
42-
getSchool(): string;
43-
isSchool(): boolean;
44-
setSchool(value: string): void;
45-
isSelfEmployed(): boolean;
46-
setSelfEmployed(): void;
47-
toString(): string;
48-
which(): Person_Employment_Which;
34+
static readonly UNEMPLOYED: 0;
35+
static readonly EMPLOYER: 1;
36+
static readonly SCHOOL: 2;
37+
static readonly SELF_EMPLOYED: 3;
38+
static readonly _capnp: {
39+
displayName: string;
40+
id: string;
41+
size: capnp.ObjectSize;
42+
};
43+
isUnemployed(): boolean;
44+
setUnemployed(): void;
45+
getEmployer(): string;
46+
isEmployer(): boolean;
47+
setEmployer(value: string): void;
48+
getSchool(): string;
49+
isSchool(): boolean;
50+
setSchool(value: string): void;
51+
isSelfEmployed(): boolean;
52+
setSelfEmployed(): void;
53+
toString(): string;
54+
which(): Person_Employment_Which;
4955
}
5056
export declare class Person extends capnp.Struct {
51-
static readonly PhoneNumber: typeof Person_PhoneNumber;
52-
static readonly _capnp: {
53-
displayName: string;
54-
id: string;
55-
size: capnp.ObjectSize;
56-
};
57-
static _Phones: capnp.ListCtor<Person_PhoneNumber>;
58-
getId(): number;
59-
setId(value: number): void;
60-
getName(): string;
61-
setName(value: string): void;
62-
getEmail(): string;
63-
setEmail(value: string): void;
64-
adoptPhones(value: capnp.Orphan<capnp.List<Person_PhoneNumber>>): void;
65-
disownPhones(): capnp.Orphan<capnp.List<Person_PhoneNumber>>;
66-
getPhones(): capnp.List<Person_PhoneNumber>;
67-
hasPhones(): boolean;
68-
initPhones(length: number): capnp.List<Person_PhoneNumber>;
69-
setPhones(value: capnp.List<Person_PhoneNumber>): void;
70-
getEmployment(): Person_Employment;
71-
initEmployment(): Person_Employment;
72-
toString(): string;
57+
static readonly PhoneNumber: typeof Person_PhoneNumber;
58+
static readonly _capnp: {
59+
displayName: string;
60+
id: string;
61+
size: capnp.ObjectSize;
62+
};
63+
static _Phones: capnp.ListCtor<Person_PhoneNumber>;
64+
getId(): number;
65+
setId(value: number): void;
66+
getName(): string;
67+
setName(value: string): void;
68+
getEmail(): string;
69+
setEmail(value: string): void;
70+
adoptPhones(value: capnp.Orphan<capnp.List<Person_PhoneNumber>>): void;
71+
disownPhones(): capnp.Orphan<capnp.List<Person_PhoneNumber>>;
72+
getPhones(): capnp.List<Person_PhoneNumber>;
73+
hasPhones(): boolean;
74+
initPhones(length: number): capnp.List<Person_PhoneNumber>;
75+
setPhones(value: capnp.List<Person_PhoneNumber>): void;
76+
getEmployment(): Person_Employment;
77+
initEmployment(): Person_Employment;
78+
toString(): string;
7379
}
7480
export declare class AddressBook extends capnp.Struct {
75-
static readonly _capnp: {
76-
displayName: string;
77-
id: string;
78-
size: capnp.ObjectSize;
79-
};
80-
static _People: capnp.ListCtor<Person>;
81-
adoptPeople(value: capnp.Orphan<capnp.List<Person>>): void;
82-
disownPeople(): capnp.Orphan<capnp.List<Person>>;
83-
getPeople(): capnp.List<Person>;
84-
hasPeople(): boolean;
85-
initPeople(length: number): capnp.List<Person>;
86-
setPeople(value: capnp.List<Person>): void;
87-
toString(): string;
81+
static readonly _capnp: {
82+
displayName: string;
83+
id: string;
84+
size: capnp.ObjectSize;
85+
};
86+
static _People: capnp.ListCtor<Person>;
87+
adoptPeople(value: capnp.Orphan<capnp.List<Person>>): void;
88+
disownPeople(): capnp.Orphan<capnp.List<Person>>;
89+
getPeople(): capnp.List<Person>;
90+
hasPeople(): boolean;
91+
initPeople(length: number): capnp.List<Person>;
92+
setPeople(value: capnp.List<Person>): void;
93+
toString(): string;
8894
}

playground/addressbook.js

+22-27
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// This file has been automatically generated by capnp-es.
22
import * as capnp from "capnp-es";
33
export const _capnpFileId = BigInt("0xef1b5abe02e1f8d4");
4-
export const PersonPhoneNumberType = {
4+
export const Person_PhoneNumber_Type = {
55
MOBILE: 0,
66
HOME: 1,
7-
WORK: 2,
7+
WORK: 2
88
};
9-
export class PersonPhoneNumber extends capnp.Struct {
10-
static Type = PersonPhoneNumberType;
9+
export class Person_PhoneNumber extends capnp.Struct {
10+
static Type = Person_PhoneNumber_Type;
1111
static _capnp = {
1212
displayName: "PhoneNumber",
1313
id: "af663da31c027e0e",
14-
size: new capnp.ObjectSize(8, 1),
14+
size: new capnp.ObjectSize(8, 1)
1515
};
1616
getNumber() {
1717
return capnp.Struct.getText(0, this);
@@ -26,24 +26,24 @@ export class PersonPhoneNumber extends capnp.Struct {
2626
capnp.Struct.setUint16(0, value, this);
2727
}
2828
toString() {
29-
return "PersonPhoneNumber_" + super.toString();
29+
return "Person_PhoneNumber_" + super.toString();
3030
}
3131
}
32-
export const PersonEmployment_Which = {
32+
export const Person_Employment_Which = {
3333
UNEMPLOYED: 0,
3434
EMPLOYER: 1,
3535
SCHOOL: 2,
36-
SELF_EMPLOYED: 3,
36+
SELF_EMPLOYED: 3
3737
};
38-
export class PersonEmployment extends capnp.Struct {
39-
static UNEMPLOYED = PersonEmployment_Which.UNEMPLOYED;
40-
static EMPLOYER = PersonEmployment_Which.EMPLOYER;
41-
static SCHOOL = PersonEmployment_Which.SCHOOL;
42-
static SELF_EMPLOYED = PersonEmployment_Which.SELF_EMPLOYED;
38+
export class Person_Employment extends capnp.Struct {
39+
static UNEMPLOYED = Person_Employment_Which.UNEMPLOYED;
40+
static EMPLOYER = Person_Employment_Which.EMPLOYER;
41+
static SCHOOL = Person_Employment_Which.SCHOOL;
42+
static SELF_EMPLOYED = Person_Employment_Which.SELF_EMPLOYED;
4343
static _capnp = {
4444
displayName: "employment",
4545
id: "e88780a90af3da0c",
46-
size: new capnp.ObjectSize(8, 4),
46+
size: new capnp.ObjectSize(8, 4)
4747
};
4848
isUnemployed() {
4949
return capnp.Struct.getUint16(4, this) === 0;
@@ -52,12 +52,7 @@ export class PersonEmployment extends capnp.Struct {
5252
capnp.Struct.setUint16(4, 0, this);
5353
}
5454
getEmployer() {
55-
capnp.Struct.testWhich(
56-
"employer",
57-
capnp.Struct.getUint16(4, this),
58-
1,
59-
this,
60-
);
55+
capnp.Struct.testWhich("employer", capnp.Struct.getUint16(4, this), 1, this);
6156
return capnp.Struct.getText(3, this);
6257
}
6358
isEmployer() {
@@ -85,18 +80,18 @@ export class PersonEmployment extends capnp.Struct {
8580
capnp.Struct.setUint16(4, 3, this);
8681
}
8782
toString() {
88-
return "PersonEmployment_" + super.toString();
83+
return "Person_Employment_" + super.toString();
8984
}
9085
which() {
9186
return capnp.Struct.getUint16(4, this);
9287
}
9388
}
9489
export class Person extends capnp.Struct {
95-
static PhoneNumber = PersonPhoneNumber;
90+
static PhoneNumber = Person_PhoneNumber;
9691
static _capnp = {
9792
displayName: "Person",
9893
id: "d94307c4985be8e7",
99-
size: new capnp.ObjectSize(8, 4),
94+
size: new capnp.ObjectSize(8, 4)
10095
};
10196
static _Phones;
10297
getId() {
@@ -136,10 +131,10 @@ export class Person extends capnp.Struct {
136131
capnp.Struct.copyFrom(value, capnp.Struct.getPointer(2, this));
137132
}
138133
getEmployment() {
139-
return capnp.Struct.getAs(PersonEmployment, this);
134+
return capnp.Struct.getAs(Person_Employment, this);
140135
}
141136
initEmployment() {
142-
return capnp.Struct.getAs(PersonEmployment, this);
137+
return capnp.Struct.getAs(Person_Employment, this);
143138
}
144139
toString() {
145140
return "Person_" + super.toString();
@@ -149,7 +144,7 @@ export class AddressBook extends capnp.Struct {
149144
static _capnp = {
150145
displayName: "AddressBook",
151146
id: "c06ea6d038a357bb",
152-
size: new capnp.ObjectSize(0, 1),
147+
size: new capnp.ObjectSize(0, 1)
153148
};
154149
static _People;
155150
adoptPeople(value) {
@@ -174,5 +169,5 @@ export class AddressBook extends capnp.Struct {
174169
return "AddressBook_" + super.toString();
175170
}
176171
}
177-
Person._Phones = capnp.CompositeList(PersonPhoneNumber);
172+
Person._Phones = capnp.CompositeList(Person_PhoneNumber);
178173
AddressBook._People = capnp.CompositeList(Person);

0 commit comments

Comments
 (0)