@neupgroup/mapper 1.2.1 → 1.2.2
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/README.md +705 -36
- package/dist/config-wrapper.d.ts +6 -0
- package/dist/config-wrapper.js +7 -0
- package/dist/config.d.ts +68 -0
- package/dist/config.js +234 -0
- package/dist/fluent-mapper.d.ts +80 -0
- package/dist/fluent-mapper.js +171 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/mapper.d.ts +27 -0
- package/dist/mapper.js +144 -0
- package/dist/orm/index.d.ts +2 -2
- package/dist/orm/types.d.ts +1 -1
- package/package.json +5 -2
package/dist/mapper.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Connections, SchemaManager } from './index';
|
|
2
|
+
export class Mapper {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.connections = new Connections();
|
|
5
|
+
this.schemaManager = new SchemaManager(this.connections);
|
|
6
|
+
}
|
|
7
|
+
static getInstance() {
|
|
8
|
+
if (!Mapper.instance) {
|
|
9
|
+
Mapper.instance = new Mapper();
|
|
10
|
+
}
|
|
11
|
+
return Mapper.instance;
|
|
12
|
+
}
|
|
13
|
+
// Auto-configuration based on environment or defaults
|
|
14
|
+
autoConfigure() {
|
|
15
|
+
// Check for environment variables or config files
|
|
16
|
+
const envConfig = this.detectEnvironmentConfig();
|
|
17
|
+
if (envConfig) {
|
|
18
|
+
this.applyConfig(envConfig);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// Use sensible defaults
|
|
22
|
+
this.applyDefaultConfig();
|
|
23
|
+
}
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
detectEnvironmentConfig() {
|
|
27
|
+
// Check for common environment variables or config files
|
|
28
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
29
|
+
// Node.js environment
|
|
30
|
+
const dbUrl = process.env.DATABASE_URL;
|
|
31
|
+
if (dbUrl) {
|
|
32
|
+
return {
|
|
33
|
+
connection: {
|
|
34
|
+
name: 'default',
|
|
35
|
+
type: this.inferConnectionType(dbUrl),
|
|
36
|
+
key: { url: dbUrl }
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Check for browser environment with global config
|
|
42
|
+
if (typeof window !== 'undefined' && window.__MAPPER_CONFIG__) {
|
|
43
|
+
return window.__MAPPER_CONFIG__;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
inferConnectionType(url) {
|
|
48
|
+
if (url.includes('mysql'))
|
|
49
|
+
return 'mysql';
|
|
50
|
+
if (url.includes('postgres') || url.includes('postgresql'))
|
|
51
|
+
return 'sql';
|
|
52
|
+
if (url.includes('mongodb'))
|
|
53
|
+
return 'mongodb';
|
|
54
|
+
if (url.includes('firestore'))
|
|
55
|
+
return 'firestore';
|
|
56
|
+
return 'api';
|
|
57
|
+
}
|
|
58
|
+
applyConfig(config) {
|
|
59
|
+
if (config.connection) {
|
|
60
|
+
const conn = config.connection;
|
|
61
|
+
this.connections.create(conn.name, conn.type).key(conn.key);
|
|
62
|
+
}
|
|
63
|
+
if (config.schemas) {
|
|
64
|
+
for (const schemaConfig of config.schemas) {
|
|
65
|
+
this.createSchema(schemaConfig);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
applyDefaultConfig() {
|
|
70
|
+
// Create a default in-memory connection for quick start
|
|
71
|
+
this.connections.create('default', 'api').key({ endpoint: 'memory' });
|
|
72
|
+
}
|
|
73
|
+
createSchema(config) {
|
|
74
|
+
const builder = this.schemaManager.create(config.name);
|
|
75
|
+
if (config.connection && config.collection) {
|
|
76
|
+
builder.use({ connection: config.connection, collection: config.collection });
|
|
77
|
+
}
|
|
78
|
+
if (config.structure) {
|
|
79
|
+
builder.setStructure(config.structure);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Simplified API methods
|
|
83
|
+
connect(name, type, config) {
|
|
84
|
+
this.connections.create(name, type).key(config);
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
schema(name) {
|
|
88
|
+
return this.schemaManager.create(name);
|
|
89
|
+
}
|
|
90
|
+
use(schemaName) {
|
|
91
|
+
return this.schemaManager.use(schemaName);
|
|
92
|
+
}
|
|
93
|
+
// Quick query methods
|
|
94
|
+
async get(schemaName, filters) {
|
|
95
|
+
const query = this.use(schemaName);
|
|
96
|
+
if (filters) {
|
|
97
|
+
Object.entries(filters).forEach(([field, value]) => {
|
|
98
|
+
query.where(field, value);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return query.get();
|
|
102
|
+
}
|
|
103
|
+
async getOne(schemaName, filters) {
|
|
104
|
+
const query = this.use(schemaName);
|
|
105
|
+
if (filters) {
|
|
106
|
+
Object.entries(filters).forEach(([field, value]) => {
|
|
107
|
+
query.where(field, value);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return query.getOne();
|
|
111
|
+
}
|
|
112
|
+
async add(schemaName, data) {
|
|
113
|
+
return this.use(schemaName).add(data);
|
|
114
|
+
}
|
|
115
|
+
async update(schemaName, filters, data) {
|
|
116
|
+
const query = this.use(schemaName);
|
|
117
|
+
Object.entries(filters).forEach(([field, value]) => {
|
|
118
|
+
query.where(field, value);
|
|
119
|
+
});
|
|
120
|
+
await query.to(data).update();
|
|
121
|
+
}
|
|
122
|
+
async delete(schemaName, filters) {
|
|
123
|
+
const query = this.use(schemaName);
|
|
124
|
+
Object.entries(filters).forEach(([field, value]) => {
|
|
125
|
+
query.where(field, value);
|
|
126
|
+
});
|
|
127
|
+
await query.delete();
|
|
128
|
+
}
|
|
129
|
+
// Get the underlying managers for advanced usage
|
|
130
|
+
getConnections() {
|
|
131
|
+
return this.connections;
|
|
132
|
+
}
|
|
133
|
+
getSchemaManager() {
|
|
134
|
+
return this.schemaManager;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Create and configure the default instance
|
|
138
|
+
export const createMapper = () => {
|
|
139
|
+
const mapper = Mapper.getInstance();
|
|
140
|
+
mapper.autoConfigure();
|
|
141
|
+
return mapper;
|
|
142
|
+
};
|
|
143
|
+
// Export a ready-to-use default instance
|
|
144
|
+
export default createMapper();
|
package/dist/orm/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { DbAdapter, QueryOptions } from './types';
|
|
2
2
|
export declare function createOrm(adapter: DbAdapter): {
|
|
3
|
-
get(options: QueryOptions): Promise<import("
|
|
3
|
+
get(options: QueryOptions): Promise<import("./types").DocumentData[]>;
|
|
4
4
|
getOne(options: QueryOptions): Promise<any>;
|
|
5
|
-
getDocuments(options: QueryOptions): Promise<import("
|
|
5
|
+
getDocuments(options: QueryOptions): Promise<import("./types").DocumentData[]>;
|
|
6
6
|
addDocument(collectionName: string, data: Record<string, any>): Promise<string>;
|
|
7
7
|
updateDocument(collectionName: string, docId: string, data: Record<string, any>): Promise<void>;
|
|
8
8
|
deleteDocument(collectionName: string, docId: string): Promise<void>;
|
package/dist/orm/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neupgroup/mapper",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Neup.Mapper core library for schema and mapping utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
},
|
|
16
16
|
"publishConfig": {
|
|
17
17
|
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^24.10.1",
|
|
21
|
+
"typescript": "^5.9.3"
|
|
18
22
|
}
|
|
19
23
|
}
|
|
20
|
-
|