@atscript/moost-mongo 0.1.3 → 0.1.4

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +21 -15
  2. package/package.json +4 -4
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ import { HttpError } from '@moostjs/event-http';
2
2
  import { TConsoleBase, Moost } from 'moost';
3
3
  import { UrlqlQuery } from 'urlql';
4
4
  import { AsMongo, AsCollection } from '@atscript/mongo';
5
- import { TAtscriptAnnotatedTypeConstructor, Validator, ValidatorError } from '@atscript/typescript/utils';
6
- import { Document, Filter, WithId, InsertOneResult, InsertManyResult, UpdateResult, DeleteResult, DeleteOptions, ObjectId, OptionalUnlessRequiredId, InsertOneOptions, BulkWriteOptions, WithoutId, ReplaceOptions, UpdateFilter, UpdateOptions } from 'mongodb';
5
+ import { TAtscriptAnnotatedType, Validator, ValidatorError } from '@atscript/typescript/utils';
6
+ import { Document, Filter, WithId, InsertOneResult, InsertManyResult, UpdateResult, DeleteResult, DeleteOptions, ObjectId, InsertOneOptions, BulkWriteOptions, ReplaceOptions, UpdateFilter, UpdateOptions } from 'mongodb';
7
7
 
8
8
  /**
9
9
  * Generic **Moost** controller that exposes a full REST‑style CRUD surface over a
@@ -23,7 +23,11 @@ import { Document, Filter, WithId, InsertOneResult, InsertManyResult, UpdateResu
23
23
  * @typeParam T - The **atscript** annotated class (constructor) representing the
24
24
  * collection schema. Must be decorated with `@AsCollection`.
25
25
  */
