@ciderjs/gasnuki 0.1.3 → 0.1.5
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 +53 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +3 -48
- package/dist/index.mjs +3 -48
- package/dist/promise.cjs +18 -0
- package/dist/promise.d.cts +6 -0
- package/dist/promise.d.mts +6 -0
- package/dist/promise.d.ts +6 -0
- package/dist/promise.mjs +16 -0
- package/package.json +10 -4
package/bin/generate.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
[key: string]: (...args: any[]) => any;
|
|
9
|
+
withSuccessHandler: <T = string | number | boolean | undefined, U = any>(
|
|
10
|
+
callback: (returnValues: T, userObject?: U) => void,
|
|
11
|
+
) => _AppsScriptRun;
|
|
12
|
+
withFailureHandler: <U = any>(
|
|
13
|
+
callback: (error: Error, userObject?: U) => void,
|
|
14
|
+
) => _AppsScriptRun;
|
|
15
|
+
withUserObject: <U = any>(userObject: U) => _AppsScriptRun;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type _AppsScriptHistoryFunction = (
|
|
19
|
+
stateObject: object,
|
|
20
|
+
params: object,
|
|
21
|
+
hash: string,
|
|
22
|
+
) => void;
|
|
23
|
+
|
|
24
|
+
interface _WebAppLovacationType {
|
|
25
|
+
hash: string;
|
|
26
|
+
parameter: Record<string, string>;
|
|
27
|
+
parameters: Record<string, string[]>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export declare interface GoogleClientSideApi {
|
|
31
|
+
script: {
|
|
32
|
+
run: _AppsScriptRun;
|
|
33
|
+
url: {
|
|
34
|
+
getLocation: (
|
|
35
|
+
callback: (location: _WebAppLovacationType) => void,
|
|
36
|
+
) => void;
|
|
37
|
+
};
|
|
38
|
+
history: {
|
|
39
|
+
push: _AppsScriptHistoryFunction;
|
|
40
|
+
replace: _AppsScriptHistoryFunction;
|
|
41
|
+
setChangeHandler: (
|
|
42
|
+
callback: (e: {
|
|
43
|
+
state: object;
|
|
44
|
+
location: _WebAppLovacationType;
|
|
45
|
+
}) => void,
|
|
46
|
+
) => void;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare global {
|
|
52
|
+
const google: GoogleClientSideApi;
|
|
53
|
+
}
|
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 [key: string]: (...args: any[]) => any;\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(", ")}>` : "";
|
|
@@ -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 [key: string]: (...args: any[]) => any;\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(", ")}>` : "";
|
|
@@ -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/dist/promise.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const ServerScripts = () => {
|
|
4
|
+
const serverScripts = {};
|
|
5
|
+
for (const method of Object.keys(google.script.run)) {
|
|
6
|
+
if (["withSuccessHandler", "withFailureHandler", "withUserObject"].includes(
|
|
7
|
+
String(method)
|
|
8
|
+
)) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
serverScripts[method] = (...args) => new Promise((resolve, reject) => {
|
|
12
|
+
google.script.run.withSuccessHandler(resolve).withFailureHandler(reject)[method](...args);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return serverScripts;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.ServerScripts = ServerScripts;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type Promised<T> = {
|
|
2
|
+
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<R> : T[K];
|
|
3
|
+
};
|
|
4
|
+
declare const ServerScripts: <T extends Record<string, (...args: any[]) => any> = Omit<Omit<Omit<typeof google.script.run, "withSuccessHandler">, "withFailureHandler">, "withUserObject">>() => Promised<T>;
|
|
5
|
+
|
|
6
|
+
export { ServerScripts };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type Promised<T> = {
|
|
2
|
+
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<R> : T[K];
|
|
3
|
+
};
|
|
4
|
+
declare const ServerScripts: <T extends Record<string, (...args: any[]) => any> = Omit<Omit<Omit<typeof google.script.run, "withSuccessHandler">, "withFailureHandler">, "withUserObject">>() => Promised<T>;
|
|
5
|
+
|
|
6
|
+
export { ServerScripts };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type Promised<T> = {
|
|
2
|
+
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<R> : T[K];
|
|
3
|
+
};
|
|
4
|
+
declare const ServerScripts: <T extends Record<string, (...args: any[]) => any> = Omit<Omit<Omit<typeof google.script.run, "withSuccessHandler">, "withFailureHandler">, "withUserObject">>() => Promised<T>;
|
|
5
|
+
|
|
6
|
+
export { ServerScripts };
|
package/dist/promise.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const ServerScripts = () => {
|
|
2
|
+
const serverScripts = {};
|
|
3
|
+
for (const method of Object.keys(google.script.run)) {
|
|
4
|
+
if (["withSuccessHandler", "withFailureHandler", "withUserObject"].includes(
|
|
5
|
+
String(method)
|
|
6
|
+
)) {
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
serverScripts[method] = (...args) => new Promise((resolve, reject) => {
|
|
10
|
+
google.script.run.withSuccessHandler(resolve).withFailureHandler(reject)[method](...args);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return serverScripts;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { ServerScripts };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ciderjs/gasnuki",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "Type definitions and utilities for Google Apps Script client-side API",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"bin": {
|
|
@@ -12,13 +12,19 @@
|
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"import": "./dist/index.mjs",
|
|
14
14
|
"require": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./promise": {
|
|
17
|
+
"types": "./dist/promise.d.ts",
|
|
18
|
+
"import": "./dist/promise.mjs",
|
|
19
|
+
"require": "./dist/promise.cjs"
|
|
15
20
|
}
|
|
16
21
|
},
|
|
17
22
|
"scripts": {
|
|
18
|
-
"
|
|
23
|
+
"prebuild": "jiti bin/generate.ts",
|
|
24
|
+
"dev": "pnpm prebuild && jiti src/cli.ts -p playground/react -s src/server",
|
|
19
25
|
"start": "node dist/cli.mjs -p playground/react -s src/server",
|
|
20
26
|
"check": "biome check --write",
|
|
21
|
-
"build": "unbuild",
|
|
27
|
+
"build": "pnpm prebuild && unbuild",
|
|
22
28
|
"test": "vitest run",
|
|
23
29
|
"prepare": "pnpm run check && pnpm run build"
|
|
24
30
|
},
|