@openweave/weave-provider 0.8.0 → 0.8.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.
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @openweave/weave-provider
3
+ *
4
+ * Storage-agnostic persistence contract for OpenWeave.
5
+ *
6
+ * Quick start:
7
+ * ```ts
8
+ * import { resolveProvider } from "@openweave/weave-provider";
9
+ *
10
+ * const provider = await resolveProvider<MyRecord>();
11
+ * await provider.set("ns:my-key", { hello: "world" });
12
+ * const record = await provider.get("ns:my-key");
13
+ * await provider.close();
14
+ * ```
15
+ */
16
+ export type { IWeaveProvider, ProviderFactory } from "./types.js";
17
+ export { WEAVE_PROVIDER_ENV, WEAVE_DATA_DIR_ENV, DEFAULT_DATA_DIR, ProviderClosedError, UnknownProviderError, } from "./types.js";
18
+ export { MemoryProvider } from "./memory-provider.js";
19
+ export { JsonProvider } from "./json-provider.js";
20
+ export { ProviderRegistry, resolveProvider } from "./registry.js";
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ /**
3
+ * @openweave/weave-provider
4
+ *
5
+ * Storage-agnostic persistence contract for OpenWeave.
6
+ *
7
+ * Quick start:
8
+ * ```ts
9
+ * import { resolveProvider } from "@openweave/weave-provider";
10
+ *
11
+ * const provider = await resolveProvider<MyRecord>();
12
+ * await provider.set("ns:my-key", { hello: "world" });
13
+ * const record = await provider.get("ns:my-key");
14
+ * await provider.close();
15
+ * ```
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.resolveProvider = exports.ProviderRegistry = exports.JsonProvider = exports.MemoryProvider = exports.UnknownProviderError = exports.ProviderClosedError = exports.DEFAULT_DATA_DIR = exports.WEAVE_DATA_DIR_ENV = exports.WEAVE_PROVIDER_ENV = void 0;
19
+ var types_js_1 = require("./types.js");
20
+ Object.defineProperty(exports, "WEAVE_PROVIDER_ENV", { enumerable: true, get: function () { return types_js_1.WEAVE_PROVIDER_ENV; } });
21
+ Object.defineProperty(exports, "WEAVE_DATA_DIR_ENV", { enumerable: true, get: function () { return types_js_1.WEAVE_DATA_DIR_ENV; } });
22
+ Object.defineProperty(exports, "DEFAULT_DATA_DIR", { enumerable: true, get: function () { return types_js_1.DEFAULT_DATA_DIR; } });
23
+ Object.defineProperty(exports, "ProviderClosedError", { enumerable: true, get: function () { return types_js_1.ProviderClosedError; } });
24
+ Object.defineProperty(exports, "UnknownProviderError", { enumerable: true, get: function () { return types_js_1.UnknownProviderError; } });
25
+ // Built-in implementations
26
+ var memory_provider_js_1 = require("./memory-provider.js");
27
+ Object.defineProperty(exports, "MemoryProvider", { enumerable: true, get: function () { return memory_provider_js_1.MemoryProvider; } });
28
+ var json_provider_js_1 = require("./json-provider.js");
29
+ Object.defineProperty(exports, "JsonProvider", { enumerable: true, get: function () { return json_provider_js_1.JsonProvider; } });
30
+ // Registry + convenience resolver
31
+ var registry_js_1 = require("./registry.js");
32
+ Object.defineProperty(exports, "ProviderRegistry", { enumerable: true, get: function () { return registry_js_1.ProviderRegistry; } });
33
+ Object.defineProperty(exports, "resolveProvider", { enumerable: true, get: function () { return registry_js_1.resolveProvider; } });
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH,uCAMoB;AALlB,8GAAA,kBAAkB,OAAA;AAClB,8GAAA,kBAAkB,OAAA;AAClB,4GAAA,gBAAgB,OAAA;AAChB,+GAAA,mBAAmB,OAAA;AACnB,gHAAA,oBAAoB,OAAA;AAGtB,2BAA2B;AAC3B,2DAAsD;AAA7C,oHAAA,cAAc,OAAA;AACvB,uDAAkD;AAAzC,gHAAA,YAAY,OAAA;AAErB,kCAAkC;AAClC,6CAAkE;AAAzD,+GAAA,gBAAgB,OAAA;AAAE,8GAAA,eAAe,OAAA"}
@@ -0,0 +1,47 @@
1
+ import { IWeaveProvider } from "./types.js";
2
+ /**
3
+ * JsonProvider
4
+ *
5
+ * File-system implementation of IWeaveProvider that stores each record as an
6
+ * individual JSON file inside a configurable data directory.
7
+ *
8
+ * Key → file-path mapping:
9
+ * key = "graph:my-session" → <dataDir>/graph__my-session.json
10
+ *
11
+ * Colons in keys are replaced with double-underscores and any characters that
12
+ * are not safe for all major file systems are percent-encoded, so the mapping
13
+ * is always reversible.
14
+ *
15
+ * Backward-compatible with the original weave-graph PersistenceManager:
16
+ * graph:<chatId> → weave-data/<chatId>.json (no namespace prefix)
17
+ * That legacy layout is preserved for existing data directories.
18
+ */
19
+ export declare class JsonProvider<T = unknown> implements IWeaveProvider<T> {
20
+ private dataDir;
21
+ private closed;
22
+ constructor(dataDir?: string);
23
+ close(): Promise<void>;
24
+ get(key: string): Promise<T | null>;
25
+ set(key: string, value: T): Promise<void>;
26
+ delete(key: string): Promise<void>;
27
+ list(prefix?: string): Promise<string[]>;
28
+ clear(prefix?: string): Promise<void>;
29
+ /**
30
+ * Convert a logical key into an absolute file path.
31
+ *
32
+ * Rules (applied in order):
33
+ * 1. Replace ":" with "__" (namespace separator)
34
+ * 2. Replace "/" with "--" (path separator used in ids)
35
+ * 3. Append ".json"
36
+ */
37
+ private keyToPath;
38
+ /**
39
+ * Reverse of keyToPath — converts a filename back into a logical key.
40
+ */
41
+ private pathToKey;
42
+ private ensureDataDir;
43
+ private assertOpen;
44
+ /** Expose dataDir for testing / diagnostics. */
45
+ get directory(): string;
46
+ }
47
+ //# sourceMappingURL=json-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-provider.d.ts","sourceRoot":"","sources":["../../src/json-provider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAyC,MAAM,YAAY,CAAC;AAEnF;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,YAAY,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,cAAc,CAAC,CAAC,CAAC;IACjE,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;gBAEX,OAAO,GAAE,MAAyB;IAQxC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQtB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAYnC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWlC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAkBxC,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3C;;;;;;;OAOG;IACH,OAAO,CAAC,SAAS;IAQjB;;OAEG;IACH,OAAO,CAAC,SAAS;YAgBH,aAAa;IAI3B,OAAO,CAAC,UAAU;IAIlB,gDAAgD;IAChD,IAAI,SAAS,IAAI,MAAM,CAEtB;CACF"}
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.JsonProvider = void 0;
37
+ const fs_1 = require("fs");
38
+ const path = __importStar(require("path"));
39
+ const types_js_1 = require("./types.js");
40
+ /**
41
+ * JsonProvider
42
+ *
43
+ * File-system implementation of IWeaveProvider that stores each record as an
44
+ * individual JSON file inside a configurable data directory.
45
+ *
46
+ * Key → file-path mapping:
47
+ * key = "graph:my-session" → <dataDir>/graph__my-session.json
48
+ *
49
+ * Colons in keys are replaced with double-underscores and any characters that
50
+ * are not safe for all major file systems are percent-encoded, so the mapping
51
+ * is always reversible.
52
+ *
53
+ * Backward-compatible with the original weave-graph PersistenceManager:
54
+ * graph:<chatId> → weave-data/<chatId>.json (no namespace prefix)
55
+ * That legacy layout is preserved for existing data directories.
56
+ */
57
+ class JsonProvider {
58
+ dataDir;
59
+ closed = false;
60
+ constructor(dataDir = types_js_1.DEFAULT_DATA_DIR) {
61
+ this.dataDir = dataDir;
62
+ }
63
+ // -------------------------------------------------------------------------
64
+ // Lifecycle
65
+ // -------------------------------------------------------------------------
66
+ async close() {
67
+ this.closed = true;
68
+ }
69
+ // -------------------------------------------------------------------------
70
+ // Core operations
71
+ // -------------------------------------------------------------------------
72
+ async get(key) {
73
+ this.assertOpen();
74
+ const filePath = this.keyToPath(key);
75
+ try {
76
+ const content = await fs_1.promises.readFile(filePath, "utf-8");
77
+ return JSON.parse(content);
78
+ }
79
+ catch (err) {
80
+ if (err.code === "ENOENT")
81
+ return null;
82
+ throw err;
83
+ }
84
+ }
85
+ async set(key, value) {
86
+ this.assertOpen();
87
+ await this.ensureDataDir();
88
+ const filePath = this.keyToPath(key);
89
+ await fs_1.promises.writeFile(filePath, JSON.stringify(value, null, 2), "utf-8");
90
+ }
91
+ async delete(key) {
92
+ this.assertOpen();
93
+ const filePath = this.keyToPath(key);
94
+ try {
95
+ await fs_1.promises.unlink(filePath);
96
+ }
97
+ catch (err) {
98
+ if (err.code !== "ENOENT")
99
+ throw err;
100
+ // key didn't exist — honour "no-op" contract
101
+ }
102
+ }
103
+ async list(prefix) {
104
+ this.assertOpen();
105
+ await this.ensureDataDir();
106
+ let entries;
107
+ try {
108
+ entries = await fs_1.promises.readdir(this.dataDir);
109
+ }
110
+ catch (err) {
111
+ if (err.code === "ENOENT")
112
+ return [];
113
+ throw err;
114
+ }
115
+ const keys = entries
116
+ .filter((f) => f.endsWith(".json"))
117
+ .map((f) => this.pathToKey(f));
118
+ if (!prefix)
119
+ return keys;
120
+ return keys.filter((k) => k.startsWith(prefix));
121
+ }
122
+ async clear(prefix) {
123
+ this.assertOpen();
124
+ const keys = await this.list(prefix);
125
+ await Promise.all(keys.map((k) => this.delete(k)));
126
+ }
127
+ // -------------------------------------------------------------------------
128
+ // Key ↔ filename helpers
129
+ // -------------------------------------------------------------------------
130
+ /**
131
+ * Convert a logical key into an absolute file path.
132
+ *
133
+ * Rules (applied in order):
134
+ * 1. Replace ":" with "__" (namespace separator)
135
+ * 2. Replace "/" with "--" (path separator used in ids)
136
+ * 3. Append ".json"
137
+ */
138
+ keyToPath(key) {
139
+ const sanitized = key
140
+ .replace(/:/g, "__")
141
+ .replace(/\//g, "--")
142
+ .replace(/[^a-zA-Z0-9_\-\.]/g, (c) => `~${c.codePointAt(0)?.toString(16)}~`);
143
+ return path.join(this.dataDir, `${sanitized}.json`);
144
+ }
145
+ /**
146
+ * Reverse of keyToPath — converts a filename back into a logical key.
147
+ */
148
+ pathToKey(filename) {
149
+ const base = filename.endsWith(".json")
150
+ ? filename.slice(0, -5)
151
+ : filename;
152
+ return base
153
+ .replace(/~([0-9a-f]+)~/g, (_, hex) => String.fromCodePoint(parseInt(hex, 16)))
154
+ .replace(/--/g, "/")
155
+ .replace(/__/g, ":");
156
+ }
157
+ // -------------------------------------------------------------------------
158
+ // Private helpers
159
+ // -------------------------------------------------------------------------
160
+ async ensureDataDir() {
161
+ await fs_1.promises.mkdir(this.dataDir, { recursive: true });
162
+ }
163
+ assertOpen() {
164
+ if (this.closed)
165
+ throw new types_js_1.ProviderClosedError("JsonProvider");
166
+ }
167
+ /** Expose dataDir for testing / diagnostics. */
168
+ get directory() {
169
+ return this.dataDir;
170
+ }
171
+ }
172
+ exports.JsonProvider = JsonProvider;
173
+ //# sourceMappingURL=json-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-provider.js","sourceRoot":"","sources":["../../src/json-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2BAAoC;AACpC,2CAA6B;AAC7B,yCAAmF;AAEnF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,YAAY;IACf,OAAO,CAAS;IAChB,MAAM,GAAG,KAAK,CAAC;IAEvB,YAAY,UAAkB,2BAAgB;QA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ACX,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AA7HD,oCA6HC"}
@@ -0,0 +1,28 @@
1
+ import { IWeaveProvider } from "./types.js";
2
+ /**
3
+ * MemoryProvider
4
+ *
5
+ * An in-memory implementation of IWeaveProvider backed by a plain `Map`.
6
+ * Zero-latency reads/writes, no I/O, no external dependencies.
7
+ *
8
+ * Ideal for:
9
+ * - Unit tests (fast, isolated, no temp-file cleanup needed)
10
+ * - Ephemeral sessions where persistence across restarts is not required
11
+ * - Streaming pipelines that only need within-process memory
12
+ */
13
+ export declare class MemoryProvider<T = unknown> implements IWeaveProvider<T> {
14
+ private store;
15
+ private closed;
16
+ close(): Promise<void>;
17
+ get(key: string): Promise<T | null>;
18
+ set(key: string, value: T): Promise<void>;
19
+ delete(key: string): Promise<void>;
20
+ list(prefix?: string): Promise<string[]>;
21
+ clear(prefix?: string): Promise<void>;
22
+ /** Current number of stored records. */
23
+ get size(): number;
24
+ /** Whether the provider has been closed. */
25
+ get isClosed(): boolean;
26
+ private assertOpen;
27
+ }
28
+ //# sourceMappingURL=memory-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-provider.d.ts","sourceRoot":"","sources":["../../src/memory-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAuB,MAAM,YAAY,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,qBAAa,cAAc,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,cAAc,CAAC,CAAC,CAAC;IACnE,OAAO,CAAC,KAAK,CAAwB;IACrC,OAAO,CAAC,MAAM,CAAS;IAMjB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAStB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAKnC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAOxC,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB3C,wCAAwC;IACxC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,4CAA4C;IAC5C,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAMD,OAAO,CAAC,UAAU;CAGnB"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoryProvider = void 0;
4
+ const types_js_1 = require("./types.js");
5
+ /**
6
+ * MemoryProvider
7
+ *
8
+ * An in-memory implementation of IWeaveProvider backed by a plain `Map`.
9
+ * Zero-latency reads/writes, no I/O, no external dependencies.
10
+ *
11
+ * Ideal for:
12
+ * - Unit tests (fast, isolated, no temp-file cleanup needed)
13
+ * - Ephemeral sessions where persistence across restarts is not required
14
+ * - Streaming pipelines that only need within-process memory
15
+ */
16
+ class MemoryProvider {
17
+ store = new Map();
18
+ closed = false;
19
+ // -------------------------------------------------------------------------
20
+ // Lifecycle
21
+ // -------------------------------------------------------------------------
22
+ async close() {
23
+ this.closed = true;
24
+ this.store.clear();
25
+ }
26
+ // -------------------------------------------------------------------------
27
+ // Core operations
28
+ // -------------------------------------------------------------------------
29
+ async get(key) {
30
+ this.assertOpen();
31
+ return this.store.get(key) ?? null;
32
+ }
33
+ async set(key, value) {
34
+ this.assertOpen();
35
+ this.store.set(key, value);
36
+ }
37
+ async delete(key) {
38
+ this.assertOpen();
39
+ this.store.delete(key);
40
+ }
41
+ async list(prefix) {
42
+ this.assertOpen();
43
+ const keys = [...this.store.keys()];
44
+ if (!prefix)
45
+ return keys;
46
+ return keys.filter((k) => k.startsWith(prefix));
47
+ }
48
+ async clear(prefix) {
49
+ this.assertOpen();
50
+ if (!prefix) {
51
+ this.store.clear();
52
+ return;
53
+ }
54
+ for (const key of this.store.keys()) {
55
+ if (key.startsWith(prefix)) {
56
+ this.store.delete(key);
57
+ }
58
+ }
59
+ }
60
+ // -------------------------------------------------------------------------
61
+ // Utility — exposed for testing introspection
62
+ // -------------------------------------------------------------------------
63
+ /** Current number of stored records. */
64
+ get size() {
65
+ return this.store.size;
66
+ }
67
+ /** Whether the provider has been closed. */
68
+ get isClosed() {
69
+ return this.closed;
70
+ }
71
+ // -------------------------------------------------------------------------
72
+ // Private helpers
73
+ // -------------------------------------------------------------------------
74
+ assertOpen() {
75
+ if (this.closed)
76
+ throw new types_js_1.ProviderClosedError("MemoryProvider");
77
+ }
78
+ }
79
+ exports.MemoryProvider = MemoryProvider;
80
+ //# sourceMappingURL=memory-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-provider.js","sourceRoot":"","sources":["../../src/memory-provider.ts"],"names":[],"mappings":";;;AAAA,yCAAiE;AAEjE;;;;;;;;;;GAUG;AACH,MAAa,cAAc;IACjB,KAAK,GAAG,IAAI,GAAG,EAAa,CAAC;IAC7B,MAAM,GAAG,KAAK,CAAC;IAEvB,4EAA4E;IAC5E,YAAY;IACZ,4EAA4E;IAE5E,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,4EAA4E;IAC5E,kBAAkB;IAClB,4EAA4E;IAE5E,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAQ;QAC7B,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK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,8BAAmB,CAAC,gBAAgB,CAAC,CAAC;IACnE,CAAC;CACF;AAzED,wCAyEC"}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,56 @@
1
+ import { IWeaveProvider, ProviderFactory } from "./types.js";
2
+ /**
3
+ * ProviderRegistry
4
+ *
5
+ * Central factory and registration hub for IWeaveProvider implementations.
6
+ *
7
+ * Built-in providers:
8
+ * "json" → JsonProvider (default)
9
+ * "memory" → MemoryProvider
10
+ *
11
+ * Third-party providers (weave-provider-sqlite, weave-provider-mongodb …) can
12
+ * register themselves at startup via `ProviderRegistry.register()`.
13
+ *
14
+ * Runtime resolution order:
15
+ * 1. `WEAVE_PROVIDER` environment variable (e.g. `WEAVE_PROVIDER=memory`)
16
+ * 2. Falls back to `"json"` when the env var is absent or empty
17
+ */
18
+ export declare class ProviderRegistry {
19
+ private static factories;
20
+ /**
21
+ * Register a new provider factory under a named key.
22
+ * The key is normalised to lower-case before storing.
23
+ *
24
+ * @example
25
+ * // In weave-provider-sqlite:
26
+ * ProviderRegistry.register("sqlite", async () => new SqliteProvider(...));
27
+ */
28
+ static register<T = unknown>(name: string, factory: ProviderFactory<T>): void;
29
+ /**
30
+ * Resolve and instantiate a provider.
31
+ *
32
+ * @param type Explicit provider type string. When omitted, reads
33
+ * `process.env.WEAVE_PROVIDER`. Defaults to `"json"`.
34
+ *
35
+ * @throws {UnknownProviderError} if the type is not registered.
36
+ */
37
+ static resolve<T = unknown>(type?: string): Promise<IWeaveProvider<T>>;
38
+ /**
39
+ * Returns the list of currently registered provider names.
40
+ * Useful for diagnostics and help text.
41
+ */
42
+ static available(): string[];
43
+ /**
44
+ * Remove a registered provider (mainly for test isolation).
45
+ */
46
+ static unregister(name: string): void;
47
+ }
48
+ /**
49
+ * Convenience function — resolve the default (or env-configured) provider.
50
+ *
51
+ * @example
52
+ * const provider = await resolveProvider<GraphSnapshot>();
53
+ * await provider.set("graph:my-session", snapshot);
54
+ */
55
+ export declare function resolveProvider<T = unknown>(type?: string): Promise<IWeaveProvider<T>>;
56
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,eAAe,EAKhB,MAAM,YAAY,CAAC;AAIpB;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAC,SAAS,CAA+C;IAYvE;;;;;;;OAOG;IACH,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI;IAI7E;;;;;;;OAOG;WACU,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAW5E;;;OAGG;IACH,MAAM,CAAC,SAAS,IAAI,MAAM,EAAE;IAI5B;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAGtC;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,CAAC,GAAG,OAAO,EAC/C,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAE5B"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProviderRegistry = void 0;
4
+ exports.resolveProvider = resolveProvider;
5
+ const types_js_1 = require("./types.js");
6
+ const json_provider_js_1 = require("./json-provider.js");
7
+ const memory_provider_js_1 = require("./memory-provider.js");
8
+ /**
9
+ * ProviderRegistry
10
+ *
11
+ * Central factory and registration hub for IWeaveProvider implementations.
12
+ *
13
+ * Built-in providers:
14
+ * "json" → JsonProvider (default)
15
+ * "memory" → MemoryProvider
16
+ *
17
+ * Third-party providers (weave-provider-sqlite, weave-provider-mongodb …) can
18
+ * register themselves at startup via `ProviderRegistry.register()`.
19
+ *
20
+ * Runtime resolution order:
21
+ * 1. `WEAVE_PROVIDER` environment variable (e.g. `WEAVE_PROVIDER=memory`)
22
+ * 2. Falls back to `"json"` when the env var is absent or empty
23
+ */
24
+ class ProviderRegistry {
25
+ static factories = new Map();
26
+ static {
27
+ // Register built-in providers
28
+ ProviderRegistry.register("json", async () => {
29
+ const dataDir = process.env[types_js_1.WEAVE_DATA_DIR_ENV] ?? types_js_1.DEFAULT_DATA_DIR;
30
+ return new json_provider_js_1.JsonProvider(dataDir);
31
+ });
32
+ ProviderRegistry.register("memory", async () => new memory_provider_js_1.MemoryProvider());
33
+ }
34
+ /**
35
+ * Register a new provider factory under a named key.
36
+ * The key is normalised to lower-case before storing.
37
+ *
38
+ * @example
39
+ * // In weave-provider-sqlite:
40
+ * ProviderRegistry.register("sqlite", async () => new SqliteProvider(...));
41
+ */
42
+ static register(name, factory) {
43
+ ProviderRegistry.factories.set(name.toLowerCase(), factory);
44
+ }
45
+ /**
46
+ * Resolve and instantiate a provider.
47
+ *
48
+ * @param type Explicit provider type string. When omitted, reads
49
+ * `process.env.WEAVE_PROVIDER`. Defaults to `"json"`.
50
+ *
51
+ * @throws {UnknownProviderError} if the type is not registered.
52
+ */
53
+ static async resolve(type) {
54
+ const raw = (type ?? process.env[types_js_1.WEAVE_PROVIDER_ENV] ?? "json")
55
+ .trim()
56
+ .toLowerCase();
57
+ const factory = ProviderRegistry.factories.get(raw);
58
+ if (!factory)
59
+ throw new types_js_1.UnknownProviderError(raw);
60
+ return factory();
61
+ }
62
+ /**
63
+ * Returns the list of currently registered provider names.
64
+ * Useful for diagnostics and help text.
65
+ */
66
+ static available() {
67
+ return [...ProviderRegistry.factories.keys()].sort();
68
+ }
69
+ /**
70
+ * Remove a registered provider (mainly for test isolation).
71
+ */
72
+ static unregister(name) {
73
+ ProviderRegistry.factories.delete(name.toLowerCase());
74
+ }
75
+ }
76
+ exports.ProviderRegistry = ProviderRegistry;
77
+ /**
78
+ * Convenience function — resolve the default (or env-configured) provider.
79
+ *
80
+ * @example
81
+ * const provider = await resolveProvider<GraphSnapshot>();
82
+ * await provider.set("graph:my-session", snapshot);
83
+ */
84
+ async function resolveProvider(type) {
85
+ return ProviderRegistry.resolve(type);
86
+ }
87
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/registry.ts"],"names":[],"mappings":";;;AA8FA,0CAIC;AAlGD,yCAOoB;AACpB,yDAAkD;AAClD,6DAAsD;AAEtD;;;;;;;;;;;;;;;GAeG;AACH,MAAa,gBAAgB;IACnB,MAAM,CAAC,SAAS,GAAG,IAAI,GAAG,EAAoC,CAAC;IAEvE;QACE,8BAA8B;QAC9B,gBAAgB,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE;YAC3C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,6BAAkB,CAAC,IAAI,2BAAgB,CAAC;YACpE,OAAO,IAAI,+BAAY,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,mCAAc,EAAE,CAAC,CAAC;IACxE,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,QAAQ,CAAc,IAAY,EAAE,OAA2B;QACpE,gBAAgB,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,OAAmC,CAAC,CAAC;IAC1F,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAc,IAAa;QAC7C,MAAM,GAAG,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,6BAAkB,CAAC,IAAI,MAAM,CAAC;aAC5D,IAAI,EAAE;aACN,WAAW,EAAE,CAAC;QAEjB,MAAM,OAAO,GAAG,gBAAgB,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,+BAAoB,CAAC,GAAG,CAAC,CAAC;QAElD,OAAO,OAAO,EAAgC,CAAC;IACjD,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,SAAS;QACd,OAAO,CAAC,GAAG,gBAAgB,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,IAAY;QAC5B,gBAAgB,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IACxD,CAAC;;AAzDH,4CA0DC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,eAAe,CACnC,IAAa;IAEb,OAAO,gBAAgB,CAAC,OAAO,CAAI,IAAI,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * weave-provider — Core type definitions
3
+ *
4
+ * IWeaveProvider<T> is the single storage contract that all provider
5
+ * implementations must satisfy. It follows a simple key-value model with
6
+ * optional namespace prefixes so that different subsystems (graph, sessions,
7
+ * vectors, paths) can share a single provider instance without colliding.
8
+ */
9
+ /**
10
+ * Storage-agnostic key-value provider used by WeaveGraph, SessionLifecycle,
11
+ * VectorStore and WeavePath for all persistence needs.
12
+ *
13
+ * @typeParam T The value type stored under each key. In practice this will be
14
+ * a serialisable plain object (JSON-compatible).
15
+ */
16
+ export interface IWeaveProvider<T = unknown> {
17
+ /**
18
+ * Retrieve a single record by its full key.
19
+ * Returns `null` if the key does not exist.
20
+ */
21
+ get(key: string): Promise<T | null>;
22
+ /**
23
+ * Persist a record under the given key, overwriting any previous value.
24
+ */
25
+ set(key: string, value: T): Promise<void>;
26
+ /**
27
+ * Remove the record associated with the given key.
28
+ * A no-op if the key does not exist (must NOT throw).
29
+ */
30
+ delete(key: string): Promise<void>;
31
+ /**
32
+ * List all keys that start with the given prefix.
33
+ * If prefix is omitted, return every key in the store.
34
+ *
35
+ * @param prefix Optional key prefix filter (e.g. `"graph:"`, `"session:"`).
36
+ */
37
+ list(prefix?: string): Promise<string[]>;
38
+ /**
39
+ * Delete all records whose keys start with the given prefix.
40
+ * If prefix is omitted, the entire store is wiped.
41
+ *
42
+ * @param prefix Optional key prefix filter.
43
+ */
44
+ clear(prefix?: string): Promise<void>;
45
+ /**
46
+ * Release any resources held by this provider (file handles, DB connections
47
+ * etc.). After `close()` is called the provider must not accept further
48
+ * operations.
49
+ */
50
+ close(): Promise<void>;
51
+ }
52
+ /**
53
+ * A zero-argument async factory that resolves to a ready-to-use provider.
54
+ * Used by the registry when building providers from a connection string.
55
+ */
56
+ export type ProviderFactory<T = unknown> = () => Promise<IWeaveProvider<T>>;
57
+ /**
58
+ * Environment variable that controls which provider the registry resolves.
59
+ *
60
+ * Accepted values (case-insensitive):
61
+ * - `"json"` (default) → JsonProvider
62
+ * - `"memory"` → MemoryProvider
63
+ * - `"sqlite"` / a file path → weave-provider-sqlite (separate package)
64
+ * - `"mongodb"` / a URI → weave-provider-mongodb (separate package)
65
+ * - `"postgres"` / a URI → weave-provider-postgres (separate package)
66
+ * - `"mysql"` / a URI → weave-provider-mysql (separate package)
67
+ */
68
+ export declare const WEAVE_PROVIDER_ENV = "WEAVE_PROVIDER";
69
+ /**
70
+ * Environment variable that controls the root data directory used by the
71
+ * JsonProvider (and, conventionally, any file-based provider).
72
+ */
73
+ export declare const WEAVE_DATA_DIR_ENV = "WEAVE_DATA_DIR";
74
+ /**
75
+ * Default data directory value when WEAVE_DATA_DIR is not set.
76
+ */
77
+ export declare const DEFAULT_DATA_DIR = "./weave-data";
78
+ /**
79
+ * Thrown when a provider operation is invoked after `close()` has been called.
80
+ */
81
+ export declare class ProviderClosedError extends Error {
82
+ constructor(providerName: string);
83
+ }
84
+ /**
85
+ * Thrown when the registry cannot resolve a provider from the current
86
+ * environment configuration.
87
+ */
88
+ export declare class UnknownProviderError extends Error {
89
+ constructor(value: string);
90
+ }
91
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;;;;;GAMG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACzC;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAEpC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1C;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAEzC;;;;;OAKG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtC;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAMD;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,OAAO,IAAI,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AAM5E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AAEnD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AAEnD;;GAEG;AACH,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAM/C;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,YAAY,EAAE,MAAM;CAIjC;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,KAAK,EAAE,MAAM;CAQ1B"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /**
3
+ * weave-provider — Core type definitions
4
+ *
5
+ * IWeaveProvider<T> is the single storage contract that all provider
6
+ * implementations must satisfy. It follows a simple key-value model with
7
+ * optional namespace prefixes so that different subsystems (graph, sessions,
8
+ * vectors, paths) can share a single provider instance without colliding.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.UnknownProviderError = exports.ProviderClosedError = exports.DEFAULT_DATA_DIR = exports.WEAVE_DATA_DIR_ENV = exports.WEAVE_PROVIDER_ENV = void 0;
12
+ // ---------------------------------------------------------------------------
13
+ // Registry configuration
14
+ // ---------------------------------------------------------------------------
15
+ /**
16
+ * Environment variable that controls which provider the registry resolves.
17
+ *
18
+ * Accepted values (case-insensitive):
19
+ * - `"json"` (default) → JsonProvider
20
+ * - `"memory"` → MemoryProvider
21
+ * - `"sqlite"` / a file path → weave-provider-sqlite (separate package)
22
+ * - `"mongodb"` / a URI → weave-provider-mongodb (separate package)
23
+ * - `"postgres"` / a URI → weave-provider-postgres (separate package)
24
+ * - `"mysql"` / a URI → weave-provider-mysql (separate package)
25
+ */
26
+ exports.WEAVE_PROVIDER_ENV = "WEAVE_PROVIDER";
27
+ /**
28
+ * Environment variable that controls the root data directory used by the
29
+ * JsonProvider (and, conventionally, any file-based provider).
30
+ */
31
+ exports.WEAVE_DATA_DIR_ENV = "WEAVE_DATA_DIR";
32
+ /**
33
+ * Default data directory value when WEAVE_DATA_DIR is not set.
34
+ */
35
+ exports.DEFAULT_DATA_DIR = "./weave-data";
36
+ // ---------------------------------------------------------------------------
37
+ // Error types
38
+ // ---------------------------------------------------------------------------
39
+ /**
40
+ * Thrown when a provider operation is invoked after `close()` has been called.
41
+ */
42
+ class ProviderClosedError extends Error {
43
+ constructor(providerName) {
44
+ super(`[${providerName}] provider has been closed and is no longer usable`);
45
+ this.name = "ProviderClosedError";
46
+ }
47
+ }
48
+ exports.ProviderClosedError = ProviderClosedError;
49
+ /**
50
+ * Thrown when the registry cannot resolve a provider from the current
51
+ * environment configuration.
52
+ */
53
+ class UnknownProviderError extends Error {
54
+ constructor(value) {
55
+ super(`[weave-provider] Unknown provider type "${value}". ` +
56
+ `Set ${exports.WEAVE_PROVIDER_ENV}=json|memory or install the corresponding ` +
57
+ `weave-provider-* package.`);
58
+ this.name = "UnknownProviderError";
59
+ }
60
+ }
61
+ exports.UnknownProviderError = UnknownProviderError;
62
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAiEH,8EAA8E;AAC9E,yBAAyB;AACzB,8EAA8E;AAE9E;;;;;;;;;;GAUG;AACU,QAAA,kBAAkB,GAAG,gBAAgB,CAAC;AAEnD;;;GAGG;AACU,QAAA,kBAAkB,GAAG,gBAAgB,CAAC;AAEnD;;GAEG;AACU,QAAA,gBAAgB,GAAG,cAAc,CAAC;AAE/C,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E;;GAEG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,YAAoB;QAC9B,KAAK,CAAC,IAAI,YAAY,oDAAoD,CAAC,CAAC;QAC5E,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AALD,kDAKC;AAED;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,KAAa;QACvB,KAAK,CACH,2CAA2C,KAAK,KAAK;YACnD,OAAO,0BAAkB,4CAA4C;YACrE,2BAA2B,CAC9B,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AATD,oDASC"}
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@openweave/weave-provider",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "Storage-agnostic persistence contract for OpenWeave — IWeaveProvider<T> interface + built-in implementations",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "type": "module",
8
- "main": "./dist/index.js",
8
+ "main": "./dist/cjs/index.js",
9
+ "module": "./dist/index.js",
9
10
  "types": "./dist/index.d.ts",
10
11
  "files": [
11
12
  "dist",
@@ -13,6 +14,7 @@
13
14
  ],
14
15
  "exports": {
15
16
  ".": {
17
+ "require": "./dist/cjs/index.js",
16
18
  "import": "./dist/index.js",
17
19
  "types": "./dist/index.d.ts"
18
20
  }
@@ -30,7 +32,7 @@
30
32
  },
31
33
  "dependencies": {},
32
34
  "scripts": {
33
- "build": "tsc",
35
+ "build": "tsc && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', '{\\\"type\\\":\\\"commonjs\\\"}')\"",
34
36
  "dev": "tsc --watch",
35
37
  "test": "vitest",
36
38
  "lint": "eslint src --max-warnings 0",