@shipload/sdk 2.0.0-rc12 → 2.0.0-rc13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipload/sdk",
3
3
  "description": "SDKs for Shipload",
4
- "version": "2.0.0-rc12",
4
+ "version": "2.0.0-rc13",
5
5
  "homepage": "https://github.com/shipload/sdk",
6
6
  "license": "MIT",
7
7
  "main": "lib/shipload.js",
@@ -143,7 +143,7 @@ export {
143
143
  projectEntityAt,
144
144
  validateSchedule,
145
145
  } from './scheduling/projection'
146
- export type {Projectable, ProjectedEntity} from './scheduling/projection'
146
+ export type {Projectable, ProjectedEntity, ProjectionOptions} from './scheduling/projection'
147
147
 
148
148
  export * from './types/capabilities'
149
149
  export * from './types/entity'
@@ -259,11 +259,22 @@ function applyTask(projected: ProjectedEntity, task: ServerContract.Types.task):
259
259
  }
260
260
  }
261
261
 
262
- export function projectEntity(entity: Projectable): ProjectedEntity {
262
+ export interface ProjectionOptions {
263
+ upToTaskIndex?: number
264
+ }
265
+
266
+ export function projectEntity(entity: Projectable, options?: ProjectionOptions): ProjectedEntity {
263
267
  const projected = createProjectedEntity(entity)
264
268
  if (!entity.schedule || entity.schedule.tasks.length === 0) return projected
265
- for (const task of entity.schedule.tasks) {
266
- applyTask(projected, task)
269
+
270
+ const tasks = entity.schedule.tasks
271
+ const taskCount =
272
+ options?.upToTaskIndex !== undefined
273
+ ? Math.max(0, Math.min(options.upToTaskIndex, tasks.length))
274
+ : tasks.length
275
+
276
+ for (let i = 0; i < taskCount; i++) {
277
+ applyTask(projected, tasks[i])
267
278
  }
268
279
  return projected
269
280
  }