@atscript/moost-db 0.1.39 → 0.1.41
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/README.md +6 -6
- package/dist/index.cjs +329 -317
- package/dist/index.d.cts +204 -0
- package/dist/index.d.mts +204 -0
- package/dist/index.mjs +263 -228
- package/package.json +21 -14
- package/LICENSE +0 -21
- package/dist/index.d.ts +0 -200
package/dist/index.cjs
CHANGED
|
@@ -1,52 +1,78 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
-
get: ((k) => from[k]).bind(null, key),
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
-
value: mod,
|
|
21
|
-
enumerable: true
|
|
22
|
-
}) : target, mod));
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
const __atscript_typescript_utils = __toESM(require("@atscript/typescript/utils"));
|
|
26
|
-
const __moostjs_event_http = __toESM(require("@moostjs/event-http"));
|
|
27
|
-
const moost = __toESM(require("moost"));
|
|
28
|
-
const __uniqu_url = __toESM(require("@uniqu/url"));
|
|
29
|
-
const __atscript_db = __toESM(require("@atscript/db"));
|
|
30
|
-
|
|
31
|
-
//#region packages/moost-db/src/decorators.ts
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _atscript_typescript_utils = require("@atscript/typescript/utils");
|
|
3
|
+
let _moostjs_event_http = require("@moostjs/event-http");
|
|
4
|
+
let moost = require("moost");
|
|
5
|
+
let _uniqu_url = require("@uniqu/url");
|
|
6
|
+
let _atscript_db = require("@atscript/db");
|
|
7
|
+
//#region src/decorators.ts
|
|
8
|
+
/**
|
|
9
|
+
* DI token under which the {@link AtscriptDbReadable} instance
|
|
10
|
+
* is exposed to the readable controller's constructor via `@Inject`.
|
|
11
|
+
*/
|
|
32
12
|
const READABLE_DEF = "__atscript_db_readable_def";
|
|
13
|
+
/**
|
|
14
|
+
* DI token under which the {@link AtscriptDbTable} instance
|
|
15
|
+
* is exposed to the controller's constructor via `@Inject`.
|
|
16
|
+
* Points to the same token as READABLE_DEF for backward compatibility.
|
|
17
|
+
*/
|
|
33
18
|
const TABLE_DEF = READABLE_DEF;
|
|
19
|
+
/**
|
|
20
|
+
* Combines the boilerplate needed to turn an {@link AsDbController}
|
|
21
|
+
* subclass into a fully wired HTTP controller for a given `@db.table` model.
|
|
22
|
+
*
|
|
23
|
+
* Internally applies three decorators:
|
|
24
|
+
* 1. **Provide** — registers the table instance under {@link TABLE_DEF}.
|
|
25
|
+
* 2. **Controller** — registers the class as a Moost HTTP controller
|
|
26
|
+
* with an optional route prefix. Defaults to `table.tableName`.
|
|
27
|
+
* 3. **Inherit** — copies metadata (routes, guards, etc.) from the
|
|
28
|
+
* parent class so they stay active in the derived controller.
|
|
29
|
+
*
|
|
30
|
+
* @param table The {@link AtscriptDbTable} instance for this controller.
|
|
31
|
+
* @param prefix Optional route prefix. Defaults to `table.tableName`.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* @TableController(usersTable)
|
|
36
|
+
* export class UsersController extends AsDbController<typeof UserModel> {}
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
34
39
|
const TableController = (table, prefix) => (0, moost.ApplyDecorators)((0, moost.Provide)(TABLE_DEF, () => table), (0, moost.Controller)(prefix || table.tableName), (0, moost.Inherit)());
|
|
40
|
+
/**
|
|
41
|
+
* Combines the boilerplate needed to turn an {@link AsDbReadableController}
|
|
42
|
+
* subclass into a fully wired HTTP controller for a given `@db.view` or `@db.table` model.
|
|
43
|
+
*
|
|
44
|
+
* @param readable The {@link AtscriptDbReadable} instance (table or view).
|
|
45
|
+
* @param prefix Optional route prefix. Defaults to `readable.tableName`.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* @ReadableController(activeTasksView)
|
|
50
|
+
* export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
35
53
|
const ReadableController = (readable, prefix) => (0, moost.ApplyDecorators)((0, moost.Provide)(READABLE_DEF, () => readable), (0, moost.Controller)(prefix || readable.tableName), (0, moost.Inherit)());
|
|
54
|
+
/**
|
|
55
|
+
* Alias for {@link ReadableController} — use with view-backed controllers.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* @ViewController(activeTasksView)
|
|
60
|
+
* export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
36
63
|
const ViewController = ReadableController;
|
|
37
|
-
|
|
38
64
|
//#endregion
|
|
39
|
-
//#region
|
|
65
|
+
//#region src/validation-interceptor.ts
|
|
40
66
|
const dbErrorCodeToStatus = { CONFLICT: 409 };
|
|
41
67
|
function transformValidationError(error, reply) {
|
|
42
|
-
if (error instanceof
|
|
68
|
+
if (error instanceof _atscript_typescript_utils.ValidatorError) reply(new _moostjs_event_http.HttpError(400, {
|
|
43
69
|
message: error.message,
|
|
44
70
|
statusCode: 400,
|
|
45
71
|
errors: error.errors
|
|
46
72
|
}));
|
|
47
|
-
else if (error instanceof
|
|
73
|
+
else if (error instanceof _atscript_db.DbError) {
|
|
48
74
|
const statusCode = dbErrorCodeToStatus[error.code] ?? 400;
|
|
49
|
-
reply(new
|
|
75
|
+
reply(new _moostjs_event_http.HttpError(statusCode, {
|
|
50
76
|
message: error.message,
|
|
51
77
|
statusCode,
|
|
52
78
|
errors: error.errors
|
|
@@ -55,138 +81,151 @@ else if (error instanceof __atscript_db.DbError) {
|
|
|
55
81
|
}
|
|
56
82
|
const validationErrorTransform = () => (0, moost.defineInterceptor)({ error: transformValidationError }, moost.TInterceptorPriority.CATCH_ERROR);
|
|
57
83
|
const UseValidationErrorTransform = () => (0, moost.Intercept)(validationErrorTransform());
|
|
58
|
-
|
|
59
84
|
//#endregion
|
|
60
|
-
//#region
|
|
61
|
-
function _define_property$1(obj, key, value) {
|
|
62
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
63
|
-
value,
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true,
|
|
66
|
-
writable: true
|
|
67
|
-
});
|
|
68
|
-
else obj[key] = value;
|
|
69
|
-
return obj;
|
|
70
|
-
}
|
|
85
|
+
//#region src/dto/controls.dto.as
|
|
71
86
|
var QueryControlsDto = class {
|
|
87
|
+
static __is_atscript_annotated_type = true;
|
|
88
|
+
static type = {};
|
|
89
|
+
static metadata = /* @__PURE__ */ new Map();
|
|
90
|
+
static id = "QueryControlsDto";
|
|
72
91
|
static toJsonSchema() {
|
|
73
|
-
(0,
|
|
92
|
+
(0, _atscript_typescript_utils.throwFeatureDisabled)("JSON Schema", "jsonSchema", "emit.jsonSchema");
|
|
74
93
|
}
|
|
75
94
|
};
|
|
76
|
-
_define_property$1(QueryControlsDto, "__is_atscript_annotated_type", true);
|
|
77
|
-
_define_property$1(QueryControlsDto, "type", {});
|
|
78
|
-
_define_property$1(QueryControlsDto, "metadata", new Map());
|
|
79
|
-
_define_property$1(QueryControlsDto, "id", "QueryControlsDto");
|
|
80
95
|
var PagesControlsDto = class {
|
|
96
|
+
static __is_atscript_annotated_type = true;
|
|
97
|
+
static type = {};
|
|
98
|
+
static metadata = /* @__PURE__ */ new Map();
|
|
99
|
+
static id = "PagesControlsDto";
|
|
81
100
|
static toJsonSchema() {
|
|
82
|
-
(0,
|
|
101
|
+
(0, _atscript_typescript_utils.throwFeatureDisabled)("JSON Schema", "jsonSchema", "emit.jsonSchema");
|
|
83
102
|
}
|
|
84
103
|
};
|
|
85
|
-
_define_property$1(PagesControlsDto, "__is_atscript_annotated_type", true);
|
|
86
|
-
_define_property$1(PagesControlsDto, "type", {});
|
|
87
|
-
_define_property$1(PagesControlsDto, "metadata", new Map());
|
|
88
|
-
_define_property$1(PagesControlsDto, "id", "PagesControlsDto");
|
|
89
104
|
var GetOneControlsDto = class {
|
|
105
|
+
static __is_atscript_annotated_type = true;
|
|
106
|
+
static type = {};
|
|
107
|
+
static metadata = /* @__PURE__ */ new Map();
|
|
108
|
+
static id = "GetOneControlsDto";
|
|
90
109
|
static toJsonSchema() {
|
|
91
|
-
(0,
|
|
110
|
+
(0, _atscript_typescript_utils.throwFeatureDisabled)("JSON Schema", "jsonSchema", "emit.jsonSchema");
|
|
92
111
|
}
|
|
93
112
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
113
|
+
var WithRelationDto = class {
|
|
114
|
+
static __is_atscript_annotated_type = true;
|
|
115
|
+
static type = {};
|
|
116
|
+
static metadata = /* @__PURE__ */ new Map();
|
|
117
|
+
static id = "WithRelationDto";
|
|
99
118
|
static toJsonSchema() {
|
|
100
|
-
(0,
|
|
119
|
+
(0, _atscript_typescript_utils.throwFeatureDisabled)("JSON Schema", "jsonSchema", "emit.jsonSchema");
|
|
101
120
|
}
|
|
102
121
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
122
|
+
var WithRelationControlsDto = class {
|
|
123
|
+
static __is_atscript_annotated_type = true;
|
|
124
|
+
static type = {};
|
|
125
|
+
static metadata = /* @__PURE__ */ new Map();
|
|
126
|
+
static id = "WithRelationControlsDto";
|
|
108
127
|
static toJsonSchema() {
|
|
109
|
-
(0,
|
|
128
|
+
(0, _atscript_typescript_utils.throwFeatureDisabled)("JSON Schema", "jsonSchema", "emit.jsonSchema");
|
|
110
129
|
}
|
|
111
130
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
131
|
+
var WithFilterDto = class {
|
|
132
|
+
static __is_atscript_annotated_type = true;
|
|
133
|
+
static type = {};
|
|
134
|
+
static metadata = /* @__PURE__ */ new Map();
|
|
135
|
+
static id = "WithFilterDto";
|
|
117
136
|
static toJsonSchema() {
|
|
118
|
-
(0,
|
|
137
|
+
(0, _atscript_typescript_utils.throwFeatureDisabled)("JSON Schema", "jsonSchema", "emit.jsonSchema");
|
|
119
138
|
}
|
|
120
139
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
140
|
+
var SortControlDto = class {
|
|
141
|
+
static __is_atscript_annotated_type = true;
|
|
142
|
+
static type = {};
|
|
143
|
+
static metadata = /* @__PURE__ */ new Map();
|
|
144
|
+
static id = "SortControlDto";
|
|
126
145
|
static toJsonSchema() {
|
|
127
|
-
(0,
|
|
146
|
+
(0, _atscript_typescript_utils.throwFeatureDisabled)("JSON Schema", "jsonSchema", "emit.jsonSchema");
|
|
128
147
|
}
|
|
129
148
|
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
149
|
+
var SelectControlDto = class {
|
|
150
|
+
static __is_atscript_annotated_type = true;
|
|
151
|
+
static type = {};
|
|
152
|
+
static metadata = /* @__PURE__ */ new Map();
|
|
153
|
+
static id = "SelectControlDto";
|
|
135
154
|
static toJsonSchema() {
|
|
136
|
-
(0,
|
|
155
|
+
(0, _atscript_typescript_utils.throwFeatureDisabled)("JSON Schema", "jsonSchema", "emit.jsonSchema");
|
|
137
156
|
}
|
|
138
157
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
_define_property$1(SelectControlDto, "metadata", new Map());
|
|
142
|
-
_define_property$1(SelectControlDto, "id", "SelectControlDto");
|
|
143
|
-
(0, __atscript_typescript_utils.defineAnnotatedType)("object", QueryControlsDto).prop("$skip", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("number").tags("positive", "int", "number").annotate("expect.int", true).annotate("expect.min", { minValue: 0 }).optional().$type).prop("$limit", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("number").tags("positive", "int", "number").annotate("expect.int", true).annotate("expect.min", { minValue: 0 }).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)("union").item((0, __atscript_typescript_utils.defineAnnotatedType)().refTo(SelectControlDto).$type).item((0, __atscript_typescript_utils.defineAnnotatedType)("array").of((0, __atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").$type).$type).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).prop("$vector", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").optional().$type).prop("$threshold", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").optional().$type).prop("$with", (0, __atscript_typescript_utils.defineAnnotatedType)("array").of((0, __atscript_typescript_utils.defineAnnotatedType)().refTo(WithRelationDto).$type).optional().$type);
|
|
144
|
-
(0, __atscript_typescript_utils.defineAnnotatedType)("object", PagesControlsDto).prop("$page", (0, __atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").annotate("expect.pattern", {
|
|
158
|
+
(0, _atscript_typescript_utils.defineAnnotatedType)("object", QueryControlsDto).prop("$skip", (0, _atscript_typescript_utils.defineAnnotatedType)().designType("number").tags("positive", "int", "number").annotate("expect.int", true).annotate("expect.min", { minValue: 0 }).optional().$type).prop("$limit", (0, _atscript_typescript_utils.defineAnnotatedType)().designType("number").tags("positive", "int", "number").annotate("expect.int", true).annotate("expect.min", { minValue: 0 }).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)("union").item((0, _atscript_typescript_utils.defineAnnotatedType)().refTo(SelectControlDto).$type).item((0, _atscript_typescript_utils.defineAnnotatedType)("array").of((0, _atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").$type).$type).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).prop("$vector", (0, _atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").optional().$type).prop("$threshold", (0, _atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").optional().$type).prop("$with", (0, _atscript_typescript_utils.defineAnnotatedType)("array").of((0, _atscript_typescript_utils.defineAnnotatedType)().refTo(WithRelationDto).$type).optional().$type);
|
|
159
|
+
(0, _atscript_typescript_utils.defineAnnotatedType)("object", PagesControlsDto).prop("$page", (0, _atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").annotate("expect.pattern", {
|
|
145
160
|
pattern: "^\\d+$",
|
|
146
161
|
flags: "u",
|
|
147
162
|
message: "Expected positive number"
|
|
148
|
-
}, true).optional().$type).prop("$size", (0,
|
|
163
|
+
}, true).optional().$type).prop("$size", (0, _atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").annotate("expect.pattern", {
|
|
149
164
|
pattern: "^\\d+$",
|
|
150
165
|
flags: "u",
|
|
151
166
|
message: "Expected positive number"
|
|
152
|
-
}, true).optional().$type).prop("$sort", (0,
|
|
153
|
-
(0,
|
|
154
|
-
(0,
|
|
155
|
-
(0,
|
|
156
|
-
(0,
|
|
157
|
-
(0,
|
|
158
|
-
(0,
|
|
159
|
-
|
|
167
|
+
}, true).optional().$type).prop("$sort", (0, _atscript_typescript_utils.defineAnnotatedType)().refTo(SortControlDto).optional().$type).prop("$select", (0, _atscript_typescript_utils.defineAnnotatedType)("union").item((0, _atscript_typescript_utils.defineAnnotatedType)().refTo(SelectControlDto).$type).item((0, _atscript_typescript_utils.defineAnnotatedType)("array").of((0, _atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").$type).$type).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).prop("$vector", (0, _atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").optional().$type).prop("$threshold", (0, _atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").optional().$type).prop("$with", (0, _atscript_typescript_utils.defineAnnotatedType)("array").of((0, _atscript_typescript_utils.defineAnnotatedType)().refTo(WithRelationDto).$type).optional().$type);
|
|
168
|
+
(0, _atscript_typescript_utils.defineAnnotatedType)("object", GetOneControlsDto).prop("$select", (0, _atscript_typescript_utils.defineAnnotatedType)("union").item((0, _atscript_typescript_utils.defineAnnotatedType)().refTo(SelectControlDto).$type).item((0, _atscript_typescript_utils.defineAnnotatedType)("array").of((0, _atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").$type).$type).optional().$type).prop("$with", (0, _atscript_typescript_utils.defineAnnotatedType)("array").of((0, _atscript_typescript_utils.defineAnnotatedType)().refTo(WithRelationDto).$type).optional().$type);
|
|
169
|
+
(0, _atscript_typescript_utils.defineAnnotatedType)("object", WithRelationDto).prop("name", (0, _atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").$type).prop("filter", (0, _atscript_typescript_utils.defineAnnotatedType)().refTo(WithFilterDto).optional().$type).prop("controls", (0, _atscript_typescript_utils.defineAnnotatedType)().refTo(WithRelationControlsDto).optional().$type).prop("insights", (0, _atscript_typescript_utils.defineAnnotatedType)().refTo(WithFilterDto).optional().$type);
|
|
170
|
+
(0, _atscript_typescript_utils.defineAnnotatedType)("object", WithRelationControlsDto).prop("$skip", (0, _atscript_typescript_utils.defineAnnotatedType)().designType("number").tags("positive", "int", "number").annotate("expect.int", true).annotate("expect.min", { minValue: 0 }).optional().$type).prop("$limit", (0, _atscript_typescript_utils.defineAnnotatedType)().designType("number").tags("positive", "int", "number").annotate("expect.int", true).annotate("expect.min", { minValue: 0 }).optional().$type).prop("$sort", (0, _atscript_typescript_utils.defineAnnotatedType)().refTo(SortControlDto).optional().$type).prop("$select", (0, _atscript_typescript_utils.defineAnnotatedType)("union").item((0, _atscript_typescript_utils.defineAnnotatedType)().refTo(SelectControlDto).$type).item((0, _atscript_typescript_utils.defineAnnotatedType)("array").of((0, _atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").$type).$type).optional().$type).prop("$with", (0, _atscript_typescript_utils.defineAnnotatedType)("array").of((0, _atscript_typescript_utils.defineAnnotatedType)().refTo(WithRelationDto).$type).optional().$type);
|
|
171
|
+
(0, _atscript_typescript_utils.defineAnnotatedType)("object", WithFilterDto).propPattern(/./, (0, _atscript_typescript_utils.defineAnnotatedType)("union").item((0, _atscript_typescript_utils.defineAnnotatedType)().designType("string").tags("string").$type).item((0, _atscript_typescript_utils.defineAnnotatedType)().designType("number").tags("number").$type).item((0, _atscript_typescript_utils.defineAnnotatedType)().designType("boolean").tags("boolean").$type).item((0, _atscript_typescript_utils.defineAnnotatedType)().designType("null").tags("null").$type).item((0, _atscript_typescript_utils.defineAnnotatedType)().refTo(WithFilterDto).$type).item((0, _atscript_typescript_utils.defineAnnotatedType)("array").of((0, _atscript_typescript_utils.defineAnnotatedType)().refTo(WithFilterDto).$type).$type).$type);
|
|
172
|
+
(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);
|
|
173
|
+
(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);
|
|
160
174
|
//#endregion
|
|
161
|
-
//#region
|
|
162
|
-
function
|
|
163
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
164
|
-
value,
|
|
165
|
-
enumerable: true,
|
|
166
|
-
configurable: true,
|
|
167
|
-
writable: true
|
|
168
|
-
});
|
|
169
|
-
else obj[key] = value;
|
|
170
|
-
return obj;
|
|
171
|
-
}
|
|
172
|
-
function _ts_decorate$1(decorators, target, key, desc) {
|
|
173
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
174
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
175
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
176
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
177
|
-
}
|
|
178
|
-
function _ts_metadata$1(k, v) {
|
|
175
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/decorateMetadata.js
|
|
176
|
+
function __decorateMetadata(k, v) {
|
|
179
177
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
180
178
|
}
|
|
181
|
-
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/decorateParam.js
|
|
181
|
+
function __decorateParam(paramIndex, decorator) {
|
|
182
182
|
return function(target, key) {
|
|
183
183
|
decorator(target, key, paramIndex);
|
|
184
184
|
};
|
|
185
185
|
}
|
|
186
|
-
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/decorate.js
|
|
188
|
+
function __decorate(decorators, target, key, desc) {
|
|
189
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
190
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
191
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
192
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/as-db-readable.controller.ts
|
|
196
|
+
var _ref$1, _ref2$1;
|
|
197
|
+
let AsDbReadableController = class AsDbReadableController {
|
|
198
|
+
/** Reference to the underlying readable (table or view). */
|
|
199
|
+
readable;
|
|
200
|
+
/** Application-scoped logger. */
|
|
201
|
+
logger;
|
|
202
|
+
/** Cached serialized type definition (static, computed once). */
|
|
203
|
+
_serializedType;
|
|
204
|
+
/** Cached search index list (static, computed once). */
|
|
205
|
+
_searchIndexes;
|
|
206
|
+
constructor(readable, app) {
|
|
207
|
+
this.readable = readable;
|
|
208
|
+
this._serializedType = (0, _atscript_typescript_utils.serializeAnnotatedType)(readable.type);
|
|
209
|
+
this._searchIndexes = readable.getSearchIndexes();
|
|
210
|
+
this.logger = app.getLogger(`db [${readable.tableName}]`);
|
|
211
|
+
this.logger.info(`Initializing ${readable.isView ? "view" : "table"} controller`);
|
|
212
|
+
try {
|
|
213
|
+
const p = this.init();
|
|
214
|
+
if (p instanceof Promise) p.catch((error) => {
|
|
215
|
+
this.logger.error(error);
|
|
216
|
+
});
|
|
217
|
+
} catch (error) {
|
|
218
|
+
this.logger.error(error);
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
187
222
|
/**
|
|
188
223
|
* One-time initialization hook. Override to seed data, register watchers, etc.
|
|
189
|
-
*/
|
|
224
|
+
*/
|
|
225
|
+
init() {}
|
|
226
|
+
_queryControlsValidator;
|
|
227
|
+
_pagesControlsValidator;
|
|
228
|
+
_getOneControlsValidator;
|
|
190
229
|
get queryControlsValidator() {
|
|
191
230
|
if (!this._queryControlsValidator) this._queryControlsValidator = QueryControlsDto.validator();
|
|
192
231
|
return this._queryControlsValidator;
|
|
@@ -202,26 +241,24 @@ var AsDbReadableController = class {
|
|
|
202
241
|
validateControls(controls, type) {
|
|
203
242
|
const v = type === "query" ? this.queryControlsValidator : type === "pages" ? this.pagesControlsValidator : this.getOneControlsValidator;
|
|
204
243
|
if (!v.validate(controls, true)) return v.errors[0]?.message || "Invalid controls";
|
|
205
|
-
return undefined;
|
|
206
244
|
}
|
|
207
245
|
validateInsights(insights) {
|
|
208
246
|
for (const [key] of insights) {
|
|
209
247
|
if (key === "*") continue;
|
|
210
248
|
if (!this.readable.flatMap.has(key)) return `Unknown field "${key}"`;
|
|
211
249
|
}
|
|
212
|
-
return undefined;
|
|
213
250
|
}
|
|
214
251
|
validateParsed(parsed, type) {
|
|
215
252
|
const controlsError = this.validateControls(parsed.controls, type);
|
|
216
|
-
if (controlsError) return new
|
|
253
|
+
if (controlsError) return new _moostjs_event_http.HttpError(400, controlsError);
|
|
217
254
|
if (parsed.insights) {
|
|
218
255
|
const insightsError = this.validateInsights(parsed.insights);
|
|
219
|
-
if (insightsError) return new
|
|
256
|
+
if (insightsError) return new _moostjs_event_http.HttpError(400, insightsError);
|
|
220
257
|
}
|
|
221
258
|
const withRelations = parsed.controls.$with;
|
|
222
259
|
if (withRelations?.length) {
|
|
223
260
|
const relations = this.readable.relations;
|
|
224
|
-
for (const rel of withRelations) if (!rel.name.includes(".") && !relations.has(rel.name)) return new
|
|
261
|
+
for (const rel of withRelations) if (!rel.name.includes(".") && !relations.has(rel.name)) return new _moostjs_event_http.HttpError(400, {
|
|
225
262
|
message: `Unknown relation "${rel.name}" in $with. Available relations: ${[...relations.keys()].join(", ") || "(none)"}`,
|
|
226
263
|
statusCode: 400,
|
|
227
264
|
errors: [{
|
|
@@ -230,44 +267,47 @@ var AsDbReadableController = class {
|
|
|
230
267
|
}]
|
|
231
268
|
});
|
|
232
269
|
}
|
|
233
|
-
return undefined;
|
|
234
270
|
}
|
|
235
271
|
/**
|
|
236
272
|
* Compute an embedding vector from a search term.
|
|
237
273
|
* Override in subclass to integrate with your embedding provider (OpenAI, etc.).
|
|
238
274
|
* Called when `$vector` is present in query controls.
|
|
239
|
-
*/
|
|
240
|
-
|
|
275
|
+
*/
|
|
276
|
+
computeEmbedding(_search, _fieldName) {
|
|
277
|
+
throw new _moostjs_event_http.HttpError(501, "Vector search requires computeEmbedding() to be implemented");
|
|
241
278
|
}
|
|
242
279
|
/**
|
|
243
280
|
* Transform filter before querying. Override to add tenant filtering, etc.
|
|
244
|
-
*/
|
|
281
|
+
*/
|
|
282
|
+
transformFilter(filter) {
|
|
245
283
|
return filter;
|
|
246
284
|
}
|
|
247
285
|
/**
|
|
248
286
|
* Transform projection before querying.
|
|
249
|
-
*/
|
|
287
|
+
*/
|
|
288
|
+
transformProjection(projection) {
|
|
250
289
|
return projection;
|
|
251
290
|
}
|
|
252
291
|
parseQueryString(url) {
|
|
253
292
|
const idx = url.indexOf("?");
|
|
254
|
-
return (0,
|
|
293
|
+
return (0, _uniqu_url.parseUrl)(idx >= 0 ? url.slice(idx + 1) : "");
|
|
255
294
|
}
|
|
256
295
|
async returnOne(result) {
|
|
257
296
|
const item = await result;
|
|
258
|
-
if (!item) return new
|
|
297
|
+
if (!item) return new _moostjs_event_http.HttpError(404);
|
|
259
298
|
return item;
|
|
260
299
|
}
|
|
261
300
|
/**
|
|
262
301
|
* Extracts a composite identifier object from query params.
|
|
263
302
|
* Tries composite primary key first, then compound unique indexes.
|
|
264
|
-
*/
|
|
303
|
+
*/
|
|
304
|
+
extractCompositeId(query) {
|
|
265
305
|
const pkFields = this.readable.primaryKeys;
|
|
266
306
|
if (pkFields.length > 1) {
|
|
267
307
|
const idObj = {};
|
|
268
308
|
let allPresent = true;
|
|
269
309
|
for (const field of pkFields) {
|
|
270
|
-
if (query[field] ===
|
|
310
|
+
if (query[field] === void 0) {
|
|
271
311
|
allPresent = false;
|
|
272
312
|
break;
|
|
273
313
|
}
|
|
@@ -280,7 +320,7 @@ var AsDbReadableController = class {
|
|
|
280
320
|
const idObj = {};
|
|
281
321
|
let allPresent = true;
|
|
282
322
|
for (const indexField of index.fields) {
|
|
283
|
-
if (query[indexField.name] ===
|
|
323
|
+
if (query[indexField.name] === void 0) {
|
|
284
324
|
allPresent = false;
|
|
285
325
|
break;
|
|
286
326
|
}
|
|
@@ -288,23 +328,23 @@ var AsDbReadableController = class {
|
|
|
288
328
|
}
|
|
289
329
|
if (allPresent) return idObj;
|
|
290
330
|
}
|
|
291
|
-
return new
|
|
331
|
+
return new _moostjs_event_http.HttpError(400, "Query params do not match any composite primary key or compound unique index");
|
|
292
332
|
}
|
|
293
333
|
/**
|
|
294
334
|
* **GET /query** — returns an array of records or a count.
|
|
295
|
-
*/
|
|
335
|
+
*/
|
|
336
|
+
async query(url) {
|
|
296
337
|
const parsed = this.parseQueryString(url);
|
|
297
338
|
const controls = parsed.controls;
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
if (controls.$with?.length) return new __moostjs_event_http.HttpError(400, "Cannot combine $with and $groupBy in the same query");
|
|
339
|
+
if (controls.$groupBy?.length) {
|
|
340
|
+
if (controls.$with?.length) return new _moostjs_event_http.HttpError(400, "Cannot combine $with and $groupBy in the same query");
|
|
301
341
|
if (parsed.insights) {
|
|
302
342
|
const insightsError = this.validateInsights(parsed.insights);
|
|
303
|
-
if (insightsError) return new
|
|
343
|
+
if (insightsError) return new _moostjs_event_http.HttpError(400, insightsError);
|
|
304
344
|
}
|
|
305
|
-
const filter
|
|
345
|
+
const filter = this.transformFilter(parsed.filter);
|
|
306
346
|
return this.readable.aggregate({
|
|
307
|
-
filter
|
|
347
|
+
filter,
|
|
308
348
|
controls,
|
|
309
349
|
insights: parsed.insights
|
|
310
350
|
});
|
|
@@ -323,7 +363,7 @@ var AsDbReadableController = class {
|
|
|
323
363
|
const searchTerm = controls.$search;
|
|
324
364
|
const indexName = controls.$index;
|
|
325
365
|
const vectorField = controls.$vector;
|
|
326
|
-
const threshold = controls.$threshold ? Number(controls.$threshold) :
|
|
366
|
+
const threshold = controls.$threshold ? Number(controls.$threshold) : void 0;
|
|
327
367
|
const queryObj = {
|
|
328
368
|
filter,
|
|
329
369
|
controls: {
|
|
@@ -333,8 +373,8 @@ var AsDbReadableController = class {
|
|
|
333
373
|
$threshold: threshold
|
|
334
374
|
}
|
|
335
375
|
};
|
|
336
|
-
if (vectorField !==
|
|
337
|
-
const vector = await this.computeEmbedding(searchTerm, vectorField ||
|
|
376
|
+
if (vectorField !== void 0 && searchTerm) {
|
|
377
|
+
const vector = await this.computeEmbedding(searchTerm, vectorField || void 0);
|
|
338
378
|
if (vectorField) return this.readable.vectorSearch(vectorField, vector, queryObj);
|
|
339
379
|
return this.readable.vectorSearch(vector, queryObj);
|
|
340
380
|
}
|
|
@@ -343,7 +383,8 @@ var AsDbReadableController = class {
|
|
|
343
383
|
}
|
|
344
384
|
/**
|
|
345
385
|
* **GET /pages** — returns paginated records with metadata.
|
|
346
|
-
*/
|
|
386
|
+
*/
|
|
387
|
+
async pages(url) {
|
|
347
388
|
const parsed = this.parseQueryString(url);
|
|
348
389
|
const error = this.validateParsed(parsed, "pages");
|
|
349
390
|
if (error) return error;
|
|
@@ -356,7 +397,7 @@ var AsDbReadableController = class {
|
|
|
356
397
|
const searchTerm = controls.$search;
|
|
357
398
|
const indexName = controls.$index;
|
|
358
399
|
const vectorField = controls.$vector;
|
|
359
|
-
const threshold = controls.$threshold ? Number(controls.$threshold) :
|
|
400
|
+
const threshold = controls.$threshold ? Number(controls.$threshold) : void 0;
|
|
360
401
|
const query = {
|
|
361
402
|
filter,
|
|
362
403
|
controls: {
|
|
@@ -368,12 +409,12 @@ var AsDbReadableController = class {
|
|
|
368
409
|
}
|
|
369
410
|
};
|
|
370
411
|
let result;
|
|
371
|
-
if (vectorField !==
|
|
372
|
-
const vector = await this.computeEmbedding(searchTerm, vectorField ||
|
|
412
|
+
if (vectorField !== void 0 && searchTerm) {
|
|
413
|
+
const vector = await this.computeEmbedding(searchTerm, vectorField || void 0);
|
|
373
414
|
if (vectorField) result = await this.readable.vectorSearchWithCount(vectorField, vector, query);
|
|
374
|
-
else result = await this.readable.vectorSearchWithCount(vector, query);
|
|
415
|
+
else result = await this.readable.vectorSearchWithCount(vector, query);
|
|
375
416
|
} else if (searchTerm && this.readable.isSearchable()) result = await this.readable.searchWithCount(searchTerm, query, indexName);
|
|
376
|
-
else result = await this.readable.findManyWithCount(query);
|
|
417
|
+
else result = await this.readable.findManyWithCount(query);
|
|
377
418
|
return {
|
|
378
419
|
data: result.data,
|
|
379
420
|
page,
|
|
@@ -384,9 +425,10 @@ else result = await this.readable.findManyWithCount(query);
|
|
|
384
425
|
}
|
|
385
426
|
/**
|
|
386
427
|
* **GET /one/:id** — retrieves a single record by ID or unique property.
|
|
387
|
-
*/
|
|
428
|
+
*/
|
|
429
|
+
async getOne(id, url) {
|
|
388
430
|
const parsed = this.parseQueryString(url);
|
|
389
|
-
if (Object.keys(parsed.filter).length > 0) return new
|
|
431
|
+
if (Object.keys(parsed.filter).length > 0) return new _moostjs_event_http.HttpError(400, "Filtering is not allowed for \"one\" endpoint");
|
|
390
432
|
const error = this.validateParsed(parsed, "getOne");
|
|
391
433
|
if (error) return error;
|
|
392
434
|
const select = this.transformProjection(parsed.controls.$select);
|
|
@@ -399,9 +441,10 @@ else result = await this.readable.findManyWithCount(query);
|
|
|
399
441
|
/**
|
|
400
442
|
* **GET /one?field1=val1&field2=val2** — retrieves a single record by composite key
|
|
401
443
|
* (composite primary key or compound unique index).
|
|
402
|
-
*/
|
|
444
|
+
*/
|
|
445
|
+
async getOneComposite(query, url) {
|
|
403
446
|
const idObj = this.extractCompositeId(query);
|
|
404
|
-
if (idObj instanceof
|
|
447
|
+
if (idObj instanceof _moostjs_event_http.HttpError) return idObj;
|
|
405
448
|
const parsed = this.parseQueryString(url);
|
|
406
449
|
const select = this.transformProjection(parsed.controls.$select);
|
|
407
450
|
const controls = {
|
|
@@ -412,7 +455,8 @@ else result = await this.readable.findManyWithCount(query);
|
|
|
412
455
|
}
|
|
413
456
|
/**
|
|
414
457
|
* **GET /meta** — returns table/view metadata for UI.
|
|
415
|
-
*/
|
|
458
|
+
*/
|
|
459
|
+
meta() {
|
|
416
460
|
return {
|
|
417
461
|
searchable: this.readable.isSearchable(),
|
|
418
462
|
vectorSearchable: this.readable.isVectorSearchable(),
|
|
@@ -420,223 +464,191 @@ else result = await this.readable.findManyWithCount(query);
|
|
|
420
464
|
type: this._serializedType
|
|
421
465
|
};
|
|
422
466
|
}
|
|
423
|
-
constructor(readable, app) {
|
|
424
|
-
/** Reference to the underlying readable (table or view). */ _define_property(this, "readable", void 0);
|
|
425
|
-
/** Application-scoped logger. */ _define_property(this, "logger", void 0);
|
|
426
|
-
/** Cached serialized type definition (static, computed once). */ _define_property(this, "_serializedType", void 0);
|
|
427
|
-
/** Cached search index list (static, computed once). */ _define_property(this, "_searchIndexes", void 0);
|
|
428
|
-
_define_property(this, "_queryControlsValidator", void 0);
|
|
429
|
-
_define_property(this, "_pagesControlsValidator", void 0);
|
|
430
|
-
_define_property(this, "_getOneControlsValidator", void 0);
|
|
431
|
-
this.readable = readable;
|
|
432
|
-
this._serializedType = (0, __atscript_typescript_utils.serializeAnnotatedType)(readable.type);
|
|
433
|
-
this._searchIndexes = readable.getSearchIndexes();
|
|
434
|
-
this.logger = app.getLogger(`db [${readable.tableName}]`);
|
|
435
|
-
this.logger.info(`Initializing ${readable.isView ? "view" : "table"} controller`);
|
|
436
|
-
try {
|
|
437
|
-
const p = this.init();
|
|
438
|
-
if (p instanceof Promise) p.catch((error) => {
|
|
439
|
-
this.logger.error(error);
|
|
440
|
-
});
|
|
441
|
-
} catch (error) {
|
|
442
|
-
this.logger.error(error);
|
|
443
|
-
throw error;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
467
|
};
|
|
447
|
-
|
|
448
|
-
(0,
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
468
|
+
__decorate([
|
|
469
|
+
(0, _moostjs_event_http.Get)("query"),
|
|
470
|
+
__decorateParam(0, (0, _moostjs_event_http.Url)()),
|
|
471
|
+
__decorateMetadata("design:type", Function),
|
|
472
|
+
__decorateMetadata("design:paramtypes", [String]),
|
|
473
|
+
__decorateMetadata("design:returntype", Promise)
|
|
453
474
|
], AsDbReadableController.prototype, "query", null);
|
|
454
|
-
|
|
455
|
-
(0,
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
475
|
+
__decorate([
|
|
476
|
+
(0, _moostjs_event_http.Get)("pages"),
|
|
477
|
+
__decorateParam(0, (0, _moostjs_event_http.Url)()),
|
|
478
|
+
__decorateMetadata("design:type", Function),
|
|
479
|
+
__decorateMetadata("design:paramtypes", [String]),
|
|
480
|
+
__decorateMetadata("design:returntype", Promise)
|
|
460
481
|
], AsDbReadableController.prototype, "pages", null);
|
|
461
|
-
|
|
462
|
-
(0,
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
482
|
+
__decorate([
|
|
483
|
+
(0, _moostjs_event_http.Get)("one/:id"),
|
|
484
|
+
__decorateParam(0, (0, moost.Param)("id")),
|
|
485
|
+
__decorateParam(1, (0, _moostjs_event_http.Url)()),
|
|
486
|
+
__decorateMetadata("design:type", Function),
|
|
487
|
+
__decorateMetadata("design:paramtypes", [String, String]),
|
|
488
|
+
__decorateMetadata("design:returntype", Promise)
|
|
468
489
|
], AsDbReadableController.prototype, "getOne", null);
|
|
469
|
-
|
|
470
|
-
(0,
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
490
|
+
__decorate([
|
|
491
|
+
(0, _moostjs_event_http.Get)("one"),
|
|
492
|
+
__decorateParam(0, (0, _moostjs_event_http.Query)()),
|
|
493
|
+
__decorateParam(1, (0, _moostjs_event_http.Url)()),
|
|
494
|
+
__decorateMetadata("design:type", Function),
|
|
495
|
+
__decorateMetadata("design:paramtypes", [typeof (_ref2$1 = typeof Record !== "undefined" && Record) === "function" ? _ref2$1 : Object, String]),
|
|
496
|
+
__decorateMetadata("design:returntype", Promise)
|
|
476
497
|
], AsDbReadableController.prototype, "getOneComposite", null);
|
|
477
|
-
|
|
478
|
-
(0,
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
498
|
+
__decorate([
|
|
499
|
+
(0, _moostjs_event_http.Get)("meta"),
|
|
500
|
+
__decorateMetadata("design:type", Function),
|
|
501
|
+
__decorateMetadata("design:paramtypes", []),
|
|
502
|
+
__decorateMetadata("design:returntype", void 0)
|
|
482
503
|
], AsDbReadableController.prototype, "meta", null);
|
|
483
|
-
AsDbReadableController =
|
|
504
|
+
AsDbReadableController = __decorate([
|
|
484
505
|
UseValidationErrorTransform(),
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
_ts_metadata$1("design:paramtypes", [typeof AtscriptDbReadable === "undefined" ? Object : AtscriptDbReadable, typeof moost.Moost === "undefined" ? Object : moost.Moost])
|
|
506
|
+
__decorateParam(0, (0, moost.Inject)(READABLE_DEF)),
|
|
507
|
+
__decorateMetadata("design:paramtypes", [Object, typeof (_ref$1 = typeof moost.Moost !== "undefined" && moost.Moost) === "function" ? _ref$1 : Object])
|
|
488
508
|
], AsDbReadableController);
|
|
489
|
-
|
|
490
509
|
//#endregion
|
|
491
|
-
//#region
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
497
|
-
}
|
|
498
|
-
function _ts_metadata(k, v) {
|
|
499
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
500
|
-
}
|
|
501
|
-
function _ts_param(paramIndex, decorator) {
|
|
502
|
-
return function(target, key) {
|
|
503
|
-
decorator(target, key, paramIndex);
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
var AsDbController = class extends AsDbReadableController {
|
|
507
|
-
/** Reference to the underlying table (typed for write access). */ get table() {
|
|
510
|
+
//#region src/as-db.controller.ts
|
|
511
|
+
var _ref, _ref2;
|
|
512
|
+
let AsDbController = class AsDbController extends AsDbReadableController {
|
|
513
|
+
/** Reference to the underlying table (typed for write access). */
|
|
514
|
+
get table() {
|
|
508
515
|
return this.readable;
|
|
509
516
|
}
|
|
517
|
+
constructor(table, app) {
|
|
518
|
+
super(table, app);
|
|
519
|
+
}
|
|
510
520
|
/**
|
|
511
521
|
* Intercepts write operations. Return `undefined` to abort.
|
|
512
|
-
*/
|
|
522
|
+
*/
|
|
523
|
+
onWrite(action, data) {
|
|
513
524
|
return data;
|
|
514
525
|
}
|
|
515
526
|
/**
|
|
516
527
|
* Intercepts delete operations. Return `undefined` to abort.
|
|
517
|
-
*/
|
|
528
|
+
*/
|
|
529
|
+
onRemove(id) {
|
|
518
530
|
return id;
|
|
519
531
|
}
|
|
520
532
|
/**
|
|
521
533
|
* **POST /** — inserts one or many records.
|
|
522
|
-
*/
|
|
534
|
+
*/
|
|
535
|
+
async insert(payload) {
|
|
523
536
|
if (Array.isArray(payload)) {
|
|
524
|
-
const data
|
|
525
|
-
if (data
|
|
526
|
-
return await this.table.insertMany(data
|
|
537
|
+
const data = await this.onWrite("insertMany", payload);
|
|
538
|
+
if (data === void 0) return new _moostjs_event_http.HttpError(500, "Not saved");
|
|
539
|
+
return await this.table.insertMany(data);
|
|
527
540
|
}
|
|
528
541
|
const data = await this.onWrite("insert", payload);
|
|
529
|
-
if (data ===
|
|
542
|
+
if (data === void 0) return new _moostjs_event_http.HttpError(500, "Not saved");
|
|
530
543
|
return await this.table.insertOne(data);
|
|
531
544
|
}
|
|
532
545
|
/**
|
|
533
546
|
* **PUT /** — fully replaces one or many records matched by primary key.
|
|
534
|
-
*/
|
|
547
|
+
*/
|
|
548
|
+
async replace(payload) {
|
|
535
549
|
if (Array.isArray(payload)) {
|
|
536
|
-
const data
|
|
537
|
-
if (data
|
|
538
|
-
return await this.table.bulkReplace(data
|
|
550
|
+
const data = await this.onWrite("replaceMany", payload);
|
|
551
|
+
if (data === void 0) return new _moostjs_event_http.HttpError(500, "Not saved");
|
|
552
|
+
return await this.table.bulkReplace(data);
|
|
539
553
|
}
|
|
540
554
|
const data = await this.onWrite("replace", payload);
|
|
541
|
-
if (data ===
|
|
555
|
+
if (data === void 0) return new _moostjs_event_http.HttpError(500, "Not saved");
|
|
542
556
|
return await this.table.replaceOne(data);
|
|
543
557
|
}
|
|
544
558
|
/**
|
|
545
559
|
* **PATCH /** — partially updates one or many records matched by primary key.
|
|
546
|
-
*/
|
|
560
|
+
*/
|
|
561
|
+
async update(payload) {
|
|
547
562
|
if (Array.isArray(payload)) {
|
|
548
|
-
const data
|
|
549
|
-
if (data
|
|
550
|
-
return await this.table.bulkUpdate(data
|
|
563
|
+
const data = await this.onWrite("updateMany", payload);
|
|
564
|
+
if (data === void 0) return new _moostjs_event_http.HttpError(500, "Not saved");
|
|
565
|
+
return await this.table.bulkUpdate(data);
|
|
551
566
|
}
|
|
552
567
|
const data = await this.onWrite("update", payload);
|
|
553
|
-
if (data ===
|
|
568
|
+
if (data === void 0) return new _moostjs_event_http.HttpError(500, "Not saved");
|
|
554
569
|
return await this.table.updateOne(data);
|
|
555
570
|
}
|
|
556
571
|
/**
|
|
557
572
|
* **DELETE /:id** — removes a single record by primary key.
|
|
558
|
-
*/
|
|
573
|
+
*/
|
|
574
|
+
async remove(id) {
|
|
559
575
|
const resolvedId = await this.onRemove(id);
|
|
560
|
-
if (resolvedId ===
|
|
576
|
+
if (resolvedId === void 0) return new _moostjs_event_http.HttpError(500, "Not deleted");
|
|
561
577
|
const result = await this.table.deleteOne(resolvedId);
|
|
562
|
-
if (result.deletedCount < 1) return new
|
|
578
|
+
if (result.deletedCount < 1) return new _moostjs_event_http.HttpError(404);
|
|
563
579
|
return result;
|
|
564
580
|
}
|
|
565
581
|
/**
|
|
566
582
|
* **DELETE /?field1=val1&field2=val2** — removes a record by composite key
|
|
567
583
|
* (composite primary key or compound unique index).
|
|
568
|
-
*/
|
|
584
|
+
*/
|
|
585
|
+
async removeComposite(query) {
|
|
569
586
|
const idObj = this.extractCompositeId(query);
|
|
570
|
-
if (idObj instanceof
|
|
587
|
+
if (idObj instanceof _moostjs_event_http.HttpError) return idObj;
|
|
571
588
|
const resolvedId = await this.onRemove(idObj);
|
|
572
|
-
if (resolvedId ===
|
|
589
|
+
if (resolvedId === void 0) return new _moostjs_event_http.HttpError(500, "Not deleted");
|
|
573
590
|
const result = await this.table.deleteOne(resolvedId);
|
|
574
|
-
if (result.deletedCount < 1) return new
|
|
591
|
+
if (result.deletedCount < 1) return new _moostjs_event_http.HttpError(404);
|
|
575
592
|
return result;
|
|
576
593
|
}
|
|
577
|
-
constructor(table, app) {
|
|
578
|
-
super(table, app);
|
|
579
|
-
}
|
|
580
594
|
};
|
|
581
|
-
|
|
582
|
-
(0,
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
595
|
+
__decorate([
|
|
596
|
+
(0, _moostjs_event_http.Post)(""),
|
|
597
|
+
__decorateParam(0, (0, _moostjs_event_http.Body)()),
|
|
598
|
+
__decorateMetadata("design:type", Function),
|
|
599
|
+
__decorateMetadata("design:paramtypes", [Object]),
|
|
600
|
+
__decorateMetadata("design:returntype", Promise)
|
|
587
601
|
], AsDbController.prototype, "insert", null);
|
|
588
|
-
|
|
589
|
-
(0,
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
602
|
+
__decorate([
|
|
603
|
+
(0, _moostjs_event_http.Put)(""),
|
|
604
|
+
__decorateParam(0, (0, _moostjs_event_http.Body)()),
|
|
605
|
+
__decorateMetadata("design:type", Function),
|
|
606
|
+
__decorateMetadata("design:paramtypes", [Object]),
|
|
607
|
+
__decorateMetadata("design:returntype", Promise)
|
|
594
608
|
], AsDbController.prototype, "replace", null);
|
|
595
|
-
|
|
596
|
-
(0,
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
609
|
+
__decorate([
|
|
610
|
+
(0, _moostjs_event_http.Patch)(""),
|
|
611
|
+
__decorateParam(0, (0, _moostjs_event_http.Body)()),
|
|
612
|
+
__decorateMetadata("design:type", Function),
|
|
613
|
+
__decorateMetadata("design:paramtypes", [Object]),
|
|
614
|
+
__decorateMetadata("design:returntype", Promise)
|
|
601
615
|
], AsDbController.prototype, "update", null);
|
|
602
|
-
|
|
603
|
-
(0,
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
616
|
+
__decorate([
|
|
617
|
+
(0, _moostjs_event_http.Delete)(":id"),
|
|
618
|
+
__decorateParam(0, (0, moost.Param)("id")),
|
|
619
|
+
__decorateMetadata("design:type", Function),
|
|
620
|
+
__decorateMetadata("design:paramtypes", [String]),
|
|
621
|
+
__decorateMetadata("design:returntype", Promise)
|
|
608
622
|
], AsDbController.prototype, "remove", null);
|
|
609
|
-
|
|
610
|
-
(0,
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
623
|
+
__decorate([
|
|
624
|
+
(0, _moostjs_event_http.Delete)(""),
|
|
625
|
+
__decorateParam(0, (0, _moostjs_event_http.Query)()),
|
|
626
|
+
__decorateMetadata("design:type", Function),
|
|
627
|
+
__decorateMetadata("design:paramtypes", [typeof (_ref2 = typeof Record !== "undefined" && Record) === "function" ? _ref2 : Object]),
|
|
628
|
+
__decorateMetadata("design:returntype", Promise)
|
|
615
629
|
], AsDbController.prototype, "removeComposite", null);
|
|
616
|
-
AsDbController =
|
|
630
|
+
AsDbController = __decorate([
|
|
617
631
|
(0, moost.Inherit)(),
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
_ts_metadata("design:paramtypes", [typeof AtscriptDbTable === "undefined" ? Object : AtscriptDbTable, typeof moost.Moost === "undefined" ? Object : moost.Moost])
|
|
632
|
+
__decorateParam(0, (0, moost.Inject)(TABLE_DEF)),
|
|
633
|
+
__decorateMetadata("design:paramtypes", [Object, typeof (_ref = typeof moost.Moost !== "undefined" && moost.Moost) === "function" ? _ref : Object])
|
|
621
634
|
], AsDbController);
|
|
622
|
-
|
|
623
635
|
//#endregion
|
|
624
|
-
Object.defineProperty(exports,
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
636
|
+
Object.defineProperty(exports, "AsDbController", {
|
|
637
|
+
enumerable: true,
|
|
638
|
+
get: function() {
|
|
639
|
+
return AsDbController;
|
|
640
|
+
}
|
|
629
641
|
});
|
|
630
|
-
Object.defineProperty(exports,
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
642
|
+
Object.defineProperty(exports, "AsDbReadableController", {
|
|
643
|
+
enumerable: true,
|
|
644
|
+
get: function() {
|
|
645
|
+
return AsDbReadableController;
|
|
646
|
+
}
|
|
635
647
|
});
|
|
636
|
-
exports.READABLE_DEF = READABLE_DEF
|
|
637
|
-
exports.ReadableController = ReadableController
|
|
638
|
-
exports.TABLE_DEF = TABLE_DEF
|
|
639
|
-
exports.TableController = TableController
|
|
640
|
-
exports.UseValidationErrorTransform = UseValidationErrorTransform
|
|
641
|
-
exports.ViewController = ViewController
|
|
642
|
-
exports.validationErrorTransform = validationErrorTransform
|
|
648
|
+
exports.READABLE_DEF = READABLE_DEF;
|
|
649
|
+
exports.ReadableController = ReadableController;
|
|
650
|
+
exports.TABLE_DEF = TABLE_DEF;
|
|
651
|
+
exports.TableController = TableController;
|
|
652
|
+
exports.UseValidationErrorTransform = UseValidationErrorTransform;
|
|
653
|
+
exports.ViewController = ViewController;
|
|
654
|
+
exports.validationErrorTransform = validationErrorTransform;
|