@forklaunch/core 0.19.4 → 1.0.1

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.
@@ -1,13 +1,13 @@
1
1
  import { Prettify } from '@forklaunch/common';
2
2
  import { AnySchemaValidator, IdiomaticSchema, Schema } from '@forklaunch/validator';
3
- import { EntitySchema, InferEntityFromProperties } from '@mikro-orm/core';
3
+ import { EntitySchema, InferEntity } from '@mikro-orm/core';
4
4
 
5
5
  declare function requestMapper<SV extends AnySchemaValidator, DomainSchema extends IdiomaticSchema<SV>, Entity extends EntitySchema, AdditionalArgs extends unknown[] = []>({ schemaValidator, schema, entity, mapperDefinition }: {
6
6
  schemaValidator: SV;
7
7
  schema: DomainSchema;
8
8
  entity: Entity;
9
9
  mapperDefinition: {
10
- toEntity: (dto: Schema<DomainSchema, SV>, ...args: AdditionalArgs) => Promise<InferEntityFromProperties<Entity>>;
10
+ toEntity: (dto: Schema<DomainSchema, SV>, ...args: AdditionalArgs) => Promise<InferEntity<Entity>>;
11
11
  };
12
12
  }): {
13
13
  entity: Entity;
@@ -16,12 +16,12 @@ declare function requestMapper<SV extends AnySchemaValidator, DomainSchema exten
16
16
  declare function responseMapper<SV extends AnySchemaValidator, DomainSchema extends IdiomaticSchema<SV>, Entity extends EntitySchema, AdditionalArgs extends unknown[] = []>({ schemaValidator, schema, entity, mapperDefinition }: {
17
17
  schemaValidator: SV;
18
18
  schema: DomainSchema;
19
- entity: InferEntityFromProperties<Entity>;
19
+ entity: Entity;
20
20
  mapperDefinition: {
21
- toDto: (entity: InferEntityFromProperties<Entity>, ...args: AdditionalArgs) => Promise<Schema<DomainSchema, SV>>;
21
+ toDto: (entity: InferEntity<Entity>, ...args: AdditionalArgs) => Promise<Schema<DomainSchema, SV>>;
22
22
  };
23
23
  }): Prettify<{
24
- entity: InferEntityFromProperties<Entity>;
24
+ entity: Entity;
25
25
  schema: DomainSchema;
26
26
  } & typeof mapperDefinition>;
27
27
 
@@ -1,13 +1,13 @@
1
1
  import { Prettify } from '@forklaunch/common';
2
2
  import { AnySchemaValidator, IdiomaticSchema, Schema } from '@forklaunch/validator';
3
- import { EntitySchema, InferEntityFromProperties } from '@mikro-orm/core';
3
+ import { EntitySchema, InferEntity } from '@mikro-orm/core';
4
4
 
5
5
  declare function requestMapper<SV extends AnySchemaValidator, DomainSchema extends IdiomaticSchema<SV>, Entity extends EntitySchema, AdditionalArgs extends unknown[] = []>({ schemaValidator, schema, entity, mapperDefinition }: {
6
6
  schemaValidator: SV;
7
7
  schema: DomainSchema;
8
8
  entity: Entity;
9
9
  mapperDefinition: {
10
- toEntity: (dto: Schema<DomainSchema, SV>, ...args: AdditionalArgs) => Promise<InferEntityFromProperties<Entity>>;
10
+ toEntity: (dto: Schema<DomainSchema, SV>, ...args: AdditionalArgs) => Promise<InferEntity<Entity>>;
11
11
  };
12
12
  }): {
13
13
  entity: Entity;
@@ -16,12 +16,12 @@ declare function requestMapper<SV extends AnySchemaValidator, DomainSchema exten
16
16
  declare function responseMapper<SV extends AnySchemaValidator, DomainSchema extends IdiomaticSchema<SV>, Entity extends EntitySchema, AdditionalArgs extends unknown[] = []>({ schemaValidator, schema, entity, mapperDefinition }: {
17
17
  schemaValidator: SV;
18
18
  schema: DomainSchema;
19
- entity: InferEntityFromProperties<Entity>;
19
+ entity: Entity;
20
20
  mapperDefinition: {
21
- toDto: (entity: InferEntityFromProperties<Entity>, ...args: AdditionalArgs) => Promise<Schema<DomainSchema, SV>>;
21
+ toDto: (entity: InferEntity<Entity>, ...args: AdditionalArgs) => Promise<Schema<DomainSchema, SV>>;
22
22
  };
23
23
  }): Prettify<{
24
- entity: InferEntityFromProperties<Entity>;
24
+ entity: Entity;
25
25
  schema: DomainSchema;
26
26
  } & typeof mapperDefinition>;
27
27
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mappers/index.ts","../../src/mappers/mapper.ts","../../src/mappers/guards/isSchemaResolutionFunction.ts","../../src/mappers/mapServiceSchemas.ts"],"sourcesContent":["export * from './mapper';\nexport * from './mapServiceSchemas';\n","import { Prettify } from '@forklaunch/common';\nimport {\n AnySchemaValidator,\n IdiomaticSchema,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { EntitySchema, InferEntityFromProperties } from '@mikro-orm/core';\n\nexport function requestMapper<\n SV extends AnySchemaValidator,\n DomainSchema extends IdiomaticSchema<SV>,\n Entity extends EntitySchema,\n AdditionalArgs extends unknown[] = []\n>({\n schemaValidator,\n schema,\n entity,\n mapperDefinition\n}: {\n schemaValidator: SV;\n schema: DomainSchema;\n entity: Entity;\n mapperDefinition: {\n toEntity: (\n dto: Schema<DomainSchema, SV>,\n ...args: AdditionalArgs\n ) => Promise<InferEntityFromProperties<Entity>>;\n };\n}): {\n entity: Entity;\n schema: DomainSchema;\n} & typeof mapperDefinition {\n const sv = schemaValidator as SchemaValidator;\n return {\n ...mapperDefinition,\n entity,\n schema,\n\n toEntity: async (\n dto: Schema<DomainSchema, SV>,\n ...args: AdditionalArgs\n ) => {\n const parsedSchema = sv.parse(sv.schemify(schema), dto);\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return mapperDefinition.toEntity(\n dto as Schema<DomainSchema, SV>,\n ...(args as AdditionalArgs)\n );\n }\n };\n}\n\nexport function responseMapper<\n SV extends AnySchemaValidator,\n DomainSchema extends IdiomaticSchema<SV>,\n Entity extends EntitySchema,\n AdditionalArgs extends unknown[] = []\n>({\n schemaValidator,\n schema,\n entity,\n mapperDefinition\n}: {\n schemaValidator: SV;\n schema: DomainSchema;\n entity: InferEntityFromProperties<Entity>;\n mapperDefinition: {\n toDto: (\n entity: InferEntityFromProperties<Entity>,\n ...args: AdditionalArgs\n ) => Promise<Schema<DomainSchema, SV>>;\n };\n}): Prettify<\n {\n entity: InferEntityFromProperties<Entity>;\n schema: DomainSchema;\n } & typeof mapperDefinition\n> {\n const sv = schemaValidator as SchemaValidator;\n return {\n ...mapperDefinition,\n entity,\n schema,\n\n toDto: async (\n entity: InferEntityFromProperties<Entity>,\n ...args: AdditionalArgs\n ) => {\n const domain = await mapperDefinition.toDto(entity, ...args);\n const parsedSchema = sv.parse(sv.schemify(schema), domain);\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return domain;\n }\n };\n}\n","import { SchemaResolutionFunction } from '../types/schemaResolution.types';\n\n/**\n * Type guard to determine if a value is a SchemaResolutionFunction.\n *\n * @template Args - The type of the options object expected by the schema resolution function.\n * @param {unknown} value - The value to check.\n * @returns {value is SchemaResolutionFunction<Args>} True if the value is a function (assumed to be a SchemaResolutionFunction), false otherwise.\n */\nexport function isSchemaResolutionFunction<\n Args extends Record<string, unknown>\n>(value: unknown): value is SchemaResolutionFunction<Args> {\n return typeof value === 'function';\n}\n","import { AnySchemaValidator, IdiomaticSchema } from '@forklaunch/validator';\nimport { isSchemaResolutionFunction } from './guards/isSchemaResolutionFunction';\nimport { SchemaResolutionFunction } from './types/schemaResolution.types';\n\n/**\n * Maps a set of service schema factories or pre-instantiated schemas to their resolved schemas using the provided arguments.\n *\n * This utility allows you to provide an object whose values are either:\n * - Schema factory functions (SchemaResolutionFunction) that accept an options object (Args) and return a schema or schema group.\n * - Already-instantiated schemas (IdiomaticSchema).\n *\n * Each factory function will be called with the provided `args` object, and the result will be included in the returned mapping.\n * If a value is already a schema (not a function), it is returned as-is.\n *\n * @template SV - The schema validator type.\n * @template T - An object whose values are either schema factory functions or instantiated schemas.\n * @template Args - The type of the options object passed to each factory function (e.g., { validator, uuidId, ... }).\n *\n * @param {T} schemas - An object mapping schema names to either factory functions (SchemaResolutionFunction) or instantiated schemas (IdiomaticSchema).\n * @param {Args} args - The options object to be passed to each schema factory function.\n * @returns {{ [K in keyof T]: T[K] extends SchemaResolutionFunction<Args> ? ReturnType<T[K]> : T[K] }} An object mapping each schema name to its resolved schema.\n *\n * @example\n * const schemas = {\n * UserSchemas: (opts) => createUserSchemas(opts),\n * ProductSchemas: (opts) => createProductSchemas(opts),\n * AlreadyInstantiated: someSchemaObject\n * };\n * const mapped = mapServiceSchemas(schemas, { validator: myValidator });\n * // mapped.UserSchemas and mapped.ProductSchemas are instantiated, mapped.AlreadyInstantiated is passed through\n */\nexport function mapServiceSchemas<\n SV extends AnySchemaValidator,\n T extends Record<\n string,\n SchemaResolutionFunction<Args> | IdiomaticSchema<SV>\n >,\n Args extends Record<string, unknown>\n>(\n schemas: T,\n args: Args\n): {\n [K in keyof T]: T[K] extends SchemaResolutionFunction<Args>\n ? ReturnType<T[K]>\n : T[K];\n} {\n return Object.fromEntries(\n Object.entries(schemas).map(([key, value]) => [\n key,\n isSchemaResolutionFunction(value) ? value(args) : value\n ])\n ) as {\n [K in keyof T]: T[K] extends SchemaResolutionFunction<Args>\n ? ReturnType<T[K]>\n : T[K];\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,uBAMO;AAGA,SAAS,cAKd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAa4B;AAC1B,QAAM,KAAK;AACX,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IAEA,UAAU,OACR,QACG,SACA;AACH,YAAM,eAAe,GAAG,MAAM,GAAG,SAAS,MAAM,GAAG,GAAG;AACtD,UAAI,CAAC,aAAa,IAAI;AACpB,cAAM,IAAI,UAAM,yCAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,MACpE;AACA,aAAO,iBAAiB;AAAA,QACtB;AAAA,QACA,GAAI;AAAA,MACN;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,eAKd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAeE;AACA,QAAM,KAAK;AACX,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IAEA,OAAO,OACLA,YACG,SACA;AACH,YAAM,SAAS,MAAM,iBAAiB,MAAMA,SAAQ,GAAG,IAAI;AAC3D,YAAM,eAAe,GAAG,MAAM,GAAG,SAAS,MAAM,GAAG,MAAM;AACzD,UAAI,CAAC,aAAa,IAAI;AACpB,cAAM,IAAI,UAAM,yCAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,MACpE;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;;;AC3FO,SAAS,2BAEd,OAAyD;AACzD,SAAO,OAAO,UAAU;AAC1B;;;ACkBO,SAAS,kBAQd,SACA,MAKA;AACA,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,MAC5C;AAAA,MACA,2BAA2B,KAAK,IAAI,MAAM,IAAI,IAAI;AAAA,IACpD,CAAC;AAAA,EACH;AAKF;","names":["entity"]}
1
+ {"version":3,"sources":["../../src/mappers/index.ts","../../src/mappers/mapper.ts","../../src/mappers/guards/isSchemaResolutionFunction.ts","../../src/mappers/mapServiceSchemas.ts"],"sourcesContent":["export * from './mapper';\nexport * from './mapServiceSchemas';\n","import { Prettify } from '@forklaunch/common';\nimport {\n AnySchemaValidator,\n IdiomaticSchema,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { EntitySchema, InferEntity } from '@mikro-orm/core';\n\nexport function requestMapper<\n SV extends AnySchemaValidator,\n DomainSchema extends IdiomaticSchema<SV>,\n Entity extends EntitySchema,\n AdditionalArgs extends unknown[] = []\n>({\n schemaValidator,\n schema,\n entity,\n mapperDefinition\n}: {\n schemaValidator: SV;\n schema: DomainSchema;\n entity: Entity;\n mapperDefinition: {\n toEntity: (\n dto: Schema<DomainSchema, SV>,\n ...args: AdditionalArgs\n ) => Promise<InferEntity<Entity>>;\n };\n}): {\n entity: Entity;\n schema: DomainSchema;\n} & typeof mapperDefinition {\n const sv = schemaValidator as SchemaValidator;\n return {\n ...mapperDefinition,\n entity,\n schema,\n\n toEntity: async (\n dto: Schema<DomainSchema, SV>,\n ...args: AdditionalArgs\n ) => {\n const parsedSchema = sv.parse(sv.schemify(schema), dto);\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return mapperDefinition.toEntity(\n dto as Schema<DomainSchema, SV>,\n ...(args as AdditionalArgs)\n );\n }\n };\n}\n\nexport function responseMapper<\n SV extends AnySchemaValidator,\n DomainSchema extends IdiomaticSchema<SV>,\n Entity extends EntitySchema,\n AdditionalArgs extends unknown[] = []\n>({\n schemaValidator,\n schema,\n entity,\n mapperDefinition\n}: {\n schemaValidator: SV;\n schema: DomainSchema;\n entity: Entity;\n mapperDefinition: {\n toDto: (\n entity: InferEntity<Entity>,\n ...args: AdditionalArgs\n ) => Promise<Schema<DomainSchema, SV>>;\n };\n}): Prettify<\n {\n entity: Entity;\n schema: DomainSchema;\n } & typeof mapperDefinition\n> {\n const sv = schemaValidator as SchemaValidator;\n return {\n ...mapperDefinition,\n entity,\n schema,\n\n toDto: async (entity: InferEntity<Entity>, ...args: AdditionalArgs) => {\n const domain = await mapperDefinition.toDto(entity, ...args);\n const parsedSchema = sv.parse(sv.schemify(schema), domain);\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return domain;\n }\n };\n}\n","import { SchemaResolutionFunction } from '../types/schemaResolution.types';\n\n/**\n * Type guard to determine if a value is a SchemaResolutionFunction.\n *\n * @template Args - The type of the options object expected by the schema resolution function.\n * @param {unknown} value - The value to check.\n * @returns {value is SchemaResolutionFunction<Args>} True if the value is a function (assumed to be a SchemaResolutionFunction), false otherwise.\n */\nexport function isSchemaResolutionFunction<\n Args extends Record<string, unknown>\n>(value: unknown): value is SchemaResolutionFunction<Args> {\n return typeof value === 'function';\n}\n","import { AnySchemaValidator, IdiomaticSchema } from '@forklaunch/validator';\nimport { isSchemaResolutionFunction } from './guards/isSchemaResolutionFunction';\nimport { SchemaResolutionFunction } from './types/schemaResolution.types';\n\n/**\n * Maps a set of service schema factories or pre-instantiated schemas to their resolved schemas using the provided arguments.\n *\n * This utility allows you to provide an object whose values are either:\n * - Schema factory functions (SchemaResolutionFunction) that accept an options object (Args) and return a schema or schema group.\n * - Already-instantiated schemas (IdiomaticSchema).\n *\n * Each factory function will be called with the provided `args` object, and the result will be included in the returned mapping.\n * If a value is already a schema (not a function), it is returned as-is.\n *\n * @template SV - The schema validator type.\n * @template T - An object whose values are either schema factory functions or instantiated schemas.\n * @template Args - The type of the options object passed to each factory function (e.g., { validator, uuidId, ... }).\n *\n * @param {T} schemas - An object mapping schema names to either factory functions (SchemaResolutionFunction) or instantiated schemas (IdiomaticSchema).\n * @param {Args} args - The options object to be passed to each schema factory function.\n * @returns {{ [K in keyof T]: T[K] extends SchemaResolutionFunction<Args> ? ReturnType<T[K]> : T[K] }} An object mapping each schema name to its resolved schema.\n *\n * @example\n * const schemas = {\n * UserSchemas: (opts) => createUserSchemas(opts),\n * ProductSchemas: (opts) => createProductSchemas(opts),\n * AlreadyInstantiated: someSchemaObject\n * };\n * const mapped = mapServiceSchemas(schemas, { validator: myValidator });\n * // mapped.UserSchemas and mapped.ProductSchemas are instantiated, mapped.AlreadyInstantiated is passed through\n */\nexport function mapServiceSchemas<\n SV extends AnySchemaValidator,\n T extends Record<\n string,\n SchemaResolutionFunction<Args> | IdiomaticSchema<SV>\n >,\n Args extends Record<string, unknown>\n>(\n schemas: T,\n args: Args\n): {\n [K in keyof T]: T[K] extends SchemaResolutionFunction<Args>\n ? ReturnType<T[K]>\n : T[K];\n} {\n return Object.fromEntries(\n Object.entries(schemas).map(([key, value]) => [\n key,\n isSchemaResolutionFunction(value) ? value(args) : value\n ])\n ) as {\n [K in keyof T]: T[K] extends SchemaResolutionFunction<Args>\n ? ReturnType<T[K]>\n : T[K];\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,uBAMO;AAGA,SAAS,cAKd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAa4B;AAC1B,QAAM,KAAK;AACX,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IAEA,UAAU,OACR,QACG,SACA;AACH,YAAM,eAAe,GAAG,MAAM,GAAG,SAAS,MAAM,GAAG,GAAG;AACtD,UAAI,CAAC,aAAa,IAAI;AACpB,cAAM,IAAI,UAAM,yCAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,MACpE;AACA,aAAO,iBAAiB;AAAA,QACtB;AAAA,QACA,GAAI;AAAA,MACN;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,eAKd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAeE;AACA,QAAM,KAAK;AACX,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IAEA,OAAO,OAAOA,YAAgC,SAAyB;AACrE,YAAM,SAAS,MAAM,iBAAiB,MAAMA,SAAQ,GAAG,IAAI;AAC3D,YAAM,eAAe,GAAG,MAAM,GAAG,SAAS,MAAM,GAAG,MAAM;AACzD,UAAI,CAAC,aAAa,IAAI;AACpB,cAAM,IAAI,UAAM,yCAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,MACpE;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;;;ACxFO,SAAS,2BAEd,OAAyD;AACzD,SAAO,OAAO,UAAU;AAC1B;;;ACkBO,SAAS,kBAQd,SACA,MAKA;AACA,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,MAC5C;AAAA,MACA,2BAA2B,KAAK,IAAI,MAAM,IAAI,IAAI;AAAA,IACpD,CAAC;AAAA,EACH;AAKF;","names":["entity"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mappers/mapper.ts","../../src/mappers/guards/isSchemaResolutionFunction.ts","../../src/mappers/mapServiceSchemas.ts"],"sourcesContent":["import { Prettify } from '@forklaunch/common';\nimport {\n AnySchemaValidator,\n IdiomaticSchema,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { EntitySchema, InferEntityFromProperties } from '@mikro-orm/core';\n\nexport function requestMapper<\n SV extends AnySchemaValidator,\n DomainSchema extends IdiomaticSchema<SV>,\n Entity extends EntitySchema,\n AdditionalArgs extends unknown[] = []\n>({\n schemaValidator,\n schema,\n entity,\n mapperDefinition\n}: {\n schemaValidator: SV;\n schema: DomainSchema;\n entity: Entity;\n mapperDefinition: {\n toEntity: (\n dto: Schema<DomainSchema, SV>,\n ...args: AdditionalArgs\n ) => Promise<InferEntityFromProperties<Entity>>;\n };\n}): {\n entity: Entity;\n schema: DomainSchema;\n} & typeof mapperDefinition {\n const sv = schemaValidator as SchemaValidator;\n return {\n ...mapperDefinition,\n entity,\n schema,\n\n toEntity: async (\n dto: Schema<DomainSchema, SV>,\n ...args: AdditionalArgs\n ) => {\n const parsedSchema = sv.parse(sv.schemify(schema), dto);\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return mapperDefinition.toEntity(\n dto as Schema<DomainSchema, SV>,\n ...(args as AdditionalArgs)\n );\n }\n };\n}\n\nexport function responseMapper<\n SV extends AnySchemaValidator,\n DomainSchema extends IdiomaticSchema<SV>,\n Entity extends EntitySchema,\n AdditionalArgs extends unknown[] = []\n>({\n schemaValidator,\n schema,\n entity,\n mapperDefinition\n}: {\n schemaValidator: SV;\n schema: DomainSchema;\n entity: InferEntityFromProperties<Entity>;\n mapperDefinition: {\n toDto: (\n entity: InferEntityFromProperties<Entity>,\n ...args: AdditionalArgs\n ) => Promise<Schema<DomainSchema, SV>>;\n };\n}): Prettify<\n {\n entity: InferEntityFromProperties<Entity>;\n schema: DomainSchema;\n } & typeof mapperDefinition\n> {\n const sv = schemaValidator as SchemaValidator;\n return {\n ...mapperDefinition,\n entity,\n schema,\n\n toDto: async (\n entity: InferEntityFromProperties<Entity>,\n ...args: AdditionalArgs\n ) => {\n const domain = await mapperDefinition.toDto(entity, ...args);\n const parsedSchema = sv.parse(sv.schemify(schema), domain);\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return domain;\n }\n };\n}\n","import { SchemaResolutionFunction } from '../types/schemaResolution.types';\n\n/**\n * Type guard to determine if a value is a SchemaResolutionFunction.\n *\n * @template Args - The type of the options object expected by the schema resolution function.\n * @param {unknown} value - The value to check.\n * @returns {value is SchemaResolutionFunction<Args>} True if the value is a function (assumed to be a SchemaResolutionFunction), false otherwise.\n */\nexport function isSchemaResolutionFunction<\n Args extends Record<string, unknown>\n>(value: unknown): value is SchemaResolutionFunction<Args> {\n return typeof value === 'function';\n}\n","import { AnySchemaValidator, IdiomaticSchema } from '@forklaunch/validator';\nimport { isSchemaResolutionFunction } from './guards/isSchemaResolutionFunction';\nimport { SchemaResolutionFunction } from './types/schemaResolution.types';\n\n/**\n * Maps a set of service schema factories or pre-instantiated schemas to their resolved schemas using the provided arguments.\n *\n * This utility allows you to provide an object whose values are either:\n * - Schema factory functions (SchemaResolutionFunction) that accept an options object (Args) and return a schema or schema group.\n * - Already-instantiated schemas (IdiomaticSchema).\n *\n * Each factory function will be called with the provided `args` object, and the result will be included in the returned mapping.\n * If a value is already a schema (not a function), it is returned as-is.\n *\n * @template SV - The schema validator type.\n * @template T - An object whose values are either schema factory functions or instantiated schemas.\n * @template Args - The type of the options object passed to each factory function (e.g., { validator, uuidId, ... }).\n *\n * @param {T} schemas - An object mapping schema names to either factory functions (SchemaResolutionFunction) or instantiated schemas (IdiomaticSchema).\n * @param {Args} args - The options object to be passed to each schema factory function.\n * @returns {{ [K in keyof T]: T[K] extends SchemaResolutionFunction<Args> ? ReturnType<T[K]> : T[K] }} An object mapping each schema name to its resolved schema.\n *\n * @example\n * const schemas = {\n * UserSchemas: (opts) => createUserSchemas(opts),\n * ProductSchemas: (opts) => createProductSchemas(opts),\n * AlreadyInstantiated: someSchemaObject\n * };\n * const mapped = mapServiceSchemas(schemas, { validator: myValidator });\n * // mapped.UserSchemas and mapped.ProductSchemas are instantiated, mapped.AlreadyInstantiated is passed through\n */\nexport function mapServiceSchemas<\n SV extends AnySchemaValidator,\n T extends Record<\n string,\n SchemaResolutionFunction<Args> | IdiomaticSchema<SV>\n >,\n Args extends Record<string, unknown>\n>(\n schemas: T,\n args: Args\n): {\n [K in keyof T]: T[K] extends SchemaResolutionFunction<Args>\n ? ReturnType<T[K]>\n : T[K];\n} {\n return Object.fromEntries(\n Object.entries(schemas).map(([key, value]) => [\n key,\n isSchemaResolutionFunction(value) ? value(args) : value\n ])\n ) as {\n [K in keyof T]: T[K] extends SchemaResolutionFunction<Args>\n ? ReturnType<T[K]>\n : T[K];\n };\n}\n"],"mappings":";AACA;AAAA,EAGE;AAAA,OAGK;AAGA,SAAS,cAKd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAa4B;AAC1B,QAAM,KAAK;AACX,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IAEA,UAAU,OACR,QACG,SACA;AACH,YAAM,eAAe,GAAG,MAAM,GAAG,SAAS,MAAM,GAAG,GAAG;AACtD,UAAI,CAAC,aAAa,IAAI;AACpB,cAAM,IAAI,MAAM,uBAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,MACpE;AACA,aAAO,iBAAiB;AAAA,QACtB;AAAA,QACA,GAAI;AAAA,MACN;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,eAKd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAeE;AACA,QAAM,KAAK;AACX,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IAEA,OAAO,OACLA,YACG,SACA;AACH,YAAM,SAAS,MAAM,iBAAiB,MAAMA,SAAQ,GAAG,IAAI;AAC3D,YAAM,eAAe,GAAG,MAAM,GAAG,SAAS,MAAM,GAAG,MAAM;AACzD,UAAI,CAAC,aAAa,IAAI;AACpB,cAAM,IAAI,MAAM,uBAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,MACpE;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;;;AC3FO,SAAS,2BAEd,OAAyD;AACzD,SAAO,OAAO,UAAU;AAC1B;;;ACkBO,SAAS,kBAQd,SACA,MAKA;AACA,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,MAC5C;AAAA,MACA,2BAA2B,KAAK,IAAI,MAAM,IAAI,IAAI;AAAA,IACpD,CAAC;AAAA,EACH;AAKF;","names":["entity"]}
1
+ {"version":3,"sources":["../../src/mappers/mapper.ts","../../src/mappers/guards/isSchemaResolutionFunction.ts","../../src/mappers/mapServiceSchemas.ts"],"sourcesContent":["import { Prettify } from '@forklaunch/common';\nimport {\n AnySchemaValidator,\n IdiomaticSchema,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { EntitySchema, InferEntity } from '@mikro-orm/core';\n\nexport function requestMapper<\n SV extends AnySchemaValidator,\n DomainSchema extends IdiomaticSchema<SV>,\n Entity extends EntitySchema,\n AdditionalArgs extends unknown[] = []\n>({\n schemaValidator,\n schema,\n entity,\n mapperDefinition\n}: {\n schemaValidator: SV;\n schema: DomainSchema;\n entity: Entity;\n mapperDefinition: {\n toEntity: (\n dto: Schema<DomainSchema, SV>,\n ...args: AdditionalArgs\n ) => Promise<InferEntity<Entity>>;\n };\n}): {\n entity: Entity;\n schema: DomainSchema;\n} & typeof mapperDefinition {\n const sv = schemaValidator as SchemaValidator;\n return {\n ...mapperDefinition,\n entity,\n schema,\n\n toEntity: async (\n dto: Schema<DomainSchema, SV>,\n ...args: AdditionalArgs\n ) => {\n const parsedSchema = sv.parse(sv.schemify(schema), dto);\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return mapperDefinition.toEntity(\n dto as Schema<DomainSchema, SV>,\n ...(args as AdditionalArgs)\n );\n }\n };\n}\n\nexport function responseMapper<\n SV extends AnySchemaValidator,\n DomainSchema extends IdiomaticSchema<SV>,\n Entity extends EntitySchema,\n AdditionalArgs extends unknown[] = []\n>({\n schemaValidator,\n schema,\n entity,\n mapperDefinition\n}: {\n schemaValidator: SV;\n schema: DomainSchema;\n entity: Entity;\n mapperDefinition: {\n toDto: (\n entity: InferEntity<Entity>,\n ...args: AdditionalArgs\n ) => Promise<Schema<DomainSchema, SV>>;\n };\n}): Prettify<\n {\n entity: Entity;\n schema: DomainSchema;\n } & typeof mapperDefinition\n> {\n const sv = schemaValidator as SchemaValidator;\n return {\n ...mapperDefinition,\n entity,\n schema,\n\n toDto: async (entity: InferEntity<Entity>, ...args: AdditionalArgs) => {\n const domain = await mapperDefinition.toDto(entity, ...args);\n const parsedSchema = sv.parse(sv.schemify(schema), domain);\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return domain;\n }\n };\n}\n","import { SchemaResolutionFunction } from '../types/schemaResolution.types';\n\n/**\n * Type guard to determine if a value is a SchemaResolutionFunction.\n *\n * @template Args - The type of the options object expected by the schema resolution function.\n * @param {unknown} value - The value to check.\n * @returns {value is SchemaResolutionFunction<Args>} True if the value is a function (assumed to be a SchemaResolutionFunction), false otherwise.\n */\nexport function isSchemaResolutionFunction<\n Args extends Record<string, unknown>\n>(value: unknown): value is SchemaResolutionFunction<Args> {\n return typeof value === 'function';\n}\n","import { AnySchemaValidator, IdiomaticSchema } from '@forklaunch/validator';\nimport { isSchemaResolutionFunction } from './guards/isSchemaResolutionFunction';\nimport { SchemaResolutionFunction } from './types/schemaResolution.types';\n\n/**\n * Maps a set of service schema factories or pre-instantiated schemas to their resolved schemas using the provided arguments.\n *\n * This utility allows you to provide an object whose values are either:\n * - Schema factory functions (SchemaResolutionFunction) that accept an options object (Args) and return a schema or schema group.\n * - Already-instantiated schemas (IdiomaticSchema).\n *\n * Each factory function will be called with the provided `args` object, and the result will be included in the returned mapping.\n * If a value is already a schema (not a function), it is returned as-is.\n *\n * @template SV - The schema validator type.\n * @template T - An object whose values are either schema factory functions or instantiated schemas.\n * @template Args - The type of the options object passed to each factory function (e.g., { validator, uuidId, ... }).\n *\n * @param {T} schemas - An object mapping schema names to either factory functions (SchemaResolutionFunction) or instantiated schemas (IdiomaticSchema).\n * @param {Args} args - The options object to be passed to each schema factory function.\n * @returns {{ [K in keyof T]: T[K] extends SchemaResolutionFunction<Args> ? ReturnType<T[K]> : T[K] }} An object mapping each schema name to its resolved schema.\n *\n * @example\n * const schemas = {\n * UserSchemas: (opts) => createUserSchemas(opts),\n * ProductSchemas: (opts) => createProductSchemas(opts),\n * AlreadyInstantiated: someSchemaObject\n * };\n * const mapped = mapServiceSchemas(schemas, { validator: myValidator });\n * // mapped.UserSchemas and mapped.ProductSchemas are instantiated, mapped.AlreadyInstantiated is passed through\n */\nexport function mapServiceSchemas<\n SV extends AnySchemaValidator,\n T extends Record<\n string,\n SchemaResolutionFunction<Args> | IdiomaticSchema<SV>\n >,\n Args extends Record<string, unknown>\n>(\n schemas: T,\n args: Args\n): {\n [K in keyof T]: T[K] extends SchemaResolutionFunction<Args>\n ? ReturnType<T[K]>\n : T[K];\n} {\n return Object.fromEntries(\n Object.entries(schemas).map(([key, value]) => [\n key,\n isSchemaResolutionFunction(value) ? value(args) : value\n ])\n ) as {\n [K in keyof T]: T[K] extends SchemaResolutionFunction<Args>\n ? ReturnType<T[K]>\n : T[K];\n };\n}\n"],"mappings":";AACA;AAAA,EAGE;AAAA,OAGK;AAGA,SAAS,cAKd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAa4B;AAC1B,QAAM,KAAK;AACX,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IAEA,UAAU,OACR,QACG,SACA;AACH,YAAM,eAAe,GAAG,MAAM,GAAG,SAAS,MAAM,GAAG,GAAG;AACtD,UAAI,CAAC,aAAa,IAAI;AACpB,cAAM,IAAI,MAAM,uBAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,MACpE;AACA,aAAO,iBAAiB;AAAA,QACtB;AAAA,QACA,GAAI;AAAA,MACN;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,eAKd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAeE;AACA,QAAM,KAAK;AACX,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IAEA,OAAO,OAAOA,YAAgC,SAAyB;AACrE,YAAM,SAAS,MAAM,iBAAiB,MAAMA,SAAQ,GAAG,IAAI;AAC3D,YAAM,eAAe,GAAG,MAAM,GAAG,SAAS,MAAM,GAAG,MAAM;AACzD,UAAI,CAAC,aAAa,IAAI;AACpB,cAAM,IAAI,MAAM,uBAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,MACpE;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;;;ACxFO,SAAS,2BAEd,OAAyD;AACzD,SAAO,OAAO,UAAU;AAC1B;;;ACkBO,SAAS,kBAQd,SACA,MAKA;AACA,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,MAC5C;AAAA,MACA,2BAA2B,KAAK,IAAI,MAAM,IAAI,IAAI;AAAA,IACpD,CAAC;AAAA,EACH;AAKF;","names":["entity"]}
@@ -1,2 +1,299 @@
1
+ import * as _mikro_orm_core from '@mikro-orm/core';
2
+ import { PropertyChain, PropertyBuilders, UniversalPropertyOptionsBuilder, EventSubscriber, EventArgs, EntityManager, FilterDef, MikroORM, TransactionEventArgs } from '@mikro-orm/core';
3
+ export { InferEntity } from '@mikro-orm/core';
1
4
 
2
- export { }
5
+ /**
6
+ * Classification levels for entity field compliance.
7
+ * Drives encryption (phi/pci), audit log redaction (all non-none), and compliance reporting.
8
+ */
9
+ declare const ComplianceLevel: {
10
+ readonly pii: "pii";
11
+ readonly phi: "phi";
12
+ readonly pci: "pci";
13
+ readonly none: "none";
14
+ };
15
+ type ComplianceLevel = (typeof ComplianceLevel)[keyof typeof ComplianceLevel];
16
+ /**
17
+ * Brand symbol — makes ClassifiedProperty structurally distinct from
18
+ * plain PropertyChain at the TypeScript level.
19
+ */
20
+ declare const CLASSIFIED: unique symbol;
21
+ /**
22
+ * A property that has been classified via `.compliance()`.
23
+ * Only ClassifiedProperty values are accepted by `defineComplianceEntity`.
24
+ *
25
+ * At runtime this is a Proxy wrapping a MikroORM PropertyBuilder.
26
+ * The brand exists only at the type level for compile-time enforcement.
27
+ */
28
+ interface ClassifiedProperty {
29
+ readonly [CLASSIFIED]: true;
30
+ }
31
+ /**
32
+ * Look up the compliance level for a single field on an entity.
33
+ * Returns `'none'` if the entity or field is not registered.
34
+ */
35
+ declare function getComplianceMetadata(entityName: string, fieldName: string): ComplianceLevel;
36
+ /**
37
+ * Get all compliance fields for an entity.
38
+ * Returns undefined if the entity is not registered.
39
+ */
40
+ declare function getEntityComplianceFields(entityName: string): Map<string, ComplianceLevel> | undefined;
41
+ /**
42
+ * Check whether an entity has any fields requiring encryption (phi or pci).
43
+ */
44
+ declare function entityHasEncryptedFields(entityName: string): boolean;
45
+ /**
46
+ * Recursively remaps every method on PropertyChain<V,O> so those returning
47
+ * PropertyChain<V2,O2> instead return ForklaunchPropertyChain<V2,O2>.
48
+ * This preserves the `.compliance()` method through chained calls like
49
+ * `.nullable().unique()`.
50
+ */
51
+ interface ForklaunchPropertyChain<Value, Options> extends RemapReturns<Value, Options> {
52
+ /**
53
+ * Classify this field's compliance level. Must be called on every scalar
54
+ * field passed to `defineComplianceEntity`.
55
+ * Returns an opaque `ClassifiedProperty`.
56
+ */
57
+ compliance(level: ComplianceLevel): ClassifiedProperty;
58
+ }
59
+ type RemapReturns<Value, Options> = {
60
+ [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];
61
+ };
62
+ /**
63
+ * Keys on PropertyBuilders that return relation builders.
64
+ * These are auto-classified as 'none' — the fp proxy wraps them
65
+ * to return ClassifiedProperty directly.
66
+ */
67
+ type RelationBuilderKeys = 'manyToOne' | 'oneToMany' | 'manyToMany' | 'oneToOne' | 'embedded';
68
+ /**
69
+ * The type of `fp` — mirrors `PropertyBuilders` but:
70
+ * - Scalar methods return `ForklaunchPropertyChain` (must call `.compliance()`)
71
+ * - Relation methods return `ClassifiedProperty` directly (auto 'none')
72
+ */
73
+ type ForklaunchPropertyBuilders = {
74
+ [K in Exclude<keyof PropertyBuilders, RelationBuilderKeys>]: PropertyBuilders[K] extends (...args: infer A) => UniversalPropertyOptionsBuilder<infer V, infer O, infer _IK> ? (...args: A) => ForklaunchPropertyChain<V, O> : PropertyBuilders[K] extends (...args: infer A) => PropertyChain<infer V, infer O> ? (...args: A) => ForklaunchPropertyChain<V, O> : PropertyBuilders[K];
75
+ } & {
76
+ [K in RelationBuilderKeys]: PropertyBuilders[K] extends (...args: infer A) => PropertyChain<infer V, infer O> ? (...args: A) => ClassifiedRelationChain<V, O> : PropertyBuilders[K];
77
+ };
78
+ /**
79
+ * A relation builder that is already classified (as 'none') but still
80
+ * supports chaining relation-specific methods like `.mappedBy()`, `.nullable()`.
81
+ * All chain methods return ClassifiedRelationChain (preserving the brand).
82
+ */
83
+ type ClassifiedRelationChain<Value, Options> = {
84
+ [K in keyof PropertyChain<Value, Options>]: PropertyChain<Value, Options>[K] extends (...args: infer A) => PropertyChain<infer V2, infer O2> ? (...args: A) => ClassifiedRelationChain<V2, O2> : PropertyChain<Value, Options>[K];
85
+ } & ClassifiedProperty;
86
+
87
+ /**
88
+ * ForkLaunch property builder. Drop-in replacement for MikroORM's `p`
89
+ * that adds `.compliance(level)` to every scalar property builder
90
+ * and auto-classifies relation builders as 'none'.
91
+ *
92
+ * - Scalar fields: `fp.string().compliance('pii')` — must call `.compliance()`
93
+ * - Relation fields: `fp.manyToOne(Target)` — auto-classified, no `.compliance()` needed
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * import { defineComplianceEntity, fp } from '@forklaunch/core/persistence';
98
+ *
99
+ * const User = defineComplianceEntity({
100
+ * name: 'User',
101
+ * properties: {
102
+ * id: fp.uuid().primary().compliance('none'),
103
+ * email: fp.string().unique().compliance('pii'),
104
+ * medicalRecord: fp.string().nullable().compliance('phi'),
105
+ * organization: () => fp.manyToOne(Organization).nullable(),
106
+ * }
107
+ * });
108
+ * ```
109
+ */
110
+ declare const fp: ForklaunchPropertyBuilders;
111
+
112
+ /**
113
+ * Maps each property to `never` if it doesn't extend ClassifiedProperty.
114
+ * Used in an intersection with TProperties to produce a type error
115
+ * when any property is not classified.
116
+ */
117
+ type AssertAllClassified<T extends Record<string, unknown>> = {
118
+ [K in keyof T]: T[K] extends ClassifiedProperty ? T[K] : T[K] extends () => ClassifiedProperty ? T[K] : ClassifiedProperty;
119
+ };
120
+ /**
121
+ * Metadata descriptor for `defineComplianceEntity`.
122
+ */
123
+ interface ComplianceEntityMetadata<TProperties extends Record<string, unknown>> {
124
+ name: string;
125
+ tableName?: string;
126
+ properties: TProperties & AssertAllClassified<TProperties>;
127
+ extends?: unknown;
128
+ primaryKeys?: string[];
129
+ hooks?: Record<string, unknown>;
130
+ repository?: () => unknown;
131
+ forceObject?: boolean;
132
+ inheritance?: 'tpt';
133
+ orderBy?: Record<string, unknown> | Record<string, unknown>[];
134
+ discriminatorColumn?: string;
135
+ versionProperty?: string;
136
+ concurrencyCheckKeys?: Set<string>;
137
+ serializedPrimaryKey?: string;
138
+ indexes?: unknown[];
139
+ uniques?: unknown[];
140
+ }
141
+ /**
142
+ * Wrapper around MikroORM's `defineEntity` that enforces compliance
143
+ * classification on every field.
144
+ *
145
+ * - Scalar fields: must call `.compliance(level)` — forgetting it is a
146
+ * compile-time error (TypeScript rejects it) AND a runtime error.
147
+ * - Relation fields: auto-classified as `'none'` by the `fp` builder.
148
+ *
149
+ * Compliance metadata is stored in a module-level registry, accessible via
150
+ * `getComplianceMetadata(entityName, fieldName)`.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * const User = defineComplianceEntity({
155
+ * name: 'User',
156
+ * properties: {
157
+ * id: fp.uuid().primary().compliance('none'),
158
+ * email: fp.string().unique().compliance('pii'),
159
+ * medicalRecord: fp.string().nullable().compliance('phi'),
160
+ * organization: () => fp.manyToOne(Organization).nullable(),
161
+ * }
162
+ * });
163
+ * export type User = InferEntity<typeof User>;
164
+ * ```
165
+ */
166
+ declare function defineComplianceEntity<TProperties extends Record<string, unknown>>(meta: ComplianceEntityMetadata<TProperties>): _mikro_orm_core.EntitySchemaWithMeta<string, string, unknown, unknown, Record<string, any>, _mikro_orm_core.EntityCtor<unknown> & _mikro_orm_core.EntityCtor>;
167
+
168
+ declare class FieldEncryptor {
169
+ private readonly masterKey;
170
+ constructor(masterKey: string);
171
+ /**
172
+ * Derive a per-tenant 32-byte key using HKDF-SHA256.
173
+ * The master key is used as input key material and the tenantId as info context.
174
+ */
175
+ deriveKey(tenantId: string): Buffer;
176
+ /**
177
+ * Encrypt a plaintext string for a specific tenant.
178
+ *
179
+ * @returns Format: `v1:{base64(iv)}:{base64(authTag)}:{base64(ciphertext)}`
180
+ */
181
+ encrypt(plaintext: string | null): string | null;
182
+ encrypt(plaintext: string | null, tenantId: string): string | null;
183
+ /**
184
+ * Decrypt a ciphertext string produced by {@link encrypt}.
185
+ */
186
+ decrypt(ciphertext: string | null): string | null;
187
+ decrypt(ciphertext: string | null, tenantId: string): string | null;
188
+ }
189
+
190
+ /**
191
+ * MikroORM EventSubscriber that enforces field-level encryption for
192
+ * compliance-classified fields (PHI and PCI).
193
+ *
194
+ * - **onBeforeCreate / onBeforeUpdate**: Encrypts PHI/PCI fields before
195
+ * database persistence. Throws `EncryptionRequiredError` if the encryption
196
+ * key is unavailable.
197
+ * - **onLoad**: Decrypts PHI/PCI fields after loading from the database.
198
+ * Pre-migration plaintext (no `v1:` prefix) is returned as-is with a
199
+ * console warning to support rolling deployments.
200
+ *
201
+ * The tenant ID for key derivation is read from the EntityManager's filter
202
+ * parameters (set by the tenant context middleware).
203
+ */
204
+ declare class ComplianceEventSubscriber implements EventSubscriber {
205
+ private readonly encryptor;
206
+ constructor(encryptor: FieldEncryptor);
207
+ beforeCreate(args: EventArgs<unknown>): Promise<void>;
208
+ beforeUpdate(args: EventArgs<unknown>): Promise<void>;
209
+ onLoad(args: EventArgs<unknown>): Promise<void>;
210
+ private encryptFields;
211
+ private decryptFields;
212
+ /**
213
+ * Read the tenant ID from the EntityManager's filter parameters.
214
+ * The tenant context middleware sets this when forking the EM per request.
215
+ */
216
+ private getTenantId;
217
+ }
218
+ /**
219
+ * Wraps an EntityManager to block `nativeInsert`, `nativeUpdate`, and
220
+ * `nativeDelete` on entities that have PHI or PCI compliance fields.
221
+ *
222
+ * This prevents bypassing the ComplianceEventSubscriber's encryption
223
+ * by using raw queries. Call this in the tenant context middleware when
224
+ * creating the request-scoped EM.
225
+ *
226
+ * @returns A Proxy-wrapped EntityManager that throws on native query
227
+ * operations targeting compliance entities.
228
+ */
229
+ declare function wrapEmWithNativeQueryBlocking<T extends EntityManager>(em: T): T;
230
+
231
+ /**
232
+ * The name used to register the tenant isolation filter.
233
+ */
234
+ declare const TENANT_FILTER_NAME = "tenant";
235
+ /**
236
+ * Creates the tenant filter definition.
237
+ *
238
+ * The filter adds `WHERE organizationId = :tenantId` to all queries
239
+ * on entities that have an `organizationId` or `organization` property.
240
+ * Entities without either property are unaffected (empty condition).
241
+ */
242
+ declare function createTenantFilterDef(): FilterDef;
243
+ /**
244
+ * Registers the global tenant isolation filter on the ORM's entity manager.
245
+ * Call this once at application bootstrap after `MikroORM.init()`.
246
+ *
247
+ * After calling this, every fork of the EM will inherit the filter.
248
+ * Set the tenant ID per-request via:
249
+ *
250
+ * ```ts
251
+ * em.setFilterParams('tenant', { tenantId: 'org-123' });
252
+ * ```
253
+ */
254
+ declare function setupTenantFilter(orm: MikroORM): void;
255
+ /**
256
+ * Returns a forked EntityManager with the tenant filter disabled.
257
+ *
258
+ * Use this only from code paths that have verified super-admin permissions.
259
+ * Queries executed through the returned EM will return cross-tenant data.
260
+ */
261
+ declare function getSuperAdminContext(em: EntityManager): EntityManager;
262
+
263
+ interface RlsConfig {
264
+ /**
265
+ * Whether to enable PostgreSQL Row-Level Security.
266
+ * Defaults to `true` when the driver is PostgreSQL, `false` otherwise.
267
+ * Set to `false` to opt out even on PostgreSQL.
268
+ */
269
+ enabled?: boolean;
270
+ }
271
+ /**
272
+ * MikroORM EventSubscriber that executes `SET LOCAL app.tenant_id = :tenantId`
273
+ * at the start of every transaction when PostgreSQL RLS is enabled.
274
+ *
275
+ * This ensures that even if the MikroORM global filter is somehow bypassed,
276
+ * the database-level RLS policy enforces tenant isolation.
277
+ *
278
+ * The tenant ID is read from the EntityManager's filter parameters
279
+ * (set by the tenant context middleware).
280
+ */
281
+ declare class RlsEventSubscriber implements EventSubscriber {
282
+ afterTransactionStart(args: TransactionEventArgs): Promise<void>;
283
+ private getTenantId;
284
+ }
285
+ /**
286
+ * Sets up PostgreSQL Row-Level Security integration.
287
+ *
288
+ * 1. Registers the `RlsEventSubscriber` to run `SET LOCAL app.tenant_id`
289
+ * at the start of every transaction.
290
+ * 2. Validates that RLS policies exist on tenant-scoped tables (warns if missing).
291
+ *
292
+ * Call this at application bootstrap after `MikroORM.init()` and `setupTenantFilter()`.
293
+ *
294
+ * @param orm - The initialized MikroORM instance
295
+ * @param config - RLS configuration (enabled defaults to auto-detect PostgreSQL)
296
+ */
297
+ declare function setupRls(orm: MikroORM, config?: RlsConfig): void;
298
+
299
+ export { type ClassifiedProperty, type ClassifiedRelationChain, ComplianceEventSubscriber, ComplianceLevel, ComplianceLevel as ComplianceLevelType, type ForklaunchPropertyBuilders, type ForklaunchPropertyChain, type RlsConfig, RlsEventSubscriber, TENANT_FILTER_NAME, createTenantFilterDef, defineComplianceEntity, entityHasEncryptedFields, fp, getComplianceMetadata, getEntityComplianceFields, getSuperAdminContext, setupRls, setupTenantFilter, wrapEmWithNativeQueryBlocking };