@ciderjs/gasnuki 0.4.0 → 0.5.0
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/README.ja.md +30 -3
- package/README.md +30 -3
- package/dist/cli.cjs +2 -2
- package/dist/cli.mjs +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/json.cjs +21 -0
- package/dist/json.d.cts +29 -0
- package/dist/json.d.mts +29 -0
- package/dist/json.d.ts +29 -0
- package/dist/json.mjs +18 -0
- package/dist/promise.cjs +16 -3
- package/dist/promise.d.cts +14 -2
- package/dist/promise.d.mts +14 -2
- package/dist/promise.d.ts +14 -2
- package/dist/promise.mjs +16 -3
- package/dist/shared/{gasnuki.DfLTmLhN.cjs → gasnuki.Co0-wxJi.cjs} +142 -41
- package/dist/shared/{gasnuki.SJQVcSIQ.mjs → gasnuki.DePJgSg9.mjs} +142 -41
- package/dist/vite.cjs +1 -1
- package/dist/vite.mjs +1 -1
- package/package.json +10 -5
package/README.ja.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# @ciderjs/gasnuki
|
|
2
2
|
|
|
3
3
|
[](./README.md)
|
|
4
|
-
[](https://github.com/luthpg/gasnuki)
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](https://www.npmjs.com/package/@ciderjs/gasnuki)
|
|
7
|
+

|
|
7
8
|
[](https://github.com/luthpg/gasnuki/issues)
|
|
8
9
|
|
|
9
10
|
Google Apps Script クライアントサイドAPIの型定義・ユーティリティ
|
|
@@ -160,7 +161,7 @@ import {
|
|
|
160
161
|
import type { ServerScripts } from '../types/appsscript';
|
|
161
162
|
|
|
162
163
|
// 開発用のモック関数を定義します
|
|
163
|
-
const
|
|
164
|
+
const mockupFunctions: PartialScriptType<ServerScripts> = {
|
|
164
165
|
// sayHello関数の動作をシミュレート
|
|
165
166
|
sayHello: async (name) => {
|
|
166
167
|
await new Promise(resolve => setTimeout(resolve, 500)); // ネットワーク遅延を模倣
|
|
@@ -169,7 +170,33 @@ const mockup: PartialScriptType<ServerScripts> = {
|
|
|
169
170
|
// 他の関数も同様にモックできます
|
|
170
171
|
};
|
|
171
172
|
|
|
172
|
-
export const gas = getPromisedServerScripts<ServerScripts>(
|
|
173
|
+
export const gas = getPromisedServerScripts<ServerScripts>({ mockupFunctions });
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 型安全な JSON パース (Optional)
|
|
177
|
+
|
|
178
|
+
通常、Google Apps Script とクライアント間の通信で `JSON.parse()` を使うと戻り値が `any` になってしまいます。また、`Date` 型などはシリアライズの過程で文字列に変換され、手動での復元が必要になります。
|
|
179
|
+
|
|
180
|
+
`gasnuki` は、シリアライズ前の型情報を Branded Type (`JsonString<T>`) として保持することで、**`any` を介さない型安全な復元**を可能にします。
|
|
181
|
+
|
|
182
|
+
`getPromisedServerScripts` のオプションに `{ parseJson: true }` を指定すると、サーバー側で `serialize()` された戻り値を自動でデシリアライズし、`Date` オブジェクトも正しく復元します。
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
// サーバー側 (Apps Script)
|
|
186
|
+
// const getAppData = () => serialize({ updatedAt: new Date(), user: 'Alice' });
|
|
187
|
+
|
|
188
|
+
// クライアント側
|
|
189
|
+
export const gas = getPromisedServerScripts<ServerScripts>({
|
|
190
|
+
parseJson: true
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
async function fetchData() {
|
|
194
|
+
// 戻り値は `any` ではなく、元のオブジェクト型として推論されます
|
|
195
|
+
// Date オブジェクトも自動的に復元されます
|
|
196
|
+
const result = await gas.getAppData();
|
|
197
|
+
console.log(result.user); // 'Alice' (string)
|
|
198
|
+
console.log(result.updatedAt instanceof Date); // true
|
|
199
|
+
}
|
|
173
200
|
```
|
|
174
201
|
|
|
175
202
|
## コントリビュート
|
package/README.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# @ciderjs/gasnuki
|
|
2
2
|
|
|
3
3
|
[](./README.ja.md)
|
|
4
|
-
[](https://github.com/luthpg/gasnuki)
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](https://www.npmjs.com/package/@ciderjs/gasnuki)
|
|
7
|
+

|
|
7
8
|
[](https://github.com/luthpg/gasnuki/issues)
|
|
8
9
|
|
|
9
10
|
Type definitions and utilities for Google Apps Script client-side API
|
|
@@ -160,7 +161,7 @@ import {
|
|
|
160
161
|
import type { ServerScripts } from '../types/appsscript';
|
|
161
162
|
|
|
162
163
|
// Define mockup functions for development
|
|
163
|
-
const
|
|
164
|
+
const mockupFunctions: PartialScriptType<ServerScripts> = {
|
|
164
165
|
// Simulate the behavior of the sayHello function
|
|
165
166
|
sayHello: async (name) => {
|
|
166
167
|
await new Promise(resolve => setTimeout(resolve, 500)); // Simulate network delay
|
|
@@ -169,7 +170,33 @@ const mockup: PartialScriptType<ServerScripts> = {
|
|
|
169
170
|
// Other functions can be mocked similarly
|
|
170
171
|
};
|
|
171
172
|
|
|
172
|
-
export const gas = getPromisedServerScripts<ServerScripts>(
|
|
173
|
+
export const gas = getPromisedServerScripts<ServerScripts>({ mockupFunctions });
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Type-Safe JSON Parsing (Optional)
|
|
177
|
+
|
|
178
|
+
Normally, using `JSON.parse()` for communication between Google Apps Script and the client results in an `any` return type. Additionally, types like `Date` are converted to strings during serialization and require manual restoration.
|
|
179
|
+
|
|
180
|
+
`gasnuki` preserves the original type information as a Branded Type (`JsonString<T>`), enabling **type-safe restoration without using `any`**.
|
|
181
|
+
|
|
182
|
+
By passing `{ parseJson: true }` as the second argument to `getPromisedServerScripts`, it will automatically deserialize return values that were `serialize()`-ed on the server side, including proper `Date` object recovery.
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
// Server-side (Apps Script)
|
|
186
|
+
// const getAppData = () => serialize({ updatedAt: new Date(), user: 'Alice' });
|
|
187
|
+
|
|
188
|
+
// Client-side
|
|
189
|
+
export const gas = getPromisedServerScripts<ServerScripts>({
|
|
190
|
+
parseJson: true
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
async function fetchData() {
|
|
194
|
+
// The return value is inferred as the original object type instead of `any`
|
|
195
|
+
// Date objects are also automatically recovered
|
|
196
|
+
const result = await gas.getAppData();
|
|
197
|
+
console.log(result.user); // 'Alice' (string)
|
|
198
|
+
console.log(result.updatedAt instanceof Date); // true
|
|
199
|
+
}
|
|
173
200
|
```
|
|
174
201
|
|
|
175
202
|
## Contributing
|
package/dist/cli.cjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
const path = require('node:path');
|
|
5
5
|
const commander = require('commander');
|
|
6
6
|
const index = require('./index.cjs');
|
|
7
|
-
const config = require('./shared/gasnuki.
|
|
7
|
+
const config = require('./shared/gasnuki.Co0-wxJi.cjs');
|
|
8
8
|
require('chokidar');
|
|
9
9
|
require('consola');
|
|
10
10
|
require('node:crypto');
|
|
@@ -26,7 +26,7 @@ function _interopNamespaceCompat(e) {
|
|
|
26
26
|
|
|
27
27
|
const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
|
|
28
28
|
|
|
29
|
-
const version = "0.
|
|
29
|
+
const version = "0.5.0";
|
|
30
30
|
|
|
31
31
|
const parseArgs = async (command) => {
|
|
32
32
|
const cliOpts = command.opts();
|
package/dist/cli.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import { generateTypes } from './index.mjs';
|
|
5
|
-
import { l as loadConfig } from './shared/gasnuki.
|
|
5
|
+
import { l as loadConfig } from './shared/gasnuki.DePJgSg9.mjs';
|
|
6
6
|
import 'chokidar';
|
|
7
7
|
import 'consola';
|
|
8
8
|
import 'node:crypto';
|
|
@@ -10,7 +10,7 @@ import 'node:fs';
|
|
|
10
10
|
import 'ts-morph';
|
|
11
11
|
import 'jiti';
|
|
12
12
|
|
|
13
|
-
const version = "0.
|
|
13
|
+
const version = "0.5.0";
|
|
14
14
|
|
|
15
15
|
const parseArgs = async (command) => {
|
|
16
16
|
const cliOpts = command.opts();
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const path = require('node:path');
|
|
4
4
|
const chokidar = require('chokidar');
|
|
5
5
|
const consola = require('consola');
|
|
6
|
-
const config = require('./shared/gasnuki.
|
|
6
|
+
const config = require('./shared/gasnuki.Co0-wxJi.cjs');
|
|
7
7
|
require('node:crypto');
|
|
8
8
|
require('node:fs');
|
|
9
9
|
require('ts-morph');
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import * as chokidar from 'chokidar';
|
|
3
3
|
import { consola } from 'consola';
|
|
4
|
-
import { g as generateAppsScriptTypes } from './shared/gasnuki.
|
|
5
|
-
export { d as defineConfig } from './shared/gasnuki.
|
|
4
|
+
import { g as generateAppsScriptTypes } from './shared/gasnuki.DePJgSg9.mjs';
|
|
5
|
+
export { d as defineConfig } from './shared/gasnuki.DePJgSg9.mjs';
|
|
6
6
|
import 'node:crypto';
|
|
7
7
|
import 'node:fs';
|
|
8
8
|
import 'ts-morph';
|
package/dist/json.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const isoDateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/;
|
|
4
|
+
function dateReviver(_key, value) {
|
|
5
|
+
if (typeof value === "string" && isoDateRegex.test(value)) {
|
|
6
|
+
const date = new Date(value);
|
|
7
|
+
if (!Number.isNaN(date.getTime())) {
|
|
8
|
+
return date;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
const serialize = (data) => {
|
|
14
|
+
return JSON.stringify(data);
|
|
15
|
+
};
|
|
16
|
+
const deserialize = (json) => {
|
|
17
|
+
return JSON.parse(json, dateReviver);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.deserialize = deserialize;
|
|
21
|
+
exports.serialize = serialize;
|
package/dist/json.d.cts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare const __brand: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* シリアライズ前の型情報 `T` を保持したJSON文字列型。
|
|
4
|
+
* 単なる string ではなく、型システム上で元の型を記憶することで、
|
|
5
|
+
* 復元時に型安全なパース(anyを介さない復元)を可能にします。
|
|
6
|
+
*/
|
|
7
|
+
type JsonString<T> = string & {
|
|
8
|
+
[__brand]: T;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* オブジェクトを型情報を保持したまま JSON 文字列に変換します。
|
|
12
|
+
* 戻り値は元の型 `T` を記憶した `JsonString<T>` となります。
|
|
13
|
+
*
|
|
14
|
+
* @param data 変換するオブジェクト
|
|
15
|
+
* @returns 型情報を保持した JSON 文字列
|
|
16
|
+
*/
|
|
17
|
+
declare const serialize: <T>(data: T) => JsonString<T>;
|
|
18
|
+
/**
|
|
19
|
+
* `JsonString<T>` から元の型 `T` を型安全に復元します。
|
|
20
|
+
* 通常の `JSON.parse` と異なり、戻り値が `any` にならず、
|
|
21
|
+
* また ISO 8601 形式の文字列は自動的に `Date` オブジェクトへ変換されます。
|
|
22
|
+
*
|
|
23
|
+
* @param json 型情報を保持した JSON 文字列
|
|
24
|
+
* @returns 元の型 `T` に復元されたオブジェクト
|
|
25
|
+
*/
|
|
26
|
+
declare const deserialize: <T>(json: JsonString<T>) => T;
|
|
27
|
+
|
|
28
|
+
export { deserialize, serialize };
|
|
29
|
+
export type { JsonString };
|
package/dist/json.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare const __brand: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* シリアライズ前の型情報 `T` を保持したJSON文字列型。
|
|
4
|
+
* 単なる string ではなく、型システム上で元の型を記憶することで、
|
|
5
|
+
* 復元時に型安全なパース(anyを介さない復元)を可能にします。
|
|
6
|
+
*/
|
|
7
|
+
type JsonString<T> = string & {
|
|
8
|
+
[__brand]: T;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* オブジェクトを型情報を保持したまま JSON 文字列に変換します。
|
|
12
|
+
* 戻り値は元の型 `T` を記憶した `JsonString<T>` となります。
|
|
13
|
+
*
|
|
14
|
+
* @param data 変換するオブジェクト
|
|
15
|
+
* @returns 型情報を保持した JSON 文字列
|
|
16
|
+
*/
|
|
17
|
+
declare const serialize: <T>(data: T) => JsonString<T>;
|
|
18
|
+
/**
|
|
19
|
+
* `JsonString<T>` から元の型 `T` を型安全に復元します。
|
|
20
|
+
* 通常の `JSON.parse` と異なり、戻り値が `any` にならず、
|
|
21
|
+
* また ISO 8601 形式の文字列は自動的に `Date` オブジェクトへ変換されます。
|
|
22
|
+
*
|
|
23
|
+
* @param json 型情報を保持した JSON 文字列
|
|
24
|
+
* @returns 元の型 `T` に復元されたオブジェクト
|
|
25
|
+
*/
|
|
26
|
+
declare const deserialize: <T>(json: JsonString<T>) => T;
|
|
27
|
+
|
|
28
|
+
export { deserialize, serialize };
|
|
29
|
+
export type { JsonString };
|
package/dist/json.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare const __brand: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* シリアライズ前の型情報 `T` を保持したJSON文字列型。
|
|
4
|
+
* 単なる string ではなく、型システム上で元の型を記憶することで、
|
|
5
|
+
* 復元時に型安全なパース(anyを介さない復元)を可能にします。
|
|
6
|
+
*/
|
|
7
|
+
type JsonString<T> = string & {
|
|
8
|
+
[__brand]: T;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* オブジェクトを型情報を保持したまま JSON 文字列に変換します。
|
|
12
|
+
* 戻り値は元の型 `T` を記憶した `JsonString<T>` となります。
|
|
13
|
+
*
|
|
14
|
+
* @param data 変換するオブジェクト
|
|
15
|
+
* @returns 型情報を保持した JSON 文字列
|
|
16
|
+
*/
|
|
17
|
+
declare const serialize: <T>(data: T) => JsonString<T>;
|
|
18
|
+
/**
|
|
19
|
+
* `JsonString<T>` から元の型 `T` を型安全に復元します。
|
|
20
|
+
* 通常の `JSON.parse` と異なり、戻り値が `any` にならず、
|
|
21
|
+
* また ISO 8601 形式の文字列は自動的に `Date` オブジェクトへ変換されます。
|
|
22
|
+
*
|
|
23
|
+
* @param json 型情報を保持した JSON 文字列
|
|
24
|
+
* @returns 元の型 `T` に復元されたオブジェクト
|
|
25
|
+
*/
|
|
26
|
+
declare const deserialize: <T>(json: JsonString<T>) => T;
|
|
27
|
+
|
|
28
|
+
export { deserialize, serialize };
|
|
29
|
+
export type { JsonString };
|
package/dist/json.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const isoDateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/;
|
|
2
|
+
function dateReviver(_key, value) {
|
|
3
|
+
if (typeof value === "string" && isoDateRegex.test(value)) {
|
|
4
|
+
const date = new Date(value);
|
|
5
|
+
if (!Number.isNaN(date.getTime())) {
|
|
6
|
+
return date;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
const serialize = (data) => {
|
|
12
|
+
return JSON.stringify(data);
|
|
13
|
+
};
|
|
14
|
+
const deserialize = (json) => {
|
|
15
|
+
return JSON.parse(json, dateReviver);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { deserialize, serialize };
|
package/dist/promise.cjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const json = require('./json.cjs');
|
|
4
|
+
|
|
5
|
+
function getPromisedServerScripts(options = {}) {
|
|
6
|
+
const { mockupFunctions = {}, parseJson = false } = options;
|
|
4
7
|
return new Proxy(mockupFunctions, {
|
|
5
8
|
get(target, method) {
|
|
6
9
|
if (!("google" in globalThis) || !google?.script?.run) {
|
|
@@ -10,10 +13,20 @@ const getPromisedServerScripts = (mockupFunctions = {}) => {
|
|
|
10
13
|
throw Error(`Method ${method} not found in AppsScript.`);
|
|
11
14
|
}
|
|
12
15
|
return (...args) => new Promise((resolve, reject) => {
|
|
13
|
-
google.script.run.withSuccessHandler(
|
|
16
|
+
google.script.run.withSuccessHandler((res) => {
|
|
17
|
+
if (parseJson && typeof res === "string") {
|
|
18
|
+
try {
|
|
19
|
+
resolve(json.deserialize(res));
|
|
20
|
+
} catch {
|
|
21
|
+
resolve(res);
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
resolve(res);
|
|
25
|
+
}
|
|
26
|
+
}).withFailureHandler(reject)[method](...args);
|
|
14
27
|
});
|
|
15
28
|
}
|
|
16
29
|
});
|
|
17
|
-
}
|
|
30
|
+
}
|
|
18
31
|
|
|
19
32
|
exports.getPromisedServerScripts = getPromisedServerScripts;
|
package/dist/promise.d.cts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
+
import { JsonString } from './json.cjs';
|
|
2
|
+
|
|
1
3
|
type Promised<T> = {
|
|
2
4
|
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<R> : T[K];
|
|
3
5
|
};
|
|
6
|
+
type UnwrapJson<T> = T extends JsonString<infer U> ? U : T;
|
|
7
|
+
type PromisedWithJson<T> = {
|
|
8
|
+
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<UnwrapJson<R>> : T[K];
|
|
9
|
+
};
|
|
4
10
|
type PartialScriptType<T> = Partial<Promised<T>>;
|
|
5
|
-
|
|
11
|
+
type PartialScriptTypeWithJson<T> = Partial<PromisedWithJson<T>>;
|
|
12
|
+
type GetPromisedServerScriptsOptions<T, IsJson extends boolean = boolean> = {
|
|
13
|
+
mockupFunctions?: IsJson extends true ? PartialScriptTypeWithJson<T> : PartialScriptType<T>;
|
|
14
|
+
parseJson?: IsJson;
|
|
15
|
+
};
|
|
16
|
+
declare function getPromisedServerScripts<T extends Record<string, (...args: any[]) => any> = Omit<typeof google.script.run, 'withSuccessHandler' | 'withFailureHandler' | 'withUserObject'>>(options: GetPromisedServerScriptsOptions<T, true>): PromisedWithJson<T>;
|
|
17
|
+
declare function getPromisedServerScripts<T extends Record<string, (...args: any[]) => any> = Omit<typeof google.script.run, 'withSuccessHandler' | 'withFailureHandler' | 'withUserObject'>>(options?: GetPromisedServerScriptsOptions<T, false>): Promised<T>;
|
|
6
18
|
|
|
7
19
|
export { getPromisedServerScripts };
|
|
8
|
-
export type { PartialScriptType, Promised };
|
|
20
|
+
export type { GetPromisedServerScriptsOptions, PartialScriptType, PartialScriptTypeWithJson, Promised, PromisedWithJson };
|
package/dist/promise.d.mts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
+
import { JsonString } from './json.mjs';
|
|
2
|
+
|
|
1
3
|
type Promised<T> = {
|
|
2
4
|
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<R> : T[K];
|
|
3
5
|
};
|
|
6
|
+
type UnwrapJson<T> = T extends JsonString<infer U> ? U : T;
|
|
7
|
+
type PromisedWithJson<T> = {
|
|
8
|
+
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<UnwrapJson<R>> : T[K];
|
|
9
|
+
};
|
|
4
10
|
type PartialScriptType<T> = Partial<Promised<T>>;
|
|
5
|
-
|
|
11
|
+
type PartialScriptTypeWithJson<T> = Partial<PromisedWithJson<T>>;
|
|
12
|
+
type GetPromisedServerScriptsOptions<T, IsJson extends boolean = boolean> = {
|
|
13
|
+
mockupFunctions?: IsJson extends true ? PartialScriptTypeWithJson<T> : PartialScriptType<T>;
|
|
14
|
+
parseJson?: IsJson;
|
|
15
|
+
};
|
|
16
|
+
declare function getPromisedServerScripts<T extends Record<string, (...args: any[]) => any> = Omit<typeof google.script.run, 'withSuccessHandler' | 'withFailureHandler' | 'withUserObject'>>(options: GetPromisedServerScriptsOptions<T, true>): PromisedWithJson<T>;
|
|
17
|
+
declare function getPromisedServerScripts<T extends Record<string, (...args: any[]) => any> = Omit<typeof google.script.run, 'withSuccessHandler' | 'withFailureHandler' | 'withUserObject'>>(options?: GetPromisedServerScriptsOptions<T, false>): Promised<T>;
|
|
6
18
|
|
|
7
19
|
export { getPromisedServerScripts };
|
|
8
|
-
export type { PartialScriptType, Promised };
|
|
20
|
+
export type { GetPromisedServerScriptsOptions, PartialScriptType, PartialScriptTypeWithJson, Promised, PromisedWithJson };
|
package/dist/promise.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
+
import { JsonString } from './json.js';
|
|
2
|
+
|
|
1
3
|
type Promised<T> = {
|
|
2
4
|
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<R> : T[K];
|
|
3
5
|
};
|
|
6
|
+
type UnwrapJson<T> = T extends JsonString<infer U> ? U : T;
|
|
7
|
+
type PromisedWithJson<T> = {
|
|
8
|
+
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<UnwrapJson<R>> : T[K];
|
|
9
|
+
};
|
|
4
10
|
type PartialScriptType<T> = Partial<Promised<T>>;
|
|
5
|
-
|
|
11
|
+
type PartialScriptTypeWithJson<T> = Partial<PromisedWithJson<T>>;
|
|
12
|
+
type GetPromisedServerScriptsOptions<T, IsJson extends boolean = boolean> = {
|
|
13
|
+
mockupFunctions?: IsJson extends true ? PartialScriptTypeWithJson<T> : PartialScriptType<T>;
|
|
14
|
+
parseJson?: IsJson;
|
|
15
|
+
};
|
|
16
|
+
declare function getPromisedServerScripts<T extends Record<string, (...args: any[]) => any> = Omit<typeof google.script.run, 'withSuccessHandler' | 'withFailureHandler' | 'withUserObject'>>(options: GetPromisedServerScriptsOptions<T, true>): PromisedWithJson<T>;
|
|
17
|
+
declare function getPromisedServerScripts<T extends Record<string, (...args: any[]) => any> = Omit<typeof google.script.run, 'withSuccessHandler' | 'withFailureHandler' | 'withUserObject'>>(options?: GetPromisedServerScriptsOptions<T, false>): Promised<T>;
|
|
6
18
|
|
|
7
19
|
export { getPromisedServerScripts };
|
|
8
|
-
export type { PartialScriptType, Promised };
|
|
20
|
+
export type { GetPromisedServerScriptsOptions, PartialScriptType, PartialScriptTypeWithJson, Promised, PromisedWithJson };
|
package/dist/promise.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { deserialize } from './json.mjs';
|
|
2
|
+
|
|
3
|
+
function getPromisedServerScripts(options = {}) {
|
|
4
|
+
const { mockupFunctions = {}, parseJson = false } = options;
|
|
2
5
|
return new Proxy(mockupFunctions, {
|
|
3
6
|
get(target, method) {
|
|
4
7
|
if (!("google" in globalThis) || !google?.script?.run) {
|
|
@@ -8,10 +11,20 @@ const getPromisedServerScripts = (mockupFunctions = {}) => {
|
|
|
8
11
|
throw Error(`Method ${method} not found in AppsScript.`);
|
|
9
12
|
}
|
|
10
13
|
return (...args) => new Promise((resolve, reject) => {
|
|
11
|
-
google.script.run.withSuccessHandler(
|
|
14
|
+
google.script.run.withSuccessHandler((res) => {
|
|
15
|
+
if (parseJson && typeof res === "string") {
|
|
16
|
+
try {
|
|
17
|
+
resolve(deserialize(res));
|
|
18
|
+
} catch {
|
|
19
|
+
resolve(res);
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
resolve(res);
|
|
23
|
+
}
|
|
24
|
+
}).withFailureHandler(reject)[method](...args);
|
|
12
25
|
});
|
|
13
26
|
}
|
|
14
27
|
});
|
|
15
|
-
}
|
|
28
|
+
}
|
|
16
29
|
|
|
17
30
|
export { getPromisedServerScripts };
|
|
@@ -72,7 +72,7 @@ const getInterfaceMethodDefinition_ = (name, node) => {
|
|
|
72
72
|
`;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
const cleanType = (t) => t.replace(/import\(
|
|
75
|
+
const cleanType = (t) => t.replace(/import\(".*?"\)\.default\./g, "").replace(/import\(".*?"\)\./g, "");
|
|
76
76
|
const cleanedReturnType = cleanType(returnType);
|
|
77
77
|
const cleanedParameters = parameters.replace(
|
|
78
78
|
/:\s*([^,;)]+)/g,
|
|
@@ -189,8 +189,85 @@ const generateAppsScriptTypes = async ({
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
-
const collectSymbolsFromType = (type, foundSymbols) => {
|
|
192
|
+
const collectSymbolsFromType = (type, foundSymbols, contextNode, depth = 0, isComponent = false) => {
|
|
193
|
+
if (type.isArray()) {
|
|
194
|
+
const elementType = type.getArrayElementType();
|
|
195
|
+
if (elementType) {
|
|
196
|
+
collectSymbolsFromType(
|
|
197
|
+
elementType,
|
|
198
|
+
foundSymbols,
|
|
199
|
+
contextNode,
|
|
200
|
+
depth + 1
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (type.isTuple()) {
|
|
205
|
+
for (const element of type.getTupleElements()) {
|
|
206
|
+
collectSymbolsFromType(element, foundSymbols, contextNode, depth + 1);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
for (const typeArg of type.getTypeArguments()) {
|
|
210
|
+
collectSymbolsFromType(typeArg, foundSymbols, contextNode, depth + 1);
|
|
211
|
+
}
|
|
212
|
+
for (const typeArg of type.getAliasTypeArguments()) {
|
|
213
|
+
collectSymbolsFromType(typeArg, foundSymbols, contextNode, depth + 1);
|
|
214
|
+
}
|
|
215
|
+
if (type.isUnion()) {
|
|
216
|
+
for (const unionType of type.getUnionTypes()) {
|
|
217
|
+
collectSymbolsFromType(
|
|
218
|
+
unionType,
|
|
219
|
+
foundSymbols,
|
|
220
|
+
contextNode,
|
|
221
|
+
depth + 1,
|
|
222
|
+
true
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (type.isIntersection()) {
|
|
227
|
+
for (const intersectionType of type.getIntersectionTypes()) {
|
|
228
|
+
collectSymbolsFromType(
|
|
229
|
+
intersectionType,
|
|
230
|
+
foundSymbols,
|
|
231
|
+
contextNode,
|
|
232
|
+
depth + 1,
|
|
233
|
+
true
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const typeText = type.getText(contextNode);
|
|
238
|
+
const importMatches = typeText.matchAll(
|
|
239
|
+
/import\("(.*?)"\)\.([^<>[\]{}() ,;]+)/g
|
|
240
|
+
);
|
|
241
|
+
for (const match of importMatches) {
|
|
242
|
+
const absolutePath = match[1];
|
|
243
|
+
const typeName = match[2];
|
|
244
|
+
if (typeName === "default" || typeName === "__type") continue;
|
|
245
|
+
let sourceFile = project.getSourceFile(absolutePath) || project.addSourceFileAtPathIfExists(absolutePath);
|
|
246
|
+
if (!sourceFile) {
|
|
247
|
+
const extensions = [".ts", ".d.ts", ".tsx"];
|
|
248
|
+
for (const ext of extensions) {
|
|
249
|
+
sourceFile = project.getSourceFile(absolutePath + ext) || project.addSourceFileAtPathIfExists(absolutePath + ext);
|
|
250
|
+
if (sourceFile) break;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (sourceFile) {
|
|
254
|
+
const exported = sourceFile.getExportedDeclarations().get(typeName);
|
|
255
|
+
let s;
|
|
256
|
+
if (exported && exported.length > 0) {
|
|
257
|
+
s = exported[0].getSymbol();
|
|
258
|
+
} else {
|
|
259
|
+
s = sourceFile.getInterface(typeName)?.getSymbol() || sourceFile.getTypeAlias(typeName)?.getSymbol() || sourceFile.getEnum(typeName)?.getSymbol() || sourceFile.getClass(typeName)?.getSymbol();
|
|
260
|
+
}
|
|
261
|
+
if (s && !foundSymbols.has(s)) {
|
|
262
|
+
foundSymbols.add(s);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
193
266
|
const aliasSymbol = type.getAliasSymbol();
|
|
267
|
+
let symbol = type.getSymbol();
|
|
268
|
+
if (!symbol && !aliasSymbol) {
|
|
269
|
+
symbol = type.getApparentType().getSymbol();
|
|
270
|
+
}
|
|
194
271
|
if (aliasSymbol) {
|
|
195
272
|
if (foundSymbols.has(aliasSymbol)) {
|
|
196
273
|
return;
|
|
@@ -201,14 +278,10 @@ const generateAppsScriptTypes = async ({
|
|
|
201
278
|
const isExternal = sourceFilePath.includes("node_modules") || !sourceFilePath.replace(/\\/g, "/").startsWith(absoluteSrcDir.replace(/\\/g, "/")) && !sourceFilePath.replace(/\\/g, "/").startsWith(path__namespace.join(projectPath, srcDir).replace(/\\/g, "/"));
|
|
202
279
|
if (isExternal) {
|
|
203
280
|
foundSymbols.add(aliasSymbol);
|
|
204
|
-
for (const typeArg of type.getAliasTypeArguments()) {
|
|
205
|
-
collectSymbolsFromType(typeArg, foundSymbols);
|
|
206
|
-
}
|
|
207
281
|
return;
|
|
208
282
|
}
|
|
209
283
|
}
|
|
210
284
|
}
|
|
211
|
-
const symbol = type.getSymbol();
|
|
212
285
|
let shouldTraverseProperties = true;
|
|
213
286
|
if (symbol) {
|
|
214
287
|
if (foundSymbols.has(symbol)) {
|
|
@@ -222,42 +295,68 @@ const generateAppsScriptTypes = async ({
|
|
|
222
295
|
path__namespace.join(projectPath, srcDir).replace(/\\/g, "/")
|
|
223
296
|
);
|
|
224
297
|
if (isExternal) {
|
|
225
|
-
|
|
298
|
+
const isAnonymous = declarations.every(
|
|
299
|
+
(d) => d.getKind() === tsMorph.SyntaxKind.TypeLiteral || d.getKind() === tsMorph.SyntaxKind.ObjectLiteralExpression
|
|
300
|
+
);
|
|
301
|
+
if (!isComponent && !isAnonymous) {
|
|
302
|
+
shouldTraverseProperties = false;
|
|
303
|
+
}
|
|
226
304
|
}
|
|
227
305
|
}
|
|
228
306
|
}
|
|
229
307
|
}
|
|
230
|
-
if (shouldTraverseProperties
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
308
|
+
if (shouldTraverseProperties) {
|
|
309
|
+
const props = /* @__PURE__ */ new Set([
|
|
310
|
+
...type.getProperties(),
|
|
311
|
+
...type.getApparentProperties()
|
|
312
|
+
]);
|
|
313
|
+
for (const prop of props) {
|
|
314
|
+
let propType;
|
|
315
|
+
if (contextNode) {
|
|
316
|
+
try {
|
|
317
|
+
propType = prop.getTypeAtLocation(contextNode);
|
|
318
|
+
} catch {
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (!propType || propType.getText() === "any") {
|
|
322
|
+
const propDecls = prop.getDeclarations();
|
|
323
|
+
if (propDecls.length > 0) {
|
|
324
|
+
propType = propDecls[0].getType();
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if ((!propType || propType.getText() === "any") && prop.getAliasedSymbol()) {
|
|
328
|
+
const aliased = prop.getAliasedSymbol();
|
|
329
|
+
if (aliased) {
|
|
330
|
+
const decl = aliased.getValueDeclaration() || aliased.getDeclarations()[0];
|
|
331
|
+
if (decl) {
|
|
332
|
+
propType = decl.getType();
|
|
244
333
|
}
|
|
245
334
|
}
|
|
246
|
-
collectSymbolsFromType(propDecl.getType(), foundSymbols);
|
|
247
335
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
336
|
+
if (propType) {
|
|
337
|
+
const propDecls = prop.getDeclarations();
|
|
338
|
+
if (propDecls.length > 0) {
|
|
339
|
+
const propDecl = propDecls[0];
|
|
340
|
+
const compilerNode = propDecl.compilerNode;
|
|
341
|
+
if (
|
|
342
|
+
// @ts-expect-error - checking kind directly for perf
|
|
343
|
+
compilerNode.name && // @ts-expect-error - checking kind directly for perf
|
|
344
|
+
compilerNode.name.kind === tsMorph.SyntaxKind.ComputedPropertyName
|
|
345
|
+
) {
|
|
346
|
+
const expression = propDecl.getNameNode().getExpression();
|
|
347
|
+
const s = expression.getSymbol();
|
|
348
|
+
if (s && !foundSymbols.has(s)) {
|
|
349
|
+
foundSymbols.add(s);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
collectSymbolsFromType(
|
|
354
|
+
propType,
|
|
355
|
+
foundSymbols,
|
|
356
|
+
contextNode,
|
|
357
|
+
depth + 1
|
|
358
|
+
);
|
|
359
|
+
}
|
|
261
360
|
}
|
|
262
361
|
}
|
|
263
362
|
};
|
|
@@ -268,14 +367,14 @@ const generateAppsScriptTypes = async ({
|
|
|
268
367
|
const func = decl.getKind() === tsMorph.SyntaxKind.FunctionDeclaration ? decl : decl.getInitializer();
|
|
269
368
|
const parameters = func.getParameters();
|
|
270
369
|
for (const param of parameters) {
|
|
271
|
-
collectSymbolsFromType(param.getType(), functionSignatureSymbols);
|
|
272
|
-
collectSymbolsFromType(param.getType(), symbolsToProcess);
|
|
370
|
+
collectSymbolsFromType(param.getType(), functionSignatureSymbols, func);
|
|
371
|
+
collectSymbolsFromType(param.getType(), symbolsToProcess, func);
|
|
273
372
|
}
|
|
274
373
|
const returnType = func.getReturnType();
|
|
275
|
-
collectSymbolsFromType(returnType, functionSignatureSymbols);
|
|
276
|
-
collectSymbolsFromType(returnType, symbolsToProcess);
|
|
374
|
+
collectSymbolsFromType(returnType, functionSignatureSymbols, func);
|
|
375
|
+
collectSymbolsFromType(returnType, symbolsToProcess, func);
|
|
277
376
|
} else if (decl.getKind() === tsMorph.SyntaxKind.InterfaceDeclaration || decl.getKind() === tsMorph.SyntaxKind.TypeAliasDeclaration) {
|
|
278
|
-
collectSymbolsFromType(decl.getType(), symbolsToProcess);
|
|
377
|
+
collectSymbolsFromType(decl.getType(), symbolsToProcess, decl);
|
|
279
378
|
}
|
|
280
379
|
}
|
|
281
380
|
const importsMap = /* @__PURE__ */ new Map();
|
|
@@ -424,7 +523,9 @@ ${text}`;
|
|
|
424
523
|
if (sortedModulePaths.length > 0) {
|
|
425
524
|
const importStatements = sortedModulePaths.map((modulePath) => {
|
|
426
525
|
const imports = [...importsMap.get(modulePath) ?? []].sort().filter((importName) => {
|
|
427
|
-
const regex = new RegExp(
|
|
526
|
+
const regex = new RegExp(
|
|
527
|
+
`(?:import\\(".*?"\\)\\.|\\b)${importName}\\b`
|
|
528
|
+
);
|
|
428
529
|
return regex.test(bodyContent);
|
|
429
530
|
});
|
|
430
531
|
if (imports.length === 0) {
|
|
@@ -54,7 +54,7 @@ const getInterfaceMethodDefinition_ = (name, node) => {
|
|
|
54
54
|
`;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
const cleanType = (t) => t.replace(/import\(
|
|
57
|
+
const cleanType = (t) => t.replace(/import\(".*?"\)\.default\./g, "").replace(/import\(".*?"\)\./g, "");
|
|
58
58
|
const cleanedReturnType = cleanType(returnType);
|
|
59
59
|
const cleanedParameters = parameters.replace(
|
|
60
60
|
/:\s*([^,;)]+)/g,
|
|
@@ -171,8 +171,85 @@ const generateAppsScriptTypes = async ({
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
const collectSymbolsFromType = (type, foundSymbols) => {
|
|
174
|
+
const collectSymbolsFromType = (type, foundSymbols, contextNode, depth = 0, isComponent = false) => {
|
|
175
|
+
if (type.isArray()) {
|
|
176
|
+
const elementType = type.getArrayElementType();
|
|
177
|
+
if (elementType) {
|
|
178
|
+
collectSymbolsFromType(
|
|
179
|
+
elementType,
|
|
180
|
+
foundSymbols,
|
|
181
|
+
contextNode,
|
|
182
|
+
depth + 1
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (type.isTuple()) {
|
|
187
|
+
for (const element of type.getTupleElements()) {
|
|
188
|
+
collectSymbolsFromType(element, foundSymbols, contextNode, depth + 1);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
for (const typeArg of type.getTypeArguments()) {
|
|
192
|
+
collectSymbolsFromType(typeArg, foundSymbols, contextNode, depth + 1);
|
|
193
|
+
}
|
|
194
|
+
for (const typeArg of type.getAliasTypeArguments()) {
|
|
195
|
+
collectSymbolsFromType(typeArg, foundSymbols, contextNode, depth + 1);
|
|
196
|
+
}
|
|
197
|
+
if (type.isUnion()) {
|
|
198
|
+
for (const unionType of type.getUnionTypes()) {
|
|
199
|
+
collectSymbolsFromType(
|
|
200
|
+
unionType,
|
|
201
|
+
foundSymbols,
|
|
202
|
+
contextNode,
|
|
203
|
+
depth + 1,
|
|
204
|
+
true
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (type.isIntersection()) {
|
|
209
|
+
for (const intersectionType of type.getIntersectionTypes()) {
|
|
210
|
+
collectSymbolsFromType(
|
|
211
|
+
intersectionType,
|
|
212
|
+
foundSymbols,
|
|
213
|
+
contextNode,
|
|
214
|
+
depth + 1,
|
|
215
|
+
true
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const typeText = type.getText(contextNode);
|
|
220
|
+
const importMatches = typeText.matchAll(
|
|
221
|
+
/import\("(.*?)"\)\.([^<>[\]{}() ,;]+)/g
|
|
222
|
+
);
|
|
223
|
+
for (const match of importMatches) {
|
|
224
|
+
const absolutePath = match[1];
|
|
225
|
+
const typeName = match[2];
|
|
226
|
+
if (typeName === "default" || typeName === "__type") continue;
|
|
227
|
+
let sourceFile = project.getSourceFile(absolutePath) || project.addSourceFileAtPathIfExists(absolutePath);
|
|
228
|
+
if (!sourceFile) {
|
|
229
|
+
const extensions = [".ts", ".d.ts", ".tsx"];
|
|
230
|
+
for (const ext of extensions) {
|
|
231
|
+
sourceFile = project.getSourceFile(absolutePath + ext) || project.addSourceFileAtPathIfExists(absolutePath + ext);
|
|
232
|
+
if (sourceFile) break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (sourceFile) {
|
|
236
|
+
const exported = sourceFile.getExportedDeclarations().get(typeName);
|
|
237
|
+
let s;
|
|
238
|
+
if (exported && exported.length > 0) {
|
|
239
|
+
s = exported[0].getSymbol();
|
|
240
|
+
} else {
|
|
241
|
+
s = sourceFile.getInterface(typeName)?.getSymbol() || sourceFile.getTypeAlias(typeName)?.getSymbol() || sourceFile.getEnum(typeName)?.getSymbol() || sourceFile.getClass(typeName)?.getSymbol();
|
|
242
|
+
}
|
|
243
|
+
if (s && !foundSymbols.has(s)) {
|
|
244
|
+
foundSymbols.add(s);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
175
248
|
const aliasSymbol = type.getAliasSymbol();
|
|
249
|
+
let symbol = type.getSymbol();
|
|
250
|
+
if (!symbol && !aliasSymbol) {
|
|
251
|
+
symbol = type.getApparentType().getSymbol();
|
|
252
|
+
}
|
|
176
253
|
if (aliasSymbol) {
|
|
177
254
|
if (foundSymbols.has(aliasSymbol)) {
|
|
178
255
|
return;
|
|
@@ -183,14 +260,10 @@ const generateAppsScriptTypes = async ({
|
|
|
183
260
|
const isExternal = sourceFilePath.includes("node_modules") || !sourceFilePath.replace(/\\/g, "/").startsWith(absoluteSrcDir.replace(/\\/g, "/")) && !sourceFilePath.replace(/\\/g, "/").startsWith(path.join(projectPath, srcDir).replace(/\\/g, "/"));
|
|
184
261
|
if (isExternal) {
|
|
185
262
|
foundSymbols.add(aliasSymbol);
|
|
186
|
-
for (const typeArg of type.getAliasTypeArguments()) {
|
|
187
|
-
collectSymbolsFromType(typeArg, foundSymbols);
|
|
188
|
-
}
|
|
189
263
|
return;
|
|
190
264
|
}
|
|
191
265
|
}
|
|
192
266
|
}
|
|
193
|
-
const symbol = type.getSymbol();
|
|
194
267
|
let shouldTraverseProperties = true;
|
|
195
268
|
if (symbol) {
|
|
196
269
|
if (foundSymbols.has(symbol)) {
|
|
@@ -204,42 +277,68 @@ const generateAppsScriptTypes = async ({
|
|
|
204
277
|
path.join(projectPath, srcDir).replace(/\\/g, "/")
|
|
205
278
|
);
|
|
206
279
|
if (isExternal) {
|
|
207
|
-
|
|
280
|
+
const isAnonymous = declarations.every(
|
|
281
|
+
(d) => d.getKind() === SyntaxKind.TypeLiteral || d.getKind() === SyntaxKind.ObjectLiteralExpression
|
|
282
|
+
);
|
|
283
|
+
if (!isComponent && !isAnonymous) {
|
|
284
|
+
shouldTraverseProperties = false;
|
|
285
|
+
}
|
|
208
286
|
}
|
|
209
287
|
}
|
|
210
288
|
}
|
|
211
289
|
}
|
|
212
|
-
if (shouldTraverseProperties
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
290
|
+
if (shouldTraverseProperties) {
|
|
291
|
+
const props = /* @__PURE__ */ new Set([
|
|
292
|
+
...type.getProperties(),
|
|
293
|
+
...type.getApparentProperties()
|
|
294
|
+
]);
|
|
295
|
+
for (const prop of props) {
|
|
296
|
+
let propType;
|
|
297
|
+
if (contextNode) {
|
|
298
|
+
try {
|
|
299
|
+
propType = prop.getTypeAtLocation(contextNode);
|
|
300
|
+
} catch {
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (!propType || propType.getText() === "any") {
|
|
304
|
+
const propDecls = prop.getDeclarations();
|
|
305
|
+
if (propDecls.length > 0) {
|
|
306
|
+
propType = propDecls[0].getType();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if ((!propType || propType.getText() === "any") && prop.getAliasedSymbol()) {
|
|
310
|
+
const aliased = prop.getAliasedSymbol();
|
|
311
|
+
if (aliased) {
|
|
312
|
+
const decl = aliased.getValueDeclaration() || aliased.getDeclarations()[0];
|
|
313
|
+
if (decl) {
|
|
314
|
+
propType = decl.getType();
|
|
226
315
|
}
|
|
227
316
|
}
|
|
228
|
-
collectSymbolsFromType(propDecl.getType(), foundSymbols);
|
|
229
317
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
318
|
+
if (propType) {
|
|
319
|
+
const propDecls = prop.getDeclarations();
|
|
320
|
+
if (propDecls.length > 0) {
|
|
321
|
+
const propDecl = propDecls[0];
|
|
322
|
+
const compilerNode = propDecl.compilerNode;
|
|
323
|
+
if (
|
|
324
|
+
// @ts-expect-error - checking kind directly for perf
|
|
325
|
+
compilerNode.name && // @ts-expect-error - checking kind directly for perf
|
|
326
|
+
compilerNode.name.kind === SyntaxKind.ComputedPropertyName
|
|
327
|
+
) {
|
|
328
|
+
const expression = propDecl.getNameNode().getExpression();
|
|
329
|
+
const s = expression.getSymbol();
|
|
330
|
+
if (s && !foundSymbols.has(s)) {
|
|
331
|
+
foundSymbols.add(s);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
collectSymbolsFromType(
|
|
336
|
+
propType,
|
|
337
|
+
foundSymbols,
|
|
338
|
+
contextNode,
|
|
339
|
+
depth + 1
|
|
340
|
+
);
|
|
341
|
+
}
|
|
243
342
|
}
|
|
244
343
|
}
|
|
245
344
|
};
|
|
@@ -250,14 +349,14 @@ const generateAppsScriptTypes = async ({
|
|
|
250
349
|
const func = decl.getKind() === SyntaxKind.FunctionDeclaration ? decl : decl.getInitializer();
|
|
251
350
|
const parameters = func.getParameters();
|
|
252
351
|
for (const param of parameters) {
|
|
253
|
-
collectSymbolsFromType(param.getType(), functionSignatureSymbols);
|
|
254
|
-
collectSymbolsFromType(param.getType(), symbolsToProcess);
|
|
352
|
+
collectSymbolsFromType(param.getType(), functionSignatureSymbols, func);
|
|
353
|
+
collectSymbolsFromType(param.getType(), symbolsToProcess, func);
|
|
255
354
|
}
|
|
256
355
|
const returnType = func.getReturnType();
|
|
257
|
-
collectSymbolsFromType(returnType, functionSignatureSymbols);
|
|
258
|
-
collectSymbolsFromType(returnType, symbolsToProcess);
|
|
356
|
+
collectSymbolsFromType(returnType, functionSignatureSymbols, func);
|
|
357
|
+
collectSymbolsFromType(returnType, symbolsToProcess, func);
|
|
259
358
|
} else if (decl.getKind() === SyntaxKind.InterfaceDeclaration || decl.getKind() === SyntaxKind.TypeAliasDeclaration) {
|
|
260
|
-
collectSymbolsFromType(decl.getType(), symbolsToProcess);
|
|
359
|
+
collectSymbolsFromType(decl.getType(), symbolsToProcess, decl);
|
|
261
360
|
}
|
|
262
361
|
}
|
|
263
362
|
const importsMap = /* @__PURE__ */ new Map();
|
|
@@ -406,7 +505,9 @@ ${text}`;
|
|
|
406
505
|
if (sortedModulePaths.length > 0) {
|
|
407
506
|
const importStatements = sortedModulePaths.map((modulePath) => {
|
|
408
507
|
const imports = [...importsMap.get(modulePath) ?? []].sort().filter((importName) => {
|
|
409
|
-
const regex = new RegExp(
|
|
508
|
+
const regex = new RegExp(
|
|
509
|
+
`(?:import\\(".*?"\\)\\.|\\b)${importName}\\b`
|
|
510
|
+
);
|
|
410
511
|
return regex.test(bodyContent);
|
|
411
512
|
});
|
|
412
513
|
if (imports.length === 0) {
|
package/dist/vite.cjs
CHANGED
package/dist/vite.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import { consola } from 'consola';
|
|
3
|
-
import { l as loadConfig, g as generateAppsScriptTypes } from './shared/gasnuki.
|
|
3
|
+
import { l as loadConfig, g as generateAppsScriptTypes } from './shared/gasnuki.DePJgSg9.mjs';
|
|
4
4
|
import 'node:crypto';
|
|
5
5
|
import 'node:fs';
|
|
6
6
|
import 'ts-morph';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ciderjs/gasnuki",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
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",
|
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
"types": "./dist/vite.d.ts",
|
|
23
23
|
"import": "./dist/vite.mjs",
|
|
24
24
|
"require": "./dist/vite.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./json": {
|
|
27
|
+
"types": "./dist/json.d.ts",
|
|
28
|
+
"import": "./dist/json.mjs",
|
|
29
|
+
"require": "./dist/json.cjs"
|
|
25
30
|
}
|
|
26
31
|
},
|
|
27
32
|
"scripts": {
|
|
@@ -45,7 +50,7 @@
|
|
|
45
50
|
"@google/clasp"
|
|
46
51
|
],
|
|
47
52
|
"author": "ciderjs/luth",
|
|
48
|
-
"license": "
|
|
53
|
+
"license": "MIT",
|
|
49
54
|
"repository": {
|
|
50
55
|
"type": "git",
|
|
51
56
|
"url": "git+ssh://git@github.com:luthpg/gasnuki.git"
|
|
@@ -62,12 +67,12 @@
|
|
|
62
67
|
"ts-morph": "^27.0.2"
|
|
63
68
|
},
|
|
64
69
|
"devDependencies": {
|
|
65
|
-
"@biomejs/biome": "^2.3.
|
|
66
|
-
"@types/node": "^25.0.
|
|
70
|
+
"@biomejs/biome": "^2.3.11",
|
|
71
|
+
"@types/node": "^25.0.5",
|
|
67
72
|
"@vitest/coverage-v8": "4.0.16",
|
|
68
73
|
"typescript": "^5.9.3",
|
|
69
74
|
"unbuild": "^3.6.1",
|
|
70
|
-
"vite": "^7.3.
|
|
75
|
+
"vite": "^7.3.1",
|
|
71
76
|
"vitest": "4.0.16"
|
|
72
77
|
},
|
|
73
78
|
"peerDependencies": {
|