Skip to content

Commit 960aded

Browse files
chore: add jsr.io config
1 parent 908981f commit 960aded

10 files changed

+96
-23
lines changed

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@jsr:registry=https://npm.jsr.io

README.md

-7
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ Configuring options for this tool is flexible and convenient. You have two main
5858
And the best part? You can use both methods simultaneously if it suits your needs. In such cases, the tool intelligently merges the parameters, giving priority to the ones provided through the CLI.
5959
This means you have complete control over your configuration, adapting it to your preferences effortlessly.
6060

61-
Decide for which lib do you want to generate your client.
62-
Currently available:
63-
64-
- surrealdb.js
65-
- surrealdb.node
66-
6761
```bash
6862
Usage: surql-gen [options]
6963

@@ -81,7 +75,6 @@ Options:
8175
-o, --outputFolder output folder (default: client_generated)
8276
-g, --generateClient generate client (default: true)
8377
--no-generateClient no client generation
84-
-l, --lib library to be used in client (default: surrealdb.js)
8578
-h, --help display help for command
8679
```
8780

jsr.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://jsr.io/schema/config-file.v1.json",
3+
"name": "@sebastianwessel/surql-gen",
4+
"description": "A small tool which generates a typescript client for SurrealDB based on the schema of a given database",
5+
"version": "2.3.0",
6+
"exports": "./dist/esm/index.js",
7+
"publish": {
8+
"include": ["dist/**/*.js", "dist/**/*.d.ts", "README.md", "package.json"],
9+
"exclude": ["src", ".github", ".vscode", "!dist", "!dist/**/*.js", "!dist/**/*.d.ts", ".tshy", "out"]
10+
}
11+
}

package-lock.json

+69-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
"build": "tshy",
3232
"lint": "npx @biomejs/biome check --write .",
3333
"test": "vitest",
34-
"prepare": "tshy"
34+
"prepublishOnly": "npm run lint && vitest --no-watch && tshy",
35+
"postpublish": "npx jsr publish"
3536
},
3637
"devDependencies": {
3738
"@biomejs/biome": "^1.8.3",
3839
"@types/node": "^20.14.10",
3940
"tshy": "^3.0.2",
41+
"jsr": "^0.12.4",
4042
"tsx": "^4.15.7",
4143
"typescript": "^5.5.2",
4244
"vitest": "^2.0.1"

src/genSchema/generateTableSchema.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ describe('generateTableSchema', () => {
1313
'DEFINE TABLE test TYPE ANY SCHEMAFULL PERMISSIONS NONE',
1414
)
1515

16-
expect(inputFields).toBe('const testInputSchemaGen = z.object({\nname: z.string(),\n})')
16+
expect(inputFields).toBe('const testInputSchemaGen = z.object({\n name: z.string()\n})')
1717

18-
expect(outputFields).toBe('const testOutputSchemaGen = z.object({\nname: z.string(),\n})')
18+
expect(outputFields).toBe('const testOutputSchemaGen = z.object({\n name: z.string()\n})')
1919
})
2020

2121
it('generates a schema for a SCHEMALESS table', async () => {
@@ -24,9 +24,9 @@ describe('generateTableSchema', () => {
2424
'DEFINE TABLE test TYPE ANY SCHEMALESS PERMISSIONS NONE',
2525
)
2626

27-
expect(inputFields).toBe('const testInputSchemaGen = z.object({\nname: z.string(),\n}).passthrough()')
27+
expect(inputFields).toBe('const testInputSchemaGen = z.object({\n name: z.string()\n}).passthrough()')
2828

29-
expect(outputFields).toBe('const testOutputSchemaGen = z.object({\nname: z.string(),\n}).passthrough()')
29+
expect(outputFields).toBe('const testOutputSchemaGen = z.object({\n name: z.string()\n}).passthrough()')
3030
})
3131

3232
it('generates a schema for a table without explicit SCHEMAFULL/SCHEMALESS setting', async () => {
@@ -35,8 +35,8 @@ describe('generateTableSchema', () => {
3535
'DEFINE TABLE test TYPE ANY PERMISSIONS NONE',
3636
)
3737

38-
expect(inputFields).toBe('const testInputSchemaGen = z.object({\nname: z.string(),\n}).passthrough()')
38+
expect(inputFields).toBe('const testInputSchemaGen = z.object({\n name: z.string()\n}).passthrough()')
3939

40-
expect(outputFields).toBe('const testOutputSchemaGen = z.object({\nname: z.string(),\n}).passthrough()')
40+
expect(outputFields).toBe('const testOutputSchemaGen = z.object({\n name: z.string()\n}).passthrough()')
4141
})
4242
})

src/genSchema/generateZodSchemaCode.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ export const generateZodSchemaCode = (fields: FieldDetail[], schemaName: string)
77
const parts = field.name.split('.').map(part => part.replace('[*]', ''))
88
let current = fieldMap
99

10+
const fieldDefault = undefined // field.default
11+
1012
let i = 0
1113
for (const part of parts) {
1214
if (i === parts.length - 1) {
1315
// Leaf node
1416
if (field.type?.startsWith('array')) {
15-
current[part] = `z.array(${field.zodString.replace('{}', '')}).default(${field.default ?? '[]'})`
17+
current[part] = `z.array(${field.zodString.replace('{}', '')}).default(${fieldDefault ?? '[]'})`
1618
} else {
17-
const fieldDefault = field.default ? `.default(${field.default})` : ''
18-
current[part] = `${field.zodString}${fieldDefault}`
19+
const fd = fieldDefault ? `.default(${fieldDefault})` : ''
20+
current[part] = `${field.zodString}${fd}`
1921
}
2022
} else {
2123
// Intermediate node

src/genSchema/tokenize.ts

-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ export const tokenize = (definition: string): TokenizedDefinition => {
4848

4949
const defaultMatch = definition.match(/DEFAULT (\S+)/im)
5050
if (defaultMatch) {
51-
// Default makes no sense in base schemas.
52-
// Get should only return existing values
53-
// Create with default means optional in schema
5451
result.default = defaultMatch[1]
5552
}
5653

vitest.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export default defineConfig({
55
include: ['**/*.test.ts'],
66
globals: true,
77
disableConsoleIntercept: true,
8-
setupFiles: ['./customMatchers.ts'],
8+
setupFiles: ['./vitest.customMatchers.ts'],
99
},
1010
})
File renamed without changes.

0 commit comments

Comments
 (0)