js-bao 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.cjs CHANGED
@@ -3034,7 +3034,7 @@ var init_BaseModel = __esm({
3034
3034
  validateBeforeSave() {
3035
3035
  const schema = this.constructor.getSchema();
3036
3036
  for (const [fieldKey, fieldOptions] of schema.fields.entries()) {
3037
- const currentValue = this.getValue(fieldKey);
3037
+ const currentValue = fieldKey === "id" ? this.id : this.getValue(fieldKey);
3038
3038
  if (fieldOptions.required && (currentValue === null || currentValue === void 0)) {
3039
3039
  throw new Error(`Field ${fieldKey} is required before save`);
3040
3040
  }
package/dist/browser.js CHANGED
@@ -3012,7 +3012,7 @@ var init_BaseModel = __esm({
3012
3012
  validateBeforeSave() {
3013
3013
  const schema = this.constructor.getSchema();
3014
3014
  for (const [fieldKey, fieldOptions] of schema.fields.entries()) {
3015
- const currentValue = this.getValue(fieldKey);
3015
+ const currentValue = fieldKey === "id" ? this.id : this.getValue(fieldKey);
3016
3016
  if (fieldOptions.required && (currentValue === null || currentValue === void 0)) {
3017
3017
  throw new Error(`Field ${fieldKey} is required before save`);
3018
3018
  }
@@ -533,7 +533,8 @@ function renderModelFile(input) {
533
533
  lines.push(`export interface ${className}Attrs {`);
534
534
  for (const [fieldName, opts] of Object.entries(fields)) {
535
535
  const tsType = tsTypeForFieldType(opts.type);
536
- const optional = opts.required === true ? "" : "?";
536
+ const isRequired = opts.required === true || opts.autoAssign === true && fieldName === "id";
537
+ const optional = isRequired ? "" : "?";
537
538
  lines.push(` ${fieldName}${optional}: ${tsType};`);
538
539
  }
539
540
  lines.push(`}`);
@@ -642,7 +643,9 @@ function renderBarrel(input) {
642
643
  lines.push(` }`);
643
644
  lines.push(`}`);
644
645
  lines.push("");
645
- lines.push(`export const allModels: unknown[] = _modelPairs.map((m) => m.class);`);
646
+ lines.push(
647
+ `export const allModels: Array<typeof BaseModel> = _modelPairs.map((m) => m.class);`
648
+ );
646
649
  lines.push("");
647
650
  return lines.join("\n");
648
651
  }
@@ -1062,10 +1065,18 @@ function parseDefineModelSchemaArg(obj, sf) {
1062
1065
  if (opts && opts.type === "id") {
1063
1066
  fd.severity = "info";
1064
1067
  opts.autoAssign = true;
1068
+ if (fd.field === "id") {
1069
+ opts.required = true;
1070
+ }
1065
1071
  } else {
1066
1072
  fd.severity = "warn";
1067
1073
  }
1068
1074
  }
1075
+ for (const [fieldName, opts] of Object.entries(fields)) {
1076
+ if (fieldName === "id" && opts.autoAssign === true && opts.required !== false) {
1077
+ opts.required = true;
1078
+ }
1079
+ }
1069
1080
  return { modelName, fields, relationships, uniqueConstraints, functionDefaults };
1070
1081
  }
1071
1082
  function parseFields(obj, sf) {
@@ -1477,7 +1488,7 @@ var Logger2 = class _Logger {
1477
1488
  // package.json
1478
1489
  var package_default = {
1479
1490
  name: "js-bao",
1480
- version: "0.4.2",
1491
+ version: "0.5.0",
1481
1492
  description: "A library providing data modeling capabilities which support live updates and queries.",
1482
1493
  types: "dist/index.d.ts",
1483
1494
  type: "module",
package/dist/codegen.cjs CHANGED
@@ -1181,7 +1181,7 @@ var SchemaExtractor = class {
1181
1181
  // package.json
1182
1182
  var package_default = {
1183
1183
  name: "js-bao",
1184
- version: "0.4.2",
1184
+ version: "0.5.0",
1185
1185
  description: "A library providing data modeling capabilities which support live updates and queries.",
1186
1186
  types: "dist/index.d.ts",
1187
1187
  type: "module",
package/dist/index.cjs CHANGED
@@ -2320,7 +2320,7 @@ var init_BaseModel = __esm({
2320
2320
  validateBeforeSave() {
2321
2321
  const schema = this.constructor.getSchema();
2322
2322
  for (const [fieldKey, fieldOptions] of schema.fields.entries()) {
2323
- const currentValue = this.getValue(fieldKey);
2323
+ const currentValue = fieldKey === "id" ? this.id : this.getValue(fieldKey);
2324
2324
  if (fieldOptions.required && (currentValue === null || currentValue === void 0)) {
2325
2325
  throw new Error(`Field ${fieldKey} is required before save`);
2326
2326
  }
package/dist/index.js CHANGED
@@ -2298,7 +2298,7 @@ var init_BaseModel = __esm({
2298
2298
  validateBeforeSave() {
2299
2299
  const schema = this.constructor.getSchema();
2300
2300
  for (const [fieldKey, fieldOptions] of schema.fields.entries()) {
2301
- const currentValue = this.getValue(fieldKey);
2301
+ const currentValue = fieldKey === "id" ? this.id : this.getValue(fieldKey);
2302
2302
  if (fieldOptions.required && (currentValue === null || currentValue === void 0)) {
2303
2303
  throw new Error(`Field ${fieldKey} is required before save`);
2304
2304
  }
package/dist/node.cjs CHANGED
@@ -3034,7 +3034,7 @@ var init_BaseModel = __esm({
3034
3034
  validateBeforeSave() {
3035
3035
  const schema = this.constructor.getSchema();
3036
3036
  for (const [fieldKey, fieldOptions] of schema.fields.entries()) {
3037
- const currentValue = this.getValue(fieldKey);
3037
+ const currentValue = fieldKey === "id" ? this.id : this.getValue(fieldKey);
3038
3038
  if (fieldOptions.required && (currentValue === null || currentValue === void 0)) {
3039
3039
  throw new Error(`Field ${fieldKey} is required before save`);
3040
3040
  }
package/dist/node.js CHANGED
@@ -3012,7 +3012,7 @@ var init_BaseModel = __esm({
3012
3012
  validateBeforeSave() {
3013
3013
  const schema = this.constructor.getSchema();
3014
3014
  for (const [fieldKey, fieldOptions] of schema.fields.entries()) {
3015
- const currentValue = this.getValue(fieldKey);
3015
+ const currentValue = fieldKey === "id" ? this.id : this.getValue(fieldKey);
3016
3016
  if (fieldOptions.required && (currentValue === null || currentValue === void 0)) {
3017
3017
  throw new Error(`Field ${fieldKey} is required before save`);
3018
3018
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-bao",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "A library providing data modeling capabilities which support live updates and queries.",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",