@bayoudhi/moose-lib-serverless 0.1.2 → 0.2.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,11 +1,83 @@
1
- import { tags, IJsonSchemaCollection as IJsonSchemaCollection$1 } from 'typia';
1
+ import { Readable } from 'node:stream';
2
+ import { IsTuple } from 'typia/lib/typings/IsTuple';
3
+ import { IJsonSchemaCollection as IJsonSchemaCollection$1, tags } from 'typia';
4
+ import { IJsonSchemaCollection } from 'typia/src/schemas/json/IJsonSchemaCollection';
5
+ import { Pattern, TagBase } from 'typia/lib/tags';
2
6
  import { ClickHouseClient, ResultSet, CommandResult } from '@clickhouse/client';
3
7
  import { Client } from '@temporalio/client';
4
8
  import { JWTPayload } from 'jose';
5
9
  import http from 'http';
6
- import { IJsonSchemaCollection } from 'typia/src/schemas/json/IJsonSchemaCollection';
7
- import { Pattern, TagBase } from 'typia/lib/tags';
8
- import { Readable } from 'node:stream';
10
+
11
+ /**
12
+ * Quote a ClickHouse identifier with backticks if not already quoted.
13
+ * Backticks allow special characters (e.g., hyphens) in identifiers.
14
+ */
15
+ declare const quoteIdentifier: (name: string) => string;
16
+ type IdentifierBrandedString = string & {
17
+ readonly __identifier_brand?: unique symbol;
18
+ };
19
+ type NonIdentifierBrandedString = string & {
20
+ readonly __identifier_brand?: unique symbol;
21
+ };
22
+ /**
23
+ * Values supported by SQL engine.
24
+ */
25
+ type Value = NonIdentifierBrandedString | number | boolean | Date | [string, string];
26
+ /**
27
+ * Supported value or SQL instance.
28
+ */
29
+ type RawValue = Value | Sql;
30
+ /**
31
+ * Sql template tag interface with attached helper methods.
32
+ */
33
+ interface SqlTemplateTag {
34
+ (strings: readonly string[], ...values: readonly (RawValue | Column | OlapTable<any> | View)[]): Sql;
35
+ /**
36
+ * Join an array of Sql fragments with a separator.
37
+ * @param fragments - Array of Sql fragments to join
38
+ * @param separator - Optional separator string (defaults to ", ")
39
+ */
40
+ join(fragments: Sql[], separator?: string): Sql;
41
+ /**
42
+ * Create raw SQL from a string without parameterization.
43
+ * WARNING: SQL injection risk if used with untrusted input.
44
+ */
45
+ raw(text: string): Sql;
46
+ }
47
+ declare const sql: SqlTemplateTag;
48
+ /**
49
+ * A SQL instance can be nested within each other to build SQL strings.
50
+ */
51
+ declare class Sql {
52
+ readonly values: Value[];
53
+ readonly strings: string[];
54
+ constructor(rawStrings: readonly string[], rawValues: readonly (RawValue | Column | OlapTable<any> | View | Sql)[]);
55
+ /**
56
+ * Append another Sql fragment, returning a new Sql instance.
57
+ */
58
+ append(other: Sql): Sql;
59
+ }
60
+ declare const toStaticQuery: (sql: Sql) => string;
61
+ declare const toQuery: (sql: Sql) => [string, {
62
+ [pN: string]: any;
63
+ }];
64
+ /**
65
+ * Build a display-only SQL string with values inlined for logging/debugging.
66
+ * Does not alter execution behavior; use toQuery for actual execution.
67
+ */
68
+ declare const toQueryPreview: (sql: Sql) => string;
69
+ declare const getValueFromParameter: (value: any) => any;
70
+ declare function createClickhouseParameter(parameterIndex: number, value: Value): string;
71
+ /**
72
+ * Convert the JS type (source is JSON format by API query parameter) to the corresponding ClickHouse type for generating named placeholder of parameterized query.
73
+ * Only support to convert number to Int or Float, boolean to Bool, string to String, other types will convert to String.
74
+ * If exist complex type e.g: object, Array, null, undefined, Date, Record.. etc, just convert to string type by ClickHouse function in SQL.
75
+ * ClickHouse support converting string to other types function.
76
+ * Please see Each section of the https://clickhouse.com/docs/en/sql-reference/functions and https://clickhouse.com/docs/en/sql-reference/functions/type-conversion-functions
77
+ * @param value
78
+ * @returns 'Float', 'Int', 'Bool', 'String'
79
+ */
80
+ declare const mapToClickHouseType: (value: Value) => string;
9
81
 
