@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 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