@forklaunch/core 1.0.9 → 1.0.10
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 → contractDetails.types-BgnK-dCg.d.mts} +940 -940
- package/lib/{apiDefinition.types-Br0fDuBQ.d.ts → contractDetails.types-BgnK-dCg.d.ts} +940 -940
- package/lib/http/index.d.mts +2 -2
- package/lib/http/index.d.ts +2 -2
- package/lib/persistence/index.d.mts +48 -82
- package/lib/persistence/index.d.ts +48 -82
- package/lib/persistence/index.js +0 -7
- package/lib/persistence/index.js.map +1 -1
- package/lib/persistence/index.mjs +0 -6
- package/lib/persistence/index.mjs.map +1 -1
- package/lib/ws/index.d.mts +2 -2
- package/lib/ws/index.d.ts +2 -2
- package/package.json +3 -3
package/lib/http/index.d.mts
CHANGED
|
@@ -3,8 +3,8 @@ export { ParsedQs } from 'qs';
|
|
|
3
3
|
import { Prettify, SanitizePathSlashes, PrettyCamelCase, TypeSafeFunction, UnionToIntersection, EmptyObject } from '@forklaunch/common';
|
|
4
4
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
5
5
|
import { ServerOptions, IncomingMessage, ServerResponse } from 'node:http';
|
|
6
|
-
import { M as Method, P as PathParamHttpContractDetails, H as HttpContractDetails, E as ExpressLikeRouterOptions, a as SessionObject, b as ParamsObject, R as ResponsesObject, B as Body, Q as QueryObject, c as HeadersObject, V as VersionSchema, d as SchemaAuthMethods, e as ExpressLikeSchemaHandler, f as ResolvedSessionObject, C as ContractDetails, g as PathMatch, L as LiveTypeFunction, h as LiveSdkFunction, A as AuthMethodsBase, O as OpenTelemetryCollector, i as MetricsDefinition, j as ExpressLikeApplicationOptions, k as ParamsDictionary, l as VersionedRequests, m as AuthMethods, D as DecodeResource, n as BasicAuthMethods, F as ForklaunchRequest, o as MiddlewareContractDetails, p as ExpressLikeSchemaAuthMapper, q as ForklaunchNextFunction, r as ForklaunchResponse, s as ForklaunchResHeaders, t as ForklaunchStatusResponse, u as ForklaunchSendableData, T as TelemetryOptions, v as LoggerMeta, w as LogFn } from '../
|
|
7
|
-
export { x as AccessLevel, y as BodyObject, z as DefaultSubscriptionData, G as DocsConfiguration, I as ErrorContainer, J as ExpressLikeAuthMapper, K as ExpressLikeGlobalAuthOptions, N as ExpressLikeHandler, U as ExpressLikeSchemaGlobalAuthOptions, W as ExtractBody, X as ExtractContentType, Y as ExtractResponseBody, Z as ExtractedParamsObject, _ as FileBody, $ as ForklaunchBaseRequest, a0 as ForklaunchResErrors, a1 as HmacMethods, a2 as HttpMethod, a3 as JsonBody, a4 as JwtAuthMethods, a5 as LiveTypeFunctionRequestInit, a6 as MapParamsSchema, a7 as MapReqBodySchema, a8 as MapReqHeadersSchema, a9 as MapReqQuerySchema, aa as MapResBodyMapSchema, ab as MapResHeadersSchema, ac as MapSchema, ad as MapSessionSchema, ae as MapVersionedReqsSchema, af as MapVersionedRespsSchema, ag as MetricType, ah as MultipartForm, ai as NumberOnlyObject, aj as PathParamMethod, ak as PermissionSet, al as RawTypedResponseBody, am as RequestContext, an as ResolvedForklaunchAuthRequest, ao as ResolvedForklaunchRequest, ap as ResolvedForklaunchResponse, aq as ResponseBody, ar as ResponseCompiledSchema, as as ResponseShape, at as RoleSet, au as ServerSentEventBody, S as StringOnlyObject, av as TextBody, aw as TypedBody, ax as TypedRequestBody, ay as TypedResponseBody, az as UnknownBody, aA as UnknownResponseBody, aB as UrlEncodedForm, aC as VersionedResponses, aD as httpRequestsTotalCounter, aE as httpServerDurationHistogram } from '../
|
|
6
|
+
import { M as Method, P as PathParamHttpContractDetails, H as HttpContractDetails, E as ExpressLikeRouterOptions, a as SessionObject, b as ParamsObject, R as ResponsesObject, B as Body, Q as QueryObject, c as HeadersObject, V as VersionSchema, d as SchemaAuthMethods, e as ExpressLikeSchemaHandler, f as ResolvedSessionObject, C as ContractDetails, g as PathMatch, L as LiveTypeFunction, h as LiveSdkFunction, A as AuthMethodsBase, O as OpenTelemetryCollector, i as MetricsDefinition, j as ExpressLikeApplicationOptions, k as ParamsDictionary, l as VersionedRequests, m as AuthMethods, D as DecodeResource, n as BasicAuthMethods, F as ForklaunchRequest, o as MiddlewareContractDetails, p as ExpressLikeSchemaAuthMapper, q as ForklaunchNextFunction, r as ForklaunchResponse, s as ForklaunchResHeaders, t as ForklaunchStatusResponse, u as ForklaunchSendableData, T as TelemetryOptions, v as LoggerMeta, w as LogFn } from '../contractDetails.types-BgnK-dCg.mjs';
|
|
7
|
+
export { x as AccessLevel, y as BodyObject, z as DefaultSubscriptionData, G as DocsConfiguration, I as ErrorContainer, J as ExpressLikeAuthMapper, K as ExpressLikeGlobalAuthOptions, N as ExpressLikeHandler, U as ExpressLikeSchemaGlobalAuthOptions, W as ExtractBody, X as ExtractContentType, Y as ExtractResponseBody, Z as ExtractedParamsObject, _ as FileBody, $ as ForklaunchBaseRequest, a0 as ForklaunchResErrors, a1 as HmacMethods, a2 as HttpMethod, a3 as JsonBody, a4 as JwtAuthMethods, a5 as LiveTypeFunctionRequestInit, a6 as MapParamsSchema, a7 as MapReqBodySchema, a8 as MapReqHeadersSchema, a9 as MapReqQuerySchema, aa as MapResBodyMapSchema, ab as MapResHeadersSchema, ac as MapSchema, ad as MapSessionSchema, ae as MapVersionedReqsSchema, af as MapVersionedRespsSchema, ag as MetricType, ah as MultipartForm, ai as NumberOnlyObject, aj as PathParamMethod, ak as PermissionSet, al as RawTypedResponseBody, am as RequestContext, an as ResolvedForklaunchAuthRequest, ao as ResolvedForklaunchRequest, ap as ResolvedForklaunchResponse, aq as ResponseBody, ar as ResponseCompiledSchema, as as ResponseShape, at as RoleSet, au as ServerSentEventBody, S as StringOnlyObject, av as TextBody, aw as TypedBody, ax as TypedRequestBody, ay as TypedResponseBody, az as UnknownBody, aA as UnknownResponseBody, aB as UrlEncodedForm, aC as VersionedResponses, aD as httpRequestsTotalCounter, aE as httpServerDurationHistogram } from '../contractDetails.types-BgnK-dCg.mjs';
|
|
8
8
|
import { JWTPayload, JWK } from 'jose';
|
|
9
9
|
import { ZodSchemaValidator } from '@forklaunch/validator/zod';
|
|
10
10
|
import { FastMCP } from 'fastmcp';
|
package/lib/http/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export { ParsedQs } from 'qs';
|
|
|
3
3
|
import { Prettify, SanitizePathSlashes, PrettyCamelCase, TypeSafeFunction, UnionToIntersection, EmptyObject } from '@forklaunch/common';
|
|
4
4
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
5
5
|
import { ServerOptions, IncomingMessage, ServerResponse } from 'node:http';
|
|
6
|
-
import { M as Method, P as PathParamHttpContractDetails, H as HttpContractDetails, E as ExpressLikeRouterOptions, a as SessionObject, b as ParamsObject, R as ResponsesObject, B as Body, Q as QueryObject, c as HeadersObject, V as VersionSchema, d as SchemaAuthMethods, e as ExpressLikeSchemaHandler, f as ResolvedSessionObject, C as ContractDetails, g as PathMatch, L as LiveTypeFunction, h as LiveSdkFunction, A as AuthMethodsBase, O as OpenTelemetryCollector, i as MetricsDefinition, j as ExpressLikeApplicationOptions, k as ParamsDictionary, l as VersionedRequests, m as AuthMethods, D as DecodeResource, n as BasicAuthMethods, F as ForklaunchRequest, o as MiddlewareContractDetails, p as ExpressLikeSchemaAuthMapper, q as ForklaunchNextFunction, r as ForklaunchResponse, s as ForklaunchResHeaders, t as ForklaunchStatusResponse, u as ForklaunchSendableData, T as TelemetryOptions, v as LoggerMeta, w as LogFn } from '../
|
|
7
|
-
export { x as AccessLevel, y as BodyObject, z as DefaultSubscriptionData, G as DocsConfiguration, I as ErrorContainer, J as ExpressLikeAuthMapper, K as ExpressLikeGlobalAuthOptions, N as ExpressLikeHandler, U as ExpressLikeSchemaGlobalAuthOptions, W as ExtractBody, X as ExtractContentType, Y as ExtractResponseBody, Z as ExtractedParamsObject, _ as FileBody, $ as ForklaunchBaseRequest, a0 as ForklaunchResErrors, a1 as HmacMethods, a2 as HttpMethod, a3 as JsonBody, a4 as JwtAuthMethods, a5 as LiveTypeFunctionRequestInit, a6 as MapParamsSchema, a7 as MapReqBodySchema, a8 as MapReqHeadersSchema, a9 as MapReqQuerySchema, aa as MapResBodyMapSchema, ab as MapResHeadersSchema, ac as MapSchema, ad as MapSessionSchema, ae as MapVersionedReqsSchema, af as MapVersionedRespsSchema, ag as MetricType, ah as MultipartForm, ai as NumberOnlyObject, aj as PathParamMethod, ak as PermissionSet, al as RawTypedResponseBody, am as RequestContext, an as ResolvedForklaunchAuthRequest, ao as ResolvedForklaunchRequest, ap as ResolvedForklaunchResponse, aq as ResponseBody, ar as ResponseCompiledSchema, as as ResponseShape, at as RoleSet, au as ServerSentEventBody, S as StringOnlyObject, av as TextBody, aw as TypedBody, ax as TypedRequestBody, ay as TypedResponseBody, az as UnknownBody, aA as UnknownResponseBody, aB as UrlEncodedForm, aC as VersionedResponses, aD as httpRequestsTotalCounter, aE as httpServerDurationHistogram } from '../
|
|
6
|
+
import { M as Method, P as PathParamHttpContractDetails, H as HttpContractDetails, E as ExpressLikeRouterOptions, a as SessionObject, b as ParamsObject, R as ResponsesObject, B as Body, Q as QueryObject, c as HeadersObject, V as VersionSchema, d as SchemaAuthMethods, e as ExpressLikeSchemaHandler, f as ResolvedSessionObject, C as ContractDetails, g as PathMatch, L as LiveTypeFunction, h as LiveSdkFunction, A as AuthMethodsBase, O as OpenTelemetryCollector, i as MetricsDefinition, j as ExpressLikeApplicationOptions, k as ParamsDictionary, l as VersionedRequests, m as AuthMethods, D as DecodeResource, n as BasicAuthMethods, F as ForklaunchRequest, o as MiddlewareContractDetails, p as ExpressLikeSchemaAuthMapper, q as ForklaunchNextFunction, r as ForklaunchResponse, s as ForklaunchResHeaders, t as ForklaunchStatusResponse, u as ForklaunchSendableData, T as TelemetryOptions, v as LoggerMeta, w as LogFn } from '../contractDetails.types-BgnK-dCg.js';
|
|
7
|
+
export { x as AccessLevel, y as BodyObject, z as DefaultSubscriptionData, G as DocsConfiguration, I as ErrorContainer, J as ExpressLikeAuthMapper, K as ExpressLikeGlobalAuthOptions, N as ExpressLikeHandler, U as ExpressLikeSchemaGlobalAuthOptions, W as ExtractBody, X as ExtractContentType, Y as ExtractResponseBody, Z as ExtractedParamsObject, _ as FileBody, $ as ForklaunchBaseRequest, a0 as ForklaunchResErrors, a1 as HmacMethods, a2 as HttpMethod, a3 as JsonBody, a4 as JwtAuthMethods, a5 as LiveTypeFunctionRequestInit, a6 as MapParamsSchema, a7 as MapReqBodySchema, a8 as MapReqHeadersSchema, a9 as MapReqQuerySchema, aa as MapResBodyMapSchema, ab as MapResHeadersSchema, ac as MapSchema, ad as MapSessionSchema, ae as MapVersionedReqsSchema, af as MapVersionedRespsSchema, ag as MetricType, ah as MultipartForm, ai as NumberOnlyObject, aj as PathParamMethod, ak as PermissionSet, al as RawTypedResponseBody, am as RequestContext, an as ResolvedForklaunchAuthRequest, ao as ResolvedForklaunchRequest, ap as ResolvedForklaunchResponse, aq as ResponseBody, ar as ResponseCompiledSchema, as as ResponseShape, at as RoleSet, au as ServerSentEventBody, S as StringOnlyObject, av as TextBody, aw as TypedBody, ax as TypedRequestBody, ay as TypedResponseBody, az as UnknownBody, aA as UnknownResponseBody, aB as UrlEncodedForm, aC as VersionedResponses, aD as httpRequestsTotalCounter, aE as httpServerDurationHistogram } from '../contractDetails.types-BgnK-dCg.js';
|
|
8
8
|
import { JWTPayload, JWK } from 'jose';
|
|
9
9
|
import { ZodSchemaValidator } from '@forklaunch/validator/zod';
|
|
10
10
|
import { FastMCP } from 'fastmcp';
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { PropertyBuilders, UniversalPropertyOptionsBuilder,
|
|
1
|
+
import { PropertyChain, PropertyBuilders, UniversalPropertyOptionsBuilder, EmptyOptions, EntityMetadataWithProperties, EntitySchemaWithMeta, InferEntityFromProperties, EventSubscriber, EventArgs, FilterDef, EntityManager, MikroORM } from '@mikro-orm/core';
|
|
2
2
|
export { InferEntity } from '@mikro-orm/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Classification levels for entity field compliance.
|
|
6
|
-
* Drives encryption (phi/pci), audit log redaction (all non-none), and compliance reporting.
|
|
7
6
|
*/
|
|
8
7
|
declare const ComplianceLevel: {
|
|
9
8
|
readonly pii: "pii";
|
|
@@ -16,56 +15,40 @@ declare function getComplianceMetadata(entityName: string, fieldName: string): C
|
|
|
16
15
|
declare function getEntityComplianceFields(entityName: string): Map<string, ComplianceLevel> | undefined;
|
|
17
16
|
declare function entityHasEncryptedFields(entityName: string): boolean;
|
|
18
17
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
* Uses a regular string property (not unique symbol) so it survives
|
|
30
|
-
* .d.ts boundaries across packages without identity divergence.
|
|
31
|
-
* MikroORM's InferBuilderValue only checks ~type and ~options — it
|
|
32
|
-
* ignores this property.
|
|
18
|
+
* A wrapper object that holds the raw MikroORM PropertyChain in `__inner`
|
|
19
|
+
* and the compliance classification in `__compliance`.
|
|
20
|
+
*
|
|
21
|
+
* This is what `.compliance()` returns. `defineComplianceEntity` requires
|
|
22
|
+
* this wrapper for scalar properties, extracts `__inner` for the return
|
|
23
|
+
* type (so InferEntity sees pure PropertyChain), and reads `__compliance`
|
|
24
|
+
* for the metadata registry.
|
|
25
|
+
*
|
|
26
|
+
* At runtime this is still a Proxy wrapping the MikroORM builder —
|
|
27
|
+
* the `__inner`/`__compliance` are type-level only.
|
|
33
28
|
*/
|
|
34
|
-
interface ClassifiedProperty {
|
|
35
|
-
readonly
|
|
29
|
+
interface ClassifiedProperty<Value = unknown, Options = unknown> {
|
|
30
|
+
readonly __inner: PropertyChain<Value, Options>;
|
|
31
|
+
readonly __compliance: ComplianceLevel;
|
|
36
32
|
}
|
|
37
33
|
/**
|
|
38
|
-
* An unclassified scalar property builder.
|
|
39
|
-
*
|
|
40
|
-
* `.compliance()`
|
|
41
|
-
*
|
|
42
|
-
* Carries the `NEEDS_CLASSIFICATION` brand — `defineComplianceEntity`
|
|
43
|
-
* rejects properties with this brand.
|
|
34
|
+
* An unclassified scalar property builder. All PropertyChain methods
|
|
35
|
+
* are remapped to return ForklaunchPropertyChain (preserving .compliance()
|
|
36
|
+
* through chains). `.compliance(level)` returns a ClassifiedProperty wrapper.
|
|
44
37
|
*
|
|
45
|
-
*
|
|
46
|
-
* from MikroORM (no brand) — which `defineEntity` and `InferEntity`
|
|
47
|
-
* understand natively.
|
|
38
|
+
* NOT assignable to ClassifiedProperty — defineComplianceEntity rejects it.
|
|
48
39
|
*/
|
|
49
|
-
type ForklaunchPropertyChain<Value, Options> = RemapReturns<Value, Options> &
|
|
50
|
-
|
|
51
|
-
* Classify this field's compliance level. Returns the raw MikroORM
|
|
52
|
-
* `PropertyChain` so `InferEntity` works without interference.
|
|
53
|
-
*/
|
|
54
|
-
compliance(level: ComplianceLevel): PropertyChain<Value, Options> & ClassifiedProperty;
|
|
40
|
+
type ForklaunchPropertyChain<Value, Options> = RemapReturns<Value, Options> & {
|
|
41
|
+
compliance(level: ComplianceLevel): ClassifiedProperty<Value, Options>;
|
|
55
42
|
};
|
|
56
43
|
type RemapReturns<Value, Options> = {
|
|
57
44
|
[K in keyof PropertyChain<Value, Options>]: PropertyChain<Value, Options>[K] extends (...args: infer A) => PropertyChain<infer V2, infer O2> ? (...args: A) => ForklaunchPropertyChain<V2, O2> : PropertyChain<Value, Options>[K];
|
|
58
45
|
};
|
|
59
46
|
type RelationBuilderKeys = 'manyToOne' | 'oneToMany' | 'manyToMany' | 'oneToOne' | 'embedded';
|
|
60
|
-
/**
|
|
61
|
-
* Generic methods on PropertyBuilders that need explicit signatures
|
|
62
|
-
* because mapped types collapse their type parameters.
|
|
63
|
-
*/
|
|
64
47
|
type GenericBuilderKeys = 'json' | 'formula' | 'type' | 'bigint' | 'array' | 'decimal' | 'enum';
|
|
65
48
|
/**
|
|
66
49
|
* The type of `fp`:
|
|
67
|
-
* - Scalar methods →
|
|
68
|
-
* - Relation methods → raw
|
|
50
|
+
* - Scalar methods → ForklaunchPropertyChain (must call .compliance())
|
|
51
|
+
* - Relation methods → raw PropertyChain (auto-classified at runtime)
|
|
69
52
|
* - Generic methods → explicit signatures preserving type parameters
|
|
70
53
|
*/
|
|
71
54
|
type ForklaunchPropertyBuilders = {
|
|
@@ -81,6 +64,15 @@ type ForklaunchPropertyBuilders = {
|
|
|
81
64
|
decimal: <Mode extends 'number' | 'string' = 'string'>(mode?: Mode) => ForklaunchPropertyChain<Mode extends 'number' ? number : string, EmptyOptions>;
|
|
82
65
|
enum: <const T extends (number | string)[] | (() => Record<string, unknown>)>(items?: T) => ForklaunchPropertyChain<T extends () => Record<string, unknown> ? T extends () => infer R ? R[keyof R] : never : T extends (infer Value)[] ? Value : T, EmptyOptions>;
|
|
83
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* For each property in T:
|
|
69
|
+
* - ClassifiedProperty<V,O> → PropertyChain<V,O> (extract __inner)
|
|
70
|
+
* - Functions (lazy relations) → pass through unchanged
|
|
71
|
+
* - Raw PropertyChain (relations from fp.manyToOne) → pass through
|
|
72
|
+
*/
|
|
73
|
+
type ExtractInner<T> = {
|
|
74
|
+
[K in keyof T]: T[K] extends ClassifiedProperty<infer V, infer O> ? PropertyChain<V, O> : T[K];
|
|
75
|
+
};
|
|
84
76
|
|
|
85
77
|
/**
|
|
86
78
|
* ForkLaunch property builder. Drop-in replacement for MikroORM's `p`
|
|
@@ -108,53 +100,27 @@ type ForklaunchPropertyBuilders = {
|
|
|
108
100
|
declare const fp: ForklaunchPropertyBuilders;
|
|
109
101
|
|
|
110
102
|
/**
|
|
111
|
-
*
|
|
112
|
-
* (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* sees pure PropertyChain types across package boundaries.
|
|
121
|
-
*/
|
|
122
|
-
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 & RejectUnclassified$1<TProperties>, TPK, TBase, TRepository, TForceObject>): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<TProperties, TPK, TBase, TRepository, TForceObject>, TBase, TProperties>;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Rejects properties with NeedsClassification brand (same check
|
|
126
|
-
* as defineComplianceEntity).
|
|
103
|
+
* Validates each property:
|
|
104
|
+
* - ClassifiedProperty (from .compliance()) → accepted
|
|
105
|
+
* - Functions (lazy relations) → pass through (no return type eval)
|
|
106
|
+
* - Raw PropertyChain (relations from fp.manyToOne) → accepted
|
|
107
|
+
* - ForklaunchPropertyChain (fp.string() without .compliance()) → rejected
|
|
108
|
+
* (it has .compliance method, which ClassifiedProperty doesn't)
|
|
109
|
+
* - Plain p.string() → rejected (not ClassifiedProperty, not a function)
|
|
110
|
+
*
|
|
111
|
+
* Uses ClassifiedProperty as the required type for non-function scalars.
|
|
127
112
|
*/
|
|
128
|
-
type
|
|
129
|
-
[K in keyof T]: T[K] extends
|
|
113
|
+
type ValidateProperties<T> = {
|
|
114
|
+
[K in keyof T]: T[K] extends ClassifiedProperty ? T[K] : T[K] extends (...args: never[]) => unknown ? T[K] : ClassifiedProperty;
|
|
130
115
|
};
|
|
131
116
|
/**
|
|
132
|
-
*
|
|
133
|
-
* returning the underlying PropertyChain.
|
|
134
|
-
*/
|
|
135
|
-
type StripBrand<T> = T extends PropertyChain<infer V, infer O> & ClassifiedProperty ? PropertyChain<V, O> : T;
|
|
136
|
-
/**
|
|
137
|
-
* Wraps shared base properties to:
|
|
138
|
-
* 1. Validate all properties have `.compliance()` called (compile check)
|
|
139
|
-
* 2. Strip the ClassifiedProperty brand from the output types
|
|
140
|
-
*
|
|
141
|
-
* Without this wrapper, spreading base properties into entities
|
|
142
|
-
* leaks the ClassifiedProperty brand across package boundaries,
|
|
143
|
-
* causing type identity mismatches.
|
|
117
|
+
* Wrapper around MikroORM's `defineEntity` that enforces compliance.
|
|
144
118
|
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* id: fp.uuid().primary().onCreate(() => v4()).compliance('none'),
|
|
149
|
-
* createdAt: fp.datetime().onCreate(() => new Date()).compliance('none'),
|
|
150
|
-
* updatedAt: fp.datetime().onCreate(() => new Date())
|
|
151
|
-
* .onUpdate(() => new Date()).compliance('none')
|
|
152
|
-
* });
|
|
153
|
-
* ```
|
|
119
|
+
* Input: requires ClassifiedProperty wrappers on scalar properties.
|
|
120
|
+
* Output: extracts the inner PropertyChain from each wrapper so
|
|
121
|
+
* InferEntity sees pure MikroORM types — no brand, no interference.
|
|
154
122
|
*/
|
|
155
|
-
declare function
|
|
156
|
-
[K in keyof T]: StripBrand<T[K]>;
|
|
157
|
-
};
|
|
123
|
+
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>): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<ExtractInner<TProperties>, TPK, TBase, TRepository, TForceObject>, TBase, ExtractInner<TProperties>>;
|
|
158
124
|
|
|
159
125
|
declare class FieldEncryptor {
|
|
160
126
|
private readonly masterKey;
|
|
@@ -303,4 +269,4 @@ declare class RlsEventSubscriber implements EventSubscriber {
|
|
|
303
269
|
*/
|
|
304
270
|
declare function setupRls(orm: MikroORM, config?: RlsConfig): void;
|
|
305
271
|
|
|
306
|
-
export { type ClassifiedProperty, ComplianceEventSubscriber, ComplianceLevel, ComplianceLevel as ComplianceLevelType, type
|
|
272
|
+
export { type ClassifiedProperty, ComplianceEventSubscriber, ComplianceLevel, ComplianceLevel as ComplianceLevelType, type ExtractInner, type ForklaunchPropertyBuilders, type ForklaunchPropertyChain, type RlsConfig, RlsEventSubscriber, TENANT_FILTER_NAME, createTenantFilterDef, defineComplianceEntity, entityHasEncryptedFields, fp, getComplianceMetadata, getEntityComplianceFields, getSuperAdminContext, setupRls, setupTenantFilter, wrapEmWithNativeQueryBlocking };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { PropertyBuilders, UniversalPropertyOptionsBuilder,
|
|
1
|
+
import { PropertyChain, PropertyBuilders, UniversalPropertyOptionsBuilder, EmptyOptions, EntityMetadataWithProperties, EntitySchemaWithMeta, InferEntityFromProperties, EventSubscriber, EventArgs, FilterDef, EntityManager, MikroORM } from '@mikro-orm/core';
|
|
2
2
|
export { InferEntity } from '@mikro-orm/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Classification levels for entity field compliance.
|
|
6
|
-
* Drives encryption (phi/pci), audit log redaction (all non-none), and compliance reporting.
|
|
7
6
|
*/
|
|
8
7
|
declare const ComplianceLevel: {
|
|
9
8
|
readonly pii: "pii";
|
|
@@ -16,56 +15,40 @@ declare function getComplianceMetadata(entityName: string, fieldName: string): C
|
|
|
16
15
|
declare function getEntityComplianceFields(entityName: string): Map<string, ComplianceLevel> | undefined;
|
|
17
16
|
declare function entityHasEncryptedFields(entityName: string): boolean;
|
|
18
17
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
* Uses a regular string property (not unique symbol) so it survives
|
|
30
|
-
* .d.ts boundaries across packages without identity divergence.
|
|
31
|
-
* MikroORM's InferBuilderValue only checks ~type and ~options — it
|
|
32
|
-
* ignores this property.
|
|
18
|
+
* A wrapper object that holds the raw MikroORM PropertyChain in `__inner`
|
|
19
|
+
* and the compliance classification in `__compliance`.
|
|
20
|
+
*
|
|
21
|
+
* This is what `.compliance()` returns. `defineComplianceEntity` requires
|
|
22
|
+
* this wrapper for scalar properties, extracts `__inner` for the return
|
|
23
|
+
* type (so InferEntity sees pure PropertyChain), and reads `__compliance`
|
|
24
|
+
* for the metadata registry.
|
|
25
|
+
*
|
|
26
|
+
* At runtime this is still a Proxy wrapping the MikroORM builder —
|
|
27
|
+
* the `__inner`/`__compliance` are type-level only.
|
|
33
28
|
*/
|
|
34
|
-
interface ClassifiedProperty {
|
|
35
|
-
readonly
|
|
29
|
+
interface ClassifiedProperty<Value = unknown, Options = unknown> {
|
|
30
|
+
readonly __inner: PropertyChain<Value, Options>;
|
|
31
|
+
readonly __compliance: ComplianceLevel;
|
|
36
32
|
}
|
|
37
33
|
/**
|
|
38
|
-
* An unclassified scalar property builder.
|
|
39
|
-
*
|
|
40
|
-
* `.compliance()`
|
|
41
|
-
*
|
|
42
|
-
* Carries the `NEEDS_CLASSIFICATION` brand — `defineComplianceEntity`
|
|
43
|
-
* rejects properties with this brand.
|
|
34
|
+
* An unclassified scalar property builder. All PropertyChain methods
|
|
35
|
+
* are remapped to return ForklaunchPropertyChain (preserving .compliance()
|
|
36
|
+
* through chains). `.compliance(level)` returns a ClassifiedProperty wrapper.
|
|
44
37
|
*
|
|
45
|
-
*
|
|
46
|
-
* from MikroORM (no brand) — which `defineEntity` and `InferEntity`
|
|
47
|
-
* understand natively.
|
|
38
|
+
* NOT assignable to ClassifiedProperty — defineComplianceEntity rejects it.
|
|
48
39
|
*/
|
|
49
|
-
type ForklaunchPropertyChain<Value, Options> = RemapReturns<Value, Options> &
|
|
50
|
-
|
|
51
|
-
* Classify this field's compliance level. Returns the raw MikroORM
|
|
52
|
-
* `PropertyChain` so `InferEntity` works without interference.
|
|
53
|
-
*/
|
|
54
|
-
compliance(level: ComplianceLevel): PropertyChain<Value, Options> & ClassifiedProperty;
|
|
40
|
+
type ForklaunchPropertyChain<Value, Options> = RemapReturns<Value, Options> & {
|
|
41
|
+
compliance(level: ComplianceLevel): ClassifiedProperty<Value, Options>;
|
|
55
42
|
};
|
|
56
43
|
type RemapReturns<Value, Options> = {
|
|
57
44
|
[K in keyof PropertyChain<Value, Options>]: PropertyChain<Value, Options>[K] extends (...args: infer A) => PropertyChain<infer V2, infer O2> ? (...args: A) => ForklaunchPropertyChain<V2, O2> : PropertyChain<Value, Options>[K];
|
|
58
45
|
};
|
|
59
46
|
type RelationBuilderKeys = 'manyToOne' | 'oneToMany' | 'manyToMany' | 'oneToOne' | 'embedded';
|
|
60
|
-
/**
|
|
61
|
-
* Generic methods on PropertyBuilders that need explicit signatures
|
|
62
|
-
* because mapped types collapse their type parameters.
|
|
63
|
-
*/
|
|
64
47
|
type GenericBuilderKeys = 'json' | 'formula' | 'type' | 'bigint' | 'array' | 'decimal' | 'enum';
|
|
65
48
|
/**
|
|
66
49
|
* The type of `fp`:
|
|
67
|
-
* - Scalar methods →
|
|
68
|
-
* - Relation methods → raw
|
|
50
|
+
* - Scalar methods → ForklaunchPropertyChain (must call .compliance())
|
|
51
|
+
* - Relation methods → raw PropertyChain (auto-classified at runtime)
|
|
69
52
|
* - Generic methods → explicit signatures preserving type parameters
|
|
70
53
|
*/
|
|
71
54
|
type ForklaunchPropertyBuilders = {
|
|
@@ -81,6 +64,15 @@ type ForklaunchPropertyBuilders = {
|
|
|
81
64
|
decimal: <Mode extends 'number' | 'string' = 'string'>(mode?: Mode) => ForklaunchPropertyChain<Mode extends 'number' ? number : string, EmptyOptions>;
|
|
82
65
|
enum: <const T extends (number | string)[] | (() => Record<string, unknown>)>(items?: T) => ForklaunchPropertyChain<T extends () => Record<string, unknown> ? T extends () => infer R ? R[keyof R] : never : T extends (infer Value)[] ? Value : T, EmptyOptions>;
|
|
83
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* For each property in T:
|
|
69
|
+
* - ClassifiedProperty<V,O> → PropertyChain<V,O> (extract __inner)
|
|
70
|
+
* - Functions (lazy relations) → pass through unchanged
|
|
71
|
+
* - Raw PropertyChain (relations from fp.manyToOne) → pass through
|
|
72
|
+
*/
|
|
73
|
+
type ExtractInner<T> = {
|
|
74
|
+
[K in keyof T]: T[K] extends ClassifiedProperty<infer V, infer O> ? PropertyChain<V, O> : T[K];
|
|
75
|
+
};
|
|
84
76
|
|
|
85
77
|
/**
|
|
86
78
|
* ForkLaunch property builder. Drop-in replacement for MikroORM's `p`
|
|
@@ -108,53 +100,27 @@ type ForklaunchPropertyBuilders = {
|
|
|
108
100
|
declare const fp: ForklaunchPropertyBuilders;
|
|
109
101
|
|
|
110
102
|
/**
|
|
111
|
-
*
|
|
112
|
-
* (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* sees pure PropertyChain types across package boundaries.
|
|
121
|
-
*/
|
|
122
|
-
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 & RejectUnclassified$1<TProperties>, TPK, TBase, TRepository, TForceObject>): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<TProperties, TPK, TBase, TRepository, TForceObject>, TBase, TProperties>;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Rejects properties with NeedsClassification brand (same check
|
|
126
|
-
* as defineComplianceEntity).
|
|
103
|
+
* Validates each property:
|
|
104
|
+
* - ClassifiedProperty (from .compliance()) → accepted
|
|
105
|
+
* - Functions (lazy relations) → pass through (no return type eval)
|
|
106
|
+
* - Raw PropertyChain (relations from fp.manyToOne) → accepted
|
|
107
|
+
* - ForklaunchPropertyChain (fp.string() without .compliance()) → rejected
|
|
108
|
+
* (it has .compliance method, which ClassifiedProperty doesn't)
|
|
109
|
+
* - Plain p.string() → rejected (not ClassifiedProperty, not a function)
|
|
110
|
+
*
|
|
111
|
+
* Uses ClassifiedProperty as the required type for non-function scalars.
|
|
127
112
|
*/
|
|
128
|
-
type
|
|
129
|
-
[K in keyof T]: T[K] extends
|
|
113
|
+
type ValidateProperties<T> = {
|
|
114
|
+
[K in keyof T]: T[K] extends ClassifiedProperty ? T[K] : T[K] extends (...args: never[]) => unknown ? T[K] : ClassifiedProperty;
|
|
130
115
|
};
|
|
131
116
|
/**
|
|
132
|
-
*
|
|
133
|
-
* returning the underlying PropertyChain.
|
|
134
|
-
*/
|
|
135
|
-
type StripBrand<T> = T extends PropertyChain<infer V, infer O> & ClassifiedProperty ? PropertyChain<V, O> : T;
|
|
136
|
-
/**
|
|
137
|
-
* Wraps shared base properties to:
|
|
138
|
-
* 1. Validate all properties have `.compliance()` called (compile check)
|
|
139
|
-
* 2. Strip the ClassifiedProperty brand from the output types
|
|
140
|
-
*
|
|
141
|
-
* Without this wrapper, spreading base properties into entities
|
|
142
|
-
* leaks the ClassifiedProperty brand across package boundaries,
|
|
143
|
-
* causing type identity mismatches.
|
|
117
|
+
* Wrapper around MikroORM's `defineEntity` that enforces compliance.
|
|
144
118
|
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* id: fp.uuid().primary().onCreate(() => v4()).compliance('none'),
|
|
149
|
-
* createdAt: fp.datetime().onCreate(() => new Date()).compliance('none'),
|
|
150
|
-
* updatedAt: fp.datetime().onCreate(() => new Date())
|
|
151
|
-
* .onUpdate(() => new Date()).compliance('none')
|
|
152
|
-
* });
|
|
153
|
-
* ```
|
|
119
|
+
* Input: requires ClassifiedProperty wrappers on scalar properties.
|
|
120
|
+
* Output: extracts the inner PropertyChain from each wrapper so
|
|
121
|
+
* InferEntity sees pure MikroORM types — no brand, no interference.
|
|
154
122
|
*/
|
|
155
|
-
declare function
|
|
156
|
-
[K in keyof T]: StripBrand<T[K]>;
|
|
157
|
-
};
|
|
123
|
+
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>): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<ExtractInner<TProperties>, TPK, TBase, TRepository, TForceObject>, TBase, ExtractInner<TProperties>>;
|
|
158
124
|
|
|
159
125
|
declare class FieldEncryptor {
|
|
160
126
|
private readonly masterKey;
|
|
@@ -303,4 +269,4 @@ declare class RlsEventSubscriber implements EventSubscriber {
|
|
|
303
269
|
*/
|
|
304
270
|
declare function setupRls(orm: MikroORM, config?: RlsConfig): void;
|
|
305
271
|
|
|
306
|
-
export { type ClassifiedProperty, ComplianceEventSubscriber, ComplianceLevel, ComplianceLevel as ComplianceLevelType, type
|
|
272
|
+
export { type ClassifiedProperty, ComplianceEventSubscriber, ComplianceLevel, ComplianceLevel as ComplianceLevelType, type ExtractInner, type ForklaunchPropertyBuilders, type ForklaunchPropertyChain, type RlsConfig, RlsEventSubscriber, TENANT_FILTER_NAME, createTenantFilterDef, defineComplianceEntity, entityHasEncryptedFields, fp, getComplianceMetadata, getEntityComplianceFields, getSuperAdminContext, setupRls, setupTenantFilter, wrapEmWithNativeQueryBlocking };
|
package/lib/persistence/index.js
CHANGED
|
@@ -25,7 +25,6 @@ __export(persistence_exports, {
|
|
|
25
25
|
RlsEventSubscriber: () => RlsEventSubscriber,
|
|
26
26
|
TENANT_FILTER_NAME: () => TENANT_FILTER_NAME,
|
|
27
27
|
createTenantFilterDef: () => createTenantFilterDef,
|
|
28
|
-
defineBaseProperties: () => defineBaseProperties,
|
|
29
28
|
defineComplianceEntity: () => defineComplianceEntity,
|
|
30
29
|
entityHasEncryptedFields: () => entityHasEncryptedFields,
|
|
31
30
|
fp: () => fp,
|
|
@@ -172,11 +171,6 @@ function defineComplianceEntity(meta) {
|
|
|
172
171
|
return (0, import_core2.defineEntity)(meta);
|
|
173
172
|
}
|
|
174
173
|
|
|
175
|
-
// src/persistence/defineBaseProperties.ts
|
|
176
|
-
function defineBaseProperties(properties) {
|
|
177
|
-
return properties;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
174
|
// src/encryption/fieldEncryptor.ts
|
|
181
175
|
var DecryptionError = class extends Error {
|
|
182
176
|
name = "DecryptionError";
|
|
@@ -458,7 +452,6 @@ function escapeSqlString(value) {
|
|
|
458
452
|
RlsEventSubscriber,
|
|
459
453
|
TENANT_FILTER_NAME,
|
|
460
454
|
createTenantFilterDef,
|
|
461
|
-
defineBaseProperties,
|
|
462
455
|
defineComplianceEntity,
|
|
463
456
|
entityHasEncryptedFields,
|
|
464
457
|
fp,
|