@atscript/moost-db 0.1.45 → 0.1.46
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 +42 -20
- package/dist/index.d.cts +10 -3
- package/dist/index.d.mts +9 -2
- package/dist/index.mjs +42 -20
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -36,7 +36,10 @@ const TABLE_DEF = READABLE_DEF;
|
|
|
36
36
|
* export class UsersController extends AsDbController<typeof UserModel> {}
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
const TableController = (table, prefix) =>
|
|
39
|
+
const TableController = (table, prefix) => {
|
|
40
|
+
const resolvedPath = prefix || table.type.metadata.get("db.http.path");
|
|
41
|
+
return (0, moost.ApplyDecorators)((0, moost.Provide)(TABLE_DEF, () => table), (0, moost.Controller)(resolvedPath || table.tableName), (0, moost.Inherit)());
|
|
42
|
+
};
|
|
40
43
|
/**
|
|
41
44
|
* Combines the boilerplate needed to turn an {@link AsDbReadableController}
|
|
42
45
|
* subclass into a fully wired HTTP controller for a given `@db.view` or `@db.table` model.
|
|
@@ -50,7 +53,10 @@ const TableController = (table, prefix) => (0, moost.ApplyDecorators)((0, moost.
|
|
|
50
53
|
* export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
|
|
51
54
|
* ```
|
|
52
55
|
*/
|
|
53
|
-
const ReadableController = (readable, prefix) =>
|
|
56
|
+
const ReadableController = (readable, prefix) => {
|
|
57
|
+
const resolvedPath = prefix || readable.type.metadata.get("db.http.path");
|
|
58
|
+
return (0, moost.ApplyDecorators)((0, moost.Provide)(READABLE_DEF, () => readable), (0, moost.Controller)(resolvedPath || readable.tableName), (0, moost.Inherit)());
|
|
59
|
+
};
|
|
54
60
|
/**
|
|
55
61
|
* Alias for {@link ReadableController} — use with view-backed controllers.
|
|
56
62
|
*
|
|
@@ -199,18 +205,21 @@ let AsDbReadableController = class AsDbReadableController {
|
|
|
199
205
|
readable;
|
|
200
206
|
/** Application-scoped logger. */
|
|
201
207
|
logger;
|
|
202
|
-
/** Cached serialized type definition (
|
|
208
|
+
/** Cached serialized type definition (lazy, computed on first access). */
|
|
203
209
|
_serializedType;
|
|
210
|
+
/** Moost application instance. */
|
|
211
|
+
app;
|
|
204
212
|
/** Cached search index list (static, computed once). */
|
|
205
213
|
_searchIndexes;
|
|
206
214
|
/** Cached full meta response (computed lazily on first meta() call). */
|
|
207
215
|
_metaResponse;
|
|
208
216
|
constructor(readable, app) {
|
|
209
217
|
this.readable = readable;
|
|
210
|
-
this.
|
|
218
|
+
this.app = app;
|
|
211
219
|
this._searchIndexes = readable.getSearchIndexes();
|
|
212
220
|
this.logger = app.getLogger(`db [${readable.tableName}]`);
|
|
213
221
|
this.logger.info(`Initializing ${readable.isView ? "view" : "table"} controller`);
|
|
222
|
+
this._resolveHttpPath();
|
|
214
223
|
try {
|
|
215
224
|
const p = this.init();
|
|
216
225
|
if (p instanceof Promise) p.catch((error) => {
|
|
@@ -221,6 +230,16 @@ let AsDbReadableController = class AsDbReadableController {
|
|
|
221
230
|
throw error;
|
|
222
231
|
}
|
|
223
232
|
}
|
|
233
|
+
/** Sets @db.http.path on the type metadata from the controller's computed prefix. */
|
|
234
|
+
_resolveHttpPath() {
|
|
235
|
+
const overview = this.app.getControllersOverview?.()?.find((o) => o.type === this.constructor);
|
|
236
|
+
if (overview?.computedPrefix) this.readable.type.metadata.set("db.http.path", overview.computedPrefix);
|
|
237
|
+
}
|
|
238
|
+
/** Lazily serializes the type (after all controllers have set their @db.http.path). */
|
|
239
|
+
get serializedType() {
|
|
240
|
+
if (!this._serializedType) this._serializedType = (0, _atscript_typescript_utils.serializeAnnotatedType)(this.readable.type, this.getSerializeOptions());
|
|
241
|
+
return this._serializedType;
|
|
242
|
+
}
|
|
224
243
|
/**
|
|
225
244
|
* One-time initialization hook. Override to seed data, register watchers, etc.
|
|
226
245
|
*/
|
|
@@ -232,21 +251,24 @@ let AsDbReadableController = class AsDbReadableController {
|
|
|
232
251
|
* Override in subclass to customise what annotations are exposed to clients.
|
|
233
252
|
*/
|
|
234
253
|
getSerializeOptions() {
|
|
235
|
-
return {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
key
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
254
|
+
return {
|
|
255
|
+
refDepth: 1,
|
|
256
|
+
processAnnotation: ({ key, value }) => {
|
|
257
|
+
if (key.startsWith("meta.") || key.startsWith("expect.") || key.startsWith("db.rel.")) return {
|
|
258
|
+
key,
|
|
259
|
+
value
|
|
260
|
+
};
|
|
261
|
+
if (key === "db.json" || key === "db.patch.strategy" || key.startsWith("db.default") || key === "db.http.path") return {
|
|
262
|
+
key,
|
|
263
|
+
value
|
|
264
|
+
};
|
|
265
|
+
if (key.startsWith("db.")) return;
|
|
266
|
+
return {
|
|
267
|
+
key,
|
|
268
|
+
value
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
};
|
|
250
272
|
}
|
|
251
273
|
/**
|
|
252
274
|
* Whether this controller is read-only (no write endpoints).
|
|
@@ -512,7 +534,7 @@ let AsDbReadableController = class AsDbReadableController {
|
|
|
512
534
|
readOnly: this._isReadOnly(),
|
|
513
535
|
relations,
|
|
514
536
|
fields,
|
|
515
|
-
type: this.
|
|
537
|
+
type: this.serializedType
|
|
516
538
|
};
|
|
517
539
|
return this._metaResponse;
|
|
518
540
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _atscript_typescript_utils0 from "@atscript/typescript/utils";
|
|
2
2
|
import { TAtscriptAnnotatedType, TAtscriptDataType, TSerializeOptions, Validator, serializeAnnotatedType } from "@atscript/typescript/utils";
|
|
3
|
+
import * as _uniqu_url0 from "@uniqu/url";
|
|
3
4
|
import { AtscriptDbReadable, AtscriptDbTable, FilterExpr, Uniquery, UniqueryControls } from "@atscript/db";
|
|
4
5
|
import { HttpError } from "@moostjs/event-http";
|
|
5
6
|
import * as moost from "moost";
|
|
@@ -18,13 +19,19 @@ declare class AsDbReadableController<T extends TAtscriptAnnotatedType = TAtscrip
|
|
|
18
19
|
protected readable: AtscriptDbReadable<T>;
|
|
19
20
|
/** Application-scoped logger. */
|
|
20
21
|
protected logger: TConsoleBase;
|
|
21
|
-
/** Cached serialized type definition (
|
|
22
|
-
private _serializedType
|
|
22
|
+
/** Cached serialized type definition (lazy, computed on first access). */
|
|
23
|
+
private _serializedType?;
|
|
24
|
+
/** Moost application instance. */
|
|
25
|
+
protected app: Moost;
|
|
23
26
|
/** Cached search index list (static, computed once). */
|
|
24
27
|
private _searchIndexes;
|
|
25
28
|
/** Cached full meta response (computed lazily on first meta() call). */
|
|
26
29
|
private _metaResponse?;
|
|
27
30
|
constructor(readable: AtscriptDbReadable<T>, app: Moost);
|
|
31
|
+
/** Sets @db.http.path on the type metadata from the controller's computed prefix. */
|
|
32
|
+
private _resolveHttpPath;
|
|
33
|
+
/** Lazily serializes the type (after all controllers have set their @db.http.path). */
|
|
34
|
+
protected get serializedType(): _atscript_typescript_utils0.TSerializedAnnotatedType;
|
|
28
35
|
/**
|
|
29
36
|
* One-time initialization hook. Override to seed data, register watchers, etc.
|
|
30
37
|
*/
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as _atscript_typescript_utils0 from "@atscript/typescript/utils";
|
|
1
2
|
import { TAtscriptAnnotatedType, TAtscriptDataType, TSerializeOptions, Validator, serializeAnnotatedType } from "@atscript/typescript/utils";
|
|
2
3
|
import { HttpError } from "@moostjs/event-http";
|
|
3
4
|
import * as moost from "moost";
|
|
@@ -18,13 +19,19 @@ declare class AsDbReadableController<T extends TAtscriptAnnotatedType = TAtscrip
|
|
|
18
19
|
protected readable: AtscriptDbReadable<T>;
|
|
19
20
|
/** Application-scoped logger. */
|
|
20
21
|
protected logger: TConsoleBase;
|
|
21
|
-
/** Cached serialized type definition (
|
|
22
|
-
private _serializedType
|
|
22
|
+
/** Cached serialized type definition (lazy, computed on first access). */
|
|
23
|
+
private _serializedType?;
|
|
24
|
+
/** Moost application instance. */
|
|
25
|
+
protected app: Moost;
|
|
23
26
|
/** Cached search index list (static, computed once). */
|
|
24
27
|
private _searchIndexes;
|
|
25
28
|
/** Cached full meta response (computed lazily on first meta() call). */
|
|
26
29
|
private _metaResponse?;
|
|
27
30
|
constructor(readable: AtscriptDbReadable<T>, app: Moost);
|
|
31
|
+
/** Sets @db.http.path on the type metadata from the controller's computed prefix. */
|
|
32
|
+
private _resolveHttpPath;
|
|
33
|
+
/** Lazily serializes the type (after all controllers have set their @db.http.path). */
|
|
34
|
+
protected get serializedType(): _atscript_typescript_utils0.TSerializedAnnotatedType;
|
|
28
35
|
/**
|
|
29
36
|
* One-time initialization hook. Override to seed data, register watchers, etc.
|
|
30
37
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -35,7 +35,10 @@ const TABLE_DEF = READABLE_DEF;
|
|
|
35
35
|
* export class UsersController extends AsDbController<typeof UserModel> {}
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
const TableController = (table, prefix) =>
|
|
38
|
+
const TableController = (table, prefix) => {
|
|
39
|
+
const resolvedPath = prefix || table.type.metadata.get("db.http.path");
|
|
40
|
+
return ApplyDecorators(Provide(TABLE_DEF, () => table), Controller(resolvedPath || table.tableName), Inherit());
|
|
41
|
+
};
|
|
39
42
|
/**
|
|
40
43
|
* Combines the boilerplate needed to turn an {@link AsDbReadableController}
|
|
41
44
|
* subclass into a fully wired HTTP controller for a given `@db.view` or `@db.table` model.
|
|
@@ -49,7 +52,10 @@ const TableController = (table, prefix) => ApplyDecorators(Provide(TABLE_DEF, ()
|
|
|
49
52
|
* export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
|
|
50
53
|
* ```
|
|
51
54
|
*/
|
|
52
|
-
const ReadableController = (readable, prefix) =>
|
|
55
|
+
const ReadableController = (readable, prefix) => {
|
|
56
|
+
const resolvedPath = prefix || readable.type.metadata.get("db.http.path");
|
|
57
|
+
return ApplyDecorators(Provide(READABLE_DEF, () => readable), Controller(resolvedPath || readable.tableName), Inherit());
|
|
58
|
+
};
|
|
53
59
|
/**
|
|
54
60
|
* Alias for {@link ReadableController} — use with view-backed controllers.
|
|
55
61
|
*
|
|
@@ -198,18 +204,21 @@ let AsDbReadableController = class AsDbReadableController {
|
|
|
198
204
|
readable;
|
|
199
205
|
/** Application-scoped logger. */
|
|
200
206
|
logger;
|
|
201
|
-
/** Cached serialized type definition (
|
|
207
|
+
/** Cached serialized type definition (lazy, computed on first access). */
|
|
202
208
|
_serializedType;
|
|
209
|
+
/** Moost application instance. */
|
|
210
|
+
app;
|
|
203
211
|
/** Cached search index list (static, computed once). */
|
|
204
212
|
_searchIndexes;
|
|
205
213
|
/** Cached full meta response (computed lazily on first meta() call). */
|
|
206
214
|
_metaResponse;
|
|
207
215
|
constructor(readable, app) {
|
|
208
216
|
this.readable = readable;
|
|
209
|
-
this.
|
|
217
|
+
this.app = app;
|
|
210
218
|
this._searchIndexes = readable.getSearchIndexes();
|
|
211
219
|
this.logger = app.getLogger(`db [${readable.tableName}]`);
|
|
212
220
|
this.logger.info(`Initializing ${readable.isView ? "view" : "table"} controller`);
|
|
221
|
+
this._resolveHttpPath();
|
|
213
222
|
try {
|
|
214
223
|
const p = this.init();
|
|
215
224
|
if (p instanceof Promise) p.catch((error) => {
|
|
@@ -220,6 +229,16 @@ let AsDbReadableController = class AsDbReadableController {
|
|
|
220
229
|
throw error;
|
|
221
230
|
}
|
|
222
231
|
}
|
|
232
|
+
/** Sets @db.http.path on the type metadata from the controller's computed prefix. */
|
|
233
|
+
_resolveHttpPath() {
|
|
234
|
+
const overview = this.app.getControllersOverview?.()?.find((o) => o.type === this.constructor);
|
|
235
|
+
if (overview?.computedPrefix) this.readable.type.metadata.set("db.http.path", overview.computedPrefix);
|
|
236
|
+
}
|
|
237
|
+
/** Lazily serializes the type (after all controllers have set their @db.http.path). */
|
|
238
|
+
get serializedType() {
|
|
239
|
+
if (!this._serializedType) this._serializedType = serializeAnnotatedType(this.readable.type, this.getSerializeOptions());
|
|
240
|
+
return this._serializedType;
|
|
241
|
+
}
|
|
223
242
|
/**
|
|
224
243
|
* One-time initialization hook. Override to seed data, register watchers, etc.
|
|
225
244
|
*/
|
|
@@ -231,21 +250,24 @@ let AsDbReadableController = class AsDbReadableController {
|
|
|
231
250
|
* Override in subclass to customise what annotations are exposed to clients.
|
|
232
251
|
*/
|
|
233
252
|
getSerializeOptions() {
|
|
234
|
-
return {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
key
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
253
|
+
return {
|
|
254
|
+
refDepth: 1,
|
|
255
|
+
processAnnotation: ({ key, value }) => {
|
|
256
|
+
if (key.startsWith("meta.") || key.startsWith("expect.") || key.startsWith("db.rel.")) return {
|
|
257
|
+
key,
|
|
258
|
+
value
|
|
259
|
+
};
|
|
260
|
+
if (key === "db.json" || key === "db.patch.strategy" || key.startsWith("db.default") || key === "db.http.path") return {
|
|
261
|
+
key,
|
|
262
|
+
value
|
|
263
|
+
};
|
|
264
|
+
if (key.startsWith("db.")) return;
|
|
265
|
+
return {
|
|
266
|
+
key,
|
|
267
|
+
value
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
};
|
|
249
271
|
}
|
|
250
272
|
/**
|
|
251
273
|
* Whether this controller is read-only (no write endpoints).
|
|
@@ -511,7 +533,7 @@ let AsDbReadableController = class AsDbReadableController {
|
|
|
511
533
|
readOnly: this._isReadOnly(),
|
|
512
534
|
relations,
|
|
513
535
|
fields,
|
|
514
|
-
type: this.
|
|
536
|
+
type: this.serializedType
|
|
515
537
|
};
|
|
516
538
|
return this._metaResponse;
|
|
517
539
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/moost-db",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.46",
|
|
4
4
|
"description": "Generic database controller for Moost with Atscript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -41,19 +41,19 @@
|
|
|
41
41
|
"@uniqu/url": "^0.1.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@atscript/core": "^0.1.
|
|
45
|
-
"@atscript/typescript": "^0.1.
|
|
46
|
-
"@moostjs/event-http": "^0.6.
|
|
44
|
+
"@atscript/core": "^0.1.47",
|
|
45
|
+
"@atscript/typescript": "^0.1.47",
|
|
46
|
+
"@moostjs/event-http": "^0.6.6",
|
|
47
47
|
"@uniqu/core": "^0.1.2",
|
|
48
|
-
"moost": "^0.6.
|
|
49
|
-
"unplugin-atscript": "^0.1.
|
|
48
|
+
"moost": "^0.6.6",
|
|
49
|
+
"unplugin-atscript": "^0.1.47"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@atscript/typescript": "^0.1.
|
|
53
|
-
"@moostjs/event-http": "^0.6.
|
|
52
|
+
"@atscript/typescript": "^0.1.47",
|
|
53
|
+
"@moostjs/event-http": "^0.6.6",
|
|
54
54
|
"@uniqu/core": "^0.1.2",
|
|
55
|
-
"moost": "^0.6.
|
|
56
|
-
"@atscript/db": "^0.1.
|
|
55
|
+
"moost": "^0.6.6",
|
|
56
|
+
"@atscript/db": "^0.1.46"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"postinstall": "asc -f dts",
|