@langchain/langgraph-checkpoint 0.1.1 → 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 +6 -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
@@ -1,49 +1,55 @@
1
- export declare const TASKS = "__pregel_tasks";
2
- export declare const ERROR = "__error__";
3
- export declare const SCHEDULED = "__scheduled__";
4
- export declare const INTERRUPT = "__interrupt__";
5
- export declare const RESUME = "__resume__";
6
- export interface ChannelProtocol<ValueType = unknown, UpdateType = unknown, CheckpointType = unknown> {
7
- ValueType: ValueType;
8
- UpdateType: UpdateType;
9
- /**
10
- * The name of the channel.
11
- */
12
- lc_graph_name: string;
13
- /**
14
- * Return a new identical channel, optionally initialized from a checkpoint.
15
- * Can be thought of as a "restoration" from a checkpoint which is a "snapshot" of the channel's state.
16
- *
17
- * @param {CheckpointType | undefined} checkpoint
18
- * @param {CheckpointType | undefined} initialValue
19
- * @returns {this}
20
- */
21
- fromCheckpoint(checkpoint?: CheckpointType): this;
22
- /**
23
- * Update the channel's value with the given sequence of updates.
24
- * The order of the updates in the sequence is arbitrary.
25
- *
26
- * @throws {InvalidUpdateError} if the sequence of updates is invalid.
27
- * @param {Array<UpdateType>} values
28
- * @returns {void}
29
- */
30
- update(values: UpdateType[]): void;
31
- /**
32
- * Return the current value of the channel.
33
- *
34
- * @throws {EmptyChannelError} if the channel is empty (never updated yet).
35
- * @returns {ValueType}
36
- */
37
- get(): ValueType;
38
- /**
39
- * Return a string representation of the channel's current state.
40
- *
41
- * @throws {EmptyChannelError} if the channel is empty (never updated yet), or doesn't support checkpoints.
42
- * @returns {CheckpointType | undefined}
43
- */
44
- checkpoint(): CheckpointType | undefined;
1
+ //#region src/serde/types.d.ts
2
+ declare const TASKS = "__pregel_tasks";
3
+ declare const ERROR = "__error__";
4
+ declare const SCHEDULED = "__scheduled__";
5
+ declare const INTERRUPT = "__interrupt__";
6
+ declare const RESUME = "__resume__";
7
+ // Mirrors BaseChannel in "@langchain/langgraph"
8
+ interface ChannelProtocol<ValueType = unknown, UpdateType = unknown, CheckpointType = unknown> {
9
+ ValueType: ValueType;
10
+ UpdateType: UpdateType;
11
+ /**
12
+ * The name of the channel.
13
+ */
14
+ lc_graph_name: string;
15
+ /**
16
+ * Return a new identical channel, optionally initialized from a checkpoint.
17
+ * Can be thought of as a "restoration" from a checkpoint which is a "snapshot" of the channel's state.
18
+ *
19
+ * @param {CheckpointType | undefined} checkpoint
20
+ * @returns {this}
21
+ */
22
+ fromCheckpoint(checkpoint?: CheckpointType): this;
23
+ /**
24
+ * Update the channel's value with the given sequence of updates.
25
+ * The order of the updates in the sequence is arbitrary.
26
+ *
27
+ * @throws {InvalidUpdateError} if the sequence of updates is invalid.
28
+ * @param {Array<UpdateType>} values
29
+ * @returns {void}
30
+ */
31
+ update(values: UpdateType[]): void;
32
+ /**
33
+ * Return the current value of the channel.
34
+ *
35
+ * @throws {EmptyChannelError} if the channel is empty (never updated yet).
36
+ * @returns {ValueType}
37
+ */
38
+ get(): ValueType;
39
+ /**
40
+ * Return a string representation of the channel's current state.
41
+ *
42
+ * @throws {EmptyChannelError} if the channel is empty (never updated yet), or doesn't support checkpoints.
43
+ * @returns {CheckpointType | undefined}
44
+ */
45
+ checkpoint(): CheckpointType | undefined;
45
46
  }
46
- export interface SendProtocol {
47
- node: string;
48
- args: any;
47
+ // Mirrors SendInterface in "@langchain/langgraph"
48
+ interface SendProtocol {
49
+ node: string;
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ args: any;
49
52
  }
53
+ //#endregion
54
+ export { ChannelProtocol, ERROR, INTERRUPT, RESUME, SCHEDULED, SendProtocol, TASKS };
55
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":["TASKS","ERROR","SCHEDULED","INTERRUPT","RESUME","ChannelProtocol","ValueType","UpdateType","CheckpointType","SendProtocol"],"sources":["../../src/serde/types.d.ts"],"sourcesContent":["export declare const TASKS = \"__pregel_tasks\";\nexport declare const ERROR = \"__error__\";\nexport declare const SCHEDULED = \"__scheduled__\";\nexport declare const INTERRUPT = \"__interrupt__\";\nexport declare const RESUME = \"__resume__\";\n// Mirrors BaseChannel in \"@langchain/langgraph\"\nexport interface ChannelProtocol<ValueType = unknown, UpdateType = unknown, CheckpointType = unknown> {\n ValueType: ValueType;\n UpdateType: UpdateType;\n /**\n * The name of the channel.\n */\n lc_graph_name: string;\n /**\n * Return a new identical channel, optionally initialized from a checkpoint.\n * Can be thought of as a \"restoration\" from a checkpoint which is a \"snapshot\" of the channel's state.\n *\n * @param {CheckpointType | undefined} checkpoint\n * @returns {this}\n */\n fromCheckpoint(checkpoint?: CheckpointType): this;\n /**\n * Update the channel's value with the given sequence of updates.\n * The order of the updates in the sequence is arbitrary.\n *\n * @throws {InvalidUpdateError} if the sequence of updates is invalid.\n * @param {Array<UpdateType>} values\n * @returns {void}\n */\n update(values: UpdateType[]): void;\n /**\n * Return the current value of the channel.\n *\n * @throws {EmptyChannelError} if the channel is empty (never updated yet).\n * @returns {ValueType}\n */\n get(): ValueType;\n /**\n * Return a string representation of the channel's current state.\n *\n * @throws {EmptyChannelError} if the channel is empty (never updated yet), or doesn't support checkpoints.\n * @returns {CheckpointType | undefined}\n */\n checkpoint(): CheckpointType | undefined;\n}\n// Mirrors SendInterface in \"@langchain/langgraph\"\nexport interface SendProtocol {\n node: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: any;\n}\n"],"mappings":";cAAqBA,KAAAA;AAAAA,cACAC,KAAAA,GADK,WAAA;AACLA,cACAC,SAAAA,GADK,eAAA;AACLA,cACAC,SAAAA,GADS,eAAA;AACTA,cACAC,MAAAA,GADS,YAAA;AAC9B;AAEiBC,UAAAA,eAAe,CAAA,YAAA,OAAA,EAAA,aAAA,OAAA,EAAA,iBAAA,OAAA,CAAA,CAAA;EAAA,SAAA,EACjBC,SADiB;YACjBA,EACCC,UADDD;;;;eA6BJA,EAAAA,MAAAA;;;AAUX;;;;;8BA1BgCE;;;;;;;;;iBASbD;;;;;;;SAORD;;;;;;;gBAOOE;;;UAGDC,YAAAA"}
@@ -1,6 +1,10 @@
1
- export const TASKS = "__pregel_tasks";
2
- export const ERROR = "__error__";
3
- export const SCHEDULED = "__scheduled__";
4
- export const INTERRUPT = "__interrupt__";
5
- export const RESUME = "__resume__";
1
+ //#region src/serde/types.ts
2
+ const TASKS = "__pregel_tasks";
3
+ const ERROR = "__error__";
4
+ const SCHEDULED = "__scheduled__";
5
+ const INTERRUPT = "__interrupt__";
6
+ const RESUME = "__resume__";
7
+
8
+ //#endregion
9
+ export { ERROR, INTERRUPT, RESUME, SCHEDULED, TASKS };
6
10
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/serde/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAG,gBAAgB,CAAC;AACtC,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC;AACjC,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CAAC;AACzC,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CAAC;AACzC,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,CAAC"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/serde/types.ts"],"sourcesContent":["export const TASKS = \"__pregel_tasks\";\nexport const ERROR = \"__error__\";\nexport const SCHEDULED = \"__scheduled__\";\nexport const INTERRUPT = \"__interrupt__\";\nexport const RESUME = \"__resume__\";\n\n// Mirrors BaseChannel in \"@langchain/langgraph\"\nexport interface ChannelProtocol<\n ValueType = unknown,\n UpdateType = unknown,\n CheckpointType = unknown\n> {\n ValueType: ValueType;\n\n UpdateType: UpdateType;\n\n /**\n * The name of the channel.\n */\n lc_graph_name: string;\n\n /**\n * Return a new identical channel, optionally initialized from a checkpoint.\n * Can be thought of as a \"restoration\" from a checkpoint which is a \"snapshot\" of the channel's state.\n *\n * @param {CheckpointType | undefined} checkpoint\n * @returns {this}\n */\n fromCheckpoint(checkpoint?: CheckpointType): this;\n\n /**\n * Update the channel's value with the given sequence of updates.\n * The order of the updates in the sequence is arbitrary.\n *\n * @throws {InvalidUpdateError} if the sequence of updates is invalid.\n * @param {Array<UpdateType>} values\n * @returns {void}\n */\n update(values: UpdateType[]): void;\n\n /**\n * Return the current value of the channel.\n *\n * @throws {EmptyChannelError} if the channel is empty (never updated yet).\n * @returns {ValueType}\n */\n get(): ValueType;\n\n /**\n * Return a string representation of the channel's current state.\n *\n * @throws {EmptyChannelError} if the channel is empty (never updated yet), or doesn't support checkpoints.\n * @returns {CheckpointType | undefined}\n */\n checkpoint(): CheckpointType | undefined;\n}\n\n// Mirrors SendInterface in \"@langchain/langgraph\"\nexport interface SendProtocol {\n node: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: any;\n}\n"],"mappings":";AAAA,MAAa,QAAQ;AACrB,MAAa,QAAQ;AACrB,MAAa,YAAY;AACzB,MAAa,YAAY;AACzB,MAAa,SAAS"}
@@ -1,222 +1,102 @@
1
- "use strict";
2
- /* eslint-disable */
3
- // @ts-nocheck
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.stringify = stringify;
6
- // Stringify that can handle circular references.
7
- // Inlined due to ESM import issues
8
- // Source: https://www.npmjs.com/package/fast-safe-stringify
1
+
2
+ //#region src/serde/utils/fast-safe-stringify/index.ts
9
3
  var LIMIT_REPLACE_NODE = "[...]";
