MCPcopy
hub / github.com/QwikDev/qwik / _serializeData

Function _serializeData

packages/qwik/src/core/container/pause.ts:73–140  ·  view source on GitHub ↗
(data: any, pureQRL?: boolean)

Source from the content-addressed store, hash-verified

71
72/** @internal */
73export const _serializeData = async (data: any, pureQRL?: boolean) => {
74 const containerState = createContainerState(null!, null!);
75 const collector = createCollector(containerState);
76 collectValue(data, collector, false);
77
78 // Wait for remaining promises
79 let promises: Promise<any>[];
80 while ((promises = collector.$promises$).length > 0) {
81 collector.$promises$ = [];
82 const results = await Promise.allSettled(promises);
83 for (const result of results) {
84 if (result.status === 'rejected') {
85 console.error(result.reason);
86 }
87 }
88 }
89
90 const objs = Array.from(collector.$objSet$.keys());
91 let count = 0;
92
93 const objToId = new Map<any, string>();
94 for (const obj of objs) {
95 objToId.set(obj, intToStr(count));
96 count++;
97 }
98 if (collector.$noSerialize$.length > 0) {
99 const undefinedID = objToId.get(undefined);
100 assertDefined(undefinedID, 'undefined ID must be defined');
101 for (const obj of collector.$noSerialize$) {
102 objToId.set(obj, undefinedID);
103 }
104 }
105
106 const mustGetObjId = (obj: any): string => {
107 let suffix = '';
108 if (isPromise(obj)) {
109 const promiseValue = getPromiseValue(obj);
110 if (!promiseValue) {
111 throw qError(QError_missingObjectId, obj);
112 }
113 obj = promiseValue.value;
114 if (promiseValue.resolved) {
115 suffix += '~';
116 } else {
117 suffix += '_';
118 }
119 }
120 if (isObject(obj)) {
121 const target = getProxyTarget(obj);
122 if (target) {
123 suffix += '!';
124 obj = target;
125 }
126 }
127 const key = objToId.get(obj);
128 if (key === undefined) {
129 throw qError(QError_missingObjectId, obj);
130 }

Callers 4

stuffFunction · 0.90
closeFunction · 0.90
rpcFunction · 0.90
workerQrlFunction · 0.90

Calls 9

createContainerStateFunction · 0.90
intToStrFunction · 0.90
assertDefinedFunction · 0.90
createCollectorFunction · 0.85
collectValueFunction · 0.85
serializeObjectsFunction · 0.85
mustGetObjIdFunction · 0.85
setMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…