@healthzkit/memcached 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alasti Company
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,105 @@
1
- # Temporary Holding Version
1
+ # @healthzkit/memcached
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Memcached health adapters for [healthzkit](https://github.com/alasti-company/healthzkit.dev). Checks return `ok` with `metadata.latencyMs`, or `fail` with an `Error`.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install healthzkit @healthzkit/memcached
9
+ # Install the client you use:
10
+ npm install memcached
11
+ # or:
12
+ npm install memjs
13
+ ```
14
+
15
+ The package is ESM-only and requires Node.js 22.12+. The clients are optional peers. TypeScript projects should also install `@types/memcached` or `@types/memjs` for their chosen client.
16
+
17
+ ## Quick start
18
+
19
+ ```ts
20
+ import { createHealthKit } from "healthzkit";
21
+ import { memcachedAdapter } from "@healthzkit/memcached/memcached";
22
+
23
+ const kit = createHealthKit({
24
+ checks: [
25
+ {
26
+ name: "memcached",
27
+ type: ["readiness"],
28
+ adapter: memcachedAdapter({ servers: "localhost:11211" }),
29
+ },
30
+ ],
31
+ });
32
+ ```
33
+
34
+ Use a subpath import to load only the client you install. Both factories are also exported from `@healthzkit/memcached`; client libraries load lazily when you use the `servers` option.
35
+
36
+ | Client | Import | Factory | Check |
37
+ | -------------------------------------------------- | --------------------------------- | ------------------ | ------------------------------------------------------------------- |
38
+ | [memcached](https://github.com/3rd-Eden/memcached) | `@healthzkit/memcached/memcached` | `memcachedAdapter` | Read-only `VERSION` across the client's server list |
39
+ | [memjs](https://github.com/memcachier/memjs) | `@healthzkit/memcached/memjs` | `memjsAdapter` | Read-only `GET` of a probe key on the server selected by the client |
40
+
41
+ ## memcached
42
+
43
+ ```ts
44
+ import Memcached from "memcached";
45
+ import { memcachedAdapter } from "@healthzkit/memcached/memcached";
46
+
47
+ // Create and reuse an internal client.
48
+ memcachedAdapter({
49
+ servers: ["localhost:11211", "localhost:11212"],
50
+ options: { timeout: 1000, retries: 1 },
51
+ });
52
+
53
+ // Reuse your application's client.
54
+ const client = new Memcached("localhost:11211");
55
+ memcachedAdapter({ client });
56
+ ```
57
+
58
+ `servers` accepts a `host:port` string, an array of locations, or an object mapping locations to weights. The adapter requires non-empty locations. `options` forwards the client's constructor options, with `retries: 1` by default. Its `timeout` is in milliseconds.
59
+
60
+ The adapter fails on any reported server error or an empty version response. This client uses the ASCII protocol and does not support SASL authentication.
61
+
62
+ ## memjs
63
+
64
+ ```ts
65
+ import { Client } from "memjs";
66
+ import { memjsAdapter } from "@healthzkit/memcached/memjs";
67
+
68
+ memjsAdapter({
69
+ servers: "localhost:11211,localhost:11212",
70
+ options: { timeout: 0.5, username: "user", password: "password" },
71
+ key: "healthzkit:healthcheck",
72
+ });
73
+
74
+ const client = Client.create("localhost:11211");
75
+ memjsAdapter({ client });
76
+ ```
77
+
78
+ `servers` is a non-empty comma-separated string in memjs format: `[user:pass@]host[:port]`. `options` forwards client and server options, with `retries: 1` by default. Its `timeout` and `conntimeout` are in seconds.
79
+
80
+ `key` defaults to `healthzkit:healthcheck`. It must be 1–250 UTF-8 bytes without whitespace or NUL. A missing key is healthy: the server responded successfully. The adapter never writes, deletes, or requires a pre-existing key. It checks the server chosen for that key, so it does not verify every cluster member. Client failover settings also affect which server responds.
81
+
82
+ ## Metadata and client ownership
83
+
84
+ Both adapters accept a synchronous or asynchronous metadata hook:
85
+
86
+ ```ts
87
+ memcachedAdapter({
88
+ servers: "localhost:11211",
89
+ metadata: () => ({ region: "us-west" }),
90
+ });
91
+ ```
92
+
93
+ The hook receives the resolved client after the check succeeds. Its fields merge into the result; measured `latencyMs` takes precedence. Hook errors fail the check.
94
+
95
+ Use either `client` or `servers` with optional `options`. Internally created clients are lazy and reused, including across concurrent checks. Adapters keep clients open between checks and do not close supplied clients. If you need explicit shutdown control, supply your own client and call `client.end()` for memcached or `client.close()` for memjs when your application stops.
96
+
97
+ Use [Scheduling](https://healthzkit.dev/guide/scheduling) to cache readiness results when you want to avoid checking the cache on every HTTP request.
98
+
99
+ ## Development
100
+
101
+ ```bash
102
+ vp test
103
+ vp check
104
+ vp run build
105
+ ```
@@ -0,0 +1,3 @@
1
+ import { MemcachedAdapterOptions, MemcachedAdapterOptionsWithClient, MemcachedAdapterOptionsWithServers, memcachedAdapter } from "./memcached.mjs";
2
+ import { MemjsAdapterOptions, MemjsAdapterOptionsWithClient, MemjsAdapterOptionsWithServers, memjsAdapter } from "./memjs.mjs";
3
+ export { type MemcachedAdapterOptions, type MemcachedAdapterOptionsWithClient, type MemcachedAdapterOptionsWithServers, type MemjsAdapterOptions, type MemjsAdapterOptionsWithClient, type MemjsAdapterOptionsWithServers, memcachedAdapter, memjsAdapter };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{memcachedAdapter as e}from"./memcached.mjs";import{memjsAdapter as t}from"./memjs.mjs";export{e as memcachedAdapter,t as memjsAdapter};
@@ -0,0 +1,21 @@
1
+ import { HealthAdapter, MetadataFn } from "@healthzkit/shared";
2
+ import Memcached from "memcached";
3
+ //#region src/memcached.d.ts
4
+ interface BaseMemcachedOptions {
5
+ metadata?: MetadataFn<Memcached>;
6
+ }
7
+ interface MemcachedAdapterOptionsWithClient extends BaseMemcachedOptions {
8
+ client: Memcached;
9
+ servers?: never;
10
+ options?: never;
11
+ }
12
+ interface MemcachedAdapterOptionsWithServers extends BaseMemcachedOptions {
13
+ servers: string | string[] | Record<string, number>;
14
+ options?: Memcached.options;
15
+ client?: never;
16
+ }
17
+ type MemcachedAdapterOptions = MemcachedAdapterOptionsWithClient | MemcachedAdapterOptionsWithServers;
18
+ /** Check every configured server using the read-only VERSION command. */
19
+ declare function memcachedAdapter(options: MemcachedAdapterOptions): HealthAdapter;
20
+ //#endregion
21
+ export { MemcachedAdapterOptions, MemcachedAdapterOptionsWithClient, MemcachedAdapterOptionsWithServers, memcachedAdapter };
@@ -0,0 +1 @@
1
+ import{buildErrorResult as e,buildResult as t}from"@healthzkit/shared";function n(n){let r;async function i(){if(n.client!==void 0)return n.client;let e=n.servers,t=typeof e==`string`?[e]:Array.isArray(e)?e:Object.keys(e??{});if(t.length===0||t.some(e=>!e.trim()))throw Error(`memcachedAdapter: provide non-empty servers or a client`);return r??=import(`memcached`).then(({default:t})=>new t(e,{retries:1,...n.options})).catch(e=>{throw r=void 0,e}),r}return{async check(){try{let e=await i(),r=Date.now();await new Promise((t,n)=>{e.version((e,r)=>{(Array.isArray(e)?e.length>0:e)?n(e):!Array.isArray(r)||r.length===0||r.some(e=>!e||!e.version)?n(Error(`memcachedAdapter: no version returned by a server`)):t()})});let a=Date.now()-r;return t(a,await n.metadata?.(e))}catch(t){return e(t)}}}}export{n as memcachedAdapter};
@@ -0,0 +1,24 @@
1
+ import { HealthAdapter, MetadataFn } from "@healthzkit/shared";
2
+ import { Client, ClientOptions, ServerOptions } from "memjs";
3
+ //#region src/memjs.d.ts
4
+ interface BaseMemjsOptions {
5
+ /** Key to read. A cache miss is healthy. Defaults to "healthzkit:healthcheck". */
6
+ key?: string;
7
+ metadata?: MetadataFn<Client>;
8
+ }
9
+ interface MemjsAdapterOptionsWithClient extends BaseMemjsOptions {
10
+ client: Client;
11
+ servers?: never;
12
+ options?: never;
13
+ }
14
+ interface MemjsAdapterOptionsWithServers extends BaseMemjsOptions {
15
+ /** Comma-separated servers in memjs format, optionally including credentials. */
16
+ servers: string;
17
+ options?: ClientOptions & ServerOptions;
18
+ client?: never;
19
+ }
20
+ type MemjsAdapterOptions = MemjsAdapterOptionsWithClient | MemjsAdapterOptionsWithServers;
21
+ /** Read a key from the server selected by memjs without writing to the cache. */
22
+ declare function memjsAdapter(options: MemjsAdapterOptions): HealthAdapter;
23
+ //#endregion
24
+ export { MemjsAdapterOptions, MemjsAdapterOptionsWithClient, MemjsAdapterOptionsWithServers, memjsAdapter };
package/dist/memjs.mjs ADDED
@@ -0,0 +1 @@
1
+ import{buildErrorResult as e,buildResult as t}from"@healthzkit/shared";function n(n){let r;async function i(){if(n.client!==void 0)return n.client;if(!n.servers?.trim()||n.servers.split(`,`).some(e=>!e.trim()))throw Error(`memjsAdapter: provide non-empty servers or a client`);return r??=import(`memjs`).then(({Client:e})=>e.create(n.servers,{retries:1,...n.options})).catch(e=>{throw r=void 0,e}),r}return{async check(){try{let e=n.key??`healthzkit:healthcheck`;if(!e||/\s/.test(e)||e.includes(`\0`)||Buffer.byteLength(e)>250)throw Error(`memjsAdapter: key must be 1–250 bytes without whitespace or NUL`);let r=await i(),a=Date.now();await r.get(e);let o=Date.now()-a;return t(o,await n.metadata?.(r))}catch(t){return e(t)}}}}export{n as memjsAdapter};
package/package.json CHANGED
@@ -1,6 +1,79 @@
1
1
  {
2
2
  "name": "@healthzkit/memcached",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Memcached health-check adapters for healthzkit (memcached and memjs).",
5
+ "keywords": [
6
+ "health-check",
7
+ "healthcheck",
8
+ "healthzkit",
9
+ "kubernetes",
10
+ "liveness",
11
+ "memcached",
12
+ "memjs",
13
+ "probe",
14
+ "readiness"
15
+ ],
16
+ "homepage": "https://healthzkit.dev",
17
+ "bugs": {
18
+ "url": "https://github.com/alasti-company/healthzkit.dev/issues"
19
+ },
20
+ "license": "MIT",
21
+ "author": {
22
+ "name": "Alasti Company",
23
+ "url": "https://healthzkit.dev"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/alasti-company/healthzkit.dev",
28
+ "directory": "packages/memcached"
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "type": "module",
34
+ "exports": {
35
+ ".": "./dist/index.mjs",
36
+ "./memcached": "./dist/memcached.mjs",
37
+ "./memjs": "./dist/memjs.mjs",
38
+ "./package.json": "./package.json"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "dependencies": {
44
+ "@healthzkit/shared": "0.0.2"
45
+ },
46
+ "devDependencies": {
47
+ "@types/memcached": "^2.2.10",
48
+ "@types/memjs": "^1.3.3",
49
+ "@types/node": "^24",
50
+ "@typescript/native-preview": "7.0.0-dev.20260707.2",
51
+ "bumpp": "^12.3.0",
52
+ "healthzkit": "0.1.1",
53
+ "memcached": "^2.2.2",
54
+ "memjs": "^1.3.2",
55
+ "typescript": "^5",
56
+ "vite-plus": "0.3.0"
57
+ },
58
+ "peerDependencies": {
59
+ "memcached": ">=2.2.2",
60
+ "memjs": ">=1.3.2"
61
+ },
62
+ "peerDependenciesMeta": {
63
+ "memcached": {
64
+ "optional": true
65
+ },
66
+ "memjs": {
67
+ "optional": true
68
+ }
69
+ },
70
+ "engines": {
71
+ "node": ">=22.12.0"
72
+ },
73
+ "scripts": {
74
+ "build": "vp pack",
75
+ "dev": "vp pack --watch",
76
+ "test": "vp test",
77
+ "check": "vp check"
78
+ }
6
79
  }