@seed-hypermedia/client 0.0.128 → 0.0.129

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/apps.mjs CHANGED
@@ -6,8 +6,9 @@ import {
6
6
  createVersionRef
7
7
  } from "./chunk-PJ2RFT5A.mjs";
8
8
  import {
9
+ editRefGeneration,
9
10
  resolveEditableDocument
10
- } from "./chunk-MJUI4O7L.mjs";
11
+ } from "./chunk-ZRJYHORB.mjs";
11
12
  import {
12
13
  computeReplaceOps,
13
14
  createBlocksMap,
@@ -134,7 +135,7 @@ async function createDocumentUpdateBlobs({
134
135
  path: hmIdPathToEntityQueryPath(base.targetId.path),
135
136
  genesis: state.genesis,
136
137
  version: change.cid.toString(),
137
- generation: Number(ts),
138
+ generation: editRefGeneration(base.document, Number(ts)),
138
139
  capability
139
140
  },
140
141
  signer
@@ -4,10 +4,10 @@ import {
4
4
  documentContainsLinkToChild,
5
5
  documentHasSelfQuery,
6
6
  shouldAutoLinkParent
7
- } from "./chunk-BWAQAXHH.mjs";
7
+ } from "./chunk-LGJJ4V2O.mjs";
8
8
  import "./chunk-O5MHN2EO.mjs";
9
9
  import "./chunk-PJ2RFT5A.mjs";
10
- import "./chunk-MJUI4O7L.mjs";
10
+ import "./chunk-ZRJYHORB.mjs";
11
11
  import "./chunk-LVAHHQIK.mjs";
12
12
  import "./chunk-DR3HJ6BV.mjs";
13
13
  import "./chunk-QU6XHE3U.mjs";
@@ -6,8 +6,9 @@ import {
6
6
  createVersionRef
7
7
  } from "./chunk-PJ2RFT5A.mjs";
8
8
  import {
9
+ editRefGeneration,
9
10
  resolveDocumentState
10
- } from "./chunk-MJUI4O7L.mjs";
11
+ } from "./chunk-ZRJYHORB.mjs";
11
12
  import {
12
13
  entityQueryPathToHmIdPath,
13
14
  packHmId,
@@ -129,7 +130,7 @@ async function autoLinkChildToParent(opts) {
129
130
  const newDepth = state.headDepth + 1;
130
131
  const { unsignedBytes, ts } = createChangeOps({ ops, genesisCid, deps: depCids, depth: newDepth });
131
132
  const changeBlock = await createChange(unsignedBytes, signer);
132
- const generation = Number(ts);
133
+ const generation = editRefGeneration(parentDocument, Number(ts));
133
134
  const refInput = await createVersionRef(
134
135
  {
135
136
  space: account,
@@ -102,6 +102,14 @@ async function resolveEditableDocument(client, id) {
102
102
  const state = await resolveDocumentState(client, packHmId(followed.targetId));
103
103
  return { ...followed, state };
104
104
  }
105
+ function editRefGeneration(document, fresh, supersedesRedirect = false) {
106
+ var _a;
107
+ if (supersedesRedirect) return fresh;
108
+ const current = (_a = document.generationInfo) == null ? void 0 : _a.generation;
109
+ if (current === void 0 || current === null) return fresh;
110
+ const generation = Number(current);
111
+ return Number.isFinite(generation) ? generation : fresh;
112
+ }
105
113
  function computeDepths(changesResp) {
106
114
  const depthMap = /* @__PURE__ */ new Map();
107
115
  const depsMap = /* @__PURE__ */ new Map();
@@ -153,5 +161,6 @@ export {
153
161
  followRedirects,
154
162
  describeRedirect,
155
163
  followToDocument,
156
- resolveEditableDocument
164
+ resolveEditableDocument,
165
+ editRefGeneration
157
166
  };
@@ -100,6 +100,17 @@ export declare function followToDocument(client: Pick<SeedClient, 'request'>, id
100
100
  *
101
101
  * Edits at a redirected address must build the Change on the redirect target's DAG (the source
102
102
  * path has no changes of its own — `ListChanges` returns nothing for it) and publish a Version
103
- * Ref at the source path with a fresh generation, which supersedes the redirect Ref.
103
+ * Ref at the source path with a fresh generation, which supersedes the redirect Ref. Every other
104
+ * edit keeps the document's generation: see {@link editRefGeneration}.
104
105
  */
105
106
  export declare function resolveEditableDocument(client: Pick<SeedClient, 'request'>, id: UnpackedHypermediaId): Promise<EditableDocumentBase>;
107
+ /**
108
+ * The generation for the Version Ref of an edit to an existing document.
109
+ *
110
+ * A generation identifies one life of a document at a path; an edit continues that life, so its
111
+ * Ref must carry the generation the document already has. Stamping each Ref with a new timestamp
112
+ * instead opens a new generation per edit. A fresh generation (`fresh`, normally the new Change's
113
+ * timestamp) is right only when the Ref takes over a path from a redirect (`supersedesRedirect`),
114
+ * or when the document reports no generation to continue.
115
+ */
116
+ export declare function editRefGeneration(document: Pick<HMDocument, 'generationInfo'>, fresh: number, supersedesRedirect?: boolean): number;
@@ -1,15 +1,17 @@
1
1
  import {
2
2
  describeRedirect,
3
+ editRefGeneration,
3
4
  followRedirects,
4
5
  followToDocument,
5
6
  resolveDocumentState,
6
7
  resolveEditableDocument
7
- } from "./chunk-MJUI4O7L.mjs";
8
+ } from "./chunk-ZRJYHORB.mjs";
8
9
  import "./chunk-QU6XHE3U.mjs";
9
10
  import "./chunk-AHQWDCHV.mjs";
10
11
  import "./chunk-7P6ASYW6.mjs";
11
12
  export {
12
13
  describeRedirect,
14
+ editRefGeneration,
13
15
  followRedirects,
14
16
  followToDocument,
15
17
  resolveDocumentState,
package/dist/index.d.ts CHANGED
@@ -42,7 +42,7 @@ export { createBlocksMap, matchBlockIds, computeReplaceOps, hmBlockNodeToBlockNo
42
42
  export type { APIBlockNode, APIBlock } from './block-diff';
43
43
  export { autoLinkChildToParent, createAutoLinkOps, documentContainsLinkToChild, documentHasSelfQuery, shouldAutoLinkParent, } from './auto-link';
44
44
  export type { AutoLinkChildToParentOptions } from './auto-link';
45
- export { describeRedirect, followRedirects, followToDocument, resolveDocumentState, resolveEditableDocument, } from './document-state';
45
+ export { describeRedirect, followRedirects, followToDocument, editRefGeneration, resolveDocumentState, resolveEditableDocument, } from './document-state';
46
46
  export type { DocumentState, EditableDocumentBase, FollowedDocument, FollowedResource, RedirectHop, } from './document-state';
47
47
  export { editorBlockToHMBlock, editorBlocksToHMBlockNodes } from './editorblock-to-hmblock';
48
48
  export { hmBlocksToEditorContent, hmBlockToEditorBlock, annotationContains } from './hmblock-to-editorblock';
package/dist/index.mjs CHANGED
@@ -88,7 +88,7 @@ import {
88
88
  documentContainsLinkToChild,
89
89
  documentHasSelfQuery,
90
90
  shouldAutoLinkParent
91
- } from "./chunk-BWAQAXHH.mjs";
91
+ } from "./chunk-LGJJ4V2O.mjs";
92
92
  import {
93
93
  createChange,
94
94
  createChangeOps,
@@ -106,11 +106,12 @@ import {
106
106
  } from "./chunk-PJ2RFT5A.mjs";
107
107
  import {
108
108
  describeRedirect,
109
+ editRefGeneration,
109
110
  followRedirects,
110
111
  followToDocument,
111
112
  resolveDocumentState,
112
113
  resolveEditableDocument
113
- } from "./chunk-MJUI4O7L.mjs";
114
+ } from "./chunk-ZRJYHORB.mjs";
114
115
  import "./chunk-2MD3FXKB.mjs";
115
116
  import {
116
117
  computeReplaceOps,
@@ -208,6 +209,7 @@ export {
208
209
  documentHasSelfQuery,
209
210
  documentToResolvedMarkdown,
210
211
  draftFilename,
212
+ editRefGeneration,
211
213
  editorBlockToHMBlock,
212
214
  editorBlocksToHMBlockNodes,
213
215
  embeddedPdfToBlocks,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seed-hypermedia/client",
3
- "version": "0.0.128",
3
+ "version": "0.0.129",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/seed-hypermedia/seed",