@atscript/moost-mongo 0.0.28 → 0.0.30
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 +18 -20
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +5 -7
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -25,7 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
const __moostjs_event_http = __toESM(require("@moostjs/event-http"));
|
|
26
26
|
const moost = __toESM(require("moost"));
|
|
27
27
|
const urlql = __toESM(require("urlql"));
|
|
28
|
-
const
|
|
28
|
+
const __atscript_typescript_utils = __toESM(require("@atscript/typescript/utils"));
|
|
29
29
|
const __atscript_mongo = __toESM(require("@atscript/mongo"));
|
|
30
30
|
|
|
31
31
|
//#region packages/moost-mongo/src/dto/controls.dto.as.js
|
|
@@ -41,7 +41,7 @@ else obj[key] = value;
|
|
|
41
41
|
}
|
|
42
42
|
var QueryControlsDto = class {
|
|
43
43
|
static toJsonSchema() {
|
|
44
|
-
return this._jsonSchema ?? (this._jsonSchema = (0,
|
|
44
|
+
return this._jsonSchema ?? (this._jsonSchema = (0, __atscript_typescript_utils.buildJsonSchema)(this));
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
_define_property$1(QueryControlsDto, "__is_atscript_annotated_type", true);
|
|
@@ -50,7 +50,7 @@ _define_property$1(QueryControlsDto, "metadata", new Map());
|
|
|
50
50
|
_define_property$1(QueryControlsDto, "_jsonSchema", void 0);
|
|
51
51
|
var PagesControlsDto = class {
|
|
52
52
|
static toJsonSchema() {
|
|
53
|
-
return this._jsonSchema ?? (this._jsonSchema = (0,
|
|
53
|
+
return this._jsonSchema ?? (this._jsonSchema = (0, __atscript_typescript_utils.buildJsonSchema)(this));
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
_define_property$1(PagesControlsDto, "__is_atscript_annotated_type", true);
|
|
@@ -59,7 +59,7 @@ _define_property$1(PagesControlsDto, "metadata", new Map());
|
|
|
59
59
|
_define_property$1(PagesControlsDto, "_jsonSchema", void 0);
|
|
60
60
|
var GetOneControlsDto = class {
|
|
61
61
|
static toJsonSchema() {
|
|
62
|
-
return this._jsonSchema ?? (this._jsonSchema = (0,
|
|
62
|
+
return this._jsonSchema ?? (this._jsonSchema = (0, __atscript_typescript_utils.buildJsonSchema)(this));
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
_define_property$1(GetOneControlsDto, "__is_atscript_annotated_type", true);
|
|
@@ -68,7 +68,7 @@ _define_property$1(GetOneControlsDto, "metadata", new Map());
|
|
|
68
68
|
_define_property$1(GetOneControlsDto, "_jsonSchema", void 0);
|
|
69
69
|
let SortControlDto = class SortControlDto$1 {
|
|
70
70
|
static toJsonSchema() {
|
|
71
|
-
return this._jsonSchema ?? (this._jsonSchema = (0,
|
|
71
|
+
return this._jsonSchema ?? (this._jsonSchema = (0, __atscript_typescript_utils.buildJsonSchema)(this));
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
74
|
_define_property$1(SortControlDto, "__is_atscript_annotated_type", true);
|
|
@@ -77,33 +77,31 @@ _define_property$1(SortControlDto, "metadata", new Map());
|
|
|
77
77
|
_define_property$1(SortControlDto, "_jsonSchema", void 0);
|
|
78
78
|
let SelectControlDto = class SelectControlDto$1 {
|
|
79
79
|
static toJsonSchema() {
|
|
80
|
-
return this._jsonSchema ?? (this._jsonSchema = (0,
|
|
80
|
+
return this._jsonSchema ?? (this._jsonSchema = (0, __atscript_typescript_utils.buildJsonSchema)(this));
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
_define_property$1(SelectControlDto, "__is_atscript_annotated_type", true);
|
|
84
84
|
_define_property$1(SelectControlDto, "type", {});
|
|
85
85
|
_define_property$1(SelectControlDto, "metadata", new Map());
|
|
86
86
|
_define_property$1(SelectControlDto, "_jsonSchema", void 0);
|
|
87
|
-
(0,
|
|
88
|
-
(0,
|
|
87
|
+
(0, __atscript_typescript_utils.defineAnnotatedType)("object", QueryControlsDto).prop("$skip", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("number").tags("positive", "int", "number").annotate("expect.min", 0).annotate("expect.int", true).optional().$type).prop("$limit", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("number").tags("positive", "int", "number").annotate("expect.min", 0).annotate("expect.int", true).optional().$type).prop("$count", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("boolean").tags("boolean").optional().$type).prop("$sort", (0, __atscript_typescript_utils.defineAnnotatedType)().refTo(SortControlDto).optional().$type).prop("$select", (0, __atscript_typescript_utils.defineAnnotatedType)().refTo(SelectControlDto).optional().$type).prop("$search", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").optional().$type).prop("$index", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").optional().$type);
|
|
88
|
+
(0, __atscript_typescript_utils.defineAnnotatedType)("object", PagesControlsDto).prop("$page", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").annotate("expect.pattern", {
|
|
89
89
|
pattern: "^\\d+$",
|
|
90
90
|
flags: "u",
|
|
91
91
|
message: "Expected positive number"
|
|
92
|
-
}, true).optional().$type).prop("$size", (0,
|
|
92
|
+
}, true).optional().$type).prop("$size", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").annotate("expect.pattern", {
|
|
93
93
|
pattern: "^\\d+$",
|
|
94
94
|
flags: "u",
|
|
95
95
|
message: "Expected positive number"
|
|
96
|
-
}, true).optional().$type).prop("$sort", (0,
|
|
97
|
-
(0,
|
|
98
|
-
(0,
|
|
99
|
-
(0,
|
|
96
|
+
}, true).optional().$type).prop("$sort", (0, __atscript_typescript_utils.defineAnnotatedType)().refTo(SortControlDto).optional().$type).prop("$select", (0, __atscript_typescript_utils.defineAnnotatedType)().refTo(SelectControlDto).optional().$type).prop("$search", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").optional().$type).prop("$index", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").optional().$type);
|
|
97
|
+
(0, __atscript_typescript_utils.defineAnnotatedType)("object", GetOneControlsDto).prop("$select", (0, __atscript_typescript_utils.defineAnnotatedType)().refTo(SelectControlDto).optional().$type);
|
|
98
|
+
(0, __atscript_typescript_utils.defineAnnotatedType)("object", SortControlDto).propPattern(/./, (0, __atscript_typescript_utils.defineAnnotatedType)("union").item((0, __atscript_typescript_utils.defineAnnotatedType)().designType("number").value(1).$type).item((0, __atscript_typescript_utils.defineAnnotatedType)().designType("number").value(-1).$type).$type);
|
|
99
|
+
(0, __atscript_typescript_utils.defineAnnotatedType)("object", SelectControlDto).propPattern(/./, (0, __atscript_typescript_utils.defineAnnotatedType)("union").item((0, __atscript_typescript_utils.defineAnnotatedType)().designType("number").value(1).$type).item((0, __atscript_typescript_utils.defineAnnotatedType)().designType("number").value(0).$type).$type);
|
|
100
100
|
|
|
101
101
|
//#endregion
|
|
102
102
|
//#region packages/moost-mongo/src/decorators.ts
|
|
103
103
|
const COLLECTION_DEF = "__atscript_mongo_collection_def";
|
|
104
|
-
const CollectionController = (type, prefix) =>
|
|
105
|
-
return (0, moost.ApplyDecorators)((0, moost.Provide)(COLLECTION_DEF, () => type), (0, moost.Controller)(prefix || type.metadata.get("mongo.collection") || type.name), (0, moost.Inherit)());
|
|
106
|
-
};
|
|
104
|
+
const CollectionController = (type, prefix) => (0, moost.ApplyDecorators)((0, moost.Provide)(COLLECTION_DEF, () => type), (0, moost.Controller)(prefix || type.metadata.get("mongo.collection") || type.name), (0, moost.Inherit)());
|
|
107
105
|
const InjectCollection = (type) => (0, moost.Resolve)(async ({ instantiate }) => {
|
|
108
106
|
const asMongo = await instantiate(__atscript_mongo.AsMongo);
|
|
109
107
|
return asMongo.getCollection(type);
|
|
@@ -167,7 +165,7 @@ var AsMongoController = class {
|
|
|
167
165
|
* @param controls - Controls object emitted by `urlql` parser.
|
|
168
166
|
* @returns Error message string or `undefined` (when valid). Can be async.
|
|
169
167
|
*/ validateQueryControls(controls) {
|
|
170
|
-
this.queryControlsValidator
|
|
168
|
+
this.queryControlsValidator?.validate(controls);
|
|
171
169
|
return undefined;
|
|
172
170
|
}
|
|
173
171
|
/**
|
|
@@ -176,7 +174,7 @@ var AsMongoController = class {
|
|
|
176
174
|
* @param controls - Controls object emitted by `urlql` parser.
|
|
177
175
|
* @returns Error message string or `undefined` (when valid). Can be async.
|
|
178
176
|
*/ validatePagesControls(controls) {
|
|
179
|
-
this.pagesControlsValidator
|
|
177
|
+
this.pagesControlsValidator?.validate(controls);
|
|
180
178
|
return undefined;
|
|
181
179
|
}
|
|
182
180
|
/**
|
|
@@ -185,7 +183,7 @@ var AsMongoController = class {
|
|
|
185
183
|
* @param controls - Controls object emitted by `urlql` parser.
|
|
186
184
|
* @returns Error message string or `undefined` (when valid). Can be async.
|
|
187
185
|
*/ validateGetOneControls(controls) {
|
|
188
|
-
this.getOneControlsValidator
|
|
186
|
+
this.getOneControlsValidator?.validate(controls);
|
|
189
187
|
return undefined;
|
|
190
188
|
}
|
|
191
189
|
/**
|
|
@@ -370,7 +368,7 @@ else if (this.asCollection.uniqueProps.size > 0) {
|
|
|
370
368
|
for (const prop of this.asCollection.uniqueProps) filter.push({ [prop]: id });
|
|
371
369
|
return this.returnOne(this.asCollection.collection.find(this.transformFilter({ $or: filter }), this.prepareQueryOptions(parsed.controls)).toArray());
|
|
372
370
|
}
|
|
373
|
-
if (idValidator) return new
|
|
371
|
+
if (idValidator) return new __atscript_typescript_utils.ValidatorError(idValidator.errors);
|
|
374
372
|
return new __moostjs_event_http.HttpError(500, "Unknown error");
|
|
375
373
|
}
|
|
376
374
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ 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, ValidatorError } from '@atscript/typescript';
|
|
5
|
+
import { TAtscriptAnnotatedTypeConstructor, Validator, ValidatorError } from '@atscript/typescript/utils';
|
|
6
6
|
import { Document, Filter, WithId, InsertOneResult, InsertManyResult, UpdateResult, DeleteResult, DeleteOptions, ObjectId, OptionalUnlessRequiredId, InsertOneOptions, BulkWriteOptions, WithoutId, ReplaceOptions, UpdateFilter, UpdateOptions } from 'mongodb';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -57,11 +57,11 @@ declare class AsMongoController<T extends TAtscriptAnnotatedTypeConstructor> {
|
|
|
57
57
|
private _pagesControlsValidator?;
|
|
58
58
|
private _getOneControlsValidator?;
|
|
59
59
|
/** Returns (and memoises) validator for *query* endpoint controls. */
|
|
60
|
-
protected get queryControlsValidator(): any;
|
|
60
|
+
protected get queryControlsValidator(): Validator<any> | undefined;
|
|
61
61
|
/** Returns (and memoises) validator for *pages* endpoint controls. */
|
|
62
|
-
protected get pagesControlsValidator(): any;
|
|
62
|
+
protected get pagesControlsValidator(): Validator<any> | undefined;
|
|
63
63
|
/** Returns (and memoises) validator for *one* endpoint controls. */
|
|
64
|
-
protected get getOneControlsValidator(): any;
|
|
64
|
+
protected get getOneControlsValidator(): Validator<any> | undefined;
|
|
65
65
|
/**
|
|
66
66
|
* Validates `$limit`, `$skip`, `$sort`, `$select`, `$count` controls for the
|
|
67
67
|
* **query** endpoint.
|
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, buildJsonSchema, defineAnnotatedType } from "@atscript/typescript";
|
|
4
|
+
import { ValidatorError, buildJsonSchema, 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
|
|
@@ -77,9 +77,7 @@ defineAnnotatedType("object", SelectControlDto).propPattern(/./, defineAnnotated
|
|
|
77
77
|
//#endregion
|
|
78
78
|
//#region packages/moost-mongo/src/decorators.ts
|
|
79
79
|
const COLLECTION_DEF = "__atscript_mongo_collection_def";
|
|
80
|
-
const CollectionController = (type, prefix) =>
|
|
81
|
-
return ApplyDecorators(Provide(COLLECTION_DEF, () => type), Controller(prefix || type.metadata.get("mongo.collection") || type.name), Inherit());
|
|
82
|
-
};
|
|
80
|
+
const CollectionController = (type, prefix) => ApplyDecorators(Provide(COLLECTION_DEF, () => type), Controller(prefix || type.metadata.get("mongo.collection") || type.name), Inherit());
|
|
83
81
|
const InjectCollection = (type) => Resolve(async ({ instantiate }) => {
|
|
84
82
|
const asMongo = await instantiate(AsMongo);
|
|
85
83
|
return asMongo.getCollection(type);
|
|
@@ -143,7 +141,7 @@ var AsMongoController = class {
|
|
|
143
141
|
* @param controls - Controls object emitted by `urlql` parser.
|
|
144
142
|
* @returns Error message string or `undefined` (when valid). Can be async.
|
|
145
143
|
*/ validateQueryControls(controls) {
|
|
146
|
-
this.queryControlsValidator
|
|
144
|
+
this.queryControlsValidator?.validate(controls);
|
|
147
145
|
return undefined;
|
|
148
146
|
}
|
|
149
147
|
/**
|
|
@@ -152,7 +150,7 @@ var AsMongoController = class {
|
|
|
152
150
|
* @param controls - Controls object emitted by `urlql` parser.
|
|
153
151
|
* @returns Error message string or `undefined` (when valid). Can be async.
|
|
154
152
|
*/ validatePagesControls(controls) {
|
|
155
|
-
this.pagesControlsValidator
|
|
153
|
+
this.pagesControlsValidator?.validate(controls);
|
|
156
154
|
return undefined;
|
|
157
155
|
}
|
|
158
156
|
/**
|
|
@@ -161,7 +159,7 @@ var AsMongoController = class {
|
|
|
161
159
|
* @param controls - Controls object emitted by `urlql` parser.
|
|
162
160
|
* @returns Error message string or `undefined` (when valid). Can be async.
|
|
163
161
|
*/ validateGetOneControls(controls) {
|
|
164
|
-
this.getOneControlsValidator
|
|
162
|
+
this.getOneControlsValidator?.validate(controls);
|
|
165
163
|
return undefined;
|
|
166
164
|
}
|
|
167
165
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/moost-mongo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
4
4
|
"description": "Atscript Mongo for Moost.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"@moostjs/event-http": "^0.5.32",
|
|
45
45
|
"mongodb": "^6.17.0",
|
|
46
46
|
"moost": "^0.5.32",
|
|
47
|
-
"@atscript/mongo": "^0.0.
|
|
48
|
-
"@atscript/typescript": "^0.0.
|
|
47
|
+
"@atscript/mongo": "^0.0.30",
|
|
48
|
+
"@atscript/typescript": "^0.0.30"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"pub": "pnpm publish --access public",
|