@langchain/langgraph-checkpoint 0.1.1 → 1.0.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.
Files changed (120) hide show
  1. package/dist/base.cjs +73 -88
  2. package/dist/base.cjs.map +1 -0
  3. package/dist/base.d.cts +94 -0
  4. package/dist/base.d.cts.map +1 -0
  5. package/dist/base.d.ts +78 -73
  6. package/dist/base.d.ts.map +1 -0
  7. package/dist/base.js +68 -80
  8. package/dist/base.js.map +1 -1
  9. package/dist/cache/base.cjs +16 -21
  10. package/dist/cache/base.cjs.map +1 -0
  11. package/dist/cache/base.d.cts +43 -0
  12. package/dist/cache/base.d.cts.map +1 -0
  13. package/dist/cache/base.d.ts +41 -36
  14. package/dist/cache/base.d.ts.map +1 -0
  15. package/dist/cache/base.js +15 -16
  16. package/dist/cache/base.js.map +1 -1
  17. package/dist/cache/index.cjs +2 -19
  18. package/dist/cache/index.js +3 -3
  19. package/dist/cache/memory.cjs +50 -58
  20. package/dist/cache/memory.cjs.map +1 -0
  21. package/dist/cache/memory.d.cts +19 -0
  22. package/dist/cache/memory.d.cts.map +1 -0
  23. package/dist/cache/memory.d.ts +18 -13
  24. package/dist/cache/memory.d.ts.map +1 -0
  25. package/dist/cache/memory.js +49 -53
  26. package/dist/cache/memory.js.map +1 -1
  27. package/dist/id.cjs +10 -16
  28. package/dist/id.cjs.map +1 -0
  29. package/dist/id.d.cts +6 -0
  30. package/dist/id.d.cts.map +1 -0
  31. package/dist/id.d.ts +6 -2
  32. package/dist/id.d.ts.map +1 -0
  33. package/dist/id.js +9 -12
  34. package/dist/id.js.map +1 -1
  35. package/dist/index.cjs +36 -27
  36. package/dist/index.d.cts +12 -0
  37. package/dist/index.d.ts +12 -8
  38. package/dist/index.js +11 -9
  39. package/dist/memory.cjs +191 -268
  40. package/dist/memory.cjs.map +1 -0
  41. package/dist/memory.d.cts +21 -0
  42. package/dist/memory.d.cts.map +1 -0
  43. package/dist/memory.d.ts +18 -12
  44. package/dist/memory.d.ts.map +1 -0
  45. package/dist/memory.js +190 -263
  46. package/dist/memory.js.map +1 -1
  47. package/dist/serde/base.d.cts +8 -0
  48. package/dist/serde/base.d.cts.map +1 -0
  49. package/dist/serde/base.d.ts +7 -3
  50. package/dist/serde/base.d.ts.map +1 -0
  51. package/dist/serde/jsonplus.cjs +90 -141
  52. package/dist/serde/jsonplus.cjs.map +1 -0
  53. package/dist/serde/jsonplus.js +89 -136
  54. package/dist/serde/jsonplus.js.map +1 -1
  55. package/dist/serde/types.cjs +14 -9
  56. package/dist/serde/types.cjs.map +1 -0
  57. package/dist/serde/types.d.cts +52 -0
  58. package/dist/serde/types.d.cts.map +1 -0
  59. package/dist/serde/types.d.ts +50 -47
  60. package/dist/serde/types.d.ts.map +1 -0
  61. package/dist/serde/types.js +9 -5
  62. package/dist/serde/types.js.map +1 -1
  63. package/dist/serde/utils/fast-safe-stringify/index.cjs +87 -208
  64. package/dist/serde/utils/fast-safe-stringify/index.cjs.map +1 -0
  65. package/dist/serde/utils/fast-safe-stringify/index.js +87 -205
  66. package/dist/serde/utils/fast-safe-stringify/index.js.map +1 -1
  67. package/dist/store/base.cjs +199 -209
  68. package/dist/store/base.cjs.map +1 -0
  69. package/dist/store/base.d.cts +391 -0
  70. package/dist/store/base.d.cts.map +1 -0
  71. package/dist/store/base.d.ts +335 -332
  72. package/dist/store/base.d.ts.map +1 -0
  73. package/dist/store/base.js +198 -204
  74. package/dist/store/base.js.map +1 -1
  75. package/dist/store/batch.cjs +114 -147
  76. package/dist/store/batch.cjs.map +1 -0
  77. package/dist/store/batch.d.cts +46 -0
  78. package/dist/store/batch.d.cts.map +1 -0
  79. package/dist/store/batch.d.ts +45 -40
  80. package/dist/store/batch.d.ts.map +1 -0
  81. package/dist/store/batch.js +114 -143
  82. package/dist/store/batch.js.map +1 -1
  83. package/dist/store/memory.cjs +256 -363
  84. package/dist/store/memory.cjs.map +1 -0
  85. package/dist/store/memory.d.cts +62 -0
  86. package/dist/store/memory.d.cts.map +1 -0
  87. package/dist/store/memory.d.ts +28 -24
  88. package/dist/store/memory.d.ts.map +1 -0
  89. package/dist/store/memory.js +255 -358
  90. package/dist/store/memory.js.map +1 -1
  91. package/dist/store/utils.cjs +137 -249
  92. package/dist/store/utils.cjs.map +1 -0
  93. package/dist/store/utils.js +137 -245
  94. package/dist/store/utils.js.map +1 -1
  95. package/dist/types.d.cts +35 -0
  96. package/dist/types.d.cts.map +1 -0
  97. package/dist/types.d.ts +29 -28
  98. package/dist/types.d.ts.map +1 -0
  99. package/package.json +33 -34
  100. package/CHANGELOG.md +0 -19
  101. package/dist/cache/index.d.ts +0 -2
  102. package/dist/cache/index.js.map +0 -1
  103. package/dist/index.js.map +0 -1
  104. package/dist/serde/base.cjs +0 -3
  105. package/dist/serde/base.js +0 -2
  106. package/dist/serde/base.js.map +0 -1
  107. package/dist/serde/jsonplus.d.ts +0 -7
  108. package/dist/serde/utils/fast-safe-stringify/index.d.ts +0 -1
  109. package/dist/store/index.cjs +0 -20
  110. package/dist/store/index.d.ts +0 -3
  111. package/dist/store/index.js +0 -4
  112. package/dist/store/index.js.map +0 -1
  113. package/dist/store/utils.d.ts +0 -26
  114. package/dist/types.cjs +0 -3
  115. package/dist/types.js +0 -2
  116. package/dist/types.js.map +0 -1
  117. package/index.cjs +0 -1
  118. package/index.d.cts +0 -1
  119. package/index.d.ts +0 -1
  120. package/index.js +0 -1
