HATEOAS-first backend framework.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

data-source.ts 543 B

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