@ftrdotdev/pi-tracker 0.8.0 → 0.9.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.
- package/CHANGELOG.md +369 -0
- package/README.md +5 -0
- package/package.json +20 -16
- package/src/compaction/candidate.test.ts +66 -125
- package/src/compaction/classifier.test.ts +22 -2
- package/src/compaction/classifier.ts +35 -22
- package/src/compaction/completion.test.ts +24 -16
- package/src/compaction/completion.ts +1 -1
- package/src/compaction/decision-record.test.ts +1 -1
- package/src/compaction/decision-record.ts +1 -1
- package/src/compaction/digest.test.ts +34 -34
- package/src/compaction/footprint.ts +2 -4
- package/src/compaction/settings.test.ts +5 -1
- package/src/compaction/settings.ts +1 -1
- package/src/compaction/settle.test.ts +50 -10
- package/src/compaction/settle.ts +1 -1
- package/src/core/deps.test.ts +128 -109
- package/src/core/deps.ts +3 -2
- package/src/core/domain.test.ts +99 -68
- package/src/core/domain.ts +16 -10
- package/src/core/persistence.test.ts +18 -19
- package/src/core/persistence.ts +4 -3
- package/src/core/store.test.ts +129 -167
- package/src/core/store.ts +77 -57
- package/src/harness-collection.test.ts +75 -0
- package/src/index.test.ts +35 -30
- package/src/index.ts +45 -66
- package/src/layers.test.ts +101 -0
- package/src/layers.ts +46 -0
- package/src/presentation/tool-metadata.test.ts +36 -38
- package/src/presentation/tool-metadata.ts +127 -130
- package/src/presentation/ui.test.ts +67 -67
- package/src/presentation/ui.ts +22 -19
- package/src/presentation/vim-settings.test.ts +3 -0
- package/src/presentation/vim-settings.ts +1 -1
package/src/core/domain.ts
CHANGED
|
@@ -67,8 +67,8 @@ const itemProduces = Schema.Array(declaredProduct).pipe(
|
|
|
67
67
|
Schema.withConstructorDefault(Effect.succeed([])),
|
|
68
68
|
);
|
|
69
69
|
|
|
70
|
-
export type DeclaredReference =
|
|
71
|
-
export type DeclaredProduct =
|
|
70
|
+
export type DeclaredReference = typeof declaredReference.Type;
|
|
71
|
+
export type DeclaredProduct = typeof declaredProduct.Type;
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* Sentinel for a list that stored no item id counter, which means the snapshot
|
|
@@ -83,7 +83,9 @@ const itemCounter = Schema.Int.pipe(
|
|
|
83
83
|
Schema.withConstructorDefault(Effect.succeed(1)),
|
|
84
84
|
);
|
|
85
85
|
|
|
86
|
-
export class TodoItem extends Schema.Class<TodoItem>(
|
|
86
|
+
export class TodoItem extends Schema.Class<TodoItem, { readonly brand: unique symbol }>(
|
|
87
|
+
"tracker/TodoItem",
|
|
88
|
+
)({
|
|
87
89
|
id: itemId,
|
|
88
90
|
title: Schema.String,
|
|
89
91
|
description: itemDescription,
|
|
@@ -93,7 +95,9 @@ export class TodoItem extends Schema.Class<TodoItem>("tracker/TodoItem")({
|
|
|
93
95
|
deps: itemDeps,
|
|
94
96
|
}) {}
|
|
95
97
|
|
|
96
|
-
export class TodoList extends Schema.Class<TodoList>(
|
|
98
|
+
export class TodoList extends Schema.Class<TodoList, { readonly brand: unique symbol }>(
|
|
99
|
+
"tracker/TodoList",
|
|
100
|
+
)({
|
|
97
101
|
id: Schema.Int,
|
|
98
102
|
name: Schema.String,
|
|
99
103
|
// Strictly-increasing counter ⇒ stable item ids, never reused after deletes.
|
|
@@ -101,7 +105,9 @@ export class TodoList extends Schema.Class<TodoList>("tracker/TodoList")({
|
|
|
101
105
|
items: Schema.Array(TodoItem),
|
|
102
106
|
}) {}
|
|
103
107
|
|
|
104
|
-
export class TrackerState extends Schema.Class<TrackerState>(
|
|
108
|
+
export class TrackerState extends Schema.Class<TrackerState, { readonly brand: unique symbol }>(
|
|
109
|
+
"tracker/TrackerState",
|
|
110
|
+
)({
|
|
105
111
|
lists: Schema.Array(TodoList),
|
|
106
112
|
// null = no active list (avoids Option in the serialized snapshot)
|
|
107
113
|
activeListId: Schema.NullOr(Schema.Int),
|
|
@@ -117,7 +123,7 @@ export class TrackerState extends Schema.Class<TrackerState>("tracker/TrackerSta
|
|
|
117
123
|
* constructors validate their input (`new TodoItem({ text: 42, ... })` throws).
|
|
118
124
|
*/
|
|
119
125
|
export const emptyState = (): TrackerState =>
|
|
120
|
-
|
|
126
|
+
TrackerState.make({ lists: [], activeListId: null, nextListId: 1 });
|
|
121
127
|
|
|
122
128
|
// --------------------------------------------------------------------------
|
|
123
129
|
// Legacy snapshot tolerance
|
|
@@ -125,7 +131,7 @@ export const emptyState = (): TrackerState =>
|
|
|
125
131
|
|
|
126
132
|
/** A copy of `item` with a replaced id. */
|
|
127
133
|
const withId = (item: TodoItem, id: number): TodoItem =>
|
|
128
|
-
|
|
134
|
+
TodoItem.make({
|
|
129
135
|
id,
|
|
130
136
|
title: item.title,
|
|
131
137
|
description: item.description,
|
|
@@ -146,7 +152,7 @@ const withId = (item: TodoItem, id: number): TodoItem =>
|
|
|
146
152
|
*/
|
|
147
153
|
const migrateList = (list: TodoList): TodoList => {
|
|
148
154
|
if (list.nextItemId === LEGACY_ITEM_COUNTER) {
|
|
149
|
-
return
|
|
155
|
+
return TodoList.make({
|
|
150
156
|
id: list.id,
|
|
151
157
|
name: list.name,
|
|
152
158
|
items: list.items.map((item, index) => withId(item, index + 1)),
|
|
@@ -163,7 +169,7 @@ const migrateList = (list: TodoList): TodoList => {
|
|
|
163
169
|
counter += 1;
|
|
164
170
|
return assigned;
|
|
165
171
|
});
|
|
166
|
-
return
|
|
172
|
+
return TodoList.make({ id: list.id, name: list.name, items, nextItemId: counter });
|
|
167
173
|
};
|
|
168
174
|
|
|
169
175
|
/**
|
|
@@ -171,7 +177,7 @@ const migrateList = (list: TodoList): TodoList => {
|
|
|
171
177
|
* every list has a counter above its ids. Pure; called once per restore.
|
|
172
178
|
*/
|
|
173
179
|
export const migrateState = (state: TrackerState): TrackerState =>
|
|
174
|
-
|
|
180
|
+
TrackerState.make({
|
|
175
181
|
lists: state.lists.map(migrateList),
|
|
176
182
|
activeListId: state.activeListId,
|
|
177
183
|
nextListId: state.nextListId,
|
|
@@ -20,37 +20,36 @@ layer(
|
|
|
20
20
|
}),
|
|
21
21
|
)("TrackerPersistence", (it) => {
|
|
22
22
|
const sampleState = (): TrackerState =>
|
|
23
|
-
|
|
23
|
+
TrackerState.make({
|
|
24
24
|
lists: [
|
|
25
|
-
|
|
25
|
+
TodoList.make({
|
|
26
26
|
id: 1,
|
|
27
27
|
name: "Work",
|
|
28
28
|
nextItemId: 3,
|
|
29
29
|
items: [
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
TodoItem.make({ id: 1, title: "write plan", done: true }),
|
|
31
|
+
TodoItem.make({ id: 2, title: "implement tracker", done: false }),
|
|
32
32
|
],
|
|
33
33
|
}),
|
|
34
|
-
|
|
34
|
+
TodoList.make({
|
|
35
35
|
id: 2,
|
|
36
36
|
name: "Home",
|
|
37
37
|
nextItemId: 2,
|
|
38
|
-
items: [
|
|
38
|
+
items: [TodoItem.make({ id: 1, title: "water plants", done: false })],
|
|
39
39
|
}),
|
|
40
40
|
],
|
|
41
41
|
activeListId: 1,
|
|
42
42
|
nextListId: 3,
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
const decodeFailureOf = (snapshot: unknown)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
45
|
+
const decodeFailureOf = Effect.fnUntraced(function* (snapshot: unknown) {
|
|
46
|
+
const persistence = yield* TrackerPersistence;
|
|
47
|
+
const result = yield* Effect.result(persistence.restore(snapshot));
|
|
48
|
+
if (!Result.isFailure(result)) assert.fail(`expected ${JSON.stringify(snapshot)} to fail`);
|
|
49
|
+
const failure = Result.getFailure(result).pipe(Option.getOrThrow);
|
|
50
|
+
assert.strictEqual(failure._tag, "SchemaError");
|
|
51
|
+
return failure.message;
|
|
52
|
+
});
|
|
54
53
|
|
|
55
54
|
it.effect("save writes the encoded snapshot", () =>
|
|
56
55
|
Effect.gen(function* () {
|
|
@@ -162,13 +161,13 @@ layer(
|
|
|
162
161
|
};
|
|
163
162
|
|
|
164
163
|
const restored = yield* persistence.restore(legacy);
|
|
165
|
-
const expected =
|
|
164
|
+
const expected = TrackerState.make({
|
|
166
165
|
lists: [
|
|
167
|
-
|
|
166
|
+
TodoList.make({
|
|
168
167
|
id: 1,
|
|
169
168
|
name: "Work",
|
|
170
169
|
nextItemId: 2,
|
|
171
|
-
items: [
|
|
170
|
+
items: [TodoItem.make({ id: 1, title: "a", done: false })],
|
|
172
171
|
}),
|
|
173
172
|
],
|
|
174
173
|
activeListId: 1,
|
|
@@ -176,7 +175,7 @@ layer(
|
|
|
176
175
|
});
|
|
177
176
|
assert.deepStrictEqual(encodeState(restored), encodeState(expected));
|
|
178
177
|
assert.deepStrictEqual(restored.lists[0]?.items, [
|
|
179
|
-
|
|
178
|
+
TodoItem.make({ id: 1, title: "a", done: false }),
|
|
180
179
|
]);
|
|
181
180
|
}),
|
|
182
181
|
);
|
package/src/core/persistence.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Context, Effect, Layer, Schema } from "effect";
|
|
|
2
2
|
import { TrackerState, decodeStateEffect, encodeStateEffect, migrateState } from "./domain.ts";
|
|
3
3
|
|
|
4
4
|
/** The plain JSON shape of a `TrackerState` (what goes into the session). */
|
|
5
|
-
export type EncodedState =
|
|
5
|
+
export type EncodedState = typeof TrackerState.Encoded;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Persistence boundary for the tracker state.
|
|
@@ -27,7 +27,7 @@ export class TrackerPersistence extends Context.Service<
|
|
|
27
27
|
readonly save: (state: TrackerState) => Effect.Effect<void, Schema.SchemaError>;
|
|
28
28
|
readonly restore: (snapshot: unknown) => Effect.Effect<TrackerState, Schema.SchemaError>;
|
|
29
29
|
}
|
|
30
|
-
>()("tracker/TrackerPersistence") {
|
|
30
|
+
>()("@ftrdotdev/pi-tracker/core/persistence/TrackerPersistence") {
|
|
31
31
|
static readonly layer = (
|
|
32
32
|
append: (encoded: EncodedState) => void,
|
|
33
33
|
): Layer.Layer<TrackerPersistence> =>
|
|
@@ -41,7 +41,8 @@ export class TrackerPersistence extends Context.Service<
|
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
const restore = Effect.fn("TrackerPersistence.restore")(function* (snapshot: unknown) {
|
|
44
|
-
|
|
44
|
+
const decoded = yield* decodeStateEffect(snapshot);
|
|
45
|
+
return migrateState(decoded);
|
|
45
46
|
});
|
|
46
47
|
|
|
47
48
|
return TrackerPersistence.of({ save, restore });
|