@ug.software/opposer 3.0.10 → 3.0.11
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/bin/commands/build.js +15 -28
- package/lib/bin/commands/init.js +27 -30
- package/lib/esm/server/security/jwt/index.d.ts +1 -1
- package/lib/esm/server/security/jwt/index.js +21 -29
- package/lib/esm/system/index.d.ts +1 -1
- package/lib/esm/system/index.js +42 -55
- package/package.json +3 -3
- package/lib/cjs/examples/full-app/index.d.ts +0 -1
- package/lib/cjs/examples/full-app/index.js +0 -102
- package/lib/cjs/examples/full-app/models/author.d.ts +0 -7
- package/lib/cjs/examples/full-app/models/author.js +0 -42
- package/lib/cjs/examples/full-app/models/book.d.ts +0 -9
- package/lib/cjs/examples/full-app/models/book.js +0 -51
- package/lib/cjs/examples/full-app/models/category.d.ts +0 -4
- package/lib/cjs/examples/full-app/models/category.js +0 -26
- package/lib/cjs/examples/full-app/schedules/catalog-refresh.d.ts +0 -28
- package/lib/cjs/examples/full-app/schedules/catalog-refresh.js +0 -149
- package/lib/cjs/examples/full-app/schedules/inventory-sync.d.ts +0 -12
- package/lib/cjs/examples/full-app/schedules/inventory-sync.js +0 -61
- package/lib/cjs/examples/full-app/schedules/library-alerts.d.ts +0 -11
- package/lib/cjs/examples/full-app/schedules/library-alerts.js +0 -55
- package/lib/cjs/examples/minimal/src/handlers/book.d.ts +0 -11
- package/lib/cjs/examples/minimal/src/handlers/book.js +0 -51
- package/lib/cjs/examples/minimal/src/index.d.ts +0 -1
- package/lib/cjs/examples/minimal/src/index.js +0 -14
- package/lib/cjs/examples/minimal/src/models/books.d.ts +0 -4
- package/lib/cjs/examples/minimal/src/models/books.js +0 -26
- package/lib/cjs/examples/orm/models/permission.d.ts +0 -6
- package/lib/cjs/examples/orm/models/permission.js +0 -38
- package/lib/cjs/examples/orm/models/profile.d.ts +0 -7
- package/lib/cjs/examples/orm/models/profile.js +0 -42
- package/lib/cjs/examples/orm/models/user.d.ts +0 -11
- package/lib/cjs/examples/orm/models/user.js +0 -70
- package/lib/cjs/examples/orm/mysql/index.d.ts +0 -1
- package/lib/cjs/examples/orm/mysql/index.js +0 -44
- package/lib/cjs/examples/orm/postgres/index.d.ts +0 -1
- package/lib/cjs/examples/orm/postgres/index.js +0 -40
- package/lib/cjs/examples/orm/sqlite/index.d.ts +0 -1
- package/lib/cjs/examples/orm/sqlite/index.js +0 -41
- package/lib/cjs/index.d.ts +0 -2
- package/lib/cjs/index.js +0 -23
- package/lib/cjs/interfaces/controller.d.ts +0 -109
- package/lib/cjs/interfaces/controller.js +0 -2
- package/lib/cjs/interfaces/field.d.ts +0 -23
- package/lib/cjs/interfaces/field.js +0 -2
- package/lib/cjs/interfaces/handler.d.ts +0 -18
- package/lib/cjs/interfaces/handler.js +0 -2
- package/lib/cjs/interfaces/jwt.d.ts +0 -21
- package/lib/cjs/interfaces/jwt.js +0 -2
- package/lib/cjs/interfaces/model.d.ts +0 -9
- package/lib/cjs/interfaces/model.js +0 -2
- package/lib/cjs/interfaces/request.d.ts +0 -13
- package/lib/cjs/interfaces/request.js +0 -2
- package/lib/cjs/interfaces/schema.d.ts +0 -9
- package/lib/cjs/interfaces/schema.js +0 -2
- package/lib/cjs/interfaces/security.d.ts +0 -32
- package/lib/cjs/interfaces/security.js +0 -2
- package/lib/cjs/interfaces/server.d.ts +0 -37
- package/lib/cjs/interfaces/server.js +0 -2
- package/lib/cjs/interfaces/system.d.ts +0 -41
- package/lib/cjs/interfaces/system.js +0 -2
- package/lib/cjs/orm/decorators/index.d.ts +0 -33
- package/lib/cjs/orm/decorators/index.js +0 -131
- package/lib/cjs/orm/driver/mysql.d.ts +0 -14
- package/lib/cjs/orm/driver/mysql.js +0 -103
- package/lib/cjs/orm/driver/postgres.d.ts +0 -14
- package/lib/cjs/orm/driver/postgres.js +0 -105
- package/lib/cjs/orm/driver/sqlite.d.ts +0 -14
- package/lib/cjs/orm/driver/sqlite.js +0 -143
- package/lib/cjs/orm/index.d.ts +0 -8
- package/lib/cjs/orm/index.js +0 -28
- package/lib/cjs/orm/metadata.d.ts +0 -47
- package/lib/cjs/orm/metadata.js +0 -47
- package/lib/cjs/orm/opposer.d.ts +0 -30
- package/lib/cjs/orm/opposer.js +0 -33
- package/lib/cjs/orm/query-builder.d.ts +0 -32
- package/lib/cjs/orm/query-builder.js +0 -278
- package/lib/cjs/orm/repository.d.ts +0 -54
- package/lib/cjs/orm/repository.js +0 -325
- package/lib/cjs/orm/validation.d.ts +0 -44
- package/lib/cjs/orm/validation.js +0 -128
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/persistent/cache/core-context.d.ts +0 -17
- package/lib/cjs/persistent/cache/core-context.js +0 -39
- package/lib/cjs/persistent/cache/global.d.ts +0 -18
- package/lib/cjs/persistent/cache/global.js +0 -22
- package/lib/cjs/persistent/cache/index.d.ts +0 -3
- package/lib/cjs/persistent/cache/index.js +0 -12
- package/lib/cjs/persistent/cache/session.d.ts +0 -19
- package/lib/cjs/persistent/cache/session.js +0 -39
- package/lib/cjs/persistent/cache/storage.d.ts +0 -14
- package/lib/cjs/persistent/cache/storage.js +0 -88
- package/lib/cjs/persistent/cache/store.d.ts +0 -16
- package/lib/cjs/persistent/cache/store.js +0 -112
- package/lib/cjs/persistent/context/index.d.ts +0 -3
- package/lib/cjs/persistent/context/index.js +0 -5
- package/lib/cjs/persistent/decorators/global.d.ts +0 -1
- package/lib/cjs/persistent/decorators/global.js +0 -25
- package/lib/cjs/persistent/decorators/session.d.ts +0 -1
- package/lib/cjs/persistent/decorators/session.js +0 -27
- package/lib/cjs/persistent/index.d.ts +0 -6
- package/lib/cjs/persistent/index.js +0 -18
- package/lib/cjs/persistent/interfaces/context.d.ts +0 -5
- package/lib/cjs/persistent/interfaces/context.js +0 -2
- package/lib/cjs/persistent/interfaces/system.d.ts +0 -47
- package/lib/cjs/persistent/interfaces/system.js +0 -29
- package/lib/cjs/persistent/system/index.d.ts +0 -7
- package/lib/cjs/persistent/system/index.js +0 -44
- package/lib/cjs/persistent/utils/memory.d.ts +0 -8
- package/lib/cjs/persistent/utils/memory.js +0 -44
- package/lib/cjs/persistent/utils/timer.d.ts +0 -14
- package/lib/cjs/persistent/utils/timer.js +0 -21
- package/lib/cjs/playground/build/client/assets/AddRounded-ByHfnsiW.js +0 -4
- package/lib/cjs/playground/build/client/assets/Button-DLrxHRm7.js +0 -1
- package/lib/cjs/playground/build/client/assets/Container-CgITmmbk.js +0 -1
- package/lib/cjs/playground/build/client/assets/Divider-B_Wx9srO.js +0 -1
- package/lib/cjs/playground/build/client/assets/List-juBjUmfP.js +0 -1
- package/lib/cjs/playground/build/client/assets/ListItemText-DgWZmgzc.js +0 -1
- package/lib/cjs/playground/build/client/assets/MenuItem-D_5SuVKQ.js +0 -1
- package/lib/cjs/playground/build/client/assets/Modal-BwXR_5Bh.js +0 -1
- package/lib/cjs/playground/build/client/assets/TableRow-B9hAmlnV.js +0 -2
- package/lib/cjs/playground/build/client/assets/TextField-UybdTIGB.js +0 -3
- package/lib/cjs/playground/build/client/assets/Tooltip-BGcUWUcF.js +0 -1
- package/lib/cjs/playground/build/client/assets/auth-CD1rXHzz.js +0 -1
- package/lib/cjs/playground/build/client/assets/auth-GyTIVKy5.js +0 -1
- package/lib/cjs/playground/build/client/assets/confirm-Dr0pbiV6.js +0 -1
- package/lib/cjs/playground/build/client/assets/dividerClasses-CIiqeEPO.js +0 -1
- package/lib/cjs/playground/build/client/assets/entry.client-D6FYz1yh.js +0 -13
- package/lib/cjs/playground/build/client/assets/index-CJ0wdt6Z.js +0 -1
- package/lib/cjs/playground/build/client/assets/index-CQc11yq_.js +0 -1153
- package/lib/cjs/playground/build/client/assets/index-Cr4I-4J2.js +0 -1
- package/lib/cjs/playground/build/client/assets/index-CtPqstFl.js +0 -26
- package/lib/cjs/playground/build/client/assets/index-Ct_NE85o.js +0 -1
- package/lib/cjs/playground/build/client/assets/index-D0I6xwmb.js +0 -1
- package/lib/cjs/playground/build/client/assets/index-DmDCpKb3.js +0 -1
- package/lib/cjs/playground/build/client/assets/index-DsSkAwyn.js +0 -1
- package/lib/cjs/playground/build/client/assets/index-_DMgWZ3Y.js +0 -1
- package/lib/cjs/playground/build/client/assets/listItemIconClasses-39Itzgzt.js +0 -1
- package/lib/cjs/playground/build/client/assets/listItemTextClasses-EQFLPLzt.js +0 -1
- package/lib/cjs/playground/build/client/assets/manifest-c06e9a7f.js +0 -1
- package/lib/cjs/playground/build/client/assets/mergeSlotProps-DptgQgAT.js +0 -1
- package/lib/cjs/playground/build/client/assets/playground-Hl52p9f5.js +0 -108
- package/lib/cjs/playground/build/client/assets/root-CQTBmuv8.js +0 -1
- package/lib/cjs/playground/build/client/assets/toast-CsAH5FIf.js +0 -1
- package/lib/cjs/playground/build/client/assets/use-request-BZNkzlTr.js +0 -1
- package/lib/cjs/playground/build/client/favicon.ico +0 -0
- package/lib/cjs/playground/build/client/index.html +0 -6
- package/lib/cjs/playground/index.d.ts +0 -2
- package/lib/cjs/playground/index.js +0 -135
- package/lib/cjs/scheduler/controllers/index.d.ts +0 -19
- package/lib/cjs/scheduler/controllers/index.js +0 -62
- package/lib/cjs/scheduler/decorators/index.d.ts +0 -9
- package/lib/cjs/scheduler/decorators/index.js +0 -21
- package/lib/cjs/scheduler/handlers/index.d.ts +0 -19
- package/lib/cjs/scheduler/handlers/index.js +0 -62
- package/lib/cjs/scheduler/index.d.ts +0 -24
- package/lib/cjs/scheduler/index.js +0 -110
- package/lib/cjs/scheduler/models/history.d.ts +0 -10
- package/lib/cjs/scheduler/models/history.js +0 -50
- package/lib/cjs/server/constants/index.d.ts +0 -78
- package/lib/cjs/server/constants/index.js +0 -372
- package/lib/cjs/server/context/index.d.ts +0 -17
- package/lib/cjs/server/context/index.js +0 -33
- package/lib/cjs/server/controller/index.d.ts +0 -3
- package/lib/cjs/server/controller/index.js +0 -217
- package/lib/cjs/server/controllers/index.d.ts +0 -5
- package/lib/cjs/server/controllers/index.js +0 -72
- package/lib/cjs/server/core/index.d.ts +0 -16
- package/lib/cjs/server/core/index.js +0 -110
- package/lib/cjs/server/core/middleware/body-parser.d.ts +0 -2
- package/lib/cjs/server/core/middleware/body-parser.js +0 -27
- package/lib/cjs/server/core/middleware/cors.d.ts +0 -4
- package/lib/cjs/server/core/middleware/cors.js +0 -32
- package/lib/cjs/server/core/middleware/logger.d.ts +0 -2
- package/lib/cjs/server/core/middleware/logger.js +0 -15
- package/lib/cjs/server/decorators/controller.d.ts +0 -3
- package/lib/cjs/server/decorators/controller.js +0 -14
- package/lib/cjs/server/decorators/field.d.ts +0 -2
- package/lib/cjs/server/decorators/field.js +0 -36
- package/lib/cjs/server/decorators/handler.d.ts +0 -3
- package/lib/cjs/server/decorators/handler.js +0 -14
- package/lib/cjs/server/decorators/index.d.ts +0 -7
- package/lib/cjs/server/decorators/index.js +0 -26
- package/lib/cjs/server/decorators/is-public-method.d.ts +0 -3
- package/lib/cjs/server/decorators/is-public-method.js +0 -16
- package/lib/cjs/server/decorators/is-public.d.ts +0 -3
- package/lib/cjs/server/decorators/is-public.js +0 -14
- package/lib/cjs/server/decorators/method.d.ts +0 -3
- package/lib/cjs/server/decorators/method.js +0 -16
- package/lib/cjs/server/decorators/payload.d.ts +0 -3
- package/lib/cjs/server/decorators/payload.js +0 -15
- package/lib/cjs/server/handlers/index.d.ts +0 -5
- package/lib/cjs/server/handlers/index.js +0 -72
- package/lib/cjs/server/helpers/index.d.ts +0 -17
- package/lib/cjs/server/helpers/index.js +0 -39
- package/lib/cjs/server/index.d.ts +0 -12
- package/lib/cjs/server/index.js +0 -176
- package/lib/cjs/server/security/controller/auth.d.ts +0 -76
- package/lib/cjs/server/security/controller/auth.js +0 -346
- package/lib/cjs/server/security/index.d.ts +0 -2
- package/lib/cjs/server/security/index.js +0 -10
- package/lib/cjs/server/security/jwt/index.d.ts +0 -23
- package/lib/cjs/server/security/jwt/index.js +0 -108
- package/lib/cjs/server/security/middleware/autorization.d.ts +0 -3
- package/lib/cjs/server/security/middleware/autorization.js +0 -46
- package/lib/cjs/server/security/middleware/permission.d.ts +0 -3
- package/lib/cjs/server/security/middleware/permission.js +0 -138
- package/lib/cjs/server/security/models/crp.d.ts +0 -8
- package/lib/cjs/server/security/models/crp.js +0 -42
- package/lib/cjs/server/security/models/ke.d.ts +0 -7
- package/lib/cjs/server/security/models/ke.js +0 -38
- package/lib/cjs/server/security/models/rl.d.ts +0 -9
- package/lib/cjs/server/security/models/rl.js +0 -50
- package/lib/cjs/server/security/models/se.d.ts +0 -11
- package/lib/cjs/server/security/models/se.js +0 -54
- package/lib/cjs/server/security/models/usr.d.ts +0 -14
- package/lib/cjs/server/security/models/usr.js +0 -82
- package/lib/cjs/server/services/delete.d.ts +0 -13
- package/lib/cjs/server/services/delete.js +0 -49
- package/lib/cjs/server/services/get.d.ts +0 -4
- package/lib/cjs/server/services/get.js +0 -145
- package/lib/cjs/server/services/insert.d.ts +0 -13
- package/lib/cjs/server/services/insert.js +0 -74
- package/lib/cjs/server/services/update.d.ts +0 -13
- package/lib/cjs/server/services/update.js +0 -60
- package/lib/cjs/system/index.d.ts +0 -13
- package/lib/cjs/system/index.js +0 -237
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Repository = void 0;
|
|
7
|
-
const metadata_js_1 = require("./metadata.js");
|
|
8
|
-
const query_builder_js_1 = require("./query-builder.js");
|
|
9
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
10
|
-
class Repository {
|
|
11
|
-
constructor(connection, target) {
|
|
12
|
-
this.connection = connection;
|
|
13
|
-
this.target = target;
|
|
14
|
-
const metadata = metadata_js_1.MetadataStore.getEntity(target);
|
|
15
|
-
const fields = metadata_js_1.MetadataStore.getFields(target);
|
|
16
|
-
if (!metadata) {
|
|
17
|
-
throw new Error(`Entity metadata not found for ${target.name}`);
|
|
18
|
-
}
|
|
19
|
-
this.metadata = metadata;
|
|
20
|
-
this.fields = fields;
|
|
21
|
-
this.translator = new query_builder_js_1.QueryTranslator(this.metadata, this.fields, this.connection.getDriver());
|
|
22
|
-
}
|
|
23
|
-
get Metadata() {
|
|
24
|
-
return this.metadata;
|
|
25
|
-
}
|
|
26
|
-
get Fields() {
|
|
27
|
-
return this.fields;
|
|
28
|
-
}
|
|
29
|
-
async find(options) {
|
|
30
|
-
const driver = this.connection.getDriver();
|
|
31
|
-
const selectParts = [];
|
|
32
|
-
// Main entity select
|
|
33
|
-
selectParts.push(this.translator.translateSelect(options.select || []));
|
|
34
|
-
// Relations
|
|
35
|
-
const relationResult = this.translator.translateRelations(options.relation || []);
|
|
36
|
-
if (relationResult.select.length > 0) {
|
|
37
|
-
selectParts.push(...relationResult.select);
|
|
38
|
-
}
|
|
39
|
-
const { sql: where, params, joins: whereJoins } = this.translator.translateFilter(options.where || {});
|
|
40
|
-
const pagination = this.translator.translatePagination(options.pagination);
|
|
41
|
-
const allJoins = new Set(relationResult.joins);
|
|
42
|
-
// Add missing joins from where clause
|
|
43
|
-
if (whereJoins.size > 0) {
|
|
44
|
-
const neededJoins = Array.from(whereJoins);
|
|
45
|
-
// We need to translate these joins if they are not already in allJoins
|
|
46
|
-
// For simplicity, let's assume translateRelations can be called for individual relations
|
|
47
|
-
const missingJoinsResult = this.translator.translateRelations(neededJoins.filter(rj => !options.relation?.some(r => (typeof r === 'string' ? r === rj : r.model === rj))));
|
|
48
|
-
missingJoinsResult.joins.forEach(j => allJoins.add(j));
|
|
49
|
-
}
|
|
50
|
-
const joinsSql = Array.from(allJoins).join(' ');
|
|
51
|
-
const sql = `SELECT ${selectParts.join(', ')} FROM ${driver.quoteIdentifier(this.metadata.tableName)} ${joinsSql} ${where} ${pagination};`;
|
|
52
|
-
const results = await driver.query(sql, params);
|
|
53
|
-
const primaryFields = this.fields.filter((f) => f.primary);
|
|
54
|
-
const entitiesMap = new Map();
|
|
55
|
-
for (const row of results) {
|
|
56
|
-
const pk = primaryFields.map((f) => row[f.name]).join(':');
|
|
57
|
-
if (!entitiesMap.has(pk)) {
|
|
58
|
-
entitiesMap.set(pk, this.reconstruct(row));
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
const existing = entitiesMap.get(pk);
|
|
62
|
-
this.merge(existing, row);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return Array.from(entitiesMap.values());
|
|
66
|
-
}
|
|
67
|
-
async findOne(options) {
|
|
68
|
-
const results = await this.find({
|
|
69
|
-
...options,
|
|
70
|
-
pagination: { page: 0, take: 1 },
|
|
71
|
-
});
|
|
72
|
-
return results.length > 0 ? results[0] : null;
|
|
73
|
-
}
|
|
74
|
-
reconstruct(row) {
|
|
75
|
-
const entity = new this.target();
|
|
76
|
-
this.merge(entity, row);
|
|
77
|
-
return entity;
|
|
78
|
-
}
|
|
79
|
-
merge(entity, row) {
|
|
80
|
-
for (const [key, value] of Object.entries(row)) {
|
|
81
|
-
if (key.includes('.')) {
|
|
82
|
-
const parts = key.split('.');
|
|
83
|
-
let current = entity;
|
|
84
|
-
let currentTarget = this.target;
|
|
85
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
86
|
-
const part = parts[i];
|
|
87
|
-
const relationField = metadata_js_1.MetadataStore.getFields(currentTarget).find((f) => f.name === part);
|
|
88
|
-
if (relationField && relationField.relation) {
|
|
89
|
-
const isArray = relationField.relation.type === 'one-to-many' || relationField.relation.type === 'many-to-many';
|
|
90
|
-
const nextTarget = relationField.relation.target();
|
|
91
|
-
if (isArray) {
|
|
92
|
-
if (!Array.isArray(current[part])) {
|
|
93
|
-
current[part] = [];
|
|
94
|
-
}
|
|
95
|
-
// We need to find if the item already exists in the array
|
|
96
|
-
// To do that we need the primary key of the target entity
|
|
97
|
-
const targetFields = metadata_js_1.MetadataStore.getFields(nextTarget);
|
|
98
|
-
const targetPrimaryFields = targetFields.filter(f => f.primary);
|
|
99
|
-
// Find child row values for child PK
|
|
100
|
-
const childPkValues = {};
|
|
101
|
-
let hasAnyValue = false;
|
|
102
|
-
targetPrimaryFields.forEach(pf => {
|
|
103
|
-
const fullKey = [...parts.slice(0, i + 1), pf.name].join('.');
|
|
104
|
-
if (row[fullKey] !== undefined && row[fullKey] !== null) {
|
|
105
|
-
childPkValues[pf.name] = row[fullKey];
|
|
106
|
-
hasAnyValue = true;
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
if (!hasAnyValue) {
|
|
110
|
-
// If all PK fields of the relation are null, it means there's no related record (LEFT JOIN result)
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
let existingChild = current[part].find((item) => {
|
|
114
|
-
return targetPrimaryFields.every(pf => item[pf.name] === childPkValues[pf.name]);
|
|
115
|
-
});
|
|
116
|
-
if (!existingChild) {
|
|
117
|
-
existingChild = new nextTarget();
|
|
118
|
-
current[part].push(existingChild);
|
|
119
|
-
}
|
|
120
|
-
current = existingChild;
|
|
121
|
-
currentTarget = nextTarget;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
if (typeof current[part] === 'string' || current[part] === undefined || current[part] === null) {
|
|
125
|
-
const id = typeof current[part] === 'string' ? current[part] : undefined;
|
|
126
|
-
current[part] = id ? { id } : new nextTarget();
|
|
127
|
-
}
|
|
128
|
-
current = current[part];
|
|
129
|
-
currentTarget = nextTarget;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
// Fallback for non-metadata relations (should not happen with decorators)
|
|
134
|
-
if (current[part] === undefined || current[part] === null) {
|
|
135
|
-
current[part] = {};
|
|
136
|
-
}
|
|
137
|
-
current = current[part];
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
const lastPart = parts[parts.length - 1];
|
|
141
|
-
if (value !== null || current[lastPart] === undefined) {
|
|
142
|
-
current[lastPart] = value;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
if (value === null && typeof entity[key] === 'object' && entity[key] !== null) {
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
entity[key] = value;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
async executeHooks(type, entity) {
|
|
154
|
-
const hooks = metadata_js_1.MetadataStore.getHooks(this.target).filter((h) => {
|
|
155
|
-
return h.type === type;
|
|
156
|
-
});
|
|
157
|
-
for (const hook of hooks) {
|
|
158
|
-
const method = entity[hook.propertyKey];
|
|
159
|
-
if (typeof method === 'function') {
|
|
160
|
-
await method.apply(entity);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
async insert(data) {
|
|
165
|
-
const entity = Object.assign(new this.target(), data);
|
|
166
|
-
// Execute hooks
|
|
167
|
-
await this.executeHooks('before-insert', entity);
|
|
168
|
-
const persistableFields = metadata_js_1.MetadataStore.getPersistableFields(this.target);
|
|
169
|
-
const now = new Date();
|
|
170
|
-
for (const field of persistableFields) {
|
|
171
|
-
if (field.createDate || field.updateDate) {
|
|
172
|
-
if (entity[field.name] === undefined) {
|
|
173
|
-
entity[field.name] = now;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
if (field.generated && field.type === 'uuid' && entity[field.name] === undefined) {
|
|
177
|
-
entity[field.name] = crypto_1.default.randomUUID();
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
const persistableKeys = persistableFields.map((f) => {
|
|
181
|
-
return f.name;
|
|
182
|
-
});
|
|
183
|
-
const keys = Object.keys(entity).filter((k) => {
|
|
184
|
-
return persistableKeys.includes(k) || k === 'id';
|
|
185
|
-
});
|
|
186
|
-
const values = keys.map((k) => {
|
|
187
|
-
return entity[k];
|
|
188
|
-
});
|
|
189
|
-
const driver = this.connection.getDriver();
|
|
190
|
-
const placeholders = keys
|
|
191
|
-
.map((_, i) => {
|
|
192
|
-
return `$${i + 1}`;
|
|
193
|
-
})
|
|
194
|
-
.join(', ');
|
|
195
|
-
const columns = keys
|
|
196
|
-
.map((k) => {
|
|
197
|
-
return driver.quoteIdentifier(k);
|
|
198
|
-
})
|
|
199
|
-
.join(', ');
|
|
200
|
-
const isSqlite = driver.constructor.name === 'SQLiteDriver';
|
|
201
|
-
if (isSqlite) {
|
|
202
|
-
const sql = `INSERT INTO ${driver.quoteIdentifier(this.metadata.tableName)} (${columns}) VALUES (${placeholders});`;
|
|
203
|
-
await driver.query(sql, values);
|
|
204
|
-
// Fetch the inserted record using primary key(s)
|
|
205
|
-
const primaryFields = this.fields.filter((f) => {
|
|
206
|
-
return f.primary;
|
|
207
|
-
});
|
|
208
|
-
const where = {};
|
|
209
|
-
primaryFields.forEach((f) => {
|
|
210
|
-
where[f.name] = entity[f.name];
|
|
211
|
-
});
|
|
212
|
-
return (await this.findOne({ where }));
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
const sql = `INSERT INTO ${driver.quoteIdentifier(this.metadata.tableName)} (${columns}) VALUES (${placeholders}) RETURNING *;`;
|
|
216
|
-
const result = await driver.query(sql, values);
|
|
217
|
-
return result[0];
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
async update(where, data) {
|
|
221
|
-
const entity = Object.assign(new this.target(), data);
|
|
222
|
-
await this.executeHooks('before-update', entity);
|
|
223
|
-
const persistableFields = metadata_js_1.MetadataStore.getPersistableFields(this.target);
|
|
224
|
-
const now = new Date();
|
|
225
|
-
for (const field of persistableFields) {
|
|
226
|
-
if (field.updateDate) {
|
|
227
|
-
entity[field.name] = now;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
const driver = this.connection.getDriver();
|
|
231
|
-
const persistableKeys = persistableFields.map((f) => {
|
|
232
|
-
return f.name;
|
|
233
|
-
});
|
|
234
|
-
const setKeys = Object.keys(entity).filter((k) => {
|
|
235
|
-
return persistableKeys.includes(k);
|
|
236
|
-
});
|
|
237
|
-
const setValues = setKeys.map((k) => {
|
|
238
|
-
return entity[k];
|
|
239
|
-
});
|
|
240
|
-
const setSql = setKeys
|
|
241
|
-
.map((k, i) => {
|
|
242
|
-
return `${driver.quoteIdentifier(k)} = $${i + 1}`;
|
|
243
|
-
})
|
|
244
|
-
.join(', ');
|
|
245
|
-
const { sql: whereSql, params: whereParams } = this.translator.translateFilter(where);
|
|
246
|
-
// Adjust whereParams placeholders
|
|
247
|
-
const adjustedWhereSql = whereSql.replace(/\$(\d+)/g, (_, n) => {
|
|
248
|
-
return `$${parseInt(n) + setValues.length}`;
|
|
249
|
-
});
|
|
250
|
-
const sql = `UPDATE ${driver.quoteIdentifier(this.metadata.tableName)} SET ${setSql} ${adjustedWhereSql};`;
|
|
251
|
-
await driver.query(sql, [...setValues, ...whereParams]);
|
|
252
|
-
}
|
|
253
|
-
async delete(where) {
|
|
254
|
-
const driver = this.connection.getDriver();
|
|
255
|
-
const { sql: whereSql, params } = this.translator.translateFilter(where);
|
|
256
|
-
const sql = `DELETE FROM ${driver.quoteIdentifier(this.metadata.tableName)} ${whereSql};`;
|
|
257
|
-
await driver.query(sql, params);
|
|
258
|
-
}
|
|
259
|
-
async count(where) {
|
|
260
|
-
const driver = this.connection.getDriver();
|
|
261
|
-
const { sql: whereSql, params } = this.translator.translateFilter(where);
|
|
262
|
-
const sql = `SELECT COUNT(*) as count FROM ${driver.quoteIdentifier(this.metadata.tableName)} ${whereSql};`;
|
|
263
|
-
const result = await driver.query(sql, params);
|
|
264
|
-
return parseInt(result[0].count);
|
|
265
|
-
}
|
|
266
|
-
async exists(where) {
|
|
267
|
-
const driver = this.connection.getDriver();
|
|
268
|
-
const { sql: whereSql, params } = this.translator.translateFilter(where);
|
|
269
|
-
const sql = `SELECT 1 FROM ${driver.quoteIdentifier(this.metadata.tableName)} ${whereSql} LIMIT 1;`;
|
|
270
|
-
const result = await driver.query(sql, params);
|
|
271
|
-
return result.length > 0;
|
|
272
|
-
}
|
|
273
|
-
async aggregate(options) {
|
|
274
|
-
const driver = this.connection.getDriver();
|
|
275
|
-
const { sql: whereSql, params } = this.translator.translateFilter(options.where || {});
|
|
276
|
-
const aggregateSql = this.translator.translateAggregate(options.aggregate);
|
|
277
|
-
const sql = `SELECT ${aggregateSql} FROM ${driver.quoteIdentifier(this.metadata.tableName)} ${whereSql};`;
|
|
278
|
-
const result = await driver.query(sql, params);
|
|
279
|
-
return result[0];
|
|
280
|
-
}
|
|
281
|
-
async distinct(options) {
|
|
282
|
-
const driver = this.connection.getDriver();
|
|
283
|
-
const { sql: whereSql, params } = this.translator.translateFilter(options.where || {});
|
|
284
|
-
const sql = `SELECT DISTINCT ${driver.quoteIdentifier(options.field)} FROM ${driver.quoteIdentifier(this.metadata.tableName)} ${whereSql};`;
|
|
285
|
-
const result = await driver.query(sql, params);
|
|
286
|
-
return result.map((r) => {
|
|
287
|
-
return r[options.field];
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
async group(options) {
|
|
291
|
-
const driver = this.connection.getDriver();
|
|
292
|
-
const { sql: whereSql, params } = this.translator.translateFilter(options.where || {});
|
|
293
|
-
const groupSql = this.translator.translateGroup(options.by);
|
|
294
|
-
let selectParts = [];
|
|
295
|
-
if (options.select) {
|
|
296
|
-
selectParts.push(this.translator.translateSelect(options.select));
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
selectParts.push(options.by
|
|
300
|
-
.map((f) => {
|
|
301
|
-
return driver.quoteIdentifier(f);
|
|
302
|
-
})
|
|
303
|
-
.join(', '));
|
|
304
|
-
}
|
|
305
|
-
if (options.aggregate) {
|
|
306
|
-
selectParts.push(this.translator.translateAggregate(options.aggregate));
|
|
307
|
-
}
|
|
308
|
-
const sql = `SELECT ${selectParts.join(', ')} FROM ${driver.quoteIdentifier(this.metadata.tableName)} ${whereSql} ${groupSql};`;
|
|
309
|
-
return await driver.query(sql, params);
|
|
310
|
-
}
|
|
311
|
-
validate(data) {
|
|
312
|
-
const errors = {};
|
|
313
|
-
for (const field of this.fields) {
|
|
314
|
-
if (field.validation) {
|
|
315
|
-
const val = field.validation();
|
|
316
|
-
const fieldErrors = val.validate(data[field.name], data);
|
|
317
|
-
if (fieldErrors && fieldErrors.length > 0) {
|
|
318
|
-
errors[field.name] = fieldErrors;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
return errors;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
exports.Repository = Repository;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export type ValidationFunction = (value: unknown, context: object) => string | null;
|
|
2
|
-
export declare class FieldValidator {
|
|
3
|
-
protected _type: string | null;
|
|
4
|
-
protected _cases: ValidationFunction[];
|
|
5
|
-
protected _default: any;
|
|
6
|
-
get type(): string | null;
|
|
7
|
-
get defaultValue(): any;
|
|
8
|
-
default(value: any): this;
|
|
9
|
-
when(test: ValidationFunction): this;
|
|
10
|
-
validate(value: unknown, context: object): string[];
|
|
11
|
-
}
|
|
12
|
-
declare class NumberValidator extends FieldValidator {
|
|
13
|
-
constructor(message: string);
|
|
14
|
-
required(message: string): this;
|
|
15
|
-
min(min: number, message: string): this;
|
|
16
|
-
max(max: number, message: string): this;
|
|
17
|
-
}
|
|
18
|
-
declare class StringValidator extends FieldValidator {
|
|
19
|
-
constructor(message: string);
|
|
20
|
-
required(message: string): this;
|
|
21
|
-
match(regex: RegExp, message: string): this;
|
|
22
|
-
}
|
|
23
|
-
declare class BooleanValidator extends FieldValidator {
|
|
24
|
-
constructor(message: string);
|
|
25
|
-
required(message: string): this;
|
|
26
|
-
}
|
|
27
|
-
declare class DateValidator extends FieldValidator {
|
|
28
|
-
constructor(message: string);
|
|
29
|
-
required(message: string): this;
|
|
30
|
-
}
|
|
31
|
-
declare class JsonValidator extends FieldValidator {
|
|
32
|
-
private children?;
|
|
33
|
-
constructor(children?: Record<string, FieldValidator> | undefined);
|
|
34
|
-
validate(value: any, context: object): string[];
|
|
35
|
-
}
|
|
36
|
-
export declare class ValidationBuilder {
|
|
37
|
-
string(message: string): StringValidator;
|
|
38
|
-
number(message: string): NumberValidator;
|
|
39
|
-
boolean(message: string): BooleanValidator;
|
|
40
|
-
date(message: string): DateValidator;
|
|
41
|
-
json(model: Record<string, FieldValidator>): JsonValidator;
|
|
42
|
-
}
|
|
43
|
-
export declare const f: () => ValidationBuilder;
|
|
44
|
-
export {};
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.f = exports.ValidationBuilder = exports.FieldValidator = void 0;
|
|
4
|
-
class FieldValidator {
|
|
5
|
-
constructor() {
|
|
6
|
-
this._type = null;
|
|
7
|
-
this._cases = [];
|
|
8
|
-
this._default = undefined;
|
|
9
|
-
}
|
|
10
|
-
get type() {
|
|
11
|
-
return this._type;
|
|
12
|
-
}
|
|
13
|
-
get defaultValue() {
|
|
14
|
-
return this._default;
|
|
15
|
-
}
|
|
16
|
-
default(value) {
|
|
17
|
-
this._default = value;
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
when(test) {
|
|
21
|
-
this._cases.push(test);
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
validate(value, context) {
|
|
25
|
-
return this._cases.map((fn) => fn(value, context)).filter((res) => res !== null);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.FieldValidator = FieldValidator;
|
|
29
|
-
class NumberValidator extends FieldValidator {
|
|
30
|
-
constructor(message) {
|
|
31
|
-
super();
|
|
32
|
-
this._type = 'number';
|
|
33
|
-
this._cases.push((value) => (value === null || value === undefined ? null : typeof value !== 'number' ? message : null));
|
|
34
|
-
}
|
|
35
|
-
required(message) {
|
|
36
|
-
this._cases.push((value) => (value === undefined || value === null || String(value).trim() === '' ? message : null));
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
min(min, message) {
|
|
40
|
-
this._cases.push((value) => (typeof value === 'number' && value < min ? message : null));
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
max(max, message) {
|
|
44
|
-
this._cases.push((value) => (typeof value === 'number' && value > max ? message : null));
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
class StringValidator extends FieldValidator {
|
|
49
|
-
constructor(message) {
|
|
50
|
-
super();
|
|
51
|
-
this._type = 'string';
|
|
52
|
-
this._cases.push((value) => (value === null || value === undefined ? null : typeof value !== 'string' ? message : null));
|
|
53
|
-
}
|
|
54
|
-
required(message) {
|
|
55
|
-
this._cases.push((value) => (!value || String(value).trim() === '' ? message : null));
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
match(regex, message) {
|
|
59
|
-
this._cases.push((value) => (value === null || value === undefined ? null : !regex.test(String(value)) ? message : null));
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
class BooleanValidator extends FieldValidator {
|
|
64
|
-
constructor(message) {
|
|
65
|
-
super();
|
|
66
|
-
this._type = 'boolean';
|
|
67
|
-
this._cases.push((value) => (value === null || value === undefined ? null : typeof value !== 'boolean' ? message : null));
|
|
68
|
-
}
|
|
69
|
-
required(message) {
|
|
70
|
-
this._cases.push((value) => (typeof value !== 'boolean' ? message : null));
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
class DateValidator extends FieldValidator {
|
|
75
|
-
constructor(message) {
|
|
76
|
-
super();
|
|
77
|
-
this._type = 'date';
|
|
78
|
-
this._cases.push((value) => {
|
|
79
|
-
if (value === null || value === undefined)
|
|
80
|
-
return null;
|
|
81
|
-
const d = new Date(value);
|
|
82
|
-
return isNaN(d.getTime()) ? message : null;
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
required(message) {
|
|
86
|
-
return this.when((value) => (!value ? message : null));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
class JsonValidator extends FieldValidator {
|
|
90
|
-
constructor(children) {
|
|
91
|
-
super();
|
|
92
|
-
this.children = children;
|
|
93
|
-
this._type = 'jsonb';
|
|
94
|
-
}
|
|
95
|
-
validate(value, context) {
|
|
96
|
-
if (typeof value !== 'object' || value === null) {
|
|
97
|
-
return ['Must be a valid JSON object.'];
|
|
98
|
-
}
|
|
99
|
-
if (!this.children)
|
|
100
|
-
return [];
|
|
101
|
-
const errors = [];
|
|
102
|
-
for (const [key, validator] of Object.entries(this.children)) {
|
|
103
|
-
const childErrors = validator.validate(value[key], context);
|
|
104
|
-
errors.push(...childErrors.map((e) => `${key}: ${e}`));
|
|
105
|
-
}
|
|
106
|
-
return errors;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
class ValidationBuilder {
|
|
110
|
-
string(message) {
|
|
111
|
-
return new StringValidator(message);
|
|
112
|
-
}
|
|
113
|
-
number(message) {
|
|
114
|
-
return new NumberValidator(message);
|
|
115
|
-
}
|
|
116
|
-
boolean(message) {
|
|
117
|
-
return new BooleanValidator(message);
|
|
118
|
-
}
|
|
119
|
-
date(message) {
|
|
120
|
-
return new DateValidator(message);
|
|
121
|
-
}
|
|
122
|
-
json(model) {
|
|
123
|
-
return new JsonValidator(model);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
exports.ValidationBuilder = ValidationBuilder;
|
|
127
|
-
const f = () => new ValidationBuilder();
|
|
128
|
-
exports.f = f;
|
package/lib/cjs/package.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Especialized storage for Opposer Core Context.
|
|
3
|
-
* Uses GlobalStorage internally but provides a clean Singleton interface
|
|
4
|
-
* for the server engine and public consumption.
|
|
5
|
-
*/
|
|
6
|
-
declare class ContextStorage {
|
|
7
|
-
private static instance;
|
|
8
|
-
private readonly namespace;
|
|
9
|
-
private constructor();
|
|
10
|
-
static getInstance(): ContextStorage;
|
|
11
|
-
set<T>(key: string, value: T): void;
|
|
12
|
-
get<T>(key: string): T;
|
|
13
|
-
has(key: string): boolean;
|
|
14
|
-
clear(): void;
|
|
15
|
-
}
|
|
16
|
-
declare const _default: ContextStorage;
|
|
17
|
-
export default _default;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const global_js_1 = __importDefault(require("../cache/global.js"));
|
|
7
|
-
/**
|
|
8
|
-
* Especialized storage for Opposer Core Context.
|
|
9
|
-
* Uses GlobalStorage internally but provides a clean Singleton interface
|
|
10
|
-
* for the server engine and public consumption.
|
|
11
|
-
*/
|
|
12
|
-
class ContextStorage {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.namespace = "opposer:core:context";
|
|
15
|
-
}
|
|
16
|
-
static getInstance() {
|
|
17
|
-
if (!ContextStorage.instance) {
|
|
18
|
-
ContextStorage.instance = new ContextStorage();
|
|
19
|
-
}
|
|
20
|
-
return ContextStorage.instance;
|
|
21
|
-
}
|
|
22
|
-
set(key, value) {
|
|
23
|
-
const data = global_js_1.default.get(this.namespace) || {};
|
|
24
|
-
data[key] = value;
|
|
25
|
-
global_js_1.default.set(this.namespace, data);
|
|
26
|
-
}
|
|
27
|
-
get(key) {
|
|
28
|
-
const data = global_js_1.default.get(this.namespace) || {};
|
|
29
|
-
return data[key];
|
|
30
|
-
}
|
|
31
|
-
has(key) {
|
|
32
|
-
const data = global_js_1.default.get(this.namespace) || {};
|
|
33
|
-
return Object.prototype.hasOwnProperty.call(data, key);
|
|
34
|
-
}
|
|
35
|
-
clear() {
|
|
36
|
-
global_js_1.default.set(this.namespace, {});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.default = ContextStorage.getInstance();
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { CacheSettings } from "../interfaces/system.js";
|
|
2
|
-
import Store from "./store.js";
|
|
3
|
-
declare const _default: {
|
|
4
|
-
__settings: CacheSettings;
|
|
5
|
-
__data: Store;
|
|
6
|
-
set(key: string, value: any): void;
|
|
7
|
-
get(key: string): any;
|
|
8
|
-
__isMaxSizeMemory: boolean;
|
|
9
|
-
__currentSizeMemory: number;
|
|
10
|
-
snapshot(): void;
|
|
11
|
-
restore(): void;
|
|
12
|
-
size(): boolean;
|
|
13
|
-
revalidate(): void | null;
|
|
14
|
-
notifyStoresForClearMemoryPerPolicy(): void;
|
|
15
|
-
clear(): void;
|
|
16
|
-
configure(): /*elided*/ any;
|
|
17
|
-
};
|
|
18
|
-
export default _default;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const index_js_1 = __importDefault(require("../system/index.js"));
|
|
7
|
-
const storage_js_1 = __importDefault(require("./storage.js"));
|
|
8
|
-
const store_js_1 = __importDefault(require("./store.js"));
|
|
9
|
-
exports.default = new (class Global extends storage_js_1.default {
|
|
10
|
-
constructor() {
|
|
11
|
-
super();
|
|
12
|
-
this.__settings = index_js_1.default.settings.cache.global;
|
|
13
|
-
this.__data = new store_js_1.default();
|
|
14
|
-
this.__data.setSettings(index_js_1.default.settings.cache.global);
|
|
15
|
-
}
|
|
16
|
-
set(key, value) {
|
|
17
|
-
this.__data.set(key, value);
|
|
18
|
-
}
|
|
19
|
-
get(key) {
|
|
20
|
-
return this.__data.get(key);
|
|
21
|
-
}
|
|
22
|
-
})().configure();
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Store = exports.GlobalStorage = exports.SessionStorage = void 0;
|
|
7
|
-
var session_1 = require("./session");
|
|
8
|
-
Object.defineProperty(exports, "SessionStorage", { enumerable: true, get: function () { return __importDefault(session_1).default; } });
|
|
9
|
-
var global_1 = require("./global");
|
|
10
|
-
Object.defineProperty(exports, "GlobalStorage", { enumerable: true, get: function () { return __importDefault(global_1).default; } });
|
|
11
|
-
var store_1 = require("./store");
|
|
12
|
-
Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return __importDefault(store_1).default; } });
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Request, Response, NextFunction } from "express";
|
|
2
|
-
import Store from "./store.js";
|
|
3
|
-
declare const _default: {
|
|
4
|
-
createStore(sessionId: string): Store;
|
|
5
|
-
loadStore(sessionId: string): Store | null;
|
|
6
|
-
initialize(req: Request, res: Response, next: NextFunction): Response<any, Record<string, any>> | undefined;
|
|
7
|
-
__settings: import("../interfaces/system.js").CacheSettings;
|
|
8
|
-
__data: Record<string, any>;
|
|
9
|
-
__isMaxSizeMemory: boolean;
|
|
10
|
-
__currentSizeMemory: number;
|
|
11
|
-
snapshot(): void;
|
|
12
|
-
restore(): void;
|
|
13
|
-
size(): boolean;
|
|
14
|
-
revalidate(): void | null;
|
|
15
|
-
notifyStoresForClearMemoryPerPolicy(): void;
|
|
16
|
-
clear(): void;
|
|
17
|
-
configure(): /*elided*/ any;
|
|
18
|
-
};
|
|
19
|
-
export default _default;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const index_js_1 = __importDefault(require("../context/index.js"));
|
|
7
|
-
const storage_js_1 = __importDefault(require("./storage.js"));
|
|
8
|
-
const store_js_1 = __importDefault(require("./store.js"));
|
|
9
|
-
exports.default = new (class Session extends storage_js_1.default {
|
|
10
|
-
createStore(sessionId) {
|
|
11
|
-
const store = new store_js_1.default(sessionId);
|
|
12
|
-
Object.defineProperty(this.__data, sessionId, {
|
|
13
|
-
value: store,
|
|
14
|
-
writable: true,
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
});
|
|
18
|
-
return store;
|
|
19
|
-
}
|
|
20
|
-
loadStore(sessionId) {
|
|
21
|
-
const store = this.__data[sessionId];
|
|
22
|
-
if (!store) {
|
|
23
|
-
if (this.__isMaxSizeMemory) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
return this.createStore(sessionId);
|
|
27
|
-
}
|
|
28
|
-
store.revalidateTimer();
|
|
29
|
-
return store;
|
|
30
|
-
}
|
|
31
|
-
initialize(req, res, next) {
|
|
32
|
-
const sessionId = req.headers["session-opposer-id"];
|
|
33
|
-
const store = this.loadStore(sessionId);
|
|
34
|
-
if (!sessionId) {
|
|
35
|
-
return res.status(401);
|
|
36
|
-
}
|
|
37
|
-
index_js_1.default.run({ store, sessionId }, next);
|
|
38
|
-
}
|
|
39
|
-
})().configure();
|