@@ -26,23 +26,32 @@ By default, ObjectQL uses these API paths:
2626
2727### Basic Usage
2828
29- Configure custom routes when creating handlers :
29+ Configure custom routes when creating the Kernel with protocol plugins :
3030
3131``` typescript
32- import { createNodeHandler , createRESTHandler , createMetadataHandler } from ' @objectql/server' ;
33-
34- // Define custom routes
35- const customRoutes = {
36- rpc: ' /v1/rpc' ,
37- data: ' /v1/resources' ,
38- metadata: ' /v1/schema' ,
39- files: ' /v1/storage'
40- };
41-
42- // Create handlers with custom routes
43- const nodeHandler = createNodeHandler (app , { routes: customRoutes });
44- const restHandler = createRESTHandler (app , { routes: customRoutes });
45- const metadataHandler = createMetadataHandler (app , { routes: customRoutes });
32+ import { ObjectStackKernel } from ' @objectstack/runtime' ;
33+ import { HonoServerPlugin } from ' @objectstack/plugin-hono-server' ;
34+ import { ObjectQLPlugin } from ' @objectql/core' ;
35+ import { JSONRPCPlugin } from ' @objectql/protocol-json-rpc' ;
36+ import { MemoryDriver } from ' @objectql/driver-memory' ;
37+
38+ // Define custom routes via plugin configuration
39+ const kernel = new ObjectStackKernel ([
40+ appConfig ,
41+ new MemoryDriver (),
42+ new ObjectQLPlugin (),
43+ new JSONRPCPlugin ({ basePath: ' /v1/rpc' }),
44+ new HonoServerPlugin ({
45+ port: 3000 ,
46+ routes: {
47+ data: ' /v1/resources' ,
48+ metadata: ' /v1/schema' ,
49+ files: ' /v1/storage'
50+ }
51+ })
52+ ]);
53+
54+ await kernel .start ();
4655```
4756
4857### Route Configuration Interface
@@ -78,62 +87,55 @@ interface ApiRouteConfig {
7887## Complete Example
7988
8089``` typescript
81- import express from ' express' ;
82- import { ObjectQL } from ' @objectql/core' ;
90+ import { ObjectStackKernel } from ' @objectstack/runtime' ;
91+ import { HonoServerPlugin } from ' @objectstack/plugin-hono-server' ;
92+ import { ObjectQLPlugin } from ' @objectql/core' ;
8393import { SqlDriver } from ' @objectql/driver-sql' ;
84- import { createNodeHandler , createRESTHandler , createMetadataHandler } from ' @objectql/server ' ;
94+ import { JSONRPCPlugin } from ' @objectql/protocol-json-rpc ' ;
8595
8696async function main() {
87- // 1. Initialize ObjectQL
88- const app = new ObjectQL ({
89- datasources: {
90- default: new SqlDriver ({
91- client: ' sqlite3' ,
92- connection: { filename: ' :memory:' },
93- useNullAsDefault: true
94- })
95- }
96- });
97-
98- // Register your objects
99- app .registerObject ({
100- name: ' user' ,
101- label: ' User' ,
102- fields: {
103- name: { type: ' text' , label: ' Name' },
104- email: { type: ' email' , label: ' Email' }
97+ // 1. Define app configuration
98+ const appConfig = {
99+ name: ' my-app' ,
100+ objects: {
101+ user: {
102+ name: ' user' ,
103+ label: ' User' ,
104+ fields: {
105+ name: { type: ' text' , label: ' Name' },
106+ email: { type: ' email' , label: ' Email' }
107+ }
108+ }
105109 }
106- });
107-
108- await app .init ();
109-
110- // 2. Define custom API routes
111- const customRoutes = {
112- rpc: ' /v1/rpc' ,
113- data: ' /v1/resources' ,
114- metadata: ' /v1/schema' ,
115- files: ' /v1/storage'
116110 };
117111
118- // 3. Create handlers with custom routes
119- const nodeHandler = createNodeHandler (app , { routes: customRoutes });
120- const restHandler = createRESTHandler (app , { routes: customRoutes });
121- const metadataHandler = createMetadataHandler (app , { routes: customRoutes });
122-
123- // 4. Setup Express with custom paths
124- const server = express ();
112+ // 2. Create Kernel with custom route configuration
113+ const kernel = new ObjectStackKernel ([
114+ appConfig ,
115+ new SqlDriver ({
116+ client: ' sqlite3' ,
117+ connection: { filename: ' :memory:' },
118+ useNullAsDefault: true
119+ }),
120+ new ObjectQLPlugin (),
121+ new JSONRPCPlugin ({ basePath: ' /v1/rpc' }),
122+ new HonoServerPlugin ({
123+ port: 3000 ,
124+ routes: {
125+ data: ' /v1/resources' ,
126+ metadata: ' /v1/schema' ,
127+ files: ' /v1/storage'
128+ }
129+ })
130+ ]);
125131
126- server .all (' /v1/rpc*' , nodeHandler );
127- server .all (' /v1/resources/*' , restHandler );
128- server .all (' /v1/schema*' , metadataHandler );
132+ await kernel .start ();
129133
130- server .listen (3000 , () => {
131- console .log (' 🚀 Server running with custom routes' );
132- console .log (' JSON-RPC: http://localhost:3000/v1/rpc' );
133- console .log (' REST API: http://localhost:3000/v1/resources' );
134- console .log (' Metadata: http://localhost:3000/v1/schema' );
135- console .log (' Files: http://localhost:3000/v1/storage' );
136- });
134+ console .log (' 🚀 Server running with custom routes' );
135+ console .log (' JSON-RPC: http://localhost:3000/v1/rpc' );
136+ console .log (' REST API: http://localhost:3000/v1/resources' );
137+ console .log (' Metadata: http://localhost:3000/v1/schema' );
138+ console .log (' Files: http://localhost:3000/v1/storage' );
137139}
138140
139141main ().catch (console .error );
0 commit comments