@gigadrive/network-config 2.0.0 → 2.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.mjs CHANGED
@@ -1,27 +1,39 @@
1
- // src/index.ts
1
+ // src/find-config.ts
2
+ import fs from "fs";
3
+ import path from "path";
4
+ var ALLOWED_CONFIG_NAMES = ["gigadrive.yaml", "gigadrive.yml", "nebula.yaml", "nebula.yml", "nebula.json"];
5
+ var findConfig = (projectFolder) => {
6
+ for (const name of ALLOWED_CONFIG_NAMES) {
7
+ const filePath = path.join(projectFolder, name);
8
+ if (fs.existsSync(filePath)) {
9
+ return filePath;
10
+ }
11
+ }
12
+ return null;
13
+ };
14
+
15
+ // src/parse-config.ts
2
16
  import Ajv from "ajv";
3
17
  import addFormats from "ajv-formats";
4
- import fs4 from "fs";
5
- import path3 from "path";
6
18
 
7
19
  // src/build-output-v3/parse.ts
8
20
  import { getFilesForPattern } from "@gigadrive/build-utils";
9
- import fs2 from "fs";
10
- import path2 from "path";
21
+ import fs3 from "fs";
22
+ import path3 from "path";
11
23
 
12
24
  // src/parse-raw-config.ts
13
- import fs from "fs";
14
- import path from "path";
25
+ import fs2 from "fs";
26
+ import path2 from "path";
15
27
  import { parse as parseYaml } from "yaml";