10
4
  var CIRCULAR_REPLACE_NODE = "[Circular]";
11
5
  var arr = [];
12
6
  var replacerStack = [];
13
7
  function defaultOptions() {
14
- return {
15
- depthLimit: Number.MAX_SAFE_INTEGER,
16
- edgesLimit: Number.MAX_SAFE_INTEGER,
17
- };
8
+ return {
9
+ depthLimit: Number.MAX_SAFE_INTEGER,
10
+ edgesLimit: Number.MAX_SAFE_INTEGER
11
+ };
18
12
  }
19
- // Regular stringify
20
13
  function stringify(obj, replacer, spacer, options) {
21
- if (typeof options === "undefined") {
22
- options = defaultOptions();
23
- }
24
- decirc(obj, "", 0, [], undefined, 0, options);
25
- var res;
26
- try {
27
- if (replacerStack.length === 0) {
28
- res = JSON.stringify(obj, replacer, spacer);
29
- }
30
- else {
31
- res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
32
- }
33
- }
34
- catch (_) {
35
- return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
36
- }
37
- finally {
38
- while (arr.length !== 0) {
39
- var part = arr.pop();
40
- if (part.length === 4) {
41
- Object.defineProperty(part[0], part[1], part[3]);
42
- }
43
- else {
44
- part[0][part[1]] = part[2];
45
- }
46
- }
47
- }
48
- return res;
14
+ if (typeof options === "undefined") options = defaultOptions();
15
+ decirc(obj, "", 0, [], void 0, 0, options);
16
+ var res;
17
+ try {
18
+ if (replacerStack.length === 0) res = JSON.stringify(obj, replacer, spacer);
19
+ else res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
20
+ } catch (_) {
21
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
22
+ } finally {
23
+ while (arr.length !== 0) {
24
+ var part = arr.pop();
25
+ if (part.length === 4) Object.defineProperty(part[0], part[1], part[3]);
26
+ else part[0][part[1]] = part[2];
27
+ }
28
+ }
29
+ return res;
49
30
  }
