Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
25 changes: 9 additions & 16 deletions docs/docs/_sidebar.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
- Getting started
- [Quickstart Guide](/getting-started/quickstart)
- [Syncano Ecosystem](/getting-started/intro)
- [Syncano Sockets](/getting-started/sockets)
- [Tools and Libraries](/getting-started/intro)
- [Windows Development Guide](/getting-started/windows)
- Starting a Project
- Setting up a Project
- [Overview](/project/overview)
- [Hosting](/project/hosting)
- Using Sockets
- [Overview](/using-sockets/overview)
- [Search & Install](/using-sockets/search-install)
- [List](/using-sockets/list)
- [Call](/using-sockets/call)
- [Config Options](/using-sockets/config-options)
- Building Sockets
- [Install Socket from NPM](/project/install-from-npm)
- Building your own Sockets
- [Basics](/building-sockets/basics)
- [Data Classes](/building-sockets/data-classes)
- [Endpoints](/building-sockets/endpoints)
- [Event Handlers](/building-sockets/event-handlers)
- [Events](/building-sockets/events)
- [Dependencies](/building-sockets/dependencies)
- [Database](/project/data-classes)
- [Core Services](/building-sockets/core-api)
- [Config Options](/building-sockets/config-options)
- [YAML Syntax](/building-sockets/yaml-syntax)
- Connecting Front-End
- [JS Client](/client-lib-reference/installation)
- CLI Reference Guide
- [Installation](/cli-reference/installation)
- [Commands](/cli-reference/commands)
- [Config Files](/cli-reference/config-files)
- [Advanced](/cli-reference/advanced)
- [Development](/cli-reference/development)
- Client Lib Reference
- [Installation](/client-lib-reference/installation)
- [Usage](/client-lib-reference/usage)
- Server Lib Reference
- [Installation](/server-lib-reference/installation)
- [Usage](/server-lib-reference/usage)
- [Support](/common/support)
- [Limits](/common/limits)
- [Contributing](/common/contributing)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
# Using Core API library

The Core API library should be used in the **Syncano Sockets** (inside the scripts powering the Syncano Sockets) to communicate with the **Syncano Core Services** and 3rd party integrated platforms. Syncano provides various Core Services:
- **Database (db)** - NoSQL database to store your application data
- **Users Management (users)** - service to store and manage users and groups of your application
- **Event Loop (events)** - service to emit events which can be caught by any Socket
- **Realtime Channels (channels)** - implement publish/subscribe model for realtime communication

Library is by default a Syncano Socket dependency, you can check `package.json` file of your Socket:

```sh
cat <my-project>/syncano/<my-socket-name>/package.json
```

```json
{
"dependencies": {
"@syncano/core": "0.13.0"
}
}
```

If `@syncano/core` is not listed there you can use `npm` to install it (you have to be inside Socket folder):
```sh
cd <my-project>/syncano/<my-socket-name>/package.json
npm add @syncano/core
```

## Library initialization

To initialize library simply import it in a Socket script where library will be used:
```js
import { data, users, socket, response, event, logger } from '@syncano/core'
```

Library initiated that way will grab necessary information from the context of you Socket Script - it means that you don't need to provide additional information such as Instance name or authentication key (token) to your Instance.
```javascript
import Syncano from '@syncano/core'

If you want to force the library to connect to specified instance type:
```js
import Server from '@syncano/core'
export default (ctx) => {
const { data, users, endpoint, response, event, logger } = new Syncano(ctx)

const { data, events } = new Server({
token: '9-12jdiasdnfo23nrokms',
instanceName: 'example-instance-name'
})
// Now you can access easily the database, e.g.:
// const awesomeMovie = await data.movies.where('title', 'Fight Club').first()

}
```

## Core API
Expand Down Expand Up @@ -63,7 +88,7 @@ data.tags.delete(7652)

```js
// Get first user with given mail
data.users
users
.where('email', 'john.doe@example.com')
.first()
.then(user => {
Expand All @@ -72,7 +97,7 @@ data.users
})

// Get first user with given mail, throws error if user was not found
data.users
users
.where('email', 'john.doe@example.com')
.firstOrFail()
.then(user => {})
Expand Down Expand Up @@ -142,8 +167,6 @@ response
### Logging

```js
import {logger} from '@syncano/core'

// Listen for all events
logger.listen(event => {
// Handle event - save to db or send email
Expand Down
13 changes: 3 additions & 10 deletions docs/docs/building-sockets/dependencies.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
# Dependencies
Sockets can use libraries installed directly from `npm` or use other Sockets as a dependency.

To add dependency from `npm` execute `yarn add` in socket folder:
To add dependency from `npm` execute `npm install <package name>` in Socket folder:

```sh
cd syncano/<socket_folder>
yarn add <dependency name>
npm install <dependency name>
```

For example:
```sh
cd syncano/hello-world
yarn add lodash
npm install lodash
```


<!--
## `npm` dependencies

## Sockets Registry dependencies
-->
56 changes: 11 additions & 45 deletions docs/docs/building-sockets/endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ endpoints:

`file` value is a relative path to the file containing the script code. The `socket.yml` location is the root.

## Private endpoints

By default, endpoints are public, which means that anyone can execute the underlying script. To change this setting add a `private: true` param to the endpoint definition:

```yaml
endpoints:
restricted:
private: true
```

## Caching

You can allow for caching the GET requests to your endpoints. Add a cache property to the endpoint definition to enable caching:
Expand All @@ -51,24 +61,14 @@ endpoint:

Now, the response from `i_will_be_cached` endpoint will be cached for `5 seconds`.

> valid cache property values are in a 0-1800 (exclusive) range with a floating point precision.
> valid cache property values are in a 0-1800 range with a floating point precision.

The cache property can be ignored on the client side. To do that, add `__skip_cache=1` query param to the GET request:

```js
s.get('socket/with_cache', { '__skip_cache': 1 })
```

## Private endpoints

By default, endpoints are public, which means that anyone can execute the underlying script. To change this setting add a `private: true` param to the endpoint definition:

```yaml
endpoints:
restricted:
private: true
```

Endpoints with this parameter, will be accessible with an account key only. They are suitable for hiding away Socket settings and configuration options. End users of your app won't have access to them.

## Channels
Expand All @@ -89,37 +89,3 @@ endpoints:
```

Read the Real-Time Channels documentation to learn more about the real-time capabilities of Syncano.

## Documentation
Since the yaml file will accept any property, you can add your own notes to any part of the specification file. In case you would like your Socket to be a part of Syncano Sockets Registry, you'll be required to document the Socket endpoints in the following manner:

```yaml
endpoints:
send_email:
file: ./src/send_email.js
parameters:
email:
type: string
description: Email of the recipient
example: "hulk@hogan.net"
response:
mimetype: application/json
examples:
- exit_code: 200
description: "Email sent successfully"
example: |
{
"email_id": 320
}
- exit_code: 400
description: "Error while sending email"
example: |
{
"reason": "Internal error!"
}
```

|Documentation Property|Description|
|---|---|
|`parameters`|Describes the arguments accepted by an endpoint. The parameters documentation should consist of `type`, `description` and `example` fields.|
|`response`|Describes the endpoints' responses in the `examples` property. `examples` is an array of possible responses with appropriate `exit_code`, `description` and response `example`. Optionally, a `mimetype` defining a response type can be added.|
Loading