(data: any, pureQRL?: boolean)
| 71 | |
| 72 | /** @internal */ |
| 73 | export 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 | } |
no test coverage detected
searching dependent graphs…