50
31
  function setReplace(replace, val, k, parent) {
51
- var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
52
- if (propertyDescriptor.get !== undefined) {
53
- if (propertyDescriptor.configurable) {
54
- Object.defineProperty(parent, k, { value: replace });
55
- arr.push([parent, k, val, propertyDescriptor]);
56
- }
57
- else {
58
- replacerStack.push([val, k, replace]);
59
- }
60
- }
61
- else {
62
- parent[k] = replace;
63
- arr.push([parent, k, val]);
64
- }
32
+ var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
33
+ if (propertyDescriptor.get !== void 0) if (propertyDescriptor.configurable) {
34
+ Object.defineProperty(parent, k, { value: replace });
35
+ arr.push([
36
+ parent,
37
+ k,
38
+ val,
39
+ propertyDescriptor
40
+ ]);
41
+ } else replacerStack.push([
42
+ val,
43
+ k,
44
+ replace
45
+ ]);
46
+ else {
47
+ parent[k] = replace;
48
+ arr.push([
49
+ parent,
50
+ k,
51
+ val
52
+ ]);
53
+ }
65
54
  }
66
55
  function decirc(val, k, edgeIndex, stack, parent, depth, options) {
67
- depth += 1;
68
- var i;
69
- if (typeof val === "object" && val !== null) {
70
- for (i = 0; i < stack.length; i++) {
71
- if (stack[i] === val) {
72
- setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
73
- return;
74
- }
75
- }
76
- if (typeof options.depthLimit !== "undefined" &&
77
- depth > options.depthLimit) {
78
- setReplace(LIMIT_REPLACE_NODE, val, k, parent);
79
- return;
80
- }
81
- if (typeof options.edgesLimit !== "undefined" &&
82
- edgeIndex + 1 > options.edgesLimit) {
83
- setReplace(LIMIT_REPLACE_NODE, val, k, parent);
84
- return;
85
- }
86
- stack.push(val);
87
- // Optimize for Arrays. Big arrays could kill the performance otherwise!
88
- if (Array.isArray(val)) {
89
- for (i = 0; i < val.length; i++) {
90
- decirc(val[i], i, i, stack, val, depth, options);
91
- }
92
- }
93
- else {
94
- var keys = Object.keys(val);
95
- for (i = 0; i < keys.length; i++) {
96
- var key = keys[i];
97
- decirc(val[key], key, i, stack, val, depth, options);
98
- }
99
- }
100
- stack.pop();
101
- }
102
- }
103
- // Stable-stringify
104
- function compareFunction(a, b) {
105
- if (a < b) {
106
- return -1;
107
- }
108
- if (a > b) {
109
- return 1;
110
- }
111
- return 0;
112
- }
113
- function deterministicStringify(obj, replacer, spacer, options) {
114
- if (typeof options === "undefined") {
115
- options = defaultOptions();
116
- }
117
- var tmp = deterministicDecirc(obj, "", 0, [], undefined, 0, options) || obj;
118
- var res;
119
- try {
120
- if (replacerStack.length === 0) {
121
- res = JSON.stringify(tmp, replacer, spacer);
122
- }
123
- else {
124
- res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer);
125
- }
126
- }
127
- catch (_) {
128
- return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
129
- }
130
- finally {
131
- // Ensure that we restore the object as it was.
132
- while (arr.length !== 0) {
133
- var part = arr.pop();
134
- if (part.length === 4) {
135
- Object.defineProperty(part[0], part[1], part[3]);
136
- }
137
- else {
138
- part[0][part[1]] = part[2];
139
- }
140
- }
141
- }
142
- return res;
56
+ depth += 1;
57
+ var i;
58
+ if (typeof val === "object" && val !== null) {
59
+ for (i = 0; i < stack.length; i++) if (stack[i] === val) {
60
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
61
+ return;
62
+ }
63
+ if (typeof options.depthLimit !== "undefined" && depth > options.depthLimit) {
64
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
65
+ return;
66
+ }
67
+ if (typeof options.edgesLimit !== "undefined" && edgeIndex + 1 > options.edgesLimit) {
68
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
69
+ return;
70
+ }
71
+ stack.push(val);
72
+ if (Array.isArray(val)) for (i = 0; i < val.length; i++) decirc(val[i], i, i, stack, val, depth, options);
73
+ else {
74
+ var keys = Object.keys(val);
75
+ for (i = 0; i < keys.length; i++) {
76
+ var key = keys[i];
77
+ decirc(val[key], key, i, stack, val, depth, options);
78
+ }
79
+ }
80
+ stack.pop();
81
+ }
143
82
  }
