@neupgroup/mapper 1.2.3 → 1.2.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.
@@ -0,0 +1,166 @@
1
+ /**
2
+ * MySQL Database Adapter
3
+ * Requires: npm install mysql2
4
+ */
5
+ export class MySQLAdapter {
6
+ constructor(config) {
7
+ try {
8
+ // Dynamically import mysql2 to avoid bundling if not used
9
+ this.mysql = require('mysql2/promise');
10
+ this.pool = this.mysql.createPool({
11
+ host: config.host,
12
+ port: config.port || 3306,
13
+ user: config.user,
14
+ password: config.password,
15
+ database: config.database,
16
+ waitForConnections: true,
17
+ connectionLimit: config.connectionLimit || 10,
18
+ queueLimit: 0,
19
+ ssl: config.ssl,
20
+ });
21
+ }
22
+ catch (error) {
23
+ throw new Error(`Failed to initialize MySQL adapter: ${error.message}\n` +
24
+ `Make sure to install mysql2: npm install mysql2`);
25
+ }
26
+ }
27
+ buildWhereClause(options) {
28
+ const values = [];
29
+ const conditions = [];
30
+ // Handle raw WHERE clause
31
+ if (options.rawWhere) {
32
+ return { sql: options.rawWhere, values: [] };
33
+ }
34
+ // Build WHERE conditions from filters
35
+ for (const filter of options.filters) {
36
+ const { field, operator, value } = filter;
37
+ switch (operator) {
38
+ case '=':
39
+ case '>':
40
+ case '<':
41
+ case '>=':
42
+ case '<=':
43
+ case '!=':
44
+ conditions.push(`\`${field}\` ${operator} ?`);
45
+ values.push(value);
46
+ break;
47
+ case 'LIKE':
48
+ conditions.push(`\`${field}\` LIKE ?`);
49
+ values.push(value);
50
+ break;
51
+ case 'IN':
52
+ conditions.push(`\`${field}\` IN (?)`);
53
+ values.push(value);
54
+ break;
55
+ default:
56
+ conditions.push(`\`${field}\` = ?`);
57
+ values.push(value);
58
+ }
59
+ }
60
+ const sql = conditions.length > 0 ? conditions.join(' AND ') : '';
61
+ return { sql, values };
62
+ }
63
+ async get(options) {
64
+ const connection = await this.pool.getConnection();
65
+ try {
66
+ const fields = options.fields.length > 0
67
+ ? options.fields.map(f => `\`${f}\``).join(', ')
68
+ : '*';
69
+ let sql = `SELECT ${fields} FROM \`${options.collectionName}\``;
70
+ const values = [];
71
+ // Add WHERE clause
72
+ const { sql: whereSql, values: whereValues } = this.buildWhereClause(options);
73
+ if (whereSql) {
74
+ sql += ` WHERE ${whereSql}`;
75
+ values.push(...whereValues);
76
+ }
77
+ // Add ORDER BY
78
+ if (options.sortBy) {
79
+ sql += ` ORDER BY \`${options.sortBy.field}\` ${options.sortBy.direction.toUpperCase()}`;
80
+ }
81
+ // Add LIMIT and OFFSET
82
+ if (options.limit !== null) {
83
+ sql += ` LIMIT ?`;
84
+ values.push(options.limit);
85
+ }
86
+ if (options.offset !== null) {
87
+ sql += ` OFFSET ?`;
88
+ values.push(options.offset);
89
+ }
90
+ const [rows] = await connection.execute(sql, values);
91
+ return rows;
92
+ }
93
+ finally {
94
+ connection.release();
95
+ }
96
+ }
97
+ async getOne(options) {
98
+ const results = await this.get({ ...options, limit: 1 });
99
+ return results[0] || null;
100
+ }
101
+ async getDocuments(options) {
102
+ return this.get(options);
103
+ }
104
+ async addDocument(collectionName, data) {
105
+ const connection = await this.pool.getConnection();
106
+ try {
107
+ const fields = Object.keys(data);
108
+ const placeholders = fields.map(() => '?').join(', ');
109
+ const values = Object.values(data);
110
+ const sql = `INSERT INTO \`${collectionName}\` (${fields.map(f => `\`${f}\``).join(', ')}) VALUES (${placeholders})`;
111
+ const [result] = await connection.execute(sql, values);
112
+ return String(result.insertId);
113
+ }
114
+ finally {
115
+ connection.release();
116
+ }
117
+ }
118
+ async updateDocument(collectionName, docId, data) {
119
+ const connection = await this.pool.getConnection();
120
+ try {
121
+ const fields = Object.keys(data);
122
+ const setClause = fields.map(f => `\`${f}\` = ?`).join(', ');
123
+ const values = [...Object.values(data), docId];
124
+ const sql = `UPDATE \`${collectionName}\` SET ${setClause} WHERE id = ?`;
125
+ await connection.execute(sql, values);
126
+ }
127
+ finally {
128
+ connection.release();
129
+ }
130
+ }
131
+ async deleteDocument(collectionName, docId) {
132
+ const connection = await this.pool.getConnection();
133
+ try {
134
+ const sql = `DELETE FROM \`${collectionName}\` WHERE id = ?`;
135
+ await connection.execute(sql, [docId]);
136
+ }
137
+ finally {
138
+ connection.release();
139
+ }
140
+ }
141
+ /**
142
+ * Close all connections in the pool
143
+ */
144
+ async close() {
145
+ await this.pool.end();
146
+ }
147
+ /**
148
+ * Execute a raw SQL query
149
+ */
150
+ async raw(sql, values) {
151
+ const connection = await this.pool.getConnection();
152
+ try {
153
+ const [results] = await connection.execute(sql, values || []);
154
+ return results;
155
+ }
156
+ finally {
157
+ connection.release();
158
+ }
159
+ }
160
+ }
161
+ /**
162
+ * Factory function to create MySQL adapter
163
+ */
164
+ export function createMySQLAdapter(config) {
165
+ return new MySQLAdapter(config);
166
+ }
@@ -0,0 +1,52 @@
1
+ import type { DbAdapter, QueryOptions, DocumentData } from '../orm/types';
2
+ export interface PostgreSQLConfig {
3
+ host: string;
4
+ port?: number;
5
+ user: string;
6
+ password: string;
7
+ database: string;
8
+ max?: number;
9
+ ssl?: boolean | {
10
+ rejectUnauthorized?: boolean;
11
+ };
12
+ }
13
+ /**
14
+ * PostgreSQL Database Adapter
15
+ * Requires: npm install pg
16
+ */
17
+ export declare class PostgreSQLAdapter implements DbAdapter {
18
+ private pool;
19
+ private pg;
20
+ constructor(config: PostgreSQLConfig);
21
+ private buildWhereClause;
22
+ get(options: QueryOptions): Promise<DocumentData[]>;
23
+ getOne(options: QueryOptions): Promise<DocumentData | null>;
24
+ getDocuments(options: QueryOptions): Promise<DocumentData[]>;
25
+ addDocument(collectionName: string, data: DocumentData): Promise<string>;
26
+ updateDocument(collectionName: string, docId: string, data: DocumentData): Promise<void>;
27
+ deleteDocument(collectionName: string, docId: string): Promise<void>;
28
+ /**
29
+ * Close all connections in the pool
30
+ */
31
+ close(): Promise<void>;
32
+ /**
33
+ * Execute a raw SQL query
34
+ */
35
+ raw(sql: string, values?: any[]): Promise<any>;
36
+ /**
37
+ * Begin a transaction
38
+ */
39
+ beginTransaction(): Promise<any>;
40
+ /**
41
+ * Commit a transaction
42
+ */
43
+ commitTransaction(client: any): Promise<void>;
44
+ /**
45
+ * Rollback a transaction
46
+ */
47
+ rollbackTransaction(client: any): Promise<void>;
48
+ }
49
+ /**
50
+ * Factory function to create PostgreSQL adapter
51
+ */
52
+ export declare function createPostgreSQLAdapter(config: PostgreSQLConfig): PostgreSQLAdapter;
@@ -0,0 +1,204 @@
1
+ /**
2
+ * PostgreSQL Database Adapter
3
+ * Requires: npm install pg
4
+ */
5
+ export class PostgreSQLAdapter {
6
+ constructor(config) {
7
+ try {
8
+ // Dynamically import pg to avoid bundling if not used
9
+ this.pg = require('pg');
10
+ this.pool = new this.pg.Pool({
11
+ host: config.host,
12
+ port: config.port || 5432,
13
+ user: config.user,
14
+ password: config.password,
15
+ database: config.database,
16
+ max: config.max || 10,
17
+ ssl: config.ssl,
18
+ });
19
+ }
20
+ catch (error) {
21
+ throw new Error(`Failed to initialize PostgreSQL adapter: ${error.message}\n` +
22
+ `Make sure to install pg: npm install pg`);
23
+ }
24
+ }
25
+ buildWhereClause(options) {
26
+ const values = [];
27
+ const conditions = [];
28
+ let paramIndex = 1;
29
+ // Handle raw WHERE clause
30
+ if (options.rawWhere) {
31
+ return { sql: options.rawWhere, values: [] };
32
+ }
33
+ // Build WHERE conditions from filters
34
+ for (const filter of options.filters) {
35
+ const { field, operator, value } = filter;
36
+ switch (operator) {
37
+ case '=':
38
+ case '>':
39
+ case '<':
40
+ case '>=':
41
+ case '<=':
42
+ case '!=':
43
+ conditions.push(`"${field}" ${operator} $${paramIndex}`);
44
+ values.push(value);
45
+ paramIndex++;
46
+ break;
47
+ case 'LIKE':
48
+ case 'ILIKE':
49
+ conditions.push(`"${field}" ${operator} $${paramIndex}`);
50
+ values.push(value);
51
+ paramIndex++;
52
+ break;
53
+ case 'IN':
54
+ conditions.push(`"${field}" = ANY($${paramIndex})`);
55
+ values.push(Array.isArray(value) ? value : [value]);
56
+ paramIndex++;
57
+ break;
58
+ default:
59
+ conditions.push(`"${field}" = $${paramIndex}`);
60
+ values.push(value);
61
+ paramIndex++;
62
+ }
63
+ }
64
+ const sql = conditions.length > 0 ? conditions.join(' AND ') : '';
65
+ return { sql, values };
66
+ }
67
+ async get(options) {
68
+ const client = await this.pool.connect();
69
+ try {
70
+ const fields = options.fields.length > 0
71
+ ? options.fields.map(f => `"${f}"`).join(', ')
72
+ : '*';
73
+ let sql = `SELECT ${fields} FROM "${options.collectionName}"`;
74
+ const values = [];
75
+ // Add WHERE clause
76
+ const { sql: whereSql, values: whereValues } = this.buildWhereClause(options);
77
+ if (whereSql) {
78
+ sql += ` WHERE ${whereSql}`;
79
+ values.push(...whereValues);
80
+ }
81
+ let paramIndex = values.length + 1;
82
+ // Add ORDER BY
83
+ if (options.sortBy) {
84
+ sql += ` ORDER BY "${options.sortBy.field}" ${options.sortBy.direction.toUpperCase()}`;
85
+ }
86
+ // Add LIMIT and OFFSET
87
+ if (options.limit !== null) {
88
+ sql += ` LIMIT $${paramIndex}`;
89
+ values.push(options.limit);
90
+ paramIndex++;
91
+ }
92
+ if (options.offset !== null) {
93
+ sql += ` OFFSET $${paramIndex}`;
94
+ values.push(options.offset);
95
+ paramIndex++;
96
+ }
97
+ const result = await client.query(sql, values);
98
+ return result.rows;
99
+ }
100
+ finally {
101
+ client.release();
102
+ }
103
+ }
104
+ async getOne(options) {
105
+ const results = await this.get({ ...options, limit: 1 });
106
+ return results[0] || null;
107
+ }
108
+ async getDocuments(options) {
109
+ return this.get(options);
110
+ }
111
+ async addDocument(collectionName, data) {
112
+ var _a;
113
+ const client = await this.pool.connect();
114
+ try {
115
+ const fields = Object.keys(data);
116
+ const values = Object.values(data);
117
+ const placeholders = fields.map((_, i) => `$${i + 1}`).join(', ');
118
+ const sql = `INSERT INTO "${collectionName}" (${fields.map(f => `"${f}"`).join(', ')}) VALUES (${placeholders}) RETURNING id`;
119
+ const result = await client.query(sql, values);
120
+ return String(((_a = result.rows[0]) === null || _a === void 0 ? void 0 : _a.id) || '');
121
+ }
122
+ finally {
123
+ client.release();
124
+ }
125
+ }
126
+ async updateDocument(collectionName, docId, data) {
127
+ const client = await this.pool.connect();
128
+ try {
129
+ const fields = Object.keys(data);
130
+ const values = Object.values(data);
131
+ const setClause = fields.map((f, i) => `"${f}" = $${i + 1}`).join(', ');
132
+ const sql = `UPDATE "${collectionName}" SET ${setClause} WHERE id = $${fields.length + 1}`;
133
+ await client.query(sql, [...values, docId]);
134
+ }
135
+ finally {
136
+ client.release();
137
+ }
138
+ }
139
+ async deleteDocument(collectionName, docId) {
140
+ const client = await this.pool.connect();
141
+ try {
142
+ const sql = `DELETE FROM "${collectionName}" WHERE id = $1`;
143
+ await client.query(sql, [docId]);
144
+ }
145
+ finally {
146
+ client.release();
147
+ }
148
+ }
149
+ /**
150
+ * Close all connections in the pool
151
+ */
152
+ async close() {
153
+ await this.pool.end();
154
+ }
155
+ /**
156
+ * Execute a raw SQL query
157
+ */
158
+ async raw(sql, values) {
159
+ const client = await this.pool.connect();
160
+ try {
161
+ const result = await client.query(sql, values || []);
162
+ return result.rows;
163
+ }
164
+ finally {
165
+ client.release();
166
+ }
167
+ }
168
+ /**
169
+ * Begin a transaction
170
+ */
171
+ async beginTransaction() {
172
+ const client = await this.pool.connect();
173
+ await client.query('BEGIN');
174
+ return client;
175
+ }
176
+ /**
177
+ * Commit a transaction
178
+ */
179
+ async commitTransaction(client) {
180
+ try {
181
+ await client.query('COMMIT');
182
+ }
183
+ finally {
184
+ client.release();
185
+ }
186
+ }
187
+ /**
188
+ * Rollback a transaction
189
+ */
190
+ async rollbackTransaction(client) {
191
+ try {
192
+ await client.query('ROLLBACK');
193
+ }
194
+ finally {
195
+ client.release();
196
+ }
197
+ }
198
+ }
199
+ /**
200
+ * Factory function to create PostgreSQL adapter
201
+ */
202
+ export function createPostgreSQLAdapter(config) {
203
+ return new PostgreSQLAdapter(config);
204
+ }
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Connections, SchemaManager } from './index';
1
+ import { Connections, SchemaManager } from './index.js';
2
2
  export interface DatabaseConnectionConfig {
3
3
  name: string;
4
4
  type: 'mysql' | 'sql' | 'firestore' | 'mongodb';
@@ -55,7 +55,7 @@ export declare class ConfigBasedMapper {
55
55
  getSchemaManager(): SchemaManager;
56
56
  use(schemaName: string): any;
57
57
  schema(name: string): any;
58
- connect(name: string, type: 'mysql' | 'sql' | 'firestore' | 'mongodb' | 'api', config: Record<string, any>): import("./mapper").Mapper;
58
+ connect(name: string, type: 'mysql' | 'sql' | 'firestore' | 'mongodb' | 'api', config: Record<string, any>): import("./mapper.js").Mapper;
59
59
  get(schemaName: string, filters?: Record<string, any>): Promise<Record<string, any>[]>;
60
60
  getOne(schemaName: string, filters?: Record<string, any>): Promise<Record<string, any> | null>;
61
61
  add(schemaName: string, data: Record<string, any>): Promise<any>;
package/dist/config.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createMapper } from './mapper';
1
+ import { createMapper } from './mapper.js';
2
2
  export class ConfigLoader {
3
3
  static getInstance() {
4
4
  if (!ConfigLoader.instance) {
@@ -0,0 +1,57 @@
1
+ import { ConnectionType } from './index.js';
2
+ /**
3
+ * A fluent builder for dynamic connections and ad-hoc queries.
4
+ * This allows defining connections with runtime values (variables, env, etc.)
5
+ * rather than relying solely on static configuration.
6
+ */
7
+ export declare class Connector {
8
+ private _name;
9
+ private _type;
10
+ private _config;
11
+ private _collection;
12
+ /**
13
+ * Start a new connection definition.
14
+ * Usage: new Connector().name('myDb')...
15
+ */
16
+ constructor(name?: string);
17
+ /**
18
+ * Set the connection name.
19
+ */
20
+ name(n: string): this;
21
+ /**
22
+ * Set the connection type.
23
+ * Supported types: 'mysql', 'sql' (postgres/sqlite), 'mongodb', 'api'.
24
+ */
25
+ type(t: ConnectionType | string): this;
26
+ /**
27
+ * Generic configuration setup.
28
+ * Pass any key-value pairs required by the adapter.
29
+ */
30
+ config(c: Record<string, any>): this;
31
+ /**
32
+ * Set the Base URL (for API connections).
33
+ */
34
+ basePath(url: string): this;
35
+ /**
36
+ * Set the Connection URL/String (for DB connections).
37
+ */
38
+ url(url: string): this;
39
+ /**
40
+ * Define the table or collection to operate on.
41
+ * This registers the connection (if not already) and prepares a query.
42
+ */
43
+ table(tableName: string): import("./fluent-mapper.js").FluentQueryBuilder;
44
+ /**
45
+ * Alias for table() for API endpoints (subpath).
46
+ */
47
+ subpath(path: string): import("./fluent-mapper.js").FluentQueryBuilder;
48
+ /**
49
+ * Finalizes the connection registration and returns a query object.
50
+ */
51
+ private finalize;
52
+ }
53
+ /**
54
+ * Factory function for cleaner syntax:
55
+ * mapper('db').type('mysql')...
56
+ */
57
+ export declare function mapper(name?: string): Connector;
@@ -0,0 +1,114 @@
1
+ import { StaticMapper } from './fluent-mapper.js';
2
+ /**
3
+ * A fluent builder for dynamic connections and ad-hoc queries.
4
+ * This allows defining connections with runtime values (variables, env, etc.)
5
+ * rather than relying solely on static configuration.
6
+ */
7
+ export class Connector {
8
+ /**
9
+ * Start a new connection definition.
10
+ * Usage: new Connector().name('myDb')...
11
+ */
12
+ constructor(name) {
13
+ this._name = '';
14
+ this._type = 'api';
15
+ this._config = {};
16
+ this._collection = '';
17
+ if (name)
18
+ this._name = name;
19
+ }
20
+ /**
21
+ * Set the connection name.
22
+ */
23
+ name(n) {
24
+ this._name = n;
25
+ return this;
26
+ }
27
+ /**
28
+ * Set the connection type.
29
+ * Supported types: 'mysql', 'sql' (postgres/sqlite), 'mongodb', 'api'.
30
+ */
31
+ type(t) {
32
+ // Map 'database_sqlite' or others to supported types if necessary
33
+ if (t === 'database_sqlite')
34
+ t = 'sql';
35
+ this._type = t;
36
+ return this;
37
+ }
38
+ /**
39
+ * Generic configuration setup.
40
+ * Pass any key-value pairs required by the adapter.
41
+ */
42
+ config(c) {
43
+ this._config = { ...this._config, ...c };
44
+ return this;
45
+ }
46
+ /**
47
+ * Set the Base URL (for API connections).
48
+ */
49
+ basePath(url) {
50
+ this._config.baseUrl = url;
51
+ return this;
52
+ }
53
+ /**
54
+ * Set the Connection URL/String (for DB connections).
55
+ */
56
+ url(url) {
57
+ this._config.url = url;
58
+ return this;
59
+ }
60
+ /**
61
+ * Define the table or collection to operate on.
62
+ * This registers the connection (if not already) and prepares a query.
63
+ */
64
+ table(tableName) {
65
+ this._collection = tableName;
66
+ return this.finalize();
67
+ }
68
+ /**
69
+ * Alias for table() for API endpoints (subpath).
70
+ */
71
+ subpath(path) {
72
+ return this.table(path);
73
+ }
74
+ /**
75
+ * Finalizes the connection registration and returns a query object.
76
+ */
77
+ finalize() {
78
+ if (!this._name)
79
+ throw new Error('Connection name is required');
80
+ // Try to register connection, or use existing
81
+ let connInterface;
82
+ try {
83
+ connInterface = StaticMapper.makeConnection(this._name, this._type, this._config);
84
+ }
85
+ catch (e) {
86
+ if (e.message && (e.message.includes('already exists') || e.message.includes('ConnectionExistingError'))) {
87
+ connInterface = StaticMapper.connection(this._name);
88
+ }
89
+ else {
90
+ connInterface = StaticMapper.connection(this._name);
91
+ }
92
+ }
93
+ // Auto-define a schema for this table/collection if we are using one
94
+ const schemaName = `${this._name}_${this._collection}`;
95
+ try {
96
+ // Using the fluent interface to define schema if not exists
97
+ connInterface.schema(schemaName)
98
+ .collection(this._collection)
99
+ .structure({ '?field': 'any' });
100
+ }
101
+ catch (e) {
102
+ // Ignore if schema already exists
103
+ }
104
+ // Return the query builder
105
+ return StaticMapper.query(schemaName);
106
+ }
107
+ }
108
+ /**
109
+ * Factory function for cleaner syntax:
110
+ * mapper('db').type('mysql')...
111
+ */
112
+ export function mapper(name) {
113
+ return new Connector(name);
114
+ }
@@ -0,0 +1,29 @@
1
+ export declare class MapperError extends Error {
2
+ readonly code: string;
3
+ readonly hint?: string | undefined;
4
+ constructor(message: string, code: string, hint?: string | undefined);
5
+ }
6
+ export declare class AdapterMissingError extends MapperError {
7
+ constructor(connectionName: string);
8
+ }
9
+ export declare class UpdatePayloadMissingError extends MapperError {
10
+ constructor();
11
+ }
12
+ export declare class DocumentMissingIdError extends MapperError {
13
+ constructor(operation: string);
14
+ }
15
+ export declare class ConnectionExistingError extends MapperError {
16
+ constructor(name: string);
17
+ }
18
+ export declare class ConnectionUnknownError extends MapperError {
19
+ constructor(method: string, name: string);
20
+ }
21
+ export declare class SchemaExistingError extends MapperError {
22
+ constructor(name: string);
23
+ }
24
+ export declare class SchemaMissingError extends MapperError {
25
+ constructor(name: string);
26
+ }
27
+ export declare class SchemaConfigurationError extends MapperError {
28
+ constructor(message: string);
29
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,50 @@
1
+ export class MapperError extends Error {
2
+ constructor(message, code, hint) {
3
+ super(message);
4
+ this.code = code;
5
+ this.hint = hint;
6
+ this.name = this.constructor.name;
7
+ // Restore prototype chain for instanceof checks (TS workaround)
8
+ Object.setPrototypeOf(this, new.target.prototype);
9
+ }
10
+ }
11
+ export class AdapterMissingError extends MapperError {
12
+ constructor(connectionName) {
13
+ super(`No adapter attached for connection '${connectionName}'.`, 'ADAPTER_MISSING', `Ensure you have registered an adapter for '${connectionName}'. You can use 'Mapper.connection().attachAdapter(...)'`);
14
+ }
15
+ }
16
+ export class UpdatePayloadMissingError extends MapperError {
17
+ constructor() {
18
+ super(`No update payload set for the query.`, 'UPDATE_PAYLOAD_MISSING', `You must call '.to({ ... })' with the data you want to update before executing '.update()' or '.updateOne()'.`);
19
+ }
20
+ }
21
+ export class DocumentMissingIdError extends MapperError {
22
+ constructor(operation) {
23
+ super(`Document is missing its 'id' field, which is required for '${operation}'.`, 'DOCUMENT_MISSING_ID', `Ensure that the documents you are trying to ${operation} have an 'id' property. If you fetched them, make sure 'id' was included in the fields.`);
24
+ }
25
+ }
26
+ export class ConnectionExistingError extends MapperError {
27
+ constructor(name) {
28
+ super(`Connection with name '${name}' already exists.`, 'CONNECTION_EXISTS', `Use a unique name for each connection or check if you are registering the same connection twice.`);
29
+ }
30
+ }
31
+ export class ConnectionUnknownError extends MapperError {
32
+ constructor(method, name) {
33
+ super(`Cannot ${method}: unknown connection '${name}'.`, 'CONNECTION_UNKNOWN', `Check if the connection '${name}' has been created using 'Mapper.connection().create(...)' or registered.`);
34
+ }
35
+ }
36
+ export class SchemaExistingError extends MapperError {
37
+ constructor(name) {
38
+ super(`Schema with name '${name}' already exists.`, 'SCHEMA_EXISTS', `Use a unique name for each schema.`);
39
+ }
40
+ }
41
+ export class SchemaMissingError extends MapperError {
42
+ constructor(name) {
43
+ super(`Unknown schema '${name}'.`, 'SCHEMA_UNKNOWN', `Ensure you have defined the schema '${name}' using 'Mapper.schema().create("${name}")...'`);
44
+ }
45
+ }
46
+ export class SchemaConfigurationError extends MapperError {
47
+ constructor(message) {
48
+ super(message, 'SCHEMA_CONFIG_ERROR', 'Ensure "connection" and "collection" are properly set using ".use({ connection, collection })" before defining structure.');
49
+ }
50
+ }