Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/epic-digital-im/webpack-plugin-parse-functions

A Webpack plugin for Parse Platform development
https://github.com/epic-digital-im/webpack-plugin-parse-functions

parse-server parseplatform webpack

Last synced: 28 days ago
JSON representation

A Webpack plugin for Parse Platform development

Awesome Lists containing this project

README

        


:package: webpack-plugin-parse-functions
:package: webpack-plugin-parse-functions

:package: webpack-plugin-parse-functions


Parse Platform Function Plugin



Report Bug
Request Feature


Parse Platform Function Plugin 🚀

# Overview
This is a Webpack plugin designed to make development on top of the Parse Platform more seamless.

# Getting Started
## How it works
If you're familiar with Next.js, you know that the routes are built out based on the file structure of the project. This follows a similar methodology.

The default file structure looks like this:
- src
- functions
- ``
- schema.json -- the schema of the `Parse.Object`-based service
- ``
- `0..ts`
- config.ts -- the configuration object to be passed to `Parse.Cloud.(, , )`
- functions
- `.ts` - functions to be defined with `Parse.Cloud.define('', )`
- jobs
- `.ts` - jobs to be defined with `Parse.Cloud.job('', )`
- triggers
- `.ts` - post-hook triggers that will conditionally run `Parse.Cloud.run('', payload)`, where `payload` is the parameter of the running hook
- `.....`

The available hooks are:
- beforeSave
- afterSave
- beforeDelete
- afterDelete
- afterCreate
- afterUpdate
- beforeCreate
- beforeUpdate

These hooks targeted at cron jobs are defined and available to be run with `Parse.Cloud.startJob('_')`
- hourly -- e.g. `Parse.Cloud.startJob('ActionItem_hourly')`
- daily
- weekly
- monthly
- datetime

## ActionTrigger
This is a special type of `Parse.Object` that is used to trigger cascading actions conditionally when a hook is run.

There are 4 conditions that must be met before an ActionTrigger will take effect:
- `ActionTrigger.active` is true
- `ActionTrigger.objectClass` matches the class of Parse.Object that is being run through the hook
- `object[ActionTrigger.property]` -> `ActionTrigger.condition` -> `ActionTrigger.value`. For example:
- `user.email` -> `equalTo` -> `[email protected]` -- this trigger will run only when the `User` instance's `email` property is equal to `[email protected]`
- `ActionTrigger.handler` is equal to an extant trigger handler function name (i.e. in the `src/functions//triggers/.ts`)

If your project doesn't need to trigger cascading function calls, you won't need to worry about this.

## How to Use
This is a normal Webpack plugin and can be used like so:

```js
// webpack.config.js
const path = require('path');
const ParseFunctionsPlugin = require('../dist/main').default;

const config = {
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new ParseFunctionsPlugin(),
],
// ...and the rest
};
```

### Plugin Options
```js
{
functionDirectory: 'src/functions', // the directory to watch & build Parse functions
moduleAlias: '@@functions', // the alias name used for importing the built files
// from, e.g. `import initialize, { ClassNames } from '@@functions';`
}
```
The default option should be preferred, but there may be times where the project requires that you diverge from these naming conventions.

### On Build
When the plugin runs, it will aggregate the files (according to the file structure above) and transpile them into modules in a `.build` folder that may then be accessed by importing members from the `moduleAlias` (default `@@functions`);

### Built Exports
After building, the built modules can be accessed using the module alias (default: `@@functions`), and will export the following.

#### Constants
```typescript
export enum ClassNames {
[]: ''
}

export const ClassNamesList = Object.values(ClassNames);

export const TriggerHandlers: TriggerHandlersMap = {
: [
{
label: "",
value: "",
},
],
};

export const Schemas: SchemaMap = {
[]: { /* ...JSON object representation of Parse.Object schema */ }
}
```

#### Types
```typescript
export type SchemaMap = {
[prop in ClassNames]: ParseFunctionServiceSchema;
};

export type TriggerHandlerOption = {
label: string;
value: string;
};

export type TriggerHandlersMap = {
[prop in ClassNames]: TriggerHandlerOption[];
};
```

#### Initializer
```typescript
/* === INITIALIZER === */
const initialize = (Parse: ParseType) => {
(Parse);
/* ... more services here ... */
};

export default initialize;
```

# TODO
- [x] Create custom hook handlers for:
- [x] beforeCreate -- fires before the initial creation of an object
- [x] afterCreate -- fires after the initial creation of an object
- [x] beforeUpdate -- fires before a previously created object is updated
- [x] afterUpdate -- fires after a previously created object is updated
- [x] hourly -- a cron job that fires hourly
- [x] daily -- a cron job that fires daily
- [x] weekly -- a cron job that fires weekly
- [x] monthly -- a cron job that fires monthly
- [x] datetime -- a cron job that fires on a specific datetime
- [x] Make a `processActionTriggers` function to avoid duplicate code
- [x] Rework functions, jobs, and triggers to export a factory function that takes a `Parse` instance as the first parameter, a configuration or context parameter, and returns a function
- [ ] Make helper types for hooks, functions, jobs, and triggers
- [x] Make export for trigger handler parameter schema