@vivero/stoma-core 0.1.0-rc.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.
@@ -0,0 +1,45 @@
1
+ // src/debug.ts
2
+ var noopDebugLogger = () => {
3
+ };
4
+ function createDebugger(namespace, enabled) {
5
+ if (!enabled) return noopDebugLogger;
6
+ if (typeof enabled === "string" && !matchNamespace(namespace, enabled)) {
7
+ return noopDebugLogger;
8
+ }
9
+ return (message, ...args) => {
10
+ const parts = [`[${namespace}]`, message];
11
+ for (const arg of args) {
12
+ parts.push(
13
+ typeof arg === "object" && arg !== null ? JSON.stringify(arg) : String(arg)
14
+ );
15
+ }
16
+ console.debug(parts.join(" "));
17
+ };
18
+ }
19
+ function matchNamespace(namespace, pattern) {
20
+ const patterns = pattern.split(",").map((p) => p.trim());
21
+ return patterns.some((p) => {
22
+ if (p === "*") return true;
23
+ const regexStr = p.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
24
+ return new RegExp(`^${regexStr}$`).test(namespace);
25
+ });
26
+ }
27
+ function createDebugFactory(enabled) {
28
+ if (!enabled) return () => noopDebugLogger;
29
+ const cache = /* @__PURE__ */ new Map();
30
+ return (namespace) => {
31
+ const cached = cache.get(namespace);
32
+ if (cached) return cached;
33
+ const logger = createDebugger(namespace, enabled);
34
+ cache.set(namespace, logger);
35
+ return logger;
36
+ };
37
+ }
38
+
39
+ export {
40
+ noopDebugLogger,
41
+ createDebugger,
42
+ matchNamespace,
43
+ createDebugFactory
44
+ };
45
+ //# sourceMappingURL=chunk-GHURCBEG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/debug.ts"],"sourcesContent":["/**\n * Zero-dependency debug logging for edge runtimes.\n *\n * Provides `debug`-style namespace-based logging without the `debug` npm\n * package (which relies on `process.env` / `localStorage` and doesn't work\n * reliably in edge runtimes). Output goes to `console.debug()`.\n *\n * Shared between `@vivero/stoma` (gateway) and\n * `@vivero/stoma-analytics` (analytics pipeline).\n *\n * @module debug\n *\n * @example\n * ```ts\n * // Gateway usage\n * createGateway({ debug: \"stoma:policy:*\", ... });\n *\n * // Analytics usage\n * createProcessor({ debug: \"stoma-analytics:processor\", ... });\n *\n * // Direct usage\n * const debug = createDebugger(\"stoma:gateway\", true);\n * debug(\"route registered\", { path: \"/api/users\", methods: [\"GET\"] });\n * // Output: [stoma:gateway] route registered {\"path\":\"/api/users\",\"methods\":[\"GET\"]}\n * ```\n */\n\n/** A debug logging function - call with a message and optional structured data. */\nexport type DebugLogger = (message: string, ...args: unknown[]) => void;\n\n/** No-op logger used when debug is disabled */\nexport const noopDebugLogger: DebugLogger = () => {};\n\n/**\n * Create a debug logger for the given namespace.\n *\n * @param namespace - e.g. \"stoma:gateway\", \"stoma-analytics:processor\"\n * @param enabled - true = all namespaces, false/undefined = none, string = comma-separated glob patterns\n *\n * @example\n * ```ts\n * const debug = createDebugger(\"stoma:gateway\", true);\n * debug(\"route registered\", { path: \"/api/users\", methods: [\"GET\"] });\n *\n * const debug2 = createDebugger(\"stoma:policy:cache\", \"stoma:policy:*\");\n * debug2(\"HIT\", \"GET:/api/users\");\n * ```\n */\nexport function createDebugger(\n namespace: string,\n enabled: boolean | string | undefined\n): DebugLogger {\n if (!enabled) return noopDebugLogger;\n\n if (typeof enabled === \"string\" && !matchNamespace(namespace, enabled)) {\n return noopDebugLogger;\n }\n\n return (message: string, ...args: unknown[]) => {\n const parts = [`[${namespace}]`, message];\n for (const arg of args) {\n parts.push(\n typeof arg === \"object\" && arg !== null\n ? JSON.stringify(arg)\n : String(arg)\n );\n }\n console.debug(parts.join(\" \"));\n };\n}\n\n/**\n * Check if a namespace matches a comma-separated list of glob patterns.\n *\n * Supports `*` as a wildcard for any sequence of characters.\n *\n * @example\n * ```ts\n * matchNamespace(\"stoma:gateway\", \"stoma:*\") // true\n * matchNamespace(\"stoma:policy:cache\", \"stoma:policy:*\") // true\n * matchNamespace(\"stoma:gateway\", \"stoma:upstream\") // false\n * matchNamespace(\"stoma:gateway\", \"stoma:gateway,stoma:upstream\") // true\n * matchNamespace(\"stoma:gateway\", \"*\") // true\n * ```\n */\nexport function matchNamespace(namespace: string, pattern: string): boolean {\n const patterns = pattern.split(\",\").map((p) => p.trim());\n return patterns.some((p) => {\n if (p === \"*\") return true;\n // Escape regex special chars, then convert * to .*\n const regexStr = p\n .replace(/[.+^${}()|[\\]\\\\]/g, \"\\\\$&\")\n .replace(/\\*/g, \".*\");\n return new RegExp(`^${regexStr}$`).test(namespace);\n });\n}\n\n/**\n * Create a debug factory that produces namespaced loggers.\n * Caches loggers by namespace so repeated calls return the same function.\n *\n * @param enabled - The gateway/processor debug setting\n * @returns A factory function: `(namespace) => DebugLogger`\n */\nexport function createDebugFactory(\n enabled: boolean | string | undefined\n): (namespace: string) => DebugLogger {\n if (!enabled) return () => noopDebugLogger;\n\n const cache = new Map<string, DebugLogger>();\n\n return (namespace: string) => {\n const cached = cache.get(namespace);\n if (cached) return cached;\n\n const logger = createDebugger(namespace, enabled);\n cache.set(namespace, logger);\n return logger;\n };\n}\n"],"mappings":";AA+BO,IAAM,kBAA+B,MAAM;AAAC;AAiB5C,SAAS,eACd,WACA,SACa;AACb,MAAI,CAAC,QAAS,QAAO;AAErB,MAAI,OAAO,YAAY,YAAY,CAAC,eAAe,WAAW,OAAO,GAAG;AACtE,WAAO;AAAA,EACT;AAEA,SAAO,CAAC,YAAoB,SAAoB;AAC9C,UAAM,QAAQ,CAAC,IAAI,SAAS,KAAK,OAAO;AACxC,eAAW,OAAO,MAAM;AACtB,YAAM;AAAA,QACJ,OAAO,QAAQ,YAAY,QAAQ,OAC/B,KAAK,UAAU,GAAG,IAClB,OAAO,GAAG;AAAA,MAChB;AAAA,IACF;AACA,YAAQ,MAAM,MAAM,KAAK,GAAG,CAAC;AAAA,EAC/B;AACF;AAgBO,SAAS,eAAe,WAAmB,SAA0B;AAC1E,QAAM,WAAW,QAAQ,MAAM,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AACvD,SAAO,SAAS,KAAK,CAAC,MAAM;AAC1B,QAAI,MAAM,IAAK,QAAO;AAEtB,UAAM,WAAW,EACd,QAAQ,qBAAqB,MAAM,EACnC,QAAQ,OAAO,IAAI;AACtB,WAAO,IAAI,OAAO,IAAI,QAAQ,GAAG,EAAE,KAAK,SAAS;AAAA,EACnD,CAAC;AACH;AASO,SAAS,mBACd,SACoC;AACpC,MAAI,CAAC,QAAS,QAAO,MAAM;AAE3B,QAAM,QAAQ,oBAAI,IAAyB;AAE3C,SAAO,CAAC,cAAsB;AAC5B,UAAM,SAAS,MAAM,IAAI,SAAS;AAClC,QAAI,OAAQ,QAAO;AAEnB,UAAM,SAAS,eAAe,WAAW,OAAO;AAChD,UAAM,IAAI,WAAW,MAAM;AAC3B,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Zero-dependency debug logging for edge runtimes.
3
+ *
4
+ * Provides `debug`-style namespace-based logging without the `debug` npm
5
+ * package (which relies on `process.env` / `localStorage` and doesn't work
6
+ * reliably in edge runtimes). Output goes to `console.debug()`.
7
+ *
8
+ * Shared between `@vivero/stoma` (gateway) and
9
+ * `@vivero/stoma-analytics` (analytics pipeline).
10
+ *
11
+ * @module debug
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // Gateway usage
16
+ * createGateway({ debug: "stoma:policy:*", ... });
17
+ *
18
+ * // Analytics usage
19
+ * createProcessor({ debug: "stoma-analytics:processor", ... });
20
+ *
21
+ * // Direct usage
22
+ * const debug = createDebugger("stoma:gateway", true);
23
+ * debug("route registered", { path: "/api/users", methods: ["GET"] });
24
+ * // Output: [stoma:gateway] route registered {"path":"/api/users","methods":["GET"]}
25
+ * ```
26
+ */
27
+ /** A debug logging function - call with a message and optional structured data. */
28
+ type DebugLogger = (message: string, ...args: unknown[]) => void;
29
+ /** No-op logger used when debug is disabled */
30
+ declare const noopDebugLogger: DebugLogger;
31
+ /**
32
+ * Create a debug logger for the given namespace.
33
+ *
34
+ * @param namespace - e.g. "stoma:gateway", "stoma-analytics:processor"
35
+ * @param enabled - true = all namespaces, false/undefined = none, string = comma-separated glob patterns
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const debug = createDebugger("stoma:gateway", true);
40
+ * debug("route registered", { path: "/api/users", methods: ["GET"] });
41
+ *
42
+ * const debug2 = createDebugger("stoma:policy:cache", "stoma:policy:*");
43
+ * debug2("HIT", "GET:/api/users");
44
+ * ```
45
+ */
46
+ declare function createDebugger(namespace: string, enabled: boolean | string | undefined): DebugLogger;
47
+ /**
48
+ * Check if a namespace matches a comma-separated list of glob patterns.
49
+ *
50
+ * Supports `*` as a wildcard for any sequence of characters.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * matchNamespace("stoma:gateway", "stoma:*") // true
55
+ * matchNamespace("stoma:policy:cache", "stoma:policy:*") // true
56
+ * matchNamespace("stoma:gateway", "stoma:upstream") // false
57
+ * matchNamespace("stoma:gateway", "stoma:gateway,stoma:upstream") // true
58
+ * matchNamespace("stoma:gateway", "*") // true
59
+ * ```
60
+ */
61
+ declare function matchNamespace(namespace: string, pattern: string): boolean;
62
+ /**
63
+ * Create a debug factory that produces namespaced loggers.
64
+ * Caches loggers by namespace so repeated calls return the same function.
65
+ *
66
+ * @param enabled - The gateway/processor debug setting
67
+ * @returns A factory function: `(namespace) => DebugLogger`
68
+ */
69
+ declare function createDebugFactory(enabled: boolean | string | undefined): (namespace: string) => DebugLogger;
70
+
71
+ export { type DebugLogger, createDebugFactory, createDebugger, matchNamespace, noopDebugLogger };
package/dist/debug.js ADDED
@@ -0,0 +1,13 @@
1
+ import {
2
+ createDebugFactory,
3
+ createDebugger,
4
+ matchNamespace,
5
+ noopDebugLogger
6
+ } from "./chunk-GHURCBEG.js";
7
+ export {
8
+ createDebugFactory,
9
+ createDebugger,
10
+ matchNamespace,
11
+ noopDebugLogger
12
+ };
13
+ //# sourceMappingURL=debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1 @@
1
+ export { DebugLogger, createDebugFactory, createDebugger, matchNamespace, noopDebugLogger } from './debug.js';
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import {
2
+ createDebugFactory,
3
+ createDebugger,
4
+ matchNamespace,
5
+ noopDebugLogger
6
+ } from "./chunk-GHURCBEG.js";
7
+ export {
8
+ createDebugFactory,
9
+ createDebugger,
10
+ matchNamespace,
11
+ noopDebugLogger
12
+ };
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@vivero/stoma-core",
3
+ "version": "0.1.0-rc.0",
4
+ "description": "Shared utilities for Stoma packages — debug logging, timing helpers, and common type guards.",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/vivero-dev/stoma.git",
9
+ "directory": "packages/core"
10
+ },
11
+ "homepage": "https://stoma.vivero.dev",
12
+ "sideEffects": false,
13
+ "license": "MIT",
14
+ "author": {
15
+ "name": "Jonathan Bennett"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/vivero-dev/stoma/issues"
19
+ },
20
+ "keywords": [
21
+ "stoma",
22
+ "utilities",
23
+ "debug",
24
+ "edge-runtime"
25
+ ],
26
+ "main": "./src/index.ts",
27
+ "module": "./src/index.ts",
28
+ "types": "./src/index.ts",
29
+ "files": [
30
+ "dist",
31
+ "LICENSE",
32
+ "README.md"
33
+ ],
34
+ "exports": {
35
+ ".": {
36
+ "types": "./src/index.ts",
37
+ "default": "./src/index.ts"
38
+ },
39
+ "./debug": {
40
+ "types": "./src/debug.ts",
41
+ "default": "./src/debug.ts"
42
+ }
43
+ },
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "provenance": true,
47
+ "main": "./dist/index.js",
48
+ "module": "./dist/index.js",
49
+ "types": "./dist/index.d.ts",
50
+ "exports": {
51
+ ".": {
52
+ "types": "./dist/index.d.ts",
53
+ "import": "./dist/index.js",
54
+ "default": "./dist/index.js"
55
+ },
56
+ "./debug": {
57
+ "types": "./dist/debug.d.ts",
58
+ "import": "./dist/debug.js",
59
+ "default": "./dist/debug.js"
60
+ }
61
+ }
62
+ },
63
+ "scripts": {
64
+ "build": "tsup",
65
+ "typecheck": "tsc --noEmit"
66
+ },
67
+ "devDependencies": {
68
+ "tsup": "^8.5.1",
69
+ "typescript": "^5.9.3"
70
+ }
71
+ }