144
- function deterministicDecirc(val, k, edgeIndex, stack, parent, depth, options) {
145
- depth += 1;
146
- var i;
147
- if (typeof val === "object" && val !== null) {
148
- for (i = 0; i < stack.length; i++) {
149
- if (stack[i] === val) {
150
- setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
151
- return;
152
- }
153
- }
154
- try {
155
- if (typeof val.toJSON === "function") {
156
- return;
157
- }
158
- }
159
- catch (_) {
160
- return;
161
- }
162
- if (typeof options.depthLimit !== "undefined" &&
163
- depth > options.depthLimit) {
164
- setReplace(LIMIT_REPLACE_NODE, val, k, parent);
165
- return;
166
- }
167
- if (typeof options.edgesLimit !== "undefined" &&
168
- edgeIndex + 1 > options.edgesLimit) {
169
- setReplace(LIMIT_REPLACE_NODE, val, k, parent);
170
- return;
171
- }
172
- stack.push(val);
173
- // Optimize for Arrays. Big arrays could kill the performance otherwise!
174
- if (Array.isArray(val)) {
175
- for (i = 0; i < val.length; i++) {
176
- deterministicDecirc(val[i], i, i, stack, val, depth, options);
177
- }
178
- }
179
- else {
180
- // Create a temporary object in the required way
181
- var tmp = {};
182
- var keys = Object.keys(val).sort(compareFunction);
183
- for (i = 0; i < keys.length; i++) {
184
- var key = keys[i];
185
- deterministicDecirc(val[key], key, i, stack, val, depth, options);
186
- tmp[key] = val[key];
187
- }
188
- if (typeof parent !== "undefined") {
189
- arr.push([parent, k, val]);
190
- parent[k] = tmp;
191
- }
192
- else {
193
- return tmp;
194
- }
195
- }
196
- stack.pop();
197
- }
198
- }
199
- // wraps replacer function to handle values we couldn't replace
200
- // and mark them as replaced value
201
83
  function replaceGetterValues(replacer) {
202
- replacer =
203
- typeof replacer !== "undefined"
204
- ? replacer
205
- : function (k, v) {
206
- return v;
207
- };
208
- return function (key, val) {
209
- if (replacerStack.length > 0) {
210
- for (var i = 0; i < replacerStack.length; i++) {
211
- var part = replacerStack[i];
212
- if (part[1] === key && part[0] === val) {
213
- val = part[2];
214
- replacerStack.splice(i, 1);
215
- break;
216
- }
217
- }
218
- }
219
- return replacer.call(this, key, val);
220
- };
84
+ replacer = typeof replacer !== "undefined" ? replacer : function(k, v) {
85
+ return v;
86
+ };
87
+ return function(key, val) {
88
+ if (replacerStack.length > 0) for (var i = 0; i < replacerStack.length; i++) {
89
+ var part = replacerStack[i];
90
+ if (part[1] === key && part[0] === val) {
91
+ val = part[2];
92
+ replacerStack.splice(i, 1);
93
+ break;
94
+ }
95
+ }
96
+ return replacer.call(this, key, val);
97
+ };
221
98
  }
