@qaecy/cue-cli 0.0.17 → 0.0.19

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.
Files changed (3) hide show
  1. package/main.js +88 -3
  2. package/package.json +1 -1
  3. package/readme.md +14 -0
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 import_fs7 = require("fs");
96
+ var import_fs8 = require("fs");
97
97
  var import_path5 = require("path");
98
98
 
99
99
  // apps/desktop/cue-cli/src/variables.ts
@@ -6065,13 +6065,97 @@ async function syncHandler(options) {
6065
6065
  }
6066
6066
  }
6067
6067
 
6068
+ // apps/desktop/cue-cli/src/cue-cli-util-remove-rdf-star.ts
6069
+ var import_fs7 = require("fs");
6070
+ var import_zlib2 = require("zlib");
6071
+
6072
+ // libs/js/rdf-tools/src/lib/nq-to-nt.ts
6073
+ var import_n35 = require("n3");
6074
+ var { quad, defaultGraph } = import_n35.DataFactory;
6075
+
6076
+ // libs/js/rdf-tools/src/lib/remove-rdf-star.ts
6077
+ var import_n36 = require("n3");
6078
+ var import_stream2 = require("stream");
6079
+ function isRDFStarTerm(term) {
6080
+ return term.termType === "Quad";
6081
+ }
6082
+ function removeRDFStar(inputStream, starCount) {
6083
+ const parser = new import_n36.Parser({ format: "N-Quads*" });
6084
+ const outputStream = new import_stream2.PassThrough();
6085
+ const writer = new import_n36.StreamWriter({ format: "N-Quads" });
6086
+ writer.pipe(outputStream);
6087
+ let count = 0;
6088
+ parser.parse(inputStream, (error, quad2, prefixes3) => {
6089
+ if (error) {
6090
+ outputStream.emit("error", error);
6091
+ writer.end();
6092
+ return;
6093
+ }
6094
+ if (quad2) {
6095
+ if (!isRDFStarTerm(quad2.subject) && !isRDFStarTerm(quad2.object)) {
6096
+ writer.write(quad2);
6097
+ } else if (starCount) {
6098
+ count++;
6099
+ starCount(count);
6100
+ }
6101
+ } else {
6102
+ console.log("Finished processing input stream of RDF*, ending writer.");
6103
+ writer.end();
6104
+ }
6105
+ });
6106
+ return outputStream;
6107
+ }
6108
+
6109
+ // apps/desktop/cue-cli/src/cue-cli-util-remove-rdf-star.ts
6110
+ async function utilRemoveRdfStarHandler(options) {
6111
+ const { input, output, verbose } = options;
6112
+ const isGzipped = input.endsWith(".gz");
6113
+ if (verbose)
6114
+ console.info(`Input: ${input} (${isGzipped ? "gzipped" : "plain"})`);
6115
+ if (verbose)
6116
+ console.info(`Output: ${output}`);
6117
+ const fileStream = (0, import_fs7.createReadStream)(input);
6118
+ const inputStream = isGzipped ? fileStream.pipe((0, import_zlib2.createGunzip)()) : fileStream;
6119
+ let removed = 0;
6120
+ const cleanStream = removeRDFStar(inputStream, (count) => {
6121
+ removed = count;
6122
+ if (verbose && count % 1e3 === 0) {
6123
+ console.info(`Removed RDF-star triples so far: ${count}`);
6124
+ }
6125
+ });
6126
+ const writeStream = (0, import_fs7.createWriteStream)(output);
6127
+ if (isGzipped) {
6128
+ const gzip = (0, import_zlib2.createGzip)();
6129
+ gzip.pipe(writeStream);
6130
+ for await (const chunk of cleanStream) {
6131
+ gzip.write(chunk);
6132
+ }
6133
+ gzip.end();
6134
+ await new Promise((resolve2, reject) => {
6135
+ writeStream.on("finish", resolve2);
6136
+ writeStream.on("error", reject);
6137
+ gzip.on("error", reject);
6138
+ });
6139
+ } else {
6140
+ for await (const chunk of cleanStream) {
6141
+ writeStream.write(chunk);
6142
+ }
6143
+ writeStream.end();
6144
+ await new Promise((resolve2, reject) => {
6145
+ writeStream.on("finish", resolve2);
6146
+ writeStream.on("error", reject);
6147
+ });
6148
+ }
6149
+ console.info(`Done. Removed ${removed} RDF-star triple(s). Output written to: ${output}`);
6150
+ }
6151
+
6068
6152
  // apps/desktop/cue-cli/src/main.ts
6069
6153
  var packageJson;
6070
6154
  try {
6071
- packageJson = JSON.parse((0, import_fs7.readFileSync)((0, import_path5.join)(__dirname, "package.json"), "utf8"));
6155
+ packageJson = JSON.parse((0, import_fs8.readFileSync)((0, import_path5.join)(__dirname, "package.json"), "utf8"));
6072
6156
  } catch {
6073
6157
  try {
6074
- packageJson = JSON.parse((0, import_fs7.readFileSync)((0, import_path5.join)(__dirname, "../package.json"), "utf8"));
6158
+ packageJson = JSON.parse((0, import_fs8.readFileSync)((0, import_path5.join)(__dirname, "../package.json"), "utf8"));
6075
6159
  } catch {
6076
6160
  packageJson = { version: "0.0.0" };
6077
6161
  console.warn("Could not find package.json, using fallback version");
@@ -6084,4 +6168,5 @@ program.command("dump").description("Dump Cue Knowledge Graph data to file\n
6084
6168
  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);
6085
6169
  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);
6086
6170
  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);
6171
+ 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);
6087
6172
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qaecy/cue-cli",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "Cue CLI for QAECY platform",
5
5
  "main": "main.js",
6
6
  "bin": {
package/readme.md CHANGED
@@ -32,3 +32,17 @@ To sync the current dir to the space with id `<space-id>` under the provider id
32
32
  | `-v, --verbose` | Enable verbose output | `false` |
33
33
  | `-e, --emulators` | Use emulators for sync | `false` |
34
34
  | `-z, --zip` | Include zipped content. Will be unzipped to `<zip_path>_unzipped`. Max uncompressed size: 500 MB, max recursion depth: 3. Cleans up unzipped files after sync. | `false` |
35
+
36
+ ### util-remove-rdf-star
37
+
38
+ Remove RDF-star (quoted triple) statements from an NQuads file. Supports both plain `.nq` and gzipped `.nq.gz` files. If the input is gzipped the output will also be gzipped.
39
+
40
+ `npx @qaecy/cue-cli util-remove-rdf-star -i <input.nq.gz> -o <output.nq.gz> -v`
41
+
42
+ #### Options
43
+
44
+ | Option | Description | Default |
45
+ |----------------------|-----------------------------------------|---------|
46
+ | `-i, --input <path>` | Input file path (`.nq` or `.nq.gz`) (required) | N/A |
47
+ | `-o, --output <path>`| Output file path (`.nq` or `.nq.gz`) (required) | N/A |
48
+ | `-v, --verbose` | Enable verbose output | `false` |