16
28
  var parseRawConfig = async (filePath) => {
17
- if (!fs.existsSync(filePath)) {
29
+ if (!fs2.existsSync(filePath)) {
18
30
  throw new Error(`Config file not found at ${filePath}`);
19
31
  }
20
- const fileContents = fs.readFileSync(filePath, "utf8");
32
+ const fileContents = fs2.readFileSync(filePath, "utf8");
21
33
  if (fileContents.length === 0) {
22
34
  throw new Error(`Config file is empty at ${filePath}`);
23
35
  }
24
- const fileExtension = path.extname(filePath).toLowerCase();
36
+ const fileExtension = path2.extname(filePath).toLowerCase();
25
37
  let parsed;
26
38
  try {
27
39
  if (fileExtension === ".json") {
@@ -49,7 +61,7 @@ var parseRawConfig = async (filePath) => {
49
61
  var configPath = ".vercel/output/config.json";
50
62
  var functionConfigsPattern = ".vercel/output/functions/*.func/.vc-config.json";
51
63
  var parseVercelBuildOutputV3 = async (parseResult, projectFolder) => {
52
- const config = await readConfigFile(path2.join(projectFolder, configPath));
64
+ const config = await readConfigFile(path3.join(projectFolder, configPath));
53
65
  if (!config || config.version < 3) {
54
66
  return parseResult;
55
67
  }
@@ -72,12 +84,12 @@ var loadAssetOverrides = async (config, parseResult) => {
72
84
  var loadFunctions = async (config, parseResult, projectFolder) => {
73
85
  const functionConfigs = await getFilesForPattern(functionConfigsPattern, projectFolder);
74
86
  for (const functionConfigPath of functionConfigs) {
75
- const functionConfig = await readConfigFile(path2.join(projectFolder, functionConfigPath));
87
+ const functionConfig = await readConfigFile(path3.join(projectFolder, functionConfigPath));
76
88
  if (!functionConfig) {
77
89
  parseResult.errors.push(`Failed to read function config at ${functionConfigPath}`);
78
90
  continue;
79
91
  }
80
- const functionName = path2.basename(path2.dirname(functionConfigPath)).replace(/\.func$/, "");
92
+ const functionName = path3.basename(path3.dirname(functionConfigPath)).replace(/\.func$/, "");
81
93
  const runtime = translateVercelRuntime(functionConfig.runtime);
82
94
  if (!runtime) {
83
95
  parseResult.errors.push(`Unsupported runtime for function ${functionName}: ${functionConfig.runtime}`);
@@ -105,7 +117,7 @@ var loadFunctions = async (config, parseResult, projectFolder) => {
105
117
  const streaming = runtime == null || runtime.startsWith("node-") || runtime.startsWith("bun-");
106
118
  const filePathMap = {};
107
119
  for (const [key, value] of Object.entries(functionConfig.filePathMap ?? {})) {
108
- filePathMap[path2.join(projectFolder, key)] = value;
120
+ filePathMap[path3.join(projectFolder, key)] = value;
109
121
  }
110
122
  parseResult.entrypoints.push({
111
123
  displayName: functionName,
@@ -116,7 +128,7 @@ var loadFunctions = async (config, parseResult, projectFolder) => {
116
128
  environmentVariables,
117
129
  streaming,
118
130
  package: {
119
- rootOverwrite: path2.join(projectFolder, functionDirectory),
131
+ rootOverwrite: path3.join(projectFolder, functionDirectory),
120
132
  filePathMap
121
133
  }
122
134
  });
@@ -142,7 +154,7 @@ var loadFunctions = async (config, parseResult, projectFolder) => {
142
154
  }
143
155
  };
144
156
  var readConfigFile = async (configFilePath) => {
145
- if (!fs2.existsSync(configFilePath)) {
157
+ if (!fs3.existsSync(configFilePath)) {
146
158
  return null;
147
159
  }
148
160
  const parsed = await parseRawConfig(configFilePath);
@@ -188,7 +200,7 @@ var translateVercelRegion = (region) => {
188
200
 
189
201
  // src/v4/parse.ts
190
202
  import { getFilesForPattern as getFilesForPattern2 } from "@gigadrive/build-utils";
191
- import fs3 from "fs";
203
+ import fs4 from "fs";
192
204
  import { minimatch } from "minimatch";
193
205
 
194
206
  // src/regions.ts
@@ -250,11 +262,11 @@ var parseConfigV4 = async (config, projectFolder) => {
250
262
  const assets = [];
251
263
  if (config.assets != null) {
252
264
  const assetsPath = `${projectFolder}/${config.assets}`;
253
- if (fs3.existsSync(assetsPath) && fs3.statSync(assetsPath).isDirectory()) {
254
- for (const asset of fs3.readdirSync(`${projectFolder}/${config.assets}`, {
265
+ if (fs4.existsSync(assetsPath) && fs4.statSync(assetsPath).isDirectory()) {
266
+ for (const asset of fs4.readdirSync(`${projectFolder}/${config.assets}`, {
255
267
  recursive: true
256
268
  })) {
257
- if (fs3.statSync(`${projectFolder}/${config.assets}/${asset}`).isDirectory()) {
269
+ if (fs4.statSync(`${projectFolder}/${config.assets}/${asset}`).isDirectory()) {
258
270
  continue;
259
271
  }
260
272
  const disallowedExtensions = [".htaccess", ".htpasswd"];
@@ -335,18 +347,343 @@ var getFunctionSettings = (path4, config) => {
335
347
  return functionSettings;
336
348
  };
337
349
 
338
- // src/index.ts
339
- var schemaV4 = JSON.parse(fs4.readFileSync(path3.join(__dirname, "./v4/schema.json"), "utf8"));
340
- var ALLOWED_CONFIG_NAMES = ["gigadrive.yaml", "gigadrive.yml", "nebula.yaml", "nebula.yml", "nebula.json"];
341
- var findConfig = (projectFolder) => {
342
- for (const name of ALLOWED_CONFIG_NAMES) {
343
- const filePath = path3.join(projectFolder, name);
344
- if (fs4.existsSync(filePath)) {
345
- return filePath;
350
+ // src/v4/schema.json
351
+ var schema_default = {
352
+ $schema: "http://json-schema.org/draft-07/schema#",
353
+ title: "Config V4",
354
+ description: "Configuration schema for version 4",
355
+ type: "object",
356
+ required: ["version"],
357
+ properties: {
358
+ version: {
359
+ type: "integer",
360
+ enum: [4],
361
+ description: "The version of the configuration file"
362
+ },
363
+ presets: {
364
+ type: ["array", "null"],
365
+ items: {
366
+ type: "string",
367
+ format: "uri"
368
+ },
369
+ description: "A list of presets to apply to the project. Each preset will be applied in order."
370
+ },
371
+ assets: {
372
+ type: ["string", "null"],
373
+ description: "The folder which holds the assets to be deployed to the edge. Defaults to none."
374
+ },
375
+ populateAssetCache: {
376
+ type: ["boolean", "null"],
377
+ description: "If true, the assets will be cached at the edge during deployment. This may increase the deployment time, depending on the size of the assets. Defaults to false."
378
+ },
379
+ regions: {
380
+ type: ["array", "null"],
381
+ description: 'The regions to which the project will be deployed. Use "global" to deploy to all regions. More regions will incur higher costs.',
382
+ items: {
383
+ type: "string"
384
+ }
385
+ },
386
+ build_commands: {
387
+ type: ["array", "null"],
388
+ description: "The commands to run to build the project. For example, `bun install` or `npm install`.",
389
+ items: {
390
+ type: "string"
391
+ }
392
+ },
393
+ functions: {
394
+ type: ["object", "null"],
395
+ description: "The serverless functions to deploy.",
396
+ additionalProperties: {
397
+ type: "object",
398
+ properties: {
399
+ memory: {
400
+ type: "number",
401
+ description: "The memory in MB to allocate to the function. Defaults to 128.",
402
+ maximum: 3009,
403
+ minimum: 128
404
+ },
405
+ max_duration: {
406
+ type: "number",
407
+ description: "The max duration in seconds for the function after which it will be terminated. Defaults to 30.",
408
+ maximum: 900,
409
+ minimum: 1
410
+ },
411
+ runtime: {
412
+ $ref: "#/$defs/runtimes",
413
+ description: "The runtime to use for the function."
414
+ },
415
+ schedule: {
416
+ type: "string",
417
+ description: "An expression to schedule the function to run at specific times.",
418
+ pattern: "^(?:rate[(](?:(?:1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/][0-9]+))?)*)))|(?:(?:(?:(?:(?:[1-3]?[0-9])W?)|LW|[L*])(?:(?:[-](?:(?:(?:[1-3]?[0-9])W?)|LW|[L*]))|(?:[/][0-9]+))?(?:[,](?:(?:(?:[1-3]?[0-9])W?)|LW|[L*])(?:(?:[-](?:(?:(?:[1-3]?[0-9])W?)|LW|[L*]))|(?:[/][0-9]+))?)*)[ ]+(?:(?:(?:[1]?[0-9])|(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)|[*])(?:(?:[-](?:(?:[1]?[0-9])|(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)|[*])(?:[/][0-9]+)?)|(?:[/][0-9]+))?(?:[,](?:(?:[1]?[0-9])|(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)|[*])(?:(?:[-](?:(?:[1]?[0-9])|(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)|[*])(?:[/][0-9]+)?)|(?:[/][0-9]+))?)*)[ ]+[?]))[ ]+(?:(?:(?:[12][0-9]{3})|[*])(?:(?:[-](?:(?:[12][0-9]{3})|[*]))|(?:[/][0-9]+))?(?:[,](?:(?:[12][0-9]{3})|[*])(?:(?:[-](?:(?:[12][0-9]{3})|[*]))|(?:[/][0-9]+))?)*)[)])$"
419
+ },
420
+ symlinks: {
421
+ type: "object",
422
+ description: "A list of symbolic links to create in the function's package.",
423
+ maxProperties: 100,
424
+ minProperties: 1,
425
+ patternProperties: {
426
+ "^.{1,256}$": {
427
+ type: "string",
428
+ maxLength: 256
429
+ }
430
+ },
431
+ additionalProperties: false
432
+ },
433
+ excludeFiles: {
434
+ oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }],
435
+ description: "A glob pattern to match files that should be excluded from your Serverless Function. If you're using a Community Runtime, the behavior might vary."
436
+ },
437
+ includeFiles: {
438
+ oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }],
439
+ description: "A glob pattern to match files that should be included in your Serverless Function. If you're using a Community Runtime, the behavior might vary."
440
+ }
441
+ }
442
+ }
443
+ },
444
+ env: {
445
+ type: "object",
446
+ maxProperties: 100,
447
+ minProperties: 0,
448
+ patternProperties: {
449
+ ".+": {
450
+ maxLength: 65536,
451
+ minLength: 0,
452
+ type: "string"
453
+ }
454
+ },
455
+ additionalProperties: false,
456
+ description: "Additional environment variables to set during runtime and build."
457
+ },
458
+ routes: {
459
+ type: ["array", "null"],
460
+ description: "A list of route definitions.",
461
+ maxItems: 1024,
462
+ items: {
463
+ type: "object",
464
+ required: ["source", "destination"],
465
+ properties: {
466
+ source: {
467
+ description: "A pattern that matches each incoming pathname (excluding querystring).",
468
+ type: "string",
469
+ maxLength: 4096
470
+ },
471
+ destination: {
472
+ description: "An absolute pathname to an existing resource or an external URL.",
473
+ type: "string",
474
+ maxLength: 4096
475
+ },
476
+ has: {
477
+ $ref: "#/$defs/matchRequirements"
478
+ },
479
+ missing: {
480
+ $ref: "#/$defs/matchRequirements"
481
+ },
482
+ statusCode: {
483
+ description: "An optional integer to override the status code of the response.",
484
+ type: "integer",
485
+ minimum: 100,
486
+ maximum: 999
487
+ },
488
+ redirect: {
489
+ type: "boolean",
490
+ description: "An optional boolean to force a redirect response."
491
+ },
492
+ methods: {
493
+ type: "array",
494
+ description: "The HTTP methods to match for the route. Defaults to all methods.",
495
+ items: {
496
+ type: "string",
497
+ enum: ["ANY", "GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]
498
+ }
499
+ },
500
+ headers: {
501
+ type: "object",
502
+ description: "Additional headers to add to the response.",
503
+ additionalProperties: {
504
+ type: "string"
505
+ }
506
+ }
507
+ }
508
+ }
509
+ },
510
+ services: {
511
+ type: "object",
512
+ description: "Optionally, specify additional services like databases to deploy.",
513
+ properties: {
514
+ redis: {
515
+ oneOf: [
516
+ {
517
+ type: "null"
518
+ },
519
+ {
520
+ type: "object",
521
+ properties: {
522
+ envBindings: {
523
+ type: "object",
524
+ description: "Optionally, specify what environment variables the credentials will be bound to. For example: `{ url: 'REDIS_URL' }` will bind the `url` environment variable to the Redis URL. If you don't specify any bindings, they will be bound to the REDIS_URL, REDIS_HOST, REDIS_PORT, REDIS_PASSWORD, REDIS_DB, and REDIS_SSL environment variables.",
525
+ additionalProperties: false,
526
+ properties: {
527
+ url: { type: "string" },
528
+ host: { type: "string" },
529
+ port: { type: "string" },
530
+ password: { type: "string" },
531
+ db: { type: "string" },
532
+ ssl: { type: "string" }
533
+ }
534
+ },
535
+ primaryRegion: {
536
+ type: "string",
537
+ description: "The primary region to deploy the Redis instance to.",
538
+ enum: [
539
+ "us-east-1",
540
+ "us-east-2",
541
+ "us-west-1",
542
+ "us-west-2",
543
+ "eu-central-1",
544
+ "eu-west-1",
545
+ "eu-west-2",
546
+ "sa-east-1",
547
+ "ap-south-1",
548
+ "ap-northeast-1",
549
+ "ap-southeast-1",
550
+ "ap-southeast-2",
551
+ "us-central1"
552
+ ]
553
+ },
554
+ readRegions: {
555
+ type: "array",
556
+ description: "Optionally, add additional regions to read from. More regions will incur higher costs.",
557
+ items: {
558
+ type: "string",
559
+ enum: [
560
+ "us-east-1",
561
+ "us-east-2",
562
+ "us-west-1",
563
+ "us-west-2",
564
+ "eu-central-1",
565
+ "eu-west-1",
566
+ "eu-west-2",
567
+ "sa-east-1",
568
+ "ap-south-1",
569
+ "ap-northeast-1",
570
+ "ap-southeast-1",
571
+ "ap-southeast-2"
572
+ ]
573
+ }
574
+ },
575
+ eviction: {
576
+ type: "boolean",
577
+ description: "Optionally, enable Redis eviction. This will evict the least recently used keys in order to make space for new ones."
578
+ }
579
+ }
580
+ }
581
+ ]
582
+ },
583
+ postgres: {
584
+ oneOf: [
585
+ {
586
+ type: "null"
587
+ },
588
+ {
589
+ type: "object",
590
+ properties: {
591
+ envBindings: {
592
+ type: "object",
593
+ description: "Optionally, specify what environment variables the credentials will be bound to. For example: `{ url: 'POSTGRES_URL' }` will bind the `url` environment variable to the Postgres URL. If you don't specify any bindings, they will be bound to the POSTGRES_URL, POSTGRES_HOST, POSTGRES_PORT, POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DATABASE environment variables.",
594
+ additionalProperties: false,
595
+ properties: {
596
+ url: { type: "string" },
597
+ host: { type: "string" },
598
+ port: { type: "string" },
599
+ user: { type: "string" },
600
+ password: { type: "string" },
601
+ database: { type: "string" }
602
+ }
603
+ },
604
+ postgresVersion: {
605
+ type: "string",
606
+ description: "The version of Postgres to deploy.",
607
+ enum: ["17", "16", "15", "14"]
608
+ },
609
+ region: {
610
+ type: "string",
611
+ description: "The region to deploy the Postgres instance to.",
612
+ enum: [
613
+ "us-east-1",
614
+ "us-east-2",
615
+ "us-west-2",
616
+ "ap-southeast-1",
617
+ "ap-southeast-2",
618
+ "eu-central-1",
619
+ "eu-west-2",
620
+ "sa-east-1"
621
+ ]
622
+ }
623
+ }
624
+ }
625
+ ]
626
+ }
627
+ }
628
+ }
629
+ },
630
+ $defs: {
631
+ runtimes: {
632
+ type: "string",
633
+ enum: ["php-83", "php-82", "php-81", "php-80", "node-20", "node-18", "node-16", "bun-1"]
634
+ },
635
+ matchRequirements: {
636
+ description: "An array of requirements that are needed to match",
637
+ type: "array",
638
+ maxItems: 16,
639
+ items: {
640
+ anyOf: [
641
+ {
642
+ type: "object",
643
+ additionalProperties: false,
644
+ required: ["type", "value"],
645
+ properties: {
646
+ type: {
647
+ description: "The type of request element to check",
648
+ type: "string",
649
+ enum: ["host"]
650
+ },
651
+ value: {
652
+ description: "A regular expression used to match the value. Named groups can be used in the destination",
653
+ type: "string",
654
+ maxLength: 4096
655
+ }
656
+ }
657
+ },
658
+ {
659
+ type: "object",
660
+ additionalProperties: false,
661
+ required: ["type", "key"],
662
+ properties: {
663
+ type: {
664
+ description: "The type of request element to check",
665
+ type: "string",
666
+ enum: ["header", "cookie", "query"]
667
+ },
668
+ key: {
669
+ description: "The name of the element contained in the particular type",
670
+ type: "string",
671
+ maxLength: 4096
672
+ },
673
+ value: {
674
+ description: "A regular expression used to match the value. Named groups can be used in the destination",
675
+ type: "string",
676
+ maxLength: 4096
677
+ }
678
+ }
679
+ }
680
+ ]
681
+ }
346
682
  }
347
683
  }
348
- return null;
349
684
  };
685
+
686
+ // src/parse-config.ts
350
687
  var parseConfig = async (filePath, projectFolder) => {
351
688
  const parsed = await parseRawConfig(filePath);
352
689
  const version = parsed.version;
@@ -354,7 +691,7 @@ var parseConfig = async (filePath, projectFolder) => {
354
691
  /*1: schemaV1,
355
692
  2: schemaV2,
356
693
  3: schemaV3,*/
357
- 4: schemaV4
694
+ 4: schema_default
358
695
  };
359
696
  const relativePath = filePath.replace("/tmp/unzipped/", "");
360
697
  const schema = schemaMap[version];
@@ -385,9 +722,25 @@ var parseConfig = async (filePath, projectFolder) => {
385
722
  }
386
723
  return parseResult;
387
724
  };
725
+
726
+ // src/runtime.ts
727
+ var RUNTIME_DEFINITIONS = [
728
+ "php-84",
729
+ "php-83",
730
+ "php-81",
731
+ "node-22",
732
+ "node-20",
733
+ "node-18",
734
+ "node-16",
735
+ "bun-1"
736
+ ];
737
+ var AVAILABLE_RUNTIMES = [...RUNTIME_DEFINITIONS];
388
738
  export {
389
739
  ALLOWED_CONFIG_NAMES,
740
+ AVAILABLE_REGIONS,
741
+ AVAILABLE_RUNTIMES,
390
742
  findConfig,
391
- parseConfig
743
+ parseConfig,
744
+ parseRawConfig
392
745
  };
393
746
  //# sourceMappingURL=index.mjs.map