@dxos/versioning 0.10.0

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 (38) hide show
  1. package/dist/lib/browser/index.mjs +417 -0
  2. package/dist/lib/browser/index.mjs.map +7 -0
  3. package/dist/lib/browser/meta.json +1 -0
  4. package/dist/lib/node-esm/index.mjs +418 -0
  5. package/dist/lib/node-esm/index.mjs.map +7 -0
  6. package/dist/lib/node-esm/meta.json +1 -0
  7. package/dist/types/src/Branch.d.ts +3 -0
  8. package/dist/types/src/Branch.d.ts.map +1 -0
  9. package/dist/types/src/History.d.ts +3 -0
  10. package/dist/types/src/History.d.ts.map +1 -0
  11. package/dist/types/src/Version.d.ts +3 -0
  12. package/dist/types/src/Version.d.ts.map +1 -0
  13. package/dist/types/src/diff.d.ts +35 -0
  14. package/dist/types/src/diff.d.ts.map +1 -0
  15. package/dist/types/src/diff.test.d.ts +2 -0
  16. package/dist/types/src/diff.test.d.ts.map +1 -0
  17. package/dist/types/src/index.d.ts +5 -0
  18. package/dist/types/src/index.d.ts.map +1 -0
  19. package/dist/types/src/internal/index.d.ts +3 -0
  20. package/dist/types/src/internal/index.d.ts.map +1 -0
  21. package/dist/types/src/internal/model.d.ts +53 -0
  22. package/dist/types/src/internal/model.d.ts.map +1 -0
  23. package/dist/types/src/internal/types.d.ts +69 -0
  24. package/dist/types/src/internal/types.d.ts.map +1 -0
  25. package/dist/types/src/model.test.d.ts +2 -0
  26. package/dist/types/src/model.test.d.ts.map +1 -0
  27. package/dist/types/tsconfig.tsbuildinfo +1 -0
  28. package/package.json +43 -0
  29. package/src/Branch.ts +21 -0
  30. package/src/History.ts +8 -0
  31. package/src/Version.ts +14 -0
  32. package/src/diff.test.ts +195 -0
  33. package/src/diff.ts +225 -0
  34. package/src/index.ts +8 -0
  35. package/src/internal/index.ts +6 -0
  36. package/src/internal/model.ts +189 -0
  37. package/src/internal/types.ts +76 -0
  38. package/src/model.test.ts +182 -0
