@@ -2,6 +2,30 @@ import type { Collection } from "./collection.ts"
2
2
import type { LargeCollection } from "./large_collection.ts"
3
3
import type { Document } from "./document.ts"
4
4
5
+ // Utility Types
6
+ export type CollectionBuilderFn = (
7
+ kv : Deno . Kv ,
8
+ key : KvKey ,
9
+ ) => Collection < KvValue , CollectionOptions < KvValue > >
10
+
11
+ export type CheckKeyOf < K , T > = K extends keyof T ? T [ K ] : never
12
+
13
+ export type KeysOfThatExtend < T1 , T2 > = keyof {
14
+ [ K in keyof T1 as T1 [ K ] extends T2 ? K : never ] : unknown
15
+ }
16
+
17
+ export type KeysOfThatDontExtend < T1 , T2 > = keyof {
18
+ [ K in keyof T1 as T1 [ K ] extends T2 ? never : K ] : unknown
19
+ }
20
+
21
+ export type CommitResult < T1 extends KvValue > = {
22
+ ok : true
23
+ versionstamp : Document < T1 > [ "versionstamp" ]
24
+ id : KvId
25
+ }
26
+
27
+ export type IdGenerator < T extends KvValue > = ( data : T ) => KvId
28
+
5
29
// Atomic Builder Types
6
30
export type CollectionSelector <
7
31
T1 extends Schema < SchemaDefinition > ,
@@ -68,8 +92,6 @@ export type AtomicSetOptions = NonNullable<
68
92
>
69
93
70
94
// Collection Types
71
- export type IdGenerator < T extends KvValue > = ( data : T ) => KvId
72
-
73
95
export type CollectionOptions < T extends KvValue > = {
74
96
/**
75
97
* Set a custom function for automatic id generation.
@@ -82,40 +104,6 @@ export type CollectionKeys = {
82
104
idKey : KvKey
83
105
}
84
106
85
- export type SetOptions = NonNullable < Parameters < Deno . Kv [ "set" ] > [ "2" ] > & {
86
- retry ?: number
87
- }
88
-
89
- export type ListOptions < T extends KvValue > = Deno . KvListOptions & {
90
- /**
91
- * Filter documents based on predicate.
92
- *
93
- * @param doc - Document
94
- * @returns true or false
95
- */
96
- filter ?: ( doc : Document < T > ) => boolean
97
-
98
- startId ?: KvId
99
-
100
- endId ?: KvId
101
- }
102
-
103
- export type CountOptions < T extends KvValue > =
104
- & CountAllOptions
105
- & Pick < ListOptions < T > , "filter" >
106
-
107
- export type FindOptions = NonNullable < Parameters < Deno . Kv [ "get" ] > [ 1 ] >
108
-
109
- export type FindManyOptions = NonNullable < Parameters < Deno . Kv [ "getMany" ] > [ 1 ] >
110
-
111
- export type UpdateManyOptions < T extends KvValue > = ListOptions < T > & SetOptions
112
-
113
- export type CommitResult < T1 extends KvValue > = {
114
- ok : true
115
- versionstamp : Document < T1 > [ "versionstamp" ]
116
- id : KvId
117
- }
118
-
119
107
// Indexable Collection Types
120
108
export type IndexableCollectionOptions < T extends Model > =
121
109
& CollectionOptions < T >
@@ -128,18 +116,8 @@ export type IndexableCollectionKeys = CollectionKeys & {
128
116
secondaryIndexKey : KvKey
129
117
}
130
118
131
- export type CheckKeyOf < K , T > = K extends keyof T ? T [ K ] : never
132
-
133
119
export type IndexType = "primary" | "secondary"
134
120
135
- export type KeysOfThatExtend < T1 , T2 > = keyof {
136
- [ K in keyof T1 as T1 [ K ] extends T2 ? K : never ] : unknown
137
- }
138
-
139
- export type KeysOfThatDontExtend < T1 , T2 > = keyof {
140
- [ K in keyof T1 as T1 [ K ] extends T2 ? never : K ] : unknown
141
- }
142
-
143
121
export type IndexRecord < T extends Model > = {
144
122
[ key in KeysOfThatExtend < T , KvId > ] ?: IndexType
145
123
}
@@ -167,12 +145,40 @@ export type LargeDocumentEntry = {
167
145
ids : KvId [ ]
168
146
}
169
147
170
- // DB Types
171
- export type CollectionBuilderFn = (
172
- kv : Deno . Kv ,
173
- key : KvKey ,
174
- ) => Collection < KvValue , CollectionOptions < KvValue > >
148
+ // Method Option types
149
+ export type SetOptions = NonNullable < Parameters < Deno . Kv [ "set" ] > [ "2" ] > & {
150
+ retry ?: number
151
+ }
175
152
153
+ export type ListOptions < T extends KvValue > = Deno . KvListOptions & {
154
+ /**
155
+ * Filter documents based on predicate.
156
+ *
157
+ * @param doc - Document
158
+ * @returns true or false
159
+ */
160
+ filter ?: ( doc : Document < T > ) => boolean
161
+
162
+ startId ?: KvId
163
+
164
+ endId ?: KvId
165
+ }
166
+
167
+ export type CountOptions < T extends KvValue > =
168
+ & CountAllOptions
169
+ & Pick < ListOptions < T > , "filter" >
170
+
171
+ export type FindOptions = NonNullable < Parameters < Deno . Kv [ "get" ] > [ 1 ] >
172
+
173
+ export type FindManyOptions = NonNullable < Parameters < Deno . Kv [ "getMany" ] > [ 1 ] >
174
+
175
+ export type UpdateManyOptions < T extends KvValue > = ListOptions < T > & SetOptions
176
+
177
+ export type CountAllOptions = Pick < Deno . KvListOptions , "consistency" >
178
+
179
+ export type DeleteAllOptions = Pick < Deno . KvListOptions , "consistency" >
180
+
181
+ // Schema Types
176
182
export type SchemaDefinition = {
177
183
[ key : string ] : SchemaDefinition | CollectionBuilderFn
178
184
}
@@ -183,10 +189,6 @@ export type Schema<T extends SchemaDefinition> = {
183
189
: never
184
190
}
185
191
186
- export type CountAllOptions = Pick < Deno . KvListOptions , "consistency" >
187
-
188
- export type DeleteAllOptions = Pick < Deno . KvListOptions , "consistency" >
189
-
190
192
// Queue Types
191
193
export type QueueMessage < T extends KvValue > = {
192
194
collectionKey : KvKey | null
@@ -226,7 +228,7 @@ export type PreparedEnqueue<T extends KvValue> = {
226
228
options : DenoKvEnqueueOptions
227
229
}
228
230
229
- // KV Types
231
+ // Data Types
230
232
export type UpdateData < T extends KvValue > = T extends KvObject ? Partial < T > : T
231
233
232
234
export type FlatDocumentData < T extends KvValue > =
@@ -243,6 +245,7 @@ export type DocumentData<T extends KvValue> = {
243
245
readonly value : T
244
246
}
245
247
248
+ // KV Types
246
249
export type KvVersionstamp < T extends KvValue > = Deno . KvEntry < T > [ "versionstamp" ]
247
250
248
251
export type KvKey = [ Deno . KvKeyPart , ...Deno . KvKey ]
0 commit comments