Skip to content

Commit

Permalink
🔀 ✨ Change enum impl (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
devkanro authored Mar 10, 2023
1 parent 555e1e0 commit 31c5626
Show file tree
Hide file tree
Showing 67 changed files with 699 additions and 606 deletions.
14 changes: 7 additions & 7 deletions examples/example-simple/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sisyphus.js/example-simple",
"version": "2.0.8",
"version": "2.1.0",
"description": "Example project using sisyphus.js",
"main": "dist/index.js",
"scripts": {
Expand All @@ -26,14 +26,14 @@
},
"homepage": "https://github.com/ButterCam/sisyphus-js#readme",
"devDependencies": {
"@sisyphus.js/cli": "^2.0.8",
"@sisyphus.js/google.proto": "^2.0.8",
"@sisyphus.js/runtime.proto": "^2.0.8"
"@sisyphus.js/cli": "^2.1.0",
"@sisyphus.js/google.proto": "^2.1.0",
"@sisyphus.js/runtime.proto": "^2.1.0"
},
"dependencies": {
"@sisyphus.js/google": "^2.0.8",
"@sisyphus.js/runtime": "^2.0.8",
"@sisyphus.js/transport-aip": "^2.0.8"
"@sisyphus.js/google": "^2.1.0",
"@sisyphus.js/runtime": "^2.1.0",
"@sisyphus.js/transport-aip": "^2.1.0"
},
"directories": {
"proto": "proto"
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"packages/*",
"examples/*"
],
"version": "2.0.8"
"version": "2.1.0"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"scripts": {
"clean": "lerna run clean",
"bootstrap": "lerna bootstrap --hoist",
"build": "lerna bootstrap --hoist && lerna run clean && lerna run build",
"publish": "lerna publish from-package --yes --no-verify-access",
"watch": "lerna run --stream --no-sort --concurrency 9999 watch",
Expand Down
10 changes: 5 additions & 5 deletions packages/sisyphus-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sisyphus.js/cli",
"version": "2.0.8",
"version": "2.1.0",
"description": "Protoc cli for sisyphus project on js platform",
"bin": {
"sisygen": "lib/index.js"
Expand Down Expand Up @@ -30,10 +30,10 @@
},
"homepage": "https://github.com/ButterCam/sisyphus-js#readme",
"dependencies": {
"@sisyphus.js/compiler": "^2.0.8",
"@sisyphus.js/protoc": "^2.0.8",
"@sisyphus.js/runtime": "^2.0.8",
"@sisyphus.js/runtime.proto": "^2.0.8",
"@sisyphus.js/compiler": "^2.1.0",
"@sisyphus.js/protoc": "^2.1.0",
"@sisyphus.js/runtime": "^2.1.0",
"@sisyphus.js/runtime.proto": "^2.1.0",
"commander": "^10.0.0",
"npmlog": "^7.0.1"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sisyphus-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export async function main(args: string[]): Promise<number> {
advance<FilesGeneratingState>({
kind: 'files',
parent: undefined,
descriptor: new FileDescSet(fileDescSet),
descriptor: new FileDescSet(<any>fileDescSet),
target: files,
src: targetProtos,
lib: generatedModules
Expand Down
2 changes: 1 addition & 1 deletion packages/sisyphus-cli/src/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function discoverGeneratedModuleInPackage(packageInfo: PackageJson, dir: s
for (let file of sisyphusDist.generatedFiles) {
const moduleName = tsModuleName(file)
if (moduleName == undefined) return
generatedModules['/' + moduleName] = path.join(packageInfo.name, packageInfo.directories?.lib ?? 'lib', moduleName)
generatedModules['/' + moduleName] = path.posix.join(packageInfo.name, packageInfo.directories?.lib ?? 'lib', moduleName)
}

return packageInfo
Expand Down
4 changes: 2 additions & 2 deletions packages/sisyphus-compiler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sisyphus.js/compiler",
"version": "2.0.8",
"version": "2.1.0",
"description": "Precompiled google common protos by sisyphus protobuf compiler",
"main": "lib/index.js",
"sisyphus": {
Expand Down Expand Up @@ -35,6 +35,6 @@
},
"homepage": "https://github.com/ButterCam/sisyphus-js#readme",
"dependencies": {
"@sisyphus.js/protoc": "^2.0.8"
"@sisyphus.js/protoc": "^2.1.0"
}
}
1 change: 0 additions & 1 deletion packages/sisyphus-compiler/src/aip/state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {CodeBuilder} from '../code-builder'
import {FileGeneratingState} from '../core/state'
import {FileDescriptor, MethodDescriptor, ServiceDescriptor} from '../descriptor'
import {GeneratingState} from '../generator'
import {FilesGeneratingState} from '../state'
Expand Down
6 changes: 3 additions & 3 deletions packages/sisyphus-compiler/src/core/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {EnumGeneratingState, EnumValueGeneratingState} from './state'

generate<EnumGeneratingState>('enum', it => {
const builder = it.target
it.generatedElements ++
it.generatedElements++

builder.normalize().lineComment(...it.descriptor.comments())
builder.normalize().document(it.descriptor.document())
Expand All @@ -25,11 +25,11 @@ generate<EnumGeneratingState>('enum', it => {

generate<EnumValueGeneratingState>('enumValue', it => {
const builder = it.target
it.generatedElements ++
it.generatedElements++

builder.normalize().lineComment(...it.descriptor.comments())
builder.normalize().document(it.descriptor.document())
builder.append(`${it.descriptor.simpleName()} = '${it.descriptor.name()}',`)
builder.append(`${it.descriptor.name()} = ${it.descriptor.number()},`)
builder.trailingComment(it.descriptor.trailingComment())
builder.ln()
})
12 changes: 8 additions & 4 deletions packages/sisyphus-compiler/src/core/field.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {CodeBuilder} from '../code-builder'
import {ExtensionDescriptor, FieldDescriptor, MessageDescriptor} from '../descriptor'
import {EnumDescriptor, ExtensionDescriptor, FieldDescriptor, MessageDescriptor} from '../descriptor'
import {ExtensionGeneratingState, FieldGeneratingState, OneofGeneratingState} from './state'

generate<FieldGeneratingState>('field', it => {
it.generatedElements ++
it.generatedElements++
const builder = it.target

builder.normalize().lineComment(...it.descriptor.comments())
Expand Down Expand Up @@ -35,7 +35,7 @@ generate<OneofGeneratingState>('oneof', it => {
})

generate<ExtensionGeneratingState>('extension', it => {
it.generatedElements ++
it.generatedElements++
const builder = it.target

builder.normalize().lineComment(...it.descriptor.comments())
Expand Down Expand Up @@ -76,7 +76,7 @@ function type(builder: CodeBuilder, field: FieldDescriptor | ExtensionDescriptor
break
// case 'TYPE_GROUP':
case 'TYPE_MESSAGE':
case 'TYPE_ENUM':
case 'TYPE_ENUM': {
const wellknown = wellknownType(builder, field.descriptor.typeName ?? '', protobuf)
if (wellknown !== null) {
return wellknown
Expand All @@ -87,7 +87,11 @@ function type(builder: CodeBuilder, field: FieldDescriptor | ExtensionDescriptor
return mapType(builder, target)
const importName = builder.importManager.import(lib, target.importName())
result = target.fullImportName(importName)
if (target instanceof EnumDescriptor) {
result = `${result} | (keyof typeof ${result})`
}
break
}
default:
throw new Error(`Unsupported field type '${field.descriptor.type}'`)
}
Expand Down
30 changes: 15 additions & 15 deletions packages/sisyphus-compiler/src/descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,24 +705,24 @@ function arrayEquals(a: any[], b: any[]): boolean {
}

function fieldPacked(syntax: string | undefined, descriptor: Google.FieldDescriptorProto) {
if (descriptor.label != Google.FieldDescriptorProto.Label.REPEATED) return undefined
if (descriptor.label != 'LABEL_REPEATED') return undefined
let defaultPacked = false
if (syntax == 'proto3') {
switch (descriptor.type) {
case Google.FieldDescriptorProto.Type.BOOL:
case Google.FieldDescriptorProto.Type.UINT32:
case Google.FieldDescriptorProto.Type.UINT64:
case Google.FieldDescriptorProto.Type.INT32:
case Google.FieldDescriptorProto.Type.INT64:
case Google.FieldDescriptorProto.Type.SINT32:
case Google.FieldDescriptorProto.Type.SINT64:
case Google.FieldDescriptorProto.Type.DOUBLE:
case Google.FieldDescriptorProto.Type.FLOAT:
case Google.FieldDescriptorProto.Type.FIXED32:
case Google.FieldDescriptorProto.Type.FIXED64:
case Google.FieldDescriptorProto.Type.SFIXED32:
case Google.FieldDescriptorProto.Type.SFIXED64:
case Google.FieldDescriptorProto.Type.ENUM:
case 'TYPE_BOOL':
case 'TYPE_UINT32':
case 'TYPE_UINT64':
case 'TYPE_INT32':
case 'TYPE_INT64':
case 'TYPE_SINT32':
case 'TYPE_SINT64':
case 'TYPE_DOUBLE':
case 'TYPE_FLOAT':
case 'TYPE_FIXED32':
case 'TYPE_FIXED64':
case 'TYPE_SFIXED32':
case 'TYPE_SFIXED64':
case 'TYPE_ENUM':
defaultPacked = true
break
}
Expand Down
Loading

0 comments on commit 31c5626

Please sign in to comment.