Skip to content

Commit 4ca5dfa

Browse files
committed
feat(plugins): implement definePlugin helper and update plugin context types
1 parent e013a25 commit 4ca5dfa

9 files changed

Lines changed: 32 additions & 15 deletions

File tree

examples/plugin-bi/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PluginDefinition } from '@objectstack/spec/system';
1+
import { definePlugin } from '@objectstack/spec';
22

33
export class BiEngine {
44
constructor() {
@@ -15,7 +15,7 @@ export class BiEngine {
1515
}
1616
}
1717

18-
const plugin: PluginDefinition = {
18+
const plugin = definePlugin({
1919
id: 'com.objectstack.bi',
2020
version: '1.0.0',
2121

@@ -58,6 +58,6 @@ const plugin: PluginDefinition = {
5858

5959
logger.info('[BI Plugin] Services registered.');
6060
}
61-
};
61+
});
6262

6363
export default plugin;
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../../tsconfig.base.json",
2+
"extends": "../../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "./dist",
55
"rootDir": "./src",
@@ -8,5 +8,6 @@
88
"esModuleInterop": true,
99
"skipLibCheck": true
1010
},
11-
"include": ["src/**/*"]
11+
"include": ["src/**/*"],
12+
"exclude": ["node_modules", "dist"]
1213
}

packages/adapters/nestjs/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { DynamicModule, Module, Global, Inject, Provider, Controller, Post, Get, Patch, Delete, Body, Param, Query, Req, Res, All, UseGuards, createParamDecorator, ExecutionContext } from '@nestjs/common';
1+
import { DynamicModule, Module, Global, Inject, Provider, Controller, Post, Get, Patch, Delete, Body, Param, Query, Req, Res, All, createParamDecorator, ExecutionContext } from '@nestjs/common';
22
import { Injectable } from '@nestjs/common';
33
import { ObjectKernel } from '@objectstack/runtime';
44

55
export const OBJECT_KERNEL = 'OBJECT_KERNEL';
66

77
export const ConnectReq = createParamDecorator(
8-
(data: unknown, ctx: ExecutionContext) => {
8+
(_data: unknown, ctx: ExecutionContext) => {
99
return ctx.switchToHttp().getRequest();
1010
},
1111
);

packages/adapters/nestjs/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../../tsconfig.base.json",
2+
"extends": "../../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "./dist",
55
"rootDir": "./src",
@@ -10,5 +10,6 @@
1010
"esModuleInterop": true,
1111
"skipLibCheck": true
1212
},
13-
"include": ["src/**/*"]
13+
"include": ["src/**/*"],
14+
"exclude": ["node_modules", "dist"]
1415
}

packages/adapters/nextjs/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ export function createRouteHandler(options: NextAdapterOptions) {
8181
// 0. Auth
8282
if (segments[0] === 'auth') {
8383
if (segments[1] === 'login' && method === 'POST') {
84-
const body = await req.json();
84+
const body = await req.json() as any;
8585
const data = await kernel.broker.call('auth.login', body, { request: rawRequest });
8686
return NextResponse.json(data);
8787
}
8888
}
8989

9090
// 1. GraphQL
9191
if (segments[0] === 'graphql' && method === 'POST') {
92-
const body = await req.json();
92+
const body = await req.json() as any;
9393
const result = await kernel.graphql(body.query, body.variables, { request: rawRequest });
9494
return NextResponse.json(result);
9595
}
@@ -116,14 +116,14 @@ export function createRouteHandler(options: NextAdapterOptions) {
116116

117117
// POST /data/:objectName/query
118118
if (segments[2] === 'query' && method === 'POST') {
119-
const body = await req.json();
119+
const body = await req.json() as any;
120120
const result = await kernel.broker.call('data.query', { object: objectName, ...body }, { request: rawRequest });
121121
return success(result.data, { count: result.count, limit: body.limit, skip: body.skip });
122122
}
123123

124124
// POST /data/:objectName/batch
125125
if (segments[2] === 'batch' && method === 'POST') {
126-
const body = await req.json();
126+
const body = await req.json() as any;
127127
const result = await kernel.broker.call('data.batch', { object: objectName, operations: body.operations }, { request: rawRequest });
128128
return success(result);
129129
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../../tsconfig.base.json",
2+
"extends": "../../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "./dist",
55
"rootDir": "./src",
@@ -8,5 +8,6 @@
88
"esModuleInterop": true,
99
"skipLibCheck": true
1010
},
11-
"include": ["src/**/*"]
11+
"include": ["src/**/*"],
12+
"exclude": ["node_modules", "dist"]
1213
}

packages/spec/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ export {
7070

7171
export * from './stack.zod';
7272

73+
export { definePlugin, type PluginContext } from './kernel/plugin.zod';
74+

packages/spec/src/kernel/plugin.zod.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export const PluginContextSchema = z.object({
9999
});
100100

101101
export type PluginContextData = z.infer<typeof PluginContextSchema>;
102+
export type PluginContext = PluginContextData;
102103

103104
export const PluginLifecycleSchema = z.object({
104105
onInstall: z.function({
@@ -138,3 +139,11 @@ export const PluginSchema = PluginLifecycleSchema.extend({
138139
});
139140

140141
export type PluginDefinition = z.infer<typeof PluginSchema>;
142+
143+
/**
144+
* Define an ObjectStack Plugin
145+
* Helper function for creating type-safe plugin definitions
146+
*/
147+
export function definePlugin(config: PluginDefinition): PluginDefinition {
148+
return config;
149+
}

packages/spec/src/stack.zod.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,6 @@ export type ObjectQLCapabilities = z.infer<typeof ObjectQLCapabilitiesSchema>;
319319
export type ObjectUICapabilities = z.infer<typeof ObjectUICapabilitiesSchema>;
320320
export type ObjectOSCapabilities = z.infer<typeof ObjectOSCapabilitiesSchema>;
321321
export type ObjectStackCapabilities = z.infer<typeof ObjectStackCapabilitiesSchema>;
322+
323+
324+

0 commit comments

Comments
 (0)