@housekit/orm 0.1.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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +224 -0
  3. package/dist/builders/delete.d.ts +21 -0
  4. package/dist/builders/insert.d.ts +128 -0
  5. package/dist/builders/prepared.d.ts +11 -0
  6. package/dist/builders/select.d.ts +352 -0
  7. package/dist/builders/select.types.d.ts +76 -0
  8. package/dist/builders/update.d.ts +23 -0
  9. package/dist/client.d.ts +52 -0
  10. package/dist/codegen/zod.d.ts +4 -0
  11. package/dist/column.d.ts +76 -0
  12. package/dist/compiler.d.ts +27 -0
  13. package/dist/core.d.ts +6 -0
  14. package/dist/data-types.d.ts +150 -0
  15. package/dist/dictionary.d.ts +263 -0
  16. package/dist/engines.d.ts +558 -0
  17. package/dist/expressions.d.ts +72 -0
  18. package/dist/external.d.ts +177 -0
  19. package/dist/index.d.ts +187 -0
  20. package/dist/index.js +222 -0
  21. package/dist/logger.d.ts +8 -0
  22. package/dist/materialized-views.d.ts +271 -0
  23. package/dist/metadata.d.ts +33 -0
  24. package/dist/modules/aggregates.d.ts +205 -0
  25. package/dist/modules/array.d.ts +122 -0
  26. package/dist/modules/conditional.d.ts +110 -0
  27. package/dist/modules/conversion.d.ts +189 -0
  28. package/dist/modules/geo.d.ts +202 -0
  29. package/dist/modules/hash.d.ts +7 -0
  30. package/dist/modules/index.d.ts +12 -0
  31. package/dist/modules/json.d.ts +130 -0
  32. package/dist/modules/math.d.ts +28 -0
  33. package/dist/modules/string.d.ts +167 -0
  34. package/dist/modules/time.d.ts +154 -0
  35. package/dist/modules/types.d.ts +177 -0
  36. package/dist/modules/window.d.ts +27 -0
  37. package/dist/relational.d.ts +33 -0
  38. package/dist/relations.d.ts +15 -0
  39. package/dist/schema-builder.d.ts +172 -0
  40. package/dist/table.d.ts +172 -0
  41. package/dist/utils/background-batcher.d.ts +20 -0
  42. package/dist/utils/batch-transform.d.ts +20 -0
  43. package/dist/utils/binary-reader.d.ts +48 -0
  44. package/dist/utils/binary-serializer.d.ts +160 -0
  45. package/dist/utils/binary-worker-code.d.ts +1 -0
  46. package/dist/utils/binary-worker-pool.d.ts +76 -0
  47. package/dist/utils/binary-worker.d.ts +12 -0
  48. package/dist/utils/insert-processing.d.ts +23 -0
  49. package/dist/utils/lru-cache.d.ts +10 -0
  50. package/package.json +68 -0
