@reintent/lib/versions
Versions: what a person made, kept and passed on.
A version is the program's data (a scene's declaration, the words bound to it: whatever the host keeps) and what the person said of it (decisions with where they came from, constraints, preferences, facts). It goes into a link as compressed JSON (#v=…); opening one restores it, and changing anything after makes a new version whose parent it is.
encode / decode a version as a link's fragment: JSON, deflate-raw, base64url
snapshot what a person said, read off an intent's layers
restore the same, written back to a intent as one commit (one undo takes it back)
merge another person's decisions, merged in by identity; what both decided
differently comes back as a conflict (a question), not written; what it
does not merge (constraints, preferences, facts) is listed, not writtenUndo and redo are the intent's history; a version is what is shared or saved, not a step. Beliefs and generated results are not in it: they are the models' cache, asked again by stamp.
Interfaces
Conflict
Defined in: packages/lib/src/versions.ts
A choice both people decided, differently: a question for the person, not written.
Properties
| Property | Type | Description |
|---|---|---|
id | Id | The choice. |
key | string | The choice's key (lamp#light). |
mine | object & DecisionOrigin | This intent's decision. |
theirs | object & DecisionOrigin | The other person's. |
Saved
Defined in: packages/lib/src/versions.ts
A version and its data.
Type Parameters
| Type Parameter |
|---|
T |
Properties
| Property | Type | Description |
|---|---|---|
data | T | The host's data: whatever it keeps (a snapshot, a scene's declaration, a prompt). |
version | Version | - |
Snapshot
Defined in: packages/lib/src/versions.ts
What a person said, as data: the intent's person's layers, by key. It is JSON.
Properties
| Property | Type | Description |
|---|---|---|
constraints | Record<string, readonly Constraint[]> | Possibilities ruled out (or in), by choice. |
decisions | Record<string, object & DecisionOrigin> | Decisions, with the sentence and who read it. |
facts | readonly string[] | What was said of the whole. |
named | Record<string, { constraints?: readonly Constraint[]; preferences?: readonly Preference[]; }> | Constraints and preferences on every choice of a name. |
preferences | Record<string, readonly Preference[]> | Possibilities weighed up, by choice. |
Version
Defined in: packages/lib/src/versions.ts
Who made a version, and from which.
Properties
Type Aliases
Merged
type Merged = object;Defined in: packages/lib/src/versions.ts
What a merge did: the conflicts it left to the person, and what it did not merge.
Properties
| Property | Type | Description |
|---|---|---|
conflicts | Conflict[] | Choices both people decided, differently: questions, not written. |
notHandled | string[] | What the other version holds that a merge of decisions does not take in: their constraints and preferences (constraint lamp#light, preference man#hat, by name constraint *#tone), the facts they told (fact “…”). Shown to the person; nothing of it is written. |
Functions
child()
function child(
parent,
by,
note?
): Version;Defined in: packages/lib/src/versions.ts
A version made from parent (a remix of what was opened), by by.
Parameters
| Parameter | Type |
|---|---|
parent | Version | null |
by | string |
note? | string |
Returns
decode()
function decode<T>(s, check?): Promise<Saved<T> | null>;Defined in: packages/lib/src/versions.ts
The version in a fragment, or null when it is not one (check says whether its data is a T).
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
s | string |
check | (data) => boolean |
Returns
Promise<Saved<T> | null>
encode()
function encode<T>(saved): Promise<string>;Defined in: packages/lib/src/versions.ts
A version as a link's fragment: its JSON, compressed (deflate-raw), in base64url.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
saved | Saved<T> |
Returns
Promise<string>
Example
import { decode, encode, inHash } from '@reintent/lib/versions';
const saved = {
version: { id: 'a1', parent: null, by: 'human' },
data: { prompt: '他站在床头' },
};
const link = `https://example.com/dream#v=${await encode(saved)}`;
const back = await decode<{ prompt: string }>(inHash(link)!);
console.log(back?.data.prompt, back?.version.by); // → '他站在床头' 'human'inHash()
function inHash(hash): string | null;Defined in: packages/lib/src/versions.ts
The version in an address or fragment (#v=…, &v=…), if any.
Parameters
| Parameter | Type |
|---|---|
hash | string |
Returns
string | null
merge()
function merge(
intent,
theirs,
opts?
): Merged;Defined in: packages/lib/src/versions.ts
Another person's decisions merged into an intent by identity, as one commit (one undo takes it
back): theirs where this intent has none. A choice both decided differently is not written: it
comes back as a conflict, a question for the person. only keeps the merge to some choices (the
entities the other person held); note names the commit.
Its scope today is decisions only. Not handled, and listed in notHandled where the other
version holds them: constraints, preferences and facts. Not handled, and not seen at all:
deletions (a decision they took back is simply absent from their snapshot, so it cannot be told
from one they never made) and program differences (the other version's program is the host's
data, merged, if at all, by the host).
Parameters
| Parameter | Type |
|---|---|
intent | Pick<Intent, "commit" | "layers"> |
theirs | Snapshot |
opts | { note?: string; only?: (id) => boolean; } |
opts.note? | string |
opts.only? | (id) => boolean |
Returns
Example
import { createIntent, entity, host, useChoose } from '@reintent/core';
import { merge, snapshot } from '@reintent/lib/versions';
const lamp = entity('lamp', { light: { kinds: ['off', 'on'] } });
const door = entity('door', { open: { kinds: ['shut', 'open'] } });
const Lamp = lamp(() => host('lamp', { light: useChoose(lamp.light) }));
const Door = door(() => host('door', { open: useChoose(door.open) }));
// Two people, each with an intent on the same program.
const mine = createIntent({ program: [<Lamp />, <Door />] });
const theirs = createIntent({ program: [<Lamp />, <Door />] });
mine.decide(lamp.light('lamp'), 'on');
theirs.decide(lamp.light('lamp'), 'off');
theirs.decide(door.open('door'), 'open');
theirs.tell('it is night');
const { conflicts, notHandled } = merge(mine, snapshot(theirs), {
note: 'their version',
});
console.log(conflicts.map((c) => [c.key, c.mine.value, c.theirs.value])); // → [ [ 'lamp#light', 'on', 'off' ] ]
console.log(mine.realize().reads.map((r) => r.value)); // → [ 'on', 'open' ]
console.log(notHandled); // → [ 'fact “it is night”' ]newId()
function newId(): string;Defined in: packages/lib/src/versions.ts
A new version's id: six letters and digits.
Returns
string
restore()
function restore(
intent,
s,
note?
): void;Defined in: packages/lib/src/versions.ts
What a person said, written back to a intent as one commit: what the snapshot does not hold is taken back, what it holds is said again (decisions with their origin). One undo takes it back.
Parameters
| Parameter | Type | Default value |
|---|---|---|
intent | Pick<Intent, "commit" | "layers"> | undefined |
s | Snapshot | undefined |
note | string | 'version restored' |
Returns
void
Example
import { createIntent, entity, host, useChoose } from '@reintent/core';
import { restore, snapshot } from '@reintent/lib/versions';
const man = entity('man', { stand: { kinds: ['bedside', 'window'] } });
const Man = man(() => host('man', { stand: useChoose(man.stand) }));
const intent = createIntent({ program: <Man /> });
intent.decide(man.stand('man'), 'window', { said: 'stand by the window', via: 'code' });
intent.tell('he comes closer');
const kept = snapshot(intent);
console.log(kept.decisions); // → { 'man#stand': { value: 'window', said: 'stand by the window', via: 'code' } }
// The page opens again, on a new intent: one commit says it all again.
const opened = createIntent({ program: <Man /> });
restore(opened, kept, 'opened a version');
console.log(opened.realize().reads[0].value, opened.layers.facts); // → 'window' [ 'he comes closer' ]
console.log(opened.history.entries.length); // → 1snapshot()
function snapshot(intent): Snapshot;Defined in: packages/lib/src/versions.ts
What a person said, read off an intent's layers: decisions with their origin, constraints, preferences, facts. Not what the models answered (beliefs, generated results).
Parameters
Returns
Last updated on
Edit on GitHub