@atscript/db 0.1.103 → 0.1.105

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.
@@ -1,4 +1,4 @@
1
- import { B as TDbInsertResult, J as TFkLookupResolver, N as TDbDeleteResult, W as TDbUpdateResult, dt as TableMetadata, it as TTableResolver, o as BaseDbAdapter, ot as TWriteTableResolver, pt as TGenericLogger, t as AtscriptDbReadable, x as TCascadeResolver, z as TDbInsertManyResult } from "./db-readable-CXdHBtF6.mjs";
1
+ import { C as TCascadeResolver, F as TDbDeleteResult, H as TDbInsertResult, K as TDbUpdateResult, V as TDbInsertManyResult, X as TFkLookupResolver, _t as TGenericLogger, a as TDbEncryptionOptions, c as BaseDbAdapter, ct as TWriteTableResolver, i as DbEncryption, ot as TTableResolver, pt as TableMetadata, t as AtscriptDbReadable } from "./db-readable-Ds01ezjj.mjs";
2
2
  import { AtscriptQueryComparison, AtscriptQueryFieldRef, AtscriptQueryFieldRef as AtscriptQueryFieldRef$1, AtscriptQueryNode, AtscriptQueryNode as AtscriptQueryNode$1, AtscriptRef, FlatOf, NavPropsOf, OwnPropsOf, PrimaryKeyOf, TAtscriptAnnotatedType, TAtscriptDataType, Validator } from "@atscript/typescript/utils";
3
3
  import { FilterExpr } from "@uniqu/core";
4
4
 
@@ -124,6 +124,21 @@ declare class AtscriptDbTable<T extends TAtscriptAnnotatedType = TAtscriptAnnota
124
124
  * Ensures the table/collection exists in the database.
125
125
  */
126
126
  ensureTable(): Promise<void>;
127
+ /** Engine-agnostic guard for user-supplied mutation filters (updateMany/deleteMany/…). */
128
+ protected _guardMutationFilter(filter: FilterExpr): void;
129
+ /**
130
+ * Encrypts `@db.encrypted` field values in place on (already validated)
131
+ * write payloads — between validation and `prepareForWrite`, so adapters
132
+ * only ever see envelope strings.
133
+ *
134
+ * Parent objects along an encrypted path are shallow-cloned before
135
+ * mutation so caller-shared nested objects are never modified.
136
+ *
137
+ * In `patch` mode, operator objects (`$inc`, `$insert`, …) targeting an
138
+ * encrypted field are rejected with `ENC_FIELD_PATCH_OP` — ciphertext is
139
+ * opaque; only plain re-assignment (which re-encrypts) is allowed.
140
+ */
141
+ protected _encryptItems(items: Array<Record<string, unknown>>, mode: "write" | "patch"): Promise<void>;
127
142
  /**
128
143
  * Applies default values for fields that are missing from the payload.
129
144
  * Defaults handled natively by the DB engine are skipped — the field stays
@@ -259,6 +274,13 @@ declare class AtscriptDbView<T extends TAtscriptAnnotatedType = TAtscriptAnnotat
259
274
  * Each readable gets its own adapter (1:1 relationship required by BaseDbAdapter).
260
275
  */
261
276
  type TAdapterFactory = () => BaseDbAdapter;
277
+ /** Options bag for {@link DbSpace} (second constructor argument). */
278
+ interface TDbSpaceOptions {
279
+ /** Logger shared by all tables/views in the space. */
280
+ logger?: TGenericLogger;
281
+ /** Field-level encryption configuration for `@db.encrypted` fields. */
282
+ encryption?: TDbEncryptionOptions;
283
+ }
262
284
  /**
263
285
  * A database space — a registry of tables and views sharing the same adapter type and driver.
264
286
  *
@@ -279,13 +301,20 @@ type TAdapterFactory = () => BaseDbAdapter;
279
301
  */
