@uniweb/api 0.6.1 → 0.6.2
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 +1 -1
- package/src/mock/store.js +18 -4
package/package.json
CHANGED
package/src/mock/store.js
CHANGED
|
@@ -85,8 +85,21 @@ function canonical(value) {
|
|
|
85
85
|
const isMulti = (section) => section?.multiple === true || section?.kind === 'multi'
|
|
86
86
|
const shortName = (model) => String(model).split('/').pop() || String(model)
|
|
87
87
|
|
|
88
|
-
/**
|
|
89
|
-
|
|
88
|
+
/**
|
|
89
|
+
* A `{ locale: value }` map — a plain object, never an array (a localized list's
|
|
90
|
+
* value), and never the value of a field whose OWN type is an object.
|
|
91
|
+
*
|
|
92
|
+
* ⛔ A `json` field's value is a plain object too — a richtext body is a ProseMirror
|
|
93
|
+
* document — and read as a map it has no `en`, so the body was DELETED from every
|
|
94
|
+
* read that carried `?locale=`, which the client sends on every browser read.
|
|
95
|
+
* Measured 2026-09-24 on a lesson whose `content` section became declared. The
|
|
96
|
+
* write checker (`schema-shape.js`) takes any object in such a field as THE value,
|
|
97
|
+
* so the projection reads it the same way: for these types the map shape is not
|
|
98
|
+
* knowable, and a value is a value.
|
|
99
|
+
*/
|
|
100
|
+
const OBJECT_TYPED = new Set(['json', 'object', 'group'])
|
|
101
|
+
const isLocaleMap = (field, value) =>
|
|
102
|
+
value != null && typeof value === 'object' && !Array.isArray(value) && !OBJECT_TYPED.has(field?.type)
|
|
90
103
|
|
|
91
104
|
export class MockStore {
|
|
92
105
|
/**
|
|
@@ -497,13 +510,14 @@ export class MockStore {
|
|
|
497
510
|
* an array, and an array is a value, not a map of them: read as a map it has no
|
|
498
511
|
* `en`, and the field was DELETED from every read that carried `?locale=` — which
|
|
499
512
|
* the client sends on every browser read. Measured 2026-09-22 on a course brief
|
|
500
|
-
* whose `outcomes` vanished, and on quiz questions whose `options` did.
|
|
513
|
+
* whose `outcomes` vanished, and on quiz questions whose `options` did. The same
|
|
514
|
+
* for a `json` field's document (`isLocaleMap`), measured 2026-09-24.
|
|
501
515
|
*/
|
|
502
516
|
project(data, section, locales) {
|
|
503
517
|
if (!locales?.length || !section?.fields || !data || typeof data !== 'object') return data
|
|
504
518
|
const out = { ...data }
|
|
505
519
|
for (const [key, field] of Object.entries(section.fields)) {
|
|
506
|
-
if (!field?.localized || !isLocaleMap(out[key])) continue
|
|
520
|
+
if (!field?.localized || !isLocaleMap(field, out[key])) continue
|
|
507
521
|
const hit = locales.find((l) => out[key][l] != null)
|
|
508
522
|
if (hit) out[key] = out[key][hit]
|
|
509
523
|
else delete out[key]
|