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/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
|
|
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;
|
|
@@ -5533,11 +5533,11 @@ var init_BaseModel = __esm({
|
|
|
5533
5533
|
});
|
|
5534
5534
|
|
|
5535
5535
|
// src/engines/SqljsEngine.ts
|
|
5536
|
-
var
|
|
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
|
-
|
|
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,
|
|
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) {
|
|
@@ -7092,6 +6965,7 @@ function defineModelSchema(input) {
|
|
|
7092
6965
|
const { name, fields } = input;
|
|
7093
6966
|
const options = {
|
|
7094
6967
|
name,
|
|
6968
|
+
className: input.options?.className,
|
|
7095
6969
|
uniqueConstraints: input.options?.uniqueConstraints ? [...input.options.uniqueConstraints] : void 0,
|
|
7096
6970
|
relationships: input.options?.relationships
|
|
7097
6971
|
};
|
|
@@ -7191,18 +7065,13 @@ function resolveUniqueConstraints(modelName, fields, customConstraints) {
|
|
|
7191
7065
|
function attachSchemaToClass(modelClass, schema) {
|
|
7192
7066
|
modelClass.schema = schema;
|
|
7193
7067
|
modelClass.modelName = schema.options.name;
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
value: function() {
|
|
7197
|
-
return schema.buildRuntimeShape(modelClass);
|
|
7198
|
-
},
|
|
7199
|
-
writable: false
|
|
7200
|
-
});
|
|
7201
|
-
} else {
|
|
7202
|
-
modelClass.getSchema = function() {
|
|
7068
|
+
Object.defineProperty(modelClass, "getSchema", {
|
|
7069
|
+
value: function() {
|
|
7203
7070
|
return schema.buildRuntimeShape(modelClass);
|
|
7204
|
-
}
|
|
7205
|
-
|
|
7071
|
+
},
|
|
7072
|
+
writable: false,
|
|
7073
|
+
configurable: true
|
|
7074
|
+
});
|
|
7206
7075
|
const runtimeShape = schema.buildRuntimeShape(modelClass);
|
|
7207
7076
|
BaseModel2.attachFieldAccessors(modelClass, runtimeShape.fields);
|
|
7208
7077
|
return runtimeShape;
|
|
@@ -7435,12 +7304,52 @@ var VALID_FIELD_TYPES = /* @__PURE__ */ new Set([
|
|
|
7435
7304
|
"id",
|
|
7436
7305
|
"stringset"
|
|
7437
7306
|
]);
|
|
7438
|
-
|
|
7307
|
+
var KNOWN_FIELD_KEYS = /* @__PURE__ */ new Set([
|
|
7308
|
+
"type",
|
|
7309
|
+
"indexed",
|
|
7310
|
+
"unique",
|
|
7311
|
+
"required",
|
|
7312
|
+
"auto_assign",
|
|
7313
|
+
"max_length",
|
|
7314
|
+
"max_count",
|
|
7315
|
+
"default"
|
|
7316
|
+
]);
|
|
7317
|
+
var KNOWN_MODEL_KEYS = /* @__PURE__ */ new Set([
|
|
7318
|
+
"fields",
|
|
7319
|
+
"relationships",
|
|
7320
|
+
"unique_constraints",
|
|
7321
|
+
"class_name"
|
|
7322
|
+
]);
|
|
7323
|
+
var KNOWN_RELATIONSHIP_KEYS = /* @__PURE__ */ new Set([
|
|
7324
|
+
"type",
|
|
7325
|
+
"model",
|
|
7326
|
+
"related_id_field",
|
|
7327
|
+
"join_model",
|
|
7328
|
+
"join_model_local_field",
|
|
7329
|
+
"join_model_related_field",
|
|
7330
|
+
"order_by_field",
|
|
7331
|
+
"order_direction",
|
|
7332
|
+
"join_model_order_by_field",
|
|
7333
|
+
"join_model_order_direction"
|
|
7334
|
+
]);
|
|
7335
|
+
var KNOWN_UNIQUE_CONSTRAINT_KEYS = /* @__PURE__ */ new Set(["name", "fields"]);
|
|
7336
|
+
function checkUnknownKeys(raw, known, context, strict) {
|
|
7337
|
+
if (!strict) return;
|
|
7338
|
+
for (const key of Object.keys(raw)) {
|
|
7339
|
+
if (!known.has(key)) {
|
|
7340
|
+
throw new Error(
|
|
7341
|
+
`${context}: unknown key "${key}". Allowed: ${[...known].join(", ")}`
|
|
7342
|
+
);
|
|
7343
|
+
}
|
|
7344
|
+
}
|
|
7345
|
+
}
|
|
7346
|
+
function parseFieldOptions(raw, context, strict) {
|
|
7439
7347
|
if (!raw.type || !VALID_FIELD_TYPES.has(raw.type)) {
|
|
7440
7348
|
throw new Error(
|
|
7441
7349
|
`Invalid field type "${raw.type}". Must be one of: ${[...VALID_FIELD_TYPES].join(", ")}`
|
|
7442
7350
|
);
|
|
7443
7351
|
}
|
|
7352
|
+
checkUnknownKeys(raw, KNOWN_FIELD_KEYS, context, strict);
|
|
7444
7353
|
const opts = { type: raw.type };
|
|
7445
7354
|
if (raw.indexed === true) opts.indexed = true;
|
|
7446
7355
|
if (raw.unique === true) opts.unique = true;
|
|
@@ -7456,8 +7365,9 @@ function requireField(raw, field, context) {
|
|
|
7456
7365
|
throw new Error(`Relationship ${context}: missing required field "${field}"`);
|
|
7457
7366
|
}
|
|
7458
7367
|
}
|
|
7459
|
-
function parseRelationship(raw) {
|
|
7368
|
+
function parseRelationship(raw, context, strict) {
|
|
7460
7369
|
const type = raw.type;
|
|
7370
|
+
checkUnknownKeys(raw, KNOWN_RELATIONSHIP_KEYS, context, strict);
|
|
7461
7371
|
if (type === "refersTo") {
|
|
7462
7372
|
requireField(raw, "model", "refersTo");
|
|
7463
7373
|
requireField(raw, "related_id_field", "refersTo");
|
|
@@ -7499,7 +7409,8 @@ function parseRelationship(raw) {
|
|
|
7499
7409
|
}
|
|
7500
7410
|
throw new Error(`Unknown relationship type: ${type}`);
|
|
7501
7411
|
}
|
|
7502
|
-
function loadSchemaFromTomlString(tomlString) {
|
|
7412
|
+
function loadSchemaFromTomlString(tomlString, options = {}) {
|
|
7413
|
+
const strict = options.strict !== false;
|
|
7503
7414
|
const parsed = (0, import_smol_toml.parse)(tomlString);
|
|
7504
7415
|
const models = parsed.models;
|
|
7505
7416
|
if (!models || typeof models !== "object") {
|
|
@@ -7507,10 +7418,20 @@ function loadSchemaFromTomlString(tomlString) {
|
|
|
7507
7418
|
}
|
|
7508
7419
|
const schemas = [];
|
|
7509
7420
|
for (const [modelName, modelDef] of Object.entries(models)) {
|
|
7421
|
+
checkUnknownKeys(
|
|
7422
|
+
modelDef,
|
|
7423
|
+
KNOWN_MODEL_KEYS,
|
|
7424
|
+
`[models.${modelName}]`,
|
|
7425
|
+
strict
|
|
7426
|
+
);
|
|
7510
7427
|
const fields = {};
|
|
7511
7428
|
if (modelDef.fields) {
|
|
7512
7429
|
for (const [fieldName, fieldDef] of Object.entries(modelDef.fields)) {
|
|
7513
|
-
fields[fieldName] = parseFieldOptions(
|
|
7430
|
+
fields[fieldName] = parseFieldOptions(
|
|
7431
|
+
fieldDef,
|
|
7432
|
+
`[models.${modelName}.fields.${fieldName}]`,
|
|
7433
|
+
strict
|
|
7434
|
+
);
|
|
7514
7435
|
}
|
|
7515
7436
|
}
|
|
7516
7437
|
let relationships;
|
|
@@ -7519,24 +7440,36 @@ function loadSchemaFromTomlString(tomlString) {
|
|
|
7519
7440
|
for (const [relName, relDef] of Object.entries(
|
|
7520
7441
|
modelDef.relationships
|
|
7521
7442
|
)) {
|
|
7522
|
-
relationships[relName] = parseRelationship(
|
|
7443
|
+
relationships[relName] = parseRelationship(
|
|
7444
|
+
relDef,
|
|
7445
|
+
`[models.${modelName}.relationships.${relName}]`,
|
|
7446
|
+
strict
|
|
7447
|
+
);
|
|
7523
7448
|
}
|
|
7524
7449
|
}
|
|
7525
7450
|
let uniqueConstraints;
|
|
7526
7451
|
if (modelDef.unique_constraints) {
|
|
7527
7452
|
uniqueConstraints = [];
|
|
7528
7453
|
for (const raw of modelDef.unique_constraints) {
|
|
7454
|
+
checkUnknownKeys(
|
|
7455
|
+
raw,
|
|
7456
|
+
KNOWN_UNIQUE_CONSTRAINT_KEYS,
|
|
7457
|
+
`[[models.${modelName}.unique_constraints]]`,
|
|
7458
|
+
strict
|
|
7459
|
+
);
|
|
7529
7460
|
uniqueConstraints.push({
|
|
7530
7461
|
name: raw.name,
|
|
7531
7462
|
fields: [...raw.fields]
|
|
7532
7463
|
});
|
|
7533
7464
|
}
|
|
7534
7465
|
}
|
|
7466
|
+
const className = typeof modelDef.class_name === "string" ? modelDef.class_name : void 0;
|
|
7535
7467
|
schemas.push(
|
|
7536
7468
|
defineModelSchema({
|
|
7537
7469
|
name: modelName,
|
|
7538
7470
|
fields,
|
|
7539
7471
|
options: {
|
|
7472
|
+
className,
|
|
7540
7473
|
uniqueConstraints,
|
|
7541
7474
|
relationships
|
|
7542
7475
|
}
|
|
@@ -7545,10 +7478,10 @@ function loadSchemaFromTomlString(tomlString) {
|
|
|
7545
7478
|
}
|
|
7546
7479
|
return schemas;
|
|
7547
7480
|
}
|
|
7548
|
-
async function loadSchemaFromToml(filePath) {
|
|
7481
|
+
async function loadSchemaFromToml(filePath, options = {}) {
|
|
7549
7482
|
const { readFile } = await import("fs/promises");
|
|
7550
7483
|
const content = await readFile(filePath, "utf-8");
|
|
7551
|
-
return loadSchemaFromTomlString(content);
|
|
7484
|
+
return loadSchemaFromTomlString(content, options);
|
|
7552
7485
|
}
|
|
7553
7486
|
|
|
7554
7487
|
// src/node.ts
|
|
@@ -7627,10 +7560,8 @@ async function getRecommendedNodeEngine() {
|
|
|
7627
7560
|
BaseModel,
|
|
7628
7561
|
DatabaseEngine,
|
|
7629
7562
|
DatabaseFactory,
|
|
7630
|
-
Field,
|
|
7631
7563
|
LogLevel,
|
|
7632
7564
|
Logger,
|
|
7633
|
-
Model,
|
|
7634
7565
|
ModelRegistry,
|
|
7635
7566
|
RecordNotFoundError,
|
|
7636
7567
|
SqljsEngine,
|
package/dist/node.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
|
type NodeSqliteEngineOptions$1 = {
|
|
670
674
|
filePath?: string;
|
|
671
675
|
options?: {
|
|
@@ -769,7 +773,7 @@ interface InitJsBaoOptions {
|
|
|
769
773
|
/**
|
|
770
774
|
* Optional array of model classes to initialize.
|
|
771
775
|
* If not provided, the ORM will rely on models being registered
|
|
772
|
-
* via
|
|
776
|
+
* via attachAndRegisterModel (assuming they have been imported by the application).
|
|
773
777
|
*/
|
|
774
778
|
models?: (typeof BaseModel)[];
|
|
775
779
|
}
|
|
@@ -977,15 +981,27 @@ declare function schemaToToml(schema: DiscoveredSchema): string;
|
|
|
977
981
|
* - Compound unique constraints are [[models.*.unique_constraints]]
|
|
978
982
|
*/
|
|
979
983
|
|
|
984
|
+
interface LoadSchemaOptions {
|
|
985
|
+
/**
|
|
986
|
+
* When true (default), throw on unknown keys at the model, field,
|
|
987
|
+
* relationship, and unique-constraint level. When false, unknown
|
|
988
|
+
* keys are silently ignored (legacy behavior).
|
|
989
|
+
*/
|
|
990
|
+
strict?: boolean;
|
|
991
|
+
}
|
|
980
992
|
/**
|
|
981
993
|
* Parse a TOML string and return an array of DefinedModelSchema objects.
|
|
994
|
+
*
|
|
995
|
+
* By default operates in strict mode: unknown keys at the model, field,
|
|
996
|
+
* relationship, or unique-constraint level cause an error. Pass
|
|
997
|
+
* `{ strict: false }` to silently ignore unknown keys (legacy behavior).
|
|
982
998
|
*/
|
|
983
|
-
declare function loadSchemaFromTomlString(tomlString: string): DefinedModelSchema[];
|
|
999
|
+
declare function loadSchemaFromTomlString(tomlString: string, options?: LoadSchemaOptions): DefinedModelSchema[];
|
|
984
1000
|
/**
|
|
985
1001
|
* Read a TOML file from disk and return an array of DefinedModelSchema objects.
|
|
986
1002
|
* Only available in Node.js environments.
|
|
987
1003
|
*/
|
|
988
|
-
declare function loadSchemaFromToml(filePath: string): Promise<DefinedModelSchema[]>;
|
|
1004
|
+
declare function loadSchemaFromToml(filePath: string, options?: LoadSchemaOptions): Promise<DefinedModelSchema[]>;
|
|
989
1005
|
|
|
990
1006
|
/**
|
|
991
1007
|
* Meta Sync — writes _meta_* YMaps into a YDoc.
|
|
@@ -1077,4 +1093,4 @@ declare function summarizePlainYDoc(dump: PlainYDoc): DumpSummary;
|
|
|
1077
1093
|
|
|
1078
1094
|
declare function getRecommendedNodeEngine(): Promise<string>;
|
|
1079
1095
|
|
|
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,
|
|
1096
|
+
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
|
@@ -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
|
type NodeSqliteEngineOptions$1 = {
|
|
670
674
|
filePath?: string;
|
|
671
675
|
options?: {
|
|
@@ -769,7 +773,7 @@ interface InitJsBaoOptions {
|
|
|
769
773
|
/**
|
|
770
774
|
* Optional array of model classes to initialize.
|
|
771
775
|
* If not provided, the ORM will rely on models being registered
|
|
772
|
-
* via
|
|
776
|
+
* via attachAndRegisterModel (assuming they have been imported by the application).
|
|
773
777
|
*/
|
|
774
778
|
models?: (typeof BaseModel)[];
|
|
775
779
|
}
|
|
@@ -977,15 +981,27 @@ declare function schemaToToml(schema: DiscoveredSchema): string;
|
|
|
977
981
|
* - Compound unique constraints are [[models.*.unique_constraints]]
|
|
978
982
|
*/
|
|
979
983
|
|
|
984
|
+
interface LoadSchemaOptions {
|
|
985
|
+
/**
|
|
986
|
+
* When true (default), throw on unknown keys at the model, field,
|
|
987
|
+
* relationship, and unique-constraint level. When false, unknown
|
|
988
|
+
* keys are silently ignored (legacy behavior).
|
|
989
|
+
*/
|
|
990
|
+
strict?: boolean;
|
|
991
|
+
}
|
|
980
992
|
/**
|
|
981
993
|
* Parse a TOML string and return an array of DefinedModelSchema objects.
|
|
994
|
+
*
|
|
995
|
+
* By default operates in strict mode: unknown keys at the model, field,
|
|
996
|
+
* relationship, or unique-constraint level cause an error. Pass
|
|
997
|
+
* `{ strict: false }` to silently ignore unknown keys (legacy behavior).
|
|
982
998
|
*/
|
|
983
|
-
declare function loadSchemaFromTomlString(tomlString: string): DefinedModelSchema[];
|
|
999
|
+
declare function loadSchemaFromTomlString(tomlString: string, options?: LoadSchemaOptions): DefinedModelSchema[];
|
|
984
1000
|
/**
|
|
985
1001
|
* Read a TOML file from disk and return an array of DefinedModelSchema objects.
|
|
986
1002
|
* Only available in Node.js environments.
|
|
987
1003
|
*/
|
|
988
|
-
declare function loadSchemaFromToml(filePath: string): Promise<DefinedModelSchema[]>;
|
|
1004
|
+
declare function loadSchemaFromToml(filePath: string, options?: LoadSchemaOptions): Promise<DefinedModelSchema[]>;
|
|
989
1005
|
|
|
990
1006
|
/**
|
|
991
1007
|
* Meta Sync — writes _meta_* YMaps into a YDoc.
|
|
@@ -1077,4 +1093,4 @@ declare function summarizePlainYDoc(dump: PlainYDoc): DumpSummary;
|
|
|
1077
1093
|
|
|
1078
1094
|
declare function getRecommendedNodeEngine(): Promise<string>;
|
|
1079
1095
|
|
|
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,
|
|
1096
|
+
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 };
|