protons 2.0.3 → 3.0.0
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/LICENSE +3 -20
- package/README.md +31 -124
- package/dist/bin/protons.js +34 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +206 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +149 -71
- package/src/index.ts +282 -0
- package/.aegir.js +0 -11
- package/.github/ISSUE_TEMPLATE/config.yml +0 -8
- package/.github/ISSUE_TEMPLATE/open_an_issue.md +0 -19
- package/.github/config.yml +0 -68
- package/.github/workflows/main.yml +0 -79
- package/CHANGELOG.md +0 -93
- package/bench/bench.proto.js +0 -30
- package/bench/index.js +0 -57
- package/example.js +0 -19
- package/example.proto +0 -4
- package/src/compile/decode.js +0 -330
- package/src/compile/encode.js +0 -133
- package/src/compile/encoding-length.js +0 -102
- package/src/compile/encodings/bool.js +0 -21
- package/src/compile/encodings/bytes.js +0 -42
- package/src/compile/encodings/double.js +0 -21
- package/src/compile/encodings/encoder.js +0 -14
- package/src/compile/encodings/fixed32.js +0 -21
- package/src/compile/encodings/fixed64.js +0 -25
- package/src/compile/encodings/float.js +0 -21
- package/src/compile/encodings/index.js +0 -22
- package/src/compile/encodings/int32.js +0 -22
- package/src/compile/encodings/int64.js +0 -49
- package/src/compile/encodings/sfixed32.js +0 -21
- package/src/compile/encodings/sint64.js +0 -19
- package/src/compile/encodings/string.js +0 -41
- package/src/compile/encodings/varint.js +0 -19
- package/src/compile/index.js +0 -165
- package/src/compile/utils.js +0 -5
- package/src/index.js +0 -39
- package/test/basic.spec.js +0 -109
- package/test/booleans.spec.js +0 -37
- package/test/bytes.spec.js +0 -36
- package/test/corrupted.spec.js +0 -50
- package/test/custom-types.spec.js +0 -55
- package/test/defaults.spec.js +0 -44
- package/test/enums.spec.js +0 -21
- package/test/float.spec.js +0 -28
- package/test/integers.spec.js +0 -72
- package/test/map.spec.js +0 -35
- package/test/nan.spec.js +0 -28
- package/test/nested.spec.js +0 -70
- package/test/notpacked.spec.js +0 -33
- package/test/oneof.spec.js +0 -59
- package/test/optional.spec.js +0 -65
- package/test/packed.spec.js +0 -61
- package/test/repeated.spec.js +0 -74
- package/test/strings.spec.js +0 -45
- package/test/test.proto.js +0 -134
- package/test/utf-8.spec.js +0 -21
package/package.json
CHANGED
|
@@ -1,83 +1,161 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protons",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Protobuf to ts transpiler",
|
|
5
|
+
"license": "Apache-2.0 OR MIT",
|
|
6
|
+
"homepage": "https://github.com/ipfs/protons/tree/master/packages/protons#readme",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/ipfs/protons"
|
|
9
|
+
"url": "git+https://github.com/ipfs/protons.git"
|
|
9
10
|
},
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"signed-varint": "^2.0.1",
|
|
13
|
-
"uint8arrays": "^3.0.0",
|
|
14
|
-
"varint": "^5.0.0"
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/ipfs/protons/issues"
|
|
15
13
|
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=16.0.0",
|
|
16
|
+
"npm": ">=7.0.0"
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"protons": "./dist/bin/protons.js"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"types": "./dist/src/index.d.ts",
|
|
23
|
+
"typesVersions": {
|
|
24
|
+
"*": {
|
|
25
|
+
"*": [
|
|
26
|
+
"*",
|
|
27
|
+
"dist/*",
|
|
28
|
+
"dist/src/*",
|
|
29
|
+
"dist/src/*/index"
|
|
30
|
+
],
|
|
31
|
+
"src/*": [
|
|
32
|
+
"*",
|
|
33
|
+
"dist/*",
|
|
34
|
+
"dist/src/*",
|
|
35
|
+
"dist/src/*/index"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"src",
|
|
41
|
+
"dist/src",
|
|
42
|
+
"!dist/test",
|
|
43
|
+
"!**/*.tsbuildinfo"
|
|
44
|
+
],
|
|
45
|
+
"exports": {
|
|
46
|
+
".": {
|
|
47
|
+
"import": "./dist/src/index.js",
|
|
48
|
+
"types": "./dist/src/index.d.ts"
|
|
49
|
+
},
|
|
50
|
+
"./status": {
|
|
51
|
+
"import": "./dist/src/status.js",
|
|
52
|
+
"types": "./dist/src/status.d.ts"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"eslintConfig": {
|
|
56
|
+
"extends": "ipfs",
|
|
57
|
+
"parserOptions": {
|
|
58
|
+
"sourceType": "module"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"release": {
|
|
62
|
+
"branches": [
|
|
63
|
+
"master"
|
|
64
|
+
],
|
|
65
|
+
"plugins": [
|
|
66
|
+
[
|
|
67
|
+
"@semantic-release/commit-analyzer",
|
|
68
|
+
{
|
|
69
|
+
"preset": "conventionalcommits",
|
|
70
|
+
"releaseRules": [
|
|
71
|
+
{
|
|
72
|
+
"breaking": true,
|
|
73
|
+
"release": "major"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"revert": true,
|
|
77
|
+
"release": "patch"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"type": "feat",
|
|
81
|
+
"release": "minor"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"type": "fix",
|
|
85
|
+
"release": "patch"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"type": "chore",
|
|
89
|
+
"release": "patch"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"type": "docs",
|
|
93
|
+
"release": "patch"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"type": "test",
|
|
97
|
+
"release": "patch"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"scope": "no-release",
|
|
101
|
+
"release": false
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
"@semantic-release/release-notes-generator",
|
|
108
|
+
{
|
|
109
|
+
"preset": "conventionalcommits",
|
|
110
|
+
"presetConfig": {
|
|
111
|
+
"types": [
|
|
112
|
+
{
|
|
113
|
+
"type": "feat",
|
|
114
|
+
"section": "Features"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"type": "fix",
|
|
118
|
+
"section": "Bug Fixes"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"type": "chore",
|
|
122
|
+
"section": "Trivial Changes"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"type": "docs",
|
|
126
|
+
"section": "Trivial Changes"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"type": "test",
|
|
130
|
+
"section": "Tests"
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
"@semantic-release/changelog",
|
|
137
|
+
"@semantic-release/npm",
|
|
138
|
+
"@semantic-release/github",
|
|
139
|
+
"@semantic-release/git"
|
|
140
|
+
]
|
|
23
141
|
},
|
|
24
142
|
"scripts": {
|
|
25
|
-
"test": "aegir test",
|
|
26
|
-
"test:browser": "aegir test --target browser",
|
|
27
|
-
"test:node": "aegir test --target node",
|
|
28
143
|
"lint": "aegir lint",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
"bugs": {
|
|
36
|
-
"url": "https://github.com/ipfs/protons/issues"
|
|
144
|
+
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
|
|
145
|
+
"build": "tsc",
|
|
146
|
+
"pretest": "npm run build",
|
|
147
|
+
"test": "aegir test -t node -f ./dist/test/*.js -f ./dist/test/**/*.js",
|
|
148
|
+
"test:node": "npm run test -- -t node --cov",
|
|
149
|
+
"release": "semantic-release -e semantic-release-monorepo"
|
|
37
150
|
},
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"test": "test"
|
|
151
|
+
"dependencies": {
|
|
152
|
+
"meow": "^10.1.2",
|
|
153
|
+
"protobufjs": "^6.11.2"
|
|
42
154
|
},
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
"decode",
|
|
50
|
-
"google",
|
|
51
|
-
"serialize",
|
|
52
|
-
"parse",
|
|
53
|
-
"levelup",
|
|
54
|
-
"encodings",
|
|
55
|
-
"encoding"
|
|
56
|
-
],
|
|
57
|
-
"author": "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
|
58
|
-
"license": "MIT",
|
|
59
|
-
"contributors": [
|
|
60
|
-
"Mathias Buus <mathiasbuus@gmail.com>",
|
|
61
|
-
"achingbrain <alex@achingbrain.net>",
|
|
62
|
-
"dignifiedquire <dignifiedquire@gmail.com>",
|
|
63
|
-
"David Dias <daviddias.p@gmail.com>",
|
|
64
|
-
"Hector Sanjuan <code@hector.link>",
|
|
65
|
-
"Young Hahn <young@mapbox.com>",
|
|
66
|
-
"Mo Kamioner <mkamioner@gmail.com>",
|
|
67
|
-
"tcme <hi@this-connect.me>",
|
|
68
|
-
"Eduardo Sorribas <eduardo@sorribas.org>",
|
|
69
|
-
"Hugo Dias <hugomrdias@gmail.com>",
|
|
70
|
-
"Lars-Magnus Skog <ralphtheninja@riseup.net>",
|
|
71
|
-
"Patrick Pfeiffer <patrick@buzzle.at>",
|
|
72
|
-
"Kevin Ennis <kennis84@gmail.com>",
|
|
73
|
-
"Elijah Insua <tmpvar@gmail.com>",
|
|
74
|
-
"Astro <astro@spaceboyz.net>",
|
|
75
|
-
"Andreas Madsen <amwebdk@gmail.com>",
|
|
76
|
-
"Sergii Shutovskyi <sergii.shutovskyi@trademob.com>",
|
|
77
|
-
"Steven Allen <steven@stebalien.com>",
|
|
78
|
-
"David Bruant <bruant.d@gmail.com>",
|
|
79
|
-
"Irakli Gozalishvili <contact@gozala.io>",
|
|
80
|
-
"João Antunes <j.goncalo.antunes@gmail.com>",
|
|
81
|
-
"Brendan Ward <bcward@consbio.org>"
|
|
82
|
-
]
|
|
155
|
+
"devDependencies": {
|
|
156
|
+
"aegir": "^36.1.3",
|
|
157
|
+
"long": "^4.0.0",
|
|
158
|
+
"pbjs": "^0.0.14",
|
|
159
|
+
"protons-runtime": "^1.0.0"
|
|
160
|
+
}
|
|
83
161
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { main as pbjs } from 'protobufjs/cli/pbjs.js'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { promisify } from 'util'
|
|
4
|
+
import fs from 'fs/promises'
|
|
5
|
+
|
|
6
|
+
function pathWithExtension (input: string, extension: string) {
|
|
7
|
+
return path.join(path.dirname(input), path.basename(input).split('.').slice(0, -1).join('.') + extension)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const types: Record<string, string> = {
|
|
11
|
+
double: 'number',
|
|
12
|
+
float: 'number',
|
|
13
|
+
int32: 'number',
|
|
14
|
+
int64: 'bigint',
|
|
15
|
+
uint32: 'number',
|
|
16
|
+
uint64: 'bigint',
|
|
17
|
+
sint32: 'number',
|
|
18
|
+
sint64: 'bigint',
|
|
19
|
+
fixed32: 'number',
|
|
20
|
+
fixed64: 'bigint',
|
|
21
|
+
sfixed32: 'number',
|
|
22
|
+
sfixed64: 'bigint',
|
|
23
|
+
bool: 'boolean',
|
|
24
|
+
string: 'string',
|
|
25
|
+
bytes: 'Uint8Array'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function findTypeName (typeName: string, classDef: MessageDef, moduleDef: ModuleDef): string {
|
|
29
|
+
if (types[typeName] != null) {
|
|
30
|
+
return types[typeName]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (isEnumDef(classDef)) {
|
|
34
|
+
throw new Error('Could not find type in enum')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (classDef.nested?.[typeName] != null) {
|
|
38
|
+
return `${classDef.fullName}.${typeName}`
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (classDef.parent != null) {
|
|
42
|
+
return findTypeName(typeName, classDef.parent, moduleDef)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (moduleDef.globals[typeName] != null) {
|
|
46
|
+
return typeName
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
throw new Error(`Could not resolve type name "${typeName}"`)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function findDef (typeName: string, classDef: MessageDef, moduleDef: ModuleDef): MessageDef {
|
|
53
|
+
if (isEnumDef(classDef)) {
|
|
54
|
+
throw new Error('Could not find type in enum')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (classDef.nested?.[typeName] != null) {
|
|
58
|
+
return classDef.nested?.[typeName]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (classDef.parent != null) {
|
|
62
|
+
return findDef(typeName, classDef.parent, moduleDef)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (moduleDef.globals[typeName] != null) {
|
|
66
|
+
return moduleDef.globals[typeName]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
throw new Error(`Could not resolve type name "${typeName}"`)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const encoders: Record<string, string> = {
|
|
73
|
+
bool: 'bool',
|
|
74
|
+
double: 'double',
|
|
75
|
+
bytes: 'bytes',
|
|
76
|
+
fixed32: 'fixed32',
|
|
77
|
+
fixed64: 'fixed64',
|
|
78
|
+
float: 'float',
|
|
79
|
+
int32: 'int32',
|
|
80
|
+
int64: 'int64',
|
|
81
|
+
sint32: 'sint32',
|
|
82
|
+
sint64: 'sint64',
|
|
83
|
+
string: 'string',
|
|
84
|
+
uint32: 'uint32',
|
|
85
|
+
uint64: 'uint64',
|
|
86
|
+
sfixed32: 'sfixed32',
|
|
87
|
+
sfixed64: 'sfixed64'
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface ClassDef {
|
|
91
|
+
name: string
|
|
92
|
+
fullName: string
|
|
93
|
+
parent?: ClassDef
|
|
94
|
+
fields?: Record<string, FieldDef>
|
|
95
|
+
nested?: Record<string, ClassDef>
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface EnumDef {
|
|
99
|
+
name: string
|
|
100
|
+
fullName: string
|
|
101
|
+
parent?: ClassDef
|
|
102
|
+
values: Record<string, number>
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
type MessageDef = ClassDef | EnumDef
|
|
106
|
+
|
|
107
|
+
function isEnumDef (obj: any): obj is EnumDef {
|
|
108
|
+
return obj.values != null
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
interface FieldDef {
|
|
112
|
+
type: string
|
|
113
|
+
id: number
|
|
114
|
+
options?: Record<string, any>
|
|
115
|
+
rule: string
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function defineFields (fields: Record<string, FieldDef>, messageDef: MessageDef, moduleDef: ModuleDef) {
|
|
119
|
+
return Object.entries(fields).map(([fieldName, fieldDef]) => {
|
|
120
|
+
const isArray = fieldDef.rule === 'repeated'
|
|
121
|
+
const isOptional = !isArray && fieldDef.options?.proto3_optional === true
|
|
122
|
+
|
|
123
|
+
return `${fieldName}${isOptional ? '?' : ''}: ${findTypeName(fieldDef.type, messageDef, moduleDef)}${isArray ? '[]' : ''}`
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function compileMessage (messageDef: MessageDef, moduleDef: ModuleDef): string {
|
|
128
|
+
if (isEnumDef(messageDef)) {
|
|
129
|
+
moduleDef.imports.add('enumeration')
|
|
130
|
+
|
|
131
|
+
return `
|
|
132
|
+
export enum ${messageDef.name} {
|
|
133
|
+
${
|
|
134
|
+
Object.entries(messageDef.values).map(([enumValueName, enumValue]) => {
|
|
135
|
+
return `${enumValueName} = '${enumValueName}'`
|
|
136
|
+
}).join(',\n ').trim()
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export namespace ${messageDef.name} {
|
|
141
|
+
export const codec = enumeration<typeof ${messageDef.name}>(${messageDef.name})
|
|
142
|
+
}
|
|
143
|
+
`
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let nested = ''
|
|
147
|
+
|
|
148
|
+
if (messageDef.nested != null) {
|
|
149
|
+
nested = '\n'
|
|
150
|
+
nested += Object.values(messageDef.nested)
|
|
151
|
+
.map(def => compileMessage(def, moduleDef).trim())
|
|
152
|
+
.join('\n')
|
|
153
|
+
.split('\n')
|
|
154
|
+
.map(line => line.trim() === '' ? '' : ` ${line}`)
|
|
155
|
+
.join('\n')
|
|
156
|
+
nested += '\n'
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const fields = messageDef.fields ?? {}
|
|
160
|
+
|
|
161
|
+
// import relevant modules
|
|
162
|
+
moduleDef.imports.add('encodeMessage')
|
|
163
|
+
moduleDef.imports.add('decodeMessage')
|
|
164
|
+
moduleDef.imports.add('message')
|
|
165
|
+
|
|
166
|
+
return `
|
|
167
|
+
export interface ${messageDef.name} {
|
|
168
|
+
${
|
|
169
|
+
defineFields(fields, messageDef, moduleDef)
|
|
170
|
+
.join('\n ')
|
|
171
|
+
.trim()
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export namespace ${messageDef.name} {${nested}
|
|
176
|
+
export const codec = message<${messageDef.name}>({
|
|
177
|
+
${Object.entries(fields)
|
|
178
|
+
.map(([name, fieldDef]) => {
|
|
179
|
+
let codec = encoders[fieldDef.type]
|
|
180
|
+
|
|
181
|
+
if (codec == null) {
|
|
182
|
+
const def = findDef(fieldDef.type, messageDef, moduleDef)
|
|
183
|
+
|
|
184
|
+
if (isEnumDef(def)) {
|
|
185
|
+
moduleDef.imports.add('enumeration')
|
|
186
|
+
} else {
|
|
187
|
+
moduleDef.imports.add('message')
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const typeName = findTypeName(fieldDef.type, messageDef, moduleDef)
|
|
191
|
+
codec = `${typeName}.codec`
|
|
192
|
+
} else {
|
|
193
|
+
moduleDef.imports.add(codec)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return `${fieldDef.id}: { name: '${name}', codec: ${codec}${fieldDef.options?.proto3_optional === true ? ', optional: true' : ''}${fieldDef.rule === 'repeated' ? ', repeats: true' : ''} }`
|
|
197
|
+
}).join(',\n ')}
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
export const encode = (obj: ${messageDef.name}): Uint8Array => {
|
|
201
|
+
return encodeMessage(obj, ${messageDef.name}.codec)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export const decode = (buf: Uint8Array): ${messageDef.name} => {
|
|
205
|
+
return decodeMessage(buf, ${messageDef.name}.codec)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
`
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
interface ModuleDef {
|
|
212
|
+
imports: Set<string>
|
|
213
|
+
types: Set<string>
|
|
214
|
+
compiled: string[]
|
|
215
|
+
globals: Record<string, ClassDef>
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function defineModule (def: ClassDef): ModuleDef {
|
|
219
|
+
const moduleDef: ModuleDef = {
|
|
220
|
+
imports: new Set(),
|
|
221
|
+
types: new Set(),
|
|
222
|
+
compiled: [],
|
|
223
|
+
globals: {}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const defs = def.nested
|
|
227
|
+
|
|
228
|
+
if (defs == null) {
|
|
229
|
+
throw new Error('No top-level messages found in protobuf')
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function defineMessage (defs: Record<string, ClassDef>, parent?: ClassDef) {
|
|
233
|
+
for (const className of Object.keys(defs)) {
|
|
234
|
+
const classDef = defs[className]
|
|
235
|
+
|
|
236
|
+
classDef.name = className
|
|
237
|
+
classDef.parent = parent
|
|
238
|
+
classDef.fullName = parent == null ? className : `${parent.fullName}.${className}`
|
|
239
|
+
|
|
240
|
+
if (classDef.nested != null) {
|
|
241
|
+
defineMessage(classDef.nested, classDef)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (parent == null) {
|
|
245
|
+
moduleDef.globals[className] = classDef
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
defineMessage(defs)
|
|
251
|
+
|
|
252
|
+
for (const className of Object.keys(defs)) {
|
|
253
|
+
const classDef = defs[className]
|
|
254
|
+
|
|
255
|
+
moduleDef.compiled.push(compileMessage(classDef, moduleDef))
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return moduleDef
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export async function generate (source: string, flags: any) {
|
|
262
|
+
// convert .protobuf to .json
|
|
263
|
+
const json = await promisify(pbjs)(['-t', 'json', source])
|
|
264
|
+
|
|
265
|
+
if (json == null) {
|
|
266
|
+
throw new Error(`Could not convert ${source} to intermediate JSON format`)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const def = JSON.parse(json)
|
|
270
|
+
const moduleDef = defineModule(def)
|
|
271
|
+
|
|
272
|
+
const content = `
|
|
273
|
+
/* eslint-disable import/export */
|
|
274
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
275
|
+
|
|
276
|
+
import { ${Array.from(moduleDef.imports).join(', ')} } from 'protons-runtime'
|
|
277
|
+
|
|
278
|
+
${moduleDef.compiled.map(str => str.trim()).join('\n\n').trim()}
|
|
279
|
+
`.trim()
|
|
280
|
+
|
|
281
|
+
await fs.writeFile(pathWithExtension(source, '.ts'), content + '\n')
|
|
282
|
+
}
|
package/.aegir.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
blank_issues_enabled: false
|
|
2
|
-
contact_links:
|
|
3
|
-
- name: Getting Help on IPFS
|
|
4
|
-
url: https://ipfs.io/help
|
|
5
|
-
about: All information about how and where to get help on IPFS.
|
|
6
|
-
- name: IPFS Official Forum
|
|
7
|
-
url: https://discuss.ipfs.io
|
|
8
|
-
about: Please post general questions, support requests, and discussions here.
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Open an issue
|
|
3
|
-
about: Only for actionable issues relevant to this repository.
|
|
4
|
-
title: ''
|
|
5
|
-
labels: need/triage
|
|
6
|
-
assignees: ''
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
<!--
|
|
10
|
-
Hello! To ensure this issue is correctly addressed as soon as possible by the IPFS team, please try to make sure:
|
|
11
|
-
|
|
12
|
-
- This issue is relevant to this repository's topic or codebase.
|
|
13
|
-
|
|
14
|
-
- A clear description is provided. It should includes as much relevant information as possible and clear scope for the issue to be actionable.
|
|
15
|
-
|
|
16
|
-
FOR GENERAL DISCUSSION, HELP OR QUESTIONS, please see the options at https://ipfs.io/help or head directly to https://discuss.ipfs.io.
|
|
17
|
-
|
|
18
|
-
(you can delete this section after reading)
|
|
19
|
-
-->
|
package/.github/config.yml
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Configuration for welcome - https://github.com/behaviorbot/welcome
|
|
2
|
-
|
|
3
|
-
# Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome
|
|
4
|
-
# Comment to be posted to on first time issues
|
|
5
|
-
newIssueWelcomeComment: >
|
|
6
|
-
Thank you for submitting your first issue to this repository! A maintainer
|
|
7
|
-
will be here shortly to triage and review.
|
|
8
|
-
|
|
9
|
-
In the meantime, please double-check that you have provided all the
|
|
10
|
-
necessary information to make this process easy! Any information that can
|
|
11
|
-
help save additional round trips is useful! We currently aim to give
|
|
12
|
-
initial feedback within **two business days**. If this does not happen, feel
|
|
13
|
-
free to leave a comment.
|
|
14
|
-
|
|
15
|
-
Please keep an eye on how this issue will be labeled, as labels give an
|
|
16
|
-
overview of priorities, assignments and additional actions requested by the
|
|
17
|
-
maintainers:
|
|
18
|
-
|
|
19
|
-
- "Priority" labels will show how urgent this is for the team.
|
|
20
|
-
- "Status" labels will show if this is ready to be worked on, blocked, or in progress.
|
|
21
|
-
- "Need" labels will indicate if additional input or analysis is required.
|
|
22
|
-
|
|
23
|
-
Finally, remember to use https://discuss.ipfs.io if you just need general
|
|
24
|
-
support.
|
|
25
|
-
|
|
26
|
-
# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome
|
|
27
|
-
# Comment to be posted to on PRs from first time contributors in your repository
|
|
28
|
-
newPRWelcomeComment: >
|
|
29
|
-
Thank you for submitting this PR!
|
|
30
|
-
|
|
31
|
-
A maintainer will be here shortly to review it.
|
|
32
|
-
|
|
33
|
-
We are super grateful, but we are also overloaded! Help us by making sure
|
|
34
|
-
that:
|
|
35
|
-
|
|
36
|
-
* The context for this PR is clear, with relevant discussion, decisions
|
|
37
|
-
and stakeholders linked/mentioned.
|
|
38
|
-
|
|
39
|
-
* Your contribution itself is clear (code comments, self-review for the
|
|
40
|
-
rest) and in its best form. Follow the [code contribution
|
|
41
|
-
guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md#code-contribution-guidelines)
|
|
42
|
-
if they apply.
|
|
43
|
-
|
|
44
|
-
Getting other community members to do a review would be great help too on
|
|
45
|
-
complex PRs (you can ask in the chats/forums). If you are unsure about
|
|
46
|
-
something, just leave us a comment.
|
|
47
|
-
|
|
48
|
-
Next steps:
|
|
49
|
-
|
|
50
|
-
* A maintainer will triage and assign priority to this PR, commenting on
|
|
51
|
-
any missing things and potentially assigning a reviewer for high
|
|
52
|
-
priority items.
|
|
53
|
-
|
|
54
|
-
* The PR gets reviews, discussed and approvals as needed.
|
|
55
|
-
|
|
56
|
-
* The PR is merged by maintainers when it has been approved and comments addressed.
|
|
57
|
-
|
|
58
|
-
We currently aim to provide initial feedback/triaging within **two business
|
|
59
|
-
days**. Please keep an eye on any labelling actions, as these will indicate
|
|
60
|
-
priorities and status of your contribution.
|
|
61
|
-
|
|
62
|
-
We are very grateful for your contribution!
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge
|
|
66
|
-
# Comment to be posted to on pull requests merged by a first time user
|
|
67
|
-
# Currently disabled
|
|
68
|
-
#firstPRMergeComment: ""
|