mirror of
https://github.com/HeyPuter/puter.git
synced 2025-01-23 06:00:21 +08:00
doc: add more extensions documentation
This commit is contained in:
parent
1679648780
commit
73f738c9d9
@ -1,2 +1,3 @@
|
||||
### `vscode`
|
||||
- `es6-string-html`
|
||||
## Puter Extensions
|
||||
|
||||
See the [Wiki Page](https://github.com/HeyPuter/puter/wiki/ex_extensions)
|
||||
|
2
doc/contributors/vscode.md
Normal file
2
doc/contributors/vscode.md
Normal file
@ -0,0 +1,2 @@
|
||||
### `vscode`
|
||||
- `es6-string-html`
|
@ -3,6 +3,10 @@ const EmitterFeature = require("@heyputer/putility/src/features/EmitterFeature")
|
||||
const { Context } = require("./util/context");
|
||||
const { ExtensionServiceState } = require("./ExtensionService");
|
||||
|
||||
/**
|
||||
* This class creates the `extension` global that is seem by Puter backend
|
||||
* extensions.
|
||||
*/
|
||||
class Extension extends AdvancedBase {
|
||||
static FEATURES = [
|
||||
EmitterFeature({
|
||||
@ -24,6 +28,9 @@ class Extension extends AdvancedBase {
|
||||
console.log('Example method called by an extension.');
|
||||
}
|
||||
|
||||
/**
|
||||
* This will get a database instance from the default service.
|
||||
*/
|
||||
get db () {
|
||||
const db = this.service.values.get('db');
|
||||
if ( ! db ) {
|
||||
@ -35,6 +42,12 @@ class Extension extends AdvancedBase {
|
||||
return db;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will create a GET endpoint on the default service.
|
||||
* @param {*} path - route for the endpoint
|
||||
* @param {*} handler - function to handle the endpoint
|
||||
* @param {*} options - options like noauth (bool) and mw (array)
|
||||
*/
|
||||
get (path, handler, options) {
|
||||
// this extension will have a default service
|
||||
this.ensure_service_();
|
||||
@ -51,6 +64,12 @@ class Extension extends AdvancedBase {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This will create a POST endpoint on the default service.
|
||||
* @param {*} path - route for the endpoint
|
||||
* @param {*} handler - function to handle the endpoint
|
||||
* @param {*} options - options like noauth (bool) and mw (array)
|
||||
*/
|
||||
post (path, handler, options) {
|
||||
// this extension will have a default service
|
||||
this.ensure_service_();
|
||||
@ -67,6 +86,13 @@ class Extension extends AdvancedBase {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will create the "default service" for an extension.
|
||||
* This is specifically for Puter extensions that do not define their
|
||||
* own service classes.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
ensure_service_ () {
|
||||
if ( this.service ) {
|
||||
return;
|
||||
|
@ -5,6 +5,11 @@ const configurable_auth = require("./middleware/configurable_auth");
|
||||
const { Context } = require("./util/context");
|
||||
const { DB_READ, DB_WRITE } = require("./services/database/consts");
|
||||
|
||||
/**
|
||||
* State shared with the default service and the `extension` global so that
|
||||
* methods on `extension` can register routes (and make other changes in the
|
||||
* future) to the default service.
|
||||
*/
|
||||
class ExtensionServiceState extends AdvancedBase {
|
||||
constructor (...a) {
|
||||
super(...a);
|
||||
|
Loading…
Reference in New Issue
Block a user