@atscript/moost-db 0.1.41 → 0.1.43

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 CHANGED
@@ -203,9 +203,11 @@ let AsDbReadableController = class AsDbReadableController {
203
203
  _serializedType;
204
204
  /** Cached search index list (static, computed once). */
205
205
  _searchIndexes;
206
+ /** Cached full meta response (computed lazily on first meta() call). */
207
+ _metaResponse;
206
208
  constructor(readable, app) {
207
209
  this.readable = readable;
208
- this._serializedType = (0, _atscript_typescript_utils.serializeAnnotatedType)(readable.type);
210
+ this._serializedType = (0, _atscript_typescript_utils.serializeAnnotatedType)(readable.type, this.getSerializeOptions());
209
211
  this._searchIndexes = readable.getSearchIndexes();
210
212
  this.logger = app.getLogger(`db [${readable.tableName}]`);
211
213
  this.logger.info(`Initializing ${readable.isView ? "view" : "table"} controller`);
@@ -223,6 +225,32 @@ let AsDbReadableController = class AsDbReadableController {
223
225
  * One-time initialization hook. Override to seed data, register watchers, etc.
224
226
  */
225
227
  init() {}
228
+ /**
229
+ * Returns serialization options for the `/meta` endpoint's type field.
230
+ * Default: whitelist — keeps `meta.*`, `expect.*`, and `db.rel.*` annotations,
231
+ * strips all other `db.*` annotations (table, column, index, default, etc.).
232
+ * Override in subclass to customise what annotations are exposed to clients.
233
+ */
234
+ getSerializeOptions() {
235
+ return { processAnnotation: ({ key, value }) => {
236
+ if (key.startsWith("meta.") || key.startsWith("expect.") || key.startsWith("db.rel.")) return {
237
+ key,
238
+ value
239
+ };
240
+ if (key.startsWith("db.")) return;
241
+ return {
242
+ key,
243
+ value
244
+ };
245
+ } };
246
+ }
247
+ /**
248
+ * Whether this controller is read-only (no write endpoints).
249
+ * Returns `true` for readable/view controllers, overridden to `false` in AsDbController.
250
+ */
251
+ _isReadOnly() {
252
+ return true;
253
+ }
226
254
  _queryControlsValidator;
227
255
  _pagesControlsValidator;
228
256
  _getOneControlsValidator;
@@ -457,12 +485,32 @@ let AsDbReadableController = class AsDbReadableController {
457
485
  * **GET /meta** — returns table/view metadata for UI.
458
486
  */
459
487
  meta() {
460
- return {
488
+ if (this._metaResponse) return this._metaResponse;
489
+ const relations = [];
490
+ for (const [name, rel] of this.readable.relations) relations.push({
491
+ name,
492
+ direction: rel.direction,
493
+ isArray: rel.isArray
494
+ });
495
+ const fields = {};
496
+ for (const fd of this.readable.fieldDescriptors) {
497
+ if (fd.ignored) continue;
498
+ fields[fd.path] = {
499
+ sortable: !!fd.isIndexed,
500
+ filterable: true
501
+ };
502
+ }
503
+ this._metaResponse = {
461
504
  searchable: this.readable.isSearchable(),
462
505
  vectorSearchable: this.readable.isVectorSearchable(),
463
506
  searchIndexes: this._searchIndexes,
507
+ primaryKeys: [...this.readable.primaryKeys],
508
+ readOnly: this._isReadOnly(),
509
+ relations,
510
+ fields,
464
511
  type: this._serializedType
465
512
  };
513
+ return this._metaResponse;
466
514
  }
467
515
  };
468
516
  __decorate([
@@ -517,6 +565,9 @@ let AsDbController = class AsDbController extends AsDbReadableController {
517
565
  constructor(table, app) {
518
566
  super(table, app);
519
567
  }
568
+ _isReadOnly() {
569
+ return false;
570
+ }
520
571
  /**
521
572
  * Intercepts write operations. Return `undefined` to abort.
522
573
  */
package/dist/index.d.cts CHANGED
@@ -1,8 +1,6 @@
1
1
  import * as _uniqu_url0 from "@uniqu/url";
2
- import * as _atscript_db0 from "@atscript/db";
2
+ import { TAtscriptAnnotatedType, TAtscriptDataType, TSerializeOptions, Validator, serializeAnnotatedType } from "@atscript/typescript/utils";
3
3
  import { AtscriptDbReadable, AtscriptDbTable, FilterExpr, Uniquery, UniqueryControls } from "@atscript/db";
4
- import * as _atscript_typescript_utils0 from "@atscript/typescript/utils";
5
- import { TAtscriptAnnotatedType, TAtscriptDataType, Validator } from "@atscript/typescript/utils";
6
4
  import { HttpError } from "@moostjs/event-http";
7
5
  import * as moost from "moost";
8
6
  import { Moost, TConsoleBase } from "moost";
@@ -24,11 +22,25 @@ declare class AsDbReadableController<T extends TAtscriptAnnotatedType = TAtscrip
24
22
  private _serializedType;
25
23
  /** Cached search index list (static, computed once). */
26
24
  private _searchIndexes;
25
+ /** Cached full meta response (computed lazily on first meta() call). */
26
+ private _metaResponse?;
27
27
  constructor(readable: AtscriptDbReadable<T>, app: Moost);
28
28
  /**
29
29
  * One-time initialization hook. Override to seed data, register watchers, etc.
30
30
  */
31
31
  protected init(): void | Promise<void>;
32
+ /**
33
+ * Returns serialization options for the `/meta` endpoint's type field.
34
+ * Default: whitelist — keeps `meta.*`, `expect.*`, and `db.rel.*` annotations,
35
+ * strips all other `db.*` annotations (table, column, index, default, etc.).
36
+ * Override in subclass to customise what annotations are exposed to clients.
37
+ */
38
+ protected getSerializeOptions(): TSerializeOptions;
39
+ /**
40
+ * Whether this controller is read-only (no write endpoints).
41
+ * Returns `true` for readable/view controllers, overridden to `false` in AsDbController.
42
+ */
43
+ protected _isReadOnly(): boolean;
32
44
  private _queryControlsValidator?;
33
45
  private _pagesControlsValidator?;
34
46
  private _getOneControlsValidator?;
@@ -88,8 +100,19 @@ declare class AsDbReadableController<T extends TAtscriptAnnotatedType = TAtscrip
88
100
  meta(): {
89
101
  searchable: boolean;
90
102
  vectorSearchable: boolean;
91
- searchIndexes: _atscript_db0.TSearchIndexInfo[];
92
- type: _atscript_typescript_utils0.TSerializedAnnotatedType;
103
+ searchIndexes: ReturnType<AtscriptDbReadable<T>["getSearchIndexes"]>;
104
+ primaryKeys: string[];
105
+ readOnly: boolean;
106
+ relations: Array<{
107
+ name: string;
108
+ direction: string;
109
+ isArray: boolean;
110
+ }>;
111
+ fields: Record<string, {
112
+ sortable: boolean;
113
+ filterable: boolean;
114
+ }>;
115
+ type: ReturnType<typeof serializeAnnotatedType>;
93
116
  };
94
117
  }
95
118
  //#endregion
@@ -108,6 +131,7 @@ declare class AsDbController<T extends TAtscriptAnnotatedType = TAtscriptAnnotat
108
131
  /** Reference to the underlying table (typed for write access). */
109
132
  protected get table(): AtscriptDbTable<T>;
110
133
  constructor(table: AtscriptDbTable<T>, app: Moost);
134
+ protected _isReadOnly(): boolean;
111
135
  /**
112
136
  * Intercepts write operations. Return `undefined` to abort.
113
137
  */
package/dist/index.d.mts CHANGED
@@ -1,10 +1,8 @@
1
- import * as _atscript_typescript_utils0 from "@atscript/typescript/utils";
2
- import { TAtscriptAnnotatedType, TAtscriptDataType, Validator } from "@atscript/typescript/utils";
1
+ import { TAtscriptAnnotatedType, TAtscriptDataType, TSerializeOptions, Validator, serializeAnnotatedType } from "@atscript/typescript/utils";
3
2
  import { HttpError } from "@moostjs/event-http";
4
3
  import * as moost from "moost";
5
4
  import { Moost, TConsoleBase } from "moost";
6
5
  import * as _uniqu_url0 from "@uniqu/url";
7
- import * as _atscript_db0 from "@atscript/db";
8
6
  import { AtscriptDbReadable, AtscriptDbTable, FilterExpr, Uniquery, UniqueryControls } from "@atscript/db";
9
7
 
10
8
  //#region src/as-db-readable.controller.d.ts
@@ -24,11 +22,25 @@ declare class AsDbReadableController<T extends TAtscriptAnnotatedType = TAtscrip
24
22
  private _serializedType;
25
23
  /** Cached search index list (static, computed once). */
26
24
  private _searchIndexes;
25
+ /** Cached full meta response (computed lazily on first meta() call). */
26
+ private _metaResponse?;
27
27
  constructor(readable: AtscriptDbReadable<T>, app: Moost);
28
28
  /**
29
29
  * One-time initialization hook. Override to seed data, register watchers, etc.
30
30
  */
31
31
  protected init(): void | Promise<void>;
32
+ /**
33
+ * Returns serialization options for the `/meta` endpoint's type field.
34
+ * Default: whitelist — keeps `meta.*`, `expect.*`, and `db.rel.*` annotations,
35
+ * strips all other `db.*` annotations (table, column, index, default, etc.).
36
+ * Override in subclass to customise what annotations are exposed to clients.
37
+ */
38
+ protected getSerializeOptions(): TSerializeOptions;
39
+ /**
40
+ * Whether this controller is read-only (no write endpoints).
41
+ * Returns `true` for readable/view controllers, overridden to `false` in AsDbController.
42
+ */
43
+ protected _isReadOnly(): boolean;
32
44
  private _queryControlsValidator?;
33
45
  private _pagesControlsValidator?;
34
46
  private _getOneControlsValidator?;
@@ -88,8 +100,19 @@ declare class AsDbReadableController<T extends TAtscriptAnnotatedType = TAtscrip
88
100
  meta(): {
89
101
  searchable: boolean;
90
102
  vectorSearchable: boolean;
91
- searchIndexes: _atscript_db0.TSearchIndexInfo[];
92
- type: _atscript_typescript_utils0.TSerializedAnnotatedType;
103
+ searchIndexes: ReturnType<AtscriptDbReadable<T>["getSearchIndexes"]>;
104
+ primaryKeys: string[];
105
+ readOnly: boolean;
106
+ relations: Array<{
107
+ name: string;
108
+ direction: string;
109
+ isArray: boolean;
110
+ }>;
111
+ fields: Record<string, {
112
+ sortable: boolean;
113
+ filterable: boolean;
114
+ }>;
115
+ type: ReturnType<typeof serializeAnnotatedType>;
93
116
  };
94
117
  }
95
118
  //#endregion
@@ -108,6 +131,7 @@ declare class AsDbController<T extends TAtscriptAnnotatedType = TAtscriptAnnotat
108
131
  /** Reference to the underlying table (typed for write access). */
109
132
  protected get table(): AtscriptDbTable<T>;
110
133
  constructor(table: AtscriptDbTable<T>, app: Moost);
134
+ protected _isReadOnly(): boolean;
111
135
  /**
112
136
  * Intercepts write operations. Return `undefined` to abort.
113
137
  */
package/dist/index.mjs CHANGED
@@ -202,9 +202,11 @@ let AsDbReadableController = class AsDbReadableController {
202
202
  _serializedType;
203
203
  /** Cached search index list (static, computed once). */
204
204
  _searchIndexes;
205
+ /** Cached full meta response (computed lazily on first meta() call). */
206
+ _metaResponse;
205
207
  constructor(readable, app) {
206
208
  this.readable = readable;
207
- this._serializedType = serializeAnnotatedType(readable.type);
209
+ this._serializedType = serializeAnnotatedType(readable.type, this.getSerializeOptions());
208
210
  this._searchIndexes = readable.getSearchIndexes();
209
211
  this.logger = app.getLogger(`db [${readable.tableName}]`);
210
212
  this.logger.info(`Initializing ${readable.isView ? "view" : "table"} controller`);
@@ -222,6 +224,32 @@ let AsDbReadableController = class AsDbReadableController {
222
224
  * One-time initialization hook. Override to seed data, register watchers, etc.
223
225
  */
224
226
  init() {}
227
+ /**
228
+ * Returns serialization options for the `/meta` endpoint's type field.
229
+ * Default: whitelist — keeps `meta.*`, `expect.*`, and `db.rel.*` annotations,
230
+ * strips all other `db.*` annotations (table, column, index, default, etc.).
231
+ * Override in subclass to customise what annotations are exposed to clients.
232
+ */
233
+ getSerializeOptions() {
234
+ return { processAnnotation: ({ key, value }) => {
235
+ if (key.startsWith("meta.") || key.startsWith("expect.") || key.startsWith("db.rel.")) return {
236
+ key,
237
+ value
238
+ };
239
+ if (key.startsWith("db.")) return;
240
+ return {
241
+ key,
242
+ value
243
+ };
244
+ } };
245
+ }
246
+ /**
247
+ * Whether this controller is read-only (no write endpoints).
248
+ * Returns `true` for readable/view controllers, overridden to `false` in AsDbController.
249
+ */
250
+ _isReadOnly() {
251
+ return true;
252
+ }
225
253
  _queryControlsValidator;
226
254
  _pagesControlsValidator;
227
255
  _getOneControlsValidator;
@@ -456,12 +484,32 @@ let AsDbReadableController = class AsDbReadableController {
456
484
  * **GET /meta** — returns table/view metadata for UI.
457
485
  */
458
486
  meta() {
459
- return {
487
+ if (this._metaResponse) return this._metaResponse;
488
+ const relations = [];
489
+ for (const [name, rel] of this.readable.relations) relations.push({
490
+ name,
491
+ direction: rel.direction,
492
+ isArray: rel.isArray
493
+ });
494
+ const fields = {};
495
+ for (const fd of this.readable.fieldDescriptors) {
496
+ if (fd.ignored) continue;
497
+ fields[fd.path] = {
498
+ sortable: !!fd.isIndexed,
499
+ filterable: true
500
+ };
501
+ }
502
+ this._metaResponse = {
460
503
  searchable: this.readable.isSearchable(),
461
504
  vectorSearchable: this.readable.isVectorSearchable(),
462
505
  searchIndexes: this._searchIndexes,
506
+ primaryKeys: [...this.readable.primaryKeys],
507
+ readOnly: this._isReadOnly(),
508
+ relations,
509
+ fields,
463
510
  type: this._serializedType
464
511
  };
512
+ return this._metaResponse;
465
513
  }
466
514
  };
467
515
  __decorate([
@@ -516,6 +564,9 @@ let AsDbController = class AsDbController extends AsDbReadableController {
516
564
  constructor(table, app) {
517
565
  super(table, app);
518
566
  }
567
+ _isReadOnly() {
568
+ return false;
569
+ }
519
570
  /**
520
571
  * Intercepts write operations. Return `undefined` to abort.
521
572
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/moost-db",
3
- "version": "0.1.41",
3
+ "version": "0.1.43",
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.39",
45
- "@atscript/typescript": "^0.1.39",
44
+ "@atscript/core": "^0.1.41",
45
+ "@atscript/typescript": "^0.1.41",
46
46
  "@moostjs/event-http": "^0.6.2",
47
47
  "@uniqu/core": "^0.1.2",
48
48
  "moost": "^0.6.2",
49
- "unplugin-atscript": "^0.1.39"
49
+ "unplugin-atscript": "^0.1.41"
50
50
  },
51
51
  "peerDependencies": {
52
- "@atscript/typescript": "^0.1.39",
52
+ "@atscript/typescript": "^0.1.41",
53
53
  "@moostjs/event-http": "^0.6.2",
54
54
  "@uniqu/core": "^0.1.2",
55
55
  "moost": "^0.6.2",
56
- "@atscript/db": "^0.1.41"
56
+ "@atscript/db": "^0.1.43"
57
57
  },
58
58
  "scripts": {
59
59
  "postinstall": "asc -f dts",