Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/daangn/metabridge

🔗 Defines the communication layer between mobile native(iOS/Android) and webview using JSON Schema and automatically generates SDK code. (TypeScript, Swift, Kotlin)
https://github.com/daangn/metabridge

bridge cli codegen schema typescript webview

Last synced: 3 months ago
JSON representation

🔗 Defines the communication layer between mobile native(iOS/Android) and webview using JSON Schema and automatically generates SDK code. (TypeScript, Swift, Kotlin)

Awesome Lists containing this project

README

        

# metabridge

## Usage

```bash
# Install CLI
$ yarn add --dev @metabridge/cli @metabridge/plugin-typescript

# Generate code
$ yarn metabridge-cli \
$ --plugin @metabridge/plugin-typescript \
$ --schema ./somewhere/mySchema.json \
$ --output ./somewhere/__generated__/mySdk.ts
```

```typescript
import { makeMyBridge } from "./somewhere/__generated__/mySdk";

const myBridge = makeMyBridge({
driver: {
onQueried(queryName, req) {
// ...your business logic for transport layer
return res;
},
},
});

// It strictly typed
myBridge.pushRouter({
// ...
});
```

## Available Plugins

- `@metabridge/plugin-typescript`: TypeScript SDK
- `@metabridge/plugin-typescript-docs`: TypeScript SDK Documentations (for WebView)
- `@metabridge/plugin-kotlin`: Kotlin Stub
- `@metabridge/plugin-swift`: Swift Stub

## How to implement the JavaScript `Driver`

Just implement this

```typescript
export interface MetaBridgeDriver {
onQueried: (queryName: string, requestBody: any) => Promise;
onSubscribed: (
subscriptionName: string,
requestBody: any,
listener: (error: Error | null, response: any | null) => void
) => () => void;
}
```

## Contributors

- [@tonyfromundefined](https://github.com/tonyfromundefined)