@atscript/db 0.1.127 → 0.1.128
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/{db-readable-BkAGccv9.d.mts → db-readable-BTl4NzNN.d.mts} +289 -16
- package/dist/{db-readable-C0nDKX8A.d.cts → db-readable-CkbZn_z-.d.cts} +289 -16
- package/dist/{db-space-B_ASuDaR.d.mts → db-space-BEB5Jl8M.d.mts} +81 -29
- package/dist/{db-space-CSntT6yS.d.cts → db-space-BevOyVrC.d.cts} +81 -29
- package/dist/{db-view-BP0Qbeux.cjs → db-view-C8-MsjND.cjs} +696 -97
- package/dist/{db-view-C8rZM5_N.mjs → db-view-Ck0I-PMI.mjs} +643 -98
- package/dist/index.cjs +46 -2
- package/dist/index.d.cts +162 -37
- package/dist/index.d.mts +162 -37
- package/dist/index.mjs +36 -4
- package/dist/{ops-DJRnNTVo.d.cts → ops-AqhV7s9o.d.cts} +24 -1
- package/dist/{ops-DJRnNTVo.d.mts → ops-AqhV7s9o.d.mts} +24 -1
- package/dist/ops.cjs +43 -0
- package/dist/ops.d.cts +2 -2
- package/dist/ops.d.mts +2 -2
- package/dist/ops.mjs +43 -1
- package/dist/plugin.cjs +12 -5
- package/dist/plugin.mjs +12 -5
- package/dist/rel.d.cts +1 -1
- package/dist/rel.d.mts +1 -1
- package/dist/sync.cjs +1096 -361
- package/dist/sync.d.cts +234 -15
- package/dist/sync.d.mts +234 -15
- package/dist/sync.mjs +1095 -362
- package/dist/{validator-CSGug4vg.cjs → validator-BNUHCXIE.cjs} +31 -2
- package/dist/{validator-BcBtg8yW.d.cts → validator-DuAmWc8L.d.cts} +38 -1
- package/dist/{validator-BcBtg8yW.d.mts → validator-DuAmWc8L.d.mts} +38 -1
- package/dist/{validator-0vRXN51D.mjs → validator-eKYWf3xf.mjs} +20 -3
- package/dist/validator.cjs +7 -1
- package/dist/validator.d.cts +3 -3
- package/dist/validator.d.mts +3 -3
- package/dist/validator.mjs +4 -3
- package/package.json +8 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as NullableOptional, Ct as TWriteTableResolver, E as TCascadeResolver, G as TDbInsertResult, Nt as TGenericLogger, Ot as TableMetadata, Q as TDbUpdateResult, R as TDbDeleteResult, St as TWriteOptions, W as TDbInsertManyResult, a as TDbEncryptionOptions, bt as TTableResolver, c as BaseDbAdapter, ct as TFkLookupResolver, g as DbPatch, ht as TReferencingForeignKey, i as DbEncryption, nt as TDeleteOptions, t as AtscriptDbReadable, v as DbRow } from "./db-readable-CkbZn_z-.cjs";
|
|
2
2
|
import { FilterExpr } from "@uniqu/core";
|
|
3
3
|
import { AtscriptQueryComparison, AtscriptQueryFieldRef, AtscriptQueryFieldRef as AtscriptQueryFieldRef$1, AtscriptQueryNode, AtscriptQueryNode as AtscriptQueryNode$1, AtscriptRef, FlatOf, NavPropsOf, OwnPropsOf, PrimaryKeyOf, TAtscriptAnnotatedType, TAtscriptDataType, Validator } from "@atscript/typescript/utils";
|
|
4
4
|
|
|
@@ -24,7 +24,7 @@ declare class NativeIntegrity extends IntegrityStrategy {
|
|
|
24
24
|
}
|
|
25
25
|
//#endregion
|
|
26
26
|
//#region src/table/db-table.d.ts
|
|
27
|
-
declare class AtscriptDbTable<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType, DataType = TAtscriptDataType<T>, FlatType = FlatOf<T
|
|
27
|
+
declare class AtscriptDbTable<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType, DataType = TAtscriptDataType<T>, FlatType = NullableOptional<FlatOf<T>>, A extends BaseDbAdapter = BaseDbAdapter, IdType = PrimaryKeyOf<T>, OwnProps = NullableOptional<OwnPropsOf<T>>, NavType extends Record<string, unknown> = NavPropsOf<T>> extends AtscriptDbReadable<T, DataType, FlatType, A, IdType, OwnProps, NavType> {
|
|
28
28
|
protected _cascadeResolver?: TCascadeResolver;
|
|
29
29
|
protected _fkLookupResolver?: TFkLookupResolver;
|
|
30
30
|
protected readonly _integrity: IntegrityStrategy;
|
|
@@ -53,9 +53,7 @@ declare class AtscriptDbTable<T extends TAtscriptAnnotatedType = TAtscriptAnnota
|
|
|
53
53
|
* Inserts a single record. Delegates to {@link insertMany} for unified
|
|
54
54
|
* nested creation support.
|
|
55
55
|
*/
|
|
56
|
-
insertOne(payload:
|
|
57
|
-
maxDepth?: number;
|
|
58
|
-
}): Promise<TDbInsertResult>;
|
|
56
|
+
insertOne(payload: DbPatch<DataType>, opts?: TWriteOptions<DataType>): Promise<TDbInsertResult>;
|
|
59
57
|
/**
|
|
60
58
|
* Inserts multiple records with batch-optimized nested creation.
|
|
61
59
|
*
|
|
@@ -66,17 +64,16 @@ declare class AtscriptDbTable<T extends TAtscriptAnnotatedType = TAtscriptAnnota
|
|
|
66
64
|
* (they receive our PKs as their FKs). Fully recursive — nested records
|
|
67
65
|
* with their own nav data trigger further batch inserts at each level.
|
|
68
66
|
* Recursive up to `maxDepth` (default 3).
|
|
67
|
+
*
|
|
68
|
+
* `opts.guard` (since 0.1.128) runs once inside the transaction, after
|
|
69
|
+
* defaults + validation, with the prepared rows — see {@link TWriteOptions}.
|
|
69
70
|
*/
|
|
70
|
-
insertMany(payloads: Array<
|
|
71
|
-
maxDepth?: number;
|
|
72
|
-
}): Promise<TDbInsertManyResult>;
|
|
71
|
+
insertMany(payloads: Array<DbPatch<DataType>>, opts?: TWriteOptions<DataType>): Promise<TDbInsertManyResult>;
|
|
73
72
|
/**
|
|
74
73
|
* Replaces a single record identified by primary key(s).
|
|
75
74
|
* Delegates to {@link bulkReplace} for unified nested relation support.
|
|
76
75
|
*/
|
|
77
|
-
replaceOne(payload: DataType
|
|
78
|
-
maxDepth?: number;
|
|
79
|
-
}): Promise<TDbUpdateResult>;
|
|
76
|
+
replaceOne(payload: DbRow<DataType>, opts?: TWriteOptions<DataType>): Promise<TDbUpdateResult>;
|
|
80
77
|
/**
|
|
81
78
|
* Replaces multiple records with deep nested relation support.
|
|
82
79
|
*
|
|
@@ -84,37 +81,43 @@ declare class AtscriptDbTable<T extends TAtscriptAnnotatedType = TAtscriptAnnota
|
|
|
84
81
|
* replaced first (their PKs become our FKs), FROM dependents are replaced
|
|
85
82
|
* after (they receive our PKs as their FKs), VIA relations clear and
|
|
86
83
|
* re-create junction rows. Fully recursive up to `maxDepth` (default 3).
|
|
84
|
+
*
|
|
85
|
+
* `opts.guard` (since 0.1.128) runs once inside the transaction, after
|
|
86
|
+
* `$cas` extraction, defaults + validation — see {@link TWriteOptions}.
|
|
87
87
|
*/
|
|
88
|
-
bulkReplace(payloads: Array<DataType
|
|
89
|
-
maxDepth?: number;
|
|
90
|
-
}): Promise<TDbUpdateResult>;
|
|
88
|
+
bulkReplace(payloads: Array<DbRow<DataType>>, opts?: TWriteOptions<DataType>): Promise<TDbUpdateResult>;
|
|
91
89
|
/**
|
|
92
90
|
* Partially updates a single record identified by primary key(s).
|
|
93
91
|
* Delegates to {@link bulkUpdate} for unified nested relation support.
|
|
94
92
|
*/
|
|
95
|
-
updateOne(payload:
|
|
96
|
-
maxDepth?: number;
|
|
97
|
-
}): Promise<TDbUpdateResult>;
|
|
93
|
+
updateOne(payload: DbPatch<DataType>, opts?: TWriteOptions<DataType>): Promise<TDbUpdateResult>;
|
|
98
94
|
/**
|
|
99
95
|
* Partially updates multiple records with deep nested relation support.
|
|
100
96
|
*
|
|
101
97
|
* Only TO relations (1:1, N:1) are supported for patching. FROM/VIA
|
|
102
98
|
* relations will error — use {@link bulkReplace} for those.
|
|
103
99
|
* Recursive up to `maxDepth` (default 3).
|
|
100
|
+
*
|
|
101
|
+
* `opts.guard` (since 0.1.128) runs once inside the transaction, after
|
|
102
|
+
* `$cas` extraction and validation, with the patches (identifying fields
|
|
103
|
+
* present, `$cas` removed) — see {@link TWriteOptions}.
|
|
104
104
|
*/
|
|
105
|
-
bulkUpdate(payloads: Array<
|
|
106
|
-
maxDepth?: number;
|
|
107
|
-
}): Promise<TDbUpdateResult>;
|
|
105
|
+
bulkUpdate(payloads: Array<DbPatch<DataType>>, opts?: TWriteOptions<DataType>): Promise<TDbUpdateResult>;
|
|
108
106
|
/**
|
|
109
107
|
* Deletes a single record by any type-compatible identifier — primary key
|
|
110
108
|
* or single-field unique index. Uses the same resolution logic as `findById`.
|
|
111
109
|
*
|
|
112
110
|
* When the adapter does not support native foreign keys (e.g. MongoDB),
|
|
113
111
|
* cascade and setNull actions are applied before the delete.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
*
|
|
113
|
+
* `opts.guard` (since 0.1.128) runs inside the transaction once the id has
|
|
114
|
+
* resolved to a filter, before cascade / delete — see {@link TDeleteOptions}.
|
|
115
|
+
* An id that resolves to no filter answers `{ deletedCount: 0 }` without
|
|
116
|
+
* calling the guard.
|
|
117
|
+
*/
|
|
118
|
+
deleteOne(id: IdType, opts?: TDeleteOptions<DataType>): Promise<TDbDeleteResult>;
|
|
119
|
+
updateMany(filter: FilterExpr<FlatType>, data: DbPatch<DataType>): Promise<TDbUpdateResult>;
|
|
120
|
+
replaceMany(filter: FilterExpr<FlatType>, data: DbRow<DataType>): Promise<TDbUpdateResult>;
|
|
118
121
|
deleteMany(filter: FilterExpr<FlatType>): Promise<TDbDeleteResult>;
|
|
119
122
|
/**
|
|
120
123
|
* Synchronizes indexes between Atscript definitions and the database.
|
|
@@ -140,11 +143,31 @@ declare class AtscriptDbTable<T extends TAtscriptAnnotatedType = TAtscriptAnnota
|
|
|
140
143
|
*/
|
|
141
144
|
protected _encryptItems(items: Array<Record<string, unknown>>, mode: "write" | "patch"): Promise<void>;
|
|
142
145
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
+
* Lazy pre-image read for a guard's `current(i)`: `null` when the row has
|
|
147
|
+
* no identifying key (e.g. an auto-increment insert) or the key cannot be
|
|
148
|
+
* resolved — never throws for a missing key.
|
|
149
|
+
* @internal
|
|
150
|
+
*/
|
|
151
|
+
_readPreImage(row: unknown): Promise<DataType | null>;
|
|
152
|
+
/**
|
|
153
|
+
* Applies `@db.default` values in place to a row's absent fields — the
|
|
154
|
+
* defaults pass every insert / replace path runs before validation.
|
|
155
|
+
* Static value defaults (`@db.default 'x'`) are filled on EVERY adapter
|
|
156
|
+
* (since 0.1.128 — writing the column's own default explicitly is
|
|
157
|
+
* equivalent to leaving it to the DDL `DEFAULT`, and write guards see the
|
|
158
|
+
* full row). Function defaults (`now` / `uuid` / `increment` / custom) the
|
|
159
|
+
* adapter handles natively are NOT filled — the field stays absent so the
|
|
160
|
+
* engine's own default applies. The version column is never touched.
|
|
146
161
|
*/
|
|
147
162
|
protected _applyDefaults(data: Record<string, unknown>): Record<string, unknown>;
|
|
163
|
+
/**
|
|
164
|
+
* The JS value for a `@db.default 'literal'`: strings (including unions of
|
|
165
|
+
* string literals) are used as-is, every other design type is parsed as
|
|
166
|
+
* JSON — the same value the SQL adapters put into the DDL `DEFAULT` clause.
|
|
167
|
+
* A literal that is not valid JSON falls back to the raw string so the
|
|
168
|
+
* validator reports it against the field instead of a bare `SyntaxError`.
|
|
169
|
+
*/
|
|
170
|
+
private _parseValueDefault;
|
|
148
171
|
/**
|
|
149
172
|
* Extracts a record-identifying filter from a payload.
|
|
150
173
|
*
|
|
@@ -235,7 +258,7 @@ interface TViewColumnMapping {
|
|
|
235
258
|
* const users = await activeUsers.findMany({ filter: {}, controls: {} })
|
|
236
259
|
* ```
|
|
237
260
|
*/
|
|
238
|
-
declare class AtscriptDbView<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType, DataType = TAtscriptDataType<T>, FlatType = FlatOf<T
|
|
261
|
+
declare class AtscriptDbView<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType, DataType = TAtscriptDataType<T>, FlatType = NullableOptional<FlatOf<T>>, A extends BaseDbAdapter = BaseDbAdapter, IdType = PrimaryKeyOf<T>, OwnProps = NullableOptional<OwnPropsOf<T>>, NavType extends Record<string, unknown> = NavPropsOf<T>> extends AtscriptDbReadable<T, DataType, FlatType, A, IdType, OwnProps, NavType> {
|
|
239
262
|
private _viewPlan?;
|
|
240
263
|
get isView(): boolean;
|
|
241
264
|
/**
|
|
@@ -267,6 +290,16 @@ declare class AtscriptDbView<T extends TAtscriptAnnotatedType = TAtscriptAnnotat
|
|
|
267
290
|
*/
|
|
268
291
|
getViewColumnMappings(): TViewColumnMapping[];
|
|
269
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Structural type guard for views: `true` when the readable reports
|
|
295
|
+
* `isView`, whether or not it is an `AtscriptDbView` instance of THIS copy
|
|
296
|
+
* of `@atscript/db`. Adapters must use this (or `readable.isView`) instead of
|
|
297
|
+
* `instanceof AtscriptDbView` — in a bundle that carries two copies of the
|
|
298
|
+
* core (app bundle + external adapter), `instanceof` is false and the adapter
|
|
299
|
+
* would create an empty physical table under the view's name.
|
|
300
|
+
* @since 0.1.128
|
|
301
|
+
*/
|
|
302
|
+
declare function isAtscriptDbView(readable: AtscriptDbReadable<any, any, any, any, any, any, any>): readable is AtscriptDbView<any, any, any, any, any, any, any>;
|
|
270
303
|
//#endregion
|
|
271
304
|
//#region src/table/db-space.d.ts
|
|
272
305
|
/**
|
|
@@ -343,6 +376,25 @@ declare class DbSpace {
|
|
|
343
376
|
* Drops a view by name. Used by schema sync to remove views no longer in the schema.
|
|
344
377
|
*/
|
|
345
378
|
dropViewByName(viewName: string): Promise<void>;
|
|
379
|
+
/**
|
|
380
|
+
* Drops a group of mutually referencing tables as one operation.
|
|
381
|
+
* Used by schema sync to remove a foreign-key cycle no longer in the schema.
|
|
382
|
+
* @since 0.1.128
|
|
383
|
+
*/
|
|
384
|
+
dropTablesByName(tableNames: string[]): Promise<void>;
|
|
385
|
+
/**
|
|
386
|
+
* Live foreign keys referencing `tableName`, or `undefined` when the
|
|
387
|
+
* adapter cannot introspect them. Used by schema sync for drop ordering
|
|
388
|
+
* and surviving-reference checks of tables without a registered readable.
|
|
389
|
+
* @since 0.1.128
|
|
390
|
+
*/
|
|
391
|
+
getReferencingForeignKeys(tableName: string): Promise<TReferencingForeignKey[] | undefined>;
|
|
392
|
+
/**
|
|
393
|
+
* A factory-fresh adapter with NO registered readable. Only the name-taking
|
|
394
|
+
* primitives may run on it (`dropTableByName`, `dropViewByName`,
|
|
395
|
+
* `dropTablesByName`, `getReferencingForeignKeys`) — adapters derive the
|
|
396
|
+
* schema for those from the driver/connection, not from a bound table.
|
|
397
|
+
*/
|
|
346
398
|
private _getAdminAdapter;
|
|
347
399
|
/**
|
|
348
400
|
* Finds all child tables with FKs pointing to the given parent table name.
|
|
@@ -356,4 +408,4 @@ declare class DbSpace {
|
|
|
356
408
|
private _getFkLookupTarget;
|
|
357
409
|
}
|
|
358
410
|
//#endregion
|
|
359
|
-
export { TViewColumnMapping as a,
|
|
411
|
+
export { TViewColumnMapping as a, AtscriptQueryFieldRef$1 as c, TViewJoin as d, TViewPlan as f, NativeIntegrity as g, IntegrityStrategy as h, AtscriptDbView as i, AtscriptQueryNode$1 as l, AtscriptDbTable as m, TAdapterFactory as n, isAtscriptDbView as o, translateQueryTree as p, TDbSpaceOptions as r, AtscriptQueryComparison as s, DbSpace as t, AtscriptRef as u };
|