11import { Value } from "../pb/shared" ;
22
3- export type PlainValue = null | number | string | boolean | Array < PlainValue > | object ;
3+ type PlainValue = null | number | string | boolean | Array < PlainValue > | object ;
44
5- export function toAllowedValue ( value : Value ) : PlainValue {
5+ function toAllowedValue ( value : Value ) : PlainValue {
66 switch ( value . kind . oneofKind ) {
77 case "nullValue" :
88 return null ;
@@ -15,7 +15,7 @@ export function toAllowedValue(value: Value): PlainValue {
1515 case "listValue" :
1616 return value . kind . listValue . values . map ( toAllowedValue ) ;
1717 case "structValue" :
18- const obj : { [ key : string ] : PlainValue } = { } ;
18+ const obj : { [ key : string ] : PlainValue } = { } ;
1919 for ( const [ k , v ] of Object . entries ( value . kind . structValue . fields ) ) {
2020 obj [ k ] = toAllowedValue ( v ) ;
2121 }
@@ -26,7 +26,7 @@ export function toAllowedValue(value: Value): PlainValue {
2626}
2727
2828
29- export function constructValue ( value : PlainValue ) : Value {
29+ function constructValue ( value : PlainValue ) : Value {
3030 if ( value === null ) {
3131 return { kind : { oneofKind : "nullValue" , nullValue : 0 } } ;
3232 }
@@ -49,7 +49,7 @@ export function constructValue(value: PlainValue): Value {
4949 } ;
5050 }
5151 if ( typeof value === "object" ) {
52- const structFields : { [ key : string ] : Value } = { } ;
52+ const structFields : { [ key : string ] : Value } = { } ;
5353 for ( const [ k , v ] of Object . entries ( value ) ) {
5454 structFields [ k ] = constructValue ( v ) ;
5555 }
@@ -62,3 +62,9 @@ export function constructValue(value: PlainValue): Value {
6262 }
6363 throw new Error ( `Unsupported value type: ${ typeof value } ` ) ;
6464}
65+
66+ export {
67+ toAllowedValue ,
68+ constructValue ,
69+ PlainValue
70+ }
0 commit comments