26
- declare class AsMongoController<T extends TAtscriptAnnotatedTypeConstructor> {
26
+ declare class AsMongoController<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType, DataType = T extends {
27
+ type: {
28
+ __dataType?: infer D;
29
+ };
30
+ } ? unknown extends D ? T extends new (...args: any[]) => infer I ? I : unknown : D : unknown> {
27
31
  protected asMongo: AsMongo;
28
32
  protected type: T;
29
33
  /** Reference to the lazily created {@link AsCollection}. */
@@ -112,7 +116,7 @@ declare class AsMongoController<T extends TAtscriptAnnotatedTypeConstructor> {
112
116
  * @param filter - The original filter object.
113
117
  * @returns The transformed filter object (may return `Promise`).
114
118
  */
115
- protected transformFilter(filter: Document): Filter<InstanceType<T>>;
119
+ protected transformFilter(filter: Document): Filter<any>;
116
120
  /**
117
121
  * Builds MongoDB `FindOptions` object out of URLQL controls.
118
122
  *
@@ -156,7 +160,7 @@ declare class AsMongoController<T extends TAtscriptAnnotatedTypeConstructor> {
156
160
  * @param url - Full request URL provided by Moost (includes query string).
157
161
  * @returns Documents array **or** document count number.
158
162
  */
159
- query(url: string): Promise<InstanceType<T>[] | number | HttpError>;
163
+ query(url: string): Promise<DataType[] | number | HttpError>;
160
164
  /**
161
165
  * **GET /pages** – returns paginated documents plus basic pagination meta.
162
166
  *
@@ -164,7 +168,7 @@ declare class AsMongoController<T extends TAtscriptAnnotatedTypeConstructor> {
164
168
  * @returns An object with keys: `documents`, `page`, `size`, `totalPages`, `totalDocuments`.
165
169
  */
166
170
  pages(url: string): Promise<{
167
- documents: InstanceType<T>[];
171
+ documents: DataType[];
168
172
  page: number;
169
173
  size: number;
170
174
  totalPages: number;
@@ -180,7 +184,7 @@ declare class AsMongoController<T extends TAtscriptAnnotatedTypeConstructor> {
180
184
  * @param id - Document `_id` or alternate unique key value.
181
185
  * @param url - Full request URL (supports `$select`, `$insights`, etc.).
182
186
  */
183
- getOne(id: string, url: string): Promise<InstanceType<T> | HttpError | ValidatorError>;
187
+ getOne(id: string, url: string): Promise<DataType | HttpError | ValidatorError>;
184
188
  /**
185
189
  * Helper that unwraps a promise returning an array of documents and
186
190
  * guarantees zero‑or‑one semantics expected by **one** endpoint.
@@ -188,7 +192,7 @@ declare class AsMongoController<T extends TAtscriptAnnotatedTypeConstructor> {
188
192
  * @param result - Promise resolving to an array of documents.
189
193
  * @returns Document, 400 or 404 { @link HttpError }.
190
194
  */
191
- protected returnOne(result: Promise<WithId<InstanceType<T>>[]>): Promise<InstanceType<T> | HttpError>;
195
+ protected returnOne(result: Promise<WithId<DataType>[]>): Promise<DataType | HttpError>;
192
196
  /**
193
197
  * **POST /** – inserts one or many documents.
194
198
  *
@@ -200,7 +204,7 @@ declare class AsMongoController<T extends TAtscriptAnnotatedTypeConstructor> {
200
204
  *
201
205
  * @param payload - Object containing `_id` plus full replacement document.
202
206
  */
203
- replace(payload: Parameters<AsCollection<T>['prepareReplace']>[0]): Promise<HttpError | UpdateResult<InstanceType<T>>>;
207
+ replace(payload: Parameters<AsCollection<T>['prepareReplace']>[0]): Promise<HttpError | UpdateResult>;
204
208
  /**
205
209
  * **PATCH /** – updates one document using MongoDB update operators.
206
210
  *
@@ -227,10 +231,10 @@ declare class AsMongoController<T extends TAtscriptAnnotatedTypeConstructor> {
227
231
  * Override to validate or mutate data, or tweak driver options. Return
228
232
  * `undefined` to abort the write – the endpoint will respond with *500 Not saved*.
229
233
  */
230
- protected onWrite(action: 'insert', data: OptionalUnlessRequiredId<InstanceType<T>>, opts: InsertOneOptions): OptionalUnlessRequiredId<InstanceType<T>> | Promise<OptionalUnlessRequiredId<InstanceType<T>> | undefined> | undefined;
231
- protected onWrite(action: 'insertMany', data: OptionalUnlessRequiredId<InstanceType<T>>[], opts: BulkWriteOptions): OptionalUnlessRequiredId<InstanceType<T>>[] | Promise<OptionalUnlessRequiredId<InstanceType<T>>[] | undefined> | undefined;
232
- protected onWrite(action: 'replace', data: WithoutId<InstanceType<T>>, opts: ReplaceOptions): WithoutId<InstanceType<T>> | Promise<WithoutId<InstanceType<T>> | undefined> | undefined;
233
- protected onWrite(action: 'update', data: UpdateFilter<InstanceType<T>>, opts: UpdateOptions): UpdateFilter<InstanceType<T>> | Promise<UpdateFilter<InstanceType<T>> | undefined> | undefined;
234
+ protected onWrite(action: 'insert', data: DataType, opts: InsertOneOptions): DataType | Promise<DataType | undefined> | undefined;
235
+ protected onWrite(action: 'insertMany', data: DataType[], opts: BulkWriteOptions): DataType[] | Promise<DataType[] | undefined> | undefined;
236
+ protected onWrite(action: 'replace', data: DataType, opts: ReplaceOptions): DataType | Promise<DataType | undefined> | undefined;
237
+ protected onWrite(action: 'update', data: UpdateFilter<any>, opts: UpdateOptions): UpdateFilter<any> | Promise<UpdateFilter<any> | undefined> | undefined;
234
238
  }
235
239
 
236
240
  /**
@@ -260,7 +264,9 @@ declare const COLLECTION_DEF = "__atscript_mongo_collection_def";
260
264
  * export class UsersController extends AsMongoController<typeof UserModel> {}
261
265
  * ```
262
266
  */
263
- declare const CollectionController: (type: TAtscriptAnnotatedTypeConstructor, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
267
+ declare const CollectionController: (type: TAtscriptAnnotatedType & {
268
+ name?: string;
269
+ }, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
264
270
  /**
265
271
  * Parameter decorator that injects the lazily-resolved {@link AsCollection}
266
272
  * instance for a given AtScript model.
@@ -282,6 +288,6 @@ declare const CollectionController: (type: TAtscriptAnnotatedTypeConstructor, pr
282
288
  * }
283
289
  * ```
284
290
  */
285
- declare const InjectCollection: (type: TAtscriptAnnotatedTypeConstructor) => ParameterDecorator & PropertyDecorator;
291
+ declare const InjectCollection: (type: TAtscriptAnnotatedType) => ParameterDecorator & PropertyDecorator;
286
292
 
287
293
  export { AsMongoController, COLLECTION_DEF, CollectionController, InjectCollection };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/moost-mongo",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Atscript Mongo for Moost.",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -39,14 +39,14 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "vitest": "3.2.4",
42
- "@atscript/core": "^0.1.3"
42
+ "@atscript/core": "^0.1.4"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@moostjs/event-http": "^0.5.32",
46
46
  "mongodb": "^6.17.0",
47
47
  "moost": "^0.5.32",
48
- "@atscript/mongo": "^0.1.3",
49
- "@atscript/typescript": "^0.1.3"
48
+ "@atscript/mongo": "^0.1.4",
49
+ "@atscript/typescript": "^0.1.4"
50
50
  },
51
51
  "scripts": {
52
52
  "pub": "pnpm publish --access public",