@lossless.org/client 1.0.0 → 1.1.0

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.
@@ -175,6 +175,13 @@ type TSmartdataAtomicIncrement<T> = Partial<Record<{
175
175
  export type TSmartdataNumericDocumentPath<T> = {
176
176
  [TKey in TSmartdataDocumentPath<T>]: NonNullable<T[TKey]> extends number ? TKey : never;
177
177
  }[TSmartdataDocumentPath<T>];
178
+ /** Declared top-level fields that carry a monotonic ordering: numbers and dates. */
179
+ export type TSmartdataMonotonicDocumentPath<T> = {
180
+ [TKey in TSmartdataDocumentPath<T>]: NonNullable<T[TKey]> extends number ? TKey : NonNullable<T[TKey]> extends Date ? TKey : never;
181
+ }[TSmartdataDocumentPath<T>];
182
+ type TSmartdataAtomicMonotonic<T> = Partial<{
183
+ [TKey in TSmartdataMonotonicDocumentPath<T>]: NonNullable<T[TKey]> extends Date ? Date : number;
184
+ }> & Partial<Record<TSmartdataAtomicNestedDocumentPath<T>, number | Date>>;
178
185
  export type TSmartdataAtomicNumericFieldReference<T> = `$${TSmartdataNumericDocumentPath<T>}`;
179
186
  export type TSmartdataAtomicNumericExpressionOperand<T> = number | TSmartdataAtomicNumericFieldReference<T> | {
180
187
  $add: readonly [
@@ -243,6 +250,18 @@ export interface ISmartdataAtomicUpdate<T> {
243
250
  $set?: TSmartdataAtomicSet<T>;
244
251
  $unset?: Partial<Record<TSmartdataAtomicDocumentPath<T>, '' | true | 1>>;
245
252
  $inc?: TSmartdataAtomicIncrement<T>;
253
+ /**
254
+ * Monotonic ceiling for a declared numeric or date field: one server-side
255
+ * compare-and-write that never lowers the stored value, so a retried or
256
+ * out-of-order writer cannot regress a counter. With `upsert: true` a
257
+ * missing field is inserted with the operand.
258
+ */
259
+ $max?: TSmartdataAtomicMonotonic<T>;
260
+ /**
261
+ * Monotonic floor for a declared numeric or date field: the mirror of
262
+ * `$max`, never raising the stored value.
263
+ */
264
+ $min?: TSmartdataAtomicMonotonic<T>;
246
265
  $setOnInsert?: TSmartdataAtomicSet<T>;
247
266
  /**
248
267
  * Appends one element to a declared top-level array field. Modifier
@@ -356,6 +375,27 @@ export interface ISmartdataAtomicUpdateManyResult {
356
375
  matchedCount: number;
357
376
  modifiedCount: number;
358
377
  }
378
+ /** One strict selector and its update, both validated before any write. */
379
+ export interface ISmartdataAtomicUpsertManyOperation<T> {
380
+ filter: TSmartdataAtomicFilter<T>;
381
+ update: ISmartdataAtomicUpdate<T>;
382
+ }
383
+ export interface ISmartdataAtomicUpsertManyOptions {
384
+ session?: TSmartdataOrdinarySession;
385
+ /** Client-side bulk operation deadline, including server selection and pool waits. */
386
+ timeoutMS?: number;
387
+ /**
388
+ * Only `false`. The batch is always unordered, so one conflicting entry
389
+ * never hides the outcome of the entries behind it.
390
+ */
391
+ ordered?: false;
392
+ }
393
+ export interface ISmartdataAtomicUpsertManyResult {
394
+ acknowledged: boolean;
395
+ matchedCount: number;
396
+ modifiedCount: number;
397
+ upsertedCount: number;
398
+ }
359
399
  export declare const convertFilterForMongoDb: (filterArg: {
360
400
  [key: string]: any;
361
401
  }) => {
@@ -386,6 +426,16 @@ export declare class SmartDataDbDoc<T extends TImplements, TImplements, TManager
386
426
  private static getDeclaredUniqueRoots;
387
427
  private static getDeclaredIdentityValueTypes;
388
428
  private static getDeclaredNumericRoots;
429
+ /**
430
+ * Returns the declared identity field this model stores as the document
431
+ * `_id`, or undefined when SmartData owns the primary key.
432
+ */
433
+ private static getIdentityDocumentIdField;
434
+ /**
435
+ * Converts an ordinary read filter and routes a declared document-id
436
+ * identity onto `_id`, so reads use the primary key index.
437
+ */
438
+ private static normalizeReadFilter;
389
439
  /**
390
440
  * Returns every equality key set that globally constrains a single document
391
441
  * of this model: each declared identity field on its own, plus the full key
@@ -485,6 +535,14 @@ export declare class SmartDataDbDoc<T extends TImplements, TImplements, TManager
485
535
  * rejected.
486
536
  */
487
537
  static atomicUpdateMany<T>(this: plugins.tsclass.typeFest.Class<T>, filterArg: TSmartdataAtomicFilter<T>, updateArg: Omit<ISmartdataAtomicUpdate<T>, '$setOnInsert'>, opts?: ISmartdataAtomicUpdateManyOptions): Promise<ISmartdataAtomicUpdateManyResult>;
538
+ /**
539
+ * Atomically upserts a bounded batch of ordinary model documents in one
540
+ * round trip. Every entry carries its own strict selector and update, and
541
+ * each entry applies atomically; the batch as a whole is not isolated unless
542
+ * the caller supplies a transaction session. The complete batch is validated
543
+ * before any write, so one invalid entry rejects the call without writing.
544
+ */
545
+ static atomicUpsertMany<T>(this: plugins.tsclass.typeFest.Class<T>, operationsArg: ReadonlyArray<ISmartdataAtomicUpsertManyOperation<T>>, opts?: ISmartdataAtomicUpsertManyOptions): Promise<ISmartdataAtomicUpsertManyResult>;
488
546
  /**
489
547
  * Computes bounded grouped counts and optional numeric sums server-side.
490
548
  * Groups by one or two declared top-level fields, always returns a `count`