@pie-qti/ims-cp-core 0.1.28 → 1.0.0-beta.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.
Files changed (37) hide show
  1. package/package.json +2 -2
  2. package/dist/index.d.ts +0 -14
  3. package/dist/index.js +0 -15
  4. package/dist/index.js.map +0 -1
  5. package/dist/localized-resources.d.ts +0 -308
  6. package/dist/localized-resources.js +0 -410
  7. package/dist/localized-resources.js.map +0 -1
  8. package/dist/manifest-parser.d.ts +0 -82
  9. package/dist/manifest-parser.js +0 -213
  10. package/dist/manifest-parser.js.map +0 -1
  11. package/dist/package-file-resolver.d.ts +0 -48
  12. package/dist/package-file-resolver.js +0 -312
  13. package/dist/package-file-resolver.js.map +0 -1
  14. package/dist/package-graph.d.ts +0 -134
  15. package/dist/package-graph.js +0 -791
  16. package/dist/package-graph.js.map +0 -1
  17. package/dist/package-path.d.ts +0 -11
  18. package/dist/package-path.js +0 -89
  19. package/dist/package-path.js.map +0 -1
  20. package/dist/passage-reusability.d.ts +0 -99
  21. package/dist/passage-reusability.js +0 -170
  22. package/dist/passage-reusability.js.map +0 -1
  23. package/dist/qti-heuristics.d.ts +0 -119
  24. package/dist/qti-heuristics.js +0 -150
  25. package/dist/qti-heuristics.js.map +0 -1
  26. package/dist/qti3-shared-content.d.ts +0 -82
  27. package/dist/qti3-shared-content.js +0 -383
  28. package/dist/qti3-shared-content.js.map +0 -1
  29. package/dist/security-parsing.d.ts +0 -9
  30. package/dist/security-parsing.js +0 -74
  31. package/dist/security-parsing.js.map +0 -1
  32. package/dist/utils/hash.d.ts +0 -20
  33. package/dist/utils/hash.js +0 -33
  34. package/dist/utils/hash.js.map +0 -1
  35. package/dist/utils/qti-xml.d.ts +0 -103
  36. package/dist/utils/qti-xml.js +0 -214
  37. package/dist/utils/qti-xml.js.map +0 -1
