@forestadmin/datasource-customizer
Advanced tools
Comparing version 1.5.3 to 1.5.4
@@ -54,3 +54,3 @@ "use strict"; | ||
const renamedDecorator = new datasource_2.default(dataSource); | ||
renamedDecorator.renameCollections(options?.rename); | ||
renamedDecorator.renameCollections(options.rename); | ||
dataSource = renamedDecorator; | ||
@@ -126,2 +126,2 @@ } | ||
exports.default = DataSourceCustomizer; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0YXNvdXJjZS1jdXN0b21pemVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2RhdGFzb3VyY2UtY3VzdG9taXplci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQVFBLG9GQUEyRDtBQUUzRCw2RkFBb0U7QUFDcEUscUZBQTREO0FBQzVELGdHQUFzRztBQUN0RywyRkFBNEY7QUFHNUYsMEVBQWlEO0FBRWpEOzs7Ozs7Ozs7R0FTRztBQUNILE1BQXFCLG9CQUFvQjtJQWtCdkM7UUFDRSxJQUFJLENBQUMsbUJBQW1CLEdBQUcsSUFBSSw4QkFBbUIsRUFBYyxDQUFDO1FBQ2pFLElBQUksQ0FBQyxLQUFLLEdBQUcsSUFBSSwwQkFBZSxDQUFDLElBQUksQ0FBQyxtQkFBbUIsQ0FBQyxDQUFDO0lBQzdELENBQUM7SUFqQkQ7O09BRUc7SUFDSCxJQUFJLE1BQU07UUFDUixPQUFPLElBQUksQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBQztJQUNoQyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJLFdBQVc7UUFDYixPQUFPLElBQUksQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxJQUFJLENBQUMsYUFBYSxDQUFDLENBQUMsQ0FBQyxJQUEwQixDQUFDLEN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ELFVBQVU7UUFDUixPQUFPLEtBQUssRUFBRSxNQUFjLEVBQUUsRUFBRSxDQUFDLElBQUksQ0FBQyxhQUFhLENBQUMsTUFBTSxDQUFDLENBQUM7SUFDOUQsQ0FBQztJQUVELEtBQUssQ0FBQyx1QkFBdUIsQ0FBQyxXQUFtQixFQUFFLGVBQXVCO1FBQ3hFLE9BQU8sMEJBQWUsQ0FBQyx1QkFBdUIsQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLElBQUksRUFBRSxXQUFXLEVBQUUsZUFBZSxDQUFDLENBQUM7SUFDaEcsQ0FBQztDQUNGO0FBN0hELHVDQTZIQyJ9 |
@@ -7,6 +7,6 @@ import { DataSource } from '@forestadmin/datasource-toolkit'; | ||
renameCollection(oldName: string, newName: string): void; | ||
renameCollections(rename?: { | ||
[newName: string]: string; | ||
renameCollections(rename?: ((oldName: string) => string) | { | ||
[oldName: string]: string; | ||
}): void; | ||
} | ||
//# sourceMappingURL=datasource.d.ts.map |
@@ -16,6 +16,6 @@ "use strict"; | ||
} | ||
if (this._collections[newName]) { | ||
throw new Error(`The given new collection name "${newName}" is already defined in the dataSource`); | ||
} | ||
if (oldName !== newName) { | ||
if (this._collections[newName]) { | ||
throw new Error(`The given new collection name "${newName}" is already defined in the dataSource`); | ||
} | ||
const collection = this._collections[oldName]; | ||
@@ -28,3 +28,6 @@ collection.rename(newName); | ||
renameCollections(rename) { | ||
for (const [oldName, newName] of Object.entries(rename ?? {})) { | ||
const tuples = typeof rename === 'function' | ||
? this.collections.map(({ name }) => [name, rename(name) ?? name]) | ||
: Object.entries(rename ?? {}); | ||
for (const [oldName, newName] of tuples) { | ||
this.renameCollection(oldName, newName); | ||
@@ -35,2 +38,2 @@ } | ||
exports.default = RenameCollectionDataSourceDecorator; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0YXNvdXJjZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4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BQU0sQ0FBQyxPQUFPLENBQUMsQ0FBQztZQUUzQixJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxHQUFHLFVBQVUsQ0FBQztZQUN4QyxPQUFPLElBQUksQ0FBQyxZQUFZLENBQUMsT0FBTyxDQUFDLENBQUM7U0FDbkM7SUFDSCxDQUFDO0lBRUQsaUJBQWlCLENBQUMsTUFBc0U7UUFDdEYsTUFBTSxNQUFNLEdBQ1YsT0FBTyxNQUFNLEtBQUssVUFBVTtZQUMxQixDQUFDLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxHQUFHLENBQUMsQ0FBQyxFQUFFLElBQUksRUFBRSxFQUFFLEVBQUUsQ0FBQyxDQUFDLElBQUksRUFBRSxNQUFNLENBQUMsSUFBSSxDQUFDLElBQUksSUFBSSxDQUFDLENBQUM7WUFDbEUsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxPQUFPLENBQUMsTUFBTSxJQUFJLEVBQUUsQ0FBQyxDQUFDO1FBRW5DLEtBQUssTUFBTSxDQUFDLE9BQU8sRUFBRSxPQUFPLENBQUMsSUFBSSxNQUFNLEVBQUU7WUFDdkMsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sRUFBRSxPQUFPLENBQUMsQ0FBQztTQUN6QztJQUNILENBQUM7Q0FDRjtBQW5DRCxzREFtQ0MifQ== |
@@ -12,3 +12,3 @@ import { PrimitiveTypes } from '@forestadmin/datasource-toolkit'; | ||
export declare type DataSourceOptions = { | ||
rename?: { | ||
rename?: ((oldName: string) => string) | { | ||
[oldName: string]: string; | ||
@@ -15,0 +15,0 @@ }; |
{ | ||
"name": "@forestadmin/datasource-customizer", | ||
"version": "1.5.3", | ||
"version": "1.5.4", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "license": "GPL-3.0", |
435512
5047