@cipherstash/stack 0.1.0 → 0.3.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +11 -14
  3. package/dist/bin/stash.js +90 -57
  4. package/dist/bin/stash.js.map +1 -1
  5. package/dist/{chunk-SJ7JO4ME.js → chunk-JLI27P46.js} +1 -1
  6. package/dist/chunk-JLI27P46.js.map +1 -0
  7. package/dist/{chunk-2GZMIJFO.js → chunk-MW6D52V2.js} +69 -43
  8. package/dist/chunk-MW6D52V2.js.map +1 -0
  9. package/dist/{chunk-5DCT6YU2.js → chunk-OAPLZLR5.js} +7 -3
  10. package/dist/{chunk-5DCT6YU2.js.map → chunk-OAPLZLR5.js.map} +1 -1
  11. package/dist/{chunk-7XRPN2KX.js → chunk-TBAIVO6T.js} +26 -23
  12. package/dist/chunk-TBAIVO6T.js.map +1 -0
  13. package/dist/{client-BxJG56Ey.d.cts → client-Bf0Xw2xo.d.cts} +44 -26
  14. package/dist/{client-DtGq9dJp.d.ts → client-Kfp8OsPB.d.ts} +44 -26
  15. package/dist/client.cjs +25 -22
  16. package/dist/client.cjs.map +1 -1
  17. package/dist/client.d.cts +2 -2
  18. package/dist/client.d.ts +2 -2
  19. package/dist/client.js +5 -5
  20. package/dist/drizzle/index.cjs +19 -16
  21. package/dist/drizzle/index.cjs.map +1 -1
  22. package/dist/drizzle/index.d.cts +5 -5
  23. package/dist/drizzle/index.d.ts +5 -5
  24. package/dist/drizzle/index.js +2 -2
  25. package/dist/drizzle/index.js.map +1 -1
  26. package/dist/dynamodb/index.cjs.map +1 -1
  27. package/dist/dynamodb/index.d.cts +10 -10
  28. package/dist/dynamodb/index.d.ts +10 -10
  29. package/dist/dynamodb/index.js.map +1 -1
  30. package/dist/identity/index.cjs +6 -2
  31. package/dist/identity/index.cjs.map +1 -1
  32. package/dist/identity/index.js +1 -1
  33. package/dist/index.cjs +94 -61
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +3 -3
  36. package/dist/index.d.ts +3 -3
  37. package/dist/index.js +7 -7
  38. package/dist/schema/index.cjs +31 -28
  39. package/dist/schema/index.cjs.map +1 -1
  40. package/dist/schema/index.d.cts +1 -1
  41. package/dist/schema/index.d.ts +1 -1
  42. package/dist/schema/index.js +11 -11
  43. package/dist/secrets/index.cjs +90 -57
  44. package/dist/secrets/index.cjs.map +1 -1
  45. package/dist/secrets/index.d.cts +1 -1
  46. package/dist/secrets/index.d.ts +1 -1
  47. package/dist/secrets/index.js +4 -4
  48. package/dist/secrets/index.js.map +1 -1
  49. package/dist/supabase/index.cjs +7 -7
  50. package/dist/supabase/index.cjs.map +1 -1
  51. package/dist/supabase/index.d.cts +3 -3
  52. package/dist/supabase/index.d.ts +3 -3
  53. package/dist/supabase/index.js +3 -3
  54. package/dist/supabase/index.js.map +1 -1
  55. package/dist/{types-public-BCj1L4fi.d.ts → types-public-0CzBV45X.d.cts} +100 -58
  56. package/dist/{types-public-BCj1L4fi.d.cts → types-public-0CzBV45X.d.ts} +100 -58
  57. package/dist/types-public.cjs.map +1 -1
  58. package/dist/types-public.d.cts +1 -1
  59. package/dist/types-public.d.ts +1 -1
  60. package/dist/types-public.js +1 -1
  61. package/package.json +1 -1
  62. package/dist/chunk-2GZMIJFO.js.map +0 -1
  63. package/dist/chunk-7XRPN2KX.js.map +0 -1
  64. package/dist/chunk-SJ7JO4ME.js.map +0 -1
