imean-cassandra-orm 1.0.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/README.md +317 -0
- package/dist/mod.cjs +308 -0
- package/dist/mod.d.cts +279 -0
- package/dist/mod.d.ts +279 -0
- package/dist/mod.js +299 -0
- package/package.json +62 -0
package/dist/mod.d.cts
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { Client as Client$1 } from 'cassandra-driver';
|
|
2
|
+
|
|
3
|
+
type TypeMap = {
|
|
4
|
+
text: string;
|
|
5
|
+
int: number;
|
|
6
|
+
bigint: number;
|
|
7
|
+
varint: number;
|
|
8
|
+
boolean: boolean;
|
|
9
|
+
timestamp: Date;
|
|
10
|
+
uuid: string;
|
|
11
|
+
blob: Uint8Array;
|
|
12
|
+
decimal: number;
|
|
13
|
+
float: number;
|
|
14
|
+
double: number;
|
|
15
|
+
list: any[];
|
|
16
|
+
set: Set<any>;
|
|
17
|
+
map: Record<string, any>;
|
|
18
|
+
};
|
|
19
|
+
type InferType<T extends keyof TypeMap> = TypeMap[T];
|
|
20
|
+
type FieldConfig<T extends keyof TypeMap> = {
|
|
21
|
+
type: T;
|
|
22
|
+
flags: {
|
|
23
|
+
partitionKey: boolean;
|
|
24
|
+
clusteringKey: boolean | {
|
|
25
|
+
order: "ASC" | "DESC";
|
|
26
|
+
};
|
|
27
|
+
optional: boolean;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
declare class FieldBuilder<T extends keyof TypeMap, F extends {
|
|
31
|
+
partitionKey: boolean;
|
|
32
|
+
clusteringKey: boolean | {
|
|
33
|
+
order: "ASC" | "DESC";
|
|
34
|
+
};
|
|
35
|
+
optional: boolean;
|
|
36
|
+
} = {
|
|
37
|
+
partitionKey: false;
|
|
38
|
+
clusteringKey: false;
|
|
39
|
+
optional: false;
|
|
40
|
+
}> {
|
|
41
|
+
type: T;
|
|
42
|
+
flags: F;
|
|
43
|
+
constructor(type: T, flags?: F);
|
|
44
|
+
partitionKey(): FieldBuilder<T, Omit<F, "partitionKey"> & {
|
|
45
|
+
partitionKey: true;
|
|
46
|
+
}>;
|
|
47
|
+
clusteringKey(order?: "ASC" | "DESC"): FieldBuilder<T, Omit<F, "clusteringKey"> & {
|
|
48
|
+
clusteringKey: true | {
|
|
49
|
+
order: "ASC" | "DESC";
|
|
50
|
+
};
|
|
51
|
+
}>;
|
|
52
|
+
optional(): FieldBuilder<T, Omit<F, "optional"> & {
|
|
53
|
+
optional: true;
|
|
54
|
+
}>;
|
|
55
|
+
}
|
|
56
|
+
type InferFieldsByFlag<S extends Record<string, FieldConfig<keyof TypeMap>>, Flag extends "partitionKey" | "clusteringKey"> = {
|
|
57
|
+
[K in keyof S as S[K]["flags"][Flag] extends true | {
|
|
58
|
+
order: "ASC" | "DESC";
|
|
59
|
+
} ? K : never]: InferType<S[K]["type"]>;
|
|
60
|
+
};
|
|
61
|
+
type InferFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = {
|
|
62
|
+
[K in keyof S]: S[K]["flags"]["optional"] extends true ? InferType<S[K]["type"]> | undefined : InferType<S[K]["type"]>;
|
|
63
|
+
};
|
|
64
|
+
declare const Field: {
|
|
65
|
+
text: () => FieldBuilder<"text", {
|
|
66
|
+
partitionKey: false;
|
|
67
|
+
clusteringKey: false;
|
|
68
|
+
optional: false;
|
|
69
|
+
}>;
|
|
70
|
+
uuid: () => FieldBuilder<"uuid", {
|
|
71
|
+
partitionKey: false;
|
|
72
|
+
clusteringKey: false;
|
|
73
|
+
optional: false;
|
|
74
|
+
}>;
|
|
75
|
+
int: () => FieldBuilder<"int", {
|
|
76
|
+
partitionKey: false;
|
|
77
|
+
clusteringKey: false;
|
|
78
|
+
optional: false;
|
|
79
|
+
}>;
|
|
80
|
+
bigint: () => FieldBuilder<"bigint", {
|
|
81
|
+
partitionKey: false;
|
|
82
|
+
clusteringKey: false;
|
|
83
|
+
optional: false;
|
|
84
|
+
}>;
|
|
85
|
+
varint: () => FieldBuilder<"varint", {
|
|
86
|
+
partitionKey: false;
|
|
87
|
+
clusteringKey: false;
|
|
88
|
+
optional: false;
|
|
89
|
+
}>;
|
|
90
|
+
decimal: () => FieldBuilder<"decimal", {
|
|
91
|
+
partitionKey: false;
|
|
92
|
+
clusteringKey: false;
|
|
93
|
+
optional: false;
|
|
94
|
+
}>;
|
|
95
|
+
float: () => FieldBuilder<"float", {
|
|
96
|
+
partitionKey: false;
|
|
97
|
+
clusteringKey: false;
|
|
98
|
+
optional: false;
|
|
99
|
+
}>;
|
|
100
|
+
double: () => FieldBuilder<"double", {
|
|
101
|
+
partitionKey: false;
|
|
102
|
+
clusteringKey: false;
|
|
103
|
+
optional: false;
|
|
104
|
+
}>;
|
|
105
|
+
boolean: () => FieldBuilder<"boolean", {
|
|
106
|
+
partitionKey: false;
|
|
107
|
+
clusteringKey: false;
|
|
108
|
+
optional: false;
|
|
109
|
+
}>;
|
|
110
|
+
timestamp: () => FieldBuilder<"timestamp", {
|
|
111
|
+
partitionKey: false;
|
|
112
|
+
clusteringKey: false;
|
|
113
|
+
optional: false;
|
|
114
|
+
}>;
|
|
115
|
+
blob: () => FieldBuilder<"blob", {
|
|
116
|
+
partitionKey: false;
|
|
117
|
+
clusteringKey: false;
|
|
118
|
+
optional: false;
|
|
119
|
+
}>;
|
|
120
|
+
list: () => FieldBuilder<"list", {
|
|
121
|
+
partitionKey: false;
|
|
122
|
+
clusteringKey: false;
|
|
123
|
+
optional: false;
|
|
124
|
+
}>;
|
|
125
|
+
set: () => FieldBuilder<"set", {
|
|
126
|
+
partitionKey: false;
|
|
127
|
+
clusteringKey: false;
|
|
128
|
+
optional: false;
|
|
129
|
+
}>;
|
|
130
|
+
map: () => FieldBuilder<"map", {
|
|
131
|
+
partitionKey: false;
|
|
132
|
+
clusteringKey: false;
|
|
133
|
+
optional: false;
|
|
134
|
+
}>;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 从 Model 实例中推断出原始字段类型
|
|
139
|
+
*
|
|
140
|
+
* @typeParam M - 继承自 Model 的类型
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* class User extends Model<{
|
|
145
|
+
* id: { type: "uuid"; flags: { partitionKey: true } };
|
|
146
|
+
* name: { type: "text" };
|
|
147
|
+
* }> {}
|
|
148
|
+
*
|
|
149
|
+
* type UserType = Infer<User>;
|
|
150
|
+
* // { id: string; name: string }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
type Infer<M extends Model<any>> = M extends Model<infer S> ? InferFields<S> : never;
|
|
154
|
+
/**
|
|
155
|
+
* 推导分区键字段类型
|
|
156
|
+
*
|
|
157
|
+
* @typeParam M - 继承自 Model 的类型
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* class User extends Model<{
|
|
162
|
+
* id: { type: "uuid"; flags: { partitionKey: true } };
|
|
163
|
+
* name: { type: "text" };
|
|
164
|
+
* }> {}
|
|
165
|
+
*
|
|
166
|
+
* type UserPartitionKey = InferPartitionKey<User>;
|
|
167
|
+
* // { id: string }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
type InferPartitionKey<M extends Model<any>> = M extends Model<infer S> ? InferFieldsByFlag<S, "partitionKey"> : never;
|
|
171
|
+
/**
|
|
172
|
+
* 推导聚类键字段类型
|
|
173
|
+
*
|
|
174
|
+
* @typeParam M - 继承自 Model 的类型
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* class User extends Model<{
|
|
179
|
+
* id: { type: "uuid"; flags: { partitionKey: true } };
|
|
180
|
+
* name: { type: "text"; flags: { clusteringKey: true } };
|
|
181
|
+
* }> {}
|
|
182
|
+
*
|
|
183
|
+
* type UserClusteringKey = InferClusteringKey<User>;
|
|
184
|
+
* // { name: string }
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
type InferClusteringKey<M extends Model<any>> = M extends Model<infer S> ? InferFieldsByFlag<S, "clusteringKey"> : never;
|
|
188
|
+
/**
|
|
189
|
+
* 推导非分区键字段类型
|
|
190
|
+
*
|
|
191
|
+
* @typeParam S - 字段配置记录类型
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* type UserFields = {
|
|
196
|
+
* id: { type: "uuid"; flags: { partitionKey: true } };
|
|
197
|
+
* name: { type: "text" };
|
|
198
|
+
* age: { type: "int" };
|
|
199
|
+
* };
|
|
200
|
+
*
|
|
201
|
+
* type NonPartitionFields = InferNonPartitionFields<UserFields>;
|
|
202
|
+
* // { name: string; age: number }
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
type InferNonPartitionFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = {
|
|
206
|
+
[K in keyof S as S[K]["flags"]["partitionKey"] extends true ? never : K]: InferType<S[K]["type"]>;
|
|
207
|
+
};
|
|
208
|
+
type Simplify<T> = T extends infer U ? {
|
|
209
|
+
[K in keyof U]: U[K];
|
|
210
|
+
} : never;
|
|
211
|
+
|
|
212
|
+
declare class Model<S extends Record<string, FieldConfig<keyof TypeMap>>, P = InferFieldsByFlag<S, "partitionKey">, C = InferFieldsByFlag<S, "clusteringKey">, NP = InferNonPartitionFields<S>, A = InferFields<S>> {
|
|
213
|
+
private client;
|
|
214
|
+
private schema;
|
|
215
|
+
private tableName;
|
|
216
|
+
private partitionKeys;
|
|
217
|
+
private clusteringKeys;
|
|
218
|
+
constructor(client: Client$1, schema: S, tableName: string);
|
|
219
|
+
getTableSchema(): string;
|
|
220
|
+
syncSchema(): Promise<void>;
|
|
221
|
+
private buildWhereClause;
|
|
222
|
+
private buildQueryParams;
|
|
223
|
+
private convertResultToType;
|
|
224
|
+
findAll(partitionFields: Simplify<P>, clusteringFields?: Simplify<Partial<C>>): Promise<Simplify<A>[]>;
|
|
225
|
+
findOne(partitionFields: Simplify<P>, clusteringFields?: Simplify<Partial<C>>): Promise<Simplify<A> | null>;
|
|
226
|
+
create(data: Simplify<P & Partial<NP>>): Promise<void>;
|
|
227
|
+
update(partitionFields: Simplify<P>, data: Simplify<Partial<NP>>): Promise<void>;
|
|
228
|
+
delete(partitionFields: Simplify<P>, clusteringFields?: Simplify<Partial<C>>): Promise<void>;
|
|
229
|
+
}
|
|
230
|
+
declare const uuid: () => string;
|
|
231
|
+
|
|
232
|
+
declare class Client {
|
|
233
|
+
private cassandraClient;
|
|
234
|
+
private models;
|
|
235
|
+
constructor(cassandraClient: Client$1);
|
|
236
|
+
useKeyspace(keyspace: string, options: {
|
|
237
|
+
class: "SimpleStrategy" | "NetworkTopologyStrategy";
|
|
238
|
+
replication_factor?: number;
|
|
239
|
+
datacenters?: Record<string, number>;
|
|
240
|
+
}): Promise<void>;
|
|
241
|
+
createModel<S extends Record<string, FieldConfig<keyof TypeMap>>>(schema: S, tableName: string): Model<S>;
|
|
242
|
+
syncAllSchemas(): Promise<void>;
|
|
243
|
+
getRawClient(): Client$1;
|
|
244
|
+
close(): Promise<void>;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
type orm_Client = Client;
|
|
248
|
+
declare const orm_Client: typeof Client;
|
|
249
|
+
declare const orm_Field: typeof Field;
|
|
250
|
+
type orm_FieldBuilder<T extends keyof TypeMap, F extends {
|
|
251
|
+
partitionKey: boolean;
|
|
252
|
+
clusteringKey: boolean | {
|
|
253
|
+
order: "ASC" | "DESC";
|
|
254
|
+
};
|
|
255
|
+
optional: boolean;
|
|
256
|
+
} = {
|
|
257
|
+
partitionKey: false;
|
|
258
|
+
clusteringKey: false;
|
|
259
|
+
optional: false;
|
|
260
|
+
}> = FieldBuilder<T, F>;
|
|
261
|
+
declare const orm_FieldBuilder: typeof FieldBuilder;
|
|
262
|
+
type orm_FieldConfig<T extends keyof TypeMap> = FieldConfig<T>;
|
|
263
|
+
type orm_Infer<M extends Model<any>> = Infer<M>;
|
|
264
|
+
type orm_InferClusteringKey<M extends Model<any>> = InferClusteringKey<M>;
|
|
265
|
+
type orm_InferFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = InferFields<S>;
|
|
266
|
+
type orm_InferFieldsByFlag<S extends Record<string, FieldConfig<keyof TypeMap>>, Flag extends "partitionKey" | "clusteringKey"> = InferFieldsByFlag<S, Flag>;
|
|
267
|
+
type orm_InferNonPartitionFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = InferNonPartitionFields<S>;
|
|
268
|
+
type orm_InferPartitionKey<M extends Model<any>> = InferPartitionKey<M>;
|
|
269
|
+
type orm_InferType<T extends keyof TypeMap> = InferType<T>;
|
|
270
|
+
type orm_Model<S extends Record<string, FieldConfig<keyof TypeMap>>, P = InferFieldsByFlag<S, "partitionKey">, C = InferFieldsByFlag<S, "clusteringKey">, NP = InferNonPartitionFields<S>, A = InferFields<S>> = Model<S, P, C, NP, A>;
|
|
271
|
+
declare const orm_Model: typeof Model;
|
|
272
|
+
type orm_Simplify<T> = Simplify<T>;
|
|
273
|
+
type orm_TypeMap = TypeMap;
|
|
274
|
+
declare const orm_uuid: typeof uuid;
|
|
275
|
+
declare namespace orm {
|
|
276
|
+
export { orm_Client as Client, orm_Field as Field, orm_FieldBuilder as FieldBuilder, type orm_FieldConfig as FieldConfig, type orm_Infer as Infer, type orm_InferClusteringKey as InferClusteringKey, type orm_InferFields as InferFields, type orm_InferFieldsByFlag as InferFieldsByFlag, type orm_InferNonPartitionFields as InferNonPartitionFields, type orm_InferPartitionKey as InferPartitionKey, type orm_InferType as InferType, orm_Model as Model, type orm_Simplify as Simplify, type orm_TypeMap as TypeMap, orm_uuid as uuid };
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export { Client, Field, FieldBuilder, type FieldConfig, type Infer, type InferClusteringKey, type InferFields, type InferFieldsByFlag, type InferNonPartitionFields, type InferPartitionKey, type InferType, Model, type Simplify, type TypeMap, orm as default, uuid };
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { Client as Client$1 } from 'cassandra-driver';
|
|
2
|
+
|
|
3
|
+
type TypeMap = {
|
|
4
|
+
text: string;
|
|
5
|
+
int: number;
|
|
6
|
+
bigint: number;
|
|
7
|
+
varint: number;
|
|
8
|
+
boolean: boolean;
|
|
9
|
+
timestamp: Date;
|
|
10
|
+
uuid: string;
|
|
11
|
+
blob: Uint8Array;
|
|
12
|
+
decimal: number;
|
|
13
|
+
float: number;
|
|
14
|
+
double: number;
|
|
15
|
+
list: any[];
|
|
16
|
+
set: Set<any>;
|
|
17
|
+
map: Record<string, any>;
|
|
18
|
+
};
|
|
19
|
+
type InferType<T extends keyof TypeMap> = TypeMap[T];
|
|
20
|
+
type FieldConfig<T extends keyof TypeMap> = {
|
|
21
|
+
type: T;
|
|
22
|
+
flags: {
|
|
23
|
+
partitionKey: boolean;
|
|
24
|
+
clusteringKey: boolean | {
|
|
25
|
+
order: "ASC" | "DESC";
|
|
26
|
+
};
|
|
27
|
+
optional: boolean;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
declare class FieldBuilder<T extends keyof TypeMap, F extends {
|
|
31
|
+
partitionKey: boolean;
|
|
32
|
+
clusteringKey: boolean | {
|
|
33
|
+
order: "ASC" | "DESC";
|
|
34
|
+
};
|
|
35
|
+
optional: boolean;
|
|
36
|
+
} = {
|
|
37
|
+
partitionKey: false;
|
|
38
|
+
clusteringKey: false;
|
|
39
|
+
optional: false;
|
|
40
|
+
}> {
|
|
41
|
+
type: T;
|
|
42
|
+
flags: F;
|
|
43
|
+
constructor(type: T, flags?: F);
|
|
44
|
+
partitionKey(): FieldBuilder<T, Omit<F, "partitionKey"> & {
|
|
45
|
+
partitionKey: true;
|
|
46
|
+
}>;
|
|
47
|
+
clusteringKey(order?: "ASC" | "DESC"): FieldBuilder<T, Omit<F, "clusteringKey"> & {
|
|
48
|
+
clusteringKey: true | {
|
|
49
|
+
order: "ASC" | "DESC";
|
|
50
|
+
};
|
|
51
|
+
}>;
|
|
52
|
+
optional(): FieldBuilder<T, Omit<F, "optional"> & {
|
|
53
|
+
optional: true;
|
|
54
|
+
}>;
|
|
55
|
+
}
|
|
56
|
+
type InferFieldsByFlag<S extends Record<string, FieldConfig<keyof TypeMap>>, Flag extends "partitionKey" | "clusteringKey"> = {
|
|
57
|
+
[K in keyof S as S[K]["flags"][Flag] extends true | {
|
|
58
|
+
order: "ASC" | "DESC";
|
|
59
|
+
} ? K : never]: InferType<S[K]["type"]>;
|
|
60
|
+
};
|
|
61
|
+
type InferFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = {
|
|
62
|
+
[K in keyof S]: S[K]["flags"]["optional"] extends true ? InferType<S[K]["type"]> | undefined : InferType<S[K]["type"]>;
|
|
63
|
+
};
|
|
64
|
+
declare const Field: {
|
|
65
|
+
text: () => FieldBuilder<"text", {
|
|
66
|
+
partitionKey: false;
|
|
67
|
+
clusteringKey: false;
|
|
68
|
+
optional: false;
|
|
69
|
+
}>;
|
|
70
|
+
uuid: () => FieldBuilder<"uuid", {
|
|
71
|
+
partitionKey: false;
|
|
72
|
+
clusteringKey: false;
|
|
73
|
+
optional: false;
|
|
74
|
+
}>;
|
|
75
|
+
int: () => FieldBuilder<"int", {
|
|
76
|
+
partitionKey: false;
|
|
77
|
+
clusteringKey: false;
|
|
78
|
+
optional: false;
|
|
79
|
+
}>;
|
|
80
|
+
bigint: () => FieldBuilder<"bigint", {
|
|
81
|
+
partitionKey: false;
|
|
82
|
+
clusteringKey: false;
|
|
83
|
+
optional: false;
|
|
84
|
+
}>;
|
|
85
|
+
varint: () => FieldBuilder<"varint", {
|
|
86
|
+
partitionKey: false;
|
|
87
|
+
clusteringKey: false;
|
|
88
|
+
optional: false;
|
|
89
|
+
}>;
|
|
90
|
+
decimal: () => FieldBuilder<"decimal", {
|
|
91
|
+
partitionKey: false;
|
|
92
|
+
clusteringKey: false;
|
|
93
|
+
optional: false;
|
|
94
|
+
}>;
|
|
95
|
+
float: () => FieldBuilder<"float", {
|
|
96
|
+
partitionKey: false;
|
|
97
|
+
clusteringKey: false;
|
|
98
|
+
optional: false;
|
|
99
|
+
}>;
|
|
100
|
+
double: () => FieldBuilder<"double", {
|
|
101
|
+
partitionKey: false;
|
|
102
|
+
clusteringKey: false;
|
|
103
|
+
optional: false;
|
|
104
|
+
}>;
|
|
105
|
+
boolean: () => FieldBuilder<"boolean", {
|
|
106
|
+
partitionKey: false;
|
|
107
|
+
clusteringKey: false;
|
|
108
|
+
optional: false;
|
|
109
|
+
}>;
|
|
110
|
+
timestamp: () => FieldBuilder<"timestamp", {
|
|
111
|
+
partitionKey: false;
|
|
112
|
+
clusteringKey: false;
|
|
113
|
+
optional: false;
|
|
114
|
+
}>;
|
|
115
|
+
blob: () => FieldBuilder<"blob", {
|
|
116
|
+
partitionKey: false;
|
|
117
|
+
clusteringKey: false;
|
|
118
|
+
optional: false;
|
|
119
|
+
}>;
|
|
120
|
+
list: () => FieldBuilder<"list", {
|
|
121
|
+
partitionKey: false;
|
|
122
|
+
clusteringKey: false;
|
|
123
|
+
optional: false;
|
|
124
|
+
}>;
|
|
125
|
+
set: () => FieldBuilder<"set", {
|
|
126
|
+
partitionKey: false;
|
|
127
|
+
clusteringKey: false;
|
|
128
|
+
optional: false;
|
|
129
|
+
}>;
|
|
130
|
+
map: () => FieldBuilder<"map", {
|
|
131
|
+
partitionKey: false;
|
|
132
|
+
clusteringKey: false;
|
|
133
|
+
optional: false;
|
|
134
|
+
}>;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 从 Model 实例中推断出原始字段类型
|
|
139
|
+
*
|
|
140
|
+
* @typeParam M - 继承自 Model 的类型
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* class User extends Model<{
|
|
145
|
+
* id: { type: "uuid"; flags: { partitionKey: true } };
|
|
146
|
+
* name: { type: "text" };
|
|
147
|
+
* }> {}
|
|
148
|
+
*
|
|
149
|
+
* type UserType = Infer<User>;
|
|
150
|
+
* // { id: string; name: string }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
type Infer<M extends Model<any>> = M extends Model<infer S> ? InferFields<S> : never;
|
|
154
|
+
/**
|
|
155
|
+
* 推导分区键字段类型
|
|
156
|
+
*
|
|
157
|
+
* @typeParam M - 继承自 Model 的类型
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* class User extends Model<{
|
|
162
|
+
* id: { type: "uuid"; flags: { partitionKey: true } };
|
|
163
|
+
* name: { type: "text" };
|
|
164
|
+
* }> {}
|
|
165
|
+
*
|
|
166
|
+
* type UserPartitionKey = InferPartitionKey<User>;
|
|
167
|
+
* // { id: string }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
type InferPartitionKey<M extends Model<any>> = M extends Model<infer S> ? InferFieldsByFlag<S, "partitionKey"> : never;
|
|
171
|
+
/**
|
|
172
|
+
* 推导聚类键字段类型
|
|
173
|
+
*
|
|
174
|
+
* @typeParam M - 继承自 Model 的类型
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* class User extends Model<{
|
|
179
|
+
* id: { type: "uuid"; flags: { partitionKey: true } };
|
|
180
|
+
* name: { type: "text"; flags: { clusteringKey: true } };
|
|
181
|
+
* }> {}
|
|
182
|
+
*
|
|
183
|
+
* type UserClusteringKey = InferClusteringKey<User>;
|
|
184
|
+
* // { name: string }
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
type InferClusteringKey<M extends Model<any>> = M extends Model<infer S> ? InferFieldsByFlag<S, "clusteringKey"> : never;
|
|
188
|
+
/**
|
|
189
|
+
* 推导非分区键字段类型
|
|
190
|
+
*
|
|
191
|
+
* @typeParam S - 字段配置记录类型
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* type UserFields = {
|
|
196
|
+
* id: { type: "uuid"; flags: { partitionKey: true } };
|
|
197
|
+
* name: { type: "text" };
|
|
198
|
+
* age: { type: "int" };
|
|
199
|
+
* };
|
|
200
|
+
*
|
|
201
|
+
* type NonPartitionFields = InferNonPartitionFields<UserFields>;
|
|
202
|
+
* // { name: string; age: number }
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
type InferNonPartitionFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = {
|
|
206
|
+
[K in keyof S as S[K]["flags"]["partitionKey"] extends true ? never : K]: InferType<S[K]["type"]>;
|
|
207
|
+
};
|
|
208
|
+
type Simplify<T> = T extends infer U ? {
|
|
209
|
+
[K in keyof U]: U[K];
|
|
210
|
+
} : never;
|
|
211
|
+
|
|
212
|
+
declare class Model<S extends Record<string, FieldConfig<keyof TypeMap>>, P = InferFieldsByFlag<S, "partitionKey">, C = InferFieldsByFlag<S, "clusteringKey">, NP = InferNonPartitionFields<S>, A = InferFields<S>> {
|
|
213
|
+
private client;
|
|
214
|
+
private schema;
|
|
215
|
+
private tableName;
|
|
216
|
+
private partitionKeys;
|
|
217
|
+
private clusteringKeys;
|
|
218
|
+
constructor(client: Client$1, schema: S, tableName: string);
|
|
219
|
+
getTableSchema(): string;
|
|
220
|
+
syncSchema(): Promise<void>;
|
|
221
|
+
private buildWhereClause;
|
|
222
|
+
private buildQueryParams;
|
|
223
|
+
private convertResultToType;
|
|
224
|
+
findAll(partitionFields: Simplify<P>, clusteringFields?: Simplify<Partial<C>>): Promise<Simplify<A>[]>;
|
|
225
|
+
findOne(partitionFields: Simplify<P>, clusteringFields?: Simplify<Partial<C>>): Promise<Simplify<A> | null>;
|
|
226
|
+
create(data: Simplify<P & Partial<NP>>): Promise<void>;
|
|
227
|
+
update(partitionFields: Simplify<P>, data: Simplify<Partial<NP>>): Promise<void>;
|
|
228
|
+
delete(partitionFields: Simplify<P>, clusteringFields?: Simplify<Partial<C>>): Promise<void>;
|
|
229
|
+
}
|
|
230
|
+
declare const uuid: () => string;
|
|
231
|
+
|
|
232
|
+
declare class Client {
|
|
233
|
+
private cassandraClient;
|
|
234
|
+
private models;
|
|
235
|
+
constructor(cassandraClient: Client$1);
|
|
236
|
+
useKeyspace(keyspace: string, options: {
|
|
237
|
+
class: "SimpleStrategy" | "NetworkTopologyStrategy";
|
|
238
|
+
replication_factor?: number;
|
|
239
|
+
datacenters?: Record<string, number>;
|
|
240
|
+
}): Promise<void>;
|
|
241
|
+
createModel<S extends Record<string, FieldConfig<keyof TypeMap>>>(schema: S, tableName: string): Model<S>;
|
|
242
|
+
syncAllSchemas(): Promise<void>;
|
|
243
|
+
getRawClient(): Client$1;
|
|
244
|
+
close(): Promise<void>;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
type orm_Client = Client;
|
|
248
|
+
declare const orm_Client: typeof Client;
|
|
249
|
+
declare const orm_Field: typeof Field;
|
|
250
|
+
type orm_FieldBuilder<T extends keyof TypeMap, F extends {
|
|
251
|
+
partitionKey: boolean;
|
|
252
|
+
clusteringKey: boolean | {
|
|
253
|
+
order: "ASC" | "DESC";
|
|
254
|
+
};
|
|
255
|
+
optional: boolean;
|
|
256
|
+
} = {
|
|
257
|
+
partitionKey: false;
|
|
258
|
+
clusteringKey: false;
|
|
259
|
+
optional: false;
|
|
260
|
+
}> = FieldBuilder<T, F>;
|
|
261
|
+
declare const orm_FieldBuilder: typeof FieldBuilder;
|
|
262
|
+
type orm_FieldConfig<T extends keyof TypeMap> = FieldConfig<T>;
|
|
263
|
+
type orm_Infer<M extends Model<any>> = Infer<M>;
|
|
264
|
+
type orm_InferClusteringKey<M extends Model<any>> = InferClusteringKey<M>;
|
|
265
|
+
type orm_InferFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = InferFields<S>;
|
|
266
|
+
type orm_InferFieldsByFlag<S extends Record<string, FieldConfig<keyof TypeMap>>, Flag extends "partitionKey" | "clusteringKey"> = InferFieldsByFlag<S, Flag>;
|
|
267
|
+
type orm_InferNonPartitionFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = InferNonPartitionFields<S>;
|
|
268
|
+
type orm_InferPartitionKey<M extends Model<any>> = InferPartitionKey<M>;
|
|
269
|
+
type orm_InferType<T extends keyof TypeMap> = InferType<T>;
|
|
270
|
+
type orm_Model<S extends Record<string, FieldConfig<keyof TypeMap>>, P = InferFieldsByFlag<S, "partitionKey">, C = InferFieldsByFlag<S, "clusteringKey">, NP = InferNonPartitionFields<S>, A = InferFields<S>> = Model<S, P, C, NP, A>;
|
|
271
|
+
declare const orm_Model: typeof Model;
|
|
272
|
+
type orm_Simplify<T> = Simplify<T>;
|
|
273
|
+
type orm_TypeMap = TypeMap;
|
|
274
|
+
declare const orm_uuid: typeof uuid;
|
|
275
|
+
declare namespace orm {
|
|
276
|
+
export { orm_Client as Client, orm_Field as Field, orm_FieldBuilder as FieldBuilder, type orm_FieldConfig as FieldConfig, type orm_Infer as Infer, type orm_InferClusteringKey as InferClusteringKey, type orm_InferFields as InferFields, type orm_InferFieldsByFlag as InferFieldsByFlag, type orm_InferNonPartitionFields as InferNonPartitionFields, type orm_InferPartitionKey as InferPartitionKey, type orm_InferType as InferType, orm_Model as Model, type orm_Simplify as Simplify, type orm_TypeMap as TypeMap, orm_uuid as uuid };
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export { Client, Field, FieldBuilder, type FieldConfig, type Infer, type InferClusteringKey, type InferFields, type InferFieldsByFlag, type InferNonPartitionFields, type InferPartitionKey, type InferType, Model, type Simplify, type TypeMap, orm as default, uuid };
|