@x12i/analytix-memorix 1.0.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/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/memorix-runtime-store.d.ts +30 -0
- package/dist/memorix-runtime-store.d.ts.map +1 -0
- package/dist/memorix-runtime-store.js +83 -0
- package/dist/memorix-runtime-store.js.map +1 -0
- package/package.json +26 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,gCAAgC,EAChC,kCAAkC,GACnC,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,gCAAgC,EAChC,kCAAkC,GACnC,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AnalytixRunResult } from "@x12i/analytix-contracts";
|
|
2
|
+
import type { ExecutionRecord, RuntimeStore } from "@x12i/analytix";
|
|
3
|
+
import { type MemorixWriterClient } from "@x12i/memorix-writer";
|
|
4
|
+
/** IDs registered against the shared Memorix Catalox catalog — see scripts/register-descriptors.mjs */
|
|
5
|
+
export declare const ANALYTIX_MEMORIX_WRITE_DESCRIPTORS: {
|
|
6
|
+
readonly resultCache: "analytix-result-cache-write";
|
|
7
|
+
readonly tierOutput: "analytix-tier-output-write";
|
|
8
|
+
readonly execution: "analytix-execution-write";
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* RuntimeStore backed by Memorix (descriptor-driven write layer over MongoDB) instead of a
|
|
12
|
+
* hand-rolled Mongo collection. Reads are served from an in-memory mirror that's populated as
|
|
13
|
+
* results are produced in this process — there is no cross-process hydration yet (see README).
|
|
14
|
+
*/
|
|
15
|
+
export declare class MemorixRuntimeStore implements RuntimeStore {
|
|
16
|
+
private writer;
|
|
17
|
+
private cacheMirror;
|
|
18
|
+
private tierMirror;
|
|
19
|
+
constructor(writer: MemorixWriterClient);
|
|
20
|
+
getCache(key: string): AnalytixRunResult | null;
|
|
21
|
+
setCache(key: string, result: AnalytixRunResult): void;
|
|
22
|
+
addExecution(record: ExecutionRecord): void;
|
|
23
|
+
listExecutions(): ExecutionRecord[];
|
|
24
|
+
private tierBucketKey;
|
|
25
|
+
getTierOutput(tierId: string, paramsKey: string): unknown | null;
|
|
26
|
+
getTierAnalyticOutput(tierId: string, paramsKey: string, analyticId: string): unknown | null;
|
|
27
|
+
setTierOutput(tierId: string, paramsKey: string, analyticId: string, output: unknown): void;
|
|
28
|
+
}
|
|
29
|
+
export declare function createMemorixRuntimeStoreFromEnv(): Promise<MemorixRuntimeStore>;
|
|
30
|
+
//# sourceMappingURL=memorix-runtime-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memorix-runtime-store.d.ts","sourceRoot":"","sources":["../src/memorix-runtime-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAkD,KAAK,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhH,uGAAuG;AACvG,eAAO,MAAM,kCAAkC;;;;CAIrC,CAAC;AAMX;;;;GAIG;AACH,qBAAa,mBAAoB,YAAW,YAAY;IAI1C,OAAO,CAAC,MAAM;IAH1B,OAAO,CAAC,WAAW,CAAwC;IAC3D,OAAO,CAAC,UAAU,CAA8C;gBAE5C,MAAM,EAAE,mBAAmB;IAE/C,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI;IAI/C,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAUtD,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI;IAS3C,cAAc,IAAI,eAAe,EAAE;IAMnC,OAAO,CAAC,aAAa;IAIrB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAIhE,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAK5F,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;CAY5F;AAED,wBAAsB,gCAAgC,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAWrF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createMemorixWriterFromEnv, writeMemorixRecord } from "@x12i/memorix-writer";
|
|
2
|
+
/** IDs registered against the shared Memorix Catalox catalog — see scripts/register-descriptors.mjs */
|
|
3
|
+
export const ANALYTIX_MEMORIX_WRITE_DESCRIPTORS = {
|
|
4
|
+
resultCache: "analytix-result-cache-write",
|
|
5
|
+
tierOutput: "analytix-tier-output-write",
|
|
6
|
+
execution: "analytix-execution-write",
|
|
7
|
+
};
|
|
8
|
+
function logWriteFailure(label, err) {
|
|
9
|
+
console.error(`[analytix-memorix] ${label} failed`, err instanceof Error ? err.message : err);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* RuntimeStore backed by Memorix (descriptor-driven write layer over MongoDB) instead of a
|
|
13
|
+
* hand-rolled Mongo collection. Reads are served from an in-memory mirror that's populated as
|
|
14
|
+
* results are produced in this process — there is no cross-process hydration yet (see README).
|
|
15
|
+
*/
|
|
16
|
+
export class MemorixRuntimeStore {
|
|
17
|
+
writer;
|
|
18
|
+
cacheMirror = new Map();
|
|
19
|
+
tierMirror = new Map();
|
|
20
|
+
constructor(writer) {
|
|
21
|
+
this.writer = writer;
|
|
22
|
+
}
|
|
23
|
+
getCache(key) {
|
|
24
|
+
return this.cacheMirror.get(key) ?? null;
|
|
25
|
+
}
|
|
26
|
+
setCache(key, result) {
|
|
27
|
+
this.cacheMirror.set(key, result);
|
|
28
|
+
void writeMemorixRecord(this.writer, {
|
|
29
|
+
writeDescriptorId: ANALYTIX_MEMORIX_WRITE_DESCRIPTORS.resultCache,
|
|
30
|
+
operation: "upsert",
|
|
31
|
+
entityId: key,
|
|
32
|
+
input: { cacheKey: key, result },
|
|
33
|
+
}).catch((err) => logWriteFailure("result-cache write", err));
|
|
34
|
+
}
|
|
35
|
+
addExecution(record) {
|
|
36
|
+
void writeMemorixRecord(this.writer, {
|
|
37
|
+
writeDescriptorId: ANALYTIX_MEMORIX_WRITE_DESCRIPTORS.execution,
|
|
38
|
+
operation: "add",
|
|
39
|
+
eventId: `exec_${record.traceId}_${Date.now()}`,
|
|
40
|
+
input: { ...record },
|
|
41
|
+
}).catch((err) => logWriteFailure("execution write", err));
|
|
42
|
+
}
|
|
43
|
+
listExecutions() {
|
|
44
|
+
// Execution history lives in Memorix (memorix-events); querying it back is a read-path
|
|
45
|
+
// follow-up (see README) — not needed on the hot path today.
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
tierBucketKey(tierId, paramsKey) {
|
|
49
|
+
return `${tierId}:${paramsKey}`;
|
|
50
|
+
}
|
|
51
|
+
getTierOutput(tierId, paramsKey) {
|
|
52
|
+
return this.tierMirror.get(this.tierBucketKey(tierId, paramsKey)) ?? null;
|
|
53
|
+
}
|
|
54
|
+
getTierAnalyticOutput(tierId, paramsKey, analyticId) {
|
|
55
|
+
const bucket = this.tierMirror.get(this.tierBucketKey(tierId, paramsKey));
|
|
56
|
+
return bucket?.[analyticId] ?? null;
|
|
57
|
+
}
|
|
58
|
+
setTierOutput(tierId, paramsKey, analyticId, output) {
|
|
59
|
+
const bucketKey = this.tierBucketKey(tierId, paramsKey);
|
|
60
|
+
const bucket = this.tierMirror.get(bucketKey) ?? {};
|
|
61
|
+
bucket[analyticId] = output;
|
|
62
|
+
this.tierMirror.set(bucketKey, bucket);
|
|
63
|
+
void writeMemorixRecord(this.writer, {
|
|
64
|
+
writeDescriptorId: ANALYTIX_MEMORIX_WRITE_DESCRIPTORS.tierOutput,
|
|
65
|
+
operation: "upsert",
|
|
66
|
+
entityId: bucketKey,
|
|
67
|
+
input: { tierId, paramsKey, outputs: bucket },
|
|
68
|
+
}).catch((err) => logWriteFailure("tier-output write", err));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export async function createMemorixRuntimeStoreFromEnv() {
|
|
72
|
+
const { createCataloxFromEnv } = await import("@x12i/catalox/firebase");
|
|
73
|
+
const appId = process.env.CATALOX_APP_ID || "analytix";
|
|
74
|
+
const { catalox } = createCataloxFromEnv();
|
|
75
|
+
const bound = catalox.withContext({
|
|
76
|
+
appId,
|
|
77
|
+
actor: { type: "service", id: "analytix-server" },
|
|
78
|
+
superAdmin: true,
|
|
79
|
+
});
|
|
80
|
+
const writer = await createMemorixWriterFromEnv({ appId, catalox: bound });
|
|
81
|
+
return new MemorixRuntimeStore(writer);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=memorix-runtime-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memorix-runtime-store.js","sourceRoot":"","sources":["../src/memorix-runtime-store.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAA4B,MAAM,sBAAsB,CAAC;AAEhH,uGAAuG;AACvG,MAAM,CAAC,MAAM,kCAAkC,GAAG;IAChD,WAAW,EAAE,6BAA6B;IAC1C,UAAU,EAAE,4BAA4B;IACxC,SAAS,EAAE,0BAA0B;CAC7B,CAAC;AAEX,SAAS,eAAe,CAAC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MAAM,EAAE;SAC9C,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,eAAe,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC,CAAC;IAC/D,CAAC;CACF;AAED,MAAM,CAAC,KAAK,UAAU,gCAAgC;IACpD,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAC;IACxE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,UAAU,CAAC;IACvD,MAAM,EAAE,OAAO,EAAE,GAAG,oBAAoB,EAAE,CAAC;IAC3C,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC;QAChC,KAAK;QACL,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,iBAAiB,EAAE;QACjD,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,MAAM,0BAA0B,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,KAAc,EAAE,CAAC,CAAC;IACpF,OAAO,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC;AACzC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@x12i/analytix-memorix",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@x12i/catalox": "^5.10.1",
|
|
9
|
+
"@x12i/memorix-writer": "^1.7.0",
|
|
10
|
+
"@x12i/analytix": "^1.0.0",
|
|
11
|
+
"@x12i/analytix-contracts": "^1.0.0"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@x12i/memorix-descriptors": "^1.16.0"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public",
|
|
21
|
+
"registry": "https://registry.npmjs.org/"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -p tsconfig.json"
|
|
25
|
+
}
|
|
26
|
+
}
|