@atscript/moost-db 0.1.42 → 0.1.44

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
@@ -172,19 +172,19 @@ var SelectControlDto = class {
172
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
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);
174
174
  //#endregion
175
- //#region \0@oxc-project+runtime@0.115.0/helpers/decorateMetadata.js
175
+ //#region \0@oxc-project+runtime@0.120.0/helpers/decorateMetadata.js
176
176
  function __decorateMetadata(k, v) {
177
177
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
178
178
  }
179
179
  //#endregion
180
- //#region \0@oxc-project+runtime@0.115.0/helpers/decorateParam.js
180
+ //#region \0@oxc-project+runtime@0.120.0/helpers/decorateParam.js
181
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
187
+ //#region \0@oxc-project+runtime@0.120.0/helpers/decorate.js
188
188
  function __decorate(decorators, target, key, desc) {
189
189
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
190
190
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -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,36 @@ 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 === "db.json" || key === "db.patch.strategy" || key.startsWith("db.default")) return {
241
+ key,
242
+ value
243
+ };
244
+ if (key.startsWith("db.")) return;
245
+ return {
246
+ key,
247
+ value
248
+ };
249
+ } };
250
+ }
251
+ /**
252
+ * Whether this controller is read-only (no write endpoints).
253
+ * Returns `true` for readable/view controllers, overridden to `false` in AsDbController.
254
+ */
255
+ _isReadOnly() {
256
+ return true;
257
+ }
226
258
  _queryControlsValidator;
227
259
  _pagesControlsValidator;
228
260
  _getOneControlsValidator;
