@noormdev/sdk 1.0.0-alpha.9 → 1.0.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.
- package/LICENSE +21 -0
- package/README.md +81 -0
- package/dist/chunk-2RW4SL2O.js +97664 -0
- package/dist/chunk-D2XW2UOP.js +42 -0
- package/dist/chunk-DSXHOXDE.js +2591 -0
- package/dist/chunk-QAECL4RN.js +3372 -0
- package/dist/chunk-SPU42W75.js +13779 -0
- package/dist/chunk-TBRUDUBQ.js +1099 -0
- package/dist/chunk-UOFJT5PY.js +1499 -0
- package/dist/chunk-YJBKNUTP.js +7233 -0
- package/dist/csv-T5P3IN4K.js +7 -0
- package/dist/engine-S4DX3V33.js +11 -0
- package/dist/index.d.ts +3904 -2392
- package/dist/index.js +12980 -8777
- package/dist/json5-LNT3RGJ7.js +7 -0
- package/dist/mssql-NL6OHOMO.js +161 -0
- package/dist/{mysql-C2DR4TF7.js → mysql-5P43DYBY.js} +7 -4
- package/dist/{postgres-SIDJBSIT.js → postgres-NIL5BE3O.js} +7 -4
- package/dist/{sqlite-5VZTBN5J.js → sqlite-F3ZSSDUM.js} +5 -3
- package/dist/sqlite-bun-LMHUMGQI.js +60 -0
- package/dist/storage-6QBJ55SB.js +8 -0
- package/dist/yaml-XI7RQ2D5.js +7 -0
- package/package.json +7 -6
- package/dist/chunk-BMB5MF2T.js +0 -489
- package/dist/chunk-BMB5MF2T.js.map +0 -1
- package/dist/engine-HESCBITZ.js +0 -3
- package/dist/engine-HESCBITZ.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mssql-T4M7OGEC.js +0 -46
- package/dist/mssql-T4M7OGEC.js.map +0 -1
- package/dist/mysql-C2DR4TF7.js.map +0 -1
- package/dist/postgres-SIDJBSIT.js.map +0 -1
- package/dist/sqlite-5VZTBN5J.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Danilo Alonso
|
|
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,81 @@
|
|
|
1
|
+
# @noormdev/sdk
|
|
2
|
+
|
|
3
|
+
Type-safe programmatic access to a noorm-managed database. Wraps [Kysely](https://kysely.dev) with noorm's config resolution, change tracking, and access policy.
|
|
4
|
+
|
|
5
|
+
**[Documentation](https://noorm.dev)** | **[SDK Reference](https://noorm.dev/reference/sdk)** | **[Source](https://github.com/noormdev/noorm)**
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @noormdev/sdk kysely
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Install the driver for your dialect alongside it — `pg`, `mysql2`, `tedious` + `tarn`, or `better-sqlite3`. They are optional peer dependencies, so only the one you use needs to be present.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { createContext } from '@noormdev/sdk';
|
|
21
|
+
|
|
22
|
+
const ctx = await createContext<{ users: { id: number; name: string } }>({
|
|
23
|
+
config: 'dev',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
await ctx.connect();
|
|
27
|
+
|
|
28
|
+
// Query through Kysely
|
|
29
|
+
const users = await ctx.kysely
|
|
30
|
+
.selectFrom('users')
|
|
31
|
+
.select(['id', 'name'])
|
|
32
|
+
.execute();
|
|
33
|
+
|
|
34
|
+
// noorm operations live under their own namespace
|
|
35
|
+
await ctx.noorm.changes.ff();
|
|
36
|
+
|
|
37
|
+
await ctx.disconnect();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`createContext` resolves connection settings the same way the CLI does — defaults, then stage, then stored config, then `NOORM_CONNECTION_*` env vars, then explicit options — so the same code runs locally and in CI.
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## Testing
|
|
44
|
+
|
|
45
|
+
Pass `requireTest: true` and the context refuses to connect unless the resolved config is marked `isTest`. This makes it impossible for a test suite to point at production by accident.
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
const ctx = await createContext<Database>({
|
|
49
|
+
config: 'test',
|
|
50
|
+
requireTest: true,
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## Typed procedures, functions, and TVFs
|
|
56
|
+
|
|
57
|
+
Stored routines can be declared as `[Args, ReturnType]` tuples so return types are inferred at the call site, with the generic still available as an override.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
type Procs = {
|
|
61
|
+
get_users: [{ department_id: number }, User];
|
|
62
|
+
refresh_cache: void;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const ctx = await createContext<Database, Procs>({ config: 'dev' });
|
|
66
|
+
|
|
67
|
+
const users = await ctx.proc('get_users', { department_id: 1 }); // User[]
|
|
68
|
+
await ctx.proc('refresh_cache');
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`createContext<DB, Procs, Funcs, Tvfs>` takes a map per routine kind. Plain `void` is shorthand for "no arguments, no meaningful return".
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## Requires
|
|
75
|
+
|
|
76
|
+
Node >= 22.13. Supports **PostgreSQL**, **MySQL**, **SQLite**, and **SQL Server**.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT
|