@base44-preview/cli 0.0.44-pr.395.9cda80a → 0.0.44-pr.405.2f92c9f

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 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().optional(),
238085
238085
  title: exports_external.string().optional(),
238086
238086
  description: exports_external.string().optional(),
238087
238087
  minLength: exports_external.number().int().min(0).optional(),
@@ -248779,160 +248779,14 @@ function createFunctionRouter(manager, logger) {
248779
248779
  return router;
248780
248780
  }
248781
248781
 
248782
- // src/cli/dev/dev-server/db/database.ts
248782
+ // src/cli/dev/dev-server/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 result = this.validateValue(value, property, key2);
248844
- if (result.hasError)
248845
- return result;
248846
- }
248847
- return {
248848
- hasError: false
248849
- };
248850
- }
248851
- validateValue(value, property, fieldPath) {
248852
- const propertyType = property?.type;
248853
- if (!fieldTypes.includes(propertyType)) {
248854
- return {
248855
- hasError: true,
248856
- error: this.createValidationError(`Error in field ${fieldPath}: Input should be a valid ${propertyType}`)
248857
- };
248858
- }
248859
- switch (propertyType) {
248860
- case "array":
248861
- if (!Array.isArray(value)) {
248862
- return {
248863
- hasError: true,
248864
- error: this.createValidationError(`Error in field ${fieldPath}: Input should be a valid array`)
248865
- };
248866
- }
248867
- if (property.items) {
248868
- for (let i5 = 0;i5 < value.length; i5++) {
248869
- const itemResult = this.validateValue(value[i5], property.items, `${fieldPath}[${i5}]`);
248870
- if (itemResult.hasError)
248871
- return itemResult;
248872
- }
248873
- }
248874
- break;
248875
- case "object":
248876
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
248877
- return {
248878
- hasError: true,
248879
- error: this.createValidationError(`Error in field ${fieldPath}: Input should be a valid object`)
248880
- };
248881
- }
248882
- if (property.properties) {
248883
- for (const [subKey, subValue] of Object.entries(value)) {
248884
- if (property.properties[subKey]) {
248885
- const subResult = this.validateValue(subValue, property.properties[subKey], `${fieldPath}.${subKey}`);
248886
- if (subResult.hasError)
248887
- return subResult;
248888
- }
248889
- }
248890
- }
248891
- break;
248892
- case "integer":
248893
- if (!Number.isInteger(value)) {
248894
- return {
248895
- hasError: true,
248896
- error: this.createValidationError(`Error in field ${fieldPath}: Input should be a valid integer`)
248897
- };
248898
- }
248899
- break;
248900
- default:
248901
- if (typeof value !== propertyType) {
248902
- return {
248903
- hasError: true,
248904
- error: this.createValidationError(`Error in field ${fieldPath}: Input should be a valid ${propertyType}`)
248905
- };
248906
- }
248907
- }
248908
- return { hasError: false };
248909
- }
248910
- validateRequiredFields(record2, entitySchema) {
248911
- if (entitySchema.required && entitySchema.required.length > 0) {
248912
- for (const required2 of entitySchema.required) {
248913
- if (record2[required2] == null) {
248914
- return {
248915
- hasError: true,
248916
- error: this.createValidationError(`Error in field ${required2}: Field required`)
248917
- };
248918
- }
248919
- }
248920
- }
248921
- return {
248922
- hasError: false
248923
- };
248924
- }
248925
- }
248926
-
248927
- // src/cli/dev/dev-server/db/database.ts
248928
248785
  class Database {
248929
248786
  collections = new Map;
248930
- schemas = new Map;
248931
- validator = new Validator;
248932
248787
  load(entities) {
248933
248788
  for (const entity2 of entities) {
248934
248789
  this.collections.set(entity2.name, new import_nedb.default);
248935
- this.schemas.set(entity2.name, entity2);
248936
248790
  }
248937
248791
  }
248938
248792
  getCollection(name2) {
@@ -248946,25 +248800,6 @@ class Database {
248946
248800
  collection.remove({}, { multi: true });
248947
248801
  }
248948
248802
  this.collections.clear();
248949
- this.schemas.clear();
248950
- }
248951
- validate(entityName, record2, partial2 = false) {
248952
- const schema9 = this.schemas.get(entityName);
248953
- if (!schema9) {
248954
- throw new Error(`Entity "${entityName}" not found`);
248955
- }
248956
- return this.validator.validate(record2, schema9, partial2);
248957
- }
248958
- prepareRecord(entityName, record2, partial2 = false) {
248959
- const schema9 = this.schemas.get(entityName);
248960
- if (!schema9) {
248961
- throw new Error(`Entity "${entityName}" not found`);
248962
- }
248963
- const filteredRecord = this.validator.filterFields(record2, schema9);
248964
- if (partial2) {
248965
- return filteredRecord;
248966
- }
248967
- return this.validator.applyDefaults(filteredRecord, schema9);
248968
248803
  }
248969
248804
  }
248970
248805
 
@@ -249156,14 +248991,8 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
249156
248991
  try {
249157
248992
  const now = new Date().toISOString();
249158
248993
  const { _id, ...body } = req.body;
249159
- const filteredBody = db2.prepareRecord(entityName, body);
249160
- const validation = db2.validate(entityName, filteredBody);
249161
- if (validation.hasError) {
249162
- res.status(422).json(validation.error);
249163
- return;
249164
- }
249165
248994
  const record2 = {
249166
- ...filteredBody,
248995
+ ...body,
249167
248996
  id: nanoid3(),
249168
248997
  created_date: now,
249169
248998
  updated_date: now
@@ -249184,21 +249013,12 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
249184
249013
  }
249185
249014
  try {
249186
249015
  const now = new Date().toISOString();
249187
- const records = [];
249188
- for (const record2 of req.body) {
249189
- const filteredRecord = db2.prepareRecord(entityName, record2);
249190
- const validation = db2.validate(entityName, filteredRecord);
249191
- if (validation.hasError) {
249192
- res.status(422).json(validation.error);
249193
- return;
249194
- }
249195
- records.push({
249196
- ...filteredRecord,
249197
- id: nanoid3(),
249198
- created_date: now,
249199
- updated_date: now
249200
- });
249201
- }
249016
+ const records = req.body.map((item) => ({
249017
+ ...item,
249018
+ id: nanoid3(),
249019
+ created_date: now,
249020
+ updated_date: now
249021
+ }));
249202
249022
  const inserted = stripInternalFields(await collection.insertAsync(records));
249203
249023
  emit(appId, entityName, "create", inserted);
249204
249024
  res.status(201).json(inserted);
@@ -249211,14 +249031,8 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
249211
249031
  const { appId, entityName, id: id2 } = req.params;
249212
249032
  const { id: _id, created_date: _created_date, ...body } = req.body;
249213
249033
  try {
249214
- const filteredBody = db2.prepareRecord(entityName, body, true);
249215
- const validation = db2.validate(entityName, filteredBody, true);
249216
- if (validation.hasError) {
249217
- res.status(422).json(validation.error);
249218
- return;
249219
- }
249220
249034
  const updateData = {
249221
- ...filteredBody,
249035
+ ...body,
249222
249036
  updated_date: new Date().toISOString()
249223
249037
  };
249224
249038
  const result = await collection.updateAsync({ id: id2 }, { $set: updateData }, { returnUpdatedDocs: true });
@@ -255561,4 +255375,4 @@ export {
255561
255375
  CLIExitError
255562
255376
  };
255563
255377
 
255564
- //# debugId=9474DF9F31ED113764756E2164756E21
255378
+ //# debugId=29A9031B09883B8D64756E2164756E21