@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.
- package/dist/base.cjs +73 -88
- package/dist/base.cjs.map +1 -0
- package/dist/base.d.cts +94 -0
- package/dist/base.d.cts.map +1 -0
- package/dist/base.d.ts +78 -73
- package/dist/base.d.ts.map +1 -0
- package/dist/base.js +68 -80
- package/dist/base.js.map +1 -1
- package/dist/cache/base.cjs +16 -21
- package/dist/cache/base.cjs.map +1 -0
- package/dist/cache/base.d.cts +43 -0
- package/dist/cache/base.d.cts.map +1 -0
- package/dist/cache/base.d.ts +41 -36
- package/dist/cache/base.d.ts.map +1 -0
- package/dist/cache/base.js +15 -16
- package/dist/cache/base.js.map +1 -1
- package/dist/cache/index.cjs +2 -19
- package/dist/cache/index.js +3 -3
- package/dist/cache/memory.cjs +50 -58
- package/dist/cache/memory.cjs.map +1 -0
- package/dist/cache/memory.d.cts +19 -0
- package/dist/cache/memory.d.cts.map +1 -0
- package/dist/cache/memory.d.ts +18 -13
- package/dist/cache/memory.d.ts.map +1 -0
- package/dist/cache/memory.js +49 -53
- package/dist/cache/memory.js.map +1 -1
- package/dist/id.cjs +10 -16
- package/dist/id.cjs.map +1 -0
- package/dist/id.d.cts +6 -0
- package/dist/id.d.cts.map +1 -0
- package/dist/id.d.ts +6 -2
- package/dist/id.d.ts.map +1 -0
- package/dist/id.js +9 -12
- package/dist/id.js.map +1 -1
- package/dist/index.cjs +36 -27
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.js +11 -9
- package/dist/memory.cjs +191 -268
- package/dist/memory.cjs.map +1 -0
- package/dist/memory.d.cts +21 -0
- package/dist/memory.d.cts.map +1 -0
- package/dist/memory.d.ts +18 -12
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +190 -263
- package/dist/memory.js.map +1 -1
- package/dist/serde/base.d.cts +8 -0
- package/dist/serde/base.d.cts.map +1 -0
- package/dist/serde/base.d.ts +7 -3
- package/dist/serde/base.d.ts.map +1 -0
- package/dist/serde/jsonplus.cjs +90 -141
- package/dist/serde/jsonplus.cjs.map +1 -0
- package/dist/serde/jsonplus.js +89 -136
- package/dist/serde/jsonplus.js.map +1 -1
- package/dist/serde/types.cjs +14 -9
- package/dist/serde/types.cjs.map +1 -0
- package/dist/serde/types.d.cts +52 -0
- package/dist/serde/types.d.cts.map +1 -0
- package/dist/serde/types.d.ts +50 -47
- package/dist/serde/types.d.ts.map +1 -0
- package/dist/serde/types.js +9 -5
- package/dist/serde/types.js.map +1 -1
- package/dist/serde/utils/fast-safe-stringify/index.cjs +87 -208
- package/dist/serde/utils/fast-safe-stringify/index.cjs.map +1 -0
- package/dist/serde/utils/fast-safe-stringify/index.js +87 -205
- package/dist/serde/utils/fast-safe-stringify/index.js.map +1 -1
- package/dist/store/base.cjs +199 -209
- package/dist/store/base.cjs.map +1 -0
- package/dist/store/base.d.cts +391 -0
- package/dist/store/base.d.cts.map +1 -0
- package/dist/store/base.d.ts +335 -332
- package/dist/store/base.d.ts.map +1 -0
- package/dist/store/base.js +198 -204
- package/dist/store/base.js.map +1 -1
- package/dist/store/batch.cjs +114 -147
- package/dist/store/batch.cjs.map +1 -0
- package/dist/store/batch.d.cts +46 -0
- package/dist/store/batch.d.cts.map +1 -0
- package/dist/store/batch.d.ts +45 -40
- package/dist/store/batch.d.ts.map +1 -0
- package/dist/store/batch.js +114 -143
- package/dist/store/batch.js.map +1 -1
- package/dist/store/memory.cjs +256 -363
- package/dist/store/memory.cjs.map +1 -0
- package/dist/store/memory.d.cts +62 -0
- package/dist/store/memory.d.cts.map +1 -0
- package/dist/store/memory.d.ts +28 -24
- package/dist/store/memory.d.ts.map +1 -0
- package/dist/store/memory.js +255 -358
- package/dist/store/memory.js.map +1 -1
- package/dist/store/utils.cjs +137 -249
- package/dist/store/utils.cjs.map +1 -0
- package/dist/store/utils.js +137 -245
- package/dist/store/utils.js.map +1 -1
- package/dist/types.d.cts +35 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +29 -28
- package/dist/types.d.ts.map +1 -0
- package/package.json +33 -34
- package/CHANGELOG.md +0 -19
- package/dist/cache/index.d.ts +0 -2
- package/dist/cache/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/serde/base.cjs +0 -3
- package/dist/serde/base.js +0 -2
- package/dist/serde/base.js.map +0 -1
- package/dist/serde/jsonplus.d.ts +0 -7
- package/dist/serde/utils/fast-safe-stringify/index.d.ts +0 -1
- package/dist/store/index.cjs +0 -20
- package/dist/store/index.d.ts +0 -3
- package/dist/store/index.js +0 -4
- package/dist/store/index.js.map +0 -1
- package/dist/store/utils.d.ts +0 -26
- package/dist/types.cjs +0 -3
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
package/dist/serde/types.d.ts
CHANGED
|
@@ -1,49 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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"}
|
package/dist/serde/types.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
package/dist/serde/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","
|
|
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
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
//#
|
|
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"}
|