|
| 1 | +--- |
| 2 | +title: "Migrating from @objectql/core" |
| 3 | +description: Step-by-step guide for migrating from @objectql/core to @objectstack/objectql |
| 4 | +--- |
| 5 | + |
| 6 | +# Migrating from `@objectql/core` to `@objectstack/objectql` |
| 7 | + |
| 8 | +Starting with `@objectstack/objectql` v3.1, all core functionality previously provided by `@objectql/core` is now available upstream. This guide walks you through migrating your project so that `@objectql/core` can be removed. |
| 9 | + |
| 10 | +## Why Migrate? |
| 11 | + |
| 12 | +| | `@objectql/core` (deprecated) | `@objectstack/objectql` (recommended) | |
| 13 | +| :--- | :--- | :--- | |
| 14 | +| **Engine** | Bridge class extending upstream `ObjectQL` | Canonical `ObjectQL` engine | |
| 15 | +| **Kernel Factory** | `createObjectQLKernel()` | `createObjectQLKernel()` (identical API) | |
| 16 | +| **Introspection** | `toTitleCase`, `convertIntrospectedSchemaToObjects` | Same functions, same signatures | |
| 17 | +| **Registry** | Re-exports from upstream | Direct exports | |
| 18 | +| **MetadataRegistry** | `@objectql/types` `MetadataRegistry` class | `MetadataFacade` (async `IMetadataService`) | |
| 19 | +| **Maintenance** | Planned deprecation | Actively maintained | |
| 20 | + |
| 21 | +## Step 1 — Update Dependencies |
| 22 | + |
| 23 | +```diff |
| 24 | + // package.json |
| 25 | + { |
| 26 | + "dependencies": { |
| 27 | +- "@objectql/core": "^4.x", |
| 28 | +- "@objectql/types": "^4.x", |
| 29 | ++ "@objectstack/objectql": "^3.1.0" |
| 30 | + } |
| 31 | + } |
| 32 | +``` |
| 33 | + |
| 34 | +Then re-install: |
| 35 | + |
| 36 | +```bash |
| 37 | +pnpm install |
| 38 | +``` |
| 39 | + |
| 40 | +## Step 2 — Update Imports |
| 41 | + |
| 42 | +### Engine, Repository & Context |
| 43 | + |
| 44 | +```diff |
| 45 | +- import { ObjectQL, ObjectRepository, ScopedContext } from '@objectql/core'; |
| 46 | ++ import { ObjectQL, ObjectRepository, ScopedContext } from '@objectstack/objectql'; |
| 47 | +``` |
| 48 | + |
| 49 | +```diff |
| 50 | +- import type { HookHandler, HookEntry, OperationContext, EngineMiddleware } from '@objectql/core'; |
| 51 | ++ import type { HookHandler, HookEntry, OperationContext, EngineMiddleware } from '@objectstack/objectql'; |
| 52 | +``` |
| 53 | + |
| 54 | +### Schema Registry |
| 55 | + |
| 56 | +```diff |
| 57 | +- import { SchemaRegistry } from '@objectql/core'; |
| 58 | ++ import { SchemaRegistry } from '@objectstack/objectql'; |
| 59 | +``` |
| 60 | + |
| 61 | +### Kernel Factory |
| 62 | + |
| 63 | +```diff |
| 64 | +- import { createObjectQLKernel } from '@objectql/core'; |
| 65 | +- import type { ObjectQLKernelOptions } from '@objectql/core'; |
| 66 | ++ import { createObjectQLKernel } from '@objectstack/objectql'; |
| 67 | ++ import type { ObjectQLKernelOptions } from '@objectstack/objectql'; |
| 68 | +``` |
| 69 | + |
| 70 | +### Utility Functions |
| 71 | + |
| 72 | +```diff |
| 73 | +- import { toTitleCase, convertIntrospectedSchemaToObjects } from '@objectql/core'; |
| 74 | ++ import { toTitleCase, convertIntrospectedSchemaToObjects } from '@objectstack/objectql'; |
| 75 | +``` |
| 76 | + |
| 77 | +### Introspection Types |
| 78 | + |
| 79 | +```diff |
| 80 | +- import type { IntrospectedSchema, IntrospectedTable } from '@objectql/types'; |
| 81 | ++ import type { IntrospectedSchema, IntrospectedTable } from '@objectstack/objectql'; |
| 82 | +``` |
| 83 | + |
| 84 | +```diff |
| 85 | +- import type { IntrospectedColumn, IntrospectedForeignKey } from '@objectql/types'; |
| 86 | ++ import type { IntrospectedColumn, IntrospectedForeignKey } from '@objectstack/objectql'; |
| 87 | +``` |
| 88 | + |
| 89 | +## Step 3 — API Differences |
| 90 | + |
| 91 | +### `createObjectQLKernel()` |
| 92 | + |
| 93 | +The function signature is identical. The only change is the return type uses the upstream `ObjectKernel`: |
| 94 | + |
| 95 | +```typescript |
| 96 | +import { createObjectQLKernel } from '@objectstack/objectql'; |
| 97 | + |
| 98 | +const kernel = await createObjectQLKernel({ |
| 99 | + plugins: [myDriverPlugin], |
| 100 | +}); |
| 101 | +await kernel.bootstrap(); |
| 102 | +``` |
| 103 | + |
| 104 | +### `convertIntrospectedSchemaToObjects()` |
| 105 | + |
| 106 | +Same signature and behavior: |
| 107 | + |
| 108 | +```typescript |
| 109 | +import { convertIntrospectedSchemaToObjects } from '@objectstack/objectql'; |
| 110 | + |
| 111 | +const objects = convertIntrospectedSchemaToObjects(schema, { |
| 112 | + excludeTables: ['migrations'], |
| 113 | + includeTables: undefined, // optional: whitelist |
| 114 | + skipSystemColumns: true, // default: skips id, created_at, updated_at |
| 115 | +}); |
| 116 | +``` |
| 117 | + |
| 118 | +### MetadataRegistry → MetadataFacade |
| 119 | + |
| 120 | +If you were using `MetadataRegistry` from `@objectql/types`, the upstream equivalent is `MetadataFacade`. The key difference is that `MetadataFacade` methods are **async** (returns `Promise`): |
| 121 | + |
| 122 | +```diff |
| 123 | +- import { MetadataRegistry } from '@objectql/types'; |
| 124 | +- const registry = new MetadataRegistry(); |
| 125 | +- registry.register('object', myObject); |
| 126 | +- const obj = registry.get('object', 'account'); |
| 127 | ++ import { MetadataFacade } from '@objectstack/objectql'; |
| 128 | ++ const facade = new MetadataFacade(); |
| 129 | ++ await facade.register('object', 'account', myObject); |
| 130 | ++ const obj = await facade.get('object', 'account'); |
| 131 | +``` |
| 132 | + |
| 133 | +### ObjectQLPlugin |
| 134 | + |
| 135 | +Both packages export an `ObjectQLPlugin`, but they serve different roles: |
| 136 | + |
| 137 | +| | `@objectql/core` `ObjectQLPlugin` | `@objectstack/objectql` `ObjectQLPlugin` | |
| 138 | +| :--- | :--- | :--- | |
| 139 | +| Interface | `RuntimePlugin` (from `@objectql/types`) | `Plugin` (from `@objectstack/core`) | |
| 140 | +| Role | Orchestrator composing sub-plugins (validator, formula, query) | Kernel plugin registering ObjectQL as core services | |
| 141 | +| Methods | `install()`, `onStart()`, `init()`, `start()` | `init()`, `start()` | |
| 142 | + |
| 143 | +If you were using the `@objectql/core` `ObjectQLPlugin` to compose sub-plugins (`ValidatorPlugin`, `FormulaPlugin`, `QueryPlugin`), those downstream plugins are **not** part of this migration — they remain in the `@objectql` ecosystem. |
| 144 | + |
| 145 | +## Step 4 — Type Mapping Reference |
| 146 | + |
| 147 | +The `convertIntrospectedSchemaToObjects()` utility maps database column types as follows: |
| 148 | + |
| 149 | +| Database Type | ObjectStack FieldType | |
| 150 | +| :--- | :--- | |
| 151 | +| `varchar`, `char` | `text` | |
| 152 | +| `text` | `textarea` | |
| 153 | +| `integer`, `int`, `bigint`, `smallint` | `number` | |
| 154 | +| `float`, `double`, `decimal`, `numeric`, `real` | `number` | |
| 155 | +| `boolean`, `bool` | `boolean` | |
| 156 | +| `timestamp`, `datetime` | `datetime` | |
| 157 | +| `date` | `date` | |
| 158 | +| `time` | `time` | |
| 159 | +| `json`, `jsonb` | `json` | |
| 160 | +| Foreign key column | `lookup` (with `reference` set to target table) | |
| 161 | +| _anything else_ | `text` (fallback) | |
| 162 | + |
| 163 | +## Step 5 — Remove `@objectql/core` |
| 164 | + |
| 165 | +Once all imports are updated and tests pass: |
| 166 | + |
| 167 | +```bash |
| 168 | +pnpm remove @objectql/core @objectql/types |
| 169 | +``` |
| 170 | + |
| 171 | +## Checklist |
| 172 | + |
| 173 | +- [ ] Replace `@objectql/core` dependency with `@objectstack/objectql` in `package.json` |
| 174 | +- [ ] Update all `import` statements (engine, registry, kernel factory, utilities, types) |
| 175 | +- [ ] Replace `MetadataRegistry` usage with `MetadataFacade` (add `await`) |
| 176 | +- [ ] Verify `ObjectQLPlugin` usage matches the upstream interface |
| 177 | +- [ ] Run `pnpm build` and fix any remaining type errors |
| 178 | +- [ ] Run `pnpm test` to verify behavior |
| 179 | +- [ ] Remove `@objectql/core` and `@objectql/types` from dependencies |
0 commit comments