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

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
@@ -249102,23 +249102,30 @@ var wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
249102
249102
  var SPACE_OR_PUNCTUATION = /[\n\r\p{Z}\p{P}]+/u;
249103
249103
 
249104
249104
  // src/core/api-spec/search.ts
249105
- var BOOST = { path: 8, summary: 5, description: 2, parameters: 0.5 };
249105
+ var BOOST = {
249106
+ method: 1,
249107
+ path: 8,
249108
+ summary: 5,
249109
+ description: 2,
249110
+ parameters: 0.5
249111
+ };
249106
249112
  var MIN_RELATIVE_SCORE = 0.2;
249107
249113
  var TOKEN_SEPARATOR = /[\n\r\p{Z}\p{P}\p{S}]+/u;
249108
- var STOPWORDS = new Set("a an and are at be by do does for from how i in is it its me my of on or our that the this to we what who with you your".split(" "));
249114
+ var STOPWORDS = new Set("a an and are at be by do does for from how i id in is it its me my of on or our that the this to we what who with you your".split(" "));
249109
249115
  function tokenize(text) {
249110
- return text.split(TOKEN_SEPARATOR).filter((word) => word && !STOPWORDS.has(word.toLowerCase()));
249116
+ return text.split(TOKEN_SEPARATOR).filter((word) => word.length >= 2 && !STOPWORDS.has(word.toLowerCase()));
249111
249117
  }
249112
249118
  function toOperationSummary(op) {
249113
249119
  return { endpoint: op.endpoint, summary: op.summary };
249114
249120
  }
249115
249121
  function buildSearchIndex(operations) {
249116
249122
  const index = new MiniSearch({
249117
- fields: ["path", "summary", "description", "parameters"],
249123
+ fields: ["method", "path", "summary", "description", "parameters"],
249118
249124
  tokenize
249119
249125
  });
249120
249126
  index.addAll(operations.map((op, id) => ({
249121
249127
  id,
249128
+ method: op.method,
249122
249129
  path: op.path.replace(/\{[^}]*\}/g, ""),
249123
249130
  summary: op.summary,
249124
249131
  description: op.description,
@@ -249126,27 +249133,37 @@ function buildSearchIndex(operations) {
249126
249133
  })));
249127
249134
  return index;
249128
249135
  }
