|
1234567891011121314151617181920 |
- import {dataSources, Resource} from '../../src';
- import {DataSource} from '../../src/backend/data-source';
- import {BaseDataSource} from '../../src/common/data-source';
-
- export const autoIncrement = async (dataSource: BaseDataSource) => {
- const data = await (dataSource as DataSource).getMultiple() as Record<string, string>[];
-
- const highestId = data.reduce<number>(
- (highestId, d) => (Number(d.id) > highestId ? Number(d.id) : highestId),
- -Infinity
- );
-
- if (Number.isFinite(highestId)) {
- return (highestId + 1);
- }
-
- return 1;
- };
-
- export const dataSource = (resource: Resource) => new dataSources.jsonlFile.DataSource(resource, 'examples/basic');
|