@objectstack/types 0.9.0 → 0.9.2

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