@openweave/weave-provider 0.8.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 lemur bookstores
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.
@@ -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"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
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 { WEAVE_PROVIDER_ENV, WEAVE_DATA_DIR_ENV, DEFAULT_DATA_DIR, ProviderClosedError, UnknownProviderError, } from "./types.js";
17
+ // Built-in implementations
18
+ export { MemoryProvider } from "./memory-provider.js";
19
+ export { JsonProvider } from "./json-provider.js";
20
+ // Registry + convenience resolver
21
+ export { ProviderRegistry, resolveProvider } from "./registry.js";
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,2BAA2B;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,kCAAkC;AAClC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
@@ -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,136 @@
1
+ import { promises as fs } from "fs";
2
+ import * as path from "path";
3
+ import { ProviderClosedError, DEFAULT_DATA_DIR } from "./types.js";
4
+ /**
5
+ * JsonProvider
6
+ *
7
+ * File-system implementation of IWeaveProvider that stores each record as an
8
+ * individual JSON file inside a configurable data directory.
9
+ *
10
+ * Key → file-path mapping:
11
+ * key = "graph:my-session" → <dataDir>/graph__my-session.json
12
+ *
13
+ * Colons in keys are replaced with double-underscores and any characters that
14
+ * are not safe for all major file systems are percent-encoded, so the mapping
15
+ * is always reversible.
16
+ *
17
+ * Backward-compatible with the original weave-graph PersistenceManager:
18
+ * graph:<chatId> → weave-data/<chatId>.json (no namespace prefix)
19
+ * That legacy layout is preserved for existing data directories.
20
+ */
21
+ export class JsonProvider {
22
+ dataDir;
23
+ closed = false;
24
+ constructor(dataDir = DEFAULT_DATA_DIR) {
25
+ this.dataDir = dataDir;
26
+ }
27
+ // -------------------------------------------------------------------------
28
+ // Lifecycle
29
+ // -------------------------------------------------------------------------
30
+ async close() {
31
+ this.closed = true;
32
+ }
33
+ // -------------------------------------------------------------------------
34
+ // Core operations
35
+ // -------------------------------------------------------------------------
36
+ async get(key) {
37
+ this.assertOpen();
38
+ const filePath = this.keyToPath(key);
39
+ try {
40
+ const content = await fs.readFile(filePath, "utf-8");
41
+ return JSON.parse(content);
42
+ }
43
+ catch (err) {
44
+ if (err.code === "ENOENT")
45
+ return null;
46
+ throw err;
47
+ }
48
+ }
49
+ async set(key, value) {
50
+ this.assertOpen();
51
+ await this.ensureDataDir();
52
+ const filePath = this.keyToPath(key);
53
+ await fs.writeFile(filePath, JSON.stringify(value, null, 2), "utf-8");
54
+ }
55
+ async delete(key) {
56
+ this.assertOpen();
57
+ const filePath = this.keyToPath(key);
58
+ try {
59
+ await fs.unlink(filePath);
60
+ }
61
+ catch (err) {
62
+ if (err.code !== "ENOENT")
63
+ throw err;
64
+ // key didn't exist — honour "no-op" contract
65
+ }
66
+ }
67
+ async list(prefix) {
68
+ this.assertOpen();
69
+ await this.ensureDataDir();
70
+ let entries;
71
+ try {
72
+ entries = await fs.readdir(this.dataDir);
73
+ }
74
+ catch (err) {
75
+ if (err.code === "ENOENT")
76
+ return [];
77
+ throw err;
78
+ }
79
+ const keys = entries
80
+ .filter((f) => f.endsWith(".json"))
81
+ .map((f) => this.pathToKey(f));
82
+ if (!prefix)
83
+ return keys;
84
+ return keys.filter((k) => k.startsWith(prefix));
85
+ }
86
+ async clear(prefix) {
87
+ this.assertOpen();
88
+ const keys = await this.list(prefix);
89
+ await Promise.all(keys.map((k) => this.delete(k)));
90
+ }
91
+ // -------------------------------------------------------------------------
92
+ // Key ↔ filename helpers
93
+ // -------------------------------------------------------------------------
94
+ /**
95
+ * Convert a logical key into an absolute file path.
96
+ *
97
+ * Rules (applied in order):
98
+ * 1. Replace ":" with "__" (namespace separator)
99
+ * 2. Replace "/" with "--" (path separator used in ids)
100
+ * 3. Append ".json"
101
+ */
102
+ keyToPath(key) {
103
+ const sanitized = key
104
+ .replace(/:/g, "__")
105
+ .replace(/\//g, "--")
106
+ .replace(/[^a-zA-Z0-9_\-\.]/g, (c) => `~${c.codePointAt(0)?.toString(16)}~`);
107
+ return path.join(this.dataDir, `${sanitized}.json`);
108
+ }
109
+ /**
110
+ * Reverse of keyToPath — converts a filename back into a logical key.
111
+ */
112
+ pathToKey(filename) {
113
+ const base = filename.endsWith(".json")
114
+ ? filename.slice(0, -5)
115
+ : filename;
116
+ return base
117
+ .replace(/~([0-9a-f]+)~/g, (_, hex) => String.fromCodePoint(parseInt(hex, 16)))
118
+ .replace(/--/g, "/")
119
+ .replace(/__/g, ":");
120
+ }
121
+ // -------------------------------------------------------------------------
122
+ // Private helpers
123
+ // -------------------------------------------------------------------------
124
+ async ensureDataDir() {
125
+ await fs.mkdir(this.dataDir, { recursive: true });
126
+ }
127
+ assertOpen() {
128
+ if (this.closed)
129
+ throw new ProviderClosedError("JsonProvider");
130
+ }
131
+ /** Expose dataDir for testing / diagnostics. */
132
+ get directory() {
133
+ return this.dataDir;
134
+ }
135
+ }
136
+ //# sourceMappingURL=json-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-provider.js","sourceRoot":"","sources":["../src/json-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,I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;IAEpE,KAAK,CAAC,aAAa;QACzB,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;IAEO,UAAU;QAChB,IAAI,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,mBAAmB,CAAC,cAAc,CAAC,CAAC;IACjE,CAAC;IAED,gDAAgD;IAChD,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
@@ -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,76 @@
1
+ import { ProviderClosedError } 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 class MemoryProvider {
14
+ store = new Map();
15
+ closed = false;
16
+ // -------------------------------------------------------------------------
17
+ // Lifecycle
18
+ // -------------------------------------------------------------------------
19
+ async close() {
20
+ this.closed = true;
21
+ this.store.clear();
22
+ }
23
+ // -------------------------------------------------------------------------
24
+ // Core operations
25
+ // -------------------------------------------------------------------------
26
+ async get(key) {
27
+ this.assertOpen();
28
+ return this.store.get(key) ?? null;
29
+ }
30
+ async set(key, value) {
31
+ this.assertOpen();
32
+ this.store.set(key, value);
33
+ }
34
+ async delete(key) {
35
+ this.assertOpen();
36
+ this.store.delete(key);
37
+ }
38
+ async list(prefix) {
39
+ this.assertOpen();
40
+ const keys = [...this.store.keys()];
41
+ if (!prefix)
42
+ return keys;
43
+ return keys.filter((k) => k.startsWith(prefix));
44
+ }
45
+ async clear(prefix) {
46
+ this.assertOpen();
47
+ if (!prefix) {
48
+ this.store.clear();
49
+ return;
50
+ }
51
+ for (const key of this.store.keys()) {
52
+ if (key.startsWith(prefix)) {
53
+ this.store.delete(key);
54
+ }
55
+ }
56
+ }
57
+ // -------------------------------------------------------------------------
58
+ // Utility — exposed for testing introspection
59
+ // -------------------------------------------------------------------------
60
+ /** Current number of stored records. */
61
+ get size() {
62
+ return this.store.size;
63
+ }
64
+ /** Whether the provider has been closed. */
65
+ get isClosed() {
66
+ return this.closed;
67
+ }
68
+ // -------------------------------------------------------------------------
69
+ // Private helpers
70
+ // -------------------------------------------------------------------------
71
+ assertOpen() {
72
+ if (this.closed)
73
+ throw new ProviderClosedError("MemoryProvider");
74
+ }
75
+ }
76
+ //# sourceMappingURL=memory-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-provider.js","sourceRoot":"","sources":["../src/memory-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,MAAM,OAAO,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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AC;IACzB,CAAC;IAED,4CAA4C;IAC5C,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,4EAA4E;IAC5E,kBAAkB;IAClB,4EAA4E;IAEpE,UAAU;QAChB,IAAI,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IACnE,CAAC;CACF"}
@@ -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,82 @@
1
+ import { WEAVE_PROVIDER_ENV, WEAVE_DATA_DIR_ENV, DEFAULT_DATA_DIR, UnknownProviderError, } from "./types.js";
2
+ import { JsonProvider } from "./json-provider.js";
3
+ import { MemoryProvider } from "./memory-provider.js";
4
+ /**
5
+ * ProviderRegistry
6
+ *
7
+ * Central factory and registration hub for IWeaveProvider implementations.
8
+ *
9
+ * Built-in providers:
10
+ * "json" → JsonProvider (default)
11
+ * "memory" → MemoryProvider
12
+ *
13
+ * Third-party providers (weave-provider-sqlite, weave-provider-mongodb …) can
14
+ * register themselves at startup via `ProviderRegistry.register()`.
15
+ *
16
+ * Runtime resolution order:
17
+ * 1. `WEAVE_PROVIDER` environment variable (e.g. `WEAVE_PROVIDER=memory`)
18
+ * 2. Falls back to `"json"` when the env var is absent or empty
19
+ */
20
+ export class ProviderRegistry {
21
+ static factories = new Map();
22
+ static {
23
+ // Register built-in providers
24
+ ProviderRegistry.register("json", async () => {
25
+ const dataDir = process.env[WEAVE_DATA_DIR_ENV] ?? DEFAULT_DATA_DIR;
26
+ return new JsonProvider(dataDir);
27
+ });
28
+ ProviderRegistry.register("memory", async () => new MemoryProvider());
29
+ }
30
+ /**
31
+ * Register a new provider factory under a named key.
32
+ * The key is normalised to lower-case before storing.
33
+ *
34
+ * @example
35
+ * // In weave-provider-sqlite:
36
+ * ProviderRegistry.register("sqlite", async () => new SqliteProvider(...));
37
+ */
38
+ static register(name, factory) {
39
+ ProviderRegistry.factories.set(name.toLowerCase(), factory);
40
+ }
41
+ /**
42
+ * Resolve and instantiate a provider.
43
+ *
44
+ * @param type Explicit provider type string. When omitted, reads
45
+ * `process.env.WEAVE_PROVIDER`. Defaults to `"json"`.
46
+ *
47
+ * @throws {UnknownProviderError} if the type is not registered.
48
+ */
49
+ static async resolve(type) {
50
+ const raw = (type ?? process.env[WEAVE_PROVIDER_ENV] ?? "json")
51
+ .trim()
52
+ .toLowerCase();
53
+ const factory = ProviderRegistry.factories.get(raw);
54
+ if (!factory)
55
+ throw new UnknownProviderError(raw);
56
+ return factory();
57
+ }
58
+ /**
59
+ * Returns the list of currently registered provider names.
60
+ * Useful for diagnostics and help text.
61
+ */
62
+ static available() {
63
+ return [...ProviderRegistry.factories.keys()].sort();
64
+ }
65
+ /**
66
+ * Remove a registered provider (mainly for test isolation).
67
+ */
68
+ static unregister(name) {
69
+ ProviderRegistry.factories.delete(name.toLowerCase());
70
+ }
71
+ }
72
+ /**
73
+ * Convenience function — resolve the default (or env-configured) provider.
74
+ *
75
+ * @example
76
+ * const provider = await resolveProvider<GraphSnapshot>();
77
+ * await provider.set("graph:my-session", snapshot);
78
+ */
79
+ export async function resolveProvider(type) {
80
+ return ProviderRegistry.resolve(type);
81
+ }
82
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,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,kBAAkB,CAAC,IAAI,gBAAgB,CAAC;YACpE,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,cAAc,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,kBAAkB,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,oBAAoB,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;;AAGH;;;;;;GAMG;AACH,MAAM,CAAC,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"}
package/dist/types.js ADDED
@@ -0,0 +1,57 @@
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
+ // Registry configuration
11
+ // ---------------------------------------------------------------------------
12
+ /**
13
+ * Environment variable that controls which provider the registry resolves.
14
+ *
15
+ * Accepted values (case-insensitive):
16
+ * - `"json"` (default) → JsonProvider
17
+ * - `"memory"` → MemoryProvider
18
+ * - `"sqlite"` / a file path → weave-provider-sqlite (separate package)
19
+ * - `"mongodb"` / a URI → weave-provider-mongodb (separate package)
20
+ * - `"postgres"` / a URI → weave-provider-postgres (separate package)
21
+ * - `"mysql"` / a URI → weave-provider-mysql (separate package)
22
+ */
23
+ export const WEAVE_PROVIDER_ENV = "WEAVE_PROVIDER";
24
+ /**
25
+ * Environment variable that controls the root data directory used by the
26
+ * JsonProvider (and, conventionally, any file-based provider).
27
+ */
28
+ export const WEAVE_DATA_DIR_ENV = "WEAVE_DATA_DIR";
29
+ /**
30
+ * Default data directory value when WEAVE_DATA_DIR is not set.
31
+ */
32
+ export const DEFAULT_DATA_DIR = "./weave-data";
33
+ // ---------------------------------------------------------------------------
34
+ // Error types
35
+ // ---------------------------------------------------------------------------
36
+ /**
37
+ * Thrown when a provider operation is invoked after `close()` has been called.
38
+ */
39
+ export class ProviderClosedError extends Error {
40
+ constructor(providerName) {
41
+ super(`[${providerName}] provider has been closed and is no longer usable`);
42
+ this.name = "ProviderClosedError";
43
+ }
44
+ }
45
+ /**
46
+ * Thrown when the registry cannot resolve a provider from the current
47
+ * environment configuration.
48
+ */
49
+ export class UnknownProviderError extends Error {
50
+ constructor(value) {
51
+ super(`[weave-provider] Unknown provider type "${value}". ` +
52
+ `Set ${WEAVE_PROVIDER_ENV}=json|memory or install the corresponding ` +
53
+ `weave-provider-* package.`);
54
+ this.name = "UnknownProviderError";
55
+ }
56
+ }
57
+ //# 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;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAE/C,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,YAAoB;QAC9B,KAAK,CAAC,IAAI,YAAY,oDAAoD,CAAC,CAAC;QAC5E,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,KAAa;QACvB,KAAK,CACH,2CAA2C,KAAK,KAAK;YACnD,OAAO,kBAAkB,4CAA4C;YACrE,2BAA2B,CAC9B,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@openweave/weave-provider",
3
+ "version": "0.8.0",
4
+ "description": "Storage-agnostic persistence contract for OpenWeave — IWeaveProvider<T> interface + built-in implementations",
5
+ "private": false,
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "files": [
11
+ "dist",
12
+ "README.md"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.js",
17
+ "types": "./dist/index.d.ts"
18
+ }
19
+ },
20
+ "keywords": [
21
+ "openweave",
22
+ "persistence",
23
+ "provider",
24
+ "storage"
25
+ ],
26
+ "devDependencies": {
27
+ "@types/node": "22.10.2",
28
+ "typescript": "5.7.2",
29
+ "vitest": "3.0.0"
30
+ },
31
+ "dependencies": {},
32
+ "scripts": {
33
+ "build": "tsc",
34
+ "dev": "tsc --watch",
35
+ "test": "vitest",
36
+ "lint": "eslint src --max-warnings 0",
37
+ "clean": "rm -rf dist"
38
+ }
39
+ }