10
82
  type EnumValues = {
11
83
  name: string;
@@ -229,24 +301,6 @@ type ClickHouseJson<maxDynamicPaths extends number | undefined = undefined, maxD
229
301
  skipRegexes?: skipRegexes;
230
302
  };
231
303
  };
232
- type ClickHousePoint = [number, number] & {
233
- _clickhouse_mapped_type?: "Point";
234
- };
235
- type ClickHouseRing = ClickHousePoint[] & {
236
- _clickhouse_mapped_type?: "Ring";
237
- };
238
- type ClickHouseLineString = ClickHousePoint[] & {
239
- _clickhouse_mapped_type?: "LineString";
240
- };
241
- type ClickHouseMultiLineString = ClickHouseLineString[] & {
242
- _clickhouse_mapped_type?: "MultiLineString";
243
- };
244
- type ClickHousePolygon = ClickHouseRing[] & {
245
- _clickhouse_mapped_type?: "Polygon";
246
- };
247
- type ClickHouseMultiPolygon = ClickHousePolygon[] & {
248
- _clickhouse_mapped_type?: "MultiPolygon";
249
- };
250
304
  /**
251
305
  * typia may have trouble handling this type.
252
306
  * In which case, use {@link WithDefault} as a workaround
@@ -1664,6 +1718,53 @@ declare class IngestApi<T> extends TypedBase<T, IngestConfig<T>> {
1664
1718
  constructor(name: string, config: IngestConfig<T>, schema: IJsonSchemaCollection$1.IV3_1, columns: Column[], validators: undefined, allowExtraFields: boolean);
1665
1719
  }
1666
1720
 
1721
+ /**
1722
+ * Utilities provided by getMooseUtils() for database access and SQL queries.
1723
+ * Works in both Moose runtime and standalone contexts.
1724
+ */
1725
+ interface MooseUtils {
1726
+ client: MooseClient;
1727
+ sql: typeof sql;
1728
+ jwt?: JWTPayload;
1729
+ }
1730
+ /**
1731
+ * @deprecated Use MooseUtils instead. ApiUtil is now a type alias to MooseUtils
1732
+ * and will be removed in a future version.
1733
+ *
1734
+ * Migration: Replace `ApiUtil` with `MooseUtils` in your type annotations.
1735
+ */
1736
+ type ApiUtil = MooseUtils;
1737
+ /** @deprecated Use MooseUtils instead. */
1738
+ type ConsumptionUtil = MooseUtils;
1739
+ declare class MooseClient {
1740
+ query: QueryClient;
1741
+ workflow: WorkflowClient;
1742
+ constructor(queryClient: QueryClient, temporalClient?: Client);
1743
+ }
1744
+ declare class QueryClient {
1745
+ client: ClickHouseClient;
1746
+ query_id_prefix: string;
1747
+ constructor(client: ClickHouseClient, query_id_prefix: string);
1748
+ execute<T = any>(sql: Sql): Promise<ResultSet<"JSONEachRow"> & {
1749
+ __query_result_t?: T[];
1750
+ }>;
1751
+ command(sql: Sql): Promise<CommandResult>;
1752
+ }
1753
+ declare class WorkflowClient {
1754
+ client: Client | undefined;
1755
+ constructor(temporalClient?: Client);
1756
+ execute(name: string, input_data: any): Promise<{
1757
+ status: number;
1758
+ body: string;
1759
+ }>;
1760
+ terminate(workflowId: string): Promise<{
1761
+ status: number;
1762
+ body: string;
1763
+ }>;
1764
+ private getWorkflowConfig;
1765
+ private processInputData;
1766
+ }
1767
+
1667
1768
  /**
1668
1769
  * Defines the signature for a handler function used by a Consumption API.
1669
1770
  * @template T The expected type of the request parameters or query parameters.
@@ -2237,144 +2338,364 @@ type SimpleAggregated<AggregationFunction extends string, ArgType = any> = {
2237
2338
  _argType?: ArgType;
2238
2339
  };
2239
2340
 
2240
- /**
2241
- * Quote a ClickHouse identifier with backticks if not already quoted.
2242
- * Backticks allow special characters (e.g., hyphens) in identifiers.
2243
- */
2244
- declare const quoteIdentifier: (name: string) => string;
2245
- type IdentifierBrandedString = string & {
2246
- readonly __identifier_brand?: unique symbol;
2341
+ type Key<T extends string | number | Date> = T;
2342
+ type JWT<T extends object> = T;
2343
+
2344
+ declare const compilerLog: (message: string) => void;
2345
+ declare const antiCachePath: (path: string) => string;
2346
+ declare const getFileName: (filePath: string) => string;
2347
+ type CliLogData = {
2348
+ message_type?: "Info" | "Success" | "Warning" | "Error" | "Highlight";
2349
+ action: string;
2350
+ message: string;
2247
2351
  };
2248
- type NonIdentifierBrandedString = string & {
2249
- readonly __identifier_brand?: unique symbol;
2352
+ declare const cliLog: (log: CliLogData) => void;
2353
+ /**
2354
+ * Method to change .ts, .cts, and .mts to .js, .cjs, and .mjs
2355
+ * This is needed because 'import' does not support .ts, .cts, and .mts
2356
+ */
2357
+ declare function mapTstoJs(filePath: string): string;
2358
+ declare const MAX_RETRIES = 150;
2359
+ declare const MAX_RETRY_TIME_MS = 1000;
2360
+ declare const RETRY_INITIAL_TIME_MS = 100;
2361
+ declare const MAX_RETRIES_PRODUCER = 150;
2362
+ declare const RETRY_FACTOR_PRODUCER = 0.2;
2363
+ declare const ACKs = -1;
2364
+ type KafkaClientConfig = {
2365
+ clientId: string;
2366
+ broker: string;
2367
+ securityProtocol?: string;
2368
+ saslUsername?: string;
2369
+ saslPassword?: string;
2370
+ saslMechanism?: string;
2250
2371
  };
2251
2372
  /**
2252
- * Values supported by SQL engine.
2373
+ * Interface for logging functionality
2253
2374
  */
2254
- type Value = NonIdentifierBrandedString | number | boolean | Date | [string, string];
2375
+ interface Logger {
2376
+ logPrefix: string;
2377
+ log: (message: string) => void;
2378
+ error: (message: string) => void;
2379
+ warn: (message: string) => void;
2380
+ }
2381
+ declare const logError: (logger: Logger, e: Error) => void;
2382
+
2255
2383
  /**
2256
- * Supported value or SQL instance.
2384
+ * @module secrets
2385
+ * Utilities for runtime environment variable resolution.
2386
+ *
2387
+ * This module provides functionality to mark values that should be resolved
2388
+ * from environment variables at runtime by the Moose CLI, rather than being
2389
+ * embedded at build time.
2390
+ *
2391
+ * @example
2392
+ * ```typescript
2393
+ * import { S3QueueEngine, mooseRuntimeEnv } from 'moose-lib';
2394
+ *
2395
+ * const table = OlapTable<MyData>(
2396
+ * "MyTable",
2397
+ * OlapConfig({
2398
+ * engine: S3QueueEngine({
2399
+ * s3_path: "s3://bucket/data/*.json",
2400
+ * format: "JSONEachRow",
2401
+ * awsAccessKeyId: mooseRuntimeEnv.get("AWS_ACCESS_KEY_ID"),
2402
+ * awsSecretAccessKey: mooseRuntimeEnv.get("AWS_SECRET_ACCESS_KEY")
2403
+ * })
2404
+ * })
2405
+ * );
2406
+ * ```
2257
2407
  */
2258
- type RawValue = Value | Sql;
2259
2408
  /**
2260
- * Sql template tag interface with attached helper methods.
2409
+ * Prefix used to mark values for runtime environment variable resolution.
2410
+ * @internal
2261
2411
  */
2262
- interface SqlTemplateTag {
2263
- (strings: readonly string[], ...values: readonly (RawValue | Column | OlapTable<any> | View)[]): Sql;
2412
+ declare const MOOSE_RUNTIME_ENV_PREFIX = "__MOOSE_RUNTIME_ENV__:";
2413
+ /**
2414
+ * Utilities for marking values to be resolved from environment variables at runtime.
2415
+ *
2416
+ * When you use `mooseRuntimeEnv.get()`, the behavior depends on the context:
2417
+ * - During infrastructure map loading: Returns a marker string for later resolution
2418
+ * - During function/workflow execution: Returns the actual environment variable value
2419
+ *
2420
+ * This is useful for:
2421
+ * - Credentials that should never be embedded in Docker images
2422
+ * - Configuration that can be rotated without rebuilding
2423
+ * - Different values for different environments (dev, staging, prod)
2424
+ * - Any runtime configuration in infrastructure elements (Tables, Topics, etc.)
2425
+ */
2426
+ declare const mooseRuntimeEnv: {
2264
2427
  /**
2265
- * Join an array of Sql fragments with a separator.
2266
- * @param fragments - Array of Sql fragments to join
2267
- * @param separator - Optional separator string (defaults to ", ")
2428
+ * Gets a value from an environment variable, with behavior depending on context.
2429
+ *
2430
+ * When IS_LOADING_INFRA_MAP=true (infrastructure loading):
2431
+ * Returns a marker string that Moose CLI will resolve later
2432
+ *
2433
+ * When IS_LOADING_INFRA_MAP is unset (function/workflow runtime):
2434
+ * Returns the actual value from the environment variable
2435
+ *
2436
+ * @param envVarName - Name of the environment variable to resolve
2437
+ * @returns Either a marker string or the actual environment variable value
2438
+ * @throws {Error} If the environment variable name is empty
2439
+ * @throws {Error} If the environment variable is not set (runtime mode only)
2440
+ *
2441
+ * @example
2442
+ * ```typescript
2443
+ * // Instead of this (evaluated at build time):
2444
+ * awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID
2445
+ *
2446
+ * // Use this (evaluated at runtime):
2447
+ * awsAccessKeyId: mooseRuntimeEnv.get("AWS_ACCESS_KEY_ID")
2448
+ * ```
2268
2449
  */
2269
- join(fragments: Sql[], separator?: string): Sql;
2450
+ get(envVarName: string): string;
2451
+ };
2452
+ /** @deprecated Use mooseRuntimeEnv instead */
2453
+ declare const mooseEnvSecrets: {
2270
2454
  /**
2271
- * Create raw SQL from a string without parameterization.
2272
- * WARNING: SQL injection risk if used with untrusted input.
2455
+ * Gets a value from an environment variable, with behavior depending on context.
2456
+ *
2457
+ * When IS_LOADING_INFRA_MAP=true (infrastructure loading):
2458
+ * Returns a marker string that Moose CLI will resolve later
2459
+ *
2460
+ * When IS_LOADING_INFRA_MAP is unset (function/workflow runtime):
2461
+ * Returns the actual value from the environment variable
2462
+ *
2463
+ * @param envVarName - Name of the environment variable to resolve
2464
+ * @returns Either a marker string or the actual environment variable value
2465
+ * @throws {Error} If the environment variable name is empty
2466
+ * @throws {Error} If the environment variable is not set (runtime mode only)
2467
+ *
2468
+ * @example
2469
+ * ```typescript
2470
+ * // Instead of this (evaluated at build time):
2471
+ * awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID
2472
+ *
2473
+ * // Use this (evaluated at runtime):
2474
+ * awsAccessKeyId: mooseRuntimeEnv.get("AWS_ACCESS_KEY_ID")
2475
+ * ```
2273
2476
  */
2274
- raw(text: string): Sql;
2477
+ get(envVarName: string): string;
2478
+ };
2479
+
2480
+ /**
2481
+ * Configuration for CSV parsing options
2482
+ */
2483
+ interface CSVParsingConfig {
2484
+ /** CSV delimiter character */
2485
+ delimiter: string;
2486
+ /** Whether to treat first row as headers */
2487
+ columns?: boolean;
2488
+ /** Whether to skip empty lines */
2489
+ skipEmptyLines?: boolean;
2490
+ /** Whether to trim whitespace from values */
2491
+ trim?: boolean;
2275
2492
  }
2276
- declare const sql: SqlTemplateTag;
2277
2493
  /**
2278
- * A SQL instance can be nested within each other to build SQL strings.
2494
+ * Configuration for JSON parsing options
2279
2495
  */
2280
- declare class Sql {
2281
- readonly values: Value[];
2282
- readonly strings: string[];
2283
- constructor(rawStrings: readonly string[], rawValues: readonly (RawValue | Column | OlapTable<any> | View | Sql)[]);
2284
- /**
2285
- * Append another Sql fragment, returning a new Sql instance.
2286
- */
2287
- append(other: Sql): Sql;
2496
+ interface JSONParsingConfig {
2497
+ /** Custom reviver function for JSON.parse */
2498
+ reviver?: (key: string, value: any) => any;
2288
2499
  }
2289
- declare const toStaticQuery: (sql: Sql) => string;
2290
- declare const toQuery: (sql: Sql) => [string, {
2291
- [pN: string]: any;
2292
- }];
2293
2500
  /**
2294
- * Build a display-only SQL string with values inlined for logging/debugging.
2295
- * Does not alter execution behavior; use toQuery for actual execution.
2501
+ * Parses CSV content into an array of objects
2502
+ *
2503
+ * @param content - The CSV content as a string
2504
+ * @param config - CSV parsing configuration
2505
+ * @returns Promise resolving to an array of parsed objects
2296
2506
  */
2297
- declare const toQueryPreview: (sql: Sql) => string;
2298
- declare const getValueFromParameter: (value: any) => any;
2299
- declare function createClickhouseParameter(parameterIndex: number, value: Value): string;
2507
+ declare function parseCSV<T = Record<string, any>>(content: string, config: CSVParsingConfig): Promise<T[]>;
2300
2508
  /**
2301
- * Convert the JS type (source is JSON format by API query parameter) to the corresponding ClickHouse type for generating named placeholder of parameterized query.
2302
- * Only support to convert number to Int or Float, boolean to Bool, string to String, other types will convert to String.
2303
- * If exist complex type e.g: object, Array, null, undefined, Date, Record.. etc, just convert to string type by ClickHouse function in SQL.
2304
- * ClickHouse support converting string to other types function.
2305
- * Please see Each section of the https://clickhouse.com/docs/en/sql-reference/functions and https://clickhouse.com/docs/en/sql-reference/functions/type-conversion-functions
2306
- * @param value
2307
- * @returns 'Float', 'Int', 'Bool', 'String'
2509
+ * Parses JSON content into an array of objects
2510
+ *
2511
+ * @param content - The JSON content as a string
2512
+ * @param config - JSON parsing configuration
2513
+ * @returns Array of parsed objects
2308
2514
  */
2309
- declare const mapToClickHouseType: (value: Value) => string;
2515
+ declare function parseJSON<T = any>(content: string, config?: JSONParsingConfig): T[];
2516
+ /**
2517
+ * Parses JSON content with automatic date revival
2518
+ *
2519
+ * @param content - The JSON content as a string
2520
+ * @returns Array of parsed objects with Date objects for ISO 8601 strings
2521
+ */
2522
+ declare function parseJSONWithDates<T = any>(content: string): T[];
2523
+ /**
2524
+ * Type guard to check if a value is a valid CSV delimiter
2525
+ */
2526
+ declare function isValidCSVDelimiter(delimiter: string): boolean;
2527
+ /**
2528
+ * Common CSV delimiters
2529
+ */
2530
+ declare const CSV_DELIMITERS: {
2531
+ readonly COMMA: ",";
2532
+ readonly TAB: "\t";
2533
+ readonly SEMICOLON: ";";
2534
+ readonly PIPE: "|";
2535
+ };
2536
+ /**
2537
+ * Default CSV parsing configuration
2538
+ */
2539
+ declare const DEFAULT_CSV_CONFIG: CSVParsingConfig;
2540
+ /**
2541
+ * Default JSON parsing configuration with date revival
2542
+ */
2543
+ declare const DEFAULT_JSON_CONFIG: JSONParsingConfig;
2310
2544
 
2545
+ type HasFunctionField<T> = T extends object ? {
2546
+ [K in keyof T]: T[K] extends Function ? true : false;
2547
+ }[keyof T] extends false | undefined ? false : true : false;
2548
+ type OptionalToUndefinedable<T> = {
2549
+ [K in {} & keyof T]: T[K];
2550
+ };
2551
+ type StripInterfaceFields<T> = {
2552
+ [K in keyof T]: StripDateIntersection<T[K]>;
2553
+ };
2311
2554
  /**
2312
- * Utilities provided by getMooseUtils() for database access and SQL queries.
2313
- * Works in both Moose runtime and standalone contexts.
2555
+ * `Date & ...` is considered "nonsensible intersection" by typia,
2556
+ * causing JSON schema to fail.
2557
+ * This helper type recursively cleans up the intersection type tagging.
2558
+ */
2559
+ type StripDateIntersection<T> = T extends Date ? Date extends T ? Date : T : T extends ReadonlyArray<unknown> ? IsTuple<T> extends true ? StripDateFromTuple<T> : T extends ReadonlyArray<infer U> ? ReadonlyArray<U> extends T ? ReadonlyArray<StripDateIntersection<U>> : Array<StripDateIntersection<U>> : T extends Array<infer U> ? Array<StripDateIntersection<U>> : T : true extends HasFunctionField<T> ? T : T extends object ? StripInterfaceFields<OptionalToUndefinedable<T>> : T;
2560
+ type StripDateFromTuple<T extends readonly any[]> = T extends ([
2561
+ infer T1,
2562
+ infer T2,
2563
+ infer T3,
2564
+ infer T4,
2565
+ infer T5,
2566
+ infer T6,
2567
+ infer T7,
2568
+ infer T8,
2569
+ infer T9,
2570
+ infer T10
2571
+ ]) ? [
2572
+ StripDateIntersection<T1>,
2573
+ StripDateIntersection<T2>,
2574
+ StripDateIntersection<T3>,
2575
+ StripDateIntersection<T4>,
2576
+ StripDateIntersection<T5>,
2577
+ StripDateIntersection<T6>,
2578
+ StripDateIntersection<T7>,
2579
+ StripDateIntersection<T8>,
2580
+ StripDateIntersection<T9>,
2581
+ StripDateIntersection<T10>
2582
+ ] : T extends ([
2583
+ infer T1,
2584
+ infer T2,
2585
+ infer T3,
2586
+ infer T4,
2587
+ infer T5,
2588
+ infer T6,
2589
+ infer T7,
2590
+ infer T8,
2591
+ infer T9
2592
+ ]) ? [
2593
+ StripDateIntersection<T1>,
2594
+ StripDateIntersection<T2>,
2595
+ StripDateIntersection<T3>,
2596
+ StripDateIntersection<T4>,
2597
+ StripDateIntersection<T5>,
2598
+ StripDateIntersection<T6>,
2599
+ StripDateIntersection<T7>,
2600
+ StripDateIntersection<T8>,
2601
+ StripDateIntersection<T9>
2602
+ ] : T extends ([
2603
+ infer T1,
2604
+ infer T2,
2605
+ infer T3,
2606
+ infer T4,
2607
+ infer T5,
2608
+ infer T6,
2609
+ infer T7,
2610
+ infer T8
2611
+ ]) ? [
2612
+ StripDateIntersection<T1>,
2613
+ StripDateIntersection<T2>,
2614
+ StripDateIntersection<T3>,
2615
+ StripDateIntersection<T4>,
2616
+ StripDateIntersection<T5>,
2617
+ StripDateIntersection<T6>,
2618
+ StripDateIntersection<T7>,
2619
+ StripDateIntersection<T8>
2620
+ ] : T extends ([
2621
+ infer T1,
2622
+ infer T2,
2623
+ infer T3,
2624
+ infer T4,
2625
+ infer T5,
2626
+ infer T6,
2627
+ infer T7
2628
+ ]) ? [
2629
+ StripDateIntersection<T1>,
2630
+ StripDateIntersection<T2>,
2631
+ StripDateIntersection<T3>,
2632
+ StripDateIntersection<T4>,
2633
+ StripDateIntersection<T5>,
2634
+ StripDateIntersection<T6>,
2635
+ StripDateIntersection<T7>
2636
+ ] : T extends [infer T1, infer T2, infer T3, infer T4, infer T5, infer T6] ? [
2637
+ StripDateIntersection<T1>,
2638
+ StripDateIntersection<T2>,
2639
+ StripDateIntersection<T3>,
2640
+ StripDateIntersection<T4>,
2641
+ StripDateIntersection<T5>,
2642
+ StripDateIntersection<T6>
2643
+ ] : T extends [infer T1, infer T2, infer T3, infer T4, infer T5] ? [
2644
+ StripDateIntersection<T1>,
2645
+ StripDateIntersection<T2>,
2646
+ StripDateIntersection<T3>,
2647
+ StripDateIntersection<T4>,
2648
+ StripDateIntersection<T5>
2649
+ ] : T extends [infer T1, infer T2, infer T3, infer T4] ? [
2650
+ StripDateIntersection<T1>,
2651
+ StripDateIntersection<T2>,
2652
+ StripDateIntersection<T3>,
2653
+ StripDateIntersection<T4>
2654
+ ] : T extends [infer T1, infer T2, infer T3] ? [
2655
+ StripDateIntersection<T1>,
2656
+ StripDateIntersection<T2>,
2657
+ StripDateIntersection<T3>
2658
+ ] : T extends [infer T1, infer T2] ? [
2659
+ StripDateIntersection<T1>,
2660
+ StripDateIntersection<T2>
2661
+ ] : T extends [infer T1] ? [StripDateIntersection<T1>] : [];
2662
+
2663
+ /**
2664
+ * Configuration for a data source
2314
2665
  */
2315
- interface MooseUtils {
2316
- client: MooseClient;
2317
- sql: typeof sql;
2318
- jwt?: JWTPayload;
2666
+ interface DataSourceConfig {
2667
+ name: string;
2668
+ supportsIncremental?: boolean;
2319
2669
  }
2320
2670
  /**
2321
- * @deprecated Use MooseUtils instead. ApiUtil is now a type alias to MooseUtils
2322
- * and will be removed in a future version.
2323
- *
2324
- * Migration: Replace `ApiUtil` with `MooseUtils` in your type annotations.
2671
+ * DataSource is an abstract class that defines the interface for all data sources.
2672
+ * It is used to extract data from a source and test the connection to the source.
2325
2673
  */
2326
- type ApiUtil = MooseUtils;
2327
- /** @deprecated Use MooseUtils instead. */
2328
- type ConsumptionUtil = MooseUtils;
2329
- declare class MooseClient {
2330
- query: QueryClient;
2331
- workflow: WorkflowClient;
2332
- constructor(queryClient: QueryClient, temporalClient?: Client);
2333
- }
2334
- declare class QueryClient {
2335
- client: ClickHouseClient;
2336
- query_id_prefix: string;
2337
- constructor(client: ClickHouseClient, query_id_prefix: string);
2338
- execute<T = any>(sql: Sql): Promise<ResultSet<"JSONEachRow"> & {
2339
- __query_result_t?: T[];
2340
- }>;
2341
- command(sql: Sql): Promise<CommandResult>;
2342
- }
2343
- declare class WorkflowClient {
2344
- client: Client | undefined;
2345
- constructor(temporalClient?: Client);
2346
- execute(name: string, input_data: any): Promise<{
2347
- status: number;
2348
- body: string;
2349
- }>;
2350
- terminate(workflowId: string): Promise<{
2351
- status: number;
2352
- body: string;
2674
+ declare abstract class DataSource<T = any, ItemType = any> {
2675
+ protected name: string;
2676
+ protected supportsIncremental: boolean;
2677
+ constructor(config: DataSourceConfig);
2678
+ /**
2679
+ * Extract data from the source
2680
+ * Returns either ItemType (for single requests) or Readable (for paginated requests)
2681
+ */
2682
+ abstract extract(): Promise<ItemType | Readable>;
2683
+ /**
2684
+ * Test connection to the source
2685
+ */
2686
+ abstract testConnection(): Promise<{
2687
+ success: boolean;
2688
+ message?: string;
2353
2689
  }>;
2354
- private getWorkflowConfig;
2355
- private processInputData;
2356
2690
  }
2357
2691
  /**
2358
- * This looks similar to the client in runner.ts which is a worker.
2359
- * Temporal SDK uses similar looking connection options & client,
2360
- * but there are different libraries for a worker & client like this one
2361
- * that triggers workflows.
2692
+ * Result returned from extraction
2693
+ * For single requests: data is of type T
2694
+ * For paginated requests: data is a Readable stream yielding items of type T
2362
2695
  */
2363
- declare function getTemporalClient(temporalUrl: string, namespace: string, clientCert: string, clientKey: string, apiKey: string): Promise<Client | undefined>;
2364
- declare const ApiHelpers: {
2365
- column: (value: string) => [string, string];
2366
- table: (value: string) => [string, string];
2367
- };
2368
- /** @deprecated Use ApiHelpers instead. */
2369
- declare const ConsumptionHelpers: {
2370
- column: (value: string) => [string, string];
2371
- table: (value: string) => [string, string];
2372
- };
2373
- declare function joinQueries({ values, separator, prefix, suffix, }: {
2374
- values: readonly RawValue[];
2375
- separator?: string;
2376
- prefix?: string;
2377
- suffix?: string;
2378
- }): Sql;
2696
+ interface ExtractionResult<T = any> {
2697
+ data: T | Readable;
2698
+ metadata: Record<string, any>;
2699
+ }
2379
2700
 
2380
- export { getStreams as $, type ApiUtil as A, type ApiConfig as B, type ConsumptionUtil as C, type DateTime as D, ClickHouseEngines as E, type FixedString as F, ConsumptionApi as G, type DeadLetter as H, type Int8 as I, type DeadLetterModel as J, DeadLetterQueue as K, type LowCardinality as L, type EgressConfig as M, ETLPipeline as N, type ETLPipelineConfig as O, type FrameworkApp as P, getApi as Q, getApis as R, getIngestApi as S, getIngestApis as T, type UInt8 as U, getMaterializedView as V, type WithDefault as W, getMaterializedViews as X, getSqlResource as Y, getSqlResources as Z, getStream as _, type ClickHouseByteSize as a, getTable as a0, getTables as a1, getView as a2, getViews as a3, getWebApp as a4, getWebApps as a5, getWorkflow as a6, getWorkflows as a7, IngestApi as a8, type IngestConfig as a9, toQueryPreview as aA, getValueFromParameter as aB, createClickhouseParameter as aC, mapToClickHouseType as aD, type MooseUtils as aE, MooseClient as aF, type ClickHousePoint as aG, type ClickHouseRing as aH, type ClickHouseLineString as aI, type ClickHouseMultiLineString as aJ, type ClickHousePolygon as aK, type ClickHouseMultiPolygon as aL, QueryClient as aM, WorkflowClient as aN, getTemporalClient as aO, ApiHelpers as aP, ConsumptionHelpers as aQ, joinQueries as aR, type ConsumerConfig as aS, type TransformConfig as aT, type TaskContext as aU, type TaskConfig as aV, type IngestPipelineConfig as aW, type MaterializedViewConfig as aX, IngestPipeline as aa, LifeCycle as ab, MaterializedView as ac, type OlapConfig as ad, OlapTable as ae, type S3QueueTableSettings as af, type SimpleAggregated as ag, SqlResource as ah, Stream as ai, type StreamConfig as aj, Task as ak, View as al, WebApp as am, type WebAppConfig as an, type WebAppHandler as ao, Workflow as ap, quoteIdentifier as aq, type IdentifierBrandedString as ar, type NonIdentifierBrandedString as as, type Value as at, type RawValue as au, type SqlTemplateTag as av, sql as aw, Sql as ax, toStaticQuery as ay, toQuery as az, type ClickHouseCodec as b, type ClickHouseDecimal as c, type ClickHouseDefault as d, type ClickHouseFixedStringSize as e, type ClickHouseFloat as f, type ClickHouseInt as g, type ClickHouseJson as h, type ClickHouseMaterialized as i, type ClickHouseNamedTuple as j, type ClickHousePrecision as k, type ClickHouseTTL as l, type DateTime64 as m, type DateTime64String as n, type DateTimeString as o, type Decimal as p, type Float32 as q, type Float64 as r, type Int16 as s, type Int32 as t, type Int64 as u, type UInt16 as v, type UInt32 as w, type UInt64 as x, type Aggregated as y, Api as z };
2701
+ export { ACKs, type Aggregated, Api, type ApiConfig, type ApiUtil, type CSVParsingConfig, CSV_DELIMITERS, type CliLogData, type ClickHouseByteSize, type ClickHouseCodec, type ClickHouseDecimal, type ClickHouseDefault, ClickHouseEngines, type ClickHouseFixedStringSize, type ClickHouseFloat, type ClickHouseInt, type ClickHouseJson, type ClickHouseMaterialized, type ClickHouseNamedTuple, type ClickHousePrecision, type ClickHouseTTL, ConsumptionApi, type ConsumptionUtil, DEFAULT_CSV_CONFIG, DEFAULT_JSON_CONFIG, DataSource, type DataSourceConfig, type DateTime, type DateTime64, type DateTime64String, type DateTimeString, type DeadLetter, type DeadLetterModel, DeadLetterQueue, type Decimal, ETLPipeline, type ETLPipelineConfig, type EgressConfig, type ExtractionResult, type FixedString, type Float32, type Float64, type FrameworkApp, type IdentifierBrandedString, IngestApi, type IngestConfig, IngestPipeline, type Int16, type Int32, type Int64, type Int8, type JSONParsingConfig, type JWT, type KafkaClientConfig, type Key, LifeCycle, type Logger, type LowCardinality, MAX_RETRIES, MAX_RETRIES_PRODUCER, MAX_RETRY_TIME_MS, MOOSE_RUNTIME_ENV_PREFIX, MaterializedView, type NonIdentifierBrandedString, type OlapConfig, OlapTable, RETRY_FACTOR_PRODUCER, RETRY_INITIAL_TIME_MS, type RawValue, type S3QueueTableSettings, type SimpleAggregated, Sql, SqlResource, type SqlTemplateTag, Stream, type StreamConfig, type StripDateIntersection, Task, type UInt16, type UInt32, type UInt64, type UInt8, type Value, View, WebApp, type WebAppConfig, type WebAppHandler, type WithDefault, Workflow, antiCachePath, cliLog, compilerLog, createClickhouseParameter, getApi, getApis, getFileName, getIngestApi, getIngestApis, getMaterializedView, getMaterializedViews, getSqlResource, getSqlResources, getStream, getStreams, getTable, getTables, getValueFromParameter, getView, getViews, getWebApp, getWebApps, getWorkflow, getWorkflows, isValidCSVDelimiter, logError, mapToClickHouseType, mapTstoJs, mooseEnvSecrets, mooseRuntimeEnv, parseCSV, parseJSON, parseJSONWithDates, quoteIdentifier, sql, toQuery, toQueryPreview, toStaticQuery };