@@ -1,791 +0,0 @@
1
- import { parseManifest } from './manifest-parser.js';
2
- import { buildPackageFileIndex, resolvePackageReference, } from './package-file-resolver.js';
3
- import { dirnamePackagePath, isExternalPackageHref, joinPackagePath, resolveCheckedPackagePath, resolvePackagePath, } from './package-path.js';
4
- import { decodeXmlAttribute, parseSrcsetCandidates } from './security-parsing.js';
5
- const ASSET_EXTENSIONS = {
6
- '.apng': 'image',
7
- '.avif': 'image',
8
- '.gif': 'image',
9
- '.jpg': 'image',
10
- '.jpeg': 'image',
11
- '.png': 'image',
12
- '.svg': 'image',
13
- '.webp': 'image',
14
- '.css': 'stylesheet',
15
- '.mp3': 'audio',
16
- '.m4a': 'audio',
17
- '.ogg': 'audio',
18
- '.wav': 'audio',
19
- '.mp4': 'video',
20
- '.mov': 'video',
21
- '.webm': 'video',
22
- '.html': 'html',
23
- '.htm': 'html',
24
- '.xml': 'source-qti',
25
- };
26
- export async function analyzeContentPackage({ packageId, manifestXml, basePath, fileAccess, heuristicsConfig, }) {
27
- const manifest = parseManifest(manifestXml, basePath);
28
- const diagnostics = [];
29
- const resources = new Map();
30
- const references = new Map();
31
- const assets = new Map();
32
- const files = fileAccess?.listFiles ? await fileAccess.listFiles() : [];
33
- const listedFiles = fileAccess?.listFiles ? new Set(files) : undefined;
34
- const fileIndexPaths = new Set(files);
35
- const versionSignals = [
36
- ...detectManifestVersionSignals(manifestXml),
37
- ...detectResourceTypeVersionSignals(manifest.resources.values()),
38
- ];
39
- for (const resource of manifest.resources.values()) {
40
- const node = toResourceNode(resource, manifest);
41
- resources.set(node.identifier, node);
42
- diagnostics.push(...unsafeManifestPathDiagnostics(resource, manifest));
43
- if (node.resolvedHref) {
44
- fileIndexPaths.add(node.resolvedHref);
45
- }
46
- for (const filePath of node.resolvedFiles) {
47
- fileIndexPaths.add(filePath);
48
- maybeRegisterAsset(assets, filePath, {
49
- ownerResourceId: node.identifier,
50
- sourcePath: node.resolvedHref,
51
- });
52
- if (fileAccess && !(await packagePathExists(filePath, fileAccess, listedFiles))) {
53
- diagnostics.push({
54
- severity: 'warning',
55
- code: 'IMS_CP_MISSING_FILE',
56
- message: `Resource ${node.identifier} declares missing package file ${filePath}.`,
57
- resourceId: node.identifier,
58
- sourcePath: node.resolvedHref,
59
- reference: filePath,
60
- });
61
- }
62
- }
63
- }
64
- const fileIndex = buildPackageFileIndex([...fileIndexPaths]);
65
- diagnostics.push(...fileIndex.diagnostics);
66
- const manifestEvidencePaths = new Set([...resources.values()].flatMap((resource) => [
67
- ...(resource.resolvedHref ? [resource.resolvedHref] : []),
68
- ...resource.resolvedFiles,
69
- ]));
70
- for (const node of resources.values()) {
71
- const resourceReferences = [];
72
- for (const dependency of node.dependencies) {
73
- if (resources.has(dependency)) {
74
- resourceReferences.push({
75
- kind: 'manifest-dependency',
76
- rawHref: dependency,
77
- targetResourceId: dependency,
78
- });
79
- }
80
- else {
81
- diagnostics.push({
82
- severity: 'warning',
83
- code: 'IMS_CP_DANGLING_DEPENDENCY',
84
- message: `Resource ${node.identifier} depends on missing resource ${dependency}.`,
85
- resourceId: node.identifier,
86
- reference: dependency,
87
- });
88
- }
89
- }
90
- if (fileAccess && node.resolvedHref && isXmlLike(node.resolvedHref)) {
91
- const xml = await fileAccess.readText(node.resolvedHref);
92
- if (xml) {
93
- versionSignals.push(...detectQtiXmlVersionSignals(xml, node));
94
- const discovered = discoverReferences(xml, node, fileIndex, manifestEvidencePaths, heuristicsConfig);
95
- diagnostics.push(...discovered.diagnostics.map((diagnostic) => ({
96
- ...diagnostic,
97
- resourceId: node.identifier,
98
- })));
99
- for (const reference of discovered.references) {
100
- if ((reference.kind === 'assessment-item-ref' || reference.kind === 'stimulus') && reference.resolvedPath) {
101
- const target = findResourceByResolvedHref(resources, reference.resolvedPath);
102
- if (target) {
103
- reference.targetResourceId = target.identifier;
104
- }
105
- else if (!(await packagePathExists(reference.resolvedPath, fileAccess, listedFiles))) {
106
- diagnostics.push({
107
- severity: 'warning',
108
- code: reference.kind === 'stimulus' ? 'IMS_CP_DANGLING_STIMULUS_REF' : 'IMS_CP_DANGLING_ITEM_REF',
109
- message: `Resource ${node.identifier} references missing ${reference.kind === 'stimulus' ? 'assessment stimulus' : 'assessment item'} ${reference.rawHref}.`,
110
- resourceId: node.identifier,
111
- sourcePath: node.resolvedHref,
112
- reference: reference.rawHref,
113
- });
114
- }
115
- }
116
- resourceReferences.push(reference);
117
- }
118
- for (const asset of discovered.assets) {
119
- registerAsset(assets, asset);
120
- if (!(await packagePathExists(asset.resolvedPath, fileAccess, listedFiles))) {
121
- diagnostics.push({
122
- severity: 'warning',
123
- code: 'IMS_CP_MISSING_ASSET',
124
- message: `Resource ${node.identifier} references missing package asset ${asset.resolvedPath}.`,
125
- resourceId: node.identifier,
126
- sourcePath: node.resolvedHref,
127
- reference: asset.rawHref,
128
- });
129
- }
130
- }
131
- }
132
- else if (!hasMissingFileDiagnostic(diagnostics, node.identifier, node.resolvedHref)) {
133
- diagnostics.push({
134
- severity: 'warning',
135
- code: 'IMS_CP_MISSING_FILE',
136
- message: `Resource ${node.identifier} could not read package XML file ${node.resolvedHref}.`,
137
- resourceId: node.identifier,
138
- sourcePath: node.resolvedHref,
139
- reference: node.resolvedHref,
140
- });
141
- }
142
- }
143
- references.set(node.identifier, resourceReferences);
144
- }
145
- const closures = new Map();
146
- for (const entrypoint of [...manifest.tests, ...manifest.items, ...manifest.passages]) {
147
- closures.set(entrypoint.identifier, buildClosure(entrypoint.identifier, resources, references, diagnostics));
148
- }
149
- const qtiVersion = summarizeQtiVersion(versionSignals);
150
- const packageDiagnostics = [...diagnostics, ...qtiVersion.diagnostics];
151
- return {
152
- packageId: packageId ?? manifest.identifier ?? 'qti-package',
153
- manifest,
154
- resources,
155
- entrypoints: [
156
- ...manifest.tests.map((resource) => toEntrypoint(resource, 'test')),
157
- ...manifest.items.map((resource) => toEntrypoint(resource, 'item')),
158
- ...manifest.passages.map((resource) => toEntrypoint(resource, 'passage')),
159
- ],
160
- references,
161
- closures,
162
- assets,
163
- qtiVersion,
164
- diagnostics: packageDiagnostics,
165
- files,
166
- };
167
- }
168
- export function serializeContentPackageEvidence(packageGraph) {
169
- const resources = [...packageGraph.resources.values()]
170
- .map((resource) => ({
171
- ...resource,
172
- files: sortStrings(resource.files),
173
- resolvedFiles: sortStrings(resource.resolvedFiles),
174
- dependencies: sortStrings(resource.dependencies),
175
- }))
176
- .sort(compareBy((resource) => resource.identifier));
177
- const references = [...packageGraph.references.entries()]
178
- .flatMap(([resourceId, resourceReferences]) => resourceReferences.map((reference) => ({ resourceId, ...reference })))
179
- .sort(compareReferenceEvidence);
180
- const assets = [...packageGraph.assets.values()]
181
- .map((asset) => ({
182
- ...asset,
183
- ownerResourceIds: asset.ownerResourceIds ? sortStrings(asset.ownerResourceIds) : undefined,
184
- sourcePaths: asset.sourcePaths ? sortStrings(asset.sourcePaths) : undefined,
185
- }))
186
- .sort(compareBy((asset) => asset.resolvedPath));
187
- const closures = [...packageGraph.closures.values()]
188
- .map((closure) => ({
189
- ...closure,
190
- resourceIds: sortStrings(closure.resourceIds),
191
- filePaths: sortStrings(closure.filePaths),
192
- assetPaths: sortStrings(closure.assetPaths),
193
- diagnostics: sortDiagnostics(closure.diagnostics),
194
- }))
195
- .sort(compareBy((closure) => closure.resourceId));
196
- return {
197
- packageId: packageGraph.packageId,
198
- manifestIdentifier: packageGraph.manifest.identifier,
199
- entrypoints: [...packageGraph.entrypoints].sort(compareBy((entrypoint) => entrypoint.resourceId)),
200
- resources,
201
- references,
202
- closures,
203
- assets,
204
- relationshipHints: buildRelationshipHints(references, assets),
205
- qtiVersion: {
206
- ...packageGraph.qtiVersion,
207
- signals: [...packageGraph.qtiVersion.signals].sort(compareVersionSignal),
208
- diagnostics: sortDiagnostics(packageGraph.qtiVersion.diagnostics),
209
- },
210
- diagnostics: sortDiagnostics(packageGraph.diagnostics),
211
- files: sortStrings(packageGraph.files),
212
- };
213
- }
214
- function toResourceNode(resource, manifest) {
215
- const base = joinPackagePath(manifest.xmlBase, resource.xmlBase);
216
- const resolvedHref = resource.href ? resolveCheckedPackagePath(base, resource.href) ?? undefined : undefined;
217
- return {
218
- identifier: resource.identifier,
219
- type: resource.type,
220
- kind: classifyResource(resource),
221
- href: resource.href,
222
- resolvedHref,
223
- xmlBase: resource.xmlBase,
224
- files: resource.files,
225
- resolvedFiles: resource.files.flatMap((file) => {
226
- const resolved = resolveCheckedPackagePath(base, file);
227
- return resolved ? [resolved] : [];
228
- }),
229
- dependencies: resource.dependencies,
230
- metadata: resource.metadata,
231
- };
232
- }
233
- function unsafeManifestPathDiagnostics(resource, manifest) {
234
- const base = joinPackagePath(manifest.xmlBase, resource.xmlBase);
235
- const diagnostics = [];
236
- const candidates = [
237
- ...(manifest.xmlBase ? [{ href: manifest.xmlBase, kind: 'manifest xml:base', basePath: undefined }] : []),
238
- ...(resource.xmlBase ? [{ href: resource.xmlBase, kind: 'resource xml:base', basePath: manifest.xmlBase }] : []),
239
- ...(resource.href ? [{ href: resource.href, kind: 'resource href' }] : []),
240
- ...resource.files.map((href) => ({ href, kind: 'file href' })),
241
- ];
242
- for (const candidate of candidates) {
243
- if (resolveCheckedPackagePath(candidate.basePath ?? base, candidate.href))
244
- continue;
245
- diagnostics.push({
246
- severity: 'error',
247
- code: 'IMS_CP_UNSAFE_MANIFEST_PATH',
248
- message: `Resource ${resource.identifier} declares unsafe manifest ${candidate.kind} ${candidate.href}.`,
249
- resourceId: resource.identifier,
250
- reference: candidate.href,
251
- });
252
- }
253
- return diagnostics;
254
- }
255
- function toEntrypoint(resource, kind) {
256
- return {
257
- resourceId: resource.identifier,
258
- kind,
259
- href: resource.href,
260
- };
261
- }
262
- function classifyResource(resource) {
263
- if (resource.type.includes('imsqti_item') || resource.type.includes('qti_item'))
264
- return 'item';
265
- if (resource.type.includes('test') || resource.type.includes('assessment'))
266
- return 'test';
267
- if (resource.type.includes('passage') || resource.type.includes('stimulus'))
268
- return 'passage';
269
- if (resource.type === 'webcontent')
270
- return 'webcontent';
271
- if (resource.files.some((file) => classifyAssetUsage(file) !== 'other'))
272
- return 'asset';
273
- return 'other';
274
- }
275
- function discoverReferences(xml, owner, fileIndex, manifestEvidencePaths, heuristicsConfig) {
276
- const references = [];
277
- const assets = [];
278
- const diagnostics = [];
279
- const basePath = owner.resolvedHref ? dirnamePackagePath(owner.resolvedHref) : '';
280
- for (const match of findAttributeReferences(xml)) {
281
- const resolution = resolvePackageReference({
282
- fileIndex,
283
- sourcePath: owner.resolvedHref,
284
- rawHref: match.rawHref,
285
- referenceKind: referenceKindForMatch(match.kind),
286
- manifestEvidencePaths,
287
- heuristicsConfig,
288
- });
289
- diagnostics.push(...resolution.diagnostics);
290
- if (resolution.status === 'skipped') {
291
- continue;
292
- }
293
- if (resolution.status === 'unsafe' || resolution.status === 'ambiguous') {
294
- continue;
295
- }
296
- const resolvedPath = resolution.status === 'resolved'
297
- ? resolution.resolvedPath
298
- : resolvePackagePath(basePath, match.rawHref);
299
- const reference = {
300
- kind: match.kind,
301
- rawHref: match.rawHref,
302
- resolvedPath,
303
- sourcePath: owner.resolvedHref,
304
- sourceElement: match.element,
305
- sourceAttribute: match.attribute,
306
- ...(resolution.status === 'resolved'
307
- ? {
308
- resolutionStrategy: resolution.strategy,
309
- heuristic: resolution.heuristic,
310
- renderHref: resolution.renderHref,
311
- }
312
- : {}),
313
- };
314
- references.push(reference);
315
- if (match.kind !== 'assessment-item-ref' && match.kind !== 'stimulus') {
316
- assets.push({
317
- rawHref: match.rawHref,
318
- resolvedPath,
319
- usage: usageFromReference(match.kind, resolvedPath),
320
- ownerResourceId: owner.identifier,
321
- sourcePath: owner.resolvedHref,
322
- sourceElement: match.element,
323
- sourceAttribute: match.attribute,
324
- ...(resolution.status === 'resolved'
325
- ? {
326
- resolutionStrategy: resolution.strategy,
327
- heuristic: resolution.heuristic,
328
- renderHref: resolution.renderHref,
329
- }
330
- : {}),
331
- });
332
- }
333
- }
334
- return { references, assets, diagnostics };
335
- }
336
- function findAttributeReferences(xml) {
337
- const refs = [];
338
- const pattern = /<(?<element>assessmentItemRef|qti-assessment-item-ref|assessmentStimulusRef|qti-assessment-stimulus-ref|img|object|audio|video|source|track|embed|stylesheet|qti-stylesheet|link|file|fileHref|qti-file-href)\b(?<attrs>(?:[^>"']+|"[^"]*"|'[^']*')*)>/gi;
339
- for (const match of xml.matchAll(pattern)) {
340
- const element = match.groups?.element ?? '';
341
- const attrs = match.groups?.attrs ?? '';
342
- for (const attribute of referenceAttributesForElement(element)) {
343
- const rawValue = readAttribute(attrs, attribute);
344
- if (!rawValue)
345
- continue;
346
- const hrefs = attribute === 'srcset' ? parseSrcsetHrefs(rawValue) : [rawValue];
347
- for (const rawHref of hrefs) {
348
- const decodedHref = decodeXmlAttribute(rawHref);
349
- if (!decodedHref || isExternalPackageHref(decodedHref))
350
- continue;
351
- refs.push({
352
- kind: kindFromElement(element),
353
- element,
354
- attribute,
355
- rawHref: decodedHref,
356
- });
357
- }
358
- }
359
- }
360
- const catalogTextPattern = /<(?<element>fileHref|filehref|qti-file-href)\b[^>]*>(?<rawHref>[^<]+)<\/(?:fileHref|filehref|qti-file-href)>/gi;
361
- for (const match of xml.matchAll(catalogTextPattern)) {
362
- const element = match.groups?.element ?? '';
363
- const rawHref = decodeXmlAttribute(match.groups?.rawHref?.trim() ?? '');
364
- if (!rawHref || isExternalPackageHref(rawHref))
365
- continue;
366
- refs.push({
367
- kind: 'catalog',
368
- element,
369
- attribute: 'text',
370
- rawHref,
371
- });
372
- }
373
- return refs;
374
- }
375
- function referenceAttributesForElement(element) {
376
- switch (element.toLowerCase()) {
377
- case 'object':
378
- return ['data'];
379
- case 'img':
380
- return ['src', 'srcset'];
381
- case 'video':
382
- return ['src', 'poster'];
383
- case 'audio':
384
- case 'source':
385
- case 'track':
386
- case 'embed':
387
- return ['src'];
388
- case 'assessmentitemref':
389
- case 'qti-assessment-item-ref':
390
- case 'assessmentstimulusref':
391
- case 'qti-assessment-stimulus-ref':
392
- case 'stylesheet':
393
- case 'qti-stylesheet':
394
- case 'link':
395
- case 'file':
396
- return ['href', 'src'];
397
- case 'filehref':
398
- case 'qti-file-href':
399
- return ['src', 'href'];
400
- default:
401
- return ['href', 'src', 'poster'];
402
- }
403
- }
404
- function parseSrcsetHrefs(value) {
405
- return parseSrcsetCandidates(value).map((candidate) => candidate.url);
406
- }
407
- function kindFromElement(element) {
408
- switch (element.toLowerCase()) {
409
- case 'assessmentitemref':
410
- case 'qti-assessment-item-ref':
411
- return 'assessment-item-ref';
412
- case 'stylesheet':
413
- case 'qti-stylesheet':
414
- case 'link':
415
- return 'stylesheet';
416
- case 'assessmentstimulusref':
417
- case 'qti-assessment-stimulus-ref':
418
- return 'stimulus';
419
- case 'filehref':
420
- case 'qti-file-href':
421
- return 'catalog';
422
- case 'object':
423
- return 'object';
424
- default:
425
- return 'asset';
426
- }
427
- }
428
- function referenceKindForMatch(kind) {
429
- switch (kind) {
430
- case 'assessment-item-ref':
431
- case 'stimulus':
432
- return 'source-xml';
433
- case 'stylesheet':
434
- return 'stylesheet';
435
- case 'catalog':
436
- return 'catalog-file';
437
- case 'asset':
438
- case 'object':
439
- return 'media-asset';
440
- default:
441
- return 'other-asset';
442
- }
443
- }
444
- function usageFromReference(kind, path) {
445
- if (kind === 'stylesheet')
446
- return 'stylesheet';
447
- if (kind === 'catalog')
448
- return 'catalog';
449
- return classifyAssetUsage(path);
450
- }
451
- function buildClosure(resourceId, resources, references, packageDiagnostics) {
452
- const visited = new Set();
453
- const filePaths = new Set();
454
- const assetPaths = new Set();
455
- const diagnostics = [];
456
- function visit(id) {
457
- if (visited.has(id))
458
- return;
459
- const node = resources.get(id);
460
- if (!node) {
461
- diagnostics.push({
462
- severity: 'warning',
463
- code: 'IMS_CP_MISSING_CLOSURE_RESOURCE',
464
- message: `Closure references missing resource ${id}.`,
465
- resourceId,
466
- reference: id,
467
- });
468
- return;
469
- }
470
- visited.add(id);
471
- if (node.resolvedHref)
472
- filePaths.add(node.resolvedHref);
473
- for (const file of node.resolvedFiles) {
474
- filePaths.add(file);
475
- if (classifyAssetUsage(file) !== 'source-qti')
476
- assetPaths.add(file);
477
- }
478
- for (const reference of references.get(id) ?? []) {
479
- if (reference.targetResourceId)
480
- visit(reference.targetResourceId);
481
- if (reference.resolvedPath && reference.kind !== 'assessment-item-ref' && reference.kind !== 'stimulus') {
482
- assetPaths.add(reference.resolvedPath);
483
- filePaths.add(reference.resolvedPath);
484
- }
485
- else if (reference.resolvedPath && !reference.targetResourceId) {
486
- filePaths.add(reference.resolvedPath);
487
- }
488
- }
489
- }
490
- visit(resourceId);
491
- const visitedResourceIds = new Set(visited);
492
- return {
493
- resourceId,
494
- resourceIds: [...visited],
495
- filePaths: [...filePaths],
496
- assetPaths: [...assetPaths],
497
- diagnostics: [
498
- ...diagnostics,
499
- ...packageDiagnostics.filter((diagnostic) => diagnostic.resourceId && visitedResourceIds.has(diagnostic.resourceId)),
500
- ],
501
- };
502
- }
503
- function maybeRegisterAsset(assets, path, context) {
504
- const usage = classifyAssetUsage(path);
505
- if (usage === 'source-qti' || usage === 'other')
506
- return;
507
- registerAsset(assets, {
508
- rawHref: path,
509
- resolvedPath: path,
510
- usage,
511
- ...context,
512
- });
513
- }
514
- function registerAsset(assets, asset) {
515
- const existing = assets.get(asset.resolvedPath);
516
- if (!existing) {
517
- assets.set(asset.resolvedPath, {
518
- ...asset,
519
- ownerResourceIds: asset.ownerResourceId ? [asset.ownerResourceId] : [],
520
- sourcePaths: asset.sourcePath ? [asset.sourcePath] : [],
521
- });
522
- return;
523
- }
524
- const ownerResourceIds = new Set([
525
- ...(existing.ownerResourceIds ?? (existing.ownerResourceId ? [existing.ownerResourceId] : [])),
526
- ...(asset.ownerResourceIds ?? (asset.ownerResourceId ? [asset.ownerResourceId] : [])),
527
- ]);
528
- const sourcePaths = new Set([
529
- ...(existing.sourcePaths ?? (existing.sourcePath ? [existing.sourcePath] : [])),
530
- ...(asset.sourcePaths ?? (asset.sourcePath ? [asset.sourcePath] : [])),
531
- ]);
532
- assets.set(asset.resolvedPath, {
533
- ...existing,
534
- rawHref: existing.rawHref || asset.rawHref,
535
- usage: existing.usage === 'other' ? asset.usage : existing.usage,
536
- ownerResourceId: existing.ownerResourceId ?? asset.ownerResourceId,
537
- ownerResourceIds: [...ownerResourceIds],
538
- sourcePath: existing.sourcePath ?? asset.sourcePath,
539
- sourcePaths: [...sourcePaths],
540
- sourceElement: existing.sourceElement ?? asset.sourceElement,
541
- sourceAttribute: existing.sourceAttribute ?? asset.sourceAttribute,
542
- resolutionStrategy: existing.resolutionStrategy ?? asset.resolutionStrategy,
543
- heuristic: existing.heuristic ?? asset.heuristic,
544
- renderHref: existing.renderHref ?? asset.renderHref,
545
- });
546
- }
547
- function findResourceByResolvedHref(resources, resolvedHref) {
548
- return [...resources.values()].find((resource) => resource.resolvedHref === resolvedHref);
549
- }
550
- function classifyAssetUsage(path) {
551
- const lower = path.toLowerCase();
552
- const extension = Object.keys(ASSET_EXTENSIONS).find((candidate) => lower.endsWith(candidate));
553
- return extension ? ASSET_EXTENSIONS[extension] : 'other';
554
- }
555
- function isXmlLike(path) {
556
- return path.toLowerCase().endsWith('.xml');
557
- }
558
- function readAttribute(attrs, name) {
559
- const match = attrs.match(new RegExp(`\\b${name}\\s*=\\s*["']([^"']+)["']`, 'i'));
560
- return match?.[1];
561
- }
562
- async function packagePathExists(path, fileAccess, listedFiles) {
563
- if (listedFiles)
564
- return listedFiles.has(path);
565
- if (fileAccess.exists)
566
- return Boolean(await fileAccess.exists(path));
567
- return true;
568
- }
569
- function hasMissingFileDiagnostic(diagnostics, resourceId, path) {
570
- return diagnostics.some((diagnostic) => diagnostic.code === 'IMS_CP_MISSING_FILE' &&
571
- diagnostic.resourceId === resourceId &&
572
- diagnostic.reference === path);
573
- }
574
- function detectManifestVersionSignals(manifestXml) {
575
- return [
576
- ...detectVersionPatterns(manifestXml, {
577
- source: 'schema_location',
578
- confidence: 'medium',
579
- includeResourceTypes: false,
580
- }),
581
- ...detectVersionPatterns(manifestXml, {
582
- source: 'package_metadata',
583
- confidence: 'low',
584
- includeResourceTypes: false,
585
- }),
586
- ];
587
- }
588
- function detectResourceTypeVersionSignals(resources) {
589
- const signals = [];
590
- for (const resource of resources) {
591
- signals.push(...detectVersionPatterns(resource.type, {
592
- source: 'manifest',
593
- confidence: 'high',
594
- resourceId: resource.identifier,
595
- }));
596
- }
597
- return dedupeVersionSignals(signals);
598
- }
599
- function detectQtiXmlVersionSignals(xml, node) {
600
- return dedupeVersionSignals(detectVersionPatterns(xml, {
601
- source: 'qti_xml',
602
- confidence: 'high',
603
- resourceId: node.identifier,
604
- sourcePath: node.resolvedHref,
605
- }));
606
- }
607
- function detectVersionPatterns(value, context) {
608
- const includeResourceTypes = context.includeResourceTypes ?? true;
609
- const patterns = [
610
- {
611
- version: '3.0',
612
- patterns: [
613
- /imsqtiasi_v3p0/i,
614
- /imsqti_v3p0/i,
615
- /qti[_-]?v?3p0/i,
616
- /qti[_\s-]?3\.0/i,
617
- ],
618
- },
619
- {
620
- version: '2.2',
621
- patterns: [
622
- /imsqti_v2p2/i,
623
- /qti[_-]?v?2p2/i,
624
- /qti[_\s-]?2\.2/i,
625
- ...(includeResourceTypes ? [/xmlv2p2/i] : []),
626
- ],
627
- },
628
- {
629
- version: '2.1',
630
- patterns: [
631
- /imsqti_v2p1/i,
632
- /qti[_-]?v?2p1/i,
633
- /qti[_\s-]?2\.1/i,
634
- ...(includeResourceTypes ? [/xmlv2p1/i] : []),
635
- ],
636
- },
637
- ];
638
- const signals = [];
639
- for (const { version, patterns: versionPatterns } of patterns) {
640
- for (const pattern of versionPatterns) {
641
- const match = value.match(pattern);
642
- if (!match)
643
- continue;
644
- signals.push({
645
- source: context.source,
646
- version,
647
- confidence: context.confidence,
648
- evidence: match[0],
649
- resourceId: context.resourceId,
650
- sourcePath: context.sourcePath,
651
- });
652
- break;
653
- }
654
- }
655
- return dedupeVersionSignals(signals);
656
- }
657
- function summarizeQtiVersion(signals) {
658
- const dedupedSignals = dedupeVersionSignals(signals);
659
- const versions = [...new Set(dedupedSignals.map((signal) => signal.version))].sort();
660
- if (versions.length === 0) {
661
- return {
662
- version: 'unknown',
663
- confidence: 'none',
664
- signals: [],
665
- diagnostics: [
666
- {
667
- severity: 'warning',
668
- code: 'QTI_VERSION_UNKNOWN',
669
- message: 'Could not determine the QTI package version from manifest, schema, metadata, or readable QTI XML.',
670
- },
671
- ],
672
- };
673
- }
674
- if (versions.length > 1) {
675
- return {
676
- version: 'conflicting',
677
- confidence: 'conflicting',
678
- signals: dedupedSignals,
679
- diagnostics: [
680
- {
681
- severity: 'warning',
682
- code: 'QTI_VERSION_CONFLICT',
683
- message: `Conflicting QTI package version signals were found: ${versions.join(', ')}.`,
684
- reference: versions.join(','),
685
- },
686
- ],
687
- };
688
- }
689
- return {
690
- version: versions[0],
691
- confidence: strongestConfidence(dedupedSignals),
692
- signals: dedupedSignals,
693
- diagnostics: [],
694
- };
695
- }
696
- function strongestConfidence(signals) {
697
- if (signals.some((signal) => signal.confidence === 'high'))
698
- return 'high';
699
- if (signals.some((signal) => signal.confidence === 'medium'))
700
- return 'medium';
701
- if (signals.some((signal) => signal.confidence === 'low'))
702
- return 'low';
703
- return 'none';
704
- }
705
- function dedupeVersionSignals(signals) {
706
- const byKey = new Map();
707
- for (const signal of signals) {
708
- const key = [
709
- signal.source,
710
- signal.version,
711
- signal.confidence,
712
- signal.resourceId ?? '',
713
- signal.sourcePath ?? '',
714
- signal.evidence,
715
- ].join('|');
716
- byKey.set(key, signal);
717
- }
718
- return [...byKey.values()];
719
- }
720
- function buildRelationshipHints(references, assets) {
721
- const hints = [];
722
- for (const reference of references) {
723
- if (reference.kind !== 'manifest-dependency' &&
724
- reference.kind !== 'assessment-item-ref' &&
725
- reference.kind !== 'stimulus') {
726
- continue;
727
- }
728
- hints.push({
729
- kind: reference.kind === 'stimulus' ? 'assessment-stimulus-ref' : reference.kind,
730
- sourceResourceId: reference.resourceId,
731
- targetResourceId: reference.targetResourceId,
732
- targetPath: reference.resolvedPath,
733
- rawHref: reference.rawHref,
734
- sourcePath: reference.sourcePath,
735
- sourceElement: reference.sourceElement,
736
- sourceAttribute: reference.sourceAttribute,
737
- });
738
- }
739
- for (const asset of assets) {
740
- const ownerResourceIds = asset.ownerResourceIds ?? (asset.ownerResourceId ? [asset.ownerResourceId] : []);
741
- if (ownerResourceIds.length < 2)
742
- continue;
743
- hints.push({
744
- kind: 'shared-asset',
745
- sourceResourceIds: sortStrings(ownerResourceIds),
746
- targetPath: asset.resolvedPath,
747
- rawHref: asset.rawHref,
748
- sourcePath: asset.sourcePath,
749
- sourceElement: asset.sourceElement,
750
- sourceAttribute: asset.sourceAttribute,
751
- });
752
- }
753
- return hints.sort(compareRelationshipHint);
754
- }
755
- function sortStrings(values) {
756
- return [...values].sort((left, right) => left.localeCompare(right));
757
- }
758
- function sortDiagnostics(diagnostics) {
759
- return [...diagnostics].sort((left, right) => left.severity.localeCompare(right.severity) ||
760
- left.code.localeCompare(right.code) ||
761
- (left.resourceId ?? '').localeCompare(right.resourceId ?? '') ||
762
- (left.sourcePath ?? '').localeCompare(right.sourcePath ?? '') ||
763
- (left.reference ?? '').localeCompare(right.reference ?? '') ||
764
- left.message.localeCompare(right.message));
765
- }
766
- function compareBy(select) {
767
- return (left, right) => (select(left) ?? '').localeCompare(select(right) ?? '');
768
- }
769
- function compareReferenceEvidence(left, right) {
770
- return (left.resourceId.localeCompare(right.resourceId) ||
771
- left.kind.localeCompare(right.kind) ||
772
- (left.targetResourceId ?? '').localeCompare(right.targetResourceId ?? '') ||
773
- (left.resolvedPath ?? '').localeCompare(right.resolvedPath ?? '') ||
774
- left.rawHref.localeCompare(right.rawHref));
775
- }
776
- function compareVersionSignal(left, right) {
777
- return (left.version.localeCompare(right.version) ||
778
- left.source.localeCompare(right.source) ||
779
- (left.resourceId ?? '').localeCompare(right.resourceId ?? '') ||
780
- (left.sourcePath ?? '').localeCompare(right.sourcePath ?? '') ||
781
- left.evidence.localeCompare(right.evidence));
782
- }
783
- function compareRelationshipHint(left, right) {
784
- return (left.kind.localeCompare(right.kind) ||
785
- (left.sourceResourceId ?? '').localeCompare(right.sourceResourceId ?? '') ||
786
- (left.sourceResourceIds?.join(',') ?? '').localeCompare(right.sourceResourceIds?.join(',') ?? '') ||
787
- (left.targetResourceId ?? '').localeCompare(right.targetResourceId ?? '') ||
788
- (left.targetPath ?? '').localeCompare(right.targetPath ?? '') ||
789
- (left.rawHref ?? '').localeCompare(right.rawHref ?? ''));
790
- }
791
- //# sourceMappingURL=package-graph.js.map