unconventional 0.0.1 → 0.0.2
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/README.md +2 -1
- package/dist/core/abstractbase.controller.d.ts +36 -0
- package/dist/core/abstractbase.controller.d.ts.map +1 -0
- package/dist/core/abstractbase.controller.js +198 -0
- package/dist/core/api-error.d.ts +29 -0
- package/dist/core/api-error.d.ts.map +1 -0
- package/dist/core/api-error.js +78 -0
- package/dist/core/base.cache.d.ts +16 -0
- package/dist/core/base.cache.d.ts.map +1 -0
- package/dist/core/base.cache.js +72 -0
- package/dist/core/base.model.d.ts +40 -0
- package/dist/core/base.model.d.ts.map +1 -0
- package/dist/core/base.model.js +189 -0
- package/dist/core/base.options.d.ts +57 -0
- package/dist/core/base.options.d.ts.map +1 -0
- package/dist/core/base.options.js +3 -0
- package/dist/core/base.service.d.ts +16 -0
- package/dist/core/base.service.d.ts.map +1 -0
- package/dist/core/base.service.js +122 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +6 -0
- package/dist/core/pg.driver.d.ts +3 -0
- package/dist/core/pg.driver.d.ts.map +1 -0
- package/dist/core/pg.driver.js +21 -0
- package/dist/decorators/index.d.ts +5 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.decorator.d.ts +5 -0
- package/dist/decorators/index.decorator.d.ts.map +1 -0
- package/dist/decorators/index.decorator.js +6 -0
- package/dist/decorators/index.js +4 -0
- package/dist/decorators/prop.decorator.d.ts +5 -0
- package/dist/decorators/prop.decorator.d.ts.map +1 -0
- package/dist/decorators/prop.decorator.js +13 -0
- package/dist/decorators/timestamp.decorator.d.ts +5 -0
- package/dist/decorators/timestamp.decorator.d.ts.map +1 -0
- package/dist/decorators/timestamp.decorator.js +6 -0
- package/dist/decorators/utils.d.ts +2 -0
- package/dist/decorators/utils.d.ts.map +1 -0
- package/dist/decorators/utils.js +3 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +32 -0
- package/dist/types/api.types.d.ts +31 -0
- package/dist/types/api.types.d.ts.map +1 -0
- package/dist/types/api.types.js +17 -0
- package/dist/types/db.types.d.ts +25 -0
- package/dist/types/db.types.d.ts.map +1 -0
- package/dist/types/db.types.js +12 -0
- package/dist/types/decorator.types.d.ts +39 -0
- package/dist/types/decorator.types.d.ts.map +1 -0
- package/dist/types/decorator.types.js +7 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/server.types.d.ts +11 -0
- package/dist/types/server.types.d.ts.map +1 -0
- package/dist/types/server.types.js +1 -0
- package/dist/utils/api.utils.d.ts +9 -0
- package/dist/utils/api.utils.d.ts.map +1 -0
- package/dist/utils/api.utils.js +46 -0
- package/dist/utils/array.utils.d.ts +3 -0
- package/dist/utils/array.utils.d.ts.map +1 -0
- package/dist/utils/array.utils.js +20 -0
- package/dist/utils/cache.utils.d.ts +3 -0
- package/dist/utils/cache.utils.d.ts.map +1 -0
- package/dist/utils/cache.utils.js +14 -0
- package/dist/utils/crypto.utils.d.ts +2 -0
- package/dist/utils/crypto.utils.d.ts.map +1 -0
- package/dist/utils/crypto.utils.js +9 -0
- package/dist/utils/db.utils.d.ts +10 -0
- package/dist/utils/db.utils.d.ts.map +1 -0
- package/dist/utils/db.utils.js +127 -0
- package/dist/utils/function.utils.d.ts +11 -0
- package/dist/utils/function.utils.d.ts.map +1 -0
- package/dist/utils/function.utils.js +14 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/middleware.utils.d.ts +4 -0
- package/dist/utils/middleware.utils.d.ts.map +1 -0
- package/dist/utils/middleware.utils.js +10 -0
- package/dist/utils/server.utils.d.ts +5 -0
- package/dist/utils/server.utils.d.ts.map +1 -0
- package/dist/utils/server.utils.js +27 -0
- package/package.json +37 -11
package/README.md
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/// <reference types="@cloudflare/workers-types" />
|
|
2
|
+
import { Context } from "hono";
|
|
3
|
+
import { BaseHandler, Env } from "../types/api.types";
|
|
4
|
+
import BaseModel from "./base.model";
|
|
5
|
+
import { ControllerMethodOptions, ControllerOptions, DownloadMethodOptions, I, PI, RequestContext } from "./base.options";
|
|
6
|
+
import BaseService from "./base.service";
|
|
7
|
+
export default abstract class AbstractBaseController<M extends typeof BaseModel, E extends Env = Env> {
|
|
8
|
+
protected _model: M;
|
|
9
|
+
protected _service: BaseService<M>;
|
|
10
|
+
protected _pageLimitDefault: number;
|
|
11
|
+
protected _pageLimitMax: number;
|
|
12
|
+
protected _options: ControllerOptions;
|
|
13
|
+
constructor(model: M, options?: ControllerOptions);
|
|
14
|
+
create(options?: ControllerMethodOptions<M, E>): BaseHandler<E>;
|
|
15
|
+
createMany(options?: ControllerMethodOptions<M, E, PI<M>[], I<M>[]>): BaseHandler<E>;
|
|
16
|
+
get(options?: ControllerMethodOptions<M, E> & DownloadMethodOptions<M, E>): BaseHandler<E>;
|
|
17
|
+
getAll(options?: ControllerMethodOptions<M, E, any, I<M>[]>): BaseHandler<E>;
|
|
18
|
+
update(options?: ControllerMethodOptions<M, E>): BaseHandler<E>;
|
|
19
|
+
updateMany(options?: ControllerMethodOptions<M, E, PI<M>[], I<M>[]>): BaseHandler<E>;
|
|
20
|
+
delete(options?: ControllerMethodOptions<M, E>): BaseHandler<E>;
|
|
21
|
+
deleteMany(options?: ControllerMethodOptions<M, E, PI<M>[], I<M>[]>): BaseHandler<E>;
|
|
22
|
+
private _create;
|
|
23
|
+
private _createMany;
|
|
24
|
+
private _get;
|
|
25
|
+
private _getAll;
|
|
26
|
+
private _update;
|
|
27
|
+
private _updateMany;
|
|
28
|
+
private _delete;
|
|
29
|
+
private _deleteMany;
|
|
30
|
+
protected getRequestContext<T extends PI<M> | PI<M>[] = PI<M>>(ctx: Context<E>, hasBody?: boolean): Promise<RequestContext<M, E, T>>;
|
|
31
|
+
protected getCache(ctx: Context, controllerLevel: boolean | undefined, routeLevel: boolean | undefined): KVNamespace | undefined;
|
|
32
|
+
protected abstract maskPrivateFields(req: RequestContext<M, E>, response: InstanceType<M> | InstanceType<M>[]): Promise<void>;
|
|
33
|
+
protected abstract removeSystemFields<T extends PI<M> | PI<M>[] = PI<M>>(req: RequestContext<M, E, T>): void;
|
|
34
|
+
protected abstract preventIDOR<T extends PI<M> | PI<M>[] = PI<M>>(req: RequestContext<M, E, T>): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=abstractbase.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstractbase.controller.d.ts","sourceRoot":"","sources":["../../src/core/abstractbase.controller.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAc,WAAW,EAAE,GAAG,EAAS,MAAM,oBAAoB,CAAC;AACzE,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,CAAC,EAAE,EAAE,EAAE,cAAc,EAAiB,MAAM,gBAAgB,CAAC;AACzI,OAAO,WAAW,MAAM,gBAAgB,CAAC;AAGzC,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,sBAAsB,CAAC,CAAC,SAAS,OAAO,SAAS,EAAE,CAAC,SAAS,GAAG,GAAG,GAAG;IAClG,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;IACpB,SAAS,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACnC,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAM;IACzC,SAAS,CAAC,aAAa,EAAE,MAAM,CAAO;IACtC,SAAS,CAAC,QAAQ,EAAE,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|
+
import { BaseEnvKey, Query } from "../types/api.types";
|
|
2
|
+
import BaseService from "./base.service";
|
|
3
|
+
export default class AbstractBaseController {
|
|
4
|
+
_model;
|
|
5
|
+
_service;
|
|
6
|
+
_pageLimitDefault = 12;
|
|
7
|
+
_pageLimitMax = 100;
|
|
8
|
+
_options = {};
|
|
9
|
+
constructor(model, options) {
|
|
10
|
+
this._model = model;
|
|
11
|
+
this._service = new BaseService(model);
|
|
12
|
+
this._options = options || {};
|
|
13
|
+
}
|
|
14
|
+
create(options) { return this._create.bind(this, options); }
|
|
15
|
+
createMany(options) { return this._createMany.bind(this, options); }
|
|
16
|
+
get(options) { return this._get.bind(this, options); }
|
|
17
|
+
getAll(options) { return this._getAll.bind(this, options); }
|
|
18
|
+
update(options) { return this._update.bind(this, options); }
|
|
19
|
+
updateMany(options) { return this._updateMany.bind(this, options); }
|
|
20
|
+
delete(options) { return this._delete.bind(this, options); }
|
|
21
|
+
deleteMany(options) { return this._deleteMany.bind(this, options); }
|
|
22
|
+
async _create(options, ctx) {
|
|
23
|
+
const reqContext = await this.getRequestContext(ctx);
|
|
24
|
+
await this.preventIDOR(reqContext);
|
|
25
|
+
if (options?.before)
|
|
26
|
+
await options.before(reqContext);
|
|
27
|
+
const isPrivileged = ctx.get(BaseEnvKey.isPrivileged);
|
|
28
|
+
if (this._model.ownerField && !(reqContext.body[this._model.ownerField] && isPrivileged)) {
|
|
29
|
+
const ownerId = ctx.get(BaseEnvKey.ownerId);
|
|
30
|
+
if (ownerId && this._model.ownerField)
|
|
31
|
+
reqContext.body[this._model.ownerField] = ownerId;
|
|
32
|
+
}
|
|
33
|
+
const config = {
|
|
34
|
+
cache: this.getCache(ctx, this._options.cache, options?.cache),
|
|
35
|
+
cacheTTL: this._options.cacheTTL ?? options?.cacheTTL,
|
|
36
|
+
upsertConfig: {
|
|
37
|
+
constraint: options?.upsertContraint
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
let response = await this._service.create(reqContext.body, config);
|
|
41
|
+
if (options?.after)
|
|
42
|
+
await options.after(reqContext, response);
|
|
43
|
+
return ctx.json(response);
|
|
44
|
+
}
|
|
45
|
+
async _createMany(options, ctx) {
|
|
46
|
+
const reqContext = await this.getRequestContext(ctx);
|
|
47
|
+
await this.preventIDOR(reqContext);
|
|
48
|
+
if (options?.before)
|
|
49
|
+
await options.before(reqContext);
|
|
50
|
+
const isPrivileged = ctx.get(BaseEnvKey.isPrivileged);
|
|
51
|
+
reqContext.body.forEach(x => {
|
|
52
|
+
if (this._model.ownerField && !(x[this._model.ownerField] && isPrivileged)) {
|
|
53
|
+
const ownerId = ctx.get(BaseEnvKey.ownerId);
|
|
54
|
+
if (ownerId && this._model.ownerField)
|
|
55
|
+
x[this._model.ownerField] = ownerId;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const config = {
|
|
59
|
+
cache: this.getCache(ctx, this._options.cache, options?.cache),
|
|
60
|
+
cacheTTL: this._options.cacheTTL ?? options?.cacheTTL,
|
|
61
|
+
upsertConfig: {
|
|
62
|
+
constraint: options?.upsertContraint
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
let response = await this._service.createMany(reqContext.body, config);
|
|
66
|
+
if (options?.after)
|
|
67
|
+
await options.after(reqContext, response);
|
|
68
|
+
return ctx.json(response);
|
|
69
|
+
}
|
|
70
|
+
async _get(options, ctx) {
|
|
71
|
+
const reqContext = await this.getRequestContext(ctx, false);
|
|
72
|
+
if (options?.before)
|
|
73
|
+
await options.before(reqContext);
|
|
74
|
+
const identifier = reqContext.params.id;
|
|
75
|
+
const config = {
|
|
76
|
+
expand: reqContext.queries[Query.Expand] || undefined,
|
|
77
|
+
cache: this.getCache(ctx, this._options.cache, options?.cache),
|
|
78
|
+
cacheTTL: this._options.cacheTTL ?? options?.cacheTTL
|
|
79
|
+
};
|
|
80
|
+
let response = await this._service.get(identifier, config);
|
|
81
|
+
if (options?.after)
|
|
82
|
+
await options.after(reqContext, response);
|
|
83
|
+
await this.maskPrivateFields(reqContext, response);
|
|
84
|
+
if (options?.download) {
|
|
85
|
+
const downloadRes = await options.download(reqContext, response);
|
|
86
|
+
const headers = {
|
|
87
|
+
'Content-Type': 'application/octet-stream',
|
|
88
|
+
'content-disposition': `attachment; filename=${downloadRes.filename}`
|
|
89
|
+
};
|
|
90
|
+
return ctx.body(downloadRes.buffer, 200, headers);
|
|
91
|
+
}
|
|
92
|
+
else
|
|
93
|
+
return ctx.json(response);
|
|
94
|
+
}
|
|
95
|
+
async _getAll(options, ctx) {
|
|
96
|
+
const reqContext = await this.getRequestContext(ctx, false);
|
|
97
|
+
if (options?.before)
|
|
98
|
+
await options.before(reqContext);
|
|
99
|
+
const queryParams = reqContext.queries;
|
|
100
|
+
let limit = parseInt(queryParams.limit) || this._pageLimitDefault;
|
|
101
|
+
if (limit > this._pageLimitMax && !options?.limitOverride)
|
|
102
|
+
limit = this._pageLimitMax;
|
|
103
|
+
let response = await this._service.getAll({
|
|
104
|
+
limit: limit,
|
|
105
|
+
cursor: queryParams.cursor,
|
|
106
|
+
sort: queryParams.orderBy,
|
|
107
|
+
filter: queryParams.filter,
|
|
108
|
+
expand: reqContext.queries[Query.Expand] || undefined,
|
|
109
|
+
cache: this.getCache(ctx, this._options.cache, options?.cache),
|
|
110
|
+
cacheTTL: this._options.cacheTTL ?? options?.cacheTTL
|
|
111
|
+
});
|
|
112
|
+
if (options?.after)
|
|
113
|
+
await options.after(reqContext, response);
|
|
114
|
+
await this.maskPrivateFields(reqContext, response);
|
|
115
|
+
return ctx.json(response);
|
|
116
|
+
}
|
|
117
|
+
async _update(options, ctx) {
|
|
118
|
+
const reqContext = await this.getRequestContext(ctx);
|
|
119
|
+
await this.preventIDOR(reqContext);
|
|
120
|
+
this.removeSystemFields(reqContext);
|
|
121
|
+
if (options?.before)
|
|
122
|
+
await options.before(reqContext);
|
|
123
|
+
const identifier = reqContext.params.id;
|
|
124
|
+
const config = {
|
|
125
|
+
cache: this.getCache(ctx, this._options.cache, options?.cache),
|
|
126
|
+
cacheTTL: this._options.cacheTTL ?? options?.cacheTTL
|
|
127
|
+
};
|
|
128
|
+
let response = await this._service.update(identifier, reqContext.body, config);
|
|
129
|
+
if (options?.after)
|
|
130
|
+
await options.after(reqContext, response);
|
|
131
|
+
return ctx.json(response);
|
|
132
|
+
}
|
|
133
|
+
async _updateMany(options, ctx) {
|
|
134
|
+
const reqContext = await this.getRequestContext(ctx);
|
|
135
|
+
await this.preventIDOR(reqContext);
|
|
136
|
+
this.removeSystemFields(reqContext);
|
|
137
|
+
if (options?.before)
|
|
138
|
+
await options.before(reqContext);
|
|
139
|
+
const config = {
|
|
140
|
+
cache: this.getCache(ctx, this._options.cache, options?.cache),
|
|
141
|
+
cacheTTL: this._options.cacheTTL ?? options?.cacheTTL
|
|
142
|
+
};
|
|
143
|
+
let response = await this._service.updateMany(reqContext.body, config);
|
|
144
|
+
if (options?.after)
|
|
145
|
+
await options.after(reqContext, response);
|
|
146
|
+
return ctx.json(response);
|
|
147
|
+
}
|
|
148
|
+
async _delete(options, ctx) {
|
|
149
|
+
const reqContext = await this.getRequestContext(ctx);
|
|
150
|
+
if (options?.before)
|
|
151
|
+
await options.before(reqContext);
|
|
152
|
+
const identifier = reqContext.params.id;
|
|
153
|
+
const config = {
|
|
154
|
+
cache: this.getCache(ctx, this._options.cache, options?.cache),
|
|
155
|
+
cacheTTL: this._options.cacheTTL ?? options?.cacheTTL
|
|
156
|
+
};
|
|
157
|
+
let response = await this._service.delete(identifier, config);
|
|
158
|
+
if (options?.after)
|
|
159
|
+
await options.after(reqContext, response);
|
|
160
|
+
return ctx.json({ success: !!response });
|
|
161
|
+
}
|
|
162
|
+
async _deleteMany(options, ctx) {
|
|
163
|
+
const reqContext = await this.getRequestContext(ctx);
|
|
164
|
+
if (options?.before)
|
|
165
|
+
await options.before(reqContext);
|
|
166
|
+
const config = {
|
|
167
|
+
filter: reqContext.queries.filter,
|
|
168
|
+
cache: this.getCache(ctx, this._options.cache, options?.cache),
|
|
169
|
+
cacheTTL: this._options.cacheTTL ?? options?.cacheTTL
|
|
170
|
+
};
|
|
171
|
+
let response = await this._service.deleteMany(config);
|
|
172
|
+
if (options?.after)
|
|
173
|
+
await options.after(reqContext, response);
|
|
174
|
+
return ctx.json({ success: !!response });
|
|
175
|
+
}
|
|
176
|
+
async getRequestContext(ctx, hasBody = true) {
|
|
177
|
+
let body = {};
|
|
178
|
+
if (hasBody) {
|
|
179
|
+
try {
|
|
180
|
+
body = await ctx.req.json();
|
|
181
|
+
}
|
|
182
|
+
catch (e) { }
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
headers: ctx.req.raw.headers,
|
|
186
|
+
waitUntil: ctx.executionCtx.waitUntil,
|
|
187
|
+
body: body,
|
|
188
|
+
params: ctx.req.param(),
|
|
189
|
+
queries: ctx.req.query(),
|
|
190
|
+
env: ctx.env,
|
|
191
|
+
get: (key) => { return ctx.get(key); }
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
getCache(ctx, controllerLevel, routeLevel) {
|
|
195
|
+
const useCache = routeLevel ?? controllerLevel;
|
|
196
|
+
return useCache ? ctx.env.CACHE : undefined;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { StatusCode } from "hono/utils/http-status";
|
|
2
|
+
export declare class APIError extends Error {
|
|
3
|
+
data?: any;
|
|
4
|
+
internalProperties?: any;
|
|
5
|
+
readonly statusCode: StatusCode;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
constructor(name: string, message: string, statusCode: StatusCode, data?: any, internalProperties?: any);
|
|
8
|
+
static errBadRequest(message: string, data?: any, internalProperties?: any): APIError;
|
|
9
|
+
static errInvalidQueryParameter(message: string, data?: any, internalProperties?: any): APIError;
|
|
10
|
+
static errMissingBody(data?: any, internalProperties?: any): APIError;
|
|
11
|
+
static errInvalidBody(data?: any, internalProperties?: any): APIError;
|
|
12
|
+
static errInvalidParameterValue(message: string, data?: any, internalProperties?: any): APIError;
|
|
13
|
+
static errInvalidHeaderParameter(message: string, data?: any, internalProperties?: any): APIError;
|
|
14
|
+
static errUnauthorized(data?: any, internalProperties?: any): APIError;
|
|
15
|
+
static errInvalidAccessToken(data?: any, internalProperties?: any): APIError;
|
|
16
|
+
static errInvalidIdToken(data?: any, internalProperties?: any): APIError;
|
|
17
|
+
static errInvalidAuthToken(message?: string, data?: any, internalProperties?: any): APIError;
|
|
18
|
+
static errInvalidSessionToken(message?: string, data?: any, internalProperties?: any): APIError;
|
|
19
|
+
static errPermissionDenied(message?: string, data?: any, internalProperties?: any): APIError;
|
|
20
|
+
static errAlreadyExists(data?: any, internalProperties?: any): APIError;
|
|
21
|
+
static errNotFound(message?: string, data?: any, internalProperties?: any): APIError;
|
|
22
|
+
static errResourceCreationFailed(message: string, data?: any, internalProperties?: any): APIError;
|
|
23
|
+
static errResourceUpdateFailed(message: string, data?: any, internalProperties?: any): APIError;
|
|
24
|
+
static errResourceDeletionFailed(message: string, data?: any, internalProperties?: any): APIError;
|
|
25
|
+
static errFailedDependency(message?: string, data?: any, internalProperties?: any): APIError;
|
|
26
|
+
static errTemporarilyUnavailable(message?: string, data?: any, internalProperties?: any): APIError;
|
|
27
|
+
static errServerError(data?: any, internalProperties?: any): APIError;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=api-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-error.d.ts","sourceRoot":"","sources":["../../src/core/api-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,qBAAa,QAAS,SAAQ,KAAK;IAQxB,IAAI,CAAC;IACL,kBAAkB,CAAC;IAR5B,SAAgB,UAAU,EAAG,UAAU,CAAC;IACxC,SAAgB,IAAI,EAAG,MAAM,CAAC;gBAG5B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,UAAU,EACf,IAAI,CAAC,KAAK,EACV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C,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,kBAAkB,CAAC,EAAE,GAAG;WAIlE,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,kBAAkB,CAAC,EAAE,GAAG;WAG/E,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,kBAAkB,CAAC,EAAE,GAAG;WAG7E,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,kBAAkB,CAAC,EAAE,GAAG;WAG/E,mBAAmB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,kBAAkB,CAAC,EAAE,GAAG;WAG1E,yBAAyB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,kBAAkB,CAAC,EAAE,GAAG;WAGhF,cAAc,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,kBAAkB,CAAC,EAAE,GAAG;CASlE"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export class APIError extends Error {
|
|
2
|
+
data;
|
|
3
|
+
internalProperties;
|
|
4
|
+
statusCode;
|
|
5
|
+
name;
|
|
6
|
+
constructor(name, message, statusCode, data, internalProperties) {
|
|
7
|
+
super();
|
|
8
|
+
this.data = data;
|
|
9
|
+
this.internalProperties = internalProperties;
|
|
10
|
+
this.name = name;
|
|
11
|
+
this.statusCode = statusCode;
|
|
12
|
+
this.message = message;
|
|
13
|
+
}
|
|
14
|
+
static errBadRequest(message, data, internalProperties) {
|
|
15
|
+
return new APIError('BadRequest', message, 400, data, internalProperties);
|
|
16
|
+
}
|
|
17
|
+
static errInvalidQueryParameter(message, data, internalProperties) {
|
|
18
|
+
return new APIError('InvalidQueryParameter', message, 400, data, internalProperties);
|
|
19
|
+
}
|
|
20
|
+
static errMissingBody(data, internalProperties) {
|
|
21
|
+
return new APIError('MissingBody', 'Missing Data in Request Body.', 400, data, internalProperties);
|
|
22
|
+
}
|
|
23
|
+
static errInvalidBody(data, internalProperties) {
|
|
24
|
+
return new APIError('InvalidBody', 'Invalid Request Body.', 422, data, internalProperties);
|
|
25
|
+
}
|
|
26
|
+
static errInvalidParameterValue(message, data, internalProperties) {
|
|
27
|
+
return new APIError('InvalidParameterValue', message, 400, data, internalProperties);
|
|
28
|
+
}
|
|
29
|
+
static errInvalidHeaderParameter(message, data, internalProperties) {
|
|
30
|
+
return new APIError('InvalidHeaderParameter', message, 400, data, internalProperties);
|
|
31
|
+
}
|
|
32
|
+
static errUnauthorized(data, internalProperties) {
|
|
33
|
+
return new APIError('Unauthorized', 'Client Authorization Failed.', 401, data, internalProperties);
|
|
34
|
+
}
|
|
35
|
+
static errInvalidAccessToken(data, internalProperties) {
|
|
36
|
+
return new APIError('InvalidAccessToken', 'Invalid authentication token', 401, data, internalProperties);
|
|
37
|
+
}
|
|
38
|
+
static errInvalidIdToken(data, internalProperties) {
|
|
39
|
+
return new APIError('InvalidIdToken', 'Invalid Id Token', 401, data, internalProperties);
|
|
40
|
+
}
|
|
41
|
+
static errInvalidAuthToken(message, data, internalProperties) {
|
|
42
|
+
message = message ? message : 'Invalid Auth Token';
|
|
43
|
+
return new APIError('InvalidAuthToken', message, 401, data, internalProperties);
|
|
44
|
+
}
|
|
45
|
+
static errInvalidSessionToken(message, data, internalProperties) {
|
|
46
|
+
message = message ? message : 'Invalid Session Token';
|
|
47
|
+
return new APIError('InvalidAuthToken', message, 401, data, internalProperties);
|
|
48
|
+
}
|
|
49
|
+
static errPermissionDenied(message, data, internalProperties) {
|
|
50
|
+
message = message ? message : "You don't have permission to perform this action.";
|
|
51
|
+
return new APIError('Forbidden', message, 403, data, internalProperties);
|
|
52
|
+
}
|
|
53
|
+
static errAlreadyExists(data, internalProperties) {
|
|
54
|
+
return new APIError('AlreadyExists', 'Requested resource already exists', 409, data, internalProperties);
|
|
55
|
+
}
|
|
56
|
+
static errNotFound(message, data, internalProperties) {
|
|
57
|
+
message = message ? message : 'Requested resource does not exist';
|
|
58
|
+
return new APIError('Resource not found', message, 404, data, internalProperties);
|
|
59
|
+
}
|
|
60
|
+
static errResourceCreationFailed(message, data, internalProperties) {
|
|
61
|
+
return new APIError('ResourceCreationFailed', message, 409, data, internalProperties);
|
|
62
|
+
}
|
|
63
|
+
static errResourceUpdateFailed(message, data, internalProperties) {
|
|
64
|
+
return new APIError('ResourceUpdateFailed', message, 409, data, internalProperties);
|
|
65
|
+
}
|
|
66
|
+
static errResourceDeletionFailed(message, data, internalProperties) {
|
|
67
|
+
return new APIError('ResourceDeletionFailed', message, 409, data, internalProperties);
|
|
68
|
+
}
|
|
69
|
+
static errFailedDependency(message, data, internalProperties) {
|
|
70
|
+
return new APIError('FailedDependency', message || 'Try again later.', 424, data, internalProperties);
|
|
71
|
+
}
|
|
72
|
+
static errTemporarilyUnavailable(message, data, internalProperties) {
|
|
73
|
+
return new APIError('ServiceTemporarilyUnavailable', message || 'Try again later.', 503, data, internalProperties);
|
|
74
|
+
}
|
|
75
|
+
static errServerError(data, internalProperties) {
|
|
76
|
+
return new APIError('Internal Server Error', 'Request could not be carried out.', 500, data, internalProperties);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="@cloudflare/workers-types" />
|
|
2
|
+
import BaseModel from "./base.model";
|
|
3
|
+
export default class BaseCache {
|
|
4
|
+
private static kvKeySizeLimit;
|
|
5
|
+
static get<T>(cache: KVNamespace, key: string): Promise<T | null>;
|
|
6
|
+
static set<T>(cache: KVNamespace, key: string, value: T, ttl?: number): Promise<void>;
|
|
7
|
+
static delete(cache: KVNamespace, key: string): Promise<void>;
|
|
8
|
+
static setModel<T extends BaseModel>(cache: KVNamespace, model: T, modifier?: object, ttl?: number): Promise<void>;
|
|
9
|
+
static getModel<U extends typeof BaseModel>(cache: KVNamespace, model: U, identifier: string | number, modifier?: object): Promise<InstanceType<U> | null>;
|
|
10
|
+
static clearModel<T extends BaseModel>(cache: KVNamespace, model: T | undefined): Promise<void>;
|
|
11
|
+
static setPage<T extends BaseModel>(cache: KVNamespace, page: T[], modifier?: object, ttl?: number): Promise<void>;
|
|
12
|
+
static getPage<U extends typeof BaseModel>(cache: KVNamespace, model: U, modifier?: object): Promise<InstanceType<U>[] | null>;
|
|
13
|
+
static clearPage<T extends typeof BaseModel>(cache: KVNamespace, model: T): Promise<void>;
|
|
14
|
+
private static getModifier;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=base.cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.cache.d.ts","sourceRoot":"","sources":["../../src/core/base.cache.ts"],"names":[],"mappings":";AAGA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,OAAO,CAAC,MAAM,CAAC,cAAc,CAAO;WAEhB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;WAS1D,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,GAAE,MAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;WAI/F,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAOtD,QAAQ,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAc3G,QAAQ,CAAC,CAAC,SAAS,OAAO,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;WAOnJ,UAAU,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;WA+BxF,OAAO,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAS3G,OAAO,CAAC,CAAC,SAAS,OAAO,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;WAOvH,SAAS,CAAC,CAAC,SAAS,OAAO,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;mBAWjF,WAAW;CAGjC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { CachePrefix, DefaultCacheTTL } from "../types/api.types";
|
|
2
|
+
import { isEmpty } from "../utils/array.utils";
|
|
3
|
+
import { sha256 } from "../utils/crypto.utils";
|
|
4
|
+
export default class BaseCache {
|
|
5
|
+
static kvKeySizeLimit = 512;
|
|
6
|
+
static async get(cache, key) {
|
|
7
|
+
if (key.length > this.kvKeySizeLimit)
|
|
8
|
+
return null;
|
|
9
|
+
const response = await cache.get(key);
|
|
10
|
+
if (!response)
|
|
11
|
+
return null;
|
|
12
|
+
return JSON.parse(response);
|
|
13
|
+
}
|
|
14
|
+
static async set(cache, key, value, ttl = DefaultCacheTTL) {
|
|
15
|
+
key.length <= this.kvKeySizeLimit && await cache.put(key, JSON.stringify(value), { expirationTtl: ttl });
|
|
16
|
+
}
|
|
17
|
+
static async delete(cache, key) {
|
|
18
|
+
key.length <= this.kvKeySizeLimit && await cache.delete(key);
|
|
19
|
+
}
|
|
20
|
+
static async setModel(cache, model, modifier, ttl) {
|
|
21
|
+
const identifier = model?.$id();
|
|
22
|
+
if (!identifier)
|
|
23
|
+
return;
|
|
24
|
+
const modifierTag = await this.getModifier(modifier);
|
|
25
|
+
await this.set(cache, `${CachePrefix.Record}${model.constructor.name}:${identifier.toString()}:${modifierTag}`, model, ttl);
|
|
26
|
+
if (model.$key()) {
|
|
27
|
+
await this.set(cache, `${CachePrefix.Record}${model.constructor.name}:${model.$key()}:${modifierTag}`, model, ttl);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
static async getModel(cache, model, identifier, modifier) {
|
|
31
|
+
const modifierTag = await this.getModifier(modifier);
|
|
32
|
+
return await this.get(cache, `${CachePrefix.Record}${model.name}:${identifier.toString()}:${modifierTag}`);
|
|
33
|
+
}
|
|
34
|
+
static async clearModel(cache, model) {
|
|
35
|
+
if (!model)
|
|
36
|
+
return;
|
|
37
|
+
const identifier = model?.$id();
|
|
38
|
+
if (!identifier)
|
|
39
|
+
return;
|
|
40
|
+
const idList = await cache.list({ prefix: `${CachePrefix.Record}${model.constructor.name}:${identifier.toString()}` });
|
|
41
|
+
const idPromises = idList.keys.map(async (key) => {
|
|
42
|
+
await this.delete(cache, key.name);
|
|
43
|
+
});
|
|
44
|
+
let keyPromises = [];
|
|
45
|
+
if (model.$key()) {
|
|
46
|
+
const keyList = await cache.list({ prefix: `${CachePrefix.Record}${model.constructor.name}:${model.$key()}` });
|
|
47
|
+
keyPromises = keyList.keys.map(async (key) => {
|
|
48
|
+
await this.delete(cache, key.name);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
await Promise.all([...idPromises, ...keyPromises]);
|
|
52
|
+
}
|
|
53
|
+
static async setPage(cache, page, modifier, ttl) {
|
|
54
|
+
if (!page.length)
|
|
55
|
+
return;
|
|
56
|
+
const modifierTag = await this.getModifier(modifier);
|
|
57
|
+
await this.set(cache, `${CachePrefix.Page}${page[0].constructor.name}:${modifierTag}`, page, ttl);
|
|
58
|
+
}
|
|
59
|
+
static async getPage(cache, model, modifier) {
|
|
60
|
+
const modifierTag = await this.getModifier(modifier);
|
|
61
|
+
return await this.get(cache, `${CachePrefix.Page}${model.name}:${modifierTag}`);
|
|
62
|
+
}
|
|
63
|
+
static async clearPage(cache, model) {
|
|
64
|
+
const list = await cache.list({ prefix: `${CachePrefix.Page}${model.name}` });
|
|
65
|
+
Promise.all(list.keys.map(async (key) => {
|
|
66
|
+
await this.delete(cache, key.name);
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
static async getModifier(modifier) {
|
|
70
|
+
return modifier && !isEmpty(modifier) ? await sha256(JSON.stringify(modifier)) : "";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DB } from "../types/db.types";
|
|
2
|
+
import { IndexSummary, PropSummary } from "../types/decorator.types";
|
|
3
|
+
import { FilterConfig, PageConfig, UpsertConfig } from "./base.options";
|
|
4
|
+
interface BaseModelSchema {
|
|
5
|
+
indexes: IndexSummary[];
|
|
6
|
+
props: PropSummary;
|
|
7
|
+
timestamped?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class Document {
|
|
10
|
+
static schema: BaseModelSchema;
|
|
11
|
+
}
|
|
12
|
+
export default class BaseModel extends Document {
|
|
13
|
+
static collection: string;
|
|
14
|
+
static idField: string;
|
|
15
|
+
static keyField?: string;
|
|
16
|
+
static ownerField?: string;
|
|
17
|
+
static db: DB;
|
|
18
|
+
id: number;
|
|
19
|
+
static create<T extends typeof BaseModel>(this: T, data: Partial<InstanceType<T>>, upsertConfig?: UpsertConfig<T>): Promise<InstanceType<T> | null>;
|
|
20
|
+
static createMany<T extends typeof BaseModel>(this: T, data: Partial<InstanceType<T>>[], upsertConfig?: UpsertConfig<T>): Promise<InstanceType<T>[] | null>;
|
|
21
|
+
static findById<T extends typeof BaseModel>(this: T, id: string | number, config?: FilterConfig): Promise<InstanceType<T> | null>;
|
|
22
|
+
static findOne<T extends typeof BaseModel>(this: T, config: FilterConfig): Promise<InstanceType<T> | null>;
|
|
23
|
+
static findMany<T extends typeof BaseModel>(this: T, config?: PageConfig & FilterConfig): Promise<Array<InstanceType<T>>>;
|
|
24
|
+
static update<T extends typeof BaseModel>(this: T, id: string | number, data: Partial<InstanceType<T>>): Promise<InstanceType<T> | null>;
|
|
25
|
+
static updateMany<T extends typeof BaseModel>(this: T, data: Partial<InstanceType<T>>[]): Promise<InstanceType<T>[] | null>;
|
|
26
|
+
static delete<T extends typeof BaseModel>(this: T, id: string): Promise<InstanceType<T> | null>;
|
|
27
|
+
static deleteMany<T extends typeof BaseModel>(this: T, config?: FilterConfig): Promise<InstanceType<T>[] | null>;
|
|
28
|
+
static count<T extends typeof BaseModel>(this: T): Promise<number | null>;
|
|
29
|
+
static fromDatabaseJson<T extends typeof BaseModel>(this: T, json: object): InstanceType<T>;
|
|
30
|
+
private static addDefaults;
|
|
31
|
+
$id(): any;
|
|
32
|
+
$key(): any;
|
|
33
|
+
$owner(): any;
|
|
34
|
+
}
|
|
35
|
+
export declare abstract class TimeStamped extends BaseModel {
|
|
36
|
+
createdAt?: Date;
|
|
37
|
+
updatedAt?: Date;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=base.model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.model.d.ts","sourceRoot":"","sources":["../../src/core/base.model.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,EAAE,EAAa,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EA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