@type-map-for/clickhouse 0.1.0
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/dist/index.d.ts +10 -0
- package/package.json +22 -0
- package/src/index.ts +30 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type ChBaseType<T> = NonNullable<T> extends string ? 'String' : NonNullable<T> extends number ? 'Int32' | 'Float64' : NonNullable<T> extends boolean ? 'Bool' : 'JSON';
|
|
2
|
+
export type ChType<T> = NonNullable<T> extends (infer U)[] ? `Array(${ChBaseType<NonNullable<U>>})` : undefined extends T ? `Nullable(${ChBaseType<T>})` : ChBaseType<T>;
|
|
3
|
+
export type ClickHouseField<T, K extends keyof T> = {
|
|
4
|
+
name: K;
|
|
5
|
+
type: ChType<T[K]>;
|
|
6
|
+
};
|
|
7
|
+
export type ClickHouseSchema<T> = Array<{
|
|
8
|
+
[K in keyof T]-?: ClickHouseField<T, K>;
|
|
9
|
+
}[keyof T]>;
|
|
10
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@type-map-for/clickhouse",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Compile-time TypeScript → ClickHouse field mapping",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Nathan Frenette",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": { "types": "./dist/index.d.ts" }
|
|
10
|
+
},
|
|
11
|
+
"files": ["dist", "src"],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc -p tsconfig.json"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": { "access": "public" },
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@type-map-for/core": "*"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "*"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* ------------------------------------------------------------------ *
|
|
2
|
+
* @type-map-for/clickhouse *
|
|
3
|
+
* *
|
|
4
|
+
* - Output shape: Array<{ name, type }> *
|
|
5
|
+
* - Arrays: Array(T) — template literal type *
|
|
6
|
+
* - Optional: Nullable(T) — template literal type *
|
|
7
|
+
* - Required: plain type string, e.g. 'String' *
|
|
8
|
+
* ------------------------------------------------------------------ */
|
|
9
|
+
|
|
10
|
+
type ChBaseType<T> =
|
|
11
|
+
NonNullable<T> extends string ? 'String'
|
|
12
|
+
: NonNullable<T> extends number ? 'Int32' | 'Float64'
|
|
13
|
+
: NonNullable<T> extends boolean ? 'Bool'
|
|
14
|
+
: 'JSON';
|
|
15
|
+
|
|
16
|
+
export type ChType<T> =
|
|
17
|
+
NonNullable<T> extends (infer U)[]
|
|
18
|
+
? `Array(${ChBaseType<NonNullable<U>>})`
|
|
19
|
+
: undefined extends T
|
|
20
|
+
? `Nullable(${ChBaseType<T>})`
|
|
21
|
+
: ChBaseType<T>;
|
|
22
|
+
|
|
23
|
+
export type ClickHouseField<T, K extends keyof T> = {
|
|
24
|
+
name: K;
|
|
25
|
+
type: ChType<T[K]>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type ClickHouseSchema<T> = Array<{
|
|
29
|
+
[K in keyof T]-?: ClickHouseField<T, K>
|
|
30
|
+
}[keyof T]>;
|