@conduitplatform/module-tools 0.16.26 → 0.17.0-alpha.2

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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.cjs +2059 -1775
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +490 -0
  5. package/dist/index.d.ts +490 -7
  6. package/dist/index.esm.js +2033 -1746
  7. package/dist/index.esm.js.map +1 -1
  8. package/dist/module.proto +25 -0
  9. package/package.json +27 -31
  10. package/dist/ManagedModule.d.ts +0 -80
  11. package/dist/classes/ConduitActiveSchema.d.ts +0 -19
  12. package/dist/classes/ConduitServiceModule.d.ts +0 -27
  13. package/dist/classes/ConfigController.d.ts +0 -7
  14. package/dist/classes/GrpcServer.d.ts +0 -23
  15. package/dist/classes/ModuleError.d.ts +0 -5
  16. package/dist/classes/index.d.ts +0 -4
  17. package/dist/helpers/GrpcHelper.d.ts +0 -8
  18. package/dist/helpers/GrpcToParsedRouterRequest.d.ts +0 -2
  19. package/dist/helpers/TypeHelpers.d.ts +0 -70
  20. package/dist/helpers/index.d.ts +0 -4
  21. package/dist/helpers/wrapGrpcFunctions.d.ts +0 -5
  22. package/dist/interfaces/ConduitService.d.ts +0 -8
  23. package/dist/interfaces/ModuleLifecycleStage.d.ts +0 -7
  24. package/dist/interfaces/index.d.ts +0 -2
  25. package/dist/logging/index.d.ts +0 -16
  26. package/dist/metrics/MetricsServer.d.ts +0 -11
  27. package/dist/metrics/clientMiddleware.d.ts +0 -2
  28. package/dist/metrics/config/defaults.d.ts +0 -91
  29. package/dist/metrics/index.d.ts +0 -23
  30. package/dist/routing/ProxyRouteBuilder.d.ts +0 -21
  31. package/dist/routing/RouteBuilder.d.ts +0 -23
  32. package/dist/routing/RoutingController.d.ts +0 -8
  33. package/dist/routing/RoutingManager.d.ts +0 -35
  34. package/dist/routing/RoutingUtilities.d.ts +0 -7
  35. package/dist/routing/index.d.ts +0 -5
  36. package/dist/routing/wrapRouterFunctions.d.ts +0 -13
  37. package/dist/utilities/convictConfigParser.d.ts +0 -2
  38. package/dist/utilities/index.d.ts +0 -3
  39. package/dist/utilities/initializeSdk.d.ts +0 -2
  40. package/dist/utilities/linearBackoffTimeout.d.ts +0 -9
  41. package/dist/utilities/merge.d.ts +0 -1
