js-bao 0.3.1 → 0.4.1
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 +91 -158
- package/dist/browser.d.cts +22 -6
- package/dist/browser.d.ts +22 -6
- package/dist/browser.js +89 -156
- package/dist/client.d.cts +7 -0
- package/dist/client.d.ts +7 -0
- package/dist/cloudflare-do.cjs +70 -5
- package/dist/cloudflare-do.d.cts +22 -3
- package/dist/cloudflare-do.d.ts +22 -3
- package/dist/cloudflare-do.js +70 -5
- package/dist/cloudflare.cjs +70 -5
- package/dist/cloudflare.d.cts +20 -1
- package/dist/cloudflare.d.ts +20 -1
- package/dist/cloudflare.js +70 -5
- package/dist/codegen-v2.cjs +1766 -0
- package/dist/codegen-v2.d.cts +1 -0
- package/dist/codegen.cjs +8 -19
- package/dist/index.cjs +91 -162
- package/dist/index.d.cts +23 -7
- package/dist/index.d.ts +23 -7
- package/dist/index.js +91 -160
- package/dist/node.cjs +94 -163
- package/dist/node.d.cts +23 -7
- package/dist/node.d.ts +23 -7
- package/dist/node.js +91 -158
- package/package.json +7 -10
package/dist/browser.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
|
|
1637
|
+
// Stores globally registered model classes by their name
|
|
1638
1638
|
models = /* @__PURE__ */ new Map();
|
|
1639
|
-
// Stores options for globally registered models
|
|
1639
|
+
// Stores options for globally registered models
|
|
1640
1640
|
modelOptions = /* @__PURE__ */ new Map();
|
|
1641
|
-
// Stores fields for globally registered models (
|
|
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
|
|
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 (
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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;
|
|
@@ -5538,10 +5538,8 @@ __export(browser_exports, {
|
|
|
5538
5538
|
BaseModel: () => BaseModel2,
|
|
5539
5539
|
DatabaseEngine: () => DatabaseEngine,
|
|
5540
5540
|
DatabaseFactory: () => BrowserDatabaseFactory,
|
|
5541
|
-
Field: () => Field,
|
|
5542
5541
|
LogLevel: () => LogLevel,
|
|
5543
5542
|
Logger: () => Logger,
|
|
5544
|
-
Model: () => Model,
|
|
5545
5543
|
ModelRegistry: () => ModelRegistry,
|
|
5546
5544
|
RecordNotFoundError: () => RecordNotFoundError,
|
|
5547
5545
|
SqljsEngine: () => SqljsEngine,
|
|
@@ -5573,131 +5571,6 @@ module.exports = __toCommonJS(browser_exports);
|
|
|
5573
5571
|
init_BaseModel();
|
|
5574
5572
|
init_ModelRegistry();
|
|
5575
5573
|
|
|
5576
|
-
// src/models/decorators.ts
|
|
5577
|
-
init_ModelRegistry();
|
|
5578
|
-
init_BaseModel();
|
|
5579
|
-
init_sql();
|
|
5580
|
-
var SCHEMA_FIELDS_PROPERTY = "_jsbaoSchemaFields";
|
|
5581
|
-
function Field(options) {
|
|
5582
|
-
return function(target, propertyKey) {
|
|
5583
|
-
const fieldName = String(propertyKey);
|
|
5584
|
-
const modelConstructor = target.constructor || target;
|
|
5585
|
-
assertValidIdentifier(
|
|
5586
|
-
fieldName,
|
|
5587
|
-
`[Field Decorator] Invalid field name on ${modelConstructor?.name || "unknown"}`
|
|
5588
|
-
);
|
|
5589
|
-
if (!modelConstructor) {
|
|
5590
|
-
console.error(
|
|
5591
|
-
"[Field Decorator] Could not determine model constructor for field:",
|
|
5592
|
-
fieldName,
|
|
5593
|
-
"Target:",
|
|
5594
|
-
target
|
|
5595
|
-
);
|
|
5596
|
-
throw new Error(
|
|
5597
|
-
`Failed to resolve model constructor for field '${fieldName}'.`
|
|
5598
|
-
);
|
|
5599
|
-
}
|
|
5600
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
5601
|
-
modelConstructor,
|
|
5602
|
-
SCHEMA_FIELDS_PROPERTY
|
|
5603
|
-
)) {
|
|
5604
|
-
modelConstructor[SCHEMA_FIELDS_PROPERTY] = /* @__PURE__ */ new Map();
|
|
5605
|
-
}
|
|
5606
|
-
modelConstructor[SCHEMA_FIELDS_PROPERTY].set(
|
|
5607
|
-
fieldName,
|
|
5608
|
-
options
|
|
5609
|
-
);
|
|
5610
|
-
Logger.debug(
|
|
5611
|
-
`[Field Decorator] Staged field "${fieldName}" for class ${modelConstructor.name}:`,
|
|
5612
|
-
options
|
|
5613
|
-
);
|
|
5614
|
-
};
|
|
5615
|
-
}
|
|
5616
|
-
function Model(options) {
|
|
5617
|
-
return function(targetClass) {
|
|
5618
|
-
Logger.debug(
|
|
5619
|
-
`[Model Decorator] Registering model:`,
|
|
5620
|
-
targetClass.name,
|
|
5621
|
-
options
|
|
5622
|
-
);
|
|
5623
|
-
assertValidIdentifier(
|
|
5624
|
-
options.name,
|
|
5625
|
-
`[Model Decorator] Invalid model name for ${targetClass.name}`
|
|
5626
|
-
);
|
|
5627
|
-
const registry = ModelRegistry.getInstance();
|
|
5628
|
-
targetClass.modelName = options.name;
|
|
5629
|
-
targetClass.getSchema = () => {
|
|
5630
|
-
const combinedFields = /* @__PURE__ */ new Map();
|
|
5631
|
-
const hierarchyStack = [];
|
|
5632
|
-
let currentEvalClass = targetClass;
|
|
5633
|
-
while (currentEvalClass && currentEvalClass.prototype) {
|
|
5634
|
-
hierarchyStack.push(currentEvalClass);
|
|
5635
|
-
const parentPrototype = Object.getPrototypeOf(
|
|
5636
|
-
currentEvalClass.prototype
|
|
5637
|
-
);
|
|
5638
|
-
currentEvalClass = parentPrototype ? parentPrototype.constructor : null;
|
|
5639
|
-
if (currentEvalClass === Object) break;
|
|
5640
|
-
}
|
|
5641
|
-
for (let i = hierarchyStack.length - 1; i >= 0; i--) {
|
|
5642
|
-
const cls = hierarchyStack[i];
|
|
5643
|
-
if (Object.prototype.hasOwnProperty.call(cls, SCHEMA_FIELDS_PROPERTY)) {
|
|
5644
|
-
const fieldsForClass = cls[SCHEMA_FIELDS_PROPERTY];
|
|
5645
|
-
fieldsForClass.forEach((fieldOpts, fieldName) => {
|
|
5646
|
-
combinedFields.set(fieldName, fieldOpts);
|
|
5647
|
-
});
|
|
5648
|
-
}
|
|
5649
|
-
}
|
|
5650
|
-
const resolvedUniqueConstraints = [];
|
|
5651
|
-
combinedFields.forEach((fieldOpts, fieldName) => {
|
|
5652
|
-
if (fieldOpts.unique) {
|
|
5653
|
-
const constraintName = `${options.name}_${fieldName}_unique`;
|
|
5654
|
-
resolvedUniqueConstraints.push({
|
|
5655
|
-
name: constraintName,
|
|
5656
|
-
fields: [fieldName]
|
|
5657
|
-
});
|
|
5658
|
-
}
|
|
5659
|
-
});
|
|
5660
|
-
if (options.uniqueConstraints) {
|
|
5661
|
-
options.uniqueConstraints.forEach(
|
|
5662
|
-
(constraintConfig) => {
|
|
5663
|
-
const allFieldsExist = constraintConfig.fields.every(
|
|
5664
|
-
(f) => combinedFields.has(f)
|
|
5665
|
-
);
|
|
5666
|
-
if (!allFieldsExist) {
|
|
5667
|
-
console.warn(
|
|
5668
|
-
`[Model Decorator] Unique constraint "${constraintConfig.name}" for model "${options.name}" specifies non-existent fields. Skipping.`
|
|
5669
|
-
);
|
|
5670
|
-
return;
|
|
5671
|
-
}
|
|
5672
|
-
if (resolvedUniqueConstraints.some(
|
|
5673
|
-
(rc) => rc.name === constraintConfig.name
|
|
5674
|
-
)) {
|
|
5675
|
-
console.warn(
|
|
5676
|
-
`[Model Decorator] Duplicate unique constraint name "${constraintConfig.name}" in model "${options.name}".`
|
|
5677
|
-
);
|
|
5678
|
-
}
|
|
5679
|
-
resolvedUniqueConstraints.push({
|
|
5680
|
-
name: constraintConfig.name,
|
|
5681
|
-
fields: constraintConfig.fields
|
|
5682
|
-
});
|
|
5683
|
-
}
|
|
5684
|
-
);
|
|
5685
|
-
}
|
|
5686
|
-
return {
|
|
5687
|
-
class: targetClass,
|
|
5688
|
-
options,
|
|
5689
|
-
fields: combinedFields,
|
|
5690
|
-
resolvedUniqueConstraints
|
|
5691
|
-
};
|
|
5692
|
-
};
|
|
5693
|
-
const directFieldsForThisClass = Object.prototype.hasOwnProperty.call(
|
|
5694
|
-
targetClass,
|
|
5695
|
-
SCHEMA_FIELDS_PROPERTY
|
|
5696
|
-
) ? targetClass[SCHEMA_FIELDS_PROPERTY] : /* @__PURE__ */ new Map();
|
|
5697
|
-
registry.registerModel(targetClass, options, directFieldsForThisClass);
|
|
5698
|
-
};
|
|
5699
|
-
}
|
|
5700
|
-
|
|
5701
5574
|
// src/engines/DatabaseEngine.ts
|
|
5702
5575
|
var DatabaseEngine = class {
|
|
5703
5576
|
createTable(_modelName, _schema, _options) {
|
|
@@ -5737,7 +5610,7 @@ var DatabaseEngine = class {
|
|
|
5737
5610
|
};
|
|
5738
5611
|
|
|
5739
5612
|
// src/engines/SqljsEngine.ts
|
|
5740
|
-
var
|
|
5613
|
+
var import_sql4 = __toESM(require("sql.js"), 1);
|
|
5741
5614
|
init_BaseModel();
|
|
5742
5615
|
var import_async_mutex = require("async-mutex");
|
|
5743
5616
|
init_sql();
|
|
@@ -5814,7 +5687,7 @@ var SqljsEngine = class _SqljsEngine {
|
|
|
5814
5687
|
"[SqljsEngine] Attempting to load SQL.js WASM from:",
|
|
5815
5688
|
locateFileConfig("sql-wasm.wasm")
|
|
5816
5689
|
);
|
|
5817
|
-
_SqljsEngine.SQL = await (0,
|
|
5690
|
+
_SqljsEngine.SQL = await (0, import_sql4.default)({
|
|
5818
5691
|
locateFile: locateFileConfig
|
|
5819
5692
|
});
|
|
5820
5693
|
Logger.info("[SqljsEngine] SQL.js WASM loaded successfully.");
|
|
@@ -6470,6 +6343,7 @@ function defineModelSchema(input) {
|
|
|
6470
6343
|
const { name, fields } = input;
|
|
6471
6344
|
const options = {
|
|
6472
6345
|
name,
|
|
6346
|
+
className: input.options?.className,
|
|
6473
6347
|
uniqueConstraints: input.options?.uniqueConstraints ? [...input.options.uniqueConstraints] : void 0,
|
|
6474
6348
|
relationships: input.options?.relationships
|
|
6475
6349
|
};
|
|
@@ -6569,18 +6443,13 @@ function resolveUniqueConstraints(modelName, fields, customConstraints) {
|
|
|
6569
6443
|
function attachSchemaToClass(modelClass, schema) {
|
|
6570
6444
|
modelClass.schema = schema;
|
|
6571
6445
|
modelClass.modelName = schema.options.name;
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
value: function() {
|
|
6575
|
-
return schema.buildRuntimeShape(modelClass);
|
|
6576
|
-
},
|
|
6577
|
-
writable: false
|
|
6578
|
-
});
|
|
6579
|
-
} else {
|
|
6580
|
-
modelClass.getSchema = function() {
|
|
6446
|
+
Object.defineProperty(modelClass, "getSchema", {
|
|
6447
|
+
value: function() {
|
|
6581
6448
|
return schema.buildRuntimeShape(modelClass);
|
|
6582
|
-
}
|
|
6583
|
-
|
|
6449
|
+
},
|
|
6450
|
+
writable: false,
|
|
6451
|
+
configurable: true
|
|
6452
|
+
});
|
|
6584
6453
|
const runtimeShape = schema.buildRuntimeShape(modelClass);
|
|
6585
6454
|
BaseModel2.attachFieldAccessors(modelClass, runtimeShape.fields);
|
|
6586
6455
|
return runtimeShape;
|
|
@@ -6813,12 +6682,52 @@ var VALID_FIELD_TYPES = /* @__PURE__ */ new Set([
|
|
|
6813
6682
|
"id",
|
|
6814
6683
|
"stringset"
|
|
6815
6684
|
]);
|
|
6816
|
-
|
|
6685
|
+
var KNOWN_FIELD_KEYS = /* @__PURE__ */ new Set([
|
|
6686
|
+
"type",
|
|
6687
|
+
"indexed",
|
|
6688
|
+
"unique",
|
|
6689
|
+
"required",
|
|
6690
|
+
"auto_assign",
|
|
6691
|
+
"max_length",
|
|
6692
|
+
"max_count",
|
|
6693
|
+
"default"
|
|
6694
|
+
]);
|
|
6695
|
+
var KNOWN_MODEL_KEYS = /* @__PURE__ */ new Set([
|
|
6696
|
+
"fields",
|
|
6697
|
+
"relationships",
|
|
6698
|
+
"unique_constraints",
|
|
6699
|
+
"class_name"
|
|
6700
|
+
]);
|
|
6701
|
+
var KNOWN_RELATIONSHIP_KEYS = /* @__PURE__ */ new Set([
|
|
6702
|
+
"type",
|
|
6703
|
+
"model",
|
|
6704
|
+
"related_id_field",
|
|
6705
|
+
"join_model",
|
|
6706
|
+
"join_model_local_field",
|
|
6707
|
+
"join_model_related_field",
|
|
6708
|
+
"order_by_field",
|
|
6709
|
+
"order_direction",
|
|
6710
|
+
"join_model_order_by_field",
|
|
6711
|
+
"join_model_order_direction"
|
|
6712
|
+
]);
|
|
6713
|
+
var KNOWN_UNIQUE_CONSTRAINT_KEYS = /* @__PURE__ */ new Set(["name", "fields"]);
|
|
6714
|
+
function checkUnknownKeys(raw, known, context, strict) {
|
|
6715
|
+
if (!strict) return;
|
|
6716
|
+
for (const key of Object.keys(raw)) {
|
|
6717
|
+
if (!known.has(key)) {
|
|
6718
|
+
throw new Error(
|
|
6719
|
+
`${context}: unknown key "${key}". Allowed: ${[...known].join(", ")}`
|
|
6720
|
+
);
|
|
6721
|
+
}
|
|
6722
|
+
}
|
|
6723
|
+
}
|
|
6724
|
+
function parseFieldOptions(raw, context, strict) {
|
|
6817
6725
|
if (!raw.type || !VALID_FIELD_TYPES.has(raw.type)) {
|
|
6818
6726
|
throw new Error(
|
|
6819
6727
|
`Invalid field type "${raw.type}". Must be one of: ${[...VALID_FIELD_TYPES].join(", ")}`
|
|
6820
6728
|
);
|
|
6821
6729
|
}
|
|
6730
|
+
checkUnknownKeys(raw, KNOWN_FIELD_KEYS, context, strict);
|
|
6822
6731
|
const opts = { type: raw.type };
|
|
6823
6732
|
if (raw.indexed === true) opts.indexed = true;
|
|
6824
6733
|
if (raw.unique === true) opts.unique = true;
|
|
@@ -6834,8 +6743,9 @@ function requireField(raw, field, context) {
|
|
|
6834
6743
|
throw new Error(`Relationship ${context}: missing required field "${field}"`);
|
|
6835
6744
|
}
|
|
6836
6745
|
}
|
|
6837
|
-
function parseRelationship(raw) {
|
|
6746
|
+
function parseRelationship(raw, context, strict) {
|
|
6838
6747
|
const type = raw.type;
|
|
6748
|
+
checkUnknownKeys(raw, KNOWN_RELATIONSHIP_KEYS, context, strict);
|
|
6839
6749
|
if (type === "refersTo") {
|
|
6840
6750
|
requireField(raw, "model", "refersTo");
|
|
6841
6751
|
requireField(raw, "related_id_field", "refersTo");
|
|
@@ -6877,7 +6787,8 @@ function parseRelationship(raw) {
|
|
|
6877
6787
|
}
|
|
6878
6788
|
throw new Error(`Unknown relationship type: ${type}`);
|
|
6879
6789
|
}
|
|
6880
|
-
function loadSchemaFromTomlString(tomlString) {
|
|
6790
|
+
function loadSchemaFromTomlString(tomlString, options = {}) {
|
|
6791
|
+
const strict = options.strict !== false;
|
|
6881
6792
|
const parsed = (0, import_smol_toml.parse)(tomlString);
|
|
6882
6793
|
const models = parsed.models;
|
|
6883
6794
|
if (!models || typeof models !== "object") {
|
|
@@ -6885,10 +6796,20 @@ function loadSchemaFromTomlString(tomlString) {
|
|
|
6885
6796
|
}
|
|
6886
6797
|
const schemas = [];
|
|
6887
6798
|
for (const [modelName, modelDef] of Object.entries(models)) {
|
|
6799
|
+
checkUnknownKeys(
|
|
6800
|
+
modelDef,
|
|
6801
|
+
KNOWN_MODEL_KEYS,
|
|
6802
|
+
`[models.${modelName}]`,
|
|
6803
|
+
strict
|
|
6804
|
+
);
|
|
6888
6805
|
const fields = {};
|
|
6889
6806
|
if (modelDef.fields) {
|
|
6890
6807
|
for (const [fieldName, fieldDef] of Object.entries(modelDef.fields)) {
|
|
6891
|
-
fields[fieldName] = parseFieldOptions(
|
|
6808
|
+
fields[fieldName] = parseFieldOptions(
|
|
6809
|
+
fieldDef,
|
|
6810
|
+
`[models.${modelName}.fields.${fieldName}]`,
|
|
6811
|
+
strict
|
|
6812
|
+
);
|
|
6892
6813
|
}
|
|
6893
6814
|
}
|
|
6894
6815
|
let relationships;
|
|
@@ -6897,24 +6818,36 @@ function loadSchemaFromTomlString(tomlString) {
|
|
|
6897
6818
|
for (const [relName, relDef] of Object.entries(
|
|
6898
6819
|
modelDef.relationships
|
|
6899
6820
|
)) {
|
|
6900
|
-
relationships[relName] = parseRelationship(
|
|
6821
|
+
relationships[relName] = parseRelationship(
|
|
6822
|
+
relDef,
|
|
6823
|
+
`[models.${modelName}.relationships.${relName}]`,
|
|
6824
|
+
strict
|
|
6825
|
+
);
|
|
6901
6826
|
}
|
|
6902
6827
|
}
|
|
6903
6828
|
let uniqueConstraints;
|
|
6904
6829
|
if (modelDef.unique_constraints) {
|
|
6905
6830
|
uniqueConstraints = [];
|
|
6906
6831
|
for (const raw of modelDef.unique_constraints) {
|
|
6832
|
+
checkUnknownKeys(
|
|
6833
|
+
raw,
|
|
6834
|
+
KNOWN_UNIQUE_CONSTRAINT_KEYS,
|
|
6835
|
+
`[[models.${modelName}.unique_constraints]]`,
|
|
6836
|
+
strict
|
|
6837
|
+
);
|
|
6907
6838
|
uniqueConstraints.push({
|
|
6908
6839
|
name: raw.name,
|
|
6909
6840
|
fields: [...raw.fields]
|
|
6910
6841
|
});
|
|
6911
6842
|
}
|
|
6912
6843
|
}
|
|
6844
|
+
const className = typeof modelDef.class_name === "string" ? modelDef.class_name : void 0;
|
|
6913
6845
|
schemas.push(
|
|
6914
6846
|
defineModelSchema({
|
|
6915
6847
|
name: modelName,
|
|
6916
6848
|
fields,
|
|
6917
6849
|
options: {
|
|
6850
|
+
className,
|
|
6918
6851
|
uniqueConstraints,
|
|
6919
6852
|
relationships
|
|
6920
6853
|
}
|
package/dist/browser.d.cts
CHANGED
|
@@ -40,6 +40,13 @@ interface UniqueConstraintConfig {
|
|
|
40
40
|
}
|
|
41
41
|
interface ModelOptions {
|
|
42
42
|
name: string;
|
|
43
|
+
/**
|
|
44
|
+
* Optional PascalCase class name. Used by the v2 codegen to drive
|
|
45
|
+
* generated TypeScript class names (and relationship method names that
|
|
46
|
+
* derive from a target's class name). When absent, the v2 codegen
|
|
47
|
+
* falls back to suffix-based singularization of `name`.
|
|
48
|
+
*/
|
|
49
|
+
className?: string;
|
|
43
50
|
uniqueConstraints?: UniqueConstraintConfig[];
|
|
44
51
|
relationships?: Record<string, RelationshipConfig>;
|
|
45
52
|
}
|
|
@@ -663,9 +670,6 @@ declare class ModelRegistry {
|
|
|
663
670
|
private validateSessionModels;
|
|
664
671
|
}
|
|
665
672
|
|
|
666
|
-
declare function Field(options: FieldOptions): (target: any, propertyKey: string | symbol) => void;
|
|
667
|
-
declare function Model(options: ModelOptions): (targetClass: Function) => void;
|
|
668
|
-
|
|
669
673
|
interface SQLJSEngineOptions {
|
|
670
674
|
wasmURL?: string;
|
|
671
675
|
locateFile?: (file: string) => string;
|
|
@@ -751,7 +755,7 @@ interface InitJsBaoOptions {
|
|
|
751
755
|
/**
|
|
752
756
|
* Optional array of model classes to initialize.
|
|
753
757
|
* If not provided, the ORM will rely on models being registered
|
|
754
|
-
* via
|
|
758
|
+
* via attachAndRegisterModel (assuming they have been imported by the application).
|
|
755
759
|
*/
|
|
756
760
|
models?: (typeof BaseModel)[];
|
|
757
761
|
}
|
|
@@ -948,10 +952,22 @@ declare function schemaToToml(schema: DiscoveredSchema): string;
|
|
|
948
952
|
* - Compound unique constraints are [[models.*.unique_constraints]]
|
|
949
953
|
*/
|
|
950
954
|
|
|
955
|
+
interface LoadSchemaOptions {
|
|
956
|
+
/**
|
|
957
|
+
* When true (default), throw on unknown keys at the model, field,
|
|
958
|
+
* relationship, and unique-constraint level. When false, unknown
|
|
959
|
+
* keys are silently ignored (legacy behavior).
|
|
960
|
+
*/
|
|
961
|
+
strict?: boolean;
|
|
962
|
+
}
|
|
951
963
|
/**
|
|
952
964
|
* Parse a TOML string and return an array of DefinedModelSchema objects.
|
|
965
|
+
*
|
|
966
|
+
* By default operates in strict mode: unknown keys at the model, field,
|
|
967
|
+
* relationship, or unique-constraint level cause an error. Pass
|
|
968
|
+
* `{ strict: false }` to silently ignore unknown keys (legacy behavior).
|
|
953
969
|
*/
|
|
954
|
-
declare function loadSchemaFromTomlString(tomlString: string): DefinedModelSchema[];
|
|
970
|
+
declare function loadSchemaFromTomlString(tomlString: string, options?: LoadSchemaOptions): DefinedModelSchema[];
|
|
955
971
|
|
|
956
972
|
/**
|
|
957
973
|
* Meta Sync — writes _meta_* YMaps into a YDoc.
|
|
@@ -1000,4 +1016,4 @@ declare function syncModelMeta(yDoc: Y.Doc, modelName: string, schema: ModelSche
|
|
|
1000
1016
|
*/
|
|
1001
1017
|
declare function syncInferredMeta(yDoc: Y.Doc, modelName: string, recordData: Record<string, any>): void;
|
|
1002
1018
|
|
|
1003
|
-
export { type AddRelationMethod, type AggregationAliasDebugInfo, type AggregationOperation, type AggregationOptions, type AggregationResult, BaseModel, type DatabaseConfig, DatabaseEngine, type DatabaseEngineType, BrowserDatabaseFactory as DatabaseFactory, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema,
|
|
1019
|
+
export { type AddRelationMethod, type AggregationAliasDebugInfo, type AggregationOperation, type AggregationOptions, type AggregationResult, BaseModel, type DatabaseConfig, DatabaseEngine, type DatabaseEngineType, BrowserDatabaseFactory as DatabaseFactory, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, type FieldOptions, type FieldType, type GroupByField, type HasManyMethod, type HasManyThroughMethod, type InferAttrs, type InitJsBaoOptions, type InitJsBaoResult, LogLevel, Logger, type ModelConstructor, type ModelOptions, ModelRegistry, type PaginatedResult, type PaginationOptions, RecordNotFoundError, type RefersToMethod, type RegisteredModelInfo, type RemoveRelationMethod, type SQLJSEngineOptions, type Schema, SqljsEngine, type SqljsEngineOptions, StringSet, type StringSetMembership, type UniqueConstraintConfig, UniqueConstraintViolationError, attachAndRegisterModel, attachSchemaToClass, autoRegisterModel, clearMetaSyncCache, createModelClass, defineModelSchema, detectEnvironment, discoverModelNames, discoverSchema, features, generateULID, inferFieldType, initJsBao, isBrowser, isNode, loadSchemaFromTomlString, registerFunctionDefault, resetJsBao, schemaToToml, syncInferredMeta, syncModelMeta };
|
package/dist/browser.d.ts
CHANGED
|
@@ -40,6 +40,13 @@ interface UniqueConstraintConfig {
|
|
|
40
40
|
}
|
|
41
41
|
interface ModelOptions {
|
|
42
42
|
name: string;
|
|
43
|
+
/**
|
|
44
|
+
* Optional PascalCase class name. Used by the v2 codegen to drive
|
|
45
|
+
* generated TypeScript class names (and relationship method names that
|
|
46
|
+
* derive from a target's class name). When absent, the v2 codegen
|
|
47
|
+
* falls back to suffix-based singularization of `name`.
|
|
48
|
+
*/
|
|
49
|
+
className?: string;
|
|
43
50
|
uniqueConstraints?: UniqueConstraintConfig[];
|
|
44
51
|
relationships?: Record<string, RelationshipConfig>;
|
|
45
52
|
}
|
|
@@ -663,9 +670,6 @@ declare class ModelRegistry {
|
|
|
663
670
|
private validateSessionModels;
|
|
664
671
|
}
|
|
665
672
|
|
|
666
|
-
declare function Field(options: FieldOptions): (target: any, propertyKey: string | symbol) => void;
|
|
667
|
-
declare function Model(options: ModelOptions): (targetClass: Function) => void;
|
|
668
|
-
|
|
669
673
|
interface SQLJSEngineOptions {
|
|
670
674
|
wasmURL?: string;
|
|
671
675
|
locateFile?: (file: string) => string;
|
|
@@ -751,7 +755,7 @@ interface InitJsBaoOptions {
|
|
|
751
755
|
/**
|
|
752
756
|
* Optional array of model classes to initialize.
|
|
753
757
|
* If not provided, the ORM will rely on models being registered
|
|
754
|
-
* via
|
|
758
|
+
* via attachAndRegisterModel (assuming they have been imported by the application).
|
|
755
759
|
*/
|
|
756
760
|
models?: (typeof BaseModel)[];
|
|
757
761
|
}
|
|
@@ -948,10 +952,22 @@ declare function schemaToToml(schema: DiscoveredSchema): string;
|
|
|
948
952
|
* - Compound unique constraints are [[models.*.unique_constraints]]
|
|
949
953
|
*/
|
|
950
954
|
|
|
955
|
+
interface LoadSchemaOptions {
|
|
956
|
+
/**
|
|
957
|
+
* When true (default), throw on unknown keys at the model, field,
|
|
958
|
+
* relationship, and unique-constraint level. When false, unknown
|
|
959
|
+
* keys are silently ignored (legacy behavior).
|
|
960
|
+
*/
|
|
961
|
+
strict?: boolean;
|
|
962
|
+
}
|
|
951
963
|
/**
|
|
952
964
|
* Parse a TOML string and return an array of DefinedModelSchema objects.
|
|
965
|
+
*
|
|
966
|
+
* By default operates in strict mode: unknown keys at the model, field,
|
|
967
|
+
* relationship, or unique-constraint level cause an error. Pass
|
|
968
|
+
* `{ strict: false }` to silently ignore unknown keys (legacy behavior).
|
|
953
969
|
*/
|
|
954
|
-
declare function loadSchemaFromTomlString(tomlString: string): DefinedModelSchema[];
|
|
970
|
+
declare function loadSchemaFromTomlString(tomlString: string, options?: LoadSchemaOptions): DefinedModelSchema[];
|
|
955
971
|
|
|
956
972
|
/**
|
|
957
973
|
* Meta Sync — writes _meta_* YMaps into a YDoc.
|
|
@@ -1000,4 +1016,4 @@ declare function syncModelMeta(yDoc: Y.Doc, modelName: string, schema: ModelSche
|
|
|
1000
1016
|
*/
|
|
1001
1017
|
declare function syncInferredMeta(yDoc: Y.Doc, modelName: string, recordData: Record<string, any>): void;
|
|
1002
1018
|
|
|
1003
|
-
export { type AddRelationMethod, type AggregationAliasDebugInfo, type AggregationOperation, type AggregationOptions, type AggregationResult, BaseModel, type DatabaseConfig, DatabaseEngine, type DatabaseEngineType, BrowserDatabaseFactory as DatabaseFactory, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema,
|
|
1019
|
+
export { type AddRelationMethod, type AggregationAliasDebugInfo, type AggregationOperation, type AggregationOptions, type AggregationResult, BaseModel, type DatabaseConfig, DatabaseEngine, type DatabaseEngineType, BrowserDatabaseFactory as DatabaseFactory, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, type FieldOptions, type FieldType, type GroupByField, type HasManyMethod, type HasManyThroughMethod, type InferAttrs, type InitJsBaoOptions, type InitJsBaoResult, LogLevel, Logger, type ModelConstructor, type ModelOptions, ModelRegistry, type PaginatedResult, type PaginationOptions, RecordNotFoundError, type RefersToMethod, type RegisteredModelInfo, type RemoveRelationMethod, type SQLJSEngineOptions, type Schema, SqljsEngine, type SqljsEngineOptions, StringSet, type StringSetMembership, type UniqueConstraintConfig, UniqueConstraintViolationError, attachAndRegisterModel, attachSchemaToClass, autoRegisterModel, clearMetaSyncCache, createModelClass, defineModelSchema, detectEnvironment, discoverModelNames, discoverSchema, features, generateULID, inferFieldType, initJsBao, isBrowser, isNode, loadSchemaFromTomlString, registerFunctionDefault, resetJsBao, schemaToToml, syncInferredMeta, syncModelMeta };
|