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/node.cjs CHANGED
@@ -1634,11 +1634,11 @@ var init_ModelRegistry = __esm({
1634
1634
  init_relationshipManager();
1635
1635
  ModelRegistry = class _ModelRegistry {
1636
1636
  static instance;
1637
- // Stores globally registered model classes by their name (from @Model decorator)
1637
+ // Stores globally registered model classes by their name
1638
1638
  models = /* @__PURE__ */ new Map();
1639
- // Stores options for globally registered models (from @Model decorator)
1639
+ // Stores options for globally registered models
1640
1640
  modelOptions = /* @__PURE__ */ new Map();
1641
- // Stores fields for globally registered models (from @Model decorator, or a static getter on class)
1641
+ // Stores fields for globally registered models (or a static getter on class)
1642
1642
  // For simplicity, let's assume fields can be derived or are less critical for this registry part
1643
1643
  // private modelFields: Map<string, Map<string, FieldOptions>> = new Map();
1644
1644
  // Holds the subset of models explicitly set for the current initialization session
@@ -1656,7 +1656,7 @@ var init_ModelRegistry = __esm({
1656
1656
  registerModel(modelClass, options, fields) {
1657
1657
  if (!options.name) {
1658
1658
  throw new Error(
1659
- `[ModelRegistry] Model class is missing a name in its @Model options. Ensure the @Model decorator includes a 'name' property.`
1659
+ `[ModelRegistry] Model class is missing a name in its options. Ensure the schema passed to defineModelSchema/createModelClass/attachAndRegisterModel includes a 'name' property.`
1660
1660
  );
1661
1661
  }
1662
1662
  if (this.models.has(options.name)) {
@@ -1700,7 +1700,7 @@ var init_ModelRegistry = __esm({
1700
1700
  }
1701
1701
  return infos;
1702
1702
  }
1703
- // Helper to get model name from class (assuming static property from @Model decorator)
1703
+ // Helper to get model name from class (set by attachAndRegisterModel/createModelClass)
1704
1704
  getModelNameFromClass(modelClass) {
1705
1705
  return modelClass.modelName;
1706
1706
  }
@@ -1711,13 +1711,13 @@ var init_ModelRegistry = __esm({
1711
1711
  const modelName = this.getModelNameFromClass(modelClass);
1712
1712
  if (!modelName) {
1713
1713
  console.warn(
1714
- `[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.`
1714
+ `[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.`
1715
1715
  );
1716
1716
  return;
1717
1717
  }
1718
1718
  if (!this.models.has(modelName) || this.models.get(modelName) !== modelClass) {
1719
1719
  console.warn(
1720
- `[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.`
1720
+ `[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.`
1721
1721
  );
1722
1722
  return;
1723
1723
  }
@@ -1747,7 +1747,7 @@ var init_ModelRegistry = __esm({
1747
1747
  } else {
1748
1748
  this.activeSessionModels = null;
1749
1749
  console.log(
1750
- "[ModelRegistry] No explicit models specified for session (undefined), will use all decorator-registered models."
1750
+ "[ModelRegistry] No explicit models specified for session (undefined), will use all globally registered models."
1751
1751
  );
1752
1752
  }
1753
1753
  this.validateSessionModels();
@@ -1758,7 +1758,7 @@ var init_ModelRegistry = __esm({
1758
1758
  const modelsToInitialize = this.activeSessionModels || this.models;
1759
1759
  if (modelsToInitialize.size === 0) {
1760
1760
  console.warn(
1761
- "[ModelRegistry] No models to initialize (either no explicit models set for session or no models globally registered via @Model decorator)."
1761
+ "[ModelRegistry] No models to initialize (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
1762
1762
  );
1763
1763
  return;
1764
1764
  }
@@ -1789,7 +1789,7 @@ var init_ModelRegistry = __esm({
1789
1789
  const modelsToInitialize = this.activeSessionModels || this.models;
1790
1790
  if (modelsToInitialize.size === 0) {
1791
1791
  Logger.warn(
1792
- "[ModelRegistry] No models to initialize for document (either no explicit models set for session or no models globally registered via @Model decorator)."
1792
+ "[ModelRegistry] No models to initialize for document (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
1793
1793
  );
1794
1794
  return;
1795
1795
  }
@@ -1827,7 +1827,7 @@ var init_ModelRegistry = __esm({
1827
1827
  const modelsToCleanup = this.activeSessionModels || this.models;
1828
1828
  if (modelsToCleanup.size === 0) {
1829
1829
  console.warn(
1830
- "[ModelRegistry] No models to cleanup for document (either no explicit models set for session or no models globally registered via @Model decorator)."
1830
+ "[ModelRegistry] No models to cleanup for document (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
1831
1831
  );
1832
1832
  return;
1833
1833
  }
@@ -2591,7 +2591,7 @@ var init_BaseModel = __esm({
2591
2591
  getDocumentId() {
2592
2592
  return this._metaDocId;
2593
2593
  }
2594
- // id is now a plain property. Subclasses will define it with @Field.
2594
+ // id is a plain property. Subclasses define it via defineModelSchema.
2595
2595
  id;
2596
2596
  type;
2597
2597
  // This should be the modelName from ModelOptions
@@ -3138,7 +3138,7 @@ var init_BaseModel = __esm({
3138
3138
  const verboseEnabled = Logger.getLogLevel() >= 5 /* VERBOSE */;
3139
3139
  if (!schema || !schema.options || !schema.options.name || !schema.resolvedUniqueConstraints) {
3140
3140
  throw new Error(
3141
- `[${this.name}] Model schema is not registered, missing options, or missing resolvedUniqueConstraints. Did you forget to use the @Model decorator or has the schema structure changed?`
3141
+ `[${this.name}] Model schema is not registered, missing options, or missing resolvedUniqueConstraints. Did you forget to call attachAndRegisterModel (or autoRegisterModel) for this model?`
3142
3142
  );
3143
3143
  }
3144
3144
  const modelName = schema.options.name;
@@ -5533,11 +5533,11 @@ var init_BaseModel = __esm({
5533
5533
  });
5534
5534
 
5535
5535
  // src/engines/SqljsEngine.ts
5536
- var import_sql5, import_async_mutex, SQL_WASM_URL, TransactionalSQLJSOperations, SqljsEngine;
5536
+ var import_sql4, import_async_mutex, SQL_WASM_URL, TransactionalSQLJSOperations, SqljsEngine;
5537
5537
  var init_SqljsEngine = __esm({
5538
5538
  "src/engines/SqljsEngine.ts"() {
5539
5539
  "use strict";
5540
- import_sql5 = __toESM(require("sql.js"), 1);
5540
+ import_sql4 = __toESM(require("sql.js"), 1);
5541
5541
  init_BaseModel();
5542
5542
  import_async_mutex = require("async-mutex");
5543
5543
  init_sql();
@@ -5614,7 +5614,7 @@ var init_SqljsEngine = __esm({
5614
5614
  "[SqljsEngine] Attempting to load SQL.js WASM from:",
5615
5615
  locateFileConfig("sql-wasm.wasm")
5616
5616
  );
5617
- _SqljsEngine.SQL = await (0, import_sql5.default)({
5617
+ _SqljsEngine.SQL = await (0, import_sql4.default)({
5618
5618
  locateFile: locateFileConfig
5619
5619
  });
5620
5620
  Logger.info("[SqljsEngine] SQL.js WASM loaded successfully.");
@@ -6661,10 +6661,8 @@ __export(node_exports, {
6661
6661
  BaseModel: () => BaseModel2,
6662
6662
  DatabaseEngine: () => DatabaseEngine,
6663
6663
  DatabaseFactory: () => NodeDatabaseFactory,
6664
- Field: () => Field,
6665
6664
  LogLevel: () => LogLevel,
6666
6665
  Logger: () => Logger,
6667
- Model: () => Model,
6668
6666
  ModelRegistry: () => ModelRegistry,
6669
6667
  RecordNotFoundError: () => RecordNotFoundError,
6670
6668
  SqljsEngine: () => SqljsEngine,
@@ -6702,131 +6700,6 @@ module.exports = __toCommonJS(node_exports);
6702
6700
  init_BaseModel();
6703
6701
  init_ModelRegistry();
6704
6702
 
6705
- // src/models/decorators.ts
6706
- init_ModelRegistry();
6707
- init_BaseModel();
6708
- init_sql();
6709
- var SCHEMA_FIELDS_PROPERTY = "_jsbaoSchemaFields";
6710
- function Field(options) {
6711
- return function(target, propertyKey) {
6712
- const fieldName = String(propertyKey);
6713
- const modelConstructor = target.constructor || target;
6714
- assertValidIdentifier(
6715
- fieldName,
6716
- `[Field Decorator] Invalid field name on ${modelConstructor?.name || "unknown"}`
6717
- );
6718
- if (!modelConstructor) {
6719
- console.error(
6720
- "[Field Decorator] Could not determine model constructor for field:",
6721
- fieldName,
6722
- "Target:",
6723
- target
6724
- );
6725
- throw new Error(
6726
- `Failed to resolve model constructor for field '${fieldName}'.`
6727
- );
6728
- }
6729
- if (!Object.prototype.hasOwnProperty.call(
6730
- modelConstructor,
6731
- SCHEMA_FIELDS_PROPERTY
6732
- )) {
6733
- modelConstructor[SCHEMA_FIELDS_PROPERTY] = /* @__PURE__ */ new Map();
6734
- }
6735
- modelConstructor[SCHEMA_FIELDS_PROPERTY].set(
6736
- fieldName,
6737
- options
6738
- );
6739
- Logger.debug(
6740
- `[Field Decorator] Staged field "${fieldName}" for class ${modelConstructor.name}:`,
6741
- options
6742
- );
6743
- };
6744
- }
6745
- function Model(options) {
6746
- return function(targetClass) {
6747
- Logger.debug(
6748
- `[Model Decorator] Registering model:`,
6749
- targetClass.name,
6750
- options
6751
- );
6752
- assertValidIdentifier(
6753
- options.name,
6754
- `[Model Decorator] Invalid model name for ${targetClass.name}`
6755
- );
6756
- const registry = ModelRegistry.getInstance();
6757
- targetClass.modelName = options.name;
6758
- targetClass.getSchema = () => {
6759
- const combinedFields = /* @__PURE__ */ new Map();
6760
- const hierarchyStack = [];
6761
- let currentEvalClass = targetClass;
6762
- while (currentEvalClass && currentEvalClass.prototype) {
6763
- hierarchyStack.push(currentEvalClass);
6764
- const parentPrototype = Object.getPrototypeOf(
6765
- currentEvalClass.prototype
6766
- );
6767
- currentEvalClass = parentPrototype ? parentPrototype.constructor : null;
6768
- if (currentEvalClass === Object) break;
6769
- }
6770
- for (let i = hierarchyStack.length - 1; i >= 0; i--) {
6771
- const cls = hierarchyStack[i];
6772
- if (Object.prototype.hasOwnProperty.call(cls, SCHEMA_FIELDS_PROPERTY)) {
6773
- const fieldsForClass = cls[SCHEMA_FIELDS_PROPERTY];
6774
- fieldsForClass.forEach((fieldOpts, fieldName) => {
6775
- combinedFields.set(fieldName, fieldOpts);
6776
- });
6777
- }
6778
- }
6779
- const resolvedUniqueConstraints = [];
6780
- combinedFields.forEach((fieldOpts, fieldName) => {
6781
- if (fieldOpts.unique) {
6782
- const constraintName = `${options.name}_${fieldName}_unique`;
6783
- resolvedUniqueConstraints.push({
6784
- name: constraintName,
6785
- fields: [fieldName]
6786
- });
6787
- }
6788
- });
6789
- if (options.uniqueConstraints) {
6790
- options.uniqueConstraints.forEach(
6791
- (constraintConfig) => {
6792
- const allFieldsExist = constraintConfig.fields.every(
6793
- (f) => combinedFields.has(f)
6794
- );
6795
- if (!allFieldsExist) {
6796
- console.warn(
6797
- `[Model Decorator] Unique constraint "${constraintConfig.name}" for model "${options.name}" specifies non-existent fields. Skipping.`
6798
- );
6799
- return;
6800
- }
6801
- if (resolvedUniqueConstraints.some(
6802
- (rc) => rc.name === constraintConfig.name
6803
- )) {
6804
- console.warn(
6805
- `[Model Decorator] Duplicate unique constraint name "${constraintConfig.name}" in model "${options.name}".`
6806
- );
6807
- }
6808
- resolvedUniqueConstraints.push({
6809
- name: constraintConfig.name,
6810
- fields: constraintConfig.fields
6811
- });
6812
- }
6813
- );
6814
- }
6815
- return {
6816
- class: targetClass,
6817
- options,
6818
- fields: combinedFields,
6819
- resolvedUniqueConstraints
6820
- };
6821
- };
6822
- const directFieldsForThisClass = Object.prototype.hasOwnProperty.call(
6823
- targetClass,
6824
- SCHEMA_FIELDS_PROPERTY
6825
- ) ? targetClass[SCHEMA_FIELDS_PROPERTY] : /* @__PURE__ */ new Map();
6826
- registry.registerModel(targetClass, options, directFieldsForThisClass);
6827
- };
6828
- }
6829
-
6830
6703
  // src/engines/DatabaseEngine.ts
6831
6704
  var DatabaseEngine = class {
6832
6705
  createTable(_modelName, _schema, _options) {
@@ -7627,10 +7500,8 @@ async function getRecommendedNodeEngine() {
7627
7500
  BaseModel,
7628
7501
  DatabaseEngine,
7629
7502
  DatabaseFactory,
7630
- Field,
7631
7503
  LogLevel,
7632
7504
  Logger,
7633
- Model,
7634
7505
  ModelRegistry,
7635
7506
  RecordNotFoundError,
7636
7507
  SqljsEngine,
package/dist/node.d.cts CHANGED
@@ -663,9 +663,6 @@ declare class ModelRegistry {
663
663
  private validateSessionModels;
664
664
  }
665
665
 
666
- declare function Field(options: FieldOptions): (target: any, propertyKey: string | symbol) => void;
667
- declare function Model(options: ModelOptions): (targetClass: Function) => void;
668
-
669
666
  type NodeSqliteEngineOptions$1 = {
670
667
  filePath?: string;
671
668
  options?: {
@@ -769,7 +766,7 @@ interface InitJsBaoOptions {
769
766
  /**
770
767
  * Optional array of model classes to initialize.
771
768
  * If not provided, the ORM will rely on models being registered
772
- * via the @Model decorator (assuming they have been imported by the application).
769
+ * via attachAndRegisterModel (assuming they have been imported by the application).
773
770
  */
774
771
  models?: (typeof BaseModel)[];
775
772
  }
@@ -1077,4 +1074,4 @@ declare function summarizePlainYDoc(dump: PlainYDoc): DumpSummary;
1077
1074
 
1078
1075
  declare function getRecommendedNodeEngine(): Promise<string>;
1079
1076
 
1080
- export { type AddRelationMethod, type AggregationAliasDebugInfo, type AggregationOperation, type AggregationOptions, type AggregationResult, BaseModel, type DatabaseConfig, DatabaseEngine, type DatabaseEngineOptions, type DatabaseEngineType, NodeDatabaseFactory as DatabaseFactory, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, type DumpOptions, type DumpSummary, type DumpSummaryEntry, Field, type FieldOptions, type FieldType, type GroupByField, type HasManyMethod, type HasManyThroughMethod, type InferAttrs, type InitJsBaoOptions, type InitJsBaoResult, LogLevel, Logger, Model, type ModelConstructor, type ModelOptions, ModelRegistry, type NodeSqliteEngineOptions, type PaginatedResult, type PaginationOptions, type PlainYDoc, RecordNotFoundError, type RefersToMethod, type RegisteredModelInfo, type RemoveRelationMethod, type SQLJSEngineOptions, type Schema, SqljsEngine, type SqljsEngineOptions, StringSet, type StringSetMembership, type UniqueConstraintConfig, UniqueConstraintViolationError, attachAndRegisterModel, attachSchemaToClass, autoRegisterModel, clearMetaSyncCache, constants, createModelClass, defineModelSchema, detectEnvironment, discoverModelNames, discoverSchema, dumpYDocToPlain, features, generateULID, getRecommendedNodeEngine, inferFieldType, initJsBao, isBrowser, isNode, isNodeModuleAvailable, loadSchemaFromToml, loadSchemaFromTomlString, registerFunctionDefault, resetJsBao, schemaToToml, summarizePlainYDoc, syncInferredMeta, syncModelMeta };
1077
+ export { type AddRelationMethod, type AggregationAliasDebugInfo, type AggregationOperation, type AggregationOptions, type AggregationResult, BaseModel, type DatabaseConfig, DatabaseEngine, type DatabaseEngineOptions, type DatabaseEngineType, NodeDatabaseFactory as DatabaseFactory, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, type DumpOptions, type DumpSummary, type DumpSummaryEntry, type FieldOptions, type FieldType, type GroupByField, type HasManyMethod, type HasManyThroughMethod, type InferAttrs, type InitJsBaoOptions, type InitJsBaoResult, LogLevel, Logger, type ModelConstructor, type ModelOptions, ModelRegistry, type NodeSqliteEngineOptions, type PaginatedResult, type PaginationOptions, type PlainYDoc, RecordNotFoundError, type RefersToMethod, type RegisteredModelInfo, type RemoveRelationMethod, type SQLJSEngineOptions, type Schema, SqljsEngine, type SqljsEngineOptions, StringSet, type StringSetMembership, type UniqueConstraintConfig, UniqueConstraintViolationError, attachAndRegisterModel, attachSchemaToClass, autoRegisterModel, clearMetaSyncCache, constants, createModelClass, defineModelSchema, detectEnvironment, discoverModelNames, discoverSchema, dumpYDocToPlain, features, generateULID, getRecommendedNodeEngine, inferFieldType, initJsBao, isBrowser, isNode, isNodeModuleAvailable, loadSchemaFromToml, loadSchemaFromTomlString, registerFunctionDefault, resetJsBao, schemaToToml, summarizePlainYDoc, syncInferredMeta, syncModelMeta };
package/dist/node.d.ts CHANGED
@@ -663,9 +663,6 @@ declare class ModelRegistry {
663
663
  private validateSessionModels;
664
664
  }
665
665
 
666
- declare function Field(options: FieldOptions): (target: any, propertyKey: string | symbol) => void;
667
- declare function Model(options: ModelOptions): (targetClass: Function) => void;
668
-
669
666
  type NodeSqliteEngineOptions$1 = {
670
667
  filePath?: string;
671
668
  options?: {
@@ -769,7 +766,7 @@ interface InitJsBaoOptions {
769
766
  /**
770
767
  * Optional array of model classes to initialize.
771
768
  * If not provided, the ORM will rely on models being registered
772
- * via the @Model decorator (assuming they have been imported by the application).
769
+ * via attachAndRegisterModel (assuming they have been imported by the application).
773
770
  */
774
771
  models?: (typeof BaseModel)[];
775
772
  }
@@ -1077,4 +1074,4 @@ declare function summarizePlainYDoc(dump: PlainYDoc): DumpSummary;
1077
1074
 
1078
1075
  declare function getRecommendedNodeEngine(): Promise<string>;
1079
1076
 
1080
- export { type AddRelationMethod, type AggregationAliasDebugInfo, type AggregationOperation, type AggregationOptions, type AggregationResult, BaseModel, type DatabaseConfig, DatabaseEngine, type DatabaseEngineOptions, type DatabaseEngineType, NodeDatabaseFactory as DatabaseFactory, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, type DumpOptions, type DumpSummary, type DumpSummaryEntry, Field, type FieldOptions, type FieldType, type GroupByField, type HasManyMethod, type HasManyThroughMethod, type InferAttrs, type InitJsBaoOptions, type InitJsBaoResult, LogLevel, Logger, Model, type ModelConstructor, type ModelOptions, ModelRegistry, type NodeSqliteEngineOptions, type PaginatedResult, type PaginationOptions, type PlainYDoc, RecordNotFoundError, type RefersToMethod, type RegisteredModelInfo, type RemoveRelationMethod, type SQLJSEngineOptions, type Schema, SqljsEngine, type SqljsEngineOptions, StringSet, type StringSetMembership, type UniqueConstraintConfig, UniqueConstraintViolationError, attachAndRegisterModel, attachSchemaToClass, autoRegisterModel, clearMetaSyncCache, constants, createModelClass, defineModelSchema, detectEnvironment, discoverModelNames, discoverSchema, dumpYDocToPlain, features, generateULID, getRecommendedNodeEngine, inferFieldType, initJsBao, isBrowser, isNode, isNodeModuleAvailable, loadSchemaFromToml, loadSchemaFromTomlString, registerFunctionDefault, resetJsBao, schemaToToml, summarizePlainYDoc, syncInferredMeta, syncModelMeta };
1077
+ export { type AddRelationMethod, type AggregationAliasDebugInfo, type AggregationOperation, type AggregationOptions, type AggregationResult, BaseModel, type DatabaseConfig, DatabaseEngine, type DatabaseEngineOptions, type DatabaseEngineType, NodeDatabaseFactory as DatabaseFactory, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, type DumpOptions, type DumpSummary, type DumpSummaryEntry, type FieldOptions, type FieldType, type GroupByField, type HasManyMethod, type HasManyThroughMethod, type InferAttrs, type InitJsBaoOptions, type InitJsBaoResult, LogLevel, Logger, type ModelConstructor, type ModelOptions, ModelRegistry, type NodeSqliteEngineOptions, type PaginatedResult, type PaginationOptions, type PlainYDoc, RecordNotFoundError, type RefersToMethod, type RegisteredModelInfo, type RemoveRelationMethod, type SQLJSEngineOptions, type Schema, SqljsEngine, type SqljsEngineOptions, StringSet, type StringSetMembership, type UniqueConstraintConfig, UniqueConstraintViolationError, attachAndRegisterModel, attachSchemaToClass, autoRegisterModel, clearMetaSyncCache, constants, createModelClass, defineModelSchema, detectEnvironment, discoverModelNames, discoverSchema, dumpYDocToPlain, features, generateULID, getRecommendedNodeEngine, inferFieldType, initJsBao, isBrowser, isNode, isNodeModuleAvailable, loadSchemaFromToml, loadSchemaFromTomlString, registerFunctionDefault, resetJsBao, schemaToToml, summarizePlainYDoc, syncInferredMeta, syncModelMeta };
package/dist/node.js CHANGED
@@ -1612,11 +1612,11 @@ var init_ModelRegistry = __esm({
1612
1612
  init_relationshipManager();
1613
1613
  ModelRegistry = class _ModelRegistry {
1614
1614
  static instance;
1615
- // Stores globally registered model classes by their name (from @Model decorator)
1615
+ // Stores globally registered model classes by their name
1616
1616
  models = /* @__PURE__ */ new Map();
1617
- // Stores options for globally registered models (from @Model decorator)
1617
+ // Stores options for globally registered models
1618
1618
  modelOptions = /* @__PURE__ */ new Map();
1619
- // Stores fields for globally registered models (from @Model decorator, or a static getter on class)
1619
+ // Stores fields for globally registered models (or a static getter on class)
1620
1620
  // For simplicity, let's assume fields can be derived or are less critical for this registry part
1621
1621
  // private modelFields: Map<string, Map<string, FieldOptions>> = new Map();
1622
1622
  // Holds the subset of models explicitly set for the current initialization session
@@ -1634,7 +1634,7 @@ var init_ModelRegistry = __esm({
1634
1634
  registerModel(modelClass, options, fields) {
1635
1635
  if (!options.name) {
1636
1636
  throw new Error(
1637
- `[ModelRegistry] Model class is missing a name in its @Model options. Ensure the @Model decorator includes a 'name' property.`
1637
+ `[ModelRegistry] Model class is missing a name in its options. Ensure the schema passed to defineModelSchema/createModelClass/attachAndRegisterModel includes a 'name' property.`
1638
1638
  );
1639
1639
  }
1640
1640
  if (this.models.has(options.name)) {
@@ -1678,7 +1678,7 @@ var init_ModelRegistry = __esm({
1678
1678
  }
1679
1679
  return infos;
1680
1680
  }
1681
- // Helper to get model name from class (assuming static property from @Model decorator)
1681
+ // Helper to get model name from class (set by attachAndRegisterModel/createModelClass)
1682
1682
  getModelNameFromClass(modelClass) {
1683
1683
  return modelClass.modelName;
1684
1684
  }
@@ -1689,13 +1689,13 @@ var init_ModelRegistry = __esm({
1689
1689
  const modelName = this.getModelNameFromClass(modelClass);
1690
1690
  if (!modelName) {
1691
1691
  console.warn(
1692
- `[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.`
1692
+ `[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.`
1693
1693
  );
1694
1694
  return;
1695
1695
  }
1696
1696
  if (!this.models.has(modelName) || this.models.get(modelName) !== modelClass) {
1697
1697
  console.warn(
1698
- `[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.`
1698
+ `[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.`
1699
1699
  );
1700
1700
  return;
1701
1701
  }
@@ -1725,7 +1725,7 @@ var init_ModelRegistry = __esm({
1725
1725
  } else {
1726
1726
  this.activeSessionModels = null;
1727
1727
  console.log(
1728
- "[ModelRegistry] No explicit models specified for session (undefined), will use all decorator-registered models."
1728
+ "[ModelRegistry] No explicit models specified for session (undefined), will use all globally registered models."
1729
1729
  );
1730
1730
  }
1731
1731
  this.validateSessionModels();
@@ -1736,7 +1736,7 @@ var init_ModelRegistry = __esm({
1736
1736
  const modelsToInitialize = this.activeSessionModels || this.models;
1737
1737
  if (modelsToInitialize.size === 0) {
1738
1738
  console.warn(
1739
- "[ModelRegistry] No models to initialize (either no explicit models set for session or no models globally registered via @Model decorator)."
1739
+ "[ModelRegistry] No models to initialize (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
1740
1740
  );
1741
1741
  return;
1742
1742
  }
@@ -1767,7 +1767,7 @@ var init_ModelRegistry = __esm({
1767
1767
  const modelsToInitialize = this.activeSessionModels || this.models;
1768
1768
  if (modelsToInitialize.size === 0) {
1769
1769
  Logger.warn(
1770
- "[ModelRegistry] No models to initialize for document (either no explicit models set for session or no models globally registered via @Model decorator)."
1770
+ "[ModelRegistry] No models to initialize for document (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
1771
1771
  );
1772
1772
  return;
1773
1773
  }
@@ -1805,7 +1805,7 @@ var init_ModelRegistry = __esm({
1805
1805
  const modelsToCleanup = this.activeSessionModels || this.models;
1806
1806
  if (modelsToCleanup.size === 0) {
1807
1807
  console.warn(
1808
- "[ModelRegistry] No models to cleanup for document (either no explicit models set for session or no models globally registered via @Model decorator)."
1808
+ "[ModelRegistry] No models to cleanup for document (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
1809
1809
  );
1810
1810
  return;
1811
1811
  }
@@ -2569,7 +2569,7 @@ var init_BaseModel = __esm({
2569
2569
  getDocumentId() {
2570
2570
  return this._metaDocId;
2571
2571
  }
2572
- // id is now a plain property. Subclasses will define it with @Field.
2572
+ // id is a plain property. Subclasses define it via defineModelSchema.
2573
2573
  id;
2574
2574
  type;
2575
2575
  // This should be the modelName from ModelOptions
@@ -3116,7 +3116,7 @@ var init_BaseModel = __esm({
3116
3116
  const verboseEnabled = Logger.getLogLevel() >= 5 /* VERBOSE */;
3117
3117
  if (!schema || !schema.options || !schema.options.name || !schema.resolvedUniqueConstraints) {
3118
3118
  throw new Error(
3119
- `[${this.name}] Model schema is not registered, missing options, or missing resolvedUniqueConstraints. Did you forget to use the @Model decorator or has the schema structure changed?`
3119
+ `[${this.name}] Model schema is not registered, missing options, or missing resolvedUniqueConstraints. Did you forget to call attachAndRegisterModel (or autoRegisterModel) for this model?`
3120
3120
  );
3121
3121
  }
3122
3122
  const modelName = schema.options.name;
@@ -6637,131 +6637,6 @@ var init_BrowserDatabaseFactory = __esm({
6637
6637
  init_BaseModel();
6638
6638
  init_ModelRegistry();
6639
6639
 
6640
- // src/models/decorators.ts
6641
- init_ModelRegistry();
6642
- init_BaseModel();
6643
- init_sql();
6644
- var SCHEMA_FIELDS_PROPERTY = "_jsbaoSchemaFields";
6645
- function Field(options) {
6646
- return function(target, propertyKey) {
6647
- const fieldName = String(propertyKey);
6648
- const modelConstructor = target.constructor || target;
6649
- assertValidIdentifier(
6650
- fieldName,
6651
- `[Field Decorator] Invalid field name on ${modelConstructor?.name || "unknown"}`
6652
- );
6653
- if (!modelConstructor) {
6654
- console.error(
6655
- "[Field Decorator] Could not determine model constructor for field:",
6656
- fieldName,
6657
- "Target:",
6658
- target
6659
- );
6660
- throw new Error(
6661
- `Failed to resolve model constructor for field '${fieldName}'.`
6662
- );
6663
- }
6664
- if (!Object.prototype.hasOwnProperty.call(
6665
- modelConstructor,
6666
- SCHEMA_FIELDS_PROPERTY
6667
- )) {
6668
- modelConstructor[SCHEMA_FIELDS_PROPERTY] = /* @__PURE__ */ new Map();
6669
- }
6670
- modelConstructor[SCHEMA_FIELDS_PROPERTY].set(
6671
- fieldName,
6672
- options
6673
- );
6674
- Logger.debug(
6675
- `[Field Decorator] Staged field "${fieldName}" for class ${modelConstructor.name}:`,
6676
- options
6677
- );
6678
- };
6679
- }
6680
- function Model(options) {
6681
- return function(targetClass) {
6682
- Logger.debug(
6683
- `[Model Decorator] Registering model:`,
6684
- targetClass.name,
6685
- options
6686
- );
6687
- assertValidIdentifier(
6688
- options.name,
6689
- `[Model Decorator] Invalid model name for ${targetClass.name}`
6690
- );
6691
- const registry = ModelRegistry.getInstance();
6692
- targetClass.modelName = options.name;
6693
- targetClass.getSchema = () => {
6694
- const combinedFields = /* @__PURE__ */ new Map();
6695
- const hierarchyStack = [];
6696
- let currentEvalClass = targetClass;
6697
- while (currentEvalClass && currentEvalClass.prototype) {
6698
- hierarchyStack.push(currentEvalClass);
6699
- const parentPrototype = Object.getPrototypeOf(
6700
- currentEvalClass.prototype
6701
- );
6702
- currentEvalClass = parentPrototype ? parentPrototype.constructor : null;
6703
- if (currentEvalClass === Object) break;
6704
- }
6705
- for (let i = hierarchyStack.length - 1; i >= 0; i--) {
6706
- const cls = hierarchyStack[i];
6707
- if (Object.prototype.hasOwnProperty.call(cls, SCHEMA_FIELDS_PROPERTY)) {
6708
- const fieldsForClass = cls[SCHEMA_FIELDS_PROPERTY];
6709
- fieldsForClass.forEach((fieldOpts, fieldName) => {
6710
- combinedFields.set(fieldName, fieldOpts);
6711
- });
6712
- }
6713
- }
6714
- const resolvedUniqueConstraints = [];
6715
- combinedFields.forEach((fieldOpts, fieldName) => {
6716
- if (fieldOpts.unique) {
6717
- const constraintName = `${options.name}_${fieldName}_unique`;
6718
- resolvedUniqueConstraints.push({
6719
- name: constraintName,
6720
- fields: [fieldName]
6721
- });
6722
- }
6723
- });
6724
- if (options.uniqueConstraints) {
6725
- options.uniqueConstraints.forEach(
6726
- (constraintConfig) => {
6727
- const allFieldsExist = constraintConfig.fields.every(
6728
- (f) => combinedFields.has(f)
6729
- );
6730
- if (!allFieldsExist) {
6731
- console.warn(
6732
- `[Model Decorator] Unique constraint "${constraintConfig.name}" for model "${options.name}" specifies non-existent fields. Skipping.`
6733
- );
6734
- return;
6735
- }
6736
- if (resolvedUniqueConstraints.some(
6737
- (rc) => rc.name === constraintConfig.name
6738
- )) {
6739
- console.warn(
6740
- `[Model Decorator] Duplicate unique constraint name "${constraintConfig.name}" in model "${options.name}".`
6741
- );
6742
- }
6743
- resolvedUniqueConstraints.push({
6744
- name: constraintConfig.name,
6745
- fields: constraintConfig.fields
6746
- });
6747
- }
6748
- );
6749
- }
6750
- return {
6751
- class: targetClass,
6752
- options,
6753
- fields: combinedFields,
6754
- resolvedUniqueConstraints
6755
- };
6756
- };
6757
- const directFieldsForThisClass = Object.prototype.hasOwnProperty.call(
6758
- targetClass,
6759
- SCHEMA_FIELDS_PROPERTY
6760
- ) ? targetClass[SCHEMA_FIELDS_PROPERTY] : /* @__PURE__ */ new Map();
6761
- registry.registerModel(targetClass, options, directFieldsForThisClass);
6762
- };
6763
- }
6764
-
6765
6640
  // src/engines/DatabaseEngine.ts
6766
6641
  var DatabaseEngine = class {
6767
6642
  createTable(_modelName, _schema, _options) {
@@ -7561,10 +7436,8 @@ export {
7561
7436
  BaseModel2 as BaseModel,
7562
7437
  DatabaseEngine,
7563
7438
  NodeDatabaseFactory as DatabaseFactory,
7564
- Field,
7565
7439
  LogLevel,
7566
7440
  Logger,
7567
- Model,
7568
7441
  ModelRegistry,
7569
7442
  RecordNotFoundError,
7570
7443
  SqljsEngine,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-bao",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "A library providing data modeling capabilities which support live updates and queries.",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",