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);
Errors
Common errors & fixes
TypeError: Class extends value undefined is not a constructor or null
Missing mobx-restful dependency (ListModel not found)
fixInstall mobx-restful: npm install mobx-restful
Error: Cannot find module 'core-js'
Missing peer dependency core-js
fixInstall 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
fixChange to: import { RestMigrator } from 'mobx-restful-migrator' Audit
Dependencies
core-jsrequiredpeer dependency required for runtime polyfills
mobx-restfulrequiredrequired for ListModel, DataObject, Filter, IDType and other base classes