@modelence/react-query 1.0.1 → 1.2.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/.yalc/modelence/README.md +86 -0
- package/.yalc/modelence/dist/bin/modelence.js +5 -0
- package/.yalc/modelence/dist/bin/modelence.js.map +1 -0
- package/.yalc/modelence/dist/chunk-3S2FFBNS.js +2 -0
- package/.yalc/modelence/dist/chunk-3S2FFBNS.js.map +1 -0
- package/.yalc/modelence/dist/chunk-3YAV3UUU.js +3 -0
- package/.yalc/modelence/dist/chunk-3YAV3UUU.js.map +1 -0
- package/.yalc/modelence/dist/chunk-55J6XMHW.js +2 -0
- package/.yalc/modelence/dist/chunk-55J6XMHW.js.map +1 -0
- package/.yalc/modelence/dist/chunk-C3UESBRX.js +2 -0
- package/.yalc/modelence/dist/chunk-C3UESBRX.js.map +1 -0
- package/.yalc/modelence/dist/chunk-DO5TZLF5.js +2 -0
- package/.yalc/modelence/dist/chunk-DO5TZLF5.js.map +1 -0
- package/.yalc/modelence/dist/chunk-DVECB2TP.js +3 -0
- package/.yalc/modelence/dist/chunk-DVECB2TP.js.map +1 -0
- package/.yalc/modelence/dist/client.d.ts +135 -0
- package/.yalc/modelence/dist/client.js +2 -0
- package/.yalc/modelence/dist/client.js.map +1 -0
- package/.yalc/modelence/dist/index-CwdohC5n.d.ts +15 -0
- package/.yalc/modelence/dist/index.d.ts +31 -0
- package/.yalc/modelence/dist/index.js +2 -0
- package/.yalc/modelence/dist/index.js.map +1 -0
- package/.yalc/modelence/dist/mongo.d.ts +5 -0
- package/.yalc/modelence/dist/mongo.js +2 -0
- package/.yalc/modelence/dist/mongo.js.map +1 -0
- package/.yalc/modelence/dist/package-3YQBVIVQ.js +2 -0
- package/.yalc/modelence/dist/package-3YQBVIVQ.js.map +1 -0
- package/.yalc/modelence/dist/server.d.ts +569 -0
- package/.yalc/modelence/dist/server.js +19 -0
- package/.yalc/modelence/dist/server.js.map +1 -0
- package/.yalc/modelence/dist/telemetry.d.ts +11 -0
- package/.yalc/modelence/dist/telemetry.js +2 -0
- package/.yalc/modelence/dist/telemetry.js.map +1 -0
- package/.yalc/modelence/dist/types-Ds1ESQSs.d.ts +106 -0
- package/.yalc/modelence/dist/types-WgRbQ-tj.d.ts +645 -0
- package/.yalc/modelence/dist/types.d.ts +7 -0
- package/.yalc/modelence/dist/types.js +2 -0
- package/.yalc/modelence/dist/types.js.map +1 -0
- package/.yalc/modelence/package.json +80 -0
- package/.yalc/modelence/yalc.sig +1 -0
- package/dist/index.d.ts +68 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +158 -1
- package/yalc.lock +10 -0
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
import './index-CwdohC5n.js';
|
|
2
|
+
import { P as Permission, d as Session, e as UserInfo } from './types-Ds1ESQSs.js';
|
|
3
|
+
import * as mongodb from 'mongodb';
|
|
4
|
+
import { WithId, IndexDescription, SearchIndexDescription, MongoClient, Collection, FilterOperators, Document, FindOptions, ObjectId, OptionalUnlessRequiredId, InsertOneResult, InsertManyResult, UpdateFilter, UpdateResult, ClientSession, DeleteResult, AggregateOptions, AggregationCursor, AnyBulkWriteOperation, BulkWriteResult } from 'mongodb';
|
|
5
|
+
import { z, ZodNumber, ZodArray } from 'zod';
|
|
6
|
+
import { Request, Response, NextFunction } from 'express';
|
|
7
|
+
|
|
8
|
+
type EmailAttachment = {
|
|
9
|
+
filename: string;
|
|
10
|
+
content: Buffer | string;
|
|
11
|
+
contentType: string;
|
|
12
|
+
};
|
|
13
|
+
type EmailPayload = {
|
|
14
|
+
from: string;
|
|
15
|
+
to: string | string[];
|
|
16
|
+
subject: string;
|
|
17
|
+
html?: string;
|
|
18
|
+
text?: string;
|
|
19
|
+
cc?: string | string[];
|
|
20
|
+
bcc?: string | string[];
|
|
21
|
+
replyTo?: string | string[];
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
attachments?: EmailAttachment[];
|
|
24
|
+
} & ({
|
|
25
|
+
html: string;
|
|
26
|
+
} | {
|
|
27
|
+
text: string;
|
|
28
|
+
});
|
|
29
|
+
interface EmailProvider {
|
|
30
|
+
sendEmail(data: EmailPayload): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type ClientInfo = {
|
|
34
|
+
screenWidth: number;
|
|
35
|
+
screenHeight: number;
|
|
36
|
+
windowWidth: number;
|
|
37
|
+
windowHeight: number;
|
|
38
|
+
pixelRatio: number;
|
|
39
|
+
orientation: string | null;
|
|
40
|
+
};
|
|
41
|
+
type ConnectionInfo = {
|
|
42
|
+
ip?: string;
|
|
43
|
+
userAgent?: string;
|
|
44
|
+
acceptLanguage?: string;
|
|
45
|
+
referrer?: string;
|
|
46
|
+
baseUrl?: string;
|
|
47
|
+
};
|
|
48
|
+
type Context = {
|
|
49
|
+
session: Session | null;
|
|
50
|
+
user: UserInfo | null;
|
|
51
|
+
roles: string[];
|
|
52
|
+
clientInfo: ClientInfo;
|
|
53
|
+
connectionInfo: ConnectionInfo;
|
|
54
|
+
};
|
|
55
|
+
type Args = Record<string, unknown>;
|
|
56
|
+
type Handler<T = unknown> = (args: Args, context: Context) => Promise<T> | T;
|
|
57
|
+
type MethodType = 'query' | 'mutation';
|
|
58
|
+
type MethodDefinition<T = unknown> = {
|
|
59
|
+
permissions?: Permission[];
|
|
60
|
+
handler: Handler<T>;
|
|
61
|
+
} | Handler<T>;
|
|
62
|
+
type Method<T = unknown> = {
|
|
63
|
+
type: MethodType;
|
|
64
|
+
name: string;
|
|
65
|
+
permissions: Permission[];
|
|
66
|
+
handler: Handler<T>;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
type RateLimitType = 'ip' | 'user';
|
|
70
|
+
type RateLimitRule = {
|
|
71
|
+
/** Logical action being limited, e.g. "signup" */
|
|
72
|
+
bucket: string;
|
|
73
|
+
/** Identifier type of the actor this rule applies to */
|
|
74
|
+
type: RateLimitType;
|
|
75
|
+
/** Time window size in milliseconds */
|
|
76
|
+
window: number;
|
|
77
|
+
/** Maximum allowed hits within the window */
|
|
78
|
+
limit: number;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
type CronJobHandler = () => Promise<void>;
|
|
82
|
+
type CronJob = {
|
|
83
|
+
alias: string;
|
|
84
|
+
params: {
|
|
85
|
+
description: string;
|
|
86
|
+
interval: number;
|
|
87
|
+
timeout: number;
|
|
88
|
+
};
|
|
89
|
+
handler: CronJobHandler;
|
|
90
|
+
state: {
|
|
91
|
+
startTs?: number;
|
|
92
|
+
scheduledRunTs?: number;
|
|
93
|
+
isRunning: boolean;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
type CronJobInputParams = {
|
|
97
|
+
description?: string;
|
|
98
|
+
interval: number;
|
|
99
|
+
timeout?: number;
|
|
100
|
+
handler: CronJobHandler;
|
|
101
|
+
};
|
|
102
|
+
type CronJobMetadata = {
|
|
103
|
+
alias: string;
|
|
104
|
+
description: string;
|
|
105
|
+
interval: number;
|
|
106
|
+
timeout: number;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
interface SerializedModelSchema {
|
|
110
|
+
[key: string]: SerializedSchema | (SerializedSchema | SerializedModelSchema)[] | SerializedModelSchema | 'v2';
|
|
111
|
+
}
|
|
112
|
+
type BaseSerializedSchema = {
|
|
113
|
+
type: 'string';
|
|
114
|
+
} | {
|
|
115
|
+
type: 'number';
|
|
116
|
+
} | {
|
|
117
|
+
type: 'boolean';
|
|
118
|
+
} | {
|
|
119
|
+
type: 'date';
|
|
120
|
+
} | {
|
|
121
|
+
type: 'array';
|
|
122
|
+
items: SerializedSchema;
|
|
123
|
+
} | {
|
|
124
|
+
type: 'object';
|
|
125
|
+
items: Record<string, SerializedSchema>;
|
|
126
|
+
} | {
|
|
127
|
+
type: 'enum';
|
|
128
|
+
items: readonly string[];
|
|
129
|
+
} | {
|
|
130
|
+
type: 'union';
|
|
131
|
+
items: SerializedSchema[];
|
|
132
|
+
} | {
|
|
133
|
+
type: 'custom';
|
|
134
|
+
typeName: string;
|
|
135
|
+
};
|
|
136
|
+
type SerializedSchema = BaseSerializedSchema | (BaseSerializedSchema & {
|
|
137
|
+
optional: true;
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Top-level query operators (logical and evaluation) - custom version without Document index signature
|
|
142
|
+
* Based on MongoDB's RootFilterOperators but without the [key: string]: any from Document
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
type StrictRootFilterOperators<TSchema> = {
|
|
146
|
+
$and?: TypedFilter<TSchema>[];
|
|
147
|
+
$or?: TypedFilter<TSchema>[];
|
|
148
|
+
$nor?: TypedFilter<TSchema>[];
|
|
149
|
+
$not?: TypedFilter<TSchema>;
|
|
150
|
+
$text?: {
|
|
151
|
+
$search: string;
|
|
152
|
+
$language?: string;
|
|
153
|
+
$caseSensitive?: boolean;
|
|
154
|
+
$diacriticSensitive?: boolean;
|
|
155
|
+
};
|
|
156
|
+
$where?: string | ((this: TSchema) => boolean);
|
|
157
|
+
$comment?: string | Document;
|
|
158
|
+
$expr?: any;
|
|
159
|
+
$jsonSchema?: any;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Type-safe MongoDB filter that ensures only schema fields can be queried
|
|
163
|
+
* while supporting all MongoDB query operators and dot notation for nested fields.
|
|
164
|
+
*
|
|
165
|
+
* This type combines:
|
|
166
|
+
* - MongoDB's native `FilterOperators<T>` for field-level operators (comprehensive operator support)
|
|
167
|
+
* - Custom `StrictRootFilterOperators<T>` for top-level operators without index signature
|
|
168
|
+
* - Custom restriction: only strings containing dots are allowed for nested field queries
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* const dbUsers = new Store('users', {
|
|
173
|
+
* schema: {
|
|
174
|
+
* name: schema.string(),
|
|
175
|
+
* age: schema.number(),
|
|
176
|
+
* tags: schema.array(schema.string()),
|
|
177
|
+
* address: schema.object({
|
|
178
|
+
* street: schema.string(),
|
|
179
|
+
* city: schema.string(),
|
|
180
|
+
* }),
|
|
181
|
+
* },
|
|
182
|
+
* indexes: []
|
|
183
|
+
* });
|
|
184
|
+
*
|
|
185
|
+
* // ✅ Valid - field exists in schema
|
|
186
|
+
* await dbUsers.findOne({ name: 'John' });
|
|
187
|
+
*
|
|
188
|
+
* // ✅ Valid - using MongoDB operators (from FilterOperators)
|
|
189
|
+
* await dbUsers.findOne({ age: { $gt: 18 } });
|
|
190
|
+
* await dbUsers.findOne({ tags: { $in: ['typescript', 'mongodb'] } });
|
|
191
|
+
* await dbUsers.findOne({ $or: [{ name: 'John' }, { name: 'Jane' }] });
|
|
192
|
+
*
|
|
193
|
+
* // ✅ Valid - dot notation for nested fields (must contain a dot)
|
|
194
|
+
* await dbUsers.findOne({ 'address.city': 'New York' });
|
|
195
|
+
* await dbUsers.findOne({ 'emails.0.address': 'test@example.com' });
|
|
196
|
+
*
|
|
197
|
+
* // ❌ TypeScript error - 'id' is not in schema and doesn't contain a dot
|
|
198
|
+
* await dbUsers.findOne({ id: '123' });
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
type TypedFilter<T> = {
|
|
202
|
+
[K in keyof WithId<T>]?: WithId<T>[K] | FilterOperators<WithId<T>[K]>;
|
|
203
|
+
} & StrictRootFilterOperators<T> & {
|
|
204
|
+
[K: DottedString]: any;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Helper type to preserve method types when extending a store.
|
|
208
|
+
* Maps each method to work with the extended schema while preserving signatures.
|
|
209
|
+
* @internal
|
|
210
|
+
*/
|
|
211
|
+
type PreserveMethodsForExtendedSchema<TBaseMethods extends Record<string, (...args: never[]) => unknown>, TExtendedSchema extends ModelSchema> = {
|
|
212
|
+
[K in keyof TBaseMethods]: TBaseMethods[K] extends (this: any, ...args: infer Args) => infer Return ? (this: WithId<InferDocumentType<TExtendedSchema>> & any, ...args: Args) => Return : never;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* The Store class provides a type-safe interface for MongoDB collections with built-in schema validation and helper methods.
|
|
216
|
+
*
|
|
217
|
+
* @category Store
|
|
218
|
+
* @typeParam TSchema - The document schema type
|
|
219
|
+
* @typeParam TMethods - Custom methods that will be added to documents
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* const dbTodos = new Store('todos', {
|
|
224
|
+
* schema: {
|
|
225
|
+
* title: schema.string(),
|
|
226
|
+
* completed: schema.boolean(),
|
|
227
|
+
* dueDate: schema.date().optional(),
|
|
228
|
+
* userId: schema.userId(),
|
|
229
|
+
* },
|
|
230
|
+
* methods: {
|
|
231
|
+
* isOverdue() {
|
|
232
|
+
* return this.dueDate < new Date();
|
|
233
|
+
* }
|
|
234
|
+
* }
|
|
235
|
+
* });
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
declare class Store<TSchema extends ModelSchema, TMethods extends Record<string, (this: WithId<InferDocumentType<TSchema>> & TMethods, ...args: any[]) => any>> {
|
|
239
|
+
/** @internal */
|
|
240
|
+
readonly _type: InferDocumentType<TSchema>;
|
|
241
|
+
/** @internal */
|
|
242
|
+
readonly _rawDoc: WithId<this['_type']>;
|
|
243
|
+
/** @internal */
|
|
244
|
+
readonly _doc: this['_rawDoc'] & TMethods;
|
|
245
|
+
readonly Doc: this['_doc'];
|
|
246
|
+
private name;
|
|
247
|
+
private readonly schema;
|
|
248
|
+
private readonly methods?;
|
|
249
|
+
private readonly indexes;
|
|
250
|
+
private readonly searchIndexes;
|
|
251
|
+
private collection?;
|
|
252
|
+
private client?;
|
|
253
|
+
/**
|
|
254
|
+
* Creates a new Store instance
|
|
255
|
+
*
|
|
256
|
+
* @param name - The collection name in MongoDB
|
|
257
|
+
* @param options - Store configuration
|
|
258
|
+
*/
|
|
259
|
+
constructor(name: string, options: {
|
|
260
|
+
/** Document schema using Modelence schema types */
|
|
261
|
+
schema: TSchema;
|
|
262
|
+
/** Custom methods to add to documents */
|
|
263
|
+
methods?: TMethods;
|
|
264
|
+
/** MongoDB indexes to create */
|
|
265
|
+
indexes: IndexDescription[];
|
|
266
|
+
/** MongoDB Atlas Search */
|
|
267
|
+
searchIndexes?: SearchIndexDescription[];
|
|
268
|
+
});
|
|
269
|
+
getName(): string;
|
|
270
|
+
/** @internal */
|
|
271
|
+
getSchema(): TSchema;
|
|
272
|
+
/** @internal */
|
|
273
|
+
getSerializedSchema(): SerializedModelSchema;
|
|
274
|
+
/**
|
|
275
|
+
* Extends the store with additional schema fields, indexes, methods, and search indexes.
|
|
276
|
+
* Returns a new Store instance with the extended schema and updated types.
|
|
277
|
+
* Methods from the original store are preserved with updated type signatures.
|
|
278
|
+
*
|
|
279
|
+
* @param config - Additional schema fields, indexes, methods, and search indexes to add
|
|
280
|
+
* @returns A new Store instance with the extended schema
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* // Extend the users collection
|
|
285
|
+
* export const dbUsers = baseUsersCollection.extend({
|
|
286
|
+
* schema: {
|
|
287
|
+
* firstName: schema.string(),
|
|
288
|
+
* lastName: schema.string(),
|
|
289
|
+
* companyId: schema.objectId().optional(),
|
|
290
|
+
* },
|
|
291
|
+
* indexes: [
|
|
292
|
+
* { key: { companyId: 1 } },
|
|
293
|
+
* { key: { lastName: 1, firstName: 1 } },
|
|
294
|
+
* ],
|
|
295
|
+
* methods: {
|
|
296
|
+
* getFullName() {
|
|
297
|
+
* return `${this.firstName} ${this.lastName}`;
|
|
298
|
+
* }
|
|
299
|
+
* }
|
|
300
|
+
* });
|
|
301
|
+
*
|
|
302
|
+
* // Now fully typed with new fields
|
|
303
|
+
* const user = await dbUsers.findOne({ firstName: 'John' });
|
|
304
|
+
* console.log(user?.getFullName());
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
extend<TExtendedSchema extends ModelSchema, TExtendedMethods extends Record<string, (this: WithId<InferDocumentType<TSchema & TExtendedSchema>> & any, ...args: any[]) => any> = Record<string, never>>(config: {
|
|
308
|
+
schema?: TExtendedSchema;
|
|
309
|
+
indexes?: IndexDescription[];
|
|
310
|
+
methods?: TExtendedMethods;
|
|
311
|
+
searchIndexes?: SearchIndexDescription[];
|
|
312
|
+
}): Store<TSchema & TExtendedSchema, PreserveMethodsForExtendedSchema<TMethods, TSchema & TExtendedSchema> & TExtendedMethods>;
|
|
313
|
+
/** @internal */
|
|
314
|
+
init(client: MongoClient): void;
|
|
315
|
+
/** @internal */
|
|
316
|
+
createIndexes(): Promise<void>;
|
|
317
|
+
private wrapDocument;
|
|
318
|
+
/**
|
|
319
|
+
* For convenience, to also allow directy passing a string or ObjectId as the selector
|
|
320
|
+
*/
|
|
321
|
+
private getSelector;
|
|
322
|
+
/** @internal */
|
|
323
|
+
requireCollection(): Collection<this["_type"]>;
|
|
324
|
+
/** @internal */
|
|
325
|
+
requireClient(): MongoClient;
|
|
326
|
+
/**
|
|
327
|
+
* Finds a single document matching the query
|
|
328
|
+
*
|
|
329
|
+
* @param query - Type-safe query filter. Only schema fields, MongoDB operators, and dot notation are allowed.
|
|
330
|
+
* @param options - Find options
|
|
331
|
+
* @returns The document, or null if not found
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```ts
|
|
335
|
+
* // ✅ Valid queries:
|
|
336
|
+
* await store.findOne({ name: 'John' })
|
|
337
|
+
* await store.findOne({ age: { $gt: 18 } })
|
|
338
|
+
* await store.findOne({ _id: new ObjectId('...') })
|
|
339
|
+
* await store.findOne({ tags: { $in: ['typescript', 'mongodb'] } })
|
|
340
|
+
* await store.findOne({ $or: [{ name: 'John' }, { name: 'Jane' }] })
|
|
341
|
+
* await store.findOne({ 'emails.address': 'test@example.com' }) // dot notation
|
|
342
|
+
*
|
|
343
|
+
* // ❌ TypeScript error - 'id' is not in schema:
|
|
344
|
+
* await store.findOne({ id: '123' })
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
findOne(query: TypedFilter<this['_type']>, options?: FindOptions): Promise<this["_doc"] | null>;
|
|
348
|
+
requireOne(query: TypedFilter<this['_type']>, options?: FindOptions, errorHandler?: () => Error): Promise<this['_doc']>;
|
|
349
|
+
private find;
|
|
350
|
+
/**
|
|
351
|
+
* Fetches a single document by its ID
|
|
352
|
+
*
|
|
353
|
+
* @param id - The ID of the document to find
|
|
354
|
+
* @returns The document, or null if not found
|
|
355
|
+
*/
|
|
356
|
+
findById(id: string | ObjectId): Promise<this['_doc'] | null>;
|
|
357
|
+
/**
|
|
358
|
+
* Fetches a single document by its ID, or throws an error if not found
|
|
359
|
+
*
|
|
360
|
+
* @param id - The ID of the document to find
|
|
361
|
+
* @param errorHandler - Optional error handler to return a custom error if the document is not found
|
|
362
|
+
* @returns The document
|
|
363
|
+
*/
|
|
364
|
+
requireById(id: string | ObjectId, errorHandler?: () => Error): Promise<this['_doc']>;
|
|
365
|
+
/**
|
|
366
|
+
* Counts the number of documents that match a query
|
|
367
|
+
*
|
|
368
|
+
* @param query - The query to filter documents
|
|
369
|
+
* @returns The number of documents that match the query
|
|
370
|
+
*/
|
|
371
|
+
countDocuments(query: TypedFilter<this['_type']>): Promise<number>;
|
|
372
|
+
/**
|
|
373
|
+
* Fetches multiple documents, equivalent to Node.js MongoDB driver's `find` and `toArray` methods combined.
|
|
374
|
+
*
|
|
375
|
+
* @param query - The query to filter documents
|
|
376
|
+
* @param options - Options
|
|
377
|
+
* @returns The documents
|
|
378
|
+
*/
|
|
379
|
+
fetch(query: TypedFilter<this['_type']>, options?: {
|
|
380
|
+
sort?: Document;
|
|
381
|
+
limit?: number;
|
|
382
|
+
skip?: number;
|
|
383
|
+
}): Promise<this['_doc'][]>;
|
|
384
|
+
/**
|
|
385
|
+
* Inserts a single document
|
|
386
|
+
*
|
|
387
|
+
* @param document - The document to insert
|
|
388
|
+
* @returns The result of the insert operation
|
|
389
|
+
*/
|
|
390
|
+
insertOne(document: OptionalUnlessRequiredId<InferDocumentType<TSchema>>): Promise<InsertOneResult>;
|
|
391
|
+
/**
|
|
392
|
+
* Inserts multiple documents
|
|
393
|
+
*
|
|
394
|
+
* @param documents - The documents to insert
|
|
395
|
+
* @returns The result of the insert operation
|
|
396
|
+
*/
|
|
397
|
+
insertMany(documents: OptionalUnlessRequiredId<InferDocumentType<TSchema>>[]): Promise<InsertManyResult>;
|
|
398
|
+
/**
|
|
399
|
+
* Updates a single document
|
|
400
|
+
*
|
|
401
|
+
* @param selector - The selector to find the document to update
|
|
402
|
+
* @param update - The update to apply to the document
|
|
403
|
+
* @returns The result of the update operation
|
|
404
|
+
*/
|
|
405
|
+
updateOne(selector: TypedFilter<this['_type']> | string | ObjectId, update: UpdateFilter<this['_type']>): Promise<UpdateResult>;
|
|
406
|
+
/**
|
|
407
|
+
* Updates a single document, or inserts it if it doesn't exist
|
|
408
|
+
*
|
|
409
|
+
* @param selector - The selector to find the document to update
|
|
410
|
+
* @param update - The MongoDB modifier to apply to the document
|
|
411
|
+
* @returns The result of the update operation
|
|
412
|
+
*/
|
|
413
|
+
upsertOne(selector: TypedFilter<this['_type']> | string | ObjectId, update: UpdateFilter<this['_type']>): Promise<UpdateResult>;
|
|
414
|
+
/**
|
|
415
|
+
* Updates multiple documents
|
|
416
|
+
*
|
|
417
|
+
* @param selector - The selector to find the documents to update
|
|
418
|
+
* @param update - The MongoDB modifier to apply to the documents
|
|
419
|
+
* @returns The result of the update operation
|
|
420
|
+
*/
|
|
421
|
+
updateMany(selector: TypedFilter<this['_type']>, update: UpdateFilter<this['_type']>, options?: {
|
|
422
|
+
session?: ClientSession;
|
|
423
|
+
}): Promise<UpdateResult>;
|
|
424
|
+
/**
|
|
425
|
+
* Updates multiple documents, or inserts them if they don't exist
|
|
426
|
+
*
|
|
427
|
+
* @param selector - The selector to find the documents to update
|
|
428
|
+
* @param update - The MongoDB modifier to apply to the documents
|
|
429
|
+
* @returns The result of the update operation
|
|
430
|
+
*/
|
|
431
|
+
upsertMany(selector: TypedFilter<this['_type']>, update: UpdateFilter<this['_type']>): Promise<UpdateResult>;
|
|
432
|
+
/**
|
|
433
|
+
* Deletes a single document
|
|
434
|
+
*
|
|
435
|
+
* @param selector - The selector to find the document to delete
|
|
436
|
+
* @returns The result of the delete operation
|
|
437
|
+
*/
|
|
438
|
+
deleteOne(selector: TypedFilter<this['_type']>): Promise<DeleteResult>;
|
|
439
|
+
/**
|
|
440
|
+
* Deletes multiple documents
|
|
441
|
+
*
|
|
442
|
+
* @param selector - The selector to find the documents to delete
|
|
443
|
+
* @returns The result of the delete operation
|
|
444
|
+
*/
|
|
445
|
+
deleteMany(selector: TypedFilter<this['_type']>): Promise<DeleteResult>;
|
|
446
|
+
/**
|
|
447
|
+
* Aggregates documents using MongoDB's aggregation framework
|
|
448
|
+
*
|
|
449
|
+
* @param pipeline - The aggregation pipeline
|
|
450
|
+
* @param options - Optional options
|
|
451
|
+
* @returns The aggregation cursor
|
|
452
|
+
*/
|
|
453
|
+
aggregate(pipeline: Document[], options?: AggregateOptions): AggregationCursor<Document>;
|
|
454
|
+
/**
|
|
455
|
+
* Performs a bulk write operation on the collection
|
|
456
|
+
*
|
|
457
|
+
* @param operations - The operations to perform
|
|
458
|
+
* @returns The result of the bulk write operation
|
|
459
|
+
*/
|
|
460
|
+
bulkWrite(operations: AnyBulkWriteOperation<this['_type']>[]): Promise<BulkWriteResult>;
|
|
461
|
+
/**
|
|
462
|
+
* Returns the raw MongoDB database instance for advanced operations
|
|
463
|
+
* @returns The MongoDB database instance
|
|
464
|
+
* @throws Error if the store is not provisioned
|
|
465
|
+
*/
|
|
466
|
+
getDatabase(): mongodb.Db;
|
|
467
|
+
/**
|
|
468
|
+
* Returns the raw MongoDB collection instance for advanced operations
|
|
469
|
+
* @returns The MongoDB collection instance
|
|
470
|
+
* @throws Error if the store is not provisioned
|
|
471
|
+
*/
|
|
472
|
+
rawCollection(): Collection<this["_type"]>;
|
|
473
|
+
/**
|
|
474
|
+
* Renames an existing collection to this store's name, used for migrations
|
|
475
|
+
* @param oldName - The previous name of the collection
|
|
476
|
+
* @throws Error if the old collection doesn't exist or if this store's collection already exists
|
|
477
|
+
*/
|
|
478
|
+
renameFrom(oldName: string, options?: {
|
|
479
|
+
session?: ClientSession;
|
|
480
|
+
}): Promise<void>;
|
|
481
|
+
/**
|
|
482
|
+
* Performs a vector similarity search using MongoDB Atlas Vector Search
|
|
483
|
+
*
|
|
484
|
+
* @param params - Vector search parameters
|
|
485
|
+
* @param params.field - The field name containing the vector embeddings
|
|
486
|
+
* @param params.embedding - The query vector to search for
|
|
487
|
+
* @param params.numCandidates - Number of nearest neighbors to consider (default: 100)
|
|
488
|
+
* @param params.limit - Maximum number of results to return (default: 10)
|
|
489
|
+
* @param params.projection - Additional fields to include in the results
|
|
490
|
+
* @param params.indexName - Name of index (default: field + VectorSearch)
|
|
491
|
+
* @returns An aggregation cursor with search results and scores
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* ```ts
|
|
495
|
+
* const results = await store.vectorSearch({
|
|
496
|
+
* field: 'embedding',
|
|
497
|
+
* embedding: [0.1, 0.2, 0.3, ...],
|
|
498
|
+
* numCandidates: 100,
|
|
499
|
+
* limit: 10,
|
|
500
|
+
* projection: { title: 1, description: 1 }
|
|
501
|
+
* });
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
504
|
+
vectorSearch({ field, embedding, numCandidates, limit, projection, indexName, }: {
|
|
505
|
+
field: string;
|
|
506
|
+
embedding: number[];
|
|
507
|
+
numCandidates?: number;
|
|
508
|
+
limit?: number;
|
|
509
|
+
projection?: Document;
|
|
510
|
+
indexName?: string;
|
|
511
|
+
}): Promise<AggregationCursor<Document>>;
|
|
512
|
+
/**
|
|
513
|
+
* Creates a MongoDB Atlas Vector Search index definition
|
|
514
|
+
*
|
|
515
|
+
* @param params - Vector index parameters
|
|
516
|
+
* @param params.field - The field name to create the vector index on
|
|
517
|
+
* @param params.dimensions - The number of dimensions in the vector embeddings
|
|
518
|
+
* @param params.similarity - The similarity metric to use (default: 'cosine')
|
|
519
|
+
* @param params.indexName - Name of index (default: field + VectorSearch)
|
|
520
|
+
* @returns A search index description object
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```ts
|
|
524
|
+
* const store = new Store('documents', {
|
|
525
|
+
* schema: {
|
|
526
|
+
* title: schema.string(),
|
|
527
|
+
* embedding: schema.array(schema.number()),
|
|
528
|
+
* },
|
|
529
|
+
* indexes: [],
|
|
530
|
+
* searchIndexes: [
|
|
531
|
+
* Store.vectorIndex({
|
|
532
|
+
* field: 'embedding',
|
|
533
|
+
* dimensions: 1536,
|
|
534
|
+
* similarity: 'cosine'
|
|
535
|
+
* })
|
|
536
|
+
* ]
|
|
537
|
+
* });
|
|
538
|
+
* ```
|
|
539
|
+
*/
|
|
540
|
+
static vectorIndex({ field, dimensions, similarity, indexName, }: {
|
|
541
|
+
field: string;
|
|
542
|
+
dimensions: number;
|
|
543
|
+
similarity?: 'cosine' | 'euclidean' | 'dotProduct';
|
|
544
|
+
indexName?: string;
|
|
545
|
+
}): {
|
|
546
|
+
type: string;
|
|
547
|
+
name: string;
|
|
548
|
+
definition: {
|
|
549
|
+
fields: {
|
|
550
|
+
type: string;
|
|
551
|
+
path: string;
|
|
552
|
+
numDimensions: number;
|
|
553
|
+
similarity: "cosine" | "euclidean" | "dotProduct";
|
|
554
|
+
}[];
|
|
555
|
+
};
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
type ObjectTypeDefinition = {
|
|
560
|
+
[key: string]: SchemaTypeDefinition;
|
|
561
|
+
};
|
|
562
|
+
type SingularSchemaTypeDefinition = z.ZodType | ObjectTypeDefinition;
|
|
563
|
+
type SchemaTypeDefinition = SingularSchemaTypeDefinition | Array<SingularSchemaTypeDefinition>;
|
|
564
|
+
type ModelSchema = {
|
|
565
|
+
[key: string]: SchemaTypeDefinition;
|
|
566
|
+
};
|
|
567
|
+
type InferDocumentType<T extends SchemaTypeDefinition> = {
|
|
568
|
+
[K in keyof T as T[K] extends z.ZodOptional<z.ZodTypeAny> ? K : never]?: T[K] extends z.ZodType ? z.infer<T[K]> : never;
|
|
569
|
+
} & {
|
|
570
|
+
[K in keyof T as T[K] extends z.ZodOptional<z.ZodTypeAny> ? never : K]: T[K] extends z.ZodType ? z.infer<T[K]> : T[K] extends Array<infer ElementType extends SchemaTypeDefinition> ? Array<InferDocumentType<ElementType>> : T[K] extends ObjectTypeDefinition ? InferDocumentType<T[K]> : never;
|
|
571
|
+
};
|
|
572
|
+
declare const schema: {
|
|
573
|
+
readonly string: (params?: z.RawCreateParams & {
|
|
574
|
+
coerce?: true;
|
|
575
|
+
}) => z.ZodString;
|
|
576
|
+
readonly number: (params?: z.RawCreateParams & {
|
|
577
|
+
coerce?: boolean;
|
|
578
|
+
}) => ZodNumber;
|
|
579
|
+
readonly date: (params?: z.RawCreateParams & {
|
|
580
|
+
coerce?: boolean;
|
|
581
|
+
}) => z.ZodDate;
|
|
582
|
+
readonly boolean: (params?: z.RawCreateParams & {
|
|
583
|
+
coerce?: boolean;
|
|
584
|
+
}) => z.ZodBoolean;
|
|
585
|
+
readonly array: <El extends z.ZodTypeAny>(schema: El, params?: z.RawCreateParams) => ZodArray<El>;
|
|
586
|
+
readonly object: <Shape extends z.ZodRawShape>(shape: Shape, params?: z.RawCreateParams) => z.ZodObject<Shape, "strip", z.ZodTypeAny, z.objectOutputType<Shape, z.ZodTypeAny, "strip">, z.objectInputType<Shape, z.ZodTypeAny, "strip">>;
|
|
587
|
+
readonly enum: {
|
|
588
|
+
<U extends string, T extends Readonly<[U, ...U[]]>>(values: T, params?: z.RawCreateParams): z.ZodEnum<z.Writeable<T>>;
|
|
589
|
+
<U extends string, T extends [U, ...U[]]>(values: T, params?: z.RawCreateParams): z.ZodEnum<T>;
|
|
590
|
+
};
|
|
591
|
+
readonly embedding: () => ZodArray<ZodNumber>;
|
|
592
|
+
readonly objectId: () => z.ZodType<ObjectId>;
|
|
593
|
+
readonly userId: () => z.ZodType<ObjectId>;
|
|
594
|
+
readonly ref: <T extends ModelSchema>(_collection: string | Store<T, InferDocumentType<T>>) => z.ZodType<ObjectId>;
|
|
595
|
+
readonly union: <Options extends Readonly<[z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]>>(types: Options, params?: z.RawCreateParams) => z.ZodUnion<Options>;
|
|
596
|
+
readonly infer: <T extends SchemaTypeDefinition>(_schema: T) => InferDocumentType<T>;
|
|
597
|
+
};
|
|
598
|
+
declare namespace schema {
|
|
599
|
+
type infer<T extends SchemaTypeDefinition> = InferDocumentType<T>;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head' | 'all' | 'use';
|
|
603
|
+
type RouteParams<T = unknown> = {
|
|
604
|
+
query: Record<string, string>;
|
|
605
|
+
body: T;
|
|
606
|
+
params: Record<string, string>;
|
|
607
|
+
headers: Record<string, string>;
|
|
608
|
+
cookies: Record<string, string>;
|
|
609
|
+
rawBody?: Buffer;
|
|
610
|
+
req: Request;
|
|
611
|
+
res: Response;
|
|
612
|
+
next: NextFunction;
|
|
613
|
+
};
|
|
614
|
+
type RouteResponse<T = unknown> = {
|
|
615
|
+
data?: T;
|
|
616
|
+
status?: number;
|
|
617
|
+
headers?: Record<string, string>;
|
|
618
|
+
redirect?: string;
|
|
619
|
+
} | null;
|
|
620
|
+
type RouteHandler<T = unknown> = (params: RouteParams, context: Pick<Context, 'session' | 'user'>) => Promise<RouteResponse<T>> | RouteResponse<T>;
|
|
621
|
+
type RouteHandlers = {
|
|
622
|
+
[key in HttpMethod]?: RouteHandler;
|
|
623
|
+
};
|
|
624
|
+
type BodyConfig = {
|
|
625
|
+
json?: boolean | {
|
|
626
|
+
limit?: string;
|
|
627
|
+
};
|
|
628
|
+
urlencoded?: boolean | {
|
|
629
|
+
limit?: string;
|
|
630
|
+
extended?: boolean;
|
|
631
|
+
};
|
|
632
|
+
raw?: boolean | {
|
|
633
|
+
limit?: string;
|
|
634
|
+
type?: string | string[];
|
|
635
|
+
};
|
|
636
|
+
};
|
|
637
|
+
type RouteDefinition = {
|
|
638
|
+
path: string;
|
|
639
|
+
handlers: RouteHandlers;
|
|
640
|
+
errorHandler?: RouteHandler;
|
|
641
|
+
body?: BodyConfig;
|
|
642
|
+
};
|
|
643
|
+
type ExpressHandler = (req: Request, res: Response) => Promise<void> | void;
|
|
644
|
+
|
|
645
|
+
export { type Args as A, type BodyConfig as B, type CronJobInputParams as C, type EmailProvider as E, type HttpMethod as H, type InferDocumentType as I, type MethodDefinition as M, type RouteDefinition as R, Store as S, type RateLimitRule as a, type ConnectionInfo as b, type RateLimitType as c, type EmailPayload as d, type RouteHandler as e, type RouteParams as f, type RouteResponse as g, type EmailAttachment as h, type ClientInfo as i, type Context as j, type Handler as k, type MethodType as l, type Method as m, type CronJob as n, type CronJobMetadata as o, type ModelSchema as p, type RouteHandlers as q, type ExpressHandler as r, schema as s };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { A as AppServer, E as ExpressMiddleware, M as ModelenceConfig } from './index-CwdohC5n.js';
|
|
2
|
+
export { A as Args, B as BodyConfig, i as ClientInfo, b as ConnectionInfo, j as Context, n as CronJob, C as CronJobInputParams, o as CronJobMetadata, h as EmailAttachment, d as EmailPayload, E as EmailProvider, r as ExpressHandler, k as Handler, H as HttpMethod, I as InferDocumentType, m as Method, M as MethodDefinition, l as MethodType, p as ModelSchema, a as RateLimitRule, c as RateLimitType, R as RouteDefinition, e as RouteHandler, q as RouteHandlers, f as RouteParams, g as RouteResponse, s as schema } from './types-WgRbQ-tj.js';
|
|
3
|
+
export { A as AppConfig, b as ConfigKey, C as ConfigSchema, g as ConfigType, h as Configs, D as DefaultRoles, P as Permission, f as Role, R as RoleDefinition, d as Session, U as User, e as UserInfo, a as WebsocketClientProvider, W as WebsocketServerProvider } from './types-Ds1ESQSs.js';
|
|
4
|
+
import 'express';
|
|
5
|
+
import 'mongodb';
|
|
6
|
+
import 'zod';
|
|
7
|
+
import 'http';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}
|