@c9up/echo 0.1.15 → 0.2.0

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.
Files changed (44) hide show
  1. package/dist/CacheManager.d.ts +52 -6
  2. package/dist/CacheManager.d.ts.map +1 -1
  3. package/dist/CacheManager.js +146 -6
  4. package/dist/CacheManager.js.map +1 -1
  5. package/dist/EchoProvider.d.ts +27 -1
  6. package/dist/EchoProvider.d.ts.map +1 -1
  7. package/dist/EchoProvider.js +31 -3
  8. package/dist/EchoProvider.js.map +1 -1
  9. package/dist/StoreManager.d.ts +25 -2
  10. package/dist/StoreManager.d.ts.map +1 -1
  11. package/dist/StoreManager.js +35 -1
  12. package/dist/StoreManager.js.map +1 -1
  13. package/dist/drivers/MemoryDriver.d.ts +1 -1
  14. package/dist/drivers/MemoryDriver.d.ts.map +1 -1
  15. package/dist/drivers/MemoryDriver.js +19 -3
  16. package/dist/drivers/MemoryDriver.js.map +1 -1
  17. package/dist/drivers/RedisDriver.d.ts +1 -1
  18. package/dist/drivers/RedisDriver.d.ts.map +1 -1
  19. package/dist/drivers/RedisDriver.js +5 -2
  20. package/dist/drivers/RedisDriver.js.map +1 -1
  21. package/dist/drivers/TieredDriver.d.ts +45 -3
  22. package/dist/drivers/TieredDriver.d.ts.map +1 -1
  23. package/dist/drivers/TieredDriver.js +77 -10
  24. package/dist/drivers/TieredDriver.js.map +1 -1
  25. package/dist/quasar.d.ts +7 -6
  26. package/dist/quasar.d.ts.map +1 -1
  27. package/dist/quasar.js +96 -68
  28. package/dist/quasar.js.map +1 -1
  29. package/dist/types.d.ts +26 -1
  30. package/dist/types.d.ts.map +1 -1
  31. package/dist/vendor/quasarConnection.d.ts +35 -0
  32. package/dist/vendor/quasarConnection.d.ts.map +1 -0
  33. package/dist/vendor/quasarConnection.js +62 -0
  34. package/dist/vendor/quasarConnection.js.map +1 -0
  35. package/package.json +1 -1
  36. package/src/CacheManager.ts +163 -12
  37. package/src/EchoProvider.ts +32 -3
  38. package/src/StoreManager.ts +52 -3
  39. package/src/drivers/MemoryDriver.ts +16 -3
  40. package/src/drivers/RedisDriver.ts +5 -2
  41. package/src/drivers/TieredDriver.ts +108 -11
  42. package/src/quasar.ts +123 -87
  43. package/src/types.ts +26 -1
  44. package/src/vendor/quasarConnection.ts +129 -0
package/dist/quasar.js CHANGED
@@ -1,70 +1,54 @@
1
1
  /**
2
2
  * Resolving a Redis connection by name, from `@c9up/quasar`.
3
3
  *
4
- * Echo does not depend on quasar: it is an optional peer, and this module
5
- * never imports it statically. The specifier is built at runtime so the
6
- * TypeScript build stays free of it too — a hard type import would make echo
7
- * unbuildable for anyone who caches in memory.
4
+ * Echo does not depend on quasar: it is an optional peer, and neither this
5
+ * module nor the vendored loader it calls imports it statically. The specifier
6
+ * is built at runtime so the TypeScript build stays free of it too.
8
7
  *
9
- * The shape is checked before use rather than asserted, the same way echo
10
- * duck-types its host framework.
8
+ * The loading, the shape check and the messages are the same in every package
9
+ * that offers a Redis-backed option, so they are vendored rather than written
10
+ * again: `src/vendor/quasarConnection.ts`, generated from one source. The bus
11
+ * below is echo's alone and stays here.
11
12
  */
