@neupgroup/mapper 1.5.3 → 1.5.4
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/dist/config.d.ts +17 -8
- package/dist/config.js +3 -1
- package/dist/env.d.ts +2 -1
- package/dist/env.js +1 -1
- package/dist/fluent-mapper.d.ts +5 -5
- package/dist/index.d.ts +2 -2
- package/dist/mapper.d.ts +2 -2
- package/dist/mapper.js +1 -1
- package/package.json +1 -1
- package/dist/usage_example.d.ts +0 -1
- package/dist/usage_example.js +0 -37
- package/dist/usage_example_v2.d.ts +0 -1
- package/dist/usage_example_v2.js +0 -19
package/dist/config.d.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
import { Connections, SchemaManager } from './index.js';
|
|
1
|
+
import { Connections, SchemaManager, ConnectionType } from './index.js';
|
|
2
2
|
export interface DatabaseConnectionConfig {
|
|
3
3
|
name: string;
|
|
4
|
-
type: 'mysql' | 'sql' | 'firestore' | 'mongodb';
|
|
5
|
-
host
|
|
6
|
-
port
|
|
7
|
-
database
|
|
8
|
-
user
|
|
4
|
+
type: 'mysql' | 'sql' | 'firestore' | 'mongodb' | 'postgres' | 'sqlite';
|
|
5
|
+
host?: string;
|
|
6
|
+
port?: number;
|
|
7
|
+
database?: string;
|
|
8
|
+
user?: string;
|
|
9
9
|
password?: string;
|
|
10
10
|
ssl?: boolean;
|
|
11
|
+
filename?: string;
|
|
12
|
+
mode?: number;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
export interface SqliteConnectionConfig {
|
|
16
|
+
name: string;
|
|
17
|
+
type: 'sqlite';
|
|
18
|
+
filename: string;
|
|
19
|
+
mode?: number;
|
|
11
20
|
[key: string]: any;
|
|
12
21
|
}
|
|
13
22
|
export interface ApiConnectionConfig {
|
|
@@ -18,7 +27,7 @@ export interface ApiConnectionConfig {
|
|
|
18
27
|
timeout?: number;
|
|
19
28
|
[key: string]: any;
|
|
20
29
|
}
|
|
21
|
-
export type ConnectionConfig = DatabaseConnectionConfig | ApiConnectionConfig;
|
|
30
|
+
export type ConnectionConfig = DatabaseConnectionConfig | ApiConnectionConfig | SqliteConnectionConfig;
|
|
22
31
|
export interface ConfigSchema {
|
|
23
32
|
name: string;
|
|
24
33
|
connection: string;
|
|
@@ -55,7 +64,7 @@ export declare class ConfigBasedMapper {
|
|
|
55
64
|
getSchemaManager(): SchemaManager;
|
|
56
65
|
use(schemaName: string): any;
|
|
57
66
|
schema(name: string): any;
|
|
58
|
-
connect(name: string, type:
|
|
67
|
+
connect(name: string, type: ConnectionType, config: Record<string, any>): import("./mapper.js").Mapper;
|
|
59
68
|
get(schemaName: string, filters?: Record<string, any>): Promise<Record<string, any>[]>;
|
|
60
69
|
getOne(schemaName: string, filters?: Record<string, any>): Promise<Record<string, any> | null>;
|
|
61
70
|
add(schemaName: string, data: Record<string, any>): Promise<any>;
|
package/dist/config.js
CHANGED
|
@@ -224,11 +224,13 @@ function inferConnectionType(url) {
|
|
|
224
224
|
if (url.includes('mysql'))
|
|
225
225
|
return 'mysql';
|
|
226
226
|
if (url.includes('postgres') || url.includes('postgresql'))
|
|
227
|
-
return '
|
|
227
|
+
return 'postgres';
|
|
228
228
|
if (url.includes('mongodb'))
|
|
229
229
|
return 'mongodb';
|
|
230
230
|
if (url.includes('firestore'))
|
|
231
231
|
return 'firestore';
|
|
232
|
+
if (url.includes('sqlite') || url.endsWith('.db') || url.endsWith('.sqlite'))
|
|
233
|
+
return 'sqlite';
|
|
232
234
|
return 'sql'; // default to sql
|
|
233
235
|
}
|
|
234
236
|
export default ConfigBasedMapper;
|
package/dist/env.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConnectionType } from './index.js';
|
|
1
2
|
export type EnvDslConnections = Record<string, Record<string, string>>;
|
|
2
3
|
/**
|
|
3
4
|
* Parse a simple DSL of the form:
|
|
@@ -15,7 +16,7 @@ export type EnvDslConnections = Record<string, Record<string, string>>;
|
|
|
15
16
|
export declare function parseConnectionsDsl(text: string): EnvDslConnections;
|
|
16
17
|
export type NormalizedConnection = {
|
|
17
18
|
name: string;
|
|
18
|
-
type:
|
|
19
|
+
type: ConnectionType;
|
|
19
20
|
key: Record<string, any>;
|
|
20
21
|
};
|
|
21
22
|
/**
|
package/dist/env.js
CHANGED
|
@@ -80,7 +80,7 @@ export function toNormalizedConnections(map) {
|
|
|
80
80
|
const conns = [];
|
|
81
81
|
for (const [name, kv] of Object.entries(map)) {
|
|
82
82
|
const rawType = (kv['type'] || kv['dbType'] || '').toLowerCase();
|
|
83
|
-
const type = ['mysql', 'sql', 'firestore', 'mongodb', 'api'].includes(rawType) ? rawType : 'api';
|
|
83
|
+
const type = ['mysql', 'sql', 'firestore', 'mongodb', 'postgres', 'api', 'sqlite'].includes(rawType) ? rawType : 'api';
|
|
84
84
|
const { type: _omitType, dbType: _omitDbType, ...rest } = kv;
|
|
85
85
|
conns.push({ name, type, key: rest });
|
|
86
86
|
}
|
package/dist/fluent-mapper.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SchemaManager } from './index.js';
|
|
1
|
+
import { SchemaManager, ConnectionType } from './index.js';
|
|
2
2
|
import { TableMigrator } from './migrator.js';
|
|
3
3
|
export declare class FluentQueryBuilder {
|
|
4
4
|
private mapper;
|
|
@@ -87,10 +87,10 @@ export declare class FluentMapper {
|
|
|
87
87
|
private mapper;
|
|
88
88
|
constructor(mapper: any);
|
|
89
89
|
query(schemaName: string): FluentQueryBuilder;
|
|
90
|
-
makeConnection(name: string, type:
|
|
90
|
+
makeConnection(name: string, type: ConnectionType, config: Record<string, any>): FluentConnectionBuilder;
|
|
91
91
|
useConnection(connectionName: string): FluentConnectionSelector;
|
|
92
92
|
connection(connectionOrConfig: string | Record<string, any>): FluentConnectionSelector;
|
|
93
|
-
makeTempConnection(type:
|
|
93
|
+
makeTempConnection(type: ConnectionType, config: Record<string, any>): FluentConnectionBuilder;
|
|
94
94
|
get(schemaName: string, filters?: Record<string, any>): Promise<Record<string, any>[]>;
|
|
95
95
|
getOne(schemaName: string, filters?: Record<string, any>): Promise<Record<string, any> | null>;
|
|
96
96
|
add(schemaName: string, data: Record<string, any>): Promise<any>;
|
|
@@ -100,8 +100,8 @@ export declare class FluentMapper {
|
|
|
100
100
|
export declare class StaticMapper {
|
|
101
101
|
private static instance;
|
|
102
102
|
private static getFluentMapper;
|
|
103
|
-
static makeConnection(name: string, type:
|
|
104
|
-
static makeTempConnection(type:
|
|
103
|
+
static makeConnection(name: string, type: ConnectionType, config: Record<string, any>): FluentConnectionBuilder;
|
|
104
|
+
static makeTempConnection(type: ConnectionType, config: Record<string, any>): FluentConnectionBuilder;
|
|
105
105
|
static query(schemaName: string): FluentQueryBuilder;
|
|
106
106
|
static connection(connectionOrConfig: string | Record<string, any>): FluentConnectionSelector;
|
|
107
107
|
static useConnection(connectionName: string): FluentConnectionSelector;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DbAdapter, QueryOptions } from './orm/index.js';
|
|
2
2
|
export type ColumnType = 'string' | 'number' | 'boolean' | 'date' | 'int';
|
|
3
|
-
export type ConnectionType = 'mysql' | 'sql' | 'firestore' | 'mongodb' | 'api' | 'sqlite';
|
|
3
|
+
export type ConnectionType = 'mysql' | 'sql' | 'firestore' | 'mongodb' | 'postgres' | 'api' | 'sqlite';
|
|
4
4
|
export interface Field {
|
|
5
5
|
name: string;
|
|
6
6
|
type: ColumnType;
|
|
@@ -130,7 +130,7 @@ export { default } from './mapper.js';
|
|
|
130
130
|
export { StaticMapper } from './fluent-mapper.js';
|
|
131
131
|
export type { FluentQueryBuilder, FluentConnectionBuilder, FluentSchemaBuilder, FluentSchemaCollectionBuilder, FluentConnectionSelector, FluentMapper } from './fluent-mapper.js';
|
|
132
132
|
export { ConfigBasedMapper, ConfigLoader, createConfigMapper, getConfigMapper, createDefaultMapper } from './config.js';
|
|
133
|
-
export type { MapperConfig, ConnectionConfig, DatabaseConnectionConfig, ApiConnectionConfig, ConfigSchema } from './config.js';
|
|
133
|
+
export type { MapperConfig, ConnectionConfig, DatabaseConnectionConfig, ApiConnectionConfig, SqliteConnectionConfig, ConfigSchema } from './config.js';
|
|
134
134
|
export { MySQLAdapter, createMySQLAdapter, PostgreSQLAdapter, createPostgreSQLAdapter, MongoDBAdapter, createMongoDBAdapter, APIAdapter, createAPIAdapter, createAdapter, createAdapterFromUrl, autoAttachAdapter } from './adapters/index.js';
|
|
135
135
|
export type { MySQLConfig, PostgreSQLConfig, MongoDBConfig, APIAdapterConfig, AdapterConfig } from './adapters/index.js';
|
|
136
136
|
export { MapperError, AdapterMissingError, UpdatePayloadMissingError, DocumentMissingIdError, ConnectionExistingError, ConnectionUnknownError, SchemaExistingError, SchemaMissingError, SchemaConfigurationError, } from './errors.js';
|
package/dist/mapper.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Connections, SchemaManager } from './index.js';
|
|
1
|
+
import { Connections, SchemaManager, ConnectionType } from './index.js';
|
|
2
2
|
export declare class Mapper {
|
|
3
3
|
private connections;
|
|
4
4
|
private schemaManager;
|
|
@@ -12,7 +12,7 @@ export declare class Mapper {
|
|
|
12
12
|
private applyConfig;
|
|
13
13
|
private applyDefaultConfig;
|
|
14
14
|
private createSchema;
|
|
15
|
-
connect(name: string, type:
|
|
15
|
+
connect(name: string, type: ConnectionType, config: Record<string, any>): this;
|
|
16
16
|
schema(name: string): ReturnType<SchemaManager['create']>;
|
|
17
17
|
use(schemaName: string): ReturnType<SchemaManager['use']>;
|
|
18
18
|
get(schemaName: string, filters?: Record<string, any>): Promise<Record<string, any>[]>;
|
package/dist/mapper.js
CHANGED
package/package.json
CHANGED
package/dist/usage_example.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/usage_example.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Mapper } from './fluent-mapper.js';
|
|
2
|
-
async function main() {
|
|
3
|
-
// 1. Connection setup (mock)
|
|
4
|
-
Mapper.makeConnection('custom', 'api', { url: 'http://localhost' });
|
|
5
|
-
// 2. Schema Definition using the new API
|
|
6
|
-
const userSchema = Mapper.schemas('users');
|
|
7
|
-
userSchema.fields = {
|
|
8
|
-
'id': ['integer', 'auto-increment'],
|
|
9
|
-
'name': ['string', 'max.20', 'unique'],
|
|
10
|
-
'gender': ['string', 'enum', ['male', 'female', 'other']],
|
|
11
|
-
'createdOn': ['datetime', 'default_current_datetime'],
|
|
12
|
-
'role': ['string', 'default.value', 'user']
|
|
13
|
-
};
|
|
14
|
-
userSchema.insertableFields = ['name', 'gender', 'role']; // exclude id, createdOn
|
|
15
|
-
userSchema.updatableFields = ['name', 'gender'];
|
|
16
|
-
userSchema.deleteType = 'softDelete';
|
|
17
|
-
userSchema.massDeleteAllowed = false;
|
|
18
|
-
console.log("Schema defined.");
|
|
19
|
-
// 3. User Query Scenarios
|
|
20
|
-
// Scenario A: Mapper.connection('name').table('name')
|
|
21
|
-
// We don't have a real DB so this will fail at execution but we check the builder construction.
|
|
22
|
-
const query1 = Mapper.connection('default').table('users');
|
|
23
|
-
console.log("Query 1 built:", query1);
|
|
24
|
-
// Scenario B: Mapper.connection('name').schemas('name').get('users').limit(1)
|
|
25
|
-
// 'users' in get() might be field selection if schema is 'name'.
|
|
26
|
-
// Let's assume 'users' is the schema name.
|
|
27
|
-
// Code: Mapper.connection('default').schemas('users').get('id', 'name').limit(1)
|
|
28
|
-
const query2 = Mapper.connection('default').schemas('users').get('id', 'name').limit(1);
|
|
29
|
-
console.log("Query 2 built (select fields):", query2);
|
|
30
|
-
// Scenario C: Mapper.schemas('name').get('field1','field2').limit(2).offset(20)
|
|
31
|
-
const query3 = Mapper.schemas('users').get('name', 'gender').limit(2).offset(20);
|
|
32
|
-
console.log("Query 3 built:", query3);
|
|
33
|
-
// 4. Test logic (mock execution would happen here)
|
|
34
|
-
// Since we don't have a real adapter that works without network/db, we just stop here.
|
|
35
|
-
// If we had an in-memory adapter we could test output.
|
|
36
|
-
}
|
|
37
|
-
main().catch(console.error);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/usage_example_v2.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Mapper } from './fluent-mapper.js';
|
|
2
|
-
async function main() {
|
|
3
|
-
// 1. Connection setup (mock) with new API
|
|
4
|
-
// Using configuration object directly
|
|
5
|
-
// Mapper.connection(['type': 'type', 'username':'username' ]) -> { type: 'api', ... }
|
|
6
|
-
const conn = Mapper.connection({ type: 'api', url: 'http://example.com' });
|
|
7
|
-
console.log("Connection created:", conn);
|
|
8
|
-
// 2. Insert with new API
|
|
9
|
-
// Mapper.connection('connectionName').collection('name').insert({...})
|
|
10
|
-
// Let's use the temp connection we just made (it is anonymous/temp in our implementation if using config object,
|
|
11
|
-
// but wait, `connection({ type: ... })` returns a selector bound to a temp name.
|
|
12
|
-
// We need to access a collection/table from the connection selector.
|
|
13
|
-
// The user requirement: Mapper.connection(...).collection('name').insert(...)
|
|
14
|
-
// Check references: FluentConnectionSelector has `schema` and `query` and `table`.
|
|
15
|
-
// Does it have `collection`? No, let's check FluentConnectionSelector.
|
|
16
|
-
// It has `schema(name)` and `query(name)` and `table(name)`.
|
|
17
|
-
// We should add `collection(name)` alias.
|
|
18
|
-
}
|
|
19
|
-
main().catch(console.error);
|