Skip to content

Commit 1bd0966

Browse files
committed
Update plugin configuration and usage documentation
Clarified that plugins can be specified as instances or package names in the configuration. Expanded the plugins guide to explain both loading methods and added instructions for creating and publishing plugin packages.
1 parent a3caf55 commit 1bd0966

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

docs/guide/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ A list of NPM packages to load as presets.
3535
ObjectQL will try to resolve the package and load schema files from its directory.
3636
Useful for sharing common business objects (User, Role, File, etc.).
3737

38-
### `plugins` (ObjectQLPlugin[])
39-
A list of plugin instances to extend the core functionality.
38+
### `plugins` ((ObjectQLPlugin | string)[])
39+
A list of plugin instances OR package names to extend the core functionality.
4040
See [Plugin System](./plugins.html) for details.
4141

4242
### `objects` (Record<string, ObjectConfig>)

docs/guide/plugins.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export class SoftDeletePlugin implements ObjectQLPlugin {
7373

7474
## Usage
7575

76+
Plugins can be loaded in two ways: by instance or by package name.
77+
78+
### 1. By Instance (Local Development)
79+
7680
```typescript
7781
const db = new ObjectQL({
7882
connection: 'sqlite://data.db',
@@ -81,3 +85,44 @@ const db = new ObjectQL({
8185
]
8286
});
8387
```
88+
89+
### 2. By Package Name (Distribution)
90+
91+
If you have installed a plugin via npm (e.g. `npm install @objectql/plugin-audit`), you can simply pass its name. ObjectQL will automatically resolve and instantiate it.
92+
93+
```typescript
94+
const db = new ObjectQL({
95+
connection: 'sqlite://data.db',
96+
plugins: [
97+
'@objectql/plugin-audit'
98+
]
99+
});
100+
```
101+
102+
## Creating a Plugin Package
103+
104+
To publish a plugin as an npm package:
105+
106+
1. Create a project exporting your plugin class/instance as the `default` export (or named export).
107+
2. Ensure it implements `ObjectQLPlugin`.
108+
109+
**index.ts**
110+
```typescript
111+
import { ObjectQLPlugin, IObjectQL } from '@objectql/types';
112+
113+
export default class MyPlugin implements ObjectQLPlugin {
114+
name = 'my-plugin';
115+
setup(app: IObjectQL) {
116+
// ...
117+
}
118+
}
119+
```
120+
121+
Then in another project:
122+
```bash
123+
npm install my-plugin-package
124+
```
125+
```typescript
126+
// objectql.config.ts
127+
plugins: ['my-plugin-package']
128+
```

0 commit comments

Comments
 (0)