12
- function isConnectionSource(value) {
13
- return (typeof value === "object" &&
14
- value !== null &&
15
- typeof Reflect.get(value, "connection") === "function");
16
- }
17
- function isRedisClient(value) {
18
- if (typeof value !== "object" || value === null)
19
- return false;
20
- // The commands this driver actually issues. A connection missing one would
21
- // fail on the first cache write, far from the cause.
22
- //
23
- // `keys` and `exists` are deliberately NOT required: `RedisClient` declares
24
- // them, but nothing here calls them — `flush()` walks a SCAN cursor because
25
- // it considers KEYS unsafe in production. Demanding `keys` would reject a
26
- // client that omits it on exactly the grounds this driver agrees with.
27
- // `scan` is optional on the interface, and `flush()` reports its absence
28
- // with a precise message of its own.
29
- const required = [
30
- "get",
31
- "set",
32
- "del",
33
- "sadd",
34
- "srem",
35
- "smembers",
36
- "expire",
37
- "ttl",
38
- ];
39
- return required.every((name) => typeof Reflect.get(value, name) === "function");
40
- }
13
+ import { quasarConnection as loadQuasarConnection } from "./vendor/quasarConnection.js";
14
+ /**
15
+ * The commands this driver actually issues.
16
+ *
17
+ * `keys` and `exists` are deliberately absent: `RedisClient` declares them, but
18
+ * nothing here calls them — `flush()` walks a SCAN cursor because it considers
19
+ * KEYS unsafe in production, so demanding `keys` would reject a client that
20
+ * omits it on exactly the grounds this driver agrees with. `scan` is optional
21
+ * on the interface, and `flush()` reports its absence with a message of its
22
+ * own.
23
+ */
24
+ const REQUIRED = [
25
+ "get",
26
+ "set",
27
+ "del",
28
+ "sadd",
29
+ "srem",
30
+ "smembers",
31
+ "expire",
32
+ "ttl",
33
+ ];
41
34
  /**
42
35
  * A resolver for `drivers.redis({ connection })` — quasar is loaded on the
43
36
  * first cache command, not at config time.
44
37
  */
45
38
  export function quasarConnection(name) {
46
- return async () => {
47
- const specifier = "@c9up/quasar/services/main";
48
- let loaded;
49
- try {
50
- loaded = await import(/* @vite-ignore */ specifier);
51
- }
52
- catch (cause) {
53
- throw new Error(`Echo: the "${name ?? "default"}" cache store asks for a quasar connection, but @c9up/quasar is not installed.\n` +
54
- " pnpm add @c9up/quasar", { cause });
55
- }
56
- const manager = isConnectionSource(loaded)
57
- ? loaded
58
- : Reflect.get(Object(loaded), "default");
59
- if (!isConnectionSource(manager)) {
60
- throw new Error("Echo: @c9up/quasar/services/main did not expose a connection() manager");
61
- }
62
- const connection = manager.connection(name);
63
- if (!isRedisClient(connection)) {
64
- throw new Error(`Echo: quasar connection "${name ?? "default"}" does not carry the commands this cache needs`);
65
- }
66
- return connection;
67
- };
39
+ return async () => loadQuasarConnection({
40
+ pkg: "echo",
41
+ name,
42
+ required: REQUIRED,
43
+ what: "the cache store",
44
+ raise: (_reason, message, cause) => new Error(message, { cause }),
45
+ });
46
+ }
47
+ function isConnectionSource(value) {
48
+ return (typeof value === "object" &&
49
+ value !== null &&
50
+ "connection" in value &&
51
+ typeof Reflect.get(value, "connection") === "function");
68
52
  }
