@cipherstash/stack 0.19.0 → 1.0.0-rc.1

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 (101) hide show
  1. package/CHANGELOG.md +596 -0
  2. package/README.md +376 -276
  3. package/dist/adapter-kit.cjs +1002 -0
  4. package/dist/adapter-kit.cjs.map +1 -0
  5. package/dist/adapter-kit.d.cts +120 -0
  6. package/dist/adapter-kit.d.ts +120 -0
  7. package/dist/adapter-kit.js +122 -0
  8. package/dist/adapter-kit.js.map +1 -0
  9. package/dist/base-operation-AOAIvsSB.d.cts +32 -0
  10. package/dist/base-operation-FXEzUXIq.d.ts +32 -0
  11. package/dist/{chunk-4AVL4VZD.js → chunk-3B5ZX3IS.js} +3 -1
  12. package/dist/chunk-3B5ZX3IS.js.map +1 -0
  13. package/dist/{chunk-U66S7VIF.js → chunk-6SGN52W6.js} +166 -107
  14. package/dist/chunk-6SGN52W6.js.map +1 -0
  15. package/dist/chunk-7333ZC6L.js +48 -0
  16. package/dist/chunk-7333ZC6L.js.map +1 -0
  17. package/dist/{chunk-MP3SSDNN.js → chunk-CLM7E4I6.js} +15 -15
  18. package/dist/{chunk-MP3SSDNN.js.map → chunk-CLM7E4I6.js.map} +1 -1
  19. package/dist/{chunk-OFQ555AX.js → chunk-IDKP6ABU.js} +2 -2
  20. package/dist/{chunk-36AA7IBJ.js → chunk-L7ISHSG7.js} +53 -20
  21. package/dist/chunk-L7ISHSG7.js.map +1 -0
  22. package/dist/{chunk-LBMC4D6D.js → chunk-NVKK7UDN.js} +1 -1
  23. package/dist/chunk-NVKK7UDN.js.map +1 -0
  24. package/dist/chunk-X3JRXEIB.js +98 -0
  25. package/dist/chunk-X3JRXEIB.js.map +1 -0
  26. package/dist/client.cjs +29 -12
  27. package/dist/client.cjs.map +1 -1
  28. package/dist/client.d.cts +3 -2
  29. package/dist/client.d.ts +3 -2
  30. package/dist/client.js +2 -2
  31. package/dist/{table-CIH7jZ2h.d.ts → columns-0lbT9stl.d.ts} +157 -138
  32. package/dist/{table-DihEAlxG.d.cts → columns-Bxv7Oo9o.d.cts} +157 -138
  33. package/dist/dynamodb/index.d.cts +3 -2
  34. package/dist/dynamodb/index.d.ts +3 -2
  35. package/dist/encryption/index.cjs +54 -16
  36. package/dist/encryption/index.cjs.map +1 -1
  37. package/dist/encryption/index.d.cts +807 -6
  38. package/dist/encryption/index.d.ts +807 -6
  39. package/dist/encryption/index.js +6 -6
  40. package/dist/encryption/v3.cjs +1078 -973
  41. package/dist/encryption/v3.cjs.map +1 -1
  42. package/dist/encryption/v3.d.cts +15 -12
  43. package/dist/encryption/v3.d.ts +15 -12
  44. package/dist/encryption/v3.js +50 -22
  45. package/dist/encryption/v3.js.map +1 -1
  46. package/dist/eql/v3/index.cjs +130 -79
  47. package/dist/eql/v3/index.cjs.map +1 -1
  48. package/dist/eql/v3/index.d.cts +115 -13
  49. package/dist/eql/v3/index.d.ts +115 -13
  50. package/dist/eql/v3/index.js +16 -6
  51. package/dist/errors/index.cjs.map +1 -1
  52. package/dist/errors/index.d.cts +5 -5
  53. package/dist/errors/index.d.ts +5 -5
  54. package/dist/errors/index.js +1 -1
  55. package/dist/identity/index.cjs.map +1 -1
  56. package/dist/identity/index.js +2 -2
  57. package/dist/index-BquA71_Y.d.ts +24 -0
  58. package/dist/index-fhWTOV0K.d.cts +24 -0
  59. package/dist/index.cjs +79 -27
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.cts +5 -17
  62. package/dist/index.d.ts +5 -17
  63. package/dist/index.js +6 -6
  64. package/dist/schema/index.cjs +29 -12
  65. package/dist/schema/index.cjs.map +1 -1
  66. package/dist/schema/index.d.cts +1 -1
  67. package/dist/schema/index.d.ts +1 -1
  68. package/dist/schema/index.js +2 -2
  69. package/dist/{types-public-CpS5KjwX.d.ts → types-public-QMjYNfQO.d.cts} +765 -726
  70. package/dist/{types-public-CpS5KjwX.d.cts → types-public-QMjYNfQO.d.ts} +765 -726
  71. package/dist/types-public.cjs.map +1 -1
  72. package/dist/types-public.d.cts +1 -1
  73. package/dist/types-public.d.ts +1 -1
  74. package/dist/types-public.js +1 -1
  75. package/dist/wasm-inline.d.ts +779 -405
  76. package/dist/wasm-inline.js +606 -299
  77. package/dist/wasm-inline.js.map +1 -1
  78. package/package.json +25 -53
  79. package/dist/chunk-36AA7IBJ.js.map +0 -1
  80. package/dist/chunk-4AVL4VZD.js.map +0 -1
  81. package/dist/chunk-IADZCZEA.js +0 -23
  82. package/dist/chunk-IADZCZEA.js.map +0 -1
  83. package/dist/chunk-IBSK6P33.js +0 -209
  84. package/dist/chunk-IBSK6P33.js.map +0 -1
  85. package/dist/chunk-LBMC4D6D.js.map +0 -1
  86. package/dist/chunk-U66S7VIF.js.map +0 -1
  87. package/dist/client-DSGHBN-g.d.cts +0 -834
  88. package/dist/client-DfCrlHXh.d.ts +0 -834
  89. package/dist/drizzle/index.cjs +0 -5617
  90. package/dist/drizzle/index.cjs.map +0 -1
  91. package/dist/drizzle/index.d.cts +0 -358
  92. package/dist/drizzle/index.d.ts +0 -358
  93. package/dist/drizzle/index.js +0 -1220
  94. package/dist/drizzle/index.js.map +0 -1
  95. package/dist/supabase/index.cjs +0 -5951
  96. package/dist/supabase/index.cjs.map +0 -1
  97. package/dist/supabase/index.d.cts +0 -223
  98. package/dist/supabase/index.d.ts +0 -223
  99. package/dist/supabase/index.js +0 -1217
  100. package/dist/supabase/index.js.map +0 -1
  101. /package/dist/{chunk-OFQ555AX.js.map → chunk-IDKP6ABU.js.map} +0 -0