@@ -0,0 +1,53 @@
1
+ import { Obj } from '@dxos/echo';
2
+ import { Text } from '@dxos/schema';
3
+ import * as Versioning from './types';
4
+ /** Any ECHO object that carries a versioning history (e.g. a markdown document). */
5
+ export type VersionedObject = Obj.Unknown & {
6
+ history?: Versioning.History | undefined;
7
+ };
8
+ /** Initializes the history struct on first use so existing documents need no migration. */
9
+ export declare const ensureHistory: (doc: VersionedObject) => Versioning.History;
10
+ /** @returns The Text content at the given automerge heads (read-only time travel). */
11
+ export declare const contentAt: (text: Text.Text, heads: readonly string[]) => string;
12
+ export type CreateCheckpointProps = {
13
+ target: Text.Text;
14
+ name: string;
15
+ message?: string;
16
+ creator?: string;
17
+ };
18
+ /**
19
+ * Records a named checkpoint of the target Text's current automerge heads and appends it to
20
+ * the object's history. Zero-copy: only the heads are stored.
21
+ */
22
+ export declare const createCheckpoint: (doc: VersionedObject, props: CreateCheckpointProps) => Versioning.Version;
23
+ /** Display label for a checkpoint: its name, or the formatted creation time when unnamed. */
24
+ export declare const versionLabel: (version: Versioning.Version) => string;
25
+ /** Display label for a branch: its name, or the formatted creation time when unnamed. */
26
+ export declare const branchLabel: (branch: Versioning.Branch) => string;
27
+ /** Find the branch record owning a given Text (undefined for the root). */
28
+ export declare const findBranch: (doc: VersionedObject, text: Text.Text) => Versioning.Branch | undefined;
29
+ export type CreateBranchProps = {
30
+ name: string;
31
+ parent: Text.Text;
32
+ heads?: readonly string[];
33
+ creator?: string;
34
+ };
35
+ /**
36
+ * Forks a draft branch: a new Text seeded with the parent's content at the anchor heads
37
+ * (defaults to the parent's current heads), recorded in the object's history. The anchor is
38
+ * auto-checkpointed so the fork point stays addressable in the timeline.
39
+ */
40
+ export declare const createBranch: (doc: VersionedObject, props: CreateBranchProps) => Versioning.Branch;
41
+ /** Applies the checkpoint's content to the tip as a new forward edit — history is never rewritten. */
42
+ export declare const restore: (doc: VersionedObject, version: Versioning.Version) => void;
43
+ export type MergeResult = {
44
+ conflicts: number;
45
+ };
46
+ /**
47
+ * 3-way merge: base = parent@anchor, ours = parent tip, theirs = branch tip.
48
+ * Conflicting hunks are left in the document with git-style markers for manual cleanup.
49
+ */
50
+ export declare const mergeBranch: (doc: VersionedObject, branch: Versioning.Branch) => MergeResult;
51
+ /** Archives the branch; its Text is retained for recovery. */
52
+ export declare const discardBranch: (doc: VersionedObject, branch: Versioning.Branch) => void;
53
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../../src/internal/model.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoB,GAAG,EAAO,MAAM,YAAY,CAAC;AAGxD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGpC,OAAO,KAAK,UAAU,MAAM,SAAS,CAAC;AAEtC,oFAAoF;AACpF,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC,OAAO,GAAG;IAAE,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,GAAG,SAAS,CAAA;CAAE,CAAC;AAEzF,2FAA2F;AAC3F,eAAO,MAAM,aAAa,QAAS,eAAe,KAAG,UAAU,CAAC,OAS/D,CAAC;AAQF,sFAAsF;AACtF,eAAO,MAAM,SAAS,SAAU,IAAI,CAAC,IAAI,SAAS,SAAS,MAAM,EAAE,KAAG,MAQrE,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5G;;;GAGG;AACH,eAAO,MAAM,gBAAgB,QAAS,eAAe,SAAS,qBAAqB,KAAG,UAAU,CAAC,OAkBhG,CAAC;AAEF,6FAA6F;AAC7F,eAAO,MAAM,YAAY,YAAa,UAAU,CAAC,OAAO,KAAG,MACG,CAAC;AAE/D,yFAAyF;AACzF,eAAO,MAAM,WAAW,WAAY,UAAU,CAAC,MAAM,KAAG,MACI,CAAC;AAE7D,2EAA2E;AAC3E,eAAO,MAAM,UAAU,QAAS,eAAe,QAAQ,IAAI,CAAC,IAAI,KAAG,UAAU,CAAC,MAAM,GAAG,SACR,CAAC;AAEhF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,QAAS,eAAe,SAAS,iBAAiB,KAAG,UAAU,CAAC,MAuCxF,CAAC;AAEF,sGAAsG;AACtG,eAAO,MAAM,OAAO,QAAS,eAAe,WAAW,UAAU,CAAC,OAAO,KAAG,IAO3E,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,WAAW,QAAS,eAAe,UAAU,UAAU,CAAC,MAAM,KAAG,WAoB7E,CAAC;AAEF,8DAA8D;AAC9D,eAAO,MAAM,aAAa,QAAS,eAAe,UAAU,UAAU,CAAC,MAAM,KAAG,IAK/E,CAAC"}
@@ -0,0 +1,69 @@
1
+ import * as Schema from 'effect/Schema';
2
+ import { Ref } from '@dxos/echo';
3
+ import { Text } from '@dxos/schema';
4
+ /**
5
+ * Named checkpoint: a pointer to the automerge heads of a Text's backing document.
6
+ * Heads are content-addressed change hashes, stable across peers, so a checkpoint is zero-copy.
7
+ * Generic over any object holding a `history` field (see model.ts).
8
+ */
9
+ export declare const Version: Schema.mutable<Schema.Struct<{
10
+ id: typeof Schema.String;
11
+ name: typeof Schema.String;
12
+ target: Ref.RefSchema<Text.Text & import("@dxos/echo/Entity").OfKind<import("@dxos/echo/internal").EntityKind.Object> & import("@dxos/echo/Obj").Unknown>;
13
+ heads: Schema.mutable<Schema.Array$<typeof Schema.String>>;
14
+ createdAt: typeof Schema.String;
15
+ creator: Schema.optional<typeof Schema.String>;
16
+ message: Schema.optional<typeof Schema.String>;
17
+ }>>;
18
+ export interface Version extends Schema.Schema.Type<typeof Version> {
19
+ }
20
+ export declare const BranchStatus: Schema.Literal<["active", "merged", "archived"]>;
21
+ export type BranchStatus = Schema.Schema.Type<typeof BranchStatus>;
22
+ /**
23
+ * A draft Text forked from a parent Text at a specific revision (anchor heads).
24
+ * The branch tree is formed by `parent` references; the root is Document.content.
25
+ */
26
+ export declare const Branch: Schema.mutable<Schema.Struct<{
27
+ id: typeof Schema.String;
28
+ name: typeof Schema.String;
29
+ content: Ref.RefSchema<Text.Text & import("@dxos/echo/Entity").OfKind<import("@dxos/echo/internal").EntityKind.Object> & import("@dxos/echo/Obj").Unknown>;
30
+ parent: Ref.RefSchema<Text.Text & import("@dxos/echo/Entity").OfKind<import("@dxos/echo/internal").EntityKind.Object> & import("@dxos/echo/Obj").Unknown>;
31
+ anchor: Schema.mutable<Schema.Array$<typeof Schema.String>>;
32
+ status: Schema.Literal<["active", "merged", "archived"]>;
33
+ createdAt: typeof Schema.String;
34
+ creator: Schema.optional<typeof Schema.String>;
35
+ mergedAt: Schema.optional<typeof Schema.String>;
36
+ }>>;
37
+ export interface Branch extends Schema.Schema.Type<typeof Branch> {
38
+ }
39
+ export declare const History: Schema.mutable<Schema.Struct<{
40
+ branches: Schema.mutable<Schema.Array$<Schema.mutable<Schema.Struct<{
41
+ id: typeof Schema.String;
42
+ name: typeof Schema.String;
43
+ content: Ref.RefSchema<Text.Text & import("@dxos/echo/Entity").OfKind<import("@dxos/echo/internal").EntityKind.Object> & import("@dxos/echo/Obj").Unknown>;
44
+ parent: Ref.RefSchema<Text.Text & import("@dxos/echo/Entity").OfKind<import("@dxos/echo/internal").EntityKind.Object> & import("@dxos/echo/Obj").Unknown>;
45
+ anchor: Schema.mutable<Schema.Array$<typeof Schema.String>>;
46
+ status: Schema.Literal<["active", "merged", "archived"]>;
47
+ createdAt: typeof Schema.String;
48
+ creator: Schema.optional<typeof Schema.String>;
49
+ mergedAt: Schema.optional<typeof Schema.String>;
50
+ }>>>>;
51
+ versions: Schema.mutable<Schema.Array$<Schema.mutable<Schema.Struct<{
52
+ id: typeof Schema.String;
53
+ name: typeof Schema.String;
54
+ target: Ref.RefSchema<Text.Text & import("@dxos/echo/Entity").OfKind<import("@dxos/echo/internal").EntityKind.Object> & import("@dxos/echo/Obj").Unknown>;
55
+ heads: Schema.mutable<Schema.Array$<typeof Schema.String>>;
56
+ createdAt: typeof Schema.String;
57
+ creator: Schema.optional<typeof Schema.String>;
58
+ message: Schema.optional<typeof Schema.String>;
59
+ }>>>>;
60
+ }>>;
61
+ export interface History extends Schema.Schema.Type<typeof History> {
62
+ }
63
+ export type MakeVersionProps = Pick<Version, 'target' | 'heads' | 'name'> & Partial<Pick<Version, 'creator' | 'message'>>;
64
+ /** Constructs a Version checkpoint record with a generated id and creation timestamp. */
65
+ export declare const makeVersion: (props: MakeVersionProps) => Version;
66
+ export type MakeBranchProps = Pick<Branch, 'content' | 'parent' | 'anchor' | 'name'> & Partial<Pick<Branch, 'creator'>>;
67
+ /** Constructs an active Branch record with a generated id and creation timestamp. */
68
+ export declare const makeBranch: (props: MakeBranchProps) => Branch;
69
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/internal/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAO,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC;;;;GAIG;AACH,eAAO,MAAM,OAAO;;;;;;;;GAUnB,CAAC;AACF,MAAM,WAAW,OAAQ,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC;CAAG;AAEtE,eAAO,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