@forklaunch/core 1.5.2 → 1.5.4
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/cache/{index.d.mts → cacheKey.d.ts} +2 -6
- package/lib/cache/cacheKey.d.ts.map +1 -0
- package/lib/cache/index.d.ts +4 -15
- package/lib/cache/index.d.ts.map +1 -0
- package/lib/{ttlCache.interface-B3xaLT00.d.ts → cache/interfaces/ttlCache.interface.d.ts} +3 -5
- package/lib/cache/interfaces/ttlCache.interface.d.ts.map +1 -0
- package/lib/{ttlCacheRecord.types-oX0ti5SP.d.mts → cache/types/ttlCacheRecord.types.d.ts} +3 -4
- package/lib/cache/types/ttlCacheRecord.types.d.ts.map +1 -0
- package/lib/controllers/index.d.ts +2 -13
- package/lib/controllers/index.d.ts.map +1 -0
- package/lib/controllers/{index.d.mts → interfaces/controller.interface.d.ts} +2 -3
- package/lib/controllers/interfaces/controller.interface.d.ts.map +1 -0
- package/lib/environment/index.d.ts +2 -28
- package/lib/environment/index.d.ts.map +1 -0
- package/lib/environment/{index.d.mts → loadCascadingEnv.d.ts} +4 -5
- package/lib/environment/loadCascadingEnv.d.ts.map +1 -0
- package/lib/http/application/expressLikeApplication.d.ts +34 -0
- package/lib/http/application/expressLikeApplication.d.ts.map +1 -0
- package/lib/http/bootstrap/listen.d.ts +2 -0
- package/lib/http/bootstrap/listen.d.ts.map +1 -0
- package/lib/http/cluster/cluster.types.d.ts +17 -0
- package/lib/http/cluster/cluster.types.d.ts.map +1 -0
- package/lib/http/cluster/isPortBound.d.ts +2 -0
- package/lib/http/cluster/isPortBound.d.ts.map +1 -0
- package/lib/http/createHmacToken.d.ts +19 -0
- package/lib/http/createHmacToken.d.ts.map +1 -0
- package/lib/http/discriminateAuthMethod.d.ts +85 -0
- package/lib/http/discriminateAuthMethod.d.ts.map +1 -0
- package/lib/http/generateHmacAuthHeaders.d.ts +31 -0
- package/lib/http/generateHmacAuthHeaders.d.ts.map +1 -0
- package/lib/http/guards/hasFeatureChecks.d.ts +2 -0
- package/lib/http/guards/hasFeatureChecks.d.ts.map +1 -0
- package/lib/http/guards/hasPermissionChecks.d.ts +2 -0
- package/lib/http/guards/hasPermissionChecks.d.ts.map +1 -0
- package/lib/http/guards/hasRoleChecks.d.ts +2 -0
- package/lib/http/guards/hasRoleChecks.d.ts.map +1 -0
- package/lib/http/guards/hasScopeChecks.d.ts +2 -0
- package/lib/http/guards/hasScopeChecks.d.ts.map +1 -0
- package/lib/http/guards/hasSend.d.ts +17 -0
- package/lib/http/guards/hasSend.d.ts.map +1 -0
- package/lib/http/guards/hasSubscriptionChecks.d.ts +2 -0
- package/lib/http/guards/hasSubscriptionChecks.d.ts.map +1 -0
- package/lib/http/guards/hasVersionedSchema.d.ts +2 -0
- package/lib/http/guards/hasVersionedSchema.d.ts.map +1 -0
- package/lib/http/guards/isBasicAuthMethod.d.ts +3 -0
- package/lib/http/guards/isBasicAuthMethod.d.ts.map +1 -0
- package/lib/http/guards/isConstrainedForklaunchRouter.d.ts +21 -0
- package/lib/http/guards/isConstrainedForklaunchRouter.d.ts.map +1 -0
- package/lib/http/guards/isExpressLikeSchemaHandler.d.ts +32 -0
- package/lib/http/guards/isExpressLikeSchemaHandler.d.ts.map +1 -0
- package/lib/http/guards/isForklaunchExpressLikeRouter.d.ts +28 -0
- package/lib/http/guards/isForklaunchExpressLikeRouter.d.ts.map +1 -0
- package/lib/http/guards/isForklaunchRequest.d.ts +26 -0
- package/lib/http/guards/isForklaunchRequest.d.ts.map +1 -0
- package/lib/http/guards/isForklaunchResponse.d.ts +23 -0
- package/lib/http/guards/isForklaunchResponse.d.ts.map +1 -0
- package/lib/http/guards/isForklaunchRouter.d.ts +21 -0
- package/lib/http/guards/isForklaunchRouter.d.ts.map +1 -0
- package/lib/http/guards/isHmacMethod.d.ts +9 -0
- package/lib/http/guards/isHmacMethod.d.ts.map +1 -0
- package/lib/http/guards/isHttpContractDetails.d.ts +29 -0
- package/lib/http/guards/isHttpContractDetails.d.ts.map +1 -0
- package/lib/http/guards/isJwtAuthMethod.d.ts +3 -0
- package/lib/http/guards/isJwtAuthMethod.d.ts.map +1 -0
- package/lib/http/guards/isLoggerMeta.d.ts +3 -0
- package/lib/http/guards/isLoggerMeta.d.ts.map +1 -0
- package/lib/http/guards/isPath.d.ts +2 -0
- package/lib/http/guards/isPath.d.ts.map +1 -0
- package/lib/http/guards/isPathParamContractDetails.d.ts +4 -0
- package/lib/http/guards/isPathParamContractDetails.d.ts.map +1 -0
- package/lib/http/guards/isRequestShape.d.ts +3 -0
- package/lib/http/guards/isRequestShape.d.ts.map +1 -0
- package/lib/http/guards/isResponseCompiledSchema.d.ts +3 -0
- package/lib/http/guards/isResponseCompiledSchema.d.ts.map +1 -0
- package/lib/http/guards/isSdkHandler.d.ts +9 -0
- package/lib/http/guards/isSdkHandler.d.ts.map +1 -0
- package/lib/http/guards/isSdkRouter.d.ts +9 -0
- package/lib/http/guards/isSdkRouter.d.ts.map +1 -0
- package/lib/http/guards/isTypedHandler.d.ts +5 -0
- package/lib/http/guards/isTypedHandler.d.ts.map +1 -0
- package/lib/http/guards/isVersionedInputSchema.d.ts +3 -0
- package/lib/http/guards/isVersionedInputSchema.d.ts.map +1 -0
- package/lib/http/handlers/delete.d.ts +5 -0
- package/lib/http/handlers/delete.d.ts.map +1 -0
- package/lib/http/handlers/get.d.ts +5 -0
- package/lib/http/handlers/get.d.ts.map +1 -0
- package/lib/http/handlers/head.d.ts +5 -0
- package/lib/http/handlers/head.d.ts.map +1 -0
- package/lib/http/handlers/middleware.d.ts +10 -0
- package/lib/http/handlers/middleware.d.ts.map +1 -0
- package/lib/http/handlers/options.d.ts +5 -0
- package/lib/http/handlers/options.d.ts.map +1 -0
- package/lib/http/handlers/patch.d.ts +5 -0
- package/lib/http/handlers/patch.d.ts.map +1 -0
- package/lib/http/handlers/post.d.ts +5 -0
- package/lib/http/handlers/post.d.ts.map +1 -0
- package/lib/http/handlers/put.d.ts +5 -0
- package/lib/http/handlers/put.d.ts.map +1 -0
- package/lib/http/handlers/trace.d.ts +5 -0
- package/lib/http/handlers/trace.d.ts.map +1 -0
- package/lib/http/handlers/typedAuthHandler.d.ts +5 -0
- package/lib/http/handlers/typedAuthHandler.d.ts.map +1 -0
- package/lib/http/handlers/typedHandler.d.ts +14 -0
- package/lib/http/handlers/typedHandler.d.ts.map +1 -0
- package/lib/http/httpStatusCodes.d.ts +75 -0
- package/lib/http/httpStatusCodes.d.ts.map +1 -0
- package/lib/http/index.d.ts +47 -1244
- package/lib/http/index.d.ts.map +1 -0
- package/lib/http/index.js +445 -410
- package/lib/http/index.js.map +1 -1
- package/lib/http/index.mjs +439 -407
- package/lib/http/index.mjs.map +1 -1
- package/lib/http/interfaces/expressLikeRouter.interface.d.ts +25 -0
- package/lib/http/interfaces/expressLikeRouter.interface.d.ts.map +1 -0
- package/lib/http/mcpGenerator/mcpGenerator.d.ts +17 -0
- package/lib/http/mcpGenerator/mcpGenerator.d.ts.map +1 -0
- package/lib/http/middleware/request/auth.middleware.d.ts +16 -0
- package/lib/http/middleware/request/auth.middleware.d.ts.map +1 -0
- package/lib/http/middleware/request/cors.middleware.d.ts +13 -0
- package/lib/http/middleware/request/cors.middleware.d.ts.map +1 -0
- package/lib/http/middleware/request/createContext.middleware.d.ts +15 -0
- package/lib/http/middleware/request/createContext.middleware.d.ts.map +1 -0
- package/lib/http/middleware/request/enrichDetails.middleware.d.ts +18 -0
- package/lib/http/middleware/request/enrichDetails.middleware.d.ts.map +1 -0
- package/lib/http/middleware/request/parse.middleware.d.ts +17 -0
- package/lib/http/middleware/request/parse.middleware.d.ts.map +1 -0
- package/lib/http/middleware/request/tenantContext.middleware.d.ts +41 -0
- package/lib/http/middleware/request/tenantContext.middleware.d.ts.map +1 -0
- package/lib/http/middleware/response/enrichExpressLikeSend.middleware.d.ts +32 -0
- package/lib/http/middleware/response/enrichExpressLikeSend.middleware.d.ts.map +1 -0
- package/lib/http/middleware/response/parse.middleware.d.ts +31 -0
- package/lib/http/middleware/response/parse.middleware.d.ts.map +1 -0
- package/lib/http/openApiV3Generator/openApiV3Generator.d.ts +17 -0
- package/lib/http/openApiV3Generator/openApiV3Generator.d.ts.map +1 -0
- package/lib/http/rateLimit/index.d.ts +2 -0
- package/lib/http/rateLimit/index.d.ts.map +1 -0
- package/lib/http/rateLimit/rateLimiter.d.ts +66 -0
- package/lib/http/rateLimit/rateLimiter.d.ts.map +1 -0
- package/lib/http/router/discriminateBody.d.ts +43 -0
- package/lib/http/router/discriminateBody.d.ts.map +1 -0
- package/lib/http/router/expressLikeRouter.d.ts +240 -0
- package/lib/http/router/expressLikeRouter.d.ts.map +1 -0
- package/lib/http/router/routerSharedLogic.d.ts +50 -0
- package/lib/http/router/routerSharedLogic.d.ts.map +1 -0
- package/lib/http/router/unpackRouters.d.ts +7 -0
- package/lib/http/router/unpackRouters.d.ts.map +1 -0
- package/lib/http/telemetry/auditLogger.d.ts +21 -0
- package/lib/http/telemetry/auditLogger.d.ts.map +1 -0
- package/lib/http/telemetry/constants.d.ts +6 -0
- package/lib/http/telemetry/constants.d.ts.map +1 -0
- package/lib/http/telemetry/evaluateTelemetryOptions.d.ts +11 -0
- package/lib/http/telemetry/evaluateTelemetryOptions.d.ts.map +1 -0
- package/lib/http/telemetry/metricsDefinition.d.ts +3 -0
- package/lib/http/telemetry/metricsDefinition.d.ts.map +1 -0
- package/lib/http/telemetry/openTelemetryCollector.d.ts +53 -0
- package/lib/http/telemetry/openTelemetryCollector.d.ts.map +1 -0
- package/lib/http/telemetry/pinoLogger.d.ts +20 -0
- package/lib/http/telemetry/pinoLogger.d.ts.map +1 -0
- package/lib/http/telemetry/recordMetric.d.ts +5 -0
- package/lib/http/telemetry/recordMetric.d.ts.map +1 -0
- package/lib/http/types/apiDefinition.types.d.ts +471 -0
- package/lib/http/types/apiDefinition.types.d.ts.map +1 -0
- package/lib/http/types/contractDetails.types.d.ts +404 -0
- package/lib/http/types/contractDetails.types.d.ts.map +1 -0
- package/lib/http/types/docsConfiguration.types.d.ts +7 -0
- package/lib/http/types/docsConfiguration.types.d.ts.map +1 -0
- package/lib/http/types/expressLikeOptions.d.ts +224 -0
- package/lib/http/types/expressLikeOptions.d.ts.map +1 -0
- package/lib/http/types/expressLikeRouter.types.d.ts +127 -0
- package/lib/http/types/expressLikeRouter.types.d.ts.map +1 -0
- package/lib/http/types/openTelemetryCollector.types.d.ts +21 -0
- package/lib/http/types/openTelemetryCollector.types.d.ts.map +1 -0
- package/lib/http/types/router.types.d.ts +52 -0
- package/lib/http/types/router.types.d.ts.map +1 -0
- package/lib/http/types/sdk.types.d.ts +259 -0
- package/lib/http/types/sdk.types.d.ts.map +1 -0
- package/lib/http/types/typedHandler.types.d.ts +18 -0
- package/lib/http/types/typedHandler.types.d.ts.map +1 -0
- package/lib/mappers/guards/isSchemaResolutionFunction.d.ts +10 -0
- package/lib/mappers/guards/isSchemaResolutionFunction.d.ts.map +1 -0
- package/lib/mappers/index.d.ts +3 -68
- package/lib/mappers/index.d.ts.map +1 -0
- package/lib/mappers/mapServiceSchemas.d.ts +33 -0
- package/lib/mappers/mapServiceSchemas.d.ts.map +1 -0
- package/lib/mappers/mapper.d.ts +26 -0
- package/lib/mappers/mapper.d.ts.map +1 -0
- package/lib/mappers/types/schemaResolution.types.d.ts +9 -0
- package/lib/mappers/types/schemaResolution.types.d.ts.map +1 -0
- package/lib/objectstore/index.d.ts +3 -71
- package/lib/objectstore/index.d.ts.map +1 -0
- package/lib/objectstore/{index.d.mts → interfaces/objectstore.interface.d.ts} +3 -16
- package/lib/objectstore/interfaces/objectstore.interface.d.ts.map +1 -0
- package/lib/objectstore/objectstoreKey.d.ts +11 -0
- package/lib/objectstore/objectstoreKey.d.ts.map +1 -0
- package/lib/persistence/complianceEventSubscriber.d.ts +13 -0
- package/lib/persistence/complianceEventSubscriber.d.ts.map +1 -0
- package/lib/persistence/compliancePropertyBuilder.d.ts +26 -0
- package/lib/persistence/compliancePropertyBuilder.d.ts.map +1 -0
- package/lib/persistence/complianceTypes.d.ts +64 -0
- package/lib/persistence/complianceTypes.d.ts.map +1 -0
- package/lib/persistence/defineComplianceEntity.d.ts +19 -0
- package/lib/persistence/defineComplianceEntity.d.ts.map +1 -0
- package/lib/persistence/encryptedType.d.ts +85 -0
- package/lib/persistence/encryptedType.d.ts.map +1 -0
- package/lib/persistence/fieldEncryptor.d.ts +48 -0
- package/lib/persistence/fieldEncryptor.d.ts.map +1 -0
- package/lib/persistence/index.d.ts +10 -403
- package/lib/persistence/index.d.ts.map +1 -0
- package/lib/persistence/index.js.map +1 -1
- package/lib/persistence/index.mjs.map +1 -1
- package/lib/persistence/rls.d.ts +56 -0
- package/lib/persistence/rls.d.ts.map +1 -0
- package/lib/persistence/tenantEm.d.ts +60 -0
- package/lib/persistence/tenantEm.d.ts.map +1 -0
- package/lib/persistence/tenantFilter.d.ts +47 -0
- package/lib/persistence/tenantFilter.d.ts.map +1 -0
- package/lib/secrets/index.d.ts +2 -0
- package/lib/secrets/index.d.ts.map +1 -0
- package/lib/secrets/secretsAccessor.d.ts +17 -0
- package/lib/secrets/secretsAccessor.d.ts.map +1 -0
- package/lib/services/complianceDataService.d.ts +47 -0
- package/lib/services/complianceDataService.d.ts.map +1 -0
- package/lib/services/configInjector.d.ts +43 -0
- package/lib/services/configInjector.d.ts.map +1 -0
- package/lib/services/guards/isConstructed.d.ts +3 -0
- package/lib/services/guards/isConstructed.d.ts.map +1 -0
- package/lib/services/guards/isConstructedSingleton.d.ts +3 -0
- package/lib/services/guards/isConstructedSingleton.d.ts.map +1 -0
- package/lib/services/guards/isConstructor.d.ts +3 -0
- package/lib/services/guards/isConstructor.d.ts.map +1 -0
- package/lib/services/index.d.ts +10 -184
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/retentionService.d.ts +31 -0
- package/lib/services/retentionService.d.ts.map +1 -0
- package/lib/services/runRetentionEnforcement.d.ts +19 -0
- package/lib/services/runRetentionEnforcement.d.ts.map +1 -0
- package/lib/services/types/configInjector.types.d.ts +39 -0
- package/lib/services/types/configInjector.types.d.ts.map +1 -0
- package/lib/services/types/entityManager.types.d.ts +4 -0
- package/lib/services/types/entityManager.types.d.ts.map +1 -0
- package/lib/services/types/service.types.d.ts +5 -0
- package/lib/services/types/service.types.d.ts.map +1 -0
- package/lib/ws/asyncApiV3Generator/asyncApiV3Generator.d.ts +12 -0
- package/lib/ws/asyncApiV3Generator/asyncApiV3Generator.d.ts.map +1 -0
- package/lib/ws/index.d.ts +4 -67
- package/lib/ws/index.d.ts.map +1 -0
- package/lib/ws/index.js.map +1 -1
- package/lib/ws/index.mjs.map +1 -1
- package/lib/ws/types/eventSchema.types.d.ts +28 -0
- package/lib/ws/types/eventSchema.types.d.ts.map +1 -0
- package/lib/ws/webSocketLike.d.ts +18 -0
- package/lib/ws/webSocketLike.d.ts.map +1 -0
- package/package.json +33 -33
- package/lib/apiDefinition.types-DF_crhB0.d.mts +0 -1092
- package/lib/apiDefinition.types-DW4lfZqy.d.ts +0 -1092
- package/lib/http/index.d.mts +0 -1244
- package/lib/mappers/index.d.mts +0 -68
- package/lib/openTelemetryCollector-BS-ej09T.d.mts +0 -70
- package/lib/openTelemetryCollector-BS-ej09T.d.ts +0 -70
- package/lib/persistence/index.d.mts +0 -403
- package/lib/services/index.d.mts +0 -185
- package/lib/ttlCache.interface-CEOkrt8d.d.mts +0 -77
- package/lib/ttlCacheRecord.types-oX0ti5SP.d.ts +0 -25
- package/lib/ws/index.d.mts +0 -67
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { Prettify, TypeSafeFunction, UnionToIntersection } from '@forklaunch/common';
|
|
2
|
+
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
3
|
+
import { LiveSdkFunction, LiveTypeFunction } from './apiDefinition.types';
|
|
4
|
+
import { AuthMethodsBase, Body, HeadersObject, Method, ParamsObject, QueryObject, ResponsesObject, VersionSchema } from './contractDetails.types';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a type-safe fetch function based on a provided fetch map.
|
|
7
|
+
* This type generates a function that provides compile-time type safety for HTTP requests,
|
|
8
|
+
* ensuring that the correct path and request parameters are used for each endpoint.
|
|
9
|
+
*
|
|
10
|
+
* @template FetchMap - A record mapping paths to their corresponding TypeSafeFunction signatures
|
|
11
|
+
* @param FetchMap[Path] - Each path should map to a TypeSafeFunction that defines the request/response contract
|
|
12
|
+
*
|
|
13
|
+
* @returns A generic function that:
|
|
14
|
+
* - Takes a path parameter constrained to keys of FetchMap
|
|
15
|
+
* - Takes optional request initialization parameters based on the function signature
|
|
16
|
+
* - Returns a Promise of the expected response type
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* The function parameters are conditionally typed:
|
|
20
|
+
* - If the mapped function expects body, query, params, or headers, reqInit is required
|
|
21
|
+
* - Otherwise, reqInit is optional
|
|
22
|
+
* - If the path doesn't map to a TypeSafeFunction, reqInit is never
|
|
23
|
+
**/
|
|
24
|
+
export type FetchFunction<FetchMap> = <const Path extends keyof FetchMap, const Method extends keyof FetchMap[Path], const Version extends keyof FetchMap[Path][Method]>(path: Path, ...reqInit: FetchMap[Path][Method] extends TypeSafeFunction ? 'GET' extends keyof FetchMap[Path] ? FetchMap[Path]['GET'] extends TypeSafeFunction ? Parameters<FetchMap[Path]['GET']>[1] extends {
|
|
25
|
+
body: unknown;
|
|
26
|
+
} | {
|
|
27
|
+
query: unknown;
|
|
28
|
+
} | {
|
|
29
|
+
params: unknown;
|
|
30
|
+
} | {
|
|
31
|
+
headers: unknown;
|
|
32
|
+
} | {
|
|
33
|
+
version: unknown;
|
|
34
|
+
} ? [
|
|
35
|
+
reqInit: Omit<Parameters<FetchMap[Path][Method]>[1], 'method'> & {
|
|
36
|
+
method: Method;
|
|
37
|
+
}
|
|
38
|
+
] : [
|
|
39
|
+
reqInit?: Omit<Parameters<FetchMap[Path][Method]>[1], 'method'> & {
|
|
40
|
+
method: Method;
|
|
41
|
+
}
|
|
42
|
+
] : [
|
|
43
|
+
reqInit: Omit<Parameters<FetchMap[Path][Method]>[1], 'method'> & {
|
|
44
|
+
method: Method;
|
|
45
|
+
}
|
|
46
|
+
] : [
|
|
47
|
+
reqInit: Omit<Parameters<FetchMap[Path][Method]>[1], 'method'> & {
|
|
48
|
+
method: Method;
|
|
49
|
+
}
|
|
50
|
+
] : FetchMap[Path][Method] extends Record<string, TypeSafeFunction> ? [
|
|
51
|
+
reqInit: Omit<Parameters<FetchMap[Path][Method][Version]>[0], 'method' | 'version'> & {
|
|
52
|
+
method: Method;
|
|
53
|
+
version: Version;
|
|
54
|
+
}
|
|
55
|
+
] : [{
|
|
56
|
+
method: Method;
|
|
57
|
+
}]) => Promise<FetchMap[Path][Method] extends TypeSafeFunction ? Awaited<ReturnType<FetchMap[Path][Method]>> : FetchMap[Path][Method] extends Record<string, TypeSafeFunction> ? Awaited<ReturnType<FetchMap[Path][Method][Version]>> : never>;
|
|
58
|
+
/**
|
|
59
|
+
* Represents the structure of a SDK router.
|
|
60
|
+
*
|
|
61
|
+
* @property sdk - The SDK object containing all the SDK functions.
|
|
62
|
+
* @property _fetchMap - The fetch map object containing all the fetch functions.
|
|
63
|
+
* @property sdkPaths - The SDK paths object containing all the SDK paths.
|
|
64
|
+
*/
|
|
65
|
+
export type SdkRouter = {
|
|
66
|
+
sdk: Record<string, unknown>;
|
|
67
|
+
_fetchMap: Record<string, unknown>;
|
|
68
|
+
sdkPaths: Record<string, string>;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Recursive interface representing a hierarchical map of router configurations.
|
|
72
|
+
* Each entry can either be a leaf node with SDK and fetch map configurations,
|
|
73
|
+
* or a nested RouterMap for deeper routing structures.
|
|
74
|
+
*
|
|
75
|
+
* @template SV - The schema validator type that constrains the router structure
|
|
76
|
+
* @param SV - Must extend AnySchemaValidator to ensure type safety
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const routerMap: RouterMap<ZodValidator> = {
|
|
81
|
+
* api: {
|
|
82
|
+
* users: {
|
|
83
|
+
* sdk: { getUser: () => Promise.resolve({}) },
|
|
84
|
+
* _fetchMap: { getUser: { get: () => fetch('/api/users') } }
|
|
85
|
+
* },
|
|
86
|
+
* posts: {
|
|
87
|
+
* sdk: { getPosts: () => Promise.resolve([]) },
|
|
88
|
+
* _fetchMap: { getPosts: { get: () => fetch('/api/posts') } }
|
|
89
|
+
* }
|
|
90
|
+
* }
|
|
91
|
+
* };
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export type RouterMap<SV extends AnySchemaValidator> = {
|
|
95
|
+
[K: string]: SdkRouter | RouterMap<SV>;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Recursive type representing a hierarchical map of SDK handlers.
|
|
99
|
+
* Each key can either be a leaf node containing a SdkHandler, or a nested SdkHandlerObject for deeper structures.
|
|
100
|
+
*
|
|
101
|
+
* @template SV - The schema validator type that constrains the handler structure.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const handlers: SdkHandlerObject<ZodValidator> = {
|
|
106
|
+
* users: {
|
|
107
|
+
* getUser: someSdkHandler,
|
|
108
|
+
* posts: {
|
|
109
|
+
* getPosts: anotherSdkHandler
|
|
110
|
+
* }
|
|
111
|
+
* }
|
|
112
|
+
* };
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export type SdkHandlerObject<SV extends AnySchemaValidator> = {
|
|
116
|
+
[K: string]: SdkHandler | SdkHandlerObject<SV>;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* @deprecated
|
|
120
|
+
* Tail-recursive type that extracts and flattens fetch map interfaces from a RouterMap structure.
|
|
121
|
+
* This version uses an accumulator pattern to avoid deep recursion and improve performance.
|
|
122
|
+
* Similar to MapToSdk but focuses on _fetchMap properties and merges all fetch maps into a single intersection type.
|
|
123
|
+
*
|
|
124
|
+
* @template SV - The schema validator type
|
|
125
|
+
* @template T - The RouterMap to extract fetch maps from
|
|
126
|
+
* @template Acc - The accumulator type for collecting fetch maps (defaults to empty object)
|
|
127
|
+
* @param SV - Must extend AnySchemaValidator
|
|
128
|
+
* @param T - Must extend RouterMap<SV>
|
|
129
|
+
* @param Acc - The accumulated fetch maps so far
|
|
130
|
+
*
|
|
131
|
+
* @returns An intersection type containing all fetch map interfaces from the router structure,
|
|
132
|
+
* flattened into a single type for unified fetch functionality
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* // Given a RouterMap with nested fetch maps
|
|
137
|
+
* type ExtractedFetch = MapToFetch<ZodValidator, typeof routerMap>;
|
|
138
|
+
* // Results in: { getUser: { get: () => Promise<Response> } } & { getPosts: { get: () => Promise<Response> } }
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export type MapToFetch<SV extends AnySchemaValidator, T extends RouterMap<SV>> = UnionToIntersection<Prettify<{
|
|
142
|
+
[K in keyof T]: T[K] extends RouterMap<SV> ? MapToFetch<SV, T[K]> : T[K] extends {
|
|
143
|
+
_fetchMap: unknown;
|
|
144
|
+
} ? T[K]['_fetchMap'] extends Record<string, unknown> ? T[K]['_fetchMap'] : never : never;
|
|
145
|
+
}[keyof T]>>;
|
|
146
|
+
/**
|
|
147
|
+
* Base interface for controller entries that defines the structure
|
|
148
|
+
* of each controller method with its path, HTTP method, and contract details.
|
|
149
|
+
* This type serves as the foundation for type-safe SDK generation by ensuring
|
|
150
|
+
* all controller entries follow a consistent structure.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const controller: Record<string, SdkHandler> = {
|
|
155
|
+
* createUser: {
|
|
156
|
+
* _path: '/users',
|
|
157
|
+
* _method: 'post',
|
|
158
|
+
* contractDetails: {
|
|
159
|
+
* name: 'createUser',
|
|
160
|
+
* body: { name: string, email: string },
|
|
161
|
+
* responses: { 201: { id: string, name: string } }
|
|
162
|
+
* }
|
|
163
|
+
* }
|
|
164
|
+
* };
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export type SdkHandler = {
|
|
168
|
+
/** The HTTP path for this endpoint, must start with '/' */
|
|
169
|
+
_path?: `/${string}`;
|
|
170
|
+
/** The HTTP method for this endpoint (get, post, put, etc.) */
|
|
171
|
+
_method?: Method;
|
|
172
|
+
/** Contract details defining the request/response schema for this endpoint */
|
|
173
|
+
contractDetails: {
|
|
174
|
+
/** The name of this endpoint/method */
|
|
175
|
+
name: string;
|
|
176
|
+
/** URL parameters schema */
|
|
177
|
+
params?: unknown;
|
|
178
|
+
/** Response schemas for different status codes */
|
|
179
|
+
responses?: unknown;
|
|
180
|
+
/** Query parameters schema */
|
|
181
|
+
query?: unknown;
|
|
182
|
+
/** Request body schema */
|
|
183
|
+
body?: unknown;
|
|
184
|
+
/** Request headers schema */
|
|
185
|
+
requestHeaders?: unknown;
|
|
186
|
+
/** Response headers schema */
|
|
187
|
+
responseHeaders?: unknown;
|
|
188
|
+
/** Authentication requirements */
|
|
189
|
+
auth?: unknown;
|
|
190
|
+
/** API versioning information */
|
|
191
|
+
versions?: unknown;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Recursively maps a client controller definition to its corresponding live SDK function types.
|
|
196
|
+
*
|
|
197
|
+
* This utility type traverses the structure of a client controller object, replacing each
|
|
198
|
+
* {@link SdkHandler} with its corresponding {@link MapHandlerToLiveSdk} type, while recursively
|
|
199
|
+
* processing nested objects. This enables type-safe SDK generation for complex controller hierarchies.
|
|
200
|
+
*
|
|
201
|
+
* @template SV - The schema validator type (e.g., zod, typebox).
|
|
202
|
+
* @template Client - The client controller object to map.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* type MySdk = MapToSdk<typeof z, typeof myController>;
|
|
206
|
+
*/
|
|
207
|
+
export type MapToSdk<SV extends AnySchemaValidator, Client> = {
|
|
208
|
+
[K in keyof Client]: Client[K] extends SdkHandler ? MapHandlerToLiveSdk<SV, Client[K]> : MapToSdk<SV, Client[K]>;
|
|
209
|
+
};
|
|
210
|
+
export type MapHandlerToLiveSdk<SV extends AnySchemaValidator, T extends SdkHandler> = LiveSdkFunction<SV, T['contractDetails']['params'] extends infer Params | undefined ? Params extends ParamsObject<SV> ? Params : ParamsObject<SV> : ParamsObject<SV>, T['contractDetails']['responses'] extends infer Responses | undefined ? Responses extends ResponsesObject<SV> ? Responses : ResponsesObject<SV> : ResponsesObject<SV>, T['contractDetails']['body'] extends infer B | undefined ? B extends Body<SV> ? B : Body<SV> : Body<SV>, T['contractDetails']['query'] extends infer Q | undefined ? Q extends QueryObject<SV> ? Q : QueryObject<SV> : QueryObject<SV>, T['contractDetails']['requestHeaders'] extends infer RequestHeaders | undefined ? RequestHeaders extends HeadersObject<SV> ? RequestHeaders : HeadersObject<SV> : HeadersObject<SV>, T['contractDetails']['responseHeaders'] extends infer ResponseHeaders | undefined ? ResponseHeaders extends HeadersObject<SV> ? ResponseHeaders : HeadersObject<SV> : HeadersObject<SV>, T['contractDetails']['versions'] extends infer Versions | undefined ? Versions extends VersionSchema<SV, Method> ? Versions : VersionSchema<SV, Method> : VersionSchema<SV, Method>, T['contractDetails']['auth'] extends infer Auth | undefined ? Auth extends AuthMethodsBase ? Auth : AuthMethodsBase : AuthMethodsBase>;
|
|
211
|
+
/**
|
|
212
|
+
* @deprecated
|
|
213
|
+
* Extracts and constructs a LiveTypeFunction from an SdkHandler object.
|
|
214
|
+
* This optimized version reduces redundant type inference while maintaining type safety.
|
|
215
|
+
*
|
|
216
|
+
* @template Entry - The controller entry containing path, method, and contract details
|
|
217
|
+
* @template SV - The schema validator type that constrains the contract details
|
|
218
|
+
* @template BasePath - The base path prefix to prepend to the entry's path
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* type UserCreateFunction = ExtractLiveTypeFn<
|
|
223
|
+
* { _path: '/users', _method: 'post', contractDetails: { body: { name: string } } },
|
|
224
|
+
* SchemaValidator,
|
|
225
|
+
* '/api/v1'
|
|
226
|
+
* >;
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
export type ExtractLiveTypeFn<Entry extends SdkHandler, SV extends AnySchemaValidator, BasePath extends `/${string}`> = LiveTypeFunction<SV, Entry['_path'] extends infer Path | undefined ? Path extends `/${string}` ? `${BasePath}${Path}` : never : never, Entry['contractDetails']['params'] extends infer Params | undefined ? Params extends ParamsObject<SV> ? Params : ParamsObject<SV> : ParamsObject<SV>, Entry['contractDetails']['responses'] extends infer Responses | undefined ? Responses extends ResponsesObject<SV> ? Responses : ResponsesObject<SV> : ResponsesObject<SV>, Entry['contractDetails']['body'] extends infer B | undefined ? B extends Body<SV> ? B : Body<SV> : Body<SV>, Entry['contractDetails']['query'] extends infer Q | undefined ? Q extends QueryObject<SV> ? Q : QueryObject<SV> : QueryObject<SV>, Entry['contractDetails']['requestHeaders'] extends infer RequestHeaders | undefined ? RequestHeaders extends HeadersObject<SV> ? RequestHeaders : HeadersObject<SV> : HeadersObject<SV>, Entry['contractDetails']['responseHeaders'] extends infer ResponseHeaders | undefined ? ResponseHeaders extends HeadersObject<SV> ? ResponseHeaders : HeadersObject<SV> : HeadersObject<SV>, Entry['_method'] extends Method ? Entry['_method'] : never, Entry['contractDetails']['versions'] extends infer Versions | undefined ? Versions extends VersionSchema<SV, Method> ? Versions : VersionSchema<SV, Method> : VersionSchema<SV, Method>, Entry['contractDetails']['auth'] extends infer Auth | undefined ? Auth extends AuthMethodsBase ? Auth : AuthMethodsBase : AuthMethodsBase>;
|
|
230
|
+
/**
|
|
231
|
+
* @deprecated
|
|
232
|
+
* Transforms a controller object into a fetch map structure that provides
|
|
233
|
+
* type-safe access to HTTP endpoints. This optimized version reduces complexity
|
|
234
|
+
* while maintaining full type safety and discriminated union behavior.
|
|
235
|
+
*
|
|
236
|
+
* @template T - The controller object type containing all endpoint definitions
|
|
237
|
+
* @template SV - The schema validator type that constrains the contract details
|
|
238
|
+
* @template RouterBasePath - The base path prefix for the router
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* const controller = {
|
|
243
|
+
* createUser: { _path: '/users', _method: 'post', contractDetails: { body: { name: string } } },
|
|
244
|
+
* getUser: { _path: '/users/:id', _method: 'get', contractDetails: { params: { id: string } } }
|
|
245
|
+
* } as const;
|
|
246
|
+
*
|
|
247
|
+
* type FetchMap = ToFetchMap<typeof controller, SchemaValidator, '/api/v1'>;
|
|
248
|
+
* // Results in properly typed fetch map with discriminated methods per path
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
export type ToFetchMap<T extends Record<string, SdkHandler>, SV extends AnySchemaValidator, RouterBasePath extends `/${string}`> = Prettify<{
|
|
252
|
+
[K in keyof T as T[K]['_path'] extends infer P | undefined ? P extends `/${string}` ? `${RouterBasePath}${P}` : never : never]: {
|
|
253
|
+
[M in T[K]['_method'] as M extends Method ? Uppercase<M> : never]: ExtractLiveTypeFn<Extract<T[K], {
|
|
254
|
+
_path: T[K]['_path'];
|
|
255
|
+
_method: M;
|
|
256
|
+
}>, SV, RouterBasePath>;
|
|
257
|
+
};
|
|
258
|
+
}>;
|
|
259
|
+
//# sourceMappingURL=sdk.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.types.d.ts","sourceRoot":"","sources":["../../../src/http/types/sdk.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EACL,eAAe,EACf,IAAI,EACJ,aAAa,EACb,MAAM,EACN,YAAY,EACZ,WAAW,EACX,eAAe,EACf,aAAa,EACd,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;;;;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,iBAAiB,CAClB,OAAO,CACL,CAAC,CAAC,CAAC,CAAC,EACJ;YACE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YACrB,OAAO,EAAE,CAAC,CAAC;SACZ,CACF,EACD,EAAE,EACF,cAAc,CACf;KACF;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
2
|
+
import { ExpressLikeSchemaHandler } from './apiDefinition.types';
|
|
3
|
+
import { Body, ContractDetails, HeadersObject, Method, ParamsObject, QueryObject, ResolvedSessionObject, ResponsesObject, SchemaAuthMethods, SessionObject, VersionSchema } from './contractDetails.types';
|
|
4
|
+
export type ContractDetailsExpressLikeSchemaHandler<SV extends AnySchemaValidator, ContractMethod extends Method, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, VersionedApi extends VersionSchema<SV, ContractMethod>, BaseRequest, BaseResponse, NextFunction, Auth extends SchemaAuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedApi, BaseRequest>> = ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, VersionedApi, ResolvedSessionObject<SV, Auth, SessionObject<SV>>, BaseRequest, BaseResponse, NextFunction>;
|
|
5
|
+
export type TypedHandler<SV extends AnySchemaValidator, Name extends string, ContractMethod extends Method, Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, VersionedApi extends VersionSchema<SV, ContractMethod>, BaseRequest, BaseResponse, NextFunction, Auth extends SchemaAuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedApi, BaseRequest>> = {
|
|
6
|
+
_typedHandler: true;
|
|
7
|
+
_path: Path | undefined;
|
|
8
|
+
contractDetails: ContractDetails<SV, Name, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth>;
|
|
9
|
+
handlers: ContractDetailsExpressLikeSchemaHandler<SV, ContractMethod, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, VersionedApi, BaseRequest, BaseResponse, NextFunction, Auth>[];
|
|
10
|
+
};
|
|
11
|
+
export type ExpressLikeTypedHandler<SV extends AnySchemaValidator, Name extends string, ContractMethod extends Method, Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, VersionedApi extends VersionSchema<SV, ContractMethod>, BaseRequest, BaseResponse, NextFunction, Auth extends SchemaAuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedApi, BaseRequest>> = {
|
|
12
|
+
_typedHandler: true;
|
|
13
|
+
_path: Path | undefined;
|
|
14
|
+
_method: ContractMethod;
|
|
15
|
+
contractDetails: ContractDetails<SV, Name, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth>;
|
|
16
|
+
handlers: ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, VersionedApi, ResolvedSessionObject<SV, Auth, SessionObject<SV>>, BaseRequest, BaseResponse, NextFunction>[];
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=typedHandler.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typedHandler.types.d.ts","sourceRoot":"","s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eAAe,CAAC,EAAE,CAAC,EACtC,OAAO,SAAS,IAAI,CAAC,EAAE,CAAC,EACxB,QAAQ,SAAS,WAAW,CAAC,EAAE,CAAC,EAChC,UAAU,SAAS,aAAa,CAAC,EAAE,CAAC,EACpC,UAAU,SAAS,aAAa,CAAC,EAAE,CAAC,EACpC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,YAAY,SAAS,aAAa,CAAC,EAAE,EAAE,cAAc,CAAC,EACtD,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,IAAI,SAAS,iBAAiB,CAC5B,EAAE,EACF,CAAC,EACD,OAAO,EACP,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,WAAW,CACZ,IACC;IACF,aAAa,EAAE,IAAI,CAAC;IACpB,KAAK,EAAE,IAAI,GAAG,SAAS,CAAC;IACxB,OAAO,EAAE,cAAc,CAAC;IACxB,eAAe,EAAE,eAAe,CAC9B,EAAE,EACF,IAAI,EACJ,cAAc,EACd,IAAI,EACJ,CAAC,EACD,UAAU,EACV,OAAO,EACP,QAAQ,EACR,UAAU,EACV,UAAU,EACV,YAAY,EACZ,WAAW,EACX,IAAI,CACL,CAAC;IACF,QAAQ,EAAE,wBAAwB,CAChC,EAAE,EACF,CAAC,EACD,UAAU,EACV,OAAO,EACP,QAAQ,EACR,UAAU,EACV,UAAU,EACV,SAAS,EACT,YAAY,EACZ,qBAAqB,CAAC,EAAE,EAAE,IAAI,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,EAClD,WAAW,EACX,YAAY,EACZ,YAAY,CACb,EAAE,CAAC;CACL,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SchemaResolutionFunction } from '../types/schemaResolution.types';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard to determine if a value is a SchemaResolutionFunction.
|
|
4
|
+
*
|
|
5
|
+
* @template Args - The type of the options object expected by the schema resolution function.
|
|
6
|
+
* @param {unknown} value - The value to check.
|
|
7
|
+
* @returns {value is SchemaResolutionFunction<Args>} True if the value is a function (assumed to be a SchemaResolutionFunction), false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isSchemaResolutionFunction<Args extends Record<string, unknown>>(value: unknown): value is SchemaResolutionFunction<Args>;
|
|
10
|
+
//# sourceMappingURL=isSchemaResolutionFunction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isSchemaResolutionFunction.d.ts","sourceRoot":"","sources":["../../../src/mappers/guards/isSchemaResolutionFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAE3E;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,wBAAwB,CAAC,IAAI,CAAC,CAEzD"}
|
package/lib/mappers/index.d.ts
CHANGED
|
@@ -1,68 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare function requestMapper<SV extends AnySchemaValidator, DomainSchema extends IdiomaticSchema<SV>, Entity extends EntitySchema, AdditionalArgs extends unknown[] = []>({ schemaValidator, schema, entity, mapperDefinition }: {
|
|
6
|
-
schemaValidator: SV;
|
|
7
|
-
schema: DomainSchema;
|
|
8
|
-
entity: Entity;
|
|
9
|
-
mapperDefinition: {
|
|
10
|
-
toEntity: (dto: Schema<DomainSchema, SV>, ...args: AdditionalArgs) => Promise<InferEntity<Entity>>;
|
|
11
|
-
};
|
|
12
|
-
}): {
|
|
13
|
-
entity: Entity;
|
|
14
|
-
schema: DomainSchema;
|
|
15
|
-
} & typeof mapperDefinition;
|
|
16
|
-
declare function responseMapper<SV extends AnySchemaValidator, DomainSchema extends IdiomaticSchema<SV>, Entity extends EntitySchema, AdditionalArgs extends unknown[] = []>({ schemaValidator, schema, entity, mapperDefinition }: {
|
|
17
|
-
schemaValidator: SV;
|
|
18
|
-
schema: DomainSchema;
|
|
19
|
-
entity: Entity;
|
|
20
|
-
mapperDefinition: {
|
|
21
|
-
toDto: (entity: InferEntity<Entity>, ...args: AdditionalArgs) => Promise<Schema<DomainSchema, SV>>;
|
|
22
|
-
};
|
|
23
|
-
}): Prettify<{
|
|
24
|
-
entity: Entity;
|
|
25
|
-
schema: DomainSchema;
|
|
26
|
-
} & typeof mapperDefinition>;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* A function type that, given an options object, returns a schema or schema-like object.
|
|
30
|
-
*
|
|
31
|
-
* @template Args - The type of the options object, typically an object with configuration or dependencies.
|
|
32
|
-
* @param {Args} options - The options to use for schema resolution (e.g., validator, uuidId, etc.).
|
|
33
|
-
* @returns {unknown} The resolved schema or schema-like object.
|
|
34
|
-
*/
|
|
35
|
-
type SchemaResolutionFunction<Args extends Record<string, unknown>> = (options: Args) => unknown;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Maps a set of service schema factories or pre-instantiated schemas to their resolved schemas using the provided arguments.
|
|
39
|
-
*
|
|
40
|
-
* This utility allows you to provide an object whose values are either:
|
|
41
|
-
* - Schema factory functions (SchemaResolutionFunction) that accept an options object (Args) and return a schema or schema group.
|
|
42
|
-
* - Already-instantiated schemas (IdiomaticSchema).
|
|
43
|
-
*
|
|
44
|
-
* Each factory function will be called with the provided `args` object, and the result will be included in the returned mapping.
|
|
45
|
-
* If a value is already a schema (not a function), it is returned as-is.
|
|
46
|
-
*
|
|
47
|
-
* @template SV - The schema validator type.
|
|
48
|
-
* @template T - An object whose values are either schema factory functions or instantiated schemas.
|
|
49
|
-
* @template Args - The type of the options object passed to each factory function (e.g., { validator, uuidId, ... }).
|
|
50
|
-
*
|
|
51
|
-
* @param {T} schemas - An object mapping schema names to either factory functions (SchemaResolutionFunction) or instantiated schemas (IdiomaticSchema).
|
|
52
|
-
* @param {Args} args - The options object to be passed to each schema factory function.
|
|
53
|
-
* @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.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* const schemas = {
|
|
57
|
-
* UserSchemas: (opts) => createUserSchemas(opts),
|
|
58
|
-
* ProductSchemas: (opts) => createProductSchemas(opts),
|
|
59
|
-
* AlreadyInstantiated: someSchemaObject
|
|
60
|
-
* };
|
|
61
|
-
* const mapped = mapServiceSchemas(schemas, { validator: myValidator });
|
|
62
|
-
* // mapped.UserSchemas and mapped.ProductSchemas are instantiated, mapped.AlreadyInstantiated is passed through
|
|
63
|
-
*/
|
|
64
|
-
declare function mapServiceSchemas<SV extends AnySchemaValidator, T extends Record<string, SchemaResolutionFunction<Args> | IdiomaticSchema<SV>>, Args extends Record<string, unknown>>(schemas: T, args: Args): {
|
|
65
|
-
[K in keyof T]: T[K] extends SchemaResolutionFunction<Args> ? ReturnType<T[K]> : T[K];
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export { mapServiceSchemas, requestMapper, responseMapper };
|
|
1
|
+
export * from './mapper';
|
|
2
|
+
export * from './mapServiceSchemas';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mappers/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AnySchemaValidator, IdiomaticSchema } from '@forklaunch/validator';
|
|
2
|
+
import { SchemaResolutionFunction } from './types/schemaResolution.types';
|
|
3
|
+
/**
|
|
4
|
+
* Maps a set of service schema factories or pre-instantiated schemas to their resolved schemas using the provided arguments.
|
|
5
|
+
*
|
|
6
|
+
* This utility allows you to provide an object whose values are either:
|
|
7
|
+
* - Schema factory functions (SchemaResolutionFunction) that accept an options object (Args) and return a schema or schema group.
|
|
8
|
+
* - Already-instantiated schemas (IdiomaticSchema).
|
|
9
|
+
*
|
|
10
|
+
* Each factory function will be called with the provided `args` object, and the result will be included in the returned mapping.
|
|
11
|
+
* If a value is already a schema (not a function), it is returned as-is.
|
|
12
|
+
*
|
|
13
|
+
* @template SV - The schema validator type.
|
|
14
|
+
* @template T - An object whose values are either schema factory functions or instantiated schemas.
|
|
15
|
+
* @template Args - The type of the options object passed to each factory function (e.g., { validator, uuidId, ... }).
|
|
16
|
+
*
|
|
17
|
+
* @param {T} schemas - An object mapping schema names to either factory functions (SchemaResolutionFunction) or instantiated schemas (IdiomaticSchema).
|
|
18
|
+
* @param {Args} args - The options object to be passed to each schema factory function.
|
|
19
|
+
* @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.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const schemas = {
|
|
23
|
+
* UserSchemas: (opts) => createUserSchemas(opts),
|
|
24
|
+
* ProductSchemas: (opts) => createProductSchemas(opts),
|
|
25
|
+
* AlreadyInstantiated: someSchemaObject
|
|
26
|
+
* };
|
|
27
|
+
* const mapped = mapServiceSchemas(schemas, { validator: myValidator });
|
|
28
|
+
* // mapped.UserSchemas and mapped.ProductSchemas are instantiated, mapped.AlreadyInstantiated is passed through
|
|
29
|
+
*/
|
|
30
|
+
export declare function mapServiceSchemas<SV extends AnySchemaValidator, T extends Record<string, SchemaResolutionFunction<Args> | IdiomaticSchema<SV>>, Args extends Record<string, unknown>>(schemas: T, args: Args): {
|
|
31
|
+
[K in keyof T]: T[K] extends SchemaResolutionFunction<Args> ? ReturnType<T[K]> : T[K];
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=mapServiceSchemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapServiceSchemas.d.ts","sourceRoot":"","sources":["../../src/mappers/mapServiceSchemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,SAAS,kBAAkB,EAC7B,CAAC,SAAS,MAAM,CACd,MAAM,EACN,wBAAwB,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,EAAE,CAAC,CACrD,EACD,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAEpC,OAAO,EAAE,CAAC,EACV,IAAI,EAAE,IAAI,GACT;KACA,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,wBAAwB,CAAC,IAAI,CAAC,GACvD,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAChB,CAAC,CAAC,CAAC,CAAC;CACT,CAWA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Prettify } from '@forklaunch/common';
|
|
2
|
+
import { AnySchemaValidator, IdiomaticSchema, Schema } from '@forklaunch/validator';
|
|
3
|
+
import { EntitySchema, InferEntity } from '@mikro-orm/core';
|
|
4
|
+
export declare function requestMapper<SV extends AnySchemaValidator, DomainSchema extends IdiomaticSchema<SV>, Entity extends EntitySchema, AdditionalArgs extends unknown[] = []>({ schemaValidator, schema, entity, mapperDefinition }: {
|
|
5
|
+
schemaValidator: SV;
|
|
6
|
+
schema: DomainSchema;
|
|
7
|
+
entity: Entity;
|
|
8
|
+
mapperDefinition: {
|
|
9
|
+
toEntity: (dto: Schema<DomainSchema, SV>, ...args: AdditionalArgs) => Promise<InferEntity<Entity>>;
|
|
10
|
+
};
|
|
11
|
+
}): {
|
|
12
|
+
entity: Entity;
|
|
13
|
+
schema: DomainSchema;
|
|
14
|
+
} & typeof mapperDefinition;
|
|
15
|
+
export declare function responseMapper<SV extends AnySchemaValidator, DomainSchema extends IdiomaticSchema<SV>, Entity extends EntitySchema, AdditionalArgs extends unknown[] = []>({ schemaValidator, schema, entity, mapperDefinition }: {
|
|
16
|
+
schemaValidator: SV;
|
|
17
|
+
schema: DomainSchema;
|
|
18
|
+
entity: Entity;
|
|
19
|
+
mapperDefinition: {
|
|
20
|
+
toDto: (entity: InferEntity<Entity>, ...args: AdditionalArgs) => Promise<Schema<DomainSchema, SV>>;
|
|
21
|
+
};
|
|
22
|
+
}): Prettify<{
|
|
23
|
+
entity: Entity;
|
|
24
|
+
schema: DomainSchema;
|
|
25
|
+
} & typeof mapperDefinition>;
|
|
26
|
+
//# sourceMappingURL=mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapper.d.ts","sourceRoot":"","sources":["../../src/mappers/mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EACL,kBAAkB,EAClB,eAAe,EAEf,MAAM,EAEP,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE5D,wBAAgB,aAAa,CAC3B,EAAE,SAAS,kBAAkB,EAC7B,YAAY,SAAS,eAAe,CAAC,EAAE,CAAC,EACxC,MAAM,SAAS,YAAY,EAC3B,cAAc,SAAS,OAAO,EAAE,GAAG,EAAE,EACrC,EACA,eAAe,EACf,MAAM,EACN,MAAM,EACN,gBAAgB,EACjB,EAAE;IACD,eAAe,EAAE,EAAE,CAAC;IACpB,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE;QAChB,QAAQ,EAAE,CACR,GAAG,EAAE,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC,EAC7B,GAAG,IAAI,EAAE,cAAc,KACpB,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;KACnC,CAAC;CACH,GAAG;IACF,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,YAAY,CAAC;CACtB,GAAG,OAAO,gBAAgB,CAqB1B;AAED,wBAAgB,cAAc,CAC5B,EAAE,SAAS,kBAAkB,EAC7B,YAAY,SAAS,eAAe,CAAC,EAAE,CAAC,EACxC,MAAM,SAAS,YAAY,EAC3B,cAAc,SAAS,OAAO,EAAE,GAAG,EAAE,EACrC,EACA,eAAe,EACf,MAAM,EACN,MAAM,EACN,gBAAgB,EACjB,EAAE;IACD,eAAe,EAAE,EAAE,CAAC;IACpB,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE;QAChB,KAAK,EAAE,CACL,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAC3B,GAAG,IAAI,EAAE,cAAc,KACpB,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC;KACxC,CAAC;CACH,GAAG,QAAQ,CACV;IACE,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,YAAY,CAAC;CACtB,GAAG,OAAO,gBAAgB,CAC5B,CAgBA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function type that, given an options object, returns a schema or schema-like object.
|
|
3
|
+
*
|
|
4
|
+
* @template Args - The type of the options object, typically an object with configuration or dependencies.
|
|
5
|
+
* @param {Args} options - The options to use for schema resolution (e.g., validator, uuidId, etc.).
|
|
6
|
+
* @returns {unknown} The resolved schema or schema-like object.
|
|
7
|
+
*/
|
|
8
|
+
export type SchemaResolutionFunction<Args extends Record<string, unknown>> = (options: Args) => unknown;
|
|
9
|
+
//# sourceMappingURL=schemaResolution.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaResolution.types.d.ts","sourceRoot":"","sources":["../../../src/mappers/types/schemaResolution.types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,wBAAwB,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAC3E,OAAO,EAAE,IAAI,KACV,OAAO,CAAC"}
|
|
@@ -1,71 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Interface representing an object store.
|
|
6
|
-
*
|
|
7
|
-
* Methods that read or write object bodies accept an optional `compliance` parameter.
|
|
8
|
-
* When provided, bodies are encrypted on write and decrypted on read using
|
|
9
|
-
* the tenant ID for key derivation. When omitted, bodies are stored as plaintext.
|
|
10
|
-
*/
|
|
11
|
-
interface ObjectStore<Client> {
|
|
12
|
-
/**
|
|
13
|
-
* Puts a record into the objectstore.
|
|
14
|
-
*/
|
|
15
|
-
putObject<T>(object: T, compliance?: ComplianceContext): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* Puts a batch of records into the objectstore.
|
|
18
|
-
*/
|
|
19
|
-
putBatchObjects<T>(objects: T[], compliance?: ComplianceContext): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Streams an object upload to the objectstore.
|
|
22
|
-
*/
|
|
23
|
-
streamUploadObject<T>(object: T, compliance?: ComplianceContext): Promise<void>;
|
|
24
|
-
/**
|
|
25
|
-
* Streams a batch of object uploads to the objectstore.
|
|
26
|
-
*/
|
|
27
|
-
streamUploadBatchObjects<T>(objects: T[], compliance?: ComplianceContext): Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* Deletes a record from the objectstore.
|
|
30
|
-
*/
|
|
31
|
-
deleteObject(objectKey: string): Promise<void>;
|
|
32
|
-
/**
|
|
33
|
-
* Deletes a batch of records from the objectstore.
|
|
34
|
-
*/
|
|
35
|
-
deleteBatchObjects(objectKeys: string[]): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Reads a record from the objectstore.
|
|
38
|
-
*/
|
|
39
|
-
readObject<T>(objectKey: string, compliance?: ComplianceContext): Promise<T>;
|
|
40
|
-
/**
|
|
41
|
-
* Reads a batch of records from the objectstore.
|
|
42
|
-
*/
|
|
43
|
-
readBatchObjects<T>(objectKeys: string[], compliance?: ComplianceContext): Promise<T[]>;
|
|
44
|
-
/**
|
|
45
|
-
* Streams a download from the objectstore.
|
|
46
|
-
* Note: Streaming bypasses application-level encryption/decryption.
|
|
47
|
-
*/
|
|
48
|
-
streamDownloadObject(objectKey: string): Promise<Readable>;
|
|
49
|
-
/**
|
|
50
|
-
* Streams multiple downloads from the objectstore.
|
|
51
|
-
* Note: Streaming bypasses application-level encryption/decryption.
|
|
52
|
-
*/
|
|
53
|
-
streamDownloadBatchObjects(objectKeys: string[]): Promise<Readable[]>;
|
|
54
|
-
/**
|
|
55
|
-
* Gets the underlying objectstore client instance.
|
|
56
|
-
*/
|
|
57
|
-
getClient(): Client;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Creates a function that generates objectstore keys with a given prefix.
|
|
62
|
-
*
|
|
63
|
-
* @param {string} objectStoreKeyPrefix - The prefix to use for all objectstore keys
|
|
64
|
-
* @returns {Function} A function that takes an ID and returns a formatted objectstore key
|
|
65
|
-
* @example
|
|
66
|
-
* const createUserObjectStoreKey = createObjectStoreKey('user');
|
|
67
|
-
* const key = createUserObjectStoreKey('123'); // Returns 'user:123'
|
|
68
|
-
*/
|
|
69
|
-
declare const createObjectStoreKey: (objectStoreKeyPrefix: string) => (id: string | string[]) => string;
|
|
70
|
-
|
|
71
|
-
export { type ObjectStore, createObjectStoreKey };
|
|
1
|
+
export * from './interfaces/objectstore.interface';
|
|
2
|
+
export * from './objectstoreKey';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/objectstore/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Readable } from 'stream';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import type { ComplianceContext } from '../../cache/types/ttlCacheRecord.types';
|
|
4
3
|
/**
|
|
5
4
|
* Interface representing an object store.
|
|
6
5
|
*
|
|
@@ -8,7 +7,7 @@ import { C as ComplianceContext } from '../ttlCacheRecord.types-oX0ti5SP.mjs';
|
|
|
8
7
|
* When provided, bodies are encrypted on write and decrypted on read using
|
|
9
8
|
* the tenant ID for key derivation. When omitted, bodies are stored as plaintext.
|
|
10
9
|
*/
|
|
11
|
-
interface ObjectStore<Client> {
|
|
10
|
+
export interface ObjectStore<Client> {
|
|
12
11
|
/**
|
|
13
12
|
* Puts a record into the objectstore.
|
|
14
13
|
*/
|
|
@@ -56,16 +55,4 @@ interface ObjectStore<Client> {
|
|
|
56
55
|
*/
|
|
57
56
|
getClient(): Client;
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Creates a function that generates objectstore keys with a given prefix.
|
|
62
|
-
*
|
|
63
|
-
* @param {string} objectStoreKeyPrefix - The prefix to use for all objectstore keys
|
|
64
|
-
* @returns {Function} A function that takes an ID and returns a formatted objectstore key
|
|
65
|
-
* @example
|
|
66
|
-
* const createUserObjectStoreKey = createObjectStoreKey('user');
|
|
67
|
-
* const key = createUserObjectStoreKey('123'); // Returns 'user:123'
|
|
68
|
-
*/
|
|
69
|
-
declare const createObjectStoreKey: (objectStoreKeyPrefix: string) => (id: string | string[]) => string;
|
|
70
|
-
|
|
71
|
-
export { type ObjectStore, createObjectStoreKey };
|
|
58
|
+
//# sourceMappingURL=objectstore.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectstore.interface.d.ts","sourceRoot":"","sources":["../../../src/objectstore/interfaces/objectstore.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,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,EAAE,CAAC,CAAC;IAEtE;;OAEG;IACH,SAAS,IAAI,MAAM,CAAC;CACrB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that generates objectstore keys with a given prefix.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} objectStoreKeyPrefix - The prefix to use for all objectstore keys
|
|
5
|
+
* @returns {Function} A function that takes an ID and returns a formatted objectstore key
|
|
6
|
+
* @example
|
|
7
|
+
* const createUserObjectStoreKey = createObjectStoreKey('user');
|
|
8
|
+
* const key = createUserObjectStoreKey('123'); // Returns 'user:123'
|
|
9
|
+
*/
|
|
10
|
+
export declare const createObjectStoreKey: (objectStoreKeyPrefix: string) => (id: string | string[]) => string;
|
|
11
|
+
//# sourceMappingURL=objectstoreKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectstoreKey.d.ts","sourceRoot":"","sources":["../../src/objectstore/objectstoreKey.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,yBACR,MAAM,UAAU,MAAM,GAAG,MAAM,EAAE,WAGvD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps an EntityManager to block `nativeInsert`, `nativeUpdate`, and
|
|
3
|
+
* `nativeDelete` on entities that have PII, PHI, or PCI compliance fields.
|
|
4
|
+
*
|
|
5
|
+
* This prevents bypassing the EncryptedType's encryption by using raw
|
|
6
|
+
* queries. Call this in the tenant context middleware when creating the
|
|
7
|
+
* request-scoped EM.
|
|
8
|
+
*
|
|
9
|
+
* @returns A Proxy-wrapped EntityManager that throws on native query
|
|
10
|
+
* operations targeting compliance entities.
|
|
11
|
+
*/
|
|
12
|
+
export declare function wrapEmWithNativeQueryBlocking<T extends object>(em: T): T;
|
|
13
|
+
//# sourceMappingURL=complianceEventSubscriber.d.ts.map
|