@hozon/provider 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +30 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Paul Le Cam
|
|
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,15 @@
|
|
|
1
|
+
# @hozon/provider
|
|
2
|
+
|
|
3
|
+
Resolve a Node adapter or database from an adapter instance, SQLite path, or PostgreSQL URL.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm add @hozon/provider
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { resolveDB } from '@hozon/provider'
|
|
11
|
+
|
|
12
|
+
const db = resolveDB(':memory:')
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
See the [driver reference](../../docs/reference/drivers.md).
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Adapter } from '@hozon/adapter';
|
|
2
|
+
import type { HozonDBParams } from '@hozon/db';
|
|
3
|
+
import { HozonDB } from '@hozon/db';
|
|
4
|
+
export type { Adapter } from '@hozon/adapter';
|
|
5
|
+
export type AdapterInput = Adapter | string;
|
|
6
|
+
export type HozonDBInput = HozonDB | AdapterInput;
|
|
7
|
+
export declare function resolveAdapter(input: AdapterInput): Adapter;
|
|
8
|
+
export declare function resolveDB(input: HozonDBInput, params?: Omit<HozonDBParams, 'adapter'>): HozonDB;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HozonDB } from '@hozon/db';
|
|
2
|
+
import { NodeSQLiteAdapter } from '@hozon/node-sqlite';
|
|
3
|
+
import { PostgresAdapter } from '@hozon/postgres';
|
|
4
|
+
export function resolveAdapter(input) {
|
|
5
|
+
if (typeof input !== 'string') {
|
|
6
|
+
return input;
|
|
7
|
+
}
|
|
8
|
+
if (input === ':memory:') {
|
|
9
|
+
return new NodeSQLiteAdapter({
|
|
10
|
+
database: ':memory:'
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if (input.startsWith('postgres://') || input.startsWith('postgresql://')) {
|
|
14
|
+
return new PostgresAdapter({
|
|
15
|
+
url: input
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return new NodeSQLiteAdapter({
|
|
19
|
+
database: input
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function resolveDB(input, params = {}) {
|
|
23
|
+
if (input instanceof HozonDB) {
|
|
24
|
+
return input;
|
|
25
|
+
}
|
|
26
|
+
return new HozonDB({
|
|
27
|
+
...params,
|
|
28
|
+
adapter: resolveAdapter(input)
|
|
29
|
+
});
|
|
30
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hozon/provider",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Database adapter resolution for Hozon",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/TairuFramework/hozon.git",
|
|
8
|
+
"directory": "packages/provider"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"type": "module",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"lib/*"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@hozon/adapter": "^0.1.0",
|
|
21
|
+
"@hozon/db": "^0.1.0",
|
|
22
|
+
"@hozon/node-sqlite": "^0.1.0",
|
|
23
|
+
"@hozon/postgres": "^0.1.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^26.6.4",
|
|
27
|
+
"del-cli": "^7.0.0",
|
|
28
|
+
"vitest": "5.0.3"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=24"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
|
|
38
|
+
"build:clean": "del-cli lib",
|
|
39
|
+
"build:js": "del-cli \"lib/**/*.js\" && swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
|
|
40
|
+
"build:types": "del-cli \"lib/**/*.d.ts\" \"lib/**/*.d.ts.map\" && tsc --emitDeclarationOnly --skipLibCheck",
|
|
41
|
+
"build:types:ci": "tsc --emitDeclarationOnly --skipLibCheck --declarationMap false",
|
|
42
|
+
"test": "pnpm run test:types && pnpm run test:unit",
|
|
43
|
+
"test:types": "tsc --noEmit --skipLibCheck -p tsconfig.test.json",
|
|
44
|
+
"test:unit": "vitest run"
|
|
45
|
+
}
|
|
46
|
+
}
|