@langchain/langgraph-checkpoint 0.1.0 → 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.
Files changed (121) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  3. package/dist/base.cjs +74 -88
  4. package/dist/base.cjs.map +1 -0
  5. package/dist/base.d.cts +95 -0
  6. package/dist/base.d.cts.map +1 -0
  7. package/dist/base.d.ts +79 -73
  8. package/dist/base.d.ts.map +1 -0
  9. package/dist/base.js +69 -80
  10. package/dist/base.js.map +1 -1
  11. package/dist/cache/base.cjs +17 -21
  12. package/dist/cache/base.cjs.map +1 -0
  13. package/dist/cache/base.d.cts +43 -0
  14. package/dist/cache/base.d.cts.map +1 -0
  15. package/dist/cache/base.d.ts +41 -36
  16. package/dist/cache/base.d.ts.map +1 -0
  17. package/dist/cache/base.js +16 -16
  18. package/dist/cache/base.js.map +1 -1
  19. package/dist/cache/index.cjs +2 -19
  20. package/dist/cache/index.js +4 -3
  21. package/dist/cache/memory.cjs +53 -58
  22. package/dist/cache/memory.cjs.map +1 -0
  23. package/dist/cache/memory.d.cts +19 -0
  24. package/dist/cache/memory.d.cts.map +1 -0
  25. package/dist/cache/memory.d.ts +18 -13
  26. package/dist/cache/memory.d.ts.map +1 -0
  27. package/dist/cache/memory.js +52 -53
  28. package/dist/cache/memory.js.map +1 -1
  29. package/dist/id.cjs +12 -16
  30. package/dist/id.cjs.map +1 -0
  31. package/dist/id.d.cts +10 -0
  32. package/dist/id.d.cts.map +1 -0
  33. package/dist/id.d.ts +10 -2
  34. package/dist/id.d.ts.map +1 -0
  35. package/dist/id.js +10 -12
  36. package/dist/id.js.map +1 -1
  37. package/dist/index.cjs +36 -27
  38. package/dist/index.d.cts +12 -0
  39. package/dist/index.d.ts +12 -8
  40. package/dist/index.js +12 -9
  41. package/dist/memory.cjs +194 -268
  42. package/dist/memory.cjs.map +1 -0
  43. package/dist/memory.d.cts +22 -0
  44. package/dist/memory.d.cts.map +1 -0
  45. package/dist/memory.d.ts +19 -12
  46. package/dist/memory.d.ts.map +1 -0
  47. package/dist/memory.js +193 -263
  48. package/dist/memory.js.map +1 -1
  49. package/dist/serde/base.d.cts +10 -0
  50. package/dist/serde/base.d.cts.map +1 -0
  51. package/dist/serde/base.d.ts +9 -3
  52. package/dist/serde/base.d.ts.map +1 -0
  53. package/dist/serde/jsonplus.cjs +92 -141
  54. package/dist/serde/jsonplus.cjs.map +1 -0
  55. package/dist/serde/jsonplus.js +90 -136
  56. package/dist/serde/jsonplus.js.map +1 -1
  57. package/dist/serde/types.cjs +15 -9
  58. package/dist/serde/types.cjs.map +1 -0
  59. package/dist/serde/types.d.cts +55 -0
  60. package/dist/serde/types.d.cts.map +1 -0
  61. package/dist/serde/types.d.ts +53 -47
  62. package/dist/serde/types.d.ts.map +1 -0
  63. package/dist/serde/types.js +9 -5
  64. package/dist/serde/types.js.map +1 -1
  65. package/dist/serde/utils/fast-safe-stringify/index.cjs +88 -208
  66. package/dist/serde/utils/fast-safe-stringify/index.cjs.map +1 -0
  67. package/dist/serde/utils/fast-safe-stringify/index.js +87 -205
  68. package/dist/serde/utils/fast-safe-stringify/index.js.map +1 -1
  69. package/dist/store/base.cjs +200 -209
  70. package/dist/store/base.cjs.map +1 -0
  71. package/dist/store/base.d.cts +392 -0
  72. package/dist/store/base.d.cts.map +1 -0
  73. package/dist/store/base.d.ts +336 -332
  74. package/dist/store/base.d.ts.map +1 -0
  75. package/dist/store/base.js +198 -204
  76. package/dist/store/base.js.map +1 -1
  77. package/dist/store/batch.cjs +116 -147
  78. package/dist/store/batch.cjs.map +1 -0
  79. package/dist/store/batch.d.cts +49 -0
  80. package/dist/store/batch.d.cts.map +1 -0
  81. package/dist/store/batch.d.ts +48 -40
  82. package/dist/store/batch.d.ts.map +1 -0
  83. package/dist/store/batch.js +116 -143
  84. package/dist/store/batch.js.map +1 -1
  85. package/dist/store/memory.cjs +262 -363
  86. package/dist/store/memory.cjs.map +1 -0
  87. package/dist/store/memory.d.cts +64 -0
  88. package/dist/store/memory.d.cts.map +1 -0
  89. package/dist/store/memory.d.ts +30 -24
  90. package/dist/store/memory.d.ts.map +1 -0
  91. package/dist/store/memory.js +261 -358
  92. package/dist/store/memory.js.map +1 -1
  93. package/dist/store/utils.cjs +141 -249
  94. package/dist/store/utils.cjs.map +1 -0
  95. package/dist/store/utils.js +140 -245
  96. package/dist/store/utils.js.map +1 -1
  97. package/dist/types.d.cts +35 -0
  98. package/dist/types.d.cts.map +1 -0
  99. package/dist/types.d.ts +29 -28
  100. package/dist/types.d.ts.map +1 -0
  101. package/package.json +16 -18
  102. package/dist/cache/index.d.ts +0 -2
  103. package/dist/cache/index.js.map +0 -1
  104. package/dist/index.js.map +0 -1
  105. package/dist/serde/base.cjs +0 -3
  106. package/dist/serde/base.js +0 -2
  107. package/dist/serde/base.js.map +0 -1
  108. package/dist/serde/jsonplus.d.ts +0 -7
  109. package/dist/serde/utils/fast-safe-stringify/index.d.ts +0 -1
  110. package/dist/store/index.cjs +0 -20
  111. package/dist/store/index.d.ts +0 -3
  112. package/dist/store/index.js +0 -4
  113. package/dist/store/index.js.map +0 -1
  114. package/dist/store/utils.d.ts +0 -26
  115. package/dist/types.cjs +0 -3
  116. package/dist/types.js +0 -2
  117. package/dist/types.js.map +0 -1
  118. package/index.cjs +0 -1
  119. package/index.d.cts +0 -1
  120. package/index.d.ts +0 -1
  121. package/index.js +0 -1
