cobolx-2 1.2.3
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/.github/pull_request_template.md +9 -0
- package/.github/workflows/ci.yml +18 -0
- package/.vscode/launch.json +19 -0
- package/.vscode/tasks.json +14 -0
- package/CHANGELOG.md +16 -0
- package/CONTRIBUTING.md +23 -0
- package/CargoX.lock +2 -0
- package/LICENSE +21 -0
- package/README.md +164 -0
- package/api-demo/CargoX.lock +1 -0
- package/api-demo/README.md +3 -0
- package/api-demo/benchmarks/arith.cbx +6 -0
- package/api-demo/cobolx.toml +6 -0
- package/api-demo/docs-output/index.html +1 -0
- package/api-demo/generated/LEGACYDEMO.cbx +5 -0
- package/api-demo/generated/client-types.ts +2 -0
- package/api-demo/generated/deploy.json +12 -0
- package/api-demo/generated/flowchart.mmd +4 -0
- package/api-demo/migrations/20260411215238_init.sql +1 -0
- package/api-demo/src/main.cbx +5 -0
- package/api-demo/tests/smoke.cbx +6 -0
- package/benchmarks/arithmetic.cbx +6 -0
- package/cargox/package.json +11 -0
- package/cargox/src/index.d.ts +4 -0
- package/cargox/src/index.js +5 -0
- package/cargox/src/index.js.map +1 -0
- package/cargox/src/index.ts +4 -0
- package/cargox/src/lockfile/index.d.ts +1 -0
- package/cargox/src/lockfile/index.js +9 -0
- package/cargox/src/lockfile/index.js.map +1 -0
- package/cargox/src/lockfile/index.ts +9 -0
- package/cargox/src/manifest.d.ts +10 -0
- package/cargox/src/manifest.js +49 -0
- package/cargox/src/manifest.js.map +1 -0
- package/cargox/src/manifest.ts +58 -0
- package/cargox/src/registry/index.d.ts +4 -0
- package/cargox/src/registry/index.js +13 -0
- package/cargox/src/registry/index.js.map +1 -0
- package/cargox/src/registry/index.ts +13 -0
- package/cargox/src/resolver/index.d.ts +5 -0
- package/cargox/src/resolver/index.js +4 -0
- package/cargox/src/resolver/index.js.map +1 -0
- package/cargox/src/resolver/index.ts +8 -0
- package/cargox/tsconfig.json +7 -0
- package/cli/cobolx-cli/package.json +23 -0
- package/cli/cobolx-cli/src/commands/add.ts +18 -0
- package/cli/cobolx-cli/src/commands/bench.ts +47 -0
- package/cli/cobolx-cli/src/commands/build.ts +74 -0
- package/cli/cobolx-cli/src/commands/check.ts +24 -0
- package/cli/cobolx-cli/src/commands/debug.ts +15 -0
- package/cli/cobolx-cli/src/commands/debug_rewind.ts +16 -0
- package/cli/cobolx-cli/src/commands/deploy.ts +18 -0
- package/cli/cobolx-cli/src/commands/dev.ts +24 -0
- package/cli/cobolx-cli/src/commands/doc.ts +19 -0
- package/cli/cobolx-cli/src/commands/fmt.ts +14 -0
- package/cli/cobolx-cli/src/commands/fuzz.ts +24 -0
- package/cli/cobolx-cli/src/commands/generate.ts +38 -0
- package/cli/cobolx-cli/src/commands/install.ts +25 -0
- package/cli/cobolx-cli/src/commands/legacy.ts +17 -0
- package/cli/cobolx-cli/src/commands/lint.ts +17 -0
- package/cli/cobolx-cli/src/commands/migrate.ts +27 -0
- package/cli/cobolx-cli/src/commands/new.ts +20 -0
- package/cli/cobolx-cli/src/commands/profile.ts +8 -0
- package/cli/cobolx-cli/src/commands/publish.ts +16 -0
- package/cli/cobolx-cli/src/commands/repl.ts +30 -0
- package/cli/cobolx-cli/src/commands/run.ts +22 -0
- package/cli/cobolx-cli/src/commands/task.ts +27 -0
- package/cli/cobolx-cli/src/commands/test.ts +44 -0
- package/cli/cobolx-cli/src/commands/update.ts +30 -0
- package/cli/cobolx-cli/src/commands/visualize.ts +25 -0
- package/cli/cobolx-cli/src/index.ts +101 -0
- package/cli/cobolx-cli/src/project.ts +74 -0
- package/cli/cobolx-cli/tsconfig.json +7 -0
- package/cobolx.toml +7 -0
- package/compiler/package.json +14 -0
- package/compiler/src/ast/types.d.ts +87 -0
- package/compiler/src/ast/types.js +2 -0
- package/compiler/src/ast/types.js.map +1 -0
- package/compiler/src/ast/types.ts +329 -0
- package/compiler/src/backend/custom.d.ts +8 -0
- package/compiler/src/backend/custom.js +12 -0
- package/compiler/src/backend/custom.js.map +1 -0
- package/compiler/src/backend/custom.ts +21 -0
- package/compiler/src/borrow_checker/checker.d.ts +3 -0
- package/compiler/src/borrow_checker/checker.js +82 -0
- package/compiler/src/borrow_checker/checker.js.map +1 -0
- package/compiler/src/borrow_checker/checker.ts +100 -0
- package/compiler/src/codegen/javascript.d.ts +2 -0
- package/compiler/src/codegen/javascript.js +89 -0
- package/compiler/src/codegen/javascript.js.map +1 -0
- package/compiler/src/codegen/javascript.ts +175 -0
- package/compiler/src/const_eval/evaluator.ts +58 -0
- package/compiler/src/diagnostics.d.ts +11 -0
- package/compiler/src/diagnostics.js +14 -0
- package/compiler/src/diagnostics.js.map +1 -0
- package/compiler/src/diagnostics.ts +20 -0
- package/compiler/src/hir/lower.d.ts +7 -0
- package/compiler/src/hir/lower.js +44 -0
- package/compiler/src/hir/lower.js.map +1 -0
- package/compiler/src/hir/lower.ts +60 -0
- package/compiler/src/hir/types.d.ts +21 -0
- package/compiler/src/hir/types.js +2 -0
- package/compiler/src/hir/types.js.map +1 -0
- package/compiler/src/hir/types.ts +26 -0
- package/compiler/src/index.d.ts +22 -0
- package/compiler/src/index.js +84 -0
- package/compiler/src/index.js.map +1 -0
- package/compiler/src/index.ts +122 -0
- package/compiler/src/lexer/lexer.d.ts +21 -0
- package/compiler/src/lexer/lexer.js +207 -0
- package/compiler/src/lexer/lexer.js.map +1 -0
- package/compiler/src/lexer/lexer.ts +274 -0
- package/compiler/src/lexer/tokens.d.ts +8 -0
- package/compiler/src/lexer/tokens.js +18 -0
- package/compiler/src/lexer/tokens.js.map +1 -0
- package/compiler/src/lexer/tokens.ts +126 -0
- package/compiler/src/macros/expand.ts +75 -0
- package/compiler/src/main.ts +4 -0
- package/compiler/src/mir/lower.d.ts +3 -0
- package/compiler/src/mir/lower.js +10 -0
- package/compiler/src/mir/lower.js.map +1 -0
- package/compiler/src/mir/lower.ts +12 -0
- package/compiler/src/mir/types.d.ts +13 -0
- package/compiler/src/mir/types.js +2 -0
- package/compiler/src/mir/types.js.map +1 -0
- package/compiler/src/mir/types.ts +16 -0
- package/compiler/src/optimizer/constantFold.d.ts +2 -0
- package/compiler/src/optimizer/constantFold.js +61 -0
- package/compiler/src/optimizer/constantFold.js.map +1 -0
- package/compiler/src/optimizer/constantFold.ts +109 -0
- package/compiler/src/parser/parser.d.ts +33 -0
- package/compiler/src/parser/parser.js +323 -0
- package/compiler/src/parser/parser.js.map +1 -0
- package/compiler/src/parser/parser.ts +710 -0
- package/compiler/src/plugins/api.ts +8 -0
- package/compiler/src/plugins/loader.ts +21 -0
- package/compiler/src/semantic/analyzer.d.ts +12 -0
- package/compiler/src/semantic/analyzer.js +144 -0
- package/compiler/src/semantic/analyzer.js.map +1 -0
- package/compiler/src/semantic/analyzer.ts +277 -0
- package/compiler/src/type_system/checker.d.ts +7 -0
- package/compiler/src/type_system/checker.js +84 -0
- package/compiler/src/type_system/checker.js.map +1 -0
- package/compiler/src/type_system/checker.ts +108 -0
- package/compiler/tsconfig.json +7 -0
- package/debugger/package.json +11 -0
- package/debugger/src/index.d.ts +1 -0
- package/debugger/src/index.js +9 -0
- package/debugger/src/index.js.map +1 -0
- package/debugger/src/index.ts +9 -0
- package/debugger/tsconfig.json +7 -0
- package/docs/CHANGELOG.md +11 -0
- package/docs/CONTRIBUTING.md +15 -0
- package/docs/LICENSE +21 -0
- package/docs/architecture.md +29 -0
- package/docs/cli.md +58 -0
- package/docs/language-spec.md +49 -0
- package/docs/packages.md +19 -0
- package/docs/platform-systems.md +31 -0
- package/docs/release-validation.md +22 -0
- package/docs/runtime.md +10 -0
- package/docs/tooling.md +17 -0
- package/docs/vscode-extension.md +40 -0
- package/enterprise-demo/CargoX.lock +2 -0
- package/enterprise-demo/README.md +3 -0
- package/enterprise-demo/benchmarks/arith.cbx +6 -0
- package/enterprise-demo/cobolx.toml +7 -0
- package/enterprise-demo/src/main.cbx +5 -0
- package/enterprise-demo/tests/smoke.cbx +6 -0
- package/examples/README.md +20 -0
- package/examples/actors-and-flags.md +8 -0
- package/examples/api-server/README.md +9 -0
- package/examples/api-server/cobolx.toml +6 -0
- package/examples/api-server/src/main.cbx +8 -0
- package/examples/debug-replay.md +7 -0
- package/examples/debugging-demo/README.md +3 -0
- package/examples/debugging-demo/cobolx.toml +6 -0
- package/examples/debugging-demo/src/main.cbx +7 -0
- package/examples/distributed-service.md +12 -0
- package/examples/distributed-system/README.md +3 -0
- package/examples/distributed-system/cobolx.toml +6 -0
- package/examples/distributed-system/generated/deploy.json +12 -0
- package/examples/distributed-system/src/main.cbx +6 -0
- package/examples/event-driven.md +5 -0
- package/examples/event-system/README.md +3 -0
- package/examples/event-system/cobolx.toml +6 -0
- package/examples/event-system/src/main.cbx +11 -0
- package/examples/functions.cbx +10 -0
- package/examples/functions.mjs +12 -0
- package/examples/hello.cbx +5 -0
- package/examples/hello.mjs +7 -0
- package/examples/legacy-sample.cob +5 -0
- package/examples/parallel-processing/README.md +3 -0
- package/examples/parallel-processing/cobolx.toml +6 -0
- package/examples/parallel-processing/src/main.cbx +6 -0
- package/examples/parallel-processing.md +8 -0
- package/examples/platform-features.cbx +32 -0
- package/examples/platform-features.mjs +35 -0
- package/examples/service.cbx +10 -0
- package/examples/workflow-engine/README.md +3 -0
- package/examples/workflow-engine/cobolx.toml +6 -0
- package/examples/workflow-engine/generated/flowchart.mmd +8 -0
- package/examples/workflow-engine/src/main.cbx +13 -0
- package/examples/workflow-engine.md +5 -0
- package/formatter/package.json +14 -0
- package/formatter/src/index.d.ts +1 -0
- package/formatter/src/index.js +59 -0
- package/formatter/src/index.js.map +1 -0
- package/formatter/src/index.ts +103 -0
- package/formatter/tsconfig.json +7 -0
- package/generated/LEGACYDEMO.cbx +5 -0
- package/install.ps1 +4 -0
- package/install.sh +5 -0
- package/linter/package.json +14 -0
- package/linter/src/index.d.ts +2 -0
- package/linter/src/index.js +18 -0
- package/linter/src/index.js.map +1 -0
- package/linter/src/index.ts +19 -0
- package/linter/tsconfig.json +7 -0
- package/lsp/server/package.json +16 -0
- package/lsp/server/src/index.ts +168 -0
- package/lsp/server/tsconfig.json +7 -0
- package/package.json +30 -0
- package/profiler/package.json +11 -0
- package/profiler/src/index.d.ts +5 -0
- package/profiler/src/index.js +11 -0
- package/profiler/src/index.js.map +1 -0
- package/profiler/src/index.ts +11 -0
- package/profiler/tsconfig.json +7 -0
- package/release.json +10 -0
- package/runtime/package.json +14 -0
- package/runtime/src/actors/index.ts +27 -0
- package/runtime/src/async/futures.ts +11 -0
- package/runtime/src/code_as_data/index.ts +5 -0
- package/runtime/src/config/index.ts +17 -0
- package/runtime/src/distributed/index.ts +13 -0
- package/runtime/src/events/index.ts +21 -0
- package/runtime/src/feature_flags/index.ts +9 -0
- package/runtime/src/gc_or_arc/index.ts +1 -0
- package/runtime/src/healing/index.ts +26 -0
- package/runtime/src/index.ts +20 -0
- package/runtime/src/intents/index.ts +9 -0
- package/runtime/src/iterators/index.ts +23 -0
- package/runtime/src/memory/arc.ts +22 -0
- package/runtime/src/observability/index.ts +23 -0
- package/runtime/src/repl/context.ts +7 -0
- package/runtime/src/scheduler/taskScheduler.ts +11 -0
- package/runtime/src/security/capabilities.ts +15 -0
- package/runtime/src/security/secrets.ts +13 -0
- package/runtime/src/state/versioned.ts +31 -0
- package/runtime/src/std_hooks/audit.ts +23 -0
- package/runtime/src/time_travel/index.ts +54 -0
- package/runtime/src/workflows/index.ts +35 -0
- package/runtime/tsconfig.json +7 -0
- package/sample-payroll/README.md +3 -0
- package/sample-payroll/cobolx.toml +3 -0
- package/sample-payroll/src/main.cbx +5 -0
- package/stdlib/business/index.js +15 -0
- package/stdlib/core/README.md +8 -0
- package/stdlib/core/runtime.js +191 -0
- package/stdlib/crypto/index.js +5 -0
- package/stdlib/datetime/index.js +3 -0
- package/stdlib/fs/index.js +9 -0
- package/stdlib/http/index.js +7 -0
- package/stdlib/io/index.js +1 -0
- package/stdlib/json/index.js +7 -0
- package/stdlib/net/index.js +4 -0
- package/tests/macros.cbx +10 -0
- package/tests/pattern_match.cbx +16 -0
- package/tests/smoke.cbx +7 -0
- package/tests/validate-release.mjs +54 -0
- package/tsconfig.base.json +24 -0
- package/vscode-extension/LICENSE +21 -0
- package/vscode-extension/README.md +47 -0
- package/vscode-extension/cobolx-1.2.0.vsix +0 -0
- package/vscode-extension/icon.png +0 -0
- package/vscode-extension/icon.svg +15 -0
- package/vscode-extension/language-configuration.json +17 -0
- package/vscode-extension/package.json +148 -0
- package/vscode-extension/snippets/cobolx.code-snippets +49 -0
- package/vscode-extension/src/extension.ts +283 -0
- package/vscode-extension/syntaxes/cobolx.tmLanguage.json +75 -0
- package/vscode-extension/tests/test.cbl +3 -0
- package/vscode-extension/tsconfig.json +7 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CompletionItemKind,
|
|
3
|
+
createConnection,
|
|
4
|
+
DiagnosticSeverity,
|
|
5
|
+
Hover,
|
|
6
|
+
InitializeParams,
|
|
7
|
+
ProposedFeatures,
|
|
8
|
+
TextDocuments,
|
|
9
|
+
TextDocumentSyncKind
|
|
10
|
+
} from "vscode-languageserver/node.js";
|
|
11
|
+
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
12
|
+
import { analyzeSource, CobolxError } from "@cobolx/compiler";
|
|
13
|
+
|
|
14
|
+
const connection = createConnection(ProposedFeatures.all);
|
|
15
|
+
const documents = new TextDocuments(TextDocument);
|
|
16
|
+
|
|
17
|
+
const KEYWORD_COMPLETIONS = [
|
|
18
|
+
"PROGRAM",
|
|
19
|
+
"BEGIN",
|
|
20
|
+
"END",
|
|
21
|
+
"SET",
|
|
22
|
+
"DISPLAY",
|
|
23
|
+
"INPUT",
|
|
24
|
+
"IF",
|
|
25
|
+
"THEN",
|
|
26
|
+
"ELSE",
|
|
27
|
+
"END-IF",
|
|
28
|
+
"FUNCTION",
|
|
29
|
+
"RETURN",
|
|
30
|
+
"END-FUNCTION",
|
|
31
|
+
"TRUE",
|
|
32
|
+
"FALSE"
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
connection.onInitialize((_params: InitializeParams) => ({
|
|
36
|
+
capabilities: {
|
|
37
|
+
textDocumentSync: TextDocumentSyncKind.Incremental,
|
|
38
|
+
completionProvider: {},
|
|
39
|
+
hoverProvider: true
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
documents.onDidChangeContent(({ document }) => {
|
|
44
|
+
validateDocument(document);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
documents.onDidOpen(({ document }) => {
|
|
48
|
+
validateDocument(document);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
connection.onCompletion(() =>
|
|
52
|
+
KEYWORD_COMPLETIONS.map((label) => ({
|
|
53
|
+
label,
|
|
54
|
+
kind: CompletionItemKind.Keyword
|
|
55
|
+
}))
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
connection.onHover(({ textDocument, position }): Hover | null => {
|
|
59
|
+
const document = documents.get(textDocument.uri);
|
|
60
|
+
if (!document) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const word = getWordAt(document, position.line, position.character);
|
|
65
|
+
if (!word) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const keywordDocs: Record<string, string> = {
|
|
70
|
+
PROGRAM: "Declares the program name.",
|
|
71
|
+
BEGIN: "Starts the executable body.",
|
|
72
|
+
END: "Ends the program body.",
|
|
73
|
+
SET: "Assigns a variable from an expression.",
|
|
74
|
+
DISPLAY: "Prints a value to standard output.",
|
|
75
|
+
INPUT: "Reads a value from standard input.",
|
|
76
|
+
IF: "Starts a conditional block.",
|
|
77
|
+
THEN: "Separates an IF condition from its body.",
|
|
78
|
+
ELSE: "Starts the fallback branch of an IF block.",
|
|
79
|
+
"END-IF": "Closes an IF block.",
|
|
80
|
+
FUNCTION: "Declares a reusable function.",
|
|
81
|
+
RETURN: "Returns a value from a function.",
|
|
82
|
+
"END-FUNCTION": "Closes a function block."
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const uppercase = word.toUpperCase();
|
|
86
|
+
if (keywordDocs[uppercase]) {
|
|
87
|
+
return {
|
|
88
|
+
contents: {
|
|
89
|
+
kind: "markdown",
|
|
90
|
+
value: `**${uppercase}**\n\n${keywordDocs[uppercase]}`
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
contents: {
|
|
97
|
+
kind: "markdown",
|
|
98
|
+
value: `Identifier \`${word}\``
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
async function validateDocument(document: TextDocument): Promise<void> {
|
|
104
|
+
try {
|
|
105
|
+
const result = analyzeSource(document.getText());
|
|
106
|
+
connection.sendDiagnostics({
|
|
107
|
+
uri: document.uri,
|
|
108
|
+
diagnostics: result.diagnostics.map((diagnostic) => ({
|
|
109
|
+
severity: diagnostic.severity === "warning" ? DiagnosticSeverity.Warning : DiagnosticSeverity.Error,
|
|
110
|
+
range: {
|
|
111
|
+
start: {
|
|
112
|
+
line: diagnostic.range.start.line - 1,
|
|
113
|
+
character: diagnostic.range.start.column - 1
|
|
114
|
+
},
|
|
115
|
+
end: {
|
|
116
|
+
line: diagnostic.range.end.line - 1,
|
|
117
|
+
character: diagnostic.range.end.column - 1
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
message: diagnostic.message,
|
|
121
|
+
source: "cobolx"
|
|
122
|
+
}))
|
|
123
|
+
});
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (error instanceof CobolxError) {
|
|
126
|
+
connection.sendDiagnostics({
|
|
127
|
+
uri: document.uri,
|
|
128
|
+
diagnostics: [
|
|
129
|
+
{
|
|
130
|
+
severity: DiagnosticSeverity.Error,
|
|
131
|
+
range: {
|
|
132
|
+
start: {
|
|
133
|
+
line: error.diagnostic.range.start.line - 1,
|
|
134
|
+
character: error.diagnostic.range.start.column - 1
|
|
135
|
+
},
|
|
136
|
+
end: {
|
|
137
|
+
line: error.diagnostic.range.end.line - 1,
|
|
138
|
+
character: error.diagnostic.range.end.column - 1
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
message: error.diagnostic.message,
|
|
142
|
+
source: "cobolx"
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
connection.console.error(String(error));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function getWordAt(document: TextDocument, line: number, character: number): string | null {
|
|
153
|
+
const text = document.getText();
|
|
154
|
+
const lines = text.split(/\r?\n/);
|
|
155
|
+
const current = lines[line] ?? "";
|
|
156
|
+
const matches = current.matchAll(/[A-Za-z_-][A-Za-z0-9_-]*/g);
|
|
157
|
+
for (const match of matches) {
|
|
158
|
+
const start = match.index ?? 0;
|
|
159
|
+
const end = start + match[0].length;
|
|
160
|
+
if (character >= start && character <= end) {
|
|
161
|
+
return match[0];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
documents.listen(connection);
|
|
168
|
+
connection.listen();
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cobolx-2",
|
|
3
|
+
"version": "1.2.3",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"workspaces": [
|
|
7
|
+
"compiler",
|
|
8
|
+
"runtime",
|
|
9
|
+
"cargox",
|
|
10
|
+
"cli/cobolx-cli",
|
|
11
|
+
"lsp/server",
|
|
12
|
+
"vscode-extension",
|
|
13
|
+
"formatter",
|
|
14
|
+
"linter",
|
|
15
|
+
"debugger",
|
|
16
|
+
"profiler"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "npm run build --workspaces",
|
|
20
|
+
"check": "npm run check --workspaces",
|
|
21
|
+
"clean": "npm run clean --workspaces --if-present",
|
|
22
|
+
"test": "node cli/cobolx-cli/dist/index.js test",
|
|
23
|
+
"bench": "node cli/cobolx-cli/dist/index.js bench",
|
|
24
|
+
"validate": "node tests/validate-release.mjs"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^24.6.0",
|
|
28
|
+
"typescript": "^5.9.3"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cobolx/profiler",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc -p tsconfig.json",
|
|
8
|
+
"check": "tsc -p tsconfig.json --noEmit",
|
|
9
|
+
"clean": "if (Test-Path dist) { Remove-Item -Recurse -Force dist }"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { performance } from "node:perf_hooks";
|
|
2
|
+
export async function profile(label, action) {
|
|
3
|
+
const start = performance.now();
|
|
4
|
+
const result = await Promise.resolve(action());
|
|
5
|
+
return {
|
|
6
|
+
label,
|
|
7
|
+
durationMs: performance.now() - start,
|
|
8
|
+
result
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,OAAO,CAAI,KAAa,EAAE,MAA4B;IAC1E,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/C,OAAO;QACL,KAAK;QACL,UAAU,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK;QACrC,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { performance } from "node:perf_hooks";
|
|
2
|
+
|
|
3
|
+
export async function profile<T>(label: string, action: () => Promise<T> | T): Promise<{ label: string; durationMs: number; result: T }> {
|
|
4
|
+
const start = performance.now();
|
|
5
|
+
const result = await Promise.resolve(action());
|
|
6
|
+
return {
|
|
7
|
+
label,
|
|
8
|
+
durationMs: performance.now() - start,
|
|
9
|
+
result
|
|
10
|
+
};
|
|
11
|
+
}
|
package/release.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cobolx/runtime",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "powershell -NoProfile -Command \"if (Test-Path dist) { Remove-Item -Recurse -Force dist }; tsc -p tsconfig.json; if (Test-Path 'dist\\\\runtime\\\\src') { Copy-Item -Recurse -Force 'dist\\\\runtime\\\\src\\\\*' dist }\"",
|
|
8
|
+
"check": "tsc -p tsconfig.json --noEmit",
|
|
9
|
+
"clean": "if (Test-Path dist) { Remove-Item -Recurse -Force dist }"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@cobolx/compiler": "0.2.0"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type Handler = (message: unknown) => void | Promise<void>;
|
|
2
|
+
|
|
3
|
+
export class Actor {
|
|
4
|
+
private readonly mailbox: unknown[] = [];
|
|
5
|
+
private busy = false;
|
|
6
|
+
|
|
7
|
+
constructor(public readonly name: string, private readonly handler: Handler) {}
|
|
8
|
+
|
|
9
|
+
send(message: unknown): void {
|
|
10
|
+
this.mailbox.push(message);
|
|
11
|
+
void this.drain();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
private async drain(): Promise<void> {
|
|
15
|
+
if (this.busy) return;
|
|
16
|
+
this.busy = true;
|
|
17
|
+
while (this.mailbox.length > 0) {
|
|
18
|
+
const message = this.mailbox.shift();
|
|
19
|
+
await this.handler(message);
|
|
20
|
+
}
|
|
21
|
+
this.busy = false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createActor(name: string, handler: Handler): Actor {
|
|
26
|
+
return new Actor(name, handler);
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ConfigDefinition<T> {
|
|
2
|
+
key: string;
|
|
3
|
+
defaultValue?: T;
|
|
4
|
+
env?: string;
|
|
5
|
+
parser?: (value: string) => T;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function readConfig<T>(definition: ConfigDefinition<T>): T {
|
|
9
|
+
const envValue = definition.env ? process.env[definition.env] : undefined;
|
|
10
|
+
if (envValue !== undefined) {
|
|
11
|
+
return definition.parser ? definition.parser(envValue) : (envValue as T);
|
|
12
|
+
}
|
|
13
|
+
if (definition.defaultValue !== undefined) {
|
|
14
|
+
return definition.defaultValue;
|
|
15
|
+
}
|
|
16
|
+
throw new Error(`Missing configuration value for ${definition.key}`);
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const registry = new Map<string, string>();
|
|
2
|
+
|
|
3
|
+
export function registerService(name: string, address: string): void {
|
|
4
|
+
registry.set(name, address);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function discoverService(name: string): string | undefined {
|
|
8
|
+
return registry.get(name);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function listServices(): Record<string, string> {
|
|
12
|
+
return Object.fromEntries(registry.entries());
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type EventHandler<T = unknown> = (payload: T) => Promise<void> | void;
|
|
2
|
+
|
|
3
|
+
export class EventBus {
|
|
4
|
+
private readonly handlers = new Map<string, EventHandler[]>();
|
|
5
|
+
|
|
6
|
+
on<T>(eventName: string, handler: EventHandler<T>): void {
|
|
7
|
+
const existing = this.handlers.get(eventName) ?? [];
|
|
8
|
+
existing.push(handler as EventHandler);
|
|
9
|
+
this.handlers.set(eventName, existing);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async emit<T>(eventName: string, payload: T): Promise<void> {
|
|
13
|
+
for (const handler of this.handlers.get(eventName) ?? []) {
|
|
14
|
+
await handler(payload);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createEventBus(): EventBus {
|
|
20
|
+
return new EventBus();
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ArcBox } from "../memory/arc.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class Supervisor {
|
|
2
|
+
constructor(private readonly maxRetries = 3) {}
|
|
3
|
+
|
|
4
|
+
async run(name: string, task: () => Promise<void> | void): Promise<void> {
|
|
5
|
+
let attempt = 0;
|
|
6
|
+
while (attempt <= this.maxRetries) {
|
|
7
|
+
try {
|
|
8
|
+
await Promise.resolve(task());
|
|
9
|
+
return;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
attempt += 1;
|
|
12
|
+
if (attempt > this.maxRetries) throw new Error(`Supervisor failed '${name}': ${String(error)}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface HealthStatus {
|
|
19
|
+
name: string;
|
|
20
|
+
healthy: boolean;
|
|
21
|
+
details?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function healthCheck(name: string, healthy: boolean, details?: Record<string, unknown>): HealthStatus {
|
|
25
|
+
return { name, healthy, details };
|
|
26
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { ArcBox } from "./memory/arc.js";
|
|
2
|
+
export { TaskScheduler } from "./scheduler/taskScheduler.js";
|
|
3
|
+
export { futureOf } from "./async/futures.js";
|
|
4
|
+
export { audit, getAuditTrail } from "./std_hooks/audit.js";
|
|
5
|
+
export { readConfig } from "./config/index.js";
|
|
6
|
+
export { log, incrementMetric, getMetrics, trace, getTraces } from "./observability/index.js";
|
|
7
|
+
export { setFeatureFlag, featureEnabled } from "./feature_flags/index.js";
|
|
8
|
+
export { getSecret, setSecret } from "./security/secrets.js";
|
|
9
|
+
export type { DatabaseCapability, FileCapability, NetworkCapability, SecretCapability } from "./security/capabilities.js";
|
|
10
|
+
export { Actor, createActor } from "./actors/index.js";
|
|
11
|
+
export { discoverService, listServices, registerService } from "./distributed/index.js";
|
|
12
|
+
export { createReplContext } from "./repl/context.js";
|
|
13
|
+
export { CobolxIterator, iter } from "./iterators/index.js";
|
|
14
|
+
export { TimeTravelDebugger, loadTimeline } from "./time_travel/index.js";
|
|
15
|
+
export { EventBus, createEventBus } from "./events/index.js";
|
|
16
|
+
export { WorkflowEngine } from "./workflows/index.js";
|
|
17
|
+
export { Supervisor, healthCheck } from "./healing/index.js";
|
|
18
|
+
export { VersionedState } from "./state/versioned.js";
|
|
19
|
+
export { normalizeIntent } from "./intents/index.js";
|
|
20
|
+
export { inspectProgram } from "./code_as_data/index.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class CobolxIterator<T> {
|
|
2
|
+
constructor(private readonly items: T[]) {}
|
|
3
|
+
|
|
4
|
+
map<U>(fn: (value: T) => U): CobolxIterator<U> {
|
|
5
|
+
return new CobolxIterator(this.items.map(fn));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
filter(fn: (value: T) => boolean): CobolxIterator<T> {
|
|
9
|
+
return new CobolxIterator(this.items.filter(fn));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
reduce<U>(fn: (acc: U, value: T) => U, initial: U): U {
|
|
13
|
+
return this.items.reduce(fn, initial);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
collect(): T[] {
|
|
17
|
+
return [...this.items];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function iter<T>(items: T[]): CobolxIterator<T> {
|
|
22
|
+
return new CobolxIterator(items);
|
|
23
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class ArcBox<T> {
|
|
2
|
+
private refs = 1;
|
|
3
|
+
|
|
4
|
+
constructor(private value: T) {}
|
|
5
|
+
|
|
6
|
+
clone(): ArcBox<T> {
|
|
7
|
+
this.refs += 1;
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
strongCount(): number {
|
|
12
|
+
return this.refs;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
release(): void {
|
|
16
|
+
this.refs = Math.max(0, this.refs - 1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get(): T {
|
|
20
|
+
return this.value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const metrics = new Map<string, number>();
|
|
2
|
+
const traces: Array<{ name: string; at: string; details?: Record<string, unknown> }> = [];
|
|
3
|
+
|
|
4
|
+
export function log(level: "INFO" | "WARN" | "ERROR", message: string, details?: Record<string, unknown>): void {
|
|
5
|
+
const payload = { level, message, details, at: new Date().toISOString() };
|
|
6
|
+
console.log(JSON.stringify(payload));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function incrementMetric(name: string, value = 1): void {
|
|
10
|
+
metrics.set(name, (metrics.get(name) ?? 0) + value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getMetrics(): Record<string, number> {
|
|
14
|
+
return Object.fromEntries(metrics.entries());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function trace(name: string, details?: Record<string, unknown>): void {
|
|
18
|
+
traces.push({ name, details, at: new Date().toISOString() });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getTraces(): Array<{ name: string; at: string; details?: Record<string, unknown> }> {
|
|
22
|
+
return [...traces];
|
|
23
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Task<T = unknown> = () => Promise<T> | T;
|
|
2
|
+
|
|
3
|
+
export class TaskScheduler {
|
|
4
|
+
async run<T>(task: Task<T>): Promise<T> {
|
|
5
|
+
return await Promise.resolve(task());
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async all<T>(tasks: Array<Task<T>>): Promise<T[]> {
|
|
9
|
+
return await Promise.all(tasks.map((task) => this.run(task)));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const secrets = new Map<string, string>();
|
|
2
|
+
|
|
3
|
+
export function setSecret(name: string, value: string): void {
|
|
4
|
+
secrets.set(name, value);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function getSecret(name: string): string {
|
|
8
|
+
const value = secrets.get(name) ?? process.env[name];
|
|
9
|
+
if (!value) {
|
|
10
|
+
throw new Error(`Secret '${name}' not found`);
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface VersionedSnapshot<T> {
|
|
2
|
+
version: number;
|
|
3
|
+
value: T;
|
|
4
|
+
at: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class VersionedState<T> {
|
|
8
|
+
private version = 0;
|
|
9
|
+
private history: VersionedSnapshot<T>[] = [];
|
|
10
|
+
|
|
11
|
+
constructor(initial: T) {
|
|
12
|
+
this.set(initial);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
set(value: T): void {
|
|
16
|
+
this.history.push({ version: this.version, value: structuredClone(value), at: new Date().toISOString() });
|
|
17
|
+
this.version += 1;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
current(): VersionedSnapshot<T> {
|
|
21
|
+
return this.history[this.history.length - 1];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
rollback(version: number): VersionedSnapshot<T> | undefined {
|
|
25
|
+
return this.history.find((item) => item.version === version);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
timeline(): VersionedSnapshot<T>[] {
|
|
29
|
+
return [...this.history];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface AuditRecord {
|
|
2
|
+
category: string;
|
|
3
|
+
action: string;
|
|
4
|
+
at: string;
|
|
5
|
+
details?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const records: AuditRecord[] = [];
|
|
9
|
+
|
|
10
|
+
export function audit(category: string, action: string, details?: Record<string, unknown>): AuditRecord {
|
|
11
|
+
const record: AuditRecord = {
|
|
12
|
+
category,
|
|
13
|
+
action,
|
|
14
|
+
at: new Date().toISOString(),
|
|
15
|
+
details
|
|
16
|
+
};
|
|
17
|
+
records.push(record);
|
|
18
|
+
return record;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getAuditTrail(): AuditRecord[] {
|
|
22
|
+
return [...records];
|
|
23
|
+
}
|