@seed-hypermedia/client 0.0.49 → 0.0.50

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/dist/index.mjs +44 -18
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -475,34 +475,60 @@ function createSeedClient(baseUrl, options) {
475
475
  async function publishDocument(input, signer) {
476
476
  if (!input.genesis && !input.baseVersion && !input.path) {
477
477
  const genesisChange = await createGenesisChange(signer);
478
- const contentChange = await createDocumentChange(
479
- {
480
- changes: input.changes,
481
- genesisCid: genesisChange.cid,
482
- deps: [genesisChange.cid],
483
- depth: 1
484
- },
485
- signer
486
- );
487
- const ref = await createVersionRef(
478
+ const generation = input.generation != null ? Number(input.generation) : 1;
479
+ if (input.changes.every((change) => {
480
+ var _a;
481
+ return ((_a = change.op) == null ? void 0 : _a.case) === "setMetadata";
482
+ })) {
483
+ const contentChange = await createDocumentChange(
484
+ {
485
+ changes: input.changes,
486
+ genesisCid: genesisChange.cid,
487
+ deps: [genesisChange.cid],
488
+ depth: 1
489
+ },
490
+ signer
491
+ );
492
+ const ref = await createVersionRef(
493
+ {
494
+ space: input.account,
495
+ path: "",
496
+ genesis: genesisChange.cid.toString(),
497
+ version: contentChange.cid.toString(),
498
+ generation,
499
+ capability: input.capability
500
+ },
501
+ signer
502
+ );
503
+ await publish({
504
+ blobs: [
505
+ { data: genesisChange.bytes, cid: genesisChange.cid.toString() },
506
+ { data: contentChange.bytes, cid: contentChange.cid.toString() },
507
+ ...ref.blobs
508
+ ]
509
+ });
510
+ return;
511
+ }
512
+ const genesisRef = await createVersionRef(
488
513
  {
489
514
  space: input.account,
490
515
  path: "",
491
516
  genesis: genesisChange.cid.toString(),
492
- version: contentChange.cid.toString(),
493
- generation: input.generation != null ? Number(input.generation) : 1,
517
+ version: genesisChange.cid.toString(),
518
+ generation,
494
519
  capability: input.capability
495
520
  },
496
521
  signer
497
522
  );
498
523
  await publish({
499
- blobs: [
500
- { data: genesisChange.bytes, cid: genesisChange.cid.toString() },
501
- { data: contentChange.bytes, cid: contentChange.cid.toString() },
502
- ...ref.blobs
503
- ]
524
+ blobs: [{ data: genesisChange.bytes, cid: genesisChange.cid.toString() }, ...genesisRef.blobs]
504
525
  });
505
- return;
526
+ input = {
527
+ ...input,
528
+ baseVersion: genesisChange.cid.toString(),
529
+ genesis: genesisChange.cid.toString(),
530
+ generation
531
+ };
506
532
  }
507
533
  const prepareInput = {
508
534
  account: input.account,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seed-hypermedia/client",
3
- "version": "0.0.49",
3
+ "version": "0.0.50",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/seed-hypermedia/seed",