@fgv/ts-agent-memory 5.1.0-48 → 5.1.0-49
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/packlets/retrieve/linkTraversalRetriever.js +1 -1
- package/dist/packlets/retrieve/linkTraversalRetriever.js.map +1 -1
- package/dist/packlets/retrieve/recencyRetriever.js +1 -1
- package/dist/packlets/retrieve/recencyRetriever.js.map +1 -1
- package/dist/packlets/retrieve/retriever.js +11 -5
- package/dist/packlets/retrieve/retriever.js.map +1 -1
- package/dist/packlets/retrieve/structuredFilterRetriever.js +27 -5
- package/dist/packlets/retrieve/structuredFilterRetriever.js.map +1 -1
- package/dist/packlets/retrieve/tagRetriever.js +1 -1
- package/dist/packlets/retrieve/tagRetriever.js.map +1 -1
- package/dist/packlets/retrieve/temporalRetrievers.js +1 -1
- package/dist/packlets/retrieve/temporalRetrievers.js.map +1 -1
- package/dist/packlets/store/fileTreeMemoryStore.js +100 -1
- package/dist/packlets/store/fileTreeMemoryStore.js.map +1 -1
- package/dist/packlets/types/envelope.js.map +1 -1
- package/dist/ts-agent-memory.d.ts +134 -13
- package/lib/packlets/retrieve/linkTraversalRetriever.d.ts +1 -1
- package/lib/packlets/retrieve/linkTraversalRetriever.js +1 -1
- package/lib/packlets/retrieve/linkTraversalRetriever.js.map +1 -1
- package/lib/packlets/retrieve/recencyRetriever.d.ts +1 -1
- package/lib/packlets/retrieve/recencyRetriever.js +1 -1
- package/lib/packlets/retrieve/recencyRetriever.js.map +1 -1
- package/lib/packlets/retrieve/retriever.d.ts +26 -7
- package/lib/packlets/retrieve/retriever.d.ts.map +1 -1
- package/lib/packlets/retrieve/retriever.js +11 -5
- package/lib/packlets/retrieve/retriever.js.map +1 -1
- package/lib/packlets/retrieve/structuredFilterRetriever.d.ts +26 -4
- package/lib/packlets/retrieve/structuredFilterRetriever.d.ts.map +1 -1
- package/lib/packlets/retrieve/structuredFilterRetriever.js +27 -5
- package/lib/packlets/retrieve/structuredFilterRetriever.js.map +1 -1
- package/lib/packlets/retrieve/tagRetriever.d.ts +1 -1
- package/lib/packlets/retrieve/tagRetriever.js +1 -1
- package/lib/packlets/retrieve/tagRetriever.js.map +1 -1
- package/lib/packlets/retrieve/temporalRetrievers.js +1 -1
- package/lib/packlets/retrieve/temporalRetrievers.js.map +1 -1
- package/lib/packlets/store/fileTreeMemoryStore.d.ts +69 -0
- package/lib/packlets/store/fileTreeMemoryStore.d.ts.map +1 -1
- package/lib/packlets/store/fileTreeMemoryStore.js +99 -0
- package/lib/packlets/store/fileTreeMemoryStore.js.map +1 -1
- package/lib/packlets/types/envelope.d.ts +11 -0
- package/lib/packlets/types/envelope.d.ts.map +1 -1
- package/lib/packlets/types/envelope.js.map +1 -1
- package/package.json +7 -7
|
@@ -3,10 +3,32 @@ import { IMemoryRecord } from '../types';
|
|
|
3
3
|
import { IMemoryIndex } from '../index';
|
|
4
4
|
import { IMemoryQuery, IMemoryRetriever, IMemoryRetrieverCapabilities } from './retriever';
|
|
5
5
|
/**
|
|
6
|
-
* Returns records matching `query.filter`, narrowed
|
|
7
|
-
* pre-filter and recency-ordered.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Returns records matching `query.filter` or `query.provenanceSource`, narrowed
|
|
7
|
+
* by any scope / kind / tag / provenance-source pre-filter and recency-ordered.
|
|
8
|
+
* Those two are this retriever's axes: a query carrying neither is not its
|
|
9
|
+
* concern and yields an empty success (so it contributes nothing to a
|
|
10
|
+
* {@link HybridRetriever}, rather than failing).
|
|
11
|
+
*
|
|
12
|
+
* Note `provenanceSource` appears on both sides of that sentence, and the
|
|
13
|
+
* duplication is real rather than sloppy: it is one of this retriever's two
|
|
14
|
+
* *dispatch* axes (it decides whether the query is this retriever's concern at
|
|
15
|
+
* all) **and** a member of the shared *pre-filter* (it narrows the result set,
|
|
16
|
+
* as it does for every other retriever). `filter` is likewise both.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* `provenanceSource` is *applied* by the shared pre-filter, so every retriever
|
|
20
|
+
* narrows by it. What this retriever adds is *answering* a query whose only axis
|
|
21
|
+
* is `provenanceSource` — the "show me everything this source produced" request,
|
|
22
|
+
* which would otherwise fall through the `filter`-absent guard and come back
|
|
23
|
+
* empty.
|
|
24
|
+
*
|
|
25
|
+
* Consequently, inside a {@link HybridRetriever} composed with the universal
|
|
26
|
+
* {@link RecencyRetriever}, a `provenanceSource`-only query is answered by both
|
|
27
|
+
* children and every matching record scores twice under a score-union merge.
|
|
28
|
+
* That is the established behavior for a dedicated-axis retriever composed with
|
|
29
|
+
* the universal one — {@link TagRetriever} double-scores a `tag`-only query the
|
|
30
|
+
* same way — and is intentional here, not an artifact of grafting a second axis
|
|
31
|
+
* onto a retriever whose original concern was arbitrary predicates.
|
|
10
32
|
* @public
|
|
11
33
|
*/
|
|
12
34
|
export declare class StructuredFilterRetriever implements IMemoryRetriever {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structuredFilterRetriever.d.ts","sourceRoot":"","sources":["../../../src/packlets/retrieve/structuredFilterRetriever.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAW,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,4BAA4B,EAM7B,MAAM,aAAa,CAAC;AAErB
|
|
1
|
+
{"version":3,"file":"structuredFilterRetriever.d.ts","sourceRoot":"","sources":["../../../src/packlets/retrieve/structuredFilterRetriever.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAW,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,4BAA4B,EAM7B,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,yBAA0B,YAAW,gBAAgB;IAChE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IAEtC,OAAO;IAIP,kDAAkD;IAClD,IAAW,YAAY,IAAI,4BAA4B,CAEtD;IAED,iCAAiC;WACnB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAAC,yBAAyB,CAAC;IAI5E,8CAA8C;IACvC,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CAa7F"}
|
|
@@ -8,10 +8,32 @@ exports.StructuredFilterRetriever = void 0;
|
|
|
8
8
|
const ts_utils_1 = require("@fgv/ts-utils");
|
|
9
9
|
const retriever_1 = require("./retriever");
|
|
10
10
|
/**
|
|
11
|
-
* Returns records matching `query.filter`, narrowed
|
|
12
|
-
* pre-filter and recency-ordered.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* Returns records matching `query.filter` or `query.provenanceSource`, narrowed
|
|
12
|
+
* by any scope / kind / tag / provenance-source pre-filter and recency-ordered.
|
|
13
|
+
* Those two are this retriever's axes: a query carrying neither is not its
|
|
14
|
+
* concern and yields an empty success (so it contributes nothing to a
|
|
15
|
+
* {@link HybridRetriever}, rather than failing).
|
|
16
|
+
*
|
|
17
|
+
* Note `provenanceSource` appears on both sides of that sentence, and the
|
|
18
|
+
* duplication is real rather than sloppy: it is one of this retriever's two
|
|
19
|
+
* *dispatch* axes (it decides whether the query is this retriever's concern at
|
|
20
|
+
* all) **and** a member of the shared *pre-filter* (it narrows the result set,
|
|
21
|
+
* as it does for every other retriever). `filter` is likewise both.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* `provenanceSource` is *applied* by the shared pre-filter, so every retriever
|
|
25
|
+
* narrows by it. What this retriever adds is *answering* a query whose only axis
|
|
26
|
+
* is `provenanceSource` — the "show me everything this source produced" request,
|
|
27
|
+
* which would otherwise fall through the `filter`-absent guard and come back
|
|
28
|
+
* empty.
|
|
29
|
+
*
|
|
30
|
+
* Consequently, inside a {@link HybridRetriever} composed with the universal
|
|
31
|
+
* {@link RecencyRetriever}, a `provenanceSource`-only query is answered by both
|
|
32
|
+
* children and every matching record scores twice under a score-union merge.
|
|
33
|
+
* That is the established behavior for a dedicated-axis retriever composed with
|
|
34
|
+
* the universal one — {@link TagRetriever} double-scores a `tag`-only query the
|
|
35
|
+
* same way — and is intentional here, not an artifact of grafting a second axis
|
|
36
|
+
* onto a retriever whose original concern was arbitrary predicates.
|
|
15
37
|
* @public
|
|
16
38
|
*/
|
|
17
39
|
class StructuredFilterRetriever {
|
|
@@ -29,7 +51,7 @@ class StructuredFilterRetriever {
|
|
|
29
51
|
/** {@inheritDoc IMemoryRetriever.retrieve} */
|
|
30
52
|
retrieve(query) {
|
|
31
53
|
return Promise.resolve((0, retriever_1.guardRetrieverCapabilities)(query, this.capabilities).onSuccess(() => {
|
|
32
|
-
if (query.filter === undefined) {
|
|
54
|
+
if (query.filter === undefined && query.provenanceSource === undefined) {
|
|
33
55
|
return (0, ts_utils_1.succeed)([]);
|
|
34
56
|
}
|
|
35
57
|
const ordered = (0, retriever_1.selectByQuery)(this._index.entries(), query).sort((0, retriever_1.orderingCompare)(query.orderBy));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structuredFilterRetriever.js","sourceRoot":"","sources":["../../../src/packlets/retrieve/structuredFilterRetriever.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAAgD;AAGhD,2CASqB;AAErB
|
|
1
|
+
{"version":3,"file":"structuredFilterRetriever.js","sourceRoot":"","sources":["../../../src/packlets/retrieve/structuredFilterRetriever.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAAgD;AAGhD,2CASqB;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAa,yBAAyB;IAGpC,YAAoB,KAAmB;QACrC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,kDAAkD;IAClD,IAAW,YAAY;QACrB,OAAO,qCAAyB,CAAC;IACnC,CAAC;IAED,iCAAiC;IAC1B,MAAM,CAAC,MAAM,CAAC,KAAmB;QACtC,OAAO,IAAA,kBAAO,EAAC,IAAI,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,8CAA8C;IACvC,QAAQ,CAAC,KAAmB;QACjC,OAAO,OAAO,CAAC,OAAO,CACpB,IAAA,sCAA0B,EAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE;YAClE,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,gBAAgB,KAAK,SAAS,EAAE,CAAC;gBACvE,OAAO,IAAA,kBAAO,EAAC,EAAE,CAAC,CAAC;YACrB,CAAC;YACD,MAAM,OAAO,GAA6B,IAAA,yBAAa,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,IAAI,CACxF,IAAA,2BAAe,EAAC,KAAK,CAAC,OAAO,CAAC,CAC/B,CAAC;YACF,OAAO,IAAA,kBAAO,EAAC,IAAA,wBAAY,EAAC,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QACnE,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AA/BD,8DA+BC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport { Result, succeed } from '@fgv/ts-utils';\nimport { IMemoryRecord } from '../types';\nimport { IMemoryIndex } from '../index';\nimport {\n IMemoryQuery,\n IMemoryRetriever,\n IMemoryRetrieverCapabilities,\n NON_SEMANTIC_CAPABILITIES,\n guardRetrieverCapabilities,\n limitRecords,\n orderingCompare,\n selectByQuery\n} from './retriever';\n\n/**\n * Returns records matching `query.filter` or `query.provenanceSource`, narrowed\n * by any scope / kind / tag / provenance-source pre-filter and recency-ordered.\n * Those two are this retriever's axes: a query carrying neither is not its\n * concern and yields an empty success (so it contributes nothing to a\n * {@link HybridRetriever}, rather than failing).\n *\n * Note `provenanceSource` appears on both sides of that sentence, and the\n * duplication is real rather than sloppy: it is one of this retriever's two\n * *dispatch* axes (it decides whether the query is this retriever's concern at\n * all) **and** a member of the shared *pre-filter* (it narrows the result set,\n * as it does for every other retriever). `filter` is likewise both.\n *\n * @remarks\n * `provenanceSource` is *applied* by the shared pre-filter, so every retriever\n * narrows by it. What this retriever adds is *answering* a query whose only axis\n * is `provenanceSource` — the \"show me everything this source produced\" request,\n * which would otherwise fall through the `filter`-absent guard and come back\n * empty.\n *\n * Consequently, inside a {@link HybridRetriever} composed with the universal\n * {@link RecencyRetriever}, a `provenanceSource`-only query is answered by both\n * children and every matching record scores twice under a score-union merge.\n * That is the established behavior for a dedicated-axis retriever composed with\n * the universal one — {@link TagRetriever} double-scores a `tag`-only query the\n * same way — and is intentional here, not an artifact of grafting a second axis\n * onto a retriever whose original concern was arbitrary predicates.\n * @public\n */\nexport class StructuredFilterRetriever implements IMemoryRetriever {\n private readonly _index: IMemoryIndex;\n\n private constructor(index: IMemoryIndex) {\n this._index = index;\n }\n\n /** {@inheritDoc IMemoryRetriever.capabilities} */\n public get capabilities(): IMemoryRetrieverCapabilities {\n return NON_SEMANTIC_CAPABILITIES;\n }\n\n /** Family-convention factory. */\n public static create(index: IMemoryIndex): Result<StructuredFilterRetriever> {\n return succeed(new StructuredFilterRetriever(index));\n }\n\n /** {@inheritDoc IMemoryRetriever.retrieve} */\n public retrieve(query: IMemoryQuery): Promise<Result<ReadonlyArray<IMemoryRecord<unknown>>>> {\n return Promise.resolve(\n guardRetrieverCapabilities(query, this.capabilities).onSuccess(() => {\n if (query.filter === undefined && query.provenanceSource === undefined) {\n return succeed([]);\n }\n const ordered: IMemoryRecord<unknown>[] = selectByQuery(this._index.entries(), query).sort(\n orderingCompare(query.orderBy)\n );\n return succeed(limitRecords(ordered, query.limit, query.offset));\n })\n );\n }\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { IMemoryIndex } from '../index';
|
|
|
4
4
|
import { IMemoryQuery, IMemoryRetriever, IMemoryRetrieverCapabilities } from './retriever';
|
|
5
5
|
/**
|
|
6
6
|
* Returns records carrying `query.tag`, recency-ordered within the tag and
|
|
7
|
-
* narrowed by any scope / kind / predicate filters. Tag is this retriever's
|
|
7
|
+
* narrowed by any scope / kind / provenance-source / predicate filters. Tag is this retriever's
|
|
8
8
|
* axis: a query without a `tag` is not its concern and yields an empty success
|
|
9
9
|
* (so it contributes nothing to a {@link HybridRetriever}, rather than failing).
|
|
10
10
|
* @public
|
|
@@ -9,7 +9,7 @@ const ts_utils_1 = require("@fgv/ts-utils");
|
|
|
9
9
|
const retriever_1 = require("./retriever");
|
|
10
10
|
/**
|
|
11
11
|
* Returns records carrying `query.tag`, recency-ordered within the tag and
|
|
12
|
-
* narrowed by any scope / kind / predicate filters. Tag is this retriever's
|
|
12
|
+
* narrowed by any scope / kind / provenance-source / predicate filters. Tag is this retriever's
|
|
13
13
|
* axis: a query without a `tag` is not its concern and yields an empty success
|
|
14
14
|
* (so it contributes nothing to a {@link HybridRetriever}, rather than failing).
|
|
15
15
|
* @public
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tagRetriever.js","sourceRoot":"","sources":["../../../src/packlets/retrieve/tagRetriever.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAAgD;AAGhD,2CASqB;AAErB;;;;;;GAMG;AACH,MAAa,YAAY;IAGvB,YAAoB,KAAmB;QACrC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,kDAAkD;IAClD,IAAW,YAAY;QACrB,OAAO,qCAAyB,CAAC;IACnC,CAAC;IAED,iCAAiC;IAC1B,MAAM,CAAC,MAAM,CAAC,KAAmB;QACtC,OAAO,IAAA,kBAAO,EAAC,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,8CAA8C;IACvC,QAAQ,CAAC,KAAmB;QACjC,OAAO,OAAO,CAAC,OAAO,CACpB,IAAA,sCAA0B,EAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE;YAClE,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;gBAC5B,OAAO,IAAA,kBAAO,EAAC,EAAE,CAAC,CAAC;YACrB,CAAC;YACD,MAAM,OAAO,GAA6B,IAAA,yBAAa,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,IAAI,CACxF,IAAA,2BAAe,EAAC,KAAK,CAAC,OAAO,CAAC,CAC/B,CAAC;YACF,OAAO,IAAA,kBAAO,EAAC,IAAA,wBAAY,EAAC,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QACnE,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AA/BD,oCA+BC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport { Result, succeed } from '@fgv/ts-utils';\nimport { IMemoryRecord } from '../types';\nimport { IMemoryIndex } from '../index';\nimport {\n IMemoryQuery,\n IMemoryRetriever,\n IMemoryRetrieverCapabilities,\n NON_SEMANTIC_CAPABILITIES,\n guardRetrieverCapabilities,\n limitRecords,\n orderingCompare,\n selectByQuery\n} from './retriever';\n\n/**\n * Returns records carrying `query.tag`, recency-ordered within the tag and\n * narrowed by any scope / kind / predicate filters. Tag is this retriever's\n * axis: a query without a `tag` is not its concern and yields an empty success\n * (so it contributes nothing to a {@link HybridRetriever}, rather than failing).\n * @public\n */\nexport class TagRetriever implements IMemoryRetriever {\n private readonly _index: IMemoryIndex;\n\n private constructor(index: IMemoryIndex) {\n this._index = index;\n }\n\n /** {@inheritDoc IMemoryRetriever.capabilities} */\n public get capabilities(): IMemoryRetrieverCapabilities {\n return NON_SEMANTIC_CAPABILITIES;\n }\n\n /** Family-convention factory. */\n public static create(index: IMemoryIndex): Result<TagRetriever> {\n return succeed(new TagRetriever(index));\n }\n\n /** {@inheritDoc IMemoryRetriever.retrieve} */\n public retrieve(query: IMemoryQuery): Promise<Result<ReadonlyArray<IMemoryRecord<unknown>>>> {\n return Promise.resolve(\n guardRetrieverCapabilities(query, this.capabilities).onSuccess(() => {\n if (query.tag === undefined) {\n return succeed([]);\n }\n const ordered: IMemoryRecord<unknown>[] = selectByQuery(this._index.entries(), query).sort(\n orderingCompare(query.orderBy)\n );\n return succeed(limitRecords(ordered, query.limit, query.offset));\n })\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tagRetriever.js","sourceRoot":"","sources":["../../../src/packlets/retrieve/tagRetriever.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAAgD;AAGhD,2CASqB;AAErB;;;;;;GAMG;AACH,MAAa,YAAY;IAGvB,YAAoB,KAAmB;QACrC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,kDAAkD;IAClD,IAAW,YAAY;QACrB,OAAO,qCAAyB,CAAC;IACnC,CAAC;IAED,iCAAiC;IAC1B,MAAM,CAAC,MAAM,CAAC,KAAmB;QACtC,OAAO,IAAA,kBAAO,EAAC,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,8CAA8C;IACvC,QAAQ,CAAC,KAAmB;QACjC,OAAO,OAAO,CAAC,OAAO,CACpB,IAAA,sCAA0B,EAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE;YAClE,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;gBAC5B,OAAO,IAAA,kBAAO,EAAC,EAAE,CAAC,CAAC;YACrB,CAAC;YACD,MAAM,OAAO,GAA6B,IAAA,yBAAa,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,IAAI,CACxF,IAAA,2BAAe,EAAC,KAAK,CAAC,OAAO,CAAC,CAC/B,CAAC;YACF,OAAO,IAAA,kBAAO,EAAC,IAAA,wBAAY,EAAC,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QACnE,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AA/BD,oCA+BC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport { Result, succeed } from '@fgv/ts-utils';\nimport { IMemoryRecord } from '../types';\nimport { IMemoryIndex } from '../index';\nimport {\n IMemoryQuery,\n IMemoryRetriever,\n IMemoryRetrieverCapabilities,\n NON_SEMANTIC_CAPABILITIES,\n guardRetrieverCapabilities,\n limitRecords,\n orderingCompare,\n selectByQuery\n} from './retriever';\n\n/**\n * Returns records carrying `query.tag`, recency-ordered within the tag and\n * narrowed by any scope / kind / provenance-source / predicate filters. Tag is this retriever's\n * axis: a query without a `tag` is not its concern and yields an empty success\n * (so it contributes nothing to a {@link HybridRetriever}, rather than failing).\n * @public\n */\nexport class TagRetriever implements IMemoryRetriever {\n private readonly _index: IMemoryIndex;\n\n private constructor(index: IMemoryIndex) {\n this._index = index;\n }\n\n /** {@inheritDoc IMemoryRetriever.capabilities} */\n public get capabilities(): IMemoryRetrieverCapabilities {\n return NON_SEMANTIC_CAPABILITIES;\n }\n\n /** Family-convention factory. */\n public static create(index: IMemoryIndex): Result<TagRetriever> {\n return succeed(new TagRetriever(index));\n }\n\n /** {@inheritDoc IMemoryRetriever.retrieve} */\n public retrieve(query: IMemoryQuery): Promise<Result<ReadonlyArray<IMemoryRecord<unknown>>>> {\n return Promise.resolve(\n guardRetrieverCapabilities(query, this.capabilities).onSuccess(() => {\n if (query.tag === undefined) {\n return succeed([]);\n }\n const ordered: IMemoryRecord<unknown>[] = selectByQuery(this._index.entries(), query).sort(\n orderingCompare(query.orderBy)\n );\n return succeed(limitRecords(ordered, query.limit, query.offset));\n })\n );\n }\n}\n"]}
|
|
@@ -20,7 +20,7 @@ exports.TEMPORAL_CAPABILITIES = {
|
|
|
20
20
|
supportsLinkTraversal: false
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
|
-
* Group the temporal records surviving a query's scope / kind / tag / predicate
|
|
23
|
+
* Group the temporal records surviving a query's scope / kind / tag / provenance-source / predicate
|
|
24
24
|
* pre-filter by entity (`kind` + `entityId`). Non-temporal records are excluded —
|
|
25
25
|
* the temporal retrievers operate only over versioned entities. The map values
|
|
26
26
|
* are each entity's versions (unordered).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporalRetrievers.js","sourceRoot":"","sources":["../../../src/packlets/retrieve/temporalRetrievers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAAgD;AAChD,oCAAoG;AAEpG,2CAQqB;AAErB;;;;;GAKG;AACU,QAAA,qBAAqB,GAAiC;IACjE,sBAAsB,EAAE,KAAK;IAC7B,qBAAqB,EAAE,IAAI;IAC3B,qBAAqB,EAAE,KAAK;CAC7B,CAAC;AAEF;;;;;GAKG;AACH,SAAS,6BAA6B,CACpC,KAAmB,EACnB,KAAmB;IAEnB,MAAM,MAAM,GAA0C,IAAI,GAAG,EAAoC,CAAC;IAClG,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;QACpC,IAAI,CAAC,IAAA,wBAAgB,EAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAA,qCAAyB,EAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC;YAChF,SAAS;QACX,CAAC;QACD,MAAM,GAAG,GAAW,GAAG,KAAK,CAAC,MAAM,CAAC,QAA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B;;QACpD,MAAM,QAAQ,GAAmD,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC1F,yLAAyL;QACzL,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QACjC,CAAC;QACD,OAAO,MAAA,QAAQ,CAAC,QAAQ,mCAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;IACtD,CAAC;IAED;;;;OAIG;IACK,MAAM,CAAC,mBAAmB,CAAC,CAAyB,EAAE,CAAyB;QACrF,MAAM,MAAM,GAAW,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACpD,MAAM,MAAM,GAAW,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACpD,OAAO,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;IAC/E,CAAC;CACF;AAnDD,4CAmDC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport { Result, succeed } from '@fgv/ts-utils';\nimport { IMemoryRecord, isTemporalRecord, selectCurrentVersion, selectVersionAsOf } from '../types';\nimport { IMemoryIndex } from '../index';\nimport {\n IMemoryQuery,\n IMemoryRetriever,\n IMemoryRetrieverCapabilities,\n guardRetrieverCapabilities,\n indexedRecordMatchesQuery,\n limitRecords,\n recencyCompare\n} from './retriever';\n\n/**\n * The capabilities every temporal retriever exposes: temporal \"as-of\" queries\n * are operational (semantic recall and link traversal are not this retriever's\n * concern).\n * @public\n */\nexport const TEMPORAL_CAPABILITIES: IMemoryRetrieverCapabilities = {\n supportsSemanticRecall: false,\n supportsTemporalQuery: true,\n supportsLinkTraversal: false\n};\n\n/**\n * Group the temporal records surviving a query's scope / kind / tag / predicate\n * pre-filter by entity (`kind` + `entityId`). Non-temporal records are excluded —\n * the temporal retrievers operate only over versioned entities. The map values\n * are each entity's versions (unordered).\n */\nfunction groupTemporalVersionsByEntity(\n index: IMemoryIndex,\n query: IMemoryQuery\n): Map<string, IMemoryRecord<unknown>[]> {\n const groups: Map<string, IMemoryRecord<unknown>[]> = new Map<string, IMemoryRecord<unknown>[]>();\n for (const entry of index.entries()) {\n if (!isTemporalRecord(entry.record) || !indexedRecordMatchesQuery(entry, query)) {\n continue;\n }\n const key: string = `${entry.record.envelope.kind}\\0${entry.record.envelope.entityId}`;\n const existing: IMemoryRecord<unknown>[] | undefined = groups.get(key);\n if (existing === undefined) {\n groups.set(key, [entry.record]);\n } else {\n existing.push(entry.record);\n }\n }\n return groups;\n}\n\n/**\n * Temporal retriever returning the **current** version of each temporal entity\n * matching the query (the newest version whose `invalid_at` is null/absent),\n * recency-ordered and limited. A fully-invalidated (soft-deleted) entity\n * contributes nothing. Non-temporal records are not this retriever's concern.\n * @public\n */\nexport class CurrentValidRetriever implements IMemoryRetriever {\n private readonly _index: IMemoryIndex;\n\n private constructor(index: IMemoryIndex) {\n this._index = index;\n }\n\n /** {@inheritDoc IMemoryRetriever.capabilities} */\n public get capabilities(): IMemoryRetrieverCapabilities {\n return TEMPORAL_CAPABILITIES;\n }\n\n /** Family-convention factory. */\n public static create(index: IMemoryIndex): Result<CurrentValidRetriever> {\n return succeed(new CurrentValidRetriever(index));\n }\n\n /** {@inheritDoc IMemoryRetriever.retrieve} */\n public retrieve(query: IMemoryQuery): Promise<Result<ReadonlyArray<IMemoryRecord<unknown>>>> {\n return Promise.resolve(\n guardRetrieverCapabilities(query, this.capabilities).onSuccess(() => {\n const selected: IMemoryRecord<unknown>[] = [];\n for (const versions of groupTemporalVersionsByEntity(this._index, query).values()) {\n const current: IMemoryRecord<unknown> | undefined = selectCurrentVersion(versions);\n if (current !== undefined) {\n selected.push(current);\n }\n }\n selected.sort(recencyCompare);\n return succeed(limitRecords(selected, query.limit, query.offset));\n })\n );\n }\n}\n\n/**\n * Temporal retriever returning, for each temporal entity matching the query, the\n * version valid at `query.asOf` (epoch ms). `asOf` is this retriever's axis: a\n * query without it yields an empty success (a no-op contribution to a\n * {@link HybridRetriever}, not a failure). Results are recency-ordered and\n * limited.\n * @public\n */\nexport class AsOfRetriever implements IMemoryRetriever {\n private readonly _index: IMemoryIndex;\n\n private constructor(index: IMemoryIndex) {\n this._index = index;\n }\n\n /** {@inheritDoc IMemoryRetriever.capabilities} */\n public get capabilities(): IMemoryRetrieverCapabilities {\n return TEMPORAL_CAPABILITIES;\n }\n\n /** Family-convention factory. */\n public static create(index: IMemoryIndex): Result<AsOfRetriever> {\n return succeed(new AsOfRetriever(index));\n }\n\n /** {@inheritDoc IMemoryRetriever.retrieve} */\n public retrieve(query: IMemoryQuery): Promise<Result<ReadonlyArray<IMemoryRecord<unknown>>>> {\n return Promise.resolve(\n guardRetrieverCapabilities(query, this.capabilities).onSuccess(() => {\n if (query.asOf === undefined) {\n return succeed([]);\n }\n const asOf: number = query.asOf;\n const selected: IMemoryRecord<unknown>[] = [];\n for (const versions of groupTemporalVersionsByEntity(this._index, query).values()) {\n const valid: IMemoryRecord<unknown> | undefined = selectVersionAsOf(versions, asOf);\n if (valid !== undefined) {\n selected.push(valid);\n }\n }\n selected.sort(recencyCompare);\n return succeed(limitRecords(selected, query.limit, query.offset));\n })\n );\n }\n}\n\n/**\n * Temporal retriever returning **every** version of each temporal entity matching\n * the query, ordered ascending by `valid_at` (then `seq` as a stable tiebreak) —\n * the entity's full history. Limited after ordering.\n *\n * @remarks\n * When the query matches more than one entity, the result is a single\n * CROSS-entity list globally sorted by `valid_at` — versions of different\n * entities interleave, NOT grouped per entity — so `limit` truncates that\n * globally-sorted list. Constrain to one entity (e.g. via `query.scope`) for a\n * single entity's contiguous history.\n * @public\n */\nexport class HistoryRetriever implements IMemoryRetriever {\n private readonly _index: IMemoryIndex;\n\n private constructor(index: IMemoryIndex) {\n this._index = index;\n }\n\n /** {@inheritDoc IMemoryRetriever.capabilities} */\n public get capabilities(): IMemoryRetrieverCapabilities {\n return TEMPORAL_CAPABILITIES;\n }\n\n /** Family-convention factory. */\n public static create(index: IMemoryIndex): Result<HistoryRetriever> {\n return succeed(new HistoryRetriever(index));\n }\n\n /** {@inheritDoc IMemoryRetriever.retrieve} */\n public retrieve(query: IMemoryQuery): Promise<Result<ReadonlyArray<IMemoryRecord<unknown>>>> {\n return Promise.resolve(\n guardRetrieverCapabilities(query, this.capabilities).onSuccess(() => {\n const history: IMemoryRecord<unknown>[] = [];\n for (const versions of groupTemporalVersionsByEntity(this._index, query).values()) {\n history.push(...versions);\n }\n history.sort(HistoryRetriever._byValidAtAscending);\n return succeed(limitRecords(history, query.limit, query.offset));\n })\n );\n }\n\n /** A version's world-truth start: its `valid_at`, defaulting to `created` when absent. */\n private static _startOf(record: IMemoryRecord<unknown>): number {\n const temporal: IMemoryRecord<unknown>['envelope']['temporal'] = record.envelope.temporal;\n /* c8 ignore next 3 -- unreachable: HistoryRetriever orders only temporal records (pre-filtered by isTemporalRecord), so `temporal` is always present; the guard keeps the type honest */\n if (temporal === undefined) {\n return record.envelope.created;\n }\n return temporal.valid_at ?? record.envelope.created;\n }\n\n /**\n * Ascending-by-`valid_at` comparator (a version's `valid_at` defaults to its\n * `created` when absent), with `seq` as a stable ascending tiebreak so\n * same-instant versions order by write sequence.\n */\n private static _byValidAtAscending(a: IMemoryRecord<unknown>, b: IMemoryRecord<unknown>): number {\n const aStart: number = HistoryRetriever._startOf(a);\n const bStart: number = HistoryRetriever._startOf(b);\n return aStart !== bStart ? aStart - bStart : a.envelope.seq - b.envelope.seq;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"temporalRetrievers.js","sourceRoot":"","sources":["../../../src/packlets/retrieve/temporalRetrievers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAAgD;AAChD,oCAAoG;AAEpG,2CAQqB;AAErB;;;;;GAKG;AACU,QAAA,qBAAqB,GAAiC;IACjE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port { Result, succeed } from '@fgv/ts-utils';\nimport { IMemoryRecord, isTemporalRecord, selectCurrentVersion, selectVersionAsOf } from '../types';\nimport { IMemoryIndex } from '../index';\nimport {\n IMemoryQuery,\n IMemoryRetriever,\n IMemoryRetrieverCapabilities,\n guardRetrieverCapabilities,\n indexedRecordMatchesQuery,\n limitRecords,\n recencyCompare\n} from './retriever';\n\n/**\n * The capabilities every temporal retriever exposes: temporal \"as-of\" queries\n * are operational (semantic recall and link traversal are not this retriever's\n * concern).\n * @public\n */\nexport const TEMPORAL_CAPABILITIES: IMemoryRetrieverCapabilities = {\n supportsSemanticRecall: false,\n supportsTemporalQuery: true,\n supportsLinkTraversal: false\n};\n\n/**\n * Group the temporal records surviving a query's scope / kind / tag / provenance-source / predicate\n * pre-filter by entity (`kind` + `entityId`). Non-temporal records are excluded —\n * the temporal retrievers operate only over versioned entities. The map values\n * are each entity's versions (unordered).\n */\nfunction groupTemporalVersionsByEntity(\n index: IMemoryIndex,\n query: IMemoryQuery\n): Map<string, IMemoryRecord<unknown>[]> {\n const groups: Map<string, IMemoryRecord<unknown>[]> = new Map<string, IMemoryRecord<unknown>[]>();\n for (const entry of index.entries()) {\n if (!isTemporalRecord(entry.record) || !indexedRecordMatchesQuery(entry, query)) {\n continue;\n }\n const key: string = `${entry.record.envelope.kind}\\0${entry.record.envelope.entityId}`;\n const existing: IMemoryRecord<unknown>[] | undefined = groups.get(key);\n if (existing === undefined) {\n groups.set(key, [entry.record]);\n } else {\n existing.push(entry.record);\n }\n }\n return groups;\n}\n\n/**\n * Temporal retriever returning the **current** version of each temporal entity\n * matching the query (the newest version whose `invalid_at` is null/absent),\n * recency-ordered and limited. A fully-invalidated (soft-deleted) entity\n * contributes nothing. Non-temporal records are not this retriever's concern.\n * @public\n */\nexport class CurrentValidRetriever implements IMemoryRetriever {\n private readonly _index: IMemoryIndex;\n\n private constructor(index: IMemoryIndex) {\n this._index = index;\n }\n\n /** {@inheritDoc IMemoryRetriever.capabilities} */\n public get capabilities(): IMemoryRetrieverCapabilities {\n return TEMPORAL_CAPABILITIES;\n }\n\n /** Family-convention factory. */\n public static create(index: IMemoryIndex): Result<CurrentValidRetriever> {\n return succeed(new CurrentValidRetriever(index));\n }\n\n /** {@inheritDoc IMemoryRetriever.retrieve} */\n public retrieve(query: IMemoryQuery): Promise<Result<ReadonlyArray<IMemoryRecord<unknown>>>> {\n return Promise.resolve(\n guardRetrieverCapabilities(query, this.capabilities).onSuccess(() => {\n const selected: IMemoryRecord<unknown>[] = [];\n for (const versions of groupTemporalVersionsByEntity(this._index, query).values()) {\n const current: IMemoryRecord<unknown> | undefined = selectCurrentVersion(versions);\n if (current !== undefined) {\n selected.push(current);\n }\n }\n selected.sort(recencyCompare);\n return succeed(limitRecords(selected, query.limit, query.offset));\n })\n );\n }\n}\n\n/**\n * Temporal retriever returning, for each temporal entity matching the query, the\n * version valid at `query.asOf` (epoch ms). `asOf` is this retriever's axis: a\n * query without it yields an empty success (a no-op contribution to a\n * {@link HybridRetriever}, not a failure). Results are recency-ordered and\n * limited.\n * @public\n */\nexport class AsOfRetriever implements IMemoryRetriever {\n private readonly _index: IMemoryIndex;\n\n private constructor(index: IMemoryIndex) {\n this._index = index;\n }\n\n /** {@inheritDoc IMemoryRetriever.capabilities} */\n public get capabilities(): IMemoryRetrieverCapabilities {\n return TEMPORAL_CAPABILITIES;\n }\n\n /** Family-convention factory. */\n public static create(index: IMemoryIndex): Result<AsOfRetriever> {\n return succeed(new AsOfRetriever(index));\n }\n\n /** {@inheritDoc IMemoryRetriever.retrieve} */\n public retrieve(query: IMemoryQuery): Promise<Result<ReadonlyArray<IMemoryRecord<unknown>>>> {\n return Promise.resolve(\n guardRetrieverCapabilities(query, this.capabilities).onSuccess(() => {\n if (query.asOf === undefined) {\n return succeed([]);\n }\n const asOf: number = query.asOf;\n const selected: IMemoryRecord<unknown>[] = [];\n for (const versions of groupTemporalVersionsByEntity(this._index, query).values()) {\n const valid: IMemoryRecord<unknown> | undefined = selectVersionAsOf(versions, asOf);\n if (valid !== undefined) {\n selected.push(valid);\n }\n }\n selected.sort(recencyCompare);\n return succeed(limitRecords(selected, query.limit, query.offset));\n })\n );\n }\n}\n\n/**\n * Temporal retriever returning **every** version of each temporal entity matching\n * the query, ordered ascending by `valid_at` (then `seq` as a stable tiebreak) —\n * the entity's full history. Limited after ordering.\n *\n * @remarks\n * When the query matches more than one entity, the result is a single\n * CROSS-entity list globally sorted by `valid_at` — versions of different\n * entities interleave, NOT grouped per entity — so `limit` truncates that\n * globally-sorted list. Constrain to one entity (e.g. via `query.scope`) for a\n * single entity's contiguous history.\n * @public\n */\nexport class HistoryRetriever implements IMemoryRetriever {\n private readonly _index: IMemoryIndex;\n\n private constructor(index: IMemoryIndex) {\n this._index = index;\n }\n\n /** {@inheritDoc IMemoryRetriever.capabilities} */\n public get capabilities(): IMemoryRetrieverCapabilities {\n return TEMPORAL_CAPABILITIES;\n }\n\n /** Family-convention factory. */\n public static create(index: IMemoryIndex): Result<HistoryRetriever> {\n return succeed(new HistoryRetriever(index));\n }\n\n /** {@inheritDoc IMemoryRetriever.retrieve} */\n public retrieve(query: IMemoryQuery): Promise<Result<ReadonlyArray<IMemoryRecord<unknown>>>> {\n return Promise.resolve(\n guardRetrieverCapabilities(query, this.capabilities).onSuccess(() => {\n const history: IMemoryRecord<unknown>[] = [];\n for (const versions of groupTemporalVersionsByEntity(this._index, query).values()) {\n history.push(...versions);\n }\n history.sort(HistoryRetriever._byValidAtAscending);\n return succeed(limitRecords(history, query.limit, query.offset));\n })\n );\n }\n\n /** A version's world-truth start: its `valid_at`, defaulting to `created` when absent. */\n private static _startOf(record: IMemoryRecord<unknown>): number {\n const temporal: IMemoryRecord<unknown>['envelope']['temporal'] = record.envelope.temporal;\n /* c8 ignore next 3 -- unreachable: HistoryRetriever orders only temporal records (pre-filtered by isTemporalRecord), so `temporal` is always present; the guard keeps the type honest */\n if (temporal === undefined) {\n return record.envelope.created;\n }\n return temporal.valid_at ?? record.envelope.created;\n }\n\n /**\n * Ascending-by-`valid_at` comparator (a version's `valid_at` defaults to its\n * `created` when absent), with `seq` as a stable ascending tiebreak so\n * same-instant versions order by write sequence.\n */\n private static _byValidAtAscending(a: IMemoryRecord<unknown>, b: IMemoryRecord<unknown>): number {\n const aStart: number = HistoryRetriever._startOf(a);\n const bStart: number = HistoryRetriever._startOf(b);\n return aStart !== bStart ? aStart - bStart : a.envelope.seq - b.envelope.seq;\n }\n}\n"]}
|
|
@@ -156,6 +156,36 @@ export interface IMemoryStore {
|
|
|
156
156
|
* existing record unchanged on a dedup no-op.
|
|
157
157
|
*/
|
|
158
158
|
put(record: IMemoryRecord<unknown>): Promise<Result<IMemoryRecord<unknown>>>;
|
|
159
|
+
/**
|
|
160
|
+
* Re-apply the kind's {@link RankProjector} to every record of `kind` already
|
|
161
|
+
* in the store, restamping {@link IMemoryEnvelope.rank}. Returns the number of
|
|
162
|
+
* records whose `rank` actually changed.
|
|
163
|
+
*
|
|
164
|
+
* @remarks
|
|
165
|
+
* **This exists because `rank` is otherwise new-store-only, and fails in a way
|
|
166
|
+
* that looks like it works.** The projector runs on the write path only, so
|
|
167
|
+
* registering one against a populated store ranks nothing already written —
|
|
168
|
+
* and because an absent `rank` sorts *last*, every pre-registration record
|
|
169
|
+
* lands below every post-registration one no matter what the projector would
|
|
170
|
+
* have scored it. The ordering is not merely partial; it is **inverted with
|
|
171
|
+
* respect to the projector's own intent**, with no failure anywhere to say so.
|
|
172
|
+
*
|
|
173
|
+
* Deliberately **does not** touch `created` / `updated` / `seq`, and fires no
|
|
174
|
+
* `'write'` observation. Routing a reconcile through {@link IMemoryStore.put}
|
|
175
|
+
* would bump transaction time on every record — trading a wrong `rank` order
|
|
176
|
+
* for a wrong recency order, and flooding any wired observer with writes that
|
|
177
|
+
* are not writes. The body is re-serialized verbatim from the file's own
|
|
178
|
+
* bytes; only the envelope's `rank` moves.
|
|
179
|
+
*
|
|
180
|
+
* Fails loudly if `kind` has no registered projector: asking to reconcile a
|
|
181
|
+
* kind you never configured is a caller error, not a no-op.
|
|
182
|
+
*
|
|
183
|
+
* **Not atomic, and safe for it.** A failure part-way leaves earlier records
|
|
184
|
+
* restamped. That is benign because restamping is idempotent — re-running
|
|
185
|
+
* converges — which is also why no report shape is offered here. A count is
|
|
186
|
+
* enough.
|
|
187
|
+
*/
|
|
188
|
+
reconcileRank(kind: Kind): Promise<Result<number>>;
|
|
159
189
|
/**
|
|
160
190
|
* Delete a record by `(kind, entityId)`. Non-temporal kinds physically delete
|
|
161
191
|
* the file and return the deleted record's {@link MemoryId}. Temporal
|
|
@@ -454,6 +484,8 @@ export declare class FileTreeMemoryStore implements IMemoryStore {
|
|
|
454
484
|
* contributes nothing.
|
|
455
485
|
*/
|
|
456
486
|
private static _projectAsOf;
|
|
487
|
+
/** {@inheritDoc IMemoryStore.reconcileRank} */
|
|
488
|
+
reconcileRank(kind: Kind): Promise<Result<number>>;
|
|
457
489
|
/** {@inheritDoc IMemoryStore.put} */
|
|
458
490
|
put(record: IMemoryRecord<unknown>): Promise<Result<IMemoryRecord<unknown>>>;
|
|
459
491
|
/** {@inheritDoc IMemoryStore.delete} */
|
|
@@ -628,6 +660,43 @@ export declare class FileTreeMemoryStore implements IMemoryStore {
|
|
|
628
660
|
*/
|
|
629
661
|
private _isMutableMetadataUnchanged;
|
|
630
662
|
private _contentHash;
|
|
663
|
+
/**
|
|
664
|
+
* The locked body of {@link FileTreeMemoryStore.reconcileRank}.
|
|
665
|
+
*
|
|
666
|
+
* @remarks
|
|
667
|
+
* Re-reads each record's file rather than trusting the in-memory index, for
|
|
668
|
+
* two reasons: the index holds converted bodies on some paths and raw ones on
|
|
669
|
+
* others, and re-serializing a *converted* body could change the bytes on disk
|
|
670
|
+
* — a reconcile of an ordering field has no business rewriting content.
|
|
671
|
+
* `splitFrontmatter` hands back the body text unconverted, so the round trip
|
|
672
|
+
* carries the authored characters through untouched and only the envelope
|
|
673
|
+
* moves. The parsed record is additionally put through `_verifyLoaded`, the
|
|
674
|
+
* same id-vs-filename and scope-derived-entityId check the load paths apply —
|
|
675
|
+
* without it, reconcile would be the one path that accepts and rewrites a file
|
|
676
|
+
* the store would refuse to load.
|
|
677
|
+
*
|
|
678
|
+
* "Untouched" is not quite "byte-identical", and the exception is line
|
|
679
|
+
* endings: `splitFrontmatter` strips a trailing `\r` per line and
|
|
680
|
+
* `joinFrontmatter` writes `\n` delimiters, so a CRLF-authored file comes back
|
|
681
|
+
* LF-normalized. That is **the store's behavior on every write path, not
|
|
682
|
+
* something reconcile introduces** — an ordinary `put` normalizes the same way
|
|
683
|
+
* — so reconcile does not rewrite content that a subsequent write would have
|
|
684
|
+
* left alone. The property being claimed here is the narrower and load-bearing
|
|
685
|
+
* one: no body is round-tripped through its registered Converter.
|
|
686
|
+
*
|
|
687
|
+
* The projector is fed an `IMemoryRecord<string>` carrying that raw body,
|
|
688
|
+
* which is exactly the shape {@link FileTreeMemoryStore._stampRank} hands it
|
|
689
|
+
* on the write path — so a projector cannot see one thing on a write and
|
|
690
|
+
* another on a reconcile. `_stampRank` itself is reused verbatim, which also
|
|
691
|
+
* inherits its throw semantics (logged at `warn`, `rank` cleared).
|
|
692
|
+
*/
|
|
693
|
+
private _reconcileRankLocked;
|
|
694
|
+
/**
|
|
695
|
+
* Re-apply the rank projector to one record on disk. Returns whether `rank`
|
|
696
|
+
* actually changed — an unchanged rank writes nothing, so a reconcile over an
|
|
697
|
+
* already-consistent store touches no files.
|
|
698
|
+
*/
|
|
699
|
+
private _restampOne;
|
|
631
700
|
/**
|
|
632
701
|
* Stamp the store-computed {@link IMemoryEnvelope.rank} onto a fully-built,
|
|
633
702
|
* fully-stamped record by running the kind's registered {@link RankProjector}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileTreeMemoryStore.d.ts","sourceRoot":"","sources":["../../../src/packlets/store/fileTreeMemoryStore.ts"],"names":[],"mappings":"AAKA,OAAO,EAAQ,OAAO,EAAE,MAAM,EAAyC,MAAM,eAAe,CAAC;AA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;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAgB1B;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,2BAA2B;IAYnC,OAAO,CAAC,YAAY;IAIpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;YACW,oBAAoB;IAoBlC;;;;OAIG;IACH,OAAO,CAAC,WAAW;IA+CnB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,UAAU;IAqBlB,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,UAAU;IAIlB,+CAA+C;IACxC,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,UAAU;IAI5C,4CAA4C;IACrC,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAMtC;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAqBnB;;;;;;;;OAQG;IACH,OAAO,CAAC,aAAa;IAyBrB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAwBxB,sEAAsE;IACtE,OAAO,CAAC,eAAe;IAyBvB,oEAAoE;IACpE,OAAO,CAAC,UAAU;IAmBlB;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAwBnB;;;;;;;OAOG;IACH,OAAO,CAAC,aAAa;IAarB,kFAAkF;IAClF,OAAO,CAAC,eAAe;IAiCvB;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;CAoBxB"}
|
|
@@ -221,6 +221,10 @@ class FileTreeMemoryStore {
|
|
|
221
221
|
}
|
|
222
222
|
return result;
|
|
223
223
|
}
|
|
224
|
+
/** {@inheritDoc IMemoryStore.reconcileRank} */
|
|
225
|
+
async reconcileRank(kind) {
|
|
226
|
+
return this._enqueue(() => this._reconcileRankLocked(kind));
|
|
227
|
+
}
|
|
224
228
|
/** {@inheritDoc IMemoryStore.put} */
|
|
225
229
|
async put(record) {
|
|
226
230
|
const result = await this._enqueue(() => this._putLocked(record));
|
|
@@ -811,6 +815,101 @@ class FileTreeMemoryStore {
|
|
|
811
815
|
_contentHash(kind, body, links) {
|
|
812
816
|
return this._hasher.computeHash({ kind, body, links });
|
|
813
817
|
}
|
|
818
|
+
/**
|
|
819
|
+
* The locked body of {@link FileTreeMemoryStore.reconcileRank}.
|
|
820
|
+
*
|
|
821
|
+
* @remarks
|
|
822
|
+
* Re-reads each record's file rather than trusting the in-memory index, for
|
|
823
|
+
* two reasons: the index holds converted bodies on some paths and raw ones on
|
|
824
|
+
* others, and re-serializing a *converted* body could change the bytes on disk
|
|
825
|
+
* — a reconcile of an ordering field has no business rewriting content.
|
|
826
|
+
* `splitFrontmatter` hands back the body text unconverted, so the round trip
|
|
827
|
+
* carries the authored characters through untouched and only the envelope
|
|
828
|
+
* moves. The parsed record is additionally put through `_verifyLoaded`, the
|
|
829
|
+
* same id-vs-filename and scope-derived-entityId check the load paths apply —
|
|
830
|
+
* without it, reconcile would be the one path that accepts and rewrites a file
|
|
831
|
+
* the store would refuse to load.
|
|
832
|
+
*
|
|
833
|
+
* "Untouched" is not quite "byte-identical", and the exception is line
|
|
834
|
+
* endings: `splitFrontmatter` strips a trailing `\r` per line and
|
|
835
|
+
* `joinFrontmatter` writes `\n` delimiters, so a CRLF-authored file comes back
|
|
836
|
+
* LF-normalized. That is **the store's behavior on every write path, not
|
|
837
|
+
* something reconcile introduces** — an ordinary `put` normalizes the same way
|
|
838
|
+
* — so reconcile does not rewrite content that a subsequent write would have
|
|
839
|
+
* left alone. The property being claimed here is the narrower and load-bearing
|
|
840
|
+
* one: no body is round-tripped through its registered Converter.
|
|
841
|
+
*
|
|
842
|
+
* The projector is fed an `IMemoryRecord<string>` carrying that raw body,
|
|
843
|
+
* which is exactly the shape {@link FileTreeMemoryStore._stampRank} hands it
|
|
844
|
+
* on the write path — so a projector cannot see one thing on a write and
|
|
845
|
+
* another on a reconcile. `_stampRank` itself is reused verbatim, which also
|
|
846
|
+
* inherits its throw semantics (logged at `warn`, `rank` cleared).
|
|
847
|
+
*/
|
|
848
|
+
async _reconcileRankLocked(kind) {
|
|
849
|
+
if (!this._rankProjectors.has(kind)) {
|
|
850
|
+
return (0, ts_utils_1.fail)(`memory reconcileRank '${kind}': no rank projector is registered for this kind`);
|
|
851
|
+
}
|
|
852
|
+
const targets = this._index
|
|
853
|
+
.entries()
|
|
854
|
+
.filter((entry) => entry.record.envelope.kind === kind);
|
|
855
|
+
let restamped = 0;
|
|
856
|
+
for (const target of targets) {
|
|
857
|
+
const applied = this._restampOne(target.scope, target.record.envelope.id);
|
|
858
|
+
if (applied.isFailure()) {
|
|
859
|
+
return (0, ts_utils_1.fail)(`memory reconcileRank '${kind}': ${applied.message}`);
|
|
860
|
+
}
|
|
861
|
+
if (applied.value) {
|
|
862
|
+
restamped++;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return (0, ts_utils_1.succeed)(restamped);
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Re-apply the rank projector to one record on disk. Returns whether `rank`
|
|
869
|
+
* actually changed — an unchanged rank writes nothing, so a reconcile over an
|
|
870
|
+
* already-consistent store touches no files.
|
|
871
|
+
*/
|
|
872
|
+
_restampOne(scope, id) {
|
|
873
|
+
return this._resolveScopeDir(scope).onSuccess((scopeDir) => {
|
|
874
|
+
/* c8 ignore next 3 - defensive: the scope dir exists for any indexed record */
|
|
875
|
+
if (scopeDir === undefined) {
|
|
876
|
+
return (0, ts_utils_1.fail)(`'${id}': scope '${scope}' not found`);
|
|
877
|
+
}
|
|
878
|
+
return scopeDir.getChildren().onSuccess((children) => {
|
|
879
|
+
const targetName = `${id}${MEMORY_FILE_EXTENSION}`;
|
|
880
|
+
const file = children.find((c) => c.type === 'file' && c.name === targetName);
|
|
881
|
+
/* c8 ignore next 3 - defensive: the file exists for any indexed record */
|
|
882
|
+
if (file === undefined) {
|
|
883
|
+
return (0, ts_utils_1.fail)(`'${id}': file not found`);
|
|
884
|
+
}
|
|
885
|
+
return file.getRawContents().onSuccess((raw) =>
|
|
886
|
+
// `parseMemoryFile` validates the body through the registered Converter,
|
|
887
|
+
// so a corrupt record is refused rather than silently rewritten, and
|
|
888
|
+
// `_verifyLoaded` re-applies the same id-vs-filename and
|
|
889
|
+
// scope-derived-entityId checks the two load paths apply. Reconcile is a
|
|
890
|
+
// read-then-write, and a file can change on disk after the index was
|
|
891
|
+
// built, so skipping them would make this the one path that accepts —
|
|
892
|
+
// and rewrites — a record the store would otherwise refuse to load.
|
|
893
|
+
// `splitFrontmatter` then supplies the body text for the write.
|
|
894
|
+
(0, converters_1.parseMemoryFile)(raw, this._registry)
|
|
895
|
+
.withErrorFormat((msg) => `'${id}': ${msg}`)
|
|
896
|
+
.onSuccess((parsedRecord) => this._verifyLoaded(scope, file, parsedRecord))
|
|
897
|
+
.onSuccess((parsed) => (0, converters_1.splitFrontmatter)(raw)
|
|
898
|
+
.withErrorFormat((msg) => `'${id}': ${msg}`)
|
|
899
|
+
.onSuccess((parts) => {
|
|
900
|
+
const before = parsed.envelope.rank;
|
|
901
|
+
const stamped = this._stampRank({
|
|
902
|
+
envelope: parsed.envelope,
|
|
903
|
+
body: parts.body
|
|
904
|
+
});
|
|
905
|
+
if (stamped.envelope.rank === before) {
|
|
906
|
+
return (0, ts_utils_1.succeed)(false);
|
|
907
|
+
}
|
|
908
|
+
return this._persist(stamped, scope, id).onSuccess(() => (0, ts_utils_1.succeed)(true));
|
|
909
|
+
})));
|
|
910
|
+
});
|
|
911
|
+
});
|
|
912
|
+
}
|
|
814
913
|
/**
|
|
815
914
|
* Stamp the store-computed {@link IMemoryEnvelope.rank} onto a fully-built,
|
|
816
915
|
* fully-stamped record by running the kind's registered {@link RankProjector}.
|