@ciderjs/gasnuki 0.1.2 → 0.1.4
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/bin/generate.ts +11 -0
- package/bin/typedef/clientside.d.ts +52 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +7 -52
- package/dist/index.mjs +7 -52
- package/package.json +4 -3
package/bin/generate.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
type RemoveReturnType<T> = {
|
|
2
|
+
[P in keyof T]: T[P] extends (...args: infer A) => any
|
|
3
|
+
? (...args: A) => void
|
|
4
|
+
: T[P];
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
type _AppsScriptRun = RemoveReturnType<ServerScripts> & {
|
|
8
|
+
withSuccessHandler: <T = string | number | boolean | undefined, U = any>(
|
|
9
|
+
callback: (returnValues: T, userObject?: U) => void,
|
|
10
|
+
) => _AppsScriptRun;
|
|
11
|
+
withFailureHandler: <U = any>(
|
|
12
|
+
callback: (error: Error, userObject?: U) => void,
|
|
13
|
+
) => _AppsScriptRun;
|
|
14
|
+
withUserObject: <U = any>(userObject: U) => _AppsScriptRun;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type _AppsScriptHistoryFunction = (
|
|
18
|
+
stateObject: object,
|
|
19
|
+
params: object,
|
|
20
|
+
hash: string,
|
|
21
|
+
) => void;
|
|
22
|
+
|
|
23
|
+
interface _WebAppLovacationType {
|
|
24
|
+
hash: string;
|
|
25
|
+
parameter: Record<string, string>;
|
|
26
|
+
parameters: Record<string, string[]>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export declare interface GoogleClientSideApi {
|
|
30
|
+
script: {
|
|
31
|
+
run: _AppsScriptRun;
|
|
32
|
+
url: {
|
|
33
|
+
getLocation: (
|
|
34
|
+
callback: (location: _WebAppLovacationType) => void,
|
|
35
|
+
) => void;
|
|
36
|
+
};
|
|
37
|
+
history: {
|
|
38
|
+
push: _AppsScriptHistoryFunction;
|
|
39
|
+
replace: _AppsScriptHistoryFunction;
|
|
40
|
+
setChangeHandler: (
|
|
41
|
+
callback: (e: {
|
|
42
|
+
state: object;
|
|
43
|
+
location: _WebAppLovacationType;
|
|
44
|
+
}) => void,
|
|
45
|
+
) => void;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare global {
|
|
51
|
+
const google: GoogleClientSideApi;
|
|
52
|
+
}
|
package/dist/cli.cjs
CHANGED
package/dist/cli.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,8 @@ const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
|
|
|
22
22
|
const chokidar__namespace = /*#__PURE__*/_interopNamespaceCompat(chokidar);
|
|
23
23
|
const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs);
|
|
24
24
|
|
|
25
|
+
const text = "type RemoveReturnType<T> = {\n [P in keyof T]: T[P] extends (...args: infer A) => any\n ? (...args: A) => void\n : T[P];\n};\n\ntype _AppsScriptRun = RemoveReturnType<ServerScripts> & {\n withSuccessHandler: <T = string | number | boolean | undefined, U = any>(\n callback: (returnValues: T, userObject?: U) => void,\n ) => _AppsScriptRun;\n withFailureHandler: <U = any>(\n callback: (error: Error, userObject?: U) => void,\n ) => _AppsScriptRun;\n withUserObject: <U = any>(userObject: U) => _AppsScriptRun;\n};\n\ntype _AppsScriptHistoryFunction = (\n stateObject: object,\n params: object,\n hash: string,\n) => void;\n\ninterface _WebAppLovacationType {\n hash: string;\n parameter: Record<string, string>;\n parameters: Record<string, string[]>;\n}\n\nexport declare interface GoogleClientSideApi {\n script: {\n run: _AppsScriptRun;\n url: {\n getLocation: (\n callback: (location: _WebAppLovacationType) => void,\n ) => void;\n };\n history: {\n push: _AppsScriptHistoryFunction;\n replace: _AppsScriptHistoryFunction;\n setChangeHandler: (\n callback: (e: {\n state: object;\n location: _WebAppLovacationType;\n }) => void,\n ) => void;\n };\n };\n}\n\ndeclare global {\n const google: GoogleClientSideApi;\n}\n";
|
|
26
|
+
|
|
25
27
|
const getInterfaceMethodDefinition_ = (name, node) => {
|
|
26
28
|
const typeParameters = node.getTypeParameters?.() ?? [];
|
|
27
29
|
const typeParamsString = typeParameters.length > 0 ? `<${typeParameters.map((tp) => tp.getText()).join(", ")}>` : "";
|
|
@@ -109,7 +111,7 @@ const generateAppsScriptTypes = async ({
|
|
|
109
111
|
for (const funcDecl of sourceFile.getFunctions()) {
|
|
110
112
|
if (!funcDecl.isAmbient()) {
|
|
111
113
|
const name = funcDecl.getName();
|
|
112
|
-
if (name != null) {
|
|
114
|
+
if (name != null && !name.endsWith("_")) {
|
|
113
115
|
methodDefinitions.push(getInterfaceMethodDefinition_(name, funcDecl));
|
|
114
116
|
}
|
|
115
117
|
}
|
|
@@ -119,7 +121,7 @@ const generateAppsScriptTypes = async ({
|
|
|
119
121
|
for (const varDecl of varStmt.getDeclarations()) {
|
|
120
122
|
const initializer = varDecl.getInitializer();
|
|
121
123
|
const varName = varDecl.getName();
|
|
122
|
-
if (initializer != null && (initializer.getKind() === tsMorph.SyntaxKind.ArrowFunction || initializer.getKind() === tsMorph.SyntaxKind.FunctionExpression)) {
|
|
124
|
+
if (initializer != null && (initializer.getKind() === tsMorph.SyntaxKind.ArrowFunction || initializer.getKind() === tsMorph.SyntaxKind.FunctionExpression) && !varName.endsWith("_")) {
|
|
123
125
|
methodDefinitions.push(
|
|
124
126
|
getInterfaceMethodDefinition_(
|
|
125
127
|
varName,
|
|
@@ -148,7 +150,7 @@ const generateAppsScriptTypes = async ({
|
|
|
148
150
|
const formattedMethods = methodDefinitions.map(
|
|
149
151
|
(method) => method.split("\n").map((line) => ` ${line}`).join("\n")
|
|
150
152
|
).join("\n\n");
|
|
151
|
-
outputContent += `export
|
|
153
|
+
outputContent += `export type ServerScripts = {
|
|
152
154
|
${formattedMethods}
|
|
153
155
|
}
|
|
154
156
|
`;
|
|
@@ -156,7 +158,7 @@ ${formattedMethods}
|
|
|
156
158
|
`Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${globalTypeDefinitions.length} type(s)).`
|
|
157
159
|
);
|
|
158
160
|
} else {
|
|
159
|
-
outputContent = "export
|
|
161
|
+
outputContent = "export type ServerScripts = {}\n";
|
|
160
162
|
consola.consola.info(
|
|
161
163
|
`Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (no functions found).`
|
|
162
164
|
);
|
|
@@ -164,54 +166,7 @@ ${formattedMethods}
|
|
|
164
166
|
outputContent += `
|
|
165
167
|
// Auto-generated Types for GoogleAppsScript in client-side code
|
|
166
168
|
|
|
167
|
-
|
|
168
|
-
[P in keyof T]: T[P] extends (...args: infer A) => any
|
|
169
|
-
? (...args: A) => void
|
|
170
|
-
: T[P];
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
type _AppsScriptRun = RemoveReturnType<ServerScripts> & {
|
|
174
|
-
withSuccessHandler: <T = string | number | boolean | undefined, U = any>(
|
|
175
|
-
callback: (returnValues: T, userObject?: U) => void,
|
|
176
|
-
) => _AppsScriptRun;
|
|
177
|
-
withFailureHandler: <U = any>(
|
|
178
|
-
callback: (error: Error, userObject?: U) => void,
|
|
179
|
-
) => _AppsScriptRun;
|
|
180
|
-
withUserObject: <U = any>(userObject: U) => _AppsScriptRun;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
type _AppsScriptHistoryFunction = (
|
|
184
|
-
stateObject: object,
|
|
185
|
-
params: object,
|
|
186
|
-
hash: string,
|
|
187
|
-
) => void;
|
|
188
|
-
|
|
189
|
-
interface _WebAppLovacationType {
|
|
190
|
-
hash: string;
|
|
191
|
-
parameter: Record<string, string>;
|
|
192
|
-
parameters: Record<string, string[]>;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export declare interface GoogleClientSideApi {
|
|
196
|
-
script: {
|
|
197
|
-
run: _AppsScriptRun;
|
|
198
|
-
url: {
|
|
199
|
-
getLocation: (callback: (location: _WebAppLovacationType) => void) => void;
|
|
200
|
-
};
|
|
201
|
-
history: {
|
|
202
|
-
push: _AppsScriptHistoryFunction;
|
|
203
|
-
replace: _AppsScriptHistoryFunction;
|
|
204
|
-
setChangeHandler: (
|
|
205
|
-
callback: (e: { state: object; location: _WebAppLovacationType }) => void
|
|
206
|
-
) => void;
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
declare global {
|
|
212
|
-
const google: GoogleClientSideApi;
|
|
213
|
-
}
|
|
214
|
-
`;
|
|
169
|
+
${text}`;
|
|
215
170
|
fs__namespace.writeFileSync(absoluteOutputFile, outputContent);
|
|
216
171
|
};
|
|
217
172
|
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,8 @@ import { consola } from 'consola';
|
|
|
4
4
|
import * as fs from 'node:fs';
|
|
5
5
|
import { Project, SyntaxKind } from 'ts-morph';
|
|
6
6
|
|
|
7
|
+
const text = "type RemoveReturnType<T> = {\n [P in keyof T]: T[P] extends (...args: infer A) => any\n ? (...args: A) => void\n : T[P];\n};\n\ntype _AppsScriptRun = RemoveReturnType<ServerScripts> & {\n withSuccessHandler: <T = string | number | boolean | undefined, U = any>(\n callback: (returnValues: T, userObject?: U) => void,\n ) => _AppsScriptRun;\n withFailureHandler: <U = any>(\n callback: (error: Error, userObject?: U) => void,\n ) => _AppsScriptRun;\n withUserObject: <U = any>(userObject: U) => _AppsScriptRun;\n};\n\ntype _AppsScriptHistoryFunction = (\n stateObject: object,\n params: object,\n hash: string,\n) => void;\n\ninterface _WebAppLovacationType {\n hash: string;\n parameter: Record<string, string>;\n parameters: Record<string, string[]>;\n}\n\nexport declare interface GoogleClientSideApi {\n script: {\n run: _AppsScriptRun;\n url: {\n getLocation: (\n callback: (location: _WebAppLovacationType) => void,\n ) => void;\n };\n history: {\n push: _AppsScriptHistoryFunction;\n replace: _AppsScriptHistoryFunction;\n setChangeHandler: (\n callback: (e: {\n state: object;\n location: _WebAppLovacationType;\n }) => void,\n ) => void;\n };\n };\n}\n\ndeclare global {\n const google: GoogleClientSideApi;\n}\n";
|
|
8
|
+
|
|
7
9
|
const getInterfaceMethodDefinition_ = (name, node) => {
|
|
8
10
|
const typeParameters = node.getTypeParameters?.() ?? [];
|
|
9
11
|
const typeParamsString = typeParameters.length > 0 ? `<${typeParameters.map((tp) => tp.getText()).join(", ")}>` : "";
|
|
@@ -91,7 +93,7 @@ const generateAppsScriptTypes = async ({
|
|
|
91
93
|
for (const funcDecl of sourceFile.getFunctions()) {
|
|
92
94
|
if (!funcDecl.isAmbient()) {
|
|
93
95
|
const name = funcDecl.getName();
|
|
94
|
-
if (name != null) {
|
|
96
|
+
if (name != null && !name.endsWith("_")) {
|
|
95
97
|
methodDefinitions.push(getInterfaceMethodDefinition_(name, funcDecl));
|
|
96
98
|
}
|
|
97
99
|
}
|
|
@@ -101,7 +103,7 @@ const generateAppsScriptTypes = async ({
|
|
|
101
103
|
for (const varDecl of varStmt.getDeclarations()) {
|
|
102
104
|
const initializer = varDecl.getInitializer();
|
|
103
105
|
const varName = varDecl.getName();
|
|
104
|
-
if (initializer != null && (initializer.getKind() === SyntaxKind.ArrowFunction || initializer.getKind() === SyntaxKind.FunctionExpression)) {
|
|
106
|
+
if (initializer != null && (initializer.getKind() === SyntaxKind.ArrowFunction || initializer.getKind() === SyntaxKind.FunctionExpression) && !varName.endsWith("_")) {
|
|
105
107
|
methodDefinitions.push(
|
|
106
108
|
getInterfaceMethodDefinition_(
|
|
107
109
|
varName,
|
|
@@ -130,7 +132,7 @@ const generateAppsScriptTypes = async ({
|
|
|
130
132
|
const formattedMethods = methodDefinitions.map(
|
|
131
133
|
(method) => method.split("\n").map((line) => ` ${line}`).join("\n")
|
|
132
134
|
).join("\n\n");
|
|
133
|
-
outputContent += `export
|
|
135
|
+
outputContent += `export type ServerScripts = {
|
|
134
136
|
${formattedMethods}
|
|
135
137
|
}
|
|
136
138
|
`;
|
|
@@ -138,7 +140,7 @@ ${formattedMethods}
|
|
|
138
140
|
`Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${globalTypeDefinitions.length} type(s)).`
|
|
139
141
|
);
|
|
140
142
|
} else {
|
|
141
|
-
outputContent = "export
|
|
143
|
+
outputContent = "export type ServerScripts = {}\n";
|
|
142
144
|
consola.info(
|
|
143
145
|
`Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (no functions found).`
|
|
144
146
|
);
|
|
@@ -146,54 +148,7 @@ ${formattedMethods}
|
|
|
146
148
|
outputContent += `
|
|
147
149
|
// Auto-generated Types for GoogleAppsScript in client-side code
|
|
148
150
|
|
|
149
|
-
|
|
150
|
-
[P in keyof T]: T[P] extends (...args: infer A) => any
|
|
151
|
-
? (...args: A) => void
|
|
152
|
-
: T[P];
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
type _AppsScriptRun = RemoveReturnType<ServerScripts> & {
|
|
156
|
-
withSuccessHandler: <T = string | number | boolean | undefined, U = any>(
|
|
157
|
-
callback: (returnValues: T, userObject?: U) => void,
|
|
158
|
-
) => _AppsScriptRun;
|
|
159
|
-
withFailureHandler: <U = any>(
|
|
160
|
-
callback: (error: Error, userObject?: U) => void,
|
|
161
|
-
) => _AppsScriptRun;
|
|
162
|
-
withUserObject: <U = any>(userObject: U) => _AppsScriptRun;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
type _AppsScriptHistoryFunction = (
|
|
166
|
-
stateObject: object,
|
|
167
|
-
params: object,
|
|
168
|
-
hash: string,
|
|
169
|
-
) => void;
|
|
170
|
-
|
|
171
|
-
interface _WebAppLovacationType {
|
|
172
|
-
hash: string;
|
|
173
|
-
parameter: Record<string, string>;
|
|
174
|
-
parameters: Record<string, string[]>;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export declare interface GoogleClientSideApi {
|
|
178
|
-
script: {
|
|
179
|
-
run: _AppsScriptRun;
|
|
180
|
-
url: {
|
|
181
|
-
getLocation: (callback: (location: _WebAppLovacationType) => void) => void;
|
|
182
|
-
};
|
|
183
|
-
history: {
|
|
184
|
-
push: _AppsScriptHistoryFunction;
|
|
185
|
-
replace: _AppsScriptHistoryFunction;
|
|
186
|
-
setChangeHandler: (
|
|
187
|
-
callback: (e: { state: object; location: _WebAppLovacationType }) => void
|
|
188
|
-
) => void;
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
declare global {
|
|
194
|
-
const google: GoogleClientSideApi;
|
|
195
|
-
}
|
|
196
|
-
`;
|
|
151
|
+
${text}`;
|
|
197
152
|
fs.writeFileSync(absoluteOutputFile, outputContent);
|
|
198
153
|
};
|
|
199
154
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ciderjs/gasnuki",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
|
-
"
|
|
18
|
+
"prebuild": "jiti bin/generate.ts",
|
|
19
|
+
"dev": "pnpm prebuild && jiti src/cli.ts -p playground/react -s src/server",
|
|
19
20
|
"start": "node dist/cli.mjs -p playground/react -s src/server",
|
|
20
21
|
"check": "biome check --write",
|
|
21
|
-
"build": "unbuild",
|
|
22
|
+
"build": "pnpm prebuild && unbuild",
|
|
22
23
|
"test": "vitest run",
|
|
23
24
|
"prepare": "pnpm run check && pnpm run build"
|
|
24
25
|
},
|