@famgia/omnify-core 2.0.2 → 2.0.4
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/index.cjs +46 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +46 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -631,6 +631,7 @@ var VALID_SCHEMA_FIELDS = /* @__PURE__ */ new Set([
|
|
|
631
631
|
var VALID_SCHEMA_OPTIONS_FIELDS = /* @__PURE__ */ new Set([
|
|
632
632
|
"id",
|
|
633
633
|
"idType",
|
|
634
|
+
"primaryKey",
|
|
634
635
|
"timestamps",
|
|
635
636
|
"softDelete",
|
|
636
637
|
"unique",
|
|
@@ -731,6 +732,13 @@ function buildSchemaOptions(data) {
|
|
|
731
732
|
if (data.idType !== void 0) {
|
|
732
733
|
options.idType = data.idType;
|
|
733
734
|
}
|
|
735
|
+
if (data.primaryKey !== void 0) {
|
|
736
|
+
if (typeof data.primaryKey === "string") {
|
|
737
|
+
options.primaryKey = data.primaryKey;
|
|
738
|
+
} else if (Array.isArray(data.primaryKey)) {
|
|
739
|
+
options.primaryKey = data.primaryKey;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
734
742
|
if (data.authenticatable !== void 0 && typeof data.authenticatable === "boolean") {
|
|
735
743
|
options.authenticatable = data.authenticatable;
|
|
736
744
|
}
|
|
@@ -2804,7 +2812,7 @@ function validateUnknownOptionsFields(schema, filePath) {
|
|
|
2804
2812
|
validationError(
|
|
2805
2813
|
`Unknown option field '${field}'`,
|
|
2806
2814
|
buildLocation7(filePath),
|
|
2807
|
-
`Valid option fields: id, idType, timestamps, softDelete, unique, indexes, translations, tableName, authenticatable, authenticatableLoginIdField, authenticatablePasswordField, authenticatableGuardName`
|
|
2815
|
+
`Valid option fields: id, idType, primaryKey, timestamps, softDelete, unique, indexes, translations, tableName, authenticatable, authenticatableLoginIdField, authenticatablePasswordField, authenticatableGuardName`
|
|
2808
2816
|
)
|
|
2809
2817
|
);
|
|
2810
2818
|
}
|
|
@@ -3390,6 +3398,43 @@ function validateOptions(schema, filePath) {
|
|
|
3390
3398
|
);
|
|
3391
3399
|
}
|
|
3392
3400
|
}
|
|
3401
|
+
if (options.primaryKey !== void 0) {
|
|
3402
|
+
const primaryKeyColumns = typeof options.primaryKey === "string" ? [options.primaryKey] : options.primaryKey;
|
|
3403
|
+
const validColumns = /* @__PURE__ */ new Set();
|
|
3404
|
+
if (schema.properties) {
|
|
3405
|
+
for (const [propName, propDef] of Object.entries(schema.properties)) {
|
|
3406
|
+
validColumns.add(toSnakeCase(propName));
|
|
3407
|
+
validColumns.add(propName);
|
|
3408
|
+
if (propDef.type === "Association") {
|
|
3409
|
+
const assoc = propDef;
|
|
3410
|
+
if (assoc.relation === "ManyToOne" || assoc.relation === "OneToOne" && !assoc.mappedBy) {
|
|
3411
|
+
const fkColumn = `${toSnakeCase(propName)}_id`;
|
|
3412
|
+
validColumns.add(fkColumn);
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
}
|
|
3416
|
+
}
|
|
3417
|
+
for (const column of primaryKeyColumns) {
|
|
3418
|
+
if (!validColumns.has(column) && !validColumns.has(toSnakeCase(column))) {
|
|
3419
|
+
errors.push(
|
|
3420
|
+
validationError(
|
|
3421
|
+
`primaryKey references non-existent column '${column}'`,
|
|
3422
|
+
buildLocation7(filePath),
|
|
3423
|
+
`Available columns: ${[...validColumns].join(", ")}`
|
|
3424
|
+
)
|
|
3425
|
+
);
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
if (options.id === true) {
|
|
3429
|
+
errors.push(
|
|
3430
|
+
validationError(
|
|
3431
|
+
`Conflicting options: 'id: true' and 'primaryKey' cannot be used together`,
|
|
3432
|
+
buildLocation7(filePath),
|
|
3433
|
+
`When using 'primaryKey', the auto-generated ID is disabled. Remove 'id: true' or 'primaryKey'.`
|
|
3434
|
+
)
|
|
3435
|
+
);
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
3393
3438
|
if (options.unique && schema.properties) {
|
|
3394
3439
|
const propertyNames = Object.keys(schema.properties);
|
|
3395
3440
|
const uniqueConstraints = Array.isArray(options.unique[0]) ? options.unique : [options.unique];
|