@xyo-network/diviner-forecasting-memory 7.2.3 → 7.3.1

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.
@@ -1,2 +1,2 @@
1
- export * from './MemoryForecastingDiviner.ts';
1
+ export * from '@xyo-network/diviner-forecasting/memory';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,cAAc,yCAAyC,CAAA"}
@@ -1,89 +1,3 @@
1
- // src/MemoryForecastingDiviner.ts
2
- import { assertEx, exists } from "@ariestools/sdk";
3
- import { AbstractForecastingDiviner } from "@xyo-network/diviner-forecasting-abstract";
4
- import {
5
- arimaForecastingMethod,
6
- seasonalArimaForecastingMethod
7
- } from "@xyo-network/diviner-forecasting-method-arima";
8
- import { ForecastingDivinerConfigSchema } from "@xyo-network/diviner-forecasting-model";
9
- import { asArchivistInstance } from "@xyo-network/sdk/archivist-model";
10
- import { BoundWitnessDivinerQuerySchema } from "@xyo-network/sdk/diviner-boundwitness/model";
11
- import { asDivinerInstance } from "@xyo-network/sdk/diviner-model";
12
- import { JSONPath } from "jsonpath-plus";
13
- var getJsonPathTransformer = (pathExpression) => {
14
- return (x) => {
15
- const ret = JSONPath({ path: pathExpression, json: x })[0];
16
- if (typeof ret === "number") return ret;
17
- throw new Error("Parsed invalid payload value");
18
- };
19
- };
20
- var defaultBatchLimit = 1e3;
21
- var defaultMaxTrainingLength = 1e4;
22
- var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractForecastingDiviner {
23
- static configSchemas = [...super.configSchemas, ForecastingDivinerConfigSchema];
24
- static defaultConfigSchema = ForecastingDivinerConfigSchema;
25
- static forecastingMethodDict = {
26
- arimaForecasting: arimaForecastingMethod,
27
- seasonalArimaForecasting: seasonalArimaForecastingMethod
28
- };
29
- get boundWitnessDiviner() {
30
- return assertEx(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
31
- }
32
- /**
33
- * The max number of records to search during the batch query
34
- */
35
- get batchLimit() {
36
- return this.config.batchLimit ?? defaultBatchLimit;
37
- }
38
- get forecastingMethod() {
39
- const forecastingMethodName = assertEx(this.config.forecastingMethod, () => "Missing forecastingMethod in config");
40
- const forecastingMethod = _MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName];
41
- if (forecastingMethod) return forecastingMethod;
42
- throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
43
- }
44
- get maxTrainingLength() {
45
- return this.config.maxTrainingLength ?? defaultMaxTrainingLength;
46
- }
47
- get transformer() {
48
- const pathExpression = assertEx(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
49
- return getJsonPathTransformer(pathExpression);
50
- }
51
- async getPayloadsInWindow(_startTimestamp, _stopTimestamp) {
52
- const addresses = this.config.witnessAddresses;
53
- const payload_schemas = [assertEx(this.config.witnessSchema, () => "Missing witnessSchema in config")];
54
- const payloads = [];
55
- const archivist = asArchivistInstance(await this.archivistInstance(), () => "Unable to resolve archivist", { required: true });
56
- const bwDiviner = asDivinerInstance(
57
- await this.resolve(this.boundWitnessDiviner),
58
- "Unable to resolve boundWitnessDiviner"
59
- );
60
- const limit = this.batchLimit;
61
- const witnessSchema = assertEx(this.config.witnessSchema, () => "Missing witnessSchema in config");
62
- let more = true;
63
- while (more || payloads.length < this.maxTrainingLength) {
64
- const query = {
65
- addresses,
66
- limit,
67
- payload_schemas,
68
- schema: BoundWitnessDivinerQuerySchema
69
- };
70
- const boundWitnesses = (await bwDiviner.divine([query])).filter(
71
- // TODO; Replace with sequence
72
- // bw => bw.$timestamp && bw.$timestamp >= startTimestamp && bw.$timestamp <= stopTimestamp,
73
- (_) => true
74
- );
75
- if (boundWitnesses.length === 0) break;
76
- more = boundWitnesses.length === limit;
77
- const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists);
78
- if (hashes.length > 0) {
79
- const batchPayloads = (await archivist.get(hashes)).filter(exists);
80
- payloads.push(...batchPayloads);
81
- }
82
- }
83
- return payloads;
84
- }
85
- };
86
- export {
87
- MemoryForecastingDiviner
88
- };
1
+ // src/index.ts
2
+ export * from "@xyo-network/diviner-forecasting/memory";
89
3
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/MemoryForecastingDiviner.ts"],
4
- "sourcesContent": ["import type { Hash } from '@ariestools/sdk'\nimport { assertEx, exists } from '@ariestools/sdk'\nimport type { ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport { AbstractForecastingDiviner } from '@xyo-network/diviner-forecasting-abstract'\nimport type {\n arimaForecastingName,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport {\n arimaForecastingMethod,\n seasonalArimaForecastingMethod,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport type { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { ForecastingDivinerConfigSchema } from '@xyo-network/diviner-forecasting-model'\nimport { asArchivistInstance } from '@xyo-network/sdk/archivist-model'\nimport type { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload } from '@xyo-network/sdk/diviner-boundwitness/model'\nimport { BoundWitnessDivinerQuerySchema } from '@xyo-network/sdk/diviner-boundwitness/model'\nimport type { DivinerInstance } from '@xyo-network/sdk/diviner-model'\nimport { asDivinerInstance } from '@xyo-network/sdk/diviner-model'\nimport type { ModuleIdentifier } from '@xyo-network/sdk/module-model'\nimport type {\n BoundWitness, Payload, Schema,\n} from '@xyo-network/sdk-protocol'\nimport { JSONPath } from 'jsonpath-plus'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n const ret = JSONPath({ path: pathExpression, json: x })[0]\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner(): ModuleIdentifier {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit(): number {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength(): number {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(_startTimestamp: number, _stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist', { required: true })\n // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style\n const bwDiviner = asDivinerInstance(\n await this.resolve(this.boundWitnessDiviner),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n // let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = {\n addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema,\n }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n // TODO; Replace with sequence\n // bw => bw.$timestamp && bw.$timestamp >= startTimestamp && bw.$timestamp <= stopTimestamp,\n _ => true,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n /* timestamp = boundWitnesses\n .map(bw => bw.$timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n */\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = (boundWitnesses.map(bw => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]) as Hash[]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],
5
- "mappings": ";AACA,SAAS,UAAU,cAAc;AAEjC,SAAS,kCAAkC;AAK3C;AAAA,EACE;AAAA,EACA;AAAA,OAC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,gBAA4C;AAChH,UAAM,YAAY,KAAK,OAAO;AAC9B,UAAM,kBAAkB,CAAC,SAAS,KAAK,OAAO,eAAe,MAAM,iCAAiC,CAAC;AACrG,UAAM,WAAsB,CAAC;AAC7B,UAAM,YAAY,oBAAoB,MAAM,KAAK,kBAAkB,GAAG,MAAM,+BAA+B,EAAE,UAAU,KAAK,CAAC;AAE7H,UAAM,YAAY;AAAA,MAChB,MAAM,KAAK,QAAQ,KAAK,mBAAmB;AAAA,MAC3C;AAAA,IACF;AACA,UAAM,QAAQ,KAAK;AACnB,UAAM,gBAAgB,SAAS,KAAK,OAAO,eAAe,MAAM,iCAAiC;AAEjG,QAAI,OAAO;AAIX,WAAO,QAAQ,SAAS,SAAS,KAAK,mBAAmB;AACvD,YAAM,QAAyC;AAAA,QAC7C;AAAA,QAAW;AAAA,QAAO;AAAA,QAAiB,QAAQ;AAAA,MAC7C;AACA,YAAM,kBAAkB,MAAM,UAAU,OAAO,CAAC,KAAK,CAAC,GAAG;AAAA;AAAA;AAAA,QAGvD,OAAK;AAAA,MACP;AACA,UAAI,eAAe,WAAW,EAAG;AAYjC,aAAO,eAAe,WAAW;AAGjC,YAAM,SAAU,eAAe,IAAI,QAAM,GAAG,eAAe,GAAG,gBAAgB,QAAQ,aAAa,CAAC,CAAC,EAAa,OAAO,MAAM;AAG/H,UAAI,OAAO,SAAS,GAAG;AACrB,cAAM,iBAAiB,MAAM,UAAU,IAAI,MAAM,GAAG,OAAO,MAAM;AACjE,iBAAS,KAAK,GAAG,aAAa;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["// Compatibility shim: this package re-exports from @xyo-network/diviner-forecasting/memory.\nexport * from '@xyo-network/diviner-forecasting/memory'\n"],
5
+ "mappings": ";AACA,cAAc;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/diviner-forecasting-memory",
3
- "version": "7.2.3",
3
+ "version": "7.3.1",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -34,30 +34,24 @@
34
34
  "README.md"
35
35
  ],