@@ -0,0 +1,76 @@
1
+ /**
2
+ * HouseKit Binary Worker Pool - High-Performance Parallel Serialization
3
+ *
4
+ * Manages a pool of worker threads for parallel RowBinary serialization.
5
+ * Automatically distributes work across available CPU cores.
6
+ */
7
+ import { EventEmitter } from 'events';
8
+ interface ColumnConfig {
9
+ name: string;
10
+ type: string;
11
+ isNullable: boolean;
12
+ }
13
+ export interface BinaryWorkerPoolOptions {
14
+ /** Number of worker threads (default: CPU cores - 1) */
15
+ poolSize?: number;
16
+ /** Maximum rows per batch sent to a worker */
17
+ batchSize?: number;
18
+ /** Enable high-water mark backpressure */
19
+ highWaterMark?: number;
20
+ }
21
+ export declare class BinaryWorkerPool extends EventEmitter {
22
+ private workers;
23
+ private columns;
24
+ private batchIdCounter;
25
+ private queue;
26
+ private isShutdown;
27
+ private readonly options;
28
+ constructor(options?: BinaryWorkerPoolOptions);
29
+ /**
30
+ * Initialize the worker pool with column configuration
31
+ */
32
+ initialize(columns: ColumnConfig[]): Promise<void>;
33
+ private spawnWorker;
34
+ private handleWorkerMessage;
35
+ /**
36
+ * Serialize rows to binary format using worker pool
37
+ */
38
+ serialize(rows: Array<Record<string, any>>): Promise<Buffer>;
39
+ /**
40
+ * Serialize rows in batches, returning an async iterator of buffers
41
+ */
42
+ serializeStream(rows: AsyncIterable<Record<string, any>> | Iterable<Record<string, any>>): AsyncGenerator<Buffer>;
43
+ private processQueue;
44
+ /**
45
+ * Get pool statistics
46
+ */
47
+ getStats(): {
48
+ workers: number;
49
+ busy: number;
50
+ queueSize: number;
51
+ };
52
+ /**
53
+ * Shutdown all workers
54
+ */
55
+ shutdown(): Promise<void>;
56
+ }
57
+ /**
58
+ * Get or create the default worker pool
59
+ */
60
+ export declare function getDefaultBinaryPool(columns?: ColumnConfig[]): Promise<BinaryWorkerPool>;
61
+ /**
62
+ * Shutdown the default pool
63
+ */
64
+ export declare function shutdownDefaultBinaryPool(): Promise<void>;
65
+ /**
66
+ * Synchronous fallback serializer for environments without Worker support
67
+ */
68
+ export declare class SyncBinarySerializer {
69
+ private encoders;
70
+ private columns;
71
+ private writer;
72
+ constructor(columns: ColumnConfig[]);
73
+ serialize(rows: Array<Record<string, any>>): Buffer;
74
+ serializeStream(rows: AsyncIterable<Record<string, any>> | Iterable<Record<string, any>>, batchSize?: number): AsyncGenerator<Buffer>;
75
+ }
76
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * HouseKit Binary Worker - Parallel RowBinary Serialization
3
+ *
4
+ * This worker thread handles binary serialization off the main thread,
5
+ * allowing the main thread to focus on I/O while serialization happens in parallel.
6
+ *
7
+ * Benefits:
8
+ * - Main thread stays responsive for network I/O
9
+ * - Serialization uses separate CPU core
10
+ * - Can saturate 10Gbps links without blocking Node.js event loop
11
+ */
12
+ export {};
@@ -0,0 +1,23 @@
1
+ import { ClickHouseColumn, type TableDefinition } from '../core';
2
+ type UUIDVersion = 1 | 3 | 4 | 5 | 6 | 7;
3
+ type PreparedInsertColumn = {
4
+ propKey: string;
5
+ column: ClickHouseColumn;
6
+ columnName: string;
7
+ hasDefault: boolean;
8
+ defaultValue: any;
9
+ defaultFn: ((row: Record<string, any>) => any) | null;
10
+ autoUUIDVersion: UUIDVersion | null;
11
+ useServerUUID: boolean;
12
+ transform: (value: any) => any;
13
+ };
14
+ export type InsertPlan = {
15
+ columns: PreparedInsertColumn[];
16
+ keyToColumn: Map<string, PreparedInsertColumn>;
17
+ columnNames: string[];
18
+ useCompact: boolean;
19
+ };
20
+ export declare function buildInsertPlan(table: TableDefinition<any>): InsertPlan;
21
+ export declare function processRowWithPlan(row: Record<string, any>, plan: InsertPlan, mode?: 'compact' | 'json'): Record<string, any> | any[];
22
+ export declare function processRowsStream(rows: AsyncIterable<Record<string, any>> | Iterable<Record<string, any>>, plan: InsertPlan, mode?: 'compact' | 'json'): AsyncGenerator<any[] | Record<string, any>, void, unknown>;
23
+ export {};
@@ -0,0 +1,10 @@
1
+ export declare class LRUCache<K, V> {
2
+ private map;
3
+ private readonly max;
4
+ constructor(options: {
5
+ max: number;
6
+ });
7
+ get(key: K): V | undefined;
8
+ set(key: K, value: V): void;
9
+ clear(): void;
10
+ }
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@housekit/orm",
3
+ "version": "0.1.1",
4
+ "description": "Type-safe ClickHouse ORM with modern DX and ClickHouse-specific optimizations. Features Turbo Mode (RowBinary), full engine support, and advanced query capabilities.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "license": "MIT",
16
+ "author": "Pablo Fernandez Ruiz",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/pablofdezr/housekit.git",
20
+ "directory": "packages/orm"
21
+ },
22
+ "homepage": "https://github.com/pablofdezr/housekit#readme",
23
+ "bugs": {
24
+ "url": "https://github.com/pablofdezr/housekit/issues"
25
+ },
26
+ "keywords": [
27
+ "clickhouse",
28
+ "orm",
29
+ "typescript",
30
+ "type-safe",
31
+ "query-builder",
32
+ "database",
33
+ "sql",
34
+ "analytics",
35
+ "olap",
36
+ "drizzle",
37
+ "turbo-mode",
38
+ "rowbinary"
39
+ ],
40
+ "files": [
41
+ "dist/**/*",
42
+ "LICENSE",
43
+ "README.md"
44
+ ],
45
+ "scripts": {
46
+ "build": "bun run build-worker.ts && bun build ./src/index.ts --outdir ./dist --target node --external \"*\" && tsc --project tsconfig.build.json",
47
+ "prepublishOnly": "bun run build",
48
+ "clean": "rm -rf dist"
49
+ },
50
+ "dependencies": {
51
+ "uuid": "^13.0.0",
52
+ "zod": "^4.2.1"
53
+ },
54
+ "peerDependencies": {
55
+ "@clickhouse/client": "^1.0.0"
56
+ },
57
+ "devDependencies": {
58
+ "@clickhouse/client": "^1.14.0",
59
+ "@types/uuid": "^11.0.0",
60
+ "typescript": "^5.0.0"
61
+ },
62
+ "publishConfig": {
63
+ "access": "public"
64
+ },
65
+ "engines": {
66
+ "node": ">=18.0.0"
67
+ }
68
+ }