Skip to content

Commit

Permalink
feat: add endo/base64 support
Browse files Browse the repository at this point in the history
  • Loading branch information
j-yw committed Sep 14, 2024
1 parent d7f2ced commit a920d39
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/telescope/__tests__/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ describe('misc', () => {
prototypes: {
typingsFormat: {
customTypes: {
base64Lib: true,
base64Lib: '@endo/base64',
},
},
},
Expand Down
6 changes: 0 additions & 6 deletions packages/telescope/src/generators/create-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
getTypesHelper,
jsonSafe,
decimal,
base64,
} from '../helpers';

const version = process.env.NODE_ENV === 'test' ? 'latest' : pkg.version;
Expand Down Expand Up @@ -100,11 +99,6 @@ export const plugin = (builder: TelescopeBuilder) => {
write(builder, 'decimals.ts', decimal);
}

if (builder.options.prototypes.typingsFormat.customTypes.base64Lib) {
builder.files.push('base64.ts');
write(builder, 'base64.ts', base64);
}

if (
!builder.options.prototypes.typingsFormat.toJsonUnknown &&
builder.options.prototypes.methods.toJSON
Expand Down
19 changes: 16 additions & 3 deletions packages/telescope/src/generators/customize-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,22 @@ export const plugin = (builder: TelescopeBuilder) => {
UTILS.Decimal = '@cosmjs/math';
}

if (builder.options.prototypes.typingsFormat.customTypes.base64Lib === true) {
UTILS.base64FromBytes = '@endo/base64';
UTILS.bytesFromBase64 = '@endo/base64';
if (
builder.options.prototypes.typingsFormat.customTypes.base64Lib ===
'@endo/base64'
) {
UTILS.base64FromBytes = {
type: 'import',
path: '@endo/base64',
name: 'decodeBase64',
importAs: 'base64FromBytes',
};
UTILS.bytesFromBase64 = {
type: 'import',
path: '@endo/base64',
name: 'encodeBase64',
importAs: 'bytesFromBase64',
};
} else {
UTILS.base64FromBytes = '__helpers__';
UTILS.bytesFromBase64 = '__helpers__';
Expand Down
3 changes: 0 additions & 3 deletions packages/telescope/src/helpers/base64.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/telescope/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ export * from './types-helper';
export * from './registry-helper';
export * from './json-safe';
export * from './decimals';
export * from './base64';
39 changes: 20 additions & 19 deletions packages/telescope/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import { ImportDeclaration } from '@babel/types';
import { ProtoServiceMethod, TelescopeOptions } from '@cosmology/types';
export interface Bundle {
bundleVariables: {};
bundleFile: string;
importPaths: ImportDeclaration[];
base: string;
bundleVariables: {};
bundleFile: string;
importPaths: ImportDeclaration[];
base: string;
}
export interface BundlerFile {
proto?: string;
package?: string;
localname: string;
filename: string;
isMsg?: boolean;
instantExportedMethods?: ProtoServiceMethod[]
proto?: string;
package?: string;
localname: string;
filename: string;
isMsg?: boolean;
instantExportedMethods?: ProtoServiceMethod[];
}

export interface ImportObj {
type: 'import' | 'default' | 'namespace' | string;
name: string;
path: string;
importAs?: string;
type: 'import' | 'default' | 'namespace' | string;
name: string;
path: string;
importAs?: string;
}
export type UtilValue = ImportObj | string;

export interface DerivedImportObj extends ImportObj {
orig: string;
orig: string;
}
export interface ImportHash {
[key: string]: string[];
[key: string]: string[];
}

export interface TelescopeInput {
protoDirs: string[];
outPath: string;
options: TelescopeOptions;
protoDirs: string[];
outPath: string;
options: TelescopeOptions;
}
4 changes: 2 additions & 2 deletions packages/telescope/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ProtoRoot, ProtoRef } from '@cosmology/types';
import { relative, dirname, extname } from 'path';
import { ImportObj } from '../types';
import { ImportObj, UtilValue } from '../types';
import { restoreExtension, toPosixPath } from '@cosmology/utils';

export const getRoot = (ref: ProtoRef): ProtoRoot => {
Expand All @@ -12,7 +12,7 @@ export const getRoot = (ref: ProtoRef): ProtoRoot => {
// Long: { type: 'default', path: 'long', name: 'Long ' },
// namespaced:
// _m0: { type: 'namespace', path: 'protobufjs/minimal', name: '_m0' },
export const UTILS = {
export const UTILS: { [key: string]: UtilValue } = {
_m0: { type: 'namespace', path: 'protobufjs/minimal', name: '_m0' },
AminoHeight: '__helpers__',
AminoMsg: '@cosmjs/amino',
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/telescope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ interface TelescopeOpts {
customTypes?: {
useCosmosSDKDec?: boolean;
usePatchedDecimal?: boolean;
base64Lib?: boolean;
base64Lib?: '@endo/base64';
};

num64?: 'long' | 'bigint';
Expand Down

0 comments on commit a920d39

Please sign in to comment.