@medyll/idae-api 0.24.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- import { type IdaeApiClientConfigCoreOptions } from './IdaeApiClientConfig';
2
- import { IdaeApiClientCollection } from './IdaeApiClientCollection';
3
- import { IdaeApiClientRequest } from './IdaeApiClientRequest';
1
+ import { type IdaeApiClientConfigCoreOptions } from "./IdaeApiClientConfig.js";
2
+ import { IdaeApiClientCollection } from "./IdaeApiClientCollection.js";
3
+ import { IdaeApiClientRequest } from "./IdaeApiClientRequest.js";
4
4
  type IdaeApiClientRequestParams<T = any> = Record<string, T>;
5
5
  declare class IdaeApiClient {
6
6
  private clientConfig;
@@ -1,7 +1,7 @@
1
1
  // packages\idae-api\src\lib\client\IdaeApiClient.ts
2
- import { IdaeApiClientConfig, IdaeApiClientConfigCore } from './IdaeApiClientConfig';
3
- import { IdaeApiClientCollection } from './IdaeApiClientCollection';
4
- import { IdaeApiClientRequest } from './IdaeApiClientRequest';
2
+ import { IdaeApiClientConfig, IdaeApiClientConfigCore, } from "./IdaeApiClientConfig.js";
3
+ import { IdaeApiClientCollection } from "./IdaeApiClientCollection.js";
4
+ import { IdaeApiClientRequest } from "./IdaeApiClientRequest.js";
5
5
  class IdaeApiClient {
6
6
  constructor(clientConfig) {
7
7
  this.clientConfig = IdaeApiClientConfig;
@@ -12,15 +12,18 @@ class IdaeApiClient {
12
12
  return this._request;
13
13
  }
14
14
  async getDbList() {
15
- return this._request.doRequest({ routeNamespace: 'methods/dbs' });
15
+ return this._request.doRequest({ routeNamespace: "methods/dbs" });
16
16
  }
17
17
  async getCollections(dbName) {
18
- return this._request.doRequest({ dbName, routeNamespace: 'methods/collections' });
18
+ return this._request.doRequest({
19
+ dbName,
20
+ routeNamespace: "methods/collections",
21
+ });
19
22
  }
20
23
  db(dbName) {
21
24
  return {
22
25
  collection: (collectionName) => new IdaeApiClientCollection(this, dbName, collectionName),
23
- getCollections: () => this.getCollections(dbName)
26
+ getCollections: () => this.getCollections(dbName),
24
27
  };
25
28
  }
26
29
  collection(collectionName, dbName) {
@@ -1,5 +1,5 @@
1
- import { IdaeApiClient } from './IdaeApiClient';
2
- import type { IdaeApiClientRequestParams } from './IdaeApiClient';
1
+ import { IdaeApiClient } from "./IdaeApiClient.js";
2
+ import type { IdaeApiClientRequestParams } from "./IdaeApiClient.js";
3
3
  declare class IdaeApiClientCollection {
4
4
  private apiClient;
5
5
  private meta;
@@ -1,52 +1,52 @@
1
1
  // packages\idae-api\src\lib\client\IdaeApiClientCollection.ts
2
- import { IdaeApiClient } from './IdaeApiClient';
2
+ import { IdaeApiClient } from "./IdaeApiClient.js";
3
3
  class IdaeApiClientCollection {
4
4
  constructor(apiClient, dbName, collectionName) {
5
5
  this.apiClient = apiClient;
6
6
  this.meta = {
7
7
  dbName,
8
- collectionName
8
+ collectionName,
9
9
  };
10
10
  }
11
11
  async findAll(params) {
12
12
  return this.apiClient.request.doRequest({
13
13
  ...this.meta,
14
- params
14
+ params,
15
15
  });
16
16
  }
17
17
  async findById(id) {
18
18
  return this.apiClient.request.doRequest({
19
19
  ...this.meta,
20
- slug: id
20
+ slug: id,
21
21
  });
22
22
  }
23
23
  async create(body) {
24
24
  return this.apiClient.request.doRequest({
25
- method: 'POST',
25
+ method: "POST",
26
26
  ...this.meta,
27
- body
27
+ body,
28
28
  });
29
29
  }
30
30
  async update(id, body) {
31
31
  return this.apiClient.request.doRequest({
32
- method: 'PUT',
32
+ method: "PUT",
33
33
  ...this.meta,
34
34
  body,
35
- slug: id
35
+ slug: id,
36
36
  });
37
37
  }
38
38
  async deleteById(id) {
39
39
  return this.apiClient.request.doRequest({
40
- method: 'DELETE',
40
+ method: "DELETE",
41
41
  ...this.meta,
42
- slug: id
42
+ slug: id,
43
43
  });
44
44
  }
45
45
  async deleteManyByQuery(params) {
46
46
  return this.apiClient.request.doRequest({
47
- method: 'DELETE',
47
+ method: "DELETE",
48
48
  ...this.meta,
49
- params
49
+ params,
50
50
  });
51
51
  }
52
52
  }
@@ -1,6 +1,6 @@
1
- import { IdaeApiClientConfigCore } from './IdaeApiClientConfig';
2
- type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
3
- type RouteNamespace = `methods/${'dbs' | 'collections'}` | undefined;
1
+ import { IdaeApiClientConfigCore } from "./IdaeApiClientConfig.js";
2
+ type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
3
+ type RouteNamespace = `methods/${"dbs" | "collections"}` | undefined;
4
4
  interface UrlParams {
5
5
  dbName?: string;
6
6
  collectionName?: string;
@@ -12,13 +12,13 @@ interface RequestOptions<T> extends UrlParams {
12
12
  baseUrl?: string;
13
13
  method?: HttpMethod;
14
14
  body?: T;
15
- headers?: RequestInit['headers'];
15
+ headers?: RequestInit["headers"];
16
16
  }
17
17
  declare class IdaeApiClientRequest {
18
18
  private baseUrl;
19
19
  private clientConfig;
20
20
  constructor(clientConfig: IdaeApiClientConfigCore);
21
- doRequest<T>({ baseUrl, method, body, headers, dbName, collectionName, slug, params, routeNamespace }: RequestOptions<T>): Promise<Response>;
21
+ doRequest<T>({ baseUrl, method, body, headers, dbName, collectionName, slug, params, routeNamespace, }: RequestOptions<T>): Promise<Response>;
22
22
  private buildUrl;
23
23
  }
24
- export { IdaeApiClientRequest, type HttpMethod, type RouteNamespace, type UrlParams, type RequestOptions };
24
+ export { IdaeApiClientRequest, type HttpMethod, type RouteNamespace, type UrlParams, type RequestOptions, };
@@ -1,24 +1,24 @@
1
1
  // packages\idae-api\src\lib\client\IdaeApiClientRequest.ts
2
- import { IdaeApiClientConfigCore } from './IdaeApiClientConfig';
2
+ import { IdaeApiClientConfigCore } from "./IdaeApiClientConfig.js";
3
3
  class IdaeApiClientRequest {
4
4
  constructor(clientConfig) {
5
5
  this.clientConfig = clientConfig;
6
6
  this.baseUrl = `${this.clientConfig.method}:${this.clientConfig.separator}${this.clientConfig.host}:${this.clientConfig.port}`;
7
7
  }
8
- async doRequest({ baseUrl = this.baseUrl, method = 'GET', body, headers = {
9
- 'Content-Type': 'application/json'
10
- }, dbName = this.clientConfig.defaultDb, collectionName, slug, params, routeNamespace }) {
8
+ async doRequest({ baseUrl = this.baseUrl, method = "GET", body, headers = {
9
+ "Content-Type": "application/json",
10
+ }, dbName = this.clientConfig.defaultDb, collectionName, slug, params, routeNamespace, }) {
11
11
  const url = this.buildUrl({
12
12
  routeNamespace,
13
13
  dbName,
14
14
  collectionName,
15
15
  slug,
16
- params
17
- }).replace('//', '/');
16
+ params,
17
+ }).replace("//", "/");
18
18
  const response = await fetch(`${baseUrl}${url}`, {
19
19
  method,
20
20
  headers,
21
- body: body ? JSON.stringify(body) : undefined
21
+ body: body ? JSON.stringify(body) : undefined,
22
22
  });
23
23
  if (!response.ok) {
24
24
  throw new Error(`HTTP error! status: ${response.status}`);
@@ -31,17 +31,17 @@ class IdaeApiClientRequest {
31
31
  throw new Error(`Invalid returned type`);
32
32
  }
33
33
  }
34
- buildUrl({ dbName, collectionName, slug, params, routeNamespace }) {
34
+ buildUrl({ dbName, collectionName, slug, params, routeNamespace, }) {
35
35
  const urls = [`/`];
36
36
  if (routeNamespace)
37
37
  urls.push(routeNamespace);
38
38
  if (dbName ?? collectionName)
39
- urls.push([dbName, collectionName].filter((x) => x).join('.'));
39
+ urls.push([dbName, collectionName].filter((x) => x).join("."));
40
40
  if (slug)
41
41
  urls.push(slug);
42
42
  if (params)
43
43
  urls.push(`?${new URLSearchParams(params).toString()}`);
44
- return urls.join('/').replace('//', '/');
44
+ return urls.join("/").replace("//", "/");
45
45
  }
46
46
  }
47
- export { IdaeApiClientRequest };
47
+ export { IdaeApiClientRequest, };
@@ -1,4 +1,4 @@
1
- import { DBaseService } from '../server/services/DBaseService';
1
+ import { DBaseService } from "../server/services/DBaseService.js";
2
2
  type RouteHandler = (service: DBaseService<any>, params: any, body?: any) => Promise<any>;
3
3
  export interface RouteDefinition {
4
4
  method: string | string[];
@@ -1,48 +1,50 @@
1
1
  // packages\idae-api\src\lib\config\routeDefinitions.ts
2
- import { DBaseService } from '../server/services/DBaseService';
2
+ import { DBaseService } from "../server/services/DBaseService.js";
3
3
  export const routes = [
4
4
  {
5
- method: 'get',
6
- path: '/:collectionName',
7
- handler: async (service, params) => service.where(params)
5
+ method: "get",
6
+ path: "/:collectionName",
7
+ handler: async (service, params) => service.where(params),
8
8
  },
9
9
  {
10
- method: 'get',
11
- path: '/:collectionName/:id',
12
- handler: async (service, params) => service.findById(params.id)
10
+ method: "get",
11
+ path: "/:collectionName/:id",
12
+ handler: async (service, params) => service.findById(params.id),
13
13
  },
14
14
  {
15
- method: 'post',
16
- path: '/:collectionName',
17
- handler: async (service, params, body) => service.create(body)
15
+ method: "post",
16
+ path: "/:collectionName",
17
+ handler: async (service, params, body) => service.create(body),
18
18
  },
19
19
  {
20
- method: 'put',
21
- path: '/:collectionName/:id',
22
- handler: async (service, params, body) => service.update(params.id, body)
20
+ method: "put",
21
+ path: "/:collectionName/:id",
22
+ handler: async (service, params, body) => service.update(params.id, body),
23
23
  },
24
24
  {
25
- method: 'delete',
26
- path: '/:collectionName/:id',
27
- handler: async (service, params) => service.deleteById(params.id)
25
+ method: "delete",
26
+ path: "/:collectionName/:id",
27
+ handler: async (service, params) => service.deleteById(params.id),
28
28
  },
29
29
  {
30
- method: 'delete',
31
- path: '/:collectionName',
32
- handler: async (service, params) => service.deleteManyByQuery(params)
30
+ method: "delete",
31
+ path: "/:collectionName",
32
+ handler: async (service, params) => service.deleteManyByQuery(params),
33
33
  },
34
34
  {
35
- method: ['where', 'create', 'update', 'deleteById', 'deleteManyByQuery'], // default method is then GET or OPTIONS (set further)
36
- path: '/query/:collectionName/:command/:parameters?',
35
+ method: ["where", "create", "update", "deleteById", "deleteManyByQuery"], // default method is then GET or OPTIONS (set further)
36
+ path: "/query/:collectionName/:command/:parameters?",
37
37
  handler: async (service, params, body) => {
38
- const decodedParams = params.body ? service.decodeUrlParams(params.body) : {};
39
- console.log(params.command, 'params --- ', { body });
38
+ const decodedParams = params.body
39
+ ? service.decodeUrlParams(params.body)
40
+ : {};
41
+ console.log(params.command, "params --- ", { body });
40
42
  return service?.[params.command]?.({ query: body });
41
- }
43
+ },
42
44
  },
43
45
  {
44
- method: ['dbs', 'collections'], // default method is then GET or OPTIONS (set further)
45
- path: '/methods/:methodName/:params?',
46
- handler: async (service, params) => { }
47
- }
46
+ method: ["dbs", "collections"], // default method is then GET or OPTIONS (set further)
47
+ path: "/methods/:methodName/:params?",
48
+ handler: async (service, params) => { },
49
+ },
48
50
  ];
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './idae-api.d.js';
2
1
  export * from './server/IdaeApi.js';
3
2
  export * from './config/routeDefinitions.js';
4
3
  export * from './client/IdaeApiClientRequest.js';
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  // auto exports of entry components
2
- export * from './idae-api.d.js';
3
2
  export * from './server/IdaeApi.js';
4
3
  export * from './config/routeDefinitions.js';
5
4
  export * from './client/IdaeApiClientRequest.js';
@@ -1,10 +1,10 @@
1
- import express from 'express';
2
- import { type RouteDefinition } from '../config/routeDefinitions';
3
- import { RouteManager } from './engine/routeManager';
1
+ import express from "express";
2
+ import { type RouteDefinition } from "../config/routeDefinitions.js";
3
+ import { RouteManager } from "./engine/routeManager.js";
4
4
  interface IdaeApiOptions {
5
5
  port?: number;
6
6
  routes?: RouteDefinition[];
7
- onInUse?: 'reboot' | 'fail' | 'replace';
7
+ onInUse?: "reboot" | "fail" | "replace";
8
8
  enableAuth?: boolean;
9
9
  jwtSecret?: string;
10
10
  tokenExpiration?: string;
@@ -19,7 +19,7 @@ declare class IdaeApi {
19
19
  private authMiddleware;
20
20
  private constructor();
21
21
  static getInstance(): IdaeApi;
22
- get state(): 'stopped' | 'running';
22
+ get state(): "stopped" | "running";
23
23
  get app(): express.Express;
24
24
  setOptions(options: IdaeApiOptions): void;
25
25
  private initializeAuth;
@@ -1,14 +1,14 @@
1
1
  // packages\idae-api\src\lib\IdaeApi.ts
2
2
  // version feat
3
- import express, {} from 'express';
4
- import { databaseMiddleware } from './middleware/databaseMiddleware';
5
- import { DBaseService } from './services/DBaseService';
6
- import { routes as defaultRoutes } from '../config/routeDefinitions';
7
- import { AuthMiddleWare } from './middleware/authMiddleware';
8
- import { RouteManager } from './engine/routeManager';
3
+ import express, {} from "express";
4
+ import { databaseMiddleware } from "./middleware/databaseMiddleware.js";
5
+ import { DBaseService } from "./services/DBaseService.js";
6
+ import { routes as defaultRoutes, } from "../config/routeDefinitions.js";
7
+ import { AuthMiddleWare } from "./middleware/authMiddleware.js";
8
+ import { RouteManager } from "./engine/routeManager.js";
9
9
  class IdaeApi {
10
10
  constructor() {
11
- this._state = 'stopped';
11
+ this._state = "stopped";
12
12
  this.authMiddleware = null;
13
13
  this._app = express();
14
14
  this.options = {};
@@ -32,7 +32,9 @@ class IdaeApi {
32
32
  this.options = { ...this.options, ...options };
33
33
  }
34
34
  initializeAuth() {
35
- if (this.options.enableAuth && this.options.jwtSecret && this.options.tokenExpiration) {
35
+ if (this.options.enableAuth &&
36
+ this.options.jwtSecret &&
37
+ this.options.tokenExpiration) {
36
38
  this.authMiddleware = new AuthMiddleWare(this.options.jwtSecret, this.options.tokenExpiration);
37
39
  }
38
40
  }
@@ -42,7 +44,7 @@ class IdaeApi {
42
44
  this.configureErrorHandling();
43
45
  }
44
46
  configureMiddleware() {
45
- this._app.use('/:collectionName', databaseMiddleware);
47
+ this._app.use("/:collectionName", databaseMiddleware);
46
48
  this._app.use(express.json());
47
49
  this._app.use(express.urlencoded({ extended: true }));
48
50
  if (this.authMiddleware) {
@@ -66,35 +68,35 @@ class IdaeApi {
66
68
  });
67
69
  }
68
70
  start() {
69
- if (this._state === 'running') {
70
- console.log('Server is already running.');
71
+ if (this._state === "running") {
72
+ console.log("Server is already running.");
71
73
  return;
72
74
  }
73
75
  const port = this.options.port || 3000;
74
76
  this.serverInstance = this._app.listen(port, () => {
75
77
  console.log(`Server is running on port: ${port}`);
76
- this._state = 'running';
78
+ this._state = "running";
77
79
  });
78
- this.serverInstance.on('error', this.handleServerError.bind(this));
80
+ this.serverInstance.on("error", this.handleServerError.bind(this));
79
81
  }
80
82
  handleServerError(error) {
81
- if (error.code === 'EADDRINUSE') {
83
+ if (error.code === "EADDRINUSE") {
82
84
  console.error(`Port ${this.options.port} is already in use.`);
83
85
  switch (this.options.onInUse) {
84
- case 'reboot':
85
- console.log('Rebooting server...');
86
+ case "reboot":
87
+ console.log("Rebooting server...");
86
88
  setTimeout(() => {
87
89
  this.stop();
88
90
  this.start();
89
91
  }, 1000);
90
92
  break;
91
- case 'replace':
92
- console.log('Replacing existing server...');
93
+ case "replace":
94
+ console.log("Replacing existing server...");
93
95
  this.stop();
94
96
  this.start();
95
97
  break;
96
98
  default:
97
- console.log('Failed to start the server.');
99
+ console.log("Failed to start the server.");
98
100
  process.exit(1);
99
101
  }
100
102
  }
@@ -106,11 +108,11 @@ class IdaeApi {
106
108
  if (this.serverInstance) {
107
109
  this.serverInstance.close((err) => {
108
110
  if (err) {
109
- console.error('Error while stopping the server:', err);
111
+ console.error("Error while stopping the server:", err);
110
112
  }
111
113
  else {
112
- console.log('Server stopped successfully.');
113
- this._state = 'stopped';
114
+ console.log("Server stopped successfully.");
115
+ this._state = "stopped";
114
116
  }
115
117
  });
116
118
  }
@@ -137,12 +139,12 @@ class IdaeApi {
137
139
  const { collectionName } = req.params;
138
140
  const connection = req.dbConnection;
139
141
  if (!connection) {
140
- throw new Error('Database connection not established');
142
+ throw new Error("Database connection not established");
141
143
  }
142
- console.log('----------------------------------------------');
144
+ console.log("----------------------------------------------");
143
145
  console.log(req.body);
144
146
  console.log(req.params);
145
- const databaseService = new DBaseService(collectionName, connection, 'mongodb');
147
+ const databaseService = new DBaseService(collectionName, connection, "mongodb");
146
148
  const result = await action(databaseService, req.params, req.body);
147
149
  res.json(result);
148
150
  }
@@ -1,6 +1,7 @@
1
- import type { ApiServerRequestParams } from '../engine/types';
2
- import type { Model, Document } from 'mongoose';
3
- import mongoose from 'mongoose';
1
+ import type { ApiServerRequestParams } from "../engine/types.js";
2
+ import type { Model, Document } from "mongoose";
3
+ import mongoose from "mongoose";
4
+ import type { DatabaseAdapter } from "./types.js";
4
5
  export declare class MongoDBAdapter<T extends Document> implements DatabaseAdapter<T> {
5
6
  private model;
6
7
  private connection;
@@ -1,6 +1,6 @@
1
1
  // packages\idae-api\src\lib\adapters\MongoDBAdapter.ts
2
- import dotenv from 'dotenv';
3
- import mongoose, { Schema } from 'mongoose';
2
+ import dotenv from "dotenv";
3
+ import mongoose, { Schema } from "mongoose";
4
4
  // Load environment variables
5
5
  dotenv.config();
6
6
  // MongoDB Adapter
@@ -15,7 +15,7 @@ export class MongoDBAdapter {
15
15
  }
16
16
  };
17
17
  // just in case
18
- collection = collection.split('.')[1] ?? collection.split('.')[0];
18
+ collection = collection.split(".")[1] ?? collection.split(".")[0];
19
19
  this.connection = connection;
20
20
  this.model = this.getModel(collection);
21
21
  }
@@ -39,7 +39,9 @@ export class MongoDBAdapter {
39
39
  return this.model.findOne(params.query);
40
40
  }
41
41
  async update(id, updateData) {
42
- return this.model.findByIdAndUpdate(id, updateData, { new: true });
42
+ return this.model.findByIdAndUpdate(id, updateData, {
43
+ new: true,
44
+ });
43
45
  }
44
46
  async deleteById(id) {
45
47
  return this.model.findByIdAndDelete(id);
@@ -51,10 +53,10 @@ export class MongoDBAdapter {
51
53
  parseSortOptions(sortBy) {
52
54
  const sortOptions = {};
53
55
  if (sortBy) {
54
- const sortFields = sortBy.split(',');
56
+ const sortFields = sortBy.split(",");
55
57
  sortFields.forEach((field) => {
56
- const [key, order] = field.split(':');
57
- sortOptions[key] = order === 'desc' ? -1 : 1;
58
+ const [key, order] = field.split(":");
59
+ sortOptions[key] = order === "desc" ? -1 : 1;
58
60
  });
59
61
  }
60
62
  return sortOptions;
@@ -1,5 +1,5 @@
1
- import mongoose from 'mongoose';
2
- import type { Request } from 'express';
1
+ import mongoose from "mongoose";
2
+ import type { Request } from "express";
3
3
  export interface DatabaseConfig {
4
4
  port: number;
5
5
  host: string;
@@ -1,7 +1,7 @@
1
1
  // packages\idae-api\src\lib\engine\DatabaseManager.ts
2
- import mongoose from 'mongoose';
3
- import dotenv from 'dotenv';
4
- import { mongooseConnectionManager } from './mongooseConnectionManager';
2
+ import mongoose from "mongoose";
3
+ import dotenv from "dotenv";
4
+ import { mongooseConnectionManager, } from "./mongooseConnectionManager.js";
5
5
  // Load environment variables
6
6
  dotenv.config();
7
7
  class DatabaseManager {
@@ -9,9 +9,9 @@ class DatabaseManager {
9
9
  this.mongooseConnectionManager = mongooseConnectionManager;
10
10
  this.config = {
11
11
  port: Number(process.env.MONGODB_DEFAULT_PORT) || 27017,
12
- host: process.env.MONGODB_DEFAULT_HOST || 'localhost',
13
- defaultDbName: process.env.MONGODB_DEFAULT_DB || 'idaenext_sitebase_app',
14
- connectionPrefix: process.env.MONGODB_DEFAULT_CONNECTION_PREFIX || 'mongodb://'
12
+ host: process.env.MONGODB_DEFAULT_HOST || "localhost",
13
+ defaultDbName: process.env.MONGODB_DEFAULT_DB || "idaenext_sitebase_app",
14
+ connectionPrefix: process.env.MONGODB_DEFAULT_CONNECTION_PREFIX || "mongodb://",
15
15
  };
16
16
  }
17
17
  static getInstance() {
@@ -21,7 +21,9 @@ class DatabaseManager {
21
21
  return DatabaseManager.instance;
22
22
  }
23
23
  getDbNameFromCollectionName(collectionName) {
24
- return collectionName.includes('.') ? collectionName.split('.')[0] : this.config.defaultDbName;
24
+ return collectionName.includes(".")
25
+ ? collectionName.split(".")[0]
26
+ : this.config.defaultDbName;
25
27
  }
26
28
  async initConnection(dbName) {
27
29
  const dbUri = `${this.config.connectionPrefix}${this.config.host}:${this.config.port}/${dbName}`;
@@ -32,20 +34,20 @@ class DatabaseManager {
32
34
  bufferCommands: false,
33
35
  serverSelectionTimeoutMS: 30000,
34
36
  socketTimeoutMS: 45000,
35
- maxPoolSize: 20
37
+ maxPoolSize: 20,
36
38
  });
37
39
  return connection;
38
40
  }
39
41
  async connectToDatabase(req) {
40
- const collectionName = req.params.collectionName || 'default';
42
+ const collectionName = req.params.collectionName || "default";
41
43
  const dbName = this.getDbNameFromCollectionName(collectionName);
42
- const collectionNames = collectionName.split('.')?.[1] ?? collectionName.split('.')?.[0];
44
+ const collectionNames = collectionName.split(".")?.[1] ?? collectionName.split(".")?.[0];
43
45
  try {
44
46
  const connection = await this.initConnection(dbName);
45
47
  return {
46
48
  connection,
47
49
  dbName,
48
- collectionName: collectionNames
50
+ collectionName: collectionNames,
49
51
  };
50
52
  }
51
53
  catch (error) {
@@ -1,4 +1,4 @@
1
- import type { RouteDefinition } from '../../config/routeDefinitions';
1
+ import type { RouteDefinition } from "../../config/routeDefinitions.js";
2
2
  export declare class RouteManager {
3
3
  private static instance;
4
4
  private routes;
@@ -16,21 +16,27 @@ export class RouteManager {
16
16
  }
17
17
  removeRoute(path, method) {
18
18
  this.routes = this.routes.filter((r) => !(r.path === path &&
19
- (Array.isArray(r.method) ? r.method.includes(method) : r.method === method)));
19
+ (Array.isArray(r.method)
20
+ ? r.method.includes(method)
21
+ : r.method === method)));
20
22
  }
21
23
  getRoutes() {
22
24
  return this.routes.filter((route) => !route.disabled);
23
25
  }
24
26
  enableRoute(path, method) {
25
27
  const route = this.routes.find((r) => r.path === path &&
26
- (Array.isArray(r.method) ? r.method.includes(method) : r.method === method));
28
+ (Array.isArray(r.method)
29
+ ? r.method.includes(method)
30
+ : r.method === method));
27
31
  if (route) {
28
32
  route.disabled = false;
29
33
  }
30
34
  }
31
35
  disableRoute(path, method) {
32
36
  const route = this.routes.find((r) => r.path === path &&
33
- (Array.isArray(r.method) ? r.method.includes(method) : r.method === method));
37
+ (Array.isArray(r.method)
38
+ ? r.method.includes(method)
39
+ : r.method === method));
34
40
  if (route) {
35
41
  route.disabled = true;
36
42
  }
@@ -1,2 +1,2 @@
1
- import type { Request, Response, NextFunction } from 'express';
1
+ import type { Request, Response, NextFunction } from "express";
2
2
  export declare const databaseMiddleware: (req: Request, res: Response, next: NextFunction) => Promise<void>;
@@ -1,5 +1,5 @@
1
1
  // packages\idae-api\src\lib\middleware\databaseMiddleware.ts
2
- import databaseManager from '../engine/DatabaseManager';
2
+ import databaseManager from "../engine/DatabaseManager.js";
3
3
  export const databaseMiddleware = async (req, res, next) => {
4
4
  try {
5
5
  const { collectionName, dbName, connection } = await databaseManager.connectToDatabase(req);
@@ -9,7 +9,7 @@ export const databaseMiddleware = async (req, res, next) => {
9
9
  next();
10
10
  }
11
11
  catch (error) {
12
- console.error('Error in database connection middleware:', error);
12
+ console.error("Error in database connection middleware:", error);
13
13
  next(error);
14
14
  }
15
15
  };
@@ -1,8 +1,8 @@
1
- import mongoose, { type Document } from 'mongoose';
2
- import { type ApiServerRequestParams } from '../engine/types';
1
+ import mongoose, { type Document } from "mongoose";
2
+ import { type ApiServerRequestParams } from "../engine/types.js";
3
3
  declare class DBaseService<T extends Document> {
4
4
  private adapter;
5
- constructor(collection: string, connection: mongoose.Connection, dbType?: 'mongodb' | 'mysql' | 'mariadb' | 'postgres');
5
+ constructor(collection: string, connection: mongoose.Connection, dbType?: "mongodb" | "mysql" | "mariadb" | "postgres");
6
6
  create(document: Partial<T>): Promise<T>;
7
7
  where(params: ApiServerRequestParams): Promise<T[]>;
8
8
  findById(id: string): Promise<T | null>;
@@ -1,22 +1,22 @@
1
1
  // packages\idae-api\src\lib\engine\DBaseService.ts
2
- import mongoose, {} from 'mongoose';
3
- import {} from '../engine/types';
4
- import { MongoDBAdapter } from '../adapters/MongoDBAdapter';
2
+ import mongoose, {} from "mongoose";
3
+ import {} from "../engine/types.js";
4
+ import { MongoDBAdapter } from "../adapters/MongoDBAdapter.js";
5
5
  class DBaseService {
6
- constructor(collection, connection, dbType = 'mongodb') {
6
+ constructor(collection, connection, dbType = "mongodb") {
7
7
  switch (dbType) {
8
- case 'mongodb':
8
+ case "mongodb":
9
9
  this.adapter = new MongoDBAdapter(collection, connection);
10
10
  break;
11
- case 'mysql':
12
- case 'mariadb':
11
+ case "mysql":
12
+ case "mariadb":
13
13
  // TODO: Implement MySQL adapter
14
- throw new Error('MySQL adapter not implemented yet');
15
- case 'postgres':
14
+ throw new Error("MySQL adapter not implemented yet");
15
+ case "postgres":
16
16
  // TODO: Implement postgres adapter
17
- throw new Error('Postgres adapter not implemented yet');
17
+ throw new Error("Postgres adapter not implemented yet");
18
18
  default:
19
- console.log('dbType', dbType);
19
+ console.log("dbType", dbType);
20
20
  throw new Error(`Unsupported database type: ${dbType}`);
21
21
  }
22
22
  }
@@ -24,7 +24,7 @@ class DBaseService {
24
24
  return this.adapter.create(document);
25
25
  }
26
26
  async where(params) {
27
- console.log('where', params);
27
+ console.log("where", params);
28
28
  return this.adapter.where(params);
29
29
  }
30
30
  async findById(id) {
@@ -44,9 +44,9 @@ class DBaseService {
44
44
  }
45
45
  decodeUrlParams(urlParams) {
46
46
  const params = {};
47
- const urlParamsArray = urlParams.split('&');
47
+ const urlParamsArray = urlParams.split("&");
48
48
  urlParamsArray.forEach((param) => {
49
- const [key, value] = param.split('=');
49
+ const [key, value] = param.split("=");
50
50
  if (key && value) {
51
51
  try {
52
52
  params[key] = JSON.parse(decodeURIComponent(value));
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@medyll/idae-api",
3
3
  "scope": "@medyll",
4
- "version": "0.24.0",
4
+ "version": "0.26.0",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
5
7
  "scripts": {
6
8
  "dev": "vite dev",
7
9
  "build": "vite build && npm run package",
@@ -19,7 +21,8 @@
19
21
  "exports": {
20
22
  ".": {
21
23
  "types": "./dist/index.d.ts",
22
- "svelte": "./dist/index.js"
24
+ "svelte": "./dist/index.js",
25
+ "default": "./dist/index.js"
23
26
  }
24
27
  },
25
28
  "files": [
@@ -27,6 +30,11 @@
27
30
  "!dist/**/*.test.*",
28
31
  "!dist/**/*.spec.*"
29
32
  ],
33
+ "tshy": {
34
+ "dialects": [
35
+ "esm"
36
+ ]
37
+ },
30
38
  "dependencies": {
31
39
  "@typegoose/auto-increment": "^4.5.0",
32
40
  "express": "^4.19.2",