@objectstack/rest 4.0.3 → 4.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -17
- package/dist/index.cjs +722 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +133 -2
- package/dist/index.d.ts +133 -2
- package/dist/index.js +712 -60
- package/dist/index.js.map +1 -1
- package/package.json +32 -6
- package/.turbo/turbo-build.log +0 -22
- package/CHANGELOG.md +0 -473
- package/src/index.ts +0 -12
- package/src/rest-api-plugin.ts +0 -72
- package/src/rest-server.ts +0 -691
- package/src/rest.test.ts +0 -672
- package/src/route-manager.ts +0 -308
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -10
package/CHANGELOG.md
DELETED
|
@@ -1,473 +0,0 @@
|
|
|
1
|
-
# @objectstack/rest
|
|
2
|
-
|
|
3
|
-
## 4.0.3
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- @objectstack/spec@4.0.3
|
|
8
|
-
- @objectstack/core@4.0.3
|
|
9
|
-
|
|
10
|
-
## 4.0.2
|
|
11
|
-
|
|
12
|
-
### Patch Changes
|
|
13
|
-
|
|
14
|
-
- Updated dependencies [5f659e9]
|
|
15
|
-
- @objectstack/spec@4.0.2
|
|
16
|
-
- @objectstack/core@4.0.2
|
|
17
|
-
|
|
18
|
-
## 4.0.0
|
|
19
|
-
|
|
20
|
-
### Patch Changes
|
|
21
|
-
|
|
22
|
-
- Updated dependencies [f08ffc3]
|
|
23
|
-
- Updated dependencies [e0b0a78]
|
|
24
|
-
- @objectstack/spec@4.0.0
|
|
25
|
-
- @objectstack/core@4.0.0
|
|
26
|
-
|
|
27
|
-
## 3.3.1
|
|
28
|
-
|
|
29
|
-
### Patch Changes
|
|
30
|
-
|
|
31
|
-
- @objectstack/spec@3.3.1
|
|
32
|
-
- @objectstack/core@3.3.1
|
|
33
|
-
|
|
34
|
-
## 3.3.0
|
|
35
|
-
|
|
36
|
-
### Patch Changes
|
|
37
|
-
|
|
38
|
-
- @objectstack/spec@3.3.0
|
|
39
|
-
- @objectstack/core@3.3.0
|
|
40
|
-
|
|
41
|
-
## 3.2.9
|
|
42
|
-
|
|
43
|
-
### Patch Changes
|
|
44
|
-
|
|
45
|
-
- @objectstack/spec@3.2.9
|
|
46
|
-
- @objectstack/core@3.2.9
|
|
47
|
-
|
|
48
|
-
## 3.2.8
|
|
49
|
-
|
|
50
|
-
### Patch Changes
|
|
51
|
-
|
|
52
|
-
- @objectstack/spec@3.2.8
|
|
53
|
-
- @objectstack/core@3.2.8
|
|
54
|
-
|
|
55
|
-
## 3.2.7
|
|
56
|
-
|
|
57
|
-
### Patch Changes
|
|
58
|
-
|
|
59
|
-
- @objectstack/spec@3.2.7
|
|
60
|
-
- @objectstack/core@3.2.7
|
|
61
|
-
|
|
62
|
-
## 3.2.6
|
|
63
|
-
|
|
64
|
-
### Patch Changes
|
|
65
|
-
|
|
66
|
-
- @objectstack/spec@3.2.6
|
|
67
|
-
- @objectstack/core@3.2.6
|
|
68
|
-
|
|
69
|
-
## 3.2.5
|
|
70
|
-
|
|
71
|
-
### Patch Changes
|
|
72
|
-
|
|
73
|
-
- @objectstack/spec@3.2.5
|
|
74
|
-
- @objectstack/core@3.2.5
|
|
75
|
-
|
|
76
|
-
## 3.2.4
|
|
77
|
-
|
|
78
|
-
### Patch Changes
|
|
79
|
-
|
|
80
|
-
- @objectstack/spec@3.2.4
|
|
81
|
-
- @objectstack/core@3.2.4
|
|
82
|
-
|
|
83
|
-
## 3.2.3
|
|
84
|
-
|
|
85
|
-
### Patch Changes
|
|
86
|
-
|
|
87
|
-
- @objectstack/spec@3.2.3
|
|
88
|
-
- @objectstack/core@3.2.3
|
|
89
|
-
|
|
90
|
-
## 3.2.2
|
|
91
|
-
|
|
92
|
-
### Patch Changes
|
|
93
|
-
|
|
94
|
-
- Updated dependencies [46defbb]
|
|
95
|
-
- @objectstack/spec@3.2.2
|
|
96
|
-
- @objectstack/core@3.2.2
|
|
97
|
-
|
|
98
|
-
## 3.2.1
|
|
99
|
-
|
|
100
|
-
### Patch Changes
|
|
101
|
-
|
|
102
|
-
- Updated dependencies [850b546]
|
|
103
|
-
- @objectstack/spec@3.2.1
|
|
104
|
-
- @objectstack/core@3.2.1
|
|
105
|
-
|
|
106
|
-
## 3.2.0
|
|
107
|
-
|
|
108
|
-
### Patch Changes
|
|
109
|
-
|
|
110
|
-
- Updated dependencies [5901c29]
|
|
111
|
-
- @objectstack/spec@3.2.0
|
|
112
|
-
- @objectstack/core@3.2.0
|
|
113
|
-
|
|
114
|
-
## 3.1.1
|
|
115
|
-
|
|
116
|
-
### Patch Changes
|
|
117
|
-
|
|
118
|
-
- Updated dependencies [953d667]
|
|
119
|
-
- @objectstack/spec@3.1.1
|
|
120
|
-
- @objectstack/core@3.1.1
|
|
121
|
-
|
|
122
|
-
## 3.1.0
|
|
123
|
-
|
|
124
|
-
### Patch Changes
|
|
125
|
-
|
|
126
|
-
- Updated dependencies [0088830]
|
|
127
|
-
- @objectstack/spec@3.1.0
|
|
128
|
-
- @objectstack/core@3.1.0
|
|
129
|
-
|
|
130
|
-
## 3.0.11
|
|
131
|
-
|
|
132
|
-
### Patch Changes
|
|
133
|
-
|
|
134
|
-
- Updated dependencies [92d9d99]
|
|
135
|
-
- @objectstack/spec@3.0.11
|
|
136
|
-
- @objectstack/core@3.0.11
|
|
137
|
-
|
|
138
|
-
## 3.0.10
|
|
139
|
-
|
|
140
|
-
### Patch Changes
|
|
141
|
-
|
|
142
|
-
- Updated dependencies [d1e5d31]
|
|
143
|
-
- @objectstack/spec@3.0.10
|
|
144
|
-
- @objectstack/core@3.0.10
|
|
145
|
-
|
|
146
|
-
## 3.0.9
|
|
147
|
-
|
|
148
|
-
### Patch Changes
|
|
149
|
-
|
|
150
|
-
- Updated dependencies [15e0df6]
|
|
151
|
-
- @objectstack/spec@3.0.9
|
|
152
|
-
- @objectstack/core@3.0.9
|
|
153
|
-
|
|
154
|
-
## 3.0.8
|
|
155
|
-
|
|
156
|
-
### Patch Changes
|
|
157
|
-
|
|
158
|
-
- Updated dependencies [5a968a2]
|
|
159
|
-
- @objectstack/spec@3.0.8
|
|
160
|
-
- @objectstack/core@3.0.8
|
|
161
|
-
|
|
162
|
-
## 3.0.7
|
|
163
|
-
|
|
164
|
-
### Patch Changes
|
|
165
|
-
|
|
166
|
-
- Updated dependencies [0119bd7]
|
|
167
|
-
- Updated dependencies [5426bdf]
|
|
168
|
-
- @objectstack/spec@3.0.7
|
|
169
|
-
- @objectstack/core@3.0.7
|
|
170
|
-
|
|
171
|
-
## 3.0.6
|
|
172
|
-
|
|
173
|
-
### Patch Changes
|
|
174
|
-
|
|
175
|
-
- Updated dependencies [5df254c]
|
|
176
|
-
- @objectstack/spec@3.0.6
|
|
177
|
-
- @objectstack/core@3.0.6
|
|
178
|
-
|
|
179
|
-
## 3.0.5
|
|
180
|
-
|
|
181
|
-
### Patch Changes
|
|
182
|
-
|
|
183
|
-
- Updated dependencies [23a4a68]
|
|
184
|
-
- @objectstack/spec@3.0.5
|
|
185
|
-
- @objectstack/core@3.0.5
|
|
186
|
-
|
|
187
|
-
## 3.0.4
|
|
188
|
-
|
|
189
|
-
### Patch Changes
|
|
190
|
-
|
|
191
|
-
- Updated dependencies [d738987]
|
|
192
|
-
- @objectstack/spec@3.0.4
|
|
193
|
-
- @objectstack/core@3.0.4
|
|
194
|
-
|
|
195
|
-
## 3.0.3
|
|
196
|
-
|
|
197
|
-
### Patch Changes
|
|
198
|
-
|
|
199
|
-
- c7267f6: Patch release for maintenance updates and improvements.
|
|
200
|
-
- Updated dependencies [c7267f6]
|
|
201
|
-
- @objectstack/spec@3.0.3
|
|
202
|
-
- @objectstack/core@3.0.3
|
|
203
|
-
|
|
204
|
-
## 3.0.2
|
|
205
|
-
|
|
206
|
-
### Patch Changes
|
|
207
|
-
|
|
208
|
-
- Updated dependencies [28985f5]
|
|
209
|
-
- @objectstack/spec@3.0.2
|
|
210
|
-
- @objectstack/core@3.0.2
|
|
211
|
-
|
|
212
|
-
## 3.0.1
|
|
213
|
-
|
|
214
|
-
### Patch Changes
|
|
215
|
-
|
|
216
|
-
- Updated dependencies [389725a]
|
|
217
|
-
- @objectstack/spec@3.0.1
|
|
218
|
-
- @objectstack/core@3.0.1
|
|
219
|
-
|
|
220
|
-
## 3.0.0
|
|
221
|
-
|
|
222
|
-
### Major Changes
|
|
223
|
-
|
|
224
|
-
- Release v3.0.0 — unified version bump for all ObjectStack packages.
|
|
225
|
-
|
|
226
|
-
### Patch Changes
|
|
227
|
-
|
|
228
|
-
- Updated dependencies
|
|
229
|
-
- @objectstack/spec@3.0.0
|
|
230
|
-
- @objectstack/core@3.0.0
|
|
231
|
-
|
|
232
|
-
## 2.0.7
|
|
233
|
-
|
|
234
|
-
### Patch Changes
|
|
235
|
-
|
|
236
|
-
- Updated dependencies
|
|
237
|
-
- @objectstack/spec@2.0.7
|
|
238
|
-
- @objectstack/core@2.0.7
|
|
239
|
-
|
|
240
|
-
## 2.0.6
|
|
241
|
-
|
|
242
|
-
### Patch Changes
|
|
243
|
-
|
|
244
|
-
- Patch release for maintenance and stability improvements
|
|
245
|
-
- Updated dependencies
|
|
246
|
-
- @objectstack/spec@2.0.6
|
|
247
|
-
- @objectstack/core@2.0.6
|
|
248
|
-
|
|
249
|
-
## 2.0.5
|
|
250
|
-
|
|
251
|
-
### Patch Changes
|
|
252
|
-
|
|
253
|
-
- Updated dependencies
|
|
254
|
-
- @objectstack/spec@2.0.5
|
|
255
|
-
- @objectstack/core@2.0.5
|
|
256
|
-
|
|
257
|
-
## 2.0.4
|
|
258
|
-
|
|
259
|
-
### Patch Changes
|
|
260
|
-
|
|
261
|
-
- Patch release for maintenance and stability improvements
|
|
262
|
-
- Updated dependencies
|
|
263
|
-
- @objectstack/spec@2.0.4
|
|
264
|
-
- @objectstack/core@2.0.4
|
|
265
|
-
|
|
266
|
-
## 2.0.3
|
|
267
|
-
|
|
268
|
-
### Patch Changes
|
|
269
|
-
|
|
270
|
-
- Patch release for maintenance and stability improvements
|
|
271
|
-
- Updated dependencies
|
|
272
|
-
- @objectstack/spec@2.0.3
|
|
273
|
-
- @objectstack/core@2.0.3
|
|
274
|
-
|
|
275
|
-
## 2.0.2
|
|
276
|
-
|
|
277
|
-
### Patch Changes
|
|
278
|
-
|
|
279
|
-
- Updated dependencies [1db8559]
|
|
280
|
-
- @objectstack/spec@2.0.2
|
|
281
|
-
- @objectstack/core@2.0.2
|
|
282
|
-
|
|
283
|
-
## 2.0.1
|
|
284
|
-
|
|
285
|
-
### Patch Changes
|
|
286
|
-
|
|
287
|
-
- Patch release for maintenance and stability improvements
|
|
288
|
-
- Updated dependencies
|
|
289
|
-
- @objectstack/spec@2.0.1
|
|
290
|
-
- @objectstack/core@2.0.1
|
|
291
|
-
|
|
292
|
-
## 2.0.0
|
|
293
|
-
|
|
294
|
-
### Patch Changes
|
|
295
|
-
|
|
296
|
-
- Updated dependencies [38e5dd5]
|
|
297
|
-
- Updated dependencies [38e5dd5]
|
|
298
|
-
- @objectstack/spec@2.0.0
|
|
299
|
-
- @objectstack/core@2.0.0
|
|
300
|
-
|
|
301
|
-
## 1.1.1
|
|
302
|
-
|
|
303
|
-
### Patch Changes
|
|
304
|
-
|
|
305
|
-
- Updated dependencies
|
|
306
|
-
- @objectstack/spec@2.0.0
|
|
307
|
-
- @objectstack/core@2.0.0
|
|
308
|
-
|
|
309
|
-
## 1.1.1
|
|
310
|
-
|
|
311
|
-
### Patch Changes
|
|
312
|
-
|
|
313
|
-
- Updated dependencies
|
|
314
|
-
- @objectstack/spec@2.0.0
|
|
315
|
-
- @objectstack/core@2.0.0
|
|
316
|
-
|
|
317
|
-
## 1.1.1
|
|
318
|
-
|
|
319
|
-
### Patch Changes
|
|
320
|
-
|
|
321
|
-
- Updated dependencies
|
|
322
|
-
- @objectstack/spec@2.0.0
|
|
323
|
-
- @objectstack/core@2.0.0
|
|
324
|
-
|
|
325
|
-
## 2.0.0
|
|
326
|
-
|
|
327
|
-
### Patch Changes
|
|
328
|
-
|
|
329
|
-
- Updated dependencies
|
|
330
|
-
- @objectstack/spec@2.0.0
|
|
331
|
-
- @objectstack/core@2.0.0
|
|
332
|
-
|
|
333
|
-
## 1.1.1
|
|
334
|
-
|
|
335
|
-
### Patch Changes
|
|
336
|
-
|
|
337
|
-
- Updated dependencies
|
|
338
|
-
- @objectstack/spec@1.1.1
|
|
339
|
-
- @objectstack/core@1.1.1
|
|
340
|
-
|
|
341
|
-
## 1.1.1
|
|
342
|
-
|
|
343
|
-
### Patch Changes
|
|
344
|
-
|
|
345
|
-
- Updated dependencies
|
|
346
|
-
- @objectstack/spec@2.0.0
|
|
347
|
-
- @objectstack/core@2.0.0
|
|
348
|
-
|
|
349
|
-
## 1.2.0
|
|
350
|
-
|
|
351
|
-
### Minor Changes
|
|
352
|
-
|
|
353
|
-
- ## New Features
|
|
354
|
-
|
|
355
|
-
- **@objectstack/rest** (new package): Extracted REST server, route management, and `createRestApiPlugin` into a dedicated package
|
|
356
|
-
- **@objectstack/runtime**: Add `createDispatcherPlugin` for structured route management (auth, graphql, analytics, packages, hub, storage, automation)
|
|
357
|
-
- **@objectstack/cli**: Dev mode (`--dev`) now auto-enables Studio UI at `/_studio/` — no need for `--ui` flag; use `--no-ui` to disable
|
|
358
|
-
- **@objectstack/cli**: Root URL `/` redirects to `/_studio/` in dev mode for convenience
|
|
359
|
-
- **@objectstack/cli**: Removed Vite dev server fallback — always serves pre-built dist, no extra port
|
|
360
|
-
- **@objectstack/studio**: Interactive API Console in Object Explorer (request builder, response viewer, history)
|
|
361
|
-
- **@objectstack/spec**: Studio Plugin schema, MCP Protocol schemas, API versioning, Dispatcher protocol
|
|
362
|
-
- **@objectstack/spec**: Comprehensive `.describe()` annotations across all Zod schemas
|
|
363
|
-
- **@objectstack/core**: Production hot reload and dynamic plugin loading protocol
|
|
364
|
-
|
|
365
|
-
## Migration Guide (from 1.1.0)
|
|
366
|
-
|
|
367
|
-
### RuntimeConfig.api removed
|
|
368
|
-
|
|
369
|
-
```ts
|
|
370
|
-
// Before (1.1.0) — implicit
|
|
371
|
-
const runtime = new Runtime({ api: { basePath: "/api/v1" } });
|
|
372
|
-
|
|
373
|
-
// After (1.2.0) — explicit
|
|
374
|
-
import { createRestApiPlugin } from "@objectstack/rest";
|
|
375
|
-
const runtime = new Runtime();
|
|
376
|
-
runtime.use(createRestApiPlugin({ basePath: "/api/v1" }));
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
### z.any() → z.unknown() (~30 fields)
|
|
380
|
-
|
|
381
|
-
Fields like `metadata`, `defaultValue`, `filters`, `config`, `data` now use `z.unknown()`. Add type narrowing where needed.
|
|
382
|
-
|
|
383
|
-
### Hub schemas relocated
|
|
384
|
-
|
|
385
|
-
Barrel imports via `Hub.*` still work. Direct path imports (`hub/license.zod.ts` → `system/license.zod.ts`) need updating.
|
|
386
|
-
|
|
387
|
-
### MetricType renamed
|
|
388
|
-
|
|
389
|
-
`MetricType` (analytics) → `AggregationMetricType`, `MetricType` (licensing) → `LicenseMetricType`
|
|
390
|
-
|
|
391
|
-
### Deprecations
|
|
392
|
-
|
|
393
|
-
- `HttpDispatcher` → `createDispatcherPlugin()`
|
|
394
|
-
- `createHonoApp` → `HonoServerPlugin`
|
|
395
|
-
|
|
396
|
-
### Patch Changes
|
|
397
|
-
|
|
398
|
-
- Updated dependencies
|
|
399
|
-
- @objectstack/spec@2.0.0
|
|
400
|
-
- @objectstack/core@2.0.0
|
|
401
|
-
|
|
402
|
-
## 1.2.0
|
|
403
|
-
|
|
404
|
-
### Minor Changes
|
|
405
|
-
|
|
406
|
-
- ## New Features
|
|
407
|
-
|
|
408
|
-
- **@objectstack/rest** (new package): Extracted REST server, route management, and `createRestApiPlugin` into a dedicated package
|
|
409
|
-
- **@objectstack/runtime**: Add `createDispatcherPlugin` for structured route management (auth, graphql, analytics, packages, hub, storage, automation)
|
|
410
|
-
- **@objectstack/cli**: Dev mode (`--dev`) now auto-enables Studio UI at `/_studio/` — no need for `--ui` flag; use `--no-ui` to disable
|
|
411
|
-
- **@objectstack/cli**: Root URL `/` redirects to `/_studio/` in dev mode for convenience
|
|
412
|
-
- **@objectstack/cli**: Removed Vite dev server fallback — always serves pre-built dist, no extra port
|
|
413
|
-
- **@objectstack/studio**: Interactive API Console in Object Explorer (request builder, response viewer, history)
|
|
414
|
-
- **@objectstack/spec**: Studio Plugin schema (`Studio.PluginManifest`)
|
|
415
|
-
- **@objectstack/spec**: MCP (Model Context Protocol) schemas for AI tools, resources, prompts, transport
|
|
416
|
-
- **@objectstack/spec**: API versioning schema with multiple strategies
|
|
417
|
-
- **@objectstack/spec**: Dispatcher protocol schema
|
|
418
|
-
- **@objectstack/spec**: Comprehensive `.describe()` annotations across all Zod schemas for JSON Schema generation
|
|
419
|
-
- **@objectstack/core**: Production hot reload and dynamic plugin loading protocol
|
|
420
|
-
|
|
421
|
-
## Migration Guide (from 1.1.0)
|
|
422
|
-
|
|
423
|
-
### RuntimeConfig.api removed
|
|
424
|
-
|
|
425
|
-
REST API is now opt-in. If you relied on automatic REST registration:
|
|
426
|
-
|
|
427
|
-
```ts
|
|
428
|
-
// Before (1.1.0) — implicit
|
|
429
|
-
const runtime = new Runtime({ api: { basePath: "/api/v1" } });
|
|
430
|
-
|
|
431
|
-
// After (1.2.0) — explicit
|
|
432
|
-
import { createRestApiPlugin } from "@objectstack/rest";
|
|
433
|
-
const runtime = new Runtime();
|
|
434
|
-
runtime.use(createRestApiPlugin({ basePath: "/api/v1" }));
|
|
435
|
-
```
|
|
436
|
-
|
|
437
|
-
### z.any() → z.unknown() (~30 fields)
|
|
438
|
-
|
|
439
|
-
Fields like `metadata`, `defaultValue`, `filters`, `config`, `data` in spec schemas changed from `z.any()` to `z.unknown()`. If you consume inferred types, add type narrowing:
|
|
440
|
-
|
|
441
|
-
```ts
|
|
442
|
-
// Before — worked silently
|
|
443
|
-
const val: string = record.metadata.foo;
|
|
444
|
-
|
|
445
|
-
// After — requires narrowing
|
|
446
|
-
const meta = record.metadata as Record<string, string>;
|
|
447
|
-
const val = meta.foo;
|
|
448
|
-
```
|
|
449
|
-
|
|
450
|
-
### Hub schemas relocated
|
|
451
|
-
|
|
452
|
-
- `hub/composer.zod.ts`, `hub/marketplace.zod.ts`, `hub/space.zod.ts`, `hub/hub-federation.zod.ts` — removed
|
|
453
|
-
- `hub/plugin-registry.zod.ts` → `kernel/plugin-registry.zod.ts`
|
|
454
|
-
- `hub/license.zod.ts` → `system/license.zod.ts`
|
|
455
|
-
- `hub/tenant.zod.ts` → `system/tenant.zod.ts`
|
|
456
|
-
|
|
457
|
-
Barrel imports via `Hub.*` namespace still work. Direct path imports need updating.
|
|
458
|
-
|
|
459
|
-
### MetricType renamed
|
|
460
|
-
|
|
461
|
-
- `MetricType` (data analytics) → `AggregationMetricType`
|
|
462
|
-
- `MetricType` (hub licensing) → `LicenseMetricType`
|
|
463
|
-
|
|
464
|
-
### Deprecations
|
|
465
|
-
|
|
466
|
-
- `HttpDispatcher` → use `createDispatcherPlugin()` instead
|
|
467
|
-
- `createHonoApp` → use `HonoServerPlugin` instead
|
|
468
|
-
|
|
469
|
-
### Patch Changes
|
|
470
|
-
|
|
471
|
-
- Updated dependencies
|
|
472
|
-
- @objectstack/spec@2.0.0
|
|
473
|
-
- @objectstack/core@2.0.0
|
package/src/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
-
|
|
3
|
-
// REST Server
|
|
4
|
-
export { RestServer } from './rest-server.js';
|
|
5
|
-
|
|
6
|
-
// Route Management
|
|
7
|
-
export { RouteManager, RouteGroupBuilder } from './route-manager.js';
|
|
8
|
-
export type { RouteEntry } from './route-manager.js';
|
|
9
|
-
|
|
10
|
-
// REST API Plugin
|
|
11
|
-
export { createRestApiPlugin } from './rest-api-plugin.js';
|
|
12
|
-
export type { RestApiPluginConfig } from './rest-api-plugin.js';
|
package/src/rest-api-plugin.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
-
|
|
3
|
-
import { Plugin, PluginContext, IHttpServer } from '@objectstack/core';
|
|
4
|
-
import { RestServer } from './rest-server.js';
|
|
5
|
-
import { ObjectStackProtocol, RestServerConfig } from '@objectstack/spec/api';
|
|
6
|
-
|
|
7
|
-
export interface RestApiPluginConfig {
|
|
8
|
-
serverServiceName?: string;
|
|
9
|
-
protocolServiceName?: string;
|
|
10
|
-
api?: RestServerConfig;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* REST API Plugin
|
|
15
|
-
*
|
|
16
|
-
* Responsibilities:
|
|
17
|
-
* 1. Consumes 'http.server' (or configured service)
|
|
18
|
-
* 2. Consumes 'protocol' (ObjectStackProtocol)
|
|
19
|
-
* 3. Instantiates RestServer to auto-generate routes
|
|
20
|
-
*/
|
|
21
|
-
export function createRestApiPlugin(config: RestApiPluginConfig = {}): Plugin {
|
|
22
|
-
return {
|
|
23
|
-
name: 'com.objectstack.rest.api',
|
|
24
|
-
version: '1.0.0',
|
|
25
|
-
|
|
26
|
-
init: async (_ctx: PluginContext) => {
|
|
27
|
-
// No service registration, this is a consumer plugin
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
start: async (ctx: PluginContext) => {
|
|
31
|
-
const serverService = config.serverServiceName || 'http.server';
|
|
32
|
-
const protocolService = config.protocolServiceName || 'protocol';
|
|
33
|
-
|
|
34
|
-
let server: IHttpServer | undefined;
|
|
35
|
-
let protocol: ObjectStackProtocol | undefined;
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
server = ctx.getService<IHttpServer>(serverService);
|
|
39
|
-
} catch (e) {
|
|
40
|
-
// Ignore missing service
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
protocol = ctx.getService<ObjectStackProtocol>(protocolService);
|
|
45
|
-
} catch (e) {
|
|
46
|
-
// Ignore missing service
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!server) {
|
|
50
|
-
ctx.logger.warn(`RestApiPlugin: HTTP Server service '${serverService}' not found. REST routes skipped.`);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (!protocol) {
|
|
55
|
-
ctx.logger.warn(`RestApiPlugin: Protocol service '${protocolService}' not found. REST routes skipped.`);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
ctx.logger.info('Hydrating REST API from Protocol...');
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
const restServer = new RestServer(server, protocol, config.api as any);
|
|
63
|
-
restServer.registerRoutes();
|
|
64
|
-
|
|
65
|
-
ctx.logger.info('REST API successfully registered');
|
|
66
|
-
} catch (err: any) {
|
|
67
|
-
ctx.logger.error('Failed to register REST API routes', { error: err.message } as any);
|
|
68
|
-
throw err;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|