rsc-superjson
Version:
A superjson wrapper for React Server Components (RSC) and Next.js
25 lines • 1.26 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import SuperJSON from "superjson";
export function SuperjsonAction(action) {
return (...args) => __awaiter(this, void 0, void 0, function* () {
return serializeWithSuperJSON(() => action(...args));
});
}
export function callSuperjsonAction(superAction) {
return deserializeWithSuperJSON(superAction);
}
function deserializeWithSuperJSON(serverAction) {
return serverAction().then(SuperJSON.deserialize);
}
function serializeWithSuperJSON(serverAction) {
return serverAction().then(SuperJSON.serialize);
}
//# sourceMappingURL=superjson-action.js.map