Skip to content

Commit aea50c6

Browse files
committed
Refactor driver and plugin imports; migrate to @objectstack/core and remove deprecated JSON schemas
1 parent ac241fb commit aea50c6

File tree

25 files changed

+54
-428
lines changed

25 files changed

+54
-428
lines changed

content/docs/developers/server-drivers.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ my-custom-db/
7676

7777
```typescript
7878
// src/driver.ts
79+
import { DriverInterface } from '@objectstack/core';
7980
import {
80-
DriverInterface,
8181
DriverOptions,
8282
DriverCapabilities,
8383
} from '@objectstack/spec';
@@ -560,7 +560,8 @@ Complete implementation of a simple in-memory driver:
560560

561561
```typescript
562562
// src/memory-driver.ts
563-
import { DriverInterface, DriverCapabilities } from '@objectstack/spec';
563+
import { DriverInterface } from '@objectstack/core';
564+
import { DriverCapabilities } from '@objectstack/spec';
564565
import { Query, QueryResult } from '@objectstack/objectql';
565566
566567
export class InMemoryDriver implements DriverInterface {
@@ -793,7 +794,7 @@ export class InMemoryDriver implements DriverInterface {
793794
```typescript
794795
// src/postgres-driver.ts
795796
import { Pool } from 'pg';
796-
import { DriverInterface } from '@objectstack/spec';
797+
import { DriverInterface } from '@objectstack/core';
797798
import { Query } from '@objectstack/objectql';
798799
799800
export class PostgresDriver implements DriverInterface {

content/docs/developers/writing-plugins.mdx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,32 @@ export default defineManifest({
133133

134134
```typescript
135135
// src/index.ts
136-
import { PluginContext } from '@objectstack/spec';
136+
import { Plugin } from '@objectstack/core';
137137
import { Account } from './objects/account.object';
138138
import { registerWebhooks } from './routes/webhooks';
139139
import { startSyncJob } from './jobs/sync';
140140

141-
export default {
141+
const myPlugin: Plugin = {
142+
name: 'my-crm-plugin',
143+
version: '1.0.0',
144+
142145
/**
143146
* Called when the plugin is enabled.
144147
* Register objects, routes, jobs, and event listeners here.
145148
*/
146-
onEnable: async (context: PluginContext) => {
147-
const { ql, os, logger, router, scheduler, storage } = context;
149+
init: async (context) => {
150+
// context comes from @objectstack/core
151+
const { logger } = context;
148152

149153
logger.info('My CRM Plugin enabled');
150154

155+
/*
156+
Note: Accessing services like 'ql' or 'router' depends on
157+
what plugins are installed in the kernel.
158+
const ql = context.getService('objectql');
159+
*/
160+
},
161+
151162
// Register custom objects
152163
await ql.registerObject(Account);
153164

@@ -343,7 +354,7 @@ Add custom HTTP endpoints for webhooks, integrations, or custom APIs:
343354

344355
```typescript
345356
// src/routes/webhooks.ts
346-
import { Router } from '@objectstack/spec';
357+
import { IHttpServer } from '@objectstack/core';
347358
import { z } from 'zod';
348359

349360
const WebhookPayloadSchema = z.object({
@@ -352,13 +363,13 @@ const WebhookPayloadSchema = z.object({
352363
timestamp: z.string(),
353364
});
354365

355-
export function registerWebhooks(router: Router) {
366+
export function registerWebhooks(server: IHttpServer) {
356367

357368
// ============================================================================
358369
// POST /api/webhooks/account
359370
// ============================================================================
360371

361-
router.post('/api/webhooks/account', async (req, res) => {
372+
server.post('/api/webhooks/account', async (req, res) => {
362373
try {
363374
// Validate webhook payload
364375
const payload = WebhookPayloadSchema.parse(req.body);
@@ -385,7 +396,7 @@ export function registerWebhooks(router: Router) {
385396
// GET /api/integrations/sync
386397
// ============================================================================
387398

388-
router.get('/api/integrations/sync', async (req, res) => {
399+
server.get('/api/integrations/sync', async (req, res) => {
389400
const { ql, logger } = req.context;
390401

391402
try {
@@ -439,7 +450,7 @@ Run tasks periodically using cron expressions:
439450

440451
```typescript
441452
// src/jobs/sync.ts
442-
import { PluginContext } from '@objectstack/spec';
453+
import { PluginContext } from '@objectstack/core';
443454

444455
export async function startSyncJob(context: PluginContext) {
445456
const { ql, os, logger, storage } = context;
@@ -506,7 +517,7 @@ React to data changes in real-time:
506517

507518
```typescript
508519
// src/events/account-created.ts
509-
import { PluginContext } from '@objectstack/spec';
520+
import { PluginContext } from '@objectstack/core';
510521

511522
export function registerEventListeners(context: PluginContext) {
512523
const { ql, logger } = context;

content/docs/references/system/data-engine.mdx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,15 @@ description: Data Engine protocol schemas
1212
## TypeScript Usage
1313

1414
```typescript
15-
import { DataEngineSchema, DataEngineFilterSchema, DataEngineQueryOptionsSchema } from '@objectstack/spec/system';
16-
import type { DataEngine, DataEngineFilter, DataEngineQueryOptions } from '@objectstack/spec/system';
15+
import { DataEngineFilterSchema, DataEngineQueryOptionsSchema } from '@objectstack/spec/system';
16+
import type { DataEngineFilter, DataEngineQueryOptions } from '@objectstack/spec/system';
1717

1818
// Validate data
19-
const result = DataEngineSchema.parse(data);
19+
const result = DataEngineFilterSchema.parse(data);
2020
```
2121

2222
---
2323

24-
## DataEngine
25-
26-
Data Engine Interface
27-
28-
### Properties
29-
30-
| Property | Type | Required | Description |
31-
| :--- | :--- | :--- | :--- |
32-
33-
---
34-
3524
## DataEngineFilter
3625

3726
Data Engine query filter conditions

content/docs/references/system/index.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ This section contains all protocol schemas for the system layer of ObjectStack.
1818
<Card href="./job" title="Job" description="Source: packages/spec/src/system/job.zod.ts" />
1919
<Card href="./logger" title="Logger" description="Source: packages/spec/src/system/logger.zod.ts" />
2020
<Card href="./manifest" title="Manifest" description="Source: packages/spec/src/system/manifest.zod.ts" />
21-
<Card href="./plugin" title="Plugin" description="Source: packages/spec/src/system/plugin.zod.ts" />
2221
<Card href="./scoped-storage" title="Scoped Storage" description="Source: packages/spec/src/system/scoped-storage.zod.ts" />
2322
<Card href="./translation" title="Translation" description="Source: packages/spec/src/system/translation.zod.ts" />
2423
</Cards>

content/docs/references/system/meta.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"job",
1212
"logger",
1313
"manifest",
14-
"plugin",
1514
"scoped-storage",
1615
"translation"
1716
]

content/docs/references/system/plugin.mdx

Lines changed: 0 additions & 140 deletions
This file was deleted.

packages/core/src/contracts/data-engine.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { QueryAST } from '@objectstack/spec/data';
2+
import { DriverOptions } from '@objectstack/spec/system';
3+
14
/**
25
* IDataEngine - Standard Data Engine Interface
36
*
@@ -32,16 +35,18 @@ export interface IDataEngine {
3235
delete(objectName: string, id: any): Promise<boolean>;
3336
}
3437

35-
// Driver Interface specific to storage drivers
36-
export interface DriverOptions {
37-
name?: string;
38-
url?: string;
39-
[key: string]: any;
40-
}
41-
42-
export interface DriverInterface extends IDataEngine {
38+
export interface DriverInterface {
4339
name: string;
4440
version: string;
4541
connect(): Promise<void>;
4642
disconnect(): Promise<void>;
43+
44+
find(object: string, query: QueryAST, options?: DriverOptions): Promise<any[]>;
45+
findOne(object: string, query: QueryAST, options?: DriverOptions): Promise<any>;
46+
create(object: string, data: any, options?: DriverOptions): Promise<any>;
47+
update(object: string, id: any, data: any, options?: DriverOptions): Promise<any>;
48+
delete(object: string, id: any, options?: DriverOptions): Promise<any>;
49+
50+
count?(object: string, query: QueryAST, options?: DriverOptions): Promise<number>;
4751
}
52+

packages/core/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "./dist",
5-
"rootDir": "./src"
5+
"rootDir": "./src",
6+
"moduleResolution": "bundler",
7+
"module": "esnext"
68
},
79
"include": ["src/**/*"],
810
"exclude": []

packages/driver-memory/src/memory-driver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { QueryAST, QueryInput } from '@objectstack/spec/data';
2-
import { DriverInterface, DriverOptions } from '@objectstack/spec/system';
2+
import { DriverOptions } from '@objectstack/spec/system';
3+
import { DriverInterface } from '@objectstack/core';
34

45
/**
56
* Example: In-Memory Driver

packages/objectql/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { QueryAST, HookContext } from '@objectstack/spec/data';
22
import { ObjectStackManifest } from '@objectstack/spec/system';
3-
import { DriverInterface, DriverOptions } from '@objectstack/spec/system';
4-
import { IDataEngine, DataEngineQueryOptions } from '@objectstack/spec/system';
3+
import { DriverOptions } from '@objectstack/spec/system';
4+
import { DriverInterface, IDataEngine, DataEngineQueryOptions } from '@objectstack/core';
55
import { SchemaRegistry } from './registry';
66

77
// Export Registry for consumers

0 commit comments

Comments
 (0)