@objectstack/types 0.8.2 → 0.9.1

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +382 -0
  3. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @objectstack/types
2
2
 
3
+ ## 0.9.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Patch release for maintenance and stability improvements. All packages updated with unified versioning.
8
+ - Updated dependencies
9
+ - @objectstack/spec@0.9.1
10
+
3
11
  ## 0.8.2
4
12
 
5
13
  ### Patch Changes
package/README.md ADDED
@@ -0,0 +1,382 @@
1
+ # @objectstack/types
2
+
3
+ Shared runtime type definitions for the ObjectStack ecosystem.
4
+
5
+ ## Overview
6
+
7
+ This package provides common TypeScript interfaces and types used across the ObjectStack runtime environment. It serves as a minimal, dependency-light package that defines the core contracts between different parts of the system.
8
+
9
+ ## Purpose
10
+
11
+ The `@objectstack/types` package exists to:
12
+
13
+ 1. **Break Circular Dependencies** - Provides shared types without creating circular imports between packages
14
+ 2. **Define Runtime Contracts** - Establishes interfaces that plugins and kernel must satisfy
15
+ 3. **Enable Type Safety** - Ensures type compatibility across the ObjectStack ecosystem
16
+ 4. **Minimal Footprint** - Ultra-lightweight with minimal dependencies
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pnpm add @objectstack/types
22
+ ```
23
+
24
+ ## Type Definitions
25
+
26
+ ### IKernel
27
+
28
+ Core interface for the ObjectStack kernel that plugins interact with.
29
+
30
+ ```typescript
31
+ export interface IKernel {
32
+ /**
33
+ * ObjectQL instance (optional to support initialization phase)
34
+ */
35
+ ql?: any;
36
+
37
+ /**
38
+ * Start the kernel and all registered plugins
39
+ */
40
+ start(): Promise<void>;
41
+
42
+ /**
43
+ * Additional kernel methods and services
44
+ */
45
+ [key: string]: any;
46
+ }
47
+ ```
48
+
49
+ **Usage:**
50
+
51
+ ```typescript
52
+ import type { IKernel } from '@objectstack/types';
53
+
54
+ export class MyPlugin {
55
+ async onStart(kernel: IKernel) {
56
+ // Access ObjectQL if available
57
+ if (kernel.ql) {
58
+ await kernel.ql.find('user', {});
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ ### RuntimeContext
65
+
66
+ Context object passed to runtime plugins during their lifecycle.
67
+
68
+ ```typescript
69
+ export interface RuntimeContext {
70
+ /**
71
+ * Reference to the kernel instance
72
+ */
73
+ engine: IKernel;
74
+ }
75
+ ```
76
+
77
+ **Usage:**
78
+
79
+ ```typescript
80
+ import type { RuntimeContext } from '@objectstack/types';
81
+
82
+ export const myPlugin = {
83
+ name: 'my-plugin',
84
+
85
+ async install(ctx: RuntimeContext) {
86
+ // Use kernel through context
87
+ await ctx.engine.start();
88
+ }
89
+ };
90
+ ```
91
+
92
+ ### RuntimePlugin
93
+
94
+ Interface for plugins that integrate with the ObjectStack runtime.
95
+
96
+ ```typescript
97
+ export interface RuntimePlugin {
98
+ /**
99
+ * Unique plugin identifier
100
+ */
101
+ name: string;
102
+
103
+ /**
104
+ * Optional: Called when plugin is registered
105
+ */
106
+ install?: (ctx: RuntimeContext) => void | Promise<void>;
107
+
108
+ /**
109
+ * Optional: Called when kernel starts
110
+ */
111
+ onStart?: (ctx: RuntimeContext) => void | Promise<void>;
112
+ }
113
+ ```
114
+
115
+ **Usage:**
116
+
117
+ ```typescript
118
+ import type { RuntimePlugin, RuntimeContext } from '@objectstack/types';
119
+
120
+ export const myPlugin: RuntimePlugin = {
121
+ name: 'my-custom-plugin',
122
+
123
+ async install(ctx: RuntimeContext) {
124
+ console.log('Plugin installed');
125
+ // Register services, hooks, etc.
126
+ },
127
+
128
+ async onStart(ctx: RuntimeContext) {
129
+ console.log('Plugin started');
130
+ // Initialize connections, start background tasks, etc.
131
+ }
132
+ };
133
+ ```
134
+
135
+ ## Architecture
136
+
137
+ ### Design Philosophy
138
+
139
+ The `@objectstack/types` package follows these principles:
140
+
141
+ 1. **Interface Segregation** - Only define what's absolutely necessary
142
+ 2. **Loose Coupling** - Enable interoperability without tight dependencies
143
+ 3. **Progressive Enhancement** - Allow plugins to implement optional interfaces
144
+ 4. **Type Safety** - Provide compile-time guarantees where possible
145
+
146
+ ### Dependency Graph
147
+
148
+ ```
149
+ @objectstack/types (Layer 0)
150
+ ├── Dependencies: @objectstack/spec (protocols only)
151
+ └── Used By:
152
+ ├── @objectstack/core (kernel implementation)
153
+ ├── @objectstack/runtime (plugin utilities)
154
+ ├── @objectstack/objectql (query engine)
155
+ └── All plugins
156
+ ```
157
+
158
+ The types package sits at the foundation of the architecture, depended upon by nearly all other packages but depending on very few itself.
159
+
160
+ ## Use Cases
161
+
162
+ ### 1. Plugin Development
163
+
164
+ When building plugins, import types for proper typing:
165
+
166
+ ```typescript
167
+ import type { RuntimePlugin, RuntimeContext } from '@objectstack/types';
168
+
169
+ export const authPlugin: RuntimePlugin = {
170
+ name: 'auth',
171
+
172
+ async install(ctx: RuntimeContext) {
173
+ // Setup authentication
174
+ },
175
+
176
+ async onStart(ctx: RuntimeContext) {
177
+ // Start auth service
178
+ }
179
+ };
180
+ ```
181
+
182
+ ### 2. Kernel Extensions
183
+
184
+ When extending the kernel with custom functionality:
185
+
186
+ ```typescript
187
+ import type { IKernel } from '@objectstack/types';
188
+
189
+ export class CustomKernel implements IKernel {
190
+ ql?: any;
191
+
192
+ async start(): Promise<void> {
193
+ // Custom kernel implementation
194
+ }
195
+ }
196
+ ```
197
+
198
+ ### 3. Runtime Integration
199
+
200
+ When integrating with the ObjectStack runtime:
201
+
202
+ ```typescript
203
+ import type { RuntimeContext } from '@objectstack/types';
204
+
205
+ export function setupRuntime(ctx: RuntimeContext) {
206
+ const kernel = ctx.engine;
207
+
208
+ // Access kernel functionality
209
+ kernel.start();
210
+ }
211
+ ```
212
+
213
+ ## TypeScript Configuration
214
+
215
+ This package is designed to work with TypeScript 5.0+:
216
+
217
+ ```json
218
+ {
219
+ "compilerOptions": {
220
+ "target": "ES2020",
221
+ "module": "ESNext",
222
+ "moduleResolution": "bundler",
223
+ "strict": true,
224
+ "esModuleInterop": true,
225
+ "skipLibCheck": true,
226
+ "declaration": true,
227
+ "declarationMap": true
228
+ }
229
+ }
230
+ ```
231
+
232
+ ## Best Practices
233
+
234
+ ### 1. Use Type-Only Imports
235
+
236
+ When importing types, use the `type` keyword to ensure they're erased at runtime:
237
+
238
+ ```typescript
239
+ import type { IKernel, RuntimePlugin } from '@objectstack/types';
240
+ ```
241
+
242
+ ### 2. Don't Import Implementation
243
+
244
+ This package contains **only types**. Never import implementation details:
245
+
246
+ ```typescript
247
+ // ✅ Good - type-only import
248
+ import type { RuntimePlugin } from '@objectstack/types';
249
+
250
+ // ❌ Bad - trying to import implementation
251
+ import { RuntimePlugin } from '@objectstack/types'; // Won't work
252
+ ```
253
+
254
+ ### 3. Extend Interfaces When Needed
255
+
256
+ Plugins can extend these interfaces for custom requirements:
257
+
258
+ ```typescript
259
+ import type { RuntimePlugin, RuntimeContext } from '@objectstack/types';
260
+
261
+ interface MyPluginContext extends RuntimeContext {
262
+ customProperty: string;
263
+ }
264
+
265
+ export const myPlugin: RuntimePlugin = {
266
+ name: 'my-plugin',
267
+
268
+ async install(ctx: RuntimeContext) {
269
+ const myCtx = ctx as MyPluginContext;
270
+ // Use custom context
271
+ }
272
+ };
273
+ ```
274
+
275
+ ### 4. Maintain Backward Compatibility
276
+
277
+ The types in this package should be stable. Use optional properties for new features:
278
+
279
+ ```typescript
280
+ export interface RuntimePlugin {
281
+ name: string;
282
+ install?: (ctx: RuntimeContext) => void | Promise<void>;
283
+ onStart?: (ctx: RuntimeContext) => void | Promise<void>;
284
+ // New optional methods are OK
285
+ onDestroy?: () => void | Promise<void>;
286
+ }
287
+ ```
288
+
289
+ ## Version Compatibility
290
+
291
+ This package follows semantic versioning:
292
+
293
+ - **Patch**: Documentation updates, internal refactoring
294
+ - **Minor**: New optional properties/methods
295
+ - **Major**: Breaking changes to existing interfaces
296
+
297
+ ## FAQ
298
+
299
+ ### Why a separate types package?
300
+
301
+ To avoid circular dependencies between `@objectstack/core` and plugins, we extract shared interfaces into a neutral package.
302
+
303
+ ### Can I use this in my plugin?
304
+
305
+ Yes! This package is designed to be used by all ObjectStack plugins and extensions.
306
+
307
+ ### Do I need this for application development?
308
+
309
+ Usually not. Application developers typically use `@objectstack/spec` for type definitions. This package is primarily for plugin and runtime developers.
310
+
311
+ ### What's the difference from @objectstack/spec?
312
+
313
+ - **@objectstack/spec**: Protocol definitions, schemas, and data types (what you configure)
314
+ - **@objectstack/types**: Runtime interfaces and contracts (how the system runs)
315
+
316
+ ## Migration Guide
317
+
318
+ ### From Direct Kernel Access
319
+
320
+ Before:
321
+
322
+ ```typescript
323
+ import { ObjectKernel } from '@objectstack/core';
324
+
325
+ function myFunction(kernel: ObjectKernel) {
326
+ // Tight coupling to concrete class
327
+ }
328
+ ```
329
+
330
+ After:
331
+
332
+ ```typescript
333
+ import type { IKernel } from '@objectstack/types';
334
+
335
+ function myFunction(kernel: IKernel) {
336
+ // Loose coupling to interface
337
+ }
338
+ ```
339
+
340
+ ### From Inline Types
341
+
342
+ Before:
343
+
344
+ ```typescript
345
+ interface MyPlugin {
346
+ name: string;
347
+ install: (ctx: any) => Promise<void>;
348
+ }
349
+ ```
350
+
351
+ After:
352
+
353
+ ```typescript
354
+ import type { RuntimePlugin } from '@objectstack/types';
355
+
356
+ const myPlugin: RuntimePlugin = {
357
+ name: 'my-plugin',
358
+ install: async (ctx) => {
359
+ // Implementation
360
+ }
361
+ };
362
+ ```
363
+
364
+ ## Related Packages
365
+
366
+ - [@objectstack/spec](../spec) - Protocol definitions and Zod schemas
367
+ - [@objectstack/core](../core) - Kernel implementation
368
+ - [@objectstack/runtime](../runtime) - Runtime utilities and helpers
369
+
370
+ ## Contributing
371
+
372
+ When adding new types to this package:
373
+
374
+ 1. Keep interfaces minimal and focused
375
+ 2. Use optional properties for extensibility
376
+ 3. Document all public types with JSDoc
377
+ 4. Avoid breaking changes
378
+ 5. Consider backward compatibility
379
+
380
+ ## License
381
+
382
+ MIT
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@objectstack/types",
3
- "version": "0.8.2",
3
+ "version": "0.9.1",
4
4
  "description": "Shared interfaces describing the ObjectStack Runtime environment",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "dependencies": {
8
- "@objectstack/spec": "0.8.2"
8
+ "@objectstack/spec": "0.9.1"
9
9
  },
10
10
  "devDependencies": {
11
11
  "typescript": "^5.0.0"