@qaecy/cue-cli 0.0.14 → 0.0.17

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 (2) hide show
  1. package/main.js +170 -70
  2. package/package.json +3 -3
package/main.js CHANGED
@@ -67,20 +67,20 @@ var init_worker_pool = __esm({
67
67
  }
68
68
  _next() {
69
69
  if (this.queue.length > 0 && this.idleWorkers.length > 0) {
70
- const { filePath, resolve, reject } = this.queue.shift();
70
+ const { filePath, resolve: resolve2, reject } = this.queue.shift();
71
71
  const worker = this.idleWorkers.pop();
72
72
  worker._currentCallback = (result) => {
73
73
  if (result.error)
74
74
  reject(new Error(result.error));
75
75
  else
76
- resolve(result.hash);
76
+ resolve2(result.hash);
77
77
  };
78
78
  worker.postMessage(filePath);
79
79
  }
80
80
  }
81
81
  hashFile(filePath) {
82
- return new Promise((resolve, reject) => {
83
- this.queue.push({ filePath, resolve, reject });
82
+ return new Promise((resolve2, reject) => {
83
+ this.queue.push({ filePath, resolve: resolve2, reject });
84
84
  this._next();
85
85
  });
86
86
  }
@@ -93,8 +93,8 @@ 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_fs6 = require("fs");
97
- var import_path4 = require("path");
96
+ var import_fs7 = require("fs");
97
+ var import_path5 = require("path");
98
98
 
99
99
  // apps/desktop/cue-cli/src/variables.ts
100
100
  var import_path = require("path");
@@ -119,7 +119,7 @@ var IGNORED_LOCAL = {
119
119
 
120
120
  // libs/js/sync-tools/src/lib/compare-local-remote.ts
121
121
  function compareLocalRemote(localFiles, remoteFiles) {
122
- return new Promise((resolve) => {
122
+ return new Promise((resolve2) => {
123
123
  const localByContentUUID = /* @__PURE__ */ new Map();
124
124
  const localBylocationUUID = /* @__PURE__ */ new Map();
125
125
  for (const lf of localFiles) {
@@ -180,7 +180,7 @@ function compareLocalRemote(localFiles, remoteFiles) {
180
180
  }
181
181
  }
182
182
  const synctPctSize = totalSize > 0 ? syncSize / totalSize : 1;
183
- resolve({
183
+ resolve2({
184
184
  localNotOnRemote,
185
185
  localNotOnRemotePathOnly,
186
186
  remoteNotOnLocal,
@@ -212,6 +212,7 @@ var BUCKET_RAW = "spaces_raw_eu_west6";
212
212
  var BUCKET_PROCESSED = "spaces_processed_eu_west6";
213
213
  var BUCKET_LOGS = "spaces_logs_eu_west6";
214
214
  var BUCKET_PUBLIC = "cue_public_eu_west6";
215
+ var BUCKET_PERSISTENCE = "db_persistence_eu_west6";
215
216
  var COLLECTION_CHAT_SESSIONS = "chatSessions";
216
217
  var COLLECTION_ORGANIZATIONS = "organizations";
217
218
  var COLLECTION_PROJECTS = "projects";
@@ -227,9 +228,10 @@ var import_firestore = require("firebase/firestore");
227
228
  var import_auth = require("firebase/auth");
228
229
  var import_app = require("firebase/app");
229
230
  var CueFirebase = class _CueFirebase {
231
+ static _instance;
232
+ _muted = true;
233
+ _emulator = false;
230
234
  constructor(config, auth, muted = false) {
231
- this._muted = true;
232
- this._emulator = false;
233
235
  this._muted = muted;
234
236
  this._init(config, auth);
235
237
  }
@@ -243,6 +245,28 @@ var CueFirebase = class _CueFirebase {
243
245
  }
244
246
  return _CueFirebase._instance;
245
247
  }
248
+ _functionAcceptTerms;
249
+ _functionEmitMessage;
250
+ _functionGetUserInfo;
251
+ _functionChangeUserRoleOnProject;
252
+ _functionInviteUserToProject;
253
+ _functionRemoveUserFromProject;
254
+ _storageProcessed;
255
+ _storageRaw;
256
+ _storageLogs;
257
+ _storageChatSessions;
258
+ _storagePublic;
259
+ _storagePersistence;
260
+ _collectionChatSessions;
261
+ _collectionOrganizations;
262
+ _collectionProjects;
263
+ _collectionRDFWriting;
264
+ _collectionAPIKeys;
265
+ _collectionUsers;
266
+ _collectionUserTermsAcceptance;
267
+ _collectionTiers;
268
+ _auth;
269
+ _app;
246
270
  get functionAcceptTerms() {
247
271
  return this._functionAcceptTerms;
248
272
  }
@@ -276,6 +300,9 @@ var CueFirebase = class _CueFirebase {
276
300
  get storagePublic() {
277
301
  return this._storagePublic;
278
302
  }
303
+ get storagePersistence() {
304
+ return this._storagePersistence;
305
+ }
279
306
  get collectionChatSessions() {
280
307
  return this._collectionChatSessions;
281
308
  }
@@ -347,6 +374,7 @@ var CueFirebase = class _CueFirebase {
347
374
  this._storageChatSessions = (0, import_storage.getStorage)(app, BUCKET_CHAT_SESSIONS);
348
375
  this._storageLogs = (0, import_storage.getStorage)(app, BUCKET_LOGS);
349
376
  this._storagePublic = (0, import_storage.getStorage)(app, BUCKET_PUBLIC);
377
+ this._storagePersistence = (0, import_storage.getStorage)(app, BUCKET_PERSISTENCE);
350
378
  this._collectionChatSessions = (0, import_firestore.collection)(
351
379
  (0, import_firestore.getFirestore)(app),
352
380
  COLLECTION_CHAT_SESSIONS
@@ -384,6 +412,8 @@ var CueFirebase = class _CueFirebase {
384
412
  throw new Error("Storage logs is not initialized");
385
413
  if (this._storagePublic === void 0)
386
414
  throw new Error("Storage public is not initialized");
415
+ if (this._storagePersistence === void 0)
416
+ throw new Error("Storage persistence is not initialized");
387
417
  if (this._app === void 0)
388
418
  throw new Error("App is not initialized");
389
419
  const functions = (0, import_functions.getFunctions)(this._app, GCP_REGION);
@@ -395,6 +425,7 @@ var CueFirebase = class _CueFirebase {
395
425
  (0, import_storage.connectStorageEmulator)(this._storageChatSessions, "localhost", 9199);
396
426
  (0, import_storage.connectStorageEmulator)(this._storageLogs, "localhost", 9199);
397
427
  (0, import_storage.connectStorageEmulator)(this._storagePublic, "localhost", 9199);
428
+ (0, import_storage.connectStorageEmulator)(this._storagePersistence, "localhost", 9199);
398
429
  if (!this._muted)
399
430
  console.info("Firebase emulators attached");
400
431
  }
@@ -3782,20 +3813,20 @@ var extractIdsFromRawPath = (filePath) => {
3782
3813
  const projectId = pathParts[0];
3783
3814
  const fileName = pathParts.pop() ?? "";
3784
3815
  const suffix = `.${fileName.split(".").pop()?.toLowerCase()}`;
3785
- const documentUUID = fileName.split(".")[0];
3816
+ const documentUUID = fileName.replace(/\.[^.]+$/, "");
3786
3817
  return { projectId, documentUUID, suffix };
3787
3818
  };
3788
3819
 
3789
3820
  // libs/js/id-builders/src/lib/md5-builder.ts
3790
3821
  var import_spark_md5 = __toESM(require("spark-md5"));
3791
3822
  async function fromReadStream(readStream) {
3792
- return new Promise((resolve, reject) => {
3823
+ return new Promise((resolve2, reject) => {
3793
3824
  const spark = new import_spark_md5.default.ArrayBuffer();
3794
3825
  readStream.on("data", (chunk) => {
3795
3826
  spark.append(chunk);
3796
3827
  });
3797
3828
  readStream.on("end", () => {
3798
- resolve(spark.end());
3829
+ resolve2(spark.end());
3799
3830
  });
3800
3831
  readStream.on("error", (err) => reject(err));
3801
3832
  });
@@ -4405,11 +4436,11 @@ async function retryWithBackoff(fn, maxRetries, delayMs, label) {
4405
4436
  }
4406
4437
  async function _doGzip(filePath) {
4407
4438
  const gzFilePath = `${filePath}.gz`;
4408
- await new Promise((resolve, reject) => {
4439
+ await new Promise((resolve2, reject) => {
4409
4440
  const gzip = (0, import_zlib.createGzip)();
4410
4441
  const source = (0, import_fs3.createReadStream)(filePath);
4411
4442
  const dest = (0, import_fs2.createWriteStream)(gzFilePath);
4412
- (0, import_promises4.pipeline)(source, gzip, dest).then(resolve).catch(reject);
4443
+ (0, import_promises4.pipeline)(source, gzip, dest).then(resolve2).catch(reject);
4413
4444
  });
4414
4445
  await (0, import_promises5.unlink)(filePath);
4415
4446
  }
@@ -5663,8 +5694,13 @@ var prefixes2 = {
5663
5694
  "xsd": prefixCC["xsd"]
5664
5695
  };
5665
5696
 
5666
- // libs/js/rdf-document-writers/src/lib/document-file.ts
5697
+ // libs/js/rdf-document-writers/src/lib/custom-template-parser.ts
5667
5698
  var import_n33 = require("n3");
5699
+ var { namedNode: namedNode3, literal: literal2 } = import_n33.DataFactory;
5700
+ var a2 = namedNode3("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
5701
+
5702
+ // libs/js/rdf-document-writers/src/lib/document-file.ts
5703
+ var import_n34 = require("n3");
5668
5704
 
5669
5705
  // libs/js/rdf-document-writers/src/lib/file-suffix.ts
5670
5706
  function getFileSuffix(filename) {
@@ -5676,17 +5712,17 @@ function getFileSuffix(filename) {
5676
5712
  }
5677
5713
 
5678
5714
  // libs/js/rdf-document-writers/src/lib/document-file.ts
5679
- var { namedNode: namedNode3, literal: literal2 } = import_n33.DataFactory;
5680
- var a2 = namedNode3("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
5715
+ var { namedNode: namedNode4, literal: literal3 } = import_n34.DataFactory;
5716
+ var a3 = namedNode4("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
5681
5717
 
5682
5718
  // libs/js/rdf-document-writers/src/lib/serialize-rdf.ts
5683
5719
  async function serializeRDF(namespace, writer) {
5684
- return new Promise((resolve, reject) => {
5720
+ return new Promise((resolve2, reject) => {
5685
5721
  writer.end((err, res) => {
5686
5722
  if (err)
5687
5723
  reject(err);
5688
- resolve(`@base <${namespace}>.
5689
- ${res}`);
5724
+ resolve2(namespace !== "" ? `@base <${namespace}>.
5725
+ ${res}` : res);
5690
5726
  });
5691
5727
  });
5692
5728
  }
@@ -5733,7 +5769,7 @@ function turtleFileMetadata(sourceFile, processorId, locationUUID, stored = fals
5733
5769
 
5734
5770
  // apps/desktop/cue-cli/src/helpers/upload-file.ts
5735
5771
  var import_promises6 = require("fs/promises");
5736
- async function uploadFile(file, spaceId, userId, providerId, verbose) {
5772
+ async function uploadFile(file, spaceId, userId, providerId) {
5737
5773
  const firebase = CueFirebase.getInstance();
5738
5774
  const rawFileMetadata = uploadedFileMetadata(
5739
5775
  file.relativePath,
@@ -5745,37 +5781,64 @@ async function uploadFile(file, spaceId, userId, providerId, verbose) {
5745
5781
  const storage = firebase.storageRaw;
5746
5782
  const fileRef = (0, import_storage5.ref)(storage, rawFileMetadata.blob_name);
5747
5783
  const fileBuffer = await (0, import_promises6.readFile)(file.fullPath);
5748
- await new Promise((resolve, reject) => {
5749
- const uploadTask = (0, import_storage5.uploadBytesResumable)(fileRef, fileBuffer, {
5750
- customMetadata: rawFileMetadata
5751
- });
5752
- uploadTask.on(
5753
- "state_changed",
5754
- null,
5755
- (error) => {
5756
- console.error("[uploadFile] Error uploading file:", {
5757
- filePath: file.fullPath,
5758
- relativePath: file.relativePath,
5759
- md5: file.md5,
5760
- blobName: rawFileMetadata.blob_name,
5761
- errorCode: error?.code,
5762
- errorMessage: error?.message,
5763
- errorPayload: error
5784
+ const maxRetries = 3;
5785
+ let attempt = 0;
5786
+ let lastError = null;
5787
+ while (attempt < maxRetries) {
5788
+ try {
5789
+ await new Promise((resolve2, reject) => {
5790
+ const uploadTask = (0, import_storage5.uploadBytesResumable)(fileRef, fileBuffer, {
5791
+ customMetadata: rawFileMetadata
5764
5792
  });
5765
- reject(error);
5766
- },
5767
- () => resolve()
5768
- );
5769
- if (!uploadTask) {
5770
- console.error("[uploadFile] Upload task could not be created:", {
5771
- filePath: file.fullPath,
5772
- relativePath: file.relativePath,
5773
- md5: file.md5,
5774
- blobName: rawFileMetadata.blob_name
5793
+ uploadTask.on(
5794
+ "state_changed",
5795
+ null,
5796
+ (error) => {
5797
+ const blobName = rawFileMetadata.blob_name;
5798
+ console.error("[uploadFile] Error uploading file:", {
5799
+ filePath: file.fullPath,
5800
+ relativePath: file.relativePath,
5801
+ md5: file.md5,
5802
+ blobName,
5803
+ blobNameLength: blobName?.length,
5804
+ blobNameIsUnusual: blobName && (blobName.length > 256 || /[^\w\-./]/.test(blobName)),
5805
+ errorCode: error?.code,
5806
+ errorMessage: error?.message,
5807
+ errorPayload: error,
5808
+ fileBufferSize: fileBuffer?.length,
5809
+ rawFileMetadataKeys: Object.keys(rawFileMetadata),
5810
+ rawFileMetadataLength: Object.keys(rawFileMetadata).length,
5811
+ attempt
5812
+ });
5813
+ reject(error);
5814
+ },
5815
+ () => resolve2()
5816
+ );
5817
+ if (!uploadTask) {
5818
+ console.error("[uploadFile] Upload task could not be created:", {
5819
+ filePath: file.fullPath,
5820
+ relativePath: file.relativePath,
5821
+ md5: file.md5,
5822
+ blobName: rawFileMetadata.blob_name,
5823
+ attempt
5824
+ });
5825
+ reject(new Error("Upload task could not be created"));
5826
+ }
5775
5827
  });
5776
- reject(new Error("Upload task could not be created"));
5828
+ lastError = null;
5829
+ break;
5830
+ } catch (err) {
5831
+ lastError = err;
5832
+ attempt++;
5833
+ if (attempt < maxRetries) {
5834
+ console.warn(`[uploadFile] Retry attempt ${attempt} for file: ${file.fullPath}`);
5835
+ await new Promise((res) => setTimeout(res, 1e3 * attempt));
5836
+ }
5777
5837
  }
5778
- });
5838
+ }
5839
+ if (lastError) {
5840
+ throw lastError;
5841
+ }
5779
5842
  return rawFileMetadata;
5780
5843
  }
5781
5844
 
@@ -5847,6 +5910,9 @@ async function publishMessage(topicName, data, useEmulator) {
5847
5910
  }
5848
5911
 
5849
5912
  // apps/desktop/cue-cli/src/cue-cli-sync.ts
5913
+ var import_promises7 = require("fs/promises");
5914
+ var import_fs6 = require("fs");
5915
+ var import_path4 = require("path");
5850
5916
  async function syncHandler(options) {
5851
5917
  const { space, path, verbose, provider, emulators, zip } = options;
5852
5918
  try {
@@ -5854,8 +5920,28 @@ async function syncHandler(options) {
5854
5920
  if (verbose)
5855
5921
  console.info("Building sync base \u23F3");
5856
5922
  const qh = async (query) => queryHandler(query, space, emulators);
5857
- const [localFiles, remoteFiles] = await Promise.all([
5858
- listLocalFiles(
5923
+ const resolvedPath = (0, import_path4.resolve)(path);
5924
+ const pathStat = await (0, import_promises7.stat)(resolvedPath);
5925
+ const isFile = pathStat.isFile();
5926
+ let localFiles;
5927
+ if (isFile) {
5928
+ if (verbose)
5929
+ console.info(`Path is a file, syncing single file: ${resolvedPath}`);
5930
+ const md5 = await fromReadStream((0, import_fs6.createReadStream)(resolvedPath));
5931
+ const relativePath = (0, import_path4.basename)(resolvedPath);
5932
+ const contentUUID = contextBasedGuid(md5);
5933
+ const locationUUID = generateFileUUID(relativePath, provider);
5934
+ localFiles = [{
5935
+ relativePath,
5936
+ fullPath: resolvedPath,
5937
+ md5,
5938
+ contentUUID,
5939
+ locationUUID,
5940
+ mtimeMs: pathStat.mtimeMs,
5941
+ size: pathStat.size
5942
+ }];
5943
+ } else {
5944
+ localFiles = await listLocalFiles(
5859
5945
  path,
5860
5946
  provider,
5861
5947
  verbose,
@@ -5863,9 +5949,9 @@ async function syncHandler(options) {
5863
5949
  IGNORED_LOCAL,
5864
5950
  HASH_WORKER_PATH,
5865
5951
  zip
5866
- ),
5867
- listRemoteFiles(space, provider, qh, verbose)
5868
- ]);
5952
+ );
5953
+ }
5954
+ const remoteFiles = await listRemoteFiles(space, provider, qh, verbose);
5869
5955
  const report = await compareLocalRemote(localFiles, remoteFiles);
5870
5956
  if (verbose) {
5871
5957
  console.info("Built sync base \u2705");
@@ -5895,22 +5981,33 @@ async function syncHandler(options) {
5895
5981
  if (verbose && report.localNotOnRemote.length)
5896
5982
  console.info("Syncing missing files \u23F3");
5897
5983
  let rdfWritten = false;
5984
+ let failedUploads = 0;
5898
5985
  for (const file of report.localNotOnRemote) {
5899
- const rawFileMetadata = await uploadFile(file, space, userId, provider, verbose);
5900
- await uploadFileRDF(file, rawFileMetadata, verbose);
5901
- syncCount += 1;
5902
- syncSize += file.size || 0;
5903
- const pct = Math.floor(syncCount / report.totalCount * 100);
5904
- if (verbose && report.totalCount > 0 && syncCount % Math.ceil(report.totalCount / 100) === 0) {
5905
- console.info(
5906
- `Progress: ${pct}% (${syncCount}/$${report.totalCount} files, ${fileSizePretty(syncSize)}/${fileSizePretty(
5907
- report.totalSize
5908
- )})`
5909
- );
5986
+ let rawFileMetadata;
5987
+ try {
5988
+ rawFileMetadata = await uploadFile(file, space, userId, provider);
5989
+ await uploadFileRDF(file, rawFileMetadata, verbose);
5990
+ syncCount += 1;
5991
+ syncSize += file.size || 0;
5992
+ const pct = Math.floor(syncCount / report.totalCount * 100);
5993
+ if (verbose && report.totalCount > 0 && syncCount % Math.ceil(report.totalCount / 100) === 0) {
5994
+ console.info(
5995
+ `Progress: ${pct}% (${syncCount}/$${report.totalCount} files, ${fileSizePretty(syncSize)}/${fileSizePretty(
5996
+ report.totalSize
5997
+ )})`
5998
+ );
5999
+ }
6000
+ rdfWritten = true;
6001
+ } catch (err) {
6002
+ failedUploads += 1;
6003
+ console.error(`[syncHandler] Failed to upload file: ${file.fullPath}`);
6004
+ if (verbose) {
6005
+ console.error("[syncHandler] Upload error details:", err);
6006
+ }
6007
+ continue;
5910
6008
  }
5911
- rdfWritten = true;
5912
6009
  }
5913
- const zipDeletePromise = zip ? deleteUnzipped(path) : Promise.resolve();
6010
+ const zipDeletePromise = zip && !isFile ? deleteUnzipped(path) : Promise.resolve();
5914
6011
  if (verbose && report.localNotOnRemotePathOnly.length)
5915
6012
  console.info(
5916
6013
  `Starting sync of missing file locations (on provider "${provider}") \u23F3`
@@ -5958,6 +6055,9 @@ async function syncHandler(options) {
5958
6055
  if (verbose) {
5959
6056
  console.info("");
5960
6057
  console.info(`Sync finished \u{1F680}\u{1F680}\u{1F680}`);
6058
+ if (failedUploads > 0) {
6059
+ console.warn(`Total files failed to upload: ${failedUploads}`);
6060
+ }
5961
6061
  }
5962
6062
  } catch (err) {
5963
6063
  console.error("Error:", err);
@@ -5968,10 +6068,10 @@ async function syncHandler(options) {
5968
6068
  // apps/desktop/cue-cli/src/main.ts
5969
6069
  var packageJson;
5970
6070
  try {
5971
- packageJson = JSON.parse((0, import_fs6.readFileSync)((0, import_path4.join)(__dirname, "package.json"), "utf8"));
6071
+ packageJson = JSON.parse((0, import_fs7.readFileSync)((0, import_path5.join)(__dirname, "package.json"), "utf8"));
5972
6072
  } catch {
5973
6073
  try {
5974
- packageJson = JSON.parse((0, import_fs6.readFileSync)((0, import_path4.join)(__dirname, "../package.json"), "utf8"));
6074
+ packageJson = JSON.parse((0, import_fs7.readFileSync)((0, import_path5.join)(__dirname, "../package.json"), "utf8"));
5975
6075
  } catch {
5976
6076
  packageJson = { version: "0.0.0" };
5977
6077
  console.warn("Could not find package.json, using fallback version");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qaecy/cue-cli",
3
- "version": "0.0.14",
3
+ "version": "0.0.17",
4
4
  "description": "Cue CLI for QAECY platform",
5
5
  "main": "main.js",
6
6
  "bin": {
@@ -20,13 +20,13 @@
20
20
  "jsonld": "8.3.3",
21
21
  "jszip": "3.10.1",
22
22
  "n3": "1.26.0",
23
- "oxigraph": "0.5.0",
23
+ "oxigraph": "0.5.3",
24
24
  "protobufjs": "7.5.4",
25
25
  "spark-md5": "3.0.2",
26
26
  "sparqljs": "3.7.3",
27
27
  "tslib": "2.3.0",
28
28
  "uuid": "9.0.0",
29
- "axios": "1.13.1"
29
+ "axios": "1.13.2"
30
30
  },
31
31
  "engines": {
32
32
  "node": ">=18"