Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions packages/foundation/core/RUNTIME_INTEGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# ObjectStack Runtime Integration

This document explains the integration of `@objectstack/runtime` and `@objectstack/objectql` into the ObjectQL platform.

## Overview

As of version 3.0.1, ObjectQL core integrates with the latest ObjectStack runtime packages:

- **@objectstack/spec@0.1.2**: Protocol specification with TypeScript interfaces
- **@objectstack/objectql@0.1.1**: Core ObjectQL engine with basic driver management
- **@objectstack/runtime@0.1.1**: Runtime kernel with application lifecycle orchestration

## Architecture

### Package Relationship

```
@objectql/core (this package)
├── Extends/complements @objectstack/objectql
├── Uses types from @objectstack/spec
└── Re-exports types from @objectstack/runtime
```

### Type Exports

The core package exports types from the runtime packages for API compatibility:

```typescript
// Type-only exports to avoid runtime issues
export type {
ObjectStackKernel,
ObjectStackRuntimeProtocol
} from '@objectstack/runtime';

export type {
ObjectQL as ObjectQLEngine,
SchemaRegistry
} from '@objectstack/objectql';
```

## Implementation Details

### Current ObjectQL vs. ObjectQLEngine

The current `ObjectQL` class in this package is a **production-ready, feature-rich** implementation that includes:

- Full metadata registry
- Hooks system
- Actions system
- Validation engine
- Repository pattern
- Formula engine
- AI integration

The `ObjectQLEngine` from `@objectstack/objectql` is a **simpler, lightweight** implementation suitable for:

- Basic CRUD operations
- Simple driver management
- Minimal runtime overhead

### Why Type-Only Exports?

The `@objectstack/objectql` package currently has a configuration issue where it points to source files instead of compiled dist files. To avoid runtime errors, we use **type-only imports** which provide TypeScript type checking without executing the runtime code.

## Usage

### Using the Full-Featured ObjectQL (Recommended)

```typescript
import { ObjectQL } from '@objectql/core';

const app = new ObjectQL({
registry: new MetadataRegistry(),
datasources: { default: driver }
});

await app.init();
const ctx = app.createContext({ userId: 'user123' });
const repo = ctx.object('todo');
const items = await repo.find({});
```

### Using Type Definitions from Runtime

```typescript
import type { ObjectStackKernel, SchemaRegistry } from '@objectql/core';

// Use types for compile-time checking
function processKernel(kernel: ObjectStackKernel) {
// Your code here
}
```

## Migration Path

If you want to use the simpler `@objectstack/objectql` implementation:

1. Install it directly: `npm install @objectstack/objectql`
2. Import from the package: `import { ObjectQL } from '@objectstack/objectql'`
3. Note: Ensure the package is properly built before use

## Compatibility

- **@objectstack/spec@0.1.2**: Introduces `searchable` field requirement on FieldConfig
- **Backward Compatible**: All existing ObjectQL APIs remain unchanged
- **Tests**: 236 tests pass successfully, confirming backward compatibility

## Future Plans

Once the `@objectstack/objectql` package configuration is fixed, we may:

1. Use it as a base class for our ObjectQL implementation
2. Move framework-specific features to plugins
3. Provide both lightweight and full-featured options

## Related Documentation

