Skip to content

Commit

Permalink
Update Flow types and README files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Dec 3, 2018
1 parent 30b5d08 commit 3238c01
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 67 deletions.
70 changes: 4 additions & 66 deletions packages/webiny-api/types.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,21 @@
// @flow
import type { Attribute } from "webiny-model";
import type { Schema as _Schema } from "webiny-api/graphql/Schema";
import type { Entity as _Entity, Identity } from "webiny-api/entities";
import type { Entity } from "webiny-entity";
import { type PluginType as _PluginType } from "webiny-plugins/types";

export type Schema = _Schema;
export type Entity = _Entity;
export type PluginType = _PluginType;

export type ImageProcessor = ({
image: Buffer,
transformations: Array<{ action: string }>
}) => Buffer;

export type AttributeToTypeParams = {
attr: Attribute,
schema: Schema,
modelToType: Function,
convertModelToType: Function
};

/**
* Interface for Token implementation.
*/
export interface IToken {
/**
* Encode Identity instance.
* @param {Identity} identity Identity instance to encode.
* @param {number} expiresOn Seconds since epoch.
* @returns {Promise<string>}
*/
encode(identity: Identity, expiresOn: number): Promise<string>;
/**
* Decode token.
* @param {string} token
* @return {Object} Token data.
*/
decode(token: string): Promise<Object>;
}

export interface IStrategy {
/**
* Define args for GraphQL endpoint
*/
args: () => Object;
authenticate: (args: Object, identity: Class<Identity>) => Promise<Identity>;
}

export type AppType = {
preInit?: Function,
init?: Function,
postInit?: Function,
install?: Function,
preInstall?: Function,
postInstall?: Function,
configure?: Function
};

export type LambdaEvent = {
security: {
permissions: Object,
identity: ?Identity,
sudo: boolean
},
entityPool: Object
};

export type EntityPluginType = PluginType & {
namespace: string,
entity: {
name: string,
factory: (params?: Object) => Entity
factory: (context: Object) => Class<Entity>
}
};

export type GraphQLSchemaPluginType = PluginType & {
namespace: string,
typedefs: Array<string> | Function<Array<string>>,
resolvers: Object | Function<Object>
typedefs: Array<string> | () => Array<string>,
resolvers: Object | () => Object
};

export type GraphQLContextPluginType = PluginType & {
Expand Down
2 changes: 1 addition & 1 deletion packages/webiny-entity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Entity component, as the name already suggests, provides a way to work with enti
Webiny currently hosts two official drivers - MySQL and Memory drivers. Additional drivers may be added (eg. PostgreSQL or MongoDB) as the need arises in the near future.

## Installation
`yarn install webiny-entity`
`yarn add webiny-entity`

## Quick Example
In general, the first step in defining a new entity is to extend a base Entity class, and then define attributes in class constructor. To quickly get an impression on how it works, please consider the following examples:
Expand Down
58 changes: 58 additions & 0 deletions packages/webiny-plugins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# webiny-plugins

A simple registry for plugins that stores all plugins in a shared object.
The only requirement for a plugin is to have a `name` and a `type` properties. The rest is entirely up to you.

There is nothing spectacular going on under the hood, just a simple object for storing references and a few utility functions.
However, this simple library has helped us greatly while developing modular APIs and UIs in React.

## Installation
`yarn add webiny-plugins`

## Adding a plugin
```
import { addPlugin } from "webiny-plugins";
// Add a plugin
addPlugin({
name: "my-plugin",
type: "say-hi",
salute: () => "Hi!"
});
addPlugin({
name: "my-second-plugin",
type: "say-hi",
salute: () => "Yo!"
});
```

## Getting plugins by type
```
// anywhere in your app
import { getPlugins } from "webiny-plugins";
const plugins = getPlugins("say-hi");
plugins.forEach(plugin => {
// Call "salute" function
plugin.salute();
});
```

## Getting a single plugin by name
```
// anywhere in your app
import { getPlugin } from "webiny-plugins";
const plugin = getPlugin("my-plugin");
// Call "salute" function
plugin.salute();
```

## Removing a plugin
```
// anywhere in your app
import { removePlugin } from "webiny-plugins";
removePlugin("my-plugin");
```

0 comments on commit 3238c01

Please sign in to comment.