@cipherstash/stack 0.16.0 → 0.19.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.
- package/CHANGELOG.md +225 -0
- package/README.md +2 -2
- package/dist/{chunk-CY5B4LIF.js → chunk-36AA7IBJ.js} +303 -204
- package/dist/chunk-36AA7IBJ.js.map +1 -0
- package/dist/{chunk-MD6742R6.js → chunk-4AVL4VZD.js} +1 -1
- package/dist/chunk-4AVL4VZD.js.map +1 -0
- package/dist/{chunk-4RNBI3UH.js → chunk-BNO32ZMV.js} +1 -1
- package/dist/chunk-BNO32ZMV.js.map +1 -0
- package/dist/{chunk-6FD7OBGM.js → chunk-HQANMV7R.js} +3 -3
- package/dist/chunk-HQANMV7R.js.map +1 -0
- package/dist/chunk-IADZCZEA.js +23 -0
- package/dist/chunk-IADZCZEA.js.map +1 -0
- package/dist/chunk-IBSK6P33.js +209 -0
- package/dist/chunk-IBSK6P33.js.map +1 -0
- package/dist/chunk-JSG2AMDI.js +17 -0
- package/dist/chunk-JSG2AMDI.js.map +1 -0
- package/dist/chunk-MP3SSDNN.js +4439 -0
- package/dist/chunk-MP3SSDNN.js.map +1 -0
- package/dist/chunk-OFQ555AX.js +191 -0
- package/dist/chunk-OFQ555AX.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-U66S7VIF.js +435 -0
- package/dist/chunk-U66S7VIF.js.map +1 -0
- package/dist/{client-C_7TF8EL.d.cts → client-DSGHBN-g.d.cts} +209 -72
- package/dist/{client-BLbA6aFD.d.ts → client-DfCrlHXh.d.ts} +209 -72
- package/dist/client.cjs +4103 -43
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +5 -5
- package/dist/client.d.ts +5 -5
- package/dist/client.js +3 -1
- package/dist/drizzle/index.cjs +4139 -77
- package/dist/drizzle/index.cjs.map +1 -1
- package/dist/drizzle/index.d.cts +33 -33
- package/dist/drizzle/index.d.ts +33 -33
- package/dist/drizzle/index.js +39 -33
- package/dist/drizzle/index.js.map +1 -1
- package/dist/dynamodb/index.cjs +31 -14
- package/dist/dynamodb/index.cjs.map +1 -1
- package/dist/dynamodb/index.d.cts +12 -12
- package/dist/dynamodb/index.d.ts +12 -12
- package/dist/dynamodb/index.js +16 -12
- package/dist/dynamodb/index.js.map +1 -1
- package/dist/encryption/index.cjs +4611 -257
- package/dist/encryption/index.cjs.map +1 -1
- package/dist/encryption/index.d.cts +3 -3
- package/dist/encryption/index.d.ts +3 -3
- package/dist/encryption/index.js +35 -7
- package/dist/encryption/v3.cjs +7791 -0
- package/dist/encryption/v3.cjs.map +1 -0
- package/dist/encryption/v3.d.cts +100 -0
- package/dist/encryption/v3.d.ts +100 -0
- package/dist/encryption/v3.js +161 -0
- package/dist/encryption/v3.js.map +1 -0
- package/dist/eql/v3/index.cjs +612 -0
- package/dist/eql/v3/index.cjs.map +1 -0
- package/dist/eql/v3/index.d.cts +71 -0
- package/dist/eql/v3/index.d.ts +71 -0
- package/dist/eql/v3/index.js +89 -0
- package/dist/eql/v3/index.js.map +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/identity/index.cjs +55 -35
- package/dist/identity/index.cjs.map +1 -1
- package/dist/identity/index.d.cts +54 -30
- package/dist/identity/index.d.ts +54 -30
- package/dist/identity/index.js +9 -177
- package/dist/identity/index.js.map +1 -1
- package/dist/index.cjs +4625 -273
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -7
- package/dist/index.d.ts +18 -7
- package/dist/index.js +20 -5
- package/dist/index.js.map +1 -1
- package/dist/schema/index.cjs +4108 -44
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.js +3 -1
- package/dist/supabase/index.cjs +4500 -75
- package/dist/supabase/index.cjs.map +1 -1
- package/dist/supabase/index.d.cts +113 -34
- package/dist/supabase/index.d.ts +113 -34
- package/dist/supabase/index.js +350 -32
- package/dist/supabase/index.js.map +1 -1
- package/dist/table-CIH7jZ2h.d.ts +603 -0
- package/dist/table-DihEAlxG.d.cts +603 -0
- package/dist/{types-public-Dv-r6Ik0.d.ts → types-public-CpS5KjwX.d.cts} +209 -36
- package/dist/{types-public-Dv-r6Ik0.d.cts → types-public-CpS5KjwX.d.ts} +209 -36
- package/dist/types-public.cjs.map +1 -1
- package/dist/types-public.d.cts +2 -2
- package/dist/types-public.d.ts +2 -2
- package/dist/types-public.js +2 -1
- package/dist/wasm-inline.d.ts +1269 -0
- package/dist/wasm-inline.js +4594 -0
- package/dist/wasm-inline.js.map +1 -0
- package/package.json +63 -13
- package/dist/chunk-4RNBI3UH.js.map +0 -1
- package/dist/chunk-6FD7OBGM.js.map +0 -1
- package/dist/chunk-CY5B4LIF.js.map +0 -1
- package/dist/chunk-JDZ2QUUF.js +0 -381
- package/dist/chunk-JDZ2QUUF.js.map +0 -1
- package/dist/chunk-MD6742R6.js.map +0 -1
|
@@ -0,0 +1,1269 @@
|
|
|
1
|
+
import { AccessKeyStrategy, OidcFederationStrategy } from '@cipherstash/auth/wasm-inline';
|
|
2
|
+
export { AccessKeyStrategy, OidcFederationStrategy } from '@cipherstash/auth/wasm-inline';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { EncryptedPayload } from '@cipherstash/protect-ffi';
|
|
5
|
+
|
|
6
|
+
/** Structural type representing encrypted data stored in the database. Always
|
|
7
|
+
* carries a ciphertext. Covers BOTH wire formats: the EQL v2.3 payloads
|
|
8
|
+
* (`k: "ct"` / `k: "sv"`) and the EQL v3 payloads (flat `{v: 3, i, c, …}`
|
|
9
|
+
* scalars and `{v: 3, k: "sv", i, sv}` SteVec documents). Which format
|
|
10
|
+
* `encrypt` produces is selected by the client's
|
|
11
|
+
* {@link ClientConfig.eqlVersion}; `decrypt` accepts both regardless.
|
|
12
|
+
* v3 scalars carry no `k` discriminator, so narrow with `'k' in payload`
|
|
13
|
+
* before reading it. See also `EncryptedValue` for branded nominal typing,
|
|
14
|
+
* and {@link EncryptedQuery} for the search-term shape returned by
|
|
15
|
+
* `encryptQuery`. */
|
|
16
|
+
type Encrypted = EncryptedPayload;
|
|
17
|
+
/** Structural contract for a column builder the client can consume for STORAGE
|
|
18
|
+
* (`encrypt`). Satisfied by v2 `EncryptedColumn` / `EncryptedField` AND v3
|
|
19
|
+
* `EncryptedTextSearchColumn` — fields ARE encryptable, so this stays wide. */
|
|
20
|
+
interface BuildableColumn {
|
|
21
|
+
getName(): string;
|
|
22
|
+
build(): ColumnSchema;
|
|
23
|
+
}
|
|
24
|
+
/** Structural contract for a table builder the client can consume. Satisfied by
|
|
25
|
+
* v2 and v3 `EncryptedTable` alike. */
|
|
26
|
+
interface BuildableTable {
|
|
27
|
+
tableName: string;
|
|
28
|
+
build(): {
|
|
29
|
+
tableName: string;
|
|
30
|
+
columns: Record<string, ColumnSchema>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Optional map from a model field's JS property name to its encrypt-config
|
|
34
|
+
* column name (the DB name). Present when the two can differ — v3 tables key
|
|
35
|
+
* their config by DB name (`column.getName()`) while models are written with
|
|
36
|
+
* JS property keys, so the model path must match by property but address the
|
|
37
|
+
* FFI/config by DB name.
|
|
38
|
+
*
|
|
39
|
+
* Absent on v2 tables, whose `build()` already keys columns by the JS property
|
|
40
|
+
* name; the model path then matches and addresses by that same key.
|
|
41
|
+
*/
|
|
42
|
+
buildColumnKeyMap?(): Record<string, string>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Options for single-value encrypt operations.
|
|
46
|
+
* Use a column from your table schema (from {@link encryptedColumn}) or a nested
|
|
47
|
+
* field (from {@link encryptedField}) as the target for encryption.
|
|
48
|
+
*/
|
|
49
|
+
type EncryptOptions = {
|
|
50
|
+
/** The column or nested field to encrypt into. From {@link EncryptedColumn} or {@link EncryptedField}. */
|
|
51
|
+
column: BuildableColumn;
|
|
52
|
+
table: BuildableTable;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* SDK-facing data types — developer-friendly aliases accepted by `dataType()`.
|
|
57
|
+
*/
|
|
58
|
+
declare const castAsEnum: z.ZodDefault<z.ZodEnum<["bigint", "boolean", "date", "timestamp", "number", "string", "json", "text"]>>;
|
|
59
|
+
declare const tokenFilterSchema: z.ZodObject<{
|
|
60
|
+
kind: z.ZodLiteral<"downcase">;
|
|
61
|
+
}, "strip", z.ZodTypeAny, {
|
|
62
|
+
kind: "downcase";
|
|
63
|
+
}, {
|
|
64
|
+
kind: "downcase";
|
|
65
|
+
}>;
|
|
66
|
+
declare const oreIndexOptsSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
67
|
+
declare const uniqueIndexOptsSchema: z.ZodObject<{
|
|
68
|
+
token_filters: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
69
|
+
kind: z.ZodLiteral<"downcase">;
|
|
70
|
+
}, "strip", z.ZodTypeAny, {
|
|
71
|
+
kind: "downcase";
|
|
72
|
+
}, {
|
|
73
|
+
kind: "downcase";
|
|
74
|
+
}>, "many">>>;
|
|
75
|
+
}, "strip", z.ZodTypeAny, {
|
|
76
|
+
token_filters?: {
|
|
77
|
+
kind: "downcase";
|
|
78
|
+
}[] | undefined;
|
|
79
|
+
}, {
|
|
80
|
+
token_filters?: {
|
|
81
|
+
kind: "downcase";
|
|
82
|
+
}[] | undefined;
|
|
83
|
+
}>;
|
|
84
|
+
declare const matchIndexOptsSchema: z.ZodObject<{
|
|
85
|
+
tokenizer: z.ZodOptional<z.ZodDefault<z.ZodUnion<[z.ZodObject<{
|
|
86
|
+
kind: z.ZodLiteral<"standard">;
|
|
87
|
+
}, "strip", z.ZodTypeAny, {
|
|
88
|
+
kind: "standard";
|
|
89
|
+
}, {
|
|
90
|
+
kind: "standard";
|
|
91
|
+
}>, z.ZodObject<{
|
|
92
|
+
kind: z.ZodLiteral<"ngram">;
|
|
93
|
+
token_length: z.ZodNumber;
|
|
94
|
+
}, "strip", z.ZodTypeAny, {
|
|
95
|
+
kind: "ngram";
|
|
96
|
+
token_length: number;
|
|
97
|
+
}, {
|
|
98
|
+
kind: "ngram";
|
|
99
|
+
token_length: number;
|
|
100
|
+
}>]>>>;
|
|
101
|
+
token_filters: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
102
|
+
kind: z.ZodLiteral<"downcase">;
|
|
103
|
+
}, "strip", z.ZodTypeAny, {
|
|
104
|
+
kind: "downcase";
|
|
105
|
+
}, {
|
|
106
|
+
kind: "downcase";
|
|
107
|
+
}>, "many">>>;
|
|
108
|
+
k: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
109
|
+
m: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
110
|
+
include_original: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
111
|
+
}, "strip", z.ZodTypeAny, {
|
|
112
|
+
token_filters?: {
|
|
113
|
+
kind: "downcase";
|
|
114
|
+
}[] | undefined;
|
|
115
|
+
tokenizer?: {
|
|
116
|
+
kind: "standard";
|
|
117
|
+
} | {
|
|
118
|
+
kind: "ngram";
|
|
119
|
+
token_length: number;
|
|
120
|
+
} | undefined;
|
|
121
|
+
k?: number | undefined;
|
|
122
|
+
m?: number | undefined;
|
|
123
|
+
include_original?: boolean | undefined;
|
|
124
|
+
}, {
|
|
125
|
+
token_filters?: {
|
|
126
|
+
kind: "downcase";
|
|
127
|
+
}[] | undefined;
|
|
128
|
+
tokenizer?: {
|
|
129
|
+
kind: "standard";
|
|
130
|
+
} | {
|
|
131
|
+
kind: "ngram";
|
|
132
|
+
token_length: number;
|
|
133
|
+
} | undefined;
|
|
134
|
+
k?: number | undefined;
|
|
135
|
+
m?: number | undefined;
|
|
136
|
+
include_original?: boolean | undefined;
|
|
137
|
+
}>;
|
|
138
|
+
declare const steVecIndexOptsSchema: z.ZodObject<{
|
|
139
|
+
prefix: z.ZodString;
|
|
140
|
+
array_index_mode: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"all">, z.ZodLiteral<"none">, z.ZodObject<{
|
|
141
|
+
item: z.ZodOptional<z.ZodBoolean>;
|
|
142
|
+
wildcard: z.ZodOptional<z.ZodBoolean>;
|
|
143
|
+
position: z.ZodOptional<z.ZodBoolean>;
|
|
144
|
+
}, "strip", z.ZodTypeAny, {
|
|
145
|
+
item?: boolean | undefined;
|
|
146
|
+
wildcard?: boolean | undefined;
|
|
147
|
+
position?: boolean | undefined;
|
|
148
|
+
}, {
|
|
149
|
+
item?: boolean | undefined;
|
|
150
|
+
wildcard?: boolean | undefined;
|
|
151
|
+
position?: boolean | undefined;
|
|
152
|
+
}>]>>;
|
|
153
|
+
}, "strip", z.ZodTypeAny, {
|
|
154
|
+
prefix: string;
|
|
155
|
+
array_index_mode?: "all" | "none" | {
|
|
156
|
+
item?: boolean | undefined;
|
|
157
|
+
wildcard?: boolean | undefined;
|
|
158
|
+
position?: boolean | undefined;
|
|
159
|
+
} | undefined;
|
|
160
|
+
}, {
|
|
161
|
+
prefix: string;
|
|
162
|
+
array_index_mode?: "all" | "none" | {
|
|
163
|
+
item?: boolean | undefined;
|
|
164
|
+
wildcard?: boolean | undefined;
|
|
165
|
+
position?: boolean | undefined;
|
|
166
|
+
} | undefined;
|
|
167
|
+
}>;
|
|
168
|
+
declare const columnSchema: z.ZodDefault<z.ZodObject<{
|
|
169
|
+
cast_as: z.ZodDefault<z.ZodEnum<["bigint", "boolean", "date", "timestamp", "number", "string", "json", "text"]>>;
|
|
170
|
+
indexes: z.ZodDefault<z.ZodObject<{
|
|
171
|
+
ore: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
|
|
172
|
+
unique: z.ZodOptional<z.ZodObject<{
|
|
173
|
+
token_filters: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
174
|
+
kind: z.ZodLiteral<"downcase">;
|
|
175
|
+
}, "strip", z.ZodTypeAny, {
|
|
176
|
+
kind: "downcase";
|
|
177
|
+
}, {
|
|
178
|
+
kind: "downcase";
|
|
179
|
+
}>, "many">>>;
|
|
180
|
+
}, "strip", z.ZodTypeAny, {
|
|
181
|
+
token_filters?: {
|
|
182
|
+
kind: "downcase";
|
|
183
|
+
}[] | undefined;
|
|
184
|
+
}, {
|
|
185
|
+
token_filters?: {
|
|
186
|
+
kind: "downcase";
|
|
187
|
+
}[] | undefined;
|
|
188
|
+
}>>;
|
|
189
|
+
match: z.ZodOptional<z.ZodObject<{
|
|
190
|
+
tokenizer: z.ZodOptional<z.ZodDefault<z.ZodUnion<[z.ZodObject<{
|
|
191
|
+
kind: z.ZodLiteral<"standard">;
|
|
192
|
+
}, "strip", z.ZodTypeAny, {
|
|
193
|
+
kind: "standard";
|
|
194
|
+
}, {
|
|
195
|
+
kind: "standard";
|
|
196
|
+
}>, z.ZodObject<{
|
|
197
|
+
kind: z.ZodLiteral<"ngram">;
|
|
198
|
+
token_length: z.ZodNumber;
|
|
199
|
+
}, "strip", z.ZodTypeAny, {
|
|
200
|
+
kind: "ngram";
|
|
201
|
+
token_length: number;
|
|
202
|
+
}, {
|
|
203
|
+
kind: "ngram";
|
|
204
|
+
token_length: number;
|
|
205
|
+
}>]>>>;
|
|
206
|
+
token_filters: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
207
|
+
kind: z.ZodLiteral<"downcase">;
|
|
208
|
+
}, "strip", z.ZodTypeAny, {
|
|
209
|
+
kind: "downcase";
|
|
210
|
+
}, {
|
|
211
|
+
kind: "downcase";
|
|
212
|
+
}>, "many">>>;
|
|
213
|
+
k: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
214
|
+
m: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
215
|
+
include_original: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
216
|
+
}, "strip", z.ZodTypeAny, {
|
|
217
|
+
token_filters?: {
|
|
218
|
+
kind: "downcase";
|
|
219
|
+
}[] | undefined;
|
|
220
|
+
tokenizer?: {
|
|
221
|
+
kind: "standard";
|
|
222
|
+
} | {
|
|
223
|
+
kind: "ngram";
|
|
224
|
+
token_length: number;
|
|
225
|
+
} | undefined;
|
|
226
|
+
k?: number | undefined;
|
|
227
|
+
m?: number | undefined;
|
|
228
|
+
include_original?: boolean | undefined;
|
|
229
|
+
}, {
|
|
230
|
+
token_filters?: {
|
|
231
|
+
kind: "downcase";
|
|
232
|
+
}[] | undefined;
|
|
233
|
+
tokenizer?: {
|
|
234
|
+
kind: "standard";
|
|
235
|
+
} | {
|
|
236
|
+
kind: "ngram";
|
|
237
|
+
token_length: number;
|
|
238
|
+
} | undefined;
|
|
239
|
+
k?: number | undefined;
|
|
240
|
+
m?: number | undefined;
|
|
241
|
+
include_original?: boolean | undefined;
|
|
242
|
+
}>>;
|
|
243
|
+
ste_vec: z.ZodOptional<z.ZodObject<{
|
|
244
|
+
prefix: z.ZodString;
|
|
245
|
+
array_index_mode: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"all">, z.ZodLiteral<"none">, z.ZodObject<{
|
|
246
|
+
item: z.ZodOptional<z.ZodBoolean>;
|
|
247
|
+
wildcard: z.ZodOptional<z.ZodBoolean>;
|
|
248
|
+
position: z.ZodOptional<z.ZodBoolean>;
|
|
249
|
+
}, "strip", z.ZodTypeAny, {
|
|
250
|
+
item?: boolean | undefined;
|
|
251
|
+
wildcard?: boolean | undefined;
|
|
252
|
+
position?: boolean | undefined;
|
|
253
|
+
}, {
|
|
254
|
+
item?: boolean | undefined;
|
|
255
|
+
wildcard?: boolean | undefined;
|
|
256
|
+
position?: boolean | undefined;
|
|
257
|
+
}>]>>;
|
|
258
|
+
}, "strip", z.ZodTypeAny, {
|
|
259
|
+
prefix: string;
|
|
260
|
+
array_index_mode?: "all" | "none" | {
|
|
261
|
+
item?: boolean | undefined;
|
|
262
|
+
wildcard?: boolean | undefined;
|
|
263
|
+
position?: boolean | undefined;
|
|
264
|
+
} | undefined;
|
|
265
|
+
}, {
|
|
266
|
+
prefix: string;
|
|
267
|
+
array_index_mode?: "all" | "none" | {
|
|
268
|
+
item?: boolean | undefined;
|
|
269
|
+
wildcard?: boolean | undefined;
|
|
270
|
+
position?: boolean | undefined;
|
|
271
|
+
} | undefined;
|
|
272
|
+
}>>;
|
|
273
|
+
}, "strip", z.ZodTypeAny, {
|
|
274
|
+
ore?: {} | undefined;
|
|
275
|
+
unique?: {
|
|
276
|
+
token_filters?: {
|
|
277
|
+
kind: "downcase";
|
|
278
|
+
}[] | undefined;
|
|
279
|
+
} | undefined;
|
|
280
|
+
match?: {
|
|
281
|
+
token_filters?: {
|
|
282
|
+
kind: "downcase";
|
|
283
|
+
}[] | undefined;
|
|
284
|
+
tokenizer?: {
|
|
285
|
+
kind: "standard";
|
|
286
|
+
} | {
|
|
287
|
+
kind: "ngram";
|
|
288
|
+
token_length: number;
|
|
289
|
+
} | undefined;
|
|
290
|
+
k?: number | undefined;
|
|
291
|
+
m?: number | undefined;
|
|
292
|
+
include_original?: boolean | undefined;
|
|
293
|
+
} | undefined;
|
|
294
|
+
ste_vec?: {
|
|
295
|
+
prefix: string;
|
|
296
|
+
array_index_mode?: "all" | "none" | {
|
|
297
|
+
item?: boolean | undefined;
|
|
298
|
+
wildcard?: boolean | undefined;
|
|
299
|
+
position?: boolean | undefined;
|
|
300
|
+
} | undefined;
|
|
301
|
+
} | undefined;
|
|
302
|
+
}, {
|
|
303
|
+
ore?: {} | undefined;
|
|
304
|
+
unique?: {
|
|
305
|
+
token_filters?: {
|
|
306
|
+
kind: "downcase";
|
|
307
|
+
}[] | undefined;
|
|
308
|
+
} | undefined;
|
|
309
|
+
match?: {
|
|
310
|
+
token_filters?: {
|
|
311
|
+
kind: "downcase";
|
|
312
|
+
}[] | undefined;
|
|
313
|
+
tokenizer?: {
|
|
314
|
+
kind: "standard";
|
|
315
|
+
} | {
|
|
316
|
+
kind: "ngram";
|
|
317
|
+
token_length: number;
|
|
318
|
+
} | undefined;
|
|
319
|
+
k?: number | undefined;
|
|
320
|
+
m?: number | undefined;
|
|
321
|
+
include_original?: boolean | undefined;
|
|
322
|
+
} | undefined;
|
|
323
|
+
ste_vec?: {
|
|
324
|
+
prefix: string;
|
|
325
|
+
array_index_mode?: "all" | "none" | {
|
|
326
|
+
item?: boolean | undefined;
|
|
327
|
+
wildcard?: boolean | undefined;
|
|
328
|
+
position?: boolean | undefined;
|
|
329
|
+
} | undefined;
|
|
330
|
+
} | undefined;
|
|
331
|
+
}>>;
|
|
332
|
+
}, "strip", z.ZodTypeAny, {
|
|
333
|
+
cast_as: "string" | "number" | "bigint" | "boolean" | "date" | "timestamp" | "json" | "text";
|
|
334
|
+
indexes: {
|
|
335
|
+
ore?: {} | undefined;
|
|
336
|
+
unique?: {
|
|
337
|
+
token_filters?: {
|
|
338
|
+
kind: "downcase";
|
|
339
|
+
}[] | undefined;
|
|
340
|
+
} | undefined;
|
|
341
|
+
match?: {
|
|
342
|
+
token_filters?: {
|
|
343
|
+
kind: "downcase";
|
|
344
|
+
}[] | undefined;
|
|
345
|
+
tokenizer?: {
|
|
346
|
+
kind: "standard";
|
|
347
|
+
} | {
|
|
348
|
+
kind: "ngram";
|
|
349
|
+
token_length: number;
|
|
350
|
+
} | undefined;
|
|
351
|
+
k?: number | undefined;
|
|
352
|
+
m?: number | undefined;
|
|
353
|
+
include_original?: boolean | undefined;
|
|
354
|
+
} | undefined;
|
|
355
|
+
ste_vec?: {
|
|
356
|
+
prefix: string;
|
|
357
|
+
array_index_mode?: "all" | "none" | {
|
|
358
|
+
item?: boolean | undefined;
|
|
359
|
+
wildcard?: boolean | undefined;
|
|
360
|
+
position?: boolean | undefined;
|
|
361
|
+
} | undefined;
|
|
362
|
+
} | undefined;
|
|
363
|
+
};
|
|
364
|
+
}, {
|
|
365
|
+
cast_as?: "string" | "number" | "bigint" | "boolean" | "date" | "timestamp" | "json" | "text" | undefined;
|
|
366
|
+
indexes?: {
|
|
367
|
+
ore?: {} | undefined;
|
|
368
|
+
unique?: {
|
|
369
|
+
token_filters?: {
|
|
370
|
+
kind: "downcase";
|
|
371
|
+
}[] | undefined;
|
|
372
|
+
} | undefined;
|
|
373
|
+
match?: {
|
|
374
|
+
token_filters?: {
|
|
375
|
+
kind: "downcase";
|
|
376
|
+
}[] | undefined;
|
|
377
|
+
tokenizer?: {
|
|
378
|
+
kind: "standard";
|
|
379
|
+
} | {
|
|
380
|
+
kind: "ngram";
|
|
381
|
+
token_length: number;
|
|
382
|
+
} | undefined;
|
|
383
|
+
k?: number | undefined;
|
|
384
|
+
m?: number | undefined;
|
|
385
|
+
include_original?: boolean | undefined;
|
|
386
|
+
} | undefined;
|
|
387
|
+
ste_vec?: {
|
|
388
|
+
prefix: string;
|
|
389
|
+
array_index_mode?: "all" | "none" | {
|
|
390
|
+
item?: boolean | undefined;
|
|
391
|
+
wildcard?: boolean | undefined;
|
|
392
|
+
position?: boolean | undefined;
|
|
393
|
+
} | undefined;
|
|
394
|
+
} | undefined;
|
|
395
|
+
} | undefined;
|
|
396
|
+
}>>;
|
|
397
|
+
/** @internal */
|
|
398
|
+
declare const encryptConfigSchema: z.ZodObject<{
|
|
399
|
+
v: z.ZodNumber;
|
|
400
|
+
tables: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodDefault<z.ZodObject<{
|
|
401
|
+
cast_as: z.ZodDefault<z.ZodEnum<["bigint", "boolean", "date", "timestamp", "number", "string", "json", "text"]>>;
|
|
402
|
+
indexes: z.ZodDefault<z.ZodObject<{
|
|
403
|
+
ore: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
|
|
404
|
+
unique: z.ZodOptional<z.ZodObject<{
|
|
405
|
+
token_filters: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
406
|
+
kind: z.ZodLiteral<"downcase">;
|
|
407
|
+
}, "strip", z.ZodTypeAny, {
|
|
408
|
+
kind: "downcase";
|
|
409
|
+
}, {
|
|
410
|
+
kind: "downcase";
|
|
411
|
+
}>, "many">>>;
|
|
412
|
+
}, "strip", z.ZodTypeAny, {
|
|
413
|
+
token_filters?: {
|
|
414
|
+
kind: "downcase";
|
|
415
|
+
}[] | undefined;
|
|
416
|
+
}, {
|
|
417
|
+
token_filters?: {
|
|
418
|
+
kind: "downcase";
|
|
419
|
+
}[] | undefined;
|
|
420
|
+
}>>;
|
|
421
|
+
match: z.ZodOptional<z.ZodObject<{
|
|
422
|
+
tokenizer: z.ZodOptional<z.ZodDefault<z.ZodUnion<[z.ZodObject<{
|
|
423
|
+
kind: z.ZodLiteral<"standard">;
|
|
424
|
+
}, "strip", z.ZodTypeAny, {
|
|
425
|
+
kind: "standard";
|
|
426
|
+
}, {
|
|
427
|
+
kind: "standard";
|
|
428
|
+
}>, z.ZodObject<{
|
|
429
|
+
kind: z.ZodLiteral<"ngram">;
|
|
430
|
+
token_length: z.ZodNumber;
|
|
431
|
+
}, "strip", z.ZodTypeAny, {
|
|
432
|
+
kind: "ngram";
|
|
433
|
+
token_length: number;
|
|
434
|
+
}, {
|
|
435
|
+
kind: "ngram";
|
|
436
|
+
token_length: number;
|
|
437
|
+
}>]>>>;
|
|
438
|
+
token_filters: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
439
|
+
kind: z.ZodLiteral<"downcase">;
|
|
440
|
+
}, "strip", z.ZodTypeAny, {
|
|
441
|
+
kind: "downcase";
|
|
442
|
+
}, {
|
|
443
|
+
kind: "downcase";
|
|
444
|
+
}>, "many">>>;
|
|
445
|
+
k: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
446
|
+
m: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
447
|
+
include_original: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
448
|
+
}, "strip", z.ZodTypeAny, {
|
|
449
|
+
token_filters?: {
|
|
450
|
+
kind: "downcase";
|
|
451
|
+
}[] | undefined;
|
|
452
|
+
tokenizer?: {
|
|
453
|
+
kind: "standard";
|
|
454
|
+
} | {
|
|
455
|
+
kind: "ngram";
|
|
456
|
+
token_length: number;
|
|
457
|
+
} | undefined;
|
|
458
|
+
k?: number | undefined;
|
|
459
|
+
m?: number | undefined;
|
|
460
|
+
include_original?: boolean | undefined;
|
|
461
|
+
}, {
|
|
462
|
+
token_filters?: {
|
|
463
|
+
kind: "downcase";
|
|
464
|
+
}[] | undefined;
|
|
465
|
+
tokenizer?: {
|
|
466
|
+
kind: "standard";
|
|
467
|
+
} | {
|
|
468
|
+
kind: "ngram";
|
|
469
|
+
token_length: number;
|
|
470
|
+
} | undefined;
|
|
471
|
+
k?: number | undefined;
|
|
472
|
+
m?: number | undefined;
|
|
473
|
+
include_original?: boolean | undefined;
|
|
474
|
+
}>>;
|
|
475
|
+
ste_vec: z.ZodOptional<z.ZodObject<{
|
|
476
|
+
prefix: z.ZodString;
|
|
477
|
+
array_index_mode: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"all">, z.ZodLiteral<"none">, z.ZodObject<{
|
|
478
|
+
item: z.ZodOptional<z.ZodBoolean>;
|
|
479
|
+
wildcard: z.ZodOptional<z.ZodBoolean>;
|
|
480
|
+
position: z.ZodOptional<z.ZodBoolean>;
|
|
481
|
+
}, "strip", z.ZodTypeAny, {
|
|
482
|
+
item?: boolean | undefined;
|
|
483
|
+
wildcard?: boolean | undefined;
|
|
484
|
+
position?: boolean | undefined;
|
|
485
|
+
}, {
|
|
486
|
+
item?: boolean | undefined;
|
|
487
|
+
wildcard?: boolean | undefined;
|
|
488
|
+
position?: boolean | undefined;
|
|
489
|
+
}>]>>;
|
|
490
|
+
}, "strip", z.ZodTypeAny, {
|
|
491
|
+
prefix: string;
|
|
492
|
+
array_index_mode?: "all" | "none" | {
|
|
493
|
+
item?: boolean | undefined;
|
|
494
|
+
wildcard?: boolean | undefined;
|
|
495
|
+
position?: boolean | undefined;
|
|
496
|
+
} | undefined;
|
|
497
|
+
}, {
|
|
498
|
+
prefix: string;
|
|
499
|
+
array_index_mode?: "all" | "none" | {
|
|
500
|
+
item?: boolean | undefined;
|
|
501
|
+
wildcard?: boolean | undefined;
|
|
502
|
+
position?: boolean | undefined;
|
|
503
|
+
} | undefined;
|
|
504
|
+
}>>;
|
|
505
|
+
}, "strip", z.ZodTypeAny, {
|
|
506
|
+
ore?: {} | undefined;
|
|
507
|
+
unique?: {
|
|
508
|
+
token_filters?: {
|
|
509
|
+
kind: "downcase";
|
|
510
|
+
}[] | undefined;
|
|
511
|
+
} | undefined;
|
|
512
|
+
match?: {
|
|
513
|
+
token_filters?: {
|
|
514
|
+
kind: "downcase";
|
|
515
|
+
}[] | undefined;
|
|
516
|
+
tokenizer?: {
|
|
517
|
+
kind: "standard";
|
|
518
|
+
} | {
|
|
519
|
+
kind: "ngram";
|
|
520
|
+
token_length: number;
|
|
521
|
+
} | undefined;
|
|
522
|
+
k?: number | undefined;
|
|
523
|
+
m?: number | undefined;
|
|
524
|
+
include_original?: boolean | undefined;
|
|
525
|
+
} | undefined;
|
|
526
|
+
ste_vec?: {
|
|
527
|
+
prefix: string;
|
|
528
|
+
array_index_mode?: "all" | "none" | {
|
|
529
|
+
item?: boolean | undefined;
|
|
530
|
+
wildcard?: boolean | undefined;
|
|
531
|
+
position?: boolean | undefined;
|
|
532
|
+
} | undefined;
|
|
533
|
+
} | undefined;
|
|
534
|
+
}, {
|
|
535
|
+
ore?: {} | undefined;
|
|
536
|
+
unique?: {
|
|
537
|
+
token_filters?: {
|
|
538
|
+
kind: "downcase";
|
|
539
|
+
}[] | undefined;
|
|
540
|
+
} | undefined;
|
|
541
|
+
match?: {
|
|
542
|
+
token_filters?: {
|
|
543
|
+
kind: "downcase";
|
|
544
|
+
}[] | undefined;
|
|
545
|
+
tokenizer?: {
|
|
546
|
+
kind: "standard";
|
|
547
|
+
} | {
|
|
548
|
+
kind: "ngram";
|
|
549
|
+
token_length: number;
|
|
550
|
+
} | undefined;
|
|
551
|
+
k?: number | undefined;
|
|
552
|
+
m?: number | undefined;
|
|
553
|
+
include_original?: boolean | undefined;
|
|
554
|
+
} | undefined;
|
|
555
|
+
ste_vec?: {
|
|
556
|
+
prefix: string;
|
|
557
|
+
array_index_mode?: "all" | "none" | {
|
|
558
|
+
item?: boolean | undefined;
|
|
559
|
+
wildcard?: boolean | undefined;
|
|
560
|
+
position?: boolean | undefined;
|
|
561
|
+
} | undefined;
|
|
562
|
+
} | undefined;
|
|
563
|
+
}>>;
|
|
564
|
+
}, "strip", z.ZodTypeAny, {
|
|
565
|
+
cast_as: "string" | "number" | "bigint" | "boolean" | "date" | "timestamp" | "json" | "text";
|
|
566
|
+
indexes: {
|
|
567
|
+
ore?: {} | undefined;
|
|
568
|
+
unique?: {
|
|
569
|
+
token_filters?: {
|
|
570
|
+
kind: "downcase";
|
|
571
|
+
}[] | undefined;
|
|
572
|
+
} | undefined;
|
|
573
|
+
match?: {
|
|
574
|
+
token_filters?: {
|
|
575
|
+
kind: "downcase";
|
|
576
|
+
}[] | undefined;
|
|
577
|
+
tokenizer?: {
|
|
578
|
+
kind: "standard";
|
|
579
|
+
} | {
|
|
580
|
+
kind: "ngram";
|
|
581
|
+
token_length: number;
|
|
582
|
+
} | undefined;
|
|
583
|
+
k?: number | undefined;
|
|
584
|
+
m?: number | undefined;
|
|
585
|
+
include_original?: boolean | undefined;
|
|
586
|
+
} | undefined;
|
|
587
|
+
ste_vec?: {
|
|
588
|
+
prefix: string;
|
|
589
|
+
array_index_mode?: "all" | "none" | {
|
|
590
|
+
item?: boolean | undefined;
|
|
591
|
+
wildcard?: boolean | undefined;
|
|
592
|
+
position?: boolean | undefined;
|
|
593
|
+
} | undefined;
|
|
594
|
+
} | undefined;
|
|
595
|
+
};
|
|
596
|
+
}, {
|
|
597
|
+
cast_as?: "string" | "number" | "bigint" | "boolean" | "date" | "timestamp" | "json" | "text" | undefined;
|
|
598
|
+
indexes?: {
|
|
599
|
+
ore?: {} | undefined;
|
|
600
|
+
unique?: {
|
|
601
|
+
token_filters?: {
|
|
602
|
+
kind: "downcase";
|
|
603
|
+
}[] | undefined;
|
|
604
|
+
} | undefined;
|
|
605
|
+
match?: {
|
|
606
|
+
token_filters?: {
|
|
607
|
+
kind: "downcase";
|
|
608
|
+
}[] | undefined;
|
|
609
|
+
tokenizer?: {
|
|
610
|
+
kind: "standard";
|
|
611
|
+
} | {
|
|
612
|
+
kind: "ngram";
|
|
613
|
+
token_length: number;
|
|
614
|
+
} | undefined;
|
|
615
|
+
k?: number | undefined;
|
|
616
|
+
m?: number | undefined;
|
|
617
|
+
include_original?: boolean | undefined;
|
|
618
|
+
} | undefined;
|
|
619
|
+
ste_vec?: {
|
|
620
|
+
prefix: string;
|
|
621
|
+
array_index_mode?: "all" | "none" | {
|
|
622
|
+
item?: boolean | undefined;
|
|
623
|
+
wildcard?: boolean | undefined;
|
|
624
|
+
position?: boolean | undefined;
|
|
625
|
+
} | undefined;
|
|
626
|
+
} | undefined;
|
|
627
|
+
} | undefined;
|
|
628
|
+
}>>>>>>;
|
|
629
|
+
}, "strip", z.ZodTypeAny, {
|
|
630
|
+
v: number;
|
|
631
|
+
tables: Record<string, Record<string, {
|
|
632
|
+
cast_as: "string" | "number" | "bigint" | "boolean" | "date" | "timestamp" | "json" | "text";
|
|
633
|
+
indexes: {
|
|
634
|
+
ore?: {} | undefined;
|
|
635
|
+
unique?: {
|
|
636
|
+
token_filters?: {
|
|
637
|
+
kind: "downcase";
|
|
638
|
+
}[] | undefined;
|
|
639
|
+
} | undefined;
|
|
640
|
+
match?: {
|
|
641
|
+
token_filters?: {
|
|
642
|
+
kind: "downcase";
|
|
643
|
+
}[] | undefined;
|
|
644
|
+
tokenizer?: {
|
|
645
|
+
kind: "standard";
|
|
646
|
+
} | {
|
|
647
|
+
kind: "ngram";
|
|
648
|
+
token_length: number;
|
|
649
|
+
} | undefined;
|
|
650
|
+
k?: number | undefined;
|
|
651
|
+
m?: number | undefined;
|
|
652
|
+
include_original?: boolean | undefined;
|
|
653
|
+
} | undefined;
|
|
654
|
+
ste_vec?: {
|
|
655
|
+
prefix: string;
|
|
656
|
+
array_index_mode?: "all" | "none" | {
|
|
657
|
+
item?: boolean | undefined;
|
|
658
|
+
wildcard?: boolean | undefined;
|
|
659
|
+
position?: boolean | undefined;
|
|
660
|
+
} | undefined;
|
|
661
|
+
} | undefined;
|
|
662
|
+
};
|
|
663
|
+
}>>;
|
|
664
|
+
}, {
|
|
665
|
+
v: number;
|
|
666
|
+
tables?: Record<string, Record<string, {
|
|
667
|
+
cast_as?: "string" | "number" | "bigint" | "boolean" | "date" | "timestamp" | "json" | "text" | undefined;
|
|
668
|
+
indexes?: {
|
|
669
|
+
ore?: {} | undefined;
|
|
670
|
+
unique?: {
|
|
671
|
+
token_filters?: {
|
|
672
|
+
kind: "downcase";
|
|
673
|
+
}[] | undefined;
|
|
674
|
+
} | undefined;
|
|
675
|
+
match?: {
|
|
676
|
+
token_filters?: {
|
|
677
|
+
kind: "downcase";
|
|
678
|
+
}[] | undefined;
|
|
679
|
+
tokenizer?: {
|
|
680
|
+
kind: "standard";
|
|
681
|
+
} | {
|
|
682
|
+
kind: "ngram";
|
|
683
|
+
token_length: number;
|
|
684
|
+
} | undefined;
|
|
685
|
+
k?: number | undefined;
|
|
686
|
+
m?: number | undefined;
|
|
687
|
+
include_original?: boolean | undefined;
|
|
688
|
+
} | undefined;
|
|
689
|
+
ste_vec?: {
|
|
690
|
+
prefix: string;
|
|
691
|
+
array_index_mode?: "all" | "none" | {
|
|
692
|
+
item?: boolean | undefined;
|
|
693
|
+
wildcard?: boolean | undefined;
|
|
694
|
+
position?: boolean | undefined;
|
|
695
|
+
} | undefined;
|
|
696
|
+
} | undefined;
|
|
697
|
+
} | undefined;
|
|
698
|
+
} | undefined> | undefined> | undefined;
|
|
699
|
+
}>;
|
|
700
|
+
/**
|
|
701
|
+
* Type-safe alias for {@link castAsEnum} used to specify the *unencrypted* data type of a column or value.
|
|
702
|
+
* This is important because once encrypted, all data is stored as binary blobs.
|
|
703
|
+
*
|
|
704
|
+
* @see {@link castAsEnum} for possible values.
|
|
705
|
+
*/
|
|
706
|
+
type CastAs = z.infer<typeof castAsEnum>;
|
|
707
|
+
type TokenFilter = z.infer<typeof tokenFilterSchema>;
|
|
708
|
+
type MatchIndexOpts = z.infer<typeof matchIndexOptsSchema>;
|
|
709
|
+
type SteVecIndexOpts = z.infer<typeof steVecIndexOptsSchema>;
|
|
710
|
+
type UniqueIndexOpts = z.infer<typeof uniqueIndexOptsSchema>;
|
|
711
|
+
type OreIndexOpts = z.infer<typeof oreIndexOptsSchema>;
|
|
712
|
+
type ColumnSchema = z.infer<typeof columnSchema>;
|
|
713
|
+
/**
|
|
714
|
+
* Shape of table columns: either top-level {@link EncryptedColumn} or nested
|
|
715
|
+
* objects whose leaves are {@link EncryptedField}. Used with {@link encryptedTable}.
|
|
716
|
+
*/
|
|
717
|
+
type EncryptedTableColumn = {
|
|
718
|
+
[key: string]: EncryptedColumn | {
|
|
719
|
+
[key: string]: EncryptedField | {
|
|
720
|
+
[key: string]: EncryptedField | {
|
|
721
|
+
[key: string]: EncryptedField;
|
|
722
|
+
};
|
|
723
|
+
};
|
|
724
|
+
};
|
|
725
|
+
};
|
|
726
|
+
type EncryptConfig = z.infer<typeof encryptConfigSchema>;
|
|
727
|
+
/**
|
|
728
|
+
* Builder for a nested encrypted field (encrypted but not searchable).
|
|
729
|
+
* Create with {@link encryptedField}. Use inside nested objects in {@link encryptedTable};
|
|
730
|
+
* supports `.dataType()` for plaintext type. No index methods (equality, orderAndRange, etc.).
|
|
731
|
+
*/
|
|
732
|
+
declare class EncryptedField {
|
|
733
|
+
private valueName;
|
|
734
|
+
private castAsValue;
|
|
735
|
+
constructor(valueName: string);
|
|
736
|
+
/**
|
|
737
|
+
* Set or override the plaintext data type for this field.
|
|
738
|
+
*
|
|
739
|
+
* By default all values are treated as `'string'`. Use this method to specify
|
|
740
|
+
* a different type so the encryption layer knows how to encode the plaintext
|
|
741
|
+
* before encrypting.
|
|
742
|
+
*
|
|
743
|
+
* @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'text'`, `'bigint'`, or `'json'`.
|
|
744
|
+
* @returns This `EncryptedField` instance for method chaining.
|
|
745
|
+
*
|
|
746
|
+
* @example
|
|
747
|
+
* ```typescript
|
|
748
|
+
* import { encryptedField } from "@cipherstash/stack/schema"
|
|
749
|
+
*
|
|
750
|
+
* const age = encryptedField("age").dataType("number")
|
|
751
|
+
* ```
|
|
752
|
+
*/
|
|
753
|
+
dataType(castAs: CastAs): this;
|
|
754
|
+
build(): {
|
|
755
|
+
cast_as: "string" | "number" | "bigint" | "boolean" | "date" | "timestamp" | "json" | "text";
|
|
756
|
+
indexes: {};
|
|
757
|
+
};
|
|
758
|
+
getName(): string;
|
|
759
|
+
}
|
|
760
|
+
declare class EncryptedColumn {
|
|
761
|
+
private columnName;
|
|
762
|
+
private castAsValue;
|
|
763
|
+
private indexesValue;
|
|
764
|
+
constructor(columnName: string);
|
|
765
|
+
/**
|
|
766
|
+
* Set or override the plaintext data type for this column.
|
|
767
|
+
*
|
|
768
|
+
* By default all columns are treated as `'string'`. Use this method to specify
|
|
769
|
+
* a different type so the encryption layer knows how to encode the plaintext
|
|
770
|
+
* before encrypting.
|
|
771
|
+
*
|
|
772
|
+
* @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.
|
|
773
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
774
|
+
*
|
|
775
|
+
* @example
|
|
776
|
+
* ```typescript
|
|
777
|
+
* import { encryptedColumn } from "@cipherstash/stack/schema"
|
|
778
|
+
*
|
|
779
|
+
* const dateOfBirth = encryptedColumn("date_of_birth").dataType("date")
|
|
780
|
+
* ```
|
|
781
|
+
*/
|
|
782
|
+
dataType(castAs: CastAs): this;
|
|
783
|
+
/**
|
|
784
|
+
* Enable Order-Revealing Encryption (ORE) indexing on this column.
|
|
785
|
+
*
|
|
786
|
+
* ORE allows sorting, comparison, and range queries on encrypted data.
|
|
787
|
+
* Use with `encryptQuery` and `queryType: 'orderAndRange'`.
|
|
788
|
+
*
|
|
789
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
790
|
+
*
|
|
791
|
+
* @example
|
|
792
|
+
* ```typescript
|
|
793
|
+
* import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
|
|
794
|
+
*
|
|
795
|
+
* const users = encryptedTable("users", {
|
|
796
|
+
* email: encryptedColumn("email").orderAndRange(),
|
|
797
|
+
* })
|
|
798
|
+
* ```
|
|
799
|
+
*/
|
|
800
|
+
orderAndRange(): this;
|
|
801
|
+
/**
|
|
802
|
+
* Enable an exact-match (unique) index on this column.
|
|
803
|
+
*
|
|
804
|
+
* Allows equality queries on encrypted data. Use with `encryptQuery`
|
|
805
|
+
* and `queryType: 'equality'`.
|
|
806
|
+
*
|
|
807
|
+
* @param tokenFilters - Optional array of token filters (e.g. `[{ kind: 'downcase' }]`).
|
|
808
|
+
* When omitted, no token filters are applied.
|
|
809
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
810
|
+
*
|
|
811
|
+
* @example
|
|
812
|
+
* ```typescript
|
|
813
|
+
* import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
|
|
814
|
+
*
|
|
815
|
+
* const users = encryptedTable("users", {
|
|
816
|
+
* email: encryptedColumn("email").equality(),
|
|
817
|
+
* })
|
|
818
|
+
* ```
|
|
819
|
+
*/
|
|
820
|
+
equality(tokenFilters?: TokenFilter[]): this;
|
|
821
|
+
/**
|
|
822
|
+
* Enable a full-text / fuzzy search (match) index on this column.
|
|
823
|
+
*
|
|
824
|
+
* Uses n-gram tokenization by default for substring and fuzzy matching.
|
|
825
|
+
* Use with `encryptQuery` and `queryType: 'freeTextSearch'`.
|
|
826
|
+
*
|
|
827
|
+
* @param opts - Optional match index configuration. Defaults to 3-character ngram
|
|
828
|
+
* tokenization with a downcase filter, `k=6`, `m=2048`, and `include_original=true`.
|
|
829
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
830
|
+
*
|
|
831
|
+
* @example
|
|
832
|
+
* ```typescript
|
|
833
|
+
* import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
|
|
834
|
+
*
|
|
835
|
+
* const users = encryptedTable("users", {
|
|
836
|
+
* email: encryptedColumn("email").freeTextSearch(),
|
|
837
|
+
* })
|
|
838
|
+
*
|
|
839
|
+
* // With custom options
|
|
840
|
+
* const posts = encryptedTable("posts", {
|
|
841
|
+
* body: encryptedColumn("body").freeTextSearch({
|
|
842
|
+
* tokenizer: { kind: "ngram", token_length: 4 },
|
|
843
|
+
* k: 8,
|
|
844
|
+
* m: 4096,
|
|
845
|
+
* }),
|
|
846
|
+
* })
|
|
847
|
+
* ```
|
|
848
|
+
*/
|
|
849
|
+
freeTextSearch(opts?: MatchIndexOpts): this;
|
|
850
|
+
/**
|
|
851
|
+
* Configure this column for searchable encrypted JSON (STE-Vec).
|
|
852
|
+
*
|
|
853
|
+
* Enables encrypted JSONPath selector queries (e.g. `'$.user.email'`) and
|
|
854
|
+
* containment queries (e.g. `{ role: 'admin' }`). Automatically sets the
|
|
855
|
+
* data type to `'json'`.
|
|
856
|
+
*
|
|
857
|
+
* When used with `encryptQuery`, the query operation is auto-inferred from
|
|
858
|
+
* the plaintext type: strings become selector queries, objects/arrays become
|
|
859
|
+
* containment queries.
|
|
860
|
+
*
|
|
861
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
862
|
+
*
|
|
863
|
+
* @example
|
|
864
|
+
* ```typescript
|
|
865
|
+
* import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
|
|
866
|
+
*
|
|
867
|
+
* const documents = encryptedTable("documents", {
|
|
868
|
+
* metadata: encryptedColumn("metadata").searchableJson(),
|
|
869
|
+
* })
|
|
870
|
+
* ```
|
|
871
|
+
*/
|
|
872
|
+
searchableJson(): this;
|
|
873
|
+
build(): {
|
|
874
|
+
cast_as: "string" | "number" | "bigint" | "boolean" | "date" | "timestamp" | "json" | "text";
|
|
875
|
+
indexes: {
|
|
876
|
+
ore?: OreIndexOpts;
|
|
877
|
+
unique?: UniqueIndexOpts;
|
|
878
|
+
match?: Required<MatchIndexOpts>;
|
|
879
|
+
ste_vec?: SteVecIndexOpts;
|
|
880
|
+
};
|
|
881
|
+
};
|
|
882
|
+
getName(): string;
|
|
883
|
+
}
|
|
884
|
+
interface TableDefinition {
|
|
885
|
+
tableName: string;
|
|
886
|
+
columns: Record<string, ColumnSchema>;
|
|
887
|
+
}
|
|
888
|
+
declare class EncryptedTable<T extends EncryptedTableColumn> {
|
|
889
|
+
readonly tableName: string;
|
|
890
|
+
readonly columnBuilders: T;
|
|
891
|
+
/** @internal Type-level brand so TypeScript can infer `T` from `EncryptedTable<T>`. */
|
|
892
|
+
readonly _columnType: T;
|
|
893
|
+
constructor(tableName: string, columnBuilders: T);
|
|
894
|
+
/**
|
|
895
|
+
* Compile this table schema into a `TableDefinition` used internally by the encryption client.
|
|
896
|
+
*
|
|
897
|
+
* Iterates over all column builders, calls `.build()` on each, and assembles
|
|
898
|
+
* the final `{ tableName, columns }` structure. For `searchableJson()` columns,
|
|
899
|
+
* the STE-Vec prefix is automatically set to `"<tableName>/<columnName>"`.
|
|
900
|
+
*
|
|
901
|
+
* @returns A `TableDefinition` containing the table name and built column configs.
|
|
902
|
+
*
|
|
903
|
+
* @example
|
|
904
|
+
* ```typescript
|
|
905
|
+
* const users = encryptedTable("users", {
|
|
906
|
+
* email: encryptedColumn("email").equality(),
|
|
907
|
+
* })
|
|
908
|
+
*
|
|
909
|
+
* const definition = users.build()
|
|
910
|
+
* // { tableName: "users", columns: { email: { cast_as: "string", indexes: { unique: ... } } } }
|
|
911
|
+
* ```
|
|
912
|
+
*/
|
|
913
|
+
build(): TableDefinition;
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Infer the plaintext (decrypted) type from a EncryptedTable schema.
|
|
917
|
+
*
|
|
918
|
+
* @example
|
|
919
|
+
* ```typescript
|
|
920
|
+
* const users = encryptedTable("users", {
|
|
921
|
+
* email: encryptedColumn("email").equality(),
|
|
922
|
+
* name: encryptedColumn("name"),
|
|
923
|
+
* })
|
|
924
|
+
*
|
|
925
|
+
* type UserPlaintext = InferPlaintext<typeof users>
|
|
926
|
+
* // => { email: string; name: string }
|
|
927
|
+
* ```
|
|
928
|
+
*/
|
|
929
|
+
type InferPlaintext<T extends EncryptedTable<any>> = T extends EncryptedTable<infer C> ? {
|
|
930
|
+
[K in keyof C as C[K] extends EncryptedColumn | EncryptedField ? K : never]: string;
|
|
931
|
+
} : never;
|
|
932
|
+
/**
|
|
933
|
+
* Infer the encrypted type from a EncryptedTable schema.
|
|
934
|
+
*
|
|
935
|
+
* @example
|
|
936
|
+
* ```typescript
|
|
937
|
+
* const users = encryptedTable("users", {
|
|
938
|
+
* email: encryptedColumn("email").equality(),
|
|
939
|
+
* })
|
|
940
|
+
*
|
|
941
|
+
* type UserEncrypted = InferEncrypted<typeof users>
|
|
942
|
+
* // => { email: Encrypted }
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
945
|
+
type InferEncrypted<T extends EncryptedTable<any>> = T extends EncryptedTable<infer C> ? {
|
|
946
|
+
[K in keyof C as C[K] extends EncryptedColumn | EncryptedField ? K : never]: Encrypted;
|
|
947
|
+
} : never;
|
|
948
|
+
/**
|
|
949
|
+
* Define an encrypted table schema.
|
|
950
|
+
*
|
|
951
|
+
* Creates a `EncryptedTable` that maps a database table name to a set of encrypted
|
|
952
|
+
* column definitions. Pass the resulting object to `Encryption({ schemas: [...] })`
|
|
953
|
+
* when initializing the client.
|
|
954
|
+
*
|
|
955
|
+
* The returned object is also a proxy that exposes each column builder directly,
|
|
956
|
+
* so you can reference columns as `users.email` when calling `encrypt`, `decrypt`,
|
|
957
|
+
* and `encryptQuery`.
|
|
958
|
+
*
|
|
959
|
+
* @param tableName - The name of the database table this schema represents.
|
|
960
|
+
* @param columns - An object whose keys are logical column names and values are
|
|
961
|
+
* {@link EncryptedColumn} from {@link encryptedColumn}, or nested objects whose
|
|
962
|
+
* leaves are {@link EncryptedField} from {@link encryptedField}.
|
|
963
|
+
* @returns A `EncryptedTable<T> & T` that can be used as both a schema definition
|
|
964
|
+
* and a column accessor.
|
|
965
|
+
*
|
|
966
|
+
* @example
|
|
967
|
+
* ```typescript
|
|
968
|
+
* import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
|
|
969
|
+
*
|
|
970
|
+
* const users = encryptedTable("users", {
|
|
971
|
+
* email: encryptedColumn("email").equality().freeTextSearch(),
|
|
972
|
+
* address: encryptedColumn("address"),
|
|
973
|
+
* })
|
|
974
|
+
*
|
|
975
|
+
* // Use as schema
|
|
976
|
+
* const client = await Encryption({ schemas: [users] })
|
|
977
|
+
*
|
|
978
|
+
* // Use as column accessor
|
|
979
|
+
* await client.encrypt("hello@example.com", { column: users.email, table: users })
|
|
980
|
+
* ```
|
|
981
|
+
*/
|
|
982
|
+
declare function encryptedTable<T extends EncryptedTableColumn>(tableName: string, columns: T): EncryptedTable<T> & T;
|
|
983
|
+
/**
|
|
984
|
+
* Define an encrypted column within a table schema.
|
|
985
|
+
*
|
|
986
|
+
* Creates a `EncryptedColumn` builder for the given column name. Chain index
|
|
987
|
+
* methods (`.equality()`, `.freeTextSearch()`, `.orderAndRange()`,
|
|
988
|
+
* `.searchableJson()`) and/or `.dataType()` to configure searchable encryption
|
|
989
|
+
* and the plaintext data type.
|
|
990
|
+
*
|
|
991
|
+
* @param columnName - The name of the database column to encrypt.
|
|
992
|
+
* @returns A new `EncryptedColumn` builder.
|
|
993
|
+
*
|
|
994
|
+
* @example
|
|
995
|
+
* ```typescript
|
|
996
|
+
* import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
|
|
997
|
+
*
|
|
998
|
+
* const users = encryptedTable("users", {
|
|
999
|
+
* email: encryptedColumn("email").equality().freeTextSearch().orderAndRange(),
|
|
1000
|
+
* })
|
|
1001
|
+
* ```
|
|
1002
|
+
*/
|
|
1003
|
+
declare function encryptedColumn(columnName: string): EncryptedColumn;
|
|
1004
|
+
/**
|
|
1005
|
+
* Define an encrypted field for use in nested or structured schemas.
|
|
1006
|
+
*
|
|
1007
|
+
* `encryptedField` is similar to {@link encryptedColumn} but creates an {@link EncryptedField}
|
|
1008
|
+
* for nested fields that are encrypted but not searchable (no indexes). Use `.dataType()`
|
|
1009
|
+
* to specify the plaintext type.
|
|
1010
|
+
*
|
|
1011
|
+
* @param valueName - The name of the value field.
|
|
1012
|
+
* @returns A new `EncryptedField` builder.
|
|
1013
|
+
*
|
|
1014
|
+
* @example
|
|
1015
|
+
* ```typescript
|
|
1016
|
+
* import { encryptedTable, encryptedField } from "@cipherstash/stack/schema"
|
|
1017
|
+
*
|
|
1018
|
+
* const orders = encryptedTable("orders", {
|
|
1019
|
+
* details: {
|
|
1020
|
+
* amount: encryptedField("amount").dataType("number"),
|
|
1021
|
+
* currency: encryptedField("currency"),
|
|
1022
|
+
* },
|
|
1023
|
+
* })
|
|
1024
|
+
* ```
|
|
1025
|
+
*/
|
|
1026
|
+
declare function encryptedField(valueName: string): EncryptedField;
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* WASM-inline entry for `@cipherstash/stack` — for Deno, Bun, Cloudflare
|
|
1030
|
+
* Workers, Supabase Edge Functions, and any runtime where the native
|
|
1031
|
+
* `@cipherstash/protect-ffi` NAPI bindings are unavailable.
|
|
1032
|
+
*
|
|
1033
|
+
* Mirrors the protect-ffi / auth `/wasm-inline` pattern: the WASM module
|
|
1034
|
+
* is inlined into the JS bundle as a base64 blob (no separate `.wasm`
|
|
1035
|
+
* fetch / file read), so this entry works in environments that disallow
|
|
1036
|
+
* `fs` or relative asset loading.
|
|
1037
|
+
*
|
|
1038
|
+
* Use this import path: `@cipherstash/stack/wasm-inline`
|
|
1039
|
+
*
|
|
1040
|
+
* @example
|
|
1041
|
+
* ```ts
|
|
1042
|
+
* import {
|
|
1043
|
+
* Encryption, encryptedTable, encryptedColumn,
|
|
1044
|
+
* } from "@cipherstash/stack/wasm-inline"
|
|
1045
|
+
*
|
|
1046
|
+
* const users = encryptedTable("users", { email: encryptedColumn("email") })
|
|
1047
|
+
*
|
|
1048
|
+
* const client = await Encryption({
|
|
1049
|
+
* schemas: [users],
|
|
1050
|
+
* config: {
|
|
1051
|
+
* workspaceCrn: Deno.env.get("CS_WORKSPACE_CRN")!,
|
|
1052
|
+
* accessKey: Deno.env.get("CS_CLIENT_ACCESS_KEY")!,
|
|
1053
|
+
* clientId: Deno.env.get("CS_CLIENT_ID")!,
|
|
1054
|
+
* clientKey: Deno.env.get("CS_CLIENT_KEY")!,
|
|
1055
|
+
* },
|
|
1056
|
+
* })
|
|
1057
|
+
*
|
|
1058
|
+
* const enc = await client.encrypt("alice@example.com", {
|
|
1059
|
+
* column: users.email,
|
|
1060
|
+
* table: users,
|
|
1061
|
+
* })
|
|
1062
|
+
* const dec = await client.decrypt(enc)
|
|
1063
|
+
* ```
|
|
1064
|
+
*
|
|
1065
|
+
* For per-user, identity-bound encryption on the edge, build an
|
|
1066
|
+
* `OidcFederationStrategy` (federates an end user's OIDC JWT — Clerk,
|
|
1067
|
+
* Supabase, … — into a CTS service token) and pass it via
|
|
1068
|
+
* `config.authStrategy`:
|
|
1069
|
+
*
|
|
1070
|
+
* ```ts
|
|
1071
|
+
* import { OidcFederationStrategy } from "@cipherstash/stack/wasm-inline"
|
|
1072
|
+
* import { cookieStore } from "@cipherstash/auth/cookies"
|
|
1073
|
+
*
|
|
1074
|
+
* const authStrategy = OidcFederationStrategy.create(
|
|
1075
|
+
* "crn:ap-southeast-2.aws:my-workspace-id", () => getClerkSessionToken(req),
|
|
1076
|
+
* { store: cookieStore({ request: req, responseHeaders }) },
|
|
1077
|
+
* )
|
|
1078
|
+
* const client = await Encryption({ schemas, config: { authStrategy, clientId, clientKey } })
|
|
1079
|
+
* ```
|
|
1080
|
+
*
|
|
1081
|
+
* For service-to-service / CI use with a custom token store, build an
|
|
1082
|
+
* `AccessKeyStrategy.create(workspaceCrn, accessKey, { store })` the same
|
|
1083
|
+
* way (it derives the region from the CRN). Both strategies are
|
|
1084
|
+
* re-exported from this entry.
|
|
1085
|
+
*/
|
|
1086
|
+
|
|
1087
|
+
/** Re-exported convenience predicate — same as the raw protect-ffi one. */
|
|
1088
|
+
declare function isEncrypted(value: unknown): boolean;
|
|
1089
|
+
/**
|
|
1090
|
+
* The plaintext shape accepted by `encrypt` and returned by `decrypt`.
|
|
1091
|
+
* Mirrors protect-ffi's `JsPlaintext` (recursive: arrays of any of
|
|
1092
|
+
* these are valid). Re-defined here so the wasm-inline `.d.ts` doesn't
|
|
1093
|
+
* pull in the Node-only protect-ffi types.
|
|
1094
|
+
*/
|
|
1095
|
+
type WasmPlaintext = string | number | boolean | null | Record<string, unknown> | WasmPlaintext[];
|
|
1096
|
+
/**
|
|
1097
|
+
* Config for {@link Encryption} on the WASM entry point.
|
|
1098
|
+
*
|
|
1099
|
+
* The workspace CRN is the single source of truth for workspace
|
|
1100
|
+
* identity and deployment region — matching the Node entry and
|
|
1101
|
+
* protect-ffi 0.25+, which read `CS_WORKSPACE_CRN` and no longer
|
|
1102
|
+
* consult a separate `CS_REGION`. The CRN is passed straight to the
|
|
1103
|
+
* underlying `AccessKeyStrategy`, which derives the region from it, so
|
|
1104
|
+
* there is no `region` field to keep in sync.
|
|
1105
|
+
*
|
|
1106
|
+
* For service-to-service / CI use, pass `accessKey` plus the workspace
|
|
1107
|
+
* `clientId` / `clientKey` and we construct an `AccessKeyStrategy` for
|
|
1108
|
+
* you. To plug in a custom token store (cookies on Supabase Edge, KV on
|
|
1109
|
+
* Cloudflare Workers, …) or to bind encryption to an end user, build the
|
|
1110
|
+
* strategy yourself — `AccessKeyStrategy` or `OidcFederationStrategy` —
|
|
1111
|
+
* and hand it to `config.authStrategy` instead. A pre-built strategy
|
|
1112
|
+
* already carries the CRN, so `workspaceCrn` is optional on that path.
|
|
1113
|
+
*
|
|
1114
|
+
* Mirrors the Node `ClientConfig`: `authStrategy` is the documented field,
|
|
1115
|
+
* `strategy` is retained as a deprecated alias (see below).
|
|
1116
|
+
*/
|
|
1117
|
+
type WasmClientConfig = {
|
|
1118
|
+
/** Workspace client identifier — required by the WASM client. */
|
|
1119
|
+
clientId: string;
|
|
1120
|
+
/** Workspace client key — required by the WASM client. */
|
|
1121
|
+
clientKey: string;
|
|
1122
|
+
} & ({
|
|
1123
|
+
/**
|
|
1124
|
+
* CipherStash workspace CRN, e.g.
|
|
1125
|
+
* `"crn:ap-southeast-2.aws:my-workspace-id"`. Required on the
|
|
1126
|
+
* access-key path — it is the single source of truth for workspace
|
|
1127
|
+
* identity and `AccessKeyStrategy` derives the region from it.
|
|
1128
|
+
*/
|
|
1129
|
+
workspaceCrn: string;
|
|
1130
|
+
accessKey: string;
|
|
1131
|
+
authStrategy?: never;
|
|
1132
|
+
strategy?: never;
|
|
1133
|
+
} | {
|
|
1134
|
+
/**
|
|
1135
|
+
* Optional on the strategy path. A pre-built `authStrategy` (e.g.
|
|
1136
|
+
* `OidcFederationStrategy.create(workspaceCrn, …)`) already
|
|
1137
|
+
* encapsulates the workspace CRN and region, so the SDK never reads
|
|
1138
|
+
* this — supply it if convenient, omit it otherwise.
|
|
1139
|
+
*/
|
|
1140
|
+
workspaceCrn?: string;
|
|
1141
|
+
accessKey?: never;
|
|
1142
|
+
/** A pre-built auth strategy for per-user or M2M authentication. */
|
|
1143
|
+
authStrategy: WasmAuthStrategy;
|
|
1144
|
+
/**
|
|
1145
|
+
* @deprecated Renamed to `authStrategy`. Still honoured for backwards
|
|
1146
|
+
* compatibility (it logs a deprecation warning at runtime) but will be
|
|
1147
|
+
* removed in a future release.
|
|
1148
|
+
*/
|
|
1149
|
+
strategy?: WasmAuthStrategy;
|
|
1150
|
+
} | {
|
|
1151
|
+
workspaceCrn?: string;
|
|
1152
|
+
accessKey?: never;
|
|
1153
|
+
authStrategy?: never;
|
|
1154
|
+
/**
|
|
1155
|
+
* @deprecated Renamed to `authStrategy`. Still honoured for backwards
|
|
1156
|
+
* compatibility (it logs a deprecation warning at runtime) but will be
|
|
1157
|
+
* removed in a future release.
|
|
1158
|
+
*/
|
|
1159
|
+
strategy: WasmAuthStrategy;
|
|
1160
|
+
});
|
|
1161
|
+
/**
|
|
1162
|
+
* Any auth strategy accepted on the WASM path. Both expose
|
|
1163
|
+
* `getToken(): Promise<Result<TokenResult, AuthFailure>>` — as of
|
|
1164
|
+
* `@cipherstash/auth` 0.41 the token is wrapped in a `@byteslice/result`
|
|
1165
|
+
* envelope. `@cipherstash/protect-ffi` 0.28+ unwraps that envelope (reading
|
|
1166
|
+
* `.data.token`, surfacing `.failure`) inside its WASM `newClient`; 0.27 read
|
|
1167
|
+
* `.token` off the envelope and saw `undefined`, so keep the ffi floor at 0.28.
|
|
1168
|
+
*
|
|
1169
|
+
* - {@link AccessKeyStrategy} — static M2M / CI access key.
|
|
1170
|
+
* - {@link OidcFederationStrategy} — federates an end-user OIDC JWT into a
|
|
1171
|
+
* CTS service token, for per-user identity-bound encryption.
|
|
1172
|
+
*/
|
|
1173
|
+
type WasmAuthStrategy = AccessKeyStrategy | OidcFederationStrategy;
|
|
1174
|
+
type WasmEncryptionConfig = {
|
|
1175
|
+
schemas: [
|
|
1176
|
+
EncryptedTable<EncryptedTableColumn>,
|
|
1177
|
+
...EncryptedTable<EncryptedTableColumn>[]
|
|
1178
|
+
];
|
|
1179
|
+
config: WasmClientConfig;
|
|
1180
|
+
};
|
|
1181
|
+
/**
|
|
1182
|
+
* WASM encryption client. Returned by {@link Encryption}.
|
|
1183
|
+
*
|
|
1184
|
+
* Wraps an opaque `wasmNewClient` handle and exposes a minimal
|
|
1185
|
+
* `encrypt` / `decrypt` surface. Larger surface (bulk, query, model
|
|
1186
|
+
* helpers) lives on the Node entry — port lazily as Deno / edge
|
|
1187
|
+
* consumers demand it.
|
|
1188
|
+
*
|
|
1189
|
+
* Construct via {@link Encryption} — the constructor is private to
|
|
1190
|
+
* prevent callers from wrapping arbitrary objects in this type.
|
|
1191
|
+
*/
|
|
1192
|
+
declare class WasmEncryptionClient {
|
|
1193
|
+
/** @internal */
|
|
1194
|
+
private readonly client;
|
|
1195
|
+
/**
|
|
1196
|
+
* @internal Gated by the module-scoped {@link INTERNAL_CONSTRUCT}
|
|
1197
|
+
* symbol: external callers can't obtain it, so {@link Encryption} is
|
|
1198
|
+
* effectively the only constructor. (A `private` constructor would
|
|
1199
|
+
* block {@link Encryption} too, since it lives outside the class.)
|
|
1200
|
+
*/
|
|
1201
|
+
constructor(token: symbol, client: unknown);
|
|
1202
|
+
encrypt(plaintext: WasmPlaintext, opts: EncryptOptions): Promise<Encrypted>;
|
|
1203
|
+
decrypt(encrypted: Encrypted): Promise<WasmPlaintext>;
|
|
1204
|
+
isEncrypted(value: unknown): boolean;
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Initialize a WASM-backed encryption client.
|
|
1208
|
+
*
|
|
1209
|
+
* Mirrors the Node entry's {@link import('./encryption').Encryption}
|
|
1210
|
+
* factory, but constructs the protect-ffi client via the WASM strategy
|
|
1211
|
+
* API. Use from Deno / Edge / Workers / Bun.
|
|
1212
|
+
*/
|
|
1213
|
+
declare function Encryption(config: WasmEncryptionConfig): Promise<WasmEncryptionClient>;
|
|
1214
|
+
/**
|
|
1215
|
+
* Convert SDK-facing `cast_as` values (`'string'`, `'number'`, …) to the
|
|
1216
|
+
* EQL-native variants (`'text'`, `'double'`, …) that the WASM
|
|
1217
|
+
* `newClient` accepts.
|
|
1218
|
+
*
|
|
1219
|
+
* The Node entry of protect-ffi performs this normalization internally
|
|
1220
|
+
* via `normalizeEncryptConfig.js`; the WASM bindings do not. Without
|
|
1221
|
+
* this, the WASM client rejects an `encryptedColumn('email')` (which
|
|
1222
|
+
* defaults to `cast_as: 'string'`) with
|
|
1223
|
+
* `unknown variant `string`, expected one of `big_int`, …`.
|
|
1224
|
+
*
|
|
1225
|
+
* `toEqlCastAs` is exhaustive over the current `CastAs` union; if a new
|
|
1226
|
+
* SDK-facing variant is added without updating that switch, this
|
|
1227
|
+
* function throws synchronously at startup with a clear message rather
|
|
1228
|
+
* than handing `undefined` to the WASM serde (which surfaces as an
|
|
1229
|
+
* opaque `unknown variant 'null'` error).
|
|
1230
|
+
*
|
|
1231
|
+
* @internal exported for unit-test coverage of the drift-guard branch.
|
|
1232
|
+
*/
|
|
1233
|
+
declare function normalizeCastAs(config: EncryptConfig): unknown;
|
|
1234
|
+
/**
|
|
1235
|
+
* Resolve a column's name structurally. Accepts any column builder exposing
|
|
1236
|
+
* `getName()` — v2 `EncryptedColumn` / `EncryptedField` AND v3 column builders
|
|
1237
|
+
* (e.g. `EncryptedTextSearchColumn`) alike — matching the structural
|
|
1238
|
+
* `BuildableColumn` contract that `EncryptOptions.column` was widened to.
|
|
1239
|
+
*
|
|
1240
|
+
* An `instanceof EncryptedColumn || EncryptedField` gate would type-check after
|
|
1241
|
+
* the widening but throw at runtime for a v3 column, breaking the type promise;
|
|
1242
|
+
* resolving the name structurally keeps the wasm-inline encrypt entry honest.
|
|
1243
|
+
* The `typeof` check still fails loudly for plain JS callers passing a value
|
|
1244
|
+
* that is not a column builder.
|
|
1245
|
+
*
|
|
1246
|
+
* @internal exported for unit-test coverage.
|
|
1247
|
+
*/
|
|
1248
|
+
declare function getColumnName(col: EncryptOptions['column']): string;
|
|
1249
|
+
/**
|
|
1250
|
+
* Reset the once-per-process deprecation-warning latch. Test-only hook so
|
|
1251
|
+
* suites can assert the warning fires deterministically, independent of test
|
|
1252
|
+
* ordering.
|
|
1253
|
+
* @internal
|
|
1254
|
+
*/
|
|
1255
|
+
declare function __resetStrategyDeprecationWarningForTests(): void;
|
|
1256
|
+
/**
|
|
1257
|
+
* Resolve the auth strategy for the WASM client from its config: an explicit
|
|
1258
|
+
* `config.authStrategy` (or the deprecated `config.strategy` alias), or — for
|
|
1259
|
+
* the access-key path — an `AccessKeyStrategy` built from the workspace CRN
|
|
1260
|
+
* (region derived from it inside `@cipherstash/auth`). An auth strategy and
|
|
1261
|
+
* `accessKey` are mutually exclusive.
|
|
1262
|
+
*
|
|
1263
|
+
* @internal exported for offline unit coverage of the strategy wiring; the
|
|
1264
|
+
* gated Deno e2e (`e2e/wasm/roundtrip.test.ts`) is the only other exercise of
|
|
1265
|
+
* this path and it skips without real `CS_*` secrets.
|
|
1266
|
+
*/
|
|
1267
|
+
declare function resolveStrategy(cfg: WasmClientConfig): WasmAuthStrategy;
|
|
1268
|
+
|
|
1269
|
+
export { type Encrypted, EncryptedColumn, EncryptedField, EncryptedTable, type EncryptedTableColumn, Encryption, type InferEncrypted, type InferPlaintext, type WasmAuthStrategy, type WasmClientConfig, WasmEncryptionClient, type WasmEncryptionConfig, type WasmPlaintext, __resetStrategyDeprecationWarningForTests, encryptedColumn, encryptedField, encryptedTable, getColumnName, isEncrypted, normalizeCastAs, resolveStrategy };
|