devframe 0.5.3 → 0.5.4
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/client/index.mjs +15 -5
- package/package.json +1 -1
package/dist/client/index.mjs
CHANGED
|
@@ -364,28 +364,38 @@ function resolveRecordOutput(record) {
|
|
|
364
364
|
if (record.error) throw reviveDumpError(record.error);
|
|
365
365
|
return record.output;
|
|
366
366
|
}
|
|
367
|
+
function hasMeaningfulArgs(args) {
|
|
368
|
+
return args.some((arg) => arg !== null && arg !== void 0);
|
|
369
|
+
}
|
|
370
|
+
function unwrapEnvelope(raw) {
|
|
371
|
+
if (raw !== null && typeof raw === "object" && "serialization" in raw && "data" in raw) return raw.data;
|
|
372
|
+
return raw;
|
|
373
|
+
}
|
|
367
374
|
function createStaticRpcCaller(manifest, fetchJson) {
|
|
368
375
|
const staticCache = /* @__PURE__ */ new Map();
|
|
369
376
|
const queryRecordCache = /* @__PURE__ */ new Map();
|
|
370
377
|
function reviveIfStructuredClone(value, serialization) {
|
|
371
|
-
if (serialization === "structured-clone") return structuredCloneDeserialize(value);
|
|
378
|
+
if (serialization === "structured-clone" && Array.isArray(value)) return structuredCloneDeserialize(value);
|
|
372
379
|
return value;
|
|
373
380
|
}
|
|
381
|
+
function decode(raw, serialization) {
|
|
382
|
+
return reviveIfStructuredClone(unwrapEnvelope(raw), serialization);
|
|
383
|
+
}
|
|
374
384
|
async function loadStatic(entry) {
|
|
375
|
-
if (!staticCache.has(entry.path)) staticCache.set(entry.path, fetchJson(entry.path).then((raw) =>
|
|
385
|
+
if (!staticCache.has(entry.path)) staticCache.set(entry.path, fetchJson(entry.path).then((raw) => decode(raw, entry.serialization)));
|
|
376
386
|
const data = await staticCache.get(entry.path);
|
|
377
387
|
if (isRecord(data)) return resolveRecordOutput(data);
|
|
378
388
|
return data;
|
|
379
389
|
}
|
|
380
390
|
async function loadQueryRecord(path, serialization) {
|
|
381
|
-
if (!queryRecordCache.has(path)) queryRecordCache.set(path, fetchJson(path).then((raw) =>
|
|
391
|
+
if (!queryRecordCache.has(path)) queryRecordCache.set(path, fetchJson(path).then((raw) => decode(raw, serialization)));
|
|
382
392
|
return await queryRecordCache.get(path);
|
|
383
393
|
}
|
|
384
394
|
async function call(functionName, args) {
|
|
385
395
|
if (!(functionName in manifest)) throw new Error(`[devframe-rpc] Function "${functionName}" not found in dump store`);
|
|
386
396
|
const entry = manifest[functionName];
|
|
387
397
|
if (isStaticEntry(entry)) {
|
|
388
|
-
if (args
|
|
398
|
+
if (hasMeaningfulArgs(args)) throw new Error(`[devframe-rpc] No dump match for "${functionName}" with args: ${JSON.stringify(args)}`);
|
|
389
399
|
return await loadStatic(entry);
|
|
390
400
|
}
|
|
391
401
|
if (isQueryEntry(entry)) {
|
|
@@ -395,7 +405,7 @@ function createStaticRpcCaller(manifest, fetchJson) {
|
|
|
395
405
|
if (entry.fallback) return resolveRecordOutput(await loadQueryRecord(entry.fallback, entry.serialization));
|
|
396
406
|
throw new Error(`[devframe-rpc] No dump match for "${functionName}" with args: ${JSON.stringify(args)}`);
|
|
397
407
|
}
|
|
398
|
-
if (args
|
|
408
|
+
if (!hasMeaningfulArgs(args)) return entry;
|
|
399
409
|
throw new Error(`[devframe-rpc] No dump match for "${functionName}" with args: ${JSON.stringify(args)}`);
|
|
400
410
|
}
|
|
401
411
|
return {
|