@atscript/moost-db 0.1.38 → 0.1.40

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/moost-db",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "description": "Generic database controller for Moost with Atscript.",
5
5
  "keywords": [
6
6
  "annotations",
@@ -9,15 +9,15 @@
9
9
  "moost",
10
10
  "typescript"
11
11
  ],
12
- "homepage": "https://github.com/moostjs/atscript/tree/main/packages/moost-db#readme",
12
+ "homepage": "https://github.com/moostjs/atscript-db/tree/main/packages/moost-db#readme",
13
13
  "bugs": {
14
- "url": "https://github.com/moostjs/atscript/issues"
14
+ "url": "https://github.com/moostjs/atscript-db/issues"
15
15
  },
16
16
  "license": "MIT",
17
17
  "author": "Artem Maltsev",
18
18
  "repository": {
19
19
  "type": "git",
20
- "url": "git+https://github.com/moostjs/atscript.git",
20
+ "url": "git+https://github.com/moostjs/atscript-db.git",
21
21
  "directory": "packages/moost-db"
22
22
  },
23
23
  "files": [
@@ -25,34 +25,41 @@
25
25
  ],
26
26
  "type": "module",
27
27
  "main": "dist/index.mjs",
28
- "types": "dist/index.d.ts",
28
+ "types": "dist/index.d.mts",
29
29
  "exports": {
30
30
  ".": {
31
- "types": "./dist/index.d.ts",
31
+ "types": "./dist/index.d.mts",
32
32
  "import": "./dist/index.mjs",
33
33
  "require": "./dist/index.cjs"
34
34
  },
35
35
  "./package.json": "./package.json"
36
36
  },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
37
40
  "dependencies": {
38
41
  "@uniqu/url": "^0.1.2"
39
42
  },
40
43
  "devDependencies": {
44
+ "@atscript/core": "^0.1.39",
45
+ "@atscript/typescript": "^0.1.39",
41
46
  "@moostjs/event-http": "^0.6.2",
47
+ "@uniqu/core": "^0.1.2",
42
48
  "moost": "^0.6.2",
43
- "vitest": "3.2.4",
44
- "@atscript/core": "^0.1.38"
49
+ "unplugin-atscript": "^0.1.39"
45
50
  },
46
51
  "peerDependencies": {
52
+ "@atscript/typescript": "^0.1.39",
47
53
  "@moostjs/event-http": "^0.6.2",
48
- "moost": "^0.6.2",
49
54
  "@uniqu/core": "^0.1.2",
50
- "@atscript/db": "^0.1.38",
51
- "@atscript/typescript": "^0.1.38"
55
+ "moost": "^0.6.2",
56
+ "@atscript/db": "^0.1.40"
52
57
  },
53
58
  "scripts": {
54
- "pub": "pnpm publish --access public",
55
- "before-build": "node ../typescript/cli.cjs -f js",
56
- "test": "vitest"
59
+ "postinstall": "asc -f dts",
60
+ "build": "vp pack",
61
+ "dev": "vp pack --watch",
62
+ "test": "vp test",
63
+ "check": "vp check"
57
64
  }
