noxium 1.0.2 → 1.0.5

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.
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var Database = require('better-sqlite3');
4
- var drivers_sqlite = require('./drivers/sqlite.cjs');
5
- var drivers_mongo = require('./drivers/mongo.cjs');
4
+ var mongo = require('./drivers/mongo.cjs');
5
+ var sqlite = require('./drivers/sqlite.cjs');
6
6
  var error = require('./error.cjs');
7
7
 
8
8
  /**
@@ -17,7 +17,7 @@ var error = require('./error.cjs');
17
17
  }
18
18
  if (!schema) throw new error.InvalidConfigError("SQLite membutuhkan schema.");
19
19
  const db = new Database(dbConfig.sqlite.path);
20
- return new drivers_sqlite.NoxiumSqlite(db, schema);
20
+ return new sqlite.NoxiumSqlite(db, schema);
21
21
  }
22
22
  case "mongo":
23
23
  {
@@ -26,7 +26,7 @@ var error = require('./error.cjs');
26
26
  throw new error.InvalidConfigError("Konfigurasi MongoDB tidak valid: field `uri` wajib diisi.");
27
27
  }
28
28
  if (!schema) throw new error.InvalidConfigError("Mongo membutuhkan schema.");
29
- return new drivers_mongo.NoxiumMongo(schema, dbConfig);
29
+ return new mongo.NoxiumMongo(schema, dbConfig);
30
30
  }
31
31
  case "postgres":
32
32
  {
@@ -52,4 +52,3 @@ var error = require('./error.cjs');
52
52
  }
53
53
 
54
54
  exports.createClient = createClient;
55
- //# sourceMappingURL=createClient.cjs.map
@@ -4,23 +4,6 @@ var mongoose = require('mongoose');
4
4
  var error = require('../error.cjs');
5
5
 
6
6
  class NoxiumMongo {
7
- model;
8
- constructor(schema, config){
9
- mongoose.connect(config.mongo.uri, {
10
- dbName: config.mongo.dbName ?? "test"
11
- });
12
- // generate definisi schema mongoose
13
- const mongooseSchemaDef = {};
14
- for (const col of schema.columns){
15
- const def = {};
16
- def.type = col.type === "int" ? Number : String;
17
- if (col.required) def.required = true;
18
- if (col.unique) def.unique = true;
19
- mongooseSchemaDef[col.name] = def;
20
- }
21
- const mongooseSchema = new mongoose.Schema(mongooseSchemaDef);
22
- this.model = mongoose.model(schema.name, mongooseSchema);
23
- }
24
7
  async insert(data) {
25
8
  try {
26
9
  const doc = new this.model(data);
@@ -57,7 +40,22 @@ class NoxiumMongo {
57
40
  [column]: value
58
41
  }).exec();
59
42
  }
43
+ constructor(schema, config){
44
+ mongoose.connect(config.mongo.uri, {
45
+ dbName: config.mongo.dbName ?? "test"
46
+ });
47
+ // generate definisi schema mongoose
48
+ const mongooseSchemaDef = {};
49
+ for (const col of schema.columns){
50
+ const def = {};
51
+ def.type = col.type === "int" ? Number : String;
52
+ if (col.required) def.required = true;
53
+ if (col.unique) def.unique = true;
54
+ mongooseSchemaDef[col.name] = def;
55
+ }
56
+ const mongooseSchema = new mongoose.Schema(mongooseSchemaDef);
57
+ this.model = mongoose.model(schema.name, mongooseSchema);
58
+ }
60
59
  }
61
60
 
62
61
  exports.NoxiumMongo = NoxiumMongo;
63
- //# sourceMappingURL=mongo.cjs.map
@@ -3,13 +3,6 @@
3
3
  var error = require('../error.cjs');
4
4
 
5
5
  class NoxiumSqlite {
6
- db;
7
- schema;
8
- constructor(db, schema){
9
- this.db = db;
10
- this.schema = schema;
11
- this.createTable(); // ✅ otomatis buat table saat instance dibuat
12
- }
13
6
  createTable() {
14
7
  const cols = this.schema.columns.map((c)=>{
15
8
  let def = `${c.name} ${c.type.toUpperCase()}`;
@@ -71,7 +64,11 @@ class NoxiumSqlite {
71
64
  const stmt = this.db.prepare(`SELECT * FROM ${this.schema.name} WHERE ${column} = ?`);
72
65
  return stmt.all(value);
73
66
  }
67
+ constructor(db, schema){
68
+ this.db = db;
69
+ this.schema = schema;
70
+ this.createTable(); // ✅ otomatis buat table saat instance dibuat
71
+ }
74
72
  }
75
73
 
76
74
  exports.NoxiumSqlite = NoxiumSqlite;
77
- //# sourceMappingURL=sqlite.cjs.map
@@ -2,8 +2,6 @@
2
2
 
3
3
  // errors.ts
4
4
  class DuplicateError extends Error {
5
- column;
6
- value;
7
5
  constructor(column, value){
8
6
  super(`Duplicate unique value: ${column} = ${value}`);
9
7
  this.name = "DuplicateError";
@@ -12,7 +10,6 @@ class DuplicateError extends Error {
12
10
  }
13
11
  }
14
12
  class ValidationError extends Error {
15
- column;
16
13
  constructor(column){
17
14
  super(`Missing required field: ${column}`);
18
15
  this.name = "ValidationError";
@@ -47,4 +44,3 @@ exports.DuplicateError = DuplicateError;
47
44
  exports.InvalidConfigError = InvalidConfigError;
48
45
  exports.RequiredConfigError = RequiredConfigError;
49
46
  exports.ValidationError = ValidationError;
50
- //# sourceMappingURL=error.cjs.map
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var path = require('path');
4
3
  var fs = require('fs');
5
- var error = require('./error.cjs');
4
+ var path = require('path');
6
5
  var createClient = require('./createClient.cjs');
6
+ var error = require('./error.cjs');
7
7
 
8
8
  const configPath = path.resolve(process.cwd(), "noxium.config.ts");
9
9
  if (!fs.existsSync(configPath)) {
@@ -12,10 +12,6 @@ if (!fs.existsSync(configPath)) {
12
12
  const rawConfig = require(configPath).default;
13
13
  const config = typeof rawConfig === "function" ? rawConfig() : rawConfig;
14
14
  class Noxium {
15
- orm;
16
- constructor(schema){
17
- this.orm = createClient.createClient(config, schema);
18
- }
19
15
  async insert(data) {
20
16
  return await this.orm.insert(data);
21
17
  }
@@ -35,7 +31,9 @@ class Noxium {
35
31
  const value = data[column];
36
32
  return await this.orm.findMany(column, value);
37
33
  }
34
+ constructor(schema){
35
+ this.orm = createClient.createClient(config, schema);
36
+ }
38
37
  }
39
38
 
40
39
  exports.Noxium = Noxium;
41
- //# sourceMappingURL=noxium.cjs.map
@@ -1,3 +1,2 @@
1
1
  'use strict';
2
2
 
3
- //# sourceMappingURL=schema.cjs.map
@@ -1,6 +1,6 @@
1
1
  import Database from 'better-sqlite3';
2
- import { NoxiumSqlite } from './drivers/sqlite.js';
3
2
  import { NoxiumMongo } from './drivers/mongo.js';
3
+ import { NoxiumSqlite } from './drivers/sqlite.js';
4
4
  import { InvalidConfigError } from './error.js';
5
5
 
6
6
  /**
@@ -50,4 +50,3 @@ import { InvalidConfigError } from './error.js';
50
50
  }
51
51
 
52
52
  export { createClient };
53
- //# sourceMappingURL=createClient.js.map
@@ -2,23 +2,6 @@ import mongoose, { Schema } from 'mongoose';
2
2
  import { DuplicateError, ValidationError } from '../error.js';
3
3
 
4
4
  class NoxiumMongo {
5
- model;
6
- constructor(schema, config){
7
- mongoose.connect(config.mongo.uri, {
8
- dbName: config.mongo.dbName ?? "test"
9
- });
10
- // generate definisi schema mongoose
11
- const mongooseSchemaDef = {};
12
- for (const col of schema.columns){
13
- const def = {};
14
- def.type = col.type === "int" ? Number : String;
15
- if (col.required) def.required = true;
16
- if (col.unique) def.unique = true;
17
- mongooseSchemaDef[col.name] = def;
18
- }
19
- const mongooseSchema = new Schema(mongooseSchemaDef);
20
- this.model = mongoose.model(schema.name, mongooseSchema);
21
- }
22
5
  async insert(data) {
23
6
  try {
24
7
  const doc = new this.model(data);
@@ -55,7 +38,22 @@ class NoxiumMongo {
55
38
  [column]: value
56
39
  }).exec();
57
40
  }
41
+ constructor(schema, config){
42
+ mongoose.connect(config.mongo.uri, {
43
+ dbName: config.mongo.dbName ?? "test"
44
+ });
45
+ // generate definisi schema mongoose
46
+ const mongooseSchemaDef = {};
47
+ for (const col of schema.columns){
48
+ const def = {};
49
+ def.type = col.type === "int" ? Number : String;
50
+ if (col.required) def.required = true;
51
+ if (col.unique) def.unique = true;
52
+ mongooseSchemaDef[col.name] = def;
53
+ }
54
+ const mongooseSchema = new Schema(mongooseSchemaDef);
55
+ this.model = mongoose.model(schema.name, mongooseSchema);
56
+ }
58
57
  }
59
58
 
60
59
  export { NoxiumMongo };
61
- //# sourceMappingURL=mongo.js.map
@@ -1,13 +1,6 @@
1
1
  import { ValidationError, DuplicateError } from '../error.js';
2
2
 
3
3
  class NoxiumSqlite {
4
- db;
5
- schema;
6
- constructor(db, schema){
7
- this.db = db;
8
- this.schema = schema;
9
- this.createTable(); // ✅ otomatis buat table saat instance dibuat
10
- }
11
4
  createTable() {
12
5
  const cols = this.schema.columns.map((c)=>{
13
6
  let def = `${c.name} ${c.type.toUpperCase()}`;
@@ -69,7 +62,11 @@ class NoxiumSqlite {
69
62
  const stmt = this.db.prepare(`SELECT * FROM ${this.schema.name} WHERE ${column} = ?`);
70
63
  return stmt.all(value);
71
64
  }
65
+ constructor(db, schema){
66
+ this.db = db;
67
+ this.schema = schema;
68
+ this.createTable(); // ✅ otomatis buat table saat instance dibuat
69
+ }
72
70
  }
73
71
 
74
72
  export { NoxiumSqlite };
75
- //# sourceMappingURL=sqlite.js.map
package/dist/esm/error.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // errors.ts
2
2
  class DuplicateError extends Error {
3
- column;
4
- value;
5
3
  constructor(column, value){
6
4
  super(`Duplicate unique value: ${column} = ${value}`);
7
5
  this.name = "DuplicateError";
@@ -10,7 +8,6 @@ class DuplicateError extends Error {
10
8
  }
11
9
  }
12
10
  class ValidationError extends Error {
13
- column;
14
11
  constructor(column){
15
12
  super(`Missing required field: ${column}`);
16
13
  this.name = "ValidationError";
@@ -42,4 +39,3 @@ class InvalidConfigError extends Error {
42
39
  }
43
40
 
44
41
  export { DuplicateError, InvalidConfigError, RequiredConfigError, ValidationError };
45
- //# sourceMappingURL=error.js.map
@@ -1,7 +1,7 @@
1
- import path from 'path';
2
1
  import { existsSync } from 'fs';
3
- import { RequiredConfigError } from './error.js';
2
+ import path from 'path';
4
3
  import { createClient } from './createClient.js';
4
+ import { RequiredConfigError } from './error.js';
5
5
 
6
6
  const configPath = path.resolve(process.cwd(), "noxium.config.ts");
7
7
  if (!existsSync(configPath)) {
@@ -10,10 +10,6 @@ if (!existsSync(configPath)) {
10
10
  const rawConfig = require(configPath).default;
11
11
  const config = typeof rawConfig === "function" ? rawConfig() : rawConfig;
12
12
  class Noxium {
13
- orm;
14
- constructor(schema){
15
- this.orm = createClient(config, schema);
16
- }
17
13
  async insert(data) {
18
14
  return await this.orm.insert(data);
19
15
  }
@@ -33,7 +29,9 @@ class Noxium {
33
29
  const value = data[column];
34
30
  return await this.orm.findMany(column, value);
35
31
  }
32
+ constructor(schema){
33
+ this.orm = createClient(config, schema);
34
+ }
36
35
  }
37
36
 
38
37
  export { Noxium };
39
- //# sourceMappingURL=noxium.js.map
@@ -1,2 +1 @@
1
1
 
2
- //# sourceMappingURL=schema.js.map
package/package.json CHANGED
@@ -1,41 +1,33 @@
1
1
  {
2
2
  "name": "noxium",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "description": "Unified ORM for SQLite and MongoDB with TypeScript",
5
5
  "main": "./dist/cjs/noxium.cjs",
6
6
  "module": "./dist/esm/noxium.js",
7
- "types": "./dist/esm/noxium.d.ts",
7
+ "types": "./dist/src/noxium.d.ts",
8
8
  "type": "module",
9
9
  "exports": {
10
10
  ".": {
11
- "require": "./dist/cjs/noxium.cjs",
12
- "import": "./dist/esm/noxium.js"
13
- },
14
- "./drivers/mongo": {
15
- "require": "./dist/cjs/drivers/mongo.cjs",
16
- "import": "./dist/esm/drivers/mongo.js"
17
- },
18
- "./drivers/sqlite": {
19
- "require": "./dist/cjs/drivers/sqlite.cjs",
20
- "import": "./dist/esm/drivers/sqlite.js"
21
- },
22
- "./config": {
23
- "require": "./dist/cjs/config.cjs",
24
- "import": "./dist/esm/config.js"
25
- },
26
- "./error": {
27
- "require": "./dist/cjs/error.cjs",
28
- "import": "./dist/esm/error.js"
29
- },
30
- "./schema": {
31
- "require": "./dist/cjs/schema.cjs",
32
- "import": "./dist/esm/schema.js"
11
+ "types": {
12
+ "require": "./dist/src/noxium.d.cts",
13
+ "default": "./dist/src/noxium.d.ts"
14
+ },
15
+ "import": {
16
+ "default": "./dist/esm/noxium.js",
17
+ "require": "./dist/cjs/noxium.cjs"
18
+ },
19
+ "require": {
20
+ "default": "./dist/esm/noxium.js",
21
+ "require": "./dist/cjs/noxium.cjs"
22
+ },
23
+ "default": {
24
+ "require": "./dist/cjs/noxium.cjs",
25
+ "default": "./dist/esm/noxium.js"
26
+ }
33
27
  }
34
28
  },
35
29
  "scripts": {
36
- "build:esm": "tsc",
37
- "build:cjs": "rollup -c rollup.config.mjs",
38
- "build": "bun run build:esm && bun run build:cjs"
30
+ "build": "rollup -c rollup.config.mjs"
39
31
  },
40
32
  "repository": {
41
33
  "type": "git",
@@ -55,15 +47,21 @@
55
47
  "license": "MIT",
56
48
  "devDependencies": {
57
49
  "@types/better-sqlite3": "^9.6.0",
58
- "@types/bun": "^1.4.0"
50
+ "@types/bun": "^1.4.0",
51
+ "@typescript/typescript6": "^6.0.2"
59
52
  },
60
53
  "peerDependencies": {
61
54
  "typescript": "^7.0.2"
62
55
  },
63
56
  "dependencies": {
57
+ "@rollup/plugin-commonjs": "^29.0.3",
58
+ "@rollup/plugin-json": "^6.1.0",
59
+ "@rollup/plugin-node-resolve": "^16.0.3",
60
+ "@rollup/plugin-swc": "^0.4.1",
64
61
  "better-sqlite3": "^13.0.3",
62
+ "glob": "^13.0.6",
65
63
  "mongoose": "^9.9.4",
66
64
  "rollup": "^4.63.1",
67
- "rollup-plugin-swc3": "^0.12.1"
65
+ "rollup-plugin-dts": "^6.5.1"
68
66
  }
69
67
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"createClient.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"mongo.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"sqlite.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"noxium.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -1,6 +0,0 @@
1
- import type { NoxiumClient, SchemaToType, TableSchema } from "./schema";
2
- import { NoxiumConfig } from "./config";
3
- /**
4
- * Validasi config dan kembalikan driver ORM sesuai type database
5
- */
6
- export declare function createClient<Schema extends TableSchema>(config: NoxiumConfig, schema?: Schema): NoxiumClient<SchemaToType<Schema>>;
@@ -1 +0,0 @@
1
- {"version":3,"file":"createClient.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,11 +0,0 @@
1
- import type { TableSchema, SchemaToType } from "../schema";
2
- import { MongoConfig } from "../config";
3
- export declare class NoxiumMongo<Schema extends TableSchema> {
4
- private model;
5
- constructor(schema: Schema, config: MongoConfig);
6
- insert(data: any): Promise<void>;
7
- update(id: any, data: any): Promise<void>;
8
- findAll(): Promise<any[]>;
9
- findUnique<K extends keyof SchemaToType<Schema>>(column: K, value: SchemaToType<Schema>[K]): Promise<any>;
10
- findMany<K extends keyof SchemaToType<Schema>>(column: K, value: SchemaToType<Schema>[K]): Promise<any[]>;
11
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"mongo.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,12 +0,0 @@
1
- import type { NoxiumClient, SchemaToType, TableSchema } from "../schema";
2
- export declare class NoxiumSqlite<Schema extends TableSchema> implements NoxiumClient<SchemaToType<Schema>> {
3
- private db;
4
- private schema;
5
- constructor(db: any, schema: Schema);
6
- private createTable;
7
- insert(data: SchemaToType<Schema>): Promise<void>;
8
- update(id: number, data: Partial<SchemaToType<Schema>>): Promise<void>;
9
- findAll(): Promise<any>;
10
- findUnique<K extends keyof SchemaToType<Schema>>(column: K, value: SchemaToType<Schema>[K]): Promise<any>;
11
- findMany<K extends keyof SchemaToType<Schema>>(column: K, value: SchemaToType<Schema>[K]): Promise<any>;
12
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"sqlite.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,15 +0,0 @@
1
- export declare class DuplicateError extends Error {
2
- column: string;
3
- value: any;
4
- constructor(column: string, value: any);
5
- }
6
- export declare class ValidationError extends Error {
7
- column: string;
8
- constructor(column: string);
9
- }
10
- export declare class RequiredConfigError extends Error {
11
- constructor();
12
- }
13
- export declare class InvalidConfigError extends Error {
14
- constructor(message: string);
15
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,12 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"noxium.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,38 +0,0 @@
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 {};
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}