@base44-preview/cli 0.0.41-pr.395.72f56e6 → 0.0.41-pr.396.3d0a1da
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/cli/index.js +10 -166
- package/dist/cli/index.js.map +6 -7
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -248581,130 +248581,14 @@ function createFunctionRouter(manager, logger) {
|
|
|
248581
248581
|
return router;
|
|
248582
248582
|
}
|
|
248583
248583
|
|
|
248584
|
-
// src/cli/dev/dev-server/
|
|
248584
|
+
// src/cli/dev/dev-server/database.ts
|
|
248585
248585
|
var import_nedb = __toESM(require_nedb(), 1);
|
|
248586
248586
|
|
|
248587
|
-
// src/cli/dev/dev-server/db/validator.ts
|
|
248588
|
-
var fieldTypes = [
|
|
248589
|
-
"string",
|
|
248590
|
-
"integer",
|
|
248591
|
-
"number",
|
|
248592
|
-
"boolean",
|
|
248593
|
-
"array",
|
|
248594
|
-
"object"
|
|
248595
|
-
];
|
|
248596
|
-
|
|
248597
|
-
class Validator {
|
|
248598
|
-
filterFields(record2, entitySchema) {
|
|
248599
|
-
const filteredRecord = {};
|
|
248600
|
-
for (const [key2, value] of Object.entries(record2)) {
|
|
248601
|
-
if (entitySchema.properties[key2]) {
|
|
248602
|
-
filteredRecord[key2] = value;
|
|
248603
|
-
}
|
|
248604
|
-
}
|
|
248605
|
-
return filteredRecord;
|
|
248606
|
-
}
|
|
248607
|
-
applyDefaults(record2, entitySchema) {
|
|
248608
|
-
const result = {};
|
|
248609
|
-
for (const [key2, property] of Object.entries(entitySchema.properties)) {
|
|
248610
|
-
if (property?.default) {
|
|
248611
|
-
result[key2] = property.default;
|
|
248612
|
-
}
|
|
248613
|
-
}
|
|
248614
|
-
return {
|
|
248615
|
-
...result,
|
|
248616
|
-
...record2
|
|
248617
|
-
};
|
|
248618
|
-
}
|
|
248619
|
-
validate(record2, entitySchema, partial2 = false) {
|
|
248620
|
-
if (!partial2) {
|
|
248621
|
-
const requiredFieldsResponse = this.validateRequiredFields(record2, entitySchema);
|
|
248622
|
-
if (requiredFieldsResponse.hasError) {
|
|
248623
|
-
return requiredFieldsResponse;
|
|
248624
|
-
}
|
|
248625
|
-
}
|
|
248626
|
-
const fieldTypesResponse = this.validateFieldTypes(record2, entitySchema);
|
|
248627
|
-
if (fieldTypesResponse.hasError) {
|
|
248628
|
-
return fieldTypesResponse;
|
|
248629
|
-
}
|
|
248630
|
-
return {
|
|
248631
|
-
hasError: false
|
|
248632
|
-
};
|
|
248633
|
-
}
|
|
248634
|
-
createValidationError(message) {
|
|
248635
|
-
return {
|
|
248636
|
-
error_type: "ValidationError",
|
|
248637
|
-
message,
|
|
248638
|
-
request_id: null,
|
|
248639
|
-
traceback: ""
|
|
248640
|
-
};
|
|
248641
|
-
}
|
|
248642
|
-
validateFieldTypes(record2, entitySchema) {
|
|
248643
|
-
for (const [key2, value] of Object.entries(record2)) {
|
|
248644
|
-
const property = entitySchema.properties[key2];
|
|
248645
|
-
const propertyType = property?.type;
|
|
248646
|
-
if (!fieldTypes.includes(propertyType)) {
|
|
248647
|
-
return {
|
|
248648
|
-
hasError: true,
|
|
248649
|
-
error: this.createValidationError(`Error in field ${key2}: Input should be a valid ${propertyType}`)
|
|
248650
|
-
};
|
|
248651
|
-
}
|
|
248652
|
-
switch (propertyType) {
|
|
248653
|
-
case "array":
|
|
248654
|
-
if (!Array.isArray(value)) {
|
|
248655
|
-
return {
|
|
248656
|
-
hasError: true,
|
|
248657
|
-
error: this.createValidationError(`Error in field ${key2}: Input should be a valid array`)
|
|
248658
|
-
};
|
|
248659
|
-
}
|
|
248660
|
-
break;
|
|
248661
|
-
case "integer":
|
|
248662
|
-
if (!Number.isInteger(value)) {
|
|
248663
|
-
return {
|
|
248664
|
-
hasError: true,
|
|
248665
|
-
error: this.createValidationError(`Error in field ${key2}: Input should be a valid integer`)
|
|
248666
|
-
};
|
|
248667
|
-
}
|
|
248668
|
-
break;
|
|
248669
|
-
default:
|
|
248670
|
-
if (typeof value !== propertyType) {
|
|
248671
|
-
return {
|
|
248672
|
-
hasError: true,
|
|
248673
|
-
error: this.createValidationError(`Error in field ${key2}: Input should be a valid ${propertyType}`)
|
|
248674
|
-
};
|
|
248675
|
-
}
|
|
248676
|
-
}
|
|
248677
|
-
}
|
|
248678
|
-
return {
|
|
248679
|
-
hasError: false
|
|
248680
|
-
};
|
|
248681
|
-
}
|
|
248682
|
-
validateRequiredFields(record2, entitySchema) {
|
|
248683
|
-
if (entitySchema.required && entitySchema.required.length > 0) {
|
|
248684
|
-
for (const required2 of entitySchema.required) {
|
|
248685
|
-
if (!record2[required2]) {
|
|
248686
|
-
return {
|
|
248687
|
-
hasError: true,
|
|
248688
|
-
error: this.createValidationError(`Error in field ${required2}: Field required`)
|
|
248689
|
-
};
|
|
248690
|
-
}
|
|
248691
|
-
}
|
|
248692
|
-
}
|
|
248693
|
-
return {
|
|
248694
|
-
hasError: false
|
|
248695
|
-
};
|
|
248696
|
-
}
|
|
248697
|
-
}
|
|
248698
|
-
|
|
248699
|
-
// src/cli/dev/dev-server/db/database.ts
|
|
248700
248587
|
class Database {
|
|
248701
248588
|
collections = new Map;
|
|
248702
|
-
schemas = new Map;
|
|
248703
|
-
validator = new Validator;
|
|
248704
248589
|
load(entities) {
|
|
248705
248590
|
for (const entity2 of entities) {
|
|
248706
248591
|
this.collections.set(entity2.name, new import_nedb.default);
|
|
248707
|
-
this.schemas.set(entity2.name, entity2);
|
|
248708
248592
|
}
|
|
248709
248593
|
}
|
|
248710
248594
|
getCollection(name2) {
|
|
@@ -248718,25 +248602,6 @@ class Database {
|
|
|
248718
248602
|
collection.remove({}, { multi: true });
|
|
248719
248603
|
}
|
|
248720
248604
|
this.collections.clear();
|
|
248721
|
-
this.schemas.clear();
|
|
248722
|
-
}
|
|
248723
|
-
validate(entityName, record2, partial2 = false) {
|
|
248724
|
-
const schema9 = this.schemas.get(entityName);
|
|
248725
|
-
if (!schema9) {
|
|
248726
|
-
throw new Error(`Entity "${entityName}" not found`);
|
|
248727
|
-
}
|
|
248728
|
-
return this.validator.validate(record2, schema9, partial2);
|
|
248729
|
-
}
|
|
248730
|
-
prepareRecord(entityName, record2, partial2 = false) {
|
|
248731
|
-
const schema9 = this.schemas.get(entityName);
|
|
248732
|
-
if (!schema9) {
|
|
248733
|
-
throw new Error(`Entity "${entityName}" not found`);
|
|
248734
|
-
}
|
|
248735
|
-
const filteredRecord = this.validator.filterFields(record2, schema9);
|
|
248736
|
-
if (partial2) {
|
|
248737
|
-
return filteredRecord;
|
|
248738
|
-
}
|
|
248739
|
-
return this.validator.applyDefaults(filteredRecord, schema9);
|
|
248740
248605
|
}
|
|
248741
248606
|
}
|
|
248742
248607
|
|
|
@@ -248928,14 +248793,8 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
248928
248793
|
try {
|
|
248929
248794
|
const now = new Date().toISOString();
|
|
248930
248795
|
const { _id, ...body } = req.body;
|
|
248931
|
-
const filteredBody = db2.prepareRecord(entityName, body);
|
|
248932
|
-
const validation = db2.validate(entityName, filteredBody);
|
|
248933
|
-
if (validation.hasError) {
|
|
248934
|
-
res.status(422).json(validation.error);
|
|
248935
|
-
return;
|
|
248936
|
-
}
|
|
248937
248796
|
const record2 = {
|
|
248938
|
-
...
|
|
248797
|
+
...body,
|
|
248939
248798
|
id: nanoid3(),
|
|
248940
248799
|
created_date: now,
|
|
248941
248800
|
updated_date: now
|
|
@@ -248956,21 +248815,12 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
248956
248815
|
}
|
|
248957
248816
|
try {
|
|
248958
248817
|
const now = new Date().toISOString();
|
|
248959
|
-
const records =
|
|
248960
|
-
|
|
248961
|
-
|
|
248962
|
-
|
|
248963
|
-
|
|
248964
|
-
|
|
248965
|
-
return;
|
|
248966
|
-
}
|
|
248967
|
-
records.push({
|
|
248968
|
-
...filteredRecord,
|
|
248969
|
-
id: nanoid3(),
|
|
248970
|
-
created_date: now,
|
|
248971
|
-
updated_date: now
|
|
248972
|
-
});
|
|
248973
|
-
}
|
|
248818
|
+
const records = req.body.map((item) => ({
|
|
248819
|
+
...item,
|
|
248820
|
+
id: nanoid3(),
|
|
248821
|
+
created_date: now,
|
|
248822
|
+
updated_date: now
|
|
248823
|
+
}));
|
|
248974
248824
|
const inserted = stripInternalFields(await collection.insertAsync(records));
|
|
248975
248825
|
emit(appId, entityName, "create", inserted);
|
|
248976
248826
|
res.status(201).json(inserted);
|
|
@@ -248983,14 +248833,8 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
248983
248833
|
const { appId, entityName, id: id2 } = req.params;
|
|
248984
248834
|
const { id: _id, created_date: _created_date, ...body } = req.body;
|
|
248985
248835
|
try {
|
|
248986
|
-
const filteredBody = db2.prepareRecord(entityName, body, true);
|
|
248987
|
-
const validation = db2.validate(entityName, filteredBody, true);
|
|
248988
|
-
if (validation.hasError) {
|
|
248989
|
-
res.status(422).json(validation.error);
|
|
248990
|
-
return;
|
|
248991
|
-
}
|
|
248992
248836
|
const updateData = {
|
|
248993
|
-
...
|
|
248837
|
+
...body,
|
|
248994
248838
|
updated_date: new Date().toISOString()
|
|
248995
248839
|
};
|
|
248996
248840
|
const result = await collection.updateAsync({ id: id2 }, { $set: updateData }, { returnUpdatedDocs: true });
|
|
@@ -255299,4 +255143,4 @@ export {
|
|
|
255299
255143
|
CLIExitError
|
|
255300
255144
|
};
|
|
255301
255145
|
|
|
255302
|
-
//# debugId=
|
|
255146
|
+
//# debugId=5197AF7DA9482FFF64756E2164756E21
|