@fileverse/api 0.0.9 → 0.0.10

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/dist/worker.js CHANGED
@@ -969,6 +969,29 @@ var init_events_model = __esm({
969
969
  `;
970
970
  await QueryBuilder.execute(sql, [Date.now(), _id]);
971
971
  }
972
+ static async markSubmitted(_id) {
973
+ const sql = `
974
+ UPDATE ${this.TABLE}
975
+ SET status = 'submitted',
976
+ lockedAt = NULL
977
+ WHERE _id = ?
978
+ `;
979
+ await QueryBuilder.execute(sql, [_id]);
980
+ }
981
+ static async findNextSubmitted(lockedFileIds) {
982
+ const exclusionClause = lockedFileIds.length > 0 ? `AND fileId NOT IN (${lockedFileIds.map(() => "?").join(", ")})` : "";
983
+ const sql = `
984
+ SELECT * FROM ${this.TABLE}
985
+ WHERE status = 'submitted'
986
+ AND userOpHash IS NOT NULL
987
+ ${exclusionClause}
988
+ ORDER BY timestamp ASC
989
+ LIMIT 1
990
+ `;
991
+ const params = [...lockedFileIds];
992
+ const row = await QueryBuilder.selectOne(sql, params);
993
+ return row ? this.parseEvent(row) : void 0;
994
+ }
972
995
  static async markProcessed(_id) {
973
996
  const sql = `
974
997
  UPDATE ${this.TABLE}
@@ -2726,6 +2749,56 @@ var init_file_manager = __esm({
2726
2749
  metadata
2727
2750
  };
2728
2751
  }
2752
+ async submitUpdateFile(file) {
2753
+ logger.debug(`Submitting update for file ${file.ddocId} with onChainFileId ${file.onChainFileId}`);
2754
+ const { encryptedSecretKey, nonce, secretKey } = await generateLinkKeyMaterial({
2755
+ ddocId: file.ddocId,
2756
+ linkKey: file.linkKey,
2757
+ linkKeyNonce: file.linkKeyNonce
2758
+ });
2759
+ const yjsContent = markdownToYjs(file.content);
2760
+ const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
2761
+ const commentKey = toUint8Array2(file.commentKey);
2762
+ const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
2763
+ const linkLock = buildLinklock(secretKey, toUint8Array2(key), commentKey);
2764
+ const encryptedTitle = await encryptTitleWithFileKey({
2765
+ title: file.title || "Untitled",
2766
+ key
2767
+ });
2768
+ const metadata = buildFileMetadata({
2769
+ encryptedTitle,
2770
+ encryptedFileSize: encryptedFile.size,
2771
+ appLock,
2772
+ ownerLock,
2773
+ ddocId: file.ddocId,
2774
+ nonce: fromUint8Array2(nonce),
2775
+ owner: this.agentClient.getAgentAddress()
2776
+ });
2777
+ const authParams = await this.getAuthParams();
2778
+ const { metadataHash, contentHash, gateHash } = await uploadAllFilesToIPFS(
2779
+ { metadata, encryptedFile, linkLock, ddocId: file.ddocId },
2780
+ authParams
2781
+ );
2782
+ const callData = prepareCallData({
2783
+ metadataHash,
2784
+ contentHash,
2785
+ gateHash,
2786
+ appFileId: file.ddocId,
2787
+ fileId: file.onChainFileId
2788
+ });
2789
+ const userOpHash = await this.sendFileOperation(callData);
2790
+ logger.debug(`Submitted update user op for file ${file.ddocId}`);
2791
+ return { userOpHash, metadata };
2792
+ }
2793
+ async submitDeleteFile(file) {
2794
+ logger.debug(`Submitting delete for file ${file.ddocId} with onChainFileId ${file.onChainFileId}`);
2795
+ const callData = prepareDeleteFileCallData({
2796
+ onChainFileId: file.onChainFileId
2797
+ });
2798
+ const userOpHash = await this.sendFileOperation(callData);
2799
+ logger.debug(`Submitted delete user op for file ${file.ddocId}`);
2800
+ return { userOpHash };
2801
+ }
2729
2802
  async updateFile(file) {
2730
2803
  logger.debug(`Updating file ${file.ddocId} with onChainFileId ${file.onChainFileId}`);
2731
2804
  const { encryptedSecretKey, nonce, secretKey } = await generateLinkKeyMaterial({
@@ -2829,6 +2902,7 @@ var init_publish = __esm({
2829
2902
  init_smart_agent();
2830
2903
  init_file_manager();
2831
2904
  init_config();
2905
+ init_pimlico_utils();
2832
2906
  createFileManager = async (portalSeed, portalAddress, ucanSecret, privateAccountKey) => {
2833
2907
  const keyPair = ucans2.EdKeypair.fromSecretKey(fromUint8Array3(ucanSecret), {
2834
2908
  exportable: true
@@ -3421,7 +3495,7 @@ CREATE TABLE IF NOT EXISTS events (
3421
3495
  type TEXT NOT NULL CHECK (type IN ('create', 'update', 'delete')),
3422
3496
  timestamp BIGINT NOT NULL,
3423
3497
  fileId TEXT NOT NULL,
3424
- status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'processed', 'failed')),
3498
+ status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'submitted', 'processed', 'failed')),
3425
3499
  retryCount INTEGER NOT NULL DEFAULT 0,
3426
3500
  lastError TEXT,
3427
3501
  lockedAt BIGINT,