@forklaunch/core 1.0.12 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{apiDefinition.types-Br0fDuBQ.d.mts → apiDefinition.types-DUkE1FHm.d.mts} +3 -50
- package/lib/{apiDefinition.types-Br0fDuBQ.d.ts → apiDefinition.types-DdQ3d8il.d.ts} +3 -50
- package/lib/http/index.d.mts +4 -2
- package/lib/http/index.d.ts +4 -2
- package/lib/http/index.js +6 -1
- package/lib/http/index.js.map +1 -1
- package/lib/http/index.mjs +6 -1
- package/lib/http/index.mjs.map +1 -1
- package/lib/openTelemetryCollector-DXGXRvQP.d.mts +51 -0
- package/lib/openTelemetryCollector-DXGXRvQP.d.ts +51 -0
- package/lib/persistence/index.d.mts +40 -19
- package/lib/persistence/index.d.ts +40 -19
- package/lib/persistence/index.js +64 -1
- package/lib/persistence/index.js.map +1 -1
- package/lib/persistence/index.mjs +59 -1
- package/lib/persistence/index.mjs.map +1 -1
- package/lib/services/index.d.mts +34 -2
- package/lib/services/index.d.ts +34 -2
- package/lib/services/index.js +173 -0
- package/lib/services/index.js.map +1 -1
- package/lib/services/index.mjs +172 -0
- package/lib/services/index.mjs.map +1 -1
- package/lib/ws/index.d.mts +2 -1
- package/lib/ws/index.d.ts +2 -1
- package/package.json +4 -4
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Counter, Gauge, Histogram, UpDownCounter, ObservableCounter, ObservableGauge, ObservableUpDownCounter } from '@opentelemetry/api';
|
|
2
|
+
import { LevelWithSilentOrString, LevelWithSilent } from 'pino';
|
|
3
|
+
|
|
4
|
+
type MetricType<T extends string> = T extends 'counter' ? Counter : T extends 'gauge' ? Gauge : T extends 'histogram' ? Histogram : T extends 'upDownCounter' ? UpDownCounter : T extends 'observableCounter' ? ObservableCounter : T extends 'observableGauge' ? ObservableGauge : T extends 'observableUpDownCounter' ? ObservableUpDownCounter : undefined;
|
|
5
|
+
type MetricsDefinition = Record<string, 'counter' | 'gauge' | 'histogram' | 'upDownCounter' | 'observableCounter' | 'observableGauge' | 'observableUpDownCounter'>;
|
|
6
|
+
type LoggerMeta = Record<string, unknown> & {
|
|
7
|
+
_meta: true;
|
|
8
|
+
};
|
|
9
|
+
interface LogFn {
|
|
10
|
+
<T extends object>(obj: T | LoggerMeta, msg?: string | LoggerMeta, ...args: unknown[]): void;
|
|
11
|
+
(obj: unknown | LoggerMeta, msg?: string | LoggerMeta, ...args: unknown[]): void;
|
|
12
|
+
(msg: string | LoggerMeta, ...args: unknown[]): void;
|
|
13
|
+
}
|
|
14
|
+
interface TelemetryOptions {
|
|
15
|
+
enabled: boolean | {
|
|
16
|
+
metrics?: boolean;
|
|
17
|
+
tracing?: boolean;
|
|
18
|
+
logging?: boolean;
|
|
19
|
+
};
|
|
20
|
+
level: LevelWithSilentOrString;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare class OpenTelemetryCollector<AppliedMetricsDefinition extends MetricsDefinition> {
|
|
24
|
+
#private;
|
|
25
|
+
constructor(serviceName: string, level?: LevelWithSilentOrString, metricDefinitions?: AppliedMetricsDefinition);
|
|
26
|
+
log(level: LevelWithSilent, ...args: (string | unknown | LoggerMeta)[]): void;
|
|
27
|
+
info: LogFn;
|
|
28
|
+
error: LogFn;
|
|
29
|
+
warn: LogFn;
|
|
30
|
+
debug: LogFn;
|
|
31
|
+
trace: LogFn;
|
|
32
|
+
getMetric<T extends keyof AppliedMetricsDefinition>(metricId: T): MetricType<AppliedMetricsDefinition[T]>;
|
|
33
|
+
}
|
|
34
|
+
declare const httpRequestsTotalCounter: Counter<{
|
|
35
|
+
"service.name": string;
|
|
36
|
+
application_id?: string;
|
|
37
|
+
"api.name": string;
|
|
38
|
+
"http.request.method": string;
|
|
39
|
+
"http.route": string;
|
|
40
|
+
"http.response.status_code": number;
|
|
41
|
+
}>;
|
|
42
|
+
declare const httpServerDurationHistogram: Histogram<{
|
|
43
|
+
"service.name": string;
|
|
44
|
+
application_id?: string;
|
|
45
|
+
"api.name": string;
|
|
46
|
+
"http.request.method": string;
|
|
47
|
+
"http.route": string;
|
|
48
|
+
"http.response.status_code": number;
|
|
49
|
+
}>;
|
|
50
|
+
|
|
51
|
+
export { type LoggerMeta as L, type MetricsDefinition as M, OpenTelemetryCollector as O, type TelemetryOptions as T, type LogFn as a, type MetricType as b, httpServerDurationHistogram as c, httpRequestsTotalCounter as h };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Counter, Gauge, Histogram, UpDownCounter, ObservableCounter, ObservableGauge, ObservableUpDownCounter } from '@opentelemetry/api';
|
|
2
|
+
import { LevelWithSilentOrString, LevelWithSilent } from 'pino';
|
|
3
|
+
|
|
4
|
+
type MetricType<T extends string> = T extends 'counter' ? Counter : T extends 'gauge' ? Gauge : T extends 'histogram' ? Histogram : T extends 'upDownCounter' ? UpDownCounter : T extends 'observableCounter' ? ObservableCounter : T extends 'observableGauge' ? ObservableGauge : T extends 'observableUpDownCounter' ? ObservableUpDownCounter : undefined;
|
|
5
|
+
type MetricsDefinition = Record<string, 'counter' | 'gauge' | 'histogram' | 'upDownCounter' | 'observableCounter' | 'observableGauge' | 'observableUpDownCounter'>;
|
|
6
|
+
type LoggerMeta = Record<string, unknown> & {
|
|
7
|
+
_meta: true;
|
|
8
|
+
};
|
|
9
|
+
interface LogFn {
|
|
10
|
+
<T extends object>(obj: T | LoggerMeta, msg?: string | LoggerMeta, ...args: unknown[]): void;
|
|
11
|
+
(obj: unknown | LoggerMeta, msg?: string | LoggerMeta, ...args: unknown[]): void;
|
|
12
|
+
(msg: string | LoggerMeta, ...args: unknown[]): void;
|
|
13
|
+
}
|
|
14
|
+
interface TelemetryOptions {
|
|
15
|
+
enabled: boolean | {
|
|
16
|
+
metrics?: boolean;
|
|
17
|
+
tracing?: boolean;
|
|
18
|
+
logging?: boolean;
|
|
19
|
+
};
|
|
20
|
+
level: LevelWithSilentOrString;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare class OpenTelemetryCollector<AppliedMetricsDefinition extends MetricsDefinition> {
|
|
24
|
+
#private;
|
|
25
|
+
constructor(serviceName: string, level?: LevelWithSilentOrString, metricDefinitions?: AppliedMetricsDefinition);
|
|
26
|
+
log(level: LevelWithSilent, ...args: (string | unknown | LoggerMeta)[]): void;
|
|
27
|
+
info: LogFn;
|
|
28
|
+
error: LogFn;
|
|
29
|
+
warn: LogFn;
|
|
30
|
+
debug: LogFn;
|
|
31
|
+
trace: LogFn;
|
|
32
|
+
getMetric<T extends keyof AppliedMetricsDefinition>(metricId: T): MetricType<AppliedMetricsDefinition[T]>;
|
|
33
|
+
}
|
|
34
|
+
declare const httpRequestsTotalCounter: Counter<{
|
|
35
|
+
"service.name": string;
|
|
36
|
+
application_id?: string;
|
|
37
|
+
"api.name": string;
|
|
38
|
+
"http.request.method": string;
|
|
39
|
+
"http.route": string;
|
|
40
|
+
"http.response.status_code": number;
|
|
41
|
+
}>;
|
|
42
|
+
declare const httpServerDurationHistogram: Histogram<{
|
|
43
|
+
"service.name": string;
|
|
44
|
+
application_id?: string;
|
|
45
|
+
"api.name": string;
|
|
46
|
+
"http.request.method": string;
|
|
47
|
+
"http.route": string;
|
|
48
|
+
"http.response.status_code": number;
|
|
49
|
+
}>;
|
|
50
|
+
|
|
51
|
+
export { type LoggerMeta as L, type MetricsDefinition as M, OpenTelemetryCollector as O, type TelemetryOptions as T, type LogFn as a, type MetricType as b, httpServerDurationHistogram as c, httpRequestsTotalCounter as h };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { PropertyBuilders, PropertyChain, EmptyOptions, EntityMetadataWithProperties, EventSubscriber, EventArgs, FilterDef, EntityManager, MikroORM } from '@mikro-orm/core';
|
|
1
|
+
import { PropertyBuilders, PropertyChain, EmptyOptions, EntityMetadataWithProperties, EntitySchemaWithMeta, InferEntityFromProperties, EventSubscriber, EventArgs, FilterDef, EntityManager, MikroORM } from '@mikro-orm/core';
|
|
3
2
|
export { InferEntity } from '@mikro-orm/core';
|
|
4
3
|
|
|
5
4
|
declare const ComplianceLevel: {
|
|
@@ -12,20 +11,35 @@ type ComplianceLevel = (typeof ComplianceLevel)[keyof typeof ComplianceLevel];
|
|
|
12
11
|
declare function getComplianceMetadata(entityName: string, fieldName: string): ComplianceLevel;
|
|
13
12
|
declare function getEntityComplianceFields(entityName: string): Map<string, ComplianceLevel> | undefined;
|
|
14
13
|
declare function entityHasEncryptedFields(entityName: string): boolean;
|
|
14
|
+
declare const RetentionAction: {
|
|
15
|
+
readonly delete: "delete";
|
|
16
|
+
readonly anonymize: "anonymize";
|
|
17
|
+
};
|
|
18
|
+
type RetentionAction = (typeof RetentionAction)[keyof typeof RetentionAction];
|
|
19
|
+
interface RetentionPolicy {
|
|
20
|
+
duration: string;
|
|
21
|
+
action: RetentionAction;
|
|
22
|
+
}
|
|
23
|
+
declare const RetentionDuration: {
|
|
24
|
+
readonly days: (n: number) => string;
|
|
25
|
+
readonly months: (n: number) => string;
|
|
26
|
+
readonly years: (n: number) => string;
|
|
27
|
+
};
|
|
28
|
+
declare function parseDuration(iso: string): number;
|
|
29
|
+
declare function getEntityRetention(entityName: string): RetentionPolicy | undefined;
|
|
30
|
+
declare function getAllRetentionPolicies(): ReadonlyMap<string, RetentionPolicy>;
|
|
15
31
|
/**
|
|
16
32
|
* Tagged wrapper returned by `.compliance()`.
|
|
17
33
|
* `__inner` is the EXACT MikroORM builder type.
|
|
18
34
|
* `defineComplianceEntity` checks for this wrapper and extracts `__inner`.
|
|
19
35
|
*/
|
|
20
|
-
interface ClassifiedProperty<Builder = unknown> {
|
|
36
|
+
interface ClassifiedProperty<Builder = unknown, Value = unknown, Options = unknown> {
|
|
21
37
|
readonly __inner: Builder;
|
|
22
38
|
readonly __compliance: ComplianceLevel;
|
|
23
|
-
readonly '~type'?:
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
readonly '~options':
|
|
27
|
-
'~options': infer O;
|
|
28
|
-
} ? O : unknown;
|
|
39
|
+
readonly '~type'?: {
|
|
40
|
+
value: Value;
|
|
41
|
+
};
|
|
42
|
+
readonly '~options': Options;
|
|
29
43
|
}
|
|
30
44
|
/**
|
|
31
45
|
* For each property, if it's a ClassifiedProperty, extract __inner.
|
|
@@ -46,10 +60,15 @@ type WithCompliance<T> = {
|
|
|
46
60
|
'~options': unknown;
|
|
47
61
|
} ? (...args: A) => WithCompliance<R> : T[K] : T[K];
|
|
48
62
|
} & {
|
|
49
|
-
compliance(level: ComplianceLevel):
|
|
63
|
+
compliance(level: ComplianceLevel): T extends {
|
|
64
|
+
'~type'?: {
|
|
65
|
+
value: infer V;
|
|
66
|
+
};
|
|
67
|
+
'~options': infer O;
|
|
68
|
+
} ? ClassifiedProperty<T, V, O> : ClassifiedProperty<T>;
|
|
50
69
|
};
|
|
51
70
|
type RelationBuilderKeys = 'manyToOne' | 'oneToMany' | 'manyToMany' | 'oneToOne' | 'embedded';
|
|
52
|
-
type GenericBuilderKeys = 'json' | 'formula' | 'type';
|
|
71
|
+
type GenericBuilderKeys = 'json' | 'formula' | 'type' | 'enum' | 'bigint' | 'array' | 'decimal';
|
|
53
72
|
/**
|
|
54
73
|
* Each scalar method wraps the EXACT MikroORM return type with
|
|
55
74
|
* WithCompliance. Relations pass through unchanged.
|
|
@@ -63,6 +82,12 @@ type ForklaunchPropertyBuilders = {
|
|
|
63
82
|
json: <T>() => WithCompliance<PropertyChain<T, EmptyOptions>>;
|
|
64
83
|
formula: <T>(formula: string | ((...args: never[]) => string)) => WithCompliance<PropertyChain<T, EmptyOptions>>;
|
|
65
84
|
type: <T>(type: T) => WithCompliance<PropertyChain<T, EmptyOptions>>;
|
|
85
|
+
enum: <const T extends (number | string)[] | (() => Record<string, any>)>(items?: T) => WithCompliance<PropertyChain<T extends () => Record<string, any> ? T extends () => infer R ? R[keyof R] : never : T extends (infer Value)[] ? Value : T, EmptyOptions & {
|
|
86
|
+
kind: 'enum';
|
|
87
|
+
}>>;
|
|
88
|
+
bigint: <Mode extends 'bigint' | 'number' | 'string' = 'bigint'>(mode?: Mode) => WithCompliance<PropertyChain<Mode extends 'bigint' ? bigint : Mode extends 'number' ? number : string, EmptyOptions>>;
|
|
89
|
+
array: <T = string>(toJsValue?: (i: string) => T, toDbValue?: (i: T) => string) => WithCompliance<PropertyChain<T[], EmptyOptions>>;
|
|
90
|
+
decimal: <Mode extends 'number' | 'string' = 'string'>(mode?: Mode) => WithCompliance<PropertyChain<Mode extends 'number' ? number : string, EmptyOptions>>;
|
|
66
91
|
};
|
|
67
92
|
|
|
68
93
|
/**
|
|
@@ -93,13 +118,9 @@ declare const fp: ForklaunchPropertyBuilders;
|
|
|
93
118
|
type ValidateProperties<T> = {
|
|
94
119
|
[K in keyof T]: T[K] extends ClassifiedProperty ? T[K] : T[K] extends (...args: never[]) => unknown ? T[K] : ClassifiedProperty;
|
|
95
120
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* so InferBuilderValue works directly. Return type is inferred by
|
|
100
|
-
* defineEntity — same leniency as plain defineEntity.
|
|
101
|
-
*/
|
|
102
|
-
declare function defineComplianceEntity<const TName extends string, const TTableName extends string, const TProperties extends Record<string, unknown>, const TPK extends (keyof TProperties)[] | undefined = undefined, const TBase = never, const TRepository = never, const TForceObject extends boolean = false>(meta: EntityMetadataWithProperties<TName, TTableName, TProperties & ValidateProperties<TProperties>, TPK, TBase, TRepository, TForceObject>): _mikro_orm_core.EntitySchemaWithMeta<TName, TTableName, _mikro_orm_core.InferEntityFromProperties<TProperties & ValidateProperties<TProperties>, TPK, TBase, TRepository, TForceObject>, TBase, TProperties & ValidateProperties<TProperties>, _mikro_orm_core.EntityCtor<_mikro_orm_core.InferEntityFromProperties<TProperties & ValidateProperties<TProperties>, TPK, TBase, TRepository, TForceObject>>>;
|
|
121
|
+
declare function defineComplianceEntity<const TName extends string, const TTableName extends string, const TProperties extends Record<string, unknown>, const TPK extends (keyof TProperties)[] | undefined = undefined, const TBase = never, const TRepository = never, const TForceObject extends boolean = false>(meta: EntityMetadataWithProperties<TName, TTableName, TProperties & ValidateProperties<TProperties>, TPK, TBase, TRepository, TForceObject> & {
|
|
122
|
+
retention?: RetentionPolicy;
|
|
123
|
+
}): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<TProperties, TPK, TBase, TRepository, TForceObject>, TBase, TProperties>;
|
|
103
124
|
|
|
104
125
|
declare class FieldEncryptor {
|
|
105
126
|
private readonly masterKey;
|
|
@@ -248,4 +269,4 @@ declare class RlsEventSubscriber implements EventSubscriber {
|
|
|
248
269
|
*/
|
|
249
270
|
declare function setupRls(orm: MikroORM, config?: RlsConfig): void;
|
|
250
271
|
|
|
251
|
-
export { type ClassifiedProperty, ComplianceEventSubscriber, ComplianceLevel, ComplianceLevel as ComplianceLevelType, type ExtractInner, type ForklaunchPropertyBuilders, type RlsConfig, RlsEventSubscriber, TENANT_FILTER_NAME, type WithCompliance, createTenantFilterDef, defineComplianceEntity, entityHasEncryptedFields, fp, getComplianceMetadata, getEntityComplianceFields, getSuperAdminContext, setupRls, setupTenantFilter, wrapEmWithNativeQueryBlocking };
|
|
272
|
+
export { type ClassifiedProperty, ComplianceEventSubscriber, ComplianceLevel, ComplianceLevel as ComplianceLevelType, type ExtractInner, type ForklaunchPropertyBuilders, RetentionAction, RetentionAction as RetentionActionType, RetentionDuration, type RetentionPolicy, type RlsConfig, RlsEventSubscriber, TENANT_FILTER_NAME, type WithCompliance, createTenantFilterDef, defineComplianceEntity, entityHasEncryptedFields, fp, getAllRetentionPolicies, getComplianceMetadata, getEntityComplianceFields, getEntityRetention, getSuperAdminContext, parseDuration, setupRls, setupTenantFilter, wrapEmWithNativeQueryBlocking };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { PropertyBuilders, PropertyChain, EmptyOptions, EntityMetadataWithProperties, EventSubscriber, EventArgs, FilterDef, EntityManager, MikroORM } from '@mikro-orm/core';
|
|
1
|
+
import { PropertyBuilders, PropertyChain, EmptyOptions, EntityMetadataWithProperties, EntitySchemaWithMeta, InferEntityFromProperties, EventSubscriber, EventArgs, FilterDef, EntityManager, MikroORM } from '@mikro-orm/core';
|
|
3
2
|
export { InferEntity } from '@mikro-orm/core';
|
|
4
3
|
|
|
5
4
|
declare const ComplianceLevel: {
|
|
@@ -12,20 +11,35 @@ type ComplianceLevel = (typeof ComplianceLevel)[keyof typeof ComplianceLevel];
|
|
|
12
11
|
declare function getComplianceMetadata(entityName: string, fieldName: string): ComplianceLevel;
|
|
13
12
|
declare function getEntityComplianceFields(entityName: string): Map<string, ComplianceLevel> | undefined;
|
|
14
13
|
declare function entityHasEncryptedFields(entityName: string): boolean;
|
|
14
|
+
declare const RetentionAction: {
|
|
15
|
+
readonly delete: "delete";
|
|
16
|
+
readonly anonymize: "anonymize";
|
|
17
|
+
};
|
|
18
|
+
type RetentionAction = (typeof RetentionAction)[keyof typeof RetentionAction];
|
|
19
|
+
interface RetentionPolicy {
|
|
20
|
+
duration: string;
|
|
21
|
+
action: RetentionAction;
|
|
22
|
+
}
|
|
23
|
+
declare const RetentionDuration: {
|
|
24
|
+
readonly days: (n: number) => string;
|
|
25
|
+
readonly months: (n: number) => string;
|
|
26
|
+
readonly years: (n: number) => string;
|
|
27
|
+
};
|
|
28
|
+
declare function parseDuration(iso: string): number;
|
|
29
|
+
declare function getEntityRetention(entityName: string): RetentionPolicy | undefined;
|
|
30
|
+
declare function getAllRetentionPolicies(): ReadonlyMap<string, RetentionPolicy>;
|
|
15
31
|
/**
|
|
16
32
|
* Tagged wrapper returned by `.compliance()`.
|
|
17
33
|
* `__inner` is the EXACT MikroORM builder type.
|
|
18
34
|
* `defineComplianceEntity` checks for this wrapper and extracts `__inner`.
|
|
19
35
|
*/
|
|
20
|
-
interface ClassifiedProperty<Builder = unknown> {
|
|
36
|
+
interface ClassifiedProperty<Builder = unknown, Value = unknown, Options = unknown> {
|
|
21
37
|
readonly __inner: Builder;
|
|
22
38
|
readonly __compliance: ComplianceLevel;
|
|
23
|
-
readonly '~type'?:
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
readonly '~options':
|
|
27
|
-
'~options': infer O;
|
|
28
|
-
} ? O : unknown;
|
|
39
|
+
readonly '~type'?: {
|
|
40
|
+
value: Value;
|
|
41
|
+
};
|
|
42
|
+
readonly '~options': Options;
|
|
29
43
|
}
|
|
30
44
|
/**
|
|
31
45
|
* For each property, if it's a ClassifiedProperty, extract __inner.
|
|
@@ -46,10 +60,15 @@ type WithCompliance<T> = {
|
|
|
46
60
|
'~options': unknown;
|
|
47
61
|
} ? (...args: A) => WithCompliance<R> : T[K] : T[K];
|
|
48
62
|
} & {
|
|
49
|
-
compliance(level: ComplianceLevel):
|
|
63
|
+
compliance(level: ComplianceLevel): T extends {
|
|
64
|
+
'~type'?: {
|
|
65
|
+
value: infer V;
|
|
66
|
+
};
|
|
67
|
+
'~options': infer O;
|
|
68
|
+
} ? ClassifiedProperty<T, V, O> : ClassifiedProperty<T>;
|
|
50
69
|
};
|
|
51
70
|
type RelationBuilderKeys = 'manyToOne' | 'oneToMany' | 'manyToMany' | 'oneToOne' | 'embedded';
|
|
52
|
-
type GenericBuilderKeys = 'json' | 'formula' | 'type';
|
|
71
|
+
type GenericBuilderKeys = 'json' | 'formula' | 'type' | 'enum' | 'bigint' | 'array' | 'decimal';
|
|
53
72
|
/**
|
|
54
73
|
* Each scalar method wraps the EXACT MikroORM return type with
|
|
55
74
|
* WithCompliance. Relations pass through unchanged.
|
|
@@ -63,6 +82,12 @@ type ForklaunchPropertyBuilders = {
|
|
|
63
82
|
json: <T>() => WithCompliance<PropertyChain<T, EmptyOptions>>;
|
|
64
83
|
formula: <T>(formula: string | ((...args: never[]) => string)) => WithCompliance<PropertyChain<T, EmptyOptions>>;
|
|
65
84
|
type: <T>(type: T) => WithCompliance<PropertyChain<T, EmptyOptions>>;
|
|
85
|
+
enum: <const T extends (number | string)[] | (() => Record<string, any>)>(items?: T) => WithCompliance<PropertyChain<T extends () => Record<string, any> ? T extends () => infer R ? R[keyof R] : never : T extends (infer Value)[] ? Value : T, EmptyOptions & {
|
|
86
|
+
kind: 'enum';
|
|
87
|
+
}>>;
|
|
88
|
+
bigint: <Mode extends 'bigint' | 'number' | 'string' = 'bigint'>(mode?: Mode) => WithCompliance<PropertyChain<Mode extends 'bigint' ? bigint : Mode extends 'number' ? number : string, EmptyOptions>>;
|
|
89
|
+
array: <T = string>(toJsValue?: (i: string) => T, toDbValue?: (i: T) => string) => WithCompliance<PropertyChain<T[], EmptyOptions>>;
|
|
90
|
+
decimal: <Mode extends 'number' | 'string' = 'string'>(mode?: Mode) => WithCompliance<PropertyChain<Mode extends 'number' ? number : string, EmptyOptions>>;
|
|
66
91
|
};
|
|
67
92
|
|
|
68
93
|
/**
|
|
@@ -93,13 +118,9 @@ declare const fp: ForklaunchPropertyBuilders;
|
|
|
93
118
|
type ValidateProperties<T> = {
|
|
94
119
|
[K in keyof T]: T[K] extends ClassifiedProperty ? T[K] : T[K] extends (...args: never[]) => unknown ? T[K] : ClassifiedProperty;
|
|
95
120
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* so InferBuilderValue works directly. Return type is inferred by
|
|
100
|
-
* defineEntity — same leniency as plain defineEntity.
|
|
101
|
-
*/
|
|
102
|
-
declare function defineComplianceEntity<const TName extends string, const TTableName extends string, const TProperties extends Record<string, unknown>, const TPK extends (keyof TProperties)[] | undefined = undefined, const TBase = never, const TRepository = never, const TForceObject extends boolean = false>(meta: EntityMetadataWithProperties<TName, TTableName, TProperties & ValidateProperties<TProperties>, TPK, TBase, TRepository, TForceObject>): _mikro_orm_core.EntitySchemaWithMeta<TName, TTableName, _mikro_orm_core.InferEntityFromProperties<TProperties & ValidateProperties<TProperties>, TPK, TBase, TRepository, TForceObject>, TBase, TProperties & ValidateProperties<TProperties>, _mikro_orm_core.EntityCtor<_mikro_orm_core.InferEntityFromProperties<TProperties & ValidateProperties<TProperties>, TPK, TBase, TRepository, TForceObject>>>;
|
|
121
|
+
declare function defineComplianceEntity<const TName extends string, const TTableName extends string, const TProperties extends Record<string, unknown>, const TPK extends (keyof TProperties)[] | undefined = undefined, const TBase = never, const TRepository = never, const TForceObject extends boolean = false>(meta: EntityMetadataWithProperties<TName, TTableName, TProperties & ValidateProperties<TProperties>, TPK, TBase, TRepository, TForceObject> & {
|
|
122
|
+
retention?: RetentionPolicy;
|
|
123
|
+
}): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<TProperties, TPK, TBase, TRepository, TForceObject>, TBase, TProperties>;
|
|
103
124
|
|
|
104
125
|
declare class FieldEncryptor {
|
|
105
126
|
private readonly masterKey;
|
|
@@ -248,4 +269,4 @@ declare class RlsEventSubscriber implements EventSubscriber {
|
|
|
248
269
|
*/
|
|
249
270
|
declare function setupRls(orm: MikroORM, config?: RlsConfig): void;
|
|
250
271
|
|
|
251
|
-
export { type ClassifiedProperty, ComplianceEventSubscriber, ComplianceLevel, ComplianceLevel as ComplianceLevelType, type ExtractInner, type ForklaunchPropertyBuilders, type RlsConfig, RlsEventSubscriber, TENANT_FILTER_NAME, type WithCompliance, createTenantFilterDef, defineComplianceEntity, entityHasEncryptedFields, fp, getComplianceMetadata, getEntityComplianceFields, getSuperAdminContext, setupRls, setupTenantFilter, wrapEmWithNativeQueryBlocking };
|
|
272
|
+
export { type ClassifiedProperty, ComplianceEventSubscriber, ComplianceLevel, ComplianceLevel as ComplianceLevelType, type ExtractInner, type ForklaunchPropertyBuilders, RetentionAction, RetentionAction as RetentionActionType, RetentionDuration, type RetentionPolicy, type RlsConfig, RlsEventSubscriber, TENANT_FILTER_NAME, type WithCompliance, createTenantFilterDef, defineComplianceEntity, entityHasEncryptedFields, fp, getAllRetentionPolicies, getComplianceMetadata, getEntityComplianceFields, getEntityRetention, getSuperAdminContext, parseDuration, setupRls, setupTenantFilter, wrapEmWithNativeQueryBlocking };
|
package/lib/persistence/index.js
CHANGED
|
@@ -22,15 +22,20 @@ var persistence_exports = {};
|
|
|
22
22
|
__export(persistence_exports, {
|
|
23
23
|
ComplianceEventSubscriber: () => ComplianceEventSubscriber,
|
|
24
24
|
ComplianceLevel: () => ComplianceLevel,
|
|
25
|
+
RetentionAction: () => RetentionAction,
|
|
26
|
+
RetentionDuration: () => RetentionDuration,
|
|
25
27
|
RlsEventSubscriber: () => RlsEventSubscriber,
|
|
26
28
|
TENANT_FILTER_NAME: () => TENANT_FILTER_NAME,
|
|
27
29
|
createTenantFilterDef: () => createTenantFilterDef,
|
|
28
30
|
defineComplianceEntity: () => defineComplianceEntity,
|
|
29
31
|
entityHasEncryptedFields: () => entityHasEncryptedFields,
|
|
30
32
|
fp: () => fp,
|
|
33
|
+
getAllRetentionPolicies: () => getAllRetentionPolicies,
|
|
31
34
|
getComplianceMetadata: () => getComplianceMetadata,
|
|
32
35
|
getEntityComplianceFields: () => getEntityComplianceFields,
|
|
36
|
+
getEntityRetention: () => getEntityRetention,
|
|
33
37
|
getSuperAdminContext: () => getSuperAdminContext,
|
|
38
|
+
parseDuration: () => parseDuration,
|
|
34
39
|
setupRls: () => setupRls,
|
|
35
40
|
setupTenantFilter: () => setupTenantFilter,
|
|
36
41
|
wrapEmWithNativeQueryBlocking: () => wrapEmWithNativeQueryBlocking
|
|
@@ -63,6 +68,47 @@ function entityHasEncryptedFields(entityName) {
|
|
|
63
68
|
}
|
|
64
69
|
return false;
|
|
65
70
|
}
|
|
71
|
+
var RetentionAction = {
|
|
72
|
+
delete: "delete",
|
|
73
|
+
anonymize: "anonymize"
|
|
74
|
+
};
|
|
75
|
+
var RetentionDuration = {
|
|
76
|
+
days: (n) => `P${n}D`,
|
|
77
|
+
months: (n) => `P${n}M`,
|
|
78
|
+
years: (n) => `P${n}Y`
|
|
79
|
+
};
|
|
80
|
+
var DURATION_REGEX = /^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?$/;
|
|
81
|
+
var MS_PER_DAY = 864e5;
|
|
82
|
+
var MIN_DURATION_MS = MS_PER_DAY;
|
|
83
|
+
function parseDuration(iso) {
|
|
84
|
+
const match = DURATION_REGEX.exec(iso);
|
|
85
|
+
if (!match) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`Invalid ISO 8601 duration: '${iso}'. Expected format: P[n]Y[n]M[n]D`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const years = parseInt(match[1] || "0", 10);
|
|
91
|
+
const months = parseInt(match[2] || "0", 10);
|
|
92
|
+
const days = parseInt(match[3] || "0", 10);
|
|
93
|
+
const totalDays = years * 365 + months * 30 + days;
|
|
94
|
+
const ms = totalDays * MS_PER_DAY;
|
|
95
|
+
if (ms < MIN_DURATION_MS) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
`Retention duration must be >= 1 day (P1D). Got: '${iso}' (${totalDays} days)`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return ms;
|
|
101
|
+
}
|
|
102
|
+
var retentionRegistry = /* @__PURE__ */ new Map();
|
|
103
|
+
function registerEntityRetention(entityName, policy) {
|
|
104
|
+
retentionRegistry.set(entityName, policy);
|
|
105
|
+
}
|
|
106
|
+
function getEntityRetention(entityName) {
|
|
107
|
+
return retentionRegistry.get(entityName);
|
|
108
|
+
}
|
|
109
|
+
function getAllRetentionPolicies() {
|
|
110
|
+
return retentionRegistry;
|
|
111
|
+
}
|
|
66
112
|
|
|
67
113
|
// src/persistence/compliancePropertyBuilder.ts
|
|
68
114
|
var import_core = require("@mikro-orm/core");
|
|
@@ -168,7 +214,19 @@ function defineComplianceEntity(meta) {
|
|
|
168
214
|
complianceFields.set(fieldName, level);
|
|
169
215
|
}
|
|
170
216
|
registerEntityCompliance(entityName, complianceFields);
|
|
171
|
-
|
|
217
|
+
if (meta.retention) {
|
|
218
|
+
parseDuration(meta.retention.duration);
|
|
219
|
+
if (!resolvedProperties["createdAt"]) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`Entity '${entityName}' has a retention policy but no 'createdAt' property. Retention requires createdAt to compute expiration.`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
registerEntityRetention(entityName, meta.retention);
|
|
225
|
+
}
|
|
226
|
+
const { retention: _retention, ...mikroMeta } = meta;
|
|
227
|
+
return (0, import_core2.defineEntity)(
|
|
228
|
+
mikroMeta
|
|
229
|
+
);
|
|
172
230
|
}
|
|
173
231
|
|
|
174
232
|
// src/encryption/fieldEncryptor.ts
|
|
@@ -449,15 +507,20 @@ function escapeSqlString(value) {
|
|
|
449
507
|
0 && (module.exports = {
|
|
450
508
|
ComplianceEventSubscriber,
|
|
451
509
|
ComplianceLevel,
|
|
510
|
+
RetentionAction,
|
|
511
|
+
RetentionDuration,
|
|
452
512
|
RlsEventSubscriber,
|
|
453
513
|
TENANT_FILTER_NAME,
|
|
454
514
|
createTenantFilterDef,
|
|
455
515
|
defineComplianceEntity,
|
|
456
516
|
entityHasEncryptedFields,
|
|
457
517
|
fp,
|
|
518
|
+
getAllRetentionPolicies,
|
|
458
519
|
getComplianceMetadata,
|
|
459
520
|
getEntityComplianceFields,
|
|
521
|
+
getEntityRetention,
|
|
460
522
|
getSuperAdminContext,
|
|
523
|
+
parseDuration,
|
|
461
524
|
setupRls,
|
|
462
525
|
setupTenantFilter,
|
|
463
526
|
wrapEmWithNativeQueryBlocking
|