protons 3.0.4 → 4.0.1
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 +22 -4
- package/dist/bin/protons.js +0 -0
- package/dist/src/index.d.ts +5 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -5
- package/dist/src/index.js.map +1 -1
- package/package.json +16 -10
- package/src/index.ts +15 -6
package/README.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
# protons <!-- omit in toc -->
|
|
2
2
|
|
|
3
|
-
[](http://ipfs.io)
|
|
4
|
+
[](http://webchat.freenode.net/?channels=%23ipfs)
|
|
5
|
+
[](https://discord.gg/ipfs)
|
|
6
|
+
[](https://codecov.io/gh/ipfs/protons)
|
|
7
|
+
[](https://github.com/ipfs/protons/actions/workflows/js-test-and-release.yml)
|
|
4
8
|
|
|
5
|
-
>
|
|
9
|
+
> Protobuf to ts transpiler
|
|
6
10
|
|
|
7
11
|
## Table of contents <!-- omit in toc -->
|
|
8
12
|
|
|
@@ -10,10 +14,13 @@
|
|
|
10
14
|
- [Usage](#usage)
|
|
11
15
|
- [Contribute](#contribute)
|
|
12
16
|
- [License](#license)
|
|
17
|
+
- [Contribute](#contribute-1)
|
|
13
18
|
|
|
14
19
|
## Install
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
```console
|
|
22
|
+
$ npm i protons
|
|
23
|
+
```
|
|
17
24
|
|
|
18
25
|
`protons` contains the code to compile `.proto` files to `.ts` files and `protons-runtime` contains the code to do serialization/deserialization to `Uint8Array`s during application execution.
|
|
19
26
|
|
|
@@ -62,4 +69,15 @@ This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/c
|
|
|
62
69
|
|
|
63
70
|
## License
|
|
64
71
|
|
|
65
|
-
|
|
72
|
+
Licensed under either of
|
|
73
|
+
|
|
74
|
+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
75
|
+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
76
|
+
|
|
77
|
+
## Contribute
|
|
78
|
+
|
|
79
|
+
Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs-unixfs-importer/issues)!
|
|
80
|
+
|
|
81
|
+
This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
|
|
82
|
+
|
|
83
|
+
[](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
|
package/dist/bin/protons.js
CHANGED
|
File without changes
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAgSA,UAAU,KAAK;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,wBAAsB,QAAQ,CAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,iBAsC3D"}
|
package/dist/src/index.js
CHANGED
|
@@ -2,8 +2,9 @@ import { main as pbjs } from 'protobufjs/cli/pbjs.js';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { promisify } from 'util';
|
|
4
4
|
import fs from 'fs/promises';
|
|
5
|
-
function pathWithExtension(input, extension) {
|
|
6
|
-
|
|
5
|
+
function pathWithExtension(input, extension, outputDir) {
|
|
6
|
+
const output = outputDir ?? path.dirname(input);
|
|
7
|
+
return path.join(output, path.basename(input).split('.').slice(0, -1).join('.') + extension);
|
|
7
8
|
}
|
|
8
9
|
const types = {
|
|
9
10
|
double: 'number',
|
|
@@ -157,11 +158,11 @@ export interface ${messageDef.name} {
|
|
|
157
158
|
})
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
export const encode = (obj: ${messageDef.name}):
|
|
161
|
+
export const encode = (obj: ${messageDef.name}): Uint8ArrayList => {
|
|
161
162
|
return encodeMessage(obj, ${messageDef.name}.codec())
|
|
162
163
|
}
|
|
163
164
|
|
|
164
|
-
export const decode = (buf: Uint8Array): ${messageDef.name} => {
|
|
165
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): ${messageDef.name} => {
|
|
165
166
|
return decodeMessage(buf, ${messageDef.name}.codec())
|
|
166
167
|
}`;
|
|
167
168
|
}
|
|
@@ -225,12 +226,15 @@ export async function generate(source, flags) {
|
|
|
225
226
|
if (moduleDef.importedTypes.size > 0) {
|
|
226
227
|
lines.push(`import type { ${Array.from(moduleDef.importedTypes).join(', ')} } from 'protons-runtime'`);
|
|
227
228
|
}
|
|
229
|
+
if (moduleDef.imports.has('encodeMessage')) {
|
|
230
|
+
lines.push("import type { Uint8ArrayList } from 'uint8arraylist'");
|
|
231
|
+
}
|
|
228
232
|
lines = [
|
|
229
233
|
...lines,
|
|
230
234
|
'',
|
|
231
235
|
...moduleDef.compiled
|
|
232
236
|
];
|
|
233
237
|
const content = lines.join('\n').trim();
|
|
234
|
-
await fs.writeFile(pathWithExtension(source, '.ts'), content + '\n');
|
|
238
|
+
await fs.writeFile(pathWithExtension(source, '.ts', flags.output), content + '\n');
|
|
235
239
|
}
|
|
236
240
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,IAAI,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,MAAM,aAAa,CAAA;AAE5B,SAAS,iBAAiB,CAAE,KAAa,EAAE,SAAiB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index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,CAAA;IAEnC,IAAI,KAAK,GAAG;QACV,oCAAoC;QACpC,sDAAsD;QACtD,EAAE;KACH,CAAA;IAED,IAAI,SAAS,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,EAAE;QAC9B,KAAK,CAAC,IAAI,CAAC,YAAY,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAA;KAC5F;IAED,IAAI,SAAS,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,EAAE;QACpC,KAAK,CAAC,IAAI,CAAC,iBAAiB,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAA;KACvG;IAED,IAAI,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE;QAC1C,KAAK,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAA;KACnE;IAED,KAAK,GAAG;QACN,GAAG,KAAK;QACR,EAAE;QACF,GAAG,SAAS,CAAC,QAAQ;KACtB,CAAA;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAA;IAEvC,MAAM,EAAE,CAAC,SAAS,CAAC,iBAAiB,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC,CAAA;AACpF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protons",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Protobuf to ts transpiler",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/protons/tree/master/packages/protons#readme",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
],
|
|
45
45
|
"exports": {
|
|
46
46
|
".": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"types": "./dist/src/index.d.ts",
|
|
48
|
+
"import": "./dist/src/index.js"
|
|
49
49
|
},
|
|
50
50
|
"./status": {
|
|
51
|
-
"
|
|
52
|
-
"
|
|
51
|
+
"types": "./dist/src/status.d.ts",
|
|
52
|
+
"import": "./dist/src/status.js"
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"eslintConfig": {
|
|
@@ -85,15 +85,15 @@
|
|
|
85
85
|
"release": "patch"
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
|
-
"type": "
|
|
88
|
+
"type": "docs",
|
|
89
89
|
"release": "patch"
|
|
90
90
|
},
|
|
91
91
|
{
|
|
92
|
-
"type": "
|
|
92
|
+
"type": "test",
|
|
93
93
|
"release": "patch"
|
|
94
94
|
},
|
|
95
95
|
{
|
|
96
|
-
"type": "
|
|
96
|
+
"type": "deps",
|
|
97
97
|
"release": "patch"
|
|
98
98
|
},
|
|
99
99
|
{
|
|
@@ -123,7 +123,11 @@
|
|
|
123
123
|
},
|
|
124
124
|
{
|
|
125
125
|
"type": "docs",
|
|
126
|
-
"section": "
|
|
126
|
+
"section": "Documentation"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"type": "deps",
|
|
130
|
+
"section": "Dependencies"
|
|
127
131
|
},
|
|
128
132
|
{
|
|
129
133
|
"type": "test",
|
|
@@ -140,6 +144,7 @@
|
|
|
140
144
|
]
|
|
141
145
|
},
|
|
142
146
|
"scripts": {
|
|
147
|
+
"clean": "aegir clean",
|
|
143
148
|
"lint": "aegir lint",
|
|
144
149
|
"dep-check": "aegir dep-check",
|
|
145
150
|
"build": "aegir build",
|
|
@@ -154,6 +159,7 @@
|
|
|
154
159
|
"devDependencies": {
|
|
155
160
|
"aegir": "^37.0.5",
|
|
156
161
|
"pbjs": "^0.0.14",
|
|
157
|
-
"protons-runtime": "^
|
|
162
|
+
"protons-runtime": "^2.0.0",
|
|
163
|
+
"uint8arraylist": "^2.0.0"
|
|
158
164
|
}
|
|
159
165
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,8 +3,9 @@ import path from 'path'
|
|
|
3
3
|
import { promisify } from 'util'
|
|
4
4
|
import fs from 'fs/promises'
|
|
5
5
|
|
|
6
|
-
function pathWithExtension (input: string, extension: string) {
|
|
7
|
-
|
|
6
|
+
function pathWithExtension (input: string, extension: string, outputDir?: string) {
|
|
7
|
+
const output = outputDir ?? path.dirname(input)
|
|
8
|
+
return path.join(output, path.basename(input).split('.').slice(0, -1).join('.') + extension)
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
const types: Record<string, string> = {
|
|
@@ -215,11 +216,11 @@ export interface ${messageDef.name} {
|
|
|
215
216
|
})
|
|
216
217
|
}
|
|
217
218
|
|
|
218
|
-
export const encode = (obj: ${messageDef.name}):
|
|
219
|
+
export const encode = (obj: ${messageDef.name}): Uint8ArrayList => {
|
|
219
220
|
return encodeMessage(obj, ${messageDef.name}.codec())
|
|
220
221
|
}
|
|
221
222
|
|
|
222
|
-
export const decode = (buf: Uint8Array): ${messageDef.name} => {
|
|
223
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): ${messageDef.name} => {
|
|
223
224
|
return decodeMessage(buf, ${messageDef.name}.codec())
|
|
224
225
|
}`
|
|
225
226
|
}
|
|
@@ -285,7 +286,11 @@ function defineModule (def: ClassDef): ModuleDef {
|
|
|
285
286
|
return moduleDef
|
|
286
287
|
}
|
|
287
288
|
|
|
288
|
-
|
|
289
|
+
interface Flags {
|
|
290
|
+
output?: string
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export async function generate (source: string, flags: Flags) {
|
|
289
294
|
// convert .protobuf to .json
|
|
290
295
|
const json = await promisify(pbjs)(['-t', 'json', source])
|
|
291
296
|
|
|
@@ -310,6 +315,10 @@ export async function generate (source: string, flags: any) {
|
|
|
310
315
|
lines.push(`import type { ${Array.from(moduleDef.importedTypes).join(', ')} } from 'protons-runtime'`)
|
|
311
316
|
}
|
|
312
317
|
|
|
318
|
+
if (moduleDef.imports.has('encodeMessage')) {
|
|
319
|
+
lines.push("import type { Uint8ArrayList } from 'uint8arraylist'")
|
|
320
|
+
}
|
|
321
|
+
|
|
313
322
|
lines = [
|
|
314
323
|
...lines,
|
|
315
324
|
'',
|
|
@@ -318,5 +327,5 @@ export async function generate (source: string, flags: any) {
|
|
|
318
327
|
|
|
319
328
|
const content = lines.join('\n').trim()
|
|
320
329
|
|
|
321
|
-
await fs.writeFile(pathWithExtension(source, '.ts'), content + '\n')
|
|
330
|
+
await fs.writeFile(pathWithExtension(source, '.ts', flags.output), content + '\n')
|
|
322
331
|
}
|