package/dist/index.d.ts CHANGED
@@ -1,7 +1,490 @@
1
- export * from './ManagedModule.js';
2
- export * from './interfaces/index.js';
3
- export * from './classes/index.js';
4
- export * from './helpers/index.js';
5
- export * from './routing/index.js';
6
- export * from './utilities/index.js';
7
- export * from './classes/ModuleError.js';
1
+ import { ConduitSchema, DatabaseProvider, ConduitModel, ConduitSchemaOptions, Query, FindOneOptions, FindManyOptions, AuthzOptions, PopulateAuthzOptions, CountDocumentsOptions, ConduitGrpcSdk, HealthCheckStatus, GrpcRequest, HealthCheckRequest, GrpcCallback, HealthCheckResponse, SetConfigRequest, GrpcResponse, SetConfigResponse, GetExportableResourcesRequest, GetExportableResourcesResponse, ExportResourcesRequest, ExportResourcesResponse, ImportResourcesRequest, ImportResourcesResponse, PeerWatchEdge, TYPE, ConduitStringValidation, ConduitNumberValidation, Params, Context, Cookies, ParsedRouterRequest, UnparsedRouterResponse, ConduitSocketParamTypes, ConduitRouteReturnDefinition, ParsedSocketRequest, UnparsedSocketResponse, Indexable, Router, Admin, ConduitMiddlewareOptions, ConduitRouteOptions, ConduitSocketOptions, ConduitRouteActions, ConduitQueryParams, ConduitUrlParams, ConduitReturn, ConduitRoute, GrpcError, ModuleErrorDefinition } from '@conduitplatform/grpc-sdk';
2
+ import { EventEmitter } from 'events';
3
+ import { ServerWritableStream, Server } from '@grpc/grpc-js';
4
+ import convict from 'convict';
5
+
6
+ declare class ConduitActiveSchema<T> extends ConduitSchema {
7
+ private readonly dbInstance;
8
+ constructor(dbInstance: DatabaseProvider, name: string, fields?: ConduitModel, modelOptions?: ConduitSchemaOptions, collectionName?: string);
9
+ findOne(query: Query<T>, options?: FindOneOptions): Promise<T | null>;
10
+ findMany(query: Query<T>, options?: FindManyOptions): Promise<T[]>;
11
+ create(query: Query<T>, options?: AuthzOptions): Promise<T>;
12
+ createMany(query: Query<T>[], options?: AuthzOptions): Promise<T[]>;
13
+ findByIdAndUpdate(id: string, document: Query<T>, options?: PopulateAuthzOptions): Promise<T | null>;
14
+ findByIdAndReplace(id: string, document: Query<T>, options?: PopulateAuthzOptions): Promise<T | null>;
15
+ replaceOne(filterQuery: Query<T>, query: Query<T>, options?: PopulateAuthzOptions): Promise<any>;
16
+ updateOne(filterQuery: Query<T>, query: Query<T>, options?: PopulateAuthzOptions): Promise<any>;
17
+ updateMany(filterQuery: Query<T>, query: Query<T>, options?: PopulateAuthzOptions): Promise<any>;
18
+ deleteOne(query: Query<T>, options?: AuthzOptions): Promise<any>;
19
+ deleteMany(query: Query<T>, options?: AuthzOptions): Promise<any>;
20
+ countDocuments(query: Query<T>, options?: CountDocumentsOptions): Promise<number>;
21
+ }
22
+
23
+ declare class GrpcServer {
24
+ private grpcServer?;
25
+ private started;
26
+ private startedOnce;
27
+ private _serviceNames;
28
+ private scheduledRestart;
29
+ private _postponeRequests;
30
+ private _useForce?;
31
+ private _services;
32
+ constructor(port?: string);
33
+ waitForReady(): Promise<void>;
34
+ private _url;
35
+ get url(): string;
36
+ createNewServer(useForce?: boolean): Promise<number>;
37
+ addService(protoPath: string, protoDescription: string, functions: {
38
+ [name: string]: Function;
39
+ }, noAuth?: boolean): Promise<GrpcServer>;
40
+ wait(time: number): Promise<void>;
41
+ refresh(): Promise<void>;
42
+ scheduleRefresh(): void;
43
+ start(): void;
44
+ private postponeRestart;
45
+ }
46
+
47
+ /**
48
+ * Framework-level types for module export/import (GitOps / config-as-code).
49
+ * Modules that implement getExportableResources(), exportResources(), and importResources()
50
+ * can participate in unified state export/import via Core.
51
+ */
52
+ interface ExportableResource {
53
+ /** e.g. "schemas", "emailTemplates", "resourceDefinitions" */
54
+ type: string;
55
+ /** Human-readable description */
56
+ description: string;
57
+ /** Import ordering: lower = imported first (e.g. schemas before endpoints) */
58
+ priority: number;
59
+ }
60
+ /** Per-resource-type arrays of exportable data (e.g. { schemas: [...], customEndpoints: [...] }) */
61
+ interface ExportResult {
62
+ [resourceType: string]: unknown[];
63
+ }
64
+ /** Per-resource-type import outcome */
65
+ interface ImportResultEntry {
66
+ created: number;
67
+ updated: number;
68
+ failed: number;
69
+ errors: string[];
70
+ }
71
+ interface ImportResult {
72
+ [resourceType: string]: ImportResultEntry;
73
+ }
74
+
75
+ declare abstract class ConduitServiceModule {
76
+ protected readonly _moduleName: string;
77
+ protected _serviceName?: string;
78
+ protected _address: string;
79
+ protected grpcServer: GrpcServer;
80
+ protected readonly events: EventEmitter;
81
+ private _serviceHealthState;
82
+ protected constructor(moduleName: string);
83
+ private _registered;
84
+ set registered(registered: boolean);
85
+ protected _port: string;
86
+ get port(): string;
87
+ private _grpcSdk;
88
+ get grpcSdk(): ConduitGrpcSdk;
89
+ set grpcSdk(grpcSdk: ConduitGrpcSdk);
90
+ get healthState(): HealthCheckStatus;
91
+ updateHealth(state: HealthCheckStatus, init?: boolean): void;
92
+ healthCheck(call: GrpcRequest<HealthCheckRequest>, callback: GrpcCallback<HealthCheckResponse>): void;
93
+ healthWatch(call: ServerWritableStream<HealthCheckRequest, HealthCheckResponse>): void;
94
+ abstract setConfig(call: GrpcRequest<SetConfigRequest>, callback: GrpcResponse<SetConfigResponse>): Promise<void>;
95
+ /** Override to declare which resource types this module can export/import. Default: none. */
96
+ protected getExportableResources(): ExportableResource[];
97
+ /** Override to export resources. resourceTypes empty = export all. Default: empty. */
98
+ protected exportResources(_resourceTypes: string[]): Promise<ExportResult>;
99
+ /** Override to import resources. Default: no-op. */
100
+ protected importResources(_resources: ExportResult): Promise<ImportResult>;
101
+ protected getExportableResourcesHandler(_call: GrpcRequest<GetExportableResourcesRequest>, callback: GrpcResponse<GetExportableResourcesResponse>): void;
102
+ protected exportResourcesHandler(call: GrpcRequest<ExportResourcesRequest>, callback: GrpcResponse<ExportResourcesResponse>): Promise<void>;
103
+ protected importResourcesHandler(call: GrpcRequest<ImportResourcesRequest>, callback: GrpcResponse<ImportResourcesResponse>): Promise<void>;
104
+ protected addHealthCheckService(): Promise<void>;
105
+ protected addModuleService(): Promise<void>;
106
+ }
107
+
108
+ declare class ConfigController {
109
+ private static instance;
110
+ private _config;
111
+ get config(): any;
112
+ set config(config: any);
113
+ static getInstance(): ConfigController;
114
+ }
115
+
116
+ interface ConduitService {
117
+ readonly protoPath: string;
118
+ readonly protoDescription: string;
119
+ functions: {
120
+ [p: string]: (call: GrpcRequest<any>, callback: GrpcResponse<any>) => void | Promise<void>;
121
+ };
122
+ }
123
+
124
+ declare enum ModuleLifecycleStage {
125
+ CREATE_GRPC = "creat-grpc-server",
126
+ PRE_SERVER_START = "pre-grpc-start",
127
+ SERVER_STARTED = "grpc-server-started",
128
+ PRE_REGISTER = "pre-register",
129
+ POST_REGISTER = "post-register"
130
+ }
131
+
132
+ interface ConduitPeerWatchEntry {
133
+ module: string;
134
+ edge?: PeerWatchEdge;
135
+ }
136
+ /** Optional `conduit.peers` block in a module `package.json`. */
137
+ interface ConduitPeersManifest {
138
+ peers?: {
139
+ await?: string[];
140
+ watch?: ConduitPeerWatchEntry[];
141
+ };
142
+ }
143
+ interface ConduitPackageJson {
144
+ name?: string;
145
+ conduit?: ConduitPeersManifest;
146
+ }
147
+ declare function readConduitPeersManifest(moduleRootDir?: string): ConduitPeersManifest | null;
148
+
149
+ declare abstract class ManagedModule<T> extends ConduitServiceModule {
150
+ readonly config?: convict.Config<T>;
151
+ configOverride: boolean;
152
+ service?: ConduitService;
153
+ protected abstract readonly configSchema?: object;
154
+ protected abstract readonly metricsSchema?: object;
155
+ private readonly serviceAddress;
156
+ private readonly servicePort;
157
+ private _moduleState;
158
+ private _declaredPeerWatchDisposers;
159
+ private _cachedPeersManifest;
160
+ private _lastPeerBatchStates;
161
+ private readonly _peerManifestRoot?;
162
+ private _configInitialized;
163
+ private _pendingConfigUpdates;
164
+ private _processingConfig;
165
+ protected constructor(moduleName: string, peerManifestRoot?: string);
166
+ get name(): string;
167
+ get address(): string;
168
+ start(): Promise<void>;
169
+ /**
170
+ * This is the first function triggered on module spin up.
171
+ * @param address {string} external address:port of service (LoadBalancer)
172
+ * @param port {string} port to bring up gRPC service
173
+ */
174
+ initialize(address: string, port: string): void;
175
+ /**
176
+ * This is triggered before spinning up the Grpc Server
177
+ * of the module. On this stage, the redis bus and state have
178
+ * not yet been initialized, and only communications with Conduit core
179
+ * have been established.
180
+ */
181
+ preServerStart(): Promise<void>;
182
+ /**
183
+ * This is triggered right after Grpc Server start.
184
+ * At this stage the core module will communicate with your service
185
+ * for health checks, and the Bus and State management mechanics
186
+ * are online and available.
187
+ */
188
+ onServerStart(): Promise<void>;
189
+ /**
190
+ * Triggers right before registering the module with Conduit Core.
191
+ */
192
+ preRegister(): Promise<void>;
193
+ /**
194
+ * Triggers when module has been registered with Conduit Core
195
+ * This is the step where you should initialize your
196
+ * module's general routing (admin or client) and any other operation,
197
+ * that would require other modules being able to reach you
198
+ */
199
+ onRegister(): Promise<void>;
200
+ /**
201
+ * This is triggered when the module receives new configuration.
202
+ * At this step the configuration has not been checked yet,
203
+ * and has only been parsed.
204
+ * @param config
205
+ */
206
+ preConfig(config: T): Promise<T>;
207
+ /**
208
+ * This is triggered when new configuration has been applied.
209
+ * This happens either when changes are being made on the configuration,
210
+ * or on module start up, where the config is recovered from the database.
211
+ * In either case the configuration is now available through the
212
+ * Config Controller of the sdk.
213
+ */
214
+ onConfig(): Promise<void>;
215
+ /**
216
+ * Registers common and module-specific metric types.
217
+ */
218
+ registerMetrics(): Promise<void>;
219
+ /**
220
+ * Initializes metric startup values.
221
+ * Implemented by individual modules.
222
+ */
223
+ initializeMetrics(): Promise<void>;
224
+ protected getPeerManifestRoot(): string;
225
+ protected loadConduitPeersManifest(): ConduitPeersManifest | null;
226
+ private validateDeclaredPeerNames;
227
+ protected awaitPeersFromManifest(): Promise<void>;
228
+ protected registerDeclaredPeerWatches(): void;
229
+ protected disposeDeclaredPeerWatches(): void;
230
+ protected onDeclaredPeerConnectionUpdate(_moduleName: string, _serving: boolean): void;
231
+ createGrpcServer(): Promise<void>;
232
+ startGrpcServer(): Promise<void>;
233
+ setConfig(call: GrpcRequest<SetConfigRequest>, callback: GrpcResponse<SetConfigResponse>): Promise<void>;
234
+ /** Used to update the module's configuration on initial Redis/DB reconciliation. */
235
+ handleConfigSyncUpdate(): Promise<void>;
236
+ /** Serializes config updates; waits for initial lifecycle before draining. */
237
+ private _drainConfigQueue;
238
+ private preRegisterLifecycle;
239
+ private postRegisterLifecycle;
240
+ }
241
+
242
+ declare class ConduitStringConstructor {
243
+ private constructor();
244
+ static get Optional(): TYPE.String;
245
+ static get Required(): {
246
+ type: TYPE.String;
247
+ required: true;
248
+ };
249
+ static RequiredWith(rules: ConduitStringValidation): {
250
+ type: TYPE.String;
251
+ required: true;
252
+ validate: ConduitStringValidation;
253
+ };
254
+ static OptionalWith(rules: ConduitStringValidation): {
255
+ type: TYPE.String;
256
+ required: false;
257
+ validate: ConduitStringValidation;
258
+ };
259
+ }
260
+ declare const ConduitString: typeof ConduitStringConstructor;
261
+ declare class ConduitNumberConstructor {
262
+ private constructor();
263
+ static get Optional(): TYPE.Number;
264
+ static get Required(): {
265
+ type: TYPE.Number;
266
+ required: true;
267
+ };
268
+ static RequiredWith(rules: ConduitNumberValidation): {
269
+ type: TYPE.Number;
270
+ required: true;
271
+ validate: ConduitNumberValidation;
272
+ };
273
+ static OptionalWith(rules: ConduitNumberValidation): {
274
+ type: TYPE.Number;
275
+ required: false;
276
+ validate: ConduitNumberValidation;
277
+ };
278
+ }
279
+ declare const ConduitNumber: typeof ConduitNumberConstructor;
280
+ declare class ConduitBooleanConstructor {
281
+ private constructor();
282
+ static get Optional(): TYPE.Boolean;
283
+ static get Required(): {
284
+ type: TYPE.Boolean;
285
+ required: true;
286
+ };
287
+ }
288
+ declare const ConduitBoolean: typeof ConduitBooleanConstructor;
289
+ declare class ConduitDateConstructor {
290
+ private constructor();
291
+ static get Optional(): TYPE.Date;
292
+ static get Required(): {
293
+ type: TYPE.Date;
294
+ required: true;
295
+ };
296
+ }
297
+ declare const ConduitDate: typeof ConduitDateConstructor;
298
+ declare class ConduitObjectIdConstructor {
299
+ private constructor();
300
+ static get Optional(): TYPE.ObjectId;
301
+ static get Required(): {
302
+ type: TYPE.ObjectId;
303
+ required: true;
304
+ };
305
+ }
306
+ declare const ConduitObjectId: typeof ConduitObjectIdConstructor;
307
+ declare class ConduitJSONConstructor {
308
+ private constructor();
309
+ static get Optional(): TYPE.JSON;
310
+ static get Required(): {
311
+ type: TYPE.JSON;
312
+ required: true;
313
+ };
314
+ }
315
+ declare const ConduitJson: typeof ConduitJSONConstructor;
316
+ declare class ConduitRelationConstructor {
317
+ private constructor();
318
+ static Optional(model: string): {
319
+ type: TYPE.Relation;
320
+ model: string;
321
+ required: false;
322
+ };
323
+ static Required(model: string): {
324
+ type: TYPE.Relation;
325
+ model: string;
326
+ required: true;
327
+ };
328
+ }
329
+ declare const ConduitRelation: typeof ConduitRelationConstructor;
330
+
331
+ declare function createServer(port: string): Promise<{
332
+ server: Server;
333
+ port: number;
334
+ }>;
335
+ declare function addServiceToServer(server: Server, protoPath: string, descriptorObject: string, functions: {
336
+ [name: string]: Function;
337
+ }): void;
338
+
339
+ declare function wrapGrpcFunctions(functions: {
340
+ [name: string]: Function;
341
+ }, postponeRestart: () => void, noAuth?: boolean): {
342
+ [name: string]: Function;
343
+ };
344
+
345
+ declare function createParsedRouterRequest(params: Params, urlParams?: Params, queryParams?: Params, bodyParams?: Params, path?: string, headers?: Headers, context?: Context, cookies?: Cookies): ParsedRouterRequest;
346
+
347
+ type RouterRequestHandler = (call: ParsedRouterRequest) => Promise<UnparsedRouterResponse>;
348
+ type RouterRequestHandlerCallback = (call: ParsedRouterRequest, callback: (response: UnparsedRouterResponse) => void) => Promise<UnparsedRouterResponse | undefined | void>;
349
+ type SocketRequestHandler = (call: ParsedSocketRequest) => Promise<UnparsedSocketResponse>;
350
+ type SocketRequestHandlerCallback = (call: ParsedSocketRequest, callback: (response: UnparsedSocketResponse) => void) => Promise<UnparsedSocketResponse | undefined | void>;
351
+ type RequestHandlers = RouterRequestHandler | RouterRequestHandlerCallback;
352
+ type SocketRequestHandlers = SocketRequestHandler | SocketRequestHandlerCallback;
353
+ interface SocketEventHandler {
354
+ params?: ConduitSocketParamTypes;
355
+ returnType?: ConduitRouteReturnDefinition;
356
+ handler: SocketRequestHandlers;
357
+ }
358
+ declare function wrapRouterGrpcFunction(fun: RequestHandlers | SocketRequestHandlers, routerType: string): (call: Indexable, callback: any) => void;
359
+
360
+ declare class RoutingController {
361
+ private _routeHandlers;
362
+ handleRequest(call: GrpcRequest<any>, callback: GrpcCallback<any>): void;
363
+ setRoutes(routes: {
364
+ [key: string]: (call: any, callback: any) => void;
365
+ }): void;
366
+ }
367
+
368
+ declare class RoutingManager {
369
+ private readonly _router;
370
+ private readonly _server;
371
+ private _moduleRoutes;
372
+ static ClientController: RoutingController;
373
+ static AdminController: RoutingController;
374
+ private _routeHandlers;
375
+ private readonly isAdmin;
376
+ constructor(_router: Router | Admin, _server: GrpcServer);
377
+ get(path: string): RouteBuilder;
378
+ post(path: string): RouteBuilder;
379
+ delete(path: string): RouteBuilder;
380
+ update(path: string): RouteBuilder;
381
+ patch(path: string): RouteBuilder;
382
+ clear(): void;
383
+ middleware(input: ConduitMiddlewareOptions, handler: RequestHandlers): void;
384
+ route(input: ConduitRouteOptions, type: ConduitRouteReturnDefinition, handler: RequestHandlers): void;
385
+ socket(input: ConduitSocketOptions, events: Record<string, SocketEventHandler>): void;
386
+ registerRoutes(): Promise<any>;
387
+ private generateGrpcName;
388
+ private extractNameFromPath;
389
+ private parseRouteObject;
390
+ }
391
+
392
+ declare class RouteBuilder {
393
+ private readonly manager?;
394
+ private readonly _options;
395
+ private _returns;
396
+ private _handler;
397
+ constructor(manager?: RoutingManager | undefined);
398
+ method(action: ConduitRouteActions): RouteBuilder;
399
+ name(name: string): RouteBuilder;
400
+ description(description: string): RouteBuilder;
401
+ cacheControl(cache: string): RouteBuilder;
402
+ middleware(middleware: string | string[], allowDuplicates?: boolean): RouteBuilder;
403
+ path(path: string): RouteBuilder;
404
+ queryParams(params: ConduitQueryParams): RouteBuilder;
405
+ urlParams(params: ConduitUrlParams): RouteBuilder;
406
+ bodyParams(params: ConduitModel): RouteBuilder;
407
+ strictParams(strict: boolean): RouteBuilder;
408
+ rateLimit(maxRequests: number, resetInterval: number): RouteBuilder;
409
+ return(name: string, fields: ConduitReturn): RouteBuilder;
410
+ handler(fn: RequestHandlers): RouteBuilder;
411
+ add(): void;
412
+ build(): ConduitRoute;
413
+ }
414
+
415
+ declare function wrapFunctionsAsync(functions: {
416
+ [name: string]: RequestHandlers | SocketRequestHandlers;
417
+ }, routerType: 'admin' | 'client'): {
418
+ [name: string]: (call: Indexable, callback?: Indexable) => void;
419
+ };
420
+
421
+ declare const initializeSdk: (coreUrl: string, moduleName: string, watchModules?: boolean, serviceHealthStatusGetter?: () => HealthCheckStatus) => ConduitGrpcSdk;
422
+
423
+ declare function linearBackoffTimeout(onTry: (stop: () => void) => void, delay: number, reps?: number, onFailure?: () => void): {
424
+ clear: () => void;
425
+ };
426
+ /**
427
+ * Registers a timeout with linear backoff.
428
+ * onFailure() only runs on rep exhaustion.
429
+ * @param {() => Promise<boolean>} onTry - Async handler, returns 'continue' boolean flag
430
+ */
431
+ declare function linearBackoffTimeoutAsync(onTry: () => Promise<boolean>, delay: number, reps?: number, onFailure?: () => void | Promise<void>, startNow?: boolean): Promise<void>;
432
+
433
+ declare function merge<T extends object>(objA: T, objB: T): T;
434
+
435
+ /**
436
+ * Reusable helpers for module export/import (GitOps).
437
+ * Standardizes stripping internal fields and optional export/import flows.
438
+ */
439
+
440
+ /** Fields removed from documents when exporting (so they are not versioned). */
441
+ declare const DEFAULT_STRIP_FIELDS: readonly ["_id", "createdAt", "updatedAt", "__v"];
442
+ /**
443
+ * Removes internal and optionally extra fields from a single document.
444
+ * Does not mutate the original if the result would differ.
445
+ */
446
+ declare function stripInternalFields(obj: Record<string, unknown>, additionalFields?: string[]): Record<string, unknown>;
447
+ interface SanitizeForExportOptions {
448
+ /** Extra field names to remove (in addition to DEFAULT_STRIP_FIELDS). */
449
+ excludeFields?: string[];
450
+ }
451
+ /**
452
+ * Returns a copy of each document with internal fields stripped.
453
+ * Use after fetching from DB to produce export-safe arrays.
454
+ */
455
+ declare function sanitizeDocumentsForExport<T extends Record<string, unknown>>(documents: T[], options?: SanitizeForExportOptions): Record<string, unknown>[];
456
+ /**
457
+ * Minimal model interface for export: can return all records.
458
+ */
459
+ interface ExportModelAdapter {
460
+ findMany(query?: Record<string, unknown>, options?: {
461
+ select?: string;
462
+ }): Promise<Record<string, unknown>[]>;
463
+ }
464
+ /**
465
+ * Fetches all documents from the adapter and returns them with internal fields stripped.
466
+ */
467
+ declare function exportModel(adapter: ExportModelAdapter, options?: SanitizeForExportOptions & {
468
+ query?: Record<string, unknown>;
469
+ select?: string;
470
+ }): Promise<Record<string, unknown>[]>;
471
+ /**
472
+ * Minimal model interface for import: find by key, create, update.
473
+ */
474
+ interface ImportModelAdapter {
475
+ keyField: string;
476
+ findOne(query: Record<string, unknown>): Promise<Record<string, unknown> | null>;
477
+ create(doc: Record<string, unknown>): Promise<Record<string, unknown>>;
478
+ updateOne(filter: Record<string, unknown>, doc: Record<string, unknown>): Promise<unknown>;
479
+ }
480
+ /**
481
+ * Upserts records by keyField. Returns counts and errors for ImportResultEntry.
482
+ */
483
+ declare function importModel(adapter: ImportModelAdapter, records: Record<string, unknown>[], options?: SanitizeForExportOptions): Promise<ImportResultEntry>;
484
+
485
+ declare class ModuleError extends GrpcError {
486
+ debugLogInfo?: string;
487
+ constructor(errorDefinition: ModuleErrorDefinition, debugLogInfo?: string);
488
+ }
489
+
490
+ export { ConduitActiveSchema, ConduitBoolean, ConduitDate, ConduitJson, ConduitNumber, ConduitObjectId, type ConduitPackageJson, type ConduitPeerWatchEntry, type ConduitPeersManifest, ConduitRelation, type ConduitService, ConduitServiceModule, ConduitString, ConfigController, DEFAULT_STRIP_FIELDS, type ExportModelAdapter, type ExportResult, type ExportableResource, GrpcServer, type ImportModelAdapter, type ImportResult, type ImportResultEntry, ManagedModule, ModuleError, ModuleLifecycleStage, type RequestHandlers, RouteBuilder, type RouterRequestHandler, type RouterRequestHandlerCallback, RoutingManager, type SanitizeForExportOptions, type SocketEventHandler, type SocketRequestHandler, type SocketRequestHandlerCallback, type SocketRequestHandlers, addServiceToServer, createParsedRouterRequest, createServer, exportModel, importModel, initializeSdk, linearBackoffTimeout, linearBackoffTimeoutAsync, merge, readConduitPeersManifest, sanitizeDocumentsForExport, stripInternalFields, wrapFunctionsAsync, wrapGrpcFunctions, wrapRouterGrpcFunction };