package/dist/base.js CHANGED
@@ -1,94 +1,83 @@
1
1
  import { uuid6 } from "./id.js";
2
2
  import { ERROR, INTERRUPT, RESUME, SCHEDULED } from "./serde/types.js";
3
3
  import { JsonPlusSerializer } from "./serde/jsonplus.js";
4
- export function deepCopy(obj) {
5
- if (typeof obj !== "object" || obj === null) {
6
- return obj;
7
- }
8
- const newObj = Array.isArray(obj) ? [] : {};
9
- for (const key in obj) {
10
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
11
- newObj[key] = deepCopy(obj[key]);
12
- }
13
- }
14
- return newObj;
4
+
5
+ //#region src/base.ts
6
+ function deepCopy(obj) {
7
+ if (typeof obj !== "object" || obj === null) return obj;
8
+ const newObj = Array.isArray(obj) ? [] : {};
9
+ for (const key in obj) if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = deepCopy(obj[key]);
10
+ return newObj;
15
11
  }
16
12
  /** @hidden */
17
- export function emptyCheckpoint() {
18
- return {
19
- v: 4,
20
- id: uuid6(-2),
21
- ts: new Date().toISOString(),
22
- channel_values: {},
23
- channel_versions: {},
24
- versions_seen: {},
25
- };
13
+ function emptyCheckpoint() {
14
+ return {
15
+ v: 4,
16
+ id: uuid6(-2),
17
+ ts: (/* @__PURE__ */ new Date()).toISOString(),
18
+ channel_values: {},
19
+ channel_versions: {},
20
+ versions_seen: {}
21
+ };
26
22
  }
27
23
  /** @hidden */
28
- export function copyCheckpoint(checkpoint) {
29
- return {
30
- v: checkpoint.v,
31
- id: checkpoint.id,
32
- ts: checkpoint.ts,
33
- channel_values: { ...checkpoint.channel_values },
34
- channel_versions: { ...checkpoint.channel_versions },
35
- versions_seen: deepCopy(checkpoint.versions_seen),
36
- };
24
+ function copyCheckpoint(checkpoint) {
25
+ return {
26
+ v: checkpoint.v,
27
+ id: checkpoint.id,
28
+ ts: checkpoint.ts,
29
+ channel_values: { ...checkpoint.channel_values },
30
+ channel_versions: { ...checkpoint.channel_versions },
31
+ versions_seen: deepCopy(checkpoint.versions_seen)
32
+ };
37
33
  }
38
- export class BaseCheckpointSaver {
39
- constructor(serde) {
40
- Object.defineProperty(this, "serde", {
41
- enumerable: true,
42
- configurable: true,
43
- writable: true,
44
- value: new JsonPlusSerializer()
45
- });
46
- this.serde = serde || this.serde;
47
- }
48
- async get(config) {
49
- const value = await this.getTuple(config);
50
- return value ? value.checkpoint : undefined;
51
- }
52
- /**
53
- * Generate the next version ID for a channel.
54
- *
55
- * Default is to use integer versions, incrementing by 1. If you override, you can use str/int/float versions,
56
- * as long as they are monotonically increasing.
57
- */
58
- getNextVersion(current) {
59
- if (typeof current === "string") {
60
- throw new Error("Please override this method to use string versions.");
61
- }
62
- return (current !== undefined && typeof current === "number" ? current + 1 : 1);
63
- }
64
- }
65
- export function compareChannelVersions(a, b) {
66
- if (typeof a === "number" && typeof b === "number") {
67
- return Math.sign(a - b);
68
- }
69
- return String(a).localeCompare(String(b));
34
+ var BaseCheckpointSaver = class {
35
+ serde = new JsonPlusSerializer();
36
+ constructor(serde) {
37
+ this.serde = serde || this.serde;
38
+ }
39
+ async get(config) {
40
+ const value = await this.getTuple(config);
41
+ return value ? value.checkpoint : void 0;
42
+ }
43
+ /**
44
+ * Generate the next version ID for a channel.
45
+ *
46
+ * Default is to use integer versions, incrementing by 1. If you override, you can use str/int/float versions,
47
+ * as long as they are monotonically increasing.
48
+ */
49
+ getNextVersion(current) {
50
+ if (typeof current === "string") throw new Error("Please override this method to use string versions.");
51
+ return current !== void 0 && typeof current === "number" ? current + 1 : 1;
52
+ }
53
+ };
54
+ function compareChannelVersions(a, b) {
55
+ if (typeof a === "number" && typeof b === "number") return Math.sign(a - b);
56
+ return String(a).localeCompare(String(b));
70
57
  }
71
- export function maxChannelVersion(...versions) {
72
- return versions.reduce((max, version, idx) => {
73
- if (idx === 0)
74
- return version;
75
- return compareChannelVersions(max, version) >= 0 ? max : version;
76
- });
58
+ function maxChannelVersion(...versions) {
59
+ return versions.reduce((max, version, idx) => {
60
+ if (idx === 0) return version;
61
+ return compareChannelVersions(max, version) >= 0 ? max : version;
62
+ });
77
63
  }
78
64
  /**
79
- * Mapping from error type to error index.
80
- * Regular writes just map to their index in the list of writes being saved.
81
- * Special writes (e.g. errors) map to negative indices, to avoid those writes from
82
- * conflicting with regular writes.
83
- * Each Checkpointer implementation should use this mapping in put_writes.
84
- */
85
- export const WRITES_IDX_MAP = {
86
- [ERROR]: -1,
87
- [SCHEDULED]: -2,
88
- [INTERRUPT]: -3,
89
- [RESUME]: -4,
65
+ * Mapping from error type to error index.
66
+ * Regular writes just map to their index in the list of writes being saved.
67
+ * Special writes (e.g. errors) map to negative indices, to avoid those writes from
68
+ * conflicting with regular writes.
69
+ * Each Checkpointer implementation should use this mapping in put_writes.
70
+ */
71
+ const WRITES_IDX_MAP = {
72
+ [ERROR]: -1,
73
+ [SCHEDULED]: -2,
74
+ [INTERRUPT]: -3,
75
+ [RESUME]: -4
90
76
  };
91
- export function getCheckpointId(config) {
92
- return (config.configurable?.checkpoint_id || config.configurable?.thread_ts || "");
77
+ function getCheckpointId(config) {
78
+ return config.configurable?.checkpoint_id || config.configurable?.thread_ts || "";
93
79
  }
80
+
81
+ //#endregion
82
+ export { BaseCheckpointSaver, WRITES_IDX_MAP, compareChannelVersions, copyCheckpoint, deepCopy, emptyCheckpoint, getCheckpointId, maxChannelVersion };
94
83
  //# sourceMappingURL=base.js.map
package/dist/base.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAMhC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AA4CzD,MAAM,UAAU,QAAQ,CAAI,GAAM;IAChC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAE5C,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QACtB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;YAClD,MAAuC,CAAC,GAAG,CAAC,GAAG,QAAQ,CACrD,GAA+B,CAAC,GAAG,CAAC,CACtC,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAW,CAAC;AACrB,CAAC;AAED,cAAc;AACd,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL,CAAC,EAAE,CAAC;QACJ,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QACb,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAC5B,cAAc,EAAE,EAAE;QAClB,gBAAgB,EAAE,EAAE;QACpB,aAAa,EAAE,EAAE;KAClB,CAAC;AACJ,CAAC;AAED,cAAc;AACd,MAAM,UAAU,cAAc,CAAC,UAA8B;IAC3D,OAAO;QACL,CAAC,EAAE,UAAU,CAAC,CAAC;QACf,EAAE,EAAE,UAAU,CAAC,EAAE;QACjB,EAAE,EAAE,UAAU,CAAC,EAAE;QACjB,cAAc,EAAE,EAAE,GAAG,UAAU,CAAC,cAAc,EAAE;QAChD,gBAAgB,EAAE,EAAE,GAAG,UAAU,CAAC,gBAAgB,EAAE;QACpD,aAAa,EAAE,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC;KAClD,CAAC;AACJ,CAAC;AAiBD,MAAM,OAAgB,mBAAmB;IAGvC,YAAY,KAA0B;QAFtC;;;;mBAA4B,IAAI,kBAAkB,EAAE;WAAC;QAGnD,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,MAAsB;QAC9B,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC1C,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9C,CAAC;IAiCD;;;;;OAKG;IACH,cAAc,CAAC,OAAsB;QACnC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QACD,OAAO,CACL,OAAO,KAAK,SAAS,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAClE,CAAC;IACT,CAAC;CACF;AAED,MAAM,UAAU,sBAAsB,CACpC,CAAiB,EACjB,CAAiB;IAEjB,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QACnD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1B,CAAC;IAED,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,GAAG,QAA0B;IAE7B,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE;QAC3C,IAAI,GAAG,KAAK,CAAC;YAAE,OAAO,OAAO,CAAC;QAC9B,OAAO,sBAAsB,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAA2B;IACpD,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACX,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACf,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACf,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;CACb,CAAC;AAEF,MAAM,UAAU,eAAe,CAAC,MAAsB;IACpD,OAAO,CACL,MAAM,CAAC,YAAY,EAAE,aAAa,IAAI,MAAM,CAAC,YAAY,EAAE,SAAS,IAAI,EAAE,CAC3E,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"base.js","names":["WRITES_IDX_MAP: Record<string, number>"],"sources":["../src/base.ts"],"sourcesContent":["import type { RunnableConfig } from \"@langchain/core/runnables\";\nimport { SerializerProtocol } from \"./serde/base.js\";\nimport { uuid6 } from \"./id.js\";\nimport type {\n PendingWrite,\n CheckpointPendingWrite,\n CheckpointMetadata,\n} from \"./types.js\";\nimport { ERROR, INTERRUPT, RESUME, SCHEDULED } from \"./serde/types.js\";\nimport { JsonPlusSerializer } from \"./serde/jsonplus.js\";\n\n/** @inline */\ntype ChannelVersion = number | string;\n\nexport type ChannelVersions = Record<string, ChannelVersion>;\n\nexport interface Checkpoint<\n N extends string = string,\n C extends string = string\n> {\n /**\n * The version of the checkpoint format. Currently 4\n */\n v: number;\n /**\n * Checkpoint ID {uuid6}\n */\n id: string;\n /**\n * Timestamp {new Date().toISOString()}\n */\n ts: string;\n /**\n * @default {}\n */\n channel_values: Record<C, unknown>;\n /**\n * @default {}\n */\n channel_versions: Record<C, ChannelVersion>;\n /**\n * @default {}\n */\n versions_seen: Record<N, Record<C, ChannelVersion>>;\n}\n\nexport interface ReadonlyCheckpoint extends Readonly<Checkpoint> {\n readonly channel_values: Readonly<Record<string, unknown>>;\n readonly channel_versions: Readonly<Record<string, ChannelVersion>>;\n readonly versions_seen: Readonly<\n Record<string, Readonly<Record<string, ChannelVersion>>>\n >;\n}\n\nexport function deepCopy<T>(obj: T): T {\n if (typeof obj !== \"object\" || obj === null) {\n return obj;\n }\n\n const newObj = Array.isArray(obj) ? [] : {};\n\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n (newObj as Record<PropertyKey, unknown>)[key] = deepCopy(\n (obj as Record<string, unknown>)[key]\n );\n }\n }\n\n return newObj as T;\n}\n\n/** @hidden */\nexport function emptyCheckpoint(): Checkpoint {\n return {\n v: 4,\n id: uuid6(-2),\n ts: new Date().toISOString(),\n channel_values: {},\n channel_versions: {},\n versions_seen: {},\n };\n}\n\n/** @hidden */\nexport function copyCheckpoint(checkpoint: ReadonlyCheckpoint): Checkpoint {\n return {\n v: checkpoint.v,\n id: checkpoint.id,\n ts: checkpoint.ts,\n channel_values: { ...checkpoint.channel_values },\n channel_versions: { ...checkpoint.channel_versions },\n versions_seen: deepCopy(checkpoint.versions_seen),\n };\n}\n\nexport interface CheckpointTuple {\n config: RunnableConfig;\n checkpoint: Checkpoint;\n metadata?: CheckpointMetadata;\n parentConfig?: RunnableConfig;\n pendingWrites?: CheckpointPendingWrite[];\n}\n\nexport type CheckpointListOptions = {\n limit?: number;\n before?: RunnableConfig;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n filter?: Record<string, any>;\n};\n\nexport abstract class BaseCheckpointSaver<V extends string | number = number> {\n serde: SerializerProtocol = new JsonPlusSerializer();\n\n constructor(serde?: SerializerProtocol) {\n this.serde = serde || this.serde;\n }\n\n async get(config: RunnableConfig): Promise<Checkpoint | undefined> {\n const value = await this.getTuple(config);\n return value ? value.checkpoint : undefined;\n }\n\n abstract getTuple(\n config: RunnableConfig\n ): Promise<CheckpointTuple | undefined>;\n\n abstract list(\n config: RunnableConfig,\n options?: CheckpointListOptions\n ): AsyncGenerator<CheckpointTuple>;\n\n abstract put(\n config: RunnableConfig,\n checkpoint: Checkpoint,\n metadata: CheckpointMetadata,\n newVersions: ChannelVersions\n ): Promise<RunnableConfig>;\n\n /**\n * Store intermediate writes linked to a checkpoint.\n */\n abstract putWrites(\n config: RunnableConfig,\n writes: PendingWrite[],\n taskId: string\n ): Promise<void>;\n\n /**\n * Delete all checkpoints and writes associated with a specific thread ID.\n * @param threadId The thread ID whose checkpoints should be deleted.\n */\n abstract deleteThread(threadId: string): Promise<void>;\n\n /**\n * Generate the next version ID for a channel.\n *\n * Default is to use integer versions, incrementing by 1. If you override, you can use str/int/float versions,\n * as long as they are monotonically increasing.\n */\n getNextVersion(current: V | undefined): V {\n if (typeof current === \"string\") {\n throw new Error(\"Please override this method to use string versions.\");\n }\n return (\n current !== undefined && typeof current === \"number\" ? current + 1 : 1\n ) as V;\n }\n}\n\nexport function compareChannelVersions(\n a: ChannelVersion,\n b: ChannelVersion\n): number {\n if (typeof a === \"number\" && typeof b === \"number\") {\n return Math.sign(a - b);\n }\n\n return String(a).localeCompare(String(b));\n}\n\nexport function maxChannelVersion(\n ...versions: ChannelVersion[]\n): ChannelVersion {\n return versions.reduce((max, version, idx) => {\n if (idx === 0) return version;\n return compareChannelVersions(max, version) >= 0 ? max : version;\n });\n}\n\n/**\n * Mapping from error type to error index.\n * Regular writes just map to their index in the list of writes being saved.\n * Special writes (e.g. errors) map to negative indices, to avoid those writes from\n * conflicting with regular writes.\n * Each Checkpointer implementation should use this mapping in put_writes.\n */\nexport const WRITES_IDX_MAP: Record<string, number> = {\n [ERROR]: -1,\n [SCHEDULED]: -2,\n [INTERRUPT]: -3,\n [RESUME]: -4,\n};\n\nexport function getCheckpointId(config: RunnableConfig): string {\n return (\n config.configurable?.checkpoint_id || config.configurable?.thread_ts || \"\"\n );\n}\n"],"mappings":";;;;;AAsDA,SAAgB,SAAY,KAAW;AACrC,KAAI,OAAO,QAAQ,YAAY,QAAQ,KACrC,QAAO;CAGT,MAAM,SAAS,MAAM,QAAQ,OAAO,KAAK;AAEzC,MAAK,MAAM,OAAO,IAChB,KAAI,OAAO,UAAU,eAAe,KAAK,KAAK,KAC5C,CAAC,OAAwC,OAAO,SAC7C,IAAgC;AAKvC,QAAO;;;AAIT,SAAgB,kBAA8B;AAC5C,QAAO;EACL,GAAG;EACH,IAAI,MAAM;EACV,qBAAI,IAAI,QAAO;EACf,gBAAgB;EAChB,kBAAkB;EAClB,eAAe;;;;AAKnB,SAAgB,eAAe,YAA4C;AACzE,QAAO;EACL,GAAG,WAAW;EACd,IAAI,WAAW;EACf,IAAI,WAAW;EACf,gBAAgB,EAAE,GAAG,WAAW;EAChC,kBAAkB,EAAE,GAAG,WAAW;EAClC,eAAe,SAAS,WAAW;;;AAmBvC,IAAsB,sBAAtB,MAA8E;CAC5E,QAA4B,IAAI;CAEhC,YAAY,OAA4B;AACtC,OAAK,QAAQ,SAAS,KAAK;;CAG7B,MAAM,IAAI,QAAyD;EACjE,MAAM,QAAQ,MAAM,KAAK,SAAS;AAClC,SAAO,QAAQ,MAAM,aAAa;;;;;;;;CAwCpC,eAAe,SAA2B;AACxC,MAAI,OAAO,YAAY,SACrB,OAAM,IAAI,MAAM;AAElB,SACE,YAAY,UAAa,OAAO,YAAY,WAAW,UAAU,IAAI;;;AAK3E,SAAgB,uBACd,GACA,GACQ;AACR,KAAI,OAAO,MAAM,YAAY,OAAO,MAAM,SACxC,QAAO,KAAK,KAAK,IAAI;AAGvB,QAAO,OAAO,GAAG,cAAc,OAAO;;AAGxC,SAAgB,kBACd,GAAG,UACa;AAChB,QAAO,SAAS,QAAQ,KAAK,SAAS,QAAQ;AAC5C,MAAI,QAAQ,EAAG,QAAO;AACtB,SAAO,uBAAuB,KAAK,YAAY,IAAI,MAAM;;;;;;;;;;AAW7D,MAAaA,iBAAyC;EACnD,QAAQ;EACR,YAAY;EACZ,YAAY;EACZ,SAAS;;AAGZ,SAAgB,gBAAgB,QAAgC;AAC9D,QACE,OAAO,cAAc,iBAAiB,OAAO,cAAc,aAAa"}
@@ -1,22 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseCache = void 0;
4
- const jsonplus_js_1 = require("../serde/jsonplus.cjs");
5
- class BaseCache {
6
- /**
7
- * Initialize the cache with a serializer.
8
- *
9
- * @param serde - The serializer to use.
10
- */
11
- constructor(serde) {
12
- Object.defineProperty(this, "serde", {
13
- enumerable: true,
14
- configurable: true,
15
- writable: true,
16
- value: new jsonplus_js_1.JsonPlusSerializer()
17
- });
18
- this.serde = serde || this.serde;
19
- }
20
- }
1
+ const require_jsonplus = require('../serde/jsonplus.cjs');
2
+
3
+ //#region src/cache/base.ts
4
+ var BaseCache = class {
5
+ serde = new require_jsonplus.JsonPlusSerializer();
6
+ /**
7
+ * Initialize the cache with a serializer.
8
+ *
9
+ * @param serde - The serializer to use.
10
+ */
11
+ constructor(serde) {
12
+ this.serde = serde || this.serde;
13
+ }
14
+ };
15
+
16
+ //#endregion
21
17
  exports.BaseCache = BaseCache;
22
- //# sourceMappingURL=base.js.map
18
+ //# sourceMappingURL=base.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.cjs","names":["JsonPlusSerializer"],"sources":["../../src/cache/base.ts"],"sourcesContent":["import { SerializerProtocol } from \"../serde/base.js\";\nimport { JsonPlusSerializer } from \"../serde/jsonplus.js\";\n\nexport type CacheNamespace = string[];\nexport type CacheFullKey = [namespace: CacheNamespace, key: string];\n\nexport abstract class BaseCache<V = unknown> {\n serde: SerializerProtocol = new JsonPlusSerializer();\n\n /**\n * Initialize the cache with a serializer.\n *\n * @param serde - The serializer to use.\n */\n constructor(serde?: SerializerProtocol) {\n this.serde = serde || this.serde;\n }\n\n /**\n * Get the cached values for the given keys.\n *\n * @param keys - The keys to get.\n */\n abstract get(\n keys: CacheFullKey[]\n ): Promise<{ key: CacheFullKey; value: V }[]>;\n\n /**\n * Set the cached values for the given keys and TTLs.\n *\n * @param pairs - The pairs to set.\n */\n abstract set(\n pairs: { key: CacheFullKey; value: V; ttl?: number }[]\n ): Promise<void>;\n\n /**\n * Delete the cached values for the given namespaces.\n * If no namespaces are provided, clear all cached values.\n *\n * @param namespaces - The namespaces to clear.\n */\n abstract clear(namespaces: CacheNamespace[]): Promise<void>;\n}\n"],"mappings":";;;AAMA,IAAsB,YAAtB,MAA6C;CAC3C,QAA4B,IAAIA;;;;;;CAOhC,YAAY,OAA4B;AACtC,OAAK,QAAQ,SAAS,KAAK"}
@@ -0,0 +1,43 @@
1
+ import { SerializerProtocol } from "../serde/base.cjs";
2
+
3
+ //#region src/cache/base.d.ts
4
+ type CacheNamespace = string[];
5
+ type CacheFullKey = [namespace: CacheNamespace, key: string];
6
+ declare abstract class BaseCache<V = unknown> {
7
+ serde: SerializerProtocol;
8
+ /**
9
+ * Initialize the cache with a serializer.
10
+ *
11
+ * @param serde - The serializer to use.
12
+ */
13
+ constructor(serde?: SerializerProtocol);
14
+ /**
15
+ * Get the cached values for the given keys.
16
+ *
17
+ * @param keys - The keys to get.
18
+ */
19
+ abstract get(keys: CacheFullKey[]): Promise<{
20
+ key: CacheFullKey;
21
+ value: V;
22
+ }[]>;
23
+ /**
24
+ * Set the cached values for the given keys and TTLs.
25
+ *
26
+ * @param pairs - The pairs to set.
27
+ */
28
+ abstract set(pairs: {
29
+ key: CacheFullKey;
30
+ value: V;
31
+ ttl?: number;
32
+ }[]): Promise<void>;
33
+ /**
34
+ * Delete the cached values for the given namespaces.
35
+ * If no namespaces are provided, clear all cached values.
36
+ *
37
+ * @param namespaces - The namespaces to clear.
38
+ */
39
+ abstract clear(namespaces: CacheNamespace[]): Promise<void>;
40
+ }
41
+ //#endregion
42
+ export { BaseCache, CacheFullKey, CacheNamespace };
43
+ //# sourceMappingURL=base.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.cts","names":["SerializerProtocol","CacheNamespace","CacheFullKey","BaseCache","V","Promise"],"sources":["../../src/cache/base.d.ts"],"sourcesContent":["import { SerializerProtocol } from \"../serde/base.js\";\nexport type CacheNamespace = string[];\nexport type CacheFullKey = [namespace: CacheNamespace, key: string];\nexport declare abstract class BaseCache<V = unknown> {\n serde: SerializerProtocol;\n /**\n * Initialize the cache with a serializer.\n *\n * @param serde - The serializer to use.\n */\n constructor(serde?: SerializerProtocol);\n /**\n * Get the cached values for the given keys.\n *\n * @param keys - The keys to get.\n */\n abstract get(keys: CacheFullKey[]): Promise<{\n key: CacheFullKey;\n value: V;\n }[]>;\n /**\n * Set the cached values for the given keys and TTLs.\n *\n * @param pairs - The pairs to set.\n */\n abstract set(pairs: {\n key: CacheFullKey;\n value: V;\n ttl?: number;\n }[]): Promise<void>;\n /**\n * Delete the cached values for the given namespaces.\n * If no namespaces are provided, clear all cached values.\n *\n * @param namespaces - The namespaces to clear.\n */\n abstract clear(namespaces: CacheNamespace[]): Promise<void>;\n}\n"],"mappings":";;;KACYC,cAAAA;KACAC,YAAAA,eAA2BD;AAD3BA,uBAEkBE,SAFJ,CAAA,IAAA,OAAA,CAAA,CAAA;EACdD,KAAAA,EAEDF,kBAFa;EACMG;;;;;aAcjBD,CAAAA,KAAAA,CAAAA,EAPWF,kBAOXE;;;;;;WAmBkBD,GAAAA,CAAAA,IAAAA,EApBRC,YAoBQD,EAAAA,CAAAA,EApBSI,OAoBTJ,CAAAA;IAAmBI,GAAAA,EAnBrCH,YAmBqCG;WAlBnCD;;;;;;;;SAQFF;WACEE;;QAELC;;;;;;;6BAOqBJ,mBAAmBI"}
@@ -1,38 +1,43 @@
1
1
  import { SerializerProtocol } from "../serde/base.js";
2
- export type CacheNamespace = string[];
3
- export type CacheFullKey = [namespace: CacheNamespace, key: string];
4
- export declare abstract class BaseCache<V = unknown> {
5
- serde: SerializerProtocol;
6
- /**
7
- * Initialize the cache with a serializer.
8
- *
9
- * @param serde - The serializer to use.
10
- */
11
- constructor(serde?: SerializerProtocol);
12
- /**
13
- * Get the cached values for the given keys.
14
- *
15
- * @param keys - The keys to get.
16
- */
17
- abstract get(keys: CacheFullKey[]): Promise<{
18
- key: CacheFullKey;
19
- value: V;
20
- }[]>;
21
- /**
22
- * Set the cached values for the given keys and TTLs.
23
- *
24
- * @param pairs - The pairs to set.
25
- */
26
- abstract set(pairs: {
27
- key: CacheFullKey;
28
- value: V;
29
- ttl?: number;
30
- }[]): Promise<void>;
31
- /**
32
- * Delete the cached values for the given namespaces.
33
- * If no namespaces are provided, clear all cached values.
34
- *
35
- * @param namespaces - The namespaces to clear.
36
- */
37
- abstract clear(namespaces: CacheNamespace[]): Promise<void>;
2
+
3
+ //#region src/cache/base.d.ts
4
+ type CacheNamespace = string[];
5
+ type CacheFullKey = [namespace: CacheNamespace, key: string];
6
+ declare abstract class BaseCache<V = unknown> {
7
+ serde: SerializerProtocol;
8
+ /**
9
+ * Initialize the cache with a serializer.
10
+ *
11
+ * @param serde - The serializer to use.
12
+ */
13
+ constructor(serde?: SerializerProtocol);
14
+ /**
15
+ * Get the cached values for the given keys.
16
+ *
17
+ * @param keys - The keys to get.
18
+ */
19
+ abstract get(keys: CacheFullKey[]): Promise<{
20
+ key: CacheFullKey;
21
+ value: V;
22
+ }[]>;
23
+ /**
24
+ * Set the cached values for the given keys and TTLs.
25
+ *
26
+ * @param pairs - The pairs to set.
27
+ */
28
+ abstract set(pairs: {
29
+ key: CacheFullKey;
30
+ value: V;
31
+ ttl?: number;
32
+ }[]): Promise<void>;
33
+ /**
34
+ * Delete the cached values for the given namespaces.
35
+ * If no namespaces are provided, clear all cached values.
36
+ *
37
+ * @param namespaces - The namespaces to clear.
38
+ */
39
+ abstract clear(namespaces: CacheNamespace[]): Promise<void>;
38
40
  }
41
+ //#endregion
42
+ export { BaseCache, CacheFullKey, CacheNamespace };
43
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","names":["SerializerProtocol","CacheNamespace","CacheFullKey","BaseCache","V","Promise"],"sources":["../../src/cache/base.d.ts"],"sourcesContent":["import { SerializerProtocol } from \"../serde/base.js\";\nexport type CacheNamespace = string[];\nexport type CacheFullKey = [namespace: CacheNamespace, key: string];\nexport declare abstract class BaseCache<V = unknown> {\n serde: SerializerProtocol;\n /**\n * Initialize the cache with a serializer.\n *\n * @param serde - The serializer to use.\n */\n constructor(serde?: SerializerProtocol);\n /**\n * Get the cached values for the given keys.\n *\n * @param keys - The keys to get.\n */\n abstract get(keys: CacheFullKey[]): Promise<{\n key: CacheFullKey;\n value: V;\n }[]>;\n /**\n * Set the cached values for the given keys and TTLs.\n *\n * @param pairs - The pairs to set.\n */\n abstract set(pairs: {\n key: CacheFullKey;\n value: V;\n ttl?: number;\n }[]): Promise<void>;\n /**\n * Delete the cached values for the given namespaces.\n * If no namespaces are provided, clear all cached values.\n *\n * @param namespaces - The namespaces to clear.\n */\n abstract clear(namespaces: CacheNamespace[]): Promise<void>;\n}\n"],"mappings":";;;KACYC,cAAAA;KACAC,YAAAA,eAA2BD;AAD3BA,uBAEkBE,SAFJ,CAAA,IAAA,OAAA,CAAA,CAAA;EACdD,KAAAA,EAEDF,kBAFa;EACMG;;;;;aAcjBD,CAAAA,KAAAA,CAAAA,EAPWF,kBAOXE;;;;;;WAmBkBD,GAAAA,CAAAA,IAAAA,EApBRC,YAoBQD,EAAAA,CAAAA,EApBSI,OAoBTJ,CAAAA;IAAmBI,GAAAA,EAnBrCH,YAmBqCG;WAlBnCD;;;;;;;;SAQFF;WACEE;;QAELC;;;;;;;6BAOqBJ,mBAAmBI"}
@@ -1,18 +1,18 @@
1
1
  import { JsonPlusSerializer } from "../serde/jsonplus.js";
2
- export class BaseCache {
3
- /**
4
- * Initialize the cache with a serializer.
5
- *
6
- * @param serde - The serializer to use.
7
- */
8
- constructor(serde) {
9
- Object.defineProperty(this, "serde", {
10
- enumerable: true,
11
- configurable: true,
12
- writable: true,
13
- value: new JsonPlusSerializer()
14
- });
15
- this.serde = serde || this.serde;
16
- }
17
- }
2
+
3
+ //#region src/cache/base.ts
4
+ var BaseCache = class {
5
+ serde = new JsonPlusSerializer();
6
+ /**
7
+ * Initialize the cache with a serializer.
8
+ *
9
+ * @param serde - The serializer to use.
10
+ */
11
+ constructor(serde) {
12
+ this.serde = serde || this.serde;
13
+ }
14
+ };
15
+
16
+ //#endregion
17
+ export { BaseCache };
18
18
  //# sourceMappingURL=base.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/cache/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAK1D,MAAM,OAAgB,SAAS;IAG7B;;;;OAIG;IACH,YAAY,KAA0B;QAPtC;;;;mBAA4B,IAAI,kBAAkB,EAAE;WAAC;QAQnD,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;IACnC,CAAC;CA2BF"}
1
+ {"version":3,"file":"base.js","names":[],"sources":["../../src/cache/base.ts"],"sourcesContent":["import { SerializerProtocol } from \"../serde/base.js\";\nimport { JsonPlusSerializer } from \"../serde/jsonplus.js\";\n\nexport type CacheNamespace = string[];\nexport type CacheFullKey = [namespace: CacheNamespace, key: string];\n\nexport abstract class BaseCache<V = unknown> {\n serde: SerializerProtocol = new JsonPlusSerializer();\n\n /**\n * Initialize the cache with a serializer.\n *\n * @param serde - The serializer to use.\n */\n constructor(serde?: SerializerProtocol) {\n this.serde = serde || this.serde;\n }\n\n /**\n * Get the cached values for the given keys.\n *\n * @param keys - The keys to get.\n */\n abstract get(\n keys: CacheFullKey[]\n ): Promise<{ key: CacheFullKey; value: V }[]>;\n\n /**\n * Set the cached values for the given keys and TTLs.\n *\n * @param pairs - The pairs to set.\n */\n abstract set(\n pairs: { key: CacheFullKey; value: V; ttl?: number }[]\n ): Promise<void>;\n\n /**\n * Delete the cached values for the given namespaces.\n * If no namespaces are provided, clear all cached values.\n *\n * @param namespaces - The namespaces to clear.\n */\n abstract clear(namespaces: CacheNamespace[]): Promise<void>;\n}\n"],"mappings":";;;AAMA,IAAsB,YAAtB,MAA6C;CAC3C,QAA4B,IAAI;;;;;;CAOhC,YAAY,OAA4B;AACtC,OAAK,QAAQ,SAAS,KAAK"}
@@ -1,19 +1,2 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./base.cjs"), exports);
18
- __exportStar(require("./memory.cjs"), exports);
19
- //# sourceMappingURL=index.js.map
1
+ const require_base = require('./base.cjs');
2
+ const require_memory = require('./memory.cjs');
@@ -1,3 +1,4 @@
1
- export * from "./base.js";
2
- export * from "./memory.js";
3
- //# sourceMappingURL=index.js.map
1
+ import { BaseCache } from "./base.js";
2
+ import { InMemoryCache } from "./memory.js";
3
+
4
+ export { };
@@ -1,59 +1,54 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InMemoryCache = void 0;
4
- const base_js_1 = require("./base.cjs");
5
- class InMemoryCache extends base_js_1.BaseCache {
6
- constructor() {
7
- super(...arguments);
8
- Object.defineProperty(this, "cache", {
9
- enumerable: true,
10
- configurable: true,
11
- writable: true,
12
- value: {}
13
- });
14
- }
15
- async get(keys) {
16
- if (!keys.length)
17
- return [];
18
- const now = Date.now();
19
- return (await Promise.all(keys.map(async (fullKey) => {
20
- const [namespace, key] = fullKey;
21
- const strNamespace = namespace.join(",");
22
- if (strNamespace in this.cache && key in this.cache[strNamespace]) {
23
- const cached = this.cache[strNamespace][key];
24
- if (cached.exp == null || now < cached.exp) {
25
- const value = await this.serde.loadsTyped(cached.enc, cached.val);
26
- return [{ key: fullKey, value }];
27
- }
28
- else {
29
- delete this.cache[strNamespace][key];
30
- }
31
- }
32
- return [];
33
- }))).flat();
34
- }
35
- async set(pairs) {
36
- const now = Date.now();
37
- for (const { key: fullKey, value, ttl } of pairs) {
38
- const [namespace, key] = fullKey;
39
- const strNamespace = namespace.join(",");
40
- const [enc, val] = await this.serde.dumpsTyped(value);
41
- const exp = ttl != null ? ttl * 1000 + now : null;
42
- this.cache[strNamespace] ??= {};
43
- this.cache[strNamespace][key] = { enc, val, exp };
44
- }
45
- }
46
- async clear(namespaces) {
47
- if (!namespaces.length) {
48
- this.cache = {};
49
- return;
50
- }
51
- for (const namespace of namespaces) {
52
- const strNamespace = namespace.join(",");
53
- if (strNamespace in this.cache)
54
- delete this.cache[strNamespace];
55
- }
56
- }
57
- }
1
+ const require_base = require('./base.cjs');
2
+
3
+ //#region src/cache/memory.ts
4
+ var InMemoryCache = class extends require_base.BaseCache {
5
+ cache = {};
6
+ async get(keys) {
7
+ if (!keys.length) return [];
8
+ const now = Date.now();
9
+ return (await Promise.all(keys.map(async (fullKey) => {
10
+ const [namespace, key] = fullKey;
11
+ const strNamespace = namespace.join(",");
12
+ if (strNamespace in this.cache && key in this.cache[strNamespace]) {
13
+ const cached = this.cache[strNamespace][key];
14
+ if (cached.exp == null || now < cached.exp) {
15
+ const value = await this.serde.loadsTyped(cached.enc, cached.val);
16
+ return [{
17
+ key: fullKey,
18
+ value
19
+ }];
20
+ } else delete this.cache[strNamespace][key];
21
+ }
22
+ return [];
23
+ }))).flat();
24
+ }
25
+ async set(pairs) {
26
+ const now = Date.now();
27
+ for (const { key: fullKey, value, ttl } of pairs) {
28
+ const [namespace, key] = fullKey;
29
+ const strNamespace = namespace.join(",");
30
+ const [enc, val] = await this.serde.dumpsTyped(value);
31
+ const exp = ttl != null ? ttl * 1e3 + now : null;
32
+ this.cache[strNamespace] ??= {};
33
+ this.cache[strNamespace][key] = {
34
+ enc,
35
+ val,
36
+ exp
37
+ };
38
+ }
39
+ }
40
+ async clear(namespaces) {
41
+ if (!namespaces.length) {
42
+ this.cache = {};
43
+ return;
44
+ }
45
+ for (const namespace of namespaces) {
46
+ const strNamespace = namespace.join(",");
47
+ if (strNamespace in this.cache) delete this.cache[strNamespace];
48
+ }
49
+ }
50
+ };
51
+
52
+ //#endregion
58
53
  exports.InMemoryCache = InMemoryCache;
59
- //# sourceMappingURL=memory.js.map
54
+ //# sourceMappingURL=memory.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.cjs","names":["BaseCache"],"sources":["../../src/cache/memory.ts"],"sourcesContent":["import { BaseCache, type CacheFullKey, type CacheNamespace } from \"./base.js\";\n\nexport class InMemoryCache<V = unknown> extends BaseCache<V> {\n private cache: {\n [namespace: string]: {\n [key: string]: {\n enc: string;\n val: Uint8Array | string;\n exp: number | null;\n };\n };\n } = {};\n\n async get(keys: CacheFullKey[]): Promise<{ key: CacheFullKey; value: V }[]> {\n if (!keys.length) return [];\n const now = Date.now();\n return (\n await Promise.all(\n keys.map(\n async (fullKey): Promise<{ key: CacheFullKey; value: V }[]> => {\n const [namespace, key] = fullKey;\n const strNamespace = namespace.join(\",\");\n\n if (strNamespace in this.cache && key in this.cache[strNamespace]) {\n const cached = this.cache[strNamespace][key];\n if (cached.exp == null || now < cached.exp) {\n const value = await this.serde.loadsTyped(\n cached.enc,\n cached.val\n );\n return [{ key: fullKey, value }];\n } else {\n delete this.cache[strNamespace][key];\n }\n }\n\n return [];\n }\n )\n )\n ).flat();\n }\n\n async set(\n pairs: { key: CacheFullKey; value: V; ttl?: number }[]\n ): Promise<void> {\n const now = Date.now();\n for (const { key: fullKey, value, ttl } of pairs) {\n const [namespace, key] = fullKey;\n const strNamespace = namespace.join(\",\");\n const [enc, val] = await this.serde.dumpsTyped(value);\n const exp = ttl != null ? ttl * 1000 + now : null;\n\n this.cache[strNamespace] ??= {};\n this.cache[strNamespace][key] = { enc, val, exp };\n }\n }\n\n async clear(namespaces: CacheNamespace[]): Promise<void> {\n if (!namespaces.length) {\n this.cache = {};\n return;\n }\n\n for (const namespace of namespaces) {\n const strNamespace = namespace.join(\",\");\n if (strNamespace in this.cache) delete this.cache[strNamespace];\n }\n }\n}\n"],"mappings":";;;AAEA,IAAa,gBAAb,cAAgDA,uBAAa;CAC3D,AAAQ,QAQJ;CAEJ,MAAM,IAAI,MAAkE;AAC1E,MAAI,CAAC,KAAK,OAAQ,QAAO;EACzB,MAAM,MAAM,KAAK;AACjB,UACE,MAAM,QAAQ,IACZ,KAAK,IACH,OAAO,YAAwD;GAC7D,MAAM,CAAC,WAAW,OAAO;GACzB,MAAM,eAAe,UAAU,KAAK;AAEpC,OAAI,gBAAgB,KAAK,SAAS,OAAO,KAAK,MAAM,eAAe;IACjE,MAAM,SAAS,KAAK,MAAM,cAAc;AACxC,QAAI,OAAO,OAAO,QAAQ,MAAM,OAAO,KAAK;KAC1C,MAAM,QAAQ,MAAM,KAAK,MAAM,WAC7B,OAAO,KACP,OAAO;AAET,YAAO,CAAC;MAAE,KAAK;MAAS;;UAExB,QAAO,KAAK,MAAM,cAAc;;AAIpC,UAAO;OAIb;;CAGJ,MAAM,IACJ,OACe;EACf,MAAM,MAAM,KAAK;AACjB,OAAK,MAAM,EAAE,KAAK,SAAS,OAAO,SAAS,OAAO;GAChD,MAAM,CAAC,WAAW,OAAO;GACzB,MAAM,eAAe,UAAU,KAAK;GACpC,MAAM,CAAC,KAAK,OAAO,MAAM,KAAK,MAAM,WAAW;GAC/C,MAAM,MAAM,OAAO,OAAO,MAAM,MAAO,MAAM;AAE7C,QAAK,MAAM,kBAAkB;AAC7B,QAAK,MAAM,cAAc,OAAO;IAAE;IAAK;IAAK;;;;CAIhD,MAAM,MAAM,YAA6C;AACvD,MAAI,CAAC,WAAW,QAAQ;AACtB,QAAK,QAAQ;AACb;;AAGF,OAAK,MAAM,aAAa,YAAY;GAClC,MAAM,eAAe,UAAU,KAAK;AACpC,OAAI,gBAAgB,KAAK,MAAO,QAAO,KAAK,MAAM"}
@@ -0,0 +1,19 @@
1
+ import { BaseCache, CacheFullKey, CacheNamespace } from "./base.cjs";
2
+
3
+ //#region src/cache/memory.d.ts
4
+ declare class InMemoryCache<V = unknown> extends BaseCache<V> {
5
+ private cache;
6
+ get(keys: CacheFullKey[]): Promise<{
7
+ key: CacheFullKey;
8
+ value: V;
9
+ }[]>;
10
+ set(pairs: {
11
+ key: CacheFullKey;
12
+ value: V;
13
+ ttl?: number;
14
+ }[]): Promise<void>;
15
+ clear(namespaces: CacheNamespace[]): Promise<void>;
16
+ }
17
+ //#endregion
18
+ export { InMemoryCache };
19
+ //# sourceMappingURL=memory.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.cts","names":["BaseCache","CacheFullKey","CacheNamespace","InMemoryCache","V","Promise"],"sources":["../../src/cache/memory.d.ts"],"sourcesContent":["import { BaseCache, type CacheFullKey, type CacheNamespace } from \"./base.js\";\nexport declare class InMemoryCache<V = unknown> extends BaseCache<V> {\n private cache;\n get(keys: CacheFullKey[]): Promise<{\n key: CacheFullKey;\n value: V;\n }[]>;\n set(pairs: {\n key: CacheFullKey;\n value: V;\n ttl?: number;\n }[]): Promise<void>;\n clear(namespaces: CacheNamespace[]): Promise<void>;\n}\n"],"mappings":";;;cACqBG,mCAAmCH,UAAUI;;EAA7CD,GAAAA,CAAAA,IAAAA,EAEPF,YAFoB,EAAA,CAAA,EAEHI,OAFG,CAAA;IAAA,GAAA,EAGrBJ,YAHqB;IAAgCG,KAAAA,EAInDA,CAJmDA;KAEpDH,CAAAA;KACDA,CAAAA,KAAAA,EAAAA;IACEG,GAAAA,EAGFH,YAHEG;IAFgBC,KAAAA,EAMhBD,CANgBC;IAKlBJ,GAAAA,CAAAA,EAAAA,MAAAA;KACEG,CAAAA,EAELC,OAFKD,CAAAA,IAAAA,CAAAA;OAELC,CAAAA,UAAAA,EACYH,cADZG,EAAAA,CAAAA,EAC+BA,OAD/BA,CAAAA,IAAAA,CAAAA"}