Skip to content

Commit 4b14cae

Browse files
authored
[#1] Add docs and public interface, closes #1
1 parent f4ebeda commit 4b14cae

6 files changed

+141
-24
lines changed

README.md

+14-7
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22
![](https://github.com/schemadb/node-sdk/workflows/CI/badge.svg)
33

44
## Usage
5-
`// TODO`
5+
6+
This library is documented in: [https://schemadb.github.io/node-sdk](https://schemadb.github.io/node-sdk)
67

78
## Development
8-
`// TODO`
99

10-
### Setup
11-
`// TODO`
10+
```bash
11+
# Fork and clone this repo
12+
npm i
13+
14+
# You can keep track of tests status while making changes
15+
npm run test:watch
1216

13-
### Test
14-
`// TODO`
17+
# And make sure everythign is fine after changes
18+
npm run lint
19+
npm run test
20+
```
1521

1622
### Contribute
17-
`// TODO`
23+
24+
[CONTRIBUTING.md](./CONTRIBUTING.md)
1825

1926
## Maintainers
2027

docs/api-reference.markdown

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
layout: default
3+
title: API Reference
4+
nav_order: 3
5+
---
6+
7+
# API Reference
8+
9+
*Work in progress*

docs/index.markdown

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ nav_order: 1
66

77
# Home
88

9-
Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups.
9+
This is the Node.js SDK for [https://schemadb.com](https://schemadb.com).
1010

11-
## Install
11+
**WARNING: this is still WIP.**
12+
13+
## Installation
1214

1315
```bash
1416
npm i @schemadb/node-sdk
1517
```
1618

1719
## Usage
1820

19-
```js
20-
const { someMiddleware } = require('@schemadb/node-sdk');
21-
```
21+
Please, have a look at [Quickstart](./quickstart.markdown).

docs/quickstart.markdown

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
layout: default
3+
title: Quickstart
4+
nav_order: 2
5+
---
6+
7+
# Quickstart
8+
9+
First of all, login to [https://schemadb.com](https://schemadb.com) and head to API Tokens page. you can create a new one over there.
10+
11+
## Initialize
12+
```js
13+
const schemadb = require('@schemadb/node-sdk');
14+
schemadb.init('1036fae0-3a28-11ea-a5e3-...');
15+
16+
// You can also pass some options
17+
schemadb.init('1036fae0-3a28-11ea-a5e3-...', {
18+
debug: true
19+
});
20+
```
21+
22+
Available options are:
23+
24+
| Option | Description | Type | Default value |
25+
| ------ | ----------- | ---- | ------------- |
26+
| `debug` | Enabled debug logging level | `Boolean` | `false` |
27+
28+
## Save a new schema
29+
30+
```js
31+
const orderSchema = {
32+
"version": 1,
33+
"definition": {
34+
"type": "record",
35+
"namespace": "com.example.store",
36+
"name": "order",
37+
"fields": [
38+
{ "name": "orderId", "type": "long" },
39+
{ "name": "storeId", "type": "long" },
40+
{
41+
"name": "timepalced",
42+
"type": "long",
43+
"logicalType": "timestamp-millis"
44+
},
45+
{ "name": "orderStatus", "type": "string" }
46+
]
47+
}
48+
};
49+
50+
// Save schema to platform
51+
await schemadb.saveSchema(orderSchema);
52+
```
53+
54+
## Encode payload
55+
56+
Schemas will be fetched only once from after instantiated, since the SDK handles caching for you.
57+
58+
```js
59+
// Get latest schema by namespace and name
60+
const schema = await schemadb.getSchema('com.example.store', 'order');
61+
62+
// Encode payload
63+
const avro = await schemadb.encode(schema, {
64+
orderId: 1234567890,
65+
storeId: 1234,
66+
timeplaced: 1586193018930,
67+
orderStatus: 'A'
68+
});
69+
```
70+
71+
## Decode binary Avro
72+
73+
```js
74+
// Decode binary buffer to JSON object
75+
const payload = await schemadb.decode(avroBinaryBuffer);
76+
```

docs/test.markdown

-11
This file was deleted.

src/index.js

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable no-unused-vars */
2+
13
import Exceptions from './lib/exceptions';
24
import { setConfiguration, Settings } from './stores/configuration';
35

@@ -9,7 +11,7 @@ const _validateAPIToken = apiToken => {
911

1012
export default {
1113
/**
12-
* Initialize SchemaDB SDK
14+
* Initialize SchemaDB SDK.
1315
*
1416
* @param {string} apiToken SchemaDB API Token
1517
* @param {object} options SDK options
@@ -22,5 +24,39 @@ export default {
2224
}
2325

2426
setConfiguration(Settings.DEBUG, !!options[Settings.DEBUG]);
27+
},
28+
/**
29+
* Save a new schema to platform. Will fail if version already exists.
30+
*
31+
* @param {object} schema Avro JSON format schema to be saved
32+
*/
33+
saveSchema: async (schema) => {
34+
return;
35+
},
36+
/**
37+
* Get latest schema version by namespace and name.
38+
*
39+
* @param {string} namespace Schema namespace
40+
* @param {string} name Schema name
41+
*/
42+
getSchema: async (namespace, name) => {
43+
return;
44+
},
45+
/**
46+
* Encode JSON to binary Avro buffer.
47+
*
48+
* @param {object} schema Avro JSON format schema to be saved
49+
* @param {object} payload Object to be encoded
50+
*/
51+
encode: async (schema, payload) => {
52+
return;
53+
},
54+
/**
55+
* Decado Avro binary to JSON object.
56+
*
57+
* @param {Buffer} binaryBuffer Avro binary encoded payload
58+
*/
59+
decode: async (binaryBuffer) => {
60+
return;
2561
}
2662
};

0 commit comments

Comments
 (0)