@@ -4159,6 +4159,7 @@ var tokenizerSchema = external_exports.union([
4159
4159
  })
4160
4160
  ]).default({ kind: "ngram", token_length: 3 }).optional();
4161
4161
  var oreIndexOptsSchema = external_exports.object({});
4162
+ var opeIndexOptsSchema = external_exports.object({});
4162
4163
  var uniqueIndexOptsSchema = external_exports.object({
4163
4164
  token_filters: external_exports.array(tokenFilterSchema).default([]).optional()
4164
4165
  });
@@ -4180,10 +4181,12 @@ var arrayIndexModeSchema = external_exports.union([
4180
4181
  ]);
4181
4182
  var steVecIndexOptsSchema = external_exports.object({
4182
4183
  prefix: external_exports.string(),
4183
- array_index_mode: arrayIndexModeSchema.optional()
4184
+ array_index_mode: arrayIndexModeSchema.optional(),
4185
+ mode: external_exports.enum(["compat", "standard"]).optional()
4184
4186
  });
4185
4187
  var indexesSchema = external_exports.object({
4186
4188
  ore: oreIndexOptsSchema.optional(),
4189
+ ope: opeIndexOptsSchema.optional(),
4187
4190
  unique: uniqueIndexOptsSchema.optional(),
4188
4191
  match: matchIndexOptsSchema.optional(),
4189
4192
  ste_vec: steVecIndexOptsSchema.optional()
@@ -4795,6 +4798,8 @@ var LockContext = class {
4795
4798
 
4796
4799
  // src/types.ts
4797
4800
  var queryTypeToFfi = {
4801
+ // v3 `_ord` domains carry `ope` instead — `resolveIndexType` swaps this
4802
+ // static default for the ordering index the column actually configures.
4798
4803
  orderAndRange: "ore",
4799
4804
  freeTextSearch: "match",
4800
4805
  equality: "unique",
@@ -4817,6 +4822,7 @@ function inferIndexType(column) {
4817
4822
  if (indexes.unique) return "unique";
4818
4823
  if (indexes.match) return "match";
4819
4824
  if (indexes.ore) return "ore";
4825
+ if (indexes.ope) return "ope";
4820
4826
  if (indexes.ste_vec) return "ste_vec";
4821
4827
  throw new Error(
4822
4828
  `Column "${column.getName()}" has no suitable index for queries`
@@ -4838,6 +4844,7 @@ function validateIndexType(column, indexType) {
4838
4844
  unique: !!indexes.unique,
4839
4845
  match: !!indexes.match,
4840
4846
  ore: !!indexes.ore,
4847
+ ope: !!indexes.ope,
4841
4848
  ste_vec: !!indexes.ste_vec
4842
4849
  };
4843
4850
  if (!indexMap[indexType]) {
@@ -4846,17 +4853,25 @@ function validateIndexType(column, indexType) {
4846
4853
  );
4847
4854
  }
4848
4855
  }
4849
- function resolvesEqualityViaOre(column) {
4850
- if (!("getQueryCapabilities" in column)) return false;
4851
- if (!column.getQueryCapabilities().equality) return false;
4856
+ function equalityOrderingIndex(column) {
4857
+ if (!("getQueryCapabilities" in column)) return null;
4858
+ if (!column.getQueryCapabilities().equality) return null;
4852
4859
  const indexes = column.build().indexes ?? {};
4853
- return !indexes.unique && !!indexes.ore;
4860
+ if (indexes.unique) return null;
4861
+ if (indexes.ore) return "ore";
4862
+ if (indexes.ope) return "ope";
4863
+ return null;
4854
4864
  }
4855
4865
  function resolveIndexType(column, queryType, plaintext) {
4856
- const indexType = queryType ? queryTypeToFfi[queryType] : inferIndexType(column);
4866
+ let indexType = queryType ? queryTypeToFfi[queryType] : inferIndexType(column);
4857
4867
  if (queryType) {
4858
- if (queryType === "equality" && resolvesEqualityViaOre(column)) {
4859
- return { indexType: "ore" };
4868
+ if (queryType === "equality") {
4869
+ const ordering = equalityOrderingIndex(column);
4870
+ if (ordering) return { indexType: ordering };
4871
+ }
4872
+ if (queryType === "orderAndRange" && indexType === "ore") {
4873
+ const indexes = column.build().indexes ?? {};
4874
+ if (!indexes.ore && indexes.ope) indexType = "ope";
4860
4875
  }
4861
4876
  validateIndexType(column, indexType);
4862
4877
  if (queryType === "searchableJson") {
@@ -4877,6 +4892,11 @@ function resolveIndexType(column, queryType, plaintext) {
4877
4892
  }
4878
4893
 
4879
4894
  // src/encryption/helpers/validation.ts
4895
+ var INT64_MIN = -9223372036854775808n;
4896
+ var INT64_MAX = 9223372036854775807n;
4897
+ function isBigintOutOfInt64Range(value) {
4898
+ return typeof value === "bigint" && (value < INT64_MIN || value > INT64_MAX);
4899
+ }
4880
4900
  function validateNumericValue(value) {
4881
4901
  if (typeof value === "number" && Number.isNaN(value)) {
4882
4902
  return {
@@ -4894,6 +4914,14 @@ function validateNumericValue(value) {
4894
4914
  }
4895
4915
  };
4896
4916
  }
4917
+ if (isBigintOutOfInt64Range(value)) {
4918
+ return {
4919
+ failure: {
4920
+ type: EncryptionErrorTypes.EncryptionError,
4921
+ message: "[encryption]: Cannot encrypt bigint value out of int64 range"
4922
+ }
4923
+ };
4924
+ }
4897
4925
  return void 0;
4898
4926
  }
4899
4927
  function assertValidNumericValue(value) {
@@ -4903,9 +4931,14 @@ function assertValidNumericValue(value) {
4903
4931
  if (typeof value === "number" && !Number.isFinite(value)) {
4904
4932
  throw new Error("[encryption]: Cannot encrypt Infinity value");
4905
4933
  }
4934
+ if (isBigintOutOfInt64Range(value)) {
4935
+ throw new Error(
4936
+ "[encryption]: Cannot encrypt bigint value out of int64 range"
4937
+ );
4938
+ }
4906
4939
  }
4907
4940
  function assertValueIndexCompatibility(value, indexType, columnName) {
4908
- if (typeof value === "number" && indexType === "match") {
4941
+ if ((typeof value === "number" || typeof value === "bigint") && indexType === "match") {
4909
4942
  throw new Error(
4910
4943
  `[encryption]: Cannot use 'match' index with numeric value on column "${columnName}". The 'freeTextSearch' index only supports string values. Configure the column with 'orderAndRange()' or 'equality()' for numeric queries.`
4911
4944
  );
@@ -5338,6 +5371,7 @@ function prepareFieldsForEncryption(model, table) {
5338
5371
  );
5339
5372
  }
5340
5373
  } else if (columnPaths2.includes(fullKey)) {
5374
+ assertValidNumericValue(value);
5341
5375
  const id = index.toString();
5342
5376
  keyMap[id] = fullKey;
5343
5377
  operationFields[fullKey] = value;
@@ -5516,6 +5550,7 @@ function prepareBulkModelsForOperation(models, table) {
5516
5550
  );
5517
5551
  }
5518
5552
  } else if (columnPaths.includes(fullKey)) {
5553
+ assertValidNumericValue(value);
5519
5554
  const id = index.toString();
5520
5555
  keyMap[id] = { modelIndex, fieldKey: fullKey };
5521
5556
  modelOperationFields[fullKey] = value;
@@ -5827,13 +5862,16 @@ var BulkDecryptModelsOperationWithLockContext = class extends EncryptionOperatio
5827
5862
  // src/encryption/operations/bulk-encrypt.ts
5828
5863
  var import_protect_ffi5 = require("@cipherstash/protect-ffi");
5829
5864
  var createEncryptPayloads = (plaintexts, column, table, lockContext) => {
5830
- return plaintexts.filter(({ plaintext }) => plaintext !== null).map(({ id, plaintext }) => ({
5831
- id,
5832
- plaintext,
5833
- column: column.getName(),
5834
- table: table.tableName,
5835
- ...lockContext && { lockContext }
5836
- }));
5865
+ return plaintexts.filter(({ plaintext }) => plaintext !== null).map(({ id, plaintext }) => {
5866
+ assertValidNumericValue(plaintext);
5867
+ return {
5868
+ id,
5869
+ plaintext,
5870
+ column: column.getName(),
5871
+ table: table.tableName,
5872
+ ...lockContext && { lockContext }
5873
+ };
5874
+ });
5837
5875
  };
5838
5876
  var createNullResult2 = (plaintexts) => plaintexts.map(({ id }) => ({ id, data: null }));
5839
5877
  var mapEncryptedDataToResult = (plaintexts, encryptedData) => {