36
36
  "dependencies": {
37
- "@xyo-network/sdk-protocol": "~7.2.3",
38
- "jsonpath-plus": "~10.4.0",
39
- "@xyo-network/diviner-forecasting-abstract": "~7.2.3",
40
- "@xyo-network/diviner-forecasting-model": "~7.2.3",
41
- "@xyo-network/diviner-forecasting-method-arima": "~7.2.3",
42
- "@xyo-network/sdk": "~7.2.3"
37
+ "@xyo-network/diviner-forecasting": "~7.3.1"
43
38
  },
44
39
  "devDependencies": {
45
- "@ariestools/sdk": "~8.1.6",
46
- "@ariestools/toolchain": "~8.7.26",
47
- "@ariestools/tsconfig": "~8.7.26",
40
+ "@ariestools/sdk": "~8.1.9",
41
+ "@ariestools/toolchain": "~9.1.1",
42
+ "@ariestools/tsconfig": "~9.1.1",
48
43
  "@opentelemetry/api": "~1.9.1",
49
- "eslint": "~10.8.0",
44
+ "@xyo-network/sdk-protocol": "~7.3.3",
45
+ "eslint": "~10.9.0",
50
46
  "eslint-import-resolver-typescript": "~4.4.5",
51
47
  "typescript": "~6.0.3",
52
48
  "zod": "~4.4.3"
53
49
  },