58
65
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025-present Artem Maltsev
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/dist/index.d.ts DELETED
@@ -1,200 +0,0 @@
1
- import * as _atscript_typescript_utils from '@atscript/typescript/utils';
2
- import { TAtscriptAnnotatedType, TAtscriptDataType, Validator } from '@atscript/typescript/utils';
3
- import * as _atscript_db from '@atscript/db';
4
- import { AtscriptDbReadable, Uniquery, FilterExpr, UniqueryControls, AtscriptDbTable } from '@atscript/db';
5
- import * as _uniqu_url from '@uniqu/url';
6
- import { HttpError } from '@moostjs/event-http';
7
- import * as moost from 'moost';
8
- import { TConsoleBase, Moost } from 'moost';
9
-
10
- /**
11
- * Read-only database controller for Moost that works with any `AtscriptDbReadable`
12
- * (tables or views). Provides query, pages, getOne, and meta endpoints.
13
- *
14
- * For write operations (insert, replace, update, delete), use {@link AsDbController}.
15
- * For views, use {@link AsDbViewController}.
16
- */
17
- declare class AsDbReadableController<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType, DataType = TAtscriptDataType<T>> {
18
- /** Reference to the underlying readable (table or view). */
19
- protected readable: AtscriptDbReadable<T>;
20
- /** Application-scoped logger. */
21
- protected logger: TConsoleBase;
22
- /** Cached serialized type definition (static, computed once). */
23
- private _serializedType;
24
- /** Cached search index list (static, computed once). */
25
- private _searchIndexes;
26
- constructor(readable: AtscriptDbReadable<T>, app: Moost);
27
- /**
28
- * One-time initialization hook. Override to seed data, register watchers, etc.
29
- */
30
- protected init(): void | Promise<void>;
31
- private _queryControlsValidator?;
32
- private _pagesControlsValidator?;
33
- private _getOneControlsValidator?;
34
- protected get queryControlsValidator(): Validator<any, unknown>;
35
- protected get pagesControlsValidator(): Validator<any, unknown>;
36
- protected get getOneControlsValidator(): Validator<any, unknown>;
37
- protected validateControls(controls: Record<string, unknown>, type: 'query' | 'pages' | 'getOne'): string | undefined;
38
- protected validateInsights(insights: Map<string, unknown>): string | undefined;
39
- protected validateParsed(parsed: Uniquery, type: 'query' | 'pages' | 'getOne'): HttpError | undefined;
40
- /**
41
- * Compute an embedding vector from a search term.
42
- * Override in subclass to integrate with your embedding provider (OpenAI, etc.).
43
- * Called when `$vector` is present in query controls.
44
- */
45
- protected computeEmbedding(_search: string, _fieldName?: string): Promise<number[]>;
46
- /**
47
- * Transform filter before querying. Override to add tenant filtering, etc.
48
- */
49
- protected transformFilter(filter: FilterExpr): FilterExpr;
50
- /**
51
- * Transform projection before querying.
52
- */
53
- protected transformProjection(projection?: UniqueryControls['$select']): UniqueryControls['$select'] | undefined;
54
- protected parseQueryString(url: string): _uniqu_url.UrlQuery;
55
- protected returnOne(result: Promise<DataType | null>): Promise<DataType | HttpError>;
56
- /**
57
- * Extracts a composite identifier object from query params.
58
- * Tries composite primary key first, then compound unique indexes.
59
- */
60
- protected extractCompositeId(query: Record<string, string>): Record<string, unknown> | HttpError;
61
- /**
62
- * **GET /query** — returns an array of records or a count.
63
- */
64
- query(url: string): Promise<DataType[] | number | HttpError>;
65
- /**
66
- * **GET /pages** — returns paginated records with metadata.
67
- */
68
- pages(url: string): Promise<{
69
- data: DataType[];
70
- page: number;
71
- itemsPerPage: number;
72
- pages: number;
73
- count: number;
74
- } | HttpError>;
75
- /**
76
- * **GET /one/:id** — retrieves a single record by ID or unique property.
77
- */
78
- getOne(id: string, url: string): Promise<DataType | HttpError>;
79
- /**
80
- * **GET /one?field1=val1&field2=val2** — retrieves a single record by composite key
81
- * (composite primary key or compound unique index).
82
- */
83
- getOneComposite(query: Record<string, string>, url: string): Promise<DataType | HttpError>;
84
- /**
85
- * **GET /meta** — returns table/view metadata for UI.
86
- */
87
- meta(): {
88
- searchable: boolean;
89
- vectorSearchable: boolean;
90
- searchIndexes: _atscript_db.TSearchIndexInfo[];
91
- type: _atscript_typescript_utils.TSerializedAnnotatedType;
92
- };
93
- }
94
-
95
- /**
96
- * Full CRUD database controller for Moost that works with any `AtscriptDbTable` +
97
- * `BaseDbAdapter`. Extends {@link AsDbReadableController} with write operations.
98
- *
99
- * Subclass and provide the table via DI:
100
- * ```ts
101
- * ‎@TableController(usersTable)
102
- * export class UsersController extends AsDbController<typeof UserModel> {}
103
- * ```
104
- */
105
- declare class AsDbController<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType, DataType = TAtscriptDataType<T>> extends AsDbReadableController<T, DataType> {
106
- /** Reference to the underlying table (typed for write access). */
107
- protected get table(): AtscriptDbTable<T>;
108
- constructor(table: AtscriptDbTable<T>, app: Moost);
109
- /**
110
- * Intercepts write operations. Return `undefined` to abort.
111
- */
112
- protected onWrite(action: 'insert' | 'insertMany' | 'replace' | 'replaceMany' | 'update' | 'updateMany', data: unknown): unknown | Promise<unknown | undefined>;
113
- /**
114
- * Intercepts delete operations. Return `undefined` to abort.
115
- */
116
- protected onRemove(id: unknown): unknown | Promise<unknown | undefined>;
117
- /**
118
- * **POST /** — inserts one or many records.
119
- */
120
- insert(payload: unknown): Promise<HttpError | unknown>;
121
- /**
122
- * **PUT /** — fully replaces one or many records matched by primary key.
123
- */
124
- replace(payload: unknown): Promise<HttpError | unknown>;
125
- /**
126
- * **PATCH /** — partially updates one or many records matched by primary key.
127
- */
128
- update(payload: unknown): Promise<HttpError | unknown>;
129
- /**
130
- * **DELETE /:id** — removes a single record by primary key.
131
- */
132
- remove(id: string): Promise<HttpError | unknown>;
133
- /**
134
- * **DELETE /?field1=val1&field2=val2** — removes a record by composite key
135
- * (composite primary key or compound unique index).
136
- */
137
- removeComposite(query: Record<string, string>): Promise<HttpError | unknown>;
138
- }
139
-
140
- /**
141
- * DI token under which the {@link AtscriptDbReadable} instance
142
- * is exposed to the readable controller's constructor via `@Inject`.
143
- */
144
- declare const READABLE_DEF = "__atscript_db_readable_def";
145
- /**
146
- * DI token under which the {@link AtscriptDbTable} instance
147
- * is exposed to the controller's constructor via `@Inject`.
148
- * Points to the same token as READABLE_DEF for backward compatibility.
149
- */
150
- declare const TABLE_DEF = "__atscript_db_readable_def";
151
- /**
152
- * Combines the boilerplate needed to turn an {@link AsDbController}
153
- * subclass into a fully wired HTTP controller for a given `@db.table` model.
154
- *
155
- * Internally applies three decorators:
156
- * 1. **Provide** — registers the table instance under {@link TABLE_DEF}.
157
- * 2. **Controller** — registers the class as a Moost HTTP controller
158
- * with an optional route prefix. Defaults to `table.tableName`.
159
- * 3. **Inherit** — copies metadata (routes, guards, etc.) from the
160
- * parent class so they stay active in the derived controller.
161
- *
162
- * @param table The {@link AtscriptDbTable} instance for this controller.
163
- * @param prefix Optional route prefix. Defaults to `table.tableName`.
164
- *
165
- * @example
166
- * ```ts
167
- * ‎@TableController(usersTable)
168
- * export class UsersController extends AsDbController<typeof UserModel> {}
169
- * ```
170
- */
171
- declare const TableController: (table: AtscriptDbTable, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
172
- /**
173
- * Combines the boilerplate needed to turn an {@link AsDbReadableController}
174
- * subclass into a fully wired HTTP controller for a given `@db.view` or `@db.table` model.
175
- *
176
- * @param readable The {@link AtscriptDbReadable} instance (table or view).
177
- * @param prefix Optional route prefix. Defaults to `readable.tableName`.
178
- *
179
- * @example
180
- * ```ts
181
- * ‎@ReadableController(activeTasksView)
182
- * export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
183
- * ```
184
- */
185
- declare const ReadableController: (readable: AtscriptDbReadable, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
186
- /**
187
- * Alias for {@link ReadableController} — use with view-backed controllers.
188
- *
189
- * @example
190
- * ```ts
191
- * ‎@ViewController(activeTasksView)
192
- * export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
193
- * ```
194
- */
195
- declare const ViewController: (readable: AtscriptDbReadable, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
196
-
197
- declare const validationErrorTransform: () => moost.TInterceptorDef;
198
- declare const UseValidationErrorTransform: () => ClassDecorator & MethodDecorator;
199
-
200
- export { AsDbController, AsDbReadableController, READABLE_DEF, ReadableController, TABLE_DEF, TableController, UseValidationErrorTransform, ViewController, validationErrorTransform };