@housekit/orm 0.1.24 → 0.1.26
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/README.md +249 -134
- package/dist/builders/insert.d.ts +25 -22
- package/dist/builders/select.d.ts +5 -5
- package/dist/client.d.ts +15 -0
- package/dist/column.d.ts +2 -2
- package/dist/index.d.ts +45 -6
- package/dist/index.js +445 -150
- package/dist/relational.d.ts +92 -20
- package/dist/schema-builder.d.ts +20 -4
- package/dist/table.d.ts +20 -4
- package/dist/utils/batch-transform.d.ts +0 -2
- package/dist/utils/binary-serializer.d.ts +57 -0
- package/dist/utils/binary-worker-code.d.ts +1 -1
- package/dist/utils/binary-worker-pool.d.ts +2 -2
- package/dist/utils/insert-processing.d.ts +7 -1
- package/package.json +1 -1
package/dist/relational.d.ts
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as ops from './expressions';
|
|
2
|
+
import * as cond from './modules/conditional';
|
|
3
|
+
import { ClickHouseColumn, type RelationDefinition, type TableDefinition, type CleanSelect } from './core';
|
|
2
4
|
import type { SQLExpression } from './expressions';
|
|
5
|
+
/**
|
|
6
|
+
* Internal map of SQL operators provided to relational query callbacks.
|
|
7
|
+
* These match the standard HouseKit operators but are bundled for ergonomic access.
|
|
8
|
+
*/
|
|
9
|
+
declare const operators: {
|
|
10
|
+
eq: typeof ops.eq;
|
|
11
|
+
ne: typeof ops.ne;
|
|
12
|
+
gt: typeof ops.gt;
|
|
13
|
+
gte: typeof ops.gte;
|
|
14
|
+
lt: typeof ops.lt;
|
|
15
|
+
lte: typeof ops.lte;
|
|
16
|
+
inArray: typeof ops.inArray;
|
|
17
|
+
notInArray: typeof ops.notInArray;
|
|
18
|
+
between: typeof ops.between;
|
|
19
|
+
notBetween: typeof ops.notBetween;
|
|
20
|
+
has: typeof ops.has;
|
|
21
|
+
hasAll: typeof ops.hasAll;
|
|
22
|
+
hasAny: typeof ops.hasAny;
|
|
23
|
+
sql: typeof ops.sql;
|
|
24
|
+
and: typeof cond.and;
|
|
25
|
+
or: typeof cond.or;
|
|
26
|
+
not: typeof cond.not;
|
|
27
|
+
isNull: typeof cond.isNull;
|
|
28
|
+
isNotNull: typeof cond.isNotNull;
|
|
29
|
+
asc: typeof ops.asc;
|
|
30
|
+
desc: typeof ops.desc;
|
|
31
|
+
};
|
|
3
32
|
type Simplify<T> = {
|
|
4
33
|
[K in keyof T]: T[K];
|
|
5
34
|
} & {};
|
|
@@ -35,46 +64,89 @@ type RelationValueForKey<TTable, K, TWithValue> = K extends keyof NormalizedRela
|
|
|
35
64
|
export type RelationalResult<TTable, TWith = undefined> = Simplify<CleanSelect<TTable> & (TWith extends RelationalWith<TTable> ? {
|
|
36
65
|
[K in keyof TWith]: RelationValueForKey<TTable, K, TWith[K]>;
|
|
37
66
|
} : {})>;
|
|
67
|
+
type WhereObject<TTable> = TTable extends TableDefinition<infer TCols> ? {
|
|
68
|
+
[K in keyof TCols]?: TCols[K] extends ClickHouseColumn<infer T> ? T | SQLExpression : any;
|
|
69
|
+
} : Record<string, any>;
|
|
38
70
|
export type RelationalFindOptions<TTable = any> = {
|
|
39
71
|
/**
|
|
40
|
-
* Filter
|
|
41
|
-
* Can be a SQL expression or a callback receiving the table columns.
|
|
72
|
+
* Filter rows.
|
|
42
73
|
*
|
|
43
|
-
* @example
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
74
|
+
* @example
|
|
75
|
+
* // Object syntax (simplest)
|
|
76
|
+
* where: { email: 'a@b.com' }
|
|
77
|
+
* where: { role: 'admin', active: true }
|
|
78
|
+
*
|
|
79
|
+
* // Direct expression
|
|
80
|
+
* where: eq(users.active, true)
|
|
81
|
+
*
|
|
82
|
+
* // Callback for complex filters
|
|
83
|
+
* where: (cols, { eq, and, gt }) => and(eq(cols.role, 'admin'), gt(cols.age, 18))
|
|
48
84
|
*/
|
|
85
|
+
where?: WhereObject<TTable> | SQLExpression | ((columns: TTable extends TableDefinition<infer TCols> ? TCols : any, ops: typeof operators) => SQLExpression);
|
|
86
|
+
/** Max rows to return */
|
|
49
87
|
limit?: number;
|
|
50
88
|
/**
|
|
51
|
-
*
|
|
89
|
+
* Select specific columns. By default all columns are returned.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* columns: { id: true, email: true }
|
|
52
93
|
*/
|
|
94
|
+
columns?: TTable extends TableDefinition<infer TCols> ? {
|
|
95
|
+
[K in keyof TCols]?: boolean;
|
|
96
|
+
} : Record<string, boolean>;
|
|
97
|
+
/** Rows to skip */
|
|
53
98
|
offset?: number;
|
|
54
99
|
/**
|
|
55
|
-
*
|
|
56
|
-
* Set to `true` for all columns or provide a `RelationalFindOptions` object for nested filtering/limiting.
|
|
100
|
+
* Sort results. Accepts direct value, array, or callback.
|
|
57
101
|
*
|
|
58
|
-
* @example
|
|
102
|
+
* @example
|
|
103
|
+
* // Direct
|
|
104
|
+
* orderBy: desc(users.createdAt)
|
|
105
|
+
*
|
|
106
|
+
* // Array
|
|
107
|
+
* orderBy: [desc(users.createdAt), asc(users.name)]
|
|
108
|
+
*
|
|
109
|
+
* // Callback
|
|
110
|
+
* orderBy: (cols, { desc }) => desc(cols.createdAt)
|
|
59
111
|
*/
|
|
60
|
-
|
|
112
|
+
orderBy?: OrderByValue | OrderByValue[] | ((columns: TTable extends TableDefinition<infer TCols> ? TCols : any, fns: {
|
|
113
|
+
asc: typeof ops.asc;
|
|
114
|
+
desc: typeof ops.desc;
|
|
115
|
+
}) => OrderByValue | OrderByValue[]);
|
|
61
116
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* - 'auto': Automatically uses GLOBAL when table has onCluster option.
|
|
65
|
-
* - 'standard': Regular LEFT JOIN.
|
|
66
|
-
* - 'global': Force GLOBAL JOIN (for sharded clusters).
|
|
67
|
-
* - 'any': Use ANY JOIN (faster, optimized for 1:1 relations).
|
|
68
|
-
* - 'global_any': Combine GLOBAL and ANY.
|
|
117
|
+
* Include related data. Use `true` for all columns or an object for filtering.
|
|
69
118
|
*
|
|
119
|
+
* @example
|
|
120
|
+
* with: {
|
|
121
|
+
* posts: true, // All posts
|
|
122
|
+
* comments: { limit: 5 }, // Latest 5 comments
|
|
123
|
+
* profile: { where: eq(profile.public, true) } // Only public profile
|
|
124
|
+
* }
|
|
125
|
+
*/
|
|
126
|
+
with?: RelationalWith<TTable>;
|
|
127
|
+
/**
|
|
128
|
+
* Join strategy for distributed clusters.
|
|
70
129
|
* @default 'auto'
|
|
71
130
|
*/
|
|
72
131
|
joinStrategy?: JoinStrategy;
|
|
73
132
|
};
|
|
133
|
+
type OrderByValue = {
|
|
134
|
+
col: ClickHouseColumn | SQLExpression;
|
|
135
|
+
dir: 'ASC' | 'DESC';
|
|
136
|
+
};
|
|
74
137
|
export type RelationalAPI<TSchema extends Record<string, TableDefinition<any>>> = {
|
|
75
138
|
[K in keyof TSchema]: {
|
|
139
|
+
/** Find multiple records with optional filtering, pagination, and relations */
|
|
76
140
|
findMany: <TOpts extends RelationalFindOptions<TSchema[K]> | undefined>(opts?: TOpts) => Promise<Array<RelationalResult<TSchema[K], TOpts extends RelationalFindOptions<TSchema[K]> ? TOpts['with'] : undefined>>>;
|
|
141
|
+
/** Find a single record (first match) */
|
|
77
142
|
findFirst: <TOpts extends RelationalFindOptions<TSchema[K]> | undefined>(opts?: TOpts) => Promise<RelationalResult<TSchema[K], TOpts extends RelationalFindOptions<TSchema[K]> ? TOpts['with'] : undefined> | null>;
|
|
143
|
+
/**
|
|
144
|
+
* Find a record by its primary key
|
|
145
|
+
* @example
|
|
146
|
+
* const user = await db.query.users.findById('uuid-here')
|
|
147
|
+
* const user = await db.query.users.findById('uuid', { with: { posts: true } })
|
|
148
|
+
*/
|
|
149
|
+
findById: <TOpts extends Omit<RelationalFindOptions<TSchema[K]>, 'where' | 'limit'> | undefined>(id: string | number, opts?: TOpts) => Promise<RelationalResult<TSchema[K], TOpts extends RelationalFindOptions<TSchema[K]> ? TOpts['with'] : undefined> | null>;
|
|
78
150
|
};
|
|
79
151
|
};
|
|
80
152
|
/**
|
package/dist/schema-builder.d.ts
CHANGED
|
@@ -66,6 +66,18 @@ export type EnhancedTableOptions<TColKeys extends string = string> = Omit<TableO
|
|
|
66
66
|
* ClickHouse data types builder.
|
|
67
67
|
* All columns are NOT NULL by default, following ClickHouse philosophy.
|
|
68
68
|
*/
|
|
69
|
+
declare function primaryUuid(): {
|
|
70
|
+
id: ClickHouseColumn<string, true, true>;
|
|
71
|
+
};
|
|
72
|
+
declare function primaryUuid<TName extends string>(name: TName): {
|
|
73
|
+
[K in TName]: ClickHouseColumn<string, true, true>;
|
|
74
|
+
};
|
|
75
|
+
declare function primaryUuidV7(): {
|
|
76
|
+
id: ClickHouseColumn<string, true, true>;
|
|
77
|
+
};
|
|
78
|
+
declare function primaryUuidV7<TName extends string>(name: TName): {
|
|
79
|
+
[K in TName]: ClickHouseColumn<string, true, true>;
|
|
80
|
+
};
|
|
69
81
|
export declare const t: {
|
|
70
82
|
int8: (name: string) => ClickHouseColumn<number, true, false>;
|
|
71
83
|
int16: (name: string) => ClickHouseColumn<number, true, false>;
|
|
@@ -136,18 +148,22 @@ export declare const t: {
|
|
|
136
148
|
* Adds 'created_at' and 'updated_at' columns with default now().
|
|
137
149
|
*/
|
|
138
150
|
timestamps: () => {
|
|
139
|
-
created_at: ClickHouseColumn<string | Date, true,
|
|
140
|
-
updated_at: ClickHouseColumn<string | Date, true,
|
|
151
|
+
created_at: ClickHouseColumn<string | Date, true, true>;
|
|
152
|
+
updated_at: ClickHouseColumn<string | Date, true, true>;
|
|
141
153
|
};
|
|
142
154
|
/**
|
|
143
155
|
* Adds a standard UUID primary key column (default: 'id').
|
|
144
156
|
*/
|
|
145
|
-
primaryUuid:
|
|
157
|
+
primaryUuid: typeof primaryUuid;
|
|
158
|
+
/**
|
|
159
|
+
* Adds a UUID v7 primary key column (default: 'id').
|
|
160
|
+
*/
|
|
161
|
+
primaryUuidV7: typeof primaryUuidV7;
|
|
146
162
|
/**
|
|
147
163
|
* Adds 'is_deleted' and 'deleted_at' columns for soft deletes.
|
|
148
164
|
*/
|
|
149
165
|
softDeletes: () => {
|
|
150
|
-
is_deleted: ClickHouseColumn<boolean, true,
|
|
166
|
+
is_deleted: ClickHouseColumn<boolean, true, true>;
|
|
151
167
|
deleted_at: ClickHouseColumn<string | Date, false, false>;
|
|
152
168
|
};
|
|
153
169
|
};
|
package/dist/table.d.ts
CHANGED
|
@@ -67,21 +67,29 @@ export type RelationDefinition<TTarget extends TableDefinition<any> = TableDefin
|
|
|
67
67
|
references?: ClickHouseColumn[];
|
|
68
68
|
};
|
|
69
69
|
export type TableColumns = Record<string, ClickHouseColumn<any, any, any>>;
|
|
70
|
+
/**
|
|
71
|
+
* Utility to force TypeScript to expand computed types for cleaner tooltips.
|
|
72
|
+
*/
|
|
73
|
+
export type Prettify<T> = {
|
|
74
|
+
[K in keyof T]: T[K];
|
|
75
|
+
} & {};
|
|
70
76
|
export type TableRow<TCols extends TableColumns> = {
|
|
71
77
|
[K in keyof TCols]: TCols[K] extends ClickHouseColumn<infer T, infer NotNull, any> ? NotNull extends true ? T : T | null : never;
|
|
72
78
|
};
|
|
73
79
|
export type TableInsert<TCols extends TableColumns> = {
|
|
74
|
-
[K in keyof TCols as TCols[K] extends ClickHouseColumn<any,
|
|
80
|
+
[K in keyof TCols as TCols[K] extends ClickHouseColumn<any, any, infer Auto> ? Auto extends true ? never : K : never]: TCols[K] extends ClickHouseColumn<infer T, infer NotNull, any> ? NotNull extends true ? T : T | null : never;
|
|
81
|
+
} & {
|
|
82
|
+
[K in keyof TCols as TCols[K] extends ClickHouseColumn<any, any, infer Auto> ? Auto extends true ? K : never : never]?: TCols[K] extends ClickHouseColumn<infer T, infer NotNull, any> ? NotNull extends true ? T : T | null : never;
|
|
75
83
|
};
|
|
76
84
|
type GetColumnType<T extends ClickHouseColumn> = T extends ClickHouseColumn<infer Type, infer IsNotNull, any> ? IsNotNull extends true ? Type : Type | null : never;
|
|
77
85
|
export type InferSelectModel<T extends {
|
|
78
86
|
$columns: TableColumns;
|
|
79
|
-
}> = {
|
|
87
|
+
}> = Prettify<{
|
|
80
88
|
[K in keyof T['$columns']]: GetColumnType<T['$columns'][K]>;
|
|
81
|
-
}
|
|
89
|
+
}>;
|
|
82
90
|
export type InferInsertModel<T extends {
|
|
83
91
|
$columns: TableColumns;
|
|
84
|
-
}> = TableInsert<T['$columns']
|
|
92
|
+
}> = Prettify<TableInsert<T['$columns']>>;
|
|
85
93
|
type InferInsertFromColumns<T> = T extends {
|
|
86
94
|
$columns: infer TCols extends TableColumns;
|
|
87
95
|
} ? TableInsert<TCols> : never;
|
|
@@ -118,6 +126,12 @@ export type TableDefinition<TCols extends TableColumns, TOptions = TableOptions>
|
|
|
118
126
|
readonly $inferInsert: InferInsertModel<{
|
|
119
127
|
$columns: TCols;
|
|
120
128
|
}>;
|
|
129
|
+
readonly $type: InferSelectModel<{
|
|
130
|
+
$columns: TCols;
|
|
131
|
+
}>;
|
|
132
|
+
readonly $insert: InferInsertModel<{
|
|
133
|
+
$columns: TCols;
|
|
134
|
+
}>;
|
|
121
135
|
} & TCols;
|
|
122
136
|
export type TableRuntime<TInsert = any, TSelect = any, TOptions = TableOptions> = {
|
|
123
137
|
$table: string;
|
|
@@ -129,6 +143,8 @@ export type TableRuntime<TInsert = any, TSelect = any, TOptions = TableOptions>
|
|
|
129
143
|
as(alias: string): TableRuntime<TInsert, TSelect, TOptions>;
|
|
130
144
|
readonly $inferSelect: TSelect;
|
|
131
145
|
readonly $inferInsert: TInsert;
|
|
146
|
+
readonly $type: TSelect;
|
|
147
|
+
readonly $insert: TInsert;
|
|
132
148
|
};
|
|
133
149
|
export interface VersionedMeta {
|
|
134
150
|
baseName: string;
|
|
@@ -8,9 +8,7 @@ export declare class BatchTransformStream extends Transform {
|
|
|
8
8
|
private plan;
|
|
9
9
|
private mode;
|
|
10
10
|
private batch;
|
|
11
|
-
private processingTimer;
|
|
12
11
|
private readonly batchSize;
|
|
13
|
-
private readonly maxProcessingTime;
|
|
14
12
|
constructor(plan: InsertPlan, mode: 'compact' | 'json', options?: BatchTransformOptions);
|
|
15
13
|
_transform(chunk: any, _encoding: BufferEncoding, callback: TransformCallback): void;
|
|
16
14
|
_flush(callback: TransformCallback): void;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Acquire a BinaryWriter from the pool (or create new if pool empty)
|
|
3
|
+
*/
|
|
4
|
+
export declare function acquireWriter(): BinaryWriter;
|
|
5
|
+
/**
|
|
6
|
+
* Release a BinaryWriter back to the pool
|
|
7
|
+
*/
|
|
8
|
+
export declare function releaseWriter(writer: BinaryWriter): void;
|
|
1
9
|
/**
|
|
2
10
|
* HouseKit Binary Serializer - Ultra-Fast RowBinary Encoding
|
|
3
11
|
*
|
|
@@ -158,3 +166,52 @@ export declare function serializeRowBinary(row: Record<string, any>, config: Bin
|
|
|
158
166
|
* Serialize multiple rows to a single RowBinary buffer
|
|
159
167
|
*/
|
|
160
168
|
export declare function serializeRowsBinary(rows: Array<Record<string, any>>, config: BinarySerializationConfig): Buffer;
|
|
169
|
+
export type RowAccessor = (row: any) => any;
|
|
170
|
+
/**
|
|
171
|
+
* Create an optimized accessor function for a column.
|
|
172
|
+
* Uses direct property access instead of dynamic lookup.
|
|
173
|
+
*/
|
|
174
|
+
export declare function createAccessor(propKey: string, columnName: string): RowAccessor;
|
|
175
|
+
/**
|
|
176
|
+
* Optimized serialization config with pre-compiled accessors
|
|
177
|
+
*/
|
|
178
|
+
export interface OptimizedBinaryConfig {
|
|
179
|
+
columns: Array<{
|
|
180
|
+
name: string;
|
|
181
|
+
type: string;
|
|
182
|
+
isNullable: boolean;
|
|
183
|
+
}>;
|
|
184
|
+
encoders: BinaryEncoder[];
|
|
185
|
+
accessors: RowAccessor[];
|
|
186
|
+
/** Skip validation for maximum performance (Optimization #4) */
|
|
187
|
+
skipValidation?: boolean;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Build an optimized binary config with pre-compiled accessors
|
|
191
|
+
*/
|
|
192
|
+
export declare function buildOptimizedBinaryConfig(columns: Array<{
|
|
193
|
+
name: string;
|
|
194
|
+
type: string;
|
|
195
|
+
isNull: boolean;
|
|
196
|
+
propKey: string;
|
|
197
|
+
}>, options?: {
|
|
198
|
+
skipValidation?: boolean;
|
|
199
|
+
}): OptimizedBinaryConfig;
|
|
200
|
+
/**
|
|
201
|
+
* Ultra-fast serialization using pre-compiled accessors and pooled writer
|
|
202
|
+
*/
|
|
203
|
+
export declare function serializeRowsOptimized(rows: Array<Record<string, any>>, config: OptimizedBinaryConfig): Buffer;
|
|
204
|
+
/**
|
|
205
|
+
* Check if a schema is numeric-heavy (>50% numeric columns)
|
|
206
|
+
*/
|
|
207
|
+
export declare function isNumericHeavySchema(columns: Array<{
|
|
208
|
+
type: string;
|
|
209
|
+
}>): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Batch serialize numeric columns using TypedArrays for better performance.
|
|
212
|
+
* Only use for schemas with mostly numeric columns.
|
|
213
|
+
*/
|
|
214
|
+
export declare function serializeNumericBatch(rows: Array<Record<string, any>>, config: OptimizedBinaryConfig, numericIndices: number[]): {
|
|
215
|
+
numericBuffer: ArrayBuffer;
|
|
216
|
+
otherData: any[][];
|
|
217
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const binaryWorkerCode = "import{parentPort as D,workerData as d}from\"worker_threads\";var X=[];for(let x=0;x<256;++x)X.push((x+256).toString(16).slice(1));function B(x,U=0){return(X[x[U+0]]+X[x[U+1]]+X[x[U+2]]+X[x[U+3]]+\"-\"+X[x[U+4]]+X[x[U+5]]+\"-\"+X[x[U+6]]+X[x[U+7]]+\"-\"+X[x[U+8]]+X[x[U+9]]+\"-\"+X[x[U+10]]+X[x[U+11]]+X[x[U+12]]+X[x[U+13]]+X[x[U+14]]+X[x[U+15]]).toLowerCase()}import{randomFillSync as o}from\"node:crypto\";var N=new Uint8Array(256),G=N.length;function P(){if(G>N.length-16)o(N),G=0;return N.slice(G,G+=16)}import{randomUUID as n}from\"node:crypto\";var S={randomUUID:n};function y(x,U,I){x=x||{};let A=x.random??x.rng?.()??P();if(A.length<16)throw Error(\"Random bytes length must be >= 16\");if(A[6]=A[6]&15|64,A[8]=A[8]&63|128,U){if(I=I||0,I<0||I+16>U.length)throw RangeError(`UUID byte range ${I}:${I+15} is out of buffer bounds`);for(let H=0;H<16;++H)U[I+H]=A[H];return U}return B(A)}function p(x,U,I){if(S.randomUUID&&!U&&!x)return S.randomUUID();return y(x,U,I)}var W=p;class z{buffer;offset=0;constructor(x=4096){this.buffer=Buffer.allocUnsafe(x)}ensureCapacity(x){let U=this.offset+x;if(U>this.buffer.length){let I=Math.max(this.buffer.length*2,U),A=Buffer.allocUnsafe(I);this.buffer.copy(A,0,0,this.offset),this.buffer=A}}reset(){this.offset=0}getBuffer(){return this.buffer.subarray(0,this.offset)}toBuffer(){return Buffer.from(this.buffer.subarray(0,this.offset))}writeInt8(x){this.ensureCapacity(1),this.buffer.writeInt8(x,this.offset),this.offset+=1}writeUInt8(x){this.ensureCapacity(1),this.buffer.writeUInt8(x,this.offset),this.offset+=1}writeInt16(x){this.ensureCapacity(2),this.buffer.writeInt16LE(x,this.offset),this.offset+=2}writeUInt16(x){this.ensureCapacity(2),this.buffer.writeUInt16LE(x,this.offset),this.offset+=2}writeInt32(x){this.ensureCapacity(4),this.buffer.writeInt32LE(x,this.offset),this.offset+=4}writeUInt32(x){this.ensureCapacity(4),this.buffer.writeUInt32LE(x,this.offset),this.offset+=4}writeInt64(x){this.ensureCapacity(8),this.buffer.writeBigInt64LE(BigInt(x),this.offset),this.offset+=8}writeUInt64(x){this.ensureCapacity(8),this.buffer.writeBigUInt64LE(BigInt(x),this.offset),this.offset+=8}writeInt128(x){this.ensureCapacity(16);let U=x&BigInt(\"0xFFFFFFFFFFFFFFFF\"),I=x>>BigInt(64);this.buffer.writeBigUInt64LE(U,this.offset),this.buffer.writeBigInt64LE(I,this.offset+8),this.offset+=16}writeUInt128(x){this.ensureCapacity(16);let U=x&BigInt(\"0xFFFFFFFFFFFFFFFF\"),I=x>>BigInt(64);this.buffer.writeBigUInt64LE(U,this.offset),this.buffer.writeBigUInt64LE(I,this.offset+8),this.offset+=16}writeInt256(x){this.ensureCapacity(32);for(let U=0;U<4;U++){let I=x&BigInt(\"0xFFFFFFFFFFFFFFFF\");this.buffer.writeBigUInt64LE(I,this.offset+U*8),x>>=BigInt(64)}this.offset+=32}writeUInt256(x){this.writeInt256(x)}writeFloat32(x){this.ensureCapacity(4),this.buffer.writeFloatLE(x,this.offset),this.offset+=4}writeFloat64(x){this.ensureCapacity(8),this.buffer.writeDoubleLE(x,this.offset),this.offset+=8}writeVarInt(x){if(x<128){this.ensureCapacity(1),this.buffer[this.offset++]=x;return}if(x<16384){this.ensureCapacity(2),this.buffer[this.offset++]=x&127|128,this.buffer[this.offset++]=x>>7;return}if(x<2097152){this.ensureCapacity(3),this.buffer[this.offset++]=x&127|128,this.buffer[this.offset++]=x>>7&127|128,this.buffer[this.offset++]=x>>14;return}this.ensureCapacity(10);while(x>=128)this.buffer[this.offset++]=x&127|128,x>>>=7;this.buffer[this.offset++]=x}writeString(x){let U=Buffer.from(x,\"utf-8\");this.writeVarInt(U.length),this.ensureCapacity(U.length),U.copy(this.buffer,this.offset),this.offset+=U.length}writeFixedString(x,U){this.ensureCapacity(U);let I=Buffer.from(x,\"utf-8\"),A=Math.min(I.length,U);if(I.copy(this.buffer,this.offset,0,A),A<U)this.buffer.fill(0,this.offset+A,this.offset+U);this.offset+=U}writeBytes(x){this.ensureCapacity(x.length),x.copy(this.buffer,this.offset),this.offset+=x.length}writeUUID(x){this.ensureCapacity(16);let U=x.replace(/-/g,\"\");if(U.length!==32)throw Error(`Invalid UUID: ${x}`);let I=Buffer.from(U,\"hex\");for(let A=7;A>=0;A--)this.buffer[this.offset++]=I[A];for(let A=15;A>=8;A--)this.buffer[this.offset++]=I[A]}writeDate(x){let U=typeof x===\"number\"?x:Math.floor(x.getTime()/86400000);this.writeUInt16(U)}writeDate32(x){let U=typeof x===\"number\"?x:Math.floor(x.getTime()/86400000);this.writeInt32(U)}writeDateTime(x){let U=typeof x===\"number\"?x:Math.floor(x.getTime()/1000);this.writeUInt32(U)}writeDateTime64(x,U=3){let I=Math.pow(10,U),A=typeof x===\"number\"?BigInt(Math.round(x*I)):BigInt(Math.round(x.getTime()*I/1000));this.writeInt64(A)}writeNullable(x){this.writeUInt8(x?1:0)}writeArrayLength(x){this.writeUInt64(x)}writeDecimal32(x,U){let I=Math.round(x*Math.pow(10,U));this.writeInt32(I)}writeDecimal64(x,U){let I=BigInt(Math.round(x*Math.pow(10,U)));this.writeInt64(I)}writeDecimal128(x,U){let I;if(typeof x===\"bigint\")I=x*BigInt(Math.pow(10,U));else I=BigInt(Math.round(x*Math.pow(10,U)));this.writeInt128(I)}writeBool(x){this.writeUInt8(x?1:0)}writeIPv4(x){if(typeof x===\"number\"){this.writeUInt32(x);return}let U=x.split(\".\").map(Number);if(U.length!==4)throw Error(`Invalid IPv4: ${x}`);let I=U[0]<<24|U[1]<<16|U[2]<<8|U[3];this.writeUInt32(I>>>0)}writeIPv6(x){if(Buffer.isBuffer(x)){if(x.length!==16)throw Error(\"IPv6 must be 16 bytes\");this.writeBytes(x);return}let I=this.expandIPv6(x).split(\":\");this.ensureCapacity(16);for(let A of I){let H=parseInt(A,16);this.buffer.writeUInt16BE(H,this.offset),this.offset+=2}}expandIPv6(x){let U=x.split(\"::\");if(U.length===1)return x;let I=U[0]?U[0].split(\":\"):[],A=U[1]?U[1].split(\":\"):[],H=8-I.length-A.length,K=Array(H).fill(\"0000\");return[...I,...K,...A].map((L)=>L.padStart(4,\"0\")).join(\":\")}writeEnum8(x){this.writeInt8(x)}writeEnum16(x){this.writeInt16(x)}}function m(x){let U=[],I=\"\",A=0;for(let H=0;H<x.length;H++){let K=x[H];if(K===\",\"&&A===0)U.push(I.trim()),I=\"\";else{if(K===\"(\")A++;if(K===\")\")A--;I+=K}}if(I.trim())U.push(I.trim());return U}function Q(x,U=!1){let I=x.toLowerCase().trim(),A=I.match(/^nullable\\((.+)\\)$/);if(A){let C=Q(A[1],!1);return($,F)=>{if(F===null||F===void 0)$.writeNullable(!0);else $.writeNullable(!1),C($,F)}}let H=I.match(/^array\\((.+)\\)$/);if(H){let C=Q(H[1],!1);return($,F)=>{let O=Array.isArray(F)?F:[];$.writeArrayLength(O.length);for(let J of O)C($,J)}}let K=I.match(/^map\\((.+)\\)$/);if(K){let[C,$]=m(K[1]);if(!C||!$)throw Error(`Invalid Map type: ${I}`);let F=Q(C),O=Q($);return(J,j)=>{let V;if(j instanceof Map)V=Array.from(j.entries());else if(typeof j===\"object\"&&j!==null)V=Object.entries(j);else V=[];J.writeUInt64(V.length);for(let[Y,q]of V)F(J,Y),O(J,q)}}let L=I.match(/^tuple\\((.+)\\)$/);if(L){let $=m(L[1]).map((F)=>Q(F));return(F,O)=>{let J=Array.isArray(O)?O:[];for(let j=0;j<$.length;j++)$[j](F,J[j])}}let T=I.match(/^nested\\((.+)\\)$/);if(T){let C=m(T[1]),F=`Tuple(${C.map((J)=>{let j=J.trim().split(/\\s+/);if(j.length<2)return\"String\";return j.slice(1).join(\" \")}).join(\", \")})`,O=Q(F);return(J,j)=>{let V=Array.isArray(j)?j:[];J.writeArrayLength(V.length);for(let Y of V){let q=Y;if(!Array.isArray(Y)&&typeof Y===\"object\")q=C.map((h)=>{let g=h.trim().split(/\\s+/)[0];return Y[g]});O(J,q)}}}let b=I.match(/^lowcardinality\\((.+)\\)$/);if(b)return Q(b[1]);let k=I.match(/^fixedstring\\((\\d+)\\)$/);if(k){let C=parseInt(k[1],10);return($,F)=>{$.writeFixedString(String(F??\"\"),C)}}let E=I.match(/^decimal(?:32|64|128)?\\((\\d+),\\s*(\\d+)\\)$/);if(E){let C=parseInt(E[2],10);if(I.includes(\"decimal128\"))return($,F)=>$.writeDecimal128(F,C);if(I.includes(\"decimal64\"))return($,F)=>$.writeDecimal64(F,C);return($,F)=>$.writeDecimal32(F,C)}let M=I.match(/^datetime64\\((\\d+)/);if(M){let C=parseInt(M[1],10);return($,F)=>$.writeDateTime64(F,C)}if(I.match(/^enum8\\(/))return(C,$)=>C.writeEnum8(Number($));if(I.match(/^enum16\\(/))return(C,$)=>C.writeEnum16(Number($));let R=w(I);if(U)return(C,$)=>{if($===null||$===void 0)C.writeNullable(!0);else C.writeNullable(!1),R(C,$)};if(I===\"uuid\")return(C,$)=>{if($===void 0||$===null)R(C,W());else R(C,$)};return R}function w(x){if(x===\"int8\")return(U,I)=>U.writeInt8(Number(I));if(x===\"uint8\")return(U,I)=>U.writeUInt8(Number(I));if(x===\"int16\")return(U,I)=>U.writeInt16(Number(I));if(x===\"uint16\")return(U,I)=>U.writeUInt16(Number(I));if(x===\"int32\")return(U,I)=>U.writeInt32(Number(I));if(x===\"uint32\")return(U,I)=>U.writeUInt32(Number(I));if(x===\"int64\")return(U,I)=>U.writeInt64(I);if(x===\"uint64\")return(U,I)=>U.writeUInt64(I);if(x===\"int128\")return(U,I)=>U.writeInt128(BigInt(I));if(x===\"uint128\")return(U,I)=>U.writeUInt128(BigInt(I));if(x===\"int256\")return(U,I)=>U.writeInt256(BigInt(I));if(x===\"uint256\")return(U,I)=>U.writeUInt256(BigInt(I));if(x===\"float32\")return(U,I)=>U.writeFloat32(Number(I));if(x===\"float64\")return(U,I)=>U.writeFloat64(Number(I));if(x===\"string\")return(U,I)=>U.writeString(String(I??\"\"));if(x===\"uuid\")return(U,I)=>U.writeUUID(String(I));if(x===\"date\")return(U,I)=>U.writeDate(I);if(x===\"date32\")return(U,I)=>U.writeDate32(I);if(x===\"datetime\")return(U,I)=>U.writeDateTime(I);if(x.startsWith(\"datetime64\"))return(U,I)=>U.writeDateTime64(I,3);if(x===\"bool\"||x===\"boolean\")return(U,I)=>U.writeBool(Boolean(I));if(x===\"ipv4\")return(U,I)=>U.writeIPv4(I);if(x===\"ipv6\")return(U,I)=>U.writeIPv6(I);return(U,I)=>U.writeString(String(I??\"\"))}var Z=null,_=null;function s(x,U){if(!Z||!_)throw Error(\"Worker not configured\");_.reset();for(let I of x)for(let A=0;A<Z.columns.length;A++){let H=Z.columns[A],K=I[H.name];Z.encoders[A](_,K)}return _.toBuffer()}function f(x){try{switch(x.type){case\"configure\":{let U=x.columns.map((I)=>Q(I.type,I.isNullable));Z={columns:x.columns,keyMapping:new Map,encoders:U},_=new z(1048576),D?.postMessage({type:\"ready\"});break}case\"serialize\":{let U=s(x.rows,x.batchId),I=new ArrayBuffer(U.length);new Uint8Array(I).set(U),D?.postMessage({type:\"result\",batchId:x.batchId,buffer:Buffer.from(I),rowCount:x.rows.length},[I]);break}case\"shutdown\":process.exit(0)}}catch(U){D?.postMessage({type:\"error\",batchId:x.batchId,error:U instanceof Error?U.message:String(U)})}}if(D){if(D.on(\"message\",f),d?.columns)f({type:\"configure\",columns:d.columns})}\n";
|
|
1
|
+
export declare const binaryWorkerCode = "var{defineProperty:i,getOwnPropertyNames:g0,getOwnPropertyDescriptor:M0}=Object,h0=Object.prototype.hasOwnProperty;var m0=new WeakMap,b0=(f)=>{var x=m0.get(f),U;if(x)return x;if(x=i({},\"__esModule\",{value:!0}),f&&typeof f===\"object\"||typeof f===\"function\")g0(f).map((m)=>!h0.call(x,m)&&i(x,m,{get:()=>f[m],enumerable:!(U=M0(f,m))||U.enumerable}));return m0.set(f,x),x};var o0=(f,x)=>{for(var U in x)i(f,U,{get:x[U],enumerable:!0,configurable:!0,set:(m)=>x[U]=()=>m})};var L=(f,x)=>()=>(f&&(x=f(f=0)),x);var A0=\"ffffffff-ffff-ffff-ffff-ffffffffffff\";var D0=\"00000000-0000-0000-0000-000000000000\";var S0;var V0=L(()=>{S0=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i});function B0(f){return typeof f===\"string\"&&S0.test(f)}var Z;var C=L(()=>{V0();Z=B0});function p0(f){if(!Z(f))throw TypeError(\"Invalid UUID\");let x;return Uint8Array.of((x=parseInt(f.slice(0,8),16))>>>24,x>>>16&255,x>>>8&255,x&255,(x=parseInt(f.slice(9,13),16))>>>8,x&255,(x=parseInt(f.slice(14,18),16))>>>8,x&255,(x=parseInt(f.slice(19,23),16))>>>8,x&255,(x=parseInt(f.slice(24,36),16))/1099511627776&255,x/4294967296&255,x>>>24&255,x>>>16&255,x>>>8&255,x&255)}var N;var F=L(()=>{C();N=p0});function X(f,x=0){return(_[f[x+0]]+_[f[x+1]]+_[f[x+2]]+_[f[x+3]]+\"-\"+_[f[x+4]]+_[f[x+5]]+\"-\"+_[f[x+6]]+_[f[x+7]]+\"-\"+_[f[x+8]]+_[f[x+9]]+\"-\"+_[f[x+10]]+_[f[x+11]]+_[f[x+12]]+_[f[x+13]]+_[f[x+14]]+_[f[x+15]]).toLowerCase()}function y0(f,x=0){let U=X(f,x);if(!Z(U))throw TypeError(\"Stringified UUID is invalid\");return U}var _,R0;var Q=L(()=>{C();_=[];for(let f=0;f<256;++f)_.push((f+256).toString(16).slice(1));R0=y0});import{randomFillSync as i0}from\"node:crypto\";function Y(){if(M>h.length-16)i0(h),M=0;return h.slice(M,M+=16)}var h,M;var b=L(()=>{h=new Uint8Array(256),M=h.length});function c0(f,x,U){let m,A=f?._v6??!1;if(f){let D=Object.keys(f);if(D.length===1&&D[0]===\"_v6\")f=void 0}if(f)m=$0(f.random??f.rng?.()??Y(),f.msecs,f.nsecs,f.clockseq,f.node,x,U);else{let D=Date.now(),R=Y();w0(K,D,R),m=$0(R,K.msecs,K.nsecs,A?void 0:K.clockseq,A?void 0:K.node,x,U)}return x??X(m)}function w0(f,x,U){if(f.msecs??=-1/0,f.nsecs??=0,x===f.msecs){if(f.nsecs++,f.nsecs>=1e4)f.node=void 0,f.nsecs=0}else if(x>f.msecs)f.nsecs=0;else if(x<f.msecs)f.node=void 0;if(!f.node)f.node=U.slice(10,16),f.node[0]|=1,f.clockseq=(U[8]<<8|U[9])&16383;return f.msecs=x,f}function $0(f,x,U,m,A,D,R=0){if(f.length<16)throw Error(\"Random bytes length must be >= 16\");if(!D)D=new Uint8Array(16),R=0;else if(R<0||R+16>D.length)throw RangeError(`UUID byte range ${R}:${R+15} is out of buffer bounds`);x??=Date.now(),U??=0,m??=(f[8]<<8|f[9])&16383,A??=f.slice(10,16),x+=12219292800000;let q=((x&268435455)*1e4+U)%4294967296;D[R++]=q>>>24&255,D[R++]=q>>>16&255,D[R++]=q>>>8&255,D[R++]=q&255;let H=x/4294967296*1e4&268435455;D[R++]=H>>>8&255,D[R++]=H&255,D[R++]=H>>>24&15|16,D[R++]=H>>>16&255,D[R++]=m>>>8|128,D[R++]=m&255;for(let n=0;n<6;++n)D[R++]=A[n];return D}var K,o;var w=L(()=>{b();Q();K={};o=c0});function z(f){let x=typeof f===\"string\"?N(f):f,U=r0(x);return typeof f===\"string\"?X(U):U}function r0(f){return Uint8Array.of((f[6]&15)<<4|f[7]>>4&15,(f[7]&15)<<4|(f[4]&240)>>4,(f[4]&15)<<4|(f[5]&240)>>4,(f[5]&15)<<4|(f[0]&240)>>4,(f[0]&15)<<4|(f[1]&240)>>4,(f[1]&15)<<4|(f[2]&240)>>4,96|f[2]&15,f[3],f[8],f[9],f[10],f[11],f[12],f[13],f[14],f[15])}var r=L(()=>{F();Q()});import{createHash as t0}from\"node:crypto\";function s0(f){if(Array.isArray(f))f=Buffer.from(f);else if(typeof f===\"string\")f=Buffer.from(f,\"utf8\");return t0(\"md5\").update(f).digest()}var L0;var H0=L(()=>{L0=s0});function u0(f){f=unescape(encodeURIComponent(f));let x=new Uint8Array(f.length);for(let U=0;U<f.length;++U)x[U]=f.charCodeAt(U);return x}function P(f,x,U,m,A,D){let R=typeof U===\"string\"?u0(U):U,q=typeof m===\"string\"?N(m):m;if(typeof m===\"string\")m=N(m);if(m?.length!==16)throw TypeError(\"Namespace must be array-like (16 iterable integer values, 0-255)\");let H=new Uint8Array(16+R.length);if(H.set(q),H.set(R,q.length),H=x(H),H[6]=H[6]&15|f,H[8]=H[8]&63|128,A){D=D||0;for(let n=0;n<16;++n)A[D+n]=H[n];return A}return X(H)}var B=\"6ba7b810-9dad-11d1-80b4-00c04fd430c8\",p=\"6ba7b811-9dad-11d1-80b4-00c04fd430c8\";var t=L(()=>{F();Q()});function s(f,x,U,m){return P(48,L0,f,x,U,m)}var _0;var I0=L(()=>{H0();t();s.DNS=B;s.URL=p;_0=s});import{randomUUID as l0}from\"node:crypto\";var u;var X0=L(()=>{u={randomUUID:l0}});function v0(f,x,U){f=f||{};let m=f.random??f.rng?.()??Y();if(m.length<16)throw Error(\"Random bytes length must be >= 16\");if(m[6]=m[6]&15|64,m[8]=m[8]&63|128,x){if(U=U||0,U<0||U+16>x.length)throw RangeError(`UUID byte range ${U}:${U+15} is out of buffer bounds`);for(let A=0;A<16;++A)x[U+A]=m[A];return x}return X(m)}function a0(f,x,U){if(u.randomUUID&&!x&&!f)return u.randomUUID();return v0(f,x,U)}var j0;var n0=L(()=>{X0();b();Q();j0=a0});import{createHash as e0}from\"node:crypto\";function f1(f){if(Array.isArray(f))f=Buffer.from(f);else if(typeof f===\"string\")f=Buffer.from(f,\"utf8\");return e0(\"sha1\").update(f).digest()}var q0;var J0=L(()=>{q0=f1});function l(f,x,U,m){return P(80,q0,f,x,U,m)}var N0;var Q0=L(()=>{J0();t();l.DNS=B;l.URL=p;N0=l});function x1(f,x,U){f??={},U??=0;let m=o({...f,_v6:!0},new Uint8Array(16));if(m=z(m),x){for(let A=0;A<16;A++)x[U+A]=m[A];return x}return X(m)}var Y0;var T0=L(()=>{Q();w();r();Y0=x1});function v(f){let x=typeof f===\"string\"?N(f):f,U=U1(x);return typeof f===\"string\"?X(U):U}function U1(f){return Uint8Array.of((f[3]&15)<<4|f[4]>>4&15,(f[4]&15)<<4|(f[5]&240)>>4,(f[5]&15)<<4|f[6]&15,f[7],(f[1]&15)<<4|(f[2]&240)>>4,(f[2]&15)<<4|(f[3]&240)>>4,16|(f[0]&240)>>4,(f[0]&15)<<4|(f[1]&240)>>4,f[8],f[9],f[10],f[11],f[12],f[13],f[14],f[15])}var G0=L(()=>{F();Q()});function m1(f,x,U){let m;if(f)m=Z0(f.random??f.rng?.()??Y(),f.msecs,f.seq,x,U);else{let A=Date.now(),D=Y();A1(a,A,D),m=Z0(D,a.msecs,a.seq,x,U)}return x??X(m)}function A1(f,x,U){if(f.msecs??=-1/0,f.seq??=0,x>f.msecs)f.seq=U[6]<<23|U[7]<<16|U[8]<<8|U[9],f.msecs=x;else if(f.seq=f.seq+1|0,f.seq===0)f.msecs++;return f}function Z0(f,x,U,m,A=0){if(f.length<16)throw Error(\"Random bytes length must be >= 16\");if(!m)m=new Uint8Array(16),A=0;else if(A<0||A+16>m.length)throw RangeError(`UUID byte range ${A}:${A+15} is out of buffer bounds`);return x??=Date.now(),U??=f[6]*127<<24|f[7]<<16|f[8]<<8|f[9],m[A++]=x/1099511627776&255,m[A++]=x/4294967296&255,m[A++]=x/16777216&255,m[A++]=x/65536&255,m[A++]=x/256&255,m[A++]=x&255,m[A++]=112|U>>>28&15,m[A++]=U>>>20&255,m[A++]=128|U>>>14&63,m[A++]=U>>>6&255,m[A++]=U<<2&255|f[10]&3,m[A++]=f[11],m[A++]=f[12],m[A++]=f[13],m[A++]=f[14],m[A++]=f[15],m}var a,O0;var C0=L(()=>{b();Q();a={};O0=m1});function D1(f){if(!Z(f))throw TypeError(\"Invalid UUID\");return parseInt(f.slice(14,15),16)}var F0;var K0=L(()=>{C();F0=D1});var z0={};o0(z0,{version:()=>F0,validate:()=>Z,v7:()=>O0,v6ToV1:()=>v,v6:()=>Y0,v5:()=>N0,v4:()=>j0,v3:()=>_0,v1ToV6:()=>z,v1:()=>o,stringify:()=>R0,parse:()=>N,NIL:()=>D0,MAX:()=>A0});var P0=L(()=>{F();Q();w();r();I0();n0();Q0();T0();G0();C0();C();K0()});import{parentPort as W,workerData as k0}from\"worker_threads\";var S1=typeof crypto<\"u\"&&typeof crypto.randomUUID===\"function\",y=null;function V1(){if(S1)return crypto.randomUUID();if(y)return y();return y=(P0(),b0(z0)).v4,y()}class f0{buffer;offset=0;constructor(f=4096){this.buffer=Buffer.allocUnsafe(f)}ensureCapacity(f){let x=this.offset+f;if(x>this.buffer.length){let U=Math.max(this.buffer.length*2,x),m=Buffer.allocUnsafe(U);this.buffer.copy(m,0,0,this.offset),this.buffer=m}}reset(){this.offset=0}getBuffer(){return this.buffer.subarray(0,this.offset)}toBuffer(){return Buffer.from(this.buffer.subarray(0,this.offset))}writeInt8(f){this.ensureCapacity(1),this.buffer.writeInt8(f,this.offset),this.offset+=1}writeUInt8(f){this.ensureCapacity(1),this.buffer.writeUInt8(f,this.offset),this.offset+=1}writeInt16(f){this.ensureCapacity(2),this.buffer.writeInt16LE(f,this.offset),this.offset+=2}writeUInt16(f){this.ensureCapacity(2),this.buffer.writeUInt16LE(f,this.offset),this.offset+=2}writeInt32(f){this.ensureCapacity(4),this.buffer.writeInt32LE(f,this.offset),this.offset+=4}writeUInt32(f){this.ensureCapacity(4),this.buffer.writeUInt32LE(f,this.offset),this.offset+=4}writeInt64(f){this.ensureCapacity(8),this.buffer.writeBigInt64LE(BigInt(f),this.offset),this.offset+=8}writeUInt64(f){this.ensureCapacity(8),this.buffer.writeBigUInt64LE(BigInt(f),this.offset),this.offset+=8}writeInt128(f){this.ensureCapacity(16);let x=f&BigInt(\"0xFFFFFFFFFFFFFFFF\"),U=f>>BigInt(64);this.buffer.writeBigUInt64LE(x,this.offset),this.buffer.writeBigInt64LE(U,this.offset+8),this.offset+=16}writeUInt128(f){this.ensureCapacity(16);let x=f&BigInt(\"0xFFFFFFFFFFFFFFFF\"),U=f>>BigInt(64);this.buffer.writeBigUInt64LE(x,this.offset),this.buffer.writeBigUInt64LE(U,this.offset+8),this.offset+=16}writeInt256(f){this.ensureCapacity(32);for(let x=0;x<4;x++){let U=f&BigInt(\"0xFFFFFFFFFFFFFFFF\");this.buffer.writeBigUInt64LE(U,this.offset+x*8),f>>=BigInt(64)}this.offset+=32}writeUInt256(f){this.writeInt256(f)}writeFloat32(f){this.ensureCapacity(4),this.buffer.writeFloatLE(f,this.offset),this.offset+=4}writeFloat64(f){this.ensureCapacity(8),this.buffer.writeDoubleLE(f,this.offset),this.offset+=8}writeVarInt(f){if(f<128){this.ensureCapacity(1),this.buffer[this.offset++]=f;return}if(f<16384){this.ensureCapacity(2),this.buffer[this.offset++]=f&127|128,this.buffer[this.offset++]=f>>7;return}if(f<2097152){this.ensureCapacity(3),this.buffer[this.offset++]=f&127|128,this.buffer[this.offset++]=f>>7&127|128,this.buffer[this.offset++]=f>>14;return}this.ensureCapacity(10);while(f>=128)this.buffer[this.offset++]=f&127|128,f>>>=7;this.buffer[this.offset++]=f}writeString(f){let x=Buffer.from(f,\"utf-8\");this.writeVarInt(x.length),this.ensureCapacity(x.length),x.copy(this.buffer,this.offset),this.offset+=x.length}writeFixedString(f,x){this.ensureCapacity(x);let U=Buffer.from(f,\"utf-8\"),m=Math.min(U.length,x);if(U.copy(this.buffer,this.offset,0,m),m<x)this.buffer.fill(0,this.offset+m,this.offset+x);this.offset+=x}writeBytes(f){this.ensureCapacity(f.length),f.copy(this.buffer,this.offset),this.offset+=f.length}writeUUID(f){this.ensureCapacity(16);let x=f.replace(/-/g,\"\");if(x.length!==32)throw Error(`Invalid UUID: ${f}`);let U=Buffer.from(x,\"hex\");for(let m=7;m>=0;m--)this.buffer[this.offset++]=U[m];for(let m=15;m>=8;m--)this.buffer[this.offset++]=U[m]}writeDate(f){let x=typeof f===\"number\"?f:Math.floor(f.getTime()/86400000);this.writeUInt16(x)}writeDate32(f){let x=typeof f===\"number\"?f:Math.floor(f.getTime()/86400000);this.writeInt32(x)}writeDateTime(f){let x=typeof f===\"number\"?f:Math.floor(f.getTime()/1000);this.writeUInt32(x)}writeDateTime64(f,x=3){let U=Math.pow(10,x),m=typeof f===\"number\"?BigInt(Math.round(f*U)):BigInt(Math.round(f.getTime()*U/1000));this.writeInt64(m)}writeNullable(f){this.writeUInt8(f?1:0)}writeArrayLength(f){this.writeUInt64(f)}writeDecimal32(f,x){let U=Math.round(f*Math.pow(10,x));this.writeInt32(U)}writeDecimal64(f,x){let U=BigInt(Math.round(f*Math.pow(10,x)));this.writeInt64(U)}writeDecimal128(f,x){let U;if(typeof f===\"bigint\")U=f*BigInt(Math.pow(10,x));else U=BigInt(Math.round(f*Math.pow(10,x)));this.writeInt128(U)}writeBool(f){this.writeUInt8(f?1:0)}writeIPv4(f){if(typeof f===\"number\"){this.writeUInt32(f);return}let x=f.split(\".\").map(Number);if(x.length!==4)throw Error(`Invalid IPv4: ${f}`);let U=x[0]<<24|x[1]<<16|x[2]<<8|x[3];this.writeUInt32(U>>>0)}writeIPv6(f){if(Buffer.isBuffer(f)){if(f.length!==16)throw Error(\"IPv6 must be 16 bytes\");this.writeBytes(f);return}let U=this.expandIPv6(f).split(\":\");this.ensureCapacity(16);for(let m of U){let A=parseInt(m,16);this.buffer.writeUInt16BE(A,this.offset),this.offset+=2}}expandIPv6(f){let x=f.split(\"::\");if(x.length===1)return f;let U=x[0]?x[0].split(\":\"):[],m=x[1]?x[1].split(\":\"):[],A=8-U.length-m.length,D=Array(A).fill(\"0000\");return[...U,...D,...m].map((R)=>R.padStart(4,\"0\")).join(\":\")}writeEnum8(f){this.writeInt8(f)}writeEnum16(f){this.writeInt16(f)}}function e(f){let x=[],U=\"\",m=0;for(let A=0;A<f.length;A++){let D=f[A];if(D===\",\"&&m===0)x.push(U.trim()),U=\"\";else{if(D===\"(\")m++;if(D===\")\")m--;U+=D}}if(U.trim())x.push(U.trim());return x}function T(f,x=!1){let U=f.toLowerCase().trim(),m=U.match(/^nullable\\((.+)\\)$/);if(m){let V=T(m[1],!1);return(S,$)=>{if($===null||$===void 0)S.writeNullable(!0);else S.writeNullable(!1),V(S,$)}}let A=U.match(/^array\\((.+)\\)$/);if(A){let V=T(A[1],!1);return(S,$)=>{let J=Array.isArray($)?$:[];S.writeArrayLength(J.length);for(let j of J)V(S,j)}}let D=U.match(/^map\\((.+)\\)$/);if(D){let[V,S]=e(D[1]);if(!V||!S)throw Error(`Invalid Map type: ${U}`);let $=T(V),J=T(S);return(j,I)=>{let G;if(I instanceof Map)G=Array.from(I.entries());else if(typeof I===\"object\"&&I!==null)G=Object.entries(I);else G=[];j.writeUInt64(G.length);for(let[O,g]of G)$(j,O),J(j,g)}}let R=U.match(/^tuple\\((.+)\\)$/);if(R){let S=e(R[1]).map(($)=>T($));return($,J)=>{let j=Array.isArray(J)?J:[];for(let I=0;I<S.length;I++)S[I]($,j[I])}}let q=U.match(/^nested\\((.+)\\)$/);if(q){let V=e(q[1]),$=`Tuple(${V.map((j)=>{let I=j.trim().split(/\\s+/);if(I.length<2)return\"String\";return I.slice(1).join(\" \")}).join(\", \")})`,J=T($);return(j,I)=>{let G=Array.isArray(I)?I:[];j.writeArrayLength(G.length);for(let O of G){let g=O;if(!Array.isArray(O)&&typeof O===\"object\")g=V.map((W0)=>{let d0=W0.trim().split(/\\s+/)[0];return O[d0]});J(j,g)}}}let H=U.match(/^lowcardinality\\((.+)\\)$/);if(H)return T(H[1]);let n=U.match(/^fixedstring\\((\\d+)\\)$/);if(n){let V=parseInt(n[1],10);return(S,$)=>{S.writeFixedString(String($??\"\"),V)}}let x0=U.match(/^decimal(?:32|64|128)?\\((\\d+),\\s*(\\d+)\\)$/);if(x0){let V=parseInt(x0[2],10);if(U.includes(\"decimal128\"))return(S,$)=>S.writeDecimal128($,V);if(U.includes(\"decimal64\"))return(S,$)=>S.writeDecimal64($,V);return(S,$)=>S.writeDecimal32($,V)}let U0=U.match(/^datetime64\\((\\d+)/);if(U0){let V=parseInt(U0[1],10);return(S,$)=>S.writeDateTime64($,V)}if(U.match(/^enum8\\(/))return(V,S)=>V.writeEnum8(Number(S));if(U.match(/^enum16\\(/))return(V,S)=>V.writeEnum16(Number(S));let d=R1(U);if(x)return(V,S)=>{if(S===null||S===void 0)V.writeNullable(!0);else V.writeNullable(!1),d(V,S)};if(U===\"uuid\")return(V,S)=>{if(S===void 0||S===null)d(V,V1());else d(V,S)};return d}function R1(f){if(f===\"int8\")return(x,U)=>x.writeInt8(Number(U));if(f===\"uint8\")return(x,U)=>x.writeUInt8(Number(U));if(f===\"int16\")return(x,U)=>x.writeInt16(Number(U));if(f===\"uint16\")return(x,U)=>x.writeUInt16(Number(U));if(f===\"int32\")return(x,U)=>x.writeInt32(Number(U));if(f===\"uint32\")return(x,U)=>x.writeUInt32(Number(U));if(f===\"int64\")return(x,U)=>x.writeInt64(U);if(f===\"uint64\")return(x,U)=>x.writeUInt64(U);if(f===\"int128\")return(x,U)=>x.writeInt128(BigInt(U));if(f===\"uint128\")return(x,U)=>x.writeUInt128(BigInt(U));if(f===\"int256\")return(x,U)=>x.writeInt256(BigInt(U));if(f===\"uint256\")return(x,U)=>x.writeUInt256(BigInt(U));if(f===\"float32\")return(x,U)=>x.writeFloat32(Number(U));if(f===\"float64\")return(x,U)=>x.writeFloat64(Number(U));if(f===\"string\")return(x,U)=>x.writeString(String(U??\"\"));if(f===\"uuid\")return(x,U)=>x.writeUUID(String(U));if(f===\"date\")return(x,U)=>x.writeDate(U);if(f===\"date32\")return(x,U)=>x.writeDate32(U);if(f===\"datetime\")return(x,U)=>x.writeDateTime(U);if(f.startsWith(\"datetime64\"))return(x,U)=>x.writeDateTime64(U,3);if(f===\"bool\"||f===\"boolean\")return(x,U)=>x.writeBool(Boolean(U));if(f===\"ipv4\")return(x,U)=>x.writeIPv4(U);if(f===\"ipv6\")return(x,U)=>x.writeIPv6(U);return(x,U)=>x.writeString(String(U??\"\"))}var k=null,E=null;function $1(f,x){if(!k||!E)throw Error(\"Worker not configured\");E.reset();for(let U of f)for(let m=0;m<k.columns.length;m++){let A=k.columns[m],D=U[A.name];k.encoders[m](E,D)}return E.toBuffer()}function E0(f){try{switch(f.type){case\"configure\":{let x=f.columns.map((U)=>T(U.type,U.isNullable));k={columns:f.columns,keyMapping:new Map,encoders:x},E=new f0(1048576),W?.postMessage({type:\"ready\"});break}case\"serialize\":{let x=$1(f.rows,f.batchId),U=new ArrayBuffer(x.length);new Uint8Array(U).set(x),W?.postMessage({type:\"result\",batchId:f.batchId,buffer:Buffer.from(U),rowCount:f.rows.length},[U]);break}case\"shutdown\":process.exit(0)}}catch(x){W?.postMessage({type:\"error\",batchId:f.batchId,error:x instanceof Error?x.message:String(x)})}}if(W){if(W.on(\"message\",E0),k0?.columns)E0({type:\"configure\",columns:k0.columns})}\n";
|
|
@@ -63,12 +63,12 @@ export declare function getDefaultBinaryPool(columns?: ColumnConfig[]): Promise<
|
|
|
63
63
|
*/
|
|
64
64
|
export declare function shutdownDefaultBinaryPool(): Promise<void>;
|
|
65
65
|
/**
|
|
66
|
-
* Synchronous fallback serializer for environments without Worker support
|
|
66
|
+
* Synchronous fallback serializer for environments without Worker support.
|
|
67
|
+
* Uses object pooling for BinaryWriter instances.
|
|
67
68
|
*/
|
|
68
69
|
export declare class SyncBinarySerializer {
|
|
69
70
|
private encoders;
|
|
70
71
|
private columns;
|
|
71
|
-
private writer;
|
|
72
72
|
constructor(columns: ColumnConfig[]);
|
|
73
73
|
serialize(rows: Array<Record<string, any>>): Buffer;
|
|
74
74
|
serializeStream(rows: AsyncIterable<Record<string, any>> | Iterable<Record<string, any>>, batchSize?: number): AsyncGenerator<Buffer>;
|
|
@@ -16,8 +16,14 @@ export type InsertPlan = {
|
|
|
16
16
|
keyToColumn: Map<string, PreparedInsertColumn>;
|
|
17
17
|
columnNames: string[];
|
|
18
18
|
useCompact: boolean;
|
|
19
|
+
/** Skip enum validation for maximum performance */
|
|
20
|
+
skipValidation?: boolean;
|
|
19
21
|
};
|
|
20
|
-
export
|
|
22
|
+
export interface InsertPlanOptions {
|
|
23
|
+
/** Skip enum validation in production for better performance */
|
|
24
|
+
skipValidation?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function buildInsertPlan(table: TableRuntime<any, any>, options?: InsertPlanOptions): InsertPlan;
|
|
21
27
|
export declare function processRowWithPlan(row: Record<string, any>, plan: InsertPlan, mode?: 'compact' | 'json'): Record<string, any> | any[];
|
|
22
28
|
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
29
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@housekit/orm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.26",
|
|
4
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
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|