Skip to content

Commit 21d9861

Browse files
committed
update(yogurt): upgrade scripting types to Milky 1.2
1 parent f37c86c commit 21d9861

5 files changed

Lines changed: 35 additions & 15 deletions

File tree

yogurt-scripting/pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

yogurt-scripting/script-api/api.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export interface ApiCollection {
1313
get_group_info: (input: z.input<typeof types.GetGroupInfoInput>) => Promise<types.GetGroupInfoOutput>;
1414
get_group_member_list: (input: z.input<typeof types.GetGroupMemberListInput>) => Promise<types.GetGroupMemberListOutput>;
1515
get_group_member_info: (input: z.input<typeof types.GetGroupMemberInfoInput>) => Promise<types.GetGroupMemberInfoOutput>;
16+
get_peer_pins: () => Promise<types.GetPeerPinsOutput>;
17+
set_peer_pin: (input: z.input<typeof types.SetPeerPinInput>) => Promise<void>;
1618
set_avatar: (input: z.input<typeof types.SetAvatarInput>) => Promise<void>;
1719
set_nickname: (input: z.input<typeof types.SetNicknameInput>) => Promise<void>;
1820
set_bio: (input: z.input<typeof types.SetBioInput>) => Promise<void>;

yogurt-scripting/script-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@acidify/yogurt-script-api",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"type": "module",
55
"description": "Yogurt Scripting API",
66
"scripts": {
@@ -20,7 +20,7 @@
2020
"author": "LagrangeDev",
2121
"license": "GPL-3.0-only",
2222
"dependencies": {
23-
"@saltify/milky-types": "^1.1.0",
23+
"@saltify/milky-types": "^1.2.2",
2424
"zod": "^4.3.6"
2525
}
2626
}

yogurt-scripting/script-api/scripts/generate-api.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
1-
import { apiCategories } from '@saltify/milky-types/api';
1+
import {zodApiCategories} from '@saltify/milky-types';
22
import * as fs from 'node:fs';
33
import * as path from 'node:path';
44

5-
const ApiCollection = Object.entries(apiCategories)
5+
const preserveAllCapitalWords = new Set([
6+
'csrf'
7+
])
8+
9+
function snakeToPascal(str) {
10+
return str
11+
.split('_')
12+
.filter(Boolean)
13+
.map(word => {
14+
if (preserveAllCapitalWords.has(word)) {
15+
return word.toUpperCase();
16+
}
17+
return word.charAt(0).toUpperCase() + word.slice(1);
18+
})
19+
.join('');
20+
}
21+
22+
const ApiCollection = Object.entries(zodApiCategories)
623
.map(([category, data]) => {
7-
const res = data.apis.map((api) => {
8-
const input = api.inputStruct ? `input: z.input<typeof types.${api.inputStruct}>` : '';
9-
const output = api.outputStruct ? `types.${api.outputStruct}` : 'void';
10-
return `${api.endpoint}: (${input}) => Promise<${output}>;`;
24+
const res = Object.entries(data.apis).map(([endpoint, api]) => {
25+
const input = api.requestSchema ? `input: z.input<typeof types.${snakeToPascal(endpoint)}Input>` : '';
26+
const output = api.responseSchema ? `types.${snakeToPascal(endpoint)}Output` : 'void';
27+
return `${endpoint}: (${input}) => Promise<${output}>;`;
1128
});
1229
return ` // ${category} API\n ${res.join('\n ')}\n`;
1330
})
1431
.join('\n');
1532

16-
await fs.promises.writeFile(path.resolve('api.d.ts'), `
33+
fs.writeFileSync(path.resolve('api.d.ts'), `
1734
/* eslint-disable */
1835
import * as types from '@saltify/milky-types';
1936
import type z from 'zod';

yogurt-scripting/script-api/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"lib": ["esnext"],
44
"module": "nodenext",
55
"target": "esnext",
6-
"moduleResolution": "nodenext"
6+
"moduleResolution": "nodenext",
7+
"types": ["node"]
78
}
89
}

0 commit comments

Comments
 (0)