@vue-skuilder/db 0.1.21 → 0.1.23
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/dist/index.d.cts +117 -4
- package/dist/index.d.ts +117 -4
- package/dist/index.js +270 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +254 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/courseConfigRegistration.ts +439 -0
- package/src/index.ts +2 -0
package/dist/index.mjs
CHANGED
|
@@ -5707,6 +5707,251 @@ var init_core = __esm({
|
|
|
5707
5707
|
init_core();
|
|
5708
5708
|
init_courseLookupDB();
|
|
5709
5709
|
|
|
5710
|
+
// src/courseConfigRegistration.ts
|
|
5711
|
+
init_logger();
|
|
5712
|
+
import { NameSpacer as NameSpacer2, toZodJSON } from "@vue-skuilder/common";
|
|
5713
|
+
function isDataShapeRegistered(dataShape, courseConfig) {
|
|
5714
|
+
const namespacedName = NameSpacer2.getDataShapeString({
|
|
5715
|
+
dataShape: dataShape.name,
|
|
5716
|
+
course: dataShape.course
|
|
5717
|
+
});
|
|
5718
|
+
const existingDataShape = courseConfig.dataShapes.find((ds) => ds.name === namespacedName);
|
|
5719
|
+
return existingDataShape !== void 0;
|
|
5720
|
+
}
|
|
5721
|
+
function isDataShapeSchemaAvailable(dataShape, courseConfig) {
|
|
5722
|
+
const namespacedName = NameSpacer2.getDataShapeString({
|
|
5723
|
+
dataShape: dataShape.name,
|
|
5724
|
+
course: dataShape.course
|
|
5725
|
+
});
|
|
5726
|
+
const existingDataShape = courseConfig.dataShapes.find((ds) => ds.name === namespacedName);
|
|
5727
|
+
return existingDataShape !== void 0 && existingDataShape.serializedZodSchema !== void 0;
|
|
5728
|
+
}
|
|
5729
|
+
function isQuestionTypeRegistered(question, courseConfig) {
|
|
5730
|
+
const namespacedName = NameSpacer2.getQuestionString({
|
|
5731
|
+
course: question.course,
|
|
5732
|
+
questionType: question.name
|
|
5733
|
+
});
|
|
5734
|
+
return courseConfig.questionTypes.some((qt) => qt.name === namespacedName);
|
|
5735
|
+
}
|
|
5736
|
+
function processCustomQuestionsData(customQuestions) {
|
|
5737
|
+
const processedDataShapes = [];
|
|
5738
|
+
const processedQuestions = [];
|
|
5739
|
+
const courseNames = customQuestions.courses.map((course) => course.name);
|
|
5740
|
+
customQuestions.questionClasses.forEach((questionClass) => {
|
|
5741
|
+
const courseName = courseNames.length > 0 ? courseNames[0] : customQuestions.meta.packageName;
|
|
5742
|
+
if (questionClass.dataShapes && Array.isArray(questionClass.dataShapes)) {
|
|
5743
|
+
questionClass.dataShapes.forEach((dataShape) => {
|
|
5744
|
+
processedDataShapes.push({
|
|
5745
|
+
name: dataShape.name,
|
|
5746
|
+
course: courseName,
|
|
5747
|
+
dataShape
|
|
5748
|
+
});
|
|
5749
|
+
});
|
|
5750
|
+
}
|
|
5751
|
+
processedQuestions.push({
|
|
5752
|
+
name: questionClass.name,
|
|
5753
|
+
course: courseName,
|
|
5754
|
+
questionClass,
|
|
5755
|
+
dataShapes: questionClass.dataShapes || [],
|
|
5756
|
+
views: questionClass.views || []
|
|
5757
|
+
});
|
|
5758
|
+
});
|
|
5759
|
+
return { dataShapes: processedDataShapes, questions: processedQuestions };
|
|
5760
|
+
}
|
|
5761
|
+
function registerDataShape(dataShape, courseConfig) {
|
|
5762
|
+
const namespacedName = NameSpacer2.getDataShapeString({
|
|
5763
|
+
dataShape: dataShape.name,
|
|
5764
|
+
course: dataShape.course
|
|
5765
|
+
});
|
|
5766
|
+
let serializedZodSchema;
|
|
5767
|
+
try {
|
|
5768
|
+
serializedZodSchema = toZodJSON(dataShape.dataShape);
|
|
5769
|
+
} catch (error) {
|
|
5770
|
+
logger.warn(`Failed to generate schema for ${namespacedName}:`, error);
|
|
5771
|
+
serializedZodSchema = void 0;
|
|
5772
|
+
}
|
|
5773
|
+
const existingIndex = courseConfig.dataShapes.findIndex((ds) => ds.name === namespacedName);
|
|
5774
|
+
if (existingIndex !== -1) {
|
|
5775
|
+
const existingDataShape = courseConfig.dataShapes[existingIndex];
|
|
5776
|
+
if (existingDataShape.serializedZodSchema === serializedZodSchema) {
|
|
5777
|
+
logger.info(
|
|
5778
|
+
`DataShape '${dataShape.name}' from '${dataShape.course}' already registered with identical schema`
|
|
5779
|
+
);
|
|
5780
|
+
return false;
|
|
5781
|
+
}
|
|
5782
|
+
if (existingDataShape.serializedZodSchema) {
|
|
5783
|
+
logger.info(
|
|
5784
|
+
`DataShape '${dataShape.name}' from '${dataShape.course}' schema has changed, updating...`
|
|
5785
|
+
);
|
|
5786
|
+
} else {
|
|
5787
|
+
logger.info(
|
|
5788
|
+
`DataShape '${dataShape.name}' from '${dataShape.course}' already registered, but with no schema. Adding schema to existing entry`
|
|
5789
|
+
);
|
|
5790
|
+
}
|
|
5791
|
+
courseConfig.dataShapes[existingIndex] = {
|
|
5792
|
+
name: namespacedName,
|
|
5793
|
+
questionTypes: existingDataShape.questionTypes,
|
|
5794
|
+
// Preserve existing question type associations
|
|
5795
|
+
serializedZodSchema
|
|
5796
|
+
};
|
|
5797
|
+
logger.info(`Updated DataShape: ${namespacedName}`);
|
|
5798
|
+
return true;
|
|
5799
|
+
}
|
|
5800
|
+
courseConfig.dataShapes.push({
|
|
5801
|
+
name: namespacedName,
|
|
5802
|
+
questionTypes: [],
|
|
5803
|
+
serializedZodSchema
|
|
5804
|
+
});
|
|
5805
|
+
logger.info(`Registered DataShape: ${namespacedName}`);
|
|
5806
|
+
return true;
|
|
5807
|
+
}
|
|
5808
|
+
function registerQuestionType(question, courseConfig) {
|
|
5809
|
+
if (isQuestionTypeRegistered(question, courseConfig)) {
|
|
5810
|
+
logger.info(`QuestionType '${question.name}' from '${question.course}' already registered`);
|
|
5811
|
+
return false;
|
|
5812
|
+
}
|
|
5813
|
+
const namespacedQuestionName = NameSpacer2.getQuestionString({
|
|
5814
|
+
course: question.course,
|
|
5815
|
+
questionType: question.name
|
|
5816
|
+
});
|
|
5817
|
+
const viewList = question.views.map((view) => {
|
|
5818
|
+
if (view.name) {
|
|
5819
|
+
return view.name;
|
|
5820
|
+
} else {
|
|
5821
|
+
return "unnamedComponent";
|
|
5822
|
+
}
|
|
5823
|
+
});
|
|
5824
|
+
const dataShapeList = question.dataShapes.map(
|
|
5825
|
+
(dataShape) => NameSpacer2.getDataShapeString({
|
|
5826
|
+
course: question.course,
|
|
5827
|
+
dataShape: dataShape.name
|
|
5828
|
+
})
|
|
5829
|
+
);
|
|
5830
|
+
courseConfig.questionTypes.push({
|
|
5831
|
+
name: namespacedQuestionName,
|
|
5832
|
+
viewList,
|
|
5833
|
+
dataShapeList
|
|
5834
|
+
});
|
|
5835
|
+
question.dataShapes.forEach((dataShape) => {
|
|
5836
|
+
const namespacedDataShapeName = NameSpacer2.getDataShapeString({
|
|
5837
|
+
course: question.course,
|
|
5838
|
+
dataShape: dataShape.name
|
|
5839
|
+
});
|
|
5840
|
+
for (const ds of courseConfig.dataShapes) {
|
|
5841
|
+
if (ds.name === namespacedDataShapeName) {
|
|
5842
|
+
ds.questionTypes.push(namespacedQuestionName);
|
|
5843
|
+
}
|
|
5844
|
+
}
|
|
5845
|
+
});
|
|
5846
|
+
logger.info(`Registered QuestionType: ${namespacedQuestionName}`);
|
|
5847
|
+
return true;
|
|
5848
|
+
}
|
|
5849
|
+
async function registerSeedData(question, courseDB, username) {
|
|
5850
|
+
if (question.questionClass.seedData && Array.isArray(question.questionClass.seedData)) {
|
|
5851
|
+
logger.info(`Registering seed data for question: ${question.name}`);
|
|
5852
|
+
try {
|
|
5853
|
+
const seedDataPromises = question.questionClass.seedData.filter(() => question.dataShapes.length > 0).map(
|
|
5854
|
+
(seedDataItem) => courseDB.addNote(
|
|
5855
|
+
question.course,
|
|
5856
|
+
question.dataShapes[0],
|
|
5857
|
+
seedDataItem,
|
|
5858
|
+
username,
|
|
5859
|
+
[]
|
|
5860
|
+
)
|
|
5861
|
+
);
|
|
5862
|
+
await Promise.all(seedDataPromises);
|
|
5863
|
+
logger.info(`Seed data registered for question: ${question.name}`);
|
|
5864
|
+
} catch (error) {
|
|
5865
|
+
logger.warn(
|
|
5866
|
+
`Failed to register seed data for question '${question.name}': ${error instanceof Error ? error.message : String(error)}`
|
|
5867
|
+
);
|
|
5868
|
+
}
|
|
5869
|
+
}
|
|
5870
|
+
}
|
|
5871
|
+
async function registerBlanksCard(BlanksCard, BlanksCardDataShapes, courseConfig, courseDB, username) {
|
|
5872
|
+
try {
|
|
5873
|
+
logger.info("Registering BlanksCard data shapes and question type...");
|
|
5874
|
+
let registeredCount = 0;
|
|
5875
|
+
const courseName = "default";
|
|
5876
|
+
for (const dataShapeClass of BlanksCardDataShapes) {
|
|
5877
|
+
const processedDataShape = {
|
|
5878
|
+
name: dataShapeClass.name,
|
|
5879
|
+
course: courseName,
|
|
5880
|
+
dataShape: dataShapeClass
|
|
5881
|
+
};
|
|
5882
|
+
if (registerDataShape(processedDataShape, courseConfig)) {
|
|
5883
|
+
registeredCount++;
|
|
5884
|
+
}
|
|
5885
|
+
}
|
|
5886
|
+
const processedQuestion = {
|
|
5887
|
+
name: BlanksCard.name,
|
|
5888
|
+
course: courseName,
|
|
5889
|
+
questionClass: {
|
|
5890
|
+
name: BlanksCard.name,
|
|
5891
|
+
dataShapes: BlanksCardDataShapes,
|
|
5892
|
+
views: BlanksCard.views || []
|
|
5893
|
+
},
|
|
5894
|
+
dataShapes: BlanksCardDataShapes,
|
|
5895
|
+
views: BlanksCard.views || []
|
|
5896
|
+
};
|
|
5897
|
+
if (registerQuestionType(processedQuestion, courseConfig)) {
|
|
5898
|
+
registeredCount++;
|
|
5899
|
+
}
|
|
5900
|
+
logger.info("Updating course configuration with BlanksCard...");
|
|
5901
|
+
const updateResult = await courseDB.updateCourseConfig(courseConfig);
|
|
5902
|
+
if (!updateResult.ok) {
|
|
5903
|
+
throw new Error(`Failed to update course config: ${JSON.stringify(updateResult)}`);
|
|
5904
|
+
}
|
|
5905
|
+
if (username) {
|
|
5906
|
+
await registerSeedData(processedQuestion, courseDB, username);
|
|
5907
|
+
}
|
|
5908
|
+
logger.info(`BlanksCard registration complete: ${registeredCount} items registered`);
|
|
5909
|
+
return { success: true };
|
|
5910
|
+
} catch (error) {
|
|
5911
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
5912
|
+
logger.error(`BlanksCard registration failed: ${errorMessage}`);
|
|
5913
|
+
return { success: false, errorMessage };
|
|
5914
|
+
}
|
|
5915
|
+
}
|
|
5916
|
+
async function registerCustomQuestionTypes(customQuestions, courseConfig, courseDB, username) {
|
|
5917
|
+
try {
|
|
5918
|
+
logger.info("Beginning custom question registration");
|
|
5919
|
+
logger.info(`Processing ${customQuestions.questionClasses.length} question classes`);
|
|
5920
|
+
const { dataShapes, questions } = processCustomQuestionsData(customQuestions);
|
|
5921
|
+
logger.info(`Found ${dataShapes.length} data shapes and ${questions.length} questions`);
|
|
5922
|
+
let registeredCount = 0;
|
|
5923
|
+
logger.info("Registering data shapes...");
|
|
5924
|
+
for (const dataShape of dataShapes) {
|
|
5925
|
+
if (registerDataShape(dataShape, courseConfig)) {
|
|
5926
|
+
registeredCount++;
|
|
5927
|
+
}
|
|
5928
|
+
}
|
|
5929
|
+
logger.info("Registering question types...");
|
|
5930
|
+
for (const question of questions) {
|
|
5931
|
+
if (registerQuestionType(question, courseConfig)) {
|
|
5932
|
+
registeredCount++;
|
|
5933
|
+
}
|
|
5934
|
+
}
|
|
5935
|
+
logger.info("Updating course configuration...");
|
|
5936
|
+
const updateResult = await courseDB.updateCourseConfig(courseConfig);
|
|
5937
|
+
if (!updateResult.ok) {
|
|
5938
|
+
throw new Error(`Failed to update course config: ${JSON.stringify(updateResult)}`);
|
|
5939
|
+
}
|
|
5940
|
+
if (username) {
|
|
5941
|
+
logger.info("Registering seed data...");
|
|
5942
|
+
for (const question of questions) {
|
|
5943
|
+
await registerSeedData(question, courseDB, username);
|
|
5944
|
+
}
|
|
5945
|
+
}
|
|
5946
|
+
logger.info(`Custom question registration complete: ${registeredCount} items registered`);
|
|
5947
|
+
return { success: true, registeredCount };
|
|
5948
|
+
} catch (error) {
|
|
5949
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
5950
|
+
logger.error(`Custom question registration failed: ${errorMessage}`);
|
|
5951
|
+
return { success: false, registeredCount: 0, errorMessage };
|
|
5952
|
+
}
|
|
5953
|
+
}
|
|
5954
|
+
|
|
5710
5955
|
// src/study/services/SrsService.ts
|
|
5711
5956
|
init_couch();
|
|
5712
5957
|
import moment8 from "moment";
|
|
@@ -8156,13 +8401,22 @@ export {
|
|
|
8156
8401
|
importParsedCards,
|
|
8157
8402
|
initializeDataDirectory,
|
|
8158
8403
|
initializeDataLayer,
|
|
8404
|
+
isDataShapeRegistered,
|
|
8405
|
+
isDataShapeSchemaAvailable,
|
|
8159
8406
|
isFilter,
|
|
8160
8407
|
isGenerator,
|
|
8161
8408
|
isQuestionRecord,
|
|
8409
|
+
isQuestionTypeRegistered,
|
|
8162
8410
|
isReview,
|
|
8163
8411
|
log,
|
|
8164
8412
|
newInterval,
|
|
8165
8413
|
parseCardHistoryID,
|
|
8414
|
+
processCustomQuestionsData,
|
|
8415
|
+
registerBlanksCard,
|
|
8416
|
+
registerCustomQuestionTypes,
|
|
8417
|
+
registerDataShape,
|
|
8418
|
+
registerQuestionType,
|
|
8419
|
+
registerSeedData,
|
|
8166
8420
|
validateMigration,
|
|
8167
8421
|
validateProcessorConfig,
|
|
8168
8422
|
validateStaticCourse
|