@learnosity/lib-qti-converter 0.13.0 → 0.14.0
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/docs/EXAMPLES.md +46 -34
- package/docs/GETTING_STARTED.md +32 -28
- package/docs/LEARNOSITY_BUNDLE_FORMAT.md +1 -1
- package/package.json +1 -1
- package/packages/cli/dist/{batchProcessors-DgiDpfpP.js → batchProcessors-DWG8qk7G.js} +28 -6
- package/packages/cli/dist/batchProcessors-DWG8qk7G.js.map +1 -0
- package/packages/cli/dist/batchWorker.js +1 -1
- package/packages/cli/dist/{learnosityToQti-CIj5603P.js → learnosityToQti-C7cTRTU2.js} +4 -4
- package/packages/cli/dist/{learnosityToQti-CIj5603P.js.map → learnosityToQti-C7cTRTU2.js.map} +1 -1
- package/packages/cli/dist/{learnosityToQtiPackage-n6nGGr32.js → learnosityToQtiPackage-C84dQKKi.js} +4 -4
- package/packages/cli/dist/{learnosityToQtiPackage-n6nGGr32.js.map → learnosityToQtiPackage-C84dQKKi.js.map} +1 -1
- package/packages/cli/dist/main.js +4 -4
- package/packages/cli/dist/{pathUtils-mTQZ0wYS.js → pathUtils-Cr9IcK0n.js} +11 -6
- package/packages/cli/dist/{pathUtils-mTQZ0wYS.js.map → pathUtils-Cr9IcK0n.js.map} +1 -1
- package/packages/cli/dist/{qtiPackageToLearnosity-B4cD8jUw.js → qtiPackageToLearnosity-BBfZgWBh.js} +7 -7
- package/packages/cli/dist/qtiPackageToLearnosity-BBfZgWBh.js.map +1 -0
- package/packages/cli/dist/{qtiToLearnosity-DDjcpShJ.js → qtiToLearnosity-C9OW_n7Z.js} +5 -5
- package/packages/cli/dist/qtiToLearnosity-C9OW_n7Z.js.map +1 -0
- package/packages/cli/dist/{resolveOptions-Czapkfc1.js → resolveOptions-D_UECo_9.js} +5 -4
- package/packages/cli/dist/resolveOptions-D_UECo_9.js.map +1 -0
- package/packages/cli/dist/{table-DTSv0atR.js → table-D1ydwhbX.js} +8 -4
- package/packages/cli/dist/table-D1ydwhbX.js.map +1 -0
- package/packages/core/dist/index.d.ts +7 -4
- package/packages/core/dist/index.js +34 -7
- package/packages/core/dist/node.d.ts +8 -5
- package/packages/core/dist/node.js +34 -7
- package/packages/cli/dist/batchProcessors-DgiDpfpP.js.map +0 -1
- package/packages/cli/dist/qtiPackageToLearnosity-B4cD8jUw.js.map +0 -1
- package/packages/cli/dist/qtiToLearnosity-DDjcpShJ.js.map +0 -1
- package/packages/cli/dist/resolveOptions-Czapkfc1.js.map +0 -1
- package/packages/cli/dist/table-DTSv0atR.js.map +0 -1
|
@@ -251,13 +251,16 @@ type OutputFormat = 'dir' | 'zip' | 'stdout';
|
|
|
251
251
|
*/
|
|
252
252
|
type DiagnosticsOutput = 'stderr' | 'file' | 'both' | 'none';
|
|
253
253
|
/**
|
|
254
|
-
* Item reference source for QTI → Learnosity conversion
|
|
254
|
+
* Item reference source for QTI → Learnosity conversion.
|
|
255
|
+
* `'itemIdentifier'` (default) uses the QTI `identifier` attribute.
|
|
256
|
+
* `'qti'` is a deprecated alias of `'itemIdentifier'`.
|
|
255
257
|
*/
|
|
256
|
-
type ItemReferenceSource = 'sourceFilename' | 'qti' | 'uuid';
|
|
258
|
+
type ItemReferenceSource = 'sourceFilename' | 'qti' | 'uuid' | 'itemIdentifier';
|
|
257
259
|
/**
|
|
258
|
-
* Item filename source for output JSON file naming (QTI → Learnosity)
|
|
260
|
+
* Item filename source for output JSON file naming (QTI → Learnosity).
|
|
261
|
+
* `'qti'` is a deprecated alias of `'itemIdentifier'`.
|
|
259
262
|
*/
|
|
260
|
-
type ItemFilenameSource = 'sourceFilename' | 'qti';
|
|
263
|
+
type ItemFilenameSource = 'sourceFilename' | 'qti' | 'itemIdentifier';
|
|
261
264
|
/**
|
|
262
265
|
* Shared conversion options
|
|
263
266
|
*/
|
|
@@ -23361,12 +23361,16 @@ function transformAssetUrls(html, options) {
|
|
|
23361
23361
|
//#endregion
|
|
23362
23362
|
//#region src/qti-to-learnosity/utils/generateItemReference.ts
|
|
23363
23363
|
/**
|
|
23364
|
-
* Generate item reference based on the configured source
|
|
23364
|
+
* Generate item reference based on the configured source.
|
|
23365
|
+
*
|
|
23366
|
+
* - `'itemIdentifier'` (default) and its deprecated alias `'qti'`, as well as an
|
|
23367
|
+
* omitted source, return the QTI `identifier`.
|
|
23368
|
+
* - `'uuid'` returns an MD5 hash of the QTI `identifier`.
|
|
23369
|
+
* - `'sourceFilename'` derives the reference from the source file name.
|
|
23365
23370
|
*/
|
|
23366
23371
|
function generateItemReference(qtiIdentifier, itemReferenceSource, sourceFile) {
|
|
23367
|
-
if (itemReferenceSource === "qti") return qtiIdentifier;
|
|
23368
23372
|
if (itemReferenceSource === "uuid") return md5hex(qtiIdentifier);
|
|
23369
|
-
if (sourceFile) return (sourceFile.split(/[\\/]/).pop() ?? sourceFile).replace(/\.xml$/i, "");
|
|
23373
|
+
if (itemReferenceSource === "sourceFilename" && sourceFile) return (sourceFile.split(/[\\/]/).pop() ?? sourceFile).replace(/\.xml$/i, "");
|
|
23370
23374
|
return qtiIdentifier;
|
|
23371
23375
|
}
|
|
23372
23376
|
//#endregion
|
|
@@ -29537,6 +29541,7 @@ function convertQtiToLearnosity(input, opts) {
|
|
|
29537
29541
|
const result = convertQtiAssessmentItemToLearnosity(input, {
|
|
29538
29542
|
qtiVersion: opts.qtiVersion,
|
|
29539
29543
|
inputPath: opts.inputPath,
|
|
29544
|
+
sourceFile: opts.inputPath,
|
|
29540
29545
|
organisationId: opts.organisationId,
|
|
29541
29546
|
mediaVault: opts.mediaVault,
|
|
29542
29547
|
customAssetUrl: opts.customAssetUrl,
|
|
@@ -31349,6 +31354,15 @@ var AssetFilenameRegistry = class {
|
|
|
31349
31354
|
* - Does not write outputs if any error diagnostics exist
|
|
31350
31355
|
* - Deterministic ordering and stable JSON serialization
|
|
31351
31356
|
*/
|
|
31357
|
+
/**
|
|
31358
|
+
* Normalize an item reference / filename source for comparison and defaulting.
|
|
31359
|
+
* `'qti'` is a deprecated alias of `'itemIdentifier'`, and an omitted value
|
|
31360
|
+
* defaults to `'itemIdentifier'`.
|
|
31361
|
+
*/
|
|
31362
|
+
function normalizeRefSource(source) {
|
|
31363
|
+
if (source === "qti" || source === void 0) return "itemIdentifier";
|
|
31364
|
+
return source;
|
|
31365
|
+
}
|
|
31352
31366
|
const utf8Decoder = new TextDecoder();
|
|
31353
31367
|
/** Decode entry bytes as UTF-8 (works for both Uint8Array and Node Buffer). */
|
|
31354
31368
|
function decodeUtf8(data) {
|
|
@@ -31400,6 +31414,17 @@ function readAssessmentItemIdentifier(inputXml, fallback) {
|
|
|
31400
31414
|
} catch {}
|
|
31401
31415
|
return identifier;
|
|
31402
31416
|
}
|
|
31417
|
+
function readAssessmentTestIdentifier(inputXml, fallback) {
|
|
31418
|
+
let identifier = fallback;
|
|
31419
|
+
const parser = new import_saxes.SaxesParser({ xmlns: true });
|
|
31420
|
+
parser.on("opentag", (tag) => {
|
|
31421
|
+
if ((tag.local ?? tag.name) === "assessmentTest") identifier = getAttr$5(tag, "identifier") ?? fallback;
|
|
31422
|
+
});
|
|
31423
|
+
try {
|
|
31424
|
+
parser.write(inputXml).close();
|
|
31425
|
+
} catch {}
|
|
31426
|
+
return identifier;
|
|
31427
|
+
}
|
|
31403
31428
|
function uniqueItemReference(baseReference, sourceHref, items) {
|
|
31404
31429
|
if (!items.has(baseReference)) return baseReference;
|
|
31405
31430
|
const readableCandidate = `${baseReference}_${normalizeHref(sourceHref).split("/").at(-1)?.replace(/\.xml$/i, "") ?? "item"}`;
|
|
@@ -31681,7 +31706,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31681
31706
|
inputXml: itemXml
|
|
31682
31707
|
});
|
|
31683
31708
|
const filenameSource = opts?.itemFilenameSource;
|
|
31684
|
-
if (filenameSource && filenameSource !== (opts.itemReferenceSource
|
|
31709
|
+
if (filenameSource && normalizeRefSource(filenameSource) !== normalizeRefSource(opts.itemReferenceSource)) {
|
|
31685
31710
|
const filename = generateItemReference(readAssessmentItemIdentifier(itemXml, md5Ref), filenameSource, itemFilePath);
|
|
31686
31711
|
itemFilenames.set(md5Ref, filename);
|
|
31687
31712
|
}
|
|
@@ -31712,8 +31737,10 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31712
31737
|
const activitiesManifest = {};
|
|
31713
31738
|
if (testResources.length > 0) for (const testResource of testResources) {
|
|
31714
31739
|
let activityReference;
|
|
31715
|
-
if (opts?.itemReferenceSource === "
|
|
31716
|
-
|
|
31740
|
+
if (normalizeRefSource(opts?.itemReferenceSource) === "itemIdentifier") {
|
|
31741
|
+
const testEntry = entries.get(normalizeHref(testResource.href));
|
|
31742
|
+
activityReference = testEntry ? readAssessmentTestIdentifier(decodeUtf8(testEntry.data), testResource.identifier) : testResource.identifier;
|
|
31743
|
+
} else {
|
|
31717
31744
|
const hrefParts = testResource.href.split("/");
|
|
31718
31745
|
activityReference = hrefParts[hrefParts.length - 1].replace(/\.xml$/i, "");
|
|
31719
31746
|
}
|
|
@@ -31849,7 +31876,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31849
31876
|
mediaVault: opts?.mediaVault ?? false,
|
|
31850
31877
|
customAssetUrl: opts?.customAssetUrl,
|
|
31851
31878
|
preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
|
|
31852
|
-
itemReferenceSource: opts?.itemReferenceSource ?? "
|
|
31879
|
+
itemReferenceSource: opts?.itemReferenceSource ?? "itemIdentifier"
|
|
31853
31880
|
}
|
|
31854
31881
|
},
|
|
31855
31882
|
items: Array.from(items.keys()).sort(),
|
|
@@ -251,13 +251,16 @@ type OutputFormat = 'dir' | 'zip' | 'stdout';
|
|
|
251
251
|
*/
|
|
252
252
|
type DiagnosticsOutput = 'stderr' | 'file' | 'both' | 'none';
|
|
253
253
|
/**
|
|
254
|
-
* Item reference source for QTI → Learnosity conversion
|
|
254
|
+
* Item reference source for QTI → Learnosity conversion.
|
|
255
|
+
* `'itemIdentifier'` (default) uses the QTI `identifier` attribute.
|
|
256
|
+
* `'qti'` is a deprecated alias of `'itemIdentifier'`.
|
|
255
257
|
*/
|
|
256
|
-
type ItemReferenceSource = 'sourceFilename' | 'qti' | 'uuid';
|
|
258
|
+
type ItemReferenceSource = 'sourceFilename' | 'qti' | 'uuid' | 'itemIdentifier';
|
|
257
259
|
/**
|
|
258
|
-
* Item filename source for output JSON file naming (QTI → Learnosity)
|
|
260
|
+
* Item filename source for output JSON file naming (QTI → Learnosity).
|
|
261
|
+
* `'qti'` is a deprecated alias of `'itemIdentifier'`.
|
|
259
262
|
*/
|
|
260
|
-
type ItemFilenameSource = 'sourceFilename' | 'qti';
|
|
263
|
+
type ItemFilenameSource = 'sourceFilename' | 'qti' | 'itemIdentifier';
|
|
261
264
|
/**
|
|
262
265
|
* Shared conversion options
|
|
263
266
|
*/
|
|
@@ -2881,7 +2884,7 @@ interface ConvertQtiPackageToLearnosityOptions {
|
|
|
2881
2884
|
customAssetUrl?: string;
|
|
2882
2885
|
/** Preserve original QTI asset basenames instead of using hashed names (default: false) */
|
|
2883
2886
|
preserveAssetFilenames?: boolean;
|
|
2884
|
-
/** How to generate item references (default: '
|
|
2887
|
+
/** How to generate item references (default: 'itemIdentifier'; 'qti' is a deprecated alias of 'itemIdentifier') */
|
|
2885
2888
|
itemReferenceSource?: ItemReferenceSource;
|
|
2886
2889
|
/** How to generate output filenames (defaults to itemReferenceSource) */
|
|
2887
2890
|
itemFilenameSource?: ItemFilenameSource;
|
|
@@ -23368,12 +23368,16 @@ function transformAssetUrls(html, options) {
|
|
|
23368
23368
|
//#endregion
|
|
23369
23369
|
//#region src/qti-to-learnosity/utils/generateItemReference.ts
|
|
23370
23370
|
/**
|
|
23371
|
-
* Generate item reference based on the configured source
|
|
23371
|
+
* Generate item reference based on the configured source.
|
|
23372
|
+
*
|
|
23373
|
+
* - `'itemIdentifier'` (default) and its deprecated alias `'qti'`, as well as an
|
|
23374
|
+
* omitted source, return the QTI `identifier`.
|
|
23375
|
+
* - `'uuid'` returns an MD5 hash of the QTI `identifier`.
|
|
23376
|
+
* - `'sourceFilename'` derives the reference from the source file name.
|
|
23372
23377
|
*/
|
|
23373
23378
|
function generateItemReference(qtiIdentifier, itemReferenceSource, sourceFile) {
|
|
23374
|
-
if (itemReferenceSource === "qti") return qtiIdentifier;
|
|
23375
23379
|
if (itemReferenceSource === "uuid") return md5hex(qtiIdentifier);
|
|
23376
|
-
if (sourceFile) return (sourceFile.split(/[\\/]/).pop() ?? sourceFile).replace(/\.xml$/i, "");
|
|
23380
|
+
if (itemReferenceSource === "sourceFilename" && sourceFile) return (sourceFile.split(/[\\/]/).pop() ?? sourceFile).replace(/\.xml$/i, "");
|
|
23377
23381
|
return qtiIdentifier;
|
|
23378
23382
|
}
|
|
23379
23383
|
//#endregion
|
|
@@ -29544,6 +29548,7 @@ function convertQtiToLearnosity(input, opts) {
|
|
|
29544
29548
|
const result = convertQtiAssessmentItemToLearnosity(input, {
|
|
29545
29549
|
qtiVersion: opts.qtiVersion,
|
|
29546
29550
|
inputPath: opts.inputPath,
|
|
29551
|
+
sourceFile: opts.inputPath,
|
|
29547
29552
|
organisationId: opts.organisationId,
|
|
29548
29553
|
mediaVault: opts.mediaVault,
|
|
29549
29554
|
customAssetUrl: opts.customAssetUrl,
|
|
@@ -31881,6 +31886,15 @@ var AssetFilenameRegistry = class {
|
|
|
31881
31886
|
* - Does not write outputs if any error diagnostics exist
|
|
31882
31887
|
* - Deterministic ordering and stable JSON serialization
|
|
31883
31888
|
*/
|
|
31889
|
+
/**
|
|
31890
|
+
* Normalize an item reference / filename source for comparison and defaulting.
|
|
31891
|
+
* `'qti'` is a deprecated alias of `'itemIdentifier'`, and an omitted value
|
|
31892
|
+
* defaults to `'itemIdentifier'`.
|
|
31893
|
+
*/
|
|
31894
|
+
function normalizeRefSource(source) {
|
|
31895
|
+
if (source === "qti" || source === void 0) return "itemIdentifier";
|
|
31896
|
+
return source;
|
|
31897
|
+
}
|
|
31884
31898
|
const utf8Decoder = new TextDecoder();
|
|
31885
31899
|
/** Decode entry bytes as UTF-8 (works for both Uint8Array and Node Buffer). */
|
|
31886
31900
|
function decodeUtf8(data) {
|
|
@@ -31932,6 +31946,17 @@ function readAssessmentItemIdentifier(inputXml, fallback) {
|
|
|
31932
31946
|
} catch {}
|
|
31933
31947
|
return identifier;
|
|
31934
31948
|
}
|
|
31949
|
+
function readAssessmentTestIdentifier(inputXml, fallback) {
|
|
31950
|
+
let identifier = fallback;
|
|
31951
|
+
const parser = new import_saxes.SaxesParser({ xmlns: true });
|
|
31952
|
+
parser.on("opentag", (tag) => {
|
|
31953
|
+
if ((tag.local ?? tag.name) === "assessmentTest") identifier = getAttr$5(tag, "identifier") ?? fallback;
|
|
31954
|
+
});
|
|
31955
|
+
try {
|
|
31956
|
+
parser.write(inputXml).close();
|
|
31957
|
+
} catch {}
|
|
31958
|
+
return identifier;
|
|
31959
|
+
}
|
|
31935
31960
|
function uniqueItemReference(baseReference, sourceHref, items) {
|
|
31936
31961
|
if (!items.has(baseReference)) return baseReference;
|
|
31937
31962
|
const readableCandidate = `${baseReference}_${normalizeHref(sourceHref).split("/").at(-1)?.replace(/\.xml$/i, "") ?? "item"}`;
|
|
@@ -32213,7 +32238,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
32213
32238
|
inputXml: itemXml
|
|
32214
32239
|
});
|
|
32215
32240
|
const filenameSource = opts?.itemFilenameSource;
|
|
32216
|
-
if (filenameSource && filenameSource !== (opts.itemReferenceSource
|
|
32241
|
+
if (filenameSource && normalizeRefSource(filenameSource) !== normalizeRefSource(opts.itemReferenceSource)) {
|
|
32217
32242
|
const filename = generateItemReference(readAssessmentItemIdentifier(itemXml, md5Ref), filenameSource, itemFilePath);
|
|
32218
32243
|
itemFilenames.set(md5Ref, filename);
|
|
32219
32244
|
}
|
|
@@ -32244,8 +32269,10 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
32244
32269
|
const activitiesManifest = {};
|
|
32245
32270
|
if (testResources.length > 0) for (const testResource of testResources) {
|
|
32246
32271
|
let activityReference;
|
|
32247
|
-
if (opts?.itemReferenceSource === "
|
|
32248
|
-
|
|
32272
|
+
if (normalizeRefSource(opts?.itemReferenceSource) === "itemIdentifier") {
|
|
32273
|
+
const testEntry = entries.get(normalizeHref(testResource.href));
|
|
32274
|
+
activityReference = testEntry ? readAssessmentTestIdentifier(decodeUtf8(testEntry.data), testResource.identifier) : testResource.identifier;
|
|
32275
|
+
} else {
|
|
32249
32276
|
const hrefParts = testResource.href.split("/");
|
|
32250
32277
|
activityReference = hrefParts[hrefParts.length - 1].replace(/\.xml$/i, "");
|
|
32251
32278
|
}
|
|
@@ -32381,7 +32408,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
32381
32408
|
mediaVault: opts?.mediaVault ?? false,
|
|
32382
32409
|
customAssetUrl: opts?.customAssetUrl,
|
|
32383
32410
|
preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
|
|
32384
|
-
itemReferenceSource: opts?.itemReferenceSource ?? "
|
|
32411
|
+
itemReferenceSource: opts?.itemReferenceSource ?? "itemIdentifier"
|
|
32385
32412
|
}
|
|
32386
32413
|
},
|
|
32387
32414
|
items: Array.from(items.keys()).sort(),
|