@point-hub/papi 0.1.4 → 0.1.6
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/lib/index.d.ts +318 -63
- package/lib/index.js +7 -7
- package/lib/index.tsbuildinfo +1 -0
- package/package.json +7 -5
- package/src/app.spec.ts +8 -0
- package/src/app.ts +13 -0
- package/src/console/commands/make-command/index.command.ts +52 -0
- package/src/console/commands/make-command/index.spec.ts +58 -0
- package/src/console/commands/make-middleware/index.command.ts +86 -0
- package/src/console/commands/make-middleware/index.spec.ts +73 -0
- package/src/console/index.spec.ts +14 -0
- package/src/console/index.ts +23 -0
- package/src/database/connection.ts +78 -0
- package/src/database/mongodb/connection.ts +339 -0
- package/src/database/mongodb/mongodb-error-handler.ts +63 -0
- package/src/database/mongodb/mongodb-helper.ts +109 -0
- package/src/database/mongodb/mongodb-querystring.spec.ts +80 -0
- package/src/database/mongodb/mongodb-querystring.ts +143 -0
- package/src/index.ts +42 -0
- package/src/server.spec.ts +68 -0
- package/src/server.ts +49 -0
- package/src/types/controller.d.ts +18 -0
- package/src/types/database.d.ts +104 -0
- package/src/types/use-case.d.ts +3 -0
package/lib/index.d.ts
CHANGED
|
@@ -1,63 +1,318 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="bun-types" />
|
|
4
|
+
declare module "build" { }
|
|
5
|
+
declare module "src/console/commands/make-command/index.command" {
|
|
6
|
+
import { BaseCommand } from '@point-hub/express-cli';
|
|
7
|
+
export default class MakeCommand extends BaseCommand {
|
|
8
|
+
constructor();
|
|
9
|
+
handle(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
declare module "src/console/commands/make-middleware/index.command" {
|
|
13
|
+
import { BaseCommand } from '@point-hub/express-cli';
|
|
14
|
+
export default class MakeMiddleware extends BaseCommand {
|
|
15
|
+
constructor();
|
|
16
|
+
handle(): Promise<void>;
|
|
17
|
+
private copyMiddleware;
|
|
18
|
+
private copyConfigureableMiddleware;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
declare module "src/console/index" {
|
|
22
|
+
import { ExpressCli } from '@point-hub/express-cli';
|
|
23
|
+
export class ConsoleKernel {
|
|
24
|
+
private command;
|
|
25
|
+
constructor(command: ExpressCli);
|
|
26
|
+
/**
|
|
27
|
+
* Register the commands for the application.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* this.command.register(new ExampleCommand());
|
|
31
|
+
*/
|
|
32
|
+
register(): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
declare module "src/database/connection" {
|
|
36
|
+
export class DatabaseConnection implements IDatabase {
|
|
37
|
+
adapter: IDatabase;
|
|
38
|
+
session: unknown;
|
|
39
|
+
constructor(adapter: IDatabase);
|
|
40
|
+
open(): Promise<void>;
|
|
41
|
+
close(): Promise<void>;
|
|
42
|
+
database(name: string): this;
|
|
43
|
+
collection(name: string): this;
|
|
44
|
+
listCollections(): Promise<{
|
|
45
|
+
name: string;
|
|
46
|
+
}[]>;
|
|
47
|
+
startSession(): IClientSession;
|
|
48
|
+
endSession(): Promise<void>;
|
|
49
|
+
startTransaction(): void;
|
|
50
|
+
commitTransaction(): Promise<void>;
|
|
51
|
+
abortTransaction(): Promise<void>;
|
|
52
|
+
createIndex(name: string, spec: unknown, options?: unknown): Promise<void>;
|
|
53
|
+
createCollection(name: string, options?: unknown): Promise<void>;
|
|
54
|
+
dropCollection(name: string, options?: unknown): Promise<void>;
|
|
55
|
+
updateSchema(name: string, schema: unknown): Promise<void>;
|
|
56
|
+
create(document: IDocument, options?: unknown): Promise<ICreateOutput>;
|
|
57
|
+
createMany(documents: IDocument[], options?: unknown): Promise<ICreateManyOutput>;
|
|
58
|
+
retrieveAll(query: IQuery, options?: unknown): Promise<IRetrieveAllOutput>;
|
|
59
|
+
retrieve(_id: string, options?: unknown): Promise<IRetrieveOutput>;
|
|
60
|
+
update(_id: string, document: IDocument, options?: unknown): Promise<IUpdateOutput>;
|
|
61
|
+
updateMany(filter: IDocument, document: IDocument, options?: unknown): Promise<IUpdateManyOutput>;
|
|
62
|
+
delete(_id: string, options?: unknown): Promise<IDeleteOutput>;
|
|
63
|
+
deleteMany(_ids: string[], options?: unknown): Promise<IDeleteManyOutput>;
|
|
64
|
+
deleteAll(options?: unknown): Promise<IDeleteManyOutput>;
|
|
65
|
+
aggregate(pipeline: IPipeline[], query: IQuery, options?: unknown): Promise<IAggregateOutput>;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
declare module "src/database/mongodb/mongodb-helper" {
|
|
69
|
+
/**
|
|
70
|
+
* https://www.mongodb.com/docs/drivers/node/current/fundamentals/indexes/
|
|
71
|
+
* https://www.mongodb.com/docs/manual/reference/collation/
|
|
72
|
+
* https://www.mongodb.com/docs/manual/core/index-sparse/
|
|
73
|
+
* https://www.mongodb.com/docs/manual/core/index-partial/
|
|
74
|
+
*/
|
|
75
|
+
export class MongoDBHelper {
|
|
76
|
+
private db;
|
|
77
|
+
constructor(db: IDatabase);
|
|
78
|
+
/**
|
|
79
|
+
* Create unique column
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* create unique attribute "name"
|
|
83
|
+
* createUnique(collection, {
|
|
84
|
+
* name: -1,
|
|
85
|
+
* })
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* create unique attribute for multiple column "first_name" and "last_name"
|
|
89
|
+
* createUnique(collection, {
|
|
90
|
+
* firstName: -1,
|
|
91
|
+
* lastName: -1,
|
|
92
|
+
* })
|
|
93
|
+
*/
|
|
94
|
+
createUnique(collection: string, properties: object): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Create unique if column is exists
|
|
97
|
+
*/
|
|
98
|
+
createUniqueIfNotNull(collection: string, properties: object): Promise<void>;
|
|
99
|
+
isExists(name: string): Promise<boolean>;
|
|
100
|
+
static stringToObjectId(val: any): any;
|
|
101
|
+
static objectIdToString(val: any): any;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
declare module "src/database/mongodb/mongodb-querystring" {
|
|
105
|
+
import { SortDirection } from 'mongodb';
|
|
106
|
+
interface IFieldsObject {
|
|
107
|
+
[key: string]: number;
|
|
108
|
+
}
|
|
109
|
+
interface ISortObject {
|
|
110
|
+
[key: string]: SortDirection;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Parse query string to number
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* page("10") // => 10
|
|
117
|
+
* page(10) // => 10
|
|
118
|
+
*/
|
|
119
|
+
export function page(page?: string | number): number;
|
|
120
|
+
/**
|
|
121
|
+
* Parse query string to number
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* limit("10") // => 10
|
|
125
|
+
* limit(10) // => 10
|
|
126
|
+
*/
|
|
127
|
+
export function limit(pageSize?: string | number): number;
|
|
128
|
+
/**
|
|
129
|
+
* Skip number of data from page
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* skip(1, 10) // => 0
|
|
133
|
+
* skip(2, 10) // => 10
|
|
134
|
+
* skip(3, 10) // => 20
|
|
135
|
+
*/
|
|
136
|
+
export function skip(currentPage: string | number, pageSize: string | number): number;
|
|
137
|
+
export function filter(filter: never): never;
|
|
138
|
+
/**
|
|
139
|
+
* Convert string param to mongodb field object
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* fields("name, address") // => { name: 1, address: 1 }
|
|
143
|
+
*/
|
|
144
|
+
export function fields(fields?: string, excludeFields?: string[]): IFieldsObject;
|
|
145
|
+
/**
|
|
146
|
+
* Convert string to array
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* convertStringToArray("name, address") // => ["name", "address"]
|
|
150
|
+
*/
|
|
151
|
+
export function convertStringToArray(fields: string): string[];
|
|
152
|
+
/**
|
|
153
|
+
* Convert array to mongodb field object
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* convertArrayToObject(["name", "address"]) // => { name: 1, address: 1 }
|
|
157
|
+
* convertArrayToObject(["name", "address"], -1) // => { name: -1, address: -1 }
|
|
158
|
+
*/
|
|
159
|
+
export function convertArrayToObject(array: string[], value?: number): IFieldsObject;
|
|
160
|
+
/**
|
|
161
|
+
* Remove excluded fields
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ex: { password: 0 }
|
|
165
|
+
*/
|
|
166
|
+
export function filterExludeFields(obj: IFieldsObject, excludeFields: string[]): IFieldsObject;
|
|
167
|
+
/**
|
|
168
|
+
* Convert string param to mongodb sort object
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* sort("name, -createdAt") // => { name: 1, createdAt: -1 }
|
|
172
|
+
*/
|
|
173
|
+
export function sort(fields: string): ISortObject;
|
|
174
|
+
const _default: {
|
|
175
|
+
page: typeof page;
|
|
176
|
+
limit: typeof limit;
|
|
177
|
+
skip: typeof skip;
|
|
178
|
+
sort: typeof sort;
|
|
179
|
+
fields: typeof fields;
|
|
180
|
+
filter: typeof filter;
|
|
181
|
+
filterExludeFields: typeof filterExludeFields;
|
|
182
|
+
convertStringToArray: typeof convertStringToArray;
|
|
183
|
+
convertArrayToObject: typeof convertArrayToObject;
|
|
184
|
+
};
|
|
185
|
+
export default _default;
|
|
186
|
+
}
|
|
187
|
+
declare module "src/database/mongodb/connection" {
|
|
188
|
+
import type { ClientSession, Collection, CollectionOptions, CreateIndexesOptions, Db, DbOptions, IndexSpecification } from 'mongodb';
|
|
189
|
+
import { MongoClient } from 'mongodb';
|
|
190
|
+
export class MongoDBConnection implements IDatabase {
|
|
191
|
+
databaseName: string;
|
|
192
|
+
client: MongoClient;
|
|
193
|
+
_database: Db | undefined;
|
|
194
|
+
_collection: Collection | undefined;
|
|
195
|
+
session: ClientSession | undefined;
|
|
196
|
+
constructor(connectionString: string, databaseName: string);
|
|
197
|
+
open(): Promise<void>;
|
|
198
|
+
close(): Promise<void>;
|
|
199
|
+
database(name: string, options?: DbOptions): this;
|
|
200
|
+
collection(name: string, options?: CollectionOptions): this;
|
|
201
|
+
listCollections(): Promise<{
|
|
202
|
+
name: string;
|
|
203
|
+
}[]>;
|
|
204
|
+
createIndex(name: string, spec: IndexSpecification, options: CreateIndexesOptions): Promise<void>;
|
|
205
|
+
updateSchema(name: string, schema: unknown): Promise<void>;
|
|
206
|
+
createCollection(name: string, options: any): Promise<void>;
|
|
207
|
+
dropCollection(name: string, options: any): Promise<void>;
|
|
208
|
+
startSession(): ClientSession;
|
|
209
|
+
endSession(): Promise<void>;
|
|
210
|
+
startTransaction(): void;
|
|
211
|
+
commitTransaction(): Promise<void>;
|
|
212
|
+
abortTransaction(): Promise<void>;
|
|
213
|
+
create(document: IDocument, options?: unknown): Promise<ICreateOutput>;
|
|
214
|
+
createMany(documents: IDocument[], options?: unknown): Promise<ICreateManyOutput>;
|
|
215
|
+
retrieveAll(query: IQuery, options?: any): Promise<IRetrieveAllOutput>;
|
|
216
|
+
retrieve(_id: string, options?: any): Promise<IRetrieveOutput>;
|
|
217
|
+
update(_id: string, document: IDocument, options?: any): Promise<IUpdateOutput>;
|
|
218
|
+
updateMany(filter: IDocument[], document: IDocument[], options?: any): Promise<IUpdateManyOutput>;
|
|
219
|
+
delete(_id: string, options?: any): Promise<IDeleteOutput>;
|
|
220
|
+
deleteMany(_ids: string[], options?: any): Promise<IDeleteManyOutput>;
|
|
221
|
+
deleteAll(options?: any): Promise<IDeleteManyOutput>;
|
|
222
|
+
aggregate(pipeline: IPipeline[], query: IQuery, options?: any): Promise<IAggregateOutput>;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
declare module "src/database/mongodb/mongodb-error-handler" {
|
|
226
|
+
import { BaseError, type IError } from '@point-hub/express-error-handler';
|
|
227
|
+
import { MongoServerError } from 'mongodb';
|
|
228
|
+
export function handleSchemaValidation(err: MongoServerError, error: IError): void;
|
|
229
|
+
export function handleUniqueValidation(err: MongoServerError, error: IError): void;
|
|
230
|
+
export class MongoErrorHandler extends BaseError {
|
|
231
|
+
constructor(err: MongoServerError);
|
|
232
|
+
get isOperational(): boolean;
|
|
233
|
+
get name(): string;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
declare module "src/server" {
|
|
237
|
+
import { Express } from 'express';
|
|
238
|
+
import { Server as HttpServer } from 'http';
|
|
239
|
+
export class Server {
|
|
240
|
+
app: Express;
|
|
241
|
+
server: HttpServer | null;
|
|
242
|
+
constructor(app: Express);
|
|
243
|
+
listen(port: number, hostname?: string): Promise<unknown>;
|
|
244
|
+
start(port: number, hostname?: string): Promise<void>;
|
|
245
|
+
stop(): void;
|
|
246
|
+
get host(): string;
|
|
247
|
+
get port(): number;
|
|
248
|
+
get url(): string;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
declare module "src/index" {
|
|
252
|
+
import { BaseCommand } from '@point-hub/express-cli';
|
|
253
|
+
import { ApiError, BaseError, errorHandlerMiddleware, find, invalidPathMiddleware } from '@point-hub/express-error-handler';
|
|
254
|
+
import { MongoServerError } from 'mongodb';
|
|
255
|
+
import { ConsoleKernel } from "src/console/index";
|
|
256
|
+
import { DatabaseConnection } from "src/database/connection";
|
|
257
|
+
import { MongoDBConnection } from "src/database/mongodb/connection";
|
|
258
|
+
import { MongoErrorHandler } from "src/database/mongodb/mongodb-error-handler";
|
|
259
|
+
import { MongoDBHelper } from "src/database/mongodb/mongodb-helper";
|
|
260
|
+
export const stubDir: string;
|
|
261
|
+
export { ExpressCli as BaseConsoleCli } from '@point-hub/express-cli';
|
|
262
|
+
export const BaseConsoleCommand: typeof BaseCommand;
|
|
263
|
+
export const BaseConsoleKernel: typeof ConsoleKernel;
|
|
264
|
+
export const BaseDatabaseConnection: typeof DatabaseConnection;
|
|
265
|
+
export const BaseMongoDBConnection: typeof MongoDBConnection;
|
|
266
|
+
export const BaseMongoDBHelper: typeof MongoDBHelper;
|
|
267
|
+
export const BaseMongoDBQuerystring: {
|
|
268
|
+
page: typeof import("src/database/mongodb/mongodb-querystring").page;
|
|
269
|
+
limit: typeof import("src/database/mongodb/mongodb-querystring").limit;
|
|
270
|
+
skip: typeof import("src/database/mongodb/mongodb-querystring").skip;
|
|
271
|
+
sort: typeof import("src/database/mongodb/mongodb-querystring").sort;
|
|
272
|
+
fields: typeof import("src/database/mongodb/mongodb-querystring").fields;
|
|
273
|
+
filter: typeof import("src/database/mongodb/mongodb-querystring").filter;
|
|
274
|
+
filterExludeFields: typeof import("src/database/mongodb/mongodb-querystring").filterExludeFields;
|
|
275
|
+
convertStringToArray: typeof import("src/database/mongodb/mongodb-querystring").convertStringToArray;
|
|
276
|
+
convertArrayToObject: typeof import("src/database/mongodb/mongodb-querystring").convertArrayToObject;
|
|
277
|
+
};
|
|
278
|
+
export const BaseMongoServerError: typeof MongoServerError;
|
|
279
|
+
export const BaseMongoErrorHandler: typeof MongoErrorHandler;
|
|
280
|
+
export const BaseErrorHandler: {
|
|
281
|
+
ApiError: typeof ApiError;
|
|
282
|
+
BaseError: typeof BaseError;
|
|
283
|
+
isTrustedError: (err: Error) => boolean;
|
|
284
|
+
getHttpError: typeof find;
|
|
285
|
+
errorHandlerMiddleware: typeof errorHandlerMiddleware;
|
|
286
|
+
invalidPathMiddleware: typeof invalidPathMiddleware;
|
|
287
|
+
};
|
|
288
|
+
export { Server as BaseServer } from "src/server";
|
|
289
|
+
}
|
|
290
|
+
declare module "cli" { }
|
|
291
|
+
declare module "src/app" {
|
|
292
|
+
import express from 'express';
|
|
293
|
+
export function createApp(): Promise<express.Express>;
|
|
294
|
+
}
|
|
295
|
+
declare module "src/app.spec" { }
|
|
296
|
+
declare module "src/server.spec" { }
|
|
297
|
+
declare module "src/console/index.spec" { }
|
|
298
|
+
declare module "src/console/commands/make-command/index.spec" { }
|
|
299
|
+
declare module "src/console/commands/make-middleware/index.spec" { }
|
|
300
|
+
declare module "src/database/mongodb/mongodb-querystring.spec" { }
|
|
301
|
+
declare module "stub/command/index.command" {
|
|
302
|
+
import { BaseCommand } from '@point-hub/express-cli';
|
|
303
|
+
export default class NewCommand extends BaseCommand {
|
|
304
|
+
constructor();
|
|
305
|
+
handle(): Promise<void>;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
declare module "stub/command/index.spec" { }
|
|
309
|
+
declare module "stub/middleware/configurable.middleware" {
|
|
310
|
+
import { NextFunction, Request, Response } from 'express';
|
|
311
|
+
export default function newMiddleware<T>(options?: T): (req: Request, res: Response, next: NextFunction) => void;
|
|
312
|
+
}
|
|
313
|
+
declare module "stub/middleware/configurable.spec" { }
|
|
314
|
+
declare module "stub/middleware/new.middleware" {
|
|
315
|
+
import { NextFunction, Request, Response } from 'express';
|
|
316
|
+
export default function (req: Request, res: Response, next: NextFunction): void;
|
|
317
|
+
}
|
|
318
|
+
declare module "stub/middleware/new.spec" { }
|