69
53
  function isPubSubSource(value) {
70
54
  return (typeof value === "object" &&
@@ -106,6 +90,8 @@ async function loadQuasar(context) {
106
90
  export function quasarBus(options) {
107
91
  const channel = options?.channel ?? "echo::invalidate";
108
92
  let ready;
93
+ /** Per subscriber, the wrapper actually registered — once it has been. */
94
+ const opened = new Map();
109
95
  const manager = () => {
110
96
  ready ??= loadQuasar(`the cache bus asks for the "${options?.connection ?? "default"}" quasar connection`).then((loaded) => {
111
97
  const source = isConnectionSource(loaded)
@@ -123,23 +109,65 @@ export function quasarBus(options) {
123
109
  const source = await manager();
124
110
  await source.publish(channel, JSON.stringify(message));
125
111
  },
126
- subscribe(handler) {
127
- // Not awaited: `subscribe` is synchronous in the bus contract, and the
128
- // socket opens on quasar's own schedule. A failure to reach Redis must
129
- // not take down the store — a bus that is down costs staleness, and
130
- // throwing here would cost every cache read.
131
- void manager()
132
- .then((source) => source.subscribe(channel, (raw) => {
112
+ async subscribe(handler) {
113
+ const wrapper = (raw) => {
133
114
  try {
134
115
  handler(JSON.parse(raw));
135
116
  }
136
117
  catch {
137
118
  /* a malformed frame is not a reason to stop listening */
138
119
  }
139
- }))
140
- .catch(() => {
141
- /* reported by the first publish, which does surface its error */
142
- });
120
+ };
121
+ // AWAITED, and a reported failure becomes a rejection.
122
+ //
123
+ // This used to be fire-and-forget with the rejection swallowed, and
124
+ // quasar catches the Redis error itself and resolves — so the tier
125
+ // believed it was subscribed while no handler was installed. Every
126
+ // instance then served its own stale L1 until the TTL ran out, with
127
+ // nothing anywhere to say the bus was down.
128
+ //
129
+ // The provider awaits this in `ready()`, so an unreachable bus is a
130
+ // failed boot rather than a deployment that looks healthy and is
131
+ // quietly incoherent.
132
+ const attempt = (async () => {
133
+ const source = await manager();
134
+ let reported;
135
+ await source.subscribe(channel, wrapper, {
136
+ onError: (error) => {
137
+ reported = error;
138
+ },
139
+ });
140
+ if (reported !== undefined) {
141
+ opened.delete(handler);
142
+ throw reported instanceof Error
143
+ ? reported
144
+ : new Error(String(reported));
145
+ }
146
+ return wrapper;
147
+ })();
148
+ opened.set(handler, attempt);
149
+ // Forgotten on a direct rejection too, so a retry is not refused by
150
+ // bookkeeping for a subscription that never happened.
151
+ attempt.catch(() => opened.delete(handler));
152
+ await attempt;
153
+ },
154
+ async unsubscribe(handler) {
155
+ // The subscribe may still be opening the socket. Removing ahead of it
156
+ // takes nothing off and leaves the handler to land afterwards, on a
157
+ // bus nobody is tracking any more.
158
+ const pending = opened.get(handler);
159
+ if (pending === undefined)
160
+ return;
161
+ const wrapper = await pending;
162
+ const source = await manager();
163
+ // NAMED. Quasar keeps a `Set` of handlers per channel, so an unnamed
164
+ // unsubscribe drops every listener on a connection the application
165
+ // shares with the cache.
166
+ await source.unsubscribe?.(channel, wrapper);
167
+ // Forgotten LAST. Dropped before the call, a refusal left a live
168
+ // listener nothing could name again — neither to retry it nor to
169
+ // remove it at a second shutdown.
170
+ opened.delete(handler);
143
171
  },
144
172
  };
145
173
  }
@@ -1 +1 @@
1
- {"version":3,"file":"quasar.js","sourceRoot":"","sources":["../src/quasar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAUH,SAAS,kBAAkB,CAAC,KAAc;IACzC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,UAAU,CACtD,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACpC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,2EAA2E;IAC3E,qDAAqD;IACrD,EAAE;IACF,4EAA4E;IAC5E,4EAA4E;IAC5E,0EAA0E;IAC1E,uEAAuE;IACvE,yEAAyE;IACzE,qCAAqC;IACrC,MAAM,QAAQ,GAAG;QAChB,KAAK;QACL,KAAK;QACL,KAAK;QACL,MAAM;QACN,MAAM;QACN,UAAU;QACV,QAAQ;QACR,KAA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,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC7C,iEAAiE;YACjE,iEAAiE;YACjE,kCAAkC;YAClC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;KACD,CAAC;AACH,CAAC"}
package/dist/types.d.ts CHANGED
@@ -49,12 +49,37 @@ export interface CacheDriver {
49
49
  get<T = unknown>(key: string): Promise<T | null>;
50
50
  set(key: string, value: unknown, ttlSeconds?: number): Promise<void>;
51
51
  delete(key: string): Promise<boolean>;
52
- flush(): Promise<void>;
52
+ /**
53
+ * Remove everything — or, when `prefix` is given, only the keys under it.
54
+ *
55
+ * A namespaced view shares this driver, so a `clear()` on one had to be
56
+ * able to say WHICH subtree it meant. Without that it flushed the whole
57
+ * store, and a namespace per tenant is the documented use: one tenant
58
+ * clearing its own cache emptied everyone else's.
59
+ *
60
+ * A driver that cannot scope the removal must REFUSE when a prefix is
61
+ * given. Flushing everything instead is the failure this parameter exists
62
+ * to prevent, and it is silent.
63
+ */
64
+ flush(prefix?: string): Promise<void>;
53
65
  has(key: string): Promise<boolean>;
54
66
  /** Grace-aware read: returns the entry even if stale, or `null` if physically gone. */
55
67
  getEntry?<T = unknown>(key: string): Promise<CacheEntry<T> | null>;
56
68
  /** Grace-aware write. */
57
69
  setEntry?(key: string, value: unknown, options: DriverSetOptions): Promise<void>;
70
+ /**
71
+ * Open whatever this driver needs OUTSIDE the process — a bus subscription,
72
+ * a connection it owns.
73
+ *
74
+ * Separate from the constructor on purpose. Building a store is what
75
+ * publishing the cache service does, and that happens while the application
76
+ * boots, including under `ream inspect` — which never shuts anything down.
77
+ * A driver that opened a socket to exist left one behind every time someone
78
+ * listed the routes. This is called once the application is ready, and its
79
+ * failure is the application's to refuse: a tiered store that never
80
+ * subscribed serves stale L1 copies to everyone until their TTL.
81
+ */
82
+ connect?(): Promise<void>;
58
83
  /**
59
84
  * Drop entries this driver knows to be expired (bentocache `prune`). Only
60
85
  * stores that do not evict on their own need it.
@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;AACD,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,EAAE,CAAC;CACf;AACD,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,MAAM,EAAE,CAAC;CACf;AACD,MAAM,WAAW,UAAU;IAC1B,GAAG,EAAE,MAAM,CAAC;CACZ;AACD,MAAM,WAAW,aAAa;IAC7B,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,uEAAuE;AACvE,MAAM,WAAW,aAAa;IAC7B,WAAW,EAAE;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,OAAO,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,OAAO,CAAC;KAChB,CAAC;IACF,YAAY,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,eAAe,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAChE,eAAe,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,eAAe,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACnC;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC5B;;;;;;;;;;OAUG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;CAC/C"}
@@ -0,0 +1,35 @@
1
+ export interface QuasarConnectionRequest {
2
+ /** The package asking. It prefixes every message this can raise. */
3
+ pkg: string;
4
+ /**
5
+ * How this package builds an error.
6
+ *
7
+ * Not optional, and not `new Error` by default: a package with its own
8
+ * error type carries codes (`E_<PKG>_<REASON>`) that a caller catches on,
9
+ * and a shared helper throwing a bare Error would silently drop them. The
10
+ * two reasons are distinguished so the codes can be too.
11
+ */
12
+ raise: (reason: "quasar-missing" | "incomplete-connection", message: string, cause?: unknown) => Error;
13
+ /** Connection name, or `undefined` for quasar's default. */
14
+ name?: string;
15
+ /** The commands the caller will actually issue. */
16
+ required: readonly string[];
17
+ /** What the caller does with them, for the message that names a gap. */
18
+ what: string;
19
+ /**
20
+ * A second way out, when this package has one.
21
+ *
22
+ * Several of them accept a client object directly, so "pass a client
23
+ * instead of a connection name" is actionable — and it was in each
24
+ * package's own message before this was shared. Dropping it to unify the
25
+ * wording would have made the error strictly less useful.
26
+ */
27
+ alternative?: string;
28
+ }
29
+ /**
30
+ * The named connection, checked for the commands the caller needs BEFORE it is
31
+ * handed over — a connection missing one would otherwise fail on the first
32
+ * command, far from the line that asked for it.
33
+ */
34
+ export declare function quasarConnection<T>(request: QuasarConnectionRequest): Promise<T>;
35
+ //# sourceMappingURL=quasarConnection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quasarConnection.d.ts","sourceRoot":"","sources":["../../src/vendor/quasarConnection.ts"],"names":[],"mappings":"AAiDA,MAAM,WAAW,uBAAuB;IACvC,oEAAoE;IACpE,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;OAOG;IACH,KAAK,EAAE,CACN,MAAM,EAAE,gBAAgB,GAAG,uBAAuB,EAClD,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,KACX,KAAK,CAAC;IACX,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACvC,OAAO,EAAE,uBAAuB,GAC9B,OAAO,CAAC,CAAC,CAAC,CAuCZ"}
@@ -0,0 +1,62 @@
1
+ // Generated from scripts/vendor/quasarConnection.ts — do not edit.
2
+ //
3
+ // This package is published and built from its own repository, so the file
4
+ // has to exist here rather than be imported. `pnpm vendor:sync` rewrites it,
5
+ // and `pnpm vendor:check` fails if this copy has drifted from the original.
6
+ /**
7
+ * Read a member without assuming how the object answers.
8
+ *
9
+ * Two shapes have to work, and they disagree about `in`. Quasar's accessor is
10
+ * a Proxy over an empty null-prototype object with only a `get` trap, so
11
+ * `"connection" in manager` is FALSE while reading it returns the function —
12
+ * gating on `in` rejected the real manager. And a module namespace under a
13
+ * test double RAISES for an export it does not have, rather than answering
14
+ * undefined, so a bare read fails on the mock. Reading through a catch is what
15
+ * satisfies both.
16
+ */
17
+ function readMember(value, name) {
18
+ if (typeof value !== "object" || value === null)
19
+ return undefined;
20
+ try {
21
+ return Reflect.get(value, name);
22
+ }
23
+ catch {
24
+ return undefined;
25
+ }
26
+ }
27
+ function isConnectionSource(value) {
28
+ return typeof readMember(value, "connection") === "function";
29
+ }
30
+ /**
31
+ * The named connection, checked for the commands the caller needs BEFORE it is
32
+ * handed over — a connection missing one would otherwise fail on the first
33
+ * command, far from the line that asked for it.
34
+ */
35
+ export async function quasarConnection(request) {
36
+ const { pkg, name, required, what, raise, alternative } = request;
37
+ const specifier = "@c9up/quasar/services/main";
38
+ let loaded;
39
+ try {
40
+ loaded = await import(/* @vite-ignore */ specifier);
41
+ }
42
+ catch (cause) {
43
+ throw raise("quasar-missing", `[${pkg}] ${what} asks for the quasar connection "${name ?? "default"}", but @c9up/quasar is not installed.\n` +
44
+ ` pnpm add @c9up/quasar${alternative ? `, ${alternative}` : ""}`, cause);
45
+ }
46
+ const manager = isConnectionSource(loaded)
47
+ ? loaded
48
+ : Reflect.get(Object(loaded), "default");
49
+ if (!isConnectionSource(manager)) {
50
+ throw raise("quasar-missing", `[${pkg}] @c9up/quasar/services/main did not expose a connection() manager`);
51
+ }
52
+ const connection = manager.connection(name);
53
+ const missing = required.filter((command) => typeof readMember(connection, command) !== "function");
54
+ if (missing.length > 0) {
55
+ throw raise("incomplete-connection", `[${pkg}] the quasar connection${name ? ` '${name}'` : ""} is missing ${missing.join(", ")}, which ${what} issues`);
56
+ }
57
+ // Load-bearing: every member of `required` has just been checked to be a
58
+ // function on this object. The caller names the type it needs because only
59
+ // the caller knows which commands it asked for.
60
+ return connection;
61
+ }
62
+ //# sourceMappingURL=quasarConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quasarConnection.js","sourceRoot":"","sources":["../../src/vendor/quasarConnection.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,4EAA4E;AAqB5E;;;;;;;;;;GAUG;AACH,SAAS,UAAU,CAAC,KAAc,EAAE,IAAY;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAClE,IAAI,CAAC;QACJ,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc;IACzC,OAAO,OAAO,UAAU,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,UAAU,CAAC;AAC9D,CAAC;AAmCD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,OAAgC;IAEhC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAClE,MAAM,SAAS,GAAG,4BAA4B,CAAC;IAC/C,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACJ,MAAM,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,KAAK,CACV,gBAAgB,EAChB,IAAI,GAAG,KAAK,IAAI,oCAAoC,IAAI,IAAI,SAAS,yCAAyC;YAC7G,0BAA0B,WAAW,CAAC,CAAC,CAAC,KAAK,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAClE,KAAK,CACL,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC;QACzC,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;IAC1C,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,MAAM,KAAK,CACV,gBAAgB,EAChB,IAAI,GAAG,oEAAoE,CAC3E,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAC9B,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,UAAU,CAAC,UAAU,EAAE,OAAO,CAAC,KAAK,UAAU,CAClE,CAAC;IACF,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,KAAK,CACV,uBAAuB,EACvB,IAAI,GAAG,0BAA0B,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,eAAe,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,SAAS,CAClH,CAAC;IACH,CAAC;IACD,yEAAyE;IACzE,2EAA2E;IAC3E,gDAAgD;IAChD,OAAO,UAAe,CAAC;AACxB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c9up/echo",
3
- "version": "0.1.15",
3
+ "version": "0.2.0",
4
4
  "description": "Cache — pluggable cache contract with memory + Redis drivers for the Ream framework",
5
5
  "license": "MIT",
6
6
  "type": "module",