mirror of
https://github.com/HeyPuter/puter.git
synced 2025-01-23 14:20:22 +08:00
doc: add more extensions documentation
This commit is contained in:
parent
1679648780
commit
73f738c9d9
@ -1,2 +1,3 @@
|
|||||||
### `vscode`
|
## Puter Extensions
|
||||||
- `es6-string-html`
|
|
||||||
|
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 { Context } = require("./util/context");
|
||||||
const { ExtensionServiceState } = require("./ExtensionService");
|
const { ExtensionServiceState } = require("./ExtensionService");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class creates the `extension` global that is seem by Puter backend
|
||||||
|
* extensions.
|
||||||
|
*/
|
||||||
class Extension extends AdvancedBase {
|
class Extension extends AdvancedBase {
|
||||||
static FEATURES = [
|
static FEATURES = [
|
||||||
EmitterFeature({
|
EmitterFeature({
|
||||||
@ -24,6 +28,9 @@ class Extension extends AdvancedBase {
|
|||||||
console.log('Example method called by an extension.');
|
console.log('Example method called by an extension.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will get a database instance from the default service.
|
||||||
|
*/
|
||||||
get db () {
|
get db () {
|
||||||
const db = this.service.values.get('db');
|
const db = this.service.values.get('db');
|
||||||
if ( ! db ) {
|
if ( ! db ) {
|
||||||
@ -35,6 +42,12 @@ class Extension extends AdvancedBase {
|
|||||||
return db;
|
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) {
|
get (path, handler, options) {
|
||||||
// this extension will have a default service
|
// this extension will have a default service
|
||||||
this.ensure_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) {
|
post (path, handler, options) {
|
||||||
// this extension will have a default service
|
// this extension will have a default service
|
||||||
this.ensure_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_ () {
|
ensure_service_ () {
|
||||||
if ( this.service ) {
|
if ( this.service ) {
|
||||||
return;
|
return;
|
||||||
|
@ -5,6 +5,11 @@ const configurable_auth = require("./middleware/configurable_auth");
|
|||||||
const { Context } = require("./util/context");
|
const { Context } = require("./util/context");
|
||||||
const { DB_READ, DB_WRITE } = require("./services/database/consts");
|
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 {
|
class ExtensionServiceState extends AdvancedBase {
|
||||||
constructor (...a) {
|
constructor (...a) {
|
||||||
super(...a);
|
super(...a);
|
||||||
|
Loading…
Reference in New Issue
Block a user