@qaecy/cue-cli 0.0.21 → 0.0.22
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/main.js +100 -3
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -93,7 +93,7 @@ var init_worker_pool = __esm({
|
|
|
93
93
|
|
|
94
94
|
// apps/desktop/cue-cli/src/main.ts
|
|
95
95
|
var import_commander = require("commander");
|
|
96
|
-
var
|
|
96
|
+
var import_fs9 = require("fs");
|
|
97
97
|
var import_path5 = require("path");
|
|
98
98
|
|
|
99
99
|
// apps/desktop/cue-cli/src/variables.ts
|
|
@@ -6149,13 +6149,109 @@ async function utilRemoveRdfStarHandler(options) {
|
|
|
6149
6149
|
console.info(`Done. Removed ${removed} RDF-star triple(s). Output written to: ${output}`);
|
|
6150
6150
|
}
|
|
6151
6151
|
|
|
6152
|
+
// apps/desktop/cue-cli/src/cue-cli-util-rdf-compare.ts
|
|
6153
|
+
var import_fs8 = require("fs");
|
|
6154
|
+
|
|
6155
|
+
// libs/js/rdf-compare/src/lib/js-rdf-compare.ts
|
|
6156
|
+
var import_n37 = require("n3");
|
|
6157
|
+
var import_jsonld = require("jsonld");
|
|
6158
|
+
function parseTurtle(content) {
|
|
6159
|
+
return new Promise((resolve2, reject) => {
|
|
6160
|
+
const parser = new import_n37.Parser({ format: "Turtle" });
|
|
6161
|
+
const quads = [];
|
|
6162
|
+
parser.parse(content, (error, quad2) => {
|
|
6163
|
+
if (error)
|
|
6164
|
+
reject(error);
|
|
6165
|
+
else if (quad2)
|
|
6166
|
+
quads.push(quad2);
|
|
6167
|
+
else
|
|
6168
|
+
resolve2(quads);
|
|
6169
|
+
});
|
|
6170
|
+
});
|
|
6171
|
+
}
|
|
6172
|
+
function quadsToNQuads(quads) {
|
|
6173
|
+
return new Promise((resolve2, reject) => {
|
|
6174
|
+
const writer = new import_n37.Writer({ format: "N-Quads" });
|
|
6175
|
+
writer.addQuads(quads);
|
|
6176
|
+
writer.end((error, result) => {
|
|
6177
|
+
if (error)
|
|
6178
|
+
reject(error);
|
|
6179
|
+
else
|
|
6180
|
+
resolve2(result);
|
|
6181
|
+
});
|
|
6182
|
+
});
|
|
6183
|
+
}
|
|
6184
|
+
async function canonicalTriples(turtleContent) {
|
|
6185
|
+
const quads = await parseTurtle(turtleContent);
|
|
6186
|
+
const nquads = await quadsToNQuads(quads);
|
|
6187
|
+
const canonized = await (0, import_jsonld.canonize)(nquads, {
|
|
6188
|
+
algorithm: "URDNA2015",
|
|
6189
|
+
inputFormat: "application/n-quads",
|
|
6190
|
+
format: "application/n-quads"
|
|
6191
|
+
});
|
|
6192
|
+
return new Set(
|
|
6193
|
+
canonized.split("\n").map((t) => t.trim()).filter((t) => t !== "")
|
|
6194
|
+
);
|
|
6195
|
+
}
|
|
6196
|
+
async function compareTTL(file1Content, file2Content) {
|
|
6197
|
+
const [triples1, triples2] = await Promise.all([
|
|
6198
|
+
canonicalTriples(file1Content),
|
|
6199
|
+
canonicalTriples(file2Content)
|
|
6200
|
+
]);
|
|
6201
|
+
const triplesOnlyInFile1 = new Set(
|
|
6202
|
+
[...triples1].filter((x) => !triples2.has(x))
|
|
6203
|
+
);
|
|
6204
|
+
const triplesOnlyInFile2 = new Set(
|
|
6205
|
+
[...triples2].filter((x) => !triples1.has(x))
|
|
6206
|
+
);
|
|
6207
|
+
return {
|
|
6208
|
+
triplesOnlyInFile1,
|
|
6209
|
+
triplesOnlyInFile2,
|
|
6210
|
+
file1TripleCount: triples1.size,
|
|
6211
|
+
file2TripleCount: triples2.size
|
|
6212
|
+
};
|
|
6213
|
+
}
|
|
6214
|
+
|
|
6215
|
+
// apps/desktop/cue-cli/src/cue-cli-util-rdf-compare.ts
|
|
6216
|
+
async function utilRdfCompareHandler(options) {
|
|
6217
|
+
const { file1, file2, verbose } = options;
|
|
6218
|
+
if (verbose)
|
|
6219
|
+
console.info(`File 1: ${file1}`);
|
|
6220
|
+
if (verbose)
|
|
6221
|
+
console.info(`File 2: ${file2}`);
|
|
6222
|
+
const content1 = (0, import_fs8.readFileSync)(file1, "utf8");
|
|
6223
|
+
const content2 = (0, import_fs8.readFileSync)(file2, "utf8");
|
|
6224
|
+
const result = await compareTTL(content1, content2);
|
|
6225
|
+
console.info(`File 1 triple count: ${result.file1TripleCount}`);
|
|
6226
|
+
console.info(`File 2 triple count: ${result.file2TripleCount}`);
|
|
6227
|
+
if (result.triplesOnlyInFile1.size === 0 && result.triplesOnlyInFile2.size === 0) {
|
|
6228
|
+
console.info("Files are semantically equivalent.");
|
|
6229
|
+
return;
|
|
6230
|
+
}
|
|
6231
|
+
if (result.triplesOnlyInFile1.size > 0) {
|
|
6232
|
+
console.info(`
|
|
6233
|
+
Triples only in file 1 (${result.triplesOnlyInFile1.size}):`);
|
|
6234
|
+
for (const triple of result.triplesOnlyInFile1) {
|
|
6235
|
+
console.info(` ${triple}`);
|
|
6236
|
+
}
|
|
6237
|
+
}
|
|
6238
|
+
if (result.triplesOnlyInFile2.size > 0) {
|
|
6239
|
+
console.info(`
|
|
6240
|
+
Triples only in file 2 (${result.triplesOnlyInFile2.size}):`);
|
|
6241
|
+
for (const triple of result.triplesOnlyInFile2) {
|
|
6242
|
+
console.info(` ${triple}`);
|
|
6243
|
+
}
|
|
6244
|
+
}
|
|
6245
|
+
process.exitCode = 1;
|
|
6246
|
+
}
|
|
6247
|
+
|
|
6152
6248
|
// apps/desktop/cue-cli/src/main.ts
|
|
6153
6249
|
var packageJson;
|
|
6154
6250
|
try {
|
|
6155
|
-
packageJson = JSON.parse((0,
|
|
6251
|
+
packageJson = JSON.parse((0, import_fs9.readFileSync)((0, import_path5.join)(__dirname, "package.json"), "utf8"));
|
|
6156
6252
|
} catch {
|
|
6157
6253
|
try {
|
|
6158
|
-
packageJson = JSON.parse((0,
|
|
6254
|
+
packageJson = JSON.parse((0, import_fs9.readFileSync)((0, import_path5.join)(__dirname, "../package.json"), "utf8"));
|
|
6159
6255
|
} catch {
|
|
6160
6256
|
packageJson = { version: "0.0.0" };
|
|
6161
6257
|
console.warn("Could not find package.json, using fallback version");
|
|
@@ -6168,5 +6264,6 @@ program.command("dump").description("Dump Cue Knowledge Graph data to file\n
|
|
|
6168
6264
|
program.command("compare").description("Compares folder content to files already updated to Cue").requiredOption("-s, --space <id>", "Specify the space ID (required)").requiredOption("-p, --path <id>", "Specify the folder path (required)").option("-k, --key <api-key>", "Specify the API key (or set CUE_API_KEY env variable)").option("--provider <provider ID>", "Specify the provider ID (eg. sharepoint, drive, dropbox) or leave empty for default provider", "").option("-v, --verbose", "Enable verbose output", false).option("-e, --emulators", "Uses emulators for sync", false).option("-z, --zip", "Include zipped content (will temporarily unzip files with same logic as when syncing and delete them again after the comparison)", false).action(compareHandler);
|
|
6169
6265
|
program.command("dump-processed").description("Dump processed files to local folder").requiredOption("-s, --space <id>", "Specify the space ID (required)").requiredOption("-p, --processor <id>", "Id of the processor to dump processed files from (required) [eg. writers-blob, processors-cad-files]").option("-k, --key <api-key>", "Specify the API key (or set CUE_API_KEY env variable)").option("-v, --verbose", "Enable verbose output", false).option("-e, --emulators", "Uses emulators for sync", false).action(dumpProcessedHandler);
|
|
6170
6266
|
program.command("repair-ttl").description("Repair TTL files in the specified space").requiredOption("-s, --space <id>", "Specify the space ID (required)").requiredOption("-p, --processor <id>", "Id of the processor to repair TTL files (required) [eg. writers-blob, processors-cad-files]").requiredOption("-f, --from <subString>", "Substring (Regex) to replace in the TTL file (required)").requiredOption("-t, --to <substituteString>", "Substring to replace in the TTL file (required)").option("-k, --key <api-key>", "Specify the API key (or set CUE_API_KEY env variable)").option("-v, --verbose", "Enable verbose output", false).option("-e, --emulators", "Uses emulators for sync", false).action(repairTtlHandler);
|
|
6267
|
+
program.command("util-rdf-compare").description("Compare two Turtle (.ttl) files and report semantic differences").requiredOption("--file1 <path>", "Path to the first TTL file").requiredOption("--file2 <path>", "Path to the second TTL file").option("-v, --verbose", "Enable verbose output", false).action(utilRdfCompareHandler);
|
|
6171
6268
|
program.command("util-remove-rdf-star").description("Remove RDF-star (quoted) triples from an NQuads file. Supports .nq and .nq.gz input/output.").requiredOption("-i, --input <path>", "Input file path (.nq or .nq.gz)").requiredOption("-o, --output <path>", "Output file path (.nq or .nq.gz)").option("-v, --verbose", "Enable verbose output", false).action(utilRemoveRdfStarHandler);
|
|
6172
6269
|
program.parse(process.argv);
|