@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
@@ -43,7 +43,7 @@ var encryptConfigSchema = z.object({
43
43
  v: z.number(),
44
44
  tables: tablesSchema
45
45
  });
46
- var ProtectValue = class {
46
+ var EncryptedField = class {
47
47
  valueName;
48
48
  castAsValue;
49
49
  constructor(valueName) {
@@ -51,20 +51,20 @@ var ProtectValue = class {
51
51
  this.castAsValue = "string";
52
52
  }
53
53
  /**
54
- * Set or override the plaintext data type for this value.
54
+ * Set or override the plaintext data type for this field.
55
55
  *
56
56
  * By default all values are treated as `'string'`. Use this method to specify
57
57
  * a different type so the encryption layer knows how to encode the plaintext
58
58
  * before encrypting.
59
59
  *
60
60
  * @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.
61
- * @returns This `ProtectValue` instance for method chaining.
61
+ * @returns This `EncryptedField` instance for method chaining.
62
62
  *
63
63
  * @example
64
64
  * ```typescript
65
- * import { encryptedValue } from "@cipherstash/stack/schema"
65
+ * import { encryptedField } from "@cipherstash/stack/schema"
66
66
  *
67
- * const age = encryptedValue("age").dataType("number")
67
+ * const age = encryptedField("age").dataType("number")
68
68
  * ```
69
69
  */
70
70
  dataType(castAs) {
@@ -81,7 +81,7 @@ var ProtectValue = class {
81
81
  return this.valueName;
82
82
  }
83
83
  };
84
- var ProtectColumn = class {
84
+ var EncryptedColumn = class {
85
85
  columnName;
86
86
  castAsValue;
87
87
  indexesValue = {};
@@ -97,7 +97,7 @@ var ProtectColumn = class {
97
97
  * before encrypting.
98
98
  *
99
99
  * @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.
100
- * @returns This `ProtectColumn` instance for method chaining.
100
+ * @returns This `EncryptedColumn` instance for method chaining.
101
101
  *
102
102
  * @example
103
103
  * ```typescript
@@ -116,7 +116,7 @@ var ProtectColumn = class {
116
116
  * ORE allows sorting, comparison, and range queries on encrypted data.
117
117
  * Use with `encryptQuery` and `queryType: 'orderAndRange'`.
118
118
  *
119
- * @returns This `ProtectColumn` instance for method chaining.
119
+ * @returns This `EncryptedColumn` instance for method chaining.
120
120
  *
121
121
  * @example
122
122
  * ```typescript
@@ -139,7 +139,7 @@ var ProtectColumn = class {
139
139
  *
140
140
  * @param tokenFilters - Optional array of token filters (e.g. `[{ kind: 'downcase' }]`).
141
141
  * When omitted, no token filters are applied.
142
- * @returns This `ProtectColumn` instance for method chaining.
142
+ * @returns This `EncryptedColumn` instance for method chaining.
143
143
  *
144
144
  * @example
145
145
  * ```typescript
@@ -164,7 +164,7 @@ var ProtectColumn = class {
164
164
  *
165
165
  * @param opts - Optional match index configuration. Defaults to 3-character ngram
166
166
  * tokenization with a downcase filter, `k=6`, `m=2048`, and `include_original=true`.
167
- * @returns This `ProtectColumn` instance for method chaining.
167
+ * @returns This `EncryptedColumn` instance for method chaining.
168
168
  *
169
169
  * @example
170
170
  * ```typescript
@@ -209,7 +209,7 @@ var ProtectColumn = class {
209
209
  * the plaintext type: strings become selector queries, objects/arrays become
210
210
  * containment queries.
211
211
  *
212
- * @returns This `ProtectColumn` instance for method chaining.
212
+ * @returns This `EncryptedColumn` instance for method chaining.
213
213
  *
214
214
  * @example
215
215
  * ```typescript
@@ -235,7 +235,7 @@ var ProtectColumn = class {
235
235
  return this.columnName;
236
236
  }
237
237
  };
238
- var ProtectTable = class {
238
+ var EncryptedTable = class {
239
239
  constructor(tableName, columnBuilders) {
240
240
  this.tableName = tableName;
241
241
  this.columnBuilders = columnBuilders;
@@ -262,7 +262,7 @@ var ProtectTable = class {
262
262
  build() {
263
263
  const builtColumns = {};
264
264
  const processColumn = (builder, colName) => {
265
- if (builder instanceof ProtectColumn) {
265
+ if (builder instanceof EncryptedColumn) {
266
266
  const builtColumn = builder.build();
267
267
  if (builtColumn.cast_as === "json" && builtColumn.indexes.ste_vec?.prefix === "enabled") {
268
268
  builtColumns[colName] = {
@@ -279,7 +279,7 @@ var ProtectTable = class {
279
279
  }
280
280
  } else {
281
281
  for (const [key, value] of Object.entries(builder)) {
282
- if (value instanceof ProtectValue) {
282
+ if (value instanceof EncryptedField) {
283
283
  builtColumns[value.getName()] = value.build();
284
284
  } else {
285
285
  processColumn(value, key);
@@ -297,7 +297,10 @@ var ProtectTable = class {
297
297
  }
298
298
  };
299
299
  function encryptedTable(tableName, columns) {
300
- const tableBuilder = new ProtectTable(tableName, columns);
300
+ const tableBuilder = new EncryptedTable(
301
+ tableName,
302
+ columns
303
+ );
301
304
  for (const [colName, colBuilder] of Object.entries(columns)) {
302
305
  ;
303
306
  tableBuilder[colName] = colBuilder;
@@ -305,10 +308,10 @@ function encryptedTable(tableName, columns) {
305
308
  return tableBuilder;
306
309
  }
307
310
  function encryptedColumn(columnName) {
308
- return new ProtectColumn(columnName);
311
+ return new EncryptedColumn(columnName);
309
312
  }
310
- function encryptedValue(valueName) {
311
- return new ProtectValue(valueName);
313
+ function encryptedField(valueName) {
314
+ return new EncryptedField(valueName);
312
315
  }
313
316
  function buildEncryptConfig(...protectTables) {
314
317
  const config = {
@@ -325,12 +328,12 @@ function buildEncryptConfig(...protectTables) {
325
328
  export {
326
329
  castAsEnum,
327
330
  encryptConfigSchema,
328
- ProtectValue,
329
- ProtectColumn,
330
- ProtectTable,
331
+ EncryptedField,
332
+ EncryptedColumn,
333
+ EncryptedTable,
331
334
  encryptedTable,
332
335
  encryptedColumn,
333
- encryptedValue,
336
+ encryptedField,
334
337
  buildEncryptConfig
335
338
  };
336
- //# sourceMappingURL=chunk-7XRPN2KX.js.map
339
+ //# sourceMappingURL=chunk-TBAIVO6T.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/schema/index.ts"],"sourcesContent":["import type { Encrypted } from '@/types'\nimport { z } from 'zod'\n\n// ------------------------\n// Zod schemas\n// ------------------------\n\n/**\n * Allowed cast types for CipherStash schema fields.\n *\n * **Possible values:**\n * - `\"bigint\"`\n * - `\"boolean\"`\n * - `\"date\"`\n * - `\"number\"`\n * - `\"string\"`\n * - `\"json\"`\n *\n * @remarks\n * This is a Zod enum used at runtime to validate schema definitions.\n * Use {@link CastAs} when typing your own code.\n *\n * @internal\n */\nexport const castAsEnum = z\n .enum(['bigint', 'boolean', 'date', 'number', 'string', 'json'])\n .default('string')\n\nconst tokenFilterSchema = z.object({\n kind: z.literal('downcase'),\n})\n\nconst tokenizerSchema = z\n .union([\n z.object({\n kind: z.literal('standard'),\n }),\n z.object({\n kind: z.literal('ngram'),\n token_length: z.number(),\n }),\n ])\n .default({ kind: 'ngram', token_length: 3 })\n .optional()\n\nconst oreIndexOptsSchema = z.object({})\n\nconst uniqueIndexOptsSchema = z.object({\n token_filters: z.array(tokenFilterSchema).default([]).optional(),\n})\n\nconst matchIndexOptsSchema = z.object({\n tokenizer: tokenizerSchema,\n token_filters: z.array(tokenFilterSchema).default([]).optional(),\n k: z.number().default(6).optional(),\n m: z.number().default(2048).optional(),\n include_original: z.boolean().default(false).optional(),\n})\n\nconst steVecIndexOptsSchema = z.object({\n prefix: z.string(),\n})\n\nconst indexesSchema = z\n .object({\n ore: oreIndexOptsSchema.optional(),\n unique: uniqueIndexOptsSchema.optional(),\n match: matchIndexOptsSchema.optional(),\n ste_vec: steVecIndexOptsSchema.optional(),\n })\n .default({})\n\nconst columnSchema = z\n .object({\n cast_as: castAsEnum,\n indexes: indexesSchema,\n })\n .default({})\n\nconst tableSchema = z.record(columnSchema).default({})\n\nconst tablesSchema = z.record(tableSchema).default({})\n\n/** @internal */\nexport const encryptConfigSchema = z.object({\n v: z.number(),\n tables: tablesSchema,\n})\n\n// ------------------------\n// Type definitions\n// ------------------------\n\n/**\n * Type-safe alias for {@link castAsEnum} used to specify the *unencrypted* data type of a column or value.\n * This is important because once encrypted, all data is stored as binary blobs.\n *\n * @see {@link castAsEnum} for possible values.\n */\nexport type CastAs = z.infer<typeof castAsEnum>\nexport type TokenFilter = z.infer<typeof tokenFilterSchema>\nexport type MatchIndexOpts = z.infer<typeof matchIndexOptsSchema>\nexport type SteVecIndexOpts = z.infer<typeof steVecIndexOptsSchema>\nexport type UniqueIndexOpts = z.infer<typeof uniqueIndexOptsSchema>\nexport type OreIndexOpts = z.infer<typeof oreIndexOptsSchema>\nexport type ColumnSchema = z.infer<typeof columnSchema>\n\n/**\n * Shape of table columns: either top-level {@link EncryptedColumn} or nested\n * objects whose leaves are {@link EncryptedField}. Used with {@link encryptedTable}.\n */\nexport type EncryptedTableColumn = {\n [key: string]:\n | EncryptedColumn\n | {\n [key: string]:\n | EncryptedField\n | {\n [key: string]:\n | EncryptedField\n | {\n [key: string]: EncryptedField\n }\n }\n }\n}\nexport type EncryptConfig = z.infer<typeof encryptConfigSchema>\n\n// ------------------------\n// Interface definitions\n// ------------------------\n\n/**\n * Builder for a nested encrypted field (encrypted but not searchable).\n * Create with {@link encryptedField}. Use inside nested objects in {@link encryptedTable};\n * supports `.dataType()` for plaintext type. No index methods (equality, orderAndRange, etc.).\n */\nexport class EncryptedField {\n private valueName: string\n private castAsValue: CastAs\n\n constructor(valueName: string) {\n this.valueName = valueName\n this.castAsValue = 'string'\n }\n\n /**\n * Set or override the plaintext data type for this field.\n *\n * By default all values are treated as `'string'`. Use this method to specify\n * a different type so the encryption layer knows how to encode the plaintext\n * before encrypting.\n *\n * @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.\n * @returns This `EncryptedField` instance for method chaining.\n *\n * @example\n * ```typescript\n * import { encryptedField } from \"@cipherstash/stack/schema\"\n *\n * const age = encryptedField(\"age\").dataType(\"number\")\n * ```\n */\n dataType(castAs: CastAs) {\n this.castAsValue = castAs\n return this\n }\n\n build() {\n return {\n cast_as: this.castAsValue,\n indexes: {},\n }\n }\n\n getName() {\n return this.valueName\n }\n}\n\nexport class EncryptedColumn {\n private columnName: string\n private castAsValue: CastAs\n private indexesValue: {\n ore?: OreIndexOpts\n unique?: UniqueIndexOpts\n match?: Required<MatchIndexOpts>\n ste_vec?: SteVecIndexOpts\n } = {}\n\n constructor(columnName: string) {\n this.columnName = columnName\n this.castAsValue = 'string'\n }\n\n /**\n * Set or override the plaintext data type for this column.\n *\n * By default all columns are treated as `'string'`. Use this method to specify\n * a different type so the encryption layer knows how to encode the plaintext\n * before encrypting.\n *\n * @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.\n * @returns This `EncryptedColumn` instance for method chaining.\n *\n * @example\n * ```typescript\n * import { encryptedColumn } from \"@cipherstash/stack/schema\"\n *\n * const dateOfBirth = encryptedColumn(\"date_of_birth\").dataType(\"date\")\n * ```\n */\n dataType(castAs: CastAs) {\n this.castAsValue = castAs\n return this\n }\n\n /**\n * Enable Order-Revealing Encryption (ORE) indexing on this column.\n *\n * ORE allows sorting, comparison, and range queries on encrypted data.\n * Use with `encryptQuery` and `queryType: 'orderAndRange'`.\n *\n * @returns This `EncryptedColumn` instance for method chaining.\n *\n * @example\n * ```typescript\n * import { encryptedTable, encryptedColumn } from \"@cipherstash/stack/schema\"\n *\n * const users = encryptedTable(\"users\", {\n * email: encryptedColumn(\"email\").orderAndRange(),\n * })\n * ```\n */\n orderAndRange() {\n this.indexesValue.ore = {}\n return this\n }\n\n /**\n * Enable an exact-match (unique) index on this column.\n *\n * Allows equality queries on encrypted data. Use with `encryptQuery`\n * and `queryType: 'equality'`.\n *\n * @param tokenFilters - Optional array of token filters (e.g. `[{ kind: 'downcase' }]`).\n * When omitted, no token filters are applied.\n * @returns This `EncryptedColumn` instance for method chaining.\n *\n * @example\n * ```typescript\n * import { encryptedTable, encryptedColumn } from \"@cipherstash/stack/schema\"\n *\n * const users = encryptedTable(\"users\", {\n * email: encryptedColumn(\"email\").equality(),\n * })\n * ```\n */\n equality(tokenFilters?: TokenFilter[]) {\n this.indexesValue.unique = {\n token_filters: tokenFilters ?? [],\n }\n return this\n }\n\n /**\n * Enable a full-text / fuzzy search (match) index on this column.\n *\n * Uses n-gram tokenization by default for substring and fuzzy matching.\n * Use with `encryptQuery` and `queryType: 'freeTextSearch'`.\n *\n * @param opts - Optional match index configuration. Defaults to 3-character ngram\n * tokenization with a downcase filter, `k=6`, `m=2048`, and `include_original=true`.\n * @returns This `EncryptedColumn` instance for method chaining.\n *\n * @example\n * ```typescript\n * import { encryptedTable, encryptedColumn } from \"@cipherstash/stack/schema\"\n *\n * const users = encryptedTable(\"users\", {\n * email: encryptedColumn(\"email\").freeTextSearch(),\n * })\n *\n * // With custom options\n * const posts = encryptedTable(\"posts\", {\n * body: encryptedColumn(\"body\").freeTextSearch({\n * tokenizer: { kind: \"ngram\", token_length: 4 },\n * k: 8,\n * m: 4096,\n * }),\n * })\n * ```\n */\n freeTextSearch(opts?: MatchIndexOpts) {\n // Provide defaults\n this.indexesValue.match = {\n tokenizer: opts?.tokenizer ?? { kind: 'ngram', token_length: 3 },\n token_filters: opts?.token_filters ?? [\n {\n kind: 'downcase',\n },\n ],\n k: opts?.k ?? 6,\n m: opts?.m ?? 2048,\n include_original: opts?.include_original ?? true,\n }\n return this\n }\n\n /**\n * Configure this column for searchable encrypted JSON (STE-Vec).\n *\n * Enables encrypted JSONPath selector queries (e.g. `'$.user.email'`) and\n * containment queries (e.g. `{ role: 'admin' }`). Automatically sets the\n * data type to `'json'`.\n *\n * When used with `encryptQuery`, the query operation is auto-inferred from\n * the plaintext type: strings become selector queries, objects/arrays become\n * containment queries.\n *\n * @returns This `EncryptedColumn` instance for method chaining.\n *\n * @example\n * ```typescript\n * import { encryptedTable, encryptedColumn } from \"@cipherstash/stack/schema\"\n *\n * const documents = encryptedTable(\"documents\", {\n * metadata: encryptedColumn(\"metadata\").searchableJson(),\n * })\n * ```\n */\n searchableJson() {\n this.castAsValue = 'json'\n this.indexesValue.ste_vec = { prefix: 'enabled' }\n return this\n }\n\n build() {\n return {\n cast_as: this.castAsValue,\n indexes: this.indexesValue,\n }\n }\n\n getName() {\n return this.columnName\n }\n}\n\ninterface TableDefinition {\n tableName: string\n columns: Record<string, ColumnSchema>\n}\n\nexport class EncryptedTable<T extends EncryptedTableColumn> {\n /** @internal Type-level brand so TypeScript can infer `T` from `EncryptedTable<T>`. */\n declare readonly _columnType: T\n\n constructor(\n public readonly tableName: string,\n private readonly columnBuilders: T,\n ) {}\n\n /**\n * Compile this table schema into a `TableDefinition` used internally by the encryption client.\n *\n * Iterates over all column builders, calls `.build()` on each, and assembles\n * the final `{ tableName, columns }` structure. For `searchableJson()` columns,\n * the STE-Vec prefix is automatically set to `\"<tableName>/<columnName>\"`.\n *\n * @returns A `TableDefinition` containing the table name and built column configs.\n *\n * @example\n * ```typescript\n * const users = encryptedTable(\"users\", {\n * email: encryptedColumn(\"email\").equality(),\n * })\n *\n * const definition = users.build()\n * // { tableName: \"users\", columns: { email: { cast_as: \"string\", indexes: { unique: ... } } } }\n * ```\n */\n build(): TableDefinition {\n const builtColumns: Record<string, ColumnSchema> = {}\n\n const processColumn = (\n builder:\n | EncryptedColumn\n | Record<\n string,\n | EncryptedField\n | Record<\n string,\n | EncryptedField\n | Record<\n string,\n EncryptedField | Record<string, EncryptedField>\n >\n >\n >,\n colName: string,\n ) => {\n if (builder instanceof EncryptedColumn) {\n const builtColumn = builder.build()\n\n // Hanlde building the ste_vec index for JSON columns so users don't have to pass the prefix.\n if (\n builtColumn.cast_as === 'json' &&\n builtColumn.indexes.ste_vec?.prefix === 'enabled'\n ) {\n builtColumns[colName] = {\n ...builtColumn,\n indexes: {\n ...builtColumn.indexes,\n ste_vec: {\n prefix: `${this.tableName}/${colName}`,\n },\n },\n }\n } else {\n builtColumns[colName] = builtColumn\n }\n } else {\n for (const [key, value] of Object.entries(builder)) {\n if (value instanceof EncryptedField) {\n builtColumns[value.getName()] = value.build()\n } else {\n processColumn(value, key)\n }\n }\n }\n }\n\n for (const [colName, builder] of Object.entries(this.columnBuilders)) {\n processColumn(builder, colName)\n }\n\n return {\n tableName: this.tableName,\n columns: builtColumns,\n }\n }\n}\n\n// ------------------------\n// Schema type inference helpers\n// ------------------------\n\n/**\n * Infer the plaintext (decrypted) type from a EncryptedTable schema.\n *\n * @example\n * ```typescript\n * const users = encryptedTable(\"users\", {\n * email: encryptedColumn(\"email\").equality(),\n * name: encryptedColumn(\"name\"),\n * })\n *\n * type UserPlaintext = InferPlaintext<typeof users>\n * // => { email: string; name: string }\n * ```\n */\nexport type InferPlaintext<T extends EncryptedTable<any>> =\n T extends EncryptedTable<infer C>\n ? {\n [K in keyof C as C[K] extends EncryptedColumn | EncryptedField\n ? K\n : never]: string\n }\n : never\n\n/**\n * Infer the encrypted type from a EncryptedTable schema.\n *\n * @example\n * ```typescript\n * const users = encryptedTable(\"users\", {\n * email: encryptedColumn(\"email\").equality(),\n * })\n *\n * type UserEncrypted = InferEncrypted<typeof users>\n * // => { email: Encrypted }\n * ```\n */\nexport type InferEncrypted<T extends EncryptedTable<any>> =\n T extends EncryptedTable<infer C>\n ? {\n [K in keyof C as C[K] extends EncryptedColumn | EncryptedField\n ? K\n : never]: Encrypted\n }\n : never\n\n// ------------------------\n// User facing functions\n// ------------------------\n\n/**\n * Define an encrypted table schema.\n *\n * Creates a `EncryptedTable` that maps a database table name to a set of encrypted\n * column definitions. Pass the resulting object to `Encryption({ schemas: [...] })`\n * when initializing the client.\n *\n * The returned object is also a proxy that exposes each column builder directly,\n * so you can reference columns as `users.email` when calling `encrypt`, `decrypt`,\n * and `encryptQuery`.\n *\n * @param tableName - The name of the database table this schema represents.\n * @param columns - An object whose keys are logical column names and values are\n * {@link EncryptedColumn} from {@link encryptedColumn}, or nested objects whose\n * leaves are {@link EncryptedField} from {@link encryptedField}.\n * @returns A `EncryptedTable<T> & T` that can be used as both a schema definition\n * and a column accessor.\n *\n * @example\n * ```typescript\n * import { encryptedTable, encryptedColumn } from \"@cipherstash/stack/schema\"\n *\n * const users = encryptedTable(\"users\", {\n * email: encryptedColumn(\"email\").equality().freeTextSearch(),\n * address: encryptedColumn(\"address\"),\n * })\n *\n * // Use as schema\n * const client = await Encryption({ schemas: [users] })\n *\n * // Use as column accessor\n * await client.encrypt(\"hello@example.com\", { column: users.email, table: users })\n * ```\n */\nexport function encryptedTable<T extends EncryptedTableColumn>(\n tableName: string,\n columns: T,\n): EncryptedTable<T> & T {\n const tableBuilder = new EncryptedTable(\n tableName,\n columns,\n ) as EncryptedTable<T> & T\n\n for (const [colName, colBuilder] of Object.entries(columns)) {\n ;(tableBuilder as EncryptedTableColumn)[colName] = colBuilder\n }\n\n return tableBuilder\n}\n\n/**\n * Define an encrypted column within a table schema.\n *\n * Creates a `EncryptedColumn` builder for the given column name. Chain index\n * methods (`.equality()`, `.freeTextSearch()`, `.orderAndRange()`,\n * `.searchableJson()`) and/or `.dataType()` to configure searchable encryption\n * and the plaintext data type.\n *\n * @param columnName - The name of the database column to encrypt.\n * @returns A new `EncryptedColumn` builder.\n *\n * @example\n * ```typescript\n * import { encryptedTable, encryptedColumn } from \"@cipherstash/stack/schema\"\n *\n * const users = encryptedTable(\"users\", {\n * email: encryptedColumn(\"email\").equality().freeTextSearch().orderAndRange(),\n * })\n * ```\n */\nexport function encryptedColumn(columnName: string) {\n return new EncryptedColumn(columnName)\n}\n\n/**\n * Define an encrypted field for use in nested or structured schemas.\n *\n * `encryptedField` is similar to {@link encryptedColumn} but creates an {@link EncryptedField}\n * for nested fields that are encrypted but not searchable (no indexes). Use `.dataType()`\n * to specify the plaintext type.\n *\n * @param valueName - The name of the value field.\n * @returns A new `EncryptedField` builder.\n *\n * @example\n * ```typescript\n * import { encryptedTable, encryptedField } from \"@cipherstash/stack/schema\"\n *\n * const orders = encryptedTable(\"orders\", {\n * details: {\n * amount: encryptedField(\"amount\").dataType(\"number\"),\n * currency: encryptedField(\"currency\"),\n * },\n * })\n * ```\n */\nexport function encryptedField(valueName: string) {\n return new EncryptedField(valueName)\n}\n\n// ------------------------\n// Internal functions\n// ------------------------\n\n/** @internal */\nexport function buildEncryptConfig(\n ...protectTables: Array<EncryptedTable<EncryptedTableColumn>>\n): EncryptConfig {\n const config: EncryptConfig = {\n v: 2,\n tables: {},\n }\n\n for (const tb of protectTables) {\n const tableDef = tb.build()\n config.tables[tableDef.tableName] = tableDef.columns\n }\n\n return config\n}\n"],"mappings":";AACA,SAAS,SAAS;AAuBX,IAAM,aAAa,EACvB,KAAK,CAAC,UAAU,WAAW,QAAQ,UAAU,UAAU,MAAM,CAAC,EAC9D,QAAQ,QAAQ;AAEnB,IAAM,oBAAoB,EAAE,OAAO;AAAA,EACjC,MAAM,EAAE,QAAQ,UAAU;AAC5B,CAAC;AAED,IAAM,kBAAkB,EACrB,MAAM;AAAA,EACL,EAAE,OAAO;AAAA,IACP,MAAM,EAAE,QA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S,IAAI,SAAS;AAAA,EAC/C;AAEA,SAAO;AACT;","names":[]}
@@ -1,4 +1,4 @@
1
- import { j as EncryptedQueryResult, k as Client, S as ScalarQueryTerm, B as BulkDecryptedData, l as BulkDecryptPayload, D as Decrypted, m as BulkEncryptedData, n as BulkEncryptPayload, o as EncryptOptions, P as ProtectColumn, g as ProtectValue, d as ProtectTable, f as ProtectTableColumn, h as Encrypted, p as EncryptQueryOptions, Q as QueryTypeName, q as EncryptedReturnType, r as EncryptConfig, K as KeysetIdentifier } from './types-public-BCj1L4fi.cjs';
1
+ import { l as EncryptedQueryResult, m as Client, S as ScalarQueryTerm, B as BulkDecryptedData, n as BulkDecryptPayload, D as Decrypted, o as BulkEncryptedData, p as BulkEncryptPayload, q as EncryptOptions, d as EncryptedColumn, h as EncryptedField, f as EncryptedTable, g as EncryptedTableColumn, j as Encrypted, r as EncryptQueryOptions, Q as QueryTypeName, s as EncryptedReturnType, t as EncryptConfig, K as KeysetIdentifier, i as EncryptedFromSchema } from './types-public-0CzBV45X.cjs';
2
2
  import { a as EncryptionError, d as LockContext } from './index-9-Ya3fDK.cjs';
3
3
  import { Result } from '@byteslice/result';
4
4
  import { JsPlaintext } from '@cipherstash/protect-ffi';
@@ -99,8 +99,8 @@ declare class BulkEncryptOperation extends EncryptionOperation<BulkEncryptedData
99
99
  getOperation(): {
100
100
  client: Client;
101
101
  plaintexts: BulkEncryptPayload;
102
- column: ProtectColumn | ProtectValue;
103
- table: ProtectTable<ProtectTableColumn>;
102
+ column: EncryptedColumn | EncryptedField;
103
+ table: EncryptedTable<EncryptedTableColumn>;
104
104
  };
105
105
  }
106
106
  declare class BulkEncryptOperationWithLockContext extends EncryptionOperation<BulkEncryptedData> {
@@ -114,13 +114,13 @@ declare class BulkEncryptModelsOperation<T extends Record<string, unknown>> exte
114
114
  private client;
115
115
  private models;
116
116
  private table;
117
- constructor(client: Client, models: Decrypted<T>[], table: ProtectTable<ProtectTableColumn>);
117
+ constructor(client: Client, models: Record<string, unknown>[], table: EncryptedTable<EncryptedTableColumn>);
118
118
  withLockContext(lockContext: LockContext): BulkEncryptModelsOperationWithLockContext<T>;
119
119
  execute(): Promise<Result<T[], EncryptionError>>;
120
120
  getOperation(): {
121
121
  client: Client;
122
- models: Decrypted<T>[];
123
- table: ProtectTable<ProtectTableColumn>;
122
+ models: Record<string, unknown>[];
123
+ table: EncryptedTable<EncryptedTableColumn>;
124
124
  };
125
125
  }
126
126
  declare class BulkEncryptModelsOperationWithLockContext<T extends Record<string, unknown>> extends EncryptionOperation<T[]> {
@@ -182,8 +182,8 @@ declare class EncryptOperation extends EncryptionOperation<Encrypted> {
182
182
  getOperation(): {
183
183
  client: Client;
184
184
  plaintext: JsPlaintext | null;
185
- column: ProtectColumn | ProtectValue;
186
- table: ProtectTable<ProtectTableColumn>;
185
+ column: EncryptedColumn | EncryptedField;
186
+ table: EncryptedTable<EncryptedTableColumn>;
187
187
  };
188
188
  }
189
189
  declare class EncryptOperationWithLockContext extends EncryptionOperation<Encrypted> {
@@ -197,13 +197,13 @@ declare class EncryptModelOperation<T extends Record<string, unknown>> extends E
197
197
  private client;
198
198
  private model;
199
199
  private table;
200
- constructor(client: Client, model: Decrypted<T>, table: ProtectTable<ProtectTableColumn>);
200
+ constructor(client: Client, model: Record<string, unknown>, table: EncryptedTable<EncryptedTableColumn>);
201
201
  withLockContext(lockContext: LockContext): EncryptModelOperationWithLockContext<T>;
202
202
  execute(): Promise<Result<T, EncryptionError>>;
203
203
  getOperation(): {
204
204
  client: Client;
205
- model: Decrypted<T>;
206
- table: ProtectTable<ProtectTableColumn>;
205
+ model: Record<string, unknown>;
206
+ table: EncryptedTable<EncryptedTableColumn>;
207
207
  };
208
208
  }
209
209
  declare class EncryptModelOperationWithLockContext<T extends Record<string, unknown>> extends EncryptionOperation<T> {
@@ -224,8 +224,8 @@ declare class EncryptQueryOperation extends EncryptionOperation<EncryptedQueryRe
224
224
  withLockContext(lockContext: LockContext): EncryptQueryOperationWithLockContext;
225
225
  execute(): Promise<Result<EncryptedQueryResult, EncryptionError>>;
226
226
  getOperation(): {
227
- column: ProtectColumn;
228
- table: ProtectTable<ProtectTableColumn>;
227
+ column: EncryptedColumn;
228
+ table: EncryptedTable<EncryptedTableColumn>;
229
229
  queryType?: QueryTypeName;
230
230
  returnType?: EncryptedReturnType;
231
231
  client: Client;
@@ -244,7 +244,7 @@ declare class EncryptQueryOperationWithLockContext extends EncryptionOperation<E
244
244
  execute(): Promise<Result<EncryptedQueryResult, EncryptionError>>;
245
245
  }
246
246
 
247
- /** The EncryptionClient is the main entry point for interacting with the CipherStash Protect.js library.
247
+ /** The EncryptionClient is the main entry point for interacting with the CipherStash Encryption library.
248
248
  * It provides methods for encrypting and decrypting individual values, as well as models (objects) and bulk operations.
249
249
  *
250
250
  * The client must be initialized using the {@link Encryption} function before it can be used.
@@ -272,7 +272,7 @@ declare class EncryptionClient {
272
272
  * Encrypt a value - returns a promise which resolves to an encrypted value.
273
273
  *
274
274
  * @param plaintext - The plaintext value to be encrypted. Can be null.
275
- * @param opts - Options specifying the column and table for encryption.
275
+ * @param opts - Options specifying the column (or nested field) and table for encryption. See {@link EncryptOptions}.
276
276
  * @returns An EncryptOperation that can be awaited or chained with additional methods.
277
277
  *
278
278
  * @example
@@ -335,8 +335,11 @@ declare class EncryptionClient {
335
335
  * .withLockContext(lockContext)
336
336
  * ```
337
337
  *
338
+ * @see {@link EncryptOptions}
338
339
  * @see {@link Result}
339
340
  * @see {@link encryptedTable}
341
+ * @see {@link encryptedColumn}
342
+ * @see {@link encryptedField}
340
343
  * @see {@link LockContext}
341
344
  * @see {@link EncryptOperation}
342
345
  */
@@ -440,10 +443,16 @@ declare class EncryptionClient {
440
443
  * All other fields are passed through unchanged. Returns a thenable operation
441
444
  * that supports `.withLockContext()` for identity-aware encryption.
442
445
  *
446
+ * The return type is **schema-aware**: fields matching the table schema are
447
+ * typed as `Encrypted`, while other fields retain their original types. For
448
+ * best results, let TypeScript infer the type parameters from the arguments
449
+ * rather than providing an explicit type argument.
450
+ *
443
451
  * @param input - The model object with plaintext values to encrypt.
444
452
  * @param table - The table schema defining which fields to encrypt.
445
- * @returns An `EncryptModelOperation<T>` that can be awaited to get a `Result`
446
- * containing the model with encrypted fields, or an `EncryptionError`.
453
+ * @returns An `EncryptModelOperation` that can be awaited to get a `Result`
454
+ * containing the model with schema-defined fields typed as `Encrypted`,
455
+ * or an `EncryptionError`.
447
456
  *
448
457
  * @example
449
458
  * ```typescript
@@ -458,7 +467,9 @@ declare class EncryptionClient {
458
467
  *
459
468
  * const client = await Encryption({ schemas: [usersSchema] })
460
469
  *
461
- * const result = await client.encryptModel<User>(
470
+ * // Let TypeScript infer the return type from the schema.
471
+ * // result.data.email is typed as `Encrypted`, result.data.id stays `string`.
472
+ * const result = await client.encryptModel(
462
473
  * { id: "user_123", email: "alice@example.com", createdAt: new Date() },
463
474
  * usersSchema,
464
475
  * )
@@ -466,12 +477,12 @@ declare class EncryptionClient {
466
477
  * if (result.failure) {
467
478
  * console.error(result.failure.message)
468
479
  * } else {
469
- * // result.data.id is unchanged, result.data.email is encrypted
470
- * console.log(result.data)
480
+ * console.log(result.data.id) // string
481
+ * console.log(result.data.email) // Encrypted
471
482
  * }
472
483
  * ```
473
484
  */
474
- encryptModel<T extends Record<string, unknown>>(input: Decrypted<T>, table: ProtectTable<ProtectTableColumn>): EncryptModelOperation<T>;
485
+ encryptModel<T extends Record<string, unknown>, S extends EncryptedTableColumn = EncryptedTableColumn>(input: T, table: EncryptedTable<S>): EncryptModelOperation<EncryptedFromSchema<T, S>>;
475
486
  /**
476
487
  * Decrypt a model (object) whose fields contain encrypted values.
477
488
  *
@@ -508,10 +519,15 @@ declare class EncryptionClient {
508
519
  * while still using a unique key for each encrypted value. Only fields
509
520
  * matching the table schema are encrypted; other fields pass through unchanged.
510
521
  *
522
+ * The return type is **schema-aware**: fields matching the table schema are
523
+ * typed as `Encrypted`, while other fields retain their original types. For
524
+ * best results, let TypeScript infer the type parameters from the arguments.
525
+ *
511
526
  * @param input - An array of model objects with plaintext values to encrypt.
512
527
  * @param table - The table schema defining which fields to encrypt.
513
- * @returns A `BulkEncryptModelsOperation<T>` that can be awaited to get a `Result`
514
- * containing an array of models with encrypted fields, or an `EncryptionError`.
528
+ * @returns A `BulkEncryptModelsOperation` that can be awaited to get a `Result`
529
+ * containing an array of models with schema-defined fields typed as `Encrypted`,
530
+ * or an `EncryptionError`.
515
531
  *
516
532
  * @example
517
533
  * ```typescript
@@ -526,7 +542,9 @@ declare class EncryptionClient {
526
542
  *
527
543
  * const client = await Encryption({ schemas: [usersSchema] })
528
544
  *
529
- * const result = await client.bulkEncryptModels<User>(
545
+ * // Let TypeScript infer the return type from the schema.
546
+ * // Each item's email is typed as `Encrypted`, id stays `string`.
547
+ * const result = await client.bulkEncryptModels(
530
548
  * [
531
549
  * { id: "1", email: "alice@example.com" },
532
550
  * { id: "2", email: "bob@example.com" },
@@ -539,7 +557,7 @@ declare class EncryptionClient {
539
557
  * }
540
558
  * ```
541
559
  */
542
- bulkEncryptModels<T extends Record<string, unknown>>(input: Array<Decrypted<T>>, table: ProtectTable<ProtectTableColumn>): BulkEncryptModelsOperation<T>;
560
+ bulkEncryptModels<T extends Record<string, unknown>, S extends EncryptedTableColumn = EncryptedTableColumn>(input: Array<T>, table: EncryptedTable<S>): BulkEncryptModelsOperation<EncryptedFromSchema<T, S>>;
543
561
  /**
544
562
  * Decrypt multiple models (objects) in a single bulk operation.
545
563
  *
@@ -577,7 +595,7 @@ declare class EncryptionClient {
577
595
  * your application data. Null plaintext values are preserved as null.
578
596
  *
579
597
  * @param plaintexts - An array of objects with `plaintext` (and optional `id`) fields.
580
- * @param opts - Options specifying the target column and table for encryption.
598
+ * @param opts - Options specifying the target column (or nested {@link encryptedField}) and table. See {@link EncryptOptions}.
581
599
  * @returns A `BulkEncryptOperation` that can be awaited to get a `Result`
582
600
  * containing an array of `{ id?, data: Encrypted }` objects, or an `EncryptionError`.
583
601
  *
@@ -1,4 +1,4 @@
1
- import { j as EncryptedQueryResult, k as Client, S as ScalarQueryTerm, B as BulkDecryptedData, l as BulkDecryptPayload, D as Decrypted, m as BulkEncryptedData, n as BulkEncryptPayload, o as EncryptOptions, P as ProtectColumn, g as ProtectValue, d as ProtectTable, f as ProtectTableColumn, h as Encrypted, p as EncryptQueryOptions, Q as QueryTypeName, q as EncryptedReturnType, r as EncryptConfig, K as KeysetIdentifier } from './types-public-BCj1L4fi.js';
1
+ import { l as EncryptedQueryResult, m as Client, S as ScalarQueryTerm, B as BulkDecryptedData, n as BulkDecryptPayload, D as Decrypted, o as BulkEncryptedData, p as BulkEncryptPayload, q as EncryptOptions, d as EncryptedColumn, h as EncryptedField, f as EncryptedTable, g as EncryptedTableColumn, j as Encrypted, r as EncryptQueryOptions, Q as QueryTypeName, s as EncryptedReturnType, t as EncryptConfig, K as KeysetIdentifier, i as EncryptedFromSchema } from './types-public-0CzBV45X.js';
2
2
  import { a as EncryptionError, d as LockContext } from './index-9-Ya3fDK.js';
3
3
  import { Result } from '@byteslice/result';
4
4
  import { JsPlaintext } from '@cipherstash/protect-ffi';
@@ -99,8 +99,8 @@ declare class BulkEncryptOperation extends EncryptionOperation<BulkEncryptedData
99
99
  getOperation(): {
100
100
  client: Client;
101
101
  plaintexts: BulkEncryptPayload;
102
- column: ProtectColumn | ProtectValue;
103
- table: ProtectTable<ProtectTableColumn>;
102
+ column: EncryptedColumn | EncryptedField;
103
+ table: EncryptedTable<EncryptedTableColumn>;
104
104
  };
105
105
  }
106
106
  declare class BulkEncryptOperationWithLockContext extends EncryptionOperation<BulkEncryptedData> {
@@ -114,13 +114,13 @@ declare class BulkEncryptModelsOperation<T extends Record<string, unknown>> exte
114
114
  private client;
115
115
  private models;
116
116
  private table;
117
- constructor(client: Client, models: Decrypted<T>[], table: ProtectTable<ProtectTableColumn>);
117
+ constructor(client: Client, models: Record<string, unknown>[], table: EncryptedTable<EncryptedTableColumn>);
118
118
  withLockContext(lockContext: LockContext): BulkEncryptModelsOperationWithLockContext<T>;
119
119
  execute(): Promise<Result<T[], EncryptionError>>;
120
120
  getOperation(): {
121
121
  client: Client;
122
- models: Decrypted<T>[];
123
- table: ProtectTable<ProtectTableColumn>;
122
+ models: Record<string, unknown>[];
123
+ table: EncryptedTable<EncryptedTableColumn>;
124
124
  };
125
125
  }
126
126
  declare class BulkEncryptModelsOperationWithLockContext<T extends Record<string, unknown>> extends EncryptionOperation<T[]> {
@@ -182,8 +182,8 @@ declare class EncryptOperation extends EncryptionOperation<Encrypted> {
182
182
  getOperation(): {
183
183
  client: Client;
184
184
  plaintext: JsPlaintext | null;
185
- column: ProtectColumn | ProtectValue;
186
- table: ProtectTable<ProtectTableColumn>;
185
+ column: EncryptedColumn | EncryptedField;
186
+ table: EncryptedTable<EncryptedTableColumn>;
187
187
  };
188
188
  }
189
189
  declare class EncryptOperationWithLockContext extends EncryptionOperation<Encrypted> {
@@ -197,13 +197,13 @@ declare class EncryptModelOperation<T extends Record<string, unknown>> extends E
197
197
  private client;
198
198
  private model;
199
199
  private table;
200
- constructor(client: Client, model: Decrypted<T>, table: ProtectTable<ProtectTableColumn>);
200
+ constructor(client: Client, model: Record<string, unknown>, table: EncryptedTable<EncryptedTableColumn>);
201
201
  withLockContext(lockContext: LockContext): EncryptModelOperationWithLockContext<T>;
202
202
  execute(): Promise<Result<T, EncryptionError>>;
203
203
  getOperation(): {
204
204
  client: Client;
205
- model: Decrypted<T>;
206
- table: ProtectTable<ProtectTableColumn>;
205
+ model: Record<string, unknown>;
206
+ table: EncryptedTable<EncryptedTableColumn>;
207
207
  };
208
208
  }
209
209
  declare class EncryptModelOperationWithLockContext<T extends Record<string, unknown>> extends EncryptionOperation<T> {
@@ -224,8 +224,8 @@ declare class EncryptQueryOperation extends EncryptionOperation<EncryptedQueryRe
224
224
  withLockContext(lockContext: LockContext): EncryptQueryOperationWithLockContext;
225
225
  execute(): Promise<Result<EncryptedQueryResult, EncryptionError>>;
226
226
  getOperation(): {
227
- column: ProtectColumn;
228
- table: ProtectTable<ProtectTableColumn>;
227
+ column: EncryptedColumn;
228
+ table: EncryptedTable<EncryptedTableColumn>;
229
229
  queryType?: QueryTypeName;
230
230
  returnType?: EncryptedReturnType;
231
231
  client: Client;
@@ -244,7 +244,7 @@ declare class EncryptQueryOperationWithLockContext extends EncryptionOperation<E
244
244
  execute(): Promise<Result<EncryptedQueryResult, EncryptionError>>;
245
245
  }
246
246
 
247
- /** The EncryptionClient is the main entry point for interacting with the CipherStash Protect.js library.
247
+ /** The EncryptionClient is the main entry point for interacting with the CipherStash Encryption library.
248
248
  * It provides methods for encrypting and decrypting individual values, as well as models (objects) and bulk operations.
249
249
  *
250
250
  * The client must be initialized using the {@link Encryption} function before it can be used.
@@ -272,7 +272,7 @@ declare class EncryptionClient {
272
272
  * Encrypt a value - returns a promise which resolves to an encrypted value.
273
273
  *
274
274
  * @param plaintext - The plaintext value to be encrypted. Can be null.
275
- * @param opts - Options specifying the column and table for encryption.
275
+ * @param opts - Options specifying the column (or nested field) and table for encryption. See {@link EncryptOptions}.
276
276
  * @returns An EncryptOperation that can be awaited or chained with additional methods.
277
277
  *
278
278
  * @example
@@ -335,8 +335,11 @@ declare class EncryptionClient {
335
335
  * .withLockContext(lockContext)
336
336
  * ```
337
337
  *
338
+ * @see {@link EncryptOptions}
338
339
  * @see {@link Result}
339
340
  * @see {@link encryptedTable}
341
+ * @see {@link encryptedColumn}
342
+ * @see {@link encryptedField}
340
343
  * @see {@link LockContext}
341
344
  * @see {@link EncryptOperation}
342
345
  */
@@ -440,10 +443,16 @@ declare class EncryptionClient {
440
443
  * All other fields are passed through unchanged. Returns a thenable operation
441
444
  * that supports `.withLockContext()` for identity-aware encryption.
442
445
  *
446
+ * The return type is **schema-aware**: fields matching the table schema are
447
+ * typed as `Encrypted`, while other fields retain their original types. For
448
+ * best results, let TypeScript infer the type parameters from the arguments
449
+ * rather than providing an explicit type argument.
450
+ *
443
451
  * @param input - The model object with plaintext values to encrypt.
444
452
  * @param table - The table schema defining which fields to encrypt.
445
- * @returns An `EncryptModelOperation<T>` that can be awaited to get a `Result`
446
- * containing the model with encrypted fields, or an `EncryptionError`.
453
+ * @returns An `EncryptModelOperation` that can be awaited to get a `Result`
454
+ * containing the model with schema-defined fields typed as `Encrypted`,
455
+ * or an `EncryptionError`.
447
456
  *
448
457
  * @example
449
458
  * ```typescript
@@ -458,7 +467,9 @@ declare class EncryptionClient {
458
467
  *
459
468
  * const client = await Encryption({ schemas: [usersSchema] })
460
469
  *
461
- * const result = await client.encryptModel<User>(
470
+ * // Let TypeScript infer the return type from the schema.
471
+ * // result.data.email is typed as `Encrypted`, result.data.id stays `string`.
472
+ * const result = await client.encryptModel(
462
473
  * { id: "user_123", email: "alice@example.com", createdAt: new Date() },
463
474
  * usersSchema,
464
475
  * )
@@ -466,12 +477,12 @@ declare class EncryptionClient {
466
477
  * if (result.failure) {
467
478
  * console.error(result.failure.message)
468
479
  * } else {
469
- * // result.data.id is unchanged, result.data.email is encrypted
470
- * console.log(result.data)
480
+ * console.log(result.data.id) // string
481
+ * console.log(result.data.email) // Encrypted
471
482
  * }
472
483
  * ```
473
484
  */
474
- encryptModel<T extends Record<string, unknown>>(input: Decrypted<T>, table: ProtectTable<ProtectTableColumn>): EncryptModelOperation<T>;
485
+ encryptModel<T extends Record<string, unknown>, S extends EncryptedTableColumn = EncryptedTableColumn>(input: T, table: EncryptedTable<S>): EncryptModelOperation<EncryptedFromSchema<T, S>>;
475
486
  /**
476
487
  * Decrypt a model (object) whose fields contain encrypted values.
477
488
  *
@@ -508,10 +519,15 @@ declare class EncryptionClient {
508
519
  * while still using a unique key for each encrypted value. Only fields
509
520
  * matching the table schema are encrypted; other fields pass through unchanged.
510
521
  *
522
+ * The return type is **schema-aware**: fields matching the table schema are
523
+ * typed as `Encrypted`, while other fields retain their original types. For
524
+ * best results, let TypeScript infer the type parameters from the arguments.
525
+ *
511
526
  * @param input - An array of model objects with plaintext values to encrypt.
512
527
  * @param table - The table schema defining which fields to encrypt.
513
- * @returns A `BulkEncryptModelsOperation<T>` that can be awaited to get a `Result`
514
- * containing an array of models with encrypted fields, or an `EncryptionError`.
528
+ * @returns A `BulkEncryptModelsOperation` that can be awaited to get a `Result`
529
+ * containing an array of models with schema-defined fields typed as `Encrypted`,
530
+ * or an `EncryptionError`.
515
531
  *
516
532
  * @example
517
533
  * ```typescript
@@ -526,7 +542,9 @@ declare class EncryptionClient {
526
542
  *
527
543
  * const client = await Encryption({ schemas: [usersSchema] })
528
544
  *
529
- * const result = await client.bulkEncryptModels<User>(
545
+ * // Let TypeScript infer the return type from the schema.
546
+ * // Each item's email is typed as `Encrypted`, id stays `string`.
547
+ * const result = await client.bulkEncryptModels(
530
548
  * [
531
549
  * { id: "1", email: "alice@example.com" },
532
550
  * { id: "2", email: "bob@example.com" },
@@ -539,7 +557,7 @@ declare class EncryptionClient {
539
557
  * }
540
558
  * ```
541
559
  */
542
- bulkEncryptModels<T extends Record<string, unknown>>(input: Array<Decrypted<T>>, table: ProtectTable<ProtectTableColumn>): BulkEncryptModelsOperation<T>;
560
+ bulkEncryptModels<T extends Record<string, unknown>, S extends EncryptedTableColumn = EncryptedTableColumn>(input: Array<T>, table: EncryptedTable<S>): BulkEncryptModelsOperation<EncryptedFromSchema<T, S>>;
543
561
  /**
544
562
  * Decrypt multiple models (objects) in a single bulk operation.
545
563
  *
@@ -577,7 +595,7 @@ declare class EncryptionClient {
577
595
  * your application data. Null plaintext values are preserved as null.
578
596
  *
579
597
  * @param plaintexts - An array of objects with `plaintext` (and optional `id`) fields.
580
- * @param opts - Options specifying the target column and table for encryption.
598
+ * @param opts - Options specifying the target column (or nested {@link encryptedField}) and table. See {@link EncryptOptions}.
581
599
  * @returns A `BulkEncryptOperation` that can be awaited to get a `Result`
582
600
  * containing an array of `{ id?, data: Encrypted }` objects, or an `EncryptionError`.
583
601
  *