@declaro/redis 2.0.0-y.0 → 2.1.1
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/browser/index.js +4 -0
- package/dist/browser/index.js.map +20 -0
- package/dist/node/index.cjs +493 -0
- package/dist/node/index.cjs.map +20 -0
- package/dist/node/index.js +458 -0
- package/dist/node/index.js.map +20 -0
- package/dist/{index.d.ts → ts/index.d.ts} +1 -0
- package/dist/ts/index.d.ts.map +1 -0
- package/dist/ts/placeholder.test.d.ts +2 -0
- package/dist/ts/placeholder.test.d.ts.map +1 -0
- package/dist/{redis → ts/redis}/index.d.ts +1 -0
- package/dist/ts/redis/index.d.ts.map +1 -0
- package/dist/{redis → ts/redis}/publish.d.ts +2 -1
- package/dist/ts/redis/publish.d.ts.map +1 -0
- package/dist/{redis → ts/redis}/queue.d.ts +1 -0
- package/dist/ts/redis/queue.d.ts.map +1 -0
- package/dist/{redis → ts/redis}/redis-event-adapter.d.ts +1 -0
- package/dist/ts/redis/redis-event-adapter.d.ts.map +1 -0
- package/dist/ts/redis/redis-event-adapter.test.d.ts +2 -0
- package/dist/ts/redis/redis-event-adapter.test.d.ts.map +1 -0
- package/dist/{redis → ts/redis}/redis-middleware.d.ts +7 -1
- package/dist/ts/redis/redis-middleware.d.ts.map +1 -0
- package/dist/{redis → ts/redis}/repository.d.ts +3 -2
- package/dist/ts/redis/repository.d.ts.map +1 -0
- package/dist/{redis → ts/redis}/storage.d.ts +2 -1
- package/dist/ts/redis/storage.d.ts.map +1 -0
- package/dist/{redis → ts/redis}/utils.d.ts +3 -2
- package/dist/ts/redis/utils.d.ts.map +1 -0
- package/dist/{settings → ts/settings}/index.d.ts +1 -0
- package/dist/ts/settings/index.d.ts.map +1 -0
- package/dist/{settings → ts/settings}/setting.d.ts +4 -3
- package/dist/ts/settings/setting.d.ts.map +1 -0
- package/dist/{settings → ts/settings}/site.d.ts +1 -0
- package/dist/ts/settings/site.d.ts.map +1 -0
- package/dist/{test-utils → ts/test-utils}/index.d.ts +1 -0
- package/dist/ts/test-utils/index.d.ts.map +1 -0
- package/package.json +28 -11
- package/src/redis/queue.ts +4 -3
- package/src/redis/redis-middleware.ts +11 -5
- package/src/redis/repository.ts +9 -3
- package/src/redis/utils.ts +5 -2
- package/src/settings/setting.ts +1 -1
- package/dist/pkg.cjs +0 -29
- package/dist/pkg.mjs +0 -55679
- package/tsconfig.json +0 -8
- package/vite.config.ts +0 -31
- /package/{LICENSE → LICENSE.md} +0 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var A=Object.create;var{getPrototypeOf:I,defineProperty:W,getOwnPropertyNames:M}=Object;var U=Object.prototype.hasOwnProperty;function O(f){return this[f]}var x,y,b=(f,T,E)=>{var S=f!=null&&typeof f==="object";if(S){var C=T?x??=new WeakMap:y??=new WeakMap,G=C.get(f);if(G)return G}E=f!=null?A(I(f)):{};let V=T||!f||!f.__esModule?W(E,"default",{value:f,enumerable:!0}):E;for(let K of M(f))if(!U.call(V,K))W(V,K,{get:O.bind(f,K),enumerable:!0});if(S)C.set(f,V);return V};var p=(f,T)=>()=>(T||f((T={exports:{}}).exports,T),T.exports);var d=p((pf,L)=>{var l=function(T){return g(T)&&!s(T)};function g(f){return!!f&&typeof f==="object"}function s(f){var T=Object.prototype.toString.call(f);return T==="[object RegExp]"||T==="[object Date]"||o(f)}var a=typeof Symbol==="function"&&Symbol.for,t=a?Symbol.for("react.element"):60103;function o(f){return f.$$typeof===t}function c(f){return Array.isArray(f)?[]:{}}function J(f,T){return T.clone!==!1&&T.isMergeableObject(f)?R(c(f),f,T):f}function n(f,T,E){return f.concat(T).map(function(S){return J(S,E)})}function e(f,T){if(!T.customMerge)return R;var E=T.customMerge(f);return typeof E==="function"?E:R}function ff(f){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(f).filter(function(T){return Object.propertyIsEnumerable.call(f,T)}):[]}function q(f){return Object.keys(f).concat(ff(f))}function F(f,T){try{return T in f}catch(E){return!1}}function Tf(f,T){return F(f,T)&&!(Object.hasOwnProperty.call(f,T)&&Object.propertyIsEnumerable.call(f,T))}function Ef(f,T,E){var S={};if(E.isMergeableObject(f))q(f).forEach(function(C){S[C]=J(f[C],E)});return q(T).forEach(function(C){if(Tf(f,C))return;if(F(f,C)&&E.isMergeableObject(T[C]))S[C]=e(C,E)(f[C],T[C],E);else S[C]=J(T[C],E)}),S}function R(f,T,E){E=E||{},E.arrayMerge=E.arrayMerge||n,E.isMergeableObject=E.isMergeableObject||l,E.cloneUnlessOtherwiseSpecified=J;var S=Array.isArray(T),C=Array.isArray(f),G=S===C;if(!G)return J(T,E);else if(S)return E.arrayMerge(f,T,E);else return Ef(f,T,E)}R.all=function(T,E){if(!Array.isArray(T))throw Error("first argument should be an array");return T.reduce(function(S,C){return R(S,C,E)},{})};var Sf=R;L.exports=Sf});import{App as N}from"@declaro/core";import X from"ioredis";function z(f){return JSON.stringify(f)}function w(f){if(!f)return null;return JSON.parse(f)}var v;((E)=>{E.SET="SET";E.GET="GET"})(v||={});class B{redis;handlers={["GET"]:[],["SET"]:[]};constructor(f){this.redis=f}async set(f,T){let E=z(T),S=await this.redis.set(f,E);return await Promise.all(this.handlers.SET.map((C)=>C("SET",f,T))),S}async get(f){let T=await this.redis.get(f);if(!T)return null;let E=w(T);if(E)await Promise.all(this.handlers.GET.map((S)=>S("GET",f,E)));return E}on(f,T){return this.handlers[f].push(T),()=>{this.handlers[f]=this.handlers[f].filter((E)=>E!=T)}}onSet(f){return this.on("SET",f)}onGet(f){return this.on("GET",f)}}var H={Connect:"redis:connect",Destroy:"redis:destroy"},D=Symbol(),Y=Symbol(),Z=Symbol(),i=Symbol(),Df=(f)=>async(T)=>{T.provide(i,f),T.on(N.Events.Init,async(E)=>{let S=new X(f);E.provide(D,S),await E.emit(H.Connect)}),T.on(N.Events.Destroy,async(E)=>{let S=P(E);await E.emit(H.Destroy)}),T.on(H.Destroy,async(E)=>{await P(E).quit()})};function P(f){let T=f.inject(D);if(!T)throw Error("No Redis connection was found. Did you forget to provide one with `redisMiddleware`?");return T}function k(f){return f.inject(i)}function m(f){let T=k(f),E=new X(T);return f.on(N.Events.Destroy,async()=>{await E.quit()}),E}function mf(f){let T=P(f);return new B(T)}async function h(f,T,E){let S=P(f),C=Array.isArray(T)?T:[T],G=JSON.stringify(E);return await Promise.all(C.map((V)=>S.lpush(V,G)))}async function _f(f,T,E){let S=m(f),C=!0;while(C){let G=await S.brpop(T,1000),[V,K]=G??[];try{let $=w(K??"");await E($??void 0)}catch($){h(f,T,K)}}return()=>C=!1}async function Wf(f,T,E){let S=JSON.stringify(E);return await P(f).publish(T,S)}function Xf(f,T,E){let S=m(f),C=Array.isArray(T)?T:[T];return S.psubscribe(...C),S.on("pmessage",(G,V,K)=>{let $=JSON.parse(K);E($)}),S}async function Ff(f,T,E){let S=P(f),C=z(E);return await S.set(T,C)}async function Lf(f,T){let S=await P(f).get(T);return w(S)}class u{eventManager;publisher;subscriber;constructor(f,T,E){this.eventManager=f;this.publisher=T;this.subscriber=E;f.on("*",async(S)=>{try{if(S.__fromRedis)return;let C=JSON.stringify(S);await T.publish(S.type,C)}catch(C){console.error("Unserializable event:",S),console.error(`There was an error serializing event ${S.type}`,C)}}),E.psubscribe("*"),E.on("pmessage",this.onMessage)}onMessage=(f,T,E)=>{try{let S=JSON.parse(E);if(S.__fromRedis=!0,typeof S.type!=="string")throw Error(`Event payload for ${T} does not have a type property, and cannot be processed`);this.eventManager.emit(S)}catch(S){console.error("Unparsable event:",E),console.error(`There was an error deserializing event ${T}`,S)}};unsubscribe(){this.publisher.unsubscribe(),this.subscriber.unsubscribe()}}var _=b(d(),1);var j="DeclaroSettings",kf="DeclaroSettingsNamespaces";class Cf{namespace;defaultValue;constructor(f,T){this.namespace=f;this.defaultValue=T}get namespaceKey(){return`${j}:${this.namespace}`}async get(f){let E=await P(f).get(this.namespaceKey);if(!E)return this.defaultValue;return JSON.parse(E)}async set(f,T){let E=P(f),S=await this.get(f),C=_.default.all([this.defaultValue??{},S??{},T]),G=JSON.stringify(C);await E.set(this.namespaceKey,G)}}class r{namespace;defaultValues;constructor(f,T){this.namespace=f;this.defaultValues=T}get namespaceKey(){return`${j}:${this.namespace}`}async set(f,T,E={}){let S=P(f),C=await this.get(f,T),G=_.default.all([this.defaultValues,C??{},E]),V=JSON.stringify(G);await S.hset(this.namespaceKey,{[T]:V})}async getAll(f){let E=await P(f).hgetall(this.namespaceKey);return Object.keys(E).reduce((C,G)=>{let V=E[G],K=V?JSON.parse(V):this.defaultValues;return{...C,[G]:K}},{})}async get(f,T){let S=await P(f).hget(this.namespaceKey,T);if(!S)return this.defaultValues;return JSON.parse(S)}}var lf=new r("Site",{domain:process.env.APP_DOMAIN??"http://localhost:8080",email:process.env.APP_EMAIL??"admin@declaro.io"});import Q from"ioredis-mock";var nf=()=>async(f)=>{let T=new Q,E=new Q,S=new Q;f.provide(D,S),f.provide(Y,T),f.provide(Z,E),f.provide(i,void 0)};export{mf as useRedisRepository,k as useRedisOptions,P as useRedis,w as unserialize,lf as siteConfig,Ff as set,z as serialize,Wf as sendMessage,Df as redisMiddleware,h as pushMessage,Xf as onMessage,_f as onFulfillMessage,nf as mockRedisMiddleware,Lf as get,m as createRedis,kf as SETTINGS_NAMESPACES,j as SETTINGS_KEY,v as RedisRepositoryEvent,B as RedisRepository,H as RedisEvents,u as RedisEventAdapter,Z as REDIS_SUB_KEY,Y as REDIS_PUB_KEY,i as REDIS_OPTIONS_KEY,D as REDIS_CLIENT_KEY,r as ConfigSet,Cf as Config};
|
|
2
|
+
|
|
3
|
+
//# debugId=9341080E6CE2BEC764756E2164756E21
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../node_modules/deepmerge/dist/cjs.js", "../../src/redis/redis-middleware.ts", "../../src/redis/utils.ts", "../../src/redis/repository.ts", "../../src/redis/queue.ts", "../../src/redis/publish.ts", "../../src/redis/storage.ts", "../../src/redis/redis-event-adapter.ts", "../../src/settings/setting.ts", "../../src/settings/site.ts", "../../src/test-utils/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"'use strict';\n\nvar isMergeableObject = function isMergeableObject(value) {\n\treturn isNonNullObject(value)\n\t\t&& !isSpecial(value)\n};\n\nfunction isNonNullObject(value) {\n\treturn !!value && typeof value === 'object'\n}\n\nfunction isSpecial(value) {\n\tvar stringValue = Object.prototype.toString.call(value);\n\n\treturn stringValue === '[object RegExp]'\n\t\t|| stringValue === '[object Date]'\n\t\t|| isReactElement(value)\n}\n\n// see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25\nvar canUseSymbol = typeof Symbol === 'function' && Symbol.for;\nvar REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7;\n\nfunction isReactElement(value) {\n\treturn value.$$typeof === REACT_ELEMENT_TYPE\n}\n\nfunction emptyTarget(val) {\n\treturn Array.isArray(val) ? [] : {}\n}\n\nfunction cloneUnlessOtherwiseSpecified(value, options) {\n\treturn (options.clone !== false && options.isMergeableObject(value))\n\t\t? deepmerge(emptyTarget(value), value, options)\n\t\t: value\n}\n\nfunction defaultArrayMerge(target, source, options) {\n\treturn target.concat(source).map(function(element) {\n\t\treturn cloneUnlessOtherwiseSpecified(element, options)\n\t})\n}\n\nfunction getMergeFunction(key, options) {\n\tif (!options.customMerge) {\n\t\treturn deepmerge\n\t}\n\tvar customMerge = options.customMerge(key);\n\treturn typeof customMerge === 'function' ? customMerge : deepmerge\n}\n\nfunction getEnumerableOwnPropertySymbols(target) {\n\treturn Object.getOwnPropertySymbols\n\t\t? Object.getOwnPropertySymbols(target).filter(function(symbol) {\n\t\t\treturn Object.propertyIsEnumerable.call(target, symbol)\n\t\t})\n\t\t: []\n}\n\nfunction getKeys(target) {\n\treturn Object.keys(target).concat(getEnumerableOwnPropertySymbols(target))\n}\n\nfunction propertyIsOnObject(object, property) {\n\ttry {\n\t\treturn property in object\n\t} catch(_) {\n\t\treturn false\n\t}\n}\n\n// Protects from prototype poisoning and unexpected merging up the prototype chain.\nfunction propertyIsUnsafe(target, key) {\n\treturn propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet,\n\t\t&& !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain,\n\t\t\t&& Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable.\n}\n\nfunction mergeObject(target, source, options) {\n\tvar destination = {};\n\tif (options.isMergeableObject(target)) {\n\t\tgetKeys(target).forEach(function(key) {\n\t\t\tdestination[key] = cloneUnlessOtherwiseSpecified(target[key], options);\n\t\t});\n\t}\n\tgetKeys(source).forEach(function(key) {\n\t\tif (propertyIsUnsafe(target, key)) {\n\t\t\treturn\n\t\t}\n\n\t\tif (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) {\n\t\t\tdestination[key] = getMergeFunction(key, options)(target[key], source[key], options);\n\t\t} else {\n\t\t\tdestination[key] = cloneUnlessOtherwiseSpecified(source[key], options);\n\t\t}\n\t});\n\treturn destination\n}\n\nfunction deepmerge(target, source, options) {\n\toptions = options || {};\n\toptions.arrayMerge = options.arrayMerge || defaultArrayMerge;\n\toptions.isMergeableObject = options.isMergeableObject || isMergeableObject;\n\t// cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge()\n\t// implementations can use it. The caller may not replace it.\n\toptions.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified;\n\n\tvar sourceIsArray = Array.isArray(source);\n\tvar targetIsArray = Array.isArray(target);\n\tvar sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;\n\n\tif (!sourceAndTargetTypesMatch) {\n\t\treturn cloneUnlessOtherwiseSpecified(source, options)\n\t} else if (sourceIsArray) {\n\t\treturn options.arrayMerge(target, source, options)\n\t} else {\n\t\treturn mergeObject(target, source, options)\n\t}\n}\n\ndeepmerge.all = function deepmergeAll(array, options) {\n\tif (!Array.isArray(array)) {\n\t\tthrow new Error('first argument should be an array')\n\t}\n\n\treturn array.reduce(function(prev, next) {\n\t\treturn deepmerge(prev, next, options)\n\t}, {})\n};\n\nvar deepmerge_1 = deepmerge;\n\nmodule.exports = deepmerge_1;\n",
|
|
6
|
+
"import { Context, App } from '@declaro/core'\nimport Redis, { Redis as RedisInstance, type RedisOptions } from 'ioredis'\nimport { RedisRepository } from './repository'\n\nexport const RedisEvents = {\n Connect: 'redis:connect',\n Destroy: 'redis:destroy',\n}\n\nexport const REDIS_CLIENT_KEY = Symbol()\nexport const REDIS_PUB_KEY = Symbol()\nexport const REDIS_SUB_KEY = Symbol()\nexport const REDIS_OPTIONS_KEY = Symbol()\n\n/**\n * @deprecated Use context's DI system instead\n * @param options The options to pass to the Redis client\n * @returns\n */\nexport const redisMiddleware = (options: RedisOptions) => async (context: Context) => {\n context.provide(REDIS_OPTIONS_KEY, options)\n\n context.on(App.Events.Init, async (context) => {\n const redis = new Redis(options)\n\n context.provide(REDIS_CLIENT_KEY, redis)\n await context.emit(RedisEvents.Connect)\n })\n\n context.on(App.Events.Destroy, async (context) => {\n const redis = useRedis(context)\n await context.emit(RedisEvents.Destroy)\n })\n\n context.on(RedisEvents.Destroy, async (context) => {\n const redis = useRedis(context)\n await redis.quit()\n })\n}\n\n/**\n * Get the centralized redis connection\n * NOTE: Do not use this connection to subscribe to events. Create your own instead with createRedis.\n * @param context\n * @returns\n */\nexport function useRedis(context: Context): RedisInstance {\n const conn = context.inject<RedisInstance>(REDIS_CLIENT_KEY)\n\n if (!conn) {\n throw new Error('No Redis connection was found. Did you forget to provide one with `redisMiddleware`?')\n }\n\n return conn\n}\n\n/**\n * Get the redis options that were provided\n *\n * @param context\n * @returns The redis options that were provided in the given context\n */\nexport function useRedisOptions(context: Context): RedisOptions {\n const options = context.inject<RedisOptions>(REDIS_OPTIONS_KEY)\n\n return options!\n}\n\n/**\n * Create a Redis connection\n *\n * @param context The context in which to create the Redis instance\n */\nexport function createRedis(context: Context): RedisInstance {\n const options = useRedisOptions(context)\n\n const conn = new Redis(options)\n\n context.on(App.Events.Destroy, async () => {\n await conn.quit()\n })\n\n return conn\n}\n\nexport function useRedisRepository<T = string>(context: Context): RedisRepository<T> {\n const conn = useRedis(context)\n\n const repository = new RedisRepository<T>(conn)\n\n return repository\n}\n",
|
|
7
|
+
"/**\n * Serialize a payload into a JSON string\n * @param message A payload to serialize\n * @returns A JSON serialized string\n */\nexport function serialize<T = string>(message: T) {\n return JSON.stringify(message)\n}\n\n/**\n * Extract a payload from a serialized string.\n * @param message A JSON string to unserialize\n * @returns\n */\nexport function unserialize<T = string>(message?: string | null): T | null | undefined {\n if (!message) {\n return null as any\n }\n return JSON.parse(message)\n}\n\nexport type MessageHandler<T = string> = (message?: T) => any\n",
|
|
8
|
+
"import type { Redis } from 'ioredis'\nimport { serialize, unserialize } from './utils'\n\nexport enum RedisRepositoryEvent {\n SET = 'SET',\n GET = 'GET',\n}\n\nexport type RepositoryEventHandler<T> = (event: RedisRepositoryEvent, id: string, item: T) => any\n\nexport class RedisRepository<T> {\n private readonly handlers = {\n [RedisRepositoryEvent.GET]: [] as RepositoryEventHandler<T>[],\n [RedisRepositoryEvent.SET]: [] as RepositoryEventHandler<T>[],\n }\n\n constructor(protected readonly redis: Redis) {}\n\n async set(id: string, item: T): Promise<'OK'> {\n const payload = serialize(item)\n\n const result = await this.redis.set(id, payload)\n\n await Promise.all(this.handlers.SET.map((handler) => handler(RedisRepositoryEvent.SET, id, item)))\n\n return result\n }\n\n async get(id: string): Promise<T | null | undefined> {\n const payload = await this.redis.get(id)\n\n if (!payload) {\n return null\n }\n\n const item = unserialize<T>(payload)\n\n if (item) {\n await Promise.all(this.handlers.GET.map((handler) => handler(RedisRepositoryEvent.GET, id, item)))\n }\n\n return item\n }\n\n on(event: RedisRepositoryEvent, handler: RepositoryEventHandler<T>) {\n this.handlers[event].push(handler)\n\n return () => {\n this.handlers[event] = this.handlers[event].filter((item) => item != handler)\n }\n }\n\n onSet(handler: RepositoryEventHandler<T>) {\n return this.on(RedisRepositoryEvent.SET, handler)\n }\n\n onGet(handler: RepositoryEventHandler<T>) {\n return this.on(RedisRepositoryEvent.GET, handler)\n }\n}\n",
|
|
9
|
+
"import { Context } from '@declaro/core'\nimport { createRedis, useRedis } from './redis-middleware'\nimport { type MessageHandler, unserialize } from './utils'\n\n/**\n * Push a message to a queue to be resolved by only one client.\n * NOTE: This uses LPUSH under the hood, not PUBLISH. For PUBLISH functionality, use `sendMessage`\n *\n * @param context\n * @param channel The channel to send the message on\n * @param payload The payload to send\n * @returns\n */\nexport async function pushMessage<T = string>(context: Context, channel: string | string[], payload: T) {\n const conn = useRedis(context)\n const channels = Array.isArray(channel) ? channel : [channel]\n\n const message = JSON.stringify(payload)\n\n return await Promise.all(channels.map((channel) => conn.lpush(channel, message)))\n}\n\n/**\n * Fulfills messages pushed to a list (LPUSH), and pops them from the list to ensure they are only processed once.\n * NOTE: If the handler fails, the message will be pushed back to the queue and an error message will be logged.\n *\n * @param context\n * @param channel The channel to receive messages on\n */\nexport async function onFulfillMessage<T>(context: Context, channel: string, handler: MessageHandler<T>) {\n const conn = createRedis(context)\n\n let shouldContinue = true\n\n while (shouldContinue) {\n const result = await conn.brpop(channel, 1000)\n const [msgChannel, message] = result ?? []\n\n try {\n const payload = unserialize<T>(message ?? '')\n await handler(payload ?? undefined)\n } catch (e) {\n pushMessage(context, channel, message)\n }\n }\n\n return () => (shouldContinue = false)\n}\n",
|
|
10
|
+
"import { Context } from '@declaro/core'\nimport { createRedis, useRedis } from './redis-middleware'\nimport { type MessageHandler } from './utils'\n/**\n * Send a message to a channel in Redis\n *\n * @param context Application context from which to inject dependencies\n * @param channel The channel on which to publish the event\n * @param message The payload to send (could be a string or JSON-serialized object)\n * @returns The number of subscribers that received the message\n */\nexport async function sendMessage<T = string>(context: Context, channel: string, message: T): Promise<number> {\n const payload = JSON.stringify(message)\n const conn = useRedis(context)\n\n const result = await conn.publish(channel, payload)\n\n return result\n}\n\n/**\n * Subscribe to messages on a channel\n * NOTE: Creates a dedicated Redis connection\n *\n * @param context\n * @param channel The channel to subscribe to\n * @param messageHandler A function to run whenever messages are received\n * @returns A dedicated connection to handle the subscription on. NOTE: Close this connection to unsubscribe.\n */\nexport function onMessage<T = string>(context: Context, channel: string | string[], messageHandler: MessageHandler<T>) {\n const conn = createRedis(context)\n const channels = Array.isArray(channel) ? channel : [channel]\n\n conn.psubscribe(...channels)\n\n conn.on('pmessage', (pattern, msgChannel, message) => {\n const payload: T = JSON.parse(message)\n\n messageHandler(payload)\n })\n\n return conn\n}\n",
|
|
11
|
+
"import { serialize, unserialize } from './utils'\nimport { useRedis } from './redis-middleware'\nimport { Context } from '@declaro/core'\n\nexport async function set<T>(context: Context, id: string, item: T) {\n const conn = useRedis(context)\n\n const payload = serialize(item)\n\n return await conn.set(id, payload)\n}\n\nexport async function get<T>(context: Context, id: string) {\n const conn = useRedis(context)\n\n const payload = await conn.get(id)\n\n const item = unserialize<T>(payload)\n\n return item\n}\n",
|
|
12
|
+
"import type { EventManager, IEvent } from '@declaro/core'\nimport type Redis from 'ioredis'\n\nexport class RedisEventAdapter {\n constructor(\n protected readonly eventManager: EventManager,\n protected readonly publisher: Redis,\n protected readonly subscriber: Redis,\n ) {\n eventManager.on('*', async (event) => {\n try {\n if ((event as any).__fromRedis) {\n // Ignore events that are coming from Redis to avoid circular calls\n return\n }\n\n const payload = JSON.stringify(event)\n await publisher.publish(event.type, payload)\n } catch (e) {\n console.error('Unserializable event:', event)\n console.error(`There was an error serializing event ${event.type}`, e)\n }\n })\n\n subscriber.psubscribe('*')\n\n subscriber.on('pmessage', this.onMessage)\n }\n\n protected onMessage = (pattern: string, channel: string, message: string) => {\n try {\n const event = JSON.parse(message) as IEvent\n ;(event as any).__fromRedis = true\n\n if (typeof event.type !== 'string') {\n throw new Error(`Event payload for ${channel} does not have a type property, and cannot be processed`)\n }\n\n this.eventManager.emit(event)\n } catch (e) {\n console.error('Unparsable event:', message)\n console.error(`There was an error deserializing event ${channel}`, e)\n }\n }\n\n unsubscribe() {\n this.publisher.unsubscribe()\n this.subscriber.unsubscribe()\n }\n}\n",
|
|
13
|
+
"import { Context } from '@declaro/core'\nimport merge from 'deepmerge'\nimport { useRedis } from '../redis'\n\nexport const SETTINGS_KEY = 'DeclaroSettings'\nexport const SETTINGS_NAMESPACES = 'DeclaroSettingsNamespaces'\n\nexport class Config<T = any> {\n constructor(public readonly namespace: string, public readonly defaultValue?: T) {}\n\n private get namespaceKey() {\n return `${SETTINGS_KEY}:${this.namespace}`\n }\n\n async get(context: Context) {\n const redis = useRedis(context)\n\n const body = await redis.get(this.namespaceKey)\n\n if (!body) {\n return this.defaultValue\n }\n return JSON.parse(body) as T\n }\n\n async set(context: Context, value: Partial<T>) {\n const redis = useRedis(context)\n\n const existingValues = await this.get(context)\n const merged = merge.all([this.defaultValue ?? {}, existingValues ?? {}, value])\n const body = JSON.stringify(merged)\n await redis.set(this.namespaceKey, body)\n }\n}\n\nexport class ConfigSet<T extends object> {\n constructor(public readonly namespace: string, public readonly defaultValues: T) {}\n\n private get namespaceKey() {\n return `${SETTINGS_KEY}:${this.namespace}`\n }\n\n async set(context: Context, key: string, values: Partial<T> = {}) {\n const redis = useRedis(context)\n\n const existingValues = await this.get(context, key)\n const mergedValues = merge.all([this.defaultValues, existingValues ?? {}, values])\n\n const serializedValues = JSON.stringify(mergedValues)\n\n await redis.hset(this.namespaceKey, {\n [key]: serializedValues,\n })\n }\n\n async getAll(context: Context) {\n const redis = useRedis(context)\n\n const results = await redis.hgetall(this.namespaceKey)\n const settings = Object.keys(results).reduce((map, key) => {\n const serialized = results[key]\n const value = serialized ? JSON.parse(serialized) : this.defaultValues\n\n return {\n ...map,\n [key]: value,\n }\n }, {} as { [key: string]: T })\n\n return settings\n }\n\n async get(context: Context, key: string): Promise<T> {\n const redis = useRedis(context)\n\n const body = await redis.hget(this.namespaceKey, key)\n\n if (!body) {\n return this.defaultValues\n }\n return JSON.parse(body) as T\n }\n}\n",
|
|
14
|
+
"import { ConfigSet } from './setting'\n\nexport const siteConfig = new ConfigSet('Site', {\n domain: process.env.APP_DOMAIN ?? 'http://localhost:8080',\n email: process.env.APP_EMAIL ?? 'admin@declaro.io',\n})\n",
|
|
15
|
+
"import { Context } from '@declaro/core'\nimport Redis from 'ioredis-mock'\nimport { REDIS_CLIENT_KEY, REDIS_OPTIONS_KEY, REDIS_PUB_KEY, REDIS_SUB_KEY } from '../redis'\n\n// TODO: move this to core\nexport const mockRedisMiddleware = () => async (context: Context) => {\n const pub = new Redis()\n const sub = new Redis()\n const redis = new Redis()\n\n context.provide(REDIS_CLIENT_KEY, redis)\n context.provide(REDIS_PUB_KEY, pub)\n context.provide(REDIS_SUB_KEY, sub)\n context.provide(REDIS_OPTIONS_KEY, undefined)\n}\n"
|
|
16
|
+
],
|
|
17
|
+
"mappings": "oiBAEA,IAAI,EAAoB,QAA0B,CAAC,EAAO,CACzD,OAAO,EAAgB,CAAK,GACxB,CAAC,EAAU,CAAK,GAGrB,SAAS,CAAe,CAAC,EAAO,CAC/B,MAAO,CAAC,CAAC,GAAS,OAAO,IAAU,SAGpC,SAAS,CAAS,CAAC,EAAO,CACzB,IAAI,EAAc,OAAO,UAAU,SAAS,KAAK,CAAK,EAEtD,OAAO,IAAgB,mBACnB,IAAgB,iBAChB,EAAe,CAAK,EAIzB,IAAI,EAAe,OAAO,SAAW,YAAc,OAAO,IACtD,EAAqB,EAAe,OAAO,IAAI,eAAe,EAAI,MAEtE,SAAS,CAAc,CAAC,EAAO,CAC9B,OAAO,EAAM,WAAa,EAG3B,SAAS,CAAW,CAAC,EAAK,CACzB,OAAO,MAAM,QAAQ,CAAG,EAAI,CAAC,EAAI,CAAC,EAGnC,SAAS,CAA6B,CAAC,EAAO,EAAS,CACtD,OAAQ,EAAQ,QAAU,IAAS,EAAQ,kBAAkB,CAAK,EAC/D,EAAU,EAAY,CAAK,EAAG,EAAO,CAA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EAAE,OAAO,CAAC,EAAK,IAAQ,CACvD,IAAM,EAAa,EAAQ,GACrB,EAAQ,EAAa,KAAK,MAAM,CAAU,EAAI,KAAK,cAEzD,MAAO,IACA,GACF,GAAM,CACX,GACD,CAAC,CAAyB,OAK3B,IAAG,CAAC,EAAkB,EAAyB,CAGjD,IAAM,EAAO,MAFC,EAAS,CAAO,EAEL,KAAK,KAAK,aAAc,CAAG,EAEpD,GAAI,CAAC,EACD,OAAO,KAAK,cAEhB,OAAO,KAAK,MAAM,CAAI,EAE9B,CChFO,IAAM,GAAa,IAAI,EAAU,OAAQ,CAC5C,OAAQ,QAAQ,IAAI,YAAc,wBAClC,MAAO,QAAQ,IAAI,WAAa,kBACpC,CAAC,ECJD,4BAIO,IAAM,GAAsB,IAAM,MAAO,IAAqB,CACjE,IAAM,EAAM,IAAI,EACV,EAAM,IAAI,EACV,EAAQ,IAAI,EAElB,EAAQ,QAAQ,EAAkB,CAAK,EACvC,EAAQ,QAAQ,EAAe,CAAG,EAClC,EAAQ,QAAQ,EAAe,CAAG,EAClC,EAAQ,QAAQ,EAAmB,MAAS",
|
|
18
|
+
"debugId": "9341080E6CE2BEC764756E2164756E21",
|
|
19
|
+
"names": []
|
|
20
|
+
}
|
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
for (let key of __getOwnPropNames(mod))
|
|
23
|
+
if (!__hasOwnProp.call(to, key))
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
26
|
+
enumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toCommonJS = (from) => {
|
|
33
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
34
|
+
if (entry)
|
|
35
|
+
return entry;
|
|
36
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
37
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
38
|
+
for (var key of __getOwnPropNames(from))
|
|
39
|
+
if (!__hasOwnProp.call(entry, key))
|
|
40
|
+
__defProp(entry, key, {
|
|
41
|
+
get: __accessProp.bind(from, key),
|
|
42
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
__moduleCache.set(from, entry);
|
|
46
|
+
return entry;
|
|
47
|
+
};
|
|
48
|
+
var __moduleCache;
|
|
49
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
50
|
+
var __returnValue = (v) => v;
|
|
51
|
+
function __exportSetter(name, newValue) {
|
|
52
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
53
|
+
}
|
|
54
|
+
var __export = (target, all) => {
|
|
55
|
+
for (var name in all)
|
|
56
|
+
__defProp(target, name, {
|
|
57
|
+
get: all[name],
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
set: __exportSetter.bind(all, name)
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// ../../node_modules/deepmerge/dist/cjs.js
|
|
65
|
+
var require_cjs = __commonJS((exports2, module2) => {
|
|
66
|
+
var isMergeableObject = function isMergeableObject2(value) {
|
|
67
|
+
return isNonNullObject(value) && !isSpecial(value);
|
|
68
|
+
};
|
|
69
|
+
function isNonNullObject(value) {
|
|
70
|
+
return !!value && typeof value === "object";
|
|
71
|
+
}
|
|
72
|
+
function isSpecial(value) {
|
|
73
|
+
var stringValue = Object.prototype.toString.call(value);
|
|
74
|
+
return stringValue === "[object RegExp]" || stringValue === "[object Date]" || isReactElement(value);
|
|
75
|
+
}
|
|
76
|
+
var canUseSymbol = typeof Symbol === "function" && Symbol.for;
|
|
77
|
+
var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for("react.element") : 60103;
|
|
78
|
+
function isReactElement(value) {
|
|
79
|
+
return value.$$typeof === REACT_ELEMENT_TYPE;
|
|
80
|
+
}
|
|
81
|
+
function emptyTarget(val) {
|
|
82
|
+
return Array.isArray(val) ? [] : {};
|
|
83
|
+
}
|
|
84
|
+
function cloneUnlessOtherwiseSpecified(value, options) {
|
|
85
|
+
return options.clone !== false && options.isMergeableObject(value) ? deepmerge(emptyTarget(value), value, options) : value;
|
|
86
|
+
}
|
|
87
|
+
function defaultArrayMerge(target, source, options) {
|
|
88
|
+
return target.concat(source).map(function(element) {
|
|
89
|
+
return cloneUnlessOtherwiseSpecified(element, options);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function getMergeFunction(key, options) {
|
|
93
|
+
if (!options.customMerge) {
|
|
94
|
+
return deepmerge;
|
|
95
|
+
}
|
|
96
|
+
var customMerge = options.customMerge(key);
|
|
97
|
+
return typeof customMerge === "function" ? customMerge : deepmerge;
|
|
98
|
+
}
|
|
99
|
+
function getEnumerableOwnPropertySymbols(target) {
|
|
100
|
+
return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(target).filter(function(symbol) {
|
|
101
|
+
return Object.propertyIsEnumerable.call(target, symbol);
|
|
102
|
+
}) : [];
|
|
103
|
+
}
|
|
104
|
+
function getKeys(target) {
|
|
105
|
+
return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target));
|
|
106
|
+
}
|
|
107
|
+
function propertyIsOnObject(object, property) {
|
|
108
|
+
try {
|
|
109
|
+
return property in object;
|
|
110
|
+
} catch (_) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function propertyIsUnsafe(target, key) {
|
|
115
|
+
return propertyIsOnObject(target, key) && !(Object.hasOwnProperty.call(target, key) && Object.propertyIsEnumerable.call(target, key));
|
|
116
|
+
}
|
|
117
|
+
function mergeObject(target, source, options) {
|
|
118
|
+
var destination = {};
|
|
119
|
+
if (options.isMergeableObject(target)) {
|
|
120
|
+
getKeys(target).forEach(function(key) {
|
|
121
|
+
destination[key] = cloneUnlessOtherwiseSpecified(target[key], options);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
getKeys(source).forEach(function(key) {
|
|
125
|
+
if (propertyIsUnsafe(target, key)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) {
|
|
129
|
+
destination[key] = getMergeFunction(key, options)(target[key], source[key], options);
|
|
130
|
+
} else {
|
|
131
|
+
destination[key] = cloneUnlessOtherwiseSpecified(source[key], options);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
return destination;
|
|
135
|
+
}
|
|
136
|
+
function deepmerge(target, source, options) {
|
|
137
|
+
options = options || {};
|
|
138
|
+
options.arrayMerge = options.arrayMerge || defaultArrayMerge;
|
|
139
|
+
options.isMergeableObject = options.isMergeableObject || isMergeableObject;
|
|
140
|
+
options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified;
|
|
141
|
+
var sourceIsArray = Array.isArray(source);
|
|
142
|
+
var targetIsArray = Array.isArray(target);
|
|
143
|
+
var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;
|
|
144
|
+
if (!sourceAndTargetTypesMatch) {
|
|
145
|
+
return cloneUnlessOtherwiseSpecified(source, options);
|
|
146
|
+
} else if (sourceIsArray) {
|
|
147
|
+
return options.arrayMerge(target, source, options);
|
|
148
|
+
} else {
|
|
149
|
+
return mergeObject(target, source, options);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
deepmerge.all = function deepmergeAll(array, options) {
|
|
153
|
+
if (!Array.isArray(array)) {
|
|
154
|
+
throw new Error("first argument should be an array");
|
|
155
|
+
}
|
|
156
|
+
return array.reduce(function(prev, next) {
|
|
157
|
+
return deepmerge(prev, next, options);
|
|
158
|
+
}, {});
|
|
159
|
+
};
|
|
160
|
+
var deepmerge_1 = deepmerge;
|
|
161
|
+
module2.exports = deepmerge_1;
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// src/index.ts
|
|
165
|
+
var exports_src = {};
|
|
166
|
+
__export(exports_src, {
|
|
167
|
+
useRedisRepository: () => useRedisRepository,
|
|
168
|
+
useRedisOptions: () => useRedisOptions,
|
|
169
|
+
useRedis: () => useRedis,
|
|
170
|
+
unserialize: () => unserialize,
|
|
171
|
+
siteConfig: () => siteConfig,
|
|
172
|
+
set: () => set,
|
|
173
|
+
serialize: () => serialize,
|
|
174
|
+
sendMessage: () => sendMessage,
|
|
175
|
+
redisMiddleware: () => redisMiddleware,
|
|
176
|
+
pushMessage: () => pushMessage,
|
|
177
|
+
onMessage: () => onMessage,
|
|
178
|
+
onFulfillMessage: () => onFulfillMessage,
|
|
179
|
+
mockRedisMiddleware: () => mockRedisMiddleware,
|
|
180
|
+
get: () => get,
|
|
181
|
+
createRedis: () => createRedis,
|
|
182
|
+
SETTINGS_NAMESPACES: () => SETTINGS_NAMESPACES,
|
|
183
|
+
SETTINGS_KEY: () => SETTINGS_KEY,
|
|
184
|
+
RedisRepositoryEvent: () => RedisRepositoryEvent,
|
|
185
|
+
RedisRepository: () => RedisRepository,
|
|
186
|
+
RedisEvents: () => RedisEvents,
|
|
187
|
+
RedisEventAdapter: () => RedisEventAdapter,
|
|
188
|
+
REDIS_SUB_KEY: () => REDIS_SUB_KEY,
|
|
189
|
+
REDIS_PUB_KEY: () => REDIS_PUB_KEY,
|
|
190
|
+
REDIS_OPTIONS_KEY: () => REDIS_OPTIONS_KEY,
|
|
191
|
+
REDIS_CLIENT_KEY: () => REDIS_CLIENT_KEY,
|
|
192
|
+
ConfigSet: () => ConfigSet,
|
|
193
|
+
Config: () => Config
|
|
194
|
+
});
|
|
195
|
+
module.exports = __toCommonJS(exports_src);
|
|
196
|
+
|
|
197
|
+
// src/redis/redis-middleware.ts
|
|
198
|
+
var import_core = require("@declaro/core");
|
|
199
|
+
var import_ioredis = __toESM(require("ioredis"));
|
|
200
|
+
|
|
201
|
+
// src/redis/utils.ts
|
|
202
|
+
function serialize(message) {
|
|
203
|
+
return JSON.stringify(message);
|
|
204
|
+
}
|
|
205
|
+
function unserialize(message) {
|
|
206
|
+
if (!message) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
return JSON.parse(message);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/redis/repository.ts
|
|
213
|
+
var RedisRepositoryEvent;
|
|
214
|
+
((RedisRepositoryEvent2) => {
|
|
215
|
+
RedisRepositoryEvent2["SET"] = "SET";
|
|
216
|
+
RedisRepositoryEvent2["GET"] = "GET";
|
|
217
|
+
})(RedisRepositoryEvent ||= {});
|
|
218
|
+
|
|
219
|
+
class RedisRepository {
|
|
220
|
+
redis;
|
|
221
|
+
handlers = {
|
|
222
|
+
["GET" /* GET */]: [],
|
|
223
|
+
["SET" /* SET */]: []
|
|
224
|
+
};
|
|
225
|
+
constructor(redis) {
|
|
226
|
+
this.redis = redis;
|
|
227
|
+
}
|
|
228
|
+
async set(id, item) {
|
|
229
|
+
const payload = serialize(item);
|
|
230
|
+
const result = await this.redis.set(id, payload);
|
|
231
|
+
await Promise.all(this.handlers.SET.map((handler) => handler("SET" /* SET */, id, item)));
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
async get(id) {
|
|
235
|
+
const payload = await this.redis.get(id);
|
|
236
|
+
if (!payload) {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
const item = unserialize(payload);
|
|
240
|
+
if (item) {
|
|
241
|
+
await Promise.all(this.handlers.GET.map((handler) => handler("GET" /* GET */, id, item)));
|
|
242
|
+
}
|
|
243
|
+
return item;
|
|
244
|
+
}
|
|
245
|
+
on(event, handler) {
|
|
246
|
+
this.handlers[event].push(handler);
|
|
247
|
+
return () => {
|
|
248
|
+
this.handlers[event] = this.handlers[event].filter((item) => item != handler);
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
onSet(handler) {
|
|
252
|
+
return this.on("SET" /* SET */, handler);
|
|
253
|
+
}
|
|
254
|
+
onGet(handler) {
|
|
255
|
+
return this.on("GET" /* GET */, handler);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/redis/redis-middleware.ts
|
|
260
|
+
var RedisEvents = {
|
|
261
|
+
Connect: "redis:connect",
|
|
262
|
+
Destroy: "redis:destroy"
|
|
263
|
+
};
|
|
264
|
+
var REDIS_CLIENT_KEY = Symbol();
|
|
265
|
+
var REDIS_PUB_KEY = Symbol();
|
|
266
|
+
var REDIS_SUB_KEY = Symbol();
|
|
267
|
+
var REDIS_OPTIONS_KEY = Symbol();
|
|
268
|
+
var redisMiddleware = (options) => async (context) => {
|
|
269
|
+
context.provide(REDIS_OPTIONS_KEY, options);
|
|
270
|
+
context.on(import_core.App.Events.Init, async (context2) => {
|
|
271
|
+
const redis = new import_ioredis.default(options);
|
|
272
|
+
context2.provide(REDIS_CLIENT_KEY, redis);
|
|
273
|
+
await context2.emit(RedisEvents.Connect);
|
|
274
|
+
});
|
|
275
|
+
context.on(import_core.App.Events.Destroy, async (context2) => {
|
|
276
|
+
const redis = useRedis(context2);
|
|
277
|
+
await context2.emit(RedisEvents.Destroy);
|
|
278
|
+
});
|
|
279
|
+
context.on(RedisEvents.Destroy, async (context2) => {
|
|
280
|
+
const redis = useRedis(context2);
|
|
281
|
+
await redis.quit();
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
function useRedis(context) {
|
|
285
|
+
const conn = context.inject(REDIS_CLIENT_KEY);
|
|
286
|
+
if (!conn) {
|
|
287
|
+
throw new Error("No Redis connection was found. Did you forget to provide one with `redisMiddleware`?");
|
|
288
|
+
}
|
|
289
|
+
return conn;
|
|
290
|
+
}
|
|
291
|
+
function useRedisOptions(context) {
|
|
292
|
+
const options = context.inject(REDIS_OPTIONS_KEY);
|
|
293
|
+
return options;
|
|
294
|
+
}
|
|
295
|
+
function createRedis(context) {
|
|
296
|
+
const options = useRedisOptions(context);
|
|
297
|
+
const conn = new import_ioredis.default(options);
|
|
298
|
+
context.on(import_core.App.Events.Destroy, async () => {
|
|
299
|
+
await conn.quit();
|
|
300
|
+
});
|
|
301
|
+
return conn;
|
|
302
|
+
}
|
|
303
|
+
function useRedisRepository(context) {
|
|
304
|
+
const conn = useRedis(context);
|
|
305
|
+
const repository = new RedisRepository(conn);
|
|
306
|
+
return repository;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/redis/queue.ts
|
|
310
|
+
async function pushMessage(context, channel, payload) {
|
|
311
|
+
const conn = useRedis(context);
|
|
312
|
+
const channels = Array.isArray(channel) ? channel : [channel];
|
|
313
|
+
const message = JSON.stringify(payload);
|
|
314
|
+
return await Promise.all(channels.map((channel2) => conn.lpush(channel2, message)));
|
|
315
|
+
}
|
|
316
|
+
async function onFulfillMessage(context, channel, handler) {
|
|
317
|
+
const conn = createRedis(context);
|
|
318
|
+
let shouldContinue = true;
|
|
319
|
+
while (shouldContinue) {
|
|
320
|
+
const result = await conn.brpop(channel, 1000);
|
|
321
|
+
const [msgChannel, message] = result ?? [];
|
|
322
|
+
try {
|
|
323
|
+
const payload = unserialize(message ?? "");
|
|
324
|
+
await handler(payload ?? undefined);
|
|
325
|
+
} catch (e) {
|
|
326
|
+
pushMessage(context, channel, message);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return () => shouldContinue = false;
|
|
330
|
+
}
|
|
331
|
+
// src/redis/publish.ts
|
|
332
|
+
async function sendMessage(context, channel, message) {
|
|
333
|
+
const payload = JSON.stringify(message);
|
|
334
|
+
const conn = useRedis(context);
|
|
335
|
+
const result = await conn.publish(channel, payload);
|
|
336
|
+
return result;
|
|
337
|
+
}
|
|
338
|
+
function onMessage(context, channel, messageHandler) {
|
|
339
|
+
const conn = createRedis(context);
|
|
340
|
+
const channels = Array.isArray(channel) ? channel : [channel];
|
|
341
|
+
conn.psubscribe(...channels);
|
|
342
|
+
conn.on("pmessage", (pattern, msgChannel, message) => {
|
|
343
|
+
const payload = JSON.parse(message);
|
|
344
|
+
messageHandler(payload);
|
|
345
|
+
});
|
|
346
|
+
return conn;
|
|
347
|
+
}
|
|
348
|
+
// src/redis/storage.ts
|
|
349
|
+
async function set(context, id, item) {
|
|
350
|
+
const conn = useRedis(context);
|
|
351
|
+
const payload = serialize(item);
|
|
352
|
+
return await conn.set(id, payload);
|
|
353
|
+
}
|
|
354
|
+
async function get(context, id) {
|
|
355
|
+
const conn = useRedis(context);
|
|
356
|
+
const payload = await conn.get(id);
|
|
357
|
+
const item = unserialize(payload);
|
|
358
|
+
return item;
|
|
359
|
+
}
|
|
360
|
+
// src/redis/redis-event-adapter.ts
|
|
361
|
+
class RedisEventAdapter {
|
|
362
|
+
eventManager;
|
|
363
|
+
publisher;
|
|
364
|
+
subscriber;
|
|
365
|
+
constructor(eventManager, publisher, subscriber) {
|
|
366
|
+
this.eventManager = eventManager;
|
|
367
|
+
this.publisher = publisher;
|
|
368
|
+
this.subscriber = subscriber;
|
|
369
|
+
eventManager.on("*", async (event) => {
|
|
370
|
+
try {
|
|
371
|
+
if (event.__fromRedis) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const payload = JSON.stringify(event);
|
|
375
|
+
await publisher.publish(event.type, payload);
|
|
376
|
+
} catch (e) {
|
|
377
|
+
console.error("Unserializable event:", event);
|
|
378
|
+
console.error(`There was an error serializing event ${event.type}`, e);
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
subscriber.psubscribe("*");
|
|
382
|
+
subscriber.on("pmessage", this.onMessage);
|
|
383
|
+
}
|
|
384
|
+
onMessage = (pattern, channel, message) => {
|
|
385
|
+
try {
|
|
386
|
+
const event = JSON.parse(message);
|
|
387
|
+
event.__fromRedis = true;
|
|
388
|
+
if (typeof event.type !== "string") {
|
|
389
|
+
throw new Error(`Event payload for ${channel} does not have a type property, and cannot be processed`);
|
|
390
|
+
}
|
|
391
|
+
this.eventManager.emit(event);
|
|
392
|
+
} catch (e) {
|
|
393
|
+
console.error("Unparsable event:", message);
|
|
394
|
+
console.error(`There was an error deserializing event ${channel}`, e);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
unsubscribe() {
|
|
398
|
+
this.publisher.unsubscribe();
|
|
399
|
+
this.subscriber.unsubscribe();
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
// src/settings/setting.ts
|
|
403
|
+
var import_deepmerge = __toESM(require_cjs(), 1);
|
|
404
|
+
var SETTINGS_KEY = "DeclaroSettings";
|
|
405
|
+
var SETTINGS_NAMESPACES = "DeclaroSettingsNamespaces";
|
|
406
|
+
|
|
407
|
+
class Config {
|
|
408
|
+
namespace;
|
|
409
|
+
defaultValue;
|
|
410
|
+
constructor(namespace, defaultValue) {
|
|
411
|
+
this.namespace = namespace;
|
|
412
|
+
this.defaultValue = defaultValue;
|
|
413
|
+
}
|
|
414
|
+
get namespaceKey() {
|
|
415
|
+
return `${SETTINGS_KEY}:${this.namespace}`;
|
|
416
|
+
}
|
|
417
|
+
async get(context) {
|
|
418
|
+
const redis = useRedis(context);
|
|
419
|
+
const body = await redis.get(this.namespaceKey);
|
|
420
|
+
if (!body) {
|
|
421
|
+
return this.defaultValue;
|
|
422
|
+
}
|
|
423
|
+
return JSON.parse(body);
|
|
424
|
+
}
|
|
425
|
+
async set(context, value) {
|
|
426
|
+
const redis = useRedis(context);
|
|
427
|
+
const existingValues = await this.get(context);
|
|
428
|
+
const merged = import_deepmerge.default.all([this.defaultValue ?? {}, existingValues ?? {}, value]);
|
|
429
|
+
const body = JSON.stringify(merged);
|
|
430
|
+
await redis.set(this.namespaceKey, body);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
class ConfigSet {
|
|
435
|
+
namespace;
|
|
436
|
+
defaultValues;
|
|
437
|
+
constructor(namespace, defaultValues) {
|
|
438
|
+
this.namespace = namespace;
|
|
439
|
+
this.defaultValues = defaultValues;
|
|
440
|
+
}
|
|
441
|
+
get namespaceKey() {
|
|
442
|
+
return `${SETTINGS_KEY}:${this.namespace}`;
|
|
443
|
+
}
|
|
444
|
+
async set(context, key, values = {}) {
|
|
445
|
+
const redis = useRedis(context);
|
|
446
|
+
const existingValues = await this.get(context, key);
|
|
447
|
+
const mergedValues = import_deepmerge.default.all([this.defaultValues, existingValues ?? {}, values]);
|
|
448
|
+
const serializedValues = JSON.stringify(mergedValues);
|
|
449
|
+
await redis.hset(this.namespaceKey, {
|
|
450
|
+
[key]: serializedValues
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
async getAll(context) {
|
|
454
|
+
const redis = useRedis(context);
|
|
455
|
+
const results = await redis.hgetall(this.namespaceKey);
|
|
456
|
+
const settings = Object.keys(results).reduce((map, key) => {
|
|
457
|
+
const serialized = results[key];
|
|
458
|
+
const value = serialized ? JSON.parse(serialized) : this.defaultValues;
|
|
459
|
+
return {
|
|
460
|
+
...map,
|
|
461
|
+
[key]: value
|
|
462
|
+
};
|
|
463
|
+
}, {});
|
|
464
|
+
return settings;
|
|
465
|
+
}
|
|
466
|
+
async get(context, key) {
|
|
467
|
+
const redis = useRedis(context);
|
|
468
|
+
const body = await redis.hget(this.namespaceKey, key);
|
|
469
|
+
if (!body) {
|
|
470
|
+
return this.defaultValues;
|
|
471
|
+
}
|
|
472
|
+
return JSON.parse(body);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
// src/settings/site.ts
|
|
476
|
+
var siteConfig = new ConfigSet("Site", {
|
|
477
|
+
domain: process.env.APP_DOMAIN ?? "http://localhost:8080",
|
|
478
|
+
email: process.env.APP_EMAIL ?? "admin@declaro.io"
|
|
479
|
+
});
|
|
480
|
+
// src/test-utils/index.ts
|
|
481
|
+
var import_ioredis_mock = __toESM(require("ioredis-mock"));
|
|
482
|
+
var mockRedisMiddleware = () => async (context) => {
|
|
483
|
+
const pub = new import_ioredis_mock.default;
|
|
484
|
+
const sub = new import_ioredis_mock.default;
|
|
485
|
+
const redis = new import_ioredis_mock.default;
|
|
486
|
+
context.provide(REDIS_CLIENT_KEY, redis);
|
|
487
|
+
context.provide(REDIS_PUB_KEY, pub);
|
|
488
|
+
context.provide(REDIS_SUB_KEY, sub);
|
|
489
|
+
context.provide(REDIS_OPTIONS_KEY, undefined);
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
//# debugId=EEFD63C020918BCC64756E2164756E21
|
|
493
|
+
//# sourceMappingURL=index.cjs.map
|