@@ -457,12 +489,32 @@ let AsDbReadableController = class AsDbReadableController {
457
489
  * **GET /meta** — returns table/view metadata for UI.
458
490
  */
459
491
  meta() {
460
- return {
492
+ if (this._metaResponse) return this._metaResponse;
493
+ const relations = [];
494
+ for (const [name, rel] of this.readable.relations) relations.push({
495
+ name,
496
+ direction: rel.direction,
497
+ isArray: rel.isArray
498
+ });
499
+ const fields = {};
500
+ for (const fd of this.readable.fieldDescriptors) {
501
+ if (fd.ignored) continue;
502
+ fields[fd.path] = {
503
+ sortable: !!fd.isIndexed,
504
+ filterable: true
505
+ };
506
+ }
507
+ this._metaResponse = {
461
508
  searchable: this.readable.isSearchable(),
462
509
  vectorSearchable: this.readable.isVectorSearchable(),
463
510
  searchIndexes: this._searchIndexes,
511
+ primaryKeys: [...this.readable.primaryKeys],
512
+ readOnly: this._isReadOnly(),
513
+ relations,
514
+ fields,
464
515
  type: this._serializedType
465
516
  };
517
+ return this._metaResponse;
466
518
  }
467
519
  };
468
520
  __decorate([
@@ -517,6 +569,9 @@ let AsDbController = class AsDbController extends AsDbReadableController {
517
569
  constructor(table, app) {
518
570
  super(table, app);
519
571
  }
572
+ _isReadOnly() {
573
+ return false;
574
+ }
520
575
  /**
521
576
  * Intercepts write operations. Return `undefined` to abort.
522
577
  */
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
@@ -171,19 +171,19 @@ defineAnnotatedType("object", WithFilterDto).propPattern(/./, defineAnnotatedTyp
171
171
  defineAnnotatedType("object", SortControlDto).propPattern(/./, defineAnnotatedType("union").item(defineAnnotatedType().designType("number").value(1).$type).item(defineAnnotatedType().designType("number").value(-1).$type).$type);
172
172
  defineAnnotatedType("object", SelectControlDto).propPattern(/./, defineAnnotatedType("union").item(defineAnnotatedType().designType("number").value(1).$type).item(defineAnnotatedType().designType("number").value(0).$type).$type);
173
173
  //#endregion
174
- //#region \0@oxc-project+runtime@0.115.0/helpers/decorateMetadata.js
174
+ //#region \0@oxc-project+runtime@0.120.0/helpers/decorateMetadata.js
175
175
  function __decorateMetadata(k, v) {
176
176
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
177
177
  }
178
178
  //#endregion
179
- //#region \0@oxc-project+runtime@0.115.0/helpers/decorateParam.js
179
+ //#region \0@oxc-project+runtime@0.120.0/helpers/decorateParam.js
180
180
  function __decorateParam(paramIndex, decorator) {
181
181
  return function(target, key) {
182
182
  decorator(target, key, paramIndex);
183
183
  };
184
184
  }
185
185
  //#endregion
186
- //#region \0@oxc-project+runtime@0.115.0/helpers/decorate.js
186
+ //#region \0@oxc-project+runtime@0.120.0/helpers/decorate.js
187
187
  function __decorate(decorators, target, key, desc) {
188
188
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
189
189
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -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,36 @@ 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 === "db.json" || key === "db.patch.strategy" || key.startsWith("db.default")) return {
240
+ key,
241
+ value
242
+ };
243
+ if (key.startsWith("db.")) return;
244
+ return {
245
+ key,
246
+ value
247
+ };
248
+ } };
249
+ }
250
+ /**
251
+ * Whether this controller is read-only (no write endpoints).
252
+ * Returns `true` for readable/view controllers, overridden to `false` in AsDbController.
253
+ */
254
+ _isReadOnly() {
255
+ return true;
256
+ }
225
257
  _queryControlsValidator;
226
258
  _pagesControlsValidator;
227
259
  _getOneControlsValidator;
@@ -456,12 +488,32 @@ let AsDbReadableController = class AsDbReadableController {
456
488
  * **GET /meta** — returns table/view metadata for UI.
457
489
  */
458
490
  meta() {
459
- return {
491
+ if (this._metaResponse) return this._metaResponse;
492
+ const relations = [];
493
+ for (const [name, rel] of this.readable.relations) relations.push({
494
+ name,
495
+ direction: rel.direction,
496
+ isArray: rel.isArray
497
+ });
498
+ const fields = {};
499
+ for (const fd of this.readable.fieldDescriptors) {
500
+ if (fd.ignored) continue;
501
+ fields[fd.path] = {
502
+ sortable: !!fd.isIndexed,
503
+ filterable: true
504
+ };
505
+ }
506
+ this._metaResponse = {
460
507
  searchable: this.readable.isSearchable(),
461
508
  vectorSearchable: this.readable.isVectorSearchable(),
462
509
  searchIndexes: this._searchIndexes,
510
+ primaryKeys: [...this.readable.primaryKeys],
511
+ readOnly: this._isReadOnly(),
512
+ relations,
513
+ fields,
463
514
  type: this._serializedType
464
515
  };
516
+ return this._metaResponse;
465
517
  }
466
518
  };
467
519
  __decorate([
@@ -516,6 +568,9 @@ let AsDbController = class AsDbController extends AsDbReadableController {
516
568
  constructor(table, app) {
517
569
  super(table, app);
518
570
  }
571
+ _isReadOnly() {
572
+ return false;
573
+ }
519
574
  /**
520
575
  * Intercepts write operations. Return `undefined` to abort.
521
576
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/moost-db",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
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.41",
45
- "@atscript/typescript": "^0.1.41",
46
- "@moostjs/event-http": "^0.6.2",
44
+ "@atscript/core": "^0.1.43",
45
+ "@atscript/typescript": "^0.1.43",
46
+ "@moostjs/event-http": "^0.6.3",
47
47
  "@uniqu/core": "^0.1.2",
48
- "moost": "^0.6.2",
49
- "unplugin-atscript": "^0.1.41"
48
+ "moost": "^0.6.3",
49
+ "unplugin-atscript": "^0.1.43"
50
50
  },
51
51
  "peerDependencies": {
52
- "@atscript/typescript": "^0.1.41",
53
- "@moostjs/event-http": "^0.6.2",
52
+ "@atscript/typescript": "^0.1.43",
53
+ "@moostjs/event-http": "^0.6.3",
54
54
  "@uniqu/core": "^0.1.2",
55
- "moost": "^0.6.2",
56
- "@atscript/db": "^0.1.42"
55
+ "moost": "^0.6.3",
56
+ "@atscript/db": "^0.1.44"
57
57
  },
58
58
  "scripts": {
59
59
  "postinstall": "asc -f dts",