@oml/cli 0.7.0
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/README.md +75 -0
- package/bin/cli.js +6 -0
- package/out/auth.d.ts +25 -0
- package/out/auth.js +253 -0
- package/out/auth.js.map +1 -0
- package/out/backend/backend-types.d.ts +19 -0
- package/out/backend/backend-types.js +3 -0
- package/out/backend/backend-types.js.map +1 -0
- package/out/backend/create-backend.d.ts +2 -0
- package/out/backend/create-backend.js +6 -0
- package/out/backend/create-backend.js.map +1 -0
- package/out/backend/direct-backend.d.ts +17 -0
- package/out/backend/direct-backend.js +97 -0
- package/out/backend/direct-backend.js.map +1 -0
- package/out/backend/reasoned-output.d.ts +38 -0
- package/out/backend/reasoned-output.js +568 -0
- package/out/backend/reasoned-output.js.map +1 -0
- package/out/cli.d.ts +1 -0
- package/out/cli.js +132 -0
- package/out/cli.js.map +1 -0
- package/out/commands/closure.d.ts +33 -0
- package/out/commands/closure.js +537 -0
- package/out/commands/closure.js.map +1 -0
- package/out/commands/compile.d.ts +11 -0
- package/out/commands/compile.js +63 -0
- package/out/commands/compile.js.map +1 -0
- package/out/commands/lint.d.ts +5 -0
- package/out/commands/lint.js +31 -0
- package/out/commands/lint.js.map +1 -0
- package/out/commands/reason.d.ts +13 -0
- package/out/commands/reason.js +62 -0
- package/out/commands/reason.js.map +1 -0
- package/out/commands/render.d.ts +15 -0
- package/out/commands/render.js +753 -0
- package/out/commands/render.js.map +1 -0
- package/out/commands/validate.d.ts +5 -0
- package/out/commands/validate.js +186 -0
- package/out/commands/validate.js.map +1 -0
- package/out/main.d.ts +1 -0
- package/out/main.js +4 -0
- package/out/main.js.map +1 -0
- package/out/update.d.ts +1 -0
- package/out/update.js +79 -0
- package/out/update.js.map +1 -0
- package/out/util.d.ts +10 -0
- package/out/util.js +63 -0
- package/out/util.js.map +1 -0
- package/package.json +36 -0
- package/src/auth.ts +315 -0
- package/src/backend/backend-types.ts +25 -0
- package/src/backend/create-backend.ts +8 -0
- package/src/backend/direct-backend.ts +114 -0
- package/src/backend/reasoned-output.ts +697 -0
- package/src/cli.ts +147 -0
- package/src/commands/closure.ts +624 -0
- package/src/commands/compile.ts +88 -0
- package/src/commands/lint.ts +35 -0
- package/src/commands/reason.ts +79 -0
- package/src/commands/render.ts +1021 -0
- package/src/commands/validate.ts +226 -0
- package/src/main.ts +5 -0
- package/src/update.ts +103 -0
- package/src/util.ts +83 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# OML CLI
|
|
2
|
+
|
|
3
|
+
`@oml/cli` is the command-line interface for linting, compiling, reasoning over, rendering, and validating OML workspaces.
|
|
4
|
+
|
|
5
|
+
## Package Layout
|
|
6
|
+
|
|
7
|
+
- [package.json](./package.json) - package manifest and published CLI entry
|
|
8
|
+
- [bin/cli.js](./bin/cli.js) - executable entrypoint used by the published `oml` command
|
|
9
|
+
- [src/main.ts](./src/main.ts) - TypeScript entrypoint
|
|
10
|
+
- [src/cli.ts](./src/cli.ts) - command registration and top-level CLI wiring
|
|
11
|
+
- [src/commands](./src/commands) - `lint`, `compile`, `reason`, `render`, and `validate` command implementations
|
|
12
|
+
- [src/backend](./src/backend) - shared RDF/reasoning and markdown execution support
|
|
13
|
+
|
|
14
|
+
## Instructions
|
|
15
|
+
|
|
16
|
+
Use the public npm registry for `@oml/*` packages:
|
|
17
|
+
|
|
18
|
+
```ini
|
|
19
|
+
registry=https://registry.npmjs.org/
|
|
20
|
+
@oml:registry=https://registry.npmjs.org/
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
From the repo:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
node ./packages/cli/bin/cli.js --help
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
When installed, the command name is `oml`.
|
|
30
|
+
|
|
31
|
+
### Quick Start
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Lint the current workspace
|
|
35
|
+
node ./packages/cli/bin/cli.js lint
|
|
36
|
+
|
|
37
|
+
# Compile RDF output
|
|
38
|
+
node ./packages/cli/bin/cli.js compile -w . -owl build/owl
|
|
39
|
+
|
|
40
|
+
# Check consistency only
|
|
41
|
+
node ./packages/cli/bin/cli.js reason -w . -owl build/owl --check-only
|
|
42
|
+
|
|
43
|
+
# Render markdown to static HTML
|
|
44
|
+
node ./packages/cli/bin/cli.js render -w . -md src/md -web build/web -owl build/owl
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Commands
|
|
48
|
+
|
|
49
|
+
- `login`
|
|
50
|
+
Runs GitHub device-flow sign-in, stores a local beta session, and validates it against the whitelist.
|
|
51
|
+
- `logout`
|
|
52
|
+
Removes the local beta sign-in session.
|
|
53
|
+
- `whoami`
|
|
54
|
+
Prints the current beta sign-in session and whether it is authorized.
|
|
55
|
+
- `lint [file] [-w <workspace>]`
|
|
56
|
+
Validates one file, or the current workspace when no file is given.
|
|
57
|
+
- `compile [-w <workspace>] [-owl <dir>] [-f <ttl|trig|nt|nq|n3>] [--clean] [--only] [--pretty]`
|
|
58
|
+
Compiles OML to RDF.
|
|
59
|
+
- `reason [-w <workspace>] [-owl <dir>] [-f <ttl|trig|nt|nq|n3>] [--clean] [--only] [--pretty] [--check-only] [-u <true|false>] [-e <true|false>] [-p <true|false>]`
|
|
60
|
+
Runs consistency checking and, unless `--check-only` is used, generates entailments.
|
|
61
|
+
- `render [-w <workspace>] -md <dir> -web <dir> [-owl <dir>] [-f <ttl|trig|nt|nq|n3>] [-c <model-uri>] [--clean] [--only] [--pretty] [-u <true|false>] [-e <true|false>] [-p <true|false>]`
|
|
62
|
+
Runs the compile/reason pipeline, then renders markdown to static HTML.
|
|
63
|
+
- `validate -md <dir> [-w <workspace>] [-owl <dir>] [-f <ttl|trig|nt|nq|n3>] [--clean] [--only] [--pretty] [-u <true|false>] [-e <true|false>] [-p <true|false>]`
|
|
64
|
+
Validates markdown table-editor SHACL blocks against their context models.
|
|
65
|
+
|
|
66
|
+
### Notes
|
|
67
|
+
|
|
68
|
+
- The CLI currently requires a beta sign-in session for operational commands. Run `oml login` first.
|
|
69
|
+
- GitHub device-flow login requires `OML_AUTH_GITHUB_CLIENT_ID`, unless you embed `DEFAULT_GITHUB_CLIENT_ID` in [`src/auth.ts`](./src/auth.ts).
|
|
70
|
+
- CLI beta authorization uses the same whitelist semantics as the extension. Configure the whitelist endpoint with `OML_AUTH_WHITELIST_URL`.
|
|
71
|
+
- The CLI currently depends on `@oml/reasoner@^0.1.0`.
|
|
72
|
+
- `reason` runs ontology consistency checks in dependency order.
|
|
73
|
+
- `render` runs the compile/reason pipeline unless `--only` is provided, then renders markdown, resolves `workspace:/` links, executes markdown blocks, and copies referenced non-markdown assets.
|
|
74
|
+
- If the reasoner reports an inconsistent ontology, the CLI exits with code `1` and prints the raw JSON result returned by the reasoner.
|
|
75
|
+
- When installed from npm, the CLI checks the npm registry for newer `@oml/cli` releases and prints `npm install -g @oml/cli@latest` when an update is available. Set `OML_NO_UPDATE_NOTIFIER=1` to disable the check.
|
package/bin/cli.js
ADDED
package/out/auth.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type Provider = 'github';
|
|
2
|
+
type StoredSession = {
|
|
3
|
+
provider: Provider;
|
|
4
|
+
userId: string;
|
|
5
|
+
userLabel?: string;
|
|
6
|
+
signedInAt: string;
|
|
7
|
+
};
|
|
8
|
+
type LoginOptions = {};
|
|
9
|
+
type AuthStatus = {
|
|
10
|
+
session: StoredSession;
|
|
11
|
+
authorized: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare class OmlCliAuthService {
|
|
14
|
+
private whitelistCache;
|
|
15
|
+
private whitelistCacheTime;
|
|
16
|
+
login(options: LoginOptions): Promise<void>;
|
|
17
|
+
logout(): Promise<void>;
|
|
18
|
+
whoami(): Promise<void>;
|
|
19
|
+
ensureAuthenticated(operationName: string): Promise<AuthStatus>;
|
|
20
|
+
private isAuthorized;
|
|
21
|
+
private fetchWhitelist;
|
|
22
|
+
private clearWhitelistCache;
|
|
23
|
+
private authenticate;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
package/out/auth.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// Copyright (c) 2026 Modelware. All rights reserved.
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import * as fs from 'node:fs/promises';
|
|
4
|
+
import * as os from 'node:os';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
const DEFAULT_WHITELIST_URL = 'https://www.modelware.io/oml-code/auth/permissions.json';
|
|
7
|
+
const CACHE_DURATION_MS = 5 * 60 * 1000;
|
|
8
|
+
const GITHUB_DEVICE_CODE_URL = 'https://github.com/login/device/code';
|
|
9
|
+
const GITHUB_TOKEN_URL = 'https://github.com/login/oauth/access_token';
|
|
10
|
+
const GITHUB_USER_URL = 'https://api.github.com/user';
|
|
11
|
+
const DEFAULT_GITHUB_CLIENT_ID = 'Ov23liQkHYczdOAvHp5P';
|
|
12
|
+
export class OmlCliAuthService {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.whitelistCache = null;
|
|
15
|
+
this.whitelistCacheTime = 0;
|
|
16
|
+
}
|
|
17
|
+
async login(options) {
|
|
18
|
+
const session = await this.authenticate();
|
|
19
|
+
const authorized = await this.isAuthorized(session);
|
|
20
|
+
if (!authorized) {
|
|
21
|
+
throw new Error('Sign in succeeded, but this account is not authorized.');
|
|
22
|
+
}
|
|
23
|
+
await writeSession(session);
|
|
24
|
+
const summary = session.userLabel ? `${session.userLabel} (${session.userId})` : session.userId;
|
|
25
|
+
console.error(chalk.green(`Signed in as ${summary} via ${session.provider}.`));
|
|
26
|
+
}
|
|
27
|
+
async logout() {
|
|
28
|
+
await deleteSession();
|
|
29
|
+
this.clearWhitelistCache();
|
|
30
|
+
console.error(chalk.green('Signed out.'));
|
|
31
|
+
}
|
|
32
|
+
async whoami() {
|
|
33
|
+
const session = await readSession();
|
|
34
|
+
if (!session) {
|
|
35
|
+
console.error(chalk.yellow('Not signed in.'));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const authorized = await this.isAuthorized(session);
|
|
39
|
+
console.error(`Provider: ${session.provider}`);
|
|
40
|
+
console.error(`User ID: ${session.userId}`);
|
|
41
|
+
console.error(`User label: ${session.userLabel ?? '(not set)'}`);
|
|
42
|
+
console.error(`Signed in at: ${session.signedInAt}`);
|
|
43
|
+
console.error(`Authorized: ${authorized ? 'yes' : 'no'}`);
|
|
44
|
+
}
|
|
45
|
+
async ensureAuthenticated(operationName) {
|
|
46
|
+
const session = await readSession();
|
|
47
|
+
if (!session) {
|
|
48
|
+
throw new Error(`${operationName} requires authentication. Run 'oml login' first.`);
|
|
49
|
+
}
|
|
50
|
+
const authorized = await this.isAuthorized(session);
|
|
51
|
+
if (!authorized) {
|
|
52
|
+
throw new Error(`${operationName} requires authorization. Your account is not authorized.`);
|
|
53
|
+
}
|
|
54
|
+
return { session, authorized };
|
|
55
|
+
}
|
|
56
|
+
async isAuthorized(session) {
|
|
57
|
+
const whitelist = await this.fetchWhitelist();
|
|
58
|
+
if (!whitelist) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
const userId = session.userId.toLowerCase();
|
|
62
|
+
return whitelist.has(userId);
|
|
63
|
+
}
|
|
64
|
+
async fetchWhitelist() {
|
|
65
|
+
const whitelistUrl = process.env.OML_AUTH_WHITELIST_URL ?? DEFAULT_WHITELIST_URL;
|
|
66
|
+
if (!whitelistUrl) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const now = Date.now();
|
|
70
|
+
if (this.whitelistCache && (now - this.whitelistCacheTime) < CACHE_DURATION_MS) {
|
|
71
|
+
return this.whitelistCache;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const response = await fetch(whitelistUrl);
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
77
|
+
}
|
|
78
|
+
const data = await response.json();
|
|
79
|
+
const userList = extractWhitelistEntries(data);
|
|
80
|
+
this.whitelistCache = new Set(userList.map((id) => String(id).toLowerCase()));
|
|
81
|
+
this.whitelistCacheTime = now;
|
|
82
|
+
return this.whitelistCache;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error(chalk.yellow(`OML: Could not verify authorization. ${error instanceof Error ? error.message : String(error)}`));
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
clearWhitelistCache() {
|
|
90
|
+
this.whitelistCache = null;
|
|
91
|
+
this.whitelistCacheTime = 0;
|
|
92
|
+
}
|
|
93
|
+
async authenticate() {
|
|
94
|
+
return authenticateWithGitHub();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function extractWhitelistEntries(data) {
|
|
98
|
+
if (Array.isArray(data)) {
|
|
99
|
+
return data.map((value) => String(value));
|
|
100
|
+
}
|
|
101
|
+
if (typeof data === 'object' && data !== null) {
|
|
102
|
+
const record = data;
|
|
103
|
+
if (Array.isArray(record.allowedUsers)) {
|
|
104
|
+
return record.allowedUsers.map((value) => String(value));
|
|
105
|
+
}
|
|
106
|
+
if (Array.isArray(record.users)) {
|
|
107
|
+
return record.users.map((value) => String(value));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
throw new Error('Invalid whitelist format. Expected array or object with "allowedUsers" or "users" property.');
|
|
111
|
+
}
|
|
112
|
+
async function readSession() {
|
|
113
|
+
try {
|
|
114
|
+
const content = await fs.readFile(getSessionPath(), 'utf-8');
|
|
115
|
+
const data = JSON.parse(content);
|
|
116
|
+
if (!data.userId || !data.provider || !data.signedInAt) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
if (data.provider !== 'github' && data.provider !== 'microsoft') {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
provider: data.provider,
|
|
124
|
+
userId: data.userId,
|
|
125
|
+
userLabel: data.userLabel,
|
|
126
|
+
signedInAt: data.signedInAt
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function writeSession(session) {
|
|
134
|
+
const sessionPath = getSessionPath();
|
|
135
|
+
await fs.mkdir(path.dirname(sessionPath), { recursive: true });
|
|
136
|
+
await fs.writeFile(sessionPath, `${JSON.stringify(session, null, 2)}\n`, 'utf-8');
|
|
137
|
+
}
|
|
138
|
+
async function deleteSession() {
|
|
139
|
+
try {
|
|
140
|
+
await fs.unlink(getSessionPath());
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (error.code !== 'ENOENT') {
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function getSessionPath() {
|
|
149
|
+
return path.join(os.homedir(), '.oml', 'auth.json');
|
|
150
|
+
}
|
|
151
|
+
async function authenticateWithGitHub() {
|
|
152
|
+
const clientId = resolveClientId();
|
|
153
|
+
const params = new URLSearchParams({
|
|
154
|
+
client_id: clientId,
|
|
155
|
+
scope: 'read:user'
|
|
156
|
+
});
|
|
157
|
+
const response = await fetch(GITHUB_DEVICE_CODE_URL, {
|
|
158
|
+
method: 'POST',
|
|
159
|
+
headers: {
|
|
160
|
+
accept: 'application/json',
|
|
161
|
+
'content-type': 'application/x-www-form-urlencoded'
|
|
162
|
+
},
|
|
163
|
+
body: params
|
|
164
|
+
});
|
|
165
|
+
if (!response.ok) {
|
|
166
|
+
throw new Error(`GitHub device authorization failed: HTTP ${response.status} ${response.statusText}`);
|
|
167
|
+
}
|
|
168
|
+
const device = await response.json();
|
|
169
|
+
if (!device.device_code || !device.user_code || !device.verification_uri) {
|
|
170
|
+
throw new Error('GitHub device authorization response was incomplete.');
|
|
171
|
+
}
|
|
172
|
+
printDeviceFlowInstructions('GitHub', device.verification_uri, device.user_code);
|
|
173
|
+
const token = await pollForGitHubAccessToken(clientId, device);
|
|
174
|
+
const userResponse = await fetch(GITHUB_USER_URL, {
|
|
175
|
+
headers: {
|
|
176
|
+
accept: 'application/vnd.github+json',
|
|
177
|
+
authorization: `Bearer ${token}`
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
if (!userResponse.ok) {
|
|
181
|
+
throw new Error(`GitHub user lookup failed: HTTP ${userResponse.status} ${userResponse.statusText}`);
|
|
182
|
+
}
|
|
183
|
+
const user = await userResponse.json();
|
|
184
|
+
if (!user.login) {
|
|
185
|
+
throw new Error('GitHub user lookup did not return a login name.');
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
provider: 'github',
|
|
189
|
+
userId: user.login,
|
|
190
|
+
userLabel: user.login,
|
|
191
|
+
signedInAt: new Date().toISOString()
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function printDeviceFlowInstructions(providerName, verificationUri, userCode) {
|
|
195
|
+
console.error(chalk.cyan(`${providerName} sign-in required.`));
|
|
196
|
+
console.error(`Open: ${verificationUri}`);
|
|
197
|
+
console.error(`Code: ${userCode}`);
|
|
198
|
+
}
|
|
199
|
+
async function pollForGitHubAccessToken(clientId, device) {
|
|
200
|
+
const deviceCode = device.device_code;
|
|
201
|
+
if (!deviceCode) {
|
|
202
|
+
throw new Error('GitHub device authorization response was incomplete.');
|
|
203
|
+
}
|
|
204
|
+
let intervalSeconds = Math.max(1, device.interval ?? 5);
|
|
205
|
+
while (true) {
|
|
206
|
+
await delay(intervalSeconds * 1000);
|
|
207
|
+
const params = new URLSearchParams({
|
|
208
|
+
client_id: clientId,
|
|
209
|
+
device_code: deviceCode,
|
|
210
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:device_code'
|
|
211
|
+
});
|
|
212
|
+
const response = await fetch(GITHUB_TOKEN_URL, {
|
|
213
|
+
method: 'POST',
|
|
214
|
+
headers: {
|
|
215
|
+
accept: 'application/json',
|
|
216
|
+
'content-type': 'application/x-www-form-urlencoded'
|
|
217
|
+
},
|
|
218
|
+
body: params
|
|
219
|
+
});
|
|
220
|
+
if (!response.ok) {
|
|
221
|
+
throw new Error(`GitHub token exchange failed: HTTP ${response.status} ${response.statusText}`);
|
|
222
|
+
}
|
|
223
|
+
const token = await response.json();
|
|
224
|
+
if (token.access_token) {
|
|
225
|
+
return token.access_token;
|
|
226
|
+
}
|
|
227
|
+
if (token.error === 'authorization_pending') {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (token.error === 'slow_down') {
|
|
231
|
+
intervalSeconds += 5;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (token.error === 'expired_token') {
|
|
235
|
+
throw new Error('GitHub device code expired before authorization completed.');
|
|
236
|
+
}
|
|
237
|
+
if (token.error === 'access_denied') {
|
|
238
|
+
throw new Error('GitHub sign-in was denied.');
|
|
239
|
+
}
|
|
240
|
+
throw new Error(token.error_description ?? token.error ?? 'GitHub sign-in failed.');
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function resolveClientId() {
|
|
244
|
+
const configured = process.env.OML_AUTH_GITHUB_CLIENT_ID?.trim() || DEFAULT_GITHUB_CLIENT_ID;
|
|
245
|
+
if (configured) {
|
|
246
|
+
return configured;
|
|
247
|
+
}
|
|
248
|
+
throw new Error('GitHub login is not configured. Set OML_AUTH_GITHUB_CLIENT_ID or embed DEFAULT_GITHUB_CLIENT_ID in packages/cli/src/auth.ts.');
|
|
249
|
+
}
|
|
250
|
+
function delay(ms) {
|
|
251
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=auth.js.map
|
package/out/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAErD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,SA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pB,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,IAAI,EAAE,IAAI,wBAAwB,CAAC;IAC7F,IAAI,UAAU,EAAE,CAAC;QACb,OAAO,UAAU,CAAC;IACtB,CAAC;IACD,MAAM,IAAI,KAAK,CACX,8HAA8H,CACjI,CAAC;AACN,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACrB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MdExecuteBlocksParams, MdExecuteBlocksResult } from '@oml/markdown';
|
|
2
|
+
export interface ValidateSummary {
|
|
3
|
+
filesChecked: number;
|
|
4
|
+
warnings: number;
|
|
5
|
+
}
|
|
6
|
+
export interface MarkdownRenderResult {
|
|
7
|
+
renderedHtml: string;
|
|
8
|
+
contextUri?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface CliBackendOptions {
|
|
11
|
+
owlOutputRoot?: string;
|
|
12
|
+
rdfFormat?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CliBackend {
|
|
15
|
+
validate(fileName: string | undefined, workspaceRoot: string): Promise<ValidateSummary>;
|
|
16
|
+
renderMarkdown(markdown: string): Promise<MarkdownRenderResult>;
|
|
17
|
+
executeMarkdownBlocks(params: MdExecuteBlocksParams, workspaceRoot: string): Promise<MdExecuteBlocksResult>;
|
|
18
|
+
dispose(): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend-types.js","sourceRoot":"","sources":["../../src/backend/backend-types.ts"],"names":[],"mappings":"AAAA,qDAAqD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-backend.js","sourceRoot":"","sources":["../../src/backend/create-backend.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,MAAM,UAAU,aAAa,CAAC,UAA6B,EAAE;IACzD,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type MdExecuteBlocksParams, type MdExecuteBlocksResult } from '@oml/markdown';
|
|
2
|
+
import type { CliBackend, CliBackendOptions, MarkdownRenderResult, ValidateSummary } from './backend-types.js';
|
|
3
|
+
export declare class DirectBackend implements CliBackend {
|
|
4
|
+
private readonly markdownRuntime;
|
|
5
|
+
private readonly owlOutputRoot?;
|
|
6
|
+
private readonly rdfFormat;
|
|
7
|
+
private servicesBundle?;
|
|
8
|
+
private initializedWorkspaceRoot?;
|
|
9
|
+
private loadedDatasetKey?;
|
|
10
|
+
constructor(options?: CliBackendOptions);
|
|
11
|
+
validate(fileName: string | undefined, workspaceRoot: string): Promise<ValidateSummary>;
|
|
12
|
+
renderMarkdown(markdown: string): Promise<MarkdownRenderResult>;
|
|
13
|
+
executeMarkdownBlocks(params: MdExecuteBlocksParams, workspaceRoot: string): Promise<MdExecuteBlocksResult>;
|
|
14
|
+
dispose(): Promise<void>;
|
|
15
|
+
private ensureServices;
|
|
16
|
+
private ensurePreparedDataset;
|
|
17
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Copyright (c) 2026 Modelware. All rights reserved.
|
|
2
|
+
import { createOwlServices } from '@oml/owl';
|
|
3
|
+
import { MarkdownHandlerRegistry, MarkdownPreviewRuntime } from '@oml/markdown';
|
|
4
|
+
import { MarkdownExecutor } from '@oml/markdown';
|
|
5
|
+
import { NodeFileSystem } from 'langium/node';
|
|
6
|
+
import { URI } from 'langium';
|
|
7
|
+
import * as fs from 'node:fs/promises';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
import { extractDocument } from '../util.js';
|
|
10
|
+
import { loadPreparedDatasetFromOutput, normalizeFormatExtension } from './reasoned-output.js';
|
|
11
|
+
export class DirectBackend {
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
this.markdownRuntime = new MarkdownPreviewRuntime(new MarkdownHandlerRegistry());
|
|
14
|
+
this.owlOutputRoot = options.owlOutputRoot ? path.resolve(options.owlOutputRoot) : undefined;
|
|
15
|
+
this.rdfFormat = normalizeFormatExtension(options.rdfFormat);
|
|
16
|
+
}
|
|
17
|
+
async validate(fileName, workspaceRoot) {
|
|
18
|
+
const services = await this.ensureServices(workspaceRoot);
|
|
19
|
+
if (fileName) {
|
|
20
|
+
const document = await extractDocument(fileName, services, undefined);
|
|
21
|
+
const warnings = (document.diagnostics ?? []).filter((d) => d.severity === 2).length;
|
|
22
|
+
return { filesChecked: 1, warnings };
|
|
23
|
+
}
|
|
24
|
+
const files = await findOmlFiles(workspaceRoot);
|
|
25
|
+
let warningCount = 0;
|
|
26
|
+
for (const file of files) {
|
|
27
|
+
const document = await extractDocument(file, services, undefined);
|
|
28
|
+
warningCount += (document.diagnostics ?? []).filter((d) => d.severity === 2).length;
|
|
29
|
+
}
|
|
30
|
+
return { filesChecked: files.length, warnings: warningCount };
|
|
31
|
+
}
|
|
32
|
+
async renderMarkdown(markdown) {
|
|
33
|
+
const rendered = this.markdownRuntime.prepare(markdown);
|
|
34
|
+
return {
|
|
35
|
+
renderedHtml: rendered.renderedHtml,
|
|
36
|
+
contextUri: rendered.contextUri
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async executeMarkdownBlocks(params, workspaceRoot) {
|
|
40
|
+
const services = await this.ensureServices(workspaceRoot);
|
|
41
|
+
await this.ensurePreparedDataset(workspaceRoot, services);
|
|
42
|
+
const reasoningService = services.reasoning.ReasoningService;
|
|
43
|
+
const executor = new MarkdownExecutor({
|
|
44
|
+
ensureContext: (modelUri) => reasoningService.ensureQueryContext(modelUri),
|
|
45
|
+
resolveContextIri: (modelUri) => reasoningService.getContextIri(modelUri),
|
|
46
|
+
query: (modelUri, sparql) => reasoningService.getSparqlService().query(modelUri, sparql),
|
|
47
|
+
construct: (modelUri, sparql) => reasoningService.getSparqlService().construct(modelUri, sparql),
|
|
48
|
+
});
|
|
49
|
+
return executor.executeBlocks(params);
|
|
50
|
+
}
|
|
51
|
+
async dispose() {
|
|
52
|
+
this.servicesBundle = undefined;
|
|
53
|
+
this.initializedWorkspaceRoot = undefined;
|
|
54
|
+
this.loadedDatasetKey = undefined;
|
|
55
|
+
}
|
|
56
|
+
async ensureServices(workspaceRoot) {
|
|
57
|
+
const resolvedRoot = path.resolve(workspaceRoot);
|
|
58
|
+
if (!this.servicesBundle || this.initializedWorkspaceRoot !== resolvedRoot) {
|
|
59
|
+
this.servicesBundle = createOwlServices(NodeFileSystem);
|
|
60
|
+
this.initializedWorkspaceRoot = resolvedRoot;
|
|
61
|
+
await this.servicesBundle.Oml.shared.workspace.WorkspaceManager.initializeWorkspace([
|
|
62
|
+
{ uri: URI.file(resolvedRoot).toString(), name: path.basename(resolvedRoot) }
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
return this.servicesBundle.Oml;
|
|
66
|
+
}
|
|
67
|
+
async ensurePreparedDataset(workspaceRoot, services) {
|
|
68
|
+
if (!this.owlOutputRoot) {
|
|
69
|
+
throw new Error('CLI markdown execution requires a prepared RDF output folder.');
|
|
70
|
+
}
|
|
71
|
+
const datasetKey = `${this.initializedWorkspaceRoot ?? ''}|${this.owlOutputRoot}|${this.rdfFormat}`;
|
|
72
|
+
if (this.loadedDatasetKey === datasetKey) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const prepared = await loadPreparedDatasetFromOutput(path.resolve(workspaceRoot), this.owlOutputRoot, this.rdfFormat);
|
|
76
|
+
services.reasoning.ReasoningService.loadPreparedDataset(prepared);
|
|
77
|
+
this.loadedDatasetKey = datasetKey;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function findOmlFiles(root) {
|
|
81
|
+
const entries = await fs.readdir(root, { withFileTypes: true });
|
|
82
|
+
const results = [];
|
|
83
|
+
for (const entry of entries) {
|
|
84
|
+
const fullPath = path.join(root, entry.name);
|
|
85
|
+
if (entry.isDirectory()) {
|
|
86
|
+
if (entry.name === 'node_modules' || entry.name.startsWith('.')) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
results.push(...await findOmlFiles(fullPath));
|
|
90
|
+
}
|
|
91
|
+
else if (entry.isFile() && path.extname(entry.name) === '.oml') {
|
|
92
|
+
results.push(fullPath);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return results;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=direct-backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direct-backend.js","sourceRoot":"","sources":["../../src/backend/direct-backend.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAErD,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAA0D,MAAM,eAAe,CAAC;AACzG,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,6BAA6B,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAE/F,MAAM,OAAO,aAAa;IAQtB,YAAY,UAA6B,EAAE;QAP1B,oBAAe,GAAG,IAAI,sBAAsB,CAAC,IAAI,uBAAuB,EAAE,CAAC,CAAC;QAQzF,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC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AO,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAChE,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YACtB,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC9D,SAAS;YACb,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;QAClD,CAAC;aAAM,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,MAAM,EAAE,CAAC;YAC/D,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3B,CAAC;IACL,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type OmlServices } from '@oml/language';
|
|
2
|
+
import { type PreparedReasonedModel } from '@oml/owl';
|
|
3
|
+
import { type ConsistencyResult } from '@oml/reasoner';
|
|
4
|
+
import type { LangiumDocument } from 'langium';
|
|
5
|
+
export interface WorkspaceOntologyEntry {
|
|
6
|
+
modelUri: string;
|
|
7
|
+
ontology: any;
|
|
8
|
+
ontologyIri: string;
|
|
9
|
+
imports: string[];
|
|
10
|
+
compiledPath: string;
|
|
11
|
+
entailmentPath: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ReasonWorkspaceOptions {
|
|
14
|
+
outputRoot: string;
|
|
15
|
+
format: string;
|
|
16
|
+
pretty: boolean;
|
|
17
|
+
explanations: boolean;
|
|
18
|
+
uniqueNamesAssumption: boolean;
|
|
19
|
+
checkOnly: boolean;
|
|
20
|
+
profile: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface ReasonWorkspaceResult {
|
|
23
|
+
ontologiesReasoned: number;
|
|
24
|
+
entailmentsWritten: number;
|
|
25
|
+
}
|
|
26
|
+
export declare class OntologyInconsistencyError extends Error {
|
|
27
|
+
readonly ontologyIri: string;
|
|
28
|
+
readonly result: ConsistencyResult;
|
|
29
|
+
constructor(ontologyIri: string, result: ConsistencyResult);
|
|
30
|
+
}
|
|
31
|
+
export declare function buildWorkspaceDocuments(services: OmlServices, workspaceRoot: string, validate?: boolean): Promise<LangiumDocument[]>;
|
|
32
|
+
export declare function writeCompiledWorkspace(services: OmlServices, workspaceRoot: string, outputRoot: string, format: string, pretty: boolean): Promise<WorkspaceOntologyEntry[]>;
|
|
33
|
+
export declare function collectWorkspaceOntologyEntries(documents: ReadonlyArray<LangiumDocument>, outputRoot: string, format: string): WorkspaceOntologyEntry[];
|
|
34
|
+
export declare function reasonWorkspaceOntologies(entries: ReadonlyArray<WorkspaceOntologyEntry>, options: ReasonWorkspaceOptions): Promise<ReasonWorkspaceResult>;
|
|
35
|
+
export declare function loadPreparedDatasetFromOutput(workspaceRoot: string, outputRoot: string, format: string): Promise<PreparedReasonedModel[]>;
|
|
36
|
+
export declare function normalizeFormatExtension(value: string | undefined): string;
|
|
37
|
+
export declare function resolveOutputPathFromOntologyIriString(ontologyIri: string, format: string): string;
|
|
38
|
+
export declare function normalizeNamespace(value: string | undefined): string | undefined;
|