{"version":3,"file":"ngx-toolkit-spring.mjs","sources":["../../../projects/spring/src/lib/spring-data.model.ts","../../../projects/spring/src/public-api.ts","../../../projects/spring/src/ngx-toolkit-spring.ts"],"sourcesContent":["import {HttpParams, HttpParamsOptions} from '@angular/common/http';\n\nexport const DEFAULT_PAGEABLE_SIZE = 25;\n\nexport class PageRequest {\n  readonly page: number;\n  readonly size: number;\n  readonly sort: Sort;\n\n  constructor(page = 0, size: number = DEFAULT_PAGEABLE_SIZE, sort?: ISort) {\n    this.page = page;\n    this.size = size;\n    this.sort = sort;\n  }\n\n  toHttpParams(\n    options: HttpParamsOptions = {}\n  ): HttpParams {\n    let params: HttpParams = new HttpParams(options)\n      // Add page & size\n      .set('page', `${this.page}`)\n      .set('size', `${this.size}`);\n\n    // Add orders\n    if (this.sort && this.sort.orders) {\n      const groupedSort: { [key in Direction]: string[] } = this.sort.orders.reduce(\n        (groupedProperty: any, order: Order) => {\n          groupedProperty[order.direction] = groupedProperty[order.direction] || [];\n          groupedProperty[order.direction].push(order.property);\n          return groupedProperty;\n        },\n        {} as { [key in Direction]: string[] }\n      );\n\n      Object.keys(groupedSort).forEach(direction => {\n        params = params.append('sort', `${groupedSort[direction].join(',')},${direction}`);\n      });\n    }\n\n    return params;\n  }\n}\n\nexport interface Page<T> {\n  // the total amount of elements\n  totalElements: number;\n  // the number of total pages\n  totalPages: number;\n  // the page content\n  content: T[];\n  // the number of the current Slice\n  number: number;\n  // the number of elements currently on this Slice\n  numberOfElements: number;\n  // the size of the Slice\n  size: number;\n  // the sorting parameters for the Slice\n  sort: Sort;\n  // whether the current Slice is the first one\n  first: boolean;\n  // whether the current Slice is the last one\n  last: boolean;\n}\n\nexport type Direction = 'ASC' | 'DESC';\nexport type NullHandling = 'NATIVE' | 'NULLS_FIRST' | 'NULLS_LAST';\nexport const DEFAULT_DIRECTION: Direction = 'ASC';\n\nexport class Sort implements ISort {\n  readonly orders: Order[];\n\n  constructor(orders: string | string[] | Order[], direction: Direction = DEFAULT_DIRECTION) {\n    if (orders) {\n      if (typeof orders === 'string') {\n        this.orders = [\n          {\n            property: orders ,\n            direction\n          }\n        ];\n      } else if (orders.length > 0) {\n        if (typeof orders[0] === 'string') {\n          this.orders = (orders as string[]).map(property => {\n            return {\n              property,\n              direction\n            };\n          });\n        } else {\n          this.orders = orders as Order[];\n        }\n      }\n    }\n  }\n}\n\nexport interface ISort {\n  orders: Order[];\n}\n\nexport interface Order {\n  property: string;\n  direction: Direction;\n  nullHandlingHint?: NullHandling;\n}\n","/*\n * Public API Surface of spring\n */\n\nexport * from './lib/spring-data.model';\n\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;MAEa,qBAAqB,GAAG,GAAG;MAE3B,WAAW;IAKtB,YAAY,IAAI,GAAG,CAAC,EAAE,OAAe,qBAAqB,EAAE,IAAY;QACtE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;KAClB;IAED,YAAY,CACV,UAA6B,EAAE;QAE/B,IAAI,MAAM,GAAe,IAAI,UAAU,CAAC,OAAO,CAAC;;aAE7C,GAAG,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;aAC3B,GAAG,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;;QAG/B,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACjC,MAAM,WAAW,GAAqC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAC3E,CAAC,eAAoB,EAAE,KAAY;gBACjC,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;gBAC1E,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAA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