@semilayer/bridge-resolver 1.0.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 SemiLayer
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 ADDED
@@ -0,0 +1,104 @@
1
+ # @semilayer/bridge-resolver
2
+
3
+ Built-in bridge registry and runtime resolver for [SemiLayer](https://semilayer.com). Ships the first-party PostgreSQL adapter and provides an extension point for community and enterprise bridges.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @semilayer/bridge-resolver
9
+ # or
10
+ pnpm add @semilayer/bridge-resolver
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```typescript
16
+ import { resolveBridge } from '@semilayer/bridge-resolver'
17
+
18
+ // Resolve the built-in Postgres bridge
19
+ const PostgresBridge = resolveBridge('@semilayer/bridge-postgres')
20
+ const bridge = new PostgresBridge({ url: process.env.DATABASE_URL })
21
+ await bridge.connect()
22
+ ```
23
+
24
+ ## Community Bridges
25
+
26
+ Community bridges are registered at startup via `registerBridge()`. They do not need to be merged into this package to be used.
27
+
28
+ ```typescript
29
+ import { registerBridge, resolveBridge } from '@semilayer/bridge-resolver'
30
+ import { MySQLBridge } from '@community/bridge-mysql'
31
+ import { MongoBridge } from '@community/bridge-mongo'
32
+
33
+ // Register at worker startup, before the first ingest job runs
34
+ registerBridge('@community/bridge-mysql', MySQLBridge)
35
+ registerBridge('@community/bridge-mongo', MongoBridge)
36
+
37
+ // ...later, the resolver finds them by name
38
+ const Ctor = resolveBridge('@community/bridge-mysql')
39
+ ```
40
+
41
+ Custom bridges take priority over built-ins with the same name — useful for testing or overriding behavior in enterprise deployments.
42
+
43
+ ## API
44
+
45
+ ### `resolveBridge(name): BridgeConstructor`
46
+
47
+ Looks up a bridge by name. Checks custom registrations first, then built-in bridges. Throws if no bridge matches the given name.
48
+
49
+ ### `registerBridge(name, ctor): void`
50
+
51
+ Registers a bridge constructor under a name. The name is the identifier users reference in their SemiLayer config (`sources.main.bridge = '@community/bridge-mysql'`).
52
+
53
+ ### `listBridges(): string[]`
54
+
55
+ Returns all registered bridge names (built-in + custom), deduplicated.
56
+
57
+ ### `clearCustomBridges(): void`
58
+
59
+ Removes all custom bridges. Built-in bridges remain registered. Primarily useful in tests.
60
+
61
+ ## Built-in Bridges
62
+
63
+ | Name | Package | Database |
64
+ |------|---------|----------|
65
+ | `@semilayer/bridge-postgres` | [`@semilayer/bridge-postgres`](https://github.com/semilayer/bridge-postgres) | PostgreSQL (and wire-compatible variants — Neon, Supabase, CockroachDB, ...) |
66
+
67
+ More first-party bridges will be added over time. See [CONTRIBUTING.md](./CONTRIBUTING.md) for the process to propose adding a new bridge to the built-in registry.
68
+
69
+ ## Writing a New Bridge
70
+
71
+ See the [bridge authoring guide](https://semilayer.dev/guides/bridges) and the [`@semilayer/bridge-postgres`](https://github.com/semilayer/bridge-postgres) reference implementation.
72
+
73
+ Every bridge must:
74
+
75
+ 1. Implement the `Bridge` interface from `@semilayer/core`
76
+ 2. Pass the compliance test suite from `@semilayer/bridge-sdk`:
77
+ ```typescript
78
+ import { createBridgeTestSuite } from '@semilayer/bridge-sdk'
79
+ import { MyBridge } from './src/index.js'
80
+
81
+ createBridgeTestSuite(() => new MyBridge({ /* config */ }))
82
+ ```
83
+ 3. Publish to npm as its own package — either under your own scope (`@acme/bridge-mydb`) or request the `@semilayer` scope if it becomes first-party
84
+
85
+ You **do not** need to PR into this repo to publish a community bridge. Publish your package and users can register it with `registerBridge()` at runtime.
86
+
87
+ If you want your bridge to ship as a built-in (so users don't need to call `registerBridge()`), open an issue here first to discuss. We're selective about what lands in the built-in registry.
88
+
89
+ ## Requirements
90
+
91
+ - Node.js 20+
92
+ - `@semilayer/core` (peer-compatible version)
93
+ - `@semilayer/bridge-postgres` (bundled as a dependency)
94
+
95
+ ## Links
96
+
97
+ - [SemiLayer documentation](https://semilayer.dev)
98
+ - [Bridge authoring guide](https://semilayer.dev/guides/bridges)
99
+ - [`@semilayer/bridge-postgres`](https://github.com/semilayer/bridge-postgres) — reference implementation
100
+ - [Contributing](./CONTRIBUTING.md)
101
+
102
+ ## License
103
+
104
+ MIT © SemiLayer
@@ -0,0 +1,35 @@
1
+ import { BridgeConstructor } from '@semilayer/core';
2
+
3
+ /**
4
+ * Register a custom bridge at runtime.
5
+ *
6
+ * Used to add community or enterprise bridges to the resolver without
7
+ * modifying the built-in registry. Custom bridges take priority over
8
+ * built-in bridges with the same name.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { registerBridge } from '@semilayer/bridge-resolver'
13
+ * import { MySQLBridge } from '@community/bridge-mysql'
14
+ *
15
+ * registerBridge('@community/bridge-mysql', MySQLBridge)
16
+ * ```
17
+ */
18
+ declare function registerBridge(name: string, ctor: BridgeConstructor): void;
19
+ /**
20
+ * Clear all custom bridges (useful in tests).
21
+ */
22
+ declare function clearCustomBridges(): void;
23
+ /**
24
+ * Resolve a bridge constructor by name.
25
+ * Checks custom bridges first, then built-in registry.
26
+ *
27
+ * @throws if the bridge is not registered
28
+ */
29
+ declare function resolveBridge(name: string): BridgeConstructor;
30
+ /**
31
+ * List all available bridge names (built-in + custom).
32
+ */
33
+ declare function listBridges(): string[];
34
+
35
+ export { clearCustomBridges, listBridges, registerBridge, resolveBridge };
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
1
+ // src/index.ts
2
+ import { PostgresBridge } from "@semilayer/bridge-postgres";
3
+ var BUILT_IN_BRIDGES = {
4
+ "@semilayer/bridge-postgres": PostgresBridge
5
+ };
6
+ var customBridges = {};
7
+ function registerBridge(name, ctor) {
8
+ customBridges[name] = ctor;
9
+ }
10
+ function clearCustomBridges() {
11
+ customBridges = {};
12
+ }
13
+ function resolveBridge(name) {
14
+ const Ctor = customBridges[name] ?? BUILT_IN_BRIDGES[name];
15
+ if (!Ctor) {
16
+ const available = [
17
+ ...Object.keys(BUILT_IN_BRIDGES),
18
+ ...Object.keys(customBridges)
19
+ ].join(", ");
20
+ throw new Error(`Unknown bridge: "${name}". Available: ${available}`);
21
+ }
22
+ return Ctor;
23
+ }
24
+ function listBridges() {
25
+ return [.../* @__PURE__ */ new Set([...Object.keys(BUILT_IN_BRIDGES), ...Object.keys(customBridges)])];
26
+ }
27
+ export {
28
+ clearCustomBridges,
29
+ listBridges,
30
+ registerBridge,
31
+ resolveBridge
32
+ };
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { BridgeConstructor } from '@semilayer/core'\nimport { PostgresBridge } from '@semilayer/bridge-postgres'\n\nconst BUILT_IN_BRIDGES: Record<string, BridgeConstructor> = {\n '@semilayer/bridge-postgres': PostgresBridge,\n}\n\nlet customBridges: Record<string, BridgeConstructor> = {}\n\n/**\n * Register a custom bridge at runtime.\n *\n * Used to add community or enterprise bridges to the resolver without\n * modifying the built-in registry. Custom bridges take priority over\n * built-in bridges with the same name.\n *\n * @example\n * ```ts\n * import { registerBridge } from '@semilayer/bridge-resolver'\n * import { MySQLBridge } from '@community/bridge-mysql'\n *\n * registerBridge('@community/bridge-mysql', MySQLBridge)\n * ```\n */\nexport function registerBridge(name: string, ctor: BridgeConstructor): void {\n customBridges[name] = ctor\n}\n\n/**\n * Clear all custom bridges (useful in tests).\n */\nexport function clearCustomBridges(): void {\n customBridges = {}\n}\n\n/**\n * Resolve a bridge constructor by name.\n * Checks custom bridges first, then built-in registry.\n *\n * @throws if the bridge is not registered\n */\nexport function resolveBridge(name: string): BridgeConstructor {\n const Ctor = customBridges[name] ?? BUILT_IN_BRIDGES[name]\n if (!Ctor) {\n const available = [\n ...Object.keys(BUILT_IN_BRIDGES),\n ...Object.keys(customBridges),\n ].join(', ')\n throw new Error(`Unknown bridge: \"${name}\". Available: ${available}`)\n }\n return Ctor\n}\n\n/**\n * List all available bridge names (built-in + custom).\n */\nexport function listBridges(): string[] {\n return [...new Set([...Object.keys(BUILT_IN_BRIDGES), ...Object.keys(customBridges)])]\n}\n"],"mappings":";AACA,SAAS,sBAAsB;AAE/B,IAAM,mBAAsD;AAAA,EAC1D,8BAA8B;AAChC;AAEA,IAAI,gBAAmD,CAAC;AAiBjD,SAAS,eAAe,MAAc,MAA+B;AAC1E,gBAAc,IAAI,IAAI;AACxB;AAKO,SAAS,qBAA2B;AACzC,kBAAgB,CAAC;AACnB;AAQO,SAAS,cAAc,MAAiC;AAC7D,QAAM,OAAO,cAAc,IAAI,KAAK,iBAAiB,IAAI;AACzD,MAAI,CAAC,MAAM;AACT,UAAM,YAAY;AAAA,MAChB,GAAG,OAAO,KAAK,gBAAgB;AAAA,MAC/B,GAAG,OAAO,KAAK,aAAa;AAAA,IAC9B,EAAE,KAAK,IAAI;AACX,UAAM,IAAI,MAAM,oBAAoB,IAAI,iBAAiB,SAAS,EAAE;AAAA,EACtE;AACA,SAAO;AACT;AAKO,SAAS,cAAwB;AACtC,SAAO,CAAC,GAAG,oBAAI,IAAI,CAAC,GAAG,OAAO,KAAK,gBAAgB,GAAG,GAAG,OAAO,KAAK,aAAa,CAAC,CAAC,CAAC;AACvF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@semilayer/bridge-resolver",
3
+ "version": "1.0.0",
4
+ "description": "SemiLayer bridge resolver — built-in registry and dynamic bridge loading for first-party and community database adapters",
5
+ "keywords": [
6
+ "semilayer",
7
+ "bridge",
8
+ "resolver",
9
+ "registry",
10
+ "adapter"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "SemiLayer",
14
+ "homepage": "https://github.com/semilayer/bridge-resolver#readme",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/semilayer/bridge-resolver.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/semilayer/bridge-resolver/issues"
21
+ },
22
+ "type": "module",
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "scripts": {
37
+ "build": "tsup",
38
+ "dev": "tsup --watch",
39
+ "lint": "eslint src/",
40
+ "typecheck": "tsc --noEmit",
41
+ "test": "vitest run",
42
+ "test:watch": "vitest",
43
+ "prepublishOnly": "npm run build"
44
+ },
45
+ "dependencies": {
46
+ "@semilayer/bridge-postgres": "^1.0.0",
47
+ "@semilayer/core": "^0.1.0"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^20.0.0",
51
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
52
+ "@typescript-eslint/parser": "^8.0.0",
53
+ "eslint": "^9.0.0",
54
+ "tsup": "^8.0.0",
55
+ "typescript": "^5.7.0",
56
+ "vitest": "^3.0.0"
57
+ },
58
+ "engines": {
59
+ "node": ">=22.0.0"
60
+ },
61
+ "publishConfig": {
62
+ "access": "public",
63
+ "provenance": true
64
+ }
65
+ }