js-bao 0.4.0 → 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 +76 -16
- package/dist/browser.d.cts +20 -1
- package/dist/browser.d.ts +20 -1
- package/dist/browser.js +76 -16
- 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 +7 -10
- package/dist/index.cjs +78 -18
- package/dist/index.d.cts +21 -2
- package/dist/index.d.ts +21 -2
- package/dist/index.js +78 -18
- package/dist/node.cjs +78 -18
- package/dist/node.d.cts +21 -2
- package/dist/node.d.ts +21 -2
- package/dist/node.js +78 -18
- package/package.json +7 -10
package/dist/browser.cjs
CHANGED
|
@@ -6343,6 +6343,7 @@ function defineModelSchema(input) {
|
|
|
6343
6343
|
const { name, fields } = input;
|
|
6344
6344
|
const options = {
|
|
6345
6345
|
name,
|
|
6346
|
+
className: input.options?.className,
|
|
6346
6347
|
uniqueConstraints: input.options?.uniqueConstraints ? [...input.options.uniqueConstraints] : void 0,
|
|
6347
6348
|
relationships: input.options?.relationships
|
|
6348
6349
|
};
|
|
@@ -6442,18 +6443,13 @@ function resolveUniqueConstraints(modelName, fields, customConstraints) {
|
|
|
6442
6443
|
function attachSchemaToClass(modelClass, schema) {
|
|
6443
6444
|
modelClass.schema = schema;
|
|
6444
6445
|
modelClass.modelName = schema.options.name;
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
value: function() {
|
|
6448
|
-
return schema.buildRuntimeShape(modelClass);
|
|
6449
|
-
},
|
|
6450
|
-
writable: false
|
|
6451
|
-
});
|
|
6452
|
-
} else {
|
|
6453
|
-
modelClass.getSchema = function() {
|
|
6446
|
+
Object.defineProperty(modelClass, "getSchema", {
|
|
6447
|
+
value: function() {
|
|
6454
6448
|
return schema.buildRuntimeShape(modelClass);
|
|
6455
|
-
}
|
|
6456
|
-
|
|
6449
|
+
},
|
|
6450
|
+
writable: false,
|
|
6451
|
+
configurable: true
|
|
6452
|
+
});
|
|
6457
6453
|
const runtimeShape = schema.buildRuntimeShape(modelClass);
|
|
6458
6454
|
BaseModel2.attachFieldAccessors(modelClass, runtimeShape.fields);
|
|
6459
6455
|
return runtimeShape;
|
|
@@ -6686,12 +6682,52 @@ var VALID_FIELD_TYPES = /* @__PURE__ */ new Set([
|
|
|
6686
6682
|
"id",
|
|
6687
6683
|
"stringset"
|
|
6688
6684
|
]);
|
|
6689
|
-
|
|
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) {
|
|
6690
6725
|
if (!raw.type || !VALID_FIELD_TYPES.has(raw.type)) {
|
|
6691
6726
|
throw new Error(
|
|
6692
6727
|
`Invalid field type "${raw.type}". Must be one of: ${[...VALID_FIELD_TYPES].join(", ")}`
|
|
6693
6728
|
);
|
|
6694
6729
|
}
|
|
6730
|
+
checkUnknownKeys(raw, KNOWN_FIELD_KEYS, context, strict);
|
|
6695
6731
|
const opts = { type: raw.type };
|
|
6696
6732
|
if (raw.indexed === true) opts.indexed = true;
|
|
6697
6733
|
if (raw.unique === true) opts.unique = true;
|
|
@@ -6707,8 +6743,9 @@ function requireField(raw, field, context) {
|
|
|
6707
6743
|
throw new Error(`Relationship ${context}: missing required field "${field}"`);
|
|
6708
6744
|
}
|
|
6709
6745
|
}
|
|
6710
|
-
function parseRelationship(raw) {
|
|
6746
|
+
function parseRelationship(raw, context, strict) {
|
|
6711
6747
|
const type = raw.type;
|
|
6748
|
+
checkUnknownKeys(raw, KNOWN_RELATIONSHIP_KEYS, context, strict);
|
|
6712
6749
|
if (type === "refersTo") {
|
|
6713
6750
|
requireField(raw, "model", "refersTo");
|
|
6714
6751
|
requireField(raw, "related_id_field", "refersTo");
|
|
@@ -6750,7 +6787,8 @@ function parseRelationship(raw) {
|
|
|
6750
6787
|
}
|
|
6751
6788
|
throw new Error(`Unknown relationship type: ${type}`);
|
|
6752
6789
|
}
|
|
6753
|
-
function loadSchemaFromTomlString(tomlString) {
|
|
6790
|
+
function loadSchemaFromTomlString(tomlString, options = {}) {
|
|
6791
|
+
const strict = options.strict !== false;
|
|
6754
6792
|
const parsed = (0, import_smol_toml.parse)(tomlString);
|
|
6755
6793
|
const models = parsed.models;
|
|
6756
6794
|
if (!models || typeof models !== "object") {
|
|
@@ -6758,10 +6796,20 @@ function loadSchemaFromTomlString(tomlString) {
|
|
|
6758
6796
|
}
|
|
6759
6797
|
const schemas = [];
|
|
6760
6798
|
for (const [modelName, modelDef] of Object.entries(models)) {
|
|
6799
|
+
checkUnknownKeys(
|
|
6800
|
+
modelDef,
|
|
6801
|
+
KNOWN_MODEL_KEYS,
|
|
6802
|
+
`[models.${modelName}]`,
|
|
6803
|
+
strict
|
|
6804
|
+
);
|
|
6761
6805
|
const fields = {};
|
|
6762
6806
|
if (modelDef.fields) {
|
|
6763
6807
|
for (const [fieldName, fieldDef] of Object.entries(modelDef.fields)) {
|
|
6764
|
-
fields[fieldName] = parseFieldOptions(
|
|
6808
|
+
fields[fieldName] = parseFieldOptions(
|
|
6809
|
+
fieldDef,
|
|
6810
|
+
`[models.${modelName}.fields.${fieldName}]`,
|
|
6811
|
+
strict
|
|
6812
|
+
);
|
|
6765
6813
|
}
|
|
6766
6814
|
}
|
|
6767
6815
|
let relationships;
|
|
@@ -6770,24 +6818,36 @@ function loadSchemaFromTomlString(tomlString) {
|
|
|
6770
6818
|
for (const [relName, relDef] of Object.entries(
|
|
6771
6819
|
modelDef.relationships
|
|
6772
6820
|
)) {
|
|
6773
|
-
relationships[relName] = parseRelationship(
|
|
6821
|
+
relationships[relName] = parseRelationship(
|
|
6822
|
+
relDef,
|
|
6823
|
+
`[models.${modelName}.relationships.${relName}]`,
|
|
6824
|
+
strict
|
|
6825
|
+
);
|
|
6774
6826
|
}
|
|
6775
6827
|
}
|
|
6776
6828
|
let uniqueConstraints;
|
|
6777
6829
|
if (modelDef.unique_constraints) {
|
|
6778
6830
|
uniqueConstraints = [];
|
|
6779
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
|
+
);
|
|
6780
6838
|
uniqueConstraints.push({
|
|
6781
6839
|
name: raw.name,
|
|
6782
6840
|
fields: [...raw.fields]
|
|
6783
6841
|
});
|
|
6784
6842
|
}
|
|
6785
6843
|
}
|
|
6844
|
+
const className = typeof modelDef.class_name === "string" ? modelDef.class_name : void 0;
|
|
6786
6845
|
schemas.push(
|
|
6787
6846
|
defineModelSchema({
|
|
6788
6847
|
name: modelName,
|
|
6789
6848
|
fields,
|
|
6790
6849
|
options: {
|
|
6850
|
+
className,
|
|
6791
6851
|
uniqueConstraints,
|
|
6792
6852
|
relationships
|
|
6793
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
|
}
|
|
@@ -945,10 +952,22 @@ declare function schemaToToml(schema: DiscoveredSchema): string;
|
|
|
945
952
|
* - Compound unique constraints are [[models.*.unique_constraints]]
|
|
946
953
|
*/
|
|
947
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
|
+
}
|
|
948
963
|
/**
|
|
949
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).
|
|
950
969
|
*/
|
|
951
|
-
declare function loadSchemaFromTomlString(tomlString: string): DefinedModelSchema[];
|
|
970
|
+
declare function loadSchemaFromTomlString(tomlString: string, options?: LoadSchemaOptions): DefinedModelSchema[];
|
|
952
971
|
|
|
953
972
|
/**
|
|
954
973
|
* Meta Sync — writes _meta_* YMaps into a YDoc.
|
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
|
}
|
|
@@ -945,10 +952,22 @@ declare function schemaToToml(schema: DiscoveredSchema): string;
|
|
|
945
952
|
* - Compound unique constraints are [[models.*.unique_constraints]]
|
|
946
953
|
*/
|
|
947
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
|
+
}
|
|
948
963
|
/**
|
|
949
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).
|
|
950
969
|
*/
|
|
951
|
-
declare function loadSchemaFromTomlString(tomlString: string): DefinedModelSchema[];
|
|
970
|
+
declare function loadSchemaFromTomlString(tomlString: string, options?: LoadSchemaOptions): DefinedModelSchema[];
|
|
952
971
|
|
|
953
972
|
/**
|
|
954
973
|
* Meta Sync — writes _meta_* YMaps into a YDoc.
|
package/dist/browser.js
CHANGED
|
@@ -6286,6 +6286,7 @@ function defineModelSchema(input) {
|
|
|
6286
6286
|
const { name, fields } = input;
|
|
6287
6287
|
const options = {
|
|
6288
6288
|
name,
|
|
6289
|
+
className: input.options?.className,
|
|
6289
6290
|
uniqueConstraints: input.options?.uniqueConstraints ? [...input.options.uniqueConstraints] : void 0,
|
|
6290
6291
|
relationships: input.options?.relationships
|
|
6291
6292
|
};
|
|
@@ -6385,18 +6386,13 @@ function resolveUniqueConstraints(modelName, fields, customConstraints) {
|
|
|
6385
6386
|
function attachSchemaToClass(modelClass, schema) {
|
|
6386
6387
|
modelClass.schema = schema;
|
|
6387
6388
|
modelClass.modelName = schema.options.name;
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
value: function() {
|
|
6391
|
-
return schema.buildRuntimeShape(modelClass);
|
|
6392
|
-
},
|
|
6393
|
-
writable: false
|
|
6394
|
-
});
|
|
6395
|
-
} else {
|
|
6396
|
-
modelClass.getSchema = function() {
|
|
6389
|
+
Object.defineProperty(modelClass, "getSchema", {
|
|
6390
|
+
value: function() {
|
|
6397
6391
|
return schema.buildRuntimeShape(modelClass);
|
|
6398
|
-
}
|
|
6399
|
-
|
|
6392
|
+
},
|
|
6393
|
+
writable: false,
|
|
6394
|
+
configurable: true
|
|
6395
|
+
});
|
|
6400
6396
|
const runtimeShape = schema.buildRuntimeShape(modelClass);
|
|
6401
6397
|
BaseModel2.attachFieldAccessors(modelClass, runtimeShape.fields);
|
|
6402
6398
|
return runtimeShape;
|
|
@@ -6629,12 +6625,52 @@ var VALID_FIELD_TYPES = /* @__PURE__ */ new Set([
|
|
|
6629
6625
|
"id",
|
|
6630
6626
|
"stringset"
|
|
6631
6627
|
]);
|
|
6632
|
-
|
|
6628
|
+
var KNOWN_FIELD_KEYS = /* @__PURE__ */ new Set([
|
|
6629
|
+
"type",
|
|
6630
|
+
"indexed",
|
|
6631
|
+
"unique",
|
|
6632
|
+
"required",
|
|
6633
|
+
"auto_assign",
|
|
6634
|
+
"max_length",
|
|
6635
|
+
"max_count",
|
|
6636
|
+
"default"
|
|
6637
|
+
]);
|
|
6638
|
+
var KNOWN_MODEL_KEYS = /* @__PURE__ */ new Set([
|
|
6639
|
+
"fields",
|
|
6640
|
+
"relationships",
|
|
6641
|
+
"unique_constraints",
|
|
6642
|
+
"class_name"
|
|
6643
|
+
]);
|
|
6644
|
+
var KNOWN_RELATIONSHIP_KEYS = /* @__PURE__ */ new Set([
|
|
6645
|
+
"type",
|
|
6646
|
+
"model",
|
|
6647
|
+
"related_id_field",
|
|
6648
|
+
"join_model",
|
|
6649
|
+
"join_model_local_field",
|
|
6650
|
+
"join_model_related_field",
|
|
6651
|
+
"order_by_field",
|
|
6652
|
+
"order_direction",
|
|
6653
|
+
"join_model_order_by_field",
|
|
6654
|
+
"join_model_order_direction"
|
|
6655
|
+
]);
|
|
6656
|
+
var KNOWN_UNIQUE_CONSTRAINT_KEYS = /* @__PURE__ */ new Set(["name", "fields"]);
|
|
6657
|
+
function checkUnknownKeys(raw, known, context, strict) {
|
|
6658
|
+
if (!strict) return;
|
|
6659
|
+
for (const key of Object.keys(raw)) {
|
|
6660
|
+
if (!known.has(key)) {
|
|
6661
|
+
throw new Error(
|
|
6662
|
+
`${context}: unknown key "${key}". Allowed: ${[...known].join(", ")}`
|
|
6663
|
+
);
|
|
6664
|
+
}
|
|
6665
|
+
}
|
|
6666
|
+
}
|
|
6667
|
+
function parseFieldOptions(raw, context, strict) {
|
|
6633
6668
|
if (!raw.type || !VALID_FIELD_TYPES.has(raw.type)) {
|
|
6634
6669
|
throw new Error(
|
|
6635
6670
|
`Invalid field type "${raw.type}". Must be one of: ${[...VALID_FIELD_TYPES].join(", ")}`
|
|
6636
6671
|
);
|
|
6637
6672
|
}
|
|
6673
|
+
checkUnknownKeys(raw, KNOWN_FIELD_KEYS, context, strict);
|
|
6638
6674
|
const opts = { type: raw.type };
|
|
6639
6675
|
if (raw.indexed === true) opts.indexed = true;
|
|
6640
6676
|
if (raw.unique === true) opts.unique = true;
|
|
@@ -6650,8 +6686,9 @@ function requireField(raw, field, context) {
|
|
|
6650
6686
|
throw new Error(`Relationship ${context}: missing required field "${field}"`);
|
|
6651
6687
|
}
|
|
6652
6688
|
}
|
|
6653
|
-
function parseRelationship(raw) {
|
|
6689
|
+
function parseRelationship(raw, context, strict) {
|
|
6654
6690
|
const type = raw.type;
|
|
6691
|
+
checkUnknownKeys(raw, KNOWN_RELATIONSHIP_KEYS, context, strict);
|
|
6655
6692
|
if (type === "refersTo") {
|
|
6656
6693
|
requireField(raw, "model", "refersTo");
|
|
6657
6694
|
requireField(raw, "related_id_field", "refersTo");
|
|
@@ -6693,7 +6730,8 @@ function parseRelationship(raw) {
|
|
|
6693
6730
|
}
|
|
6694
6731
|
throw new Error(`Unknown relationship type: ${type}`);
|
|
6695
6732
|
}
|
|
6696
|
-
function loadSchemaFromTomlString(tomlString) {
|
|
6733
|
+
function loadSchemaFromTomlString(tomlString, options = {}) {
|
|
6734
|
+
const strict = options.strict !== false;
|
|
6697
6735
|
const parsed = parseToml(tomlString);
|
|
6698
6736
|
const models = parsed.models;
|
|
6699
6737
|
if (!models || typeof models !== "object") {
|
|
@@ -6701,10 +6739,20 @@ function loadSchemaFromTomlString(tomlString) {
|
|
|
6701
6739
|
}
|
|
6702
6740
|
const schemas = [];
|
|
6703
6741
|
for (const [modelName, modelDef] of Object.entries(models)) {
|
|
6742
|
+
checkUnknownKeys(
|
|
6743
|
+
modelDef,
|
|
6744
|
+
KNOWN_MODEL_KEYS,
|
|
6745
|
+
`[models.${modelName}]`,
|
|
6746
|
+
strict
|
|
6747
|
+
);
|
|
6704
6748
|
const fields = {};
|
|
6705
6749
|
if (modelDef.fields) {
|
|
6706
6750
|
for (const [fieldName, fieldDef] of Object.entries(modelDef.fields)) {
|
|
6707
|
-
fields[fieldName] = parseFieldOptions(
|
|
6751
|
+
fields[fieldName] = parseFieldOptions(
|
|
6752
|
+
fieldDef,
|
|
6753
|
+
`[models.${modelName}.fields.${fieldName}]`,
|
|
6754
|
+
strict
|
|
6755
|
+
);
|
|
6708
6756
|
}
|
|
6709
6757
|
}
|
|
6710
6758
|
let relationships;
|
|
@@ -6713,24 +6761,36 @@ function loadSchemaFromTomlString(tomlString) {
|
|
|
6713
6761
|
for (const [relName, relDef] of Object.entries(
|
|
6714
6762
|
modelDef.relationships
|
|
6715
6763
|
)) {
|
|
6716
|
-
relationships[relName] = parseRelationship(
|
|
6764
|
+
relationships[relName] = parseRelationship(
|
|
6765
|
+
relDef,
|
|
6766
|
+
`[models.${modelName}.relationships.${relName}]`,
|
|
6767
|
+
strict
|
|
6768
|
+
);
|
|
6717
6769
|
}
|
|
6718
6770
|
}
|
|
6719
6771
|
let uniqueConstraints;
|
|
6720
6772
|
if (modelDef.unique_constraints) {
|
|
6721
6773
|
uniqueConstraints = [];
|
|
6722
6774
|
for (const raw of modelDef.unique_constraints) {
|
|
6775
|
+
checkUnknownKeys(
|
|
6776
|
+
raw,
|
|
6777
|
+
KNOWN_UNIQUE_CONSTRAINT_KEYS,
|
|
6778
|
+
`[[models.${modelName}.unique_constraints]]`,
|
|
6779
|
+
strict
|
|
6780
|
+
);
|
|
6723
6781
|
uniqueConstraints.push({
|
|
6724
6782
|
name: raw.name,
|
|
6725
6783
|
fields: [...raw.fields]
|
|
6726
6784
|
});
|
|
6727
6785
|
}
|
|
6728
6786
|
}
|
|
6787
|
+
const className = typeof modelDef.class_name === "string" ? modelDef.class_name : void 0;
|
|
6729
6788
|
schemas.push(
|
|
6730
6789
|
defineModelSchema({
|
|
6731
6790
|
name: modelName,
|
|
6732
6791
|
fields,
|
|
6733
6792
|
options: {
|
|
6793
|
+
className,
|
|
6734
6794
|
uniqueConstraints,
|
|
6735
6795
|
relationships
|
|
6736
6796
|
}
|
package/dist/client.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
|
}
|
package/dist/client.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
|
}
|
package/dist/cloudflare-do.cjs
CHANGED
|
@@ -4266,6 +4266,7 @@ function defineModelSchema(input) {
|
|
|
4266
4266
|
const { name, fields } = input;
|
|
4267
4267
|
const options = {
|
|
4268
4268
|
name,
|
|
4269
|
+
className: input.options?.className,
|
|
4269
4270
|
uniqueConstraints: input.options?.uniqueConstraints ? [...input.options.uniqueConstraints] : void 0,
|
|
4270
4271
|
relationships: input.options?.relationships
|
|
4271
4272
|
};
|
|
@@ -4342,12 +4343,52 @@ var VALID_FIELD_TYPES = /* @__PURE__ */ new Set([
|
|
|
4342
4343
|
"id",
|
|
4343
4344
|
"stringset"
|
|
4344
4345
|
]);
|
|
4345
|
-
|
|
4346
|
+
var KNOWN_FIELD_KEYS = /* @__PURE__ */ new Set([
|
|
4347
|
+
"type",
|
|
4348
|
+
"indexed",
|
|
4349
|
+
"unique",
|
|
4350
|
+
"required",
|
|
4351
|
+
"auto_assign",
|
|
4352
|
+
"max_length",
|
|
4353
|
+
"max_count",
|
|
4354
|
+
"default"
|
|
4355
|
+
]);
|
|
4356
|
+
var KNOWN_MODEL_KEYS = /* @__PURE__ */ new Set([
|
|
4357
|
+
"fields",
|
|
4358
|
+
"relationships",
|
|
4359
|
+
"unique_constraints",
|
|
4360
|
+
"class_name"
|
|
4361
|
+
]);
|
|
4362
|
+
var KNOWN_RELATIONSHIP_KEYS = /* @__PURE__ */ new Set([
|
|
4363
|
+
"type",
|
|
4364
|
+
"model",
|
|
4365
|
+
"related_id_field",
|
|
4366
|
+
"join_model",
|
|
4367
|
+
"join_model_local_field",
|
|
4368
|
+
"join_model_related_field",
|
|
4369
|
+
"order_by_field",
|
|
4370
|
+
"order_direction",
|
|
4371
|
+
"join_model_order_by_field",
|
|
4372
|
+
"join_model_order_direction"
|
|
4373
|
+
]);
|
|
4374
|
+
var KNOWN_UNIQUE_CONSTRAINT_KEYS = /* @__PURE__ */ new Set(["name", "fields"]);
|
|
4375
|
+
function checkUnknownKeys(raw, known, context, strict) {
|
|
4376
|
+
if (!strict) return;
|
|
4377
|
+
for (const key of Object.keys(raw)) {
|
|
4378
|
+
if (!known.has(key)) {
|
|
4379
|
+
throw new Error(
|
|
4380
|
+
`${context}: unknown key "${key}". Allowed: ${[...known].join(", ")}`
|
|
4381
|
+
);
|
|
4382
|
+
}
|
|
4383
|
+
}
|
|
4384
|
+
}
|
|
4385
|
+
function parseFieldOptions(raw, context, strict) {
|
|
4346
4386
|
if (!raw.type || !VALID_FIELD_TYPES.has(raw.type)) {
|
|
4347
4387
|
throw new Error(
|
|
4348
4388
|
`Invalid field type "${raw.type}". Must be one of: ${[...VALID_FIELD_TYPES].join(", ")}`
|
|
4349
4389
|
);
|
|
4350
4390
|
}
|
|
4391
|
+
checkUnknownKeys(raw, KNOWN_FIELD_KEYS, context, strict);
|
|
4351
4392
|
const opts = { type: raw.type };
|
|
4352
4393
|
if (raw.indexed === true) opts.indexed = true;
|
|
4353
4394
|
if (raw.unique === true) opts.unique = true;
|
|
@@ -4363,8 +4404,9 @@ function requireField(raw, field, context) {
|
|
|
4363
4404
|
throw new Error(`Relationship ${context}: missing required field "${field}"`);
|
|
4364
4405
|
}
|
|
4365
4406
|
}
|
|
4366
|
-
function parseRelationship(raw) {
|
|
4407
|
+
function parseRelationship(raw, context, strict) {
|
|
4367
4408
|
const type = raw.type;
|
|
4409
|
+
checkUnknownKeys(raw, KNOWN_RELATIONSHIP_KEYS, context, strict);
|
|
4368
4410
|
if (type === "refersTo") {
|
|
4369
4411
|
requireField(raw, "model", "refersTo");
|
|
4370
4412
|
requireField(raw, "related_id_field", "refersTo");
|
|
@@ -4406,7 +4448,8 @@ function parseRelationship(raw) {
|
|
|
4406
4448
|
}
|
|
4407
4449
|
throw new Error(`Unknown relationship type: ${type}`);
|
|
4408
4450
|
}
|
|
4409
|
-
function loadSchemaFromTomlString(tomlString) {
|
|
4451
|
+
function loadSchemaFromTomlString(tomlString, options = {}) {
|
|
4452
|
+
const strict = options.strict !== false;
|
|
4410
4453
|
const parsed = (0, import_smol_toml.parse)(tomlString);
|
|
4411
4454
|
const models = parsed.models;
|
|
4412
4455
|
if (!models || typeof models !== "object") {
|
|
@@ -4414,10 +4457,20 @@ function loadSchemaFromTomlString(tomlString) {
|
|
|
4414
4457
|
}
|
|
4415
4458
|
const schemas = [];
|
|
4416
4459
|
for (const [modelName, modelDef] of Object.entries(models)) {
|
|
4460
|
+
checkUnknownKeys(
|
|
4461
|
+
modelDef,
|
|
4462
|
+
KNOWN_MODEL_KEYS,
|
|
4463
|
+
`[models.${modelName}]`,
|
|
4464
|
+
strict
|
|
4465
|
+
);
|
|
4417
4466
|
const fields = {};
|
|
4418
4467
|
if (modelDef.fields) {
|
|
4419
4468
|
for (const [fieldName, fieldDef] of Object.entries(modelDef.fields)) {
|
|
4420
|
-
fields[fieldName] = parseFieldOptions(
|
|
4469
|
+
fields[fieldName] = parseFieldOptions(
|
|
4470
|
+
fieldDef,
|
|
4471
|
+
`[models.${modelName}.fields.${fieldName}]`,
|
|
4472
|
+
strict
|
|
4473
|
+
);
|
|
4421
4474
|
}
|
|
4422
4475
|
}
|
|
4423
4476
|
let relationships;
|
|
@@ -4426,24 +4479,36 @@ function loadSchemaFromTomlString(tomlString) {
|
|
|
4426
4479
|
for (const [relName, relDef] of Object.entries(
|
|
4427
4480
|
modelDef.relationships
|
|
4428
4481
|
)) {
|
|
4429
|
-
relationships[relName] = parseRelationship(
|
|
4482
|
+
relationships[relName] = parseRelationship(
|
|
4483
|
+
relDef,
|
|
4484
|
+
`[models.${modelName}.relationships.${relName}]`,
|
|
4485
|
+
strict
|
|
4486
|
+
);
|
|
4430
4487
|
}
|
|
4431
4488
|
}
|
|
4432
4489
|
let uniqueConstraints;
|
|
4433
4490
|
if (modelDef.unique_constraints) {
|
|
4434
4491
|
uniqueConstraints = [];
|
|
4435
4492
|
for (const raw of modelDef.unique_constraints) {
|
|
4493
|
+
checkUnknownKeys(
|
|
4494
|
+
raw,
|
|
4495
|
+
KNOWN_UNIQUE_CONSTRAINT_KEYS,
|
|
4496
|
+
`[[models.${modelName}.unique_constraints]]`,
|
|
4497
|
+
strict
|
|
4498
|
+
);
|
|
4436
4499
|
uniqueConstraints.push({
|
|
4437
4500
|
name: raw.name,
|
|
4438
4501
|
fields: [...raw.fields]
|
|
4439
4502
|
});
|
|
4440
4503
|
}
|
|
4441
4504
|
}
|
|
4505
|
+
const className = typeof modelDef.class_name === "string" ? modelDef.class_name : void 0;
|
|
4442
4506
|
schemas.push(
|
|
4443
4507
|
defineModelSchema({
|
|
4444
4508
|
name: modelName,
|
|
4445
4509
|
fields,
|
|
4446
4510
|
options: {
|
|
4511
|
+
className,
|
|
4447
4512
|
uniqueConstraints,
|
|
4448
4513
|
relationships
|
|
4449
4514
|
}
|
package/dist/cloudflare-do.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
|
}
|
|
@@ -1221,8 +1228,8 @@ declare function createDatabaseDO(config?: DatabaseDOConfig): {
|
|
|
1221
1228
|
_initialized: boolean;
|
|
1222
1229
|
/** @internal — cache for $contains misuse check: "model:field" keys known to be in data_json */
|
|
1223
1230
|
_containsMisuseCache: Set<string>;
|
|
1224
|
-
|
|
1225
|
-
|
|
1231
|
+
readonly state: DurableObjectState;
|
|
1232
|
+
readonly engine: DurableObjectEngine;
|
|
1226
1233
|
/** @internal */
|
|
1227
1234
|
_ensureInitialized(): Promise<void>;
|
|
1228
1235
|
fetch(request: Request): Promise<Response>;
|
|
@@ -1845,10 +1852,22 @@ interface DefinedModelSchema<TFields extends Record<string, FieldOptions> = Reco
|
|
|
1845
1852
|
* - Compound unique constraints are [[models.*.unique_constraints]]
|
|
1846
1853
|
*/
|
|
1847
1854
|
|
|
1855
|
+
interface LoadSchemaOptions {
|
|
1856
|
+
/**
|
|
1857
|
+
* When true (default), throw on unknown keys at the model, field,
|
|
1858
|
+
* relationship, and unique-constraint level. When false, unknown
|
|
1859
|
+
* keys are silently ignored (legacy behavior).
|
|
1860
|
+
*/
|
|
1861
|
+
strict?: boolean;
|
|
1862
|
+
}
|
|
1848
1863
|
/**
|
|
1849
1864
|
* Parse a TOML string and return an array of DefinedModelSchema objects.
|
|
1865
|
+
*
|
|
1866
|
+
* By default operates in strict mode: unknown keys at the model, field,
|
|
1867
|
+
* relationship, or unique-constraint level cause an error. Pass
|
|
1868
|
+
* `{ strict: false }` to silently ignore unknown keys (legacy behavior).
|
|
1850
1869
|
*/
|
|
1851
|
-
declare function loadSchemaFromTomlString(tomlString: string): DefinedModelSchema[];
|
|
1870
|
+
declare function loadSchemaFromTomlString(tomlString: string, options?: LoadSchemaOptions): DefinedModelSchema[];
|
|
1852
1871
|
|
|
1853
1872
|
/**
|
|
1854
1873
|
* Meta Sync — writes _meta_* YMaps into a YDoc.
|
package/dist/cloudflare-do.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
|
}
|
|
@@ -1221,8 +1228,8 @@ declare function createDatabaseDO(config?: DatabaseDOConfig): {
|
|
|
1221
1228
|
_initialized: boolean;
|
|
1222
1229
|
/** @internal — cache for $contains misuse check: "model:field" keys known to be in data_json */
|
|
1223
1230
|
_containsMisuseCache: Set<string>;
|
|
1224
|
-
|
|
1225
|
-
|
|
1231
|
+
readonly state: DurableObjectState;
|
|
1232
|
+
readonly engine: DurableObjectEngine;
|
|
1226
1233
|
/** @internal */
|
|
1227
1234
|
_ensureInitialized(): Promise<void>;
|
|
1228
1235
|
fetch(request: Request): Promise<Response>;
|
|
@@ -1845,10 +1852,22 @@ interface DefinedModelSchema<TFields extends Record<string, FieldOptions> = Reco
|
|
|
1845
1852
|
* - Compound unique constraints are [[models.*.unique_constraints]]
|
|
1846
1853
|
*/
|
|
1847
1854
|
|
|
1855
|
+
interface LoadSchemaOptions {
|
|
1856
|
+
/**
|
|
1857
|
+
* When true (default), throw on unknown keys at the model, field,
|
|
1858
|
+
* relationship, and unique-constraint level. When false, unknown
|
|
1859
|
+
* keys are silently ignored (legacy behavior).
|
|
1860
|
+
*/
|
|
1861
|
+
strict?: boolean;
|
|
1862
|
+
}
|
|
1848
1863
|
/**
|
|
1849
1864
|
* Parse a TOML string and return an array of DefinedModelSchema objects.
|
|
1865
|
+
*
|
|
1866
|
+
* By default operates in strict mode: unknown keys at the model, field,
|
|
1867
|
+
* relationship, or unique-constraint level cause an error. Pass
|
|
1868
|
+
* `{ strict: false }` to silently ignore unknown keys (legacy behavior).
|
|
1850
1869
|
*/
|
|
1851
|
-
declare function loadSchemaFromTomlString(tomlString: string): DefinedModelSchema[];
|
|
1870
|
+
declare function loadSchemaFromTomlString(tomlString: string, options?: LoadSchemaOptions): DefinedModelSchema[];
|
|
1852
1871
|
|
|
1853
1872
|
/**
|
|
1854
1873
|
* Meta Sync — writes _meta_* YMaps into a YDoc.
|