Registry / database / mobx-restful-migrator

mobx-restful-migrator

JSON →
library0.2.1jsnpmunverified

A TypeScript data migration framework built on MobX-RESTful's ListModel abstraction, enabling flexible field mappings, async generator-based flow control, cross-table relationships, and event-driven logging. Current stable version: 0.2.1. Ideal for migrating data between databases via RESTful APIs with customizable schemas and full TypeScript support. Differentiates from other migration tools by tight integration with MobX-RESTful and reactive programming patterns.

npm install mobx-restful-migrator
INSTALL
IMPORT
SIG · MOBX-RESTFUL-MIGRA
M
mobx-restful-migrator
databasejavascriptv0.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RestMigrator
import { RestMigrator } from 'mobx-restful-migrator'
import RestMigrator from 'mobx-restful-migrator'
RestMigrator is a named export, not default. Use named import.
MigrationSchema
import { MigrationSchema } from 'mobx-restful-migrator'
const MigrationSchema = require('mobx-restful-migrator').MigrationSchema
ESM-only package; CJS require works but named import recommended.
ConsoleLogger
import { ConsoleLogger } from 'mobx-restful-migrator'
Standard named export for logging.

Shows full migration setup: source CSV, target models, schema definition with direct/custom/cross-table mappings, and async generator migration execution.

import { RestMigrator, MigrationSchema, ConsoleLogger } from 'mobx-restful-migrator'; import { HTTPClient } from 'koajax'; import { ListModel, DataObject, Filter, IDType, toggle } from 'mobx-restful'; import { buildURLData } from 'web-utility'; // Define source data interface interface SourceArticle { id: number; title: string; subtitle: string; keywords: string; content: string; author: string; email: string; } // Define target models interface User { id: number; name: string; email?: string; } interface Article { id: number; title: string; category: string; tags: string[]; content: string; author: User; } export abstract class TableModel<D extends DataObject, F extends Filter<D> = Filter<D>> extends ListModel<D, F> { client = new HTTPClient({ baseURI: 'http://localhost:8080', responseType: 'json' }); @toggle('uploading') async updateOne(data: Filter<D>, id?: IDType) { const { body } = await (id ? this.client.put<D>(`${this.baseURI}/${id}`, data) : this.client.post<D>(this.baseURI, data)); return (this.currentOne = body!); } async loadPage(pageIndex: number, pageSize: number, filter: F) { const { body } = await this.client.get<{ list: D[]; count: number }>( `${this.baseURI}?${buildURLData({ ...filter, pageIndex, pageSize })}` ); return { pageData: body!.list, totalCount: body!.count }; } } class UserModel extends TableModel<User> { baseURI = '/users'; } class ArticleModel extends TableModel<Article> { baseURI = '/articles'; } // Migration configuration const schema: MigrationSchema = { sourceType: 'CSV', targetModel: new ArticleModel(), fieldMappings: [ { sourceField: 'title', targetField: 'title', type: 'direct' }, { sourceField: 'keywords', targetField: 'category', type: 'custom', transform: (val) => val.split(',')[0] }, { sourceField: 'keywords', targetField: 'tags', type: 'custom', transform: (val) => val.split(',').slice(1) }, { sourceField: 'content', targetField: 'content', type: 'direct' }, { sourceField: 'author', targetField: 'author', type: 'crossTable', model: new UserModel(), mapping: { 'name': 'author', 'email': 'email' } } ] }; // Execute migration const migrator = new RestMigrator(schema, new ConsoleLogger()); async function migrate() { for await (const progress of migrator.migrate()) { console.log(`Progress: ${progress.percent}%`); } } migrate().catch(console.error);
Debug
Known issues
gotchaPackage requires peer dependency core-js >=3 and mobx-restful (not installed automatically)
fix
Install peers: npm install mobx-restful core-js
affects: >=0.1
gotchaMigrationSchema type is not exported explicitly; must import from the main module
fix
Use correct import: import { MigrationSchema } from 'mobx-restful-migrator'
affects: >=0.1
gotchaRestMigrator.migrate() returns AsyncGenerator; forgetting to use for-await-of results in undefined behavior
fix
Use for await (const progress of migrator.migrate()) { ... }
affects: >=0.1
Errors
Common errors & fixes
TypeError: Class extends value undefined is not a constructor or null
Missing mobx-restful dependency (ListModel not found)
fix
Install mobx-restful: npm install mobx-restful
Error: Cannot find module 'core-js'
Missing peer dependency core-js
fix
Install core-js: npm install core-js
TypeError: migrator.migrate is not a function or its return value is not iterable
Import error: default import instead of named import for RestMigrator
fix
Change to: import { RestMigrator } from 'mobx-restful-migrator'
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
core-jsrequiredpeer dependency required for runtime polyfills
mobx-restfulrequiredrequired for ListModel, DataObject, Filter, IDType and other base classes
Agent activity
9 hits · last 30 days
node
8
Resources