noxium 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.
@@ -0,0 +1,39 @@
1
+ import path from 'path';
2
+ import { existsSync } from 'fs';
3
+ import { RequiredConfigError } from './error.js';
4
+ import { createClient } from './createClient.js';
5
+
6
+ const configPath = path.resolve(process.cwd(), "noxium.config.ts");
7
+ if (!existsSync(configPath)) {
8
+ throw new RequiredConfigError();
9
+ }
10
+ const rawConfig = require(configPath).default;
11
+ const config = typeof rawConfig === "function" ? rawConfig() : rawConfig;
12
+ class Noxium {
13
+ orm;
14
+ constructor(schema){
15
+ this.orm = createClient(config, schema);
16
+ }
17
+ async insert(data) {
18
+ return await this.orm.insert(data);
19
+ }
20
+ async update(id, data) {
21
+ return await this.orm.update(id, data);
22
+ }
23
+ async findAll() {
24
+ return await this.orm.findAll();
25
+ }
26
+ async findUnique(data) {
27
+ const column = Object.keys(data)[0];
28
+ const value = data[column];
29
+ return await this.orm.findUnique(column, value);
30
+ }
31
+ async findMany(data) {
32
+ const column = Object.keys(data)[0];
33
+ const value = data[column];
34
+ return await this.orm.findMany(column, value);
35
+ }
36
+ }
37
+
38
+ export { Noxium };
39
+ //# sourceMappingURL=noxa.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noxa.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/dist/noxa.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { SchemaToType, TableSchema, UniqueWhere } from "./schema";
2
+ export declare class Noxium<Schema extends TableSchema> {
3
+ private orm;
4
+ constructor(schema?: Schema);
5
+ insert(data: SchemaToType<Schema>): Promise<void>;
6
+ update(id: any, data: Partial<SchemaToType<Schema>>): Promise<void>;
7
+ findAll(): Promise<SchemaToType<Schema>[]>;
8
+ findUnique<K extends keyof SchemaToType<Schema>>(data: UniqueWhere<Schema>): Promise<SchemaToType<Schema> | null>;
9
+ findMany<K extends keyof SchemaToType<Schema>>(data: {
10
+ [P in K]: SchemaToType<Schema>[P];
11
+ }): Promise<SchemaToType<Schema>[]>;
12
+ }
@@ -0,0 +1,38 @@
1
+ type ColumnType = "int" | "text";
2
+ interface Column<Name extends string = string> {
3
+ name: Name;
4
+ type: ColumnType;
5
+ unique?: boolean;
6
+ required?: boolean;
7
+ }
8
+ export interface TableSchema<Name extends string = string, Cols extends readonly Column[] = readonly Column[]> {
9
+ name: Name;
10
+ columns: Cols;
11
+ }
12
+ export type SchemaToType<S extends TableSchema> = {
13
+ [C in Extract<S["columns"][number], {
14
+ required: true;
15
+ }> as C["name"]]: C["type"] extends "int" ? number : C["type"] extends "text" ? string : never;
16
+ } & {
17
+ [C in Exclude<S["columns"][number], {
18
+ required: true;
19
+ }> as C["name"]]?: C["type"] extends "int" ? number : C["type"] extends "text" ? string : never;
20
+ } & {
21
+ [key: string]: any;
22
+ };
23
+ export type UniqueKeys<S extends TableSchema> = Extract<S["columns"][number], {
24
+ unique: true;
25
+ }>["name"];
26
+ export type UniqueWhere<S extends TableSchema> = {
27
+ [K in UniqueKeys<S>]: {
28
+ [P in K]: SchemaToType<S>[P];
29
+ };
30
+ }[UniqueKeys<S>];
31
+ export interface NoxiumClient<T> {
32
+ insert(data: T): Promise<void>;
33
+ update(id: any, data: Partial<T>): Promise<void>;
34
+ findAll(): Promise<T[]>;
35
+ findUnique<K extends keyof T>(column: K, value: T[K]): Promise<T | null>;
36
+ findMany<K extends keyof T>(column: K, value: T[K]): Promise<T[]>;
37
+ }
38
+ export {};
package/mydb.sqlite ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "noxium",
3
+ "version": "1.0.0",
4
+ "description": "Unified ORM for SQLite and MongoDB with TypeScript",
5
+ "main": "./dist/cjs/noxium.cjs",
6
+ "module": "./dist/esm/noxium.js",
7
+ "types": "./dist/noxium.d.ts",
8
+ "type": "module",
9
+ "exports": {
10
+ ".": {
11
+ "require": "./dist/cjs/noxium.cjs",
12
+ "import": "./dist/esm/noxium.js",
13
+ "types": "./dist/noxium.d.ts"
14
+ },
15
+ "./drivers/mongo": {
16
+ "require": "./dist/cjs/drivers/mongo.cjs",
17
+ "import": "./dist/esm/drivers/mongo.js",
18
+ "types": "./dist/drivers/mongo.d.ts"
19
+ },
20
+ "./drivers/sqlite": {
21
+ "require": "./dist/cjs/drivers/sqlite.cjs",
22
+ "import": "./dist/esm/drivers/sqlite.js",
23
+ "types": "./dist/drivers/sqlite.d.ts"
24
+ },
25
+ "./config": {
26
+ "require": "./dist/cjs/config.cjs",
27
+ "import": "./dist/esm/config.js",
28
+ "types": "./dist/config.d.ts"
29
+ },
30
+ "./error": {
31
+ "require": "./dist/cjs/error.cjs",
32
+ "import": "./dist/esm/error.js",
33
+ "types": "./dist/error.d.ts"
34
+ },
35
+ "./schema": {
36
+ "require": "./dist/cjs/schema.cjs",
37
+ "import": "./dist/esm/schema.js",
38
+ "types": "./dist/schema.d.ts"
39
+ }
40
+ },
41
+ "scripts": {
42
+ "build:esm": "tsc",
43
+ "build:cjs": "rollup -c rollup.config.mjs",
44
+ "build": "bun run build:esm && bun run build:cjs"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/ayiin-dev/noxium.git"
49
+ },
50
+ "bugs": {
51
+ "url": "https://github.com/ayiin-dev/noxium/issues"
52
+ },
53
+ "homepage": "https://github.com/ayiin-dev/noxium#readme",
54
+ "keywords": [
55
+ "orm",
56
+ "sqlite",
57
+ "mongodb",
58
+ "typescript",
59
+ "database"
60
+ ],
61
+ "license": "MIT",
62
+ "devDependencies": {
63
+ "@types/better-sqlite3": "^9.6.0",
64
+ "@types/bun": "^1.4.0"
65
+ },
66
+ "peerDependencies": {
67
+ "typescript": "^7.0.2"
68
+ },
69
+ "dependencies": {
70
+ "better-sqlite3": "^13.0.3",
71
+ "mongoose": "^9.9.4",
72
+ "rollup": "^4.63.1",
73
+ "rollup-plugin-swc3": "^0.12.1"
74
+ }
75
+ }