222
- //# sourceMappingURL=index.js.map
99
+
100
+ //#endregion
101
+ exports.stringify = stringify;
102
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../../../src/serde/utils/fast-safe-stringify/index.ts"],"sourcesContent":["/* eslint-disable */\n// @ts-nocheck\n\n// Stringify that can handle circular references.\n// Inlined due to ESM import issues\n// Source: https://www.npmjs.com/package/fast-safe-stringify\n\nvar LIMIT_REPLACE_NODE = \"[...]\";\nvar CIRCULAR_REPLACE_NODE = \"[Circular]\";\n\nvar arr = [];\nvar replacerStack = [];\n\nfunction defaultOptions() {\n return {\n depthLimit: Number.MAX_SAFE_INTEGER,\n edgesLimit: Number.MAX_SAFE_INTEGER,\n };\n}\n\n// Regular stringify\nexport function stringify(obj, replacer?, spacer?, options?) {\n if (typeof options === \"undefined\") {\n options = defaultOptions();\n }\n\n decirc(obj, \"\", 0, [], undefined, 0, options);\n var res;\n try {\n if (replacerStack.length === 0) {\n res = JSON.stringify(obj, replacer, spacer);\n } else {\n res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);\n }\n } catch (_) {\n return JSON.stringify(\n \"[unable to serialize, circular reference is too complex to analyze]\"\n );\n } finally {\n while (arr.length !== 0) {\n var part = arr.pop();\n if (part.length === 4) {\n Object.defineProperty(part[0], part[1], part[3]);\n } else {\n part[0][part[1]] = part[2];\n }\n }\n }\n return res;\n}\n\nfunction setReplace(replace, val, k, parent) {\n var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);\n if (propertyDescriptor.get !== undefined) {\n if (propertyDescriptor.configurable) {\n Object.defineProperty(parent, k, { value: replace });\n arr.push([parent, k, val, propertyDescriptor]);\n } else {\n replacerStack.push([val, k, replace]);\n }\n } else {\n parent[k] = replace;\n arr.push([parent, k, val]);\n }\n}\n\nfunction decirc(val, k, edgeIndex, stack, parent, depth, options) {\n depth += 1;\n var i;\n if (typeof val === \"object\" && val !== null) {\n for (i = 0; i < stack.length; i++) {\n if (stack[i] === val) {\n setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);\n return;\n }\n }\n\n if (\n typeof options.depthLimit !== \"undefined\" &&\n depth > options.depthLimit\n ) {\n setReplace(LIMIT_REPLACE_NODE, val, k, parent);\n return;\n }\n\n if (\n typeof options.edgesLimit !== \"undefined\" &&\n edgeIndex + 1 > options.edgesLimit\n ) {\n setReplace(LIMIT_REPLACE_NODE, val, k, parent);\n return;\n }\n\n stack.push(val);\n // Optimize for Arrays. Big arrays could kill the performance otherwise!\n if (Array.isArray(val)) {\n for (i = 0; i < val.length; i++) {\n decirc(val[i], i, i, stack, val, depth, options);\n }\n } else {\n var keys = Object.keys(val);\n for (i = 0; i < keys.length; i++) {\n var key = keys[i];\n decirc(val[key], key, i, stack, val, depth, options);\n }\n }\n stack.pop();\n }\n}\n\n// Stable-stringify\nfunction compareFunction(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction deterministicStringify(obj, replacer, spacer, options) {\n if (typeof options === \"undefined\") {\n options = defaultOptions();\n }\n\n var tmp = deterministicDecirc(obj, \"\", 0, [], undefined, 0, options) || obj;\n var res;\n try {\n if (replacerStack.length === 0) {\n res = JSON.stringify(tmp, replacer, spacer);\n } else {\n res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer);\n }\n } catch (_) {\n return JSON.stringify(\n \"[unable to serialize, circular reference is too complex to analyze]\"\n );\n } finally {\n // Ensure that we restore the object as it was.\n while (arr.length !== 0) {\n var part = arr.pop();\n if (part.length === 4) {\n Object.defineProperty(part[0], part[1], part[3]);\n } else {\n part[0][part[1]] = part[2];\n }\n }\n }\n return res;\n}\n\nfunction deterministicDecirc(val, k, edgeIndex, stack, parent, depth, options) {\n depth += 1;\n var i;\n if (typeof val === \"object\" && val !== null) {\n for (i = 0; i < stack.length; i++) {\n if (stack[i] === val) {\n setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);\n return;\n }\n }\n try {\n if (typeof val.toJSON === \"function\") {\n return;\n }\n } catch (_) {\n return;\n }\n\n if (\n typeof options.depthLimit !== \"undefined\" &&\n depth > options.depthLimit\n ) {\n setReplace(LIMIT_REPLACE_NODE, val, k, parent);\n return;\n }\n\n if (\n typeof options.edgesLimit !== \"undefined\" &&\n edgeIndex + 1 > options.edgesLimit\n ) {\n setReplace(LIMIT_REPLACE_NODE, val, k, parent);\n return;\n }\n\n stack.push(val);\n // Optimize for Arrays. Big arrays could kill the performance otherwise!\n if (Array.isArray(val)) {\n for (i = 0; i < val.length; i++) {\n deterministicDecirc(val[i], i, i, stack, val, depth, options);\n }\n } else {\n // Create a temporary object in the required way\n var tmp = {};\n var keys = Object.keys(val).sort(compareFunction);\n for (i = 0; i < keys.length; i++) {\n var key = keys[i];\n deterministicDecirc(val[key], key, i, stack, val, depth, options);\n tmp[key] = val[key];\n }\n if (typeof parent !== \"undefined\") {\n arr.push([parent, k, val]);\n parent[k] = tmp;\n } else {\n return tmp;\n }\n }\n stack.pop();\n }\n}\n\n// wraps replacer function to handle values we couldn't replace\n// and mark them as replaced value\nfunction replaceGetterValues(replacer) {\n replacer =\n typeof replacer !== \"undefined\"\n ? replacer\n : function (k, v) {\n return v;\n };\n return function (key, val) {\n if (replacerStack.length > 0) {\n for (var i = 0; i < replacerStack.length; i++) {\n var part = replacerStack[i];\n if (part[1] === key && part[0] === val) {\n val = part[2];\n replacerStack.splice(i, 1);\n break;\n }\n }\n }\n return replacer.call(this, key, val);\n };\n}\n"],"mappings":";;AAOA,IAAI,qBAAqB;AACzB,IAAI,wBAAwB;AAE5B,IAAI,MAAM;AACV,IAAI,gBAAgB;AAEpB,SAAS,iBAAiB;AACxB,QAAO;EACL,YAAY,OAAO;EACnB,YAAY,OAAO;;;AAKvB,SAAgB,UAAU,KAAK,UAAW,QAAS,SAAU;AAC3D,KAAI,OAAO,YAAY,YACrB,WAAU;AAGZ,QAAO,KAAK,IAAI,GAAG,IAAI,QAAW,GAAG;CACrC,IAAI;AACJ,KAAI;AACF,MAAI,cAAc,WAAW,EAC3B,OAAM,KAAK,UAAU,KAAK,UAAU;MAEpC,OAAM,KAAK,UAAU,KAAK,oBAAoB,WAAW;UAEpD,GAAG;AACV,SAAO,KAAK,UACV;WAEM;AACR,SAAO,IAAI,WAAW,GAAG;GACvB,IAAI,OAAO,IAAI;AACf,OAAI,KAAK,WAAW,EAClB,QAAO,eAAe,KAAK,IAAI,KAAK,IAAI,KAAK;OAE7C,MAAK,GAAG,KAAK,MAAM,KAAK;;;AAI9B,QAAO;;AAGT,SAAS,WAAW,SAAS,KAAK,GAAG,QAAQ;CAC3C,IAAI,qBAAqB,OAAO,yBAAyB,QAAQ;AACjE,KAAI,mBAAmB,QAAQ,OAC7B,KAAI,mBAAmB,cAAc;AACnC,SAAO,eAAe,QAAQ,GAAG,EAAE,OAAO;AAC1C,MAAI,KAAK;GAAC;GAAQ;GAAG;GAAK;;OAE1B,eAAc,KAAK;EAAC;EAAK;EAAG;;MAEzB;AACL,SAAO,KAAK;AACZ,MAAI,KAAK;GAAC;GAAQ;GAAG;;;;AAIzB,SAAS,OAAO,KAAK,GAAG,WAAW,OAAO,QAAQ,OAAO,SAAS;AAChE,UAAS;CACT,IAAI;AACJ,KAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;AAC3C,OAAK,IAAI,GAAG,IAAI,MAAM,QAAQ,IAC5B,KAAI,MAAM,OAAO,KAAK;AACpB,cAAW,uBAAuB,KAAK,GAAG;AAC1C;;AAIJ,MACE,OAAO,QAAQ,eAAe,eAC9B,QAAQ,QAAQ,YAChB;AACA,cAAW,oBAAoB,KAAK,GAAG;AACvC;;AAGF,MACE,OAAO,QAAQ,eAAe,eAC9B,YAAY,IAAI,QAAQ,YACxB;AACA,cAAW,oBAAoB,KAAK,GAAG;AACvC;;AAGF,QAAM,KAAK;AAEX,MAAI,MAAM,QAAQ,KAChB,MAAK,IAAI,GAAG,IAAI,IAAI,QAAQ,IAC1B,QAAO,IAAI,IAAI,GAAG,GAAG,OAAO,KAAK,OAAO;OAErC;GACL,IAAI,OAAO,OAAO,KAAK;AACvB,QAAK,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;IAChC,IAAI,MAAM,KAAK;AACf,WAAO,IAAI,MAAM,KAAK,GAAG,OAAO,KAAK,OAAO;;;AAGhD,QAAM;;;AA4GV,SAAS,oBAAoB,UAAU;AACrC,YACE,OAAO,aAAa,cAChB,WACA,SAAU,GAAG,GAAG;AACd,SAAO;;AAEf,QAAO,SAAU,KAAK,KAAK;AACzB,MAAI,cAAc,SAAS,EACzB,MAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ,KAAK;GAC7C,IAAI,OAAO,cAAc;AACzB,OAAI,KAAK,OAAO,OAAO,KAAK,OAAO,KAAK;AACtC,UAAM,KAAK;AACX,kBAAc,OAAO,GAAG;AACxB;;;AAIN,SAAO,SAAS,KAAK,MAAM,KAAK"}