@pie-element/shared-controller-utils 0.1.1-next.2 → 0.1.1-next.20261002100925

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @pie-framework/controller-utils
1
+ # @pie-element/shared-controller-utils
2
2
 
3
3
  Controller utility functions for PIE elements.
4
4
 
@@ -9,7 +9,7 @@ This package is part of the PIE workspace and should be installed via workspace
9
9
  ```json
10
10
  {
11
11
  "dependencies": {
12
- "@pie-framework/controller-utils": "workspace:*"
12
+ "@pie-element/shared-controller-utils": "workspace:*"
13
13
  }
14
14
  }
15
15
  ```
@@ -17,7 +17,7 @@ This package is part of the PIE workspace and should be installed via workspace
17
17
  ## Usage
18
18
 
19
19
  ```typescript
20
- import { /* utility functions */ } from '@pie-framework/controller-utils';
20
+ import { getShuffledChoices, lockChoices, partialScoring } from '@pie-element/shared-controller-utils';
21
21
  ```
22
22
 
23
23
  ## Development
package/dist/index.js CHANGED
@@ -33,7 +33,7 @@ async function a(e, t, a, o = "value") {
33
33
  let c = r(e);
34
34
  if (a && typeof a == "function") try {
35
35
  let e = n(c.map((e) => e[o]));
36
- i(e) ? console.error(`shuffledValues is an empty array - refusing to call updateSession. shuffledChoices: ${JSON.stringify(c)}, key: ${o}`) : t.id && t.element && await a(t.id, t.element, { shuffledValues: e });
36
+ i(e) ? console.error(`shuffledValues is an empty array - refusing to call updateSession. shuffledChoices: ${JSON.stringify(c)}, key: ${o}`) : await a(t.id, t.element, { shuffledValues: e });
37
37
  } catch (e) {
38
38
  console.warn("Unable to save shuffled order for choices"), console.error(e);
39
39
  }
@@ -41,7 +41,7 @@ async function a(e, t, a, o = "value") {
41
41
  return c;
42
42
  }
43
43
  function o(e, t, n) {
44
- return !!(e.lockChoiceOrder || n["@pie-element"]?.lockChoiceOrder || (n.role ?? "student") === "instructor");
44
+ return !!(e.lockChoiceOrder || n?.["@pie-element"]?.lockChoiceOrder);
45
45
  }
46
46
  //#endregion
47
47
  //#region src/partial-scoring.ts
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * Functions for managing shuffled choice order and session persistence.
5
5
  */
6
+ import type { PieUpdateSession } from '@pie-element/shared-types';
6
7
  interface Session {
7
8
  id?: string;
8
9
  element?: string;
@@ -23,24 +24,22 @@ interface Environment {
23
24
  };
24
25
  role?: 'student' | 'instructor';
25
26
  }
26
- type UpdateSessionFunction = (sessionId: string, element: string, data: {
27
- shuffledValues: string[];
28
- }) => Promise<void>;
29
27
  /**
30
28
  * Get shuffled choices, either from session storage or by creating a new shuffle.
31
29
  *
32
30
  * This function:
33
31
  * 1. Checks if shuffled values already exist in the session
34
32
  * 2. If they exist, returns choices in that order
35
- * 3. If they don't exist, shuffles the choices and optionally saves to session
33
+ * 3. If they don't exist, shuffles the choices and saves the order through `updateSession`
36
34
  *
37
35
  * @param choices - Array of choice objects to shuffle
38
- * @param session - Current session object that may contain previous shuffle order
36
+ * @param session - Current session object that may contain previous shuffle order. An element
37
+ * that shuffles each of its parts passes a stand-in built for that part, with no id or element.
39
38
  * @param updateSession - Optional function to persist the shuffle order
40
39
  * @param choiceKey - Property name to use as the unique identifier (e.g., 'value', 'id')
41
40
  * @returns Promise resolving to shuffled choices array
42
41
  */
43
- export declare function getShuffledChoices<T extends Choice>(choices: T[], session: Session | undefined, updateSession?: UpdateSessionFunction, choiceKey?: string): Promise<T[] | undefined>;
42
+ export declare function getShuffledChoices<T extends Choice>(choices: T[], session: Session | undefined, updateSession?: PieUpdateSession, choiceKey?: string): Promise<T[] | undefined>;
44
43
  /**
45
44
  * Determine whether choice order should be locked (ordinal) or shuffled.
46
45
  *
@@ -51,13 +50,15 @@ export declare function getShuffledChoices<T extends Choice>(choices: T[], sessi
51
50
  * Logic:
52
51
  * 1. If model.lockChoiceOrder is true, lock order
53
52
  * 2. If env['@pie-element'].lockChoiceOrder is true, lock order
54
- * 3. If role is 'instructor', lock order (instructors see ordinal order)
55
- * 4. Otherwise (student role), allow shuffling
53
+ * 3. Otherwise, allow shuffling
54
+ *
55
+ * The role plays no part (PIE-714): an instructor reviewing a session sees the order its
56
+ * student saw.
56
57
  *
57
58
  * @param model - Model configuration
58
59
  * @param session - Current session (unused currently but kept for API compatibility)
59
60
  * @param env - Environment configuration
60
61
  * @returns Whether to lock choice order
61
62
  */
62
- export declare function lockChoices(model: Model, _session: Session | undefined, env: Environment): boolean;
63
+ export declare function lockChoices(model: Model, _session: Session | undefined, env: Environment | undefined): boolean;
63
64
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/shared-controller-utils",
3
- "version": "0.1.1-next.2",
3
+ "version": "0.1.1-next.20261002100925",
4
4
  "description": "Controller utility functions for PIE elements",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,13 +21,7 @@
21
21
  "clean": "rm -rf dist"
22
22
  },
23
23
  "dependencies": {
24
- "@pie-element/shared-types": "0.2.0-next.0"
25
- },
26
- "devDependencies": {
27
- "@types/bun": "latest",
28
- "typescript": "^5.9.3",
29
- "vite": "^8.1.5",
30
- "vitest": "^4.1.11"
24
+ "@pie-element/shared-types": "0.2.0-next.20261002100925"
31
25
  },
32
26
  "publishConfig": {
33
27
  "access": "public"