HATEOAS-first backend framework.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

data-source.ts 657 B

1234567891011121314151617181920
  1. import {dataSources, Resource} from '../../src';
  2. import {DataSource} from '../../src/backend/data-source';
  3. import {BaseDataSource} from '../../src/common/data-source';
  4. export const autoIncrement = async (dataSource: BaseDataSource) => {
  5. const data = await (dataSource as DataSource).getMultiple() as Record<string, string>[];
  6. const highestId = data.reduce<number>(
  7. (highestId, d) => (Number(d.id) > highestId ? Number(d.id) : highestId),
  8. -Infinity
  9. );
  10. if (Number.isFinite(highestId)) {
  11. return (highestId + 1);
  12. }
  13. return 1;
  14. };
  15. export const dataSource = (resource: Resource) => new dataSources.jsonlFile.DataSource(resource, 'examples/basic');