@atscript/moost-mongo 0.1.2 → 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.
- package/dist/index.cjs +5 -5
- package/dist/index.d.ts +24 -18
- package/dist/index.mjs +6 -6
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -41,7 +41,7 @@ else obj[key] = value;
|
|
|
41
41
|
}
|
|
42
42
|
var QueryControlsDto = class {
|
|
43
43
|
static toJsonSchema() {
|
|
44
|
-
|
|
44
|
+
throw new Error("JSON Schema support is disabled. To enable, set `jsonSchema: 'lazy'` or `jsonSchema: 'bundle'` in tsPlugin options, or add @emit.jsonSchema annotation to individual interfaces.");
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
_define_property$1(QueryControlsDto, "__is_atscript_annotated_type", true);
|
|
@@ -49,7 +49,7 @@ _define_property$1(QueryControlsDto, "type", {});
|
|
|
49
49
|
_define_property$1(QueryControlsDto, "metadata", new Map());
|
|
50
50
|
var PagesControlsDto = class {
|
|
51
51
|
static toJsonSchema() {
|
|
52
|
-
|
|
52
|
+
throw new Error("JSON Schema support is disabled. To enable, set `jsonSchema: 'lazy'` or `jsonSchema: 'bundle'` in tsPlugin options, or add @emit.jsonSchema annotation to individual interfaces.");
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
_define_property$1(PagesControlsDto, "__is_atscript_annotated_type", true);
|
|
@@ -57,7 +57,7 @@ _define_property$1(PagesControlsDto, "type", {});
|
|
|
57
57
|
_define_property$1(PagesControlsDto, "metadata", new Map());
|
|
58
58
|
var GetOneControlsDto = class {
|
|
59
59
|
static toJsonSchema() {
|
|
60
|
-
|
|
60
|
+
throw new Error("JSON Schema support is disabled. To enable, set `jsonSchema: 'lazy'` or `jsonSchema: 'bundle'` in tsPlugin options, or add @emit.jsonSchema annotation to individual interfaces.");
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
_define_property$1(GetOneControlsDto, "__is_atscript_annotated_type", true);
|
|
@@ -65,7 +65,7 @@ _define_property$1(GetOneControlsDto, "type", {});
|
|
|
65
65
|
_define_property$1(GetOneControlsDto, "metadata", new Map());
|
|
66
66
|
let SortControlDto = class SortControlDto$1 {
|
|
67
67
|
static toJsonSchema() {
|
|
68
|
-
|
|
68
|
+
throw new Error("JSON Schema support is disabled. To enable, set `jsonSchema: 'lazy'` or `jsonSchema: 'bundle'` in tsPlugin options, or add @emit.jsonSchema annotation to individual interfaces.");
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
_define_property$1(SortControlDto, "__is_atscript_annotated_type", true);
|
|
@@ -73,7 +73,7 @@ _define_property$1(SortControlDto, "type", {});
|
|
|
73
73
|
_define_property$1(SortControlDto, "metadata", new Map());
|
|
74
74
|
let SelectControlDto = class SelectControlDto$1 {
|
|
75
75
|
static toJsonSchema() {
|
|
76
|
-
|
|
76
|
+
throw new Error("JSON Schema support is disabled. To enable, set `jsonSchema: 'lazy'` or `jsonSchema: 'bundle'` in tsPlugin options, or add @emit.jsonSchema annotation to individual interfaces.");
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
_define_property$1(SelectControlDto, "__is_atscript_annotated_type", true);
|
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 {
|
|
6
|
-
import { Document, Filter, WithId, InsertOneResult, InsertManyResult, UpdateResult, DeleteResult, DeleteOptions, ObjectId,
|
|
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
|
|
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}. */
|
|
@@ -57,11 +61,11 @@ declare class AsMongoController<T extends TAtscriptAnnotatedTypeConstructor> {
|
|
|
57
61
|
private _pagesControlsValidator?;
|
|
58
62
|
private _getOneControlsValidator?;
|
|
59
63
|
/** Returns (and memoises) validator for *query* endpoint controls. */
|
|
60
|
-
protected get queryControlsValidator(): Validator<any,
|
|
64
|
+
protected get queryControlsValidator(): Validator<any, unknown> | undefined;
|
|
61
65
|
/** Returns (and memoises) validator for *pages* endpoint controls. */
|
|
62
|
-
protected get pagesControlsValidator(): Validator<any,
|
|
66
|
+
protected get pagesControlsValidator(): Validator<any, unknown> | undefined;
|
|
63
67
|
/** Returns (and memoises) validator for *one* endpoint controls. */
|
|
64
|
-
protected get getOneControlsValidator(): Validator<any,
|
|
68
|
+
protected get getOneControlsValidator(): Validator<any, unknown> | undefined;
|
|
65
69
|
/**
|
|
66
70
|
* Validates `$limit`, `$skip`, `$sort`, `$select`, `$count` controls for the
|
|
67
71
|
* **query** endpoint.
|
|
@@ -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<
|
|
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<
|
|
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:
|
|
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<
|
|
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<
|
|
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
|
|
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:
|
|
231
|
-
protected onWrite(action: 'insertMany', data:
|
|
232
|
-
protected onWrite(action: 'replace', data:
|
|
233
|
-
protected onWrite(action: 'update', data: UpdateFilter<
|
|
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:
|
|
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:
|
|
291
|
+
declare const InjectCollection: (type: TAtscriptAnnotatedType) => ParameterDecorator & PropertyDecorator;
|
|
286
292
|
|
|
287
293
|
export { AsMongoController, COLLECTION_DEF, CollectionController, InjectCollection };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Body, Delete, Get, HttpError, Patch, Post, Put, Url } from "@moostjs/event-http";
|
|
2
2
|
import { ApplyDecorators, Controller, Inherit, Inject, Moost, Param, Provide, Resolve } from "moost";
|
|
3
3
|
import { parseUrlql } from "urlql";
|
|
4
|
-
import { ValidatorError,
|
|
4
|
+
import { ValidatorError, defineAnnotatedType } from "@atscript/typescript/utils";
|
|
5
5
|
import { AsMongo } from "@atscript/mongo";
|
|
6
6
|
|
|
7
7
|
//#region packages/moost-mongo/src/dto/controls.dto.as.js
|
|
@@ -17,7 +17,7 @@ else obj[key] = value;
|
|
|
17
17
|
}
|
|
18
18
|
var QueryControlsDto = class {
|
|
19
19
|
static toJsonSchema() {
|
|
20
|
-
|
|
20
|
+
throw new Error("JSON Schema support is disabled. To enable, set `jsonSchema: 'lazy'` or `jsonSchema: 'bundle'` in tsPlugin options, or add @emit.jsonSchema annotation to individual interfaces.");
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
_define_property$1(QueryControlsDto, "__is_atscript_annotated_type", true);
|
|
@@ -25,7 +25,7 @@ _define_property$1(QueryControlsDto, "type", {});
|
|
|
25
25
|
_define_property$1(QueryControlsDto, "metadata", new Map());
|
|
26
26
|
var PagesControlsDto = class {
|
|
27
27
|
static toJsonSchema() {
|
|
28
|
-
|
|
28
|
+
throw new Error("JSON Schema support is disabled. To enable, set `jsonSchema: 'lazy'` or `jsonSchema: 'bundle'` in tsPlugin options, or add @emit.jsonSchema annotation to individual interfaces.");
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
_define_property$1(PagesControlsDto, "__is_atscript_annotated_type", true);
|
|
@@ -33,7 +33,7 @@ _define_property$1(PagesControlsDto, "type", {});
|
|
|
33
33
|
_define_property$1(PagesControlsDto, "metadata", new Map());
|
|
34
34
|
var GetOneControlsDto = class {
|
|
35
35
|
static toJsonSchema() {
|
|
36
|
-
|
|
36
|
+
throw new Error("JSON Schema support is disabled. To enable, set `jsonSchema: 'lazy'` or `jsonSchema: 'bundle'` in tsPlugin options, or add @emit.jsonSchema annotation to individual interfaces.");
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
_define_property$1(GetOneControlsDto, "__is_atscript_annotated_type", true);
|
|
@@ -41,7 +41,7 @@ _define_property$1(GetOneControlsDto, "type", {});
|
|
|
41
41
|
_define_property$1(GetOneControlsDto, "metadata", new Map());
|
|
42
42
|
let SortControlDto = class SortControlDto$1 {
|
|
43
43
|
static toJsonSchema() {
|
|
44
|
-
|
|
44
|
+
throw new Error("JSON Schema support is disabled. To enable, set `jsonSchema: 'lazy'` or `jsonSchema: 'bundle'` in tsPlugin options, or add @emit.jsonSchema annotation to individual interfaces.");
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
_define_property$1(SortControlDto, "__is_atscript_annotated_type", true);
|
|
@@ -49,7 +49,7 @@ _define_property$1(SortControlDto, "type", {});
|
|
|
49
49
|
_define_property$1(SortControlDto, "metadata", new Map());
|
|
50
50
|
let SelectControlDto = class SelectControlDto$1 {
|
|
51
51
|
static toJsonSchema() {
|
|
52
|
-
|
|
52
|
+
throw new Error("JSON Schema support is disabled. To enable, set `jsonSchema: 'lazy'` or `jsonSchema: 'bundle'` in tsPlugin options, or add @emit.jsonSchema annotation to individual interfaces.");
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
_define_property$1(SelectControlDto, "__is_atscript_annotated_type", true);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/moost-mongo",
|
|
3
|
-
"version": "0.1.
|
|
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.
|
|
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.
|
|
49
|
-
"@atscript/typescript": "^0.1.
|
|
48
|
+
"@atscript/mongo": "^0.1.4",
|
|
49
|
+
"@atscript/typescript": "^0.1.4"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"pub": "pnpm publish --access public",
|