@push.rocks/smartdb 1.0.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.
- package/.smartconfig.json +38 -0
- package/dist_ts/00_commitinfo_data.d.ts +8 -0
- package/dist_ts/00_commitinfo_data.js +9 -0
- package/dist_ts/index.d.ts +5 -0
- package/dist_ts/index.js +8 -0
- package/dist_ts/ts_local/classes.localsmartdb.d.ts +78 -0
- package/dist_ts/ts_local/classes.localsmartdb.js +115 -0
- package/dist_ts/ts_local/index.d.ts +2 -0
- package/dist_ts/ts_local/index.js +2 -0
- package/dist_ts/ts_local/plugins.d.ts +2 -0
- package/dist_ts/ts_local/plugins.js +3 -0
- package/dist_ts/ts_smartdb/engine/AggregationEngine.d.ts +66 -0
- package/dist_ts/ts_smartdb/engine/AggregationEngine.js +189 -0
- package/dist_ts/ts_smartdb/engine/IndexEngine.d.ts +97 -0
- package/dist_ts/ts_smartdb/engine/IndexEngine.js +678 -0
- package/dist_ts/ts_smartdb/engine/QueryEngine.d.ts +54 -0
- package/dist_ts/ts_smartdb/engine/QueryEngine.js +271 -0
- package/dist_ts/ts_smartdb/engine/QueryPlanner.d.ts +64 -0
- package/dist_ts/ts_smartdb/engine/QueryPlanner.js +308 -0
- package/dist_ts/ts_smartdb/engine/SessionEngine.d.ts +117 -0
- package/dist_ts/ts_smartdb/engine/SessionEngine.js +232 -0
- package/dist_ts/ts_smartdb/engine/TransactionEngine.d.ts +85 -0
- package/dist_ts/ts_smartdb/engine/TransactionEngine.js +287 -0
- package/dist_ts/ts_smartdb/engine/UpdateEngine.d.ts +47 -0
- package/dist_ts/ts_smartdb/engine/UpdateEngine.js +461 -0
- package/dist_ts/ts_smartdb/errors/SmartdbErrors.d.ts +100 -0
- package/dist_ts/ts_smartdb/errors/SmartdbErrors.js +155 -0
- package/dist_ts/ts_smartdb/index.d.ts +26 -0
- package/dist_ts/ts_smartdb/index.js +31 -0
- package/dist_ts/ts_smartdb/plugins.d.ts +10 -0
- package/dist_ts/ts_smartdb/plugins.js +14 -0
- package/dist_ts/ts_smartdb/server/CommandRouter.d.ts +87 -0
- package/dist_ts/ts_smartdb/server/CommandRouter.js +222 -0
- package/dist_ts/ts_smartdb/server/SmartdbServer.d.ts +102 -0
- package/dist_ts/ts_smartdb/server/SmartdbServer.js +279 -0
- package/dist_ts/ts_smartdb/server/WireProtocol.d.ts +117 -0
- package/dist_ts/ts_smartdb/server/WireProtocol.js +298 -0
- package/dist_ts/ts_smartdb/server/handlers/AdminHandler.d.ts +100 -0
- package/dist_ts/ts_smartdb/server/handlers/AdminHandler.js +668 -0
- package/dist_ts/ts_smartdb/server/handlers/AggregateHandler.d.ts +31 -0
- package/dist_ts/ts_smartdb/server/handlers/AggregateHandler.js +277 -0
- package/dist_ts/ts_smartdb/server/handlers/DeleteHandler.d.ts +8 -0
- package/dist_ts/ts_smartdb/server/handlers/DeleteHandler.js +95 -0
- package/dist_ts/ts_smartdb/server/handlers/FindHandler.d.ts +31 -0
- package/dist_ts/ts_smartdb/server/handlers/FindHandler.js +291 -0
- package/dist_ts/ts_smartdb/server/handlers/HelloHandler.d.ts +11 -0
- package/dist_ts/ts_smartdb/server/handlers/HelloHandler.js +62 -0
- package/dist_ts/ts_smartdb/server/handlers/IndexHandler.d.ts +20 -0
- package/dist_ts/ts_smartdb/server/handlers/IndexHandler.js +183 -0
- package/dist_ts/ts_smartdb/server/handlers/InsertHandler.d.ts +8 -0
- package/dist_ts/ts_smartdb/server/handlers/InsertHandler.js +79 -0
- package/dist_ts/ts_smartdb/server/handlers/UpdateHandler.d.ts +24 -0
- package/dist_ts/ts_smartdb/server/handlers/UpdateHandler.js +296 -0
- package/dist_ts/ts_smartdb/server/handlers/index.d.ts +8 -0
- package/dist_ts/ts_smartdb/server/handlers/index.js +10 -0
- package/dist_ts/ts_smartdb/server/index.d.ts +6 -0
- package/dist_ts/ts_smartdb/server/index.js +7 -0
- package/dist_ts/ts_smartdb/storage/FileStorageAdapter.d.ts +85 -0
- package/dist_ts/ts_smartdb/storage/FileStorageAdapter.js +465 -0
- package/dist_ts/ts_smartdb/storage/IStorageAdapter.d.ts +145 -0
- package/dist_ts/ts_smartdb/storage/IStorageAdapter.js +2 -0
- package/dist_ts/ts_smartdb/storage/MemoryStorageAdapter.d.ts +67 -0
- package/dist_ts/ts_smartdb/storage/MemoryStorageAdapter.js +378 -0
- package/dist_ts/ts_smartdb/storage/OpLog.d.ts +93 -0
- package/dist_ts/ts_smartdb/storage/OpLog.js +221 -0
- package/dist_ts/ts_smartdb/storage/WAL.d.ts +117 -0
- package/dist_ts/ts_smartdb/storage/WAL.js +286 -0
- package/dist_ts/ts_smartdb/types/interfaces.d.ts +363 -0
- package/dist_ts/ts_smartdb/types/interfaces.js +2 -0
- package/dist_ts/ts_smartdb/utils/checksum.d.ts +30 -0
- package/dist_ts/ts_smartdb/utils/checksum.js +77 -0
- package/dist_ts/ts_smartdb/utils/index.d.ts +1 -0
- package/dist_ts/ts_smartdb/utils/index.js +2 -0
- package/license +19 -0
- package/package.json +69 -0
- package/readme.md +529 -0
- package/ts/00_commitinfo_data.ts +8 -0
- package/ts/index.ts +11 -0
- package/ts/ts_local/classes.localsmartdb.ts +143 -0
- package/ts/ts_local/index.ts +2 -0
- package/ts/ts_local/plugins.ts +3 -0
- package/ts/ts_smartdb/engine/AggregationEngine.ts +283 -0
- package/ts/ts_smartdb/engine/IndexEngine.ts +798 -0
- package/ts/ts_smartdb/engine/QueryEngine.ts +301 -0
- package/ts/ts_smartdb/engine/QueryPlanner.ts +393 -0
- package/ts/ts_smartdb/engine/SessionEngine.ts +292 -0
- package/ts/ts_smartdb/engine/TransactionEngine.ts +351 -0
- package/ts/ts_smartdb/engine/UpdateEngine.ts +506 -0
- package/ts/ts_smartdb/errors/SmartdbErrors.ts +181 -0
- package/ts/ts_smartdb/index.ts +46 -0
- package/ts/ts_smartdb/plugins.ts +17 -0
- package/ts/ts_smartdb/server/CommandRouter.ts +289 -0
- package/ts/ts_smartdb/server/SmartdbServer.ts +354 -0
- package/ts/ts_smartdb/server/WireProtocol.ts +416 -0
- package/ts/ts_smartdb/server/handlers/AdminHandler.ts +719 -0
- package/ts/ts_smartdb/server/handlers/AggregateHandler.ts +342 -0
- package/ts/ts_smartdb/server/handlers/DeleteHandler.ts +115 -0
- package/ts/ts_smartdb/server/handlers/FindHandler.ts +330 -0
- package/ts/ts_smartdb/server/handlers/HelloHandler.ts +78 -0
- package/ts/ts_smartdb/server/handlers/IndexHandler.ts +207 -0
- package/ts/ts_smartdb/server/handlers/InsertHandler.ts +97 -0
- package/ts/ts_smartdb/server/handlers/UpdateHandler.ts +344 -0
- package/ts/ts_smartdb/server/handlers/index.ts +10 -0
- package/ts/ts_smartdb/server/index.ts +10 -0
- package/ts/ts_smartdb/storage/FileStorageAdapter.ts +562 -0
- package/ts/ts_smartdb/storage/IStorageAdapter.ts +208 -0
- package/ts/ts_smartdb/storage/MemoryStorageAdapter.ts +455 -0
- package/ts/ts_smartdb/storage/OpLog.ts +282 -0
- package/ts/ts_smartdb/storage/WAL.ts +375 -0
- package/ts/ts_smartdb/types/interfaces.ts +433 -0
- package/ts/ts_smartdb/utils/checksum.ts +88 -0
- package/ts/ts_smartdb/utils/index.ts +1 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import type * as plugins from '../plugins.js';
|
|
2
|
+
export type Document = Record<string, any>;
|
|
3
|
+
export interface WithId<TSchema> {
|
|
4
|
+
_id: plugins.bson.ObjectId;
|
|
5
|
+
}
|
|
6
|
+
export interface ISmartdbClientOptions {
|
|
7
|
+
/** Storage adapter type: 'memory' or 'file' */
|
|
8
|
+
storageType?: 'memory' | 'file';
|
|
9
|
+
/** Path for file-based storage */
|
|
10
|
+
storagePath?: string;
|
|
11
|
+
/** Enable persistence for memory adapter */
|
|
12
|
+
persist?: boolean;
|
|
13
|
+
/** Path for persistence file when using memory adapter */
|
|
14
|
+
persistPath?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface IParsedConnectionString {
|
|
17
|
+
protocol: 'smartdb';
|
|
18
|
+
storageType: 'memory' | 'file';
|
|
19
|
+
options: {
|
|
20
|
+
persist?: string;
|
|
21
|
+
path?: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface IInsertOneOptions {
|
|
25
|
+
/** Session for transaction support */
|
|
26
|
+
session?: IClientSession;
|
|
27
|
+
/** Custom write concern */
|
|
28
|
+
writeConcern?: IWriteConcern;
|
|
29
|
+
}
|
|
30
|
+
export interface IInsertManyOptions extends IInsertOneOptions {
|
|
31
|
+
/** If true, inserts are ordered and stop on first error */
|
|
32
|
+
ordered?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface IFindOptions<TSchema = Document> {
|
|
35
|
+
/** Projection to apply */
|
|
36
|
+
projection?: Partial<Record<keyof TSchema | string, 0 | 1 | boolean>>;
|
|
37
|
+
/** Sort specification */
|
|
38
|
+
sort?: ISortSpecification;
|
|
39
|
+
/** Number of documents to skip */
|
|
40
|
+
skip?: number;
|
|
41
|
+
/** Maximum number of documents to return */
|
|
42
|
+
limit?: number;
|
|
43
|
+
/** Session for transaction support */
|
|
44
|
+
session?: IClientSession;
|
|
45
|
+
/** Hint for index usage */
|
|
46
|
+
hint?: string | Document;
|
|
47
|
+
}
|
|
48
|
+
export interface IUpdateOptions {
|
|
49
|
+
/** Create document if it doesn't exist */
|
|
50
|
+
upsert?: boolean;
|
|
51
|
+
/** Session for transaction support */
|
|
52
|
+
session?: IClientSession;
|
|
53
|
+
/** Array filters for positional updates */
|
|
54
|
+
arrayFilters?: Document[];
|
|
55
|
+
/** Custom write concern */
|
|
56
|
+
writeConcern?: IWriteConcern;
|
|
57
|
+
/** Hint for index usage */
|
|
58
|
+
hint?: string | Document;
|
|
59
|
+
}
|
|
60
|
+
export interface IReplaceOptions extends IUpdateOptions {
|
|
61
|
+
}
|
|
62
|
+
export interface IDeleteOptions {
|
|
63
|
+
/** Session for transaction support */
|
|
64
|
+
session?: IClientSession;
|
|
65
|
+
/** Custom write concern */
|
|
66
|
+
writeConcern?: IWriteConcern;
|
|
67
|
+
/** Hint for index usage */
|
|
68
|
+
hint?: string | Document;
|
|
69
|
+
}
|
|
70
|
+
export interface IFindOneAndUpdateOptions extends IUpdateOptions {
|
|
71
|
+
/** Return the document before or after the update */
|
|
72
|
+
returnDocument?: 'before' | 'after';
|
|
73
|
+
/** Projection to apply */
|
|
74
|
+
projection?: Document;
|
|
75
|
+
/** Sort specification to determine which document to modify */
|
|
76
|
+
sort?: ISortSpecification;
|
|
77
|
+
}
|
|
78
|
+
export interface IFindOneAndReplaceOptions extends IFindOneAndUpdateOptions {
|
|
79
|
+
}
|
|
80
|
+
export interface IFindOneAndDeleteOptions {
|
|
81
|
+
/** Projection to apply */
|
|
82
|
+
projection?: Document;
|
|
83
|
+
/** Sort specification to determine which document to delete */
|
|
84
|
+
sort?: ISortSpecification;
|
|
85
|
+
/** Session for transaction support */
|
|
86
|
+
session?: IClientSession;
|
|
87
|
+
}
|
|
88
|
+
export interface IInsertOneResult {
|
|
89
|
+
acknowledged: boolean;
|
|
90
|
+
insertedId: plugins.bson.ObjectId;
|
|
91
|
+
}
|
|
92
|
+
export interface IInsertManyResult {
|
|
93
|
+
acknowledged: boolean;
|
|
94
|
+
insertedCount: number;
|
|
95
|
+
insertedIds: Record<number, plugins.bson.ObjectId>;
|
|
96
|
+
}
|
|
97
|
+
export interface IUpdateResult {
|
|
98
|
+
acknowledged: boolean;
|
|
99
|
+
matchedCount: number;
|
|
100
|
+
modifiedCount: number;
|
|
101
|
+
upsertedCount: number;
|
|
102
|
+
upsertedId: plugins.bson.ObjectId | null;
|
|
103
|
+
}
|
|
104
|
+
export interface IDeleteResult {
|
|
105
|
+
acknowledged: boolean;
|
|
106
|
+
deletedCount: number;
|
|
107
|
+
}
|
|
108
|
+
export interface IModifyResult<TSchema> {
|
|
109
|
+
value: TSchema | null;
|
|
110
|
+
ok: 1 | 0;
|
|
111
|
+
lastErrorObject?: {
|
|
112
|
+
n: number;
|
|
113
|
+
updatedExisting?: boolean;
|
|
114
|
+
upserted?: plugins.bson.ObjectId;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export type ISortDirection = 1 | -1 | 'asc' | 'desc' | 'ascending' | 'descending';
|
|
118
|
+
export type ISortSpecification = Record<string, ISortDirection> | [string, ISortDirection][];
|
|
119
|
+
export interface IIndexSpecification {
|
|
120
|
+
key: Record<string, 1 | -1 | 'text' | '2dsphere'>;
|
|
121
|
+
name?: string;
|
|
122
|
+
unique?: boolean;
|
|
123
|
+
sparse?: boolean;
|
|
124
|
+
expireAfterSeconds?: number;
|
|
125
|
+
background?: boolean;
|
|
126
|
+
partialFilterExpression?: Document;
|
|
127
|
+
}
|
|
128
|
+
export interface IIndexInfo {
|
|
129
|
+
v: number;
|
|
130
|
+
key: Record<string, 1 | -1 | string>;
|
|
131
|
+
name: string;
|
|
132
|
+
unique?: boolean;
|
|
133
|
+
sparse?: boolean;
|
|
134
|
+
expireAfterSeconds?: number;
|
|
135
|
+
}
|
|
136
|
+
export interface ICreateIndexOptions {
|
|
137
|
+
unique?: boolean;
|
|
138
|
+
sparse?: boolean;
|
|
139
|
+
expireAfterSeconds?: number;
|
|
140
|
+
name?: string;
|
|
141
|
+
background?: boolean;
|
|
142
|
+
partialFilterExpression?: Document;
|
|
143
|
+
}
|
|
144
|
+
export interface IWriteConcern {
|
|
145
|
+
w?: number | 'majority';
|
|
146
|
+
j?: boolean;
|
|
147
|
+
wtimeout?: number;
|
|
148
|
+
}
|
|
149
|
+
export interface IAggregateOptions {
|
|
150
|
+
/** Allow disk use for large aggregations */
|
|
151
|
+
allowDiskUse?: boolean;
|
|
152
|
+
/** Maximum time in ms */
|
|
153
|
+
maxTimeMS?: number;
|
|
154
|
+
/** Session for transaction support */
|
|
155
|
+
session?: IClientSession;
|
|
156
|
+
/** Batch size for cursor */
|
|
157
|
+
batchSize?: number;
|
|
158
|
+
/** Collation settings */
|
|
159
|
+
collation?: ICollation;
|
|
160
|
+
/** Hint for index usage */
|
|
161
|
+
hint?: string | Document;
|
|
162
|
+
/** Comment for profiling */
|
|
163
|
+
comment?: string;
|
|
164
|
+
}
|
|
165
|
+
export interface ICollation {
|
|
166
|
+
locale: string;
|
|
167
|
+
caseLevel?: boolean;
|
|
168
|
+
caseFirst?: string;
|
|
169
|
+
strength?: number;
|
|
170
|
+
numericOrdering?: boolean;
|
|
171
|
+
alternate?: string;
|
|
172
|
+
maxVariable?: string;
|
|
173
|
+
backwards?: boolean;
|
|
174
|
+
}
|
|
175
|
+
export interface IChangeStreamOptions {
|
|
176
|
+
/** Resume after this token */
|
|
177
|
+
resumeAfter?: IResumeToken;
|
|
178
|
+
/** Start at this operation time */
|
|
179
|
+
startAtOperationTime?: plugins.bson.Timestamp;
|
|
180
|
+
/** Start after this token */
|
|
181
|
+
startAfter?: IResumeToken;
|
|
182
|
+
/** Full document lookup mode */
|
|
183
|
+
fullDocument?: 'default' | 'updateLookup' | 'whenAvailable' | 'required';
|
|
184
|
+
/** Full document before change */
|
|
185
|
+
fullDocumentBeforeChange?: 'off' | 'whenAvailable' | 'required';
|
|
186
|
+
/** Batch size */
|
|
187
|
+
batchSize?: number;
|
|
188
|
+
/** Maximum await time in ms */
|
|
189
|
+
maxAwaitTimeMS?: number;
|
|
190
|
+
}
|
|
191
|
+
export interface IResumeToken {
|
|
192
|
+
_data: string;
|
|
193
|
+
}
|
|
194
|
+
export type ChangeStreamOperationType = 'insert' | 'update' | 'replace' | 'delete' | 'drop' | 'rename' | 'dropDatabase' | 'invalidate';
|
|
195
|
+
export interface IChangeStreamDocument<TSchema = Document> {
|
|
196
|
+
_id: IResumeToken;
|
|
197
|
+
operationType: ChangeStreamOperationType;
|
|
198
|
+
fullDocument?: TSchema;
|
|
199
|
+
fullDocumentBeforeChange?: TSchema;
|
|
200
|
+
ns: {
|
|
201
|
+
db: string;
|
|
202
|
+
coll?: string;
|
|
203
|
+
};
|
|
204
|
+
documentKey?: {
|
|
205
|
+
_id: plugins.bson.ObjectId;
|
|
206
|
+
};
|
|
207
|
+
updateDescription?: {
|
|
208
|
+
updatedFields?: Document;
|
|
209
|
+
removedFields?: string[];
|
|
210
|
+
truncatedArrays?: Array<{
|
|
211
|
+
field: string;
|
|
212
|
+
newSize: number;
|
|
213
|
+
}>;
|
|
214
|
+
};
|
|
215
|
+
clusterTime?: plugins.bson.Timestamp;
|
|
216
|
+
txnNumber?: number;
|
|
217
|
+
lsid?: {
|
|
218
|
+
id: plugins.bson.Binary;
|
|
219
|
+
uid: plugins.bson.Binary;
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
export interface IClientSession {
|
|
223
|
+
id: {
|
|
224
|
+
id: plugins.bson.Binary;
|
|
225
|
+
};
|
|
226
|
+
inTransaction(): boolean;
|
|
227
|
+
startTransaction(options?: ITransactionOptions): void;
|
|
228
|
+
commitTransaction(): Promise<void>;
|
|
229
|
+
abortTransaction(): Promise<void>;
|
|
230
|
+
withTransaction<T>(fn: () => Promise<T>, options?: ITransactionOptions): Promise<T>;
|
|
231
|
+
endSession(): Promise<void>;
|
|
232
|
+
}
|
|
233
|
+
export interface ITransactionOptions {
|
|
234
|
+
readConcern?: IReadConcern;
|
|
235
|
+
writeConcern?: IWriteConcern;
|
|
236
|
+
readPreference?: string;
|
|
237
|
+
maxCommitTimeMS?: number;
|
|
238
|
+
}
|
|
239
|
+
export interface IReadConcern {
|
|
240
|
+
level: 'local' | 'available' | 'majority' | 'linearizable' | 'snapshot';
|
|
241
|
+
}
|
|
242
|
+
export interface IBulkWriteOptions {
|
|
243
|
+
ordered?: boolean;
|
|
244
|
+
session?: IClientSession;
|
|
245
|
+
writeConcern?: IWriteConcern;
|
|
246
|
+
}
|
|
247
|
+
export interface IBulkWriteOperation<TSchema = Document> {
|
|
248
|
+
insertOne?: {
|
|
249
|
+
document: TSchema;
|
|
250
|
+
};
|
|
251
|
+
updateOne?: {
|
|
252
|
+
filter: Document;
|
|
253
|
+
update: Document;
|
|
254
|
+
upsert?: boolean;
|
|
255
|
+
arrayFilters?: Document[];
|
|
256
|
+
hint?: Document | string;
|
|
257
|
+
};
|
|
258
|
+
updateMany?: {
|
|
259
|
+
filter: Document;
|
|
260
|
+
update: Document;
|
|
261
|
+
upsert?: boolean;
|
|
262
|
+
arrayFilters?: Document[];
|
|
263
|
+
hint?: Document | string;
|
|
264
|
+
};
|
|
265
|
+
replaceOne?: {
|
|
266
|
+
filter: Document;
|
|
267
|
+
replacement: TSchema;
|
|
268
|
+
upsert?: boolean;
|
|
269
|
+
hint?: Document | string;
|
|
270
|
+
};
|
|
271
|
+
deleteOne?: {
|
|
272
|
+
filter: Document;
|
|
273
|
+
hint?: Document | string;
|
|
274
|
+
};
|
|
275
|
+
deleteMany?: {
|
|
276
|
+
filter: Document;
|
|
277
|
+
hint?: Document | string;
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
export interface IBulkWriteResult {
|
|
281
|
+
acknowledged: boolean;
|
|
282
|
+
insertedCount: number;
|
|
283
|
+
matchedCount: number;
|
|
284
|
+
modifiedCount: number;
|
|
285
|
+
deletedCount: number;
|
|
286
|
+
upsertedCount: number;
|
|
287
|
+
insertedIds: Record<number, plugins.bson.ObjectId>;
|
|
288
|
+
upsertedIds: Record<number, plugins.bson.ObjectId>;
|
|
289
|
+
}
|
|
290
|
+
export interface IStoredDocument extends Document {
|
|
291
|
+
_id: plugins.bson.ObjectId;
|
|
292
|
+
}
|
|
293
|
+
export interface IOpLogEntry {
|
|
294
|
+
ts: plugins.bson.Timestamp;
|
|
295
|
+
op: 'i' | 'u' | 'd' | 'c' | 'n';
|
|
296
|
+
ns: string;
|
|
297
|
+
o: Document;
|
|
298
|
+
o2?: Document;
|
|
299
|
+
txnNumber?: number;
|
|
300
|
+
lsid?: {
|
|
301
|
+
id: plugins.bson.Binary;
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
export interface IDatabaseInfo {
|
|
305
|
+
name: string;
|
|
306
|
+
sizeOnDisk: number;
|
|
307
|
+
empty: boolean;
|
|
308
|
+
}
|
|
309
|
+
export interface ICollectionInfo {
|
|
310
|
+
name: string;
|
|
311
|
+
type: 'collection' | 'view';
|
|
312
|
+
options: Document;
|
|
313
|
+
info: {
|
|
314
|
+
readOnly: boolean;
|
|
315
|
+
uuid?: plugins.bson.Binary;
|
|
316
|
+
};
|
|
317
|
+
idIndex?: IIndexInfo;
|
|
318
|
+
}
|
|
319
|
+
export interface IServerStatus {
|
|
320
|
+
host: string;
|
|
321
|
+
version: string;
|
|
322
|
+
process: string;
|
|
323
|
+
pid: number;
|
|
324
|
+
uptime: number;
|
|
325
|
+
uptimeMillis: number;
|
|
326
|
+
uptimeEstimate: number;
|
|
327
|
+
localTime: Date;
|
|
328
|
+
mem: {
|
|
329
|
+
resident: number;
|
|
330
|
+
virtual: number;
|
|
331
|
+
};
|
|
332
|
+
connections: {
|
|
333
|
+
current: number;
|
|
334
|
+
available: number;
|
|
335
|
+
totalCreated: number;
|
|
336
|
+
};
|
|
337
|
+
ok: 1;
|
|
338
|
+
}
|
|
339
|
+
export interface ICollectionStats {
|
|
340
|
+
ns: string;
|
|
341
|
+
count: number;
|
|
342
|
+
size: number;
|
|
343
|
+
avgObjSize: number;
|
|
344
|
+
storageSize: number;
|
|
345
|
+
totalIndexSize: number;
|
|
346
|
+
indexSizes: Record<string, number>;
|
|
347
|
+
nindexes: number;
|
|
348
|
+
ok: 1;
|
|
349
|
+
}
|
|
350
|
+
export interface ICountDocumentsOptions {
|
|
351
|
+
skip?: number;
|
|
352
|
+
limit?: number;
|
|
353
|
+
session?: IClientSession;
|
|
354
|
+
hint?: string | Document;
|
|
355
|
+
maxTimeMS?: number;
|
|
356
|
+
}
|
|
357
|
+
export interface IEstimatedDocumentCountOptions {
|
|
358
|
+
maxTimeMS?: number;
|
|
359
|
+
}
|
|
360
|
+
export interface IDistinctOptions {
|
|
361
|
+
session?: IClientSession;
|
|
362
|
+
maxTimeMS?: number;
|
|
363
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CRC32 checksum utilities for data integrity
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Calculate CRC32 checksum for a string
|
|
6
|
+
*/
|
|
7
|
+
export declare function calculateCRC32(data: string): number;
|
|
8
|
+
/**
|
|
9
|
+
* Calculate CRC32 checksum for a Buffer
|
|
10
|
+
*/
|
|
11
|
+
export declare function calculateCRC32Buffer(data: Buffer): number;
|
|
12
|
+
/**
|
|
13
|
+
* Calculate checksum for a document (serialized as JSON)
|
|
14
|
+
*/
|
|
15
|
+
export declare function calculateDocumentChecksum(doc: Record<string, any>): number;
|
|
16
|
+
/**
|
|
17
|
+
* Add checksum to a document
|
|
18
|
+
*/
|
|
19
|
+
export declare function addChecksum<T extends Record<string, any>>(doc: T): T & {
|
|
20
|
+
_checksum: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Verify checksum of a document
|
|
24
|
+
* Returns true if checksum is valid or if document has no checksum
|
|
25
|
+
*/
|
|
26
|
+
export declare function verifyChecksum(doc: Record<string, any>): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Remove checksum from a document
|
|
29
|
+
*/
|
|
30
|
+
export declare function removeChecksum<T extends Record<string, any>>(doc: T): Omit<T, '_checksum'>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CRC32 checksum utilities for data integrity
|
|
3
|
+
*/
|
|
4
|
+
// CRC32 lookup table
|
|
5
|
+
const CRC32_TABLE = [];
|
|
6
|
+
// Initialize the CRC32 table
|
|
7
|
+
function initCRC32Table() {
|
|
8
|
+
if (CRC32_TABLE.length > 0)
|
|
9
|
+
return;
|
|
10
|
+
for (let i = 0; i < 256; i++) {
|
|
11
|
+
let crc = i;
|
|
12
|
+
for (let j = 0; j < 8; j++) {
|
|
13
|
+
crc = (crc & 1) ? (0xEDB88320 ^ (crc >>> 1)) : (crc >>> 1);
|
|
14
|
+
}
|
|
15
|
+
CRC32_TABLE[i] = crc >>> 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Calculate CRC32 checksum for a string
|
|
20
|
+
*/
|
|
21
|
+
export function calculateCRC32(data) {
|
|
22
|
+
initCRC32Table();
|
|
23
|
+
let crc = 0xFFFFFFFF;
|
|
24
|
+
for (let i = 0; i < data.length; i++) {
|
|
25
|
+
const byte = data.charCodeAt(i) & 0xFF;
|
|
26
|
+
crc = CRC32_TABLE[(crc ^ byte) & 0xFF] ^ (crc >>> 8);
|
|
27
|
+
}
|
|
28
|
+
return (~crc) >>> 0;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Calculate CRC32 checksum for a Buffer
|
|
32
|
+
*/
|
|
33
|
+
export function calculateCRC32Buffer(data) {
|
|
34
|
+
initCRC32Table();
|
|
35
|
+
let crc = 0xFFFFFFFF;
|
|
36
|
+
for (let i = 0; i < data.length; i++) {
|
|
37
|
+
crc = CRC32_TABLE[(crc ^ data[i]) & 0xFF] ^ (crc >>> 8);
|
|
38
|
+
}
|
|
39
|
+
return (~crc) >>> 0;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Calculate checksum for a document (serialized as JSON)
|
|
43
|
+
*/
|
|
44
|
+
export function calculateDocumentChecksum(doc) {
|
|
45
|
+
// Exclude _checksum field from calculation
|
|
46
|
+
const { _checksum, ...docWithoutChecksum } = doc;
|
|
47
|
+
const json = JSON.stringify(docWithoutChecksum);
|
|
48
|
+
return calculateCRC32(json);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Add checksum to a document
|
|
52
|
+
*/
|
|
53
|
+
export function addChecksum(doc) {
|
|
54
|
+
const checksum = calculateDocumentChecksum(doc);
|
|
55
|
+
return { ...doc, _checksum: checksum };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Verify checksum of a document
|
|
59
|
+
* Returns true if checksum is valid or if document has no checksum
|
|
60
|
+
*/
|
|
61
|
+
export function verifyChecksum(doc) {
|
|
62
|
+
if (!('_checksum' in doc)) {
|
|
63
|
+
// No checksum to verify
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
const storedChecksum = doc._checksum;
|
|
67
|
+
const calculatedChecksum = calculateDocumentChecksum(doc);
|
|
68
|
+
return storedChecksum === calculatedChecksum;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Remove checksum from a document
|
|
72
|
+
*/
|
|
73
|
+
export function removeChecksum(doc) {
|
|
74
|
+
const { _checksum, ...docWithoutChecksum } = doc;
|
|
75
|
+
return docWithoutChecksum;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hlY2tzdW0uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi90cy90c19zbWFydGRiL3V0aWxzL2NoZWNrc3VtLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBRUgscUJBQXFCO0FBQ3JCLE1BQU0sV0FBVyxHQUFhLEVBQUUsQ0FBQztBQUVqQyw2QkFBNkI7QUFDN0IsU0FBUyxjQUFjO0lBQ3JCLElBQUksV0FBVyxDQUFDLE1BQU0sR0FBRyxDQUFDO1FBQUUsT0FBTztJQUVuQyxLQUFLLElBQUksQ0FBQyxHQUFHLENBQUMsRUFBRSxDQUFDLEdBQUcsR0FBRyxFQUFFLENBQUMsRUFBRSxFQUFFLENBQUM7UUFDN0IsSUFBSSxHQUFHLEdBQUcsQ0FBQyxDQUFDO1FBQ1osS0FBSyxJQUFJLENBQUMsR0FBRyxDQUFDLEVBQUUsQ0FBQyxHQUFHLENBQUMsRUFBRSxDQUFDLEVBQUUsRUFBRSxDQUFDO1lBQzNCLEdBQUcsR0FBRyxDQUFDLEdBQUcsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxVQUFVLEdBQUcsQ0F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tCLENBQUM7QUFDL0MsQ0FBQztBQUVEOztHQUVHO0FBQ0gsTUFBTSxVQUFVLGNBQWMsQ0FBZ0MsR0FBTTtJQUNsRSxNQUFNLEVBQUUsU0FBUyxFQUFFLEdBQUcsa0JBQWtCLEVBQUUsR0FBRyxHQUFHLENBQUM7SUFDakQsT0FBTyxrQkFBMEMsQ0FBQztBQUNwRCxDQUFDIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './checksum.js';
|
package/license
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2021 Task Venture Capital GmbH (hello@task.vc)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@push.rocks/smartdb",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "A pure TypeScript MongoDB wire-protocol-compatible database server with pluggable storage, indexing, transactions, and zero external binary dependencies.",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist_ts/index.js"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"author": "Task Venture Capital GmbH",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "(tstest test/. --verbose --logfile --timeout 60)",
|
|
14
|
+
"build": "(tsbuild tsfolders)",
|
|
15
|
+
"buildDocs": "tsdoc"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@git.zone/tsbuild": "^4.4.0",
|
|
19
|
+
"@git.zone/tsbundle": "^2.10.0",
|
|
20
|
+
"@git.zone/tsrun": "^2.0.2",
|
|
21
|
+
"@git.zone/tstest": "^3.6.1",
|
|
22
|
+
"@types/node": "^25.5.0",
|
|
23
|
+
"mongodb": "^7.1.1"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@push.rocks/smartfs": "^1.5.0",
|
|
27
|
+
"@push.rocks/smartpath": "^6.0.0",
|
|
28
|
+
"@push.rocks/smartpromise": "^4.2.3",
|
|
29
|
+
"@push.rocks/smartrx": "^3.0.10",
|
|
30
|
+
"bson": "^7.2.0",
|
|
31
|
+
"mingo": "^7.2.0"
|
|
32
|
+
},
|
|
33
|
+
"browserslist": [
|
|
34
|
+
"last 1 chrome versions"
|
|
35
|
+
],
|
|
36
|
+
"files": [
|
|
37
|
+
"ts/**/*",
|
|
38
|
+
"ts_web/**/*",
|
|
39
|
+
"dist/**/*",
|
|
40
|
+
"dist_*/**/*",
|
|
41
|
+
"dist_ts/**/*",
|
|
42
|
+
"dist_ts_web/**/*",
|
|
43
|
+
"assets/**/*",
|
|
44
|
+
"cli.js",
|
|
45
|
+
".smartconfig.json",
|
|
46
|
+
"readme.md"
|
|
47
|
+
],
|
|
48
|
+
"keywords": [
|
|
49
|
+
"mongodb",
|
|
50
|
+
"wire protocol",
|
|
51
|
+
"typescript database",
|
|
52
|
+
"in-memory database",
|
|
53
|
+
"testing",
|
|
54
|
+
"local database",
|
|
55
|
+
"database server",
|
|
56
|
+
"typescript"
|
|
57
|
+
],
|
|
58
|
+
"homepage": "https://code.foss.global/push.rocks/smartdb#readme",
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "https://code.foss.global/push.rocks/smartdb.git"
|
|
62
|
+
},
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://code.foss.global/push.rocks/smartdb/issues"
|
|
65
|
+
},
|
|
66
|
+
"pnpm": {
|
|
67
|
+
"overrides": {}
|
|
68
|
+
}
|
|
69
|
+
}
|