- [ObjectQL Types](../types/README.md)
- [ObjectQL Platform Node](../platform-node/README.md)
- [@objectstack/spec on npm](https://www.npmjs.com/package/@objectstack/spec)
- [@objectstack/runtime on npm](https://www.npmjs.com/package/@objectstack/runtime)
4 changes: 3 additions & 1 deletion packages/foundation/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
},
"dependencies": {
"@objectql/types": "workspace:*",
"@objectstack/spec": "^0.1.1",
"@objectstack/spec": "^0.1.2",
"@objectstack/runtime": "^0.1.1",
"@objectstack/objectql": "^0.1.1",
"js-yaml": "^4.1.0",
"openai": "^4.28.0"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/foundation/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
* LICENSE file in the root directory of this source tree.
*/

// Re-export types from @objectstack packages for API compatibility
// Note: Using type-only imports to avoid runtime issues with @objectstack/objectql package configuration
export type { ObjectStackKernel, ObjectStackRuntimeProtocol } from '@objectstack/runtime';
export type { ObjectQL as ObjectQLEngine, SchemaRegistry } from '@objectstack/objectql';

// Export our enhanced runtime components (actual implementations)
export * from './repository';
export * from './app';

Expand Down
6 changes: 4 additions & 2 deletions packages/foundation/core/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export function convertIntrospectedSchemaToObjects(
type: 'lookup',
reference_to: foreignKey.referencedTable,
label: toTitleCase(column.name),
required: !column.nullable
required: !column.nullable,
searchable: false
Comment on lines 119 to +121
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new searchable: false assignments for introspected fields are important for aligning with @objectstack/spec@0.1.2, but there are no assertions in the existing convertIntrospectedSchemaToObjects tests to verify this behavior. Please add test coverage (e.g., in introspection.test.ts or util.test.ts) that asserts introspected fields have searchable === false so regressions in spec compliance are caught.

Copilot uses AI. Check for mistakes.
};
} else {
// Regular field
Expand All @@ -129,7 +130,8 @@ export function convertIntrospectedSchemaToObjects(
name: column.name,
type: fieldType,
label: toTitleCase(column.name),
required: !column.nullable
required: !column.nullable,
searchable: false
};

// Add unique constraint
Expand Down
2 changes: 1 addition & 1 deletion packages/foundation/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"test": "jest --passWithNoTests"
},
"dependencies": {
"@objectstack/spec": "^0.1.1"
"@objectstack/spec": "^0.1.2"
},
Comment on lines 29 to 31
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@objectql/types is described as a pure contract/types package, but it still declares a runtime dependency on @objectstack/spec. To keep this package dependency-free as a low-level contract layer, consider removing @objectstack/spec from dependencies (for example by inlining the required spec types here and/or treating @objectstack/spec as a devDependency used only at build time).

Copilot uses AI. Check for mistakes.
"devDependencies": {
"ts-json-schema-generator": "^2.4.0"
Expand Down
5 changes: 4 additions & 1 deletion packages/foundation/types/src/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export interface FieldOption {
* All other protocol properties (description, defaultValue, maxLength, minLength, precision, scale, min, max,
* reference, referenceFilters, writeRequiresMasterRead, expression, formula, summaryOperations) are inherited as-is.
*/
export interface FieldConfig extends Omit<Field, 'name' | 'label' | 'type' | 'options' | 'required' | 'multiple' | 'unique' | 'deleteBehavior' | 'hidden' | 'readonly' | 'encryption' | 'index' | 'externalId'> {
export interface FieldConfig extends Omit<Field, 'name' | 'label' | 'type' | 'options' | 'required' | 'multiple' | 'unique' | 'deleteBehavior' | 'hidden' | 'readonly' | 'encryption' | 'index' | 'externalId' | 'searchable'> {
/** Field name (inferred from Record key when used in ObjectConfig.fields) */
name?: string;

Expand All @@ -147,6 +147,9 @@ export interface FieldConfig extends Omit<Field, 'name' | 'label' | 'type' | 'op
/** Whether the field is unique in the table. */
unique?: boolean;

/** Whether the field is searchable (full-text search). Defaults to false. */
searchable?: boolean;
Comment on lines +150 to +151
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that searchable is re-declared on FieldConfig, the preceding documentation comment's list of boolean flags that are "re-declared here" is slightly out of date because it doesn't include searchable. Please update the comment to mention searchable alongside the other re-declared boolean flags so the docs accurately reflect the interface.

Copilot uses AI. Check for mistakes.

/** Delete behavior for relationships */
deleteBehavior?: 'set_null' | 'cascade' | 'restrict';

Expand Down
41 changes: 35 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading