@neupgroup/mapper 1.7.0 → 1.7.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/dist/builders/base-dispatcher.d.ts +10 -0
- package/dist/builders/base-dispatcher.js +19 -0
- package/dist/builders/clause-builder.d.ts +11 -0
- package/dist/builders/clause-builder.js +27 -0
- package/dist/builders/dml-builders.d.ts +25 -0
- package/dist/builders/dml-builders.js +55 -0
- package/dist/builders/raw-builder.d.ts +8 -0
- package/dist/builders/raw-builder.js +22 -0
- package/dist/builders/schema-builders.d.ts +44 -0
- package/dist/builders/schema-builders.js +84 -0
- package/dist/connector.d.ts +2 -2
- package/dist/discovery.js +4 -8
- package/dist/fluent-mapper.d.ts +35 -150
- package/dist/fluent-mapper.js +70 -525
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -2
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SelectBuilder, InsertBuilder, UpdateBuilder, DeleteBuilder } from './dml-builders.js';
|
|
2
|
+
export declare class BaseDispatcher {
|
|
3
|
+
private mapper;
|
|
4
|
+
private target;
|
|
5
|
+
constructor(mapper: any, target: string);
|
|
6
|
+
select(fields?: string[]): SelectBuilder;
|
|
7
|
+
insert(data: any): InsertBuilder;
|
|
8
|
+
update(data: any): UpdateBuilder;
|
|
9
|
+
delete(): DeleteBuilder;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SelectBuilder, InsertBuilder, UpdateBuilder, DeleteBuilder } from './dml-builders.js';
|
|
2
|
+
export class BaseDispatcher {
|
|
3
|
+
constructor(mapper, target) {
|
|
4
|
+
this.mapper = mapper;
|
|
5
|
+
this.target = target;
|
|
6
|
+
}
|
|
7
|
+
select(fields = []) {
|
|
8
|
+
return new SelectBuilder(this.mapper, this.target, fields);
|
|
9
|
+
}
|
|
10
|
+
insert(data) {
|
|
11
|
+
return new InsertBuilder(this.mapper, this.target, data);
|
|
12
|
+
}
|
|
13
|
+
update(data) {
|
|
14
|
+
return new UpdateBuilder(this.mapper, this.target, data);
|
|
15
|
+
}
|
|
16
|
+
delete() {
|
|
17
|
+
return new DeleteBuilder(this.mapper, this.target);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class ClauseBuilder {
|
|
2
|
+
protected mapper: any;
|
|
3
|
+
protected target: string;
|
|
4
|
+
protected query: any;
|
|
5
|
+
constructor(mapper: any, target: string);
|
|
6
|
+
where(field: string, value: any, operator?: string): this;
|
|
7
|
+
whereComplex(raw: string): this;
|
|
8
|
+
whereRaw(raw: string): this;
|
|
9
|
+
limit(n: number): this;
|
|
10
|
+
offset(n: number): this;
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class ClauseBuilder {
|
|
2
|
+
constructor(mapper, target) {
|
|
3
|
+
this.mapper = mapper;
|
|
4
|
+
this.target = target;
|
|
5
|
+
// Initialize the underlying query object from the mapper core
|
|
6
|
+
this.query = mapper.use(target);
|
|
7
|
+
}
|
|
8
|
+
where(field, value, operator) {
|
|
9
|
+
this.query.where(field, value, operator);
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
whereComplex(raw) {
|
|
13
|
+
this.query.whereComplex(raw);
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
whereRaw(raw) {
|
|
17
|
+
return this.whereComplex(raw);
|
|
18
|
+
}
|
|
19
|
+
limit(n) {
|
|
20
|
+
this.query.limit(n);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
offset(n) {
|
|
24
|
+
this.query.offset(n);
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ClauseBuilder } from './clause-builder.js';
|
|
2
|
+
export declare class SelectBuilder extends ClauseBuilder {
|
|
3
|
+
fields: string[];
|
|
4
|
+
constructor(mapper: any, target: string, fields?: string[]);
|
|
5
|
+
get(): Promise<any[]>;
|
|
6
|
+
getOne(): Promise<any | null>;
|
|
7
|
+
}
|
|
8
|
+
export declare class InsertBuilder {
|
|
9
|
+
private mapper;
|
|
10
|
+
private target;
|
|
11
|
+
private data;
|
|
12
|
+
private query;
|
|
13
|
+
constructor(mapper: any, target: string, data: any);
|
|
14
|
+
private ensureSchema;
|
|
15
|
+
run(): Promise<any>;
|
|
16
|
+
}
|
|
17
|
+
export declare class UpdateBuilder extends ClauseBuilder {
|
|
18
|
+
private data;
|
|
19
|
+
constructor(mapper: any, target: string, data: any);
|
|
20
|
+
run(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export declare class DeleteBuilder extends ClauseBuilder {
|
|
23
|
+
constructor(mapper: any, target: string);
|
|
24
|
+
run(): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ClauseBuilder } from './clause-builder.js';
|
|
2
|
+
export class SelectBuilder extends ClauseBuilder {
|
|
3
|
+
constructor(mapper, target, fields = []) {
|
|
4
|
+
super(mapper, target);
|
|
5
|
+
this.fields = fields;
|
|
6
|
+
if (fields.length > 0) {
|
|
7
|
+
this.query.selectFields(fields);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
async get() {
|
|
11
|
+
return this.query.get();
|
|
12
|
+
}
|
|
13
|
+
async getOne() {
|
|
14
|
+
return this.query.getOne();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class InsertBuilder {
|
|
18
|
+
constructor(mapper, target, data) {
|
|
19
|
+
this.mapper = mapper;
|
|
20
|
+
this.target = target;
|
|
21
|
+
this.data = data;
|
|
22
|
+
this.query = mapper.use(target);
|
|
23
|
+
// Ensure we handle auto-registration if needed (legacy behavior support)
|
|
24
|
+
this.ensureSchema(mapper, target);
|
|
25
|
+
}
|
|
26
|
+
ensureSchema(mapper, target) {
|
|
27
|
+
try {
|
|
28
|
+
mapper.use(target);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
mapper.getSchemaManager().create(target).use({ connection: 'default', collection: target }).setStructure({});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async run() {
|
|
35
|
+
return this.mapper.add(this.target, this.data);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class UpdateBuilder extends ClauseBuilder {
|
|
39
|
+
constructor(mapper, target, data) {
|
|
40
|
+
super(mapper, target);
|
|
41
|
+
this.data = data;
|
|
42
|
+
this.query.to(data);
|
|
43
|
+
}
|
|
44
|
+
async run() {
|
|
45
|
+
return this.query.update();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export class DeleteBuilder extends ClauseBuilder {
|
|
49
|
+
constructor(mapper, target) {
|
|
50
|
+
super(mapper, target);
|
|
51
|
+
}
|
|
52
|
+
async run() {
|
|
53
|
+
return this.query.delete();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class RawBuilder {
|
|
2
|
+
constructor(mapper, sql) {
|
|
3
|
+
this.mapper = mapper;
|
|
4
|
+
this.sql = sql;
|
|
5
|
+
this._bindings = [];
|
|
6
|
+
}
|
|
7
|
+
bind(bindings) {
|
|
8
|
+
this._bindings = Array.isArray(bindings) ? bindings : [bindings];
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
async run() {
|
|
12
|
+
const connections = this.mapper.getConnections();
|
|
13
|
+
const conn = connections.get('default');
|
|
14
|
+
if (!conn)
|
|
15
|
+
throw new Error("No default connection found for raw query.");
|
|
16
|
+
const adapter = connections.getAdapter(conn.name);
|
|
17
|
+
if (adapter && typeof adapter.query === 'function') {
|
|
18
|
+
return adapter.query(this.sql, this._bindings);
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`Connection '${conn.name}' does not support raw queries.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare class SchemaCreator {
|
|
2
|
+
private mapper;
|
|
3
|
+
private name;
|
|
4
|
+
private type;
|
|
5
|
+
private migrator;
|
|
6
|
+
constructor(mapper: any, name: string, type: string);
|
|
7
|
+
private ensureRegistration;
|
|
8
|
+
addColumn(name: string): import("../migrator.js").ColumnBuilder;
|
|
9
|
+
structure(config: any): this;
|
|
10
|
+
exec(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare class SchemaUpdater {
|
|
13
|
+
private mapper;
|
|
14
|
+
private name;
|
|
15
|
+
private migrator;
|
|
16
|
+
constructor(mapper: any, name: string);
|
|
17
|
+
addColumn(name: string): import("../migrator.js").ColumnBuilder;
|
|
18
|
+
selectColumn(name: string): import("../migrator.js").ColumnBuilder;
|
|
19
|
+
dropColumn(name: string): this;
|
|
20
|
+
exec(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export declare class SchemaDropper {
|
|
23
|
+
private name;
|
|
24
|
+
constructor(name: string);
|
|
25
|
+
exec(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare class SchemaHandler {
|
|
28
|
+
protected mapper: any;
|
|
29
|
+
protected name: string;
|
|
30
|
+
protected schemaType: string;
|
|
31
|
+
constructor(mapper: any, name: string, schemaType: string);
|
|
32
|
+
create(): SchemaCreator;
|
|
33
|
+
update(): SchemaUpdater;
|
|
34
|
+
drop(): SchemaDropper;
|
|
35
|
+
}
|
|
36
|
+
export declare class SchemaDispatcher {
|
|
37
|
+
private mapper;
|
|
38
|
+
private name;
|
|
39
|
+
constructor(mapper: any, name: string);
|
|
40
|
+
type(type: 'table' | 'api' | 'collection'): SchemaHandler;
|
|
41
|
+
create(): SchemaCreator;
|
|
42
|
+
update(): SchemaUpdater;
|
|
43
|
+
drop(): SchemaDropper;
|
|
44
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { TableMigrator } from '../migrator.js';
|
|
2
|
+
import { parseDescriptorStructure } from '../index.js';
|
|
3
|
+
export class SchemaCreator {
|
|
4
|
+
constructor(mapper, name, type) {
|
|
5
|
+
this.mapper = mapper;
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.type = type;
|
|
8
|
+
this.migrator = new TableMigrator(name);
|
|
9
|
+
this.ensureRegistration();
|
|
10
|
+
}
|
|
11
|
+
ensureRegistration() {
|
|
12
|
+
// Register if technically missing from memory so migrator has something to work with
|
|
13
|
+
const manager = this.mapper.getSchemaManager();
|
|
14
|
+
if (!manager.schemas.has(this.name)) {
|
|
15
|
+
manager.create(this.name).use({ connection: 'default', collection: this.name }).setStructure({});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// DDL Methods
|
|
19
|
+
addColumn(name) { return this.migrator.addColumn(name); }
|
|
20
|
+
structure(config) {
|
|
21
|
+
// Apply structure config to the in-memory definition immediately for usage
|
|
22
|
+
const def = this.mapper.getSchemaManager().schemas.get(this.name);
|
|
23
|
+
if (def) {
|
|
24
|
+
const parsed = parseDescriptorStructure(config);
|
|
25
|
+
def.fields = parsed.fields;
|
|
26
|
+
def.fieldsMap = new Map();
|
|
27
|
+
def.fields.forEach((f) => def.fieldsMap.set(f.name, f));
|
|
28
|
+
}
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
async exec() {
|
|
32
|
+
return this.migrator.exec();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class SchemaUpdater {
|
|
36
|
+
constructor(mapper, name) {
|
|
37
|
+
this.mapper = mapper;
|
|
38
|
+
this.name = name;
|
|
39
|
+
this.migrator = new TableMigrator(name);
|
|
40
|
+
}
|
|
41
|
+
addColumn(name) { return this.migrator.addColumn(name); }
|
|
42
|
+
selectColumn(name) { return this.migrator.selectColumn(name); }
|
|
43
|
+
dropColumn(name) { this.migrator.dropColumn(name); return this; }
|
|
44
|
+
async exec() {
|
|
45
|
+
return this.migrator.exec();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export class SchemaDropper {
|
|
49
|
+
constructor(name) {
|
|
50
|
+
this.name = name;
|
|
51
|
+
}
|
|
52
|
+
async exec() {
|
|
53
|
+
return new TableMigrator(this.name).drop().exec();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class SchemaHandler {
|
|
57
|
+
constructor(mapper, name, schemaType) {
|
|
58
|
+
this.mapper = mapper;
|
|
59
|
+
this.name = name;
|
|
60
|
+
this.schemaType = schemaType;
|
|
61
|
+
}
|
|
62
|
+
create() {
|
|
63
|
+
return new SchemaCreator(this.mapper, this.name, this.schemaType);
|
|
64
|
+
}
|
|
65
|
+
update() {
|
|
66
|
+
return new SchemaUpdater(this.mapper, this.name);
|
|
67
|
+
}
|
|
68
|
+
drop() {
|
|
69
|
+
return new SchemaDropper(this.name);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export class SchemaDispatcher {
|
|
73
|
+
constructor(mapper, name) {
|
|
74
|
+
this.mapper = mapper;
|
|
75
|
+
this.name = name;
|
|
76
|
+
}
|
|
77
|
+
type(type) {
|
|
78
|
+
return new SchemaHandler(this.mapper, this.name, type);
|
|
79
|
+
}
|
|
80
|
+
// Shortcuts if type is omitted (defaults to 'table' behavior essentially)
|
|
81
|
+
create() { return new SchemaHandler(this.mapper, this.name, 'table').create(); }
|
|
82
|
+
update() { return new SchemaHandler(this.mapper, this.name, 'table').update(); }
|
|
83
|
+
drop() { return new SchemaHandler(this.mapper, this.name, 'table').drop(); }
|
|
84
|
+
}
|
package/dist/connector.d.ts
CHANGED
|
@@ -40,11 +40,11 @@ export declare class Connector {
|
|
|
40
40
|
* Define the table or collection to operate on.
|
|
41
41
|
* This registers the connection (if not already) and prepares a query.
|
|
42
42
|
*/
|
|
43
|
-
table(tableName: string): import("./fluent-mapper.js").
|
|
43
|
+
table(tableName: string): import("./fluent-mapper.js").BaseDispatcher;
|
|
44
44
|
/**
|
|
45
45
|
* Alias for table() for API endpoints (subpath).
|
|
46
46
|
*/
|
|
47
|
-
subpath(path: string): import("./fluent-mapper.js").
|
|
47
|
+
subpath(path: string): import("./fluent-mapper.js").BaseDispatcher;
|
|
48
48
|
/**
|
|
49
49
|
* Finalizes the connection registration and returns a query object.
|
|
50
50
|
*/
|
package/dist/discovery.js
CHANGED
|
@@ -49,17 +49,13 @@ export async function discover() {
|
|
|
49
49
|
const schemaDef = mod[schemaName] || mod.schema || mod.default;
|
|
50
50
|
if (schemaDef && schemaDef.fields) {
|
|
51
51
|
const connectionName = schemaDef.usesConnection || 'default';
|
|
52
|
-
StaticMapper.
|
|
53
|
-
.
|
|
54
|
-
.collection(schemaDef.collectionName || schemaName)
|
|
52
|
+
StaticMapper.schema(schemaName)
|
|
53
|
+
.create()
|
|
55
54
|
.structure(schemaDef.fields);
|
|
56
55
|
// Apply options if present
|
|
56
|
+
// Apply options if present
|
|
57
57
|
if (schemaDef.insertableFields || schemaDef.updatableFields) {
|
|
58
|
-
const
|
|
59
|
-
const schema = manager.create(schemaName); // This might throw if exists, should use update
|
|
60
|
-
// ... existing StaticMapper already handles this in discovery pattern?
|
|
61
|
-
// Actually StaticMapper.schemas(schemaName) works.
|
|
62
|
-
const wrapper = StaticMapper.schemas(schemaName);
|
|
58
|
+
const wrapper = StaticMapper.getFluentMapper().mapper.getSchemaManager().create(schemaName);
|
|
63
59
|
if (schemaDef.insertableFields)
|
|
64
60
|
wrapper.insertableFields = schemaDef.insertableFields;
|
|
65
61
|
if (schemaDef.updatableFields)
|
package/dist/fluent-mapper.d.ts
CHANGED
|
@@ -1,168 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
whereRaw(raw: string): this;
|
|
11
|
-
limit(n: number): this;
|
|
12
|
-
offset(n: number): this;
|
|
13
|
-
to(update: Record<string, any>): this;
|
|
14
|
-
get(...fields: string[]): any;
|
|
15
|
-
then(onfulfilled?: ((value: any) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
|
|
16
|
-
getOne(): Promise<Record<string, any> | null>;
|
|
17
|
-
add(data: Record<string, any>): Promise<any>;
|
|
18
|
-
insert(data: Record<string, any>): Promise<any>;
|
|
19
|
-
update(data?: Record<string, any>): Promise<void>;
|
|
20
|
-
delete(): Promise<void>;
|
|
21
|
-
deleteOne(): Promise<void>;
|
|
22
|
-
updateOne(data?: Record<string, any>): Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
export declare class FluentSchemaBuilder {
|
|
25
|
-
private mapper;
|
|
26
|
-
private schemaName;
|
|
27
|
-
private _migrator?;
|
|
28
|
-
constructor(mapper: any, schemaName: string, connectionName?: string);
|
|
29
|
-
private getDef;
|
|
30
|
-
set fields(config: any);
|
|
31
|
-
structure(config: any): this;
|
|
32
|
-
collection(collectionName: string): this;
|
|
33
|
-
set insertableFields(val: string[]);
|
|
34
|
-
set updatableFields(val: string[]);
|
|
35
|
-
set deleteType(val: 'softDelete' | 'hardDelete');
|
|
36
|
-
set massDeleteAllowed(val: boolean);
|
|
37
|
-
set massEditAllowed(val: boolean);
|
|
38
|
-
get migrator(): TableMigrator;
|
|
39
|
-
useConnection(name: string): this;
|
|
40
|
-
addColumn(name: string): import("./migrator.js").ColumnBuilder;
|
|
41
|
-
selectColumn(name: string): import("./migrator.js").ColumnBuilder;
|
|
42
|
-
dropColumn(name: string): this;
|
|
43
|
-
drop(): this;
|
|
44
|
-
exec(): Promise<void>;
|
|
45
|
-
}
|
|
1
|
+
import { ConnectionType } from './index.js';
|
|
2
|
+
import { BaseDispatcher } from './builders/base-dispatcher.js';
|
|
3
|
+
import { RawBuilder } from './builders/raw-builder.js';
|
|
4
|
+
import { SchemaDispatcher } from './builders/schema-builders.js';
|
|
5
|
+
export { BaseDispatcher, RawBuilder, SchemaDispatcher };
|
|
6
|
+
export * from './builders/dml-builders.js';
|
|
7
|
+
export * from './builders/schema-builders.js';
|
|
8
|
+
export * from './builders/raw-builder.js';
|
|
9
|
+
export * from './builders/clause-builder.js';
|
|
46
10
|
export declare class FluentConnectionBuilder {
|
|
11
|
+
private name;
|
|
12
|
+
private type;
|
|
47
13
|
private mapper;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
constructor(mapper: any, connectionName: string, connectionType: string, config: Record<string, any>);
|
|
52
|
-
schema(schemaName: string): FluentSchemaBuilder;
|
|
53
|
-
query(schemaName: string): FluentQueryBuilder;
|
|
54
|
-
useConnection(connectionName: string): FluentConnectionSelector;
|
|
55
|
-
}
|
|
56
|
-
export declare class RawQueryBuilder {
|
|
57
|
-
private mapper;
|
|
58
|
-
private sql;
|
|
59
|
-
private _bindings;
|
|
60
|
-
constructor(mapper: any, sql: string);
|
|
61
|
-
bind(bindings: any[] | any): this;
|
|
62
|
-
run(): Promise<any>;
|
|
63
|
-
}
|
|
64
|
-
export declare class BaseQueryBuilder {
|
|
65
|
-
private mapper;
|
|
66
|
-
private target;
|
|
67
|
-
private queryBuilder;
|
|
68
|
-
private _select;
|
|
69
|
-
private _insertData?;
|
|
70
|
-
private _updateData?;
|
|
71
|
-
private _action;
|
|
72
|
-
constructor(mapper: any, target: string);
|
|
73
|
-
select(fields: string[]): this;
|
|
74
|
-
where(field: string, value: any, operator?: string): this;
|
|
75
|
-
whereRaw(raw: string): this;
|
|
76
|
-
limit(n: number): this;
|
|
77
|
-
offset(n: number): this;
|
|
78
|
-
insert(data: any): this;
|
|
79
|
-
update(data: any): this;
|
|
80
|
-
get(): Promise<any>;
|
|
81
|
-
getOne(): Promise<any>;
|
|
82
|
-
run(): Promise<any>;
|
|
83
|
-
}
|
|
84
|
-
export declare class FluentApiRequestBuilder {
|
|
85
|
-
private mapper;
|
|
86
|
-
private connectionName;
|
|
87
|
-
private _path;
|
|
88
|
-
private _headers;
|
|
89
|
-
constructor(mapper: any, connectionName: string, path?: string);
|
|
90
|
-
path(p: string): this;
|
|
91
|
-
header(key: string | Record<string, string | string[]>, value?: string | string[]): this;
|
|
92
|
-
headers(h: Record<string, string | string[]> | any[]): this;
|
|
93
|
-
get(): Promise<any>;
|
|
94
|
-
post(data?: any): Promise<any>;
|
|
95
|
-
put(data?: any): Promise<any>;
|
|
96
|
-
patch(data?: any): Promise<any>;
|
|
97
|
-
delete(): Promise<any>;
|
|
98
|
-
private execute;
|
|
14
|
+
constructor(mapper: any, name: string, type: ConnectionType, config: Record<string, any>);
|
|
15
|
+
base(target: string): BaseDispatcher;
|
|
16
|
+
query(target: string): BaseDispatcher;
|
|
99
17
|
}
|
|
100
18
|
export declare class FluentConnectionSelector {
|
|
101
19
|
private mapper;
|
|
102
|
-
private
|
|
103
|
-
constructor(mapper: any,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
query(schemaName: string): FluentQueryBuilder;
|
|
107
|
-
table(tableName: string): FluentQueryBuilder;
|
|
108
|
-
collection(collectionName: string): FluentQueryBuilder;
|
|
109
|
-
path(path: string): FluentApiRequestBuilder;
|
|
110
|
-
header(key: string | Record<string, string | string[]>, value?: string | string[]): FluentApiRequestBuilder;
|
|
111
|
-
headers(headers: Record<string, string> | any[]): FluentApiRequestBuilder;
|
|
112
|
-
get(): Promise<any>;
|
|
113
|
-
post(data?: any): Promise<any>;
|
|
114
|
-
put(data?: any): Promise<any>;
|
|
115
|
-
patch(data?: any): Promise<any>;
|
|
116
|
-
delete(): Promise<any>;
|
|
20
|
+
private name;
|
|
21
|
+
constructor(mapper: any, name: string);
|
|
22
|
+
base(target: string): BaseDispatcher;
|
|
23
|
+
query(target: string): BaseDispatcher;
|
|
117
24
|
}
|
|
118
25
|
export declare class FluentMapper {
|
|
119
26
|
private mapper;
|
|
120
27
|
constructor(mapper: any);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
raw(sql: string):
|
|
125
|
-
base(target: string): BaseQueryBuilder;
|
|
28
|
+
base(target: string): BaseDispatcher;
|
|
29
|
+
query(target: string): BaseDispatcher;
|
|
30
|
+
schema(name: string): SchemaDispatcher;
|
|
31
|
+
raw(sql: string): RawBuilder;
|
|
126
32
|
makeConnection(name: string, type: ConnectionType, config: Record<string, any>): FluentConnectionBuilder;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
add(schemaName: string, data: Record<string, any>): Promise<any>;
|
|
133
|
-
update(schemaName: string, filters: Record<string, any>, data: Record<string, any>): Promise<void>;
|
|
134
|
-
delete(schemaName: string, filters: Record<string, any>): Promise<void>;
|
|
135
|
-
dropTable(name: string): Promise<void>;
|
|
33
|
+
connection(configOrName: string | any): FluentConnectionSelector;
|
|
34
|
+
get(target: string): Promise<any>;
|
|
35
|
+
add(target: string, data: any): Promise<any>;
|
|
36
|
+
update(target: string, filter: any, data: any): Promise<any>;
|
|
37
|
+
delete(target: string, filter: any): Promise<any>;
|
|
136
38
|
}
|
|
137
39
|
export declare class StaticMapper {
|
|
138
40
|
private static instance;
|
|
139
41
|
private static getFluentMapper;
|
|
140
|
-
static
|
|
141
|
-
static
|
|
142
|
-
static
|
|
143
|
-
static
|
|
144
|
-
static
|
|
145
|
-
static
|
|
146
|
-
static raw(sql: string): RawQueryBuilder;
|
|
147
|
-
static base(target: string): BaseQueryBuilder;
|
|
148
|
-
static connection(connectionOrConfig: string | Record<string, any>): FluentConnectionSelector;
|
|
149
|
-
static useConnection(connectionName: string): FluentConnectionSelector;
|
|
150
|
-
static schemas(name?: string): any;
|
|
151
|
-
static get(schemaName: string, filters?: Record<string, any>): Promise<Record<string, any>[]>;
|
|
152
|
-
static getOne(schemaName: string, filters?: Record<string, any>): Promise<Record<string, any> | null>;
|
|
153
|
-
static add(schemaName: string, data: Record<string, any>): Promise<any>;
|
|
154
|
-
static update(schemaName: string, filters: Record<string, any>, data: Record<string, any>): Promise<void>;
|
|
155
|
-
static delete(schemaName: string, filters: Record<string, any>): Promise<void>;
|
|
156
|
-
static dropTable(name: string): Promise<void>;
|
|
157
|
-
static getConnections(): Connections;
|
|
42
|
+
static base(target: string): BaseDispatcher;
|
|
43
|
+
static query(target: string): BaseDispatcher;
|
|
44
|
+
static schema(name: string): SchemaDispatcher;
|
|
45
|
+
static raw(sql: string): RawBuilder;
|
|
46
|
+
static connection(arg: any): FluentConnectionSelector;
|
|
47
|
+
static makeConnection(n: string, t: ConnectionType, c: any): FluentConnectionBuilder;
|
|
158
48
|
static discover(): Promise<void>;
|
|
49
|
+
static get(t: string): Promise<any>;
|
|
50
|
+
static add(t: string, d: any): Promise<any>;
|
|
159
51
|
}
|
|
160
52
|
export declare const Mapper: typeof StaticMapper;
|
|
161
53
|
export default Mapper;
|
|
162
|
-
export declare class SchemaManagerWrapper {
|
|
163
|
-
private manager;
|
|
164
|
-
constructor(manager: SchemaManager);
|
|
165
|
-
table(name: string): TableMigrator;
|
|
166
|
-
schema(name: string): TableMigrator;
|
|
167
|
-
dropTable(name: string): Promise<void>;
|
|
168
|
-
}
|
package/dist/fluent-mapper.js
CHANGED
|
@@ -1,565 +1,110 @@
|
|
|
1
1
|
import { createMapper } from './mapper.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
catch (e) {
|
|
17
|
-
// Auto-register schema if missing
|
|
18
|
-
mapper.getSchemaManager().create(schemaName).use({ connection: connectionName || 'default', collection: schemaName }).setStructure({});
|
|
19
|
-
this.query = mapper.use(schemaName);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
where(field, value, operator) {
|
|
23
|
-
this.query.where(field, value, operator);
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
whereComplex(raw) {
|
|
27
|
-
this.query.whereComplex(raw);
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
whereRaw(raw) {
|
|
31
|
-
return this.whereComplex(raw);
|
|
32
|
-
}
|
|
33
|
-
limit(n) {
|
|
34
|
-
this.query.limit(n);
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
offset(n) {
|
|
38
|
-
this.query.offset(n);
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
to(update) {
|
|
42
|
-
this.query.to(update);
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
get(...fields) {
|
|
46
|
-
if (fields.length > 0) {
|
|
47
|
-
this.query.selectFields(fields);
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
return this.query.get();
|
|
51
|
-
}
|
|
52
|
-
then(onfulfilled, onrejected) {
|
|
53
|
-
return this.query.get().then(onfulfilled, onrejected);
|
|
54
|
-
}
|
|
55
|
-
async getOne() {
|
|
56
|
-
return this.query.getOne();
|
|
57
|
-
}
|
|
58
|
-
async add(data) {
|
|
59
|
-
return this.mapper.add(this.schemaName, data);
|
|
60
|
-
}
|
|
61
|
-
async insert(data) {
|
|
62
|
-
return this.add(data);
|
|
63
|
-
}
|
|
64
|
-
async update(data) {
|
|
65
|
-
if (data) {
|
|
66
|
-
this.query.to(data);
|
|
67
|
-
}
|
|
68
|
-
return this.query.update();
|
|
69
|
-
}
|
|
70
|
-
async delete() {
|
|
71
|
-
return this.query.delete();
|
|
72
|
-
}
|
|
73
|
-
async deleteOne() {
|
|
74
|
-
return this.query.deleteOne();
|
|
75
|
-
}
|
|
76
|
-
async updateOne(data) {
|
|
77
|
-
if (data) {
|
|
78
|
-
this.query.to(data);
|
|
79
|
-
}
|
|
80
|
-
return this.query.updateOne();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// DDL Builder (Migrations & Schema Definition)
|
|
84
|
-
export class FluentSchemaBuilder {
|
|
85
|
-
constructor(mapper, schemaName, connectionName) {
|
|
86
|
-
this.mapper = mapper;
|
|
87
|
-
this.schemaName = schemaName;
|
|
88
|
-
// Ensure schema exists for configuration
|
|
89
|
-
const manager = mapper.getSchemaManager();
|
|
90
|
-
const exists = manager.schemas.has(schemaName);
|
|
91
|
-
if (!exists) {
|
|
92
|
-
manager.create(schemaName).use({ connection: connectionName || 'default', collection: schemaName }).setStructure({});
|
|
93
|
-
}
|
|
94
|
-
// If connectionName provided, update it
|
|
95
|
-
if (connectionName) {
|
|
96
|
-
const def = this.getDef();
|
|
97
|
-
if (def)
|
|
98
|
-
def.connectionName = connectionName;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
getDef() {
|
|
102
|
-
return this.mapper.getSchemaManager().schemas.get(this.schemaName);
|
|
103
|
-
}
|
|
104
|
-
// Schema Configuration Proxies
|
|
105
|
-
set fields(config) {
|
|
106
|
-
const def = this.getDef();
|
|
107
|
-
if (def) {
|
|
108
|
-
const parsed = parseDescriptorStructure(config);
|
|
109
|
-
def.fields = parsed.fields;
|
|
110
|
-
def.fieldsMap = new Map();
|
|
111
|
-
def.fields.forEach((f) => def.fieldsMap.set(f.name, f));
|
|
112
|
-
def.allowUndefinedFields = parsed.allowUndefinedFields;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
structure(config) {
|
|
116
|
-
this.fields = config;
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
collection(collectionName) {
|
|
120
|
-
const def = this.getDef();
|
|
121
|
-
if (def)
|
|
122
|
-
def.collectionName = collectionName;
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
125
|
-
set insertableFields(val) {
|
|
126
|
-
const def = this.getDef();
|
|
127
|
-
if (def)
|
|
128
|
-
def.insertableFields = val;
|
|
129
|
-
}
|
|
130
|
-
set updatableFields(val) {
|
|
131
|
-
const def = this.getDef();
|
|
132
|
-
if (def)
|
|
133
|
-
def.updatableFields = val;
|
|
134
|
-
}
|
|
135
|
-
set deleteType(val) {
|
|
136
|
-
const def = this.getDef();
|
|
137
|
-
if (def)
|
|
138
|
-
def.deleteType = val;
|
|
139
|
-
}
|
|
140
|
-
set massDeleteAllowed(val) {
|
|
141
|
-
const def = this.getDef();
|
|
142
|
-
if (def)
|
|
143
|
-
def.massDeleteAllowed = val;
|
|
144
|
-
}
|
|
145
|
-
set massEditAllowed(val) {
|
|
146
|
-
const def = this.getDef();
|
|
147
|
-
if (def)
|
|
148
|
-
def.massEditAllowed = val;
|
|
149
|
-
}
|
|
150
|
-
// Migration / DDL Methods
|
|
151
|
-
get migrator() {
|
|
152
|
-
if (!this._migrator) {
|
|
153
|
-
this._migrator = new TableMigrator(this.schemaName);
|
|
154
|
-
const def = this.getDef();
|
|
155
|
-
if (def === null || def === void 0 ? void 0 : def.connectionName) {
|
|
156
|
-
this._migrator.useConnection(def.connectionName);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return this._migrator;
|
|
160
|
-
}
|
|
161
|
-
useConnection(name) {
|
|
162
|
-
this.migrator.useConnection(name);
|
|
163
|
-
const def = this.getDef();
|
|
164
|
-
if (def)
|
|
165
|
-
def.connectionName = name;
|
|
166
|
-
return this;
|
|
167
|
-
}
|
|
168
|
-
addColumn(name) { return this.migrator.addColumn(name); }
|
|
169
|
-
selectColumn(name) { return this.migrator.selectColumn(name); }
|
|
170
|
-
dropColumn(name) { this.migrator.dropColumn(name); return this; }
|
|
171
|
-
drop() { this.migrator.drop(); return this; }
|
|
172
|
-
async exec() {
|
|
173
|
-
return this.migrator.exec();
|
|
174
|
-
}
|
|
175
|
-
}
|
|
2
|
+
// Import segregated builders
|
|
3
|
+
import { BaseDispatcher } from './builders/base-dispatcher.js';
|
|
4
|
+
import { RawBuilder } from './builders/raw-builder.js';
|
|
5
|
+
import { SchemaDispatcher } from './builders/schema-builders.js';
|
|
6
|
+
// Re-export for external usage
|
|
7
|
+
export { BaseDispatcher, RawBuilder, SchemaDispatcher };
|
|
8
|
+
export * from './builders/dml-builders.js';
|
|
9
|
+
export * from './builders/schema-builders.js';
|
|
10
|
+
export * from './builders/raw-builder.js';
|
|
11
|
+
export * from './builders/clause-builder.js';
|
|
12
|
+
// =========================================================================================
|
|
13
|
+
// CONNECTION & MAPPER WRAPPERS
|
|
14
|
+
// =========================================================================================
|
|
176
15
|
export class FluentConnectionBuilder {
|
|
177
|
-
constructor(mapper,
|
|
178
|
-
this.
|
|
179
|
-
this.
|
|
180
|
-
this.connectionType = connectionType;
|
|
181
|
-
this.connectionConfig = config;
|
|
182
|
-
// Create the connection immediately
|
|
183
|
-
this.mapper.connect(connectionName, connectionType, config);
|
|
184
|
-
}
|
|
185
|
-
schema(schemaName) {
|
|
186
|
-
return new FluentSchemaBuilder(this.mapper, schemaName, this.connectionName);
|
|
187
|
-
}
|
|
188
|
-
query(schemaName) {
|
|
189
|
-
return new FluentQueryBuilder(this.mapper, schemaName);
|
|
190
|
-
}
|
|
191
|
-
useConnection(connectionName) {
|
|
192
|
-
return new FluentConnectionSelector(this.mapper, connectionName);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
export class RawQueryBuilder {
|
|
196
|
-
constructor(mapper, sql) {
|
|
197
|
-
this.mapper = mapper;
|
|
198
|
-
this.sql = sql;
|
|
199
|
-
this._bindings = [];
|
|
200
|
-
}
|
|
201
|
-
bind(bindings) {
|
|
202
|
-
if (Array.isArray(bindings)) {
|
|
203
|
-
this._bindings = bindings;
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
this._bindings = [bindings];
|
|
207
|
-
}
|
|
208
|
-
return this;
|
|
209
|
-
}
|
|
210
|
-
async run() {
|
|
211
|
-
// Find a default connection or use one if specified (not currently supported in raw() entry point args, defaulting to 'default')
|
|
212
|
-
// To support explicit connection for raw, we might need Mapper.connection('name').raw(...)
|
|
213
|
-
const connections = this.mapper.getConnections();
|
|
214
|
-
const conn = connections.get('default'); // Default fallback
|
|
215
|
-
if (!conn)
|
|
216
|
-
throw new Error("No default connection found for raw query.");
|
|
217
|
-
const adapter = connections.getAdapter(conn.name);
|
|
218
|
-
if (adapter && typeof adapter.query === 'function') {
|
|
219
|
-
return adapter.query(this.sql, this._bindings);
|
|
220
|
-
}
|
|
221
|
-
throw new Error(`Connection '${conn.name}' does not support raw queries.`);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
export class BaseQueryBuilder {
|
|
225
|
-
constructor(mapper, target) {
|
|
226
|
-
this.mapper = mapper;
|
|
227
|
-
this.target = target;
|
|
228
|
-
this._select = [];
|
|
229
|
-
this._action = 'select';
|
|
230
|
-
this.queryBuilder = new FluentQueryBuilder(mapper, target);
|
|
231
|
-
}
|
|
232
|
-
select(fields) {
|
|
233
|
-
this._select = fields;
|
|
234
|
-
this._action = 'select';
|
|
235
|
-
return this;
|
|
236
|
-
}
|
|
237
|
-
where(field, value, operator) {
|
|
238
|
-
this.queryBuilder.where(field, value, operator);
|
|
239
|
-
return this;
|
|
240
|
-
}
|
|
241
|
-
whereRaw(raw) {
|
|
242
|
-
this.queryBuilder.whereRaw(raw);
|
|
243
|
-
return this;
|
|
244
|
-
}
|
|
245
|
-
limit(n) {
|
|
246
|
-
this.queryBuilder.limit(n);
|
|
247
|
-
return this;
|
|
248
|
-
}
|
|
249
|
-
offset(n) {
|
|
250
|
-
this.queryBuilder.offset(n);
|
|
251
|
-
return this;
|
|
252
|
-
}
|
|
253
|
-
insert(data) {
|
|
254
|
-
this._insertData = data;
|
|
255
|
-
this._action = 'insert';
|
|
256
|
-
return this;
|
|
257
|
-
}
|
|
258
|
-
update(data) {
|
|
259
|
-
this._updateData = data;
|
|
260
|
-
this._action = 'update';
|
|
261
|
-
return this;
|
|
262
|
-
}
|
|
263
|
-
async get() {
|
|
264
|
-
return this.queryBuilder.get(...this._select);
|
|
265
|
-
}
|
|
266
|
-
async getOne() {
|
|
267
|
-
// If select fields were provided, apply them first (though getOne usually fetches all or requires separate select handling in standard query)
|
|
268
|
-
// FluentQueryBuilder.getOne doesn't take args, but we can ensure fields are selected if underlying support exists.
|
|
269
|
-
// Current FluentQueryBuilder doesn't support select() state persistence easily without get() args.
|
|
270
|
-
// We'll proceed with getOne(). To support partial select on getOne, we might need to enhance FluentQueryBuilder or just fetch all.
|
|
271
|
-
// For now, delegating effectively:
|
|
272
|
-
return this.queryBuilder.getOne();
|
|
273
|
-
}
|
|
274
|
-
async run() {
|
|
275
|
-
if (this._action === 'insert') {
|
|
276
|
-
return this.queryBuilder.insert(this._insertData);
|
|
277
|
-
}
|
|
278
|
-
if (this._action === 'update') {
|
|
279
|
-
return this.queryBuilder.update(this._updateData);
|
|
280
|
-
}
|
|
281
|
-
// Fallback or other actions
|
|
282
|
-
return this.get();
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
export class FluentApiRequestBuilder {
|
|
286
|
-
constructor(mapper, connectionName, path = '') {
|
|
16
|
+
constructor(mapper, name, type, config) {
|
|
17
|
+
this.name = name;
|
|
18
|
+
this.type = type;
|
|
287
19
|
this.mapper = mapper;
|
|
288
|
-
this.
|
|
289
|
-
this._path = '';
|
|
290
|
-
this._headers = {};
|
|
291
|
-
this._path = path;
|
|
20
|
+
this.mapper.connect(name, type, config);
|
|
292
21
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
this._path = p;
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
if (!p.startsWith('/') && !this._path.endsWith('/')) {
|
|
299
|
-
this._path += '/';
|
|
300
|
-
}
|
|
301
|
-
this._path += p;
|
|
302
|
-
}
|
|
303
|
-
return this;
|
|
304
|
-
}
|
|
305
|
-
header(key, value) {
|
|
306
|
-
if (typeof key === 'object') {
|
|
307
|
-
Object.entries(key).forEach(([k, v]) => this.header(k, v));
|
|
308
|
-
}
|
|
309
|
-
else if (value !== undefined) {
|
|
310
|
-
if (this._headers[key]) {
|
|
311
|
-
const existing = this._headers[key];
|
|
312
|
-
if (Array.isArray(existing)) {
|
|
313
|
-
if (Array.isArray(value)) {
|
|
314
|
-
existing.push(...value);
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
existing.push(value);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
this._headers[key] = [existing, ...(Array.isArray(value) ? value : [value])];
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
this._headers[key] = value;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
// Check for "Key: Value" string
|
|
330
|
-
if (key.includes(':')) {
|
|
331
|
-
const [k, ...v] = key.split(':');
|
|
332
|
-
this.header(k.trim(), v.join(':').trim());
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return this;
|
|
336
|
-
}
|
|
337
|
-
headers(h) {
|
|
338
|
-
if (Array.isArray(h)) {
|
|
339
|
-
h.forEach(item => this.header(item));
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
this.header(h);
|
|
343
|
-
}
|
|
344
|
-
return this;
|
|
22
|
+
base(target) {
|
|
23
|
+
return new BaseDispatcher(this.mapper, target);
|
|
345
24
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
async put(data) { return this.execute('PUT', data); }
|
|
349
|
-
async patch(data) { return this.execute('PATCH', data); }
|
|
350
|
-
async delete() { return this.execute('DELETE'); }
|
|
351
|
-
async execute(method, data) {
|
|
352
|
-
const adapter = this.mapper.getConnections().getAdapter(this.connectionName);
|
|
353
|
-
if (!adapter || typeof adapter.request !== 'function') {
|
|
354
|
-
throw new Error(`Connection "${this.connectionName}" does not support custom requests.`);
|
|
355
|
-
}
|
|
356
|
-
return adapter.request(method, this._path, data, this._headers);
|
|
25
|
+
query(target) {
|
|
26
|
+
return this.base(target);
|
|
357
27
|
}
|
|
358
28
|
}
|
|
359
29
|
export class FluentConnectionSelector {
|
|
360
|
-
constructor(mapper,
|
|
30
|
+
constructor(mapper, name) {
|
|
361
31
|
this.mapper = mapper;
|
|
362
|
-
this.
|
|
363
|
-
}
|
|
364
|
-
schema(schemaName) {
|
|
365
|
-
return new FluentSchemaBuilder(this.mapper, schemaName, this.connectionName);
|
|
32
|
+
this.name = name;
|
|
366
33
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
return new
|
|
372
|
-
}
|
|
373
|
-
table(tableName) {
|
|
374
|
-
return this.query(tableName);
|
|
375
|
-
}
|
|
376
|
-
collection(collectionName) {
|
|
377
|
-
return this.query(collectionName);
|
|
378
|
-
}
|
|
379
|
-
// API Request methods
|
|
380
|
-
path(path) {
|
|
381
|
-
return new FluentApiRequestBuilder(this.mapper, this.connectionName, path);
|
|
382
|
-
}
|
|
383
|
-
header(key, value) {
|
|
384
|
-
return new FluentApiRequestBuilder(this.mapper, this.connectionName).header(key, value);
|
|
385
|
-
}
|
|
386
|
-
headers(headers) {
|
|
387
|
-
return new FluentApiRequestBuilder(this.mapper, this.connectionName).headers(headers);
|
|
388
|
-
}
|
|
389
|
-
get() {
|
|
390
|
-
return new FluentApiRequestBuilder(this.mapper, this.connectionName).get();
|
|
391
|
-
}
|
|
392
|
-
post(data) {
|
|
393
|
-
return new FluentApiRequestBuilder(this.mapper, this.connectionName).post(data);
|
|
394
|
-
}
|
|
395
|
-
put(data) {
|
|
396
|
-
return new FluentApiRequestBuilder(this.mapper, this.connectionName).put(data);
|
|
397
|
-
}
|
|
398
|
-
patch(data) {
|
|
399
|
-
return new FluentApiRequestBuilder(this.mapper, this.connectionName).patch(data);
|
|
34
|
+
base(target) {
|
|
35
|
+
// Determine how to pass context? BaseDispatcher usually gets just mapper and target.
|
|
36
|
+
// If we need specific connection, we might need to assume 'useConnection' behavior.
|
|
37
|
+
// For now, simple forwarding.
|
|
38
|
+
return new BaseDispatcher(this.mapper, target);
|
|
400
39
|
}
|
|
401
|
-
|
|
402
|
-
return
|
|
40
|
+
query(target) {
|
|
41
|
+
return this.base(target);
|
|
403
42
|
}
|
|
404
43
|
}
|
|
405
44
|
export class FluentMapper {
|
|
406
45
|
constructor(mapper) {
|
|
407
46
|
this.mapper = mapper;
|
|
408
47
|
}
|
|
409
|
-
|
|
410
|
-
|
|
48
|
+
// Entry Point: BASE (DML)
|
|
49
|
+
base(target) {
|
|
50
|
+
return new BaseDispatcher(this.mapper, target);
|
|
51
|
+
}
|
|
52
|
+
// Entry Point: QUERY (Alias for Base)
|
|
53
|
+
query(target) {
|
|
54
|
+
return this.base(target);
|
|
411
55
|
}
|
|
56
|
+
// Entry Point: SCHEMA (DDL)
|
|
412
57
|
schema(name) {
|
|
413
|
-
return new
|
|
414
|
-
}
|
|
415
|
-
table(name) {
|
|
416
|
-
return this.query(name);
|
|
58
|
+
return new SchemaDispatcher(this.mapper, name);
|
|
417
59
|
}
|
|
60
|
+
// Entry Point: RAW
|
|
418
61
|
raw(sql) {
|
|
419
|
-
return new
|
|
420
|
-
}
|
|
421
|
-
base(target) {
|
|
422
|
-
return new BaseQueryBuilder(this.mapper, target);
|
|
62
|
+
return new RawBuilder(this.mapper, sql);
|
|
423
63
|
}
|
|
64
|
+
// Connection Management
|
|
424
65
|
makeConnection(name, type, config) {
|
|
425
66
|
return new FluentConnectionBuilder(this.mapper, name, type, config);
|
|
426
67
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
new FluentConnectionBuilder(this.mapper, tempName, type, config); // Registers it
|
|
446
|
-
return new FluentConnectionSelector(this.mapper, tempName);
|
|
447
|
-
}
|
|
448
|
-
makeTempConnection(type, config) {
|
|
449
|
-
const tempName = `temp_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
450
|
-
return new FluentConnectionBuilder(this.mapper, tempName, type, config);
|
|
451
|
-
}
|
|
452
|
-
// Direct query methods for quick usage
|
|
453
|
-
async get(schemaName, filters) {
|
|
454
|
-
return this.mapper.get(schemaName, filters);
|
|
455
|
-
}
|
|
456
|
-
async getOne(schemaName, filters) {
|
|
457
|
-
return this.mapper.getOne(schemaName, filters);
|
|
458
|
-
}
|
|
459
|
-
async add(schemaName, data) {
|
|
460
|
-
return this.mapper.add(schemaName, data);
|
|
461
|
-
}
|
|
462
|
-
async update(schemaName, filters, data) {
|
|
463
|
-
return this.mapper.update(schemaName, filters, data);
|
|
464
|
-
}
|
|
465
|
-
async delete(schemaName, filters) {
|
|
466
|
-
return this.mapper.delete(schemaName, filters);
|
|
467
|
-
}
|
|
468
|
-
async dropTable(name) {
|
|
469
|
-
return new TableMigrator(name).drop().exec();
|
|
68
|
+
connection(configOrName) {
|
|
69
|
+
if (typeof configOrName === 'string')
|
|
70
|
+
return new FluentConnectionSelector(this.mapper, configOrName);
|
|
71
|
+
// Temp connection logic could go here
|
|
72
|
+
return new FluentConnectionSelector(this.mapper, 'default');
|
|
73
|
+
}
|
|
74
|
+
// Direct shortcuts (Legacy support maintenance)
|
|
75
|
+
async get(target) { return this.base(target).select().get(); }
|
|
76
|
+
async add(target, data) { return this.base(target).insert(data).run(); }
|
|
77
|
+
async update(target, filter, data) {
|
|
78
|
+
let b = this.base(target).update(data);
|
|
79
|
+
Object.keys(filter).forEach(k => b.where(k, filter[k]));
|
|
80
|
+
return b.run();
|
|
81
|
+
}
|
|
82
|
+
async delete(target, filter) {
|
|
83
|
+
let b = this.base(target).delete();
|
|
84
|
+
Object.keys(filter).forEach(k => b.where(k, filter[k]));
|
|
85
|
+
return b.run();
|
|
470
86
|
}
|
|
471
87
|
}
|
|
472
|
-
// Static API class that provides the fluent interface
|
|
473
88
|
export class StaticMapper {
|
|
474
89
|
static getFluentMapper() {
|
|
475
90
|
if (!StaticMapper.instance) {
|
|
476
|
-
|
|
477
|
-
StaticMapper.instance = new FluentMapper(baseMapper);
|
|
91
|
+
StaticMapper.instance = new FluentMapper(createMapper());
|
|
478
92
|
}
|
|
479
93
|
return StaticMapper.instance;
|
|
480
94
|
}
|
|
481
|
-
static
|
|
482
|
-
|
|
483
|
-
}
|
|
484
|
-
static
|
|
485
|
-
|
|
486
|
-
}
|
|
487
|
-
static query(schemaName) {
|
|
488
|
-
return StaticMapper.getFluentMapper().query(schemaName);
|
|
489
|
-
}
|
|
490
|
-
static schema(name) {
|
|
491
|
-
if (name)
|
|
492
|
-
return StaticMapper.getFluentMapper().schema(name);
|
|
493
|
-
return StaticMapper.schemas();
|
|
494
|
-
}
|
|
495
|
-
static table(name) {
|
|
496
|
-
return StaticMapper.query(name);
|
|
497
|
-
}
|
|
498
|
-
static raw(sql) {
|
|
499
|
-
return StaticMapper.getFluentMapper().raw(sql);
|
|
500
|
-
}
|
|
501
|
-
static base(target) {
|
|
502
|
-
return StaticMapper.getFluentMapper().base(target);
|
|
503
|
-
}
|
|
504
|
-
// New API
|
|
505
|
-
static connection(connectionOrConfig) {
|
|
506
|
-
return StaticMapper.getFluentMapper().connection(connectionOrConfig);
|
|
507
|
-
}
|
|
508
|
-
// Deprecated alias
|
|
509
|
-
static useConnection(connectionName) {
|
|
510
|
-
return StaticMapper.connection(connectionName);
|
|
511
|
-
}
|
|
512
|
-
static schemas(name) {
|
|
513
|
-
if (name)
|
|
514
|
-
return StaticMapper.schema(name);
|
|
515
|
-
return new SchemaManagerWrapper(StaticMapper.getFluentMapper().mapper.getSchemaManager());
|
|
516
|
-
}
|
|
517
|
-
// Direct static methods
|
|
518
|
-
static async get(schemaName, filters) {
|
|
519
|
-
return StaticMapper.getFluentMapper().get(schemaName, filters);
|
|
520
|
-
}
|
|
521
|
-
static async getOne(schemaName, filters) {
|
|
522
|
-
return StaticMapper.getFluentMapper().getOne(schemaName, filters);
|
|
523
|
-
}
|
|
524
|
-
static async add(schemaName, data) {
|
|
525
|
-
return StaticMapper.getFluentMapper().add(schemaName, data);
|
|
526
|
-
}
|
|
527
|
-
static async update(schemaName, filters, data) {
|
|
528
|
-
return StaticMapper.getFluentMapper().update(schemaName, filters, data);
|
|
529
|
-
}
|
|
530
|
-
static async delete(schemaName, filters) {
|
|
531
|
-
return StaticMapper.getFluentMapper().delete(schemaName, filters);
|
|
532
|
-
}
|
|
533
|
-
static async dropTable(name) {
|
|
534
|
-
return StaticMapper.getFluentMapper().dropTable(name);
|
|
535
|
-
}
|
|
536
|
-
static getConnections() {
|
|
537
|
-
return StaticMapper.getFluentMapper().mapper.getConnections();
|
|
538
|
-
}
|
|
95
|
+
static base(target) { return StaticMapper.getFluentMapper().base(target); }
|
|
96
|
+
static query(target) { return StaticMapper.getFluentMapper().query(target); }
|
|
97
|
+
static schema(name) { return StaticMapper.getFluentMapper().schema(name); }
|
|
98
|
+
static raw(sql) { return StaticMapper.getFluentMapper().raw(sql); }
|
|
99
|
+
static connection(arg) { return StaticMapper.getFluentMapper().connection(arg); }
|
|
100
|
+
static makeConnection(n, t, c) { return StaticMapper.getFluentMapper().makeConnection(n, t, c); }
|
|
539
101
|
static async discover() {
|
|
540
102
|
const { discover } = await import('./discovery.js');
|
|
541
103
|
return discover();
|
|
542
104
|
}
|
|
105
|
+
// Helpers for simple usage
|
|
106
|
+
static async get(t) { return StaticMapper.getFluentMapper().get(t); }
|
|
107
|
+
static async add(t, d) { return StaticMapper.getFluentMapper().add(t, d); }
|
|
543
108
|
}
|
|
544
|
-
// Export a default instance for convenience
|
|
545
109
|
export const Mapper = StaticMapper;
|
|
546
110
|
export default Mapper;
|
|
547
|
-
// Helper to access parseDescriptorStructure from index.ts if not exported?
|
|
548
|
-
// It is NOT exported. I need to export it or duplicate logic.
|
|
549
|
-
// I'll export it from index.ts.
|
|
550
|
-
import { parseDescriptorStructure } from './index.js'; // fixed import at bottom
|
|
551
|
-
export class SchemaManagerWrapper {
|
|
552
|
-
constructor(manager) {
|
|
553
|
-
this.manager = manager;
|
|
554
|
-
}
|
|
555
|
-
table(name) {
|
|
556
|
-
// This allows Mapper.schemas().table('name') to return a migrator
|
|
557
|
-
return new TableMigrator(name);
|
|
558
|
-
}
|
|
559
|
-
schema(name) {
|
|
560
|
-
return this.table(name);
|
|
561
|
-
}
|
|
562
|
-
async dropTable(name) {
|
|
563
|
-
return new TableMigrator(name).drop().exec();
|
|
564
|
-
}
|
|
565
|
-
}
|
package/dist/index.d.ts
CHANGED
|
@@ -127,8 +127,8 @@ export type { EnvDslConnections, NormalizedConnection } from './env.js';
|
|
|
127
127
|
export { documentationMd, markdownToHtml, getDocumentationHtml } from './docs.js';
|
|
128
128
|
export { Mapper, createMapper } from './mapper.js';
|
|
129
129
|
export { default } from './mapper.js';
|
|
130
|
-
export { StaticMapper,
|
|
131
|
-
export type {
|
|
130
|
+
export { StaticMapper, RawBuilder, BaseDispatcher } from './fluent-mapper.js';
|
|
131
|
+
export type { FluentConnectionBuilder, FluentConnectionSelector, FluentMapper } from './fluent-mapper.js';
|
|
132
132
|
export { ConfigBasedMapper, ConfigLoader, createConfigMapper, getConfigMapper, createDefaultMapper } from './config.js';
|
|
133
133
|
export type { MapperConfig, ConnectionConfig, DatabaseConnectionConfig, ApiConnectionConfig, SqliteConnectionConfig, ConfigSchema } from './config.js';
|
|
134
134
|
export { MySQLAdapter, createMySQLAdapter, PostgreSQLAdapter, createPostgreSQLAdapter, MongoDBAdapter, createMongoDBAdapter, APIAdapter, createAPIAdapter, SQLiteAdapter, createSQLiteAdapter, createAdapter, createAdapterFromUrl, autoAttachAdapter } from './adapters/index.js';
|
package/dist/index.js
CHANGED
|
@@ -396,8 +396,7 @@ export { documentationMd, markdownToHtml, getDocumentationHtml } from './docs.js
|
|
|
396
396
|
// Export the simplified Mapper and default instance
|
|
397
397
|
export { Mapper, createMapper } from './mapper.js';
|
|
398
398
|
export { default } from './mapper.js';
|
|
399
|
-
|
|
400
|
-
export { StaticMapper, RawQueryBuilder, BaseQueryBuilder } from './fluent-mapper.js';
|
|
399
|
+
export { StaticMapper, RawBuilder, BaseDispatcher } from './fluent-mapper.js';
|
|
401
400
|
// Export the new config-based system
|
|
402
401
|
export { ConfigBasedMapper, ConfigLoader, createConfigMapper, getConfigMapper, createDefaultMapper } from './config.js';
|
|
403
402
|
// Export database adapters
|