@base44-preview/cli 0.0.42-pr.404.ec1a1ee → 0.0.43-pr.395.eec7338
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 +168 -12
- package/dist/cli/index.js.map +8 -7
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -238081,7 +238081,7 @@ var FieldRLSSchema = exports_external.looseObject({
|
|
|
238081
238081
|
delete: RLSRuleSchema.optional()
|
|
238082
238082
|
});
|
|
238083
238083
|
var PropertyDefinitionSchema = exports_external.looseObject({
|
|
238084
|
-
type: exports_external.string()
|
|
238084
|
+
type: exports_external.string(),
|
|
238085
238085
|
title: exports_external.string().optional(),
|
|
238086
238086
|
description: exports_external.string().optional(),
|
|
238087
238087
|
minLength: exports_external.number().int().min(0).optional(),
|
|
@@ -238557,7 +238557,7 @@ import { join as join7 } from "node:path";
|
|
|
238557
238557
|
// package.json
|
|
238558
238558
|
var package_default = {
|
|
238559
238559
|
name: "base44",
|
|
238560
|
-
version: "0.0.
|
|
238560
|
+
version: "0.0.43",
|
|
238561
238561
|
description: "Base44 CLI - Unified interface for managing Base44 applications",
|
|
238562
238562
|
type: "module",
|
|
238563
238563
|
bin: {
|
|
@@ -248779,14 +248779,130 @@ function createFunctionRouter(manager, logger) {
|
|
|
248779
248779
|
return router;
|
|
248780
248780
|
}
|
|
248781
248781
|
|
|
248782
|
-
// src/cli/dev/dev-server/database.ts
|
|
248782
|
+
// src/cli/dev/dev-server/db/database.ts
|
|
248783
248783
|
var import_nedb = __toESM(require_nedb(), 1);
|
|
248784
248784
|
|
|
248785
|
+
// src/cli/dev/dev-server/db/validator.ts
|
|
248786
|
+
var fieldTypes = [
|
|
248787
|
+
"string",
|
|
248788
|
+
"integer",
|
|
248789
|
+
"number",
|
|
248790
|
+
"boolean",
|
|
248791
|
+
"array",
|
|
248792
|
+
"object"
|
|
248793
|
+
];
|
|
248794
|
+
|
|
248795
|
+
class Validator {
|
|
248796
|
+
filterFields(record2, entitySchema) {
|
|
248797
|
+
const filteredRecord = {};
|
|
248798
|
+
for (const [key2, value] of Object.entries(record2)) {
|
|
248799
|
+
if (entitySchema.properties[key2]) {
|
|
248800
|
+
filteredRecord[key2] = value;
|
|
248801
|
+
}
|
|
248802
|
+
}
|
|
248803
|
+
return filteredRecord;
|
|
248804
|
+
}
|
|
248805
|
+
applyDefaults(record2, entitySchema) {
|
|
248806
|
+
const result = {};
|
|
248807
|
+
for (const [key2, property] of Object.entries(entitySchema.properties)) {
|
|
248808
|
+
if (property.default !== undefined) {
|
|
248809
|
+
result[key2] = property.default;
|
|
248810
|
+
}
|
|
248811
|
+
}
|
|
248812
|
+
return {
|
|
248813
|
+
...result,
|
|
248814
|
+
...record2
|
|
248815
|
+
};
|
|
248816
|
+
}
|
|
248817
|
+
validate(record2, entitySchema, partial2 = false) {
|
|
248818
|
+
if (!partial2) {
|
|
248819
|
+
const requiredFieldsResponse = this.validateRequiredFields(record2, entitySchema);
|
|
248820
|
+
if (requiredFieldsResponse.hasError) {
|
|
248821
|
+
return requiredFieldsResponse;
|
|
248822
|
+
}
|
|
248823
|
+
}
|
|
248824
|
+
const fieldTypesResponse = this.validateFieldTypes(record2, entitySchema);
|
|
248825
|
+
if (fieldTypesResponse.hasError) {
|
|
248826
|
+
return fieldTypesResponse;
|
|
248827
|
+
}
|
|
248828
|
+
return {
|
|
248829
|
+
hasError: false
|
|
248830
|
+
};
|
|
248831
|
+
}
|
|
248832
|
+
createValidationError(message) {
|
|
248833
|
+
return {
|
|
248834
|
+
error_type: "ValidationError",
|
|
248835
|
+
message,
|
|
248836
|
+
request_id: null,
|
|
248837
|
+
traceback: ""
|
|
248838
|
+
};
|
|
248839
|
+
}
|
|
248840
|
+
validateFieldTypes(record2, entitySchema) {
|
|
248841
|
+
for (const [key2, value] of Object.entries(record2)) {
|
|
248842
|
+
const property = entitySchema.properties[key2];
|
|
248843
|
+
const propertyType = property?.type;
|
|
248844
|
+
if (!fieldTypes.includes(propertyType)) {
|
|
248845
|
+
return {
|
|
248846
|
+
hasError: true,
|
|
248847
|
+
error: this.createValidationError(`Error in field ${key2}: Input should be a valid ${propertyType}`)
|
|
248848
|
+
};
|
|
248849
|
+
}
|
|
248850
|
+
switch (propertyType) {
|
|
248851
|
+
case "array":
|
|
248852
|
+
if (!Array.isArray(value)) {
|
|
248853
|
+
return {
|
|
248854
|
+
hasError: true,
|
|
248855
|
+
error: this.createValidationError(`Error in field ${key2}: Input should be a valid array`)
|
|
248856
|
+
};
|
|
248857
|
+
}
|
|
248858
|
+
break;
|
|
248859
|
+
case "integer":
|
|
248860
|
+
if (!Number.isInteger(value)) {
|
|
248861
|
+
return {
|
|
248862
|
+
hasError: true,
|
|
248863
|
+
error: this.createValidationError(`Error in field ${key2}: Input should be a valid integer`)
|
|
248864
|
+
};
|
|
248865
|
+
}
|
|
248866
|
+
break;
|
|
248867
|
+
default:
|
|
248868
|
+
if (typeof value !== propertyType) {
|
|
248869
|
+
return {
|
|
248870
|
+
hasError: true,
|
|
248871
|
+
error: this.createValidationError(`Error in field ${key2}: Input should be a valid ${propertyType}`)
|
|
248872
|
+
};
|
|
248873
|
+
}
|
|
248874
|
+
}
|
|
248875
|
+
}
|
|
248876
|
+
return {
|
|
248877
|
+
hasError: false
|
|
248878
|
+
};
|
|
248879
|
+
}
|
|
248880
|
+
validateRequiredFields(record2, entitySchema) {
|
|
248881
|
+
if (entitySchema.required && entitySchema.required.length > 0) {
|
|
248882
|
+
for (const required2 of entitySchema.required) {
|
|
248883
|
+
if (record2[required2] == null) {
|
|
248884
|
+
return {
|
|
248885
|
+
hasError: true,
|
|
248886
|
+
error: this.createValidationError(`Error in field ${required2}: Field required`)
|
|
248887
|
+
};
|
|
248888
|
+
}
|
|
248889
|
+
}
|
|
248890
|
+
}
|
|
248891
|
+
return {
|
|
248892
|
+
hasError: false
|
|
248893
|
+
};
|
|
248894
|
+
}
|
|
248895
|
+
}
|
|
248896
|
+
|
|
248897
|
+
// src/cli/dev/dev-server/db/database.ts
|
|
248785
248898
|
class Database {
|
|
248786
248899
|
collections = new Map;
|
|
248900
|
+
schemas = new Map;
|
|
248901
|
+
validator = new Validator;
|
|
248787
248902
|
load(entities) {
|
|
248788
248903
|
for (const entity2 of entities) {
|
|
248789
248904
|
this.collections.set(entity2.name, new import_nedb.default);
|
|
248905
|
+
this.schemas.set(entity2.name, entity2);
|
|
248790
248906
|
}
|
|
248791
248907
|
}
|
|
248792
248908
|
getCollection(name2) {
|
|
@@ -248800,6 +248916,25 @@ class Database {
|
|
|
248800
248916
|
collection.remove({}, { multi: true });
|
|
248801
248917
|
}
|
|
248802
248918
|
this.collections.clear();
|
|
248919
|
+
this.schemas.clear();
|
|
248920
|
+
}
|
|
248921
|
+
validate(entityName, record2, partial2 = false) {
|
|
248922
|
+
const schema9 = this.schemas.get(entityName);
|
|
248923
|
+
if (!schema9) {
|
|
248924
|
+
throw new Error(`Entity "${entityName}" not found`);
|
|
248925
|
+
}
|
|
248926
|
+
return this.validator.validate(record2, schema9, partial2);
|
|
248927
|
+
}
|
|
248928
|
+
prepareRecord(entityName, record2, partial2 = false) {
|
|
248929
|
+
const schema9 = this.schemas.get(entityName);
|
|
248930
|
+
if (!schema9) {
|
|
248931
|
+
throw new Error(`Entity "${entityName}" not found`);
|
|
248932
|
+
}
|
|
248933
|
+
const filteredRecord = this.validator.filterFields(record2, schema9);
|
|
248934
|
+
if (partial2) {
|
|
248935
|
+
return filteredRecord;
|
|
248936
|
+
}
|
|
248937
|
+
return this.validator.applyDefaults(filteredRecord, schema9);
|
|
248803
248938
|
}
|
|
248804
248939
|
}
|
|
248805
248940
|
|
|
@@ -248991,8 +249126,14 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
248991
249126
|
try {
|
|
248992
249127
|
const now = new Date().toISOString();
|
|
248993
249128
|
const { _id, ...body } = req.body;
|
|
249129
|
+
const filteredBody = db2.prepareRecord(entityName, body);
|
|
249130
|
+
const validation = db2.validate(entityName, filteredBody);
|
|
249131
|
+
if (validation.hasError) {
|
|
249132
|
+
res.status(422).json(validation.error);
|
|
249133
|
+
return;
|
|
249134
|
+
}
|
|
248994
249135
|
const record2 = {
|
|
248995
|
-
...
|
|
249136
|
+
...filteredBody,
|
|
248996
249137
|
id: nanoid3(),
|
|
248997
249138
|
created_date: now,
|
|
248998
249139
|
updated_date: now
|
|
@@ -249013,12 +249154,21 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249013
249154
|
}
|
|
249014
249155
|
try {
|
|
249015
249156
|
const now = new Date().toISOString();
|
|
249016
|
-
const records =
|
|
249017
|
-
|
|
249018
|
-
|
|
249019
|
-
|
|
249020
|
-
|
|
249021
|
-
|
|
249157
|
+
const records = [];
|
|
249158
|
+
for (const record2 of req.body) {
|
|
249159
|
+
const filteredRecord = db2.prepareRecord(entityName, record2);
|
|
249160
|
+
const validation = db2.validate(entityName, filteredRecord);
|
|
249161
|
+
if (validation.hasError) {
|
|
249162
|
+
res.status(422).json(validation.error);
|
|
249163
|
+
return;
|
|
249164
|
+
}
|
|
249165
|
+
records.push({
|
|
249166
|
+
...filteredRecord,
|
|
249167
|
+
id: nanoid3(),
|
|
249168
|
+
created_date: now,
|
|
249169
|
+
updated_date: now
|
|
249170
|
+
});
|
|
249171
|
+
}
|
|
249022
249172
|
const inserted = stripInternalFields(await collection.insertAsync(records));
|
|
249023
249173
|
emit(appId, entityName, "create", inserted);
|
|
249024
249174
|
res.status(201).json(inserted);
|
|
@@ -249031,8 +249181,14 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249031
249181
|
const { appId, entityName, id: id2 } = req.params;
|
|
249032
249182
|
const { id: _id, created_date: _created_date, ...body } = req.body;
|
|
249033
249183
|
try {
|
|
249184
|
+
const filteredBody = db2.prepareRecord(entityName, body, true);
|
|
249185
|
+
const validation = db2.validate(entityName, filteredBody, true);
|
|
249186
|
+
if (validation.hasError) {
|
|
249187
|
+
res.status(422).json(validation.error);
|
|
249188
|
+
return;
|
|
249189
|
+
}
|
|
249034
249190
|
const updateData = {
|
|
249035
|
-
...
|
|
249191
|
+
...filteredBody,
|
|
249036
249192
|
updated_date: new Date().toISOString()
|
|
249037
249193
|
};
|
|
249038
249194
|
const result = await collection.updateAsync({ id: id2 }, { $set: updateData }, { returnUpdatedDocs: true });
|
|
@@ -255375,4 +255531,4 @@ export {
|
|
|
255375
255531
|
CLIExitError
|
|
255376
255532
|
};
|
|
255377
255533
|
|
|
255378
|
-
//# debugId=
|
|
255534
|
+
//# debugId=E1E29CEB4EDF231E64756E2164756E21
|