@@ -1,49 +1,52 @@
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
+ interface ChannelProtocol<ValueType = unknown, UpdateType = unknown, CheckpointType = unknown> {
8
+ ValueType: ValueType;
9
+ UpdateType: UpdateType;
10
+ /**
11
+ * The name of the channel.
12
+ */
13
+ lc_graph_name: string;
14
+ /**
15
+ * Return a new identical channel, optionally initialized from a checkpoint.
16
+ * Can be thought of as a "restoration" from a checkpoint which is a "snapshot" of the channel's state.
17
+ *
18
+ * @param {CheckpointType | undefined} checkpoint
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;
45
45
  }
46
- export interface SendProtocol {
47
- node: string;
48
- args: any;
46
+ interface SendProtocol {
47
+ node: string;
48
+ args: any;
49
49
  }
50
+ //#endregion
51
+ export { ChannelProtocol, ERROR, INTERRUPT, RESUME, SCHEDULED, SendProtocol, TASKS };
52
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/serde/types.ts"],"mappings":";cAAa,KAAA;AAAA,cACA,KAAA;AAAA,cACA,SAAA;AAAA,cACA,SAAA;AAAA,cACA,MAAA;AAAA,UAGI,eAAA;EAKf,SAAA,EAAW,SAAA;EAEX,UAAA,EAAY,UAAA;;;;EAKZ,aAAA;EAjBoB;;;;AACtB;;;EAyBE,cAAA,CAAe,UAAA,GAAa,cAAA;EAzBR;AACtB;;;;;AAGA;;EA+BE,MAAA,CAAO,MAAA,EAAQ,UAAA;EA1BJ;;;;;;EAkCX,GAAA,IAAO,SAAA;EAQqB;;;;;;EAA5B,UAAA,IAAc,cAAA;AAAA;AAAA,UAIC,YAAA;EACf,IAAA;EAEA,IAAA;AAAA"}
@@ -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
+ //#endregion
8
+ export { ERROR, INTERRUPT, RESUME, SCHEDULED, TASKS };
9
+
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,101 @@
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
+ //#region src/serde/utils/fast-safe-stringify/index.ts
9
2
  var LIMIT_REPLACE_NODE = "[...]";
10
3
  var CIRCULAR_REPLACE_NODE = "[Circular]";
11
4
  var arr = [];
12
5
  var replacerStack = [];
13
6
  function defaultOptions() {
14
- return {
15
- depthLimit: Number.MAX_SAFE_INTEGER,
16
- edgesLimit: Number.MAX_SAFE_INTEGER,
17
- };
7
+ return {
8
+ depthLimit: Number.MAX_SAFE_INTEGER,
9
+ edgesLimit: Number.MAX_SAFE_INTEGER
10
+ };
18
11
  }
19
- // Regular stringify
20
12
  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;
13
+ if (typeof options === "undefined") options = defaultOptions();
14
+ decirc(obj, "", 0, [], void 0, 0, options);
15
+ var res;
16
+ try {
17
+ if (replacerStack.length === 0) res = JSON.stringify(obj, replacer, spacer);
18
+ else res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
19
+ } catch (_) {
20
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
21
+ } finally {
22
+ while (arr.length !== 0) {
23
+ var part = arr.pop();
24
+ if (part.length === 4) Object.defineProperty(part[0], part[1], part[3]);
25
+ else part[0][part[1]] = part[2];
26
+ }
27
+ }
28
+ return res;
49
29
  }
50
30
  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
- }
31
+ var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
32
+ if (propertyDescriptor.get !== void 0) if (propertyDescriptor.configurable) {
33
+ Object.defineProperty(parent, k, { value: replace });
34
+ arr.push([
35
+ parent,
36
+ k,
37
+ val,
38
+ propertyDescriptor
39
+ ]);
40
+ } else replacerStack.push([
41
+ val,
42
+ k,
43
+ replace
44
+ ]);
45
+ else {
46
+ parent[k] = replace;
47
+ arr.push([
48
+ parent,
49
+ k,
50
+ val
51
+ ]);
52
+ }
65
53
  }
66
54
  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;
55
+ depth += 1;
56
+ var i;
57
+ if (typeof val === "object" && val !== null) {
58
+ for (i = 0; i < stack.length; i++) if (stack[i] === val) {
59
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
60
+ return;
61
+ }
62
+ if (typeof options.depthLimit !== "undefined" && depth > options.depthLimit) {
63
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
64
+ return;
65
+ }
66
+ if (typeof options.edgesLimit !== "undefined" && edgeIndex + 1 > options.edgesLimit) {
67
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
68
+ return;
69
+ }
70
+ stack.push(val);
71
+ if (Array.isArray(val)) for (i = 0; i < val.length; i++) decirc(val[i], i, i, stack, val, depth, options);
72
+ else {
73
+ var keys = Object.keys(val);
74
+ for (i = 0; i < keys.length; i++) {
75
+ var key = keys[i];
76
+ decirc(val[key], key, i, stack, val, depth, options);
77
+ }
78
+ }
79
+ stack.pop();
80
+ }
143
81
  }
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
82
  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
- };
83
+ replacer = typeof replacer !== "undefined" ? replacer : function(k, v) {
84
+ return v;
85
+ };
86
+ return function(key, val) {
87
+ if (replacerStack.length > 0) for (var i = 0; i < replacerStack.length; i++) {
88
+ var part = replacerStack[i];
89
+ if (part[1] === key && part[0] === val) {
90
+ val = part[2];
91
+ replacerStack.splice(i, 1);
92
+ break;
93
+ }
94
+ }
95
+ return replacer.call(this, key, val);
96
+ };
221
97
  }
222
- //# sourceMappingURL=index.js.map
98
+ //#endregion
99
+ exports.stringify = stringify;
100
+
101
+ //# 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,EAAE;AACZ,IAAI,gBAAgB,EAAE;AAEtB,SAAS,iBAAiB;AACxB,QAAO;EACL,YAAY,OAAO;EACnB,YAAY,OAAO;EACpB;;AAIH,SAAgB,UAAU,KAAK,UAAW,QAAS,SAAU;AAC3D,KAAI,OAAO,YAAY,YACrB,WAAU,gBAAgB;AAG5B,QAAO,KAAK,IAAI,GAAG,EAAE,EAAE,KAAA,GAAW,GAAG,QAAQ;CAC7C,IAAI;AACJ,KAAI;AACF,MAAI,cAAc,WAAW,EAC3B,OAAM,KAAK,UAAU,KAAK,UAAU,OAAO;MAE3C,OAAM,KAAK,UAAU,KAAK,oBAAoB,SAAS,EAAE,OAAO;UAE3D,GAAG;AACV,SAAO,KAAK,UACV,sEACD;WACO;AACR,SAAO,IAAI,WAAW,GAAG;GACvB,IAAI,OAAO,IAAI,KAAK;AACpB,OAAI,KAAK,WAAW,EAClB,QAAO,eAAe,KAAK,IAAI,KAAK,IAAI,KAAK,GAAG;OAEhD,MAAK,GAAG,KAAK,MAAM,KAAK;;;AAI9B,QAAO;;AAGT,SAAS,WAAW,SAAS,KAAK,GAAG,QAAQ;CAC3C,IAAI,qBAAqB,OAAO,yBAAyB,QAAQ,EAAE;AACnE,KAAI,mBAAmB,QAAQ,KAAA,EAC7B,KAAI,mBAAmB,cAAc;AACnC,SAAO,eAAe,QAAQ,GAAG,EAAE,OAAO,SAAS,CAAC;AACpD,MAAI,KAAK;GAAC;GAAQ;GAAG;GAAK;GAAmB,CAAC;OAE9C,eAAc,KAAK;EAAC;EAAK;EAAG;EAAQ,CAAC;MAElC;AACL,SAAO,KAAK;AACZ,MAAI,KAAK;GAAC;GAAQ;GAAG;GAAI,CAAC;;;AAI9B,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,OAAO;AACjD;;AAIJ,MACE,OAAO,QAAQ,eAAe,eAC9B,QAAQ,QAAQ,YAChB;AACA,cAAW,oBAAoB,KAAK,GAAG,OAAO;AAC9C;;AAGF,MACE,OAAO,QAAQ,eAAe,eAC9B,YAAY,IAAI,QAAQ,YACxB;AACA,cAAW,oBAAoB,KAAK,GAAG,OAAO;AAC9C;;AAGF,QAAM,KAAK,IAAI;AAEf,MAAI,MAAM,QAAQ,IAAI,CACpB,MAAK,IAAI,GAAG,IAAI,IAAI,QAAQ,IAC1B,QAAO,IAAI,IAAI,GAAG,GAAG,OAAO,KAAK,OAAO,QAAQ;OAE7C;GACL,IAAI,OAAO,OAAO,KAAK,IAAI;AAC3B,QAAK,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;IAChC,IAAI,MAAM,KAAK;AACf,WAAO,IAAI,MAAM,KAAK,GAAG,OAAO,KAAK,OAAO,QAAQ;;;AAGxD,QAAM,KAAK;;;AA4Gf,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,EAAE;AAC1B;;;AAIN,SAAO,SAAS,KAAK,MAAM,KAAK,IAAI"}