280
302
  declare class DbSpace {
281
303
  protected readonly adapterFactory: TAdapterFactory;
282
- protected readonly logger: TGenericLogger;
283
304
  private _readables;
284
305
  /** All tables created in this space — used for reverse FK lookup during cascade. */
285
306
  private _allTables;
286
307
  /** Lazily created adapter for administrative ops (drop table/view) that don't need a registered readable. */
287
308
  private _adminAdapter?;
288
- constructor(adapterFactory: TAdapterFactory, logger?: TGenericLogger);
309
+ protected readonly logger: TGenericLogger;
310
+ /** Encryption service for `@db.encrypted` fields — validated eagerly at construction. */
311
+ protected readonly _encryption?: DbEncryption;
312
+ /**
313
+ * @param adapterFactory - Creates a fresh adapter per table/view.
314
+ * @param loggerOrOptions - Either a logger (legacy signature) or a
315
+ * {@link TDbSpaceOptions} bag carrying `logger` and/or `encryption`.
316
+ */
317
+ constructor(adapterFactory: TAdapterFactory, loggerOrOptions?: TGenericLogger | TDbSpaceOptions);
289
318
  /**
290
319
  * Auto-detects whether the type is a table or view and returns the
291
320
  * appropriate instance. Uses `@db.view` or `@db.view.for` presence to distinguish.
@@ -327,4 +356,4 @@ declare class DbSpace {
327
356
  private _getFkLookupTarget;
328
357
  }
329
358
  //#endregion
330
- export { AtscriptQueryComparison as a, AtscriptRef as c, translateQueryTree as d, AtscriptDbTable as f, TViewColumnMapping as i, TViewJoin as l, NativeIntegrity as m, TAdapterFactory as n, AtscriptQueryFieldRef$1 as o, IntegrityStrategy as p, AtscriptDbView as r, AtscriptQueryNode$1 as s, DbSpace as t, TViewPlan as u };
359
+ export { TViewColumnMapping as a, AtscriptQueryNode$1 as c, TViewPlan as d, translateQueryTree as f, NativeIntegrity as h, AtscriptDbView as i, AtscriptRef as l, IntegrityStrategy as m, TAdapterFactory as n, AtscriptQueryComparison as o, AtscriptDbTable as p, TDbSpaceOptions as r, AtscriptQueryFieldRef$1 as s, DbSpace as t, TViewJoin as u };
@@ -1,4 +1,4 @@
1
- import { B as TDbInsertResult, J as TFkLookupResolver, N as TDbDeleteResult, W as TDbUpdateResult, dt as TableMetadata, it as TTableResolver, o as BaseDbAdapter, ot as TWriteTableResolver, pt as TGenericLogger, t as AtscriptDbReadable, x as TCascadeResolver, z as TDbInsertManyResult } from "./db-readable-mhPp-MPv.cjs";
1
+ import { C as TCascadeResolver, F as TDbDeleteResult, H as TDbInsertResult, K as TDbUpdateResult, V as TDbInsertManyResult, X as TFkLookupResolver, _t as TGenericLogger, a as TDbEncryptionOptions, c as BaseDbAdapter, ct as TWriteTableResolver, i as DbEncryption, ot as TTableResolver, pt as TableMetadata, t as AtscriptDbReadable } from "./db-readable-BepVc21V.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
 
@@ -124,6 +124,21 @@ declare class AtscriptDbTable<T extends TAtscriptAnnotatedType = TAtscriptAnnota
124
124
  * Ensures the table/collection exists in the database.
125
125
  */
126
126
  ensureTable(): Promise<void>;
127
+ /** Engine-agnostic guard for user-supplied mutation filters (updateMany/deleteMany/…). */
128
+ protected _guardMutationFilter(filter: FilterExpr): void;
129
+ /**
130
+ * Encrypts `@db.encrypted` field values in place on (already validated)
131
+ * write payloads — between validation and `prepareForWrite`, so adapters
132
+ * only ever see envelope strings.
133
+ *
134
+ * Parent objects along an encrypted path are shallow-cloned before
135
+ * mutation so caller-shared nested objects are never modified.
136
+ *
137
+ * In `patch` mode, operator objects (`$inc`, `$insert`, …) targeting an
138
+ * encrypted field are rejected with `ENC_FIELD_PATCH_OP` — ciphertext is
139
+ * opaque; only plain re-assignment (which re-encrypts) is allowed.
140
+ */
141
+ protected _encryptItems(items: Array<Record<string, unknown>>, mode: "write" | "patch"): Promise<void>;
127
142
  /**
128
143
  * Applies default values for fields that are missing from the payload.
129
144
  * Defaults handled natively by the DB engine are skipped — the field stays
@@ -259,6 +274,13 @@ declare class AtscriptDbView<T extends TAtscriptAnnotatedType = TAtscriptAnnotat
259
274
  * Each readable gets its own adapter (1:1 relationship required by BaseDbAdapter).
260
275
  */
261
276
  type TAdapterFactory = () => BaseDbAdapter;
277
+ /** Options bag for {@link DbSpace} (second constructor argument). */
278
+ interface TDbSpaceOptions {
279
+ /** Logger shared by all tables/views in the space. */
280
+ logger?: TGenericLogger;
281
+ /** Field-level encryption configuration for `@db.encrypted` fields. */
282
+ encryption?: TDbEncryptionOptions;
283
+ }
262
284
  /**
263
285
  * A database space — a registry of tables and views sharing the same adapter type and driver.
264
286
  *
@@ -279,13 +301,20 @@ type TAdapterFactory = () => BaseDbAdapter;
279
301
  */
280
302
  declare class DbSpace {
281
303
  protected readonly adapterFactory: TAdapterFactory;
282
- protected readonly logger: TGenericLogger;
283
304
  private _readables;
284
305
  /** All tables created in this space — used for reverse FK lookup during cascade. */
285
306
  private _allTables;
286
307
  /** Lazily created adapter for administrative ops (drop table/view) that don't need a registered readable. */
287
308
  private _adminAdapter?;
288
- constructor(adapterFactory: TAdapterFactory, logger?: TGenericLogger);
309
+ protected readonly logger: TGenericLogger;
310
+ /** Encryption service for `@db.encrypted` fields — validated eagerly at construction. */
311
+ protected readonly _encryption?: DbEncryption;
312
+ /**
313
+ * @param adapterFactory - Creates a fresh adapter per table/view.
314
+ * @param loggerOrOptions - Either a logger (legacy signature) or a
315
+ * {@link TDbSpaceOptions} bag carrying `logger` and/or `encryption`.
316
+ */
317
+ constructor(adapterFactory: TAdapterFactory, loggerOrOptions?: TGenericLogger | TDbSpaceOptions);
289
318
  /**
290
319
  * Auto-detects whether the type is a table or view and returns the
291
320
  * appropriate instance. Uses `@db.view` or `@db.view.for` presence to distinguish.
@@ -327,4 +356,4 @@ declare class DbSpace {
327
356
  private _getFkLookupTarget;
328
357
  }
329
358
  //#endregion
330
- export { AtscriptQueryComparison as a, AtscriptRef as c, translateQueryTree as d, AtscriptDbTable as f, TViewColumnMapping as i, TViewJoin as l, NativeIntegrity as m, TAdapterFactory as n, AtscriptQueryFieldRef$1 as o, IntegrityStrategy as p, AtscriptDbView as r, AtscriptQueryNode$1 as s, DbSpace as t, TViewPlan as u };
359
+ export { TViewColumnMapping as a, AtscriptQueryNode$1 as c, TViewPlan as d, translateQueryTree as f, NativeIntegrity as h, AtscriptDbView as i, AtscriptRef as l, IntegrityStrategy as m, TAdapterFactory as n, AtscriptQueryComparison as o, AtscriptDbTable as p, TDbSpaceOptions as r, AtscriptQueryFieldRef$1 as s, DbSpace as t, TViewJoin as u };