@apifn/core 0.0.1 → 0.0.2

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/index.cjs CHANGED
@@ -5823,7 +5823,6 @@ var KNOWN_DESCRIPTOR_KEYS = [
5823
5823
  "headers",
5824
5824
  "security"
5825
5825
  ];
5826
- var PATH_PARAM_PATTERN = /:([A-Za-z0-9_]+)/g;
5827
5826
  function isObject(value) {
5828
5827
  return typeof value === "object" && value !== null && !Array.isArray(value);
5829
5828
  }
@@ -5856,10 +5855,29 @@ function withBasePath(path2, basePath) {
5856
5855
  }
5857
5856
  function toOpenApiPath(path2) {
5858
5857
  const params = [];
5859
- const openApiPath = path2.replace(PATH_PARAM_PATTERN, (_match, param) => {
5858
+ let openApiPath = "";
5859
+ let index = 0;
5860
+ while (index < path2.length) {
5861
+ const char = path2[index];
5862
+ if (char !== ":") {
5863
+ openApiPath += char;
5864
+ index += 1;
5865
+ continue;
5866
+ }
5867
+ let end = index + 1;
5868
+ while (end < path2.length && /[A-Za-z0-9_]/.test(path2[end])) {
5869
+ end += 1;
5870
+ }
5871
+ if (end === index + 1) {
5872
+ openApiPath += char;
5873
+ index += 1;
5874
+ continue;
5875
+ }
5876
+ const param = path2.slice(index + 1, end);
5860
5877
  params.push(param);
5861
- return `{${param}}`;
5862
- });
5878
+ openApiPath += `{${param}}`;
5879
+ index = end;
5880
+ }
5863
5881
  return { path: openApiPath, pathParams: params };
5864
5882
  }
5865
5883
  function pathParamsToDescriptors(pathParams) {
@@ -6406,8 +6424,6 @@ function upconvertNode(value) {
6406
6424
  const merged = new Set(currentType);
6407
6425
  merged.add("null");
6408
6426
  output.type = Array.from(merged);
6409
- } else {
6410
- output.type = ["null"];
6411
6427
  }
6412
6428
  }
6413
6429
  return output;
