@base44-preview/cli 0.1.32-pr.663.ac8cbb8 → 0.1.32-pr.663.d2e3c0d

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
@@ -249214,44 +249214,6 @@ function areaListing(area, operations, max = AREA_OPERATIONS_MAX) {
249214
249214
  truncated: operations.length > max
249215
249215
  };
249216
249216
  }
249217
- // src/core/api-spec/grep.ts
249218
- var CONTEXT_CHARS = 40;
249219
- var MAX_SNIPPETS = 3;
249220
- var MAX_SNIPPET_CHARS = 200;
249221
- function unescapeJson(snippet) {
249222
- return snippet.replace(/\\[nrt]/g, " ").replace(/\\"/g, '"');
249223
- }
249224
- function snippets(text, pattern) {
249225
- const found = [];
249226
- for (const match of text.matchAll(pattern)) {
249227
- const start = Math.max(0, match.index - CONTEXT_CHARS);
249228
- const end = match.index + match[0].length + CONTEXT_CHARS;
249229
- found.push(unescapeJson(text.slice(start, Math.min(end, start + MAX_SNIPPET_CHARS))));
249230
- if (found.length === MAX_SNIPPETS || match[0].length === 0) {
249231
- break;
249232
- }
249233
- }
249234
- return found;
249235
- }
249236
- function grepSpec(spec, operations, pattern, options = {}) {
249237
- const regex = new RegExp(pattern, options.ignoreCase ? "gi" : "g");
249238
- const hits = [];
249239
- for (const op of operations) {
249240
- const { summary, description, parameters, requestBody, responses } = op.operation;
249241
- const matches = snippets(`${op.endpoint} ${JSON.stringify({ summary, description, parameters, requestBody, responses })}`, regex);
249242
- if (matches.length > 0) {
249243
- hits.push({ ...toOperationSummary(op), matches });
249244
- }
249245
- }
249246
- const schemas = options.schemas === false ? {} : spec.components?.schemas;
249247
- for (const [schema, definition] of Object.entries(schemas ?? {})) {
249248
- const matches = snippets(JSON.stringify(definition), regex);
249249
- if (matches.length > 0) {
249250
- hits.push({ schema, matches });
249251
- }
249252
- }
249253
- return hits.slice(0, options.limit ?? 20);
249254
- }
249255
249217
  // src/core/api-spec/schema.ts
249256
249218
  var HTTP_METHODS = [
249257
249219
  "get",
@@ -249439,9 +249401,50 @@ function leftoverRefs(node, schemas, found = new Map) {
249439
249401
  }
249440
249402
  return found;
249441
249403
  }
249404
+ var SCHEMA_DATA_KEYS = new Set([
249405
+ "example",
249406
+ "examples",
249407
+ "default",
249408
+ "enum",
249409
+ "const"
249410
+ ]);
249411
+ var DOCS_CALLOUT = /<(Info|Note|Tip|Check|Warning)>([\s\S]*?)<\/\1>/g;
249412
+ var RELATIVE_LINK = /\[([^\]]+)\]\(\/[^)]*\)/g;
249413
+ function cleanText(text) {
249414
+ return text.replace(DOCS_CALLOUT, (_, kind, body) => kind === "Warning" ? `Warning: ${body}` : body).replace(RELATIVE_LINK, "$1");
249415
+ }
249416
+ function slimSchema(node, isPropertyMap = false) {
249417
+ if (Array.isArray(node)) {
249418
+ return node.map((item) => slimSchema(item));
249419
+ }
249420
+ if (node === null || typeof node !== "object") {
249421
+ return node;
249422
+ }
249423
+ const entries = Object.entries(node);
249424
+ if (isPropertyMap) {
249425
+ return Object.fromEntries(entries.map(([name, value]) => [name, slimSchema(value)]));
249426
+ }
249427
+ const slim = {};
249428
+ for (const [key, value] of entries) {
249429
+ if (key === "title" && typeof value === "string") {
249430
+ continue;
249431
+ }
249432
+ slim[key] = SCHEMA_DATA_KEYS.has(key) ? value : key === "properties" ? slimSchema(value, true) : key === "description" && typeof value === "string" ? cleanText(value) : slimSchema(value);
249433
+ }
249434
+ const { anyOf, ...rest } = slim;
249435
+ const nullable = Array.isArray(anyOf) && anyOf.length === 2 ? nullableType(anyOf) : undefined;
249436
+ return nullable ? { type: [nullable, "null"], ...rest } : slim;
249437
+ }
249438
+ function nullableType(variants) {
249439
+ const types = variants.map((variant) => variant !== null && typeof variant === "object" && Object.keys(variant).length === 1 && typeof variant.type === "string" ? variant.type : undefined);
249440
+ if (types.includes(undefined) || !types.includes("null")) {
249441
+ return;
249442
+ }
249443
+ return types.find((type) => type !== "null");
249444
+ }
249442
249445
  function getOperationContract(spec, op) {
249443
249446
  const schemas = spec.components?.schemas ?? {};
249444
- const inline = (node) => node === undefined ? null : inlineRefs(node, schemas);
249447
+ const inline = (node) => node === undefined ? null : slimSchema(inlineRefs(node, schemas));
249445
249448
  const responses = Object.entries(op.operation.responses ?? {}).flatMap(([status, response]) => {
249446
249449
  const parsed = ResponseObjectSchema.safeParse(response);
249447
249450
  return parsed.success ? [[status, parsed.data]] : [];
@@ -249454,7 +249457,7 @@ function getOperationContract(spec, op) {
249454
249457
  method: op.method,
249455
249458
  path: op.path,
249456
249459
  summary: op.summary,
249457
- description: op.description,
249460
+ description: cleanText(op.description),
249458
249461
  parameters: (op.operation.parameters ?? []).flatMap((parameter) => {
249459
249462
  const parsed = ParameterSchema.safeParse(parameter);
249460
249463
  if (!parsed.success) {
@@ -249468,7 +249471,7 @@ function getOperationContract(spec, op) {
249468
249471
  in: location2,
249469
249472
  required: required ?? false,
249470
249473
  schema: inline(schema ?? {}),
249471
- ...description && !inSchema ? { description } : {},
249474
+ ...description && !inSchema ? { description: cleanText(description) } : {},
249472
249475
  ..."example" in parsed.data ? { example: parsed.data.example } : {}
249473
249476
  }
249474
249477
  ];
@@ -249476,14 +249479,25 @@ function getOperationContract(spec, op) {
249476
249479
  ...requestBody.contentType && requestBody.contentType !== "application/json" ? { requestBodyContentType: requestBody.contentType } : {},
249477
249480
  requestBodySchema: inline(requestBody.schema),
249478
249481
  responseSchema: inline(success),
249479
- errors: Object.fromEntries(errors.map(([status, response]) => [status, response.description ?? ""]))
249482
+ errors: Object.fromEntries(errors.map(([status, response]) => [
249483
+ status,
249484
+ cleanText(response.description ?? "")
249485
+ ]))
249480
249486
  };
249481
249487
  const refs = leftoverRefs(contract, schemas);
249482
249488
  return {
249483
249489
  ...contract,
249484
- ...refs.size > 0 ? { refs: Object.fromEntries(refs) } : {}
249490
+ ...refs.size > 0 ? {
249491
+ refs: Object.fromEntries([...refs].map(([ref, schema]) => [ref, slimSchema(schema)]))
249492
+ } : {}
249485
249493
  };
249486
249494
  }
249495
+
249496
+ // src/core/api-spec/grep.ts
249497
+ function grepOperations(spec, operations, pattern, options = {}) {
249498
+ const regex = new RegExp(pattern, options.ignoreCase ? "i" : "");
249499
+ return operations.filter((op) => regex.test(JSON.stringify(getOperationContract(spec, op)))).slice(0, options.limit ?? 20).map(toOperationSummary);
249500
+ }
249487
249501
  // src/core/api-spec/request.ts
249488
249502
  var MAX_ERROR_BODY_CHARS = 4000;
249489
249503
  async function readBody(response) {
@@ -249510,7 +249524,8 @@ async function sendApiRequest(method, path, body) {
249510
249524
  } catch (error) {
249511
249525
  const apiError = await ApiError.fromHttpError(error, `calling ${method} ${path}`);
249512
249526
  const raw = error instanceof HTTPError ? await readBody(error.response) : undefined;
249513
- throw new ApiError(apiError.message, {
249527
+ const message = raw && apiError.statusCode !== undefined ? `Error calling ${method} ${path}: HTTP ${apiError.statusCode}` : apiError.message;
249528
+ throw new ApiError(message, {
249514
249529
  statusCode: apiError.statusCode,
249515
249530
  requestUrl: apiError.requestUrl,
249516
249531
  requestMethod: apiError.requestMethod,
@@ -249778,11 +249793,9 @@ async function grepAction(ctx, pattern, options) {
249778
249793
  if (options.readOnly) {
249779
249794
  operations = operations.filter((op) => op.readOnly);
249780
249795
  }
249781
- const narrowed = options.area !== undefined || options.readOnly === true;
249782
- const hits = grepSpec(spec, operations, pattern, {
249796
+ const hits = grepOperations(spec, operations, pattern, {
249783
249797
  ignoreCase: options.ignoreCase,
249784
- limit,
249785
- schemas: !narrowed
249798
+ limit
249786
249799
  });
249787
249800
  return { stdout: formatJson(hits) };
249788
249801
  }
@@ -249790,7 +249803,7 @@ function getApiGrepCommand() {
249790
249803
  return new Base44Command("grep", {
249791
249804
  requireAuth: false,
249792
249805
  requireAppContext: false
249793
- }).description("Search the API spec with a regular expression, for when search misses").argument("<pattern>", 'Regular expression, e.g. "runs.*status"').option("--area <area>", "Search only one area's operations (see base44 api catalog)").option("-i, --ignore-case", "Case-insensitive match").option("--limit <n>", "Most operations or schemas to return (default 20)").option("--read-only", READ_ONLY_FILTER_HELP).option("--refresh", REFRESH_OPTION_HELP).action(grepAction);
249806
+ }).description("Search the API spec with a regular expression, for when search misses").argument("<pattern>", 'Regular expression, e.g. "runs.*status"').option("--area <area>", "Search only one area's operations (see base44 api catalog)").option("-i, --ignore-case", "Case-insensitive match").option("--limit <n>", "Most operations to return (default 20)").option("--read-only", READ_ONLY_FILTER_HELP).option("--refresh", REFRESH_OPTION_HELP).action(grepAction);
249794
249807
  }
249795
249808
 
249796
249809
  // src/cli/commands/api/search.ts
@@ -262350,7 +262363,7 @@ var nativeEnumType = ZodNativeEnum.create;
262350
262363
  var promiseType = ZodPromise.create;
262351
262364
  var effectsType = ZodEffects.create;
262352
262365
  var optionalType = ZodOptional2.create;
262353
- var nullableType = ZodNullable2.create;
262366
+ var nullableType2 = ZodNullable2.create;
262354
262367
  var preprocessType = ZodEffects.createWithPreprocess;
262355
262368
  var pipelineType = ZodPipeline.create;
262356
262369
  // ../functions-compiler/src/contracts.ts
@@ -273352,4 +273365,4 @@ export {
273352
273365
  runCLI
273353
273366
  };
273354
273367
 
273355
- //# debugId=47D4434C61AEF7C764756E2164756E21
273368
+ //# debugId=34B2FE9173AAC44664756E2164756E21