@servicelabsco/nestjs-utility-services 3.0.8 → 3.0.9
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/CHANGELOG.md +85 -0
- package/dist/auth/es6.classes.d.ts +4 -2
- package/dist/auth/es6.classes.js +2 -0
- package/dist/auth/es6.classes.js.map +1 -1
- package/dist/common/decorators/cache.method.decorator.d.ts +11 -0
- package/dist/common/decorators/cache.method.decorator.js +37 -0
- package/dist/common/decorators/cache.method.decorator.js.map +1 -0
- package/dist/common/decorators/index.d.ts +3 -0
- package/dist/common/decorators/index.js +3 -0
- package/dist/common/decorators/index.js.map +1 -1
- package/dist/common/decorators/when.column.updated.decorator.d.ts +8 -0
- package/dist/common/decorators/when.column.updated.decorator.js +22 -0
- package/dist/common/decorators/when.column.updated.decorator.js.map +1 -0
- package/dist/common/decorators/when.new.record.decorator.d.ts +5 -0
- package/dist/common/decorators/when.new.record.decorator.js +19 -0
- package/dist/common/decorators/when.new.record.decorator.js.map +1 -0
- package/dist/common/es6.classes.d.ts +8 -1
- package/dist/common/es6.classes.js +9 -1
- package/dist/common/es6.classes.js.map +1 -1
- package/dist/common/interfaces/index.d.ts +2 -0
- package/dist/common/interfaces/index.js +2 -0
- package/dist/common/interfaces/index.js.map +1 -1
- package/dist/common/interfaces/method.cache.interface.d.ts +4 -0
- package/dist/common/interfaces/method.cache.interface.js +3 -0
- package/dist/common/interfaces/method.cache.interface.js.map +1 -0
- package/dist/common/interfaces/updated.column.interface.d.ts +7 -0
- package/dist/common/interfaces/updated.column.interface.js +3 -0
- package/dist/common/interfaces/updated.column.interface.js.map +1 -0
- package/dist/common/libraries/common.subscriber.d.ts +15 -4
- package/dist/common/libraries/common.subscriber.js +133 -32
- package/dist/common/libraries/common.subscriber.js.map +1 -1
- package/dist/platformUtility/es6.classes.d.ts +2 -3
- package/dist/platformUtility/es6.classes.js +0 -2
- package/dist/platformUtility/es6.classes.js.map +1 -1
- package/dist/platformUtility/services/cache.service.js +2 -0
- package/dist/platformUtility/services/cache.service.js.map +1 -1
- package/dist/platformUtility/services/local.property.service.d.ts +0 -1
- package/dist/platformUtility/services/local.property.service.js +1 -10
- package/dist/platformUtility/services/local.property.service.js.map +1 -1
- package/dist/security/es6.classes.d.ts +4 -0
- package/dist/security/es6.classes.js +4 -0
- package/dist/security/es6.classes.js.map +1 -1
- package/dist/system/es6.classes.d.ts +4 -5
- package/dist/system/es6.classes.js +0 -2
- package/dist/system/es6.classes.js.map +1 -1
- package/dist/system/jobs/client.credential.job.js +15 -4
- package/dist/system/jobs/client.credential.job.js.map +1 -1
- package/package.json +1 -1
- package/dist/config/entity.constants.d.ts +0 -171
- package/dist/config/entity.constants.js +0 -173
- package/dist/config/entity.constants.js.map +0 -1
- package/dist/platformUtility/services/es6.jobs.service.d.ts +0 -18
- package/dist/platformUtility/services/es6.jobs.service.js +0 -57
- package/dist/platformUtility/services/es6.jobs.service.js.map +0 -1
- package/dist/system/services/es6.jobs.service.d.ts +0 -62
- package/dist/system/services/es6.jobs.service.js +0 -145
- package/dist/system/services/es6.jobs.service.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,90 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.0.9
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **`@CacheMethod()` — cache an async method's result through `CacheService` in one line.**
|
|
8
|
+
Replaces the hand-written get → miss → load → set block:
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
@CacheMethod({ key: (identifier: string) => `inbound.webhook.${identifier}.key`, ttlMinutes: 10 })
|
|
12
|
+
protected async identifyWebhook(identifier: string): Promise<InboundWebhookEntity | null> {
|
|
13
|
+
return InboundWebhookEntity.findOne({ where: { identifier } });
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- hit → the cached value is returned without running the method (`0` / `false` / `''` count
|
|
18
|
+
as hits); an optional `hydrate: (raw) => MyEntity.create(raw)` restores class instances,
|
|
19
|
+
since cached values round-trip through JSON;
|
|
20
|
+
- miss → the method runs and a non-null result is cached for `ttlMinutes`; `null` /
|
|
21
|
+
`undefined` is not cached;
|
|
22
|
+
- `key` receives the method's arguments (type-checked against them) with `this` bound to the
|
|
23
|
+
instance; keys are the same strings `CacheService.get/set/delete` take, so existing
|
|
24
|
+
hand-written caches keep their entries and `cacheService.delete(key)` evicts;
|
|
25
|
+
- `CacheService` installs itself as the store (`CacheMethod.useCache(this)`), so the decorator
|
|
26
|
+
works on DI services and plain `new`-ed library classes alike. Without it (unit tests, apps
|
|
27
|
+
without `CacheService`) the method runs uncached; a failed cache write is logged and the
|
|
28
|
+
fresh result returned.
|
|
29
|
+
|
|
30
|
+
- **`@WhenColumnUpdated()` — the `isColumnUpdated` guard of a `CommonJob` database-event
|
|
31
|
+
handler as a decorator.**
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
@WhenColumnUpdated(['active', 'deleted_at'])
|
|
35
|
+
async refreshCacheKey(evt: DatabaseEventDto<ClientCredentialEntity>) {
|
|
36
|
+
await this.clientCredentialService.setCredentialCache(evt.entity.identifier);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- runs for inserts and for updates touching any listed column (exactly `isColumnUpdated`);
|
|
41
|
+
otherwise skipped, resolving to `undefined`; all arguments are forwarded;
|
|
42
|
+
- compile-time checked: only on `CommonJob` methods whose first parameter is a
|
|
43
|
+
`DatabaseEventDto<Entity>`, and every column must be a property of `Entity` (a typo fails
|
|
44
|
+
with `unknownColumns: "<name>"`); the `CommonJob` requirement is also enforced at class
|
|
45
|
+
definition.
|
|
46
|
+
- `ClientCredentialJob.refreshCacheKey` uses it.
|
|
47
|
+
|
|
48
|
+
- **`@WhenNewRecord()` — the `isNewRecord` guard as a decorator.** The method runs only for a
|
|
49
|
+
newly created record (no / empty `databaseEntity`); updates resolve to `undefined`. Same
|
|
50
|
+
compile-time and class-definition checks as `@WhenColumnUpdated()` (`CommonJob` methods,
|
|
51
|
+
first parameter a `DatabaseEventDto`). `ClientCredentialJob.setKey` uses it.
|
|
52
|
+
|
|
53
|
+
### Changed
|
|
54
|
+
|
|
55
|
+
- **nu no longer ships generated registry files.** `LocalPropertyService` stops registering entities
|
|
56
|
+
from `config/entity.constants.ts`, and that file plus `platformUtility/` and
|
|
57
|
+
`system/services/es6.jobs.service.ts` (`Es6JobsService`) are gone: `PlatformRegistryService`
|
|
58
|
+
(3.0.8) derives the same entity and job hashes from TypeORM metadata and the Nest container.
|
|
59
|
+
`PlatformUtility.getEntity` / `getJob` / `getService` and `setEntities` / `setJobs` /
|
|
60
|
+
`setServices` are unchanged, so consumers that still register explicitly keep working.
|
|
61
|
+
- Generated with `@servicelabsco/slabs-dev-cli` ≥ 1.0.14, which stops emitting these files for any
|
|
62
|
+
repo on nu ≥ 3.0.8 and always emits the core `controllers` / `entities` / `jobs` / `services` /
|
|
63
|
+
`subscribers` keys in `es6.classes.ts`.
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
|
|
67
|
+
- **`CommonSubscriber` no longer reports equal-but-differently-typed values as updated columns.**
|
|
68
|
+
TypeORM's `updatedColumns` normalises timestamps and json but compares everything else with
|
|
69
|
+
`===`; the re-check now compares by column type, reading the `ColumnMetadata` TypeORM passes
|
|
70
|
+
(no per-column `findColumnWithPropertyName` scan or `type.toString()`):
|
|
71
|
+
- decimals (`float`, `numeric`, `decimal`, `real`, ...) by value, rounded to `scale` when set —
|
|
72
|
+
`'12.50'` vs `12.5`, float noise below the scale; a `float` without a scale compared exactly
|
|
73
|
+
(previously `10 ** undefined` = `NaN`, so it was never normalised);
|
|
74
|
+
- integers (`Number`, `int`, `bigint`, ...) by value, BigInt-safe — `'5'` vs `5`, pg `bigint`
|
|
75
|
+
strings;
|
|
76
|
+
- booleans by the literals Postgres accepts — `'false'` / `'f'` / `0` vs `false`, `'yes'` / `1`
|
|
77
|
+
vs `true` (previously `'false'` counted as changed); an unrecognised value stays changed;
|
|
78
|
+
- `date` columns by calendar date — an ISO string or `Date` vs the stored `YYYY-MM-DD`.
|
|
79
|
+
|
|
80
|
+
Backward compatible: `float`, `Number` and `Boolean` columns (the types normalised before) keep
|
|
81
|
+
the `value || 0` / `value || false` rule exactly (`null` / `''` / `NaN` equal `0` / `false`);
|
|
82
|
+
newly normalised types treat `null` as distinct, and exact types beyond double precision are
|
|
83
|
+
compared as text. A differential run of old vs new over 3,336 value pairs across every column
|
|
84
|
+
type found no case where a column the old code treated as unchanged is now reported; every
|
|
85
|
+
difference is an equal value in another form. Any other column TypeORM reports (text,
|
|
86
|
+
timestamps, json, ...) is kept as before.
|
|
87
|
+
|
|
3
88
|
## 3.0.8
|
|
4
89
|
|
|
5
90
|
### Changed
|
|
@@ -30,10 +30,12 @@ import { SocialService } from './services/social.service';
|
|
|
30
30
|
import { UserService } from './services/user.service';
|
|
31
31
|
declare const es6Classes: {
|
|
32
32
|
controllers: (typeof AdminAuthController | typeof SocialController | typeof UserController)[];
|
|
33
|
-
dtos: (typeof UserRolesAccessObjectDto | typeof
|
|
34
|
-
entities: (typeof CreatorEntity | typeof
|
|
33
|
+
dtos: (typeof UserRolesAccessObjectDto | typeof PermissionAssignmentDto | typeof RoleAssignmentDto | typeof UserLoginDto | typeof SessionIdentifierAttributesDto | typeof CreateUserDto | typeof OfflineUserDto | typeof UpdateUserDto)[];
|
|
34
|
+
entities: (typeof CreatorEntity | typeof UserReferralEntity | typeof DeviceTokenEntity | typeof RefreshTokenEntity | typeof SessionIdentifierEntity | typeof SocialIdentityEntity | typeof CountryEntity)[];
|
|
35
35
|
interfaces: any[];
|
|
36
|
+
jobs: any[];
|
|
36
37
|
middlewares: (typeof BasicAuthMiddleware | typeof ClientConnectMiddleware | typeof InternalMiddleware | typeof JwtMiddleware | typeof RestrictedMiddleware)[];
|
|
37
38
|
services: (typeof AccessService | typeof RefreshTokenService | typeof UserService | typeof AuthService | typeof DeviceTokenService | typeof SocialIdentityService | typeof SocialService)[];
|
|
39
|
+
subscribers: any[];
|
|
38
40
|
};
|
|
39
41
|
export default es6Classes;
|
package/dist/auth/es6.classes.js
CHANGED
|
@@ -58,8 +58,10 @@ const es6Classes = {
|
|
|
58
58
|
user_referral_entity_1.UserReferralEntity,
|
|
59
59
|
],
|
|
60
60
|
interfaces: [],
|
|
61
|
+
jobs: [],
|
|
61
62
|
middlewares: [basic_auth_middleware_1.BasicAuthMiddleware, client_connect_middleware_1.ClientConnectMiddleware, internal_middleware_1.InternalMiddleware, jwt_middleware_1.JwtMiddleware, restricted_middleware_1.RestrictedMiddleware],
|
|
62
63
|
services: [access_service_1.AccessService, auth_service_1.AuthService, device_token_service_1.DeviceTokenService, refresh_token_service_1.RefreshTokenService, social_identity_service_1.SocialIdentityService, social_service_1.SocialService, user_service_1.UserService],
|
|
64
|
+
subscribers: [],
|
|
63
65
|
};
|
|
64
66
|
exports.default = es6Classes;
|
|
65
67
|
//# sourceMappingURL=es6.classes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"es6.classes.js","sourceRoot":"","sources":["../../src/auth/es6.classes.ts"],"names":[],"mappings":";;AAAA,+EAA0E;AAC1E,uEAAmE;AACnE,mEAA+D;AAC/D,4DAAuD;AACvD,8DAAyD;AACzD,gFAA2E;AAC3E,oEAA+D;AAC/D,gGAA0F;AAC1F,4DAAuD;AACvD,4DAAuD;AACvD,oEAA+D;AAC/D,0DAAqD;AACrD,sFAA+E;AAC/E,8DAA0D;AAC1D,8DAA0D;AAC1D,wEAAmE;AACnE,0EAAqE;AACrE,oFAA+E;AAC/E,8EAAyE;AACzE,wDAAoD;AACpD,0EAAqE;AACrE,+EAA0E;AAC1E,uFAAkF;AAClF,2EAAuE;AACvE,iEAA6D;AAC7D,+EAA2E;AAC3E,8DAA0D;AAC1D,0DAAsD;AACtD,0EAAqE;AACrE,4EAAuE;AACvE,gFAA2E;AAC3E,8DAA0D;AAC1D,0DAAsD;AAEtD,MA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CAAC,2CAAmB,EAAE,oCAAgB,EAAE,gCAAc,CAAC;IACpE,IAAI,EAAE;QACF,+BAAa;QACb,iCAAc;QACd,mDAAuB;QACvB,uCAAiB;QACjB,kEAA8B;QAC9B,+BAAa;QACb,+BAAa;QACb,uCAAiB;QACjB,6BAAY;QACZ,uDAAwB;KAC3B;IACD,QAAQ,EAAE;QACN,8BAAa;QACb,8BAAa;QACb,uCAAiB;QACjB,yCAAkB;QAClB,mDAAuB;QACvB,6CAAoB;QACpB,wBAAU;QACV,yCAAkB;KACrB;IACD,UAAU,EAAE,EAAE;IACd,IAAI,EAAE,EAAE;IACR,WAAW,EAAE,CAAC,2CAAmB,EAAE,mDAAuB,EAAE,wCAAkB,EAAE,8BAAa,EAAE,4CAAoB,CAAC;IACpH,QAAQ,EAAE,CAAC,8BAAa,EAAE,0BAAW,EAAE,yCAAkB,EAAE,2CAAmB,EAAE,+CAAqB,EAAE,8BAAa,EAAE,0BAAW,CAAC;IAClI,WAAW,EAAE,EAAE;CAClB,CAAC;AAEF,kBAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MethodCacheInterface } from '../interfaces/method.cache.interface';
|
|
2
|
+
export interface CacheMethodOptions<A extends any[] = any[], R = any> {
|
|
3
|
+
key: (this: any, ...args: A) => string;
|
|
4
|
+
ttlMinutes: number;
|
|
5
|
+
hydrate?: (raw: any) => R;
|
|
6
|
+
}
|
|
7
|
+
export declare function CacheMethod<A extends any[], R>(options: CacheMethodOptions<A, R>): (_target: object, _propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<(...args: A) => Promise<R>>) => TypedPropertyDescriptor<(...args: A) => Promise<R>>;
|
|
8
|
+
export declare namespace CacheMethod {
|
|
9
|
+
var useCache: (cache?: MethodCacheInterface) => void;
|
|
10
|
+
}
|
|
11
|
+
export { CacheMethod as CacheMethodDecorator };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CacheMethod = CacheMethod;
|
|
4
|
+
exports.CacheMethodDecorator = CacheMethod;
|
|
5
|
+
const custom_logger_1 = require("../libraries/custom.logger");
|
|
6
|
+
let store;
|
|
7
|
+
function CacheMethod(options) {
|
|
8
|
+
if (!(options.ttlMinutes > 0))
|
|
9
|
+
throw new Error(`@CacheMethod: ttlMinutes must be > 0, got ${options.ttlMinutes}`);
|
|
10
|
+
return (_target, _propertyKey, descriptor) => {
|
|
11
|
+
const original = descriptor.value;
|
|
12
|
+
descriptor.value = async function (...args) {
|
|
13
|
+
const cache = store;
|
|
14
|
+
if (!cache)
|
|
15
|
+
return original.apply(this, args);
|
|
16
|
+
const key = options.key.apply(this, args);
|
|
17
|
+
const cached = await cache.get(key, null);
|
|
18
|
+
if (cached !== null && cached !== undefined)
|
|
19
|
+
return options.hydrate ? options.hydrate(cached) : cached;
|
|
20
|
+
const result = await original.apply(this, args);
|
|
21
|
+
if (result === null || result === undefined)
|
|
22
|
+
return result;
|
|
23
|
+
try {
|
|
24
|
+
await cache.set(key, result, new Date(Date.now() + options.ttlMinutes * 60_000));
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
custom_logger_1.CustomLogger.error(`@CacheMethod: caching failed for key=${key}; returning uncached result`, error);
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
return descriptor;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
CacheMethod.useCache = (cache) => {
|
|
35
|
+
store = cache;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=cache.method.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.method.decorator.js","sourceRoot":"","sources":["../../../src/common/decorators/cache.method.decorator.ts"],"names":[],"mappings":";;AAqDA,kCAiCC;AAauB,2CAAoB;AAnG5C,8DAA0D;AAuB1D,IAAI,KAAuC,CAAC;AA8B5C,SAAgB,WAA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,EAAE,KAAK,CAAC,CAAC;YACxG,CAAC;YAED,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC;AAQD,WAAW,CAAC,QAAQ,GAAG,CAAC,KAA4B,EAAQ,EAAE;IAC1D,KAAK,GAAG,KAAK,CAAC;AAClB,CAAC,CAAC"}
|
|
@@ -14,5 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cache.method.decorator"), exports);
|
|
17
18
|
__exportStar(require("./public.exposed.decorator"), exports);
|
|
19
|
+
__exportStar(require("./when.column.updated.decorator"), exports);
|
|
20
|
+
__exportStar(require("./when.new.record.decorator"), exports);
|
|
18
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AAAA,6DAA2C;AAAA,kEAAgD;AAAA,8DAA2C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DatabaseEventDto } from '../dtos/database.event.dto';
|
|
2
|
+
import { CommonJob } from '../libraries/common.job';
|
|
3
|
+
type DatabaseEventMethod<E> = (evt: DatabaseEventDto<E>, ...rest: any[]) => Promise<any>;
|
|
4
|
+
type KnownColumns<E, C extends string> = [Exclude<C, keyof E>] extends [never] ? unknown : {
|
|
5
|
+
unknownColumns: Exclude<C, keyof E>;
|
|
6
|
+
};
|
|
7
|
+
export declare function WhenColumnUpdated<C extends string>(columns: C | C[]): <E>(target: CommonJob, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<DatabaseEventMethod<E>> & KnownColumns<E, C>) => void;
|
|
8
|
+
export { WhenColumnUpdated as WhenColumnUpdatedDecorator };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhenColumnUpdated = WhenColumnUpdated;
|
|
4
|
+
exports.WhenColumnUpdatedDecorator = WhenColumnUpdated;
|
|
5
|
+
const common_job_1 = require("../libraries/common.job");
|
|
6
|
+
function WhenColumnUpdated(columns) {
|
|
7
|
+
const list = Array.isArray(columns) ? columns : [columns];
|
|
8
|
+
if (!list.length)
|
|
9
|
+
throw new Error('@WhenColumnUpdated: pass at least one column');
|
|
10
|
+
return (target, propertyKey, descriptor) => {
|
|
11
|
+
if (!(target instanceof common_job_1.CommonJob)) {
|
|
12
|
+
throw new Error(`@WhenColumnUpdated: ${String(propertyKey)} must be a method of a CommonJob subclass`);
|
|
13
|
+
}
|
|
14
|
+
const original = descriptor.value;
|
|
15
|
+
descriptor.value = async function (evt, ...rest) {
|
|
16
|
+
if (!this['isColumnUpdated'](evt, list))
|
|
17
|
+
return undefined;
|
|
18
|
+
return original.apply(this, [evt, ...rest]);
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=when.column.updated.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when.column.updated.decorator.js","sourceRoot":"","sources":["../../../src/common/decorators/when.column.updated.decorator.ts"],"names":[],"mappings":";;AAuCA,8CAqBC;AAG6B,uDAA0B;AA9DxD,wDAAoD;AAsCpD,SAAgB,iBAAiB,CAAmB,OAAgB;IAChE,MAAM,IAAI,GAAa,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IACpE,IAAI,CAAC,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAElF,OAAO,CACH,MAAiB,EACjB,WAA4B,EAC5B,UAAgF,EAC5E,EAAE;QACN,IAAI,CAAC,CAAC,MAAM,YAAY,sBAAS,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,uBAAuB,MAAM,CAAC,WAAW,CAAC,2CAA2C,CAAC,CAAC;QAC3G,CAAC;QAED,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC;QAElC,UAAU,CAAC,KAAK,GAAG,KAAK,WAA4B,GAAwB,EAAE,GAAG,IAAW;YACxF,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC;gBAAE,OAAO,SAAS,CAAC;YAE1D,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;QAChD,CAAC,CAAC;IACN,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DatabaseEventDto } from '../dtos/database.event.dto';
|
|
2
|
+
import { CommonJob } from '../libraries/common.job';
|
|
3
|
+
type DatabaseEventMethod<E> = (evt: DatabaseEventDto<E>, ...rest: any[]) => Promise<any>;
|
|
4
|
+
export declare function WhenNewRecord(): <E>(target: CommonJob, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<DatabaseEventMethod<E>>) => void;
|
|
5
|
+
export { WhenNewRecord as WhenNewRecordDecorator };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhenNewRecord = WhenNewRecord;
|
|
4
|
+
exports.WhenNewRecordDecorator = WhenNewRecord;
|
|
5
|
+
const common_job_1 = require("../libraries/common.job");
|
|
6
|
+
function WhenNewRecord() {
|
|
7
|
+
return (target, propertyKey, descriptor) => {
|
|
8
|
+
if (!(target instanceof common_job_1.CommonJob)) {
|
|
9
|
+
throw new Error(`@WhenNewRecord: ${String(propertyKey)} must be a method of a CommonJob subclass`);
|
|
10
|
+
}
|
|
11
|
+
const original = descriptor.value;
|
|
12
|
+
descriptor.value = async function (evt, ...rest) {
|
|
13
|
+
if (!this['isNewRecord'](evt))
|
|
14
|
+
return undefined;
|
|
15
|
+
return original.apply(this, [evt, ...rest]);
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=when.new.record.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when.new.record.decorator.js","sourceRoot":"","sources":["../../../src/common/decorators/when.new.record.decorator.ts"],"names":[],"mappings":";;AA6BA,sCAcC;AAGyB,+CAAsB;AA7ChD,wDAAoD;AA4BpD,SAAgB,aAAa;IACzB,OAAO,CAAI,MAAiB,EAAE,WAA4B,EAAE,UAA2D,EAAQ,EAAE;QAC7H,IAAI,CAAC,CAAC,MAAM,YAAY,sBAAS,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,CAAC,WAAW,CAAC,2CAA2C,CAAC,CAAC;QACvG,CAAC;QAED,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC;QAElC,UAAU,CAAC,KAAK,GAAG,KAAK,WAA4B,GAAwB,EAAE,GAAG,IAAW;YACxF,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC;gBAAE,OAAO,SAAS,CAAC;YAEhD,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;QAChD,CAAC,CAAC;IACN,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { RedisIoAdapter } from './adapters/redis.io.adapter';
|
|
2
|
+
import { CacheMethodDecorator } from './decorators/cache.method.decorator';
|
|
2
3
|
import { PublicExposedDecorator } from './decorators/public.exposed.decorator';
|
|
4
|
+
import { WhenColumnUpdatedDecorator } from './decorators/when.column.updated.decorator';
|
|
3
5
|
import { AggregationParamDto } from './dtos/aggregation.param.dto';
|
|
4
6
|
import { CaptureRecordIndexDto } from './dtos/capture.record.index.dto';
|
|
5
7
|
import { CaptureRecordShowDto } from './dtos/capture.record.show.dto';
|
|
@@ -43,10 +45,13 @@ declare const es6Classes: {
|
|
|
43
45
|
DEFAULT_ADMIN: number;
|
|
44
46
|
INTERNAL: number;
|
|
45
47
|
})[];
|
|
46
|
-
|
|
48
|
+
controllers: any[];
|
|
49
|
+
decorators: (typeof CacheMethodDecorator | typeof PublicExposedDecorator | typeof WhenColumnUpdatedDecorator)[];
|
|
47
50
|
dtos: (typeof MetaDataDto | typeof DatabaseEventDto | typeof LayoutColumnDbDto | typeof GenericIndexParamDto | typeof RecordDataManagerDto | typeof RecordTabDto | typeof AggregationParamDto | typeof GroupParamDto | typeof ReportBodyDto | typeof ReportDataManagerDto | typeof CaptureRecordIndexDto | typeof CaptureRecordShowDto | typeof ForeignMigrationDto | typeof GenericShowParamDto | typeof IndexColumnDto | typeof JsonFieldConditionDto | typeof KeyValueParamDto | typeof RenameColumnDto)[];
|
|
51
|
+
entities: any[];
|
|
48
52
|
exceptions: (typeof NoLoggedUserException)[];
|
|
49
53
|
interfaces: any[];
|
|
54
|
+
jobs: any[];
|
|
50
55
|
libraries: (typeof CommonJob | typeof CachedProperty | typeof GenericIndexParser | typeof GenericShowParser | typeof DataManager | typeof ListManager | typeof RecordManager | typeof ReportDataManager | typeof ReportListManager | {
|
|
51
56
|
register(entity: new (...args: any[]) => any, job: new (...args: any[]) => any): void;
|
|
52
57
|
jobsFor(entity: new (...args: any[]) => any): (new (...args: any[]) => any)[];
|
|
@@ -54,5 +59,7 @@ declare const es6Classes: {
|
|
|
54
59
|
size(): number;
|
|
55
60
|
clear(): void;
|
|
56
61
|
} | typeof BaseMigrationUtility | typeof CommonConsumer | typeof DatabaseEventEvaluator | typeof Money | typeof SeederUtility)[];
|
|
62
|
+
services: any[];
|
|
63
|
+
subscribers: any[];
|
|
57
64
|
};
|
|
58
65
|
export default es6Classes;
|
|
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const redis_io_adapter_1 = require("./adapters/redis.io.adapter");
|
|
4
4
|
const role_constants_1 = require("./constants/role.constants");
|
|
5
5
|
const user_constants_1 = require("./constants/user.constants");
|
|
6
|
+
const cache_method_decorator_1 = require("./decorators/cache.method.decorator");
|
|
6
7
|
const public_exposed_decorator_1 = require("./decorators/public.exposed.decorator");
|
|
8
|
+
const when_column_updated_decorator_1 = require("./decorators/when.column.updated.decorator");
|
|
9
|
+
const when_new_record_decorator_1 = require("./decorators/when.new.record.decorator");
|
|
7
10
|
const aggregation_param_dto_1 = require("./dtos/aggregation.param.dto");
|
|
8
11
|
const capture_record_index_dto_1 = require("./dtos/capture.record.index.dto");
|
|
9
12
|
const capture_record_show_dto_1 = require("./dtos/capture.record.show.dto");
|
|
@@ -70,7 +73,8 @@ const subscriber_registry_1 = require("./libraries/subscriber.registry");
|
|
|
70
73
|
const es6Classes = {
|
|
71
74
|
adapters: [redis_io_adapter_1.RedisIoAdapter],
|
|
72
75
|
constants: [role_constants_1.RoleConstants, user_constants_1.UserConstants],
|
|
73
|
-
|
|
76
|
+
controllers: [],
|
|
77
|
+
decorators: [cache_method_decorator_1.CacheMethodDecorator, public_exposed_decorator_1.PublicExposedDecorator, when_column_updated_decorator_1.WhenColumnUpdatedDecorator, when_new_record_decorator_1.WhenNewRecordDecorator],
|
|
74
78
|
dtos: [
|
|
75
79
|
aggregation_param_dto_1.AggregationParamDto,
|
|
76
80
|
capture_record_index_dto_1.CaptureRecordIndexDto,
|
|
@@ -94,6 +98,7 @@ const es6Classes = {
|
|
|
94
98
|
report_body_dto_1.ReportBodyDto,
|
|
95
99
|
report_data_manager_dto_1.ReportDataManagerDto,
|
|
96
100
|
],
|
|
101
|
+
entities: [],
|
|
97
102
|
exceptions: [
|
|
98
103
|
access_exception_1.AccessException,
|
|
99
104
|
form_exception_1.FormException,
|
|
@@ -104,6 +109,7 @@ const es6Classes = {
|
|
|
104
109
|
too_many_attempts_exception_1.TooManyAttemptsException,
|
|
105
110
|
],
|
|
106
111
|
interfaces: [],
|
|
112
|
+
jobs: [],
|
|
107
113
|
libraries: [
|
|
108
114
|
auth_1.Auth,
|
|
109
115
|
base_migration_utility_1.BaseMigrationUtility,
|
|
@@ -141,6 +147,8 @@ const es6Classes = {
|
|
|
141
147
|
sentry_sdk_1.SentrySdk,
|
|
142
148
|
subscriber_registry_1.SubscriberRegistry,
|
|
143
149
|
],
|
|
150
|
+
services: [],
|
|
151
|
+
subscribers: [],
|
|
144
152
|
};
|
|
145
153
|
exports.default = es6Classes;
|
|
146
154
|
//# sourceMappingURL=es6.classes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"es6.classes.js","sourceRoot":"","sources":["../../src/common/es6.classes.ts"],"names":[],"mappings":";;AAAA,kEAA6D;AAC7D,+DAA2D;AAC3D,+DAA2D;AAC3D,oFAA+E;AAC/E,wEAAmE;AACnE,8EAAwE;AACxE,4EAAsE;AACtE,kEAA6D;AAC7D,wEAAmE;AACnE,4EAAsE;AACtE,0EAAoE;AACpE,4DAAuD;AACvD,8DAAyD;AACzD,8DAAyD;AACzD,oFAA8E;AAC9E,8EAAwE;AACxE,oEAA8D;AAC9D,oEAA8D;AAC9D,sEAAgE;AAChE,wDAAmD;AACnD,4EAAsE;AACtE,0DAAqD;AACrD,gEAA2D;AAC3D,4DAAuD;AACvD,4EAAsE;AACtE,oEAAgE;AAChE,gEAA4D;AAC5D,8EAA0E;AAC1E,oFAA8E;AAC9E,0EAAsE;AACtE,gFAA4E;AAC5E,0FAAoF;AACpF,2CAAwC;AACxC,+EAA0E;AAC1E,iEAA6D;AAC7D,2DAAuD;AACvD,iEAA6D;AAC7D,6DAAyD;AACzD,uDAAmD;AACnD,qEAAgE;AAChE,yEAAoE;AACpE,+DAA2D;AAC3D,qEAAiE;AACjE,2DAAuD;AACvD,6DAAyD;AACzD,2DAAuD;AACvD,mFAA8E;AAC9E,qDAAiD;AACjD,uFAAkF;AAClF,mEAA+D;AAC/D,2EAAsE;AACtE,yEAAoE;AACpE,2CAAwC;AACxC,+DAA2D;AAC3D,2DAAuD;AACvD,2DAAuD;AACvD,qEAAiE;AACjE,6CAA0C;AAC1C,mEAA+D;AAC/D,+DAA2D;AAC3D,uEAAkE;AAClE,yEAAoE;AACpE,yEAAoE;AACpE,qFAAgF;AAChF,+DAA2D;AAC3D,uDAAmD;AACnD,yEAAqE;AAErE,MAAM,UAAU,GAAG;IACf,QAAQ,EAAE,CAAC,iCAAc,CAAC;IAC1B,SAAS,EAAE,CAAC,8BAAa,EAAE,8BAAa,CAAC;IACzC,UAAU,EAAE,CAAC,iDAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"es6.classes.js","sourceRoot":"","sources":["../../src/common/es6.classes.ts"],"names":[],"mappings":";;AAAA,kEAA6D;AAC7D,+DAA2D;AAC3D,+DAA2D;AAC3D,gFAA2E;AAC3E,oFAA+E;AAC/E,8FAAwF;AACxF,sFAAgF;AAChF,wEAAmE;AACnE,8EAAwE;AACxE,4EAAsE;AACtE,kEAA6D;AAC7D,wEAAmE;AACnE,4EAAsE;AACtE,0EAAoE;AACpE,4DAAuD;AACvD,8DAAyD;AACzD,8DAAyD;AACzD,oFAA8E;AAC9E,8EAAwE;AACxE,oEAA8D;AAC9D,oEAA8D;AAC9D,sEAAgE;AAChE,wDAAmD;AACnD,4EAAsE;AACtE,0DAAqD;AACrD,gEAA2D;AAC3D,4DAAuD;AACvD,4EAAsE;AACtE,oEAAgE;AAChE,gEAA4D;AAC5D,8EAA0E;AAC1E,oFAA8E;AAC9E,0EAAsE;AACtE,gFAA4E;AAC5E,0F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EAAE,EAAE;IACR,SAAS,EAAE;QACP,WAAI;QACJ,6CAAoB;QACpB,gCAAc;QACd,0BAAW;QACX,gCAAc;QACd,4BAAY;QACZ,sBAAS;QACT,mCAAe;QACf,uCAAiB;QACjB,8BAAa;QACb,oCAAgB;QAChB,0BAAW;QACX,4BAAY;QACZ,0BAAW;QACX,iDAAsB;QACtB,oBAAQ;QACR,qDAAwB;QACxB,kCAAe;QACf,yCAAkB;QAClB,uCAAiB;QACjB,WAAI;QACJ,8BAAa;QACb,0BAAW;QACX,0BAAW;QACX,oCAAgB;QAChB,aAAK;QACL,kCAAe;QACf,8BAAa;QACb,qCAAgB;QAChB,uCAAiB;QACjB,uCAAiB;QACjB,mDAAuB;QACvB,8BAAa;QACb,sBAAS;QACT,wCAAkB;KACrB;IACD,QAAQ,EAAE,EAAE;IACZ,WAAW,EAAE,EAAE;CAClB,CAAC;AAEF,kBAAe,UAAU,CAAC"}
|
|
@@ -14,5 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./method.cache.interface"), exports);
|
|
17
18
|
__exportStar(require("./platform.registry.resolver.interface"), exports);
|
|
19
|
+
__exportStar(require("./updated.column.interface"), exports);
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AAAA,yEAAuD;AAAA,6DAA0C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method.cache.interface.js","sourceRoot":"","sources":["../../../src/common/interfaces/method.cache.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updated.column.interface.js","sourceRoot":"","sources":["../../../src/common/interfaces/updated.column.interface.ts"],"names":[],"mappings":""}
|
|
@@ -19,11 +19,22 @@ export declare class CommonSubscriber<T> implements EntitySubscriberInterface<T>
|
|
|
19
19
|
protected getInsertEventData(event: any): DatabaseEventDto<T>;
|
|
20
20
|
private getMetadata;
|
|
21
21
|
private isMongoEntity;
|
|
22
|
+
private static readonly DECIMAL_TYPES;
|
|
23
|
+
private static readonly INTEGER_TYPES;
|
|
24
|
+
private static readonly BOOLEAN_TYPES;
|
|
25
|
+
private static readonly LEGACY_EMPTY_AS_ZERO_TYPES;
|
|
26
|
+
private static readonly TRUE_LITERALS;
|
|
27
|
+
private static readonly FALSE_LITERALS;
|
|
22
28
|
private getUpdatedRecords;
|
|
23
|
-
private
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
private
|
|
29
|
+
private isValueChanged;
|
|
30
|
+
private isDecimalChanged;
|
|
31
|
+
private isIntegerChanged;
|
|
32
|
+
private isBooleanChanged;
|
|
33
|
+
private isEmpty;
|
|
34
|
+
private toNumber;
|
|
35
|
+
private toBigInt;
|
|
36
|
+
private toBoolean;
|
|
37
|
+
private toDateString;
|
|
27
38
|
afterRemove(_event: RemoveEvent<T>): Promise<void>;
|
|
28
39
|
isColumnUpdated(event: any, column: any): boolean;
|
|
29
40
|
isNewRecord(event: any): boolean;
|
|
@@ -101,43 +101,129 @@ class CommonSubscriber {
|
|
|
101
101
|
return name === 'mongodb';
|
|
102
102
|
}
|
|
103
103
|
getUpdatedRecords(event) {
|
|
104
|
-
const updates = [];
|
|
105
104
|
if (!Array.isArray(event?.updatedColumns))
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
return
|
|
120
|
-
|
|
121
|
-
|
|
105
|
+
return [];
|
|
106
|
+
const updates = new Set();
|
|
107
|
+
for (const column of event.updatedColumns) {
|
|
108
|
+
const name = column?.databaseName;
|
|
109
|
+
if (!name || name === '_id' || updates.has(name))
|
|
110
|
+
continue;
|
|
111
|
+
if (this.isValueChanged(event, column))
|
|
112
|
+
updates.add(name);
|
|
113
|
+
}
|
|
114
|
+
return [...updates];
|
|
115
|
+
}
|
|
116
|
+
isValueChanged(event, column) {
|
|
117
|
+
if (!event.databaseEntity || !event.entity || typeof column.getEntityValue !== 'function')
|
|
118
|
+
return true;
|
|
119
|
+
const before = column.getEntityValue(event.databaseEntity);
|
|
120
|
+
const after = column.getEntityValue(event.entity);
|
|
121
|
+
const emptyAsZero = CommonSubscriber.LEGACY_EMPTY_AS_ZERO_TYPES.has(column.type);
|
|
122
|
+
if (CommonSubscriber.DECIMAL_TYPES.has(column.type))
|
|
123
|
+
return this.isDecimalChanged(before, after, emptyAsZero, column.scale);
|
|
124
|
+
if (CommonSubscriber.INTEGER_TYPES.has(column.type))
|
|
125
|
+
return this.isIntegerChanged(before, after, emptyAsZero);
|
|
126
|
+
if (CommonSubscriber.BOOLEAN_TYPES.has(column.type))
|
|
127
|
+
return this.isBooleanChanged(before, after, emptyAsZero);
|
|
128
|
+
if (column.type === 'date')
|
|
129
|
+
return this.toDateString(before, column.utc) !== this.toDateString(after, column.utc);
|
|
122
130
|
return true;
|
|
123
131
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
132
|
+
isDecimalChanged(before, after, emptyAsZero, scale) {
|
|
133
|
+
if (emptyAsZero) {
|
|
134
|
+
before = before || 0;
|
|
135
|
+
after = after || 0;
|
|
136
|
+
}
|
|
137
|
+
else if (this.isEmpty(before) || this.isEmpty(after))
|
|
138
|
+
return before !== after;
|
|
139
|
+
const a = this.toNumber(before);
|
|
140
|
+
const b = this.toNumber(after);
|
|
141
|
+
if (Number.isNaN(a) || Number.isNaN(b))
|
|
142
|
+
return before !== after;
|
|
143
|
+
const factor = scale === undefined || scale === null ? 1 : 10 ** scale;
|
|
144
|
+
const scaledA = a * factor;
|
|
145
|
+
const scaledB = b * factor;
|
|
146
|
+
if (!emptyAsZero && (Math.abs(scaledA) > Number.MAX_SAFE_INTEGER || Math.abs(scaledB) > Number.MAX_SAFE_INTEGER)) {
|
|
147
|
+
return String(before).trim() !== String(after).trim();
|
|
148
|
+
}
|
|
149
|
+
if (factor === 1 && (scale === undefined || scale === null))
|
|
150
|
+
return a !== b;
|
|
151
|
+
return Math.round(scaledA) !== Math.round(scaledB);
|
|
152
|
+
}
|
|
153
|
+
isIntegerChanged(before, after, emptyAsZero) {
|
|
154
|
+
if (emptyAsZero) {
|
|
155
|
+
before = before || 0;
|
|
156
|
+
after = after || 0;
|
|
157
|
+
}
|
|
158
|
+
else if (this.isEmpty(before) || this.isEmpty(after))
|
|
159
|
+
return before !== after;
|
|
160
|
+
const a = this.toBigInt(before);
|
|
161
|
+
const b = this.toBigInt(after);
|
|
162
|
+
if (a !== undefined && b !== undefined)
|
|
163
|
+
return a !== b;
|
|
164
|
+
return this.isDecimalChanged(before, after, emptyAsZero);
|
|
165
|
+
}
|
|
166
|
+
isBooleanChanged(before, after, emptyAsZero) {
|
|
167
|
+
if (emptyAsZero) {
|
|
168
|
+
before = before || false;
|
|
169
|
+
after = after || false;
|
|
170
|
+
}
|
|
171
|
+
else if (this.isEmpty(before) || this.isEmpty(after))
|
|
172
|
+
return before !== after;
|
|
173
|
+
const a = this.toBoolean(before);
|
|
174
|
+
const b = this.toBoolean(after);
|
|
175
|
+
if (a === undefined || b === undefined)
|
|
176
|
+
return before !== after;
|
|
177
|
+
return a !== b;
|
|
178
|
+
}
|
|
179
|
+
isEmpty(value) {
|
|
180
|
+
return value === null || value === undefined;
|
|
181
|
+
}
|
|
182
|
+
toNumber(value) {
|
|
183
|
+
if (typeof value === 'number')
|
|
184
|
+
return value;
|
|
185
|
+
if (typeof value === 'string')
|
|
186
|
+
return value.trim() === '' ? NaN : Number(value);
|
|
187
|
+
if (typeof value === 'bigint' || typeof value === 'boolean')
|
|
188
|
+
return Number(value);
|
|
189
|
+
return NaN;
|
|
131
190
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
191
|
+
toBigInt(value) {
|
|
192
|
+
if (typeof value === 'bigint')
|
|
193
|
+
return value;
|
|
194
|
+
if (typeof value === 'number')
|
|
195
|
+
return Number.isInteger(value) ? BigInt(value) : undefined;
|
|
196
|
+
if (typeof value === 'string' && /^\s*-?\d+\s*$/.test(value))
|
|
197
|
+
return BigInt(value.trim());
|
|
198
|
+
return undefined;
|
|
136
199
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
200
|
+
toBoolean(value) {
|
|
201
|
+
if (typeof value === 'boolean')
|
|
202
|
+
return value;
|
|
203
|
+
if (value === 1 || value === 0)
|
|
204
|
+
return value === 1;
|
|
205
|
+
if (typeof value === 'string') {
|
|
206
|
+
const literal = value.trim().toLowerCase();
|
|
207
|
+
if (CommonSubscriber.TRUE_LITERALS.has(literal))
|
|
208
|
+
return true;
|
|
209
|
+
if (CommonSubscriber.FALSE_LITERALS.has(literal))
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
toDateString(value, utc) {
|
|
215
|
+
if (this.isEmpty(value))
|
|
216
|
+
return null;
|
|
217
|
+
if (value instanceof Date) {
|
|
218
|
+
if (Number.isNaN(value.getTime()))
|
|
219
|
+
return String(value);
|
|
220
|
+
const year = utc ? value.getUTCFullYear() : value.getFullYear();
|
|
221
|
+
const month = (utc ? value.getUTCMonth() : value.getMonth()) + 1;
|
|
222
|
+
const day = utc ? value.getUTCDate() : value.getDate();
|
|
223
|
+
return `${String(year).padStart(4, '0')}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
|
|
224
|
+
}
|
|
225
|
+
const text = String(value).trim();
|
|
226
|
+
return /^\d{4}-\d{2}-\d{2}/.exec(text)?.[0] ?? text;
|
|
141
227
|
}
|
|
142
228
|
async afterRemove(_event) {
|
|
143
229
|
}
|
|
@@ -166,4 +252,19 @@ class CommonSubscriber {
|
|
|
166
252
|
}
|
|
167
253
|
}
|
|
168
254
|
exports.CommonSubscriber = CommonSubscriber;
|
|
255
|
+
CommonSubscriber.DECIMAL_TYPES = new Set([
|
|
256
|
+
'float',
|
|
257
|
+
'float4',
|
|
258
|
+
'float8',
|
|
259
|
+
'double precision',
|
|
260
|
+
'real',
|
|
261
|
+
'decimal',
|
|
262
|
+
'numeric',
|
|
263
|
+
'money',
|
|
264
|
+
]);
|
|
265
|
+
CommonSubscriber.INTEGER_TYPES = new Set([Number, 'int', 'int2', 'int4', 'int8', 'integer', 'smallint', 'bigint']);
|
|
266
|
+
CommonSubscriber.BOOLEAN_TYPES = new Set([Boolean, 'boolean', 'bool']);
|
|
267
|
+
CommonSubscriber.LEGACY_EMPTY_AS_ZERO_TYPES = new Set(['float', Number, Boolean]);
|
|
268
|
+
CommonSubscriber.TRUE_LITERALS = new Set(['t', 'true', 'y', 'yes', 'on', '1']);
|
|
269
|
+
CommonSubscriber.FALSE_LITERALS = new Set(['f', 'false', 'n', 'no', 'off', '0']);
|
|
169
270
|
//# sourceMappingURL=common.subscriber.js.map
|