diff --git a/packages/webiny-api/types.js b/packages/webiny-api/types.js index 11f991ca55a..592755b23a5 100644 --- a/packages/webiny-api/types.js +++ b/packages/webiny-api/types.js @@ -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} - */ - encode(identity: Identity, expiresOn: number): Promise; - /** - * Decode token. - * @param {string} token - * @return {Object} Token data. - */ - decode(token: string): Promise; -} - -export interface IStrategy { - /** - * Define args for GraphQL endpoint - */ - args: () => Object; - authenticate: (args: Object, identity: Class) => Promise; -} - -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 } }; export type GraphQLSchemaPluginType = PluginType & { namespace: string, - typedefs: Array | Function>, - resolvers: Object | Function + typedefs: Array | () => Array, + resolvers: Object | () => Object }; export type GraphQLContextPluginType = PluginType & { diff --git a/packages/webiny-entity/README.md b/packages/webiny-entity/README.md index 5e196856b21..235eb6c6174 100644 --- a/packages/webiny-entity/README.md +++ b/packages/webiny-entity/README.md @@ -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: diff --git a/packages/webiny-plugins/README.md b/packages/webiny-plugins/README.md new file mode 100644 index 00000000000..658404699f3 --- /dev/null +++ b/packages/webiny-plugins/README.md @@ -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"); +```