Skip to content

Commit ed3a3ab

Browse files
authored
Merge pull request #43 from cipherstash/typing
feat: implement jseql-ffi es6
2 parents 64ca0be + eeaec18 commit ed3a3ab

File tree

13 files changed

+644
-412
lines changed

13 files changed

+644
-412
lines changed

.changeset/giant-flies-hide.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@cipherstash/nextjs": minor
3+
"@cipherstash/jseql": minor
4+
"@cipherstash/basic-example": minor
5+
---
6+
7+
Implemented typing and import synatx for es6.

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,10 @@ const eqlClient = await eql()
102102
.. or using ES6?
103103

104104
```typescript
105-
import { createRequire } from 'node:module'
106-
const require = createRequire(import.meta.url)
107-
const { eql } = require('@cipherstash/jseql')
108-
105+
import { eql } from '@cipherstash/jseql'
109106
const eqlClient = await eql()
110107
```
111108

112-
We are working on a solution to support the `import` statement in the future.
113-
114109
### Encrypting data
115110

116111
To encrypt data, use the `encrypt` function. This function takes a plaintext string and an object with the table and column name as parameters.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"changeset:version": "changeset version",
2929
"changeset:publish": "changeset publish",
3030
"dev": "turbo dev --filter './packages/*'",
31+
"clean": "rimraf --glob **/.next **/.turbo **/dist **/node_modules",
3132
"code:fix": "biome check --write",
3233
"release": "turbo run build && changeset publish",
3334
"test": "turbo test --filter './packages/*'"
@@ -36,6 +37,7 @@
3637
"@biomejs/biome": "^1.9.3",
3738
"@changesets/cli": "^2.27.9",
3839
"@types/node": "^22.10.2",
40+
"rimraf": "6.0.1",
3941
"turbo": "2.1.1"
4042
},
4143
"packageManager": "pnpm@9.15.3",

packages/jseql/__tests__/jseql.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ describe('jseql-ffi', () => {
191191
describe('bulk encryption', () => {
192192
it('should bulk encrypt and decrypt a payload', async () => {
193193
const eqlClient = await eql()
194-
195194
const ciphertexts = await eqlClient.bulkEncrypt(
196195
[
197196
{
@@ -209,8 +208,6 @@ describe('bulk encryption', () => {
209208
},
210209
)
211210

212-
console.log('ct', ciphertexts)
213-
214211
const plaintexts = await eqlClient.bulkDecrypt(ciphertexts)
215212

216213
expect(plaintexts).toEqual([
@@ -227,21 +224,17 @@ describe('bulk encryption', () => {
227224

228225
it('should return null if plaintexts is empty', async () => {
229226
const eqlClient = await eql()
230-
231227
const ciphertexts = await eqlClient.bulkEncrypt([], {
232228
table: 'users',
233229
column: 'column_name',
234230
})
235-
236231
expect(ciphertexts).toEqual(null)
237232
}, 30000)
238233

239234
it('should return null if decrypting empty ciphertexts', async () => {
240235
const eqlClient = await eql()
241-
242236
const ciphertexts = null
243237
const plaintexts = await eqlClient.bulkDecrypt(ciphertexts)
244-
245238
expect(plaintexts).toEqual(null)
246239
}, 30000)
247240
})

packages/jseql/generateSchema.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env node
2+
3+
import fs from 'node:fs/promises'
4+
import { execa } from 'execa'
5+
6+
async function main() {
7+
const url =
8+
'https://raw.githubusercontent.com/cipherstash/encrypt-query-language/main/sql/schemas/cs_plaintext_v1.schema.json'
9+
10+
const response = await fetch(url)
11+
const data = await response.json()
12+
13+
await fs.writeFile(
14+
'./cs_plaintext_v1.schema.json',
15+
JSON.stringify(data, null, 2),
16+
)
17+
18+
await execa('pnpm', ['run', 'generate-types'], { stdio: 'inherit' })
19+
20+
console.log('Types generated!')
21+
}
22+
23+
main().catch((err) => {
24+
console.error(err)
25+
process.exit(1)
26+
})

packages/jseql/generateSchema.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/jseql/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@
3535
"scripts": {
3636
"build": "tsup",
3737
"dev": "tsup --watch",
38+
"update-schema": "node ./generateSchema.mjs",
3839
"generate-types": "json2ts ./cs_plaintext_v1.schema.json --output ./src/cs_plaintext_v1.ts",
3940
"test": "vitest run"
4041
},
4142
"devDependencies": {
4243
"dotenv": "^16.4.7",
44+
"execa": "^9.5.2",
4345
"json-schema-to-typescript": "^15.0.2",
4446
"tsup": "^8.3.0",
4547
"vitest": "^2.1.8"
@@ -51,7 +53,7 @@
5153
"access": "public"
5254
},
5355
"dependencies": {
54-
"@cipherstash/jseql-ffi": "^0.4.0"
56+
"@cipherstash/jseql-ffi": "0.5.0"
5557
},
5658
"optionalDependencies": {
5759
"@rollup/rollup-linux-x64-gnu": "4.24.0"

0 commit comments

Comments
 (0)