working rss feed to nostr publish
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
export const deserializerMiddleware = (options, deserializer) => (next, context) => async (args) => {
|
||||
const { response } = await next(args);
|
||||
try {
|
||||
const parsed = await deserializer(response, options);
|
||||
return {
|
||||
response,
|
||||
output: parsed,
|
||||
};
|
||||
}
|
||||
catch (error) {
|
||||
Object.defineProperty(error, "$response", {
|
||||
value: response,
|
||||
});
|
||||
if (!("$metadata" in error)) {
|
||||
const hint = `Deserialization error: to see the raw response, inspect the hidden field {error}.$response on this object.`;
|
||||
error.message += "\n " + hint;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export * from "./deserializerMiddleware";
|
||||
export * from "./serdePlugin";
|
||||
export * from "./serializerMiddleware";
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { deserializerMiddleware } from "./deserializerMiddleware";
|
||||
import { serializerMiddleware } from "./serializerMiddleware";
|
||||
export const deserializerMiddlewareOption = {
|
||||
name: "deserializerMiddleware",
|
||||
step: "deserialize",
|
||||
tags: ["DESERIALIZER"],
|
||||
override: true,
|
||||
};
|
||||
export const serializerMiddlewareOption = {
|
||||
name: "serializerMiddleware",
|
||||
step: "serialize",
|
||||
tags: ["SERIALIZER"],
|
||||
override: true,
|
||||
};
|
||||
export function getSerdePlugin(config, serializer, deserializer) {
|
||||
return {
|
||||
applyToStack: (commandStack) => {
|
||||
commandStack.add(deserializerMiddleware(config, deserializer), deserializerMiddlewareOption);
|
||||
commandStack.add(serializerMiddleware(config, serializer), serializerMiddlewareOption);
|
||||
},
|
||||
};
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
export const serializerMiddleware = (options, serializer) => (next, context) => async (args) => {
|
||||
const endpoint = context.endpointV2?.url && options.urlParser
|
||||
? async () => options.urlParser(context.endpointV2.url)
|
||||
: options.endpoint;
|
||||
if (!endpoint) {
|
||||
throw new Error("No valid endpoint provider available.");
|
||||
}
|
||||
const request = await serializer(args.input, { ...options, endpoint });
|
||||
return next({
|
||||
...args,
|
||||
request,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user