@base44-preview/cli 0.0.44-pr.380.71fe077 → 0.0.44-pr.395.8d1c073

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().optional(),
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(),
@@ -238236,22 +238236,6 @@ var DeployFunctionsResponseSchema = exports_external.object({
238236
238236
  skipped: exports_external.array(exports_external.string()).optional().nullable(),
238237
238237
  errors: exports_external.array(exports_external.object({ name: exports_external.string(), message: exports_external.string() })).nullable()
238238
238238
  });
238239
- var FunctionInfoSchema = exports_external.object({
238240
- name: exports_external.string(),
238241
- deployment_id: exports_external.string(),
238242
- entry: exports_external.string(),
238243
- files: exports_external.array(FunctionFileSchema),
238244
- automations: exports_external.array(AutomationSchema)
238245
- }).transform((data) => ({
238246
- name: data.name,
238247
- deploymentId: data.deployment_id,
238248
- entry: data.entry,
238249
- files: data.files,
238250
- automations: data.automations
238251
- }));
238252
- var ListFunctionsResponseSchema = exports_external.object({
238253
- functions: exports_external.array(FunctionInfoSchema)
238254
- });
238255
238239
  var LogLevelSchema = exports_external.enum(["info", "warning", "error", "debug"]);
238256
238240
  var FunctionLogEntrySchema = exports_external.object({
238257
238241
  time: exports_external.string(),
@@ -238325,20 +238309,6 @@ async function fetchFunctionLogs(functionName, filters = {}) {
238325
238309
  }
238326
238310
  return result.data;
238327
238311
  }
238328
- async function listDeployedFunctions() {
238329
- const appClient = getAppClient();
238330
- let response;
238331
- try {
238332
- response = await appClient.get("backend-functions", { timeout: 30000 });
238333
- } catch (error48) {
238334
- throw await ApiError.fromHttpError(error48, "listing deployed functions");
238335
- }
238336
- const result = ListFunctionsResponseSchema.safeParse(await response.json());
238337
- if (!result.success) {
238338
- throw new SchemaValidationError("Invalid response from server", result.error);
238339
- }
238340
- return result.data;
238341
- }
238342
238312
  // src/core/resources/function/config.ts
238343
238313
  import { basename as basename2, dirname as dirname3, join as join5, relative } from "node:path";
238344
238314
  async function readFunctionConfig(configPath) {
@@ -247620,36 +247590,10 @@ async function deployFunctionsAction() {
247620
247590
  }
247621
247591
  return { outroMessage: "Functions deployed to Base44" };
247622
247592
  }
247623
- function getDeployCommand(context) {
247624
- return new Command("deploy").description("Deploy local functions to Base44").action(async () => {
247593
+ function getFunctionsDeployCommand(context) {
247594
+ return new Command("functions").description("Manage project functions").addCommand(new Command("deploy").description("Deploy local functions to Base44").action(async () => {
247625
247595
  await runCommand(deployFunctionsAction, { requireAuth: true }, context);
247626
- });
247627
- }
247628
-
247629
- // src/cli/commands/functions/list.ts
247630
- async function listFunctionsAction() {
247631
- const { functions } = await runTask("Fetching functions...", async () => listDeployedFunctions());
247632
- if (functions.length === 0) {
247633
- return { outroMessage: "No functions on remote" };
247634
- }
247635
- for (const fn of functions) {
247636
- const automationCount = fn.automations.length;
247637
- const automationLabel = automationCount > 0 ? theme.styles.dim(` (${automationCount} automation${automationCount > 1 ? "s" : ""})`) : "";
247638
- R2.message(` ${fn.name}${automationLabel}`);
247639
- }
247640
- return {
247641
- outroMessage: `${functions.length} function${functions.length !== 1 ? "s" : ""} on remote`
247642
- };
247643
- }
247644
- function getListCommand(context) {
247645
- return new Command("list").description("List all deployed functions").action(async () => {
247646
- await runCommand(listFunctionsAction, { requireAuth: true }, context);
247647
- });
247648
- }
247649
-
247650
- // src/cli/commands/functions/index.ts
247651
- function getFunctionsCommand(context) {
247652
- return new Command("functions").description("Manage backend functions").addCommand(getDeployCommand(context)).addCommand(getListCommand(context));
247596
+ }));
247653
247597
  }
247654
247598
 
247655
247599
  // src/cli/commands/project/create.ts
@@ -247887,7 +247831,7 @@ ${summaryLines.join(`
247887
247831
  }
247888
247832
  return { outroMessage: "App deployed successfully" };
247889
247833
  }
247890
- function getDeployCommand2(context) {
247834
+ function getDeployCommand(context) {
247891
247835
  return new Command("deploy").description("Deploy all project resources (entities, functions, agents, connectors, and site)").option("-y, --yes", "Skip confirmation prompt").action(async (options) => {
247892
247836
  await runCommand(() => deployAction({
247893
247837
  ...options,
@@ -248835,14 +248779,160 @@ function createFunctionRouter(manager, logger) {
248835
248779
  return router;
248836
248780
  }
248837
248781
 
248838
- // src/cli/dev/dev-server/database.ts
248782
+ // src/cli/dev/dev-server/db/database.ts
248839
248783
  var import_nedb = __toESM(require_nedb(), 1);
248840
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
248841
248928
  class Database {
248842
248929
  collections = new Map;
248930
+ schemas = new Map;
248931
+ validator = new Validator;
248843
248932
  load(entities) {
248844
248933
  for (const entity2 of entities) {
248845
248934
  this.collections.set(entity2.name, new import_nedb.default);
248935
+ this.schemas.set(entity2.name, entity2);
248846
248936
  }
248847
248937
  }
248848
248938
  getCollection(name2) {
@@ -248856,6 +248946,25 @@ class Database {
248856
248946
  collection.remove({}, { multi: true });
248857
248947
  }
248858
248948
  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);
248859
248968
  }
248860
248969
  }
248861
248970
 
@@ -249047,8 +249156,14 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
249047
249156
  try {
249048
249157
  const now = new Date().toISOString();
249049
249158
  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
+ }
249050
249165
  const record2 = {
249051
- ...body,
249166
+ ...filteredBody,
249052
249167
  id: nanoid3(),
249053
249168
  created_date: now,
249054
249169
  updated_date: now
@@ -249069,12 +249184,21 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
249069
249184
  }
249070
249185
  try {
249071
249186
  const now = new Date().toISOString();
249072
- const records = req.body.map((item) => ({
249073
- ...item,
249074
- id: nanoid3(),
249075
- created_date: now,
249076
- updated_date: now
249077
- }));
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
+ }
249078
249202
  const inserted = stripInternalFields(await collection.insertAsync(records));
249079
249203
  emit(appId, entityName, "create", inserted);
249080
249204
  res.status(201).json(inserted);
@@ -249087,8 +249211,14 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
249087
249211
  const { appId, entityName, id: id2 } = req.params;
249088
249212
  const { id: _id, created_date: _created_date, ...body } = req.body;
249089
249213
  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
+ }
249090
249220
  const updateData = {
249091
- ...body,
249221
+ ...filteredBody,
249092
249222
  updated_date: new Date().toISOString()
249093
249223
  };
249094
249224
  const result = await collection.updateAsync({ id: id2 }, { $set: updateData }, { returnUpdatedDocs: true });
@@ -251179,13 +251309,13 @@ function createProgram(context) {
251179
251309
  program2.addCommand(getLogoutCommand(context));
251180
251310
  program2.addCommand(getCreateCommand(context));
251181
251311
  program2.addCommand(getDashboardCommand(context));
251182
- program2.addCommand(getDeployCommand2(context));
251312
+ program2.addCommand(getDeployCommand(context));
251183
251313
  program2.addCommand(getLinkCommand(context));
251184
251314
  program2.addCommand(getEjectCommand(context));
251185
251315
  program2.addCommand(getEntitiesPushCommand(context));
251186
251316
  program2.addCommand(getAgentsCommand(context));
251187
251317
  program2.addCommand(getConnectorsCommand(context));
251188
- program2.addCommand(getFunctionsCommand(context));
251318
+ program2.addCommand(getFunctionsDeployCommand(context));
251189
251319
  program2.addCommand(getSecretsCommand(context));
251190
251320
  program2.addCommand(getSiteCommand(context));
251191
251321
  program2.addCommand(getTypesCommand(context));
@@ -255431,4 +255561,4 @@ export {
255431
255561
  CLIExitError
255432
255562
  };
255433
255563
 
255434
- //# debugId=FD4A53B035AEBB5D64756E2164756E21
255564
+ //# debugId=9474DF9F31ED113764756E2164756E21