js-bao 0.2.10 → 0.2.12

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 (67) hide show
  1. package/README.md +174 -0
  2. package/dist/BaseModel-5YQCROYE.js +17 -0
  3. package/dist/BaseModel-5YQCROYE.js.map +1 -0
  4. package/dist/BaseModel-FCNWDJBH.js +17 -0
  5. package/dist/BaseModel-FCNWDJBH.js.map +1 -0
  6. package/dist/BrowserDatabaseFactory-PXOTK2DQ.js +119 -0
  7. package/dist/BrowserDatabaseFactory-PXOTK2DQ.js.map +1 -0
  8. package/dist/BrowserDatabaseFactory-WD4VX2VZ.js +119 -0
  9. package/dist/BrowserDatabaseFactory-WD4VX2VZ.js.map +1 -0
  10. package/dist/IncludeResolver-RCKQGNPZ.js +385 -0
  11. package/dist/IncludeResolver-RCKQGNPZ.js.map +1 -0
  12. package/dist/IncludeResolver-WGSQDMS7.js +385 -0
  13. package/dist/IncludeResolver-WGSQDMS7.js.map +1 -0
  14. package/dist/NodeDatabaseFactory-J4Z36UF3.js +165 -0
  15. package/dist/NodeDatabaseFactory-J4Z36UF3.js.map +1 -0
  16. package/dist/NodeDatabaseFactory-QIEKAXBM.js +10 -0
  17. package/dist/NodeDatabaseFactory-QIEKAXBM.js.map +1 -0
  18. package/dist/NodeSqliteEngine-HJSAYE4E.js +383 -0
  19. package/dist/NodeSqliteEngine-HJSAYE4E.js.map +1 -0
  20. package/dist/NodeSqliteEngine-I5SLWLME.js +383 -0
  21. package/dist/NodeSqliteEngine-I5SLWLME.js.map +1 -0
  22. package/dist/browser.cjs +3779 -3370
  23. package/dist/browser.d.cts +18 -1
  24. package/dist/browser.d.ts +18 -1
  25. package/dist/browser.js +3750 -3341
  26. package/dist/chunk-3PZWHUZO.js +4153 -0
  27. package/dist/chunk-3PZWHUZO.js.map +1 -0
  28. package/dist/chunk-53MS4MN7.js +373 -0
  29. package/dist/chunk-53MS4MN7.js.map +1 -0
  30. package/dist/chunk-65G2P4GL.js +709 -0
  31. package/dist/chunk-65G2P4GL.js.map +1 -0
  32. package/dist/chunk-6UX3YSCW.js +4151 -0
  33. package/dist/chunk-6UX3YSCW.js.map +1 -0
  34. package/dist/chunk-DANSD6BE.js +709 -0
  35. package/dist/chunk-DANSD6BE.js.map +1 -0
  36. package/dist/chunk-DF3JEQXA.js +373 -0
  37. package/dist/chunk-DF3JEQXA.js.map +1 -0
  38. package/dist/chunk-GO3APTPX.js +61 -0
  39. package/dist/chunk-GO3APTPX.js.map +1 -0
  40. package/dist/chunk-ID4U6IQC.js +53 -0
  41. package/dist/chunk-ID4U6IQC.js.map +1 -0
  42. package/dist/chunk-RQVS3LVL.js +165 -0
  43. package/dist/chunk-RQVS3LVL.js.map +1 -0
  44. package/dist/client.cjs +837 -0
  45. package/dist/client.d.cts +1101 -0
  46. package/dist/client.d.ts +1101 -0
  47. package/dist/client.js +806 -0
  48. package/dist/cloudflare-do.cjs +3637 -0
  49. package/dist/cloudflare-do.d.cts +1366 -0
  50. package/dist/cloudflare-do.d.ts +1366 -0
  51. package/dist/cloudflare-do.js +3614 -0
  52. package/dist/cloudflare.cjs +1048 -0
  53. package/dist/cloudflare.d.cts +1381 -0
  54. package/dist/cloudflare.d.ts +1381 -0
  55. package/dist/cloudflare.js +1017 -0
  56. package/dist/codegen.cjs +259 -18
  57. package/dist/environment-TOTQICSE.js +17 -0
  58. package/dist/environment-TOTQICSE.js.map +1 -0
  59. package/dist/index.cjs +1906 -1493
  60. package/dist/index.d.cts +19 -2
  61. package/dist/index.d.ts +19 -2
  62. package/dist/index.js +1871 -1458
  63. package/dist/node.cjs +4779 -4366
  64. package/dist/node.d.cts +18 -1
  65. package/dist/node.d.ts +18 -1
  66. package/dist/node.js +4602 -4189
  67. package/package.json +41 -12
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/models/relationshipManager.ts","../src/models/ModelRegistry.ts"],"sourcesContent":["import * as Y from \"yjs\";\nimport { DatabaseEngine } from \"../engines/DatabaseEngine\";\nimport { BaseModel, Logger } from \"./BaseModel\";\nimport {\n RefersToRelationshipConfig,\n HasManyRelationshipConfig,\n HasManyThroughRelationshipConfig,\n} from \"../types/relationshipTypes\";\n\n// Helper type for the functions returned by generators\nexport type RelationshipMethod = (\n this: BaseModel,\n ...args: any[]\n) => Promise<any>;\n\nexport function generateRefersToMethod(\n _sourceModelClass: typeof BaseModel,\n config: RefersToRelationshipConfig,\n targetModelClass: typeof BaseModel\n): RelationshipMethod {\n return async function (this: BaseModel) {\n const relatedId = (this as any)[config.relatedIdField];\n if (relatedId === null || typeof relatedId === \"undefined\") return null;\n return (targetModelClass as any).find(relatedId as string);\n };\n}\n\nexport function generateHasManyMethod(\n _sourceModelClass: typeof BaseModel,\n config: HasManyRelationshipConfig,\n targetModelClass: typeof BaseModel,\n _dbEngine: DatabaseEngine\n): RelationshipMethod {\n return async function (\n this: BaseModel,\n paginationArgs?: {\n limit?: number;\n afterCursor?: string;\n beforeCursor?: string;\n direction?: \"forward\" | \"backward\";\n }\n ) {\n const {\n limit,\n afterCursor,\n beforeCursor,\n direction = \"forward\",\n } = paginationArgs || {};\n const {\n relatedIdField,\n orderByField = \"id\",\n orderDirection = \"ASC\",\n } = config;\n\n const targetSchema = (targetModelClass as any).getSchema();\n if (!targetSchema || !targetSchema.options || !targetSchema.options.name) {\n Logger.error(\n `[RelationshipManager] Target model ${targetModelClass.name} for hasMany relationship has no valid schema name.`\n );\n return { data: [], nextCursor: null, prevCursor: null };\n }\n\n // Build document filter\n const filter: any = { [relatedIdField]: this.id };\n\n // Build query options\n const queryOptions: any = {\n sort: { [orderByField]: orderDirection === \"ASC\" ? 1 : -1 },\n };\n\n // Only add limit if specified\n if (limit !== undefined) {\n queryOptions.limit = limit + 1;\n }\n\n // Handle cursor-based pagination\n if (direction === \"forward\" && afterCursor) {\n filter[orderByField] = {\n [orderDirection === \"ASC\" ? \"$gt\" : \"$lt\"]: afterCursor,\n };\n } else if (direction === \"backward\") {\n if (beforeCursor) {\n filter[orderByField] = {\n [orderDirection === \"ASC\" ? \"$lt\" : \"$gt\"]: beforeCursor,\n };\n }\n queryOptions.sort = { [orderByField]: orderDirection === \"ASC\" ? -1 : 1 }; // Reverse sort for backward\n }\n\n const result = await (targetModelClass as any).query(filter, queryOptions);\n const results = result.data;\n\n // Handle cursor generation\n let nextCursor: string | null = null;\n let prevCursor: string | null = null;\n\n // Determine if this is the first page\n const isFirstPage = direction === \"forward\" && !afterCursor;\n\n // Only handle pagination cursors if limit is specified\n if (limit !== undefined) {\n if (direction === \"forward\") {\n if (results.length > limit) {\n nextCursor = (results[limit - 1] as any)[orderByField] as string;\n results.pop();\n }\n // For forward pagination, set prevCursor only if NOT on first page\n if (results.length > 0 && !isFirstPage) {\n prevCursor = (results[0] as any)[orderByField] as string;\n }\n } else {\n // Backward pagination\n if (results.length > limit) {\n prevCursor = (results[limit - 1] as any)[orderByField] as string;\n results.pop();\n }\n results.reverse(); // Reverse results for backward pagination\n\n // For backward pagination, set nextCursor if we have results and started with a cursor\n if (results.length > 0 && beforeCursor) {\n nextCursor = (results[results.length - 1] as any)[\n orderByField\n ] as string;\n }\n\n // For backward pagination, set prevCursor to enable further backward navigation\n // Only set it if we have more results than requested (indicating there are more pages)\n if (results.length > 0 && !beforeCursor) {\n // If this is the first backward call and we got exactly the limit,\n // set prevCursor to the first result to enable getting previous pages\n if (results.length === limit) {\n prevCursor = (results[0] as any)[orderByField] as string;\n }\n }\n }\n }\n\n return { data: results, nextCursor, prevCursor };\n };\n}\n\nexport function generateHasManyThroughMethod(\n _sourceModelClass: typeof BaseModel,\n config: HasManyThroughRelationshipConfig,\n targetModelClass: typeof BaseModel,\n joinModelClass: typeof BaseModel,\n _dbEngine: DatabaseEngine\n): RelationshipMethod {\n return async function (\n this: BaseModel,\n paginationArgs?: {\n limit?: number;\n afterCursor?: string;\n beforeCursor?: string;\n direction?: \"forward\" | \"backward\";\n }\n ) {\n const {\n limit,\n afterCursor,\n beforeCursor,\n direction = \"forward\",\n } = paginationArgs || {};\n\n const joinSchema = (joinModelClass as any).getSchema();\n const targetSchema = (targetModelClass as any).getSchema();\n\n if (!joinSchema || !joinSchema.options || !joinSchema.options.name) {\n Logger.error(\n `[RelationshipManager] Join model ${joinModelClass.name} for hasManyThrough relationship has no valid schema name.`\n );\n return { data: [], nextCursor: null, prevCursor: null };\n }\n if (!targetSchema || !targetSchema.options || !targetSchema.options.name) {\n Logger.error(\n `[RelationshipManager] Target model ${targetModelClass.name} for hasManyThrough relationship has no valid schema name.`\n );\n return { data: [], nextCursor: null, prevCursor: null };\n }\n\n const {\n joinModelLocalField,\n joinModelRelatedField,\n joinModelOrderByField = \"id\",\n joinModelOrderDirection = \"ASC\",\n } = config;\n\n // Build document filter for join query\n const joinFilter: any = { [joinModelLocalField]: this.id };\n\n // Build query options for join query\n const joinQueryOptions: any = {\n sort: {\n [joinModelOrderByField]: joinModelOrderDirection === \"ASC\" ? 1 : -1,\n },\n projection: { [joinModelRelatedField]: 1, [joinModelOrderByField]: 1 },\n };\n\n // Only add limit if specified\n if (limit !== undefined) {\n joinQueryOptions.limit = limit + 1;\n }\n\n // Handle cursor-based pagination\n if (direction === \"forward\" && afterCursor) {\n joinFilter[joinModelOrderByField] = {\n [joinModelOrderDirection === \"ASC\" ? \"$gt\" : \"$lt\"]: afterCursor,\n };\n } else if (direction === \"backward\") {\n if (beforeCursor) {\n joinFilter[joinModelOrderByField] = {\n [joinModelOrderDirection === \"ASC\" ? \"$lt\" : \"$gt\"]: beforeCursor,\n };\n }\n joinQueryOptions.sort = {\n [joinModelOrderByField]: joinModelOrderDirection === \"ASC\" ? -1 : 1,\n }; // Reverse sort for backward\n }\n\n const joinResult = await (joinModelClass as any).query(\n joinFilter,\n joinQueryOptions\n );\n const joinResults = joinResult.data;\n\n let nextCursorFromJoin: string | null = null;\n let prevCursorFromJoin: string | null = null;\n\n // Determine if this is the first page\n const isFirstPage = direction === \"forward\" && !afterCursor;\n\n // Only handle pagination cursors if limit is specified\n if (limit !== undefined) {\n if (direction === \"forward\") {\n if (joinResults.length > limit) {\n nextCursorFromJoin = (joinResults[limit - 1] as any)[\n joinModelOrderByField\n ] as string;\n joinResults.pop();\n }\n // For forward pagination, set prevCursor only if NOT on first page\n if (joinResults.length > 0 && !isFirstPage) {\n prevCursorFromJoin = (joinResults[0] as any)[\n joinModelOrderByField\n ] as string;\n }\n } else {\n // Backward pagination\n if (joinResults.length > limit) {\n prevCursorFromJoin = (joinResults[limit - 1] as any)[\n joinModelOrderByField\n ] as string;\n joinResults.pop();\n }\n joinResults.reverse(); // Reverse results for backward pagination\n\n // For backward pagination, set nextCursor if we have results and started with a cursor\n if (joinResults.length > 0 && beforeCursor) {\n nextCursorFromJoin = (joinResults[joinResults.length - 1] as any)[\n joinModelOrderByField\n ] as string;\n }\n\n // For backward pagination, set prevCursor to enable further backward navigation\n // Only set it if we have more results than requested (indicating there are more pages)\n if (joinResults.length > 0 && !beforeCursor) {\n // If this is the first backward call and we got exactly the limit,\n // set prevCursor to the first result to enable getting previous pages\n if (joinResults.length === limit) {\n prevCursorFromJoin = (joinResults[0] as any)[\n joinModelOrderByField\n ] as string;\n }\n }\n }\n }\n\n const relatedIds = joinResults\n .map((r: any) => r[joinModelRelatedField])\n .filter((id: any): id is string => id != null && typeof id === \"string\");\n if (relatedIds.length === 0)\n return { data: [], nextCursor: null, prevCursor: null };\n\n const targetResult = await (targetModelClass as any).query({\n id: { $in: relatedIds },\n });\n\n return {\n data: targetResult.data,\n nextCursor: nextCursorFromJoin,\n prevCursor: prevCursorFromJoin,\n };\n };\n}\n\nexport function generateHasManyThroughAddMethod(\n _sourceModelClass: typeof BaseModel,\n config: HasManyThroughRelationshipConfig,\n _targetModelClass: typeof BaseModel, // Used to potentially validate the ID/instance passed\n joinModelClass: typeof BaseModel\n): RelationshipMethod {\n return async function (\n this: BaseModel,\n targetInstanceOrId: BaseModel | string\n ): Promise<void> {\n const targetId =\n typeof targetInstanceOrId === \"string\"\n ? targetInstanceOrId\n : targetInstanceOrId.id;\n if (!targetId) {\n Logger.error(\"[RelationshipManager.add] Target ID is missing.\");\n throw new Error(\"Target ID is missing for add operation.\");\n }\n\n const joinData: Record<string, any> = {};\n joinData[config.joinModelLocalField] = this.id;\n joinData[config.joinModelRelatedField] = targetId;\n\n // Get Y.Doc for transaction - prefer from source model's document context\n let yDoc: Y.Doc | null = null;\n let targetDocId: string | null = null;\n\n // Check if source model (this) has multi-document metadata\n const sourceModelConstructor = this.constructor as typeof BaseModel;\n const connectedDocuments = (sourceModelConstructor as any)\n .connectedDocuments;\n if ((this as any)._metaDocId && connectedDocuments) {\n targetDocId = (this as any)._metaDocId;\n if (targetDocId) {\n const documentInfo = connectedDocuments.get(targetDocId);\n if (documentInfo) {\n yDoc = documentInfo.yDoc;\n }\n }\n }\n\n // Fallback to join model's legacy document if multi-document isn't available\n if (!yDoc) {\n const legacyDocId = \"__legacy_default__\";\n const legacyDocInfo = (joinModelClass as any).connectedDocuments?.get(\n legacyDocId\n );\n if (legacyDocInfo) {\n yDoc = legacyDocInfo.yDoc;\n }\n }\n\n if (!yDoc) {\n throw new Error(\n `[${joinModelClass.name}] No Y.Doc is connected for this join model. Connect a document via initJsBao(...).connectDocument or call initializeForDocument(yDoc, db, docId, permissionHint) before managing relationships.`\n );\n }\n\n await yDoc.transact(async () => {\n // Optional: Check if link already exists to prevent duplicates,\n // if the join table doesn't have a unique constraint for the pair.\n // This would require a query.\n const newJoinInstance = new (joinModelClass as any)(joinData);\n // Use targetDocument parameter if we're in multi-document mode\n if (targetDocId) {\n await newJoinInstance.save({ targetDocument: targetDocId });\n } else {\n await newJoinInstance.save(); // Fallback to legacy mode\n }\n Logger.debug(\n `[RelationshipManager.add] Created join entry in ${config.joinModel}:`,\n newJoinInstance.toJSON()\n );\n }, `add-join-${config.joinModel}-${this.id}-${targetId}`);\n };\n}\n\nexport function generateHasManyThroughRemoveMethod(\n _sourceModelClass: typeof BaseModel,\n config: HasManyThroughRelationshipConfig,\n _targetModelClass: typeof BaseModel, // Used to potentially validate the ID/instance passed\n joinModelClass: typeof BaseModel\n): RelationshipMethod {\n return async function (\n this: BaseModel,\n targetInstanceOrId: BaseModel | string\n ): Promise<void> {\n const targetId =\n typeof targetInstanceOrId === \"string\"\n ? targetInstanceOrId\n : targetInstanceOrId.id;\n if (!targetId) {\n Logger.error(\"[RelationshipManager.remove] Target ID is missing.\");\n throw new Error(\"Target ID is missing for remove operation.\");\n }\n\n // Get Y.Doc for transaction - prefer from source model's document context\n let yDoc: Y.Doc | null = null;\n let targetDocId: string | null = null;\n\n // Check if source model (this) has multi-document metadata\n const sourceModelConstructor = this.constructor as typeof BaseModel;\n const connectedDocuments = (sourceModelConstructor as any)\n .connectedDocuments;\n if ((this as any)._metaDocId && connectedDocuments) {\n targetDocId = (this as any)._metaDocId;\n if (targetDocId) {\n const documentInfo = connectedDocuments.get(targetDocId);\n if (documentInfo) {\n yDoc = documentInfo.yDoc;\n }\n }\n }\n\n // Fallback to join model's legacy document if multi-document isn't available\n if (!yDoc) {\n const legacyDocId = \"__legacy_default__\";\n const legacyDocInfo = (joinModelClass as any).connectedDocuments?.get(\n legacyDocId\n );\n if (legacyDocInfo) {\n yDoc = legacyDocInfo.yDoc;\n }\n }\n\n if (!yDoc) {\n throw new Error(\n `[${joinModelClass.name}] No Y.Doc is connected for this join model. Connect a document via initJsBao(...).connectDocument or call initializeForDocument(yDoc, db, docId, permissionHint) before managing relationships.`\n );\n }\n\n await yDoc.transact(async () => {\n const joinRecordsResult = await (joinModelClass as any).query(\n {\n [config.joinModelLocalField]: this.id,\n [config.joinModelRelatedField]: targetId,\n },\n {\n limit: 1,\n projection: { id: 1 },\n }\n );\n\n if (joinRecordsResult.data.length > 0) {\n for (const record of joinRecordsResult.data) {\n // Assuming query returns instances or objects with an id,\n // we need a way to delete by ID or get the instance to call .delete()\n const instanceToDelete = await (joinModelClass as any).find(\n record.id\n );\n if (instanceToDelete) {\n await instanceToDelete.delete();\n Logger.debug(\n `[RelationshipManager.remove] Deleted join entry from ${config.joinModel} with ID: ${record.id}`\n );\n } else {\n Logger.warn(\n `[RelationshipManager.remove] Join entry with ID ${record.id} found by query but not in YMap for deletion.`\n );\n }\n }\n } else {\n Logger.debug(\n `[RelationshipManager.remove] No join entry found in ${config.joinModel} for localId: ${this.id}, relatedId: ${targetId}. No action taken.`\n );\n }\n }, `remove-join-${config.joinModel}-${this.id}-${targetId}`);\n };\n}\n\n// TODO:\n// - Add generateHasManyThroughRemoveMethod\n// These would handle creating/deleting records in the joinModel\n// and should occur within a yDoc.transact() block.\n","import * as Y from \"yjs\";\nimport { DatabaseEngine } from \"../engines/DatabaseEngine\";\nimport { ModelOptions, FieldOptions } from \"../types/ormTypes\";\nimport { BaseModel, Logger } from \"./BaseModel\";\nimport {\n RelationshipConfig,\n RefersToRelationshipConfig,\n HasManyRelationshipConfig,\n HasManyThroughRelationshipConfig,\n} from \"../types/relationshipTypes\";\nimport * as RelationshipManager from \"./relationshipManager\";\nimport { DocumentPermissionHint } from \"../types/documentTypes\";\n\n// Define the structure for stored model information\n// This might be simplified if ModelRegistry primarily deals with classes and options are elsewhere\nexport interface RegisteredModelInfo {\n class: typeof BaseModel;\n options: ModelOptions;\n fields: Map<string, FieldOptions>; // Assuming fields are accessible, e.g. via a static method on the class\n}\n\nexport class ModelRegistry {\n private static instance: ModelRegistry;\n // Stores globally registered model classes by their name (from @Model decorator)\n private models: Map<string, typeof BaseModel> = new Map();\n // Stores options for globally registered models (from @Model decorator)\n private modelOptions: Map<string, ModelOptions> = new Map();\n // Stores fields for globally registered models (from @Model decorator, or a static getter on class)\n // For simplicity, let's assume fields can be derived or are less critical for this registry part\n // private modelFields: Map<string, Map<string, FieldOptions>> = new Map();\n\n // Holds the subset of models explicitly set for the current initialization session\n private activeSessionModels: Map<string, typeof BaseModel> | null = null;\n private dbEngine: DatabaseEngine | null = null; // Store dbEngine for relationship methods\n\n private constructor() {}\n\n public static getInstance(): ModelRegistry {\n if (!ModelRegistry.instance) {\n ModelRegistry.instance = new ModelRegistry();\n }\n return ModelRegistry.instance;\n }\n\n public registerModel(\n modelClass: any,\n options: ModelOptions,\n fields: Map<string, FieldOptions>\n ): void {\n if (!options.name) {\n throw new Error(\n `[ModelRegistry] Model class is missing a name in its @Model options. Ensure the @Model decorator includes a 'name' property.`\n );\n }\n if (this.models.has(options.name)) {\n console.warn(\n `[ModelRegistry] Model \"${options.name}\" is already registered. Overwriting.`\n );\n }\n this.models.set(options.name, modelClass as typeof BaseModel);\n if (fields) {\n BaseModel.attachFieldAccessors(modelClass, fields);\n }\n this.modelOptions.set(options.name, options);\n // this.modelFields.set(options.name, fields); // If storing fields directly\n console.log(\n `[ModelRegistry] Model \"${options.name}\" registered successfully.`\n );\n }\n\n // Gets the class for a globally registered model\n public getModelClass(name: string): typeof BaseModel | undefined {\n return this.models.get(name);\n }\n\n public getModelOptions(name: string): ModelOptions | undefined {\n return this.modelOptions.get(name);\n }\n\n // This method might need to be adapted based on how fields are ultimately managed\n public getModelInfo(modelName: string): RegisteredModelInfo | undefined {\n const modelClass = this.models.get(modelName);\n const options = this.modelOptions.get(modelName);\n if (modelClass && options) {\n // Assuming fields can be accessed from the modelClass, e.g., a static getter\n const fields = (modelClass as any).getSchema\n ? (modelClass as any).getSchema().fields\n : new Map<string, FieldOptions>();\n return { class: modelClass, options, fields };\n }\n return undefined;\n }\n\n public getAllRegisteredModelsInfo(): RegisteredModelInfo[] {\n const infos: RegisteredModelInfo[] = [];\n for (const modelName of this.models.keys()) {\n const info = this.getModelInfo(modelName);\n if (info) {\n infos.push(info);\n }\n }\n return infos;\n }\n\n // Helper to get model name from class (assuming static property from @Model decorator)\n private getModelNameFromClass(\n modelClass: typeof BaseModel\n ): string | undefined {\n // Accessing a static property 'modelName' set by the @Model decorator\n return (modelClass as any).modelName;\n }\n\n public setExplicitModelsForSession(\n modelClasses?: (typeof BaseModel)[]\n ): void {\n if (modelClasses && modelClasses.length > 0) {\n this.activeSessionModels = new Map();\n modelClasses.forEach((modelClass) => {\n const modelName = this.getModelNameFromClass(modelClass);\n if (!modelName) {\n console.warn(\n `[ModelRegistry] A model class provided to setExplicitModelsForSession does not have a static 'modelName' property or it's undefined. It will be ignored. Ensure @Model decorator sets this.`\n );\n return;\n }\n if (\n !this.models.has(modelName) ||\n this.models.get(modelName) !== modelClass\n ) {\n console.warn(\n `[ModelRegistry] Model class with name ${modelName} provided to setExplicitModelsForSession was not found in the global decorator-based registry or does not match. It will be ignored. Ensure the model file is imported and the @Model decorator has run correctly.`\n );\n return;\n }\n // Ensure activeSessionModels is not null before calling set\n if (this.activeSessionModels) {\n this.activeSessionModels.set(modelName, modelClass);\n }\n });\n\n // Defensive check for this.activeSessionModels before accessing .keys()\n let sessionModelNamesMessage =\n \"none (no models were successfully added or session map is null)\";\n if (this.activeSessionModels) {\n const currentSessionModelKeys = Array.from(\n this.activeSessionModels.keys()\n );\n if (currentSessionModelKeys.length > 0) {\n sessionModelNamesMessage = currentSessionModelKeys.join(\", \");\n } else {\n sessionModelNamesMessage =\n \"none (session map initialized but no models added)\";\n }\n }\n Logger.debug(\n `[ModelRegistry] Explicit models set for session: ${sessionModelNamesMessage}`\n );\n } else if (modelClasses && modelClasses.length === 0) {\n // Explicitly an empty array: session should have NO models active\n this.activeSessionModels = new Map();\n Logger.debug(\n \"[ModelRegistry] Explicitly no models for session (empty array passed).\"\n );\n } else {\n // modelClasses is undefined: session should use all globally registered models\n this.activeSessionModels = null;\n console.log(\n \"[ModelRegistry] No explicit models specified for session (undefined), will use all decorator-registered models.\"\n );\n }\n this.validateSessionModels();\n }\n\n public async initializeAll(\n yDoc: Y.Doc,\n dbEngine: DatabaseEngine\n ): Promise<void> {\n Logger.debug(\"[ModelRegistry] Attempting to initialize models...\");\n this.dbEngine = dbEngine; // Store dbEngine instance\n\n const modelsToInitialize = this.activeSessionModels || this.models;\n\n if (modelsToInitialize.size === 0) {\n console.warn(\n \"[ModelRegistry] No models to initialize (either no explicit models set for session or no models globally registered via @Model decorator).\"\n );\n return;\n }\n\n console.log(\n `[ModelRegistry] Initializing models: ${Array.from(\n modelsToInitialize.keys()\n ).join(\", \")}`\n );\n\n for (const [modelName, modelClass] of modelsToInitialize.entries()) {\n if (modelClass && typeof modelClass.initialize === \"function\") {\n Logger.debug(`[ModelRegistry] Initializing model: ${modelName}`);\n await modelClass.initialize(yDoc, dbEngine); // Assumes BaseModel has a static initialize\n } else {\n const staticModelName = (modelClass as any)?.modelName || \"unknown\";\n console.warn(\n `[ModelRegistry] Model ${staticModelName} (class name: ${modelClass?.name}) does not have a static initialize method or class is not defined.`\n );\n }\n }\n Logger.debug(\"[ModelRegistry] Model initialization phase complete.\");\n }\n\n // New method to initialize models for a specific document\n public async initializeAllForDocument(\n yDoc: Y.Doc,\n dbEngine: DatabaseEngine,\n docId: string,\n permissionHint: DocumentPermissionHint\n ): Promise<void> {\n Logger.debug(\n `[ModelRegistry] Initializing models for document ${docId}...`\n );\n this.dbEngine = dbEngine; // Store dbEngine instance\n\n const modelsToInitialize = this.activeSessionModels || this.models;\n\n if (modelsToInitialize.size === 0) {\n Logger.warn(\n \"[ModelRegistry] No models to initialize for document (either no explicit models set for session or no models globally registered via @Model decorator).\"\n );\n return;\n }\n\n Logger.debug(\n `[ModelRegistry] Initializing models for document ${docId}: ${Array.from(\n modelsToInitialize.keys()\n ).join(\", \")}`\n );\n\n for (const [modelName, modelClass] of modelsToInitialize.entries()) {\n if (\n modelClass &&\n typeof modelClass.initializeForDocument === \"function\"\n ) {\n Logger.debug(\n `[ModelRegistry] Initializing model ${modelName} for document ${docId}`\n );\n await modelClass.initializeForDocument(\n yDoc,\n dbEngine,\n docId,\n permissionHint\n );\n } else {\n const staticModelName = (modelClass as any)?.modelName || \"unknown\";\n console.warn(\n `[ModelRegistry] Model ${staticModelName} (class name: ${modelClass?.name}) does not have a static initializeForDocument method or class is not defined.`\n );\n }\n }\n\n // Initialize relationships after all models are set up for this document\n await this.initializeRelationships();\n\n Logger.debug(\n `[ModelRegistry] Model initialization complete for document ${docId}`\n );\n }\n\n // New method to remove data from a disconnected document\n public async removeDocumentData(\n docId: string,\n dbEngine: DatabaseEngine\n ): Promise<void> {\n Logger.debug(`[ModelRegistry] Removing data for document ${docId}...`);\n\n const modelsToCleanup = this.activeSessionModels || this.models;\n\n if (modelsToCleanup.size === 0) {\n console.warn(\n \"[ModelRegistry] No models to cleanup for document (either no explicit models set for session or no models globally registered via @Model decorator).\"\n );\n return;\n }\n\n // Remove from database using _meta_doc_id filter\n for (const [modelName, modelClass] of modelsToCleanup.entries()) {\n try {\n Logger.debug(\n `[ModelRegistry] Removing ${modelName} data for document ${docId}`\n );\n\n // Delete all records with this document ID from the database\n await dbEngine.deleteByDocumentId(modelName, docId);\n\n // Clean up YMap data for this document if the model has the method\n if (\n modelClass &&\n typeof modelClass.cleanupDocumentData === \"function\"\n ) {\n await modelClass.cleanupDocumentData(docId);\n }\n } catch (error) {\n console.error(\n `[ModelRegistry] Error removing ${modelName} data for document ${docId}:`,\n error\n );\n }\n }\n\n Logger.debug(`[ModelRegistry] Data removal complete for document ${docId}`);\n }\n\n // New method to initialize relationships\n public async initializeRelationships(): Promise<void> {\n if (!this.dbEngine) {\n console.error(\n \"[ModelRegistry] DB engine not available for initializing relationships. Ensure initializeAll has been called.\"\n );\n return;\n }\n const dbEngine = this.dbEngine; // Use stored dbEngine\n\n Logger.debug(\n \"[ModelRegistry] Initializing relationships for active models...\"\n );\n const activeModels = this.getActiveModels();\n\n for (const [modelName, modelClass] of activeModels.entries()) {\n const modelSchema = (modelClass as any).getSchema\n ? (modelClass as any).getSchema()\n : null;\n const relationshipsConfig = modelSchema?.options?.relationships as\n | Record<string, RelationshipConfig>\n | undefined;\n\n if (relationshipsConfig) {\n Logger.debug(\n `[ModelRegistry] Setting up relationships for ${modelName}`\n );\n for (const relName in relationshipsConfig) {\n const config = relationshipsConfig[relName];\n // Ensure model and targetModelClass are valid before proceeding\n if (!config.model) {\n throw new Error(\n `[ModelRegistry] Relationship \"${relName}\" on model \"${modelName}\" is missing a target model name.`\n );\n }\n const targetModelClass = this.getModelClass(config.model);\n\n if (!targetModelClass) {\n throw new Error(\n `[ModelRegistry] Relationship \"${relName}\" on model \"${modelName}\" refers to an unknown model \"${config.model}\". Ensure \"${config.model}\" is registered and included in the session.`\n );\n }\n\n // Check if targetModelClass has getSchema method\n if (typeof (targetModelClass as any).getSchema !== \"function\") {\n throw new Error(\n `[ModelRegistry] Target model \"${config.model}\" for relationship \"${relName}\" on \"${modelName}\" does not have a getSchema method.`\n );\n }\n\n switch (config.type) {\n case \"refersTo\":\n Logger.debug(\n ` - Adding '${relName}' (refersTo ${config.model}) to ${modelName}`\n );\n const refersToMethod = RelationshipManager.generateRefersToMethod(\n modelClass,\n config as RefersToRelationshipConfig,\n targetModelClass\n );\n this.addPrototypeMethod(modelClass, relName, refersToMethod);\n break;\n case \"hasMany\":\n Logger.debug(\n ` - Adding '${relName}' (hasMany ${config.model}) to ${modelName}`\n );\n const hasManyMethod = RelationshipManager.generateHasManyMethod(\n modelClass,\n config as HasManyRelationshipConfig,\n targetModelClass,\n dbEngine\n );\n this.addPrototypeMethod(modelClass, relName, hasManyMethod);\n break;\n case \"hasManyThrough\":\n const joinModelName = (config as HasManyThroughRelationshipConfig)\n .joinModel;\n const joinModelClass = this.getModelClass(joinModelName);\n if (!joinModelClass) {\n throw new Error(\n `[ModelRegistry] Join model \"${joinModelName}\" for relationship \"${relName}\" on model \"${modelName}\" not found. Ensure it is registered and included in the session.`\n );\n }\n // Check if joinModelClass has getSchema method\n if (typeof (joinModelClass as any).getSchema !== \"function\") {\n throw new Error(\n `[ModelRegistry] Join model \"${joinModelName}\" for relationship \"${relName}\" on \"${modelName}\" does not have a getSchema method.`\n );\n }\n Logger.debug(\n ` - Adding '${relName}' (hasManyThrough ${config.model} via ${joinModelName}) to ${modelName}`\n );\n const hasManyThroughFetchMethod =\n RelationshipManager.generateHasManyThroughMethod(\n modelClass,\n config as HasManyThroughRelationshipConfig,\n targetModelClass,\n joinModelClass,\n dbEngine\n );\n this.addPrototypeMethod(\n modelClass,\n relName,\n hasManyThroughFetchMethod\n );\n\n // Add helper methods: add<RelNameSingular> and remove<RelNameSingular>\n const relNameSingular = config.model.endsWith(\"s\")\n ? config.model.slice(0, -1)\n : config.model; // Use target model name for singularization logic\n const capitalizedSingularRelName =\n relNameSingular.charAt(0).toUpperCase() +\n relNameSingular.slice(1);\n\n const addMethodName = `add${capitalizedSingularRelName}`;\n const addMethodLogic =\n RelationshipManager.generateHasManyThroughAddMethod(\n modelClass,\n config as HasManyThroughRelationshipConfig,\n targetModelClass,\n joinModelClass\n );\n this.addPrototypeMethod(\n modelClass,\n addMethodName,\n addMethodLogic\n );\n Logger.debug(\n ` - Adding '${addMethodName}' helper to ${modelName} (for relationship ${relName})`\n );\n\n const removeMethodName = `remove${capitalizedSingularRelName}`;\n const removeMethodLogic =\n RelationshipManager.generateHasManyThroughRemoveMethod(\n modelClass,\n config as HasManyThroughRelationshipConfig,\n targetModelClass,\n joinModelClass\n );\n this.addPrototypeMethod(\n modelClass,\n removeMethodName,\n removeMethodLogic\n );\n Logger.debug(\n ` - Adding '${removeMethodName}' helper to ${modelName} (for relationship ${relName})`\n );\n break;\n default:\n console.warn(\n `[ModelRegistry] Unknown relationship type \"${\n (config as any).type\n }\" for ${relName} on ${modelName}. Skipping.`\n );\n }\n }\n }\n }\n Logger.debug(\"[ModelRegistry] Relationship initialization phase complete.\");\n }\n\n // Helper to add methods to prototype\n private addPrototypeMethod(\n modelClass: typeof BaseModel,\n methodName: string,\n methodLogic: Function\n ) {\n Object.defineProperty(modelClass.prototype, methodName, {\n value: methodLogic,\n writable: true,\n enumerable: false, // Keep it clean, like other prototype methods\n configurable: true,\n });\n }\n\n public clearSessionState(): void {\n this.activeSessionModels = null;\n Logger.debug(\n \"[ModelRegistry] Session state cleared (activeSessionModels reset).\"\n );\n }\n\n public getActiveModels(): Map<string, typeof BaseModel> {\n return this.activeSessionModels || this.models;\n }\n private validateSessionModels(): void {\n const activeModels = this.getActiveModels();\n if (!activeModels || activeModels.size === 0) {\n return; // No models to validate\n }\n\n for (const [modelName, modelClass] of activeModels.entries()) {\n const modelSchema = (modelClass as any).getSchema\n ? (modelClass as any).getSchema()\n : null;\n const relationships = modelSchema?.options?.relationships as\n | Record<string, RelationshipConfig>\n | undefined;\n\n if (relationships) {\n for (const relName in relationships) {\n const config = relationships[relName];\n const targetModelName = config.model;\n\n // Check if the target model is active\n if (!activeModels.has(targetModelName)) {\n throw new Error(\n `[ModelRegistry] Validation Error: Model \"${modelName}\" has a relationship \"${relName}\" that refers to model \"${targetModelName}\", but \"${targetModelName}\" is not active in the current session. Please include it in the 'models' array during initialization.`\n );\n }\n\n // If it's a hasManyThrough, also check the join model\n if (config.type === \"hasManyThrough\") {\n const joinModelName = (config as HasManyThroughRelationshipConfig)\n .joinModel;\n if (!activeModels.has(joinModelName)) {\n throw new Error(\n `[ModelRegistry] Validation Error: Model \"${modelName}\" has a relationship \"${relName}\" that uses join model \"${joinModelName}\", but \"${joinModelName}\" is not active in the current session. Please include it in the 'models' array during initialization.`\n );\n }\n }\n }\n }\n }\n }\n}\n"],"mappings":";;;;;;AAeO,SAAS,uBACd,mBACA,QACA,kBACoB;AACpB,SAAO,iBAAiC;AACtC,UAAM,YAAa,KAAa,OAAO,cAAc;AACrD,QAAI,cAAc,QAAQ,OAAO,cAAc,YAAa,QAAO;AACnE,WAAQ,iBAAyB,KAAK,SAAmB;AAAA,EAC3D;AACF;AAEO,SAAS,sBACd,mBACA,QACA,kBACA,WACoB;AACpB,SAAO,eAEL,gBAMA;AACA,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY;AAAA,IACd,IAAI,kBAAkB,CAAC;AACvB,UAAM;AAAA,MACJ;AAAA,MACA,eAAe;AAAA,MACf,iBAAiB;AAAA,IACnB,IAAI;AAEJ,UAAM,eAAgB,iBAAyB,UAAU;AACzD,QAAI,CAAC,gBAAgB,CAAC,aAAa,WAAW,CAAC,aAA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