js-bao 0.3.1 → 0.4.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/dist/browser.cjs +15 -142
- package/dist/browser.d.cts +2 -5
- package/dist/browser.d.ts +2 -5
- package/dist/browser.js +13 -140
- package/dist/codegen.cjs +2 -10
- package/dist/index.cjs +13 -144
- package/dist/index.d.cts +2 -5
- package/dist/index.d.ts +2 -5
- package/dist/index.js +13 -142
- package/dist/node.cjs +16 -145
- package/dist/node.d.cts +2 -5
- package/dist/node.d.ts +2 -5
- package/dist/node.js +13 -140
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1877,7 +1877,7 @@ var init_BaseModel = __esm({
|
|
|
1877
1877
|
getDocumentId() {
|
|
1878
1878
|
return this._metaDocId;
|
|
1879
1879
|
}
|
|
1880
|
-
// id is
|
|
1880
|
+
// id is a plain property. Subclasses define it via defineModelSchema.
|
|
1881
1881
|
id;
|
|
1882
1882
|
type;
|
|
1883
1883
|
// This should be the modelName from ModelOptions
|
|
@@ -2424,7 +2424,7 @@ var init_BaseModel = __esm({
|
|
|
2424
2424
|
const verboseEnabled = Logger.getLogLevel() >= 5 /* VERBOSE */;
|
|
2425
2425
|
if (!schema || !schema.options || !schema.options.name || !schema.resolvedUniqueConstraints) {
|
|
2426
2426
|
throw new Error(
|
|
2427
|
-
`[${this.name}] Model schema is not registered, missing options, or missing resolvedUniqueConstraints. Did you forget to
|
|
2427
|
+
`[${this.name}] Model schema is not registered, missing options, or missing resolvedUniqueConstraints. Did you forget to call attachAndRegisterModel (or autoRegisterModel) for this model?`
|
|
2428
2428
|
);
|
|
2429
2429
|
}
|
|
2430
2430
|
const modelName = schema.options.name;
|
|
@@ -5132,11 +5132,11 @@ var init_ModelRegistry = __esm({
|
|
|
5132
5132
|
init_relationshipManager();
|
|
5133
5133
|
ModelRegistry = class _ModelRegistry {
|
|
5134
5134
|
static instance;
|
|
5135
|
-
// Stores globally registered model classes by their name
|
|
5135
|
+
// Stores globally registered model classes by their name
|
|
5136
5136
|
models = /* @__PURE__ */ new Map();
|
|
5137
|
-
// Stores options for globally registered models
|
|
5137
|
+
// Stores options for globally registered models
|
|
5138
5138
|
modelOptions = /* @__PURE__ */ new Map();
|
|
5139
|
-
// Stores fields for globally registered models (
|
|
5139
|
+
// Stores fields for globally registered models (or a static getter on class)
|
|
5140
5140
|
// For simplicity, let's assume fields can be derived or are less critical for this registry part
|
|
5141
5141
|
// private modelFields: Map<string, Map<string, FieldOptions>> = new Map();
|
|
5142
5142
|
// Holds the subset of models explicitly set for the current initialization session
|
|
@@ -5154,7 +5154,7 @@ var init_ModelRegistry = __esm({
|
|
|
5154
5154
|
registerModel(modelClass, options, fields) {
|
|
5155
5155
|
if (!options.name) {
|
|
5156
5156
|
throw new Error(
|
|
5157
|
-
`[ModelRegistry] Model class is missing a name in its
|
|
5157
|
+
`[ModelRegistry] Model class is missing a name in its options. Ensure the schema passed to defineModelSchema/createModelClass/attachAndRegisterModel includes a 'name' property.`
|
|
5158
5158
|
);
|
|
5159
5159
|
}
|
|
5160
5160
|
if (this.models.has(options.name)) {
|
|
@@ -5198,7 +5198,7 @@ var init_ModelRegistry = __esm({
|
|
|
5198
5198
|
}
|
|
5199
5199
|
return infos;
|
|
5200
5200
|
}
|
|
5201
|
-
// Helper to get model name from class (
|
|
5201
|
+
// Helper to get model name from class (set by attachAndRegisterModel/createModelClass)
|
|
5202
5202
|
getModelNameFromClass(modelClass) {
|
|
5203
5203
|
return modelClass.modelName;
|
|
5204
5204
|
}
|
|
@@ -5209,13 +5209,13 @@ var init_ModelRegistry = __esm({
|
|
|
5209
5209
|
const modelName = this.getModelNameFromClass(modelClass);
|
|
5210
5210
|
if (!modelName) {
|
|
5211
5211
|
console.warn(
|
|
5212
|
-
`[ModelRegistry] A model class provided to setExplicitModelsForSession does not have a static 'modelName' property or it's undefined. It will be ignored. Ensure
|
|
5212
|
+
`[ModelRegistry] A model class provided to setExplicitModelsForSession does not have a static 'modelName' property or it's undefined. It will be ignored. Ensure attachAndRegisterModel (or createModelClass) was called for this model.`
|
|
5213
5213
|
);
|
|
5214
5214
|
return;
|
|
5215
5215
|
}
|
|
5216
5216
|
if (!this.models.has(modelName) || this.models.get(modelName) !== modelClass) {
|
|
5217
5217
|
console.warn(
|
|
5218
|
-
`[ModelRegistry] Model class with name ${modelName} provided to setExplicitModelsForSession was not found in the global
|
|
5218
|
+
`[ModelRegistry] Model class with name ${modelName} provided to setExplicitModelsForSession was not found in the global registry or does not match. It will be ignored. Ensure the model file is imported and attachAndRegisterModel (or createModelClass) has run.`
|
|
5219
5219
|
);
|
|
5220
5220
|
return;
|
|
5221
5221
|
}
|
|
@@ -5245,7 +5245,7 @@ var init_ModelRegistry = __esm({
|
|
|
5245
5245
|
} else {
|
|
5246
5246
|
this.activeSessionModels = null;
|
|
5247
5247
|
console.log(
|
|
5248
|
-
"[ModelRegistry] No explicit models specified for session (undefined), will use all
|
|
5248
|
+
"[ModelRegistry] No explicit models specified for session (undefined), will use all globally registered models."
|
|
5249
5249
|
);
|
|
5250
5250
|
}
|
|
5251
5251
|
this.validateSessionModels();
|
|
@@ -5256,7 +5256,7 @@ var init_ModelRegistry = __esm({
|
|
|
5256
5256
|
const modelsToInitialize = this.activeSessionModels || this.models;
|
|
5257
5257
|
if (modelsToInitialize.size === 0) {
|
|
5258
5258
|
console.warn(
|
|
5259
|
-
"[ModelRegistry] No models to initialize (either no explicit models set for session or no models globally registered via
|
|
5259
|
+
"[ModelRegistry] No models to initialize (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
|
|
5260
5260
|
);
|
|
5261
5261
|
return;
|
|
5262
5262
|
}
|
|
@@ -5287,7 +5287,7 @@ var init_ModelRegistry = __esm({
|
|
|
5287
5287
|
const modelsToInitialize = this.activeSessionModels || this.models;
|
|
5288
5288
|
if (modelsToInitialize.size === 0) {
|
|
5289
5289
|
Logger.warn(
|
|
5290
|
-
"[ModelRegistry] No models to initialize for document (either no explicit models set for session or no models globally registered via
|
|
5290
|
+
"[ModelRegistry] No models to initialize for document (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
|
|
5291
5291
|
);
|
|
5292
5292
|
return;
|
|
5293
5293
|
}
|
|
@@ -5325,7 +5325,7 @@ var init_ModelRegistry = __esm({
|
|
|
5325
5325
|
const modelsToCleanup = this.activeSessionModels || this.models;
|
|
5326
5326
|
if (modelsToCleanup.size === 0) {
|
|
5327
5327
|
console.warn(
|
|
5328
|
-
"[ModelRegistry] No models to cleanup for document (either no explicit models set for session or no models globally registered via
|
|
5328
|
+
"[ModelRegistry] No models to cleanup for document (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
|
|
5329
5329
|
);
|
|
5330
5330
|
return;
|
|
5331
5331
|
}
|
|
@@ -6649,10 +6649,8 @@ __export(index_exports, {
|
|
|
6649
6649
|
DatabaseEngine: () => DatabaseEngine,
|
|
6650
6650
|
DocumentClosedError: () => DocumentClosedError,
|
|
6651
6651
|
DocumentResolutionError: () => DocumentResolutionError,
|
|
6652
|
-
Field: () => Field,
|
|
6653
6652
|
LogLevel: () => LogLevel,
|
|
6654
6653
|
Logger: () => Logger,
|
|
6655
|
-
Model: () => Model,
|
|
6656
6654
|
ModelRegistry: () => ModelRegistry,
|
|
6657
6655
|
RecordNotFoundError: () => RecordNotFoundError,
|
|
6658
6656
|
StringSet: () => StringSet,
|
|
@@ -6894,133 +6892,6 @@ async function resetJsBao() {
|
|
|
6894
6892
|
// src/index.ts
|
|
6895
6893
|
init_documentTypes();
|
|
6896
6894
|
init_BaseModel();
|
|
6897
|
-
|
|
6898
|
-
// src/models/decorators.ts
|
|
6899
|
-
init_ModelRegistry();
|
|
6900
|
-
init_BaseModel();
|
|
6901
|
-
init_sql();
|
|
6902
|
-
var SCHEMA_FIELDS_PROPERTY = "_jsbaoSchemaFields";
|
|
6903
|
-
function Field(options) {
|
|
6904
|
-
return function(target, propertyKey) {
|
|
6905
|
-
const fieldName = String(propertyKey);
|
|
6906
|
-
const modelConstructor = target.constructor || target;
|
|
6907
|
-
assertValidIdentifier(
|
|
6908
|
-
fieldName,
|
|
6909
|
-
`[Field Decorator] Invalid field name on ${modelConstructor?.name || "unknown"}`
|
|
6910
|
-
);
|
|
6911
|
-
if (!modelConstructor) {
|
|
6912
|
-
console.error(
|
|
6913
|
-
"[Field Decorator] Could not determine model constructor for field:",
|
|
6914
|
-
fieldName,
|
|
6915
|
-
"Target:",
|
|
6916
|
-
target
|
|
6917
|
-
);
|
|
6918
|
-
throw new Error(
|
|
6919
|
-
`Failed to resolve model constructor for field '${fieldName}'.`
|
|
6920
|
-
);
|
|
6921
|
-
}
|
|
6922
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
6923
|
-
modelConstructor,
|
|
6924
|
-
SCHEMA_FIELDS_PROPERTY
|
|
6925
|
-
)) {
|
|
6926
|
-
modelConstructor[SCHEMA_FIELDS_PROPERTY] = /* @__PURE__ */ new Map();
|
|
6927
|
-
}
|
|
6928
|
-
modelConstructor[SCHEMA_FIELDS_PROPERTY].set(
|
|
6929
|
-
fieldName,
|
|
6930
|
-
options
|
|
6931
|
-
);
|
|
6932
|
-
Logger.debug(
|
|
6933
|
-
`[Field Decorator] Staged field "${fieldName}" for class ${modelConstructor.name}:`,
|
|
6934
|
-
options
|
|
6935
|
-
);
|
|
6936
|
-
};
|
|
6937
|
-
}
|
|
6938
|
-
function Model(options) {
|
|
6939
|
-
return function(targetClass) {
|
|
6940
|
-
Logger.debug(
|
|
6941
|
-
`[Model Decorator] Registering model:`,
|
|
6942
|
-
targetClass.name,
|
|
6943
|
-
options
|
|
6944
|
-
);
|
|
6945
|
-
assertValidIdentifier(
|
|
6946
|
-
options.name,
|
|
6947
|
-
`[Model Decorator] Invalid model name for ${targetClass.name}`
|
|
6948
|
-
);
|
|
6949
|
-
const registry = ModelRegistry.getInstance();
|
|
6950
|
-
targetClass.modelName = options.name;
|
|
6951
|
-
targetClass.getSchema = () => {
|
|
6952
|
-
const combinedFields = /* @__PURE__ */ new Map();
|
|
6953
|
-
const hierarchyStack = [];
|
|
6954
|
-
let currentEvalClass = targetClass;
|
|
6955
|
-
while (currentEvalClass && currentEvalClass.prototype) {
|
|
6956
|
-
hierarchyStack.push(currentEvalClass);
|
|
6957
|
-
const parentPrototype = Object.getPrototypeOf(
|
|
6958
|
-
currentEvalClass.prototype
|
|
6959
|
-
);
|
|
6960
|
-
currentEvalClass = parentPrototype ? parentPrototype.constructor : null;
|
|
6961
|
-
if (currentEvalClass === Object) break;
|
|
6962
|
-
}
|
|
6963
|
-
for (let i = hierarchyStack.length - 1; i >= 0; i--) {
|
|
6964
|
-
const cls = hierarchyStack[i];
|
|
6965
|
-
if (Object.prototype.hasOwnProperty.call(cls, SCHEMA_FIELDS_PROPERTY)) {
|
|
6966
|
-
const fieldsForClass = cls[SCHEMA_FIELDS_PROPERTY];
|
|
6967
|
-
fieldsForClass.forEach((fieldOpts, fieldName) => {
|
|
6968
|
-
combinedFields.set(fieldName, fieldOpts);
|
|
6969
|
-
});
|
|
6970
|
-
}
|
|
6971
|
-
}
|
|
6972
|
-
const resolvedUniqueConstraints = [];
|
|
6973
|
-
combinedFields.forEach((fieldOpts, fieldName) => {
|
|
6974
|
-
if (fieldOpts.unique) {
|
|
6975
|
-
const constraintName = `${options.name}_${fieldName}_unique`;
|
|
6976
|
-
resolvedUniqueConstraints.push({
|
|
6977
|
-
name: constraintName,
|
|
6978
|
-
fields: [fieldName]
|
|
6979
|
-
});
|
|
6980
|
-
}
|
|
6981
|
-
});
|
|
6982
|
-
if (options.uniqueConstraints) {
|
|
6983
|
-
options.uniqueConstraints.forEach(
|
|
6984
|
-
(constraintConfig) => {
|
|
6985
|
-
const allFieldsExist = constraintConfig.fields.every(
|
|
6986
|
-
(f) => combinedFields.has(f)
|
|
6987
|
-
);
|
|
6988
|
-
if (!allFieldsExist) {
|
|
6989
|
-
console.warn(
|
|
6990
|
-
`[Model Decorator] Unique constraint "${constraintConfig.name}" for model "${options.name}" specifies non-existent fields. Skipping.`
|
|
6991
|
-
);
|
|
6992
|
-
return;
|
|
6993
|
-
}
|
|
6994
|
-
if (resolvedUniqueConstraints.some(
|
|
6995
|
-
(rc) => rc.name === constraintConfig.name
|
|
6996
|
-
)) {
|
|
6997
|
-
console.warn(
|
|
6998
|
-
`[Model Decorator] Duplicate unique constraint name "${constraintConfig.name}" in model "${options.name}".`
|
|
6999
|
-
);
|
|
7000
|
-
}
|
|
7001
|
-
resolvedUniqueConstraints.push({
|
|
7002
|
-
name: constraintConfig.name,
|
|
7003
|
-
fields: constraintConfig.fields
|
|
7004
|
-
});
|
|
7005
|
-
}
|
|
7006
|
-
);
|
|
7007
|
-
}
|
|
7008
|
-
return {
|
|
7009
|
-
class: targetClass,
|
|
7010
|
-
options,
|
|
7011
|
-
fields: combinedFields,
|
|
7012
|
-
resolvedUniqueConstraints
|
|
7013
|
-
};
|
|
7014
|
-
};
|
|
7015
|
-
const directFieldsForThisClass = Object.prototype.hasOwnProperty.call(
|
|
7016
|
-
targetClass,
|
|
7017
|
-
SCHEMA_FIELDS_PROPERTY
|
|
7018
|
-
) ? targetClass[SCHEMA_FIELDS_PROPERTY] : /* @__PURE__ */ new Map();
|
|
7019
|
-
registry.registerModel(targetClass, options, directFieldsForThisClass);
|
|
7020
|
-
};
|
|
7021
|
-
}
|
|
7022
|
-
|
|
7023
|
-
// src/index.ts
|
|
7024
6895
|
init_StringSet();
|
|
7025
6896
|
|
|
7026
6897
|
// src/models/schema.ts
|
|
@@ -7593,10 +7464,8 @@ function summarizePlainYDoc(dump) {
|
|
|
7593
7464
|
DatabaseEngine,
|
|
7594
7465
|
DocumentClosedError,
|
|
7595
7466
|
DocumentResolutionError,
|
|
7596
|
-
Field,
|
|
7597
7467
|
LogLevel,
|
|
7598
7468
|
Logger,
|
|
7599
|
-
Model,
|
|
7600
7469
|
ModelRegistry,
|
|
7601
7470
|
RecordNotFoundError,
|
|
7602
7471
|
StringSet,
|
package/dist/index.d.cts
CHANGED
|
@@ -702,7 +702,7 @@ interface InitJsBaoOptions {
|
|
|
702
702
|
/**
|
|
703
703
|
* Optional array of model classes to initialize.
|
|
704
704
|
* If not provided, the ORM will rely on models being registered
|
|
705
|
-
* via
|
|
705
|
+
* via attachAndRegisterModel (assuming they have been imported by the application).
|
|
706
706
|
*/
|
|
707
707
|
models?: (typeof BaseModel)[];
|
|
708
708
|
}
|
|
@@ -742,9 +742,6 @@ declare function initJsBao(options: InitJsBaoOptions): Promise<InitJsBaoResult>;
|
|
|
742
742
|
*/
|
|
743
743
|
declare function resetJsBao(): Promise<void>;
|
|
744
744
|
|
|
745
|
-
declare function Field(options: FieldOptions): (target: any, propertyKey: string | symbol) => void;
|
|
746
|
-
declare function Model(options: ModelOptions): (targetClass: Function) => void;
|
|
747
|
-
|
|
748
745
|
interface ResolvedUniqueConstraint {
|
|
749
746
|
name: string;
|
|
750
747
|
fields: string[];
|
|
@@ -956,4 +953,4 @@ declare function dumpYDocToPlain(yDoc: Y.Doc, options?: DumpOptions): PlainYDoc;
|
|
|
956
953
|
*/
|
|
957
954
|
declare function summarizePlainYDoc(dump: PlainYDoc): DumpSummary;
|
|
958
955
|
|
|
959
|
-
export { BaseModel, type ConnectedDocument, type DatabaseConfig, DatabaseEngine, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, DocumentClosedError, type DocumentConnectionCallback, type DocumentConnectionEvent, type DocumentFilter, type DocumentManager, type DocumentPermissionHint, DocumentResolutionError, type DumpOptions, type DumpSummary, type DumpSummaryEntry,
|
|
956
|
+
export { BaseModel, type ConnectedDocument, type DatabaseConfig, DatabaseEngine, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, DocumentClosedError, type DocumentConnectionCallback, type DocumentConnectionEvent, type DocumentFilter, type DocumentManager, type DocumentPermissionHint, DocumentResolutionError, type DumpOptions, type DumpSummary, type DumpSummaryEntry, type FieldOptions, type IncludeSpec, type InferAttrs, type InitJsBaoOptions, type InitJsBaoResult, LogLevel, Logger, type ModelConstructor, type ModelOptions, ModelRegistry, type PaginatedResult, type PaginationOptions, type PlainYDoc, type ProjectionSpec, type QueryOptions, type QueryResult, RecordNotFoundError, type SaveOptions, StringSet, UniqueConstraintViolationError, attachAndRegisterModel, attachSchemaToClass, autoRegisterModel, clearMetaSyncCache, createModelClass, defineModelSchema, discoverModelNames, discoverSchema, dumpYDocToPlain, generateULID, inferFieldType, initJsBao, loadSchemaFromToml, loadSchemaFromTomlString, registerFunctionDefault, resetJsBao, schemaToToml, summarizePlainYDoc, syncInferredMeta, syncModelMeta };
|
package/dist/index.d.ts
CHANGED
|
@@ -702,7 +702,7 @@ interface InitJsBaoOptions {
|
|
|
702
702
|
/**
|
|
703
703
|
* Optional array of model classes to initialize.
|
|
704
704
|
* If not provided, the ORM will rely on models being registered
|
|
705
|
-
* via
|
|
705
|
+
* via attachAndRegisterModel (assuming they have been imported by the application).
|
|
706
706
|
*/
|
|
707
707
|
models?: (typeof BaseModel)[];
|
|
708
708
|
}
|
|
@@ -742,9 +742,6 @@ declare function initJsBao(options: InitJsBaoOptions): Promise<InitJsBaoResult>;
|
|
|
742
742
|
*/
|
|
743
743
|
declare function resetJsBao(): Promise<void>;
|
|
744
744
|
|
|
745
|
-
declare function Field(options: FieldOptions): (target: any, propertyKey: string | symbol) => void;
|
|
746
|
-
declare function Model(options: ModelOptions): (targetClass: Function) => void;
|
|
747
|
-
|
|
748
745
|
interface ResolvedUniqueConstraint {
|
|
749
746
|
name: string;
|
|
750
747
|
fields: string[];
|
|
@@ -956,4 +953,4 @@ declare function dumpYDocToPlain(yDoc: Y.Doc, options?: DumpOptions): PlainYDoc;
|
|
|
956
953
|
*/
|
|
957
954
|
declare function summarizePlainYDoc(dump: PlainYDoc): DumpSummary;
|
|
958
955
|
|
|
959
|
-
export { BaseModel, type ConnectedDocument, type DatabaseConfig, DatabaseEngine, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, DocumentClosedError, type DocumentConnectionCallback, type DocumentConnectionEvent, type DocumentFilter, type DocumentManager, type DocumentPermissionHint, DocumentResolutionError, type DumpOptions, type DumpSummary, type DumpSummaryEntry,
|
|
956
|
+
export { BaseModel, type ConnectedDocument, type DatabaseConfig, DatabaseEngine, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, DocumentClosedError, type DocumentConnectionCallback, type DocumentConnectionEvent, type DocumentFilter, type DocumentManager, type DocumentPermissionHint, DocumentResolutionError, type DumpOptions, type DumpSummary, type DumpSummaryEntry, type FieldOptions, type IncludeSpec, type InferAttrs, type InitJsBaoOptions, type InitJsBaoResult, LogLevel, Logger, type ModelConstructor, type ModelOptions, ModelRegistry, type PaginatedResult, type PaginationOptions, type PlainYDoc, type ProjectionSpec, type QueryOptions, type QueryResult, RecordNotFoundError, type SaveOptions, StringSet, UniqueConstraintViolationError, attachAndRegisterModel, attachSchemaToClass, autoRegisterModel, clearMetaSyncCache, createModelClass, defineModelSchema, discoverModelNames, discoverSchema, dumpYDocToPlain, generateULID, inferFieldType, initJsBao, loadSchemaFromToml, loadSchemaFromTomlString, registerFunctionDefault, resetJsBao, schemaToToml, summarizePlainYDoc, syncInferredMeta, syncModelMeta };
|
package/dist/index.js
CHANGED
|
@@ -1855,7 +1855,7 @@ var init_BaseModel = __esm({
|
|
|
1855
1855
|
getDocumentId() {
|
|
1856
1856
|
return this._metaDocId;
|
|
1857
1857
|
}
|
|
1858
|
-
// id is
|
|
1858
|
+
// id is a plain property. Subclasses define it via defineModelSchema.
|
|
1859
1859
|
id;
|
|
1860
1860
|
type;
|
|
1861
1861
|
// This should be the modelName from ModelOptions
|
|
@@ -2402,7 +2402,7 @@ var init_BaseModel = __esm({
|
|
|
2402
2402
|
const verboseEnabled = Logger.getLogLevel() >= 5 /* VERBOSE */;
|
|
2403
2403
|
if (!schema || !schema.options || !schema.options.name || !schema.resolvedUniqueConstraints) {
|
|
2404
2404
|
throw new Error(
|
|
2405
|
-
`[${this.name}] Model schema is not registered, missing options, or missing resolvedUniqueConstraints. Did you forget to
|
|
2405
|
+
`[${this.name}] Model schema is not registered, missing options, or missing resolvedUniqueConstraints. Did you forget to call attachAndRegisterModel (or autoRegisterModel) for this model?`
|
|
2406
2406
|
);
|
|
2407
2407
|
}
|
|
2408
2408
|
const modelName = schema.options.name;
|
|
@@ -5110,11 +5110,11 @@ var init_ModelRegistry = __esm({
|
|
|
5110
5110
|
init_relationshipManager();
|
|
5111
5111
|
ModelRegistry = class _ModelRegistry {
|
|
5112
5112
|
static instance;
|
|
5113
|
-
// Stores globally registered model classes by their name
|
|
5113
|
+
// Stores globally registered model classes by their name
|
|
5114
5114
|
models = /* @__PURE__ */ new Map();
|
|
5115
|
-
// Stores options for globally registered models
|
|
5115
|
+
// Stores options for globally registered models
|
|
5116
5116
|
modelOptions = /* @__PURE__ */ new Map();
|
|
5117
|
-
// Stores fields for globally registered models (
|
|
5117
|
+
// Stores fields for globally registered models (or a static getter on class)
|
|
5118
5118
|
// For simplicity, let's assume fields can be derived or are less critical for this registry part
|
|
5119
5119
|
// private modelFields: Map<string, Map<string, FieldOptions>> = new Map();
|
|
5120
5120
|
// Holds the subset of models explicitly set for the current initialization session
|
|
@@ -5132,7 +5132,7 @@ var init_ModelRegistry = __esm({
|
|
|
5132
5132
|
registerModel(modelClass, options, fields) {
|
|
5133
5133
|
if (!options.name) {
|
|
5134
5134
|
throw new Error(
|
|
5135
|
-
`[ModelRegistry] Model class is missing a name in its
|
|
5135
|
+
`[ModelRegistry] Model class is missing a name in its options. Ensure the schema passed to defineModelSchema/createModelClass/attachAndRegisterModel includes a 'name' property.`
|
|
5136
5136
|
);
|
|
5137
5137
|
}
|
|
5138
5138
|
if (this.models.has(options.name)) {
|
|
@@ -5176,7 +5176,7 @@ var init_ModelRegistry = __esm({
|
|
|
5176
5176
|
}
|
|
5177
5177
|
return infos;
|
|
5178
5178
|
}
|
|
5179
|
-
// Helper to get model name from class (
|
|
5179
|
+
// Helper to get model name from class (set by attachAndRegisterModel/createModelClass)
|
|
5180
5180
|
getModelNameFromClass(modelClass) {
|
|
5181
5181
|
return modelClass.modelName;
|
|
5182
5182
|
}
|
|
@@ -5187,13 +5187,13 @@ var init_ModelRegistry = __esm({
|
|
|
5187
5187
|
const modelName = this.getModelNameFromClass(modelClass);
|
|
5188
5188
|
if (!modelName) {
|
|
5189
5189
|
console.warn(
|
|
5190
|
-
`[ModelRegistry] A model class provided to setExplicitModelsForSession does not have a static 'modelName' property or it's undefined. It will be ignored. Ensure
|
|
5190
|
+
`[ModelRegistry] A model class provided to setExplicitModelsForSession does not have a static 'modelName' property or it's undefined. It will be ignored. Ensure attachAndRegisterModel (or createModelClass) was called for this model.`
|
|
5191
5191
|
);
|
|
5192
5192
|
return;
|
|
5193
5193
|
}
|
|
5194
5194
|
if (!this.models.has(modelName) || this.models.get(modelName) !== modelClass) {
|
|
5195
5195
|
console.warn(
|
|
5196
|
-
`[ModelRegistry] Model class with name ${modelName} provided to setExplicitModelsForSession was not found in the global
|
|
5196
|
+
`[ModelRegistry] Model class with name ${modelName} provided to setExplicitModelsForSession was not found in the global registry or does not match. It will be ignored. Ensure the model file is imported and attachAndRegisterModel (or createModelClass) has run.`
|
|
5197
5197
|
);
|
|
5198
5198
|
return;
|
|
5199
5199
|
}
|
|
@@ -5223,7 +5223,7 @@ var init_ModelRegistry = __esm({
|
|
|
5223
5223
|
} else {
|
|
5224
5224
|
this.activeSessionModels = null;
|
|
5225
5225
|
console.log(
|
|
5226
|
-
"[ModelRegistry] No explicit models specified for session (undefined), will use all
|
|
5226
|
+
"[ModelRegistry] No explicit models specified for session (undefined), will use all globally registered models."
|
|
5227
5227
|
);
|
|
5228
5228
|
}
|
|
5229
5229
|
this.validateSessionModels();
|
|
@@ -5234,7 +5234,7 @@ var init_ModelRegistry = __esm({
|
|
|
5234
5234
|
const modelsToInitialize = this.activeSessionModels || this.models;
|
|
5235
5235
|
if (modelsToInitialize.size === 0) {
|
|
5236
5236
|
console.warn(
|
|
5237
|
-
"[ModelRegistry] No models to initialize (either no explicit models set for session or no models globally registered via
|
|
5237
|
+
"[ModelRegistry] No models to initialize (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
|
|
5238
5238
|
);
|
|
5239
5239
|
return;
|
|
5240
5240
|
}
|
|
@@ -5265,7 +5265,7 @@ var init_ModelRegistry = __esm({
|
|
|
5265
5265
|
const modelsToInitialize = this.activeSessionModels || this.models;
|
|
5266
5266
|
if (modelsToInitialize.size === 0) {
|
|
5267
5267
|
Logger.warn(
|
|
5268
|
-
"[ModelRegistry] No models to initialize for document (either no explicit models set for session or no models globally registered via
|
|
5268
|
+
"[ModelRegistry] No models to initialize for document (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
|
|
5269
5269
|
);
|
|
5270
5270
|
return;
|
|
5271
5271
|
}
|
|
@@ -5303,7 +5303,7 @@ var init_ModelRegistry = __esm({
|
|
|
5303
5303
|
const modelsToCleanup = this.activeSessionModels || this.models;
|
|
5304
5304
|
if (modelsToCleanup.size === 0) {
|
|
5305
5305
|
console.warn(
|
|
5306
|
-
"[ModelRegistry] No models to cleanup for document (either no explicit models set for session or no models globally registered via
|
|
5306
|
+
"[ModelRegistry] No models to cleanup for document (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
|
|
5307
5307
|
);
|
|
5308
5308
|
return;
|
|
5309
5309
|
}
|
|
@@ -6834,133 +6834,6 @@ async function resetJsBao() {
|
|
|
6834
6834
|
// src/index.ts
|
|
6835
6835
|
init_documentTypes();
|
|
6836
6836
|
init_BaseModel();
|
|
6837
|
-
|
|
6838
|
-
// src/models/decorators.ts
|
|
6839
|
-
init_ModelRegistry();
|
|
6840
|
-
init_BaseModel();
|
|
6841
|
-
init_sql();
|
|
6842
|
-
var SCHEMA_FIELDS_PROPERTY = "_jsbaoSchemaFields";
|
|
6843
|
-
function Field(options) {
|
|
6844
|
-
return function(target, propertyKey) {
|
|
6845
|
-
const fieldName = String(propertyKey);
|
|
6846
|
-
const modelConstructor = target.constructor || target;
|
|
6847
|
-
assertValidIdentifier(
|
|
6848
|
-
fieldName,
|
|
6849
|
-
`[Field Decorator] Invalid field name on ${modelConstructor?.name || "unknown"}`
|
|
6850
|
-
);
|
|
6851
|
-
if (!modelConstructor) {
|
|
6852
|
-
console.error(
|
|
6853
|
-
"[Field Decorator] Could not determine model constructor for field:",
|
|
6854
|
-
fieldName,
|
|
6855
|
-
"Target:",
|
|
6856
|
-
target
|
|
6857
|
-
);
|
|
6858
|
-
throw new Error(
|
|
6859
|
-
`Failed to resolve model constructor for field '${fieldName}'.`
|
|
6860
|
-
);
|
|
6861
|
-
}
|
|
6862
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
6863
|
-
modelConstructor,
|
|
6864
|
-
SCHEMA_FIELDS_PROPERTY
|
|
6865
|
-
)) {
|
|
6866
|
-
modelConstructor[SCHEMA_FIELDS_PROPERTY] = /* @__PURE__ */ new Map();
|
|
6867
|
-
}
|
|
6868
|
-
modelConstructor[SCHEMA_FIELDS_PROPERTY].set(
|
|
6869
|
-
fieldName,
|
|
6870
|
-
options
|
|
6871
|
-
);
|
|
6872
|
-
Logger.debug(
|
|
6873
|
-
`[Field Decorator] Staged field "${fieldName}" for class ${modelConstructor.name}:`,
|
|
6874
|
-
options
|
|
6875
|
-
);
|
|
6876
|
-
};
|
|
6877
|
-
}
|
|
6878
|
-
function Model(options) {
|
|
6879
|
-
return function(targetClass) {
|
|
6880
|
-
Logger.debug(
|
|
6881
|
-
`[Model Decorator] Registering model:`,
|
|
6882
|
-
targetClass.name,
|
|
6883
|
-
options
|
|
6884
|
-
);
|
|
6885
|
-
assertValidIdentifier(
|
|
6886
|
-
options.name,
|
|
6887
|
-
`[Model Decorator] Invalid model name for ${targetClass.name}`
|
|
6888
|
-
);
|
|
6889
|
-
const registry = ModelRegistry.getInstance();
|
|
6890
|
-
targetClass.modelName = options.name;
|
|
6891
|
-
targetClass.getSchema = () => {
|
|
6892
|
-
const combinedFields = /* @__PURE__ */ new Map();
|
|
6893
|
-
const hierarchyStack = [];
|
|
6894
|
-
let currentEvalClass = targetClass;
|
|
6895
|
-
while (currentEvalClass && currentEvalClass.prototype) {
|
|
6896
|
-
hierarchyStack.push(currentEvalClass);
|
|
6897
|
-
const parentPrototype = Object.getPrototypeOf(
|
|
6898
|
-
currentEvalClass.prototype
|
|
6899
|
-
);
|
|
6900
|
-
currentEvalClass = parentPrototype ? parentPrototype.constructor : null;
|
|
6901
|
-
if (currentEvalClass === Object) break;
|
|
6902
|
-
}
|
|
6903
|
-
for (let i = hierarchyStack.length - 1; i >= 0; i--) {
|
|
6904
|
-
const cls = hierarchyStack[i];
|
|
6905
|
-
if (Object.prototype.hasOwnProperty.call(cls, SCHEMA_FIELDS_PROPERTY)) {
|
|
6906
|
-
const fieldsForClass = cls[SCHEMA_FIELDS_PROPERTY];
|
|
6907
|
-
fieldsForClass.forEach((fieldOpts, fieldName) => {
|
|
6908
|
-
combinedFields.set(fieldName, fieldOpts);
|
|
6909
|
-
});
|
|
6910
|
-
}
|
|
6911
|
-
}
|
|
6912
|
-
const resolvedUniqueConstraints = [];
|
|
6913
|
-
combinedFields.forEach((fieldOpts, fieldName) => {
|
|
6914
|
-
if (fieldOpts.unique) {
|
|
6915
|
-
const constraintName = `${options.name}_${fieldName}_unique`;
|
|
6916
|
-
resolvedUniqueConstraints.push({
|
|
6917
|
-
name: constraintName,
|
|
6918
|
-
fields: [fieldName]
|
|
6919
|
-
});
|
|
6920
|
-
}
|
|
6921
|
-
});
|
|
6922
|
-
if (options.uniqueConstraints) {
|
|
6923
|
-
options.uniqueConstraints.forEach(
|
|
6924
|
-
(constraintConfig) => {
|
|
6925
|
-
const allFieldsExist = constraintConfig.fields.every(
|
|
6926
|
-
(f) => combinedFields.has(f)
|
|
6927
|
-
);
|
|
6928
|
-
if (!allFieldsExist) {
|
|
6929
|
-
console.warn(
|
|
6930
|
-
`[Model Decorator] Unique constraint "${constraintConfig.name}" for model "${options.name}" specifies non-existent fields. Skipping.`
|
|
6931
|
-
);
|
|
6932
|
-
return;
|
|
6933
|
-
}
|
|
6934
|
-
if (resolvedUniqueConstraints.some(
|
|
6935
|
-
(rc) => rc.name === constraintConfig.name
|
|
6936
|
-
)) {
|
|
6937
|
-
console.warn(
|
|
6938
|
-
`[Model Decorator] Duplicate unique constraint name "${constraintConfig.name}" in model "${options.name}".`
|
|
6939
|
-
);
|
|
6940
|
-
}
|
|
6941
|
-
resolvedUniqueConstraints.push({
|
|
6942
|
-
name: constraintConfig.name,
|
|
6943
|
-
fields: constraintConfig.fields
|
|
6944
|
-
});
|
|
6945
|
-
}
|
|
6946
|
-
);
|
|
6947
|
-
}
|
|
6948
|
-
return {
|
|
6949
|
-
class: targetClass,
|
|
6950
|
-
options,
|
|
6951
|
-
fields: combinedFields,
|
|
6952
|
-
resolvedUniqueConstraints
|
|
6953
|
-
};
|
|
6954
|
-
};
|
|
6955
|
-
const directFieldsForThisClass = Object.prototype.hasOwnProperty.call(
|
|
6956
|
-
targetClass,
|
|
6957
|
-
SCHEMA_FIELDS_PROPERTY
|
|
6958
|
-
) ? targetClass[SCHEMA_FIELDS_PROPERTY] : /* @__PURE__ */ new Map();
|
|
6959
|
-
registry.registerModel(targetClass, options, directFieldsForThisClass);
|
|
6960
|
-
};
|
|
6961
|
-
}
|
|
6962
|
-
|
|
6963
|
-
// src/index.ts
|
|
6964
6837
|
init_StringSet();
|
|
6965
6838
|
|
|
6966
6839
|
// src/models/schema.ts
|
|
@@ -7532,10 +7405,8 @@ export {
|
|
|
7532
7405
|
DatabaseEngine,
|
|
7533
7406
|
DocumentClosedError,
|
|
7534
7407
|
DocumentResolutionError,
|
|
7535
|
-
Field,
|
|
7536
7408
|
LogLevel,
|
|
7537
7409
|
Logger,
|
|
7538
|
-
Model,
|
|
7539
7410
|
ModelRegistry,
|
|
7540
7411
|
RecordNotFoundError,
|
|
7541
7412
|
StringSet,
|