@@ -132,7 +132,7 @@ var encryptConfigSchema = import_zod.z.object({
132
132
  v: import_zod.z.number(),
133
133
  tables: tablesSchema
134
134
  });
135
- var ProtectValue = class {
135
+ var EncryptedField = class {
136
136
  valueName;
137
137
  castAsValue;
138
138
  constructor(valueName) {
@@ -140,20 +140,20 @@ var ProtectValue = class {
140
140
  this.castAsValue = "string";
141
141
  }
142
142
  /**
143
- * Set or override the plaintext data type for this value.
143
+ * Set or override the plaintext data type for this field.
144
144
  *
145
145
  * By default all values are treated as `'string'`. Use this method to specify
146
146
  * a different type so the encryption layer knows how to encode the plaintext
147
147
  * before encrypting.
148
148
  *
149
149
  * @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.
150
- * @returns This `ProtectValue` instance for method chaining.
150
+ * @returns This `EncryptedField` instance for method chaining.
151
151
  *
152
152
  * @example
153
153
  * ```typescript
154
- * import { encryptedValue } from "@cipherstash/stack/schema"
154
+ * import { encryptedField } from "@cipherstash/stack/schema"
155
155
  *
156
- * const age = encryptedValue("age").dataType("number")
156
+ * const age = encryptedField("age").dataType("number")
157
157
  * ```
158
158
  */
159
159
  dataType(castAs) {
@@ -170,7 +170,7 @@ var ProtectValue = class {
170
170
  return this.valueName;
171
171
  }
172
172
  };
173
- var ProtectColumn = class {
173
+ var EncryptedColumn = class {
174
174
  columnName;
175
175
  castAsValue;
176
176
  indexesValue = {};
@@ -186,7 +186,7 @@ var ProtectColumn = class {
186
186
  * before encrypting.
187
187
  *
188
188
  * @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.
189
- * @returns This `ProtectColumn` instance for method chaining.
189
+ * @returns This `EncryptedColumn` instance for method chaining.
190
190
  *
191
191
  * @example
192
192
  * ```typescript
@@ -205,7 +205,7 @@ var ProtectColumn = class {
205
205
  * ORE allows sorting, comparison, and range queries on encrypted data.
206
206
  * Use with `encryptQuery` and `queryType: 'orderAndRange'`.
207
207
  *
208
- * @returns This `ProtectColumn` instance for method chaining.
208
+ * @returns This `EncryptedColumn` instance for method chaining.
209
209
  *
210
210
  * @example
211
211
  * ```typescript
@@ -228,7 +228,7 @@ var ProtectColumn = class {
228
228
  *
229
229
  * @param tokenFilters - Optional array of token filters (e.g. `[{ kind: 'downcase' }]`).
230
230
  * When omitted, no token filters are applied.
231
- * @returns This `ProtectColumn` instance for method chaining.
231
+ * @returns This `EncryptedColumn` instance for method chaining.
232
232
  *
233
233
  * @example
234
234
  * ```typescript
@@ -253,7 +253,7 @@ var ProtectColumn = class {
253
253
  *
254
254
  * @param opts - Optional match index configuration. Defaults to 3-character ngram
255
255
  * tokenization with a downcase filter, `k=6`, `m=2048`, and `include_original=true`.
256
- * @returns This `ProtectColumn` instance for method chaining.
256
+ * @returns This `EncryptedColumn` instance for method chaining.
257
257
  *
258
258
  * @example
259
259
  * ```typescript
@@ -298,7 +298,7 @@ var ProtectColumn = class {
298
298
  * the plaintext type: strings become selector queries, objects/arrays become
299
299
  * containment queries.
300
300
  *
301
- * @returns This `ProtectColumn` instance for method chaining.
301
+ * @returns This `EncryptedColumn` instance for method chaining.
302
302
  *
303
303
  * @example
304
304
  * ```typescript
@@ -324,7 +324,7 @@ var ProtectColumn = class {
324
324
  return this.columnName;
325
325
  }
326
326
  };
327
- var ProtectTable = class {
327
+ var EncryptedTable = class {
328
328
  constructor(tableName, columnBuilders) {
329
329
  this.tableName = tableName;
330
330
  this.columnBuilders = columnBuilders;
@@ -351,7 +351,7 @@ var ProtectTable = class {
351
351
  build() {
352
352
  const builtColumns = {};
353
353
  const processColumn = (builder, colName) => {
354
- if (builder instanceof ProtectColumn) {
354
+ if (builder instanceof EncryptedColumn) {
355
355
  const builtColumn = builder.build();
356
356
  if (builtColumn.cast_as === "json" && builtColumn.indexes.ste_vec?.prefix === "enabled") {
357
357
  builtColumns[colName] = {
@@ -368,7 +368,7 @@ var ProtectTable = class {
368
368
  }
369
369
  } else {
370
370
  for (const [key, value] of Object.entries(builder)) {
371
- if (value instanceof ProtectValue) {
371
+ if (value instanceof EncryptedField) {
372
372
  builtColumns[value.getName()] = value.build();
373
373
  } else {
374
374
  processColumn(value, key);
@@ -386,7 +386,10 @@ var ProtectTable = class {
386
386
  }
387
387
  };
388
388
  function encryptedTable(tableName, columns) {
389
- const tableBuilder = new ProtectTable(tableName, columns);
389
+ const tableBuilder = new EncryptedTable(
390
+ tableName,
391
+ columns
392
+ );
390
393
  for (const [colName, colBuilder] of Object.entries(columns)) {
391
394
  ;
392
395
  tableBuilder[colName] = colBuilder;
@@ -394,7 +397,7 @@ function encryptedTable(tableName, columns) {
394
397
  return tableBuilder;
395
398
  }
396
399
  function encryptedColumn(columnName) {
397
- return new ProtectColumn(columnName);
400
+ return new EncryptedColumn(columnName);
398
401
  }
399
402
  function buildEncryptConfig(...protectTables) {
400
403
  const config = {
@@ -488,7 +491,7 @@ function initStackLogger(config) {
488
491
  const rates = samplingFromEnv();
489
492
  (0, import_evlog.initLogger)({
490
493
  env: { service: "@cipherstash/stack" },
491
- enabled: config?.enabled ?? true,
494
+ enabled: config?.enabled ?? !!rates,
492
495
  pretty: config?.pretty,
493
496
  ...rates && { sampling: { rates } },
494
497
  ...config?.drain && { drain: config.drain }
@@ -501,7 +504,11 @@ function safeMessage(args) {
501
504
  var logger = {
502
505
  debug(...args) {
503
506
  const log = (0, import_evlog.createRequestLogger)();
504
- log.set({ level: "debug", source: "@cipherstash/stack", message: safeMessage(args) });
507
+ log.set({
508
+ level: "debug",
509
+ source: "@cipherstash/stack",
510
+ message: safeMessage(args)
511
+ });
505
512
  log.emit();
506
513
  },
507
514
  info(...args) {
@@ -522,22 +529,22 @@ var logger = {
522
529
  }
523
530
  };
524
531
 
525
- // src/encryption/ffi/index.ts
532
+ // src/encryption/index.ts
526
533
  var import_result11 = require("@byteslice/result");
527
534
  var import_protect_ffi9 = require("@cipherstash/protect-ffi");
528
535
 
529
- // src/encryption/ffi/helpers/type-guards.ts
536
+ // src/encryption/helpers/type-guards.ts
530
537
  function isScalarQueryTermArray(value) {
531
538
  return Array.isArray(value) && value.length > 0 && typeof value[0] === "object" && value[0] !== null && "column" in value[0] && "table" in value[0];
532
539
  }
533
540
 
534
- // src/encryption/ffi/helpers/error-code.ts
541
+ // src/encryption/helpers/error-code.ts
535
542
  var import_protect_ffi = require("@cipherstash/protect-ffi");
536
543
  function getErrorCode(error) {
537
544
  return error instanceof import_protect_ffi.ProtectError ? error.code : void 0;
538
545
  }
539
546
 
540
- // src/encryption/ffi/operations/batch-encrypt-query.ts
547
+ // src/encryption/operations/batch-encrypt-query.ts
541
548
  var import_result = require("@byteslice/result");
542
549
  var import_protect_ffi2 = require("@cipherstash/protect-ffi");
543
550
 
@@ -555,7 +562,7 @@ var queryTypeToQueryOp = {
555
562
  steVecTerm: "ste_vec_term"
556
563
  };
557
564
 
558
- // src/encryption/ffi/helpers/infer-index-type.ts
565
+ // src/encryption/helpers/infer-index-type.ts
559
566
  function inferIndexType(column) {
560
567
  const config = column.build();
561
568
  const indexes = config.indexes;
@@ -615,7 +622,7 @@ function resolveIndexType(column, queryType, plaintext) {
615
622
  return { indexType };
616
623
  }
617
624
 
618
- // src/encryption/ffi/helpers/validation.ts
625
+ // src/encryption/helpers/validation.ts
619
626
  function validateNumericValue(value) {
620
627
  if (typeof value === "number" && Number.isNaN(value)) {
621
628
  return {
@@ -651,7 +658,7 @@ function assertValueIndexCompatibility(value, indexType, columnName) {
651
658
  }
652
659
  }
653
660
 
654
- // src/encryption/ffi/operations/base-operation.ts
661
+ // src/encryption/operations/base-operation.ts
655
662
  var EncryptionOperation = class {
656
663
  auditMetadata;
657
664
  /**
@@ -679,7 +686,7 @@ var EncryptionOperation = class {
679
686
  }
680
687
  };
681
688
 
682
- // src/encryption/ffi/operations/batch-encrypt-query.ts
689
+ // src/encryption/operations/batch-encrypt-query.ts
683
690
  function filterNullTerms(terms) {
684
691
  const nullIndices = /* @__PURE__ */ new Set();
685
692
  const nonNullTerms = [];
@@ -834,7 +841,7 @@ var BatchEncryptQueryOperationWithLockContext = class extends EncryptionOperatio
834
841
  }
835
842
  };
836
843
 
837
- // src/encryption/ffi/operations/bulk-decrypt.ts
844
+ // src/encryption/operations/bulk-decrypt.ts
838
845
  var import_result2 = require("@byteslice/result");
839
846
  var import_protect_ffi3 = require("@cipherstash/protect-ffi");
840
847
  var createDecryptPayloads = (encryptedPayloads, lockContext) => {
@@ -985,10 +992,10 @@ var BulkDecryptOperationWithLockContext = class extends EncryptionOperation {
985
992
  }
986
993
  };
987
994
 
988
- // src/encryption/ffi/operations/bulk-decrypt-models.ts
995
+ // src/encryption/operations/bulk-decrypt-models.ts
989
996
  var import_result3 = require("@byteslice/result");
990
997
 
991
- // src/encryption/ffi/model-helpers.ts
998
+ // src/encryption/helpers/model-helpers.ts
992
999
  var import_protect_ffi4 = require("@cipherstash/protect-ffi");
993
1000
  function setNestedValue(obj, path2, value) {
994
1001
  const FORBIDDEN_KEYS = ["__proto__", "prototype", "constructor"];
@@ -1503,7 +1510,7 @@ async function bulkEncryptModelsWithLockContext(models, table, client, lockConte
1503
1510
  });
1504
1511
  }
1505
1512
 
1506
- // src/encryption/ffi/operations/bulk-decrypt-models.ts
1513
+ // src/encryption/operations/bulk-decrypt-models.ts
1507
1514
  var BulkDecryptModelsOperation = class extends EncryptionOperation {
1508
1515
  client;
1509
1516
  models;
@@ -1600,7 +1607,7 @@ var BulkDecryptModelsOperationWithLockContext = class extends EncryptionOperatio
1600
1607
  }
1601
1608
  };
1602
1609
 
1603
- // src/encryption/ffi/operations/bulk-encrypt.ts
1610
+ // src/encryption/operations/bulk-encrypt.ts
1604
1611
  var import_result4 = require("@byteslice/result");
1605
1612
  var import_protect_ffi5 = require("@cipherstash/protect-ffi");
1606
1613
  var createEncryptPayloads = (plaintexts, column, table, lockContext) => {
@@ -1765,7 +1772,7 @@ var BulkEncryptOperationWithLockContext = class extends EncryptionOperation {
1765
1772
  }
1766
1773
  };
1767
1774
 
1768
- // src/encryption/ffi/operations/bulk-encrypt-models.ts
1775
+ // src/encryption/operations/bulk-encrypt-models.ts
1769
1776
  var import_result5 = require("@byteslice/result");
1770
1777
  var BulkEncryptModelsOperation = class extends EncryptionOperation {
1771
1778
  client;
@@ -1874,7 +1881,7 @@ var BulkEncryptModelsOperationWithLockContext = class extends EncryptionOperatio
1874
1881
  }
1875
1882
  };
1876
1883
 
1877
- // src/encryption/ffi/operations/decrypt.ts
1884
+ // src/encryption/operations/decrypt.ts
1878
1885
  var import_result6 = require("@byteslice/result");
1879
1886
  var import_protect_ffi6 = require("@cipherstash/protect-ffi");
1880
1887
  var DecryptOperation = class extends EncryptionOperation {
@@ -1981,7 +1988,7 @@ var DecryptOperationWithLockContext = class extends EncryptionOperation {
1981
1988
  }
1982
1989
  };
1983
1990
 
1984
- // src/encryption/ffi/operations/decrypt-model.ts
1991
+ // src/encryption/operations/decrypt-model.ts
1985
1992
  var import_result7 = require("@byteslice/result");
1986
1993
  var DecryptModelOperation = class extends EncryptionOperation {
1987
1994
  client;
@@ -2077,7 +2084,7 @@ var DecryptModelOperationWithLockContext = class extends EncryptionOperation {
2077
2084
  }
2078
2085
  };
2079
2086
 
2080
- // src/encryption/ffi/operations/encrypt.ts
2087
+ // src/encryption/operations/encrypt.ts
2081
2088
  var import_result8 = require("@byteslice/result");
2082
2089
  var import_protect_ffi7 = require("@cipherstash/protect-ffi");
2083
2090
  var EncryptOperation = class extends EncryptionOperation {
@@ -2203,7 +2210,7 @@ var EncryptOperationWithLockContext = class extends EncryptionOperation {
2203
2210
  }
2204
2211
  };
2205
2212
 
2206
- // src/encryption/ffi/operations/encrypt-model.ts
2213
+ // src/encryption/operations/encrypt-model.ts
2207
2214
  var import_result9 = require("@byteslice/result");
2208
2215
  var EncryptModelOperation = class extends EncryptionOperation {
2209
2216
  client;
@@ -2310,7 +2317,7 @@ var EncryptModelOperationWithLockContext = class extends EncryptionOperation {
2310
2317
  }
2311
2318
  };
2312
2319
 
2313
- // src/encryption/ffi/operations/encrypt-query.ts
2320
+ // src/encryption/operations/encrypt-query.ts
2314
2321
  var import_result10 = require("@byteslice/result");
2315
2322
  var import_protect_ffi8 = require("@cipherstash/protect-ffi");
2316
2323
  var EncryptQueryOperation = class extends EncryptionOperation {
@@ -2460,9 +2467,9 @@ var EncryptQueryOperationWithLockContext = class extends EncryptionOperation {
2460
2467
  }
2461
2468
  };
2462
2469
 
2463
- // src/encryption/ffi/index.ts
2470
+ // src/encryption/index.ts
2464
2471
  var noClientError = () => new Error(
2465
- "The EQL client has not been initialized. Please call init() before using the client."
2472
+ "The Encryption client has not been initialized. Please call init() before using the client."
2466
2473
  );
2467
2474
  var EncryptionClient = class {
2468
2475
  client;
@@ -2485,7 +2492,7 @@ var EncryptionClient = class {
2485
2492
  config.encryptConfig
2486
2493
  );
2487
2494
  logger.debug(
2488
- "Initializing the Protect.js client with the following encrypt config:",
2495
+ "Initializing the Encryption client with the following config:",
2489
2496
  {
2490
2497
  encryptConfig: validated
2491
2498
  }
@@ -2493,15 +2500,15 @@ var EncryptionClient = class {
2493
2500
  this.client = await (0, import_protect_ffi9.newClient)({
2494
2501
  encryptConfig: validated,
2495
2502
  clientOpts: {
2496
- workspaceCrn: config.workspaceCrn,
2497
- accessKey: config.accessKey,
2498
- clientId: config.clientId,
2499
- clientKey: config.clientKey,
2503
+ workspaceCrn: config.workspaceCrn ?? process.env.CS_WORKSPACE_CRN,
2504
+ accessKey: config.accessKey ?? process.env.CS_CLIENT_ACCESS_KEY,
2505
+ clientId: config.clientId ?? process.env.CS_CLIENT_ID,
2506
+ clientKey: config.clientKey ?? process.env.CS_CLIENT_KEY,
2500
2507
  keyset: toFfiKeysetIdentifier(config.keyset)
2501
2508
  }
2502
2509
  });
2503
2510
  this.encryptConfig = validated;
2504
- logger.debug("Successfully initialized the Protect.js client.");
2511
+ logger.debug("Successfully initialized the Encryption client.");
2505
2512
  return this;
2506
2513
  },
2507
2514
  (error) => ({
@@ -2514,7 +2521,7 @@ var EncryptionClient = class {
2514
2521
  * Encrypt a value - returns a promise which resolves to an encrypted value.
2515
2522
  *
2516
2523
  * @param plaintext - The plaintext value to be encrypted. Can be null.
2517
- * @param opts - Options specifying the column and table for encryption.
2524
+ * @param opts - Options specifying the column (or nested field) and table for encryption. See {@link EncryptOptions}.
2518
2525
  * @returns An EncryptOperation that can be awaited or chained with additional methods.
2519
2526
  *
2520
2527
  * @example
@@ -2577,8 +2584,11 @@ var EncryptionClient = class {
2577
2584
  * .withLockContext(lockContext)
2578
2585
  * ```
2579
2586
  *
2587
+ * @see {@link EncryptOptions}
2580
2588
  * @see {@link Result}
2581
2589
  * @see {@link encryptedTable}
2590
+ * @see {@link encryptedColumn}
2591
+ * @see {@link encryptedField}
2582
2592
  * @see {@link LockContext}
2583
2593
  * @see {@link EncryptOperation}
2584
2594
  */
@@ -2646,10 +2656,16 @@ var EncryptionClient = class {
2646
2656
  * All other fields are passed through unchanged. Returns a thenable operation
2647
2657
  * that supports `.withLockContext()` for identity-aware encryption.
2648
2658
  *
2659
+ * The return type is **schema-aware**: fields matching the table schema are
2660
+ * typed as `Encrypted`, while other fields retain their original types. For
2661
+ * best results, let TypeScript infer the type parameters from the arguments
2662
+ * rather than providing an explicit type argument.
2663
+ *
2649
2664
  * @param input - The model object with plaintext values to encrypt.
2650
2665
  * @param table - The table schema defining which fields to encrypt.
2651
- * @returns An `EncryptModelOperation<T>` that can be awaited to get a `Result`
2652
- * containing the model with encrypted fields, or an `EncryptionError`.
2666
+ * @returns An `EncryptModelOperation` that can be awaited to get a `Result`
2667
+ * containing the model with schema-defined fields typed as `Encrypted`,
2668
+ * or an `EncryptionError`.
2653
2669
  *
2654
2670
  * @example
2655
2671
  * ```typescript
@@ -2664,7 +2680,9 @@ var EncryptionClient = class {
2664
2680
  *
2665
2681
  * const client = await Encryption({ schemas: [usersSchema] })
2666
2682
  *
2667
- * const result = await client.encryptModel<User>(
2683
+ * // Let TypeScript infer the return type from the schema.
2684
+ * // result.data.email is typed as `Encrypted`, result.data.id stays `string`.
2685
+ * const result = await client.encryptModel(
2668
2686
  * { id: "user_123", email: "alice@example.com", createdAt: new Date() },
2669
2687
  * usersSchema,
2670
2688
  * )
@@ -2672,13 +2690,17 @@ var EncryptionClient = class {
2672
2690
  * if (result.failure) {
2673
2691
  * console.error(result.failure.message)
2674
2692
  * } else {
2675
- * // result.data.id is unchanged, result.data.email is encrypted
2676
- * console.log(result.data)
2693
+ * console.log(result.data.id) // string
2694
+ * console.log(result.data.email) // Encrypted
2677
2695
  * }
2678
2696
  * ```
2679
2697
  */
2680
2698
  encryptModel(input, table) {
2681
- return new EncryptModelOperation(this.client, input, table);
2699
+ return new EncryptModelOperation(
2700
+ this.client,
2701
+ input,
2702
+ table
2703
+ );
2682
2704
  }
2683
2705
  /**
2684
2706
  * Decrypt a model (object) whose fields contain encrypted values.
@@ -2718,10 +2740,15 @@ var EncryptionClient = class {
2718
2740
  * while still using a unique key for each encrypted value. Only fields
2719
2741
  * matching the table schema are encrypted; other fields pass through unchanged.
2720
2742
  *
2743
+ * The return type is **schema-aware**: fields matching the table schema are
2744
+ * typed as `Encrypted`, while other fields retain their original types. For
2745
+ * best results, let TypeScript infer the type parameters from the arguments.
2746
+ *
2721
2747
  * @param input - An array of model objects with plaintext values to encrypt.
2722
2748
  * @param table - The table schema defining which fields to encrypt.
2723
- * @returns A `BulkEncryptModelsOperation<T>` that can be awaited to get a `Result`
2724
- * containing an array of models with encrypted fields, or an `EncryptionError`.
2749
+ * @returns A `BulkEncryptModelsOperation` that can be awaited to get a `Result`
2750
+ * containing an array of models with schema-defined fields typed as `Encrypted`,
2751
+ * or an `EncryptionError`.
2725
2752
  *
2726
2753
  * @example
2727
2754
  * ```typescript
@@ -2736,7 +2763,9 @@ var EncryptionClient = class {
2736
2763
  *
2737
2764
  * const client = await Encryption({ schemas: [usersSchema] })
2738
2765
  *
2739
- * const result = await client.bulkEncryptModels<User>(
2766
+ * // Let TypeScript infer the return type from the schema.
2767
+ * // Each item's email is typed as `Encrypted`, id stays `string`.
2768
+ * const result = await client.bulkEncryptModels(
2740
2769
  * [
2741
2770
  * { id: "1", email: "alice@example.com" },
2742
2771
  * { id: "2", email: "bob@example.com" },
@@ -2750,7 +2779,11 @@ var EncryptionClient = class {
2750
2779
  * ```
2751
2780
  */
2752
2781
  bulkEncryptModels(input, table) {
2753
- return new BulkEncryptModelsOperation(this.client, input, table);
2782
+ return new BulkEncryptModelsOperation(
2783
+ this.client,
2784
+ input,
2785
+ table
2786
+ );
2754
2787
  }
2755
2788
  /**
2756
2789
  * Decrypt multiple models (objects) in a single bulk operation.
@@ -2791,7 +2824,7 @@ var EncryptionClient = class {
2791
2824
  * your application data. Null plaintext values are preserved as null.
2792
2825
  *
2793
2826
  * @param plaintexts - An array of objects with `plaintext` (and optional `id`) fields.
2794
- * @param opts - Options specifying the target column and table for encryption.
2827
+ * @param opts - Options specifying the target column (or nested {@link encryptedField}) and table. See {@link EncryptOptions}.
2795
2828
  * @returns A `BulkEncryptOperation` that can be awaited to get a `Result`
2796
2829
  * containing an array of `{ id?, data: Encrypted }` objects, or an `EncryptionError`.
2797
2830
  *