@01-edu/shared 2.0.2 → 2.0.3

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.
Files changed (2) hide show
  1. package/attrs-defs.js +19 -2
  2. package/package.json +1 -1
package/attrs-defs.js CHANGED
@@ -3247,6 +3247,12 @@ const isPathStatusSucceeded = (path, object) => {
3247
3247
  }
3248
3248
  }
3249
3249
 
3250
+ const addVersionChain = (object, path) => {
3251
+ const objReq = object.parent.children[path.slice('../'.length)]
3252
+ const versions = objReq?.versions?.map(({ key }) => `../${key}`)
3253
+ return versions?.length ? [path, ...versions] : [path]
3254
+ }
3255
+
3250
3256
  /**
3251
3257
  * @throws This function throws an error if any of the required objects is invalid
3252
3258
  * @returns {bool} true if all the required objects are succeeded, false otherwise
@@ -3257,11 +3263,22 @@ const hasSucceededRequiredObjects = (requirements, object) => {
3257
3263
  const { objects } = requirements
3258
3264
  if (!objects || !objects.length) return true
3259
3265
 
3266
+ // include the old versions
3267
+ const processedObjects = objects.map(p =>
3268
+ Array.isArray(p)
3269
+ ? p.flatMap(path => addVersionChain(object, path))
3270
+ : addVersionChain(object, p),
3271
+ )
3272
+
3260
3273
  // required objects are the ones that need to be done to unblock the current object
3261
- const requiredObjects = objects.filter(p => !Array.isArray(p) && Boolean(p))
3274
+ const requiredObjects = processedObjects.filter(
3275
+ p => !Array.isArray(p) && Boolean(p),
3276
+ )
3262
3277
  // pathway objects represent the choices a student can take to unblock the current object
3263
3278
  // note: at least one object from each pathway must be successfully completed
3264
- const pathWayObjects = objects?.filter(p => Array.isArray(p) && Boolean(p))
3279
+ const pathWayObjects = processedObjects?.filter(
3280
+ p => Array.isArray(p) && Boolean(p),
3281
+ )
3265
3282
 
3266
3283
  const hasSeccededRequiredObjects = requiredObjects.every(path =>
3267
3284
  isPathStatusSucceeded(path, object),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@01-edu/shared",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "scripts": {