@01-edu/shared 2.0.2 → 2.0.4

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/attrs-defs.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  numTime,
9
9
  } from './event-utils.js'
10
10
  import { flatGraphContents, getCoreOfSattelite, limitations } from './graph.js'
11
- import { onboardingTypes } from './onboarding.js'
11
+ import { onboardingTypes } from './object-structure.ts'
12
12
  import { getObjectFromRelativePath } from './path.js'
13
13
  import { gamesScoring } from './score.js'
14
14
  import { hasRequiredSkills, skillsSet } from './skill-definitions.js'
@@ -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),
@@ -1,5 +1,5 @@
1
1
  import { attributes, relationAttributes } from './attrs.js'
2
- import { childTypes, objectTypes } from './toolbox.js'
2
+ import { childTypes, objectTypes } from './object-structure.ts'
3
3
 
4
4
  const normalize = str =>
5
5
  str
@@ -9,14 +9,22 @@ const normalize = str =>
9
9
  .replaceAll(' ', '-')
10
10
 
11
11
  const assertDef = def => {
12
- const { type, name, attrs, children, childrenAttrs, referencePath, ...rest } =
13
- def
12
+ const {
13
+ type,
14
+ name,
15
+ attrs,
16
+ children: _children,
17
+ childrenAttrs,
18
+ referencePath: _referencePath,
19
+ ...rest
20
+ } = def
14
21
  const [extra] = Object.keys(rest)
15
22
  if (extra) {
16
23
  throw Error(
17
24
  `Unexpected property ${extra}, did you mean to define an attribute ?`,
18
25
  )
19
26
  }
27
+ if (type === 'campus') throw Error(`Campuses can't be defined in definitions`)
20
28
  if (!objectTypes.has(type)) throw Error(`Invalid type property`)
21
29
  if (!name || typeof name !== 'string') throw Error(`Invalid name property`)
22
30
  if (!attrs || typeof attrs !== 'object' || Array.isArray(attrs)) {
@@ -0,0 +1,60 @@
1
+ export const onboardingTypes = new Set([
2
+ 'onboarding',
3
+ 'piscine-registration',
4
+ 'interview',
5
+ 'games',
6
+ 'administration',
7
+ 'module-registration',
8
+ 'form-step',
9
+ 'sign-step',
10
+ 'upload-step',
11
+ 'contact-validation-step',
12
+ 'avatar-step',
13
+ ] as const)
14
+
15
+ type Extract<T> = [T] extends [Set<infer V>] ? V : never
16
+
17
+ export const objectTypes = new Set([
18
+ 'module',
19
+ 'piscine',
20
+ 'exam',
21
+ 'raid',
22
+ 'quest',
23
+ 'exercise',
24
+ 'project',
25
+ 'signup',
26
+ 'campus',
27
+ ...onboardingTypes,
28
+ ] as const)
29
+
30
+ export type ObjectType = Extract<typeof objectTypes>
31
+ export const childTypes = {
32
+ campus: ['signup', 'onboarding', 'piscine', 'module'],
33
+ signup: [
34
+ 'form-step',
35
+ 'sign-step',
36
+ 'upload-step',
37
+ 'contact-validation-step',
38
+ 'avatar-step',
39
+ ],
40
+ onboarding: [
41
+ 'games',
42
+ 'administration',
43
+ 'interview',
44
+ 'piscine-registration',
45
+ 'module-registration',
46
+ ],
47
+ administration: [
48
+ 'form-step',
49
+ 'sign-step',
50
+ 'upload-step',
51
+ 'contact-validation-step',
52
+ 'avatar-step',
53
+ ],
54
+ piscine: ['quest', 'exam', 'raid', 'project'],
55
+ exam: ['exercise'],
56
+ quest: ['exercise'],
57
+ module: ['project', 'piscine', 'exam'],
58
+ } as const satisfies Partial<Record<ObjectType, ObjectType[]>>
59
+
60
+ export type ChildTypes = typeof childTypes
package/onboarding.js CHANGED
@@ -1,17 +1,3 @@
1
- export const onboardingTypes = new Set([
2
- 'onboarding',
3
- 'piscine-registration',
4
- 'interview',
5
- 'games',
6
- 'administration',
7
- 'module-registration',
8
- 'form-step',
9
- 'sign-step',
10
- 'upload-step',
11
- 'contact-validation-step',
12
- 'avatar-step',
13
- ])
14
-
15
1
  export const prevValidated = (key, object) => {
16
2
  const { prev } = (
17
3
  object.parent.type !== 'onboarding' ? object : object.parent
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.4",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "scripts": {
@@ -19,7 +19,8 @@
19
19
  "./programming-languages.js",
20
20
  "./score.js",
21
21
  "./skill-definitions.js",
22
- "./toolbox.js"
22
+ "./toolbox.js",
23
+ "./object-structure.ts"
23
24
  ],
24
25
  "license": "Fair",
25
26
  "bin": {
package/toolbox.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { isFinished } from './event-utils.js'
2
- import { onboardingTypes } from './onboarding.js'
3
2
 
4
3
  const keyCodes = {
5
4
  13: ({ save, value, event, allowLineBreak }) => {
@@ -11,48 +10,6 @@ const keyCodes = {
11
10
  event.metaKey || event.ctrlKey ? save(value) : false, // cmd+s
12
11
  }
13
12
 
14
- export const contentObjects = new Set([
15
- 'module',
16
- 'piscine',
17
- 'exam',
18
- 'raid',
19
- 'quest',
20
- 'exercise',
21
- 'project',
22
- 'signup',
23
- ])
24
-
25
- export const objectTypes = new Set([...contentObjects, ...onboardingTypes])
26
-
27
- export const childTypes = {
28
- campus: ['signup', 'onboarding', 'piscine', 'module'],
29
- signup: [
30
- 'form-step',
31
- 'sign-step',
32
- 'upload-step',
33
- 'contact-validation-step',
34
- 'avatar-step',
35
- ],
36
- onboarding: [
37
- 'games',
38
- 'administration',
39
- 'interview',
40
- 'piscine-registration',
41
- 'module-registration',
42
- ],
43
- administration: [
44
- 'form-step',
45
- 'sign-step',
46
- 'upload-step',
47
- 'contact-validation-step',
48
- 'avatar-step',
49
- ],
50
- piscine: ['quest', 'exam', 'raid', 'project'],
51
- exam: ['exercise'],
52
- quest: ['exercise'],
53
- module: ['project', 'piscine', 'exam'],
54
- }
55
-
56
13
  export const handleKeyDownEvent = args => {
57
14
  const handler = keyCodes[args.event.keyCode]
58
15