@pie-qti/element-schemas 1.0.0-beta.0 → 1.0.0-beta.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.
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @pie-qti/element-schemas
3
+ *
4
+ * PIE element JSON schemas for validation
5
+ */
6
+ /**
7
+ * Available PIE element schemas
8
+ */
9
+ export declare const AVAILABLE_SCHEMAS: readonly ["multiple-choice", "extended-text-entry", "placement-ordering", "match", "explicit-constructed-response", "select-text", "inline-dropdown", "drag-in-the-blank", "ebsr", "hotspot", "image-cloze-association", "match-list", "passage"];
10
+ export type ElementType = typeof AVAILABLE_SCHEMAS[number];
11
+ /**
12
+ * Load a PIE element schema
13
+ * @param elementType - Element type (e.g., 'multiple-choice')
14
+ * @returns JSON schema object
15
+ */
16
+ export declare function loadSchema(elementType: ElementType): Promise<object>;
17
+ /**
18
+ * Load all available schemas
19
+ * @returns Map of element type to schema
20
+ */
21
+ export declare function loadAllSchemas(): Promise<Map<string, object>>;
22
+ /**
23
+ * Get schema synchronously (must be loaded first)
24
+ * @param elementType - Element type
25
+ * @returns Cached schema or undefined
26
+ */
27
+ export declare function getSchema(elementType: ElementType): object | undefined;
28
+ /**
29
+ * Check if a schema is available
30
+ * @param elementType - Element type to check
31
+ */
32
+ export declare function hasSchema(elementType: string): elementType is ElementType;
package/dist/index.js ADDED
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @pie-qti/element-schemas
3
+ *
4
+ * PIE element JSON schemas for validation
5
+ */
6
+ import { readFile } from 'node:fs/promises';
7
+ import { dirname, resolve } from 'node:path';
8
+ import { fileURLToPath } from 'node:url';
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
10
+ /**
11
+ * Available PIE element schemas
12
+ */
13
+ export const AVAILABLE_SCHEMAS = [
14
+ 'multiple-choice',
15
+ 'extended-text-entry',
16
+ 'placement-ordering',
17
+ 'match',
18
+ 'explicit-constructed-response',
19
+ 'select-text',
20
+ 'inline-dropdown',
21
+ 'drag-in-the-blank',
22
+ 'ebsr',
23
+ 'hotspot',
24
+ 'image-cloze-association',
25
+ 'match-list',
26
+ 'passage',
27
+ ];
28
+ /**
29
+ * Schema cache
30
+ */
31
+ const schemaCache = new Map();
32
+ /**
33
+ * Load a PIE element schema
34
+ * @param elementType - Element type (e.g., 'multiple-choice')
35
+ * @returns JSON schema object
36
+ */
37
+ export async function loadSchema(elementType) {
38
+ // Check cache first
39
+ if (schemaCache.has(elementType)) {
40
+ return schemaCache.get(elementType);
41
+ }
42
+ const schemaPath = resolve(__dirname, `schemas/${elementType}.json`);
43
+ try {
44
+ const content = await readFile(schemaPath, 'utf-8');
45
+ const schema = JSON.parse(content);
46
+ schemaCache.set(elementType, schema);
47
+ return schema;
48
+ }
49
+ catch (error) {
50
+ throw new Error(`Failed to load schema for ${elementType}: ${error.message}`);
51
+ }
52
+ }
53
+ /**
54
+ * Load all available schemas
55
+ * @returns Map of element type to schema
56
+ */
57
+ export async function loadAllSchemas() {
58
+ const schemas = new Map();
59
+ for (const elementType of AVAILABLE_SCHEMAS) {
60
+ const schema = await loadSchema(elementType);
61
+ schemas.set(`@pie-element/${elementType}`, schema);
62
+ }
63
+ return schemas;
64
+ }
65
+ /**
66
+ * Get schema synchronously (must be loaded first)
67
+ * @param elementType - Element type
68
+ * @returns Cached schema or undefined
69
+ */
70
+ export function getSchema(elementType) {
71
+ return schemaCache.get(elementType);
72
+ }
73
+ /**
74
+ * Check if a schema is available
75
+ * @param elementType - Element type to check
76
+ */
77
+ export function hasSchema(elementType) {
78
+ return AVAILABLE_SCHEMAS.includes(elementType);
79
+ }
80
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,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E1C,KAAK,MAAM,WAAW,IAAI,iBAAiB,EAAE,CAAC;QAC5C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,WAAW,CAAC,CAAC;QAC7C,OAAO,CAAC,GAAG,CAAC,gBAAgB,WAAW,EAAE,EAAE,MAAM,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,WAAwB;IAChD,OAAO,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,WAAmB;IAC3C,OAAO,iBAAiB,CAAC,QAAQ,CAAC,WAA0B,CAAC,CAAC;AAChE,CAAC","sourcesContent":["/**\n * @pie-qti/element-schemas\n *\n * PIE element JSON schemas for validation\n */\n\nimport { readFile } from 'node:fs/promises';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\n/**\n * Available PIE element schemas\n */\nexport const AVAILABLE_SCHEMAS = [\n 'multiple-choice',\n 'extended-text-entry',\n 'placement-ordering',\n 'match',\n 'explicit-constructed-response',\n 'select-text',\n 'inline-dropdown',\n 'drag-in-the-blank',\n 'ebsr',\n 'hotspot',\n 'image-cloze-association',\n 'match-list',\n 'passage',\n] as const;\n\nexport type ElementType = typeof AVAILABLE_SCHEMAS[number];\n\n/**\n * Schema cache\n */\nconst schemaCache = new Map<string, object>();\n\n/**\n * Load a PIE element schema\n * @param elementType - Element type (e.g., 'multiple-choice')\n * @returns JSON schema object\n */\nexport async function loadSchema(elementType: ElementType): Promise<object> {\n // Check cache first\n if (schemaCache.has(elementType)) {\n return schemaCache.get(elementType)!;\n }\n\n const schemaPath = resolve(__dirname, `schemas/${elementType}.json`);\n\n try {\n const content = await readFile(schemaPath, 'utf-8');\n const schema = JSON.parse(content);\n schemaCache.set(elementType, schema);\n return schema;\n } catch (error) {\n throw new Error(\n `Failed to load schema for ${elementType}: ${(error as Error).message}`\n );\n }\n}\n\n/**\n * Load all available schemas\n * @returns Map of element type to schema\n */\nexport async function loadAllSchemas(): Promise<Map<string, object>> {\n const schemas = new Map<string, object>();\n\n for (const elementType of AVAILABLE_SCHEMAS) {\n const schema = await loadSchema(elementType);\n schemas.set(`@pie-element/${elementType}`, schema);\n }\n\n return schemas;\n}\n\n/**\n * Get schema synchronously (must be loaded first)\n * @param elementType - Element type\n * @returns Cached schema or undefined\n */\nexport function getSchema(elementType: ElementType): object | undefined {\n return schemaCache.get(elementType);\n}\n\n/**\n * Check if a schema is available\n * @param elementType - Element type to check\n */\nexport function hasSchema(elementType: string): elementType is ElementType {\n return AVAILABLE_SCHEMAS.includes(elementType as ElementType);\n}\n"]}