@gigadrive/network-config 3.1.0 → 3.1.1

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.d.mts CHANGED
@@ -484,7 +484,7 @@ interface ConfigV4 extends Config {
484
484
  /**
485
485
  * Additional environment variables to set during runtime and build.
486
486
  */
487
- env: Record<string, string>;
487
+ env?: Record<string, string>;
488
488
  /**
489
489
  * Optionally, specify additional services like databases to deploy.
490
490
  */
@@ -507,6 +507,10 @@ interface ConfigV4FunctionSettings {
507
507
  * The runtime to use for the function.
508
508
  */
509
509
  runtime?: Runtime;
510
+ /**
511
+ * Enable function response streaming. When omitted, Node and Bun runtimes stream by default.
512
+ */
513
+ streaming?: boolean;
510
514
  /**
511
515
  * Use to create symlinks on the final function. This is useful for applications that require use of the file system, since serverless functions are ephemeral and have read-only file systems, except for /tmp.
512
516
  */
package/dist/index.d.ts CHANGED
@@ -484,7 +484,7 @@ interface ConfigV4 extends Config {
484
484
  /**
485
485
  * Additional environment variables to set during runtime and build.
486
486
  */
487
- env: Record<string, string>;
487
+ env?: Record<string, string>;
488
488
  /**
489
489
  * Optionally, specify additional services like databases to deploy.
490
490
  */
@@ -507,6 +507,10 @@ interface ConfigV4FunctionSettings {
507
507
  * The runtime to use for the function.
508
508
  */
509
509
  runtime?: Runtime;
510
+ /**
511
+ * Enable function response streaming. When omitted, Node and Bun runtimes stream by default.
512
+ */
513
+ streaming?: boolean;
510
514
  /**
511
515
  * Use to create symlinks on the final function. This is useful for applications that require use of the file system, since serverless functions are ephemeral and have read-only file systems, except for /tmp.
512
516
  */
package/dist/index.js CHANGED
@@ -47438,6 +47438,19 @@ schema (${ast._tag}): ${ast}`;
47438
47438
  if (value3 == null) return void 0;
47439
47439
  return Array.isArray(value3) ? value3 : [value3];
47440
47440
  };
47441
+ var runtimeStreamsByDefault = (runtime5) => runtime5 == null || runtime5.startsWith("node-") || runtime5.startsWith("bun-");
47442
+ var normalizeRouteDestination = (destination) => {
47443
+ const [withoutHash] = destination.split("#", 1);
47444
+ const [withoutQuery] = withoutHash.split("?", 1);
47445
+ return withoutQuery.replace(/^\/+/, "");
47446
+ };
47447
+ var destinationMatchesEntrypoint = (destination, entrypointPath) => {
47448
+ const normalizedDestination = normalizeRouteDestination(destination);
47449
+ if (normalizedDestination === entrypointPath) return true;
47450
+ if (!normalizedDestination.includes("$")) return false;
47451
+ const pattern2 = normalizedDestination.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\$[\w]+/g, ".+");
47452
+ return new RegExp(`^${pattern2}$`).test(entrypointPath);
47453
+ };
47441
47454
  var matchesPattern = (path3, pattern2) => {
47442
47455
  if (minimatch(path3, pattern2)) return true;
47443
47456
  try {
@@ -47456,10 +47469,12 @@ schema (${ast._tag}): ${ast}`;
47456
47469
  }
47457
47470
  return settings;
47458
47471
  };
47459
- var resolveRouteHandler = (destination, redirect) => {
47472
+ var resolveRouteHandler = (destination, redirect, entrypoints = []) => {
47460
47473
  const isExternal = destination.toLowerCase().startsWith("http://") || destination.toLowerCase().startsWith("https://");
47461
47474
  if (redirect === true) return "HTTP_REDIRECT";
47462
- return isExternal ? "HTTP_PROXY" : "SERVERLESS_FUNCTION";
47475
+ if (isExternal) return "HTTP_PROXY";
47476
+ const matchingEntrypoints = entrypoints.filter((item) => destinationMatchesEntrypoint(destination, item.path));
47477
+ return matchingEntrypoints.length > 0 && matchingEntrypoints.every((entrypoint) => entrypoint.streaming === true) ? "SERVERLESS_FUNCTION_STREAMING" : "SERVERLESS_FUNCTION";
47463
47478
  };
47464
47479
  var isRegion = (r) => AVAILABLE_REGIONS.includes(r);
47465
47480
  var resolveRegions = (configRegions) => {
@@ -47467,10 +47482,10 @@ schema (${ast._tag}): ${ast}`;
47467
47482
  const valid = configRegions?.filter(isRegion);
47468
47483
  return valid && valid.length > 0 ? valid : AVAILABLE_REGIONS;
47469
47484
  };
47470
- var mapRoute = (route) => ({
47485
+ var mapRoute = (route, entrypoints) => ({
47471
47486
  path: route.source,
47472
47487
  destination: route.destination,
47473
- handler: resolveRouteHandler(route.destination, route.redirect),
47488
+ handler: resolveRouteHandler(route.destination, route.redirect, entrypoints),
47474
47489
  headers: route.headers ?? {},
47475
47490
  methods: route.methods ?? ["ANY"],
47476
47491
  positiveRequirements: route.has,
@@ -47481,9 +47496,8 @@ schema (${ast._tag}): ${ast}`;
47481
47496
  const entrypoints = [];
47482
47497
  if (config2.functions == null) return entrypoints;
47483
47498
  for (const [fnPath, func2] of Object.entries(config2.functions)) {
47484
- const settings = getFunctionSettings(fnPath, config2);
47485
- if (settings == null) {
47486
- yield* new FunctionConfigError({
47499
+ if (getFunctionSettings(fnPath, config2) == null) {
47500
+ return yield* new FunctionConfigError({
47487
47501
  message: `Settings invalid for function at path '${fnPath}'`,
47488
47502
  functionPath: fnPath
47489
47503
  });
@@ -47498,14 +47512,23 @@ schema (${ast._tag}): ${ast}`;
47498
47512
  for (const file of matchedFiles) {
47499
47513
  if (entrypoints.some((ep) => ep.path === file)) continue;
47500
47514
  if (Object.keys(config2.functions).some((f) => f === file && f !== fnPath)) continue;
47515
+ const settings = getFunctionSettings(file, config2);
47516
+ if (settings == null) {
47517
+ return yield* new FunctionConfigError({
47518
+ message: `Settings invalid for function at path '${file}'`,
47519
+ functionPath: file
47520
+ });
47521
+ }
47522
+ const runtime5 = settings.runtime ?? "node-20";
47523
+ const streaming = settings.streaming ?? runtimeStreamsByDefault(runtime5);
47501
47524
  entrypoints.push({
47502
47525
  path: file,
47503
- runtime: settings.runtime ?? "node-20",
47526
+ runtime: runtime5,
47504
47527
  memory: settings.memory ?? 128,
47505
47528
  maxDuration: settings.max_duration ?? 30,
47506
47529
  schedule: func2.schedule,
47507
47530
  symlinks: func2.symlinks,
47508
- streaming: settings.runtime == null || settings.runtime.startsWith("node-") || settings.runtime.startsWith("bun-"),
47531
+ streaming,
47509
47532
  package: settings.includeFiles != null || settings.excludeFiles != null ? {
47510
47533
  includeFiles: toArray3(settings.includeFiles),
47511
47534
  excludeFiles: toArray3(settings.excludeFiles)
@@ -47581,7 +47604,7 @@ schema (${ast._tag}): ${ast}`;
47581
47604
  entrypoints,
47582
47605
  errors: [],
47583
47606
  warnings: [],
47584
- routes: (config2.routes ?? []).map(mapRoute)
47607
+ routes: (config2.routes ?? []).map((route) => mapRoute(route, entrypoints))
47585
47608
  };
47586
47609
  })
47587
47610
  })
@@ -47799,7 +47822,7 @@ schema (${ast._tag}): ${ast}`;
47799
47822
  Object.assign(environmentVariables, env);
47800
47823
  }
47801
47824
  }
47802
- const streaming = runtime5.startsWith("node-") || runtime5.startsWith("bun-");
47825
+ const streaming = functionConfig.supportsResponseStreaming ?? functionConfig.experimentalResponseStreaming ?? runtime5.startsWith("node-");
47803
47826
  let filePathMap = {};
47804
47827
  for (const [key, value3] of Object.entries(configFilePathMap)) {
47805
47828
  filePathMap[pathService.join(projectFolder, key)] = value3;
@@ -47935,6 +47958,10 @@ schema (${ast._tag}): ${ast}`;
47935
47958
  $ref: "#/$defs/runtimes",
47936
47959
  description: "The runtime to use for the function."
47937
47960
  },
47961
+ streaming: {
47962
+ type: "boolean",
47963
+ description: "Enable function response streaming. When omitted, Node and Bun runtimes stream by default."
47964
+ },
47938
47965
  schedule: {
47939
47966
  type: "string",
47940
47967
  description: "An expression to schedule the function to run at specific times.",