249129
- function summaryCoverage(query, op) {
249130
- const terms = tokenize(query.toLowerCase());
249131
- if (!op || terms.length === 0) {
249132
- return 0;
249133
- }
249134
- const words = tokenize(op.summary.toLowerCase());
249135
- return terms.filter((term) => words.some((word) => word.startsWith(term))).length / terms.length;
249136
+ function summaryMatch(terms, op) {
249137
+ const words = tokenize(op?.summary.toLowerCase() ?? "");
249138
+ const named = (word) => terms.some((term) => word.startsWith(term));
249139
+ return {
249140
+ coverage: terms.filter((term) => words.some((word) => word.startsWith(term))).length / terms.length,
249141
+ precision: words.length ? words.filter(named).length / words.length : 0
249142
+ };
249136
249143
  }
249144
+ var readsFirst = (op) => op?.method === "GET" ? 0 : 1;
249137
249145
  function searchOperations(operations, query, options = {}) {
249146
+ const terms = tokenize(query.toLowerCase());
249147
+ if (terms.length === 0) {
249148
+ return [];
249149
+ }
249138
249150
  const index = buildSearchIndex(operations);
249139
249151
  const hits = index.search(query, {
249140
249152
  prefix: (term) => term.length >= 3,
249141
249153
  fuzzy: (term) => term.length >= 4 ? 0.2 : false,
249142
249154
  boost: BOOST,
249143
249155
  filter: options.readOnly ? (hit) => operations[hit.id]?.readOnly === true : undefined
249144
- }).map((hit) => ({
249145
- ...hit,
249146
- score: hit.score * (1 + summaryCoverage(query, operations[hit.id]))
249147
- })).sort((a, b) => b.score - a.score);
249148
- const baseline = (hits[0]?.score ?? 0) * MIN_RELATIVE_SCORE;
249149
- return hits.filter((hit) => hit.score >= baseline).slice(0, options.limit ?? 5).flatMap((hit) => {
249156
+ }).map((hit) => {
249157
+ const match = summaryMatch(terms, operations[hit.id]);
249158
+ return {
249159
+ ...hit,
249160
+ ...match,
249161
+ full: match.coverage === 1,
249162
+ score: hit.score * (1 + match.coverage)
249163
+ };
249164
+ }).sort((a, b) => Number(b.full) - Number(a.full) || (a.full ? b.precision - a.precision || readsFirst(operations[a.id]) - readsFirst(operations[b.id]) : 0) || b.score - a.score);
249165
+ const baseline = Math.max(0, ...hits.map((hit) => hit.score)) * MIN_RELATIVE_SCORE;
249166
+ return hits.filter((hit) => hit.full || hit.score >= baseline).slice(0, options.limit ?? 5).flatMap((hit) => {
249150
249167
  const op = operations[hit.id];
249151
249168
  return op ? [toOperationSummary(op)] : [];
249152
249169
  });
@@ -249177,7 +249194,7 @@ function groupByArea(operations) {
249177
249194
  }
249178
249195
  return new Map([...areas].sort(([a], [b]) => byCodePoint(a, b)));
249179
249196
  }
249180
- function readsFirst(ops) {
249197
+ function readsFirst2(ops) {
249181
249198
  const isRead = (op) => op.method === "GET" ? 0 : 1;
249182
249199
  return [...ops].sort((a, b) => isRead(a) - isRead(b));
249183
249200
  }
@@ -249185,7 +249202,7 @@ function catalogIndex(operations) {
249185
249202
  const areas = [...groupByArea(operations)].map(([area, ops]) => ops.length <= INLINE_AREA_MAX ? { area, operations: ops.map(toOperationSummary) } : {
249186
249203
  area,
249187
249204
  operationCount: ops.length,
249188
- sample: readsFirst(ops).slice(0, AREA_SAMPLE_MAX).map((op) => op.summary)
249205
+ sample: readsFirst2(ops).slice(0, AREA_SAMPLE_MAX).map((op) => op.summary)
249189
249206
  });
249190
249207
  return { areas, total: operations.length };
249191
249208
  }
@@ -249636,7 +249653,7 @@ function getApiCatalogCommand() {
249636
249653
  }
249637
249654
 
249638
249655
  // src/cli/commands/api/fetch.ts
249639
- async function findOperation(ctx, method, path, refresh) {
249656
+ async function findOperation(ctx, method, path, { refresh, flag }) {
249640
249657
  const { spec } = await loadSpecTask(ctx, refresh);
249641
249658
  const op = matchOperation(listOperations(spec), method, path);
249642
249659
  if (!op) {
@@ -249644,7 +249661,7 @@ async function findOperation(ctx, method, path, refresh) {
249644
249661
  hints: [
249645
249662
  {
249646
249663
  message: "The cached spec may predate this route; fetch it again",
249647
- command: "base44 api fetch <METHOD> <path> --help --refresh"
249664
+ command: `base44 api fetch ${method} ${path} ${flag} --refresh`
249648
249665
  },
249649
249666
  {
249650
249667
  message: "Find the operation and its path template",
@@ -249703,11 +249720,17 @@ async function fetchAction(ctx, methodArg, path, options, command) {
249703
249720
  }
249704
249721
  const method = methodArg.toUpperCase();
249705
249722
  if (options.help) {
249706
- const { spec, op } = await findOperation(ctx, method, path, options.refresh);
249723
+ const { spec, op } = await findOperation(ctx, method, path, {
249724
+ refresh: options.refresh,
249725
+ flag: "--help"
249726
+ });
249707
249727
  return { stdout: formatJson(getOperationContract(spec, op)) };
249708
249728
  }
249709
249729
  if (options.readOnly) {
249710
- const { op } = await findOperation(ctx, method, path, options.refresh);
249730
+ const { op } = await findOperation(ctx, method, path, {
249731
+ refresh: options.refresh,
249732
+ flag: "--read-only"
249733
+ });
249711
249734
  if (!op.readOnly) {
249712
249735
  throw new InvalidInputError(`Refused under --read-only: ${op.method} ${op.path} is not a read-only operation. Nothing was sent.`);
249713
249736
  }
@@ -273329,4 +273352,4 @@ export {
273329
273352
  runCLI
273330
273353
  };
273331
273354
 
273332
- //# debugId=FB96E058A37AEBFF64756E2164756E21
273355
+ //# debugId=47D4434C61AEF7C764756E2164756E21