54
- "peerDependencies": {
55
- "@ariestools/sdk": "^8.1"
56
- },
57
50
  "engines": {
58
51
  "node": "^24"
59
52
  },
60
53
  "publishConfig": {
61
54
  "access": "public"
62
- }
55
+ },
56
+ "deprecated": "Use @xyo-network/diviner-forecasting/memory instead. This package is a compatibility shim only and will not receive further updates."
63
57
  }
@@ -1,22 +0,0 @@
1
- import type { ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
- import { AbstractForecastingDiviner } from '@xyo-network/diviner-forecasting-abstract';
3
- import type { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
4
- import type { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
5
- import type { ModuleIdentifier } from '@xyo-network/sdk/module-model';
6
- import type { Payload, Schema } from '@xyo-network/sdk-protocol';
7
- export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
8
- export declare class MemoryForecastingDiviner<TParams extends ForecastingDivinerParams = ForecastingDivinerParams> extends AbstractForecastingDiviner<TParams> {
9
- static readonly configSchemas: Schema[];
10
- static readonly defaultConfigSchema: Schema;
11
- protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
12
- get boundWitnessDiviner(): ModuleIdentifier;
13
- /**
14
- * The max number of records to search during the batch query
15
- */
16
- protected get batchLimit(): number;
17
- protected get forecastingMethod(): ForecastingMethod;
18
- protected get maxTrainingLength(): number;
19
- protected get transformer(): PayloadValueTransformer;
20
- protected getPayloadsInWindow(_startTimestamp: number, _stopTimestamp: number): Promise<Payload[]>;
21
- }
22
- //# sourceMappingURL=MemoryForecastingDiviner.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MemoryForecastingDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryForecastingDiviner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AACzF,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAA;AACtF,OAAO,KAAK,EACV,oBAAoB,EACpB,4BAA4B,EAC7B,MAAM,+CAA+C,CAAA;AAKtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAOxG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,KAAK,EACI,OAAO,EAAE,MAAM,EAC9B,MAAM,2BAA2B,CAAA;AAGlC,MAAM,MAAM,wBAAwB,GAAG,OAAO,oBAAoB,GAAG,OAAO,4BAA4B,CAAA;AAcxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC,OAAO,CAAC;IAC3C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA2D;IAC3G,gBAAyB,mBAAmB,EAAE,MAAM,CAAiC;IAErF,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAGnG;IAED,IAAI,mBAAmB,IAAI,gBAAgB,CAE1C;IAED;;OAEG;IACH,SAAS,KAAK,UAAU,IAAI,MAAM,CAEjC;IAED,cAAuB,iBAAiB,IAAI,iBAAiB,CAK5D;IAED,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAmDlH"}