@@ -6499,8 +6515,19 @@ var HTTP_METHODS = ["get", "put", "post", "delete", "options", "head", "patch",
6499
6515
  function isRef(obj) {
6500
6516
  return typeof obj === "object" && obj !== null && "$ref" in obj;
6501
6517
  }
6502
- function resolveParam(p) {
6503
- if (isRef(p)) return null;
6518
+ function emitUnresolvedRef(opPath, location, ref, emit) {
6519
+ emit({
6520
+ type: "modified",
6521
+ breaking: true,
6522
+ path: `${opPath}.${location}`,
6523
+ description: `Parameter reference '${ref}' in ${opPath} could not be resolved; diff coverage is incomplete`
6524
+ });
6525
+ }
6526
+ function resolveParam(p, opPath, location, emit) {
6527
+ if (isRef(p)) {
6528
+ emitUnresolvedRef(opPath, location, p.$ref, emit);
6529
+ return null;
6530
+ }
6504
6531
  if (typeof p === "object" && p !== null && "name" in p && "in" in p) {
6505
6532
  return p;
6506
6533
  }
@@ -6524,8 +6551,8 @@ function isTypeNarrowing(before, after) {
6524
6551
  return false;
6525
6552
  }
6526
6553
  function diffParameters(opPath, before, after, emit) {
6527
- const beforeParams = (before.parameters ?? []).map(resolveParam).filter((p) => p !== null);
6528
- const afterParams = (after.parameters ?? []).map(resolveParam).filter((p) => p !== null);
6554
+ const beforeParams = (before.parameters ?? []).map((param, index) => resolveParam(param, opPath, `parameters[${index}]`, emit)).filter((p) => p !== null);
6555
+ const afterParams = (after.parameters ?? []).map((param, index) => resolveParam(param, opPath, `parameters[${index}]`, emit)).filter((p) => p !== null);
6529
6556
  const beforeMap = /* @__PURE__ */ new Map();
6530
6557
  for (const p of beforeParams) {
6531
6558
  beforeMap.set(`${p.in}:${p.name}`, p);
@@ -6605,6 +6632,16 @@ function diffRequestBody(opPath, before, after, emit) {
6605
6632
  return;
6606
6633
  }
6607
6634
  if (!beforeBody || !afterBody) return;
6635
+ if (!beforeBody.required && afterBody.required) {
6636
+ emit({
6637
+ type: "modified",
6638
+ breaking: true,
6639
+ path: `${opPath}.requestBody.required`,
6640
+ description: `Request body became required in ${opPath}`,
6641
+ before: false,
6642
+ after: true
6643
+ });
6644
+ }
6608
6645
  const beforeSchema = beforeBody.content?.["application/json"]?.schema ?? null;
6609
6646
  const afterSchema = afterBody.content?.["application/json"]?.schema ?? null;
6610
6647
  if (!beforeSchema || !afterSchema) return;
@@ -6626,12 +6663,12 @@ function diffObjectSchemaRequiredFields(opPath, schemaPath, before, after, emit)
6626
6663
  const afterProps = after.properties ?? {};
6627
6664
  const beforeProps = before.properties ?? {};
6628
6665
  for (const field of afterRequired) {
6629
- if (!beforeRequired.has(field) && !beforeProps[field]) {
6666
+ if (!beforeRequired.has(field)) {
6630
6667
  emit({
6631
6668
  type: "modified",
6632
6669
  breaking: true,
6633
6670
  path: `${opPath}.${schemaPath}.required`,
6634
- description: `New required field '${field}' added to request body in ${opPath}`
6671
+ description: beforeProps[field] ? `Existing request body field '${field}' became required in ${opPath}` : `New required field '${field}' added to request body in ${opPath}`
6635
6672
  });
6636
6673
  }
6637
6674
  }
@@ -6729,11 +6766,12 @@ function diffSecurity(opPath, before, after, emit) {
6729
6766
  }
6730
6767
  for (const key of beforeKeys) {
6731
6768
  if (!afterKeys.has(key)) {
6769
+ const removedAlternative = afterSec.length > 0;
6732
6770
  emit({
6733
6771
  type: "removed",
6734
- breaking: false,
6772
+ breaking: removedAlternative,
6735
6773
  path: `${opPath}.security`,
6736
- description: `Security requirement removed from ${opPath}`,
6774
+ description: removedAlternative ? `Security requirement alternative removed from ${opPath} \u2014 breaking` : `Security requirement removed from ${opPath}`,
6737
6775
  before: beforeSec,
6738
6776
  after: afterSec
6739
6777
  });
@@ -7009,7 +7047,8 @@ function apifnWatchMiddleware(options) {
7009
7047
  baseUrl,
7010
7048
  apiKey,
7011
7049
  fireAndForget = true,
7012
- silent = false
7050
+ silent = false,
7051
+ timeoutMs = 2e3
7013
7052
  } = options;
7014
7053
  const eventUrl = `${baseUrl.replace(/\/$/, "")}/api/events`;
7015
7054
  const headers = {
@@ -7019,11 +7058,19 @@ function apifnWatchMiddleware(options) {
7019
7058
  if (apiKey) headers["Authorization"] = `Bearer ${apiKey}`;
7020
7059
  async function sendEvent(event) {
7021
7060
  try {
7022
- const res = await fetch(eventUrl, {
7023
- method: "POST",
7024
- headers,
7025
- body: JSON.stringify(event)
7026
- });
7061
+ const controller = new AbortController();
7062
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
7063
+ let res;
7064
+ try {
7065
+ res = await fetch(eventUrl, {
7066
+ method: "POST",
7067
+ headers,
7068
+ body: JSON.stringify(event),
7069
+ signal: controller.signal
7070
+ });
7071
+ } finally {
7072
+ clearTimeout(timer);
7073
+ }
7027
7074
  if (!res.ok && !silent) {
7028
7075
  console.warn(`[apifn/watchfn] Event POST returned HTTP ${res.status}`);
7029
7076
  }