@fulmenhq/tsfulmen 0.3.0 → 0.3.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/CHANGELOG.md +22 -0
- package/dist/appidentity/index.js +156 -4150
- package/dist/appidentity/index.js.map +1 -1
- package/dist/bin/prometheus-cli.d.ts +1 -0
- package/dist/bin/prometheus-cli.js +9331 -0
- package/dist/bin/prometheus-cli.js.map +1 -0
- package/dist/bin/schema-cli.d.ts +1 -0
- package/dist/bin/schema-cli.js +6104 -0
- package/dist/bin/schema-cli.js.map +1 -0
- package/dist/bin/signals-cli.d.ts +1 -0
- package/dist/bin/signals-cli.js +2104 -0
- package/dist/bin/signals-cli.js.map +1 -0
- package/dist/config/index.js +29 -4915
- package/dist/config/index.js.map +1 -1
- package/dist/crucible/index.js +120 -5336
- package/dist/crucible/index.js.map +1 -1
- package/dist/errors/index.js +52 -4434
- package/dist/errors/index.js.map +1 -1
- package/dist/foundry/index.js +197 -1874
- package/dist/foundry/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +161 -4154
- package/dist/index.js.map +1 -1
- package/dist/pathfinder/index.js +47 -4378
- package/dist/pathfinder/index.js.map +1 -1
- package/dist/reports/license-inventory.csv +2 -2
- package/dist/schema/index.js +0 -4
- package/dist/schema/index.js.map +1 -1
- package/dist/signals/index.js +231 -3570
- package/dist/signals/index.js.map +1 -1
- package/dist/telemetry/http/index.js +94 -5280
- package/dist/telemetry/http/index.js.map +1 -1
- package/dist/telemetry/index.js +70 -4786
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/prometheus/index.js +461 -4450
- package/dist/telemetry/prometheus/index.js.map +1 -1
- package/package.json +8 -2
package/dist/pathfinder/index.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { crc32, xxhash128, createXXHash128, createCRC32 } from 'hash-wasm';
|
|
2
2
|
import { createHash, randomUUID } from 'crypto';
|
|
3
3
|
import addFormats from 'ajv-formats';
|
|
4
|
-
import
|
|
5
|
-
import fs2, { readFile,
|
|
6
|
-
import { parse
|
|
7
|
-
import path3, {
|
|
4
|
+
import 'child_process';
|
|
5
|
+
import fs2, { readFile, access, lstat, realpath } from 'fs/promises';
|
|
6
|
+
import { parse } from 'yaml';
|
|
7
|
+
import path3, { join, resolve, dirname, relative, extname } from 'path';
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
9
|
import glob from 'fast-glob';
|
|
10
10
|
import Ajv from 'ajv';
|
|
11
11
|
import Ajv2019 from 'ajv/dist/2019.js';
|
|
12
12
|
import Ajv2020 from 'ajv/dist/2020.js';
|
|
13
13
|
import AjvDraft04 from 'ajv-draft-04';
|
|
14
|
-
import
|
|
15
|
-
import picomatch from 'picomatch';
|
|
16
|
-
import { suggest as suggest$1, substringSimilarity, score as score$1, normalize as normalize$1, jaro_winkler, damerau_levenshtein, osa_distance, levenshtein } from '@3leaps/string-metrics-wasm';
|
|
17
|
-
import { Command } from 'commander';
|
|
14
|
+
import 'commander';
|
|
18
15
|
import { createReadStream, promises } from 'fs';
|
|
16
|
+
import picomatch from 'picomatch';
|
|
19
17
|
import { homedir } from 'os';
|
|
20
18
|
|
|
21
19
|
var __defProp = Object.defineProperty;
|
|
@@ -432,23 +430,9 @@ var init_ajv_formats = __esm({
|
|
|
432
430
|
});
|
|
433
431
|
|
|
434
432
|
// src/schema/errors.ts
|
|
435
|
-
var
|
|
436
|
-
__export(errors_exports, {
|
|
437
|
-
ExportErrorReason: () => ExportErrorReason,
|
|
438
|
-
SchemaExportError: () => SchemaExportError,
|
|
439
|
-
SchemaValidationError: () => SchemaValidationError
|
|
440
|
-
});
|
|
441
|
-
var ExportErrorReason, SchemaValidationError, SchemaExportError;
|
|
433
|
+
var SchemaValidationError;
|
|
442
434
|
var init_errors2 = __esm({
|
|
443
435
|
"src/schema/errors.ts"() {
|
|
444
|
-
ExportErrorReason = /* @__PURE__ */ ((ExportErrorReason2) => {
|
|
445
|
-
ExportErrorReason2["FILE_EXISTS"] = "FILE_EXISTS";
|
|
446
|
-
ExportErrorReason2["WRITE_FAILED"] = "WRITE_FAILED";
|
|
447
|
-
ExportErrorReason2["INVALID_FORMAT"] = "INVALID_FORMAT";
|
|
448
|
-
ExportErrorReason2["PROVENANCE_FAILED"] = "PROVENANCE_FAILED";
|
|
449
|
-
ExportErrorReason2["UNKNOWN"] = "UNKNOWN";
|
|
450
|
-
return ExportErrorReason2;
|
|
451
|
-
})(ExportErrorReason || {});
|
|
452
436
|
SchemaValidationError = class _SchemaValidationError extends Error {
|
|
453
437
|
constructor(message, schemaId, diagnostics = [], source, cause) {
|
|
454
438
|
super(message);
|
|
@@ -588,100 +572,10 @@ Source: ${this.source.type}`;
|
|
|
588
572
|
};
|
|
589
573
|
}
|
|
590
574
|
};
|
|
591
|
-
SchemaExportError = class _SchemaExportError extends SchemaValidationError {
|
|
592
|
-
constructor(message, reason, schemaId, outPath, cause) {
|
|
593
|
-
super(message, schemaId, [], void 0, cause);
|
|
594
|
-
this.reason = reason;
|
|
595
|
-
this.schemaId = schemaId;
|
|
596
|
-
this.outPath = outPath;
|
|
597
|
-
this.cause = cause;
|
|
598
|
-
this.name = "SchemaExportError";
|
|
599
|
-
if (Error.captureStackTrace) {
|
|
600
|
-
Error.captureStackTrace(this, _SchemaExportError);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
/**
|
|
604
|
-
* Create error for file already exists
|
|
605
|
-
*/
|
|
606
|
-
static fileExists(outPath) {
|
|
607
|
-
return new _SchemaExportError(
|
|
608
|
-
`Output file already exists: ${outPath}. Use overwrite option to replace.`,
|
|
609
|
-
"FILE_EXISTS" /* FILE_EXISTS */,
|
|
610
|
-
void 0,
|
|
611
|
-
outPath
|
|
612
|
-
);
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* Create error for invalid export format
|
|
616
|
-
*/
|
|
617
|
-
static invalidFormat(format, outPath) {
|
|
618
|
-
return new _SchemaExportError(
|
|
619
|
-
`Invalid export format: ${format}. Must be 'json' or 'yaml'.`,
|
|
620
|
-
"INVALID_FORMAT" /* INVALID_FORMAT */,
|
|
621
|
-
void 0,
|
|
622
|
-
outPath
|
|
623
|
-
);
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Create error for write failure
|
|
627
|
-
*/
|
|
628
|
-
static writeFailed(outPath, error) {
|
|
629
|
-
return new _SchemaExportError(
|
|
630
|
-
`Failed to write schema to ${outPath}: ${error.message}`,
|
|
631
|
-
"WRITE_FAILED" /* WRITE_FAILED */,
|
|
632
|
-
void 0,
|
|
633
|
-
outPath,
|
|
634
|
-
error
|
|
635
|
-
);
|
|
636
|
-
}
|
|
637
|
-
/**
|
|
638
|
-
* Create error for provenance extraction failure
|
|
639
|
-
*/
|
|
640
|
-
static provenanceFailed(details, error) {
|
|
641
|
-
return new _SchemaExportError(
|
|
642
|
-
`Failed to extract provenance metadata: ${details}`,
|
|
643
|
-
"PROVENANCE_FAILED" /* PROVENANCE_FAILED */,
|
|
644
|
-
void 0,
|
|
645
|
-
void 0,
|
|
646
|
-
error
|
|
647
|
-
);
|
|
648
|
-
}
|
|
649
|
-
};
|
|
650
575
|
}
|
|
651
576
|
});
|
|
652
577
|
|
|
653
578
|
// src/schema/utils.ts
|
|
654
|
-
function formatDiagnostics(diagnostics) {
|
|
655
|
-
if (diagnostics.length === 0) {
|
|
656
|
-
return "No validation issues found.";
|
|
657
|
-
}
|
|
658
|
-
const lines = [];
|
|
659
|
-
const errors = diagnostics.filter((d) => d.severity === "ERROR");
|
|
660
|
-
const warnings = diagnostics.filter((d) => d.severity === "WARN");
|
|
661
|
-
if (errors.length > 0) {
|
|
662
|
-
lines.push(`\u274C ${errors.length} error(s) found:`);
|
|
663
|
-
errors.forEach((diag, index) => {
|
|
664
|
-
lines.push(` ${index + 1}. ${diag.message}`);
|
|
665
|
-
if (diag.pointer) {
|
|
666
|
-
lines.push(` at ${diag.pointer}`);
|
|
667
|
-
}
|
|
668
|
-
if (diag.keyword) {
|
|
669
|
-
lines.push(` keyword: ${diag.keyword}`);
|
|
670
|
-
}
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
|
-
if (warnings.length > 0) {
|
|
674
|
-
lines.push("");
|
|
675
|
-
lines.push(`\u26A0\uFE0F ${warnings.length} warning(s) found:`);
|
|
676
|
-
warnings.forEach((diag, index) => {
|
|
677
|
-
lines.push(` ${index + 1}. ${diag.message}`);
|
|
678
|
-
if (diag.pointer) {
|
|
679
|
-
lines.push(` at ${diag.pointer}`);
|
|
680
|
-
}
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
return lines.join("\n");
|
|
684
|
-
}
|
|
685
579
|
function createDiagnostic(pointer, message, keyword, severity = "ERROR", source = "ajv", data) {
|
|
686
580
|
return {
|
|
687
581
|
pointer,
|
|
@@ -697,261 +591,27 @@ var init_utils = __esm({
|
|
|
697
591
|
init_errors2();
|
|
698
592
|
}
|
|
699
593
|
});
|
|
700
|
-
async function detectGoneat(customPath) {
|
|
701
|
-
if (customPath) {
|
|
702
|
-
try {
|
|
703
|
-
await access(customPath);
|
|
704
|
-
return customPath;
|
|
705
|
-
} catch {
|
|
706
|
-
return null;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
if (process.env.GONEAT_PATH) {
|
|
710
|
-
try {
|
|
711
|
-
await access(process.env.GONEAT_PATH);
|
|
712
|
-
return process.env.GONEAT_PATH;
|
|
713
|
-
} catch {
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
try {
|
|
717
|
-
await access("./bin/goneat");
|
|
718
|
-
return "./bin/goneat";
|
|
719
|
-
} catch {
|
|
720
|
-
}
|
|
721
|
-
return "goneat";
|
|
722
|
-
}
|
|
723
|
-
async function isGoneatAvailable(goneatPath) {
|
|
724
|
-
let pathToTest;
|
|
725
|
-
if (goneatPath) {
|
|
726
|
-
pathToTest = goneatPath;
|
|
727
|
-
} else {
|
|
728
|
-
pathToTest = await detectGoneat();
|
|
729
|
-
if (!pathToTest) return false;
|
|
730
|
-
}
|
|
731
|
-
return new Promise((resolve2) => {
|
|
732
|
-
const proc = spawn(pathToTest, ["version"], { stdio: "ignore" });
|
|
733
|
-
const timeout = setTimeout(() => {
|
|
734
|
-
proc.kill();
|
|
735
|
-
resolve2(false);
|
|
736
|
-
}, 5e3);
|
|
737
|
-
proc.on("close", (code) => {
|
|
738
|
-
clearTimeout(timeout);
|
|
739
|
-
resolve2(code === 0);
|
|
740
|
-
});
|
|
741
|
-
proc.on("error", () => {
|
|
742
|
-
clearTimeout(timeout);
|
|
743
|
-
resolve2(false);
|
|
744
|
-
});
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
async function runGoneatValidation(schemaPath, dataPath, goneatPath) {
|
|
748
|
-
const detected = await detectGoneat(goneatPath);
|
|
749
|
-
if (!detected) {
|
|
750
|
-
return {
|
|
751
|
-
valid: false,
|
|
752
|
-
diagnostics: [
|
|
753
|
-
createDiagnostic(
|
|
754
|
-
"",
|
|
755
|
-
"goneat binary not found. Install goneat or specify path with --goneat-path",
|
|
756
|
-
"goneat-unavailable",
|
|
757
|
-
"ERROR",
|
|
758
|
-
"goneat"
|
|
759
|
-
)
|
|
760
|
-
],
|
|
761
|
-
source: "goneat"
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
if (!await isGoneatAvailable(detected)) {
|
|
765
|
-
return {
|
|
766
|
-
valid: false,
|
|
767
|
-
diagnostics: [
|
|
768
|
-
createDiagnostic(
|
|
769
|
-
"",
|
|
770
|
-
`goneat binary found at '${detected}' but not executable or version check failed`,
|
|
771
|
-
"goneat-not-executable",
|
|
772
|
-
"ERROR",
|
|
773
|
-
"goneat"
|
|
774
|
-
)
|
|
775
|
-
],
|
|
776
|
-
source: "goneat"
|
|
777
|
-
};
|
|
778
|
-
}
|
|
779
|
-
return new Promise((resolve2) => {
|
|
780
|
-
const args = [
|
|
781
|
-
"schema",
|
|
782
|
-
"validate",
|
|
783
|
-
"--schema",
|
|
784
|
-
schemaPath,
|
|
785
|
-
"--data",
|
|
786
|
-
dataPath,
|
|
787
|
-
"--format",
|
|
788
|
-
"json"
|
|
789
|
-
];
|
|
790
|
-
const proc = spawn(detected, args);
|
|
791
|
-
let stdout = "";
|
|
792
|
-
let stderr = "";
|
|
793
|
-
proc.stdout.on("data", (data) => {
|
|
794
|
-
stdout += data.toString();
|
|
795
|
-
});
|
|
796
|
-
proc.stderr.on("data", (data) => {
|
|
797
|
-
stderr += data.toString();
|
|
798
|
-
});
|
|
799
|
-
proc.on("close", (code) => {
|
|
800
|
-
let output;
|
|
801
|
-
try {
|
|
802
|
-
output = JSON.parse(stdout);
|
|
803
|
-
} catch {
|
|
804
|
-
resolve2({
|
|
805
|
-
valid: false,
|
|
806
|
-
diagnostics: [
|
|
807
|
-
createDiagnostic(
|
|
808
|
-
"",
|
|
809
|
-
`goneat validation failed: ${stderr || "unknown error"}`,
|
|
810
|
-
"goneat-error",
|
|
811
|
-
"ERROR",
|
|
812
|
-
"goneat"
|
|
813
|
-
)
|
|
814
|
-
],
|
|
815
|
-
source: "goneat"
|
|
816
|
-
});
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
const diagnostics = output.errors?.map(
|
|
820
|
-
(error) => createDiagnostic(
|
|
821
|
-
error.path || "",
|
|
822
|
-
error.message,
|
|
823
|
-
error.keyword || "validation",
|
|
824
|
-
"ERROR",
|
|
825
|
-
"goneat"
|
|
826
|
-
)
|
|
827
|
-
) || [];
|
|
828
|
-
resolve2({
|
|
829
|
-
valid: code === 0 && output.valid,
|
|
830
|
-
diagnostics,
|
|
831
|
-
source: "goneat"
|
|
832
|
-
});
|
|
833
|
-
});
|
|
834
|
-
proc.on("error", (error) => {
|
|
835
|
-
resolve2({
|
|
836
|
-
valid: false,
|
|
837
|
-
diagnostics: [
|
|
838
|
-
createDiagnostic(
|
|
839
|
-
"",
|
|
840
|
-
`Failed to execute goneat: ${error.message}`,
|
|
841
|
-
"goneat-spawn-error",
|
|
842
|
-
"ERROR",
|
|
843
|
-
"goneat"
|
|
844
|
-
)
|
|
845
|
-
],
|
|
846
|
-
source: "goneat"
|
|
847
|
-
});
|
|
848
|
-
});
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
594
|
var init_goneat_bridge = __esm({
|
|
852
595
|
"src/schema/goneat-bridge.ts"() {
|
|
853
596
|
init_utils();
|
|
854
597
|
}
|
|
855
598
|
});
|
|
856
|
-
function parseSchemaInput(input) {
|
|
857
|
-
if (!input) {
|
|
858
|
-
throw SchemaValidationError.parseFailed(
|
|
859
|
-
{ type: "string", content: "" },
|
|
860
|
-
new Error("schema content is empty")
|
|
861
|
-
);
|
|
862
|
-
}
|
|
863
|
-
try {
|
|
864
|
-
if (typeof input === "string") {
|
|
865
|
-
try {
|
|
866
|
-
return JSON.parse(input);
|
|
867
|
-
} catch {
|
|
868
|
-
return parse(input);
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
if (Buffer.isBuffer(input)) {
|
|
872
|
-
const content = input.toString("utf-8");
|
|
873
|
-
try {
|
|
874
|
-
return JSON.parse(content);
|
|
875
|
-
} catch {
|
|
876
|
-
return parse(content);
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
return input;
|
|
880
|
-
} catch (error) {
|
|
881
|
-
throw SchemaValidationError.parseFailed(
|
|
882
|
-
{
|
|
883
|
-
type: typeof input === "string" ? "string" : "object",
|
|
884
|
-
content: typeof input === "string" ? input : JSON.stringify(input)
|
|
885
|
-
},
|
|
886
|
-
error
|
|
887
|
-
);
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
function sortObjectKeys(obj) {
|
|
891
|
-
if (obj === null || typeof obj !== "object") {
|
|
892
|
-
return obj;
|
|
893
|
-
}
|
|
894
|
-
if (Array.isArray(obj)) {
|
|
895
|
-
return obj.map(sortObjectKeys);
|
|
896
|
-
}
|
|
897
|
-
const sorted = {};
|
|
898
|
-
const keys = Object.keys(obj).sort();
|
|
899
|
-
for (const key of keys) {
|
|
900
|
-
sorted[key] = sortObjectKeys(obj[key]);
|
|
901
|
-
}
|
|
902
|
-
return sorted;
|
|
903
|
-
}
|
|
904
|
-
function normalizeSchema(input, options = {}) {
|
|
905
|
-
try {
|
|
906
|
-
const parsed = parseSchemaInput(input);
|
|
907
|
-
const sorted = sortObjectKeys(parsed);
|
|
908
|
-
if (options.compact) {
|
|
909
|
-
return JSON.stringify(sorted);
|
|
910
|
-
}
|
|
911
|
-
return JSON.stringify(sorted, null, 2);
|
|
912
|
-
} catch (error) {
|
|
913
|
-
if (error instanceof SchemaValidationError) {
|
|
914
|
-
throw error;
|
|
915
|
-
}
|
|
916
|
-
throw SchemaValidationError.parseFailed(
|
|
917
|
-
{
|
|
918
|
-
type: typeof input === "string" ? "string" : "object",
|
|
919
|
-
content: typeof input === "string" ? input : JSON.stringify(input)
|
|
920
|
-
},
|
|
921
|
-
error
|
|
922
|
-
);
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
function compareSchemas(schemaA, schemaB, options = {}) {
|
|
926
|
-
const normalizedA = normalizeSchema(schemaA, options);
|
|
927
|
-
const normalizedB = normalizeSchema(schemaB, options);
|
|
928
|
-
return {
|
|
929
|
-
equal: normalizedA === normalizedB,
|
|
930
|
-
normalizedA,
|
|
931
|
-
normalizedB
|
|
932
|
-
};
|
|
933
|
-
}
|
|
934
599
|
var init_normalizer = __esm({
|
|
935
600
|
"src/schema/normalizer.ts"() {
|
|
936
601
|
init_errors2();
|
|
937
602
|
}
|
|
938
603
|
});
|
|
939
604
|
function optionsChanged(newOptions) {
|
|
940
|
-
if (!
|
|
941
|
-
|
|
942
|
-
return newOptions.baseDir !== globalRegistryOptions.baseDir || JSON.stringify(newOptions.patterns) !== JSON.stringify(globalRegistryOptions.patterns) || newOptions.followSymlinks !== globalRegistryOptions.followSymlinks || newOptions.maxDepth !== globalRegistryOptions.maxDepth;
|
|
605
|
+
if (!globalRegistryOptions) return false;
|
|
606
|
+
return true;
|
|
943
607
|
}
|
|
944
608
|
function getSchemaRegistry(options) {
|
|
945
|
-
if (!globalRegistry || optionsChanged(
|
|
609
|
+
if (!globalRegistry || optionsChanged()) {
|
|
946
610
|
globalRegistry = new SchemaRegistry(options);
|
|
947
611
|
globalRegistryOptions = options;
|
|
948
612
|
}
|
|
949
613
|
return globalRegistry;
|
|
950
614
|
}
|
|
951
|
-
async function listSchemas(prefix, options) {
|
|
952
|
-
const registry = getSchemaRegistry(options);
|
|
953
|
-
return registry.listSchemas(prefix);
|
|
954
|
-
}
|
|
955
615
|
var DEFAULT_PATTERNS, SchemaRegistry, globalRegistry, globalRegistryOptions;
|
|
956
616
|
var init_registry = __esm({
|
|
957
617
|
"src/schema/registry.ts"() {
|
|
@@ -972,9 +632,9 @@ var init_registry = __esm({
|
|
|
972
632
|
* Get default schema directory using import.meta.url
|
|
973
633
|
*/
|
|
974
634
|
getDefaultSchemaDir() {
|
|
975
|
-
const
|
|
976
|
-
const
|
|
977
|
-
return join(
|
|
635
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
636
|
+
const __dirname2 = dirname(__filename);
|
|
637
|
+
return join(__dirname2, "..", "..", "schemas", "crucible-ts");
|
|
978
638
|
}
|
|
979
639
|
/**
|
|
980
640
|
* Build logical schema ID from file path
|
|
@@ -1862,25 +1522,11 @@ var init_telemetry = __esm({
|
|
|
1862
1522
|
metrics = new MetricsRegistry();
|
|
1863
1523
|
}
|
|
1864
1524
|
});
|
|
1865
|
-
|
|
1866
|
-
// src/schema/validator.ts
|
|
1867
|
-
var validator_exports = {};
|
|
1868
|
-
__export(validator_exports, {
|
|
1869
|
-
clearCache: () => clearCache,
|
|
1870
|
-
compileSchema: () => compileSchema,
|
|
1871
|
-
compileSchemaById: () => compileSchemaById,
|
|
1872
|
-
getCacheSize: () => getCacheSize,
|
|
1873
|
-
validateData: () => validateData,
|
|
1874
|
-
validateDataBySchemaId: () => validateDataBySchemaId,
|
|
1875
|
-
validateFile: () => validateFile,
|
|
1876
|
-
validateFileBySchemaId: () => validateFileBySchemaId,
|
|
1877
|
-
validateSchema: () => validateSchema
|
|
1878
|
-
});
|
|
1879
1525
|
async function loadMetaSchema(draft) {
|
|
1880
|
-
const
|
|
1881
|
-
const
|
|
1526
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
1527
|
+
const __dirname2 = dirname(__filename);
|
|
1882
1528
|
const metaSchemaPath = join(
|
|
1883
|
-
|
|
1529
|
+
__dirname2,
|
|
1884
1530
|
"..",
|
|
1885
1531
|
"..",
|
|
1886
1532
|
"schemas",
|
|
@@ -1896,9 +1542,9 @@ async function loadVocabularySchemas(draft) {
|
|
|
1896
1542
|
if (draft !== "draft-2019-09" && draft !== "draft-2020-12") {
|
|
1897
1543
|
return [];
|
|
1898
1544
|
}
|
|
1899
|
-
const
|
|
1900
|
-
const
|
|
1901
|
-
const vocabDir = join(
|
|
1545
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
1546
|
+
const __dirname2 = dirname(__filename);
|
|
1547
|
+
const vocabDir = join(__dirname2, "..", "..", "schemas", "crucible-ts", "meta", draft, "meta");
|
|
1902
1548
|
const vocabFiles = draft === "draft-2020-12" ? [
|
|
1903
1549
|
"core.json",
|
|
1904
1550
|
"applicator.json",
|
|
@@ -1926,9 +1572,9 @@ async function loadVocabularySchemas(draft) {
|
|
|
1926
1572
|
return schemas;
|
|
1927
1573
|
}
|
|
1928
1574
|
async function loadReferencedSchema(uri) {
|
|
1929
|
-
const
|
|
1930
|
-
const
|
|
1931
|
-
const repoRoot = join(
|
|
1575
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
1576
|
+
const __dirname2 = dirname(__filename);
|
|
1577
|
+
const repoRoot = join(__dirname2, "..", "..");
|
|
1932
1578
|
let resolvedPath;
|
|
1933
1579
|
if (uri.startsWith("https://schemas.fulmenhq.dev/")) {
|
|
1934
1580
|
let relativePath = uri.replace("https://schemas.fulmenhq.dev/", "");
|
|
@@ -2103,104 +1749,6 @@ function validateData(data, validator) {
|
|
|
2103
1749
|
}
|
|
2104
1750
|
return result;
|
|
2105
1751
|
}
|
|
2106
|
-
async function validateFile(filePath, validator) {
|
|
2107
|
-
try {
|
|
2108
|
-
const content = await readFile(filePath, "utf-8");
|
|
2109
|
-
let data;
|
|
2110
|
-
try {
|
|
2111
|
-
data = JSON.parse(content);
|
|
2112
|
-
} catch {
|
|
2113
|
-
data = parse(content);
|
|
2114
|
-
}
|
|
2115
|
-
return validateData(data, validator);
|
|
2116
|
-
} catch (error) {
|
|
2117
|
-
if (error instanceof SchemaValidationError) {
|
|
2118
|
-
throw error;
|
|
2119
|
-
}
|
|
2120
|
-
throw SchemaValidationError.validationFailed(
|
|
2121
|
-
filePath,
|
|
2122
|
-
[
|
|
2123
|
-
createDiagnostic(
|
|
2124
|
-
"",
|
|
2125
|
-
`Failed to read or parse file: ${error.message}`,
|
|
2126
|
-
"file-read",
|
|
2127
|
-
"ERROR",
|
|
2128
|
-
"ajv"
|
|
2129
|
-
)
|
|
2130
|
-
],
|
|
2131
|
-
{ type: "file", id: filePath }
|
|
2132
|
-
);
|
|
2133
|
-
}
|
|
2134
|
-
}
|
|
2135
|
-
async function validateSchema(schema) {
|
|
2136
|
-
try {
|
|
2137
|
-
let parsedSchema;
|
|
2138
|
-
if (typeof schema === "string") {
|
|
2139
|
-
try {
|
|
2140
|
-
parsedSchema = JSON.parse(schema);
|
|
2141
|
-
} catch {
|
|
2142
|
-
parsedSchema = parse(schema);
|
|
2143
|
-
}
|
|
2144
|
-
} else if (Buffer.isBuffer(schema)) {
|
|
2145
|
-
const content = schema.toString("utf-8");
|
|
2146
|
-
try {
|
|
2147
|
-
parsedSchema = JSON.parse(content);
|
|
2148
|
-
} catch {
|
|
2149
|
-
parsedSchema = parse(content);
|
|
2150
|
-
}
|
|
2151
|
-
} else {
|
|
2152
|
-
parsedSchema = schema;
|
|
2153
|
-
}
|
|
2154
|
-
const dialect = detectDialect(parsedSchema);
|
|
2155
|
-
const ajv = await getAjv(dialect);
|
|
2156
|
-
const metaValid = ajv.validateSchema(parsedSchema);
|
|
2157
|
-
if (!metaValid && ajv.errors) {
|
|
2158
|
-
const diagnostics = ajv.errors.map(
|
|
2159
|
-
(error) => createDiagnostic(
|
|
2160
|
-
error.instancePath || "",
|
|
2161
|
-
error.message || "Schema meta-validation failed",
|
|
2162
|
-
error.keyword || "unknown",
|
|
2163
|
-
"ERROR",
|
|
2164
|
-
"ajv"
|
|
2165
|
-
)
|
|
2166
|
-
);
|
|
2167
|
-
return { valid: false, diagnostics, source: "ajv" };
|
|
2168
|
-
}
|
|
2169
|
-
await compileSchema(parsedSchema);
|
|
2170
|
-
return {
|
|
2171
|
-
valid: true,
|
|
2172
|
-
diagnostics: [],
|
|
2173
|
-
source: "ajv"
|
|
2174
|
-
};
|
|
2175
|
-
} catch (error) {
|
|
2176
|
-
if (error instanceof SchemaValidationError) {
|
|
2177
|
-
return {
|
|
2178
|
-
valid: false,
|
|
2179
|
-
diagnostics: error.diagnostics,
|
|
2180
|
-
source: "ajv"
|
|
2181
|
-
};
|
|
2182
|
-
}
|
|
2183
|
-
return {
|
|
2184
|
-
valid: false,
|
|
2185
|
-
diagnostics: [
|
|
2186
|
-
createDiagnostic(
|
|
2187
|
-
"",
|
|
2188
|
-
`Schema validation failed: ${error.message}`,
|
|
2189
|
-
"schema-validation",
|
|
2190
|
-
"ERROR",
|
|
2191
|
-
"ajv"
|
|
2192
|
-
)
|
|
2193
|
-
],
|
|
2194
|
-
source: "ajv"
|
|
2195
|
-
};
|
|
2196
|
-
}
|
|
2197
|
-
}
|
|
2198
|
-
function clearCache() {
|
|
2199
|
-
schemaCache.clear();
|
|
2200
|
-
}
|
|
2201
|
-
function getCacheSize() {
|
|
2202
|
-
return schemaCache.size;
|
|
2203
|
-
}
|
|
2204
1752
|
async function compileSchemaById(schemaId, registryOptions) {
|
|
2205
1753
|
try {
|
|
2206
1754
|
const registry = getSchemaRegistry(registryOptions);
|
|
@@ -2228,15 +1776,6 @@ async function validateDataBySchemaId(data, schemaId, registryOptions) {
|
|
|
2228
1776
|
throw error;
|
|
2229
1777
|
}
|
|
2230
1778
|
}
|
|
2231
|
-
async function validateFileBySchemaId(filePath, schemaId, registryOptions) {
|
|
2232
|
-
try {
|
|
2233
|
-
const validator = await compileSchemaById(schemaId, registryOptions);
|
|
2234
|
-
return validateFile(filePath, validator);
|
|
2235
|
-
} catch (error) {
|
|
2236
|
-
metrics.counter("schema_validation_errors").inc();
|
|
2237
|
-
throw error;
|
|
2238
|
-
}
|
|
2239
|
-
}
|
|
2240
1779
|
var ajvInstances, metaschemaReady, schemaCache;
|
|
2241
1780
|
var init_validator = __esm({
|
|
2242
1781
|
"src/schema/validator.ts"() {
|
|
@@ -2250,174 +1789,15 @@ var init_validator = __esm({
|
|
|
2250
1789
|
schemaCache = /* @__PURE__ */ new Map();
|
|
2251
1790
|
}
|
|
2252
1791
|
});
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
async function extractProvenanceMetadata(schemaId) {
|
|
2261
|
-
try {
|
|
2262
|
-
const __filename3 = fileURLToPath(import.meta.url);
|
|
2263
|
-
const __dirname4 = dirname(__filename3);
|
|
2264
|
-
const metadataPath = join(__dirname4, "..", "..", ".crucible", "metadata", "metadata.yaml");
|
|
2265
|
-
const metadataContent = await readFile(metadataPath, "utf-8");
|
|
2266
|
-
const metadata = parse(metadataContent);
|
|
2267
|
-
const crucibleSource = metadata.sources?.[0];
|
|
2268
|
-
const crucibleVersion = crucibleSource?.version || "unknown";
|
|
2269
|
-
const revision = crucibleSource?.commit;
|
|
2270
|
-
const pkgPath = join(__dirname4, "..", "..", "package.json");
|
|
2271
|
-
const pkgContent = await readFile(pkgPath, "utf-8");
|
|
2272
|
-
const pkg = JSON.parse(pkgContent);
|
|
2273
|
-
return {
|
|
2274
|
-
schema_id: schemaId,
|
|
2275
|
-
crucible_version: crucibleVersion,
|
|
2276
|
-
library_version: pkg.version,
|
|
2277
|
-
revision,
|
|
2278
|
-
exported_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2279
|
-
export_source: "tsfulmen"
|
|
2280
|
-
};
|
|
2281
|
-
} catch (error) {
|
|
2282
|
-
throw SchemaExportError.provenanceFailed(error.message, error);
|
|
2283
|
-
}
|
|
2284
|
-
}
|
|
2285
|
-
function embedProvenance(schemaContent, provenance, format) {
|
|
2286
|
-
if (format === "json") {
|
|
2287
|
-
const withProvenance = {
|
|
2288
|
-
...schemaContent,
|
|
2289
|
-
$comment: {
|
|
2290
|
-
...typeof schemaContent.$comment === "object" ? schemaContent.$comment : {},
|
|
2291
|
-
"x-crucible-source": provenance
|
|
2292
|
-
}
|
|
2293
|
-
};
|
|
2294
|
-
return JSON.stringify(withProvenance, null, 2);
|
|
2295
|
-
}
|
|
2296
|
-
const yamlContent = stringify(schemaContent, {
|
|
2297
|
-
indent: 2,
|
|
2298
|
-
lineWidth: 0
|
|
2299
|
-
});
|
|
2300
|
-
const provenanceComment = [
|
|
2301
|
-
"# x-crucible-source:",
|
|
2302
|
-
`# schema_id: ${provenance.schema_id}`,
|
|
2303
|
-
`# crucible_version: ${provenance.crucible_version}`,
|
|
2304
|
-
`# library_version: ${provenance.library_version}`,
|
|
2305
|
-
...provenance.revision ? [`# revision: ${provenance.revision}`] : [],
|
|
2306
|
-
`# exported_at: ${provenance.exported_at}`,
|
|
2307
|
-
`# export_source: ${provenance.export_source}`,
|
|
2308
|
-
""
|
|
2309
|
-
].join("\n");
|
|
2310
|
-
return provenanceComment + yamlContent;
|
|
2311
|
-
}
|
|
2312
|
-
function detectFormat(outPath, formatOption) {
|
|
2313
|
-
if (formatOption && formatOption !== "auto") {
|
|
2314
|
-
return formatOption;
|
|
2315
|
-
}
|
|
2316
|
-
const ext = extname(outPath).toLowerCase();
|
|
2317
|
-
switch (ext) {
|
|
2318
|
-
case ".json":
|
|
2319
|
-
return "json";
|
|
2320
|
-
case ".yaml":
|
|
2321
|
-
case ".yml":
|
|
2322
|
-
return "yaml";
|
|
2323
|
-
default:
|
|
2324
|
-
throw SchemaExportError.invalidFormat(ext, outPath);
|
|
2325
|
-
}
|
|
2326
|
-
}
|
|
2327
|
-
async function exportSchema(options) {
|
|
2328
|
-
const {
|
|
2329
|
-
schemaId,
|
|
2330
|
-
outPath,
|
|
2331
|
-
includeProvenance = true,
|
|
2332
|
-
validate = true,
|
|
2333
|
-
overwrite = false,
|
|
2334
|
-
format: formatOption,
|
|
2335
|
-
baseDir
|
|
2336
|
-
} = options;
|
|
2337
|
-
const format = detectFormat(outPath, formatOption);
|
|
2338
|
-
if (!overwrite) {
|
|
2339
|
-
try {
|
|
2340
|
-
await access(outPath);
|
|
2341
|
-
throw SchemaExportError.fileExists(outPath);
|
|
2342
|
-
} catch (error) {
|
|
2343
|
-
if (error.code !== "ENOENT") {
|
|
2344
|
-
throw error;
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
|
-
}
|
|
2348
|
-
const registry = getSchemaRegistry({ baseDir });
|
|
2349
|
-
const schema = await registry.getSchema(schemaId);
|
|
2350
|
-
const schemaContent = await readFile(schema.path, "utf-8");
|
|
2351
|
-
if (validate) {
|
|
2352
|
-
const validationResult = await validateSchema(schemaContent);
|
|
2353
|
-
if (!validationResult.valid) {
|
|
2354
|
-
throw SchemaValidationError.validationFailed(schemaId, validationResult.diagnostics, {
|
|
2355
|
-
type: "file",
|
|
2356
|
-
id: schema.path
|
|
2357
|
-
});
|
|
2358
|
-
}
|
|
2359
|
-
}
|
|
2360
|
-
let schemaObject;
|
|
2361
|
-
try {
|
|
2362
|
-
schemaObject = JSON.parse(schemaContent);
|
|
2363
|
-
} catch {
|
|
2364
|
-
schemaObject = parse(schemaContent);
|
|
2365
|
-
}
|
|
2366
|
-
Object.freeze(schemaObject);
|
|
2367
|
-
let provenance;
|
|
2368
|
-
let outputContent;
|
|
2369
|
-
if (includeProvenance) {
|
|
2370
|
-
provenance = await extractProvenanceMetadata(schemaId);
|
|
2371
|
-
outputContent = embedProvenance(schemaObject, provenance, format);
|
|
2372
|
-
} else {
|
|
2373
|
-
if (format === "json") {
|
|
2374
|
-
outputContent = JSON.stringify(schemaObject, null, 2);
|
|
2375
|
-
} else {
|
|
2376
|
-
outputContent = stringify(schemaObject, { indent: 2, lineWidth: 0 });
|
|
2377
|
-
}
|
|
2378
|
-
}
|
|
2379
|
-
await mkdir(dirname(outPath), { recursive: true });
|
|
2380
|
-
try {
|
|
2381
|
-
await writeFile(outPath, outputContent, "utf-8");
|
|
2382
|
-
} catch (error) {
|
|
2383
|
-
throw SchemaExportError.writeFailed(outPath, error);
|
|
2384
|
-
}
|
|
2385
|
-
return {
|
|
2386
|
-
success: true,
|
|
2387
|
-
schemaId,
|
|
2388
|
-
outPath,
|
|
2389
|
-
format,
|
|
2390
|
-
includeProvenance,
|
|
2391
|
-
provenance
|
|
2392
|
-
};
|
|
2393
|
-
}
|
|
2394
|
-
function stripProvenance(content) {
|
|
2395
|
-
try {
|
|
2396
|
-
const parsed = JSON.parse(content);
|
|
2397
|
-
if (parsed.$comment && typeof parsed.$comment === "object") {
|
|
2398
|
-
const comment = { ...parsed.$comment };
|
|
2399
|
-
delete comment["x-crucible-source"];
|
|
2400
|
-
if (Object.keys(comment).length === 0) {
|
|
2401
|
-
delete parsed.$comment;
|
|
2402
|
-
} else {
|
|
2403
|
-
parsed.$comment = comment;
|
|
2404
|
-
}
|
|
2405
|
-
}
|
|
2406
|
-
return JSON.stringify(parsed, null, 2);
|
|
2407
|
-
} catch {
|
|
2408
|
-
const lines = content.split("\n");
|
|
2409
|
-
const filtered = lines.filter((line) => {
|
|
2410
|
-
const trimmed = line.trim();
|
|
2411
|
-
return !(trimmed.startsWith("# x-crucible-source:") || trimmed.startsWith("# ") && /^#\s+(schema_id|crucible_version|library_version|revision|exported_at|export_source):/.test(
|
|
2412
|
-
trimmed
|
|
2413
|
-
));
|
|
2414
|
-
});
|
|
2415
|
-
while (filtered.length > 0 && filtered[0]?.trim() === "") {
|
|
2416
|
-
filtered.shift();
|
|
2417
|
-
}
|
|
2418
|
-
return filtered.join("\n");
|
|
1792
|
+
var init_cli = __esm({
|
|
1793
|
+
"src/schema/cli.ts"() {
|
|
1794
|
+
init_goneat_bridge();
|
|
1795
|
+
init_normalizer();
|
|
1796
|
+
init_registry();
|
|
1797
|
+
init_utils();
|
|
1798
|
+
init_validator();
|
|
2419
1799
|
}
|
|
2420
|
-
}
|
|
1800
|
+
});
|
|
2421
1801
|
var init_export = __esm({
|
|
2422
1802
|
"src/schema/export.ts"() {
|
|
2423
1803
|
init_errors2();
|
|
@@ -2426,3729 +1806,18 @@ var init_export = __esm({
|
|
|
2426
1806
|
}
|
|
2427
1807
|
});
|
|
2428
1808
|
|
|
2429
|
-
// src/
|
|
2430
|
-
var
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
}
|
|
2442
|
-
}
|
|
2443
|
-
static invalidSchema(catalog, details, cause) {
|
|
2444
|
-
return new _FoundryCatalogError(
|
|
2445
|
-
`Invalid schema in ${catalog} catalog: ${details}`,
|
|
2446
|
-
catalog,
|
|
2447
|
-
cause
|
|
2448
|
-
);
|
|
2449
|
-
}
|
|
2450
|
-
static missingCatalog(catalog) {
|
|
2451
|
-
return new _FoundryCatalogError(`Catalog ${catalog} not found or could not be loaded`, catalog);
|
|
2452
|
-
}
|
|
2453
|
-
static invalidPattern(patternId, details) {
|
|
2454
|
-
return new _FoundryCatalogError(`Invalid pattern ${patternId}: ${details}`, "patterns");
|
|
2455
|
-
}
|
|
2456
|
-
static compilationError(patternId, details, cause) {
|
|
2457
|
-
return new _FoundryCatalogError(
|
|
2458
|
-
`Failed to compile pattern ${patternId}: ${details}`,
|
|
2459
|
-
"patterns",
|
|
2460
|
-
cause
|
|
2461
|
-
);
|
|
2462
|
-
}
|
|
2463
|
-
};
|
|
2464
|
-
}
|
|
2465
|
-
});
|
|
2466
|
-
async function loadCatalog(filePath, catalogName, schemaId) {
|
|
2467
|
-
try {
|
|
2468
|
-
let content;
|
|
2469
|
-
if (typeof Bun !== "undefined") {
|
|
2470
|
-
try {
|
|
2471
|
-
const file = Bun.file(filePath);
|
|
2472
|
-
if (!await file.exists()) {
|
|
2473
|
-
throw FoundryCatalogError.missingCatalog(catalogName);
|
|
2474
|
-
}
|
|
2475
|
-
content = await file.text();
|
|
2476
|
-
} catch (error) {
|
|
2477
|
-
if (error instanceof Error && error.message.includes("No such file")) {
|
|
2478
|
-
throw FoundryCatalogError.missingCatalog(catalogName);
|
|
2479
|
-
}
|
|
2480
|
-
throw error;
|
|
2481
|
-
}
|
|
2482
|
-
} else {
|
|
2483
|
-
try {
|
|
2484
|
-
content = await readFile(filePath, "utf-8");
|
|
2485
|
-
} catch (error) {
|
|
2486
|
-
if (error.code === "ENOENT") {
|
|
2487
|
-
throw FoundryCatalogError.missingCatalog(catalogName);
|
|
2488
|
-
}
|
|
2489
|
-
throw error;
|
|
2490
|
-
}
|
|
2491
|
-
}
|
|
2492
|
-
const data = parse(content);
|
|
2493
|
-
const result = await validateDataBySchemaId(data, schemaId);
|
|
2494
|
-
if (!result.valid) {
|
|
2495
|
-
const errorMessages = result.diagnostics.map((d) => `${d.pointer}: ${d.message}`).join("; ");
|
|
2496
|
-
throw FoundryCatalogError.invalidSchema(
|
|
2497
|
-
catalogName,
|
|
2498
|
-
`Schema validation failed: ${errorMessages}`
|
|
2499
|
-
);
|
|
2500
|
-
}
|
|
2501
|
-
return data;
|
|
2502
|
-
} catch (error) {
|
|
2503
|
-
if (error instanceof FoundryCatalogError) {
|
|
2504
|
-
throw error;
|
|
2505
|
-
}
|
|
2506
|
-
const err = error;
|
|
2507
|
-
if (err.code === "ENOENT") {
|
|
2508
|
-
throw FoundryCatalogError.missingCatalog(catalogName);
|
|
2509
|
-
} else if (err.code === "EACCES") {
|
|
2510
|
-
throw FoundryCatalogError.invalidSchema(
|
|
2511
|
-
catalogName,
|
|
2512
|
-
"Permission denied accessing catalog file",
|
|
2513
|
-
err
|
|
2514
|
-
);
|
|
2515
|
-
} else if (err.code === "EISDIR") {
|
|
2516
|
-
throw FoundryCatalogError.invalidSchema(
|
|
2517
|
-
catalogName,
|
|
2518
|
-
"Expected file but found directory",
|
|
2519
|
-
err
|
|
2520
|
-
);
|
|
2521
|
-
} else if (err.code === "EMFILE" || err.code === "ENFILE") {
|
|
2522
|
-
throw FoundryCatalogError.invalidSchema(catalogName, "Too many open files", err);
|
|
2523
|
-
}
|
|
2524
|
-
throw FoundryCatalogError.invalidSchema(catalogName, "Failed to load catalog", err);
|
|
2525
|
-
}
|
|
2526
|
-
}
|
|
2527
|
-
async function loadPatternCatalog() {
|
|
2528
|
-
return loadCatalog(SSOT_PATHS.patterns, "patterns", SCHEMA_IDS.patterns);
|
|
2529
|
-
}
|
|
2530
|
-
async function loadHttpStatusCatalog() {
|
|
2531
|
-
return loadCatalog(
|
|
2532
|
-
SSOT_PATHS.httpStatuses,
|
|
2533
|
-
"httpStatuses",
|
|
2534
|
-
SCHEMA_IDS.httpStatuses
|
|
2535
|
-
);
|
|
2536
|
-
}
|
|
2537
|
-
async function loadMimeTypeCatalog() {
|
|
2538
|
-
return loadCatalog(SSOT_PATHS.mimeTypes, "mimeTypes", SCHEMA_IDS.mimeTypes);
|
|
2539
|
-
}
|
|
2540
|
-
async function loadCountryCodeCatalog() {
|
|
2541
|
-
return loadCatalog(
|
|
2542
|
-
SSOT_PATHS.countryCodes,
|
|
2543
|
-
"countryCodes",
|
|
2544
|
-
SCHEMA_IDS.countryCodes
|
|
2545
|
-
);
|
|
2546
|
-
}
|
|
2547
|
-
async function loadAllCatalogs() {
|
|
2548
|
-
const [patterns, httpStatuses, mimeTypes, countryCodes] = await Promise.all([
|
|
2549
|
-
loadPatternCatalog(),
|
|
2550
|
-
loadHttpStatusCatalog(),
|
|
2551
|
-
loadMimeTypeCatalog(),
|
|
2552
|
-
loadCountryCodeCatalog()
|
|
2553
|
-
]);
|
|
2554
|
-
return { patterns, httpStatuses, mimeTypes, countryCodes };
|
|
2555
|
-
}
|
|
2556
|
-
var __filename, __dirname2, SSOT_PATHS, SCHEMA_IDS;
|
|
2557
|
-
var init_loader = __esm({
|
|
2558
|
-
"src/foundry/loader.ts"() {
|
|
2559
|
-
init_validator();
|
|
2560
|
-
init_errors3();
|
|
2561
|
-
__filename = fileURLToPath(import.meta.url);
|
|
2562
|
-
__dirname2 = dirname(__filename);
|
|
2563
|
-
SSOT_PATHS = {
|
|
2564
|
-
patterns: join(__dirname2, "../../config/crucible-ts/library/foundry/patterns.yaml"),
|
|
2565
|
-
httpStatuses: join(__dirname2, "../../config/crucible-ts/library/foundry/http-statuses.yaml"),
|
|
2566
|
-
mimeTypes: join(__dirname2, "../../config/crucible-ts/library/foundry/mime-types.yaml"),
|
|
2567
|
-
countryCodes: join(__dirname2, "../../config/crucible-ts/library/foundry/country-codes.yaml")
|
|
2568
|
-
};
|
|
2569
|
-
SCHEMA_IDS = {
|
|
2570
|
-
patterns: "library/foundry/v1.0.0/patterns",
|
|
2571
|
-
httpStatuses: "library/foundry/v1.0.0/http-status-groups",
|
|
2572
|
-
mimeTypes: "library/foundry/v1.0.0/mime-types",
|
|
2573
|
-
countryCodes: "library/foundry/v1.0.0/country-codes"
|
|
2574
|
-
};
|
|
2575
|
-
}
|
|
2576
|
-
});
|
|
2577
|
-
|
|
2578
|
-
// src/foundry/country-codes.ts
|
|
2579
|
-
function deepClone(obj) {
|
|
2580
|
-
if (obj === null || typeof obj !== "object") {
|
|
2581
|
-
return obj;
|
|
2582
|
-
}
|
|
2583
|
-
if (Array.isArray(obj)) {
|
|
2584
|
-
return obj.map((item) => deepClone(item));
|
|
2585
|
-
}
|
|
2586
|
-
const cloned = {};
|
|
2587
|
-
for (const key in obj) {
|
|
2588
|
-
if (Object.hasOwn(obj, key)) {
|
|
2589
|
-
cloned[key] = deepClone(obj[key]);
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
return cloned;
|
|
2593
|
-
}
|
|
2594
|
-
function deepFreeze(obj) {
|
|
2595
|
-
Object.freeze(obj);
|
|
2596
|
-
for (const key in obj) {
|
|
2597
|
-
if (Object.hasOwn(obj, key)) {
|
|
2598
|
-
const value = obj[key];
|
|
2599
|
-
if (value !== null && typeof value === "object") {
|
|
2600
|
-
deepFreeze(value);
|
|
2601
|
-
}
|
|
2602
|
-
}
|
|
2603
|
-
}
|
|
2604
|
-
return obj;
|
|
2605
|
-
}
|
|
2606
|
-
function normalizeNumeric(code) {
|
|
2607
|
-
const str = typeof code === "number" ? code.toString() : code;
|
|
2608
|
-
return str.padStart(3, "0");
|
|
2609
|
-
}
|
|
2610
|
-
async function ensureCatalogLoaded() {
|
|
2611
|
-
if (catalogCache !== null) {
|
|
2612
|
-
return;
|
|
2613
|
-
}
|
|
2614
|
-
catalogCache = await loadCountryCodeCatalog();
|
|
2615
|
-
for (const country of catalogCache.countries) {
|
|
2616
|
-
alpha2Index.set(country.alpha2.toUpperCase(), country);
|
|
2617
|
-
alpha3Index.set(country.alpha3.toUpperCase(), country);
|
|
2618
|
-
const normalized = normalizeNumeric(country.numeric);
|
|
2619
|
-
numericIndex.set(normalized, country);
|
|
2620
|
-
}
|
|
2621
|
-
}
|
|
2622
|
-
async function getCountryByAlpha2(code) {
|
|
2623
|
-
await ensureCatalogLoaded();
|
|
2624
|
-
const normalized = code.toUpperCase();
|
|
2625
|
-
const country = alpha2Index.get(normalized);
|
|
2626
|
-
return country ? deepFreeze(deepClone(country)) : null;
|
|
2627
|
-
}
|
|
2628
|
-
async function getCountryByAlpha3(code) {
|
|
2629
|
-
await ensureCatalogLoaded();
|
|
2630
|
-
const normalized = code.toUpperCase();
|
|
2631
|
-
const country = alpha3Index.get(normalized);
|
|
2632
|
-
return country ? deepFreeze(deepClone(country)) : null;
|
|
2633
|
-
}
|
|
2634
|
-
async function getCountryByNumeric(code) {
|
|
2635
|
-
await ensureCatalogLoaded();
|
|
2636
|
-
const normalized = normalizeNumeric(code);
|
|
2637
|
-
const country = numericIndex.get(normalized);
|
|
2638
|
-
return country ? deepFreeze(deepClone(country)) : null;
|
|
2639
|
-
}
|
|
2640
|
-
async function listCountries() {
|
|
2641
|
-
await ensureCatalogLoaded();
|
|
2642
|
-
return Array.from(alpha2Index.values()).map((c) => deepFreeze(deepClone(c)));
|
|
2643
|
-
}
|
|
2644
|
-
function clearCountryCodeCache() {
|
|
2645
|
-
catalogCache = null;
|
|
2646
|
-
alpha2Index.clear();
|
|
2647
|
-
alpha3Index.clear();
|
|
2648
|
-
numericIndex.clear();
|
|
2649
|
-
}
|
|
2650
|
-
var catalogCache, alpha2Index, alpha3Index, numericIndex;
|
|
2651
|
-
var init_country_codes = __esm({
|
|
2652
|
-
"src/foundry/country-codes.ts"() {
|
|
2653
|
-
init_loader();
|
|
2654
|
-
catalogCache = null;
|
|
2655
|
-
alpha2Index = /* @__PURE__ */ new Map();
|
|
2656
|
-
alpha3Index = /* @__PURE__ */ new Map();
|
|
2657
|
-
numericIndex = /* @__PURE__ */ new Map();
|
|
2658
|
-
}
|
|
2659
|
-
});
|
|
2660
|
-
|
|
2661
|
-
// src/crucible/foundry/exitCodes.ts
|
|
2662
|
-
function getExitCodeInfo(code) {
|
|
2663
|
-
return exitCodeMetadata[code];
|
|
2664
|
-
}
|
|
2665
|
-
var exitCodes, exitCodeMetadata, EXIT_CODES_VERSION;
|
|
2666
|
-
var init_exitCodes = __esm({
|
|
2667
|
-
"src/crucible/foundry/exitCodes.ts"() {
|
|
2668
|
-
exitCodes = {
|
|
2669
|
-
// Standard Exit Codes (0-1)
|
|
2670
|
-
// POSIX standard success and generic failure codes
|
|
2671
|
-
EXIT_SUCCESS: 0,
|
|
2672
|
-
EXIT_FAILURE: 1,
|
|
2673
|
-
// Networking & Port Management (10-19)
|
|
2674
|
-
// Network-related failures (ports, connectivity, etc.)
|
|
2675
|
-
EXIT_PORT_IN_USE: 10,
|
|
2676
|
-
EXIT_PORT_RANGE_EXHAUSTED: 11,
|
|
2677
|
-
EXIT_INSTANCE_ALREADY_RUNNING: 12,
|
|
2678
|
-
EXIT_NETWORK_UNREACHABLE: 13,
|
|
2679
|
-
EXIT_CONNECTION_REFUSED: 14,
|
|
2680
|
-
EXIT_CONNECTION_TIMEOUT: 15,
|
|
2681
|
-
// Configuration & Validation (20-29)
|
|
2682
|
-
// Configuration errors, validation failures, version mismatches
|
|
2683
|
-
EXIT_CONFIG_INVALID: 20,
|
|
2684
|
-
EXIT_MISSING_DEPENDENCY: 21,
|
|
2685
|
-
EXIT_SSOT_VERSION_MISMATCH: 22,
|
|
2686
|
-
EXIT_CONFIG_FILE_NOT_FOUND: 23,
|
|
2687
|
-
EXIT_ENVIRONMENT_INVALID: 24,
|
|
2688
|
-
// Runtime Errors (30-39)
|
|
2689
|
-
// Errors during normal operation (health checks, database, etc.)
|
|
2690
|
-
EXIT_HEALTH_CHECK_FAILED: 30,
|
|
2691
|
-
EXIT_DATABASE_UNAVAILABLE: 31,
|
|
2692
|
-
EXIT_EXTERNAL_SERVICE_UNAVAILABLE: 32,
|
|
2693
|
-
EXIT_RESOURCE_EXHAUSTED: 33,
|
|
2694
|
-
EXIT_OPERATION_TIMEOUT: 34,
|
|
2695
|
-
// Command-Line Usage Errors (40-49)
|
|
2696
|
-
// Invalid arguments, missing required flags, usage errors
|
|
2697
|
-
EXIT_INVALID_ARGUMENT: 40,
|
|
2698
|
-
EXIT_MISSING_REQUIRED_ARGUMENT: 41,
|
|
2699
|
-
EXIT_USAGE: 64,
|
|
2700
|
-
// Permissions & File Access (50-59)
|
|
2701
|
-
// Permission denied, file not found, access errors
|
|
2702
|
-
EXIT_PERMISSION_DENIED: 50,
|
|
2703
|
-
EXIT_FILE_NOT_FOUND: 51,
|
|
2704
|
-
EXIT_DIRECTORY_NOT_FOUND: 52,
|
|
2705
|
-
EXIT_FILE_READ_ERROR: 53,
|
|
2706
|
-
EXIT_FILE_WRITE_ERROR: 54,
|
|
2707
|
-
// Data & Processing Errors (60-69)
|
|
2708
|
-
// Data validation, parsing, transformation failures
|
|
2709
|
-
EXIT_DATA_INVALID: 60,
|
|
2710
|
-
EXIT_PARSE_ERROR: 61,
|
|
2711
|
-
EXIT_TRANSFORMATION_FAILED: 62,
|
|
2712
|
-
EXIT_DATA_CORRUPT: 63,
|
|
2713
|
-
// Security & Authentication (70-79)
|
|
2714
|
-
// Authentication failures, authorization errors, security violations
|
|
2715
|
-
EXIT_AUTHENTICATION_FAILED: 70,
|
|
2716
|
-
EXIT_AUTHORIZATION_FAILED: 71,
|
|
2717
|
-
EXIT_SECURITY_VIOLATION: 72,
|
|
2718
|
-
EXIT_CERTIFICATE_INVALID: 73,
|
|
2719
|
-
// Observability & Monitoring (80-89)
|
|
2720
|
-
// Observability infrastructure failures. Use when observability is CRITICAL to operation (e.g., monitoring agents, telemetry exporters). For workhorses where observability is auxiliary: - Log warning and continue (don't exit) - Emit degraded health status - Only exit if explicitly configured (fail_on_observability_error: true)
|
|
2721
|
-
EXIT_METRICS_UNAVAILABLE: 80,
|
|
2722
|
-
EXIT_TRACING_FAILED: 81,
|
|
2723
|
-
EXIT_LOGGING_FAILED: 82,
|
|
2724
|
-
EXIT_ALERT_SYSTEM_FAILED: 83,
|
|
2725
|
-
EXIT_STRUCTURED_LOGGING_FAILED: 84,
|
|
2726
|
-
// Testing & Validation (91-99)
|
|
2727
|
-
// Test execution outcomes and validation failures. NOTE: Test harnesses MUST use EXIT_SUCCESS (0) for successful test runs per ecosystem conventions (pytest, Go testing, Jest all use 0 for success). Codes in this category are for FAILURES and exceptional conditions only.
|
|
2728
|
-
EXIT_TEST_FAILURE: 91,
|
|
2729
|
-
EXIT_TEST_ERROR: 92,
|
|
2730
|
-
EXIT_TEST_INTERRUPTED: 93,
|
|
2731
|
-
EXIT_TEST_USAGE_ERROR: 94,
|
|
2732
|
-
EXIT_TEST_NO_TESTS_COLLECTED: 95,
|
|
2733
|
-
EXIT_COVERAGE_THRESHOLD_NOT_MET: 96,
|
|
2734
|
-
// Shell & Process Control (124-127)
|
|
2735
|
-
// Exit codes from shell conventions and process control utilities (timeout, exec)
|
|
2736
|
-
EXIT_TIMEOUT: 124,
|
|
2737
|
-
EXIT_TIMEOUT_INTERNAL: 125,
|
|
2738
|
-
EXIT_CANNOT_EXECUTE: 126,
|
|
2739
|
-
EXIT_NOT_FOUND: 127,
|
|
2740
|
-
// Signal-Induced Exits (128-165)
|
|
2741
|
-
// Process terminated by Unix signals (128+N pattern per POSIX). Signal codes follow Linux numbering; macOS/FreeBSD differ for SIGUSR1/SIGUSR2. For full signal semantics, see config/library/foundry/signals.yaml. For signal handling patterns, see docs/standards/library/modules/signal-handling.md.
|
|
2742
|
-
EXIT_SIGNAL_HUP: 129,
|
|
2743
|
-
EXIT_SIGNAL_INT: 130,
|
|
2744
|
-
EXIT_SIGNAL_QUIT: 131,
|
|
2745
|
-
EXIT_SIGNAL_KILL: 137,
|
|
2746
|
-
EXIT_SIGNAL_PIPE: 141,
|
|
2747
|
-
EXIT_SIGNAL_ALRM: 142,
|
|
2748
|
-
EXIT_SIGNAL_TERM: 143,
|
|
2749
|
-
EXIT_SIGNAL_USR1: 138,
|
|
2750
|
-
EXIT_SIGNAL_USR2: 140
|
|
2751
|
-
};
|
|
2752
|
-
exitCodeMetadata = {
|
|
2753
|
-
0: {
|
|
2754
|
-
code: 0,
|
|
2755
|
-
name: "EXIT_SUCCESS",
|
|
2756
|
-
description: "Successful execution",
|
|
2757
|
-
context: "Command completed without errors",
|
|
2758
|
-
category: "standard"
|
|
2759
|
-
},
|
|
2760
|
-
1: {
|
|
2761
|
-
code: 1,
|
|
2762
|
-
name: "EXIT_FAILURE",
|
|
2763
|
-
description: "Generic failure (unspecified error)",
|
|
2764
|
-
context: "Use when no more specific exit code applies",
|
|
2765
|
-
category: "standard"
|
|
2766
|
-
},
|
|
2767
|
-
10: {
|
|
2768
|
-
code: 10,
|
|
2769
|
-
name: "EXIT_PORT_IN_USE",
|
|
2770
|
-
description: "Specified port is already in use",
|
|
2771
|
-
context: "Server startup when port unavailable and fail_if_unavailable strategy",
|
|
2772
|
-
category: "networking"
|
|
2773
|
-
},
|
|
2774
|
-
11: {
|
|
2775
|
-
code: 11,
|
|
2776
|
-
name: "EXIT_PORT_RANGE_EXHAUSTED",
|
|
2777
|
-
description: "No available ports in configured range",
|
|
2778
|
-
context: "Server startup when all ports in environment range occupied",
|
|
2779
|
-
category: "networking"
|
|
2780
|
-
},
|
|
2781
|
-
12: {
|
|
2782
|
-
code: 12,
|
|
2783
|
-
name: "EXIT_INSTANCE_ALREADY_RUNNING",
|
|
2784
|
-
description: "Another instance already running on target port",
|
|
2785
|
-
context: "Server startup when PID registry shows active process on port",
|
|
2786
|
-
category: "networking"
|
|
2787
|
-
},
|
|
2788
|
-
13: {
|
|
2789
|
-
code: 13,
|
|
2790
|
-
name: "EXIT_NETWORK_UNREACHABLE",
|
|
2791
|
-
description: "Network destination unreachable",
|
|
2792
|
-
context: "Client connections, health checks, external service validation",
|
|
2793
|
-
category: "networking"
|
|
2794
|
-
},
|
|
2795
|
-
14: {
|
|
2796
|
-
code: 14,
|
|
2797
|
-
name: "EXIT_CONNECTION_REFUSED",
|
|
2798
|
-
description: "Connection refused by remote host",
|
|
2799
|
-
context: "Database connections, API endpoints, upstream services",
|
|
2800
|
-
category: "networking"
|
|
2801
|
-
},
|
|
2802
|
-
15: {
|
|
2803
|
-
code: 15,
|
|
2804
|
-
name: "EXIT_CONNECTION_TIMEOUT",
|
|
2805
|
-
description: "Connection attempt timed out",
|
|
2806
|
-
context: "Slow networks, unresponsive services, firewall blocks",
|
|
2807
|
-
category: "networking"
|
|
2808
|
-
},
|
|
2809
|
-
20: {
|
|
2810
|
-
code: 20,
|
|
2811
|
-
name: "EXIT_CONFIG_INVALID",
|
|
2812
|
-
description: "Configuration file failed validation",
|
|
2813
|
-
context: "Startup validation, schema mismatches, invalid YAML/JSON",
|
|
2814
|
-
category: "configuration",
|
|
2815
|
-
retryHint: "no_retry"
|
|
2816
|
-
},
|
|
2817
|
-
21: {
|
|
2818
|
-
code: 21,
|
|
2819
|
-
name: "EXIT_MISSING_DEPENDENCY",
|
|
2820
|
-
description: "Required dependency not found",
|
|
2821
|
-
context: "Missing binaries, libraries, or runtime requirements",
|
|
2822
|
-
category: "configuration",
|
|
2823
|
-
retryHint: "investigate"
|
|
2824
|
-
},
|
|
2825
|
-
22: {
|
|
2826
|
-
code: 22,
|
|
2827
|
-
name: "EXIT_SSOT_VERSION_MISMATCH",
|
|
2828
|
-
description: "SSOT (Crucible) version incompatible",
|
|
2829
|
-
context: "Helper library detects unsupported Crucible version",
|
|
2830
|
-
category: "configuration",
|
|
2831
|
-
retryHint: "no_retry"
|
|
2832
|
-
},
|
|
2833
|
-
23: {
|
|
2834
|
-
code: 23,
|
|
2835
|
-
name: "EXIT_CONFIG_FILE_NOT_FOUND",
|
|
2836
|
-
description: "Required configuration file not found",
|
|
2837
|
-
context: "Explicitly specified config path doesn't exist",
|
|
2838
|
-
category: "configuration"
|
|
2839
|
-
},
|
|
2840
|
-
24: {
|
|
2841
|
-
code: 24,
|
|
2842
|
-
name: "EXIT_ENVIRONMENT_INVALID",
|
|
2843
|
-
description: "Invalid or unsupported environment specification",
|
|
2844
|
-
context: "Unknown environment name, missing environment config",
|
|
2845
|
-
category: "configuration"
|
|
2846
|
-
},
|
|
2847
|
-
30: {
|
|
2848
|
-
code: 30,
|
|
2849
|
-
name: "EXIT_HEALTH_CHECK_FAILED",
|
|
2850
|
-
description: "Health check endpoint returned non-healthy status",
|
|
2851
|
-
context: "Startup health validation, readiness probes",
|
|
2852
|
-
category: "runtime",
|
|
2853
|
-
retryHint: "retry"
|
|
2854
|
-
},
|
|
2855
|
-
31: {
|
|
2856
|
-
code: 31,
|
|
2857
|
-
name: "EXIT_DATABASE_UNAVAILABLE",
|
|
2858
|
-
description: "Database connection failed or unavailable",
|
|
2859
|
-
context: "Startup connection checks, critical query failures",
|
|
2860
|
-
category: "runtime",
|
|
2861
|
-
retryHint: "retry"
|
|
2862
|
-
},
|
|
2863
|
-
32: {
|
|
2864
|
-
code: 32,
|
|
2865
|
-
name: "EXIT_EXTERNAL_SERVICE_UNAVAILABLE",
|
|
2866
|
-
description: "Required external service unavailable",
|
|
2867
|
-
context: "API dependencies, message queues, cache servers",
|
|
2868
|
-
category: "runtime"
|
|
2869
|
-
},
|
|
2870
|
-
33: {
|
|
2871
|
-
code: 33,
|
|
2872
|
-
name: "EXIT_RESOURCE_EXHAUSTED",
|
|
2873
|
-
description: "System resources exhausted (memory, disk, file descriptors)",
|
|
2874
|
-
context: "Out-of-memory, disk full, too many open files",
|
|
2875
|
-
category: "runtime",
|
|
2876
|
-
retryHint: "investigate"
|
|
2877
|
-
},
|
|
2878
|
-
34: {
|
|
2879
|
-
code: 34,
|
|
2880
|
-
name: "EXIT_OPERATION_TIMEOUT",
|
|
2881
|
-
description: "Operation exceeded timeout threshold",
|
|
2882
|
-
context: "Long-running tasks, async operations, batch processing",
|
|
2883
|
-
category: "runtime",
|
|
2884
|
-
retryHint: "retry"
|
|
2885
|
-
},
|
|
2886
|
-
40: {
|
|
2887
|
-
code: 40,
|
|
2888
|
-
name: "EXIT_INVALID_ARGUMENT",
|
|
2889
|
-
description: "Invalid command-line argument or flag value",
|
|
2890
|
-
context: "Type errors, out-of-range values, malformed input",
|
|
2891
|
-
category: "usage"
|
|
2892
|
-
},
|
|
2893
|
-
41: {
|
|
2894
|
-
code: 41,
|
|
2895
|
-
name: "EXIT_MISSING_REQUIRED_ARGUMENT",
|
|
2896
|
-
description: "Required command-line argument not provided",
|
|
2897
|
-
context: "Missing --config, --port, or other required flags",
|
|
2898
|
-
category: "usage"
|
|
2899
|
-
},
|
|
2900
|
-
64: {
|
|
2901
|
-
code: 64,
|
|
2902
|
-
name: "EXIT_USAGE",
|
|
2903
|
-
description: "Command-line usage error",
|
|
2904
|
-
context: "BSD sysexits.h EX_USAGE - wrong number of arguments, bad syntax",
|
|
2905
|
-
category: "usage",
|
|
2906
|
-
bsdEquivalent: "EX_USAGE"
|
|
2907
|
-
},
|
|
2908
|
-
50: {
|
|
2909
|
-
code: 50,
|
|
2910
|
-
name: "EXIT_PERMISSION_DENIED",
|
|
2911
|
-
description: "Insufficient permissions for operation",
|
|
2912
|
-
context: "File access, port binding (<1024), privileged operations",
|
|
2913
|
-
category: "permissions"
|
|
2914
|
-
},
|
|
2915
|
-
51: {
|
|
2916
|
-
code: 51,
|
|
2917
|
-
name: "EXIT_FILE_NOT_FOUND",
|
|
2918
|
-
description: "Required file not found",
|
|
2919
|
-
context: "Assets, templates, data files (not config - use 23)",
|
|
2920
|
-
category: "permissions"
|
|
2921
|
-
},
|
|
2922
|
-
52: {
|
|
2923
|
-
code: 52,
|
|
2924
|
-
name: "EXIT_DIRECTORY_NOT_FOUND",
|
|
2925
|
-
description: "Required directory not found",
|
|
2926
|
-
context: "State directories, log paths, data directories",
|
|
2927
|
-
category: "permissions"
|
|
2928
|
-
},
|
|
2929
|
-
53: {
|
|
2930
|
-
code: 53,
|
|
2931
|
-
name: "EXIT_FILE_READ_ERROR",
|
|
2932
|
-
description: "Error reading file",
|
|
2933
|
-
context: "Corrupt files, I/O errors, encoding issues",
|
|
2934
|
-
category: "permissions"
|
|
2935
|
-
},
|
|
2936
|
-
54: {
|
|
2937
|
-
code: 54,
|
|
2938
|
-
name: "EXIT_FILE_WRITE_ERROR",
|
|
2939
|
-
description: "Error writing file",
|
|
2940
|
-
context: "Disk full, read-only filesystem, permission errors",
|
|
2941
|
-
category: "permissions"
|
|
2942
|
-
},
|
|
2943
|
-
60: {
|
|
2944
|
-
code: 60,
|
|
2945
|
-
name: "EXIT_DATA_INVALID",
|
|
2946
|
-
description: "Input data failed validation",
|
|
2947
|
-
context: "Schema validation, business rule violations",
|
|
2948
|
-
category: "data"
|
|
2949
|
-
},
|
|
2950
|
-
61: {
|
|
2951
|
-
code: 61,
|
|
2952
|
-
name: "EXIT_PARSE_ERROR",
|
|
2953
|
-
description: "Error parsing input data",
|
|
2954
|
-
context: "Malformed JSON/YAML/XML, syntax errors",
|
|
2955
|
-
category: "data"
|
|
2956
|
-
},
|
|
2957
|
-
62: {
|
|
2958
|
-
code: 62,
|
|
2959
|
-
name: "EXIT_TRANSFORMATION_FAILED",
|
|
2960
|
-
description: "Data transformation or conversion failed",
|
|
2961
|
-
context: "Type conversions, format transformations, encoding changes",
|
|
2962
|
-
category: "data"
|
|
2963
|
-
},
|
|
2964
|
-
63: {
|
|
2965
|
-
code: 63,
|
|
2966
|
-
name: "EXIT_DATA_CORRUPT",
|
|
2967
|
-
description: "Data corruption detected",
|
|
2968
|
-
context: "Checksum failures, integrity violations",
|
|
2969
|
-
category: "data"
|
|
2970
|
-
},
|
|
2971
|
-
70: {
|
|
2972
|
-
code: 70,
|
|
2973
|
-
name: "EXIT_AUTHENTICATION_FAILED",
|
|
2974
|
-
description: "Authentication failed",
|
|
2975
|
-
context: "Invalid credentials, expired tokens, auth service unavailable",
|
|
2976
|
-
category: "security"
|
|
2977
|
-
},
|
|
2978
|
-
71: {
|
|
2979
|
-
code: 71,
|
|
2980
|
-
name: "EXIT_AUTHORIZATION_FAILED",
|
|
2981
|
-
description: "Authorization failed (authenticated but insufficient permissions)",
|
|
2982
|
-
context: "RBAC failures, scope violations, resource access denied",
|
|
2983
|
-
category: "security"
|
|
2984
|
-
},
|
|
2985
|
-
72: {
|
|
2986
|
-
code: 72,
|
|
2987
|
-
name: "EXIT_SECURITY_VIOLATION",
|
|
2988
|
-
description: "Security policy violation detected",
|
|
2989
|
-
context: "Suspicious activity, rate limit exceeded, IP blocklist",
|
|
2990
|
-
category: "security"
|
|
2991
|
-
},
|
|
2992
|
-
73: {
|
|
2993
|
-
code: 73,
|
|
2994
|
-
name: "EXIT_CERTIFICATE_INVALID",
|
|
2995
|
-
description: "TLS/SSL certificate validation failed",
|
|
2996
|
-
context: "Expired certs, untrusted CAs, hostname mismatches",
|
|
2997
|
-
category: "security",
|
|
2998
|
-
bsdEquivalent: "EX_PROTOCOL"
|
|
2999
|
-
},
|
|
3000
|
-
80: {
|
|
3001
|
-
code: 80,
|
|
3002
|
-
name: "EXIT_METRICS_UNAVAILABLE",
|
|
3003
|
-
description: "Metrics endpoint or collection system unavailable",
|
|
3004
|
-
context: "Use for observability-focused tools (Prometheus exporters, StatsD agents).\nWorkhorses SHOULD log warning and continue unless configured to fail-fast.\n",
|
|
3005
|
-
category: "observability"
|
|
3006
|
-
},
|
|
3007
|
-
81: {
|
|
3008
|
-
code: 81,
|
|
3009
|
-
name: "EXIT_TRACING_FAILED",
|
|
3010
|
-
description: "Distributed tracing system unavailable",
|
|
3011
|
-
context: "OTLP exporter failed, Jaeger collector unreachable",
|
|
3012
|
-
category: "observability"
|
|
3013
|
-
},
|
|
3014
|
-
82: {
|
|
3015
|
-
code: 82,
|
|
3016
|
-
name: "EXIT_LOGGING_FAILED",
|
|
3017
|
-
description: "Logging system unavailable or misconfigured",
|
|
3018
|
-
context: "Log aggregator unreachable, log file unwritable",
|
|
3019
|
-
category: "observability"
|
|
3020
|
-
},
|
|
3021
|
-
83: {
|
|
3022
|
-
code: 83,
|
|
3023
|
-
name: "EXIT_ALERT_SYSTEM_FAILED",
|
|
3024
|
-
description: "Alerting system unavailable",
|
|
3025
|
-
context: "PagerDuty API failed, Slack webhook unreachable",
|
|
3026
|
-
category: "observability"
|
|
3027
|
-
},
|
|
3028
|
-
84: {
|
|
3029
|
-
code: 84,
|
|
3030
|
-
name: "EXIT_STRUCTURED_LOGGING_FAILED",
|
|
3031
|
-
description: "Structured logging system unavailable",
|
|
3032
|
-
context: "JSON log aggregator unreachable, log schema validation failed",
|
|
3033
|
-
category: "observability"
|
|
3034
|
-
},
|
|
3035
|
-
91: {
|
|
3036
|
-
code: 91,
|
|
3037
|
-
name: "EXIT_TEST_FAILURE",
|
|
3038
|
-
description: "One or more tests failed",
|
|
3039
|
-
context: "Test assertions failed, expected behavior not met.\nMaps to pytest exit code 1, Go test failure, Jest failure.\n",
|
|
3040
|
-
category: "testing"
|
|
3041
|
-
},
|
|
3042
|
-
92: {
|
|
3043
|
-
code: 92,
|
|
3044
|
-
name: "EXIT_TEST_ERROR",
|
|
3045
|
-
description: "Test execution error (not test failure)",
|
|
3046
|
-
context: "Test setup failed, fixture unavailable, test harness error.\nMaps to pytest exit code 3 (internal error).\n",
|
|
3047
|
-
category: "testing"
|
|
3048
|
-
},
|
|
3049
|
-
93: {
|
|
3050
|
-
code: 93,
|
|
3051
|
-
name: "EXIT_TEST_INTERRUPTED",
|
|
3052
|
-
description: "Test run interrupted by user or system",
|
|
3053
|
-
context: "Ctrl+C during tests, system signal, user cancellation.\nMaps to pytest exit code 2.\n",
|
|
3054
|
-
category: "testing"
|
|
3055
|
-
},
|
|
3056
|
-
94: {
|
|
3057
|
-
code: 94,
|
|
3058
|
-
name: "EXIT_TEST_USAGE_ERROR",
|
|
3059
|
-
description: "Test command usage error",
|
|
3060
|
-
context: "Invalid test arguments, bad configuration.\nMaps to pytest exit code 4.\n",
|
|
3061
|
-
category: "testing"
|
|
3062
|
-
},
|
|
3063
|
-
95: {
|
|
3064
|
-
code: 95,
|
|
3065
|
-
name: "EXIT_TEST_NO_TESTS_COLLECTED",
|
|
3066
|
-
description: "No tests found or all tests skipped",
|
|
3067
|
-
context: "Empty test suite, all tests deselected or skipped.\nMaps to pytest exit code 5.\n",
|
|
3068
|
-
category: "testing"
|
|
3069
|
-
},
|
|
3070
|
-
96: {
|
|
3071
|
-
code: 96,
|
|
3072
|
-
name: "EXIT_COVERAGE_THRESHOLD_NOT_MET",
|
|
3073
|
-
description: "Test coverage below required threshold",
|
|
3074
|
-
context: "Code coverage validation, quality gate failure",
|
|
3075
|
-
category: "testing"
|
|
3076
|
-
},
|
|
3077
|
-
124: {
|
|
3078
|
-
code: 124,
|
|
3079
|
-
name: "EXIT_TIMEOUT",
|
|
3080
|
-
description: "Command timed out before completion",
|
|
3081
|
-
context: "GNU timeout or similar utility terminated command after deadline",
|
|
3082
|
-
category: "shell"
|
|
3083
|
-
},
|
|
3084
|
-
125: {
|
|
3085
|
-
code: 125,
|
|
3086
|
-
name: "EXIT_TIMEOUT_INTERNAL",
|
|
3087
|
-
description: "Timeout utility itself failed",
|
|
3088
|
-
context: "Error in timeout tool before or during command execution (not command failure)",
|
|
3089
|
-
category: "shell"
|
|
3090
|
-
},
|
|
3091
|
-
126: {
|
|
3092
|
-
code: 126,
|
|
3093
|
-
name: "EXIT_CANNOT_EXECUTE",
|
|
3094
|
-
description: "Command found but could not be executed",
|
|
3095
|
-
context: "Permission denied, not executable, exec format error",
|
|
3096
|
-
category: "shell",
|
|
3097
|
-
bsdEquivalent: "EX_NOPERM (partial)"
|
|
3098
|
-
},
|
|
3099
|
-
127: {
|
|
3100
|
-
code: 127,
|
|
3101
|
-
name: "EXIT_NOT_FOUND",
|
|
3102
|
-
description: "Command not found",
|
|
3103
|
-
context: "Executable not found in PATH or specified path does not exist",
|
|
3104
|
-
category: "shell",
|
|
3105
|
-
bsdEquivalent: "EX_UNAVAILABLE (partial)"
|
|
3106
|
-
},
|
|
3107
|
-
129: {
|
|
3108
|
-
code: 129,
|
|
3109
|
-
name: "EXIT_SIGNAL_HUP",
|
|
3110
|
-
description: "Hangup signal (SIGHUP) - config reload via restart",
|
|
3111
|
-
context: "Config reload via restart-based pattern (mandatory schema validation).\nProcess exits with 129, supervisor restarts with new config.\nSee signals.yaml for reload behavior definition.",
|
|
3112
|
-
category: "signals",
|
|
3113
|
-
bsdEquivalent: "128 + 1"
|
|
3114
|
-
},
|
|
3115
|
-
130: {
|
|
3116
|
-
code: 130,
|
|
3117
|
-
name: "EXIT_SIGNAL_INT",
|
|
3118
|
-
description: "Interrupt signal (SIGINT) - user interrupt with Ctrl+C double-tap",
|
|
3119
|
-
context: "Ctrl+C pressed. First tap initiates graceful shutdown, second within 2s forces immediate exit.\nSame exit code (130) for both graceful and force modes.\nSee signals.yaml for double-tap behavior definition.",
|
|
3120
|
-
category: "signals",
|
|
3121
|
-
bsdEquivalent: "128 + 2"
|
|
3122
|
-
},
|
|
3123
|
-
131: {
|
|
3124
|
-
code: 131,
|
|
3125
|
-
name: "EXIT_SIGNAL_QUIT",
|
|
3126
|
-
description: "Quit signal (SIGQUIT) - immediate exit",
|
|
3127
|
-
context: "Ctrl+\\ on Unix, Ctrl+Break on Windows. Immediate termination without cleanup.\nUse for emergency shutdown or debugging (core dumps).",
|
|
3128
|
-
category: "signals",
|
|
3129
|
-
bsdEquivalent: "128 + 3"
|
|
3130
|
-
},
|
|
3131
|
-
137: {
|
|
3132
|
-
code: 137,
|
|
3133
|
-
name: "EXIT_SIGNAL_KILL",
|
|
3134
|
-
description: "Kill signal (SIGKILL)",
|
|
3135
|
-
context: "Forceful termination, non-graceful shutdown (not catchable)",
|
|
3136
|
-
category: "signals",
|
|
3137
|
-
bsdEquivalent: "128 + 9",
|
|
3138
|
-
pythonNote: "Cannot be caught in Python (OS-level)"
|
|
3139
|
-
},
|
|
3140
|
-
141: {
|
|
3141
|
-
code: 141,
|
|
3142
|
-
name: "EXIT_SIGNAL_PIPE",
|
|
3143
|
-
description: "Broken pipe (SIGPIPE) - observe only",
|
|
3144
|
-
context: "Writing to closed pipe/socket. Fulmen default is observe_only (log + graceful exit).\nApplications may override to ignore for network services.\nSee signals.yaml for SIGPIPE handling guidance.",
|
|
3145
|
-
category: "signals",
|
|
3146
|
-
bsdEquivalent: "128 + 13",
|
|
3147
|
-
pythonNote: "Raised as BrokenPipeError exception"
|
|
3148
|
-
},
|
|
3149
|
-
142: {
|
|
3150
|
-
code: 142,
|
|
3151
|
-
name: "EXIT_SIGNAL_ALRM",
|
|
3152
|
-
description: "Alarm signal (SIGALRM) - watchdog timeout",
|
|
3153
|
-
context: "Watchdog timer expired. Treat as timeout-induced exit.\nWatchdog pattern out of scope for v1.0.0 module implementations.",
|
|
3154
|
-
category: "signals",
|
|
3155
|
-
bsdEquivalent: "128 + 14",
|
|
3156
|
-
pythonNote: "Supported by signal module, rarely used in practice"
|
|
3157
|
-
},
|
|
3158
|
-
143: {
|
|
3159
|
-
code: 143,
|
|
3160
|
-
name: "EXIT_SIGNAL_TERM",
|
|
3161
|
-
description: "Termination signal (SIGTERM) - graceful shutdown",
|
|
3162
|
-
context: "Graceful shutdown requested by container orchestrator or process supervisor.\nStandard 30-second timeout for cleanup. Applications run cleanup handlers before exit.\nSee signals.yaml for graceful shutdown behavior definition.",
|
|
3163
|
-
category: "signals",
|
|
3164
|
-
bsdEquivalent: "128 + 15",
|
|
3165
|
-
pythonNote: "Default signal for graceful shutdown"
|
|
3166
|
-
},
|
|
3167
|
-
138: {
|
|
3168
|
-
code: 138,
|
|
3169
|
-
name: "EXIT_SIGNAL_USR1",
|
|
3170
|
-
description: "User-defined signal 1 (SIGUSR1) - custom handler",
|
|
3171
|
-
context: "Application-specific signal (e.g., reopen logs, dump stats, trigger profiling).\nApplications register custom handlers. Exit code 138 on Linux (128+10).\nPlatform differences: macOS/FreeBSD use signal 30 (exit 158), not 10.",
|
|
3172
|
-
category: "signals"
|
|
3173
|
-
},
|
|
3174
|
-
140: {
|
|
3175
|
-
code: 140,
|
|
3176
|
-
name: "EXIT_SIGNAL_USR2",
|
|
3177
|
-
description: "User-defined signal 2 (SIGUSR2) - custom handler",
|
|
3178
|
-
context: "Application-specific signal (e.g., toggle debug mode, rotate credentials).\nApplications register custom handlers. Exit code 140 on Linux (128+12).\nPlatform differences: macOS/FreeBSD use signal 31 (exit 159), not 12.",
|
|
3179
|
-
category: "signals"
|
|
3180
|
-
}
|
|
3181
|
-
};
|
|
3182
|
-
EXIT_CODES_VERSION = "v1.0.0";
|
|
3183
|
-
}
|
|
3184
|
-
});
|
|
3185
|
-
|
|
3186
|
-
// src/foundry/exit-codes/capabilities.ts
|
|
3187
|
-
function supportsSignalExitCodes() {
|
|
3188
|
-
return process.platform !== "win32";
|
|
3189
|
-
}
|
|
3190
|
-
function getPlatform() {
|
|
3191
|
-
return process.platform;
|
|
3192
|
-
}
|
|
3193
|
-
function isWindows() {
|
|
3194
|
-
return process.platform === "win32";
|
|
3195
|
-
}
|
|
3196
|
-
function isPOSIX() {
|
|
3197
|
-
return !isWindows();
|
|
3198
|
-
}
|
|
3199
|
-
function getPlatformCapabilities() {
|
|
3200
|
-
return {
|
|
3201
|
-
platform: getPlatform(),
|
|
3202
|
-
supportsSignalExitCodes: supportsSignalExitCodes(),
|
|
3203
|
-
isPOSIX: isPOSIX(),
|
|
3204
|
-
isWindows: isWindows()
|
|
3205
|
-
};
|
|
3206
|
-
}
|
|
3207
|
-
var init_capabilities = __esm({
|
|
3208
|
-
"src/foundry/exit-codes/capabilities.ts"() {
|
|
3209
|
-
}
|
|
3210
|
-
});
|
|
3211
|
-
|
|
3212
|
-
// src/foundry/exit-codes/simplified.ts
|
|
3213
|
-
function mapExitCodeToSimplified(code, mode = "basic" /* BASIC */) {
|
|
3214
|
-
if (code === 0) {
|
|
3215
|
-
return 0;
|
|
3216
|
-
}
|
|
3217
|
-
if (mode === "basic" /* BASIC */) {
|
|
3218
|
-
return 1;
|
|
3219
|
-
}
|
|
3220
|
-
const info = exitCodeMetadata[code];
|
|
3221
|
-
if (!info) {
|
|
3222
|
-
return 3;
|
|
3223
|
-
}
|
|
3224
|
-
if (info.retryHint === "retry") {
|
|
3225
|
-
return 1;
|
|
3226
|
-
}
|
|
3227
|
-
if (info.retryHint === "no_retry") {
|
|
3228
|
-
return 2;
|
|
3229
|
-
}
|
|
3230
|
-
if (info.retryHint === "investigate") {
|
|
3231
|
-
return 3;
|
|
3232
|
-
}
|
|
3233
|
-
switch (info.category) {
|
|
3234
|
-
case "configuration":
|
|
3235
|
-
case "usage":
|
|
3236
|
-
return 2;
|
|
3237
|
-
case "networking":
|
|
3238
|
-
case "runtime":
|
|
3239
|
-
return 1;
|
|
3240
|
-
case "permissions":
|
|
3241
|
-
case "data":
|
|
3242
|
-
return 2;
|
|
3243
|
-
case "security":
|
|
3244
|
-
return 3;
|
|
3245
|
-
case "observability":
|
|
3246
|
-
return 1;
|
|
3247
|
-
case "testing":
|
|
3248
|
-
return 1;
|
|
3249
|
-
case "signals":
|
|
3250
|
-
return 3;
|
|
3251
|
-
default:
|
|
3252
|
-
return 1;
|
|
3253
|
-
}
|
|
3254
|
-
}
|
|
3255
|
-
function getSimplifiedCodes(mode) {
|
|
3256
|
-
switch (mode) {
|
|
3257
|
-
case "basic" /* BASIC */:
|
|
3258
|
-
return [0, 1];
|
|
3259
|
-
case "severity" /* SEVERITY */:
|
|
3260
|
-
return [0, 1, 2, 3];
|
|
3261
|
-
default:
|
|
3262
|
-
return [0, 1];
|
|
3263
|
-
}
|
|
3264
|
-
}
|
|
3265
|
-
function getSimplifiedCodeDescription(code, mode) {
|
|
3266
|
-
if (mode === "basic" /* BASIC */) {
|
|
3267
|
-
switch (code) {
|
|
3268
|
-
case 0:
|
|
3269
|
-
return "Success";
|
|
3270
|
-
case 1:
|
|
3271
|
-
return "Failure";
|
|
3272
|
-
default:
|
|
3273
|
-
return "Unknown";
|
|
3274
|
-
}
|
|
3275
|
-
}
|
|
3276
|
-
if (mode === "severity" /* SEVERITY */) {
|
|
3277
|
-
switch (code) {
|
|
3278
|
-
case 0:
|
|
3279
|
-
return "Success";
|
|
3280
|
-
case 1:
|
|
3281
|
-
return "Recoverable error (retry possible)";
|
|
3282
|
-
case 2:
|
|
3283
|
-
return "Configuration error (fix config, don't retry)";
|
|
3284
|
-
case 3:
|
|
3285
|
-
return "Fatal error (investigate required)";
|
|
3286
|
-
default:
|
|
3287
|
-
return "Unknown";
|
|
3288
|
-
}
|
|
3289
|
-
}
|
|
3290
|
-
return "Unknown mode";
|
|
3291
|
-
}
|
|
3292
|
-
var SimplifiedMode;
|
|
3293
|
-
var init_simplified = __esm({
|
|
3294
|
-
"src/foundry/exit-codes/simplified.ts"() {
|
|
3295
|
-
init_exitCodes();
|
|
3296
|
-
SimplifiedMode = /* @__PURE__ */ ((SimplifiedMode2) => {
|
|
3297
|
-
SimplifiedMode2["BASIC"] = "basic";
|
|
3298
|
-
SimplifiedMode2["SEVERITY"] = "severity";
|
|
3299
|
-
return SimplifiedMode2;
|
|
3300
|
-
})(SimplifiedMode || {});
|
|
3301
|
-
}
|
|
3302
|
-
});
|
|
3303
|
-
|
|
3304
|
-
// src/foundry/exit-codes/index.ts
|
|
3305
|
-
var init_exit_codes = __esm({
|
|
3306
|
-
"src/foundry/exit-codes/index.ts"() {
|
|
3307
|
-
init_exitCodes();
|
|
3308
|
-
init_capabilities();
|
|
3309
|
-
init_simplified();
|
|
3310
|
-
}
|
|
3311
|
-
});
|
|
3312
|
-
|
|
3313
|
-
// src/foundry/http-statuses.ts
|
|
3314
|
-
function deepClone2(obj) {
|
|
3315
|
-
if (obj === null || typeof obj !== "object") {
|
|
3316
|
-
return obj;
|
|
3317
|
-
}
|
|
3318
|
-
if (Array.isArray(obj)) {
|
|
3319
|
-
return obj.map((item) => deepClone2(item));
|
|
3320
|
-
}
|
|
3321
|
-
const cloned = {};
|
|
3322
|
-
for (const key in obj) {
|
|
3323
|
-
if (Object.hasOwn(obj, key)) {
|
|
3324
|
-
cloned[key] = deepClone2(obj[key]);
|
|
3325
|
-
}
|
|
3326
|
-
}
|
|
3327
|
-
return cloned;
|
|
3328
|
-
}
|
|
3329
|
-
function deepFreeze2(obj) {
|
|
3330
|
-
Object.freeze(obj);
|
|
3331
|
-
for (const key in obj) {
|
|
3332
|
-
if (Object.hasOwn(obj, key)) {
|
|
3333
|
-
const value = obj[key];
|
|
3334
|
-
if (value !== null && typeof value === "object") {
|
|
3335
|
-
deepFreeze2(value);
|
|
3336
|
-
}
|
|
3337
|
-
}
|
|
3338
|
-
}
|
|
3339
|
-
return obj;
|
|
3340
|
-
}
|
|
3341
|
-
async function ensureCatalogLoaded2() {
|
|
3342
|
-
if (catalogCache2 !== null) {
|
|
3343
|
-
return;
|
|
3344
|
-
}
|
|
3345
|
-
catalogCache2 = await loadHttpStatusCatalog();
|
|
3346
|
-
for (const group of catalogCache2.groups) {
|
|
3347
|
-
const groupId = group.id;
|
|
3348
|
-
for (const code of group.codes) {
|
|
3349
|
-
statusCodeIndex.set(code.value, {
|
|
3350
|
-
value: code.value,
|
|
3351
|
-
reason: code.reason,
|
|
3352
|
-
group: groupId
|
|
3353
|
-
});
|
|
3354
|
-
}
|
|
3355
|
-
}
|
|
3356
|
-
}
|
|
3357
|
-
async function getHttpStatus(code) {
|
|
3358
|
-
await ensureCatalogLoaded2();
|
|
3359
|
-
const status = statusCodeIndex.get(code);
|
|
3360
|
-
return status ? deepFreeze2(deepClone2(status)) : null;
|
|
3361
|
-
}
|
|
3362
|
-
function isInformational(code) {
|
|
3363
|
-
return code >= 100 && code < 200;
|
|
3364
|
-
}
|
|
3365
|
-
function isSuccess(code) {
|
|
3366
|
-
return code >= 200 && code < 300;
|
|
3367
|
-
}
|
|
3368
|
-
function isRedirection(code) {
|
|
3369
|
-
return code >= 300 && code < 400;
|
|
3370
|
-
}
|
|
3371
|
-
function isClientError(code) {
|
|
3372
|
-
return code >= 400 && code < 500;
|
|
3373
|
-
}
|
|
3374
|
-
function isServerError(code) {
|
|
3375
|
-
return code >= 500 && code < 600;
|
|
3376
|
-
}
|
|
3377
|
-
async function listHttpStatuses() {
|
|
3378
|
-
await ensureCatalogLoaded2();
|
|
3379
|
-
return Array.from(statusCodeIndex.values()).map((s) => deepFreeze2(deepClone2(s)));
|
|
3380
|
-
}
|
|
3381
|
-
async function getStatusReason(code) {
|
|
3382
|
-
const status = await getHttpStatus(code);
|
|
3383
|
-
return status?.reason ?? null;
|
|
3384
|
-
}
|
|
3385
|
-
function clearHttpStatusCache() {
|
|
3386
|
-
catalogCache2 = null;
|
|
3387
|
-
statusCodeIndex.clear();
|
|
3388
|
-
}
|
|
3389
|
-
var catalogCache2, statusCodeIndex;
|
|
3390
|
-
var init_http_statuses = __esm({
|
|
3391
|
-
"src/foundry/http-statuses.ts"() {
|
|
3392
|
-
init_loader();
|
|
3393
|
-
catalogCache2 = null;
|
|
3394
|
-
statusCodeIndex = /* @__PURE__ */ new Map();
|
|
3395
|
-
}
|
|
3396
|
-
});
|
|
3397
|
-
|
|
3398
|
-
// src/foundry/magic-numbers.ts
|
|
3399
|
-
function hasBOM(buffer) {
|
|
3400
|
-
if (buffer.length < 3) return false;
|
|
3401
|
-
return buffer[0] === UTF8_BOM[0] && buffer[1] === UTF8_BOM[1] && buffer[2] === UTF8_BOM[2];
|
|
3402
|
-
}
|
|
3403
|
-
function getBOMOffset(buffer) {
|
|
3404
|
-
return hasBOM(buffer) ? 3 : 0;
|
|
3405
|
-
}
|
|
3406
|
-
var UTF8_BOM, XML_PATTERNS, JSON_PATTERNS, YAML_PATTERNS, NDJSON_PATTERNS, CSV_PATTERNS, PROTOBUF_PATTERNS, TEXT_PATTERNS, MAGIC_NUMBER_DATABASE;
|
|
3407
|
-
var init_magic_numbers = __esm({
|
|
3408
|
-
"src/foundry/magic-numbers.ts"() {
|
|
3409
|
-
UTF8_BOM = [239, 187, 191];
|
|
3410
|
-
XML_PATTERNS = [
|
|
3411
|
-
{
|
|
3412
|
-
offset: 0,
|
|
3413
|
-
bytes: [60, 63, 120, 109, 108],
|
|
3414
|
-
description: "XML declaration: <?xml"
|
|
3415
|
-
},
|
|
3416
|
-
{
|
|
3417
|
-
offset: 0,
|
|
3418
|
-
bytes: [239, 187, 191, 60, 63, 120, 109, 108],
|
|
3419
|
-
description: "XML with UTF-8 BOM: BOM + <?xml"
|
|
3420
|
-
}
|
|
3421
|
-
];
|
|
3422
|
-
JSON_PATTERNS = [
|
|
3423
|
-
{
|
|
3424
|
-
offset: 0,
|
|
3425
|
-
bytes: [123],
|
|
3426
|
-
description: "JSON object start: {"
|
|
3427
|
-
},
|
|
3428
|
-
{
|
|
3429
|
-
offset: 0,
|
|
3430
|
-
bytes: [91],
|
|
3431
|
-
description: "JSON array start: ["
|
|
3432
|
-
},
|
|
3433
|
-
{
|
|
3434
|
-
offset: 0,
|
|
3435
|
-
bytes: [239, 187, 191, 123],
|
|
3436
|
-
description: "JSON object with BOM: BOM + {"
|
|
3437
|
-
},
|
|
3438
|
-
{
|
|
3439
|
-
offset: 0,
|
|
3440
|
-
bytes: [239, 187, 191, 91],
|
|
3441
|
-
description: "JSON array with BOM: BOM + ["
|
|
3442
|
-
}
|
|
3443
|
-
];
|
|
3444
|
-
YAML_PATTERNS = [
|
|
3445
|
-
{
|
|
3446
|
-
offset: 0,
|
|
3447
|
-
bytes: [45, 45, 45],
|
|
3448
|
-
description: "YAML document marker: ---"
|
|
3449
|
-
},
|
|
3450
|
-
{
|
|
3451
|
-
offset: 0,
|
|
3452
|
-
bytes: [37, 89, 65, 77, 76],
|
|
3453
|
-
description: "YAML directive: %YAML"
|
|
3454
|
-
}
|
|
3455
|
-
];
|
|
3456
|
-
NDJSON_PATTERNS = [];
|
|
3457
|
-
CSV_PATTERNS = [];
|
|
3458
|
-
PROTOBUF_PATTERNS = [];
|
|
3459
|
-
TEXT_PATTERNS = [];
|
|
3460
|
-
MAGIC_NUMBER_DATABASE = [
|
|
3461
|
-
{
|
|
3462
|
-
mimeType: "application/xml",
|
|
3463
|
-
patterns: XML_PATTERNS,
|
|
3464
|
-
priority: 10,
|
|
3465
|
-
matchStrategy: "exact"
|
|
3466
|
-
},
|
|
3467
|
-
{
|
|
3468
|
-
mimeType: "application/x-ndjson",
|
|
3469
|
-
patterns: NDJSON_PATTERNS,
|
|
3470
|
-
priority: 9,
|
|
3471
|
-
matchStrategy: "heuristic"
|
|
3472
|
-
},
|
|
3473
|
-
{
|
|
3474
|
-
mimeType: "application/json",
|
|
3475
|
-
patterns: JSON_PATTERNS,
|
|
3476
|
-
priority: 8,
|
|
3477
|
-
matchStrategy: "exact"
|
|
3478
|
-
},
|
|
3479
|
-
{
|
|
3480
|
-
mimeType: "application/yaml",
|
|
3481
|
-
patterns: YAML_PATTERNS,
|
|
3482
|
-
priority: 7,
|
|
3483
|
-
matchStrategy: "exact"
|
|
3484
|
-
},
|
|
3485
|
-
{
|
|
3486
|
-
mimeType: "application/yaml",
|
|
3487
|
-
patterns: [],
|
|
3488
|
-
priority: 6.5,
|
|
3489
|
-
matchStrategy: "heuristic"
|
|
3490
|
-
},
|
|
3491
|
-
{
|
|
3492
|
-
mimeType: "text/csv",
|
|
3493
|
-
patterns: CSV_PATTERNS,
|
|
3494
|
-
priority: 6,
|
|
3495
|
-
matchStrategy: "heuristic"
|
|
3496
|
-
},
|
|
3497
|
-
{
|
|
3498
|
-
mimeType: "application/x-protobuf",
|
|
3499
|
-
patterns: PROTOBUF_PATTERNS,
|
|
3500
|
-
priority: 5,
|
|
3501
|
-
matchStrategy: "heuristic"
|
|
3502
|
-
},
|
|
3503
|
-
{
|
|
3504
|
-
mimeType: "text/plain",
|
|
3505
|
-
patterns: TEXT_PATTERNS,
|
|
3506
|
-
priority: 1,
|
|
3507
|
-
matchStrategy: "heuristic"
|
|
3508
|
-
}
|
|
3509
|
-
];
|
|
3510
|
-
}
|
|
3511
|
-
});
|
|
3512
|
-
|
|
3513
|
-
// src/foundry/detector.ts
|
|
3514
|
-
function createDetector(catalog) {
|
|
3515
|
-
return new MimeTypeDetector(MAGIC_NUMBER_DATABASE, catalog);
|
|
3516
|
-
}
|
|
3517
|
-
var MimeTypeDetector;
|
|
3518
|
-
var init_detector = __esm({
|
|
3519
|
-
"src/foundry/detector.ts"() {
|
|
3520
|
-
init_magic_numbers();
|
|
3521
|
-
MimeTypeDetector = class {
|
|
3522
|
-
patterns;
|
|
3523
|
-
catalog;
|
|
3524
|
-
constructor(patterns, catalog) {
|
|
3525
|
-
this.patterns = [...patterns].sort((a, b) => b.priority - a.priority);
|
|
3526
|
-
this.catalog = catalog;
|
|
3527
|
-
}
|
|
3528
|
-
/**
|
|
3529
|
-
* Detect MIME type from buffer content
|
|
3530
|
-
*/
|
|
3531
|
-
detect(buffer, _options = {}) {
|
|
3532
|
-
const offset = getBOMOffset(buffer);
|
|
3533
|
-
const workingBuffer = offset > 0 ? buffer.subarray(offset) : buffer;
|
|
3534
|
-
for (const pattern of this.patterns) {
|
|
3535
|
-
if (pattern.matchStrategy === "exact" && this.matchPattern(workingBuffer, pattern)) {
|
|
3536
|
-
return this.catalog.get(pattern.mimeType) || null;
|
|
3537
|
-
}
|
|
3538
|
-
if (pattern.matchStrategy === "heuristic" && this.matchHeuristic(workingBuffer, pattern)) {
|
|
3539
|
-
return this.catalog.get(pattern.mimeType) || null;
|
|
3540
|
-
}
|
|
3541
|
-
}
|
|
3542
|
-
return null;
|
|
3543
|
-
}
|
|
3544
|
-
/**
|
|
3545
|
-
* Match buffer against a pattern signature
|
|
3546
|
-
*/
|
|
3547
|
-
matchPattern(buffer, signature) {
|
|
3548
|
-
for (const pattern of signature.patterns) {
|
|
3549
|
-
if (this.matchBytes(buffer, pattern)) {
|
|
3550
|
-
return true;
|
|
3551
|
-
}
|
|
3552
|
-
}
|
|
3553
|
-
return false;
|
|
3554
|
-
}
|
|
3555
|
-
/**
|
|
3556
|
-
* Match bytes at specified offset with optional masking
|
|
3557
|
-
*/
|
|
3558
|
-
matchBytes(buffer, pattern) {
|
|
3559
|
-
const { offset, bytes, mask } = pattern;
|
|
3560
|
-
if (buffer.length < offset + bytes.length) {
|
|
3561
|
-
return false;
|
|
3562
|
-
}
|
|
3563
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
3564
|
-
const bufferByte = buffer[offset + i];
|
|
3565
|
-
const patternByte = bytes[i];
|
|
3566
|
-
const maskByte = mask ? mask[i] : 255;
|
|
3567
|
-
if ((bufferByte & maskByte) !== (patternByte & maskByte)) {
|
|
3568
|
-
return false;
|
|
3569
|
-
}
|
|
3570
|
-
}
|
|
3571
|
-
return true;
|
|
3572
|
-
}
|
|
3573
|
-
/**
|
|
3574
|
-
* Heuristic detection for formats without magic numbers
|
|
3575
|
-
*/
|
|
3576
|
-
matchHeuristic(buffer, signature) {
|
|
3577
|
-
switch (signature.mimeType) {
|
|
3578
|
-
case "application/x-ndjson":
|
|
3579
|
-
return this.detectNDJSON(buffer);
|
|
3580
|
-
case "application/yaml":
|
|
3581
|
-
return this.detectYAML(buffer);
|
|
3582
|
-
case "text/csv":
|
|
3583
|
-
return this.detectCSV(buffer);
|
|
3584
|
-
case "application/x-protobuf":
|
|
3585
|
-
return this.detectProtobuf(buffer);
|
|
3586
|
-
case "text/plain":
|
|
3587
|
-
return this.detectPlainText(buffer);
|
|
3588
|
-
default:
|
|
3589
|
-
return false;
|
|
3590
|
-
}
|
|
3591
|
-
}
|
|
3592
|
-
/**
|
|
3593
|
-
* Detect NDJSON (newline-delimited JSON)
|
|
3594
|
-
*/
|
|
3595
|
-
detectNDJSON(buffer) {
|
|
3596
|
-
try {
|
|
3597
|
-
const text = buffer.toString("utf-8", 0, Math.min(buffer.length, 512));
|
|
3598
|
-
const lines = text.split("\n").filter((line) => line.trim().length > 0);
|
|
3599
|
-
if (lines.length < 2) return false;
|
|
3600
|
-
const linesToCheck = Math.min(3, lines.length);
|
|
3601
|
-
let validJsonLines = 0;
|
|
3602
|
-
for (let i = 0; i < linesToCheck; i++) {
|
|
3603
|
-
try {
|
|
3604
|
-
JSON.parse(lines[i]);
|
|
3605
|
-
validJsonLines++;
|
|
3606
|
-
} catch {
|
|
3607
|
-
return false;
|
|
3608
|
-
}
|
|
3609
|
-
}
|
|
3610
|
-
return validJsonLines >= 2;
|
|
3611
|
-
} catch {
|
|
3612
|
-
return false;
|
|
3613
|
-
}
|
|
3614
|
-
}
|
|
3615
|
-
/**
|
|
3616
|
-
* Detect YAML format (heuristic for files without --- header)
|
|
3617
|
-
*/
|
|
3618
|
-
detectYAML(buffer) {
|
|
3619
|
-
try {
|
|
3620
|
-
const text = buffer.toString("utf-8", 0, Math.min(buffer.length, 512));
|
|
3621
|
-
const lines = text.split("\n").filter((line) => line.trim().length > 0);
|
|
3622
|
-
if (lines.length === 0) return false;
|
|
3623
|
-
let yamlIndicators = 0;
|
|
3624
|
-
let nonYamlIndicators = 0;
|
|
3625
|
-
for (const line of lines.slice(0, 10)) {
|
|
3626
|
-
const trimmed = line.trim();
|
|
3627
|
-
if (trimmed.startsWith("#")) continue;
|
|
3628
|
-
if (/^[\w"'-]+\s*:\s*.+$/.test(trimmed)) {
|
|
3629
|
-
yamlIndicators++;
|
|
3630
|
-
continue;
|
|
3631
|
-
}
|
|
3632
|
-
if (/^-\s+/.test(trimmed)) {
|
|
3633
|
-
yamlIndicators++;
|
|
3634
|
-
continue;
|
|
3635
|
-
}
|
|
3636
|
-
if (trimmed.startsWith("{") || trimmed.startsWith("[") || trimmed.endsWith(",")) {
|
|
3637
|
-
nonYamlIndicators++;
|
|
3638
|
-
}
|
|
3639
|
-
}
|
|
3640
|
-
return yamlIndicators >= 2 && nonYamlIndicators === 0;
|
|
3641
|
-
} catch {
|
|
3642
|
-
return false;
|
|
3643
|
-
}
|
|
3644
|
-
}
|
|
3645
|
-
/**
|
|
3646
|
-
* Detect CSV format
|
|
3647
|
-
*/
|
|
3648
|
-
detectCSV(buffer) {
|
|
3649
|
-
try {
|
|
3650
|
-
const text = buffer.toString("utf-8", 0, Math.min(buffer.length, 512));
|
|
3651
|
-
const lines = text.split("\n").filter((line) => line.trim().length > 0);
|
|
3652
|
-
if (lines.length < 2) return false;
|
|
3653
|
-
const delimiters = [",", ";", " "];
|
|
3654
|
-
for (const delimiter of delimiters) {
|
|
3655
|
-
const counts = lines.map((line) => {
|
|
3656
|
-
const escaped = delimiter.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3657
|
-
const matches = line.match(new RegExp(escaped, "g"));
|
|
3658
|
-
return matches ? matches.length : 0;
|
|
3659
|
-
});
|
|
3660
|
-
const firstCount = counts[0];
|
|
3661
|
-
if (firstCount > 0 && counts.every((count) => count === firstCount)) {
|
|
3662
|
-
return true;
|
|
3663
|
-
}
|
|
3664
|
-
}
|
|
3665
|
-
return false;
|
|
3666
|
-
} catch {
|
|
3667
|
-
return false;
|
|
3668
|
-
}
|
|
3669
|
-
}
|
|
3670
|
-
/**
|
|
3671
|
-
* Detect protobuf binary format
|
|
3672
|
-
*/
|
|
3673
|
-
detectProtobuf(buffer) {
|
|
3674
|
-
if (buffer.length < 4) return false;
|
|
3675
|
-
const firstByte = buffer[0];
|
|
3676
|
-
const wireType = firstByte & 7;
|
|
3677
|
-
const fieldNumber = firstByte >> 3;
|
|
3678
|
-
const hasValidWireType = wireType === 0 || wireType === 1 || wireType === 2 || wireType === 5;
|
|
3679
|
-
const hasValidFieldNumber = fieldNumber > 0 && fieldNumber < 100;
|
|
3680
|
-
const isBinary = this.isBinaryContent(buffer);
|
|
3681
|
-
return hasValidWireType && hasValidFieldNumber && isBinary;
|
|
3682
|
-
}
|
|
3683
|
-
/**
|
|
3684
|
-
* Detect plain text format
|
|
3685
|
-
*/
|
|
3686
|
-
detectPlainText(buffer) {
|
|
3687
|
-
const sample = buffer.subarray(0, Math.min(buffer.length, 512));
|
|
3688
|
-
if (sample.length === 0) return false;
|
|
3689
|
-
let binaryBytes = 0;
|
|
3690
|
-
for (const byte of sample) {
|
|
3691
|
-
if (byte === 0 || byte < 32 && byte !== 9 && byte !== 10 && byte !== 13) {
|
|
3692
|
-
binaryBytes++;
|
|
3693
|
-
}
|
|
3694
|
-
}
|
|
3695
|
-
return binaryBytes / sample.length < 0.05;
|
|
3696
|
-
}
|
|
3697
|
-
/**
|
|
3698
|
-
* Check if buffer contains binary content
|
|
3699
|
-
*/
|
|
3700
|
-
isBinaryContent(buffer) {
|
|
3701
|
-
const sample = buffer.subarray(0, Math.min(buffer.length, 512));
|
|
3702
|
-
let binaryBytes = 0;
|
|
3703
|
-
for (const byte of sample) {
|
|
3704
|
-
if (byte === 0 || byte < 32 && byte !== 9 && byte !== 10 && byte !== 13) {
|
|
3705
|
-
binaryBytes++;
|
|
3706
|
-
}
|
|
3707
|
-
}
|
|
3708
|
-
return binaryBytes / sample.length > 0.1;
|
|
3709
|
-
}
|
|
3710
|
-
};
|
|
3711
|
-
}
|
|
3712
|
-
});
|
|
3713
|
-
function deepClone3(obj) {
|
|
3714
|
-
if (obj === null || typeof obj !== "object") {
|
|
3715
|
-
return obj;
|
|
3716
|
-
}
|
|
3717
|
-
if (Array.isArray(obj)) {
|
|
3718
|
-
return obj.map((item) => deepClone3(item));
|
|
3719
|
-
}
|
|
3720
|
-
const cloned = {};
|
|
3721
|
-
for (const key in obj) {
|
|
3722
|
-
if (Object.hasOwn(obj, key)) {
|
|
3723
|
-
cloned[key] = deepClone3(obj[key]);
|
|
3724
|
-
}
|
|
3725
|
-
}
|
|
3726
|
-
return cloned;
|
|
3727
|
-
}
|
|
3728
|
-
function deepFreeze3(obj) {
|
|
3729
|
-
Object.freeze(obj);
|
|
3730
|
-
for (const key in obj) {
|
|
3731
|
-
if (Object.hasOwn(obj, key)) {
|
|
3732
|
-
const value = obj[key];
|
|
3733
|
-
if (value !== null && typeof value === "object") {
|
|
3734
|
-
deepFreeze3(value);
|
|
3735
|
-
}
|
|
3736
|
-
}
|
|
3737
|
-
}
|
|
3738
|
-
return obj;
|
|
3739
|
-
}
|
|
3740
|
-
async function ensureCatalogLoaded3() {
|
|
3741
|
-
if (catalogCache3 !== null) {
|
|
3742
|
-
return;
|
|
3743
|
-
}
|
|
3744
|
-
catalogCache3 = await loadMimeTypeCatalog();
|
|
3745
|
-
for (const mimeType of catalogCache3.types) {
|
|
3746
|
-
mimeStringIndex.set(mimeType.mime.toLowerCase(), mimeType);
|
|
3747
|
-
for (const ext of mimeType.extensions) {
|
|
3748
|
-
const normalized = ext.toLowerCase().replace(/^\./, "");
|
|
3749
|
-
extensionIndex.set(normalized, mimeType);
|
|
3750
|
-
}
|
|
3751
|
-
}
|
|
3752
|
-
detectorInstance = createDetector(mimeStringIndex);
|
|
3753
|
-
}
|
|
3754
|
-
async function getMimeType(mimeString) {
|
|
3755
|
-
await ensureCatalogLoaded3();
|
|
3756
|
-
const normalized = mimeString.toLowerCase();
|
|
3757
|
-
const mimeType = mimeStringIndex.get(normalized);
|
|
3758
|
-
return mimeType ? deepFreeze3(deepClone3(mimeType)) : null;
|
|
3759
|
-
}
|
|
3760
|
-
async function getMimeTypeByExtension(extension) {
|
|
3761
|
-
await ensureCatalogLoaded3();
|
|
3762
|
-
const normalized = extension.toLowerCase().replace(/^\./, "");
|
|
3763
|
-
const mimeType = extensionIndex.get(normalized);
|
|
3764
|
-
return mimeType ? deepFreeze3(deepClone3(mimeType)) : null;
|
|
3765
|
-
}
|
|
3766
|
-
async function isSupportedMimeType(mime) {
|
|
3767
|
-
await ensureCatalogLoaded3();
|
|
3768
|
-
return mimeStringIndex.has(mime.toLowerCase());
|
|
3769
|
-
}
|
|
3770
|
-
async function detectMimeType(input, options) {
|
|
3771
|
-
await ensureCatalogLoaded3();
|
|
3772
|
-
if (!detectorInstance) {
|
|
3773
|
-
throw new Error("Detector not initialized");
|
|
3774
|
-
}
|
|
3775
|
-
if (typeof input === "string") {
|
|
3776
|
-
return detectMimeTypeFromFile(input, options);
|
|
3777
|
-
}
|
|
3778
|
-
if (Buffer.isBuffer(input)) {
|
|
3779
|
-
return detectMimeTypeFromBuffer(input, options);
|
|
3780
|
-
}
|
|
3781
|
-
return detectMimeTypeFromStream(input, options);
|
|
3782
|
-
}
|
|
3783
|
-
async function detectMimeTypeFromFile(filePath, options = {}) {
|
|
3784
|
-
await ensureCatalogLoaded3();
|
|
3785
|
-
if (!detectorInstance) {
|
|
3786
|
-
throw new Error("Detector not initialized");
|
|
3787
|
-
}
|
|
3788
|
-
const bytesToRead = options.bytesToRead || 512;
|
|
3789
|
-
if (typeof Bun !== "undefined") {
|
|
3790
|
-
const file = Bun.file(filePath);
|
|
3791
|
-
if (!await file.exists()) {
|
|
3792
|
-
return null;
|
|
3793
|
-
}
|
|
3794
|
-
const slice = file.slice(0, bytesToRead);
|
|
3795
|
-
const arrayBuffer = await slice.arrayBuffer();
|
|
3796
|
-
const buffer = Buffer.from(arrayBuffer);
|
|
3797
|
-
return detectMimeTypeFromBuffer(buffer, options);
|
|
3798
|
-
}
|
|
3799
|
-
try {
|
|
3800
|
-
const buffer = await readFile(filePath, { encoding: null });
|
|
3801
|
-
const sample = buffer.subarray(0, Math.min(buffer.length, bytesToRead));
|
|
3802
|
-
return detectMimeTypeFromBuffer(sample, options);
|
|
3803
|
-
} catch (error) {
|
|
3804
|
-
if (error.code === "ENOENT") {
|
|
3805
|
-
return null;
|
|
3806
|
-
}
|
|
3807
|
-
throw error;
|
|
3808
|
-
}
|
|
3809
|
-
}
|
|
3810
|
-
function detectMimeTypeFromBuffer(buffer, options = {}) {
|
|
3811
|
-
if (!detectorInstance) {
|
|
3812
|
-
throw new Error("Detector not initialized");
|
|
3813
|
-
}
|
|
3814
|
-
const result = detectorInstance.detect(buffer, options);
|
|
3815
|
-
return result ? deepFreeze3(deepClone3(result)) : null;
|
|
3816
|
-
}
|
|
3817
|
-
async function detectMimeTypeFromStream(stream, options = {}) {
|
|
3818
|
-
await ensureCatalogLoaded3();
|
|
3819
|
-
const bytesToRead = options.bytesToRead || 512;
|
|
3820
|
-
const chunks = [];
|
|
3821
|
-
let totalBytes = 0;
|
|
3822
|
-
const webStream = typeof stream.getReader === "function" ? stream : Readable.toWeb(stream);
|
|
3823
|
-
const reader = webStream.getReader();
|
|
3824
|
-
try {
|
|
3825
|
-
while (totalBytes < bytesToRead) {
|
|
3826
|
-
const { value, done } = await reader.read();
|
|
3827
|
-
if (done) break;
|
|
3828
|
-
chunks.push(value);
|
|
3829
|
-
totalBytes += value.length;
|
|
3830
|
-
}
|
|
3831
|
-
const buffer = Buffer.concat(chunks.map((c) => Buffer.from(c)));
|
|
3832
|
-
const sample = buffer.subarray(0, Math.min(buffer.length, bytesToRead));
|
|
3833
|
-
return detectMimeTypeFromBuffer(sample, options);
|
|
3834
|
-
} finally {
|
|
3835
|
-
reader.releaseLock();
|
|
3836
|
-
}
|
|
3837
|
-
}
|
|
3838
|
-
function matchMagicNumber(buffer, mimeType) {
|
|
3839
|
-
if (!detectorInstance) {
|
|
3840
|
-
throw new Error("Detector not initialized");
|
|
3841
|
-
}
|
|
3842
|
-
const result = detectorInstance.detect(buffer);
|
|
3843
|
-
return result?.mime === mimeType;
|
|
3844
|
-
}
|
|
3845
|
-
async function listMimeTypes() {
|
|
3846
|
-
await ensureCatalogLoaded3();
|
|
3847
|
-
return Array.from(mimeStringIndex.values()).map((m) => deepFreeze3(deepClone3(m)));
|
|
3848
|
-
}
|
|
3849
|
-
function clearMimeTypeCache() {
|
|
3850
|
-
catalogCache3 = null;
|
|
3851
|
-
mimeStringIndex.clear();
|
|
3852
|
-
extensionIndex.clear();
|
|
3853
|
-
detectorInstance = null;
|
|
3854
|
-
}
|
|
3855
|
-
var catalogCache3, mimeStringIndex, extensionIndex, detectorInstance;
|
|
3856
|
-
var init_mime_types = __esm({
|
|
3857
|
-
"src/foundry/mime-types.ts"() {
|
|
3858
|
-
init_detector();
|
|
3859
|
-
init_loader();
|
|
3860
|
-
catalogCache3 = null;
|
|
3861
|
-
mimeStringIndex = /* @__PURE__ */ new Map();
|
|
3862
|
-
extensionIndex = /* @__PURE__ */ new Map();
|
|
3863
|
-
detectorInstance = null;
|
|
3864
|
-
}
|
|
3865
|
-
});
|
|
3866
|
-
function deepClone4(obj) {
|
|
3867
|
-
if (obj === null || typeof obj !== "object") {
|
|
3868
|
-
return obj;
|
|
3869
|
-
}
|
|
3870
|
-
if (Array.isArray(obj)) {
|
|
3871
|
-
return obj.map((item) => deepClone4(item));
|
|
3872
|
-
}
|
|
3873
|
-
const cloned = {};
|
|
3874
|
-
for (const key in obj) {
|
|
3875
|
-
if (Object.hasOwn(obj, key)) {
|
|
3876
|
-
cloned[key] = deepClone4(obj[key]);
|
|
3877
|
-
}
|
|
3878
|
-
}
|
|
3879
|
-
return cloned;
|
|
3880
|
-
}
|
|
3881
|
-
function deepFreeze4(obj) {
|
|
3882
|
-
Object.freeze(obj);
|
|
3883
|
-
for (const key in obj) {
|
|
3884
|
-
if (Object.hasOwn(obj, key)) {
|
|
3885
|
-
const value = obj[key];
|
|
3886
|
-
if (value !== null && typeof value === "object") {
|
|
3887
|
-
deepFreeze4(value);
|
|
3888
|
-
}
|
|
3889
|
-
}
|
|
3890
|
-
}
|
|
3891
|
-
return obj;
|
|
3892
|
-
}
|
|
3893
|
-
async function ensureCatalogLoaded4() {
|
|
3894
|
-
if (catalogCache4 !== null) {
|
|
3895
|
-
return;
|
|
3896
|
-
}
|
|
3897
|
-
catalogCache4 = await loadPatternCatalog();
|
|
3898
|
-
for (const pattern of catalogCache4.patterns) {
|
|
3899
|
-
patternIndex.set(pattern.id, pattern);
|
|
3900
|
-
}
|
|
3901
|
-
}
|
|
3902
|
-
async function getPattern(id) {
|
|
3903
|
-
await ensureCatalogLoaded4();
|
|
3904
|
-
const pattern = patternIndex.get(id);
|
|
3905
|
-
return pattern ? deepFreeze4(deepClone4(pattern)) : null;
|
|
3906
|
-
}
|
|
3907
|
-
async function getPatternRegex(id) {
|
|
3908
|
-
await ensureCatalogLoaded4();
|
|
3909
|
-
const pattern = patternIndex.get(id);
|
|
3910
|
-
if (!pattern) {
|
|
3911
|
-
return null;
|
|
3912
|
-
}
|
|
3913
|
-
if (pattern.kind !== "regex") {
|
|
3914
|
-
throw FoundryCatalogError.invalidSchema(
|
|
3915
|
-
"patterns",
|
|
3916
|
-
`Pattern '${id}' is not a regex pattern (kind: ${pattern.kind})`
|
|
3917
|
-
);
|
|
3918
|
-
}
|
|
3919
|
-
const cached = compiledRegexCache.get(id);
|
|
3920
|
-
if (cached !== void 0) {
|
|
3921
|
-
return cached;
|
|
3922
|
-
}
|
|
3923
|
-
let flags = "";
|
|
3924
|
-
if (pattern.flags?.typescript?.ignoreCase) {
|
|
3925
|
-
flags += "i";
|
|
3926
|
-
}
|
|
3927
|
-
const hasUnicodePropertyEscapes = /\\p\{/.test(pattern.pattern);
|
|
3928
|
-
if (pattern.flags?.typescript?.unicode || hasUnicodePropertyEscapes) {
|
|
3929
|
-
flags += "u";
|
|
3930
|
-
}
|
|
3931
|
-
const regex = new RegExp(pattern.pattern, flags);
|
|
3932
|
-
compiledRegexCache.set(id, regex);
|
|
3933
|
-
return regex;
|
|
3934
|
-
}
|
|
3935
|
-
function getCompiledGlob(id, pattern) {
|
|
3936
|
-
const cached = compiledGlobCache.get(id);
|
|
3937
|
-
if (cached !== void 0) {
|
|
3938
|
-
return cached;
|
|
3939
|
-
}
|
|
3940
|
-
const matcher = picomatch(pattern);
|
|
3941
|
-
compiledGlobCache.set(id, matcher);
|
|
3942
|
-
return matcher;
|
|
3943
|
-
}
|
|
3944
|
-
async function matchPattern(id, value) {
|
|
3945
|
-
await ensureCatalogLoaded4();
|
|
3946
|
-
const pattern = patternIndex.get(id);
|
|
3947
|
-
if (!pattern) {
|
|
3948
|
-
throw FoundryCatalogError.missingCatalog(`Pattern '${id}' not found`);
|
|
3949
|
-
}
|
|
3950
|
-
if (pattern.kind === "regex") {
|
|
3951
|
-
const regex = await getPatternRegex(id);
|
|
3952
|
-
return regex ? regex.test(value) : false;
|
|
3953
|
-
}
|
|
3954
|
-
if (pattern.kind === "glob") {
|
|
3955
|
-
const matcher = getCompiledGlob(id, pattern.pattern);
|
|
3956
|
-
return matcher(value);
|
|
3957
|
-
}
|
|
3958
|
-
if (pattern.kind === "literal") {
|
|
3959
|
-
return pattern.pattern === value;
|
|
3960
|
-
}
|
|
3961
|
-
throw FoundryCatalogError.invalidSchema("patterns", `Unknown pattern kind: ${pattern.kind}`);
|
|
3962
|
-
}
|
|
3963
|
-
async function listPatterns() {
|
|
3964
|
-
await ensureCatalogLoaded4();
|
|
3965
|
-
return Array.from(patternIndex.values()).map((p) => deepFreeze4(deepClone4(p)));
|
|
3966
|
-
}
|
|
3967
|
-
async function describePattern(id) {
|
|
3968
|
-
const pattern = await getPattern(id);
|
|
3969
|
-
return pattern?.description ?? null;
|
|
3970
|
-
}
|
|
3971
|
-
function clearPatternCache() {
|
|
3972
|
-
catalogCache4 = null;
|
|
3973
|
-
patternIndex.clear();
|
|
3974
|
-
compiledRegexCache.clear();
|
|
3975
|
-
compiledGlobCache.clear();
|
|
3976
|
-
}
|
|
3977
|
-
var catalogCache4, patternIndex, compiledRegexCache, compiledGlobCache;
|
|
3978
|
-
var init_patterns = __esm({
|
|
3979
|
-
"src/foundry/patterns.ts"() {
|
|
3980
|
-
init_errors3();
|
|
3981
|
-
init_loader();
|
|
3982
|
-
catalogCache4 = null;
|
|
3983
|
-
patternIndex = /* @__PURE__ */ new Map();
|
|
3984
|
-
compiledRegexCache = /* @__PURE__ */ new Map();
|
|
3985
|
-
compiledGlobCache = /* @__PURE__ */ new Map();
|
|
3986
|
-
}
|
|
3987
|
-
});
|
|
3988
|
-
function getConfigPath() {
|
|
3989
|
-
if (__dirname3.includes("/dist/")) {
|
|
3990
|
-
return join(__dirname3, "../../config/crucible-ts/library/foundry/signals.yaml");
|
|
3991
|
-
}
|
|
3992
|
-
return join(__dirname3, "../../../config/crucible-ts/library/foundry/signals.yaml");
|
|
3993
|
-
}
|
|
3994
|
-
async function loadCatalog2() {
|
|
3995
|
-
const filePath = SSOT_PATHS2.signals;
|
|
3996
|
-
const catalogName = "signals";
|
|
3997
|
-
try {
|
|
3998
|
-
let content;
|
|
3999
|
-
if (typeof Bun !== "undefined") {
|
|
4000
|
-
try {
|
|
4001
|
-
const file = Bun.file(filePath);
|
|
4002
|
-
if (!await file.exists()) {
|
|
4003
|
-
throw FoundryCatalogError.missingCatalog(catalogName);
|
|
4004
|
-
}
|
|
4005
|
-
content = await file.text();
|
|
4006
|
-
} catch (error) {
|
|
4007
|
-
if (error instanceof Error && error.message.includes("No such file")) {
|
|
4008
|
-
throw FoundryCatalogError.missingCatalog(catalogName);
|
|
4009
|
-
}
|
|
4010
|
-
throw error;
|
|
4011
|
-
}
|
|
4012
|
-
} else {
|
|
4013
|
-
try {
|
|
4014
|
-
content = await readFile(filePath, "utf-8");
|
|
4015
|
-
} catch (error) {
|
|
4016
|
-
if (error.code === "ENOENT") {
|
|
4017
|
-
throw FoundryCatalogError.missingCatalog(catalogName);
|
|
4018
|
-
}
|
|
4019
|
-
throw error;
|
|
4020
|
-
}
|
|
4021
|
-
}
|
|
4022
|
-
const data = parse(content);
|
|
4023
|
-
const result = await validateDataBySchemaId(data, SCHEMA_ID);
|
|
4024
|
-
if (!result.valid) {
|
|
4025
|
-
const errorMessages = result.diagnostics.map((d) => `${d.pointer}: ${d.message}`).join("; ");
|
|
4026
|
-
throw FoundryCatalogError.invalidSchema(
|
|
4027
|
-
catalogName,
|
|
4028
|
-
`Schema validation failed: ${errorMessages}`
|
|
4029
|
-
);
|
|
4030
|
-
}
|
|
4031
|
-
return data;
|
|
4032
|
-
} catch (error) {
|
|
4033
|
-
if (error instanceof FoundryCatalogError) {
|
|
4034
|
-
throw error;
|
|
4035
|
-
}
|
|
4036
|
-
const err = error;
|
|
4037
|
-
if (err.code === "ENOENT") {
|
|
4038
|
-
throw FoundryCatalogError.missingCatalog(catalogName);
|
|
4039
|
-
} else if (err.code === "EACCES") {
|
|
4040
|
-
throw FoundryCatalogError.invalidSchema(
|
|
4041
|
-
catalogName,
|
|
4042
|
-
"Permission denied accessing catalog file",
|
|
4043
|
-
err
|
|
4044
|
-
);
|
|
4045
|
-
} else if (err.code === "EISDIR") {
|
|
4046
|
-
throw FoundryCatalogError.invalidSchema(
|
|
4047
|
-
catalogName,
|
|
4048
|
-
"Expected file but found directory",
|
|
4049
|
-
err
|
|
4050
|
-
);
|
|
4051
|
-
} else if (err.code === "EMFILE" || err.code === "ENFILE") {
|
|
4052
|
-
throw FoundryCatalogError.invalidSchema(catalogName, "Too many open files", err);
|
|
4053
|
-
}
|
|
4054
|
-
throw FoundryCatalogError.invalidSchema(catalogName, "Failed to load catalog", err);
|
|
4055
|
-
}
|
|
4056
|
-
}
|
|
4057
|
-
async function getCatalog() {
|
|
4058
|
-
if (!cachedCatalog) {
|
|
4059
|
-
cachedCatalog = await loadCatalog2();
|
|
4060
|
-
}
|
|
4061
|
-
return cachedCatalog;
|
|
4062
|
-
}
|
|
4063
|
-
async function getSignalsVersion() {
|
|
4064
|
-
const catalog = await getCatalog();
|
|
4065
|
-
return catalog.version;
|
|
4066
|
-
}
|
|
4067
|
-
async function listSignals() {
|
|
4068
|
-
const catalog = await getCatalog();
|
|
4069
|
-
return catalog.signals.map((signal) => ({ ...signal }));
|
|
4070
|
-
}
|
|
4071
|
-
async function getSignal(identifier) {
|
|
4072
|
-
const catalog = await getCatalog();
|
|
4073
|
-
const signal = catalog.signals.find((s) => s.id === identifier || s.name === identifier);
|
|
4074
|
-
return signal ? { ...signal } : null;
|
|
4075
|
-
}
|
|
4076
|
-
async function listBehaviors() {
|
|
4077
|
-
const catalog = await getCatalog();
|
|
4078
|
-
return catalog.behaviors.map((behavior) => ({ ...behavior }));
|
|
4079
|
-
}
|
|
4080
|
-
async function getBehavior(id) {
|
|
4081
|
-
const catalog = await getCatalog();
|
|
4082
|
-
const behavior = catalog.behaviors.find((b) => b.id === id);
|
|
4083
|
-
return behavior ? { ...behavior } : null;
|
|
4084
|
-
}
|
|
4085
|
-
async function getSignalCatalog() {
|
|
4086
|
-
return await getCatalog();
|
|
4087
|
-
}
|
|
4088
|
-
var __filename2, __dirname3, SSOT_PATHS2, SCHEMA_ID, cachedCatalog;
|
|
4089
|
-
var init_catalog = __esm({
|
|
4090
|
-
"src/foundry/signals/catalog.ts"() {
|
|
4091
|
-
init_validator();
|
|
4092
|
-
init_errors3();
|
|
4093
|
-
__filename2 = fileURLToPath(import.meta.url);
|
|
4094
|
-
__dirname3 = dirname(__filename2);
|
|
4095
|
-
SSOT_PATHS2 = {
|
|
4096
|
-
signals: getConfigPath()
|
|
4097
|
-
};
|
|
4098
|
-
SCHEMA_ID = "library/foundry/v1.0.0/signals";
|
|
4099
|
-
cachedCatalog = null;
|
|
4100
|
-
}
|
|
4101
|
-
});
|
|
4102
|
-
|
|
4103
|
-
// src/foundry/signals/capabilities.ts
|
|
4104
|
-
function getPlatform2() {
|
|
4105
|
-
const platform = process.platform;
|
|
4106
|
-
switch (platform) {
|
|
4107
|
-
case "linux":
|
|
4108
|
-
return "linux";
|
|
4109
|
-
case "darwin":
|
|
4110
|
-
return "darwin";
|
|
4111
|
-
case "win32":
|
|
4112
|
-
return "win32";
|
|
4113
|
-
case "freebsd":
|
|
4114
|
-
return "freebsd";
|
|
4115
|
-
default:
|
|
4116
|
-
return "unknown";
|
|
4117
|
-
}
|
|
4118
|
-
}
|
|
4119
|
-
function isPOSIX2() {
|
|
4120
|
-
const platform = getPlatform2();
|
|
4121
|
-
return platform === "linux" || platform === "darwin" || platform === "freebsd";
|
|
4122
|
-
}
|
|
4123
|
-
function isWindows2() {
|
|
4124
|
-
return getPlatform2() === "win32";
|
|
4125
|
-
}
|
|
4126
|
-
async function supportsSignal(signalName) {
|
|
4127
|
-
const signal = await getSignal(signalName);
|
|
4128
|
-
if (!signal) {
|
|
4129
|
-
return false;
|
|
4130
|
-
}
|
|
4131
|
-
if (isPOSIX2()) {
|
|
4132
|
-
return true;
|
|
4133
|
-
}
|
|
4134
|
-
if (isWindows2()) {
|
|
4135
|
-
return signal.windows_event !== null;
|
|
4136
|
-
}
|
|
4137
|
-
return false;
|
|
4138
|
-
}
|
|
4139
|
-
function supportsSignalExitCodes2() {
|
|
4140
|
-
return isPOSIX2();
|
|
4141
|
-
}
|
|
4142
|
-
async function getPlatformCapabilities2() {
|
|
4143
|
-
const platform = getPlatform2();
|
|
4144
|
-
const isPosix = isPOSIX2();
|
|
4145
|
-
const isWin = isWindows2();
|
|
4146
|
-
const catalog = await getSignalCatalog();
|
|
4147
|
-
const supported = [];
|
|
4148
|
-
const unsupported = [];
|
|
4149
|
-
const mapped = [];
|
|
4150
|
-
for (const signal of catalog.signals) {
|
|
4151
|
-
if (isPosix) {
|
|
4152
|
-
supported.push(signal.name);
|
|
4153
|
-
} else if (isWin) {
|
|
4154
|
-
if (signal.windows_event !== null) {
|
|
4155
|
-
supported.push(signal.name);
|
|
4156
|
-
mapped.push(signal.name);
|
|
4157
|
-
} else {
|
|
4158
|
-
unsupported.push(signal.name);
|
|
4159
|
-
}
|
|
4160
|
-
} else {
|
|
4161
|
-
unsupported.push(signal.name);
|
|
4162
|
-
}
|
|
4163
|
-
}
|
|
4164
|
-
return {
|
|
4165
|
-
platform,
|
|
4166
|
-
isPOSIX: isPosix,
|
|
4167
|
-
isWindows: isWin,
|
|
4168
|
-
supportsNativeSignals: isPosix,
|
|
4169
|
-
supportsSignalExitCodes: supportsSignalExitCodes2(),
|
|
4170
|
-
supportedSignals: supported,
|
|
4171
|
-
unsupportedSignals: unsupported,
|
|
4172
|
-
mappedSignals: mapped
|
|
4173
|
-
};
|
|
4174
|
-
}
|
|
4175
|
-
async function getSignalNumber(signalName) {
|
|
4176
|
-
const signal = await getSignal(signalName);
|
|
4177
|
-
if (!signal) {
|
|
4178
|
-
return null;
|
|
4179
|
-
}
|
|
4180
|
-
const platform = getPlatform2();
|
|
4181
|
-
if (signal.platform_overrides) {
|
|
4182
|
-
if (platform === "darwin" && signal.platform_overrides.darwin !== void 0) {
|
|
4183
|
-
return signal.platform_overrides.darwin;
|
|
4184
|
-
}
|
|
4185
|
-
if (platform === "freebsd" && signal.platform_overrides.freebsd !== void 0) {
|
|
4186
|
-
return signal.platform_overrides.freebsd;
|
|
4187
|
-
}
|
|
4188
|
-
}
|
|
4189
|
-
return signal.unix_number;
|
|
4190
|
-
}
|
|
4191
|
-
async function getWindowsEvent(signalName) {
|
|
4192
|
-
const signal = await getSignal(signalName);
|
|
4193
|
-
if (!signal) {
|
|
4194
|
-
return null;
|
|
4195
|
-
}
|
|
4196
|
-
return signal.windows_event;
|
|
4197
|
-
}
|
|
4198
|
-
var init_capabilities2 = __esm({
|
|
4199
|
-
"src/foundry/signals/capabilities.ts"() {
|
|
4200
|
-
init_catalog();
|
|
4201
|
-
}
|
|
4202
|
-
});
|
|
4203
|
-
|
|
4204
|
-
// src/foundry/signals/config-reload-endpoint.ts
|
|
4205
|
-
function createConfigReloadEndpoint(options) {
|
|
4206
|
-
const { loader, validator, onReload: onReload2, auth, rateLimit, logger, telemetry } = options;
|
|
4207
|
-
return async (payload, req) => {
|
|
4208
|
-
const correlationId = payload.correlation_id ?? generateCorrelationId2();
|
|
4209
|
-
const authResult = await auth(req);
|
|
4210
|
-
if (!authResult.authenticated) {
|
|
4211
|
-
if (logger) {
|
|
4212
|
-
logger.warn("Config reload endpoint: authentication failed", {
|
|
4213
|
-
correlation_id: correlationId,
|
|
4214
|
-
reason: authResult.reason
|
|
4215
|
-
});
|
|
4216
|
-
}
|
|
4217
|
-
if (telemetry) {
|
|
4218
|
-
telemetry.emit("fulmen.config.http_endpoint.auth_failed", {
|
|
4219
|
-
correlation_id: correlationId
|
|
4220
|
-
});
|
|
4221
|
-
}
|
|
4222
|
-
return {
|
|
4223
|
-
status: "error",
|
|
4224
|
-
error: "authentication_failed",
|
|
4225
|
-
message: authResult.reason || "Authentication required",
|
|
4226
|
-
statusCode: 401
|
|
4227
|
-
};
|
|
4228
|
-
}
|
|
4229
|
-
const identity = authResult.identity || "unknown";
|
|
4230
|
-
if (rateLimit) {
|
|
4231
|
-
const rateLimitResult = await rateLimit(identity);
|
|
4232
|
-
if (!rateLimitResult.allowed) {
|
|
4233
|
-
if (logger) {
|
|
4234
|
-
logger.warn("Config reload endpoint: rate limit exceeded", {
|
|
4235
|
-
correlation_id: correlationId,
|
|
4236
|
-
identity
|
|
4237
|
-
});
|
|
4238
|
-
}
|
|
4239
|
-
if (telemetry) {
|
|
4240
|
-
telemetry.emit("fulmen.config.http_endpoint.rate_limited", {
|
|
4241
|
-
correlation_id: correlationId
|
|
4242
|
-
});
|
|
4243
|
-
}
|
|
4244
|
-
return {
|
|
4245
|
-
status: "error",
|
|
4246
|
-
error: "rate_limit_exceeded",
|
|
4247
|
-
message: "Rate limit exceeded. Please try again later.",
|
|
4248
|
-
statusCode: 429
|
|
4249
|
-
};
|
|
4250
|
-
}
|
|
4251
|
-
}
|
|
4252
|
-
if (telemetry) {
|
|
4253
|
-
telemetry.emit("fulmen.config.http_endpoint.reload_requested", {
|
|
4254
|
-
correlation_id: correlationId
|
|
4255
|
-
});
|
|
4256
|
-
}
|
|
4257
|
-
try {
|
|
4258
|
-
const config = await loader();
|
|
4259
|
-
if (validator) {
|
|
4260
|
-
const validation = await validator(config);
|
|
4261
|
-
if (!validation.valid) {
|
|
4262
|
-
if (logger) {
|
|
4263
|
-
logger.warn("Config reload endpoint: validation failed", {
|
|
4264
|
-
correlation_id: correlationId,
|
|
4265
|
-
error_count: validation.errors?.length ?? 0
|
|
4266
|
-
});
|
|
4267
|
-
}
|
|
4268
|
-
if (telemetry) {
|
|
4269
|
-
telemetry.emit("fulmen.config.http_endpoint.reload_rejected", {
|
|
4270
|
-
correlation_id: correlationId,
|
|
4271
|
-
reason: "validation_failed"
|
|
4272
|
-
});
|
|
4273
|
-
}
|
|
4274
|
-
return {
|
|
4275
|
-
status: "error",
|
|
4276
|
-
error: "validation_failed",
|
|
4277
|
-
message: "Configuration validation failed",
|
|
4278
|
-
validation_errors: validation.errors,
|
|
4279
|
-
statusCode: 422
|
|
4280
|
-
};
|
|
4281
|
-
}
|
|
4282
|
-
}
|
|
4283
|
-
if (onReload2) {
|
|
4284
|
-
await onReload2(config);
|
|
4285
|
-
}
|
|
4286
|
-
if (telemetry) {
|
|
4287
|
-
telemetry.emit("fulmen.config.http_endpoint.reload_accepted", {
|
|
4288
|
-
correlation_id: correlationId
|
|
4289
|
-
});
|
|
4290
|
-
}
|
|
4291
|
-
if (logger) {
|
|
4292
|
-
logger.info("Config reload endpoint: reload accepted", {
|
|
4293
|
-
correlation_id: correlationId,
|
|
4294
|
-
reason: payload.reason
|
|
4295
|
-
});
|
|
4296
|
-
}
|
|
4297
|
-
return {
|
|
4298
|
-
status: "reloaded",
|
|
4299
|
-
correlation_id: correlationId,
|
|
4300
|
-
message: "Configuration reloaded",
|
|
4301
|
-
statusCode: 200
|
|
4302
|
-
};
|
|
4303
|
-
} catch (error) {
|
|
4304
|
-
if (logger) {
|
|
4305
|
-
logger.warn("Config reload endpoint: reload failed", {
|
|
4306
|
-
correlation_id: correlationId,
|
|
4307
|
-
error: error instanceof Error ? error.message : String(error)
|
|
4308
|
-
});
|
|
4309
|
-
}
|
|
4310
|
-
if (telemetry) {
|
|
4311
|
-
telemetry.emit("fulmen.config.http_endpoint.reload_error", {
|
|
4312
|
-
correlation_id: correlationId,
|
|
4313
|
-
error_type: error instanceof Error ? error.constructor.name : "unknown"
|
|
4314
|
-
});
|
|
4315
|
-
}
|
|
4316
|
-
return {
|
|
4317
|
-
status: "error",
|
|
4318
|
-
error: "reload_failed",
|
|
4319
|
-
message: error instanceof Error ? error.message : String(error),
|
|
4320
|
-
statusCode: 500
|
|
4321
|
-
};
|
|
4322
|
-
}
|
|
4323
|
-
};
|
|
4324
|
-
}
|
|
4325
|
-
function generateCorrelationId2() {
|
|
4326
|
-
return `cfg-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
4327
|
-
}
|
|
4328
|
-
var init_config_reload_endpoint = __esm({
|
|
4329
|
-
"src/foundry/signals/config-reload-endpoint.ts"() {
|
|
4330
|
-
}
|
|
4331
|
-
});
|
|
4332
|
-
|
|
4333
|
-
// src/appidentity/runtime.ts
|
|
4334
|
-
function detectRuntime() {
|
|
4335
|
-
const versions = process.versions;
|
|
4336
|
-
if (typeof versions.bun === "string" && versions.bun.length > 0) {
|
|
4337
|
-
return { name: "bun", version: versions.bun };
|
|
4338
|
-
}
|
|
4339
|
-
if (typeof versions.node === "string" && versions.node.length > 0) {
|
|
4340
|
-
return { name: "node", version: versions.node };
|
|
4341
|
-
}
|
|
4342
|
-
return { name: "unknown" };
|
|
4343
|
-
}
|
|
4344
|
-
function buildRuntimeInfo(options = {}) {
|
|
4345
|
-
const runtime = detectRuntime();
|
|
4346
|
-
const serviceName = options.serviceName ?? options.identity?.app.binary_name ?? "unknown-service";
|
|
4347
|
-
const vendor = options.vendor ?? options.identity?.app.vendor;
|
|
4348
|
-
return {
|
|
4349
|
-
service: {
|
|
4350
|
-
name: serviceName,
|
|
4351
|
-
vendor,
|
|
4352
|
-
version: options.version
|
|
4353
|
-
},
|
|
4354
|
-
runtime,
|
|
4355
|
-
platform: {
|
|
4356
|
-
os: process.platform,
|
|
4357
|
-
arch: process.arch
|
|
4358
|
-
}
|
|
4359
|
-
};
|
|
4360
|
-
}
|
|
4361
|
-
var init_runtime = __esm({
|
|
4362
|
-
"src/appidentity/runtime.ts"() {
|
|
4363
|
-
}
|
|
4364
|
-
});
|
|
4365
|
-
|
|
4366
|
-
// src/foundry/signals/control-discovery-endpoint.ts
|
|
4367
|
-
function createControlDiscoveryEndpoint(options) {
|
|
4368
|
-
const { identity, version, endpoints, auth, authSummary, logger, telemetry } = options;
|
|
4369
|
-
return async (req) => {
|
|
4370
|
-
if (auth) {
|
|
4371
|
-
const authResult = await auth(req);
|
|
4372
|
-
if (!authResult.authenticated) {
|
|
4373
|
-
if (logger) {
|
|
4374
|
-
logger.warn("Control discovery endpoint: authentication failed", {
|
|
4375
|
-
reason: authResult.reason
|
|
4376
|
-
});
|
|
4377
|
-
}
|
|
4378
|
-
if (telemetry) {
|
|
4379
|
-
telemetry.emit("fulmen.control.discovery.auth_failed", {
|
|
4380
|
-
service: identity.app.binary_name
|
|
4381
|
-
});
|
|
4382
|
-
}
|
|
4383
|
-
return {
|
|
4384
|
-
status: "error",
|
|
4385
|
-
error: "authentication_failed",
|
|
4386
|
-
message: authResult.reason || "Authentication required",
|
|
4387
|
-
statusCode: 401
|
|
4388
|
-
};
|
|
4389
|
-
}
|
|
4390
|
-
}
|
|
4391
|
-
if (telemetry) {
|
|
4392
|
-
telemetry.emit("fulmen.control.discovery.served", {
|
|
4393
|
-
service: identity.app.binary_name
|
|
4394
|
-
});
|
|
4395
|
-
}
|
|
4396
|
-
const runtime = buildRuntimeInfo({ identity, version });
|
|
4397
|
-
return {
|
|
4398
|
-
status: "ok",
|
|
4399
|
-
service: {
|
|
4400
|
-
name: identity.app.binary_name,
|
|
4401
|
-
vendor: identity.app.vendor,
|
|
4402
|
-
version
|
|
4403
|
-
},
|
|
4404
|
-
runtime: {
|
|
4405
|
-
name: runtime.runtime.name,
|
|
4406
|
-
version: runtime.runtime.version,
|
|
4407
|
-
platform: runtime.platform.os,
|
|
4408
|
-
arch: runtime.platform.arch
|
|
4409
|
-
},
|
|
4410
|
-
auth_summary: authSummary,
|
|
4411
|
-
endpoints,
|
|
4412
|
-
statusCode: 200
|
|
4413
|
-
};
|
|
4414
|
-
};
|
|
4415
|
-
}
|
|
4416
|
-
var init_control_discovery_endpoint = __esm({
|
|
4417
|
-
"src/foundry/signals/control-discovery-endpoint.ts"() {
|
|
4418
|
-
init_runtime();
|
|
4419
|
-
}
|
|
4420
|
-
});
|
|
4421
|
-
|
|
4422
|
-
// src/foundry/signals/convenience.ts
|
|
4423
|
-
async function onShutdown(manager, handler, options = {}) {
|
|
4424
|
-
await manager.register("SIGTERM", handler, options);
|
|
4425
|
-
await manager.register("SIGINT", handler, options);
|
|
4426
|
-
}
|
|
4427
|
-
async function onReload(manager, handler, options = {}) {
|
|
4428
|
-
await manager.register("SIGHUP", handler, options);
|
|
4429
|
-
}
|
|
4430
|
-
async function onUSR1(manager, handler, options = {}) {
|
|
4431
|
-
await manager.register("SIGUSR1", handler, options);
|
|
4432
|
-
}
|
|
4433
|
-
async function onUSR2(manager, handler, options = {}) {
|
|
4434
|
-
await manager.register("SIGUSR2", handler, options);
|
|
4435
|
-
}
|
|
4436
|
-
async function onEmergencyQuit(manager, handler, options = {}) {
|
|
4437
|
-
await manager.register("SIGQUIT", handler, options);
|
|
4438
|
-
}
|
|
4439
|
-
async function onAnyShutdown(manager, handler, options = {}) {
|
|
4440
|
-
await manager.register("SIGTERM", handler, options);
|
|
4441
|
-
await manager.register("SIGINT", handler, options);
|
|
4442
|
-
await manager.register("SIGQUIT", handler, options);
|
|
4443
|
-
}
|
|
4444
|
-
var init_convenience = __esm({
|
|
4445
|
-
"src/foundry/signals/convenience.ts"() {
|
|
4446
|
-
}
|
|
4447
|
-
});
|
|
4448
|
-
|
|
4449
|
-
// src/foundry/signals/double-tap.ts
|
|
4450
|
-
async function createDoubleTapTracker(signalName, config = {}) {
|
|
4451
|
-
const signal = await getSignal(signalName);
|
|
4452
|
-
const defaultWindowMs = signal?.double_tap_window_seconds ? signal.double_tap_window_seconds * 1e3 : 2e3;
|
|
4453
|
-
const defaultExitCode = signal?.double_tap_exit_code || 130;
|
|
4454
|
-
const defaultHintMessage = signal?.double_tap_message || "Press Ctrl+C again within 2s to force quit";
|
|
4455
|
-
return {
|
|
4456
|
-
firstTapTime: null,
|
|
4457
|
-
windowMs: config.windowMs ?? defaultWindowMs,
|
|
4458
|
-
exitCode: config.exitCode ?? defaultExitCode,
|
|
4459
|
-
hintMessage: config.hintMessage ?? defaultHintMessage,
|
|
4460
|
-
logger: config.logger,
|
|
4461
|
-
testMode: config.testMode ?? false
|
|
4462
|
-
};
|
|
4463
|
-
}
|
|
4464
|
-
function handleDoubleTap(state) {
|
|
4465
|
-
const now = Date.now();
|
|
4466
|
-
if (state.firstTapTime === null) {
|
|
4467
|
-
state.firstTapTime = now;
|
|
4468
|
-
if (state.logger) {
|
|
4469
|
-
state.logger.info(state.hintMessage);
|
|
4470
|
-
} else {
|
|
4471
|
-
console.log(state.hintMessage);
|
|
4472
|
-
}
|
|
4473
|
-
return false;
|
|
4474
|
-
}
|
|
4475
|
-
const elapsed = now - state.firstTapTime;
|
|
4476
|
-
if (elapsed < state.windowMs) {
|
|
4477
|
-
if (state.logger) {
|
|
4478
|
-
state.logger.info("Force quitting...");
|
|
4479
|
-
} else {
|
|
4480
|
-
console.log("Force quitting...");
|
|
4481
|
-
}
|
|
4482
|
-
if (!state.testMode) {
|
|
4483
|
-
process.exit(state.exitCode);
|
|
4484
|
-
}
|
|
4485
|
-
return true;
|
|
4486
|
-
}
|
|
4487
|
-
state.firstTapTime = now;
|
|
4488
|
-
if (state.logger) {
|
|
4489
|
-
state.logger.info(state.hintMessage);
|
|
4490
|
-
} else {
|
|
4491
|
-
console.log(state.hintMessage);
|
|
4492
|
-
}
|
|
4493
|
-
return false;
|
|
4494
|
-
}
|
|
4495
|
-
function resetDoubleTap(state) {
|
|
4496
|
-
state.firstTapTime = null;
|
|
4497
|
-
}
|
|
4498
|
-
function isWithinWindow(state) {
|
|
4499
|
-
if (state.firstTapTime === null) {
|
|
4500
|
-
return false;
|
|
4501
|
-
}
|
|
4502
|
-
const elapsed = Date.now() - state.firstTapTime;
|
|
4503
|
-
return elapsed < state.windowMs;
|
|
4504
|
-
}
|
|
4505
|
-
function getWindowTimeRemaining(state) {
|
|
4506
|
-
if (state.firstTapTime === null) {
|
|
4507
|
-
return null;
|
|
4508
|
-
}
|
|
4509
|
-
const elapsed = Date.now() - state.firstTapTime;
|
|
4510
|
-
const remaining = state.windowMs - elapsed;
|
|
4511
|
-
return remaining > 0 ? remaining : null;
|
|
4512
|
-
}
|
|
4513
|
-
var init_double_tap = __esm({
|
|
4514
|
-
"src/foundry/signals/double-tap.ts"() {
|
|
4515
|
-
init_catalog();
|
|
4516
|
-
}
|
|
4517
|
-
});
|
|
4518
|
-
|
|
4519
|
-
// src/foundry/signals/windows.ts
|
|
4520
|
-
async function handleWindowsFallback(signalName, options = {}) {
|
|
4521
|
-
const signal = await getSignal(signalName);
|
|
4522
|
-
if (!signal) {
|
|
4523
|
-
return {
|
|
4524
|
-
supported: false,
|
|
4525
|
-
logged: false
|
|
4526
|
-
};
|
|
4527
|
-
}
|
|
4528
|
-
if (signal.windows_event !== null) {
|
|
4529
|
-
return {
|
|
4530
|
-
supported: true,
|
|
4531
|
-
logged: false
|
|
4532
|
-
};
|
|
4533
|
-
}
|
|
4534
|
-
const fallback = signal.windows_fallback;
|
|
4535
|
-
if (!fallback) {
|
|
4536
|
-
return {
|
|
4537
|
-
supported: false,
|
|
4538
|
-
logged: false
|
|
4539
|
-
};
|
|
4540
|
-
}
|
|
4541
|
-
if (options.silent) {
|
|
4542
|
-
return {
|
|
4543
|
-
supported: false,
|
|
4544
|
-
fallback,
|
|
4545
|
-
logged: false
|
|
4546
|
-
};
|
|
4547
|
-
}
|
|
4548
|
-
const logger = options.logger || defaultLogger;
|
|
4549
|
-
const telemetry = options.telemetry;
|
|
4550
|
-
const logMeta = {
|
|
4551
|
-
signal: signal.name,
|
|
4552
|
-
platform: "windows",
|
|
4553
|
-
fallback: fallback.fallback_behavior,
|
|
4554
|
-
operation_hint: fallback.operation_hint
|
|
4555
|
-
};
|
|
4556
|
-
logger.info(fallback.log_message, logMeta);
|
|
4557
|
-
if (telemetry) {
|
|
4558
|
-
telemetry.emit(fallback.telemetry_event, fallback.telemetry_tags);
|
|
4559
|
-
}
|
|
4560
|
-
return {
|
|
4561
|
-
supported: false,
|
|
4562
|
-
fallback,
|
|
4563
|
-
logged: true
|
|
4564
|
-
};
|
|
4565
|
-
}
|
|
4566
|
-
async function getFallbackMetadata(signalName) {
|
|
4567
|
-
const signal = await getSignal(signalName);
|
|
4568
|
-
if (!signal || !signal.windows_fallback) {
|
|
4569
|
-
return null;
|
|
4570
|
-
}
|
|
4571
|
-
return signal.windows_fallback;
|
|
4572
|
-
}
|
|
4573
|
-
async function requiresFallback(signalName) {
|
|
4574
|
-
const signal = await getSignal(signalName);
|
|
4575
|
-
if (!signal) {
|
|
4576
|
-
return false;
|
|
4577
|
-
}
|
|
4578
|
-
return signal.windows_event === null && signal.windows_fallback !== void 0;
|
|
4579
|
-
}
|
|
4580
|
-
async function getHttpFallbackGuidance(signalName) {
|
|
4581
|
-
const fallback = await getFallbackMetadata(signalName);
|
|
4582
|
-
if (!fallback || fallback.fallback_behavior !== "http_admin_endpoint") {
|
|
4583
|
-
return null;
|
|
4584
|
-
}
|
|
4585
|
-
return fallback.operation_hint;
|
|
4586
|
-
}
|
|
4587
|
-
var defaultLogger;
|
|
4588
|
-
var init_windows = __esm({
|
|
4589
|
-
"src/foundry/signals/windows.ts"() {
|
|
4590
|
-
init_catalog();
|
|
4591
|
-
defaultLogger = {
|
|
4592
|
-
info(message, meta) {
|
|
4593
|
-
if (meta) {
|
|
4594
|
-
console.info(message, meta);
|
|
4595
|
-
} else {
|
|
4596
|
-
console.info(message);
|
|
4597
|
-
}
|
|
4598
|
-
},
|
|
4599
|
-
warn(message, meta) {
|
|
4600
|
-
if (meta) {
|
|
4601
|
-
console.warn(message, meta);
|
|
4602
|
-
} else {
|
|
4603
|
-
console.warn(message);
|
|
4604
|
-
}
|
|
4605
|
-
}
|
|
4606
|
-
};
|
|
4607
|
-
}
|
|
4608
|
-
});
|
|
4609
|
-
|
|
4610
|
-
// src/foundry/signals/guards.ts
|
|
4611
|
-
async function ensureSupported(signalName, options = {}) {
|
|
4612
|
-
const { includeGuidance = true } = options;
|
|
4613
|
-
const signal = await getSignal(signalName);
|
|
4614
|
-
if (!signal) {
|
|
4615
|
-
throw FoundryCatalogError.invalidSchema(
|
|
4616
|
-
"signals",
|
|
4617
|
-
`Signal "${signalName}" not found in catalog. Valid signals: SIGTERM, SIGINT, SIGHUP, SIGQUIT, SIGPIPE, SIGALRM, SIGUSR1, SIGUSR2`
|
|
4618
|
-
);
|
|
4619
|
-
}
|
|
4620
|
-
const supported = await supportsSignal(signalName);
|
|
4621
|
-
if (supported) {
|
|
4622
|
-
return;
|
|
4623
|
-
}
|
|
4624
|
-
let message = `Signal ${signal.name} is not supported on this platform`;
|
|
4625
|
-
if (isWindows2() && includeGuidance) {
|
|
4626
|
-
const fallback = await getFallbackMetadata(signalName);
|
|
4627
|
-
if (fallback) {
|
|
4628
|
-
message += `. ${fallback.log_message}`;
|
|
4629
|
-
switch (fallback.fallback_behavior) {
|
|
4630
|
-
case "http_admin_endpoint":
|
|
4631
|
-
message += `. Use HTTP endpoint: ${fallback.operation_hint}`;
|
|
4632
|
-
break;
|
|
4633
|
-
case "exception_handling":
|
|
4634
|
-
message += `. Alternative: ${fallback.operation_hint}`;
|
|
4635
|
-
break;
|
|
4636
|
-
case "timer_api":
|
|
4637
|
-
message += `. Alternative: ${fallback.operation_hint}`;
|
|
4638
|
-
break;
|
|
4639
|
-
}
|
|
4640
|
-
}
|
|
4641
|
-
}
|
|
4642
|
-
throw FoundryCatalogError.invalidSchema("signals", message);
|
|
4643
|
-
}
|
|
4644
|
-
function ensureSignalExitCodesSupported() {
|
|
4645
|
-
if (!isPOSIX2()) {
|
|
4646
|
-
throw FoundryCatalogError.invalidSchema(
|
|
4647
|
-
"signals",
|
|
4648
|
-
"Signal-based exit codes (128+N pattern) are not supported on this platform. Windows does not propagate signal numbers via exit codes. Use explicit exit codes or monitor via HTTP admin endpoint."
|
|
4649
|
-
);
|
|
4650
|
-
}
|
|
4651
|
-
}
|
|
4652
|
-
function ensurePOSIX() {
|
|
4653
|
-
if (!isPOSIX2()) {
|
|
4654
|
-
throw FoundryCatalogError.invalidSchema(
|
|
4655
|
-
"signals",
|
|
4656
|
-
"This operation requires a POSIX-compliant platform (Linux, macOS, FreeBSD). Current platform does not support native signal handling."
|
|
4657
|
-
);
|
|
4658
|
-
}
|
|
4659
|
-
}
|
|
4660
|
-
function ensureWindows() {
|
|
4661
|
-
if (!isWindows2()) {
|
|
4662
|
-
throw FoundryCatalogError.invalidSchema(
|
|
4663
|
-
"signals",
|
|
4664
|
-
"This operation requires Windows platform. Current platform uses native signals."
|
|
4665
|
-
);
|
|
4666
|
-
}
|
|
4667
|
-
}
|
|
4668
|
-
var init_guards = __esm({
|
|
4669
|
-
"src/foundry/signals/guards.ts"() {
|
|
4670
|
-
init_errors3();
|
|
4671
|
-
init_capabilities2();
|
|
4672
|
-
init_catalog();
|
|
4673
|
-
init_windows();
|
|
4674
|
-
}
|
|
4675
|
-
});
|
|
4676
|
-
|
|
4677
|
-
// src/foundry/signals/http-helper.ts
|
|
4678
|
-
function createSignalEndpoint(options) {
|
|
4679
|
-
const { manager, auth, rateLimit, logger, telemetry, allowedSignals } = options;
|
|
4680
|
-
return async (payload, req) => {
|
|
4681
|
-
const correlationId = payload.correlation_id ?? generateCorrelationId3();
|
|
4682
|
-
const authResult = await auth(req);
|
|
4683
|
-
if (!authResult.authenticated) {
|
|
4684
|
-
if (logger) {
|
|
4685
|
-
logger.warn("Signal endpoint: authentication failed", {
|
|
4686
|
-
correlation_id: correlationId,
|
|
4687
|
-
reason: authResult.reason
|
|
4688
|
-
});
|
|
4689
|
-
}
|
|
4690
|
-
if (telemetry) {
|
|
4691
|
-
telemetry.emit("fulmen.signal.http_endpoint.auth_failed", {
|
|
4692
|
-
correlation_id: correlationId
|
|
4693
|
-
});
|
|
4694
|
-
}
|
|
4695
|
-
return {
|
|
4696
|
-
status: "error",
|
|
4697
|
-
error: "authentication_failed",
|
|
4698
|
-
message: authResult.reason || "Authentication required",
|
|
4699
|
-
statusCode: 401
|
|
4700
|
-
};
|
|
4701
|
-
}
|
|
4702
|
-
const identity = authResult.identity || "unknown";
|
|
4703
|
-
if (!payload.signal) {
|
|
4704
|
-
return {
|
|
4705
|
-
status: "error",
|
|
4706
|
-
error: "invalid_request",
|
|
4707
|
-
message: "Signal name is required",
|
|
4708
|
-
statusCode: 400
|
|
4709
|
-
};
|
|
4710
|
-
}
|
|
4711
|
-
const signalName = normalizeSignalName(payload.signal);
|
|
4712
|
-
const defaultAllowed = [
|
|
4713
|
-
"SIGHUP",
|
|
4714
|
-
"SIGTERM",
|
|
4715
|
-
"SIGINT",
|
|
4716
|
-
"SIGQUIT",
|
|
4717
|
-
"SIGUSR1",
|
|
4718
|
-
"SIGUSR2",
|
|
4719
|
-
"SIGPIPE",
|
|
4720
|
-
"SIGALRM"
|
|
4721
|
-
];
|
|
4722
|
-
const allowed = (allowedSignals || defaultAllowed).map((s) => normalizeSignalName(s));
|
|
4723
|
-
if (!allowed.includes(signalName)) {
|
|
4724
|
-
return {
|
|
4725
|
-
status: "error",
|
|
4726
|
-
error: "invalid_signal",
|
|
4727
|
-
message: `Signal '${payload.signal}' is not recognized. Valid signals: ${allowed.join(", ")}`,
|
|
4728
|
-
valid_signals: allowed,
|
|
4729
|
-
statusCode: 400
|
|
4730
|
-
};
|
|
4731
|
-
}
|
|
4732
|
-
const supported = await supportsSignal(signalName);
|
|
4733
|
-
if (!supported) {
|
|
4734
|
-
return {
|
|
4735
|
-
status: "error",
|
|
4736
|
-
error: "signal_not_supported",
|
|
4737
|
-
message: `Signal ${signalName} is not supported on this platform`,
|
|
4738
|
-
statusCode: 400
|
|
4739
|
-
};
|
|
4740
|
-
}
|
|
4741
|
-
if (rateLimit) {
|
|
4742
|
-
const rateLimitResult = await rateLimit(identity, signalName);
|
|
4743
|
-
if (!rateLimitResult.allowed) {
|
|
4744
|
-
if (logger) {
|
|
4745
|
-
logger.warn("Signal endpoint: rate limit exceeded", {
|
|
4746
|
-
correlation_id: correlationId,
|
|
4747
|
-
identity,
|
|
4748
|
-
signal: signalName
|
|
4749
|
-
});
|
|
4750
|
-
}
|
|
4751
|
-
if (telemetry) {
|
|
4752
|
-
telemetry.emit("fulmen.signal.http_endpoint.rate_limited", {
|
|
4753
|
-
correlation_id: correlationId,
|
|
4754
|
-
signal: signalName
|
|
4755
|
-
});
|
|
4756
|
-
}
|
|
4757
|
-
return {
|
|
4758
|
-
status: "error",
|
|
4759
|
-
error: "rate_limit_exceeded",
|
|
4760
|
-
message: "Rate limit exceeded. Please try again later.",
|
|
4761
|
-
statusCode: 429
|
|
4762
|
-
};
|
|
4763
|
-
}
|
|
4764
|
-
}
|
|
4765
|
-
if (logger) {
|
|
4766
|
-
logger.info("Signal endpoint: signal received", {
|
|
4767
|
-
correlation_id: correlationId,
|
|
4768
|
-
identity,
|
|
4769
|
-
signal: signalName,
|
|
4770
|
-
reason: payload.reason
|
|
4771
|
-
});
|
|
4772
|
-
}
|
|
4773
|
-
if (telemetry) {
|
|
4774
|
-
telemetry.emit("fulmen.signal.http_endpoint.signal_received", {
|
|
4775
|
-
correlation_id: correlationId,
|
|
4776
|
-
signal: signalName
|
|
4777
|
-
});
|
|
4778
|
-
}
|
|
4779
|
-
void manager.trigger(signalName).catch((error) => {
|
|
4780
|
-
if (logger) {
|
|
4781
|
-
logger.warn("Signal handler execution failed", {
|
|
4782
|
-
correlation_id: correlationId,
|
|
4783
|
-
signal: signalName,
|
|
4784
|
-
error: error instanceof Error ? error.message : String(error)
|
|
4785
|
-
});
|
|
4786
|
-
}
|
|
4787
|
-
});
|
|
4788
|
-
return {
|
|
4789
|
-
status: "accepted",
|
|
4790
|
-
signal: signalName,
|
|
4791
|
-
correlation_id: correlationId,
|
|
4792
|
-
message: "Signal will be processed asynchronously",
|
|
4793
|
-
statusCode: 202
|
|
4794
|
-
};
|
|
4795
|
-
};
|
|
4796
|
-
}
|
|
4797
|
-
function normalizeSignalName(signal) {
|
|
4798
|
-
const upper = signal.toUpperCase();
|
|
4799
|
-
if (upper.startsWith("SIG")) {
|
|
4800
|
-
return upper;
|
|
4801
|
-
}
|
|
4802
|
-
return `SIG${upper}`;
|
|
4803
|
-
}
|
|
4804
|
-
function generateCorrelationId3() {
|
|
4805
|
-
return `sig-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
4806
|
-
}
|
|
4807
|
-
function createBearerTokenAuth(expectedToken) {
|
|
4808
|
-
return (req) => {
|
|
4809
|
-
const headers = req.headers;
|
|
4810
|
-
const authHeader = headers?.authorization || headers?.Authorization;
|
|
4811
|
-
if (!authHeader) {
|
|
4812
|
-
return {
|
|
4813
|
-
authenticated: false,
|
|
4814
|
-
reason: "Missing Authorization header"
|
|
4815
|
-
};
|
|
4816
|
-
}
|
|
4817
|
-
const [scheme, token] = authHeader.split(" ");
|
|
4818
|
-
if (scheme !== "Bearer" || token !== expectedToken) {
|
|
4819
|
-
return {
|
|
4820
|
-
authenticated: false,
|
|
4821
|
-
reason: "Invalid bearer token"
|
|
4822
|
-
};
|
|
4823
|
-
}
|
|
4824
|
-
return {
|
|
4825
|
-
authenticated: true,
|
|
4826
|
-
identity: "bearer-token-user"
|
|
4827
|
-
};
|
|
4828
|
-
};
|
|
4829
|
-
}
|
|
4830
|
-
function createSimpleRateLimiter(requestsPerMinute) {
|
|
4831
|
-
const requests = /* @__PURE__ */ new Map();
|
|
4832
|
-
const windowMs = 6e4;
|
|
4833
|
-
return (identity) => {
|
|
4834
|
-
const now = Date.now();
|
|
4835
|
-
const key = identity;
|
|
4836
|
-
let timestamps = requests.get(key) || [];
|
|
4837
|
-
timestamps = timestamps.filter((ts) => now - ts < windowMs);
|
|
4838
|
-
if (timestamps.length >= requestsPerMinute) {
|
|
4839
|
-
const oldestTimestamp = Math.min(...timestamps);
|
|
4840
|
-
const resetAt = oldestTimestamp + windowMs;
|
|
4841
|
-
return {
|
|
4842
|
-
allowed: false,
|
|
4843
|
-
remaining: 0,
|
|
4844
|
-
reset_at: resetAt
|
|
4845
|
-
};
|
|
4846
|
-
}
|
|
4847
|
-
timestamps.push(now);
|
|
4848
|
-
requests.set(key, timestamps);
|
|
4849
|
-
return {
|
|
4850
|
-
allowed: true,
|
|
4851
|
-
remaining: requestsPerMinute - timestamps.length,
|
|
4852
|
-
reset_at: now + windowMs
|
|
4853
|
-
};
|
|
4854
|
-
};
|
|
4855
|
-
}
|
|
4856
|
-
var init_http_helper = __esm({
|
|
4857
|
-
"src/foundry/signals/http-helper.ts"() {
|
|
4858
|
-
init_capabilities2();
|
|
4859
|
-
}
|
|
4860
|
-
});
|
|
4861
|
-
|
|
4862
|
-
// src/foundry/signals/manager.ts
|
|
4863
|
-
function createSignalManager(options = {}) {
|
|
4864
|
-
return new SignalManager(options);
|
|
4865
|
-
}
|
|
4866
|
-
var SignalManager;
|
|
4867
|
-
var init_manager = __esm({
|
|
4868
|
-
"src/foundry/signals/manager.ts"() {
|
|
4869
|
-
init_capabilities2();
|
|
4870
|
-
init_catalog();
|
|
4871
|
-
init_double_tap();
|
|
4872
|
-
init_windows();
|
|
4873
|
-
SignalManager = class {
|
|
4874
|
-
handlers = /* @__PURE__ */ new Map();
|
|
4875
|
-
nativeListeners = /* @__PURE__ */ new Map();
|
|
4876
|
-
options;
|
|
4877
|
-
handlerIdCounter = 0;
|
|
4878
|
-
doubleTapTrackers = /* @__PURE__ */ new Map();
|
|
4879
|
-
shuttingDown = false;
|
|
4880
|
-
constructor(options = {}) {
|
|
4881
|
-
this.options = {
|
|
4882
|
-
defaultTimeoutMs: options.defaultTimeoutMs ?? 3e4,
|
|
4883
|
-
timeoutBehavior: options.timeoutBehavior ?? "log_and_continue",
|
|
4884
|
-
testMode: options.testMode ?? false,
|
|
4885
|
-
doubleTapWindowMs: options.doubleTapWindowMs ?? 2e3,
|
|
4886
|
-
doubleTapExitCode: options.doubleTapExitCode ?? 130,
|
|
4887
|
-
logger: options.logger,
|
|
4888
|
-
telemetry: options.telemetry
|
|
4889
|
-
};
|
|
4890
|
-
}
|
|
4891
|
-
/**
|
|
4892
|
-
* Register a signal handler
|
|
4893
|
-
*
|
|
4894
|
-
* @param signal - Signal name (e.g., "SIGTERM") or NodeJS.Signals
|
|
4895
|
-
* @param handler - Handler function
|
|
4896
|
-
* @param options - Handler options
|
|
4897
|
-
*/
|
|
4898
|
-
async register(signal, handler, options = {}) {
|
|
4899
|
-
const signalName = typeof signal === "string" ? signal : signal;
|
|
4900
|
-
const supported = await supportsSignal(signalName);
|
|
4901
|
-
if (!supported) {
|
|
4902
|
-
if (isWindows2()) {
|
|
4903
|
-
await handleWindowsFallback(signalName, {
|
|
4904
|
-
logger: this.options.logger,
|
|
4905
|
-
telemetry: this.options.telemetry
|
|
4906
|
-
});
|
|
4907
|
-
}
|
|
4908
|
-
return;
|
|
4909
|
-
}
|
|
4910
|
-
if (!this.handlers.has(signalName)) {
|
|
4911
|
-
this.handlers.set(signalName, []);
|
|
4912
|
-
}
|
|
4913
|
-
const registration = {
|
|
4914
|
-
signal: signalName,
|
|
4915
|
-
handler,
|
|
4916
|
-
priority: options.priority ?? 0,
|
|
4917
|
-
timeoutMs: options.timeoutMs ?? this.options.defaultTimeoutMs,
|
|
4918
|
-
id: options.id ?? `handler-${++this.handlerIdCounter}`,
|
|
4919
|
-
registeredAt: Date.now()
|
|
4920
|
-
};
|
|
4921
|
-
const handlers = this.handlers.get(signalName);
|
|
4922
|
-
if (!handlers) {
|
|
4923
|
-
throw new Error(`Handler list not initialized for signal ${signalName}`);
|
|
4924
|
-
}
|
|
4925
|
-
handlers.push(registration);
|
|
4926
|
-
handlers.sort((a, b) => {
|
|
4927
|
-
if (a.priority !== b.priority) {
|
|
4928
|
-
return b.priority - a.priority;
|
|
4929
|
-
}
|
|
4930
|
-
return a.registeredAt - b.registeredAt;
|
|
4931
|
-
});
|
|
4932
|
-
if (!this.nativeListeners.has(signalName)) {
|
|
4933
|
-
await this.registerNativeListener(signalName);
|
|
4934
|
-
}
|
|
4935
|
-
if (this.options.logger) {
|
|
4936
|
-
this.options.logger.info(`Signal handler registered: ${signalName}`, {
|
|
4937
|
-
handler_id: registration.id,
|
|
4938
|
-
priority: registration.priority,
|
|
4939
|
-
timeout_ms: registration.timeoutMs
|
|
4940
|
-
});
|
|
4941
|
-
}
|
|
4942
|
-
if (this.options.telemetry) {
|
|
4943
|
-
this.options.telemetry.emit("fulmen.signal.handler_registered", {
|
|
4944
|
-
signal: signalName,
|
|
4945
|
-
handler_id: registration.id,
|
|
4946
|
-
priority: String(registration.priority)
|
|
4947
|
-
});
|
|
4948
|
-
}
|
|
4949
|
-
}
|
|
4950
|
-
/**
|
|
4951
|
-
* Register native Node.js signal listener
|
|
4952
|
-
*/
|
|
4953
|
-
async registerNativeListener(signalName) {
|
|
4954
|
-
const signal = await getSignal(signalName);
|
|
4955
|
-
if (!signal) {
|
|
4956
|
-
return;
|
|
4957
|
-
}
|
|
4958
|
-
const useDoubleTap = signal.default_behavior === "graceful_shutdown_with_double_tap";
|
|
4959
|
-
if (useDoubleTap) {
|
|
4960
|
-
const tracker = await createDoubleTapTracker(signalName, {
|
|
4961
|
-
windowMs: this.options.doubleTapWindowMs,
|
|
4962
|
-
exitCode: this.options.doubleTapExitCode,
|
|
4963
|
-
logger: this.options.logger,
|
|
4964
|
-
testMode: this.options.testMode
|
|
4965
|
-
});
|
|
4966
|
-
this.doubleTapTrackers.set(signalName, tracker);
|
|
4967
|
-
}
|
|
4968
|
-
const listener = async (sig) => {
|
|
4969
|
-
if (useDoubleTap) {
|
|
4970
|
-
const tracker = this.doubleTapTrackers.get(signalName);
|
|
4971
|
-
if (tracker) {
|
|
4972
|
-
const forceQuit = handleDoubleTap(tracker);
|
|
4973
|
-
if (forceQuit) {
|
|
4974
|
-
return;
|
|
4975
|
-
}
|
|
4976
|
-
}
|
|
4977
|
-
}
|
|
4978
|
-
await this.executeHandlers(signalName, sig);
|
|
4979
|
-
};
|
|
4980
|
-
process.on(signalName, listener);
|
|
4981
|
-
this.nativeListeners.set(signalName, listener);
|
|
4982
|
-
}
|
|
4983
|
-
/**
|
|
4984
|
-
* Execute all registered handlers for a signal
|
|
4985
|
-
*/
|
|
4986
|
-
async executeHandlers(signalName, signal) {
|
|
4987
|
-
const handlers = this.handlers.get(signalName);
|
|
4988
|
-
if (!handlers || handlers.length === 0) {
|
|
4989
|
-
return;
|
|
4990
|
-
}
|
|
4991
|
-
this.shuttingDown = true;
|
|
4992
|
-
if (this.options.logger) {
|
|
4993
|
-
this.options.logger.info(`Signal received: ${signalName}`, {
|
|
4994
|
-
handler_count: handlers.length
|
|
4995
|
-
});
|
|
4996
|
-
}
|
|
4997
|
-
for (const registration of handlers) {
|
|
4998
|
-
try {
|
|
4999
|
-
await this.executeWithTimeout(registration, signal);
|
|
5000
|
-
} catch (error) {
|
|
5001
|
-
if (this.options.logger) {
|
|
5002
|
-
this.options.logger.warn(`Signal handler failed: ${signalName}`, {
|
|
5003
|
-
handler_id: registration.id,
|
|
5004
|
-
error: error instanceof Error ? error.message : String(error)
|
|
5005
|
-
});
|
|
5006
|
-
}
|
|
5007
|
-
if (this.options.telemetry) {
|
|
5008
|
-
this.options.telemetry.emit("fulmen.signal.handler_error", {
|
|
5009
|
-
signal: signalName,
|
|
5010
|
-
handler_id: registration.id,
|
|
5011
|
-
error_type: error instanceof Error ? error.constructor.name : "unknown"
|
|
5012
|
-
});
|
|
5013
|
-
}
|
|
5014
|
-
if (this.options.timeoutBehavior === "force_exit") {
|
|
5015
|
-
const exitCode = (await getSignal(signalName))?.exit_code ?? 1;
|
|
5016
|
-
if (!this.options.testMode) {
|
|
5017
|
-
process.exit(exitCode);
|
|
5018
|
-
}
|
|
5019
|
-
return;
|
|
5020
|
-
}
|
|
5021
|
-
}
|
|
5022
|
-
}
|
|
5023
|
-
const tracker = this.doubleTapTrackers.get(signalName);
|
|
5024
|
-
if (tracker) {
|
|
5025
|
-
resetDoubleTap(tracker);
|
|
5026
|
-
}
|
|
5027
|
-
}
|
|
5028
|
-
/**
|
|
5029
|
-
* Execute a handler with timeout enforcement
|
|
5030
|
-
*/
|
|
5031
|
-
async executeWithTimeout(registration, signal) {
|
|
5032
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
5033
|
-
setTimeout(() => {
|
|
5034
|
-
reject(new Error(`Handler timeout exceeded: ${registration.timeoutMs}ms`));
|
|
5035
|
-
}, registration.timeoutMs);
|
|
5036
|
-
});
|
|
5037
|
-
const handlerPromise = Promise.resolve(registration.handler(signal));
|
|
5038
|
-
try {
|
|
5039
|
-
await Promise.race([handlerPromise, timeoutPromise]);
|
|
5040
|
-
if (this.options.telemetry) {
|
|
5041
|
-
this.options.telemetry.emit("fulmen.signal.handler_completed", {
|
|
5042
|
-
signal: registration.signal,
|
|
5043
|
-
handler_id: registration.id
|
|
5044
|
-
});
|
|
5045
|
-
}
|
|
5046
|
-
} catch (error) {
|
|
5047
|
-
if (this.options.telemetry) {
|
|
5048
|
-
this.options.telemetry.emit("fulmen.signal.handler_timeout", {
|
|
5049
|
-
signal: registration.signal,
|
|
5050
|
-
handler_id: registration.id,
|
|
5051
|
-
timeout_ms: String(registration.timeoutMs)
|
|
5052
|
-
});
|
|
5053
|
-
}
|
|
5054
|
-
throw error;
|
|
5055
|
-
}
|
|
5056
|
-
}
|
|
5057
|
-
/**
|
|
5058
|
-
* Unregister a signal handler
|
|
5059
|
-
*
|
|
5060
|
-
* @param signal - Signal name
|
|
5061
|
-
* @param handler - Handler to remove (if not provided, removes all handlers)
|
|
5062
|
-
*/
|
|
5063
|
-
unregister(signal, handler) {
|
|
5064
|
-
const handlers = this.handlers.get(signal);
|
|
5065
|
-
if (!handlers) {
|
|
5066
|
-
return;
|
|
5067
|
-
}
|
|
5068
|
-
if (handler) {
|
|
5069
|
-
const index = handlers.findIndex((h) => h.handler === handler);
|
|
5070
|
-
if (index !== -1) {
|
|
5071
|
-
handlers.splice(index, 1);
|
|
5072
|
-
}
|
|
5073
|
-
} else {
|
|
5074
|
-
handlers.length = 0;
|
|
5075
|
-
}
|
|
5076
|
-
if (handlers.length === 0) {
|
|
5077
|
-
const listener = this.nativeListeners.get(signal);
|
|
5078
|
-
if (listener) {
|
|
5079
|
-
process.off(signal, listener);
|
|
5080
|
-
this.nativeListeners.delete(signal);
|
|
5081
|
-
}
|
|
5082
|
-
this.handlers.delete(signal);
|
|
5083
|
-
}
|
|
5084
|
-
}
|
|
5085
|
-
/**
|
|
5086
|
-
* Check if a signal has registered handlers
|
|
5087
|
-
*/
|
|
5088
|
-
isRegistered(signal) {
|
|
5089
|
-
const handlers = this.handlers.get(signal);
|
|
5090
|
-
return handlers !== void 0 && handlers.length > 0;
|
|
5091
|
-
}
|
|
5092
|
-
/**
|
|
5093
|
-
* Get handler count for a signal
|
|
5094
|
-
*/
|
|
5095
|
-
getHandlerCount(signal) {
|
|
5096
|
-
const handlers = this.handlers.get(signal);
|
|
5097
|
-
return handlers?.length ?? 0;
|
|
5098
|
-
}
|
|
5099
|
-
/**
|
|
5100
|
-
* Trigger signal handlers manually (for testing)
|
|
5101
|
-
*
|
|
5102
|
-
* @param signal - Signal name
|
|
5103
|
-
*/
|
|
5104
|
-
async trigger(signal) {
|
|
5105
|
-
const handlers = this.handlers.get(signal);
|
|
5106
|
-
if (!handlers || handlers.length === 0) {
|
|
5107
|
-
return;
|
|
5108
|
-
}
|
|
5109
|
-
await this.executeHandlers(signal, signal);
|
|
5110
|
-
}
|
|
5111
|
-
/**
|
|
5112
|
-
* Shutdown the signal manager and cleanup all handlers
|
|
5113
|
-
*/
|
|
5114
|
-
async shutdown() {
|
|
5115
|
-
for (const [signal, listener] of this.nativeListeners.entries()) {
|
|
5116
|
-
process.off(signal, listener);
|
|
5117
|
-
}
|
|
5118
|
-
this.nativeListeners.clear();
|
|
5119
|
-
this.handlers.clear();
|
|
5120
|
-
this.doubleTapTrackers.clear();
|
|
5121
|
-
this.shuttingDown = false;
|
|
5122
|
-
}
|
|
5123
|
-
/**
|
|
5124
|
-
* Check if manager is currently shutting down
|
|
5125
|
-
*/
|
|
5126
|
-
isShuttingDown() {
|
|
5127
|
-
return this.shuttingDown;
|
|
5128
|
-
}
|
|
5129
|
-
};
|
|
5130
|
-
}
|
|
5131
|
-
});
|
|
5132
|
-
|
|
5133
|
-
// src/foundry/signals/reload.ts
|
|
5134
|
-
function createConfigReloadHandler(options) {
|
|
5135
|
-
const {
|
|
5136
|
-
loader,
|
|
5137
|
-
validator,
|
|
5138
|
-
onValidated,
|
|
5139
|
-
exitCode = 129,
|
|
5140
|
-
logger,
|
|
5141
|
-
telemetry,
|
|
5142
|
-
testMode = false
|
|
5143
|
-
} = options;
|
|
5144
|
-
return async () => {
|
|
5145
|
-
if (logger) {
|
|
5146
|
-
logger.info("Config reload requested (SIGHUP)");
|
|
5147
|
-
}
|
|
5148
|
-
if (telemetry) {
|
|
5149
|
-
telemetry.emit("fulmen.signal.config_reload_requested", {
|
|
5150
|
-
signal: "SIGHUP"
|
|
5151
|
-
});
|
|
5152
|
-
}
|
|
5153
|
-
try {
|
|
5154
|
-
const newConfig = await loader();
|
|
5155
|
-
const result = await validator(newConfig);
|
|
5156
|
-
if (!result.valid) {
|
|
5157
|
-
if (logger) {
|
|
5158
|
-
logger.warn("Config validation failed - continuing with current config", {
|
|
5159
|
-
error_count: result.errors?.length ?? 0,
|
|
5160
|
-
errors: result.errors
|
|
5161
|
-
});
|
|
5162
|
-
}
|
|
5163
|
-
if (telemetry) {
|
|
5164
|
-
telemetry.emit("fulmen.signal.config_reload_rejected", {
|
|
5165
|
-
signal: "SIGHUP",
|
|
5166
|
-
reason: "validation_failed",
|
|
5167
|
-
error_count: String(result.errors?.length ?? 0)
|
|
5168
|
-
});
|
|
5169
|
-
}
|
|
5170
|
-
return;
|
|
5171
|
-
}
|
|
5172
|
-
if (logger) {
|
|
5173
|
-
logger.info("Config validation succeeded - exiting for restart");
|
|
5174
|
-
}
|
|
5175
|
-
if (telemetry) {
|
|
5176
|
-
telemetry.emit("fulmen.signal.config_reload_accepted", {
|
|
5177
|
-
signal: "SIGHUP"
|
|
5178
|
-
});
|
|
5179
|
-
}
|
|
5180
|
-
if (onValidated) {
|
|
5181
|
-
await onValidated(newConfig);
|
|
5182
|
-
}
|
|
5183
|
-
if (!testMode) {
|
|
5184
|
-
process.exit(exitCode);
|
|
5185
|
-
}
|
|
5186
|
-
} catch (error) {
|
|
5187
|
-
if (logger) {
|
|
5188
|
-
logger.warn("Config reload failed with error - continuing with current config", {
|
|
5189
|
-
error: error instanceof Error ? error.message : String(error)
|
|
5190
|
-
});
|
|
5191
|
-
}
|
|
5192
|
-
if (telemetry) {
|
|
5193
|
-
telemetry.emit("fulmen.signal.config_reload_error", {
|
|
5194
|
-
signal: "SIGHUP",
|
|
5195
|
-
error_type: error instanceof Error ? error.constructor.name : "unknown"
|
|
5196
|
-
});
|
|
5197
|
-
}
|
|
5198
|
-
}
|
|
5199
|
-
};
|
|
5200
|
-
}
|
|
5201
|
-
var ConfigReloadTracker;
|
|
5202
|
-
var init_reload = __esm({
|
|
5203
|
-
"src/foundry/signals/reload.ts"() {
|
|
5204
|
-
ConfigReloadTracker = class {
|
|
5205
|
-
failures = 0;
|
|
5206
|
-
lastFailureTime = null;
|
|
5207
|
-
maxFailures;
|
|
5208
|
-
logger;
|
|
5209
|
-
telemetry;
|
|
5210
|
-
constructor(options) {
|
|
5211
|
-
this.maxFailures = options.maxFailures ?? 3;
|
|
5212
|
-
this.logger = options.logger;
|
|
5213
|
-
this.telemetry = options.telemetry;
|
|
5214
|
-
}
|
|
5215
|
-
/**
|
|
5216
|
-
* Record a reload failure
|
|
5217
|
-
*
|
|
5218
|
-
* @returns true if threshold exceeded, false otherwise
|
|
5219
|
-
*/
|
|
5220
|
-
recordFailure() {
|
|
5221
|
-
this.failures++;
|
|
5222
|
-
this.lastFailureTime = Date.now();
|
|
5223
|
-
if (this.failures >= this.maxFailures) {
|
|
5224
|
-
if (this.logger) {
|
|
5225
|
-
this.logger.warn(
|
|
5226
|
-
`${this.failures} consecutive config reload failures - check config source`,
|
|
5227
|
-
{
|
|
5228
|
-
failure_count: this.failures,
|
|
5229
|
-
threshold: this.maxFailures
|
|
5230
|
-
}
|
|
5231
|
-
);
|
|
5232
|
-
}
|
|
5233
|
-
if (this.telemetry) {
|
|
5234
|
-
this.telemetry.emit("fulmen.signal.config_reload_threshold_exceeded", {
|
|
5235
|
-
failure_count: String(this.failures),
|
|
5236
|
-
threshold: String(this.maxFailures)
|
|
5237
|
-
});
|
|
5238
|
-
}
|
|
5239
|
-
return true;
|
|
5240
|
-
}
|
|
5241
|
-
return false;
|
|
5242
|
-
}
|
|
5243
|
-
/**
|
|
5244
|
-
* Record a successful reload (resets counter)
|
|
5245
|
-
*/
|
|
5246
|
-
recordSuccess() {
|
|
5247
|
-
this.failures = 0;
|
|
5248
|
-
this.lastFailureTime = null;
|
|
5249
|
-
}
|
|
5250
|
-
/**
|
|
5251
|
-
* Get current failure count
|
|
5252
|
-
*/
|
|
5253
|
-
getFailureCount() {
|
|
5254
|
-
return this.failures;
|
|
5255
|
-
}
|
|
5256
|
-
/**
|
|
5257
|
-
* Get last failure timestamp
|
|
5258
|
-
*/
|
|
5259
|
-
getLastFailureTime() {
|
|
5260
|
-
return this.lastFailureTime;
|
|
5261
|
-
}
|
|
5262
|
-
};
|
|
5263
|
-
}
|
|
5264
|
-
});
|
|
5265
|
-
|
|
5266
|
-
// src/foundry/signals/index.ts
|
|
5267
|
-
var init_signals = __esm({
|
|
5268
|
-
"src/foundry/signals/index.ts"() {
|
|
5269
|
-
init_capabilities2();
|
|
5270
|
-
init_catalog();
|
|
5271
|
-
init_config_reload_endpoint();
|
|
5272
|
-
init_control_discovery_endpoint();
|
|
5273
|
-
init_convenience();
|
|
5274
|
-
init_double_tap();
|
|
5275
|
-
init_guards();
|
|
5276
|
-
init_http_helper();
|
|
5277
|
-
init_manager();
|
|
5278
|
-
init_reload();
|
|
5279
|
-
init_windows();
|
|
5280
|
-
}
|
|
5281
|
-
});
|
|
5282
|
-
function distance(a, b, metric = "levenshtein") {
|
|
5283
|
-
switch (metric) {
|
|
5284
|
-
case "levenshtein":
|
|
5285
|
-
return levenshtein(a, b);
|
|
5286
|
-
case "damerau_osa":
|
|
5287
|
-
return osa_distance(a, b);
|
|
5288
|
-
case "damerau_unrestricted":
|
|
5289
|
-
return damerau_levenshtein(a, b);
|
|
5290
|
-
case "jaro_winkler":
|
|
5291
|
-
return jaro_winkler(a, b);
|
|
5292
|
-
case "substring":
|
|
5293
|
-
return substringSimilarity(a, b).score;
|
|
5294
|
-
default:
|
|
5295
|
-
throw new Error(
|
|
5296
|
-
`Invalid metric '${metric}': must be one of: levenshtein, damerau_osa, damerau_unrestricted, jaro_winkler, substring`
|
|
5297
|
-
);
|
|
5298
|
-
}
|
|
5299
|
-
}
|
|
5300
|
-
var init_distance = __esm({
|
|
5301
|
-
"src/foundry/similarity/distance.ts"() {
|
|
5302
|
-
}
|
|
5303
|
-
});
|
|
5304
|
-
|
|
5305
|
-
// src/foundry/similarity/errors.ts
|
|
5306
|
-
var init_errors4 = __esm({
|
|
5307
|
-
"src/foundry/similarity/errors.ts"() {
|
|
5308
|
-
init_errors3();
|
|
5309
|
-
}
|
|
5310
|
-
});
|
|
5311
|
-
function toNormalizationLocale(locale) {
|
|
5312
|
-
if (!locale) {
|
|
5313
|
-
return void 0;
|
|
5314
|
-
}
|
|
5315
|
-
if (locale === "tr" || locale === "az" || locale === "lt") {
|
|
5316
|
-
return locale;
|
|
5317
|
-
}
|
|
5318
|
-
return void 0;
|
|
5319
|
-
}
|
|
5320
|
-
function normalize(value, preset = "default", locale) {
|
|
5321
|
-
if (typeof preset === "object") {
|
|
5322
|
-
const targetPreset = preset.stripAccents ? "aggressive" : "default";
|
|
5323
|
-
const targetLocale = toNormalizationLocale(preset.locale ?? locale);
|
|
5324
|
-
return normalize$1(value, targetPreset, targetLocale);
|
|
5325
|
-
}
|
|
5326
|
-
return normalize$1(value, preset, toNormalizationLocale(locale));
|
|
5327
|
-
}
|
|
5328
|
-
function casefold(value, locale) {
|
|
5329
|
-
if (locale === "tr") {
|
|
5330
|
-
return value.toLocaleLowerCase("tr-TR");
|
|
5331
|
-
}
|
|
5332
|
-
return value.toLowerCase();
|
|
5333
|
-
}
|
|
5334
|
-
function stripAccents(value) {
|
|
5335
|
-
return value.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
5336
|
-
}
|
|
5337
|
-
function equalsIgnoreCase(a, b, options) {
|
|
5338
|
-
return normalize(a, options) === normalize(b, options);
|
|
5339
|
-
}
|
|
5340
|
-
var init_normalization = __esm({
|
|
5341
|
-
"src/foundry/similarity/normalization.ts"() {
|
|
5342
|
-
}
|
|
5343
|
-
});
|
|
5344
|
-
function score(a, b, metric = "levenshtein") {
|
|
5345
|
-
if (metric === "substring") {
|
|
5346
|
-
return substringSimilarity(a, b).score;
|
|
5347
|
-
}
|
|
5348
|
-
return score$1(a, b, metric);
|
|
5349
|
-
}
|
|
5350
|
-
var init_score = __esm({
|
|
5351
|
-
"src/foundry/similarity/score.ts"() {
|
|
5352
|
-
}
|
|
5353
|
-
});
|
|
5354
|
-
function suggest(input, candidates, options) {
|
|
5355
|
-
const metric = options?.metric ?? DEFAULT_METRIC;
|
|
5356
|
-
const minScore = options?.minScore ?? DEFAULT_MIN_SCORE;
|
|
5357
|
-
const maxSuggestions = options?.maxSuggestions ?? DEFAULT_MAX_SUGGESTIONS;
|
|
5358
|
-
let normalizePreset = options?.normalizePreset ?? DEFAULT_NORMALIZE_PRESET;
|
|
5359
|
-
if (options?.normalize === false) {
|
|
5360
|
-
normalizePreset = "none";
|
|
5361
|
-
} else if (options?.normalize === true && !options?.normalizePreset) {
|
|
5362
|
-
normalizePreset = "default";
|
|
5363
|
-
}
|
|
5364
|
-
const wasmOptions = {
|
|
5365
|
-
metric,
|
|
5366
|
-
normalizePreset,
|
|
5367
|
-
minScore,
|
|
5368
|
-
maxSuggestions,
|
|
5369
|
-
preferPrefix: options?.preferPrefix,
|
|
5370
|
-
jaroPrefixScale: options?.jaroPrefixScale,
|
|
5371
|
-
jaroMaxPrefix: options?.jaroMaxPrefix
|
|
5372
|
-
};
|
|
5373
|
-
const results = suggest$1(input, candidates, wasmOptions);
|
|
5374
|
-
return results.map((r) => ({
|
|
5375
|
-
value: r.value,
|
|
5376
|
-
score: r.score,
|
|
5377
|
-
matchedRange: r.matchedRange,
|
|
5378
|
-
reason: r.reason,
|
|
5379
|
-
normalizedValue: r.normalizedValue
|
|
5380
|
-
}));
|
|
5381
|
-
}
|
|
5382
|
-
var DEFAULT_MIN_SCORE, DEFAULT_MAX_SUGGESTIONS, DEFAULT_METRIC, DEFAULT_NORMALIZE_PRESET;
|
|
5383
|
-
var init_suggest = __esm({
|
|
5384
|
-
"src/foundry/similarity/suggest.ts"() {
|
|
5385
|
-
DEFAULT_MIN_SCORE = 0.6;
|
|
5386
|
-
DEFAULT_MAX_SUGGESTIONS = 3;
|
|
5387
|
-
DEFAULT_METRIC = "levenshtein";
|
|
5388
|
-
DEFAULT_NORMALIZE_PRESET = "default";
|
|
5389
|
-
}
|
|
5390
|
-
});
|
|
5391
|
-
|
|
5392
|
-
// src/foundry/similarity/index.ts
|
|
5393
|
-
var init_similarity = __esm({
|
|
5394
|
-
"src/foundry/similarity/index.ts"() {
|
|
5395
|
-
init_distance();
|
|
5396
|
-
init_errors4();
|
|
5397
|
-
init_normalization();
|
|
5398
|
-
init_score();
|
|
5399
|
-
init_suggest();
|
|
5400
|
-
}
|
|
5401
|
-
});
|
|
5402
|
-
|
|
5403
|
-
// src/foundry/index.ts
|
|
5404
|
-
var foundry_exports = {};
|
|
5405
|
-
__export(foundry_exports, {
|
|
5406
|
-
ConfigReloadTracker: () => ConfigReloadTracker,
|
|
5407
|
-
EXIT_CODES_VERSION: () => EXIT_CODES_VERSION,
|
|
5408
|
-
FoundryCatalogError: () => FoundryCatalogError,
|
|
5409
|
-
SignalManager: () => SignalManager,
|
|
5410
|
-
SimplifiedMode: () => SimplifiedMode,
|
|
5411
|
-
VERSION: () => VERSION,
|
|
5412
|
-
casefold: () => casefold,
|
|
5413
|
-
clearCountryCodeCache: () => clearCountryCodeCache,
|
|
5414
|
-
clearHttpStatusCache: () => clearHttpStatusCache,
|
|
5415
|
-
clearMimeTypeCache: () => clearMimeTypeCache,
|
|
5416
|
-
clearPatternCache: () => clearPatternCache,
|
|
5417
|
-
createBearerTokenAuth: () => createBearerTokenAuth,
|
|
5418
|
-
createConfigReloadEndpoint: () => createConfigReloadEndpoint,
|
|
5419
|
-
createConfigReloadHandler: () => createConfigReloadHandler,
|
|
5420
|
-
createControlDiscoveryEndpoint: () => createControlDiscoveryEndpoint,
|
|
5421
|
-
createDoubleTapTracker: () => createDoubleTapTracker,
|
|
5422
|
-
createSignalEndpoint: () => createSignalEndpoint,
|
|
5423
|
-
createSignalManager: () => createSignalManager,
|
|
5424
|
-
createSimpleRateLimiter: () => createSimpleRateLimiter,
|
|
5425
|
-
describePattern: () => describePattern,
|
|
5426
|
-
detectMimeType: () => detectMimeType,
|
|
5427
|
-
detectMimeTypeFromBuffer: () => detectMimeTypeFromBuffer,
|
|
5428
|
-
detectMimeTypeFromFile: () => detectMimeTypeFromFile,
|
|
5429
|
-
detectMimeTypeFromStream: () => detectMimeTypeFromStream,
|
|
5430
|
-
distance: () => distance,
|
|
5431
|
-
ensurePOSIX: () => ensurePOSIX,
|
|
5432
|
-
ensureSignalExitCodesSupported: () => ensureSignalExitCodesSupported,
|
|
5433
|
-
ensureSupported: () => ensureSupported,
|
|
5434
|
-
ensureWindows: () => ensureWindows,
|
|
5435
|
-
equalsIgnoreCase: () => equalsIgnoreCase,
|
|
5436
|
-
exitCodeMetadata: () => exitCodeMetadata,
|
|
5437
|
-
exitCodes: () => exitCodes,
|
|
5438
|
-
getBehavior: () => getBehavior,
|
|
5439
|
-
getCountryByAlpha2: () => getCountryByAlpha2,
|
|
5440
|
-
getCountryByAlpha3: () => getCountryByAlpha3,
|
|
5441
|
-
getCountryByNumeric: () => getCountryByNumeric,
|
|
5442
|
-
getExitCodeInfo: () => getExitCodeInfo,
|
|
5443
|
-
getFallbackMetadata: () => getFallbackMetadata,
|
|
5444
|
-
getHttpFallbackGuidance: () => getHttpFallbackGuidance,
|
|
5445
|
-
getHttpStatus: () => getHttpStatus,
|
|
5446
|
-
getMimeType: () => getMimeType,
|
|
5447
|
-
getMimeTypeByExtension: () => getMimeTypeByExtension,
|
|
5448
|
-
getPattern: () => getPattern,
|
|
5449
|
-
getPatternRegex: () => getPatternRegex,
|
|
5450
|
-
getPlatform: () => getPlatform,
|
|
5451
|
-
getPlatformCapabilities: () => getPlatformCapabilities,
|
|
5452
|
-
getSignal: () => getSignal,
|
|
5453
|
-
getSignalCatalog: () => getSignalCatalog,
|
|
5454
|
-
getSignalNumber: () => getSignalNumber,
|
|
5455
|
-
getSignalPlatformCapabilities: () => getPlatformCapabilities2,
|
|
5456
|
-
getSignalsVersion: () => getSignalsVersion,
|
|
5457
|
-
getSimplifiedCodeDescription: () => getSimplifiedCodeDescription,
|
|
5458
|
-
getSimplifiedCodes: () => getSimplifiedCodes,
|
|
5459
|
-
getStatusReason: () => getStatusReason,
|
|
5460
|
-
getWindowTimeRemaining: () => getWindowTimeRemaining,
|
|
5461
|
-
getWindowsEvent: () => getWindowsEvent,
|
|
5462
|
-
handleDoubleTap: () => handleDoubleTap,
|
|
5463
|
-
handleWindowsFallback: () => handleWindowsFallback,
|
|
5464
|
-
isClientError: () => isClientError,
|
|
5465
|
-
isInformational: () => isInformational,
|
|
5466
|
-
isPOSIX: () => isPOSIX,
|
|
5467
|
-
isRedirection: () => isRedirection,
|
|
5468
|
-
isServerError: () => isServerError,
|
|
5469
|
-
isSignalPOSIX: () => isPOSIX2,
|
|
5470
|
-
isSignalWindows: () => isWindows2,
|
|
5471
|
-
isSuccess: () => isSuccess,
|
|
5472
|
-
isSupportedMimeType: () => isSupportedMimeType,
|
|
5473
|
-
isWindows: () => isWindows,
|
|
5474
|
-
isWithinWindow: () => isWithinWindow,
|
|
5475
|
-
listBehaviors: () => listBehaviors,
|
|
5476
|
-
listCountries: () => listCountries,
|
|
5477
|
-
listHttpStatuses: () => listHttpStatuses,
|
|
5478
|
-
listMimeTypes: () => listMimeTypes,
|
|
5479
|
-
listPatterns: () => listPatterns,
|
|
5480
|
-
listSignals: () => listSignals,
|
|
5481
|
-
loadAllCatalogs: () => loadAllCatalogs,
|
|
5482
|
-
loadCountryCodeCatalog: () => loadCountryCodeCatalog,
|
|
5483
|
-
loadHttpStatusCatalog: () => loadHttpStatusCatalog,
|
|
5484
|
-
loadMimeTypeCatalog: () => loadMimeTypeCatalog,
|
|
5485
|
-
loadPatternCatalog: () => loadPatternCatalog,
|
|
5486
|
-
mapExitCodeToSimplified: () => mapExitCodeToSimplified,
|
|
5487
|
-
matchMagicNumber: () => matchMagicNumber,
|
|
5488
|
-
matchPattern: () => matchPattern,
|
|
5489
|
-
normalize: () => normalize,
|
|
5490
|
-
onAnyShutdown: () => onAnyShutdown,
|
|
5491
|
-
onEmergencyQuit: () => onEmergencyQuit,
|
|
5492
|
-
onReload: () => onReload,
|
|
5493
|
-
onShutdown: () => onShutdown,
|
|
5494
|
-
onUSR1: () => onUSR1,
|
|
5495
|
-
onUSR2: () => onUSR2,
|
|
5496
|
-
requiresFallback: () => requiresFallback,
|
|
5497
|
-
resetDoubleTap: () => resetDoubleTap,
|
|
5498
|
-
score: () => score,
|
|
5499
|
-
stripAccents: () => stripAccents,
|
|
5500
|
-
suggest: () => suggest,
|
|
5501
|
-
supportsSignal: () => supportsSignal,
|
|
5502
|
-
supportsSignalBasedExitCodes: () => supportsSignalExitCodes2,
|
|
5503
|
-
supportsSignalExitCodes: () => supportsSignalExitCodes
|
|
5504
|
-
});
|
|
5505
|
-
var VERSION;
|
|
5506
|
-
var init_foundry = __esm({
|
|
5507
|
-
"src/foundry/index.ts"() {
|
|
5508
|
-
init_country_codes();
|
|
5509
|
-
init_errors3();
|
|
5510
|
-
init_exit_codes();
|
|
5511
|
-
init_http_statuses();
|
|
5512
|
-
init_loader();
|
|
5513
|
-
init_mime_types();
|
|
5514
|
-
init_patterns();
|
|
5515
|
-
init_signals();
|
|
5516
|
-
init_similarity();
|
|
5517
|
-
VERSION = "0.1.1";
|
|
5518
|
-
}
|
|
5519
|
-
});
|
|
5520
|
-
|
|
5521
|
-
// src/appidentity/cache.ts
|
|
5522
|
-
function getCachedIdentity() {
|
|
5523
|
-
return cachedIdentity;
|
|
5524
|
-
}
|
|
5525
|
-
function setCachedIdentity(identity) {
|
|
5526
|
-
cachedIdentity = identity;
|
|
5527
|
-
}
|
|
5528
|
-
function clearIdentityCache() {
|
|
5529
|
-
cachedIdentity = null;
|
|
5530
|
-
}
|
|
5531
|
-
var cachedIdentity;
|
|
5532
|
-
var init_cache = __esm({
|
|
5533
|
-
"src/appidentity/cache.ts"() {
|
|
5534
|
-
cachedIdentity = null;
|
|
5535
|
-
}
|
|
5536
|
-
});
|
|
5537
|
-
|
|
5538
|
-
// src/appidentity/constants.ts
|
|
5539
|
-
var APP_IDENTITY_FILENAME, APP_IDENTITY_DIR, APP_IDENTITY_ENV_VAR, APP_IDENTITY_SCHEMA_ID, MAX_ANCESTOR_SEARCH_DEPTH;
|
|
5540
|
-
var init_constants = __esm({
|
|
5541
|
-
"src/appidentity/constants.ts"() {
|
|
5542
|
-
APP_IDENTITY_FILENAME = "app.yaml";
|
|
5543
|
-
APP_IDENTITY_DIR = ".fulmen";
|
|
5544
|
-
APP_IDENTITY_ENV_VAR = "FULMEN_APP_IDENTITY_PATH";
|
|
5545
|
-
APP_IDENTITY_SCHEMA_ID = "config/repository/app-identity/v1.0.0/app-identity";
|
|
5546
|
-
MAX_ANCESTOR_SEARCH_DEPTH = 20;
|
|
5547
|
-
}
|
|
5548
|
-
});
|
|
5549
|
-
|
|
5550
|
-
// src/appidentity/errors.ts
|
|
5551
|
-
var errors_exports2 = {};
|
|
5552
|
-
__export(errors_exports2, {
|
|
5553
|
-
AppIdentityError: () => AppIdentityError
|
|
5554
|
-
});
|
|
5555
|
-
var AppIdentityError;
|
|
5556
|
-
var init_errors5 = __esm({
|
|
5557
|
-
"src/appidentity/errors.ts"() {
|
|
5558
|
-
init_errors6();
|
|
5559
|
-
AppIdentityError = class _AppIdentityError extends FulmenError {
|
|
5560
|
-
identityPath;
|
|
5561
|
-
constructor(message, identityPath, cause) {
|
|
5562
|
-
let errorData;
|
|
5563
|
-
if (cause) {
|
|
5564
|
-
errorData = FulmenError.fromError(cause, {
|
|
5565
|
-
code: "APP_IDENTITY_ERROR",
|
|
5566
|
-
severity: "high",
|
|
5567
|
-
context: { identityPath }
|
|
5568
|
-
}).data;
|
|
5569
|
-
} else {
|
|
5570
|
-
errorData = {
|
|
5571
|
-
code: "APP_IDENTITY_ERROR",
|
|
5572
|
-
message,
|
|
5573
|
-
severity: "high",
|
|
5574
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5575
|
-
context: { identityPath }
|
|
5576
|
-
};
|
|
5577
|
-
}
|
|
5578
|
-
super(errorData);
|
|
5579
|
-
this.name = "AppIdentityError";
|
|
5580
|
-
this.identityPath = identityPath;
|
|
5581
|
-
if (Error.captureStackTrace) {
|
|
5582
|
-
Error.captureStackTrace(this, _AppIdentityError);
|
|
5583
|
-
}
|
|
5584
|
-
}
|
|
5585
|
-
/**
|
|
5586
|
-
* Create error for identity not found
|
|
5587
|
-
*/
|
|
5588
|
-
static notFound(searchedPaths) {
|
|
5589
|
-
const message = `App identity not found
|
|
5590
|
-
Searched paths:
|
|
5591
|
-
${searchedPaths.map((p) => ` - ${p}`).join("\n")}`;
|
|
5592
|
-
return new _AppIdentityError(message);
|
|
5593
|
-
}
|
|
5594
|
-
/**
|
|
5595
|
-
* Create error for schema validation failure
|
|
5596
|
-
*/
|
|
5597
|
-
static validationFailed(path5, diagnostics) {
|
|
5598
|
-
const errorCount = diagnostics.filter((d) => d.severity === "ERROR").length;
|
|
5599
|
-
const warningCount = diagnostics.filter((d) => d.severity === "WARN").length;
|
|
5600
|
-
let message = `Invalid app identity: ${path5}
|
|
5601
|
-
`;
|
|
5602
|
-
message += `Validation errors: ${errorCount} error(s), ${warningCount} warning(s)
|
|
5603
|
-
`;
|
|
5604
|
-
const displayDiagnostics = diagnostics.slice(0, 3);
|
|
5605
|
-
for (const diag of displayDiagnostics) {
|
|
5606
|
-
message += ` - ${diag.message}`;
|
|
5607
|
-
if (diag.pointer) {
|
|
5608
|
-
message += ` at ${diag.pointer}`;
|
|
5609
|
-
}
|
|
5610
|
-
message += "\n";
|
|
5611
|
-
}
|
|
5612
|
-
if (diagnostics.length > 3) {
|
|
5613
|
-
message += ` ... and ${diagnostics.length - 3} more
|
|
5614
|
-
`;
|
|
5615
|
-
}
|
|
5616
|
-
return new _AppIdentityError(message, path5);
|
|
5617
|
-
}
|
|
5618
|
-
/**
|
|
5619
|
-
* Create error for environment variable override pointing to missing file
|
|
5620
|
-
*/
|
|
5621
|
-
static envOverrideMissing(envPath) {
|
|
5622
|
-
const message = `FULMEN_APP_IDENTITY_PATH points to missing file: ${envPath}
|
|
5623
|
-
`;
|
|
5624
|
-
return new _AppIdentityError(message, envPath);
|
|
5625
|
-
}
|
|
5626
|
-
/**
|
|
5627
|
-
* Create error for YAML parsing failure
|
|
5628
|
-
*/
|
|
5629
|
-
static parseFailed(path5, cause) {
|
|
5630
|
-
const message = `Failed to parse identity file: ${path5}
|
|
5631
|
-
${cause.message}`;
|
|
5632
|
-
return new _AppIdentityError(message, path5, cause);
|
|
5633
|
-
}
|
|
5634
|
-
/**
|
|
5635
|
-
* Create error for file read failure
|
|
5636
|
-
*/
|
|
5637
|
-
static readFailed(path5, cause) {
|
|
5638
|
-
const message = `Failed to read identity file: ${path5}
|
|
5639
|
-
${cause.message}`;
|
|
5640
|
-
return new _AppIdentityError(message, path5, cause);
|
|
5641
|
-
}
|
|
5642
|
-
/**
|
|
5643
|
-
* Create error for embedded identity already registered
|
|
5644
|
-
*
|
|
5645
|
-
* Uses first-wins semantics - once registered, cannot be replaced
|
|
5646
|
-
*/
|
|
5647
|
-
static alreadyRegistered() {
|
|
5648
|
-
const message = "Embedded identity already registered. Registration uses first-wins semantics and cannot be replaced.";
|
|
5649
|
-
return new _AppIdentityError(message);
|
|
5650
|
-
}
|
|
5651
|
-
/**
|
|
5652
|
-
* Create error for embedded identity YAML parsing failure
|
|
5653
|
-
*/
|
|
5654
|
-
static embeddedParseFailed(cause) {
|
|
5655
|
-
const message = `Failed to parse embedded identity YAML: ${cause.message}`;
|
|
5656
|
-
return new _AppIdentityError(message, void 0, cause);
|
|
5657
|
-
}
|
|
5658
|
-
/**
|
|
5659
|
-
* Create error for embedded identity schema validation failure
|
|
5660
|
-
*/
|
|
5661
|
-
static embeddedValidationFailed(diagnostics) {
|
|
5662
|
-
const errorCount = diagnostics.filter((d) => d.severity === "ERROR").length;
|
|
5663
|
-
const warningCount = diagnostics.filter((d) => d.severity === "WARN").length;
|
|
5664
|
-
let message = "Invalid embedded identity\n";
|
|
5665
|
-
message += `Validation errors: ${errorCount} error(s), ${warningCount} warning(s)
|
|
5666
|
-
`;
|
|
5667
|
-
const displayDiagnostics = diagnostics.slice(0, 3);
|
|
5668
|
-
for (const diag of displayDiagnostics) {
|
|
5669
|
-
message += ` - ${diag.message}`;
|
|
5670
|
-
if (diag.pointer) {
|
|
5671
|
-
message += ` at ${diag.pointer}`;
|
|
5672
|
-
}
|
|
5673
|
-
message += "\n";
|
|
5674
|
-
}
|
|
5675
|
-
if (diagnostics.length > 3) {
|
|
5676
|
-
message += ` ... and ${diagnostics.length - 3} more
|
|
5677
|
-
`;
|
|
5678
|
-
}
|
|
5679
|
-
return new _AppIdentityError(message);
|
|
5680
|
-
}
|
|
5681
|
-
};
|
|
5682
|
-
}
|
|
5683
|
-
});
|
|
5684
|
-
async function discoverIdentityPath(options) {
|
|
5685
|
-
if (options?.path) {
|
|
5686
|
-
const exists = await fileExists(options.path);
|
|
5687
|
-
if (!exists) {
|
|
5688
|
-
throw AppIdentityError.notFound([options.path]);
|
|
5689
|
-
}
|
|
5690
|
-
return { path: options.path, source: "explicit" };
|
|
5691
|
-
}
|
|
5692
|
-
const envPath = process.env[APP_IDENTITY_ENV_VAR];
|
|
5693
|
-
if (envPath) {
|
|
5694
|
-
const exists = await fileExists(envPath);
|
|
5695
|
-
if (!exists) {
|
|
5696
|
-
throw AppIdentityError.envOverrideMissing(envPath);
|
|
5697
|
-
}
|
|
5698
|
-
return { path: envPath, source: "env" };
|
|
5699
|
-
}
|
|
5700
|
-
const startDir = options?.startDir || process.cwd();
|
|
5701
|
-
const result = await searchAncestors(startDir);
|
|
5702
|
-
if (result) {
|
|
5703
|
-
return { path: result, source: "ancestor" };
|
|
5704
|
-
}
|
|
5705
|
-
return null;
|
|
5706
|
-
}
|
|
5707
|
-
async function searchAncestors(startDir) {
|
|
5708
|
-
let currentDir = startDir;
|
|
5709
|
-
const searchedPaths = [];
|
|
5710
|
-
for (let i = 0; i < MAX_ANCESTOR_SEARCH_DEPTH; i++) {
|
|
5711
|
-
const candidatePath = join(currentDir, APP_IDENTITY_DIR, APP_IDENTITY_FILENAME);
|
|
5712
|
-
searchedPaths.push(candidatePath);
|
|
5713
|
-
if (await fileExists(candidatePath)) {
|
|
5714
|
-
return candidatePath;
|
|
5715
|
-
}
|
|
5716
|
-
const parentDir = dirname(currentDir);
|
|
5717
|
-
if (parentDir === currentDir) {
|
|
5718
|
-
throw AppIdentityError.notFound(searchedPaths);
|
|
5719
|
-
}
|
|
5720
|
-
currentDir = parentDir;
|
|
5721
|
-
}
|
|
5722
|
-
throw AppIdentityError.notFound(searchedPaths);
|
|
5723
|
-
}
|
|
5724
|
-
async function fileExists(path5) {
|
|
5725
|
-
try {
|
|
5726
|
-
await access(path5);
|
|
5727
|
-
return true;
|
|
5728
|
-
} catch {
|
|
5729
|
-
return false;
|
|
5730
|
-
}
|
|
5731
|
-
}
|
|
5732
|
-
var init_discovery = __esm({
|
|
5733
|
-
"src/appidentity/discovery.ts"() {
|
|
5734
|
-
init_constants();
|
|
5735
|
-
init_errors5();
|
|
5736
|
-
}
|
|
5737
|
-
});
|
|
5738
|
-
function getEmbeddedIdentity() {
|
|
5739
|
-
return embeddedIdentity;
|
|
5740
|
-
}
|
|
5741
|
-
var embeddedIdentity;
|
|
5742
|
-
var init_embedded = __esm({
|
|
5743
|
-
"src/appidentity/embedded.ts"() {
|
|
5744
|
-
init_schema();
|
|
5745
|
-
init_constants();
|
|
5746
|
-
init_errors5();
|
|
5747
|
-
embeddedIdentity = null;
|
|
5748
|
-
}
|
|
5749
|
-
});
|
|
5750
|
-
|
|
5751
|
-
// src/appidentity/loader.ts
|
|
5752
|
-
var loader_exports = {};
|
|
5753
|
-
__export(loader_exports, {
|
|
5754
|
-
clearIdentityCache: () => clearIdentityCache,
|
|
5755
|
-
getCachedIdentity: () => getCachedIdentity,
|
|
5756
|
-
loadIdentity: () => loadIdentity
|
|
5757
|
-
});
|
|
5758
|
-
function deepFreeze5(obj) {
|
|
5759
|
-
Object.freeze(obj);
|
|
5760
|
-
Object.getOwnPropertyNames(obj).forEach((prop) => {
|
|
5761
|
-
const value = obj[prop];
|
|
5762
|
-
if (value !== null && (typeof value === "object" || typeof value === "function") && !Object.isFrozen(value)) {
|
|
5763
|
-
deepFreeze5(value);
|
|
5764
|
-
}
|
|
5765
|
-
});
|
|
5766
|
-
return obj;
|
|
5767
|
-
}
|
|
5768
|
-
async function loadIdentity(options) {
|
|
5769
|
-
if (options?.identity) {
|
|
5770
|
-
return deepFreeze5(structuredClone(options.identity));
|
|
5771
|
-
}
|
|
5772
|
-
if (!options?.skipCache) {
|
|
5773
|
-
const cached = getCachedIdentity();
|
|
5774
|
-
if (cached) {
|
|
5775
|
-
return cached;
|
|
5776
|
-
}
|
|
5777
|
-
}
|
|
5778
|
-
let discovery;
|
|
5779
|
-
try {
|
|
5780
|
-
discovery = await discoverIdentityPath({
|
|
5781
|
-
path: options?.path,
|
|
5782
|
-
startDir: options?.startDir
|
|
5783
|
-
});
|
|
5784
|
-
} catch (error) {
|
|
5785
|
-
const hasExplicitPath = Boolean(options?.path);
|
|
5786
|
-
const hasEnvOverride = Boolean(process.env[APP_IDENTITY_ENV_VAR]);
|
|
5787
|
-
if (!hasExplicitPath && !hasEnvOverride && error instanceof AppIdentityError) {
|
|
5788
|
-
const embedded = getEmbeddedIdentity();
|
|
5789
|
-
if (embedded) {
|
|
5790
|
-
setCachedIdentity(embedded);
|
|
5791
|
-
return embedded;
|
|
5792
|
-
}
|
|
5793
|
-
}
|
|
5794
|
-
throw error;
|
|
5795
|
-
}
|
|
5796
|
-
if (!discovery) {
|
|
5797
|
-
const embedded = getEmbeddedIdentity();
|
|
5798
|
-
if (embedded) {
|
|
5799
|
-
setCachedIdentity(embedded);
|
|
5800
|
-
return embedded;
|
|
5801
|
-
}
|
|
5802
|
-
throw AppIdentityError.notFound([]);
|
|
5803
|
-
}
|
|
5804
|
-
let content;
|
|
5805
|
-
try {
|
|
5806
|
-
content = await readFile(discovery.path, "utf-8");
|
|
5807
|
-
} catch (error) {
|
|
5808
|
-
throw AppIdentityError.readFailed(
|
|
5809
|
-
discovery.path,
|
|
5810
|
-
error instanceof Error ? error : new Error(String(error))
|
|
5811
|
-
);
|
|
5812
|
-
}
|
|
5813
|
-
let parsed;
|
|
5814
|
-
try {
|
|
5815
|
-
parsed = parse(content);
|
|
5816
|
-
} catch (error) {
|
|
5817
|
-
throw AppIdentityError.parseFailed(
|
|
5818
|
-
discovery.path,
|
|
5819
|
-
error instanceof Error ? error : new Error(String(error))
|
|
5820
|
-
);
|
|
5821
|
-
}
|
|
5822
|
-
if (!options?.skipValidation) {
|
|
5823
|
-
const result = await validateDataBySchemaId(parsed, APP_IDENTITY_SCHEMA_ID);
|
|
5824
|
-
if (!result.valid) {
|
|
5825
|
-
throw AppIdentityError.validationFailed(discovery.path, result.diagnostics);
|
|
5826
|
-
}
|
|
5827
|
-
}
|
|
5828
|
-
const identity = deepFreeze5(structuredClone(parsed));
|
|
5829
|
-
setCachedIdentity(identity);
|
|
5830
|
-
return identity;
|
|
5831
|
-
}
|
|
5832
|
-
var init_loader2 = __esm({
|
|
5833
|
-
"src/appidentity/loader.ts"() {
|
|
5834
|
-
init_schema();
|
|
5835
|
-
init_cache();
|
|
5836
|
-
init_constants();
|
|
5837
|
-
init_discovery();
|
|
5838
|
-
init_embedded();
|
|
5839
|
-
init_errors5();
|
|
5840
|
-
}
|
|
5841
|
-
});
|
|
5842
|
-
function createCLI(options = {}) {
|
|
5843
|
-
const program = new Command();
|
|
5844
|
-
program.name("tsfulmen-schema").description("Schema validation and discovery CLI for Fulmen (developer tool)").version("0.1.0");
|
|
5845
|
-
program.command("list").description("List available schemas from registry").argument("[prefix]", "Filter schemas by prefix").option("--base-dir <path>", "Override schema base directory").action(async (prefix, cmdOptions) => {
|
|
5846
|
-
try {
|
|
5847
|
-
const schemas = await listSchemas(prefix, {
|
|
5848
|
-
baseDir: cmdOptions?.baseDir || options.baseDir
|
|
5849
|
-
});
|
|
5850
|
-
if (schemas.length === 0) {
|
|
5851
|
-
console.log("No schemas found");
|
|
5852
|
-
return;
|
|
5853
|
-
}
|
|
5854
|
-
console.log(`Found ${schemas.length} schema(s):
|
|
5855
|
-
`);
|
|
5856
|
-
for (const schema of schemas) {
|
|
5857
|
-
console.log(` ${schema.id}`);
|
|
5858
|
-
console.log(` Format: ${schema.format}`);
|
|
5859
|
-
console.log(` Path: ${schema.relativePath}`);
|
|
5860
|
-
if (schema.description) {
|
|
5861
|
-
console.log(` Description: ${schema.description}`);
|
|
5862
|
-
}
|
|
5863
|
-
console.log();
|
|
5864
|
-
}
|
|
5865
|
-
} catch (error) {
|
|
5866
|
-
console.error("Error listing schemas:", error.message);
|
|
5867
|
-
process.exit(1);
|
|
5868
|
-
}
|
|
5869
|
-
});
|
|
5870
|
-
program.command("show").description("Show schema details").requiredOption("--schema-id <id>", "Schema ID to show").option("--base-dir <path>", "Override schema base directory").action(async (cmdOptions) => {
|
|
5871
|
-
try {
|
|
5872
|
-
const registry = getSchemaRegistry({
|
|
5873
|
-
baseDir: cmdOptions.baseDir || options.baseDir
|
|
5874
|
-
});
|
|
5875
|
-
const schema = await registry.getSchema(cmdOptions.schemaId);
|
|
5876
|
-
console.log("Schema Details:\n");
|
|
5877
|
-
console.log(` ID: ${schema.id}`);
|
|
5878
|
-
console.log(` Format: ${schema.format}`);
|
|
5879
|
-
console.log(` Path: ${schema.path}`);
|
|
5880
|
-
console.log(` Relative Path: ${schema.relativePath}`);
|
|
5881
|
-
if (schema.version) {
|
|
5882
|
-
console.log(` Version: ${schema.version}`);
|
|
5883
|
-
}
|
|
5884
|
-
if (schema.description) {
|
|
5885
|
-
console.log(` Description: ${schema.description}`);
|
|
5886
|
-
}
|
|
5887
|
-
if (schema.schemaDraft) {
|
|
5888
|
-
console.log(` Schema Draft: ${schema.schemaDraft}`);
|
|
5889
|
-
}
|
|
5890
|
-
const content = await readFile(schema.path, "utf-8");
|
|
5891
|
-
console.log("\nSchema Content:");
|
|
5892
|
-
console.log(content);
|
|
5893
|
-
} catch (error) {
|
|
5894
|
-
console.error("Error showing schema:", error.message);
|
|
5895
|
-
process.exit(1);
|
|
5896
|
-
}
|
|
5897
|
-
});
|
|
5898
|
-
program.command("validate").description("Validate data file against schema").requiredOption("--schema-id <id>", "Schema ID to validate against").argument("<file>", "Data file to validate").option("--use-goneat", "Use goneat for validation (requires goneat binary)").option("--goneat-path <path>", "Path to goneat binary").option("--base-dir <path>", "Override schema base directory").action(
|
|
5899
|
-
async (file, cmdOptions) => {
|
|
5900
|
-
try {
|
|
5901
|
-
let result;
|
|
5902
|
-
if (cmdOptions.useGoneat) {
|
|
5903
|
-
const available = await isGoneatAvailable(cmdOptions.goneatPath);
|
|
5904
|
-
if (!available) {
|
|
5905
|
-
console.error("\u274C goneat not available. Install goneat or remove --use-goneat flag.");
|
|
5906
|
-
console.error(" AJV validation (default) works without external dependencies.");
|
|
5907
|
-
process.exit(1);
|
|
5908
|
-
}
|
|
5909
|
-
const registry = getSchemaRegistry({
|
|
5910
|
-
baseDir: cmdOptions.baseDir || options.baseDir
|
|
5911
|
-
});
|
|
5912
|
-
const schema = await registry.getSchema(cmdOptions.schemaId);
|
|
5913
|
-
console.log("Using goneat validation...");
|
|
5914
|
-
result = await runGoneatValidation(schema.path, file, cmdOptions.goneatPath);
|
|
5915
|
-
} else {
|
|
5916
|
-
console.log("Using AJV validation...");
|
|
5917
|
-
result = await validateFileBySchemaId(file, cmdOptions.schemaId, {
|
|
5918
|
-
baseDir: cmdOptions.baseDir || options.baseDir
|
|
5919
|
-
});
|
|
5920
|
-
}
|
|
5921
|
-
if (result.valid) {
|
|
5922
|
-
console.log(`\u2705 Validation passed (${result.source})`);
|
|
5923
|
-
process.exit(0);
|
|
5924
|
-
} else {
|
|
5925
|
-
console.log(`\u274C Validation failed (${result.source})`);
|
|
5926
|
-
console.log("\nDiagnostics:");
|
|
5927
|
-
console.log(formatDiagnostics(result.diagnostics));
|
|
5928
|
-
process.exit(1);
|
|
5929
|
-
}
|
|
5930
|
-
} catch (error) {
|
|
5931
|
-
console.error("Error validating file:", error.message);
|
|
5932
|
-
process.exit(1);
|
|
5933
|
-
}
|
|
5934
|
-
}
|
|
5935
|
-
);
|
|
5936
|
-
program.command("validate-schema").description("Validate a schema file itself").argument("<file>", "Schema file to validate").action(async (file) => {
|
|
5937
|
-
try {
|
|
5938
|
-
const content = await readFile(file, "utf-8");
|
|
5939
|
-
const { validateSchema: validateSchema2 } = await Promise.resolve().then(() => (init_validator(), validator_exports));
|
|
5940
|
-
const result = await validateSchema2(content);
|
|
5941
|
-
if (result.valid) {
|
|
5942
|
-
console.log("\u2705 Schema is valid");
|
|
5943
|
-
process.exit(0);
|
|
5944
|
-
} else {
|
|
5945
|
-
console.log("\u274C Schema is invalid");
|
|
5946
|
-
console.log("\nDiagnostics:");
|
|
5947
|
-
console.log(formatDiagnostics(result.diagnostics));
|
|
5948
|
-
process.exit(1);
|
|
5949
|
-
}
|
|
5950
|
-
} catch (error) {
|
|
5951
|
-
console.error("Error validating schema:", error.message);
|
|
5952
|
-
process.exit(1);
|
|
5953
|
-
}
|
|
5954
|
-
});
|
|
5955
|
-
program.command("normalize").description("Normalize schema to canonical JSON format").argument("<file>", "Schema file to normalize").option("--compact", "Output compact JSON (no formatting)").option("-o, --output <file>", "Write to output file instead of stdout").action(async (file, cmdOptions) => {
|
|
5956
|
-
try {
|
|
5957
|
-
const content = await readFile(file, "utf-8");
|
|
5958
|
-
const normalized = normalizeSchema(content, {
|
|
5959
|
-
compact: cmdOptions.compact
|
|
5960
|
-
});
|
|
5961
|
-
if (cmdOptions.output) {
|
|
5962
|
-
await writeFile(cmdOptions.output, normalized, "utf-8");
|
|
5963
|
-
console.log(`\u2705 Normalized schema written to ${cmdOptions.output}`);
|
|
5964
|
-
} else {
|
|
5965
|
-
console.log(normalized);
|
|
5966
|
-
}
|
|
5967
|
-
} catch (error) {
|
|
5968
|
-
console.error("Error normalizing schema:", error.message);
|
|
5969
|
-
process.exit(1);
|
|
5970
|
-
}
|
|
5971
|
-
});
|
|
5972
|
-
program.command("compare").description("Compare two schemas for semantic equality").argument("<file1>", "First schema file").argument("<file2>", "Second schema file").option("--show-normalized", "Show normalized outputs").action(async (file1, file2, cmdOptions) => {
|
|
5973
|
-
try {
|
|
5974
|
-
const content1 = await readFile(file1, "utf-8");
|
|
5975
|
-
const content2 = await readFile(file2, "utf-8");
|
|
5976
|
-
const result = compareSchemas(content1, content2);
|
|
5977
|
-
if (result.equal) {
|
|
5978
|
-
console.log("\u2705 Schemas are semantically equal");
|
|
5979
|
-
} else {
|
|
5980
|
-
console.log("\u274C Schemas differ");
|
|
5981
|
-
}
|
|
5982
|
-
if (cmdOptions.showNormalized) {
|
|
5983
|
-
console.log("\nNormalized Schema 1:");
|
|
5984
|
-
console.log(result.normalizedA);
|
|
5985
|
-
console.log("\nNormalized Schema 2:");
|
|
5986
|
-
console.log(result.normalizedB);
|
|
5987
|
-
}
|
|
5988
|
-
process.exit(result.equal ? 0 : 1);
|
|
5989
|
-
} catch (error) {
|
|
5990
|
-
console.error("Error comparing schemas:", error.message);
|
|
5991
|
-
process.exit(1);
|
|
5992
|
-
}
|
|
5993
|
-
});
|
|
5994
|
-
program.command("export").description("Export schema from registry to file with provenance").requiredOption("--schema-id <id>", "Schema ID to export").requiredOption("--out <path>", "Output file path").option("--force", "Overwrite existing file", false).option("--no-provenance", "Exclude provenance metadata").option("--no-validate", "Skip schema validation before export").option("--format <format>", "Export format (json|yaml|auto)", "auto").option("--base-dir <path>", "Override schema base directory").action(
|
|
5995
|
-
async (cmdOptions) => {
|
|
5996
|
-
try {
|
|
5997
|
-
const { exportSchema: exportSchema2 } = await Promise.resolve().then(() => (init_export(), export_exports));
|
|
5998
|
-
const { exitCodes: exitCodes2 } = await Promise.resolve().then(() => (init_foundry(), foundry_exports));
|
|
5999
|
-
const result = await exportSchema2({
|
|
6000
|
-
schemaId: cmdOptions.schemaId,
|
|
6001
|
-
outPath: cmdOptions.out,
|
|
6002
|
-
includeProvenance: cmdOptions.provenance ?? true,
|
|
6003
|
-
validate: cmdOptions.validate ?? true,
|
|
6004
|
-
overwrite: cmdOptions.force ?? false,
|
|
6005
|
-
format: cmdOptions.format ?? "auto",
|
|
6006
|
-
baseDir: cmdOptions.baseDir || options.baseDir
|
|
6007
|
-
});
|
|
6008
|
-
console.log("\u2705 Schema exported successfully");
|
|
6009
|
-
console.log(` Schema ID: ${result.schemaId}`);
|
|
6010
|
-
console.log(` Output: ${result.outPath}`);
|
|
6011
|
-
console.log(` Format: ${result.format}`);
|
|
6012
|
-
if (result.provenance) {
|
|
6013
|
-
console.log("\nProvenance:");
|
|
6014
|
-
console.log(` Crucible: ${result.provenance.crucible_version}`);
|
|
6015
|
-
console.log(` Library: ${result.provenance.library_version}`);
|
|
6016
|
-
if (result.provenance.revision) {
|
|
6017
|
-
console.log(` Revision: ${result.provenance.revision}`);
|
|
6018
|
-
}
|
|
6019
|
-
console.log(` Exported: ${result.provenance.exported_at}`);
|
|
6020
|
-
}
|
|
6021
|
-
process.exit(exitCodes2.EXIT_SUCCESS);
|
|
6022
|
-
} catch (error) {
|
|
6023
|
-
const { exitCodes: exitCodes2 } = await Promise.resolve().then(() => (init_foundry(), foundry_exports));
|
|
6024
|
-
const { SchemaExportError: SchemaExportError2, SchemaValidationError: SchemaValidationError2, ExportErrorReason: ExportErrorReason2 } = await Promise.resolve().then(() => (init_errors2(), errors_exports));
|
|
6025
|
-
console.error("\u274C Schema export failed:", error.message);
|
|
6026
|
-
if (error instanceof SchemaExportError2) {
|
|
6027
|
-
if (error.outPath) {
|
|
6028
|
-
console.error(` Output path: ${error.outPath}`);
|
|
6029
|
-
}
|
|
6030
|
-
switch (error.reason) {
|
|
6031
|
-
case ExportErrorReason2.FILE_EXISTS:
|
|
6032
|
-
case ExportErrorReason2.WRITE_FAILED:
|
|
6033
|
-
process.exit(exitCodes2.EXIT_FILE_WRITE_ERROR);
|
|
6034
|
-
break;
|
|
6035
|
-
case ExportErrorReason2.INVALID_FORMAT:
|
|
6036
|
-
process.exit(exitCodes2.EXIT_INVALID_ARGUMENT);
|
|
6037
|
-
break;
|
|
6038
|
-
default:
|
|
6039
|
-
process.exit(exitCodes2.EXIT_FAILURE);
|
|
6040
|
-
}
|
|
6041
|
-
}
|
|
6042
|
-
if (error instanceof SchemaValidationError2) {
|
|
6043
|
-
const errorMsg = error.message.toLowerCase();
|
|
6044
|
-
if (errorMsg.includes("not found")) {
|
|
6045
|
-
process.exit(exitCodes2.EXIT_FILE_NOT_FOUND);
|
|
6046
|
-
}
|
|
6047
|
-
process.exit(exitCodes2.EXIT_DATA_INVALID);
|
|
6048
|
-
}
|
|
6049
|
-
process.exit(exitCodes2.EXIT_FAILURE);
|
|
6050
|
-
}
|
|
6051
|
-
}
|
|
6052
|
-
);
|
|
6053
|
-
program.command("identity-show").description("Show application identity from .fulmen/app.yaml").option("--path <path>", "Explicit path to app.yaml").option("--json", "Output as JSON").action(async (cmdOptions) => {
|
|
6054
|
-
try {
|
|
6055
|
-
const { loadIdentity: loadIdentity2 } = await Promise.resolve().then(() => (init_loader2(), loader_exports));
|
|
6056
|
-
const { exitCodes: exitCodes2 } = await Promise.resolve().then(() => (init_foundry(), foundry_exports));
|
|
6057
|
-
const identity = await loadIdentity2({ path: cmdOptions.path });
|
|
6058
|
-
if (cmdOptions.json) {
|
|
6059
|
-
console.log(JSON.stringify(identity, null, 2));
|
|
6060
|
-
} else {
|
|
6061
|
-
console.log("Application Identity:\n");
|
|
6062
|
-
console.log(` Binary Name: ${identity.app.binary_name}`);
|
|
6063
|
-
console.log(` Vendor: ${identity.app.vendor}`);
|
|
6064
|
-
console.log(` Env Prefix: ${identity.app.env_prefix}`);
|
|
6065
|
-
console.log(` Config Name: ${identity.app.config_name}`);
|
|
6066
|
-
console.log(` Description: ${identity.app.description}`);
|
|
6067
|
-
if (identity.metadata) {
|
|
6068
|
-
console.log("\nMetadata:");
|
|
6069
|
-
if (identity.metadata.license) {
|
|
6070
|
-
console.log(` License: ${identity.metadata.license}`);
|
|
6071
|
-
}
|
|
6072
|
-
if (identity.metadata.repository_category) {
|
|
6073
|
-
console.log(` Category: ${identity.metadata.repository_category}`);
|
|
6074
|
-
}
|
|
6075
|
-
if (identity.metadata.telemetry_namespace) {
|
|
6076
|
-
console.log(` Telemetry: ${identity.metadata.telemetry_namespace}`);
|
|
6077
|
-
}
|
|
6078
|
-
if (identity.metadata.project_url) {
|
|
6079
|
-
console.log(` Project URL: ${identity.metadata.project_url}`);
|
|
6080
|
-
}
|
|
6081
|
-
}
|
|
6082
|
-
}
|
|
6083
|
-
process.exit(exitCodes2.EXIT_SUCCESS);
|
|
6084
|
-
} catch (error) {
|
|
6085
|
-
const { exitCodes: exitCodes2 } = await Promise.resolve().then(() => (init_foundry(), foundry_exports));
|
|
6086
|
-
const { AppIdentityError: AppIdentityError2 } = await Promise.resolve().then(() => (init_errors5(), errors_exports2));
|
|
6087
|
-
console.error("\u274C Failed to load identity:", error.message);
|
|
6088
|
-
if (error instanceof AppIdentityError2) {
|
|
6089
|
-
if (error.message.includes("not found")) {
|
|
6090
|
-
process.exit(exitCodes2.EXIT_FILE_NOT_FOUND);
|
|
6091
|
-
}
|
|
6092
|
-
if (error.message.includes("Invalid") || error.message.includes("validation")) {
|
|
6093
|
-
process.exit(exitCodes2.EXIT_DATA_INVALID);
|
|
6094
|
-
}
|
|
6095
|
-
}
|
|
6096
|
-
process.exit(exitCodes2.EXIT_FAILURE);
|
|
6097
|
-
}
|
|
6098
|
-
});
|
|
6099
|
-
program.command("identity-validate").description("Validate application identity against schema").argument("[file]", "Path to app.yaml (defaults to discovery)").action(async (file) => {
|
|
6100
|
-
try {
|
|
6101
|
-
const { loadIdentity: loadIdentity2 } = await Promise.resolve().then(() => (init_loader2(), loader_exports));
|
|
6102
|
-
const { exitCodes: exitCodes2 } = await Promise.resolve().then(() => (init_foundry(), foundry_exports));
|
|
6103
|
-
console.log("Validating application identity...");
|
|
6104
|
-
const identity = await loadIdentity2({ path: file });
|
|
6105
|
-
console.log("\u2705 Identity is valid");
|
|
6106
|
-
console.log(` Binary: ${identity.app.binary_name}`);
|
|
6107
|
-
console.log(` Vendor: ${identity.app.vendor}`);
|
|
6108
|
-
process.exit(exitCodes2.EXIT_SUCCESS);
|
|
6109
|
-
} catch (error) {
|
|
6110
|
-
const { exitCodes: exitCodes2 } = await Promise.resolve().then(() => (init_foundry(), foundry_exports));
|
|
6111
|
-
const { AppIdentityError: AppIdentityError2 } = await Promise.resolve().then(() => (init_errors5(), errors_exports2));
|
|
6112
|
-
console.error("\u274C Identity validation failed:", error.message);
|
|
6113
|
-
if (error instanceof AppIdentityError2) {
|
|
6114
|
-
if (error.message.includes("not found")) {
|
|
6115
|
-
process.exit(exitCodes2.EXIT_FILE_NOT_FOUND);
|
|
6116
|
-
}
|
|
6117
|
-
if (error.message.includes("Invalid") || error.message.includes("validation")) {
|
|
6118
|
-
process.exit(exitCodes2.EXIT_DATA_INVALID);
|
|
6119
|
-
}
|
|
6120
|
-
}
|
|
6121
|
-
process.exit(exitCodes2.EXIT_FAILURE);
|
|
6122
|
-
}
|
|
6123
|
-
});
|
|
6124
|
-
return program;
|
|
6125
|
-
}
|
|
6126
|
-
var init_cli = __esm({
|
|
6127
|
-
"src/schema/cli.ts"() {
|
|
6128
|
-
init_goneat_bridge();
|
|
6129
|
-
init_normalizer();
|
|
6130
|
-
init_registry();
|
|
6131
|
-
init_utils();
|
|
6132
|
-
init_validator();
|
|
6133
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
6134
|
-
const program = createCLI();
|
|
6135
|
-
program.parse(process.argv);
|
|
6136
|
-
}
|
|
6137
|
-
}
|
|
6138
|
-
});
|
|
6139
|
-
|
|
6140
|
-
// src/schema/index.ts
|
|
6141
|
-
var init_schema = __esm({
|
|
6142
|
-
"src/schema/index.ts"() {
|
|
6143
|
-
init_ajv_formats();
|
|
6144
|
-
init_cli();
|
|
6145
|
-
init_errors2();
|
|
6146
|
-
init_export();
|
|
6147
|
-
init_goneat_bridge();
|
|
6148
|
-
init_normalizer();
|
|
6149
|
-
init_registry();
|
|
6150
|
-
init_utils();
|
|
6151
|
-
init_validator();
|
|
1809
|
+
// src/schema/index.ts
|
|
1810
|
+
var init_schema = __esm({
|
|
1811
|
+
"src/schema/index.ts"() {
|
|
1812
|
+
init_ajv_formats();
|
|
1813
|
+
init_cli();
|
|
1814
|
+
init_errors2();
|
|
1815
|
+
init_export();
|
|
1816
|
+
init_goneat_bridge();
|
|
1817
|
+
init_normalizer();
|
|
1818
|
+
init_registry();
|
|
1819
|
+
init_utils();
|
|
1820
|
+
init_validator();
|
|
6152
1821
|
}
|
|
6153
1822
|
});
|
|
6154
1823
|
|
|
@@ -6413,7 +2082,7 @@ var init_fulmen_error = __esm({
|
|
|
6413
2082
|
});
|
|
6414
2083
|
|
|
6415
2084
|
// src/errors/index.ts
|
|
6416
|
-
var
|
|
2085
|
+
var init_errors3 = __esm({
|
|
6417
2086
|
"src/errors/index.ts"() {
|
|
6418
2087
|
init_correlation();
|
|
6419
2088
|
init_fulmen_error();
|
|
@@ -6790,11 +2459,11 @@ var MonorepoMarkers = [
|
|
|
6790
2459
|
];
|
|
6791
2460
|
|
|
6792
2461
|
// src/pathfinder/finder.ts
|
|
6793
|
-
|
|
2462
|
+
init_errors3();
|
|
6794
2463
|
init_telemetry();
|
|
6795
2464
|
|
|
6796
2465
|
// src/pathfinder/errors.ts
|
|
6797
|
-
|
|
2466
|
+
init_errors3();
|
|
6798
2467
|
var PathfinderErrorCode = /* @__PURE__ */ ((PathfinderErrorCode2) => {
|
|
6799
2468
|
PathfinderErrorCode2["INVALID_CONFIG"] = "pathfinder.invalid_config";
|
|
6800
2469
|
PathfinderErrorCode2["INVALID_ROOT"] = "pathfinder.invalid_root";
|
|
@@ -7742,8 +3411,8 @@ async function assertValidPathResult(result) {
|
|
|
7742
3411
|
}
|
|
7743
3412
|
|
|
7744
3413
|
// src/pathfinder/index.ts
|
|
7745
|
-
var
|
|
3414
|
+
var VERSION = "0.1.0";
|
|
7746
3415
|
|
|
7747
|
-
export { ChecksumAlgorithm, ChecksumEncoding, ConstraintType, DEFAULT_CONFIG, DEFAULT_IGNORE_FILES, DEFAULT_MAX_DEPTH, EnforcementLevel, GitMarkers, GoModMarkers, LoaderType, MAX_PATH_LENGTH, MonorepoMarkers, NodeMarkers, PATH_SEPARATOR, Pathfinder, PathfinderErrorCode, PythonMarkers,
|
|
3416
|
+
export { ChecksumAlgorithm, ChecksumEncoding, ConstraintType, DEFAULT_CONFIG, DEFAULT_IGNORE_FILES, DEFAULT_MAX_DEPTH, EnforcementLevel, GitMarkers, GoModMarkers, LoaderType, MAX_PATH_LENGTH, MonorepoMarkers, NodeMarkers, PATH_SEPARATOR, Pathfinder, PathfinderErrorCode, PythonMarkers, VERSION, assertValidConfig, assertValidPathResult, calculateChecksum, calculateChecksumsBatch, compileConfigSchema, compilePathResultSchema, createPathfinderError, findByExtensions, findConfigFiles, findRepositoryRoot, findSchemaFiles, validateConfig, validatePathResult, withBoundary, withConstraint, withFollowSymlinks, withMaxDepth, withStopAtFirst, wrapPathfinderError };
|
|
7748
3417
|
//# sourceMappingURL=index.js.map
|
|
7749
3418
|
//# sourceMappingURL=index.js.map
|