@ciderjs/gasnuki 0.2.1 → 0.2.3

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 CHANGED
@@ -1,5 +1,10 @@
1
1
  # gasnuki
2
2
 
3
+ [![Test Coverage](https://img.shields.io/badge/test%20coverage-93.43%25-brightgreen)](https://github.com/luthpg/gasnuki)
4
+ [![License](https://img.shields.io/badge/license-ISC-blue.svg)](LICENSE)
5
+ [![npm version](https://img.shields.io/npm/v/@ciderjs/gasnuki.svg)](https://www.npmjs.com/package/@ciderjs/gasnuki)
6
+ [![GitHub issues](https://img.shields.io/github/issues/luthpg/gasnuki.svg)](https://github.com/luthpg/gasnuki/issues)
7
+
3
8
  Google Apps Script クライアントサイドAPIの型定義・ユーティリティ
4
9
 
5
10
  ## 概要
@@ -27,11 +32,22 @@ pnpm add @ciderjs/gasnuki
27
32
  npx @ciderjs/gasnuki
28
33
  ```
29
34
 
35
+ ... または、プロジェクトのnpmスクリプトを `package.json` に追加:
36
+
37
+ ```jsonc
38
+ {
39
+ // others...
40
+ "scripts": {
41
+ "gas": "gasnuki"
42
+ }
43
+ }
44
+ ```
45
+
30
46
  デフォルトでは `types` ディレクトリに型定義ファイルが生成されます。
31
47
 
32
48
  2. 生成されたディレクトリ(デフォルト: `types`)を `tsconfig.json` の `include` に追加してください:
33
49
 
34
- ```json
50
+ ```jsonc
35
51
  {
36
52
  "compilerOptions": {
37
53
  // ... your options ...
@@ -56,7 +72,7 @@ google.script.run
56
72
  .getContent('Sheet1');
57
73
  ```
58
74
 
59
- ## 提供機能
75
+ ## 機能
60
76
 
61
77
  - Google Apps Script クライアントAPIの型定義
62
78
  - サーバーサイド関数の戻り値型をvoidに変換するユーティリティ型
@@ -68,4 +84,4 @@ google.script.run
68
84
 
69
85
  ## ライセンス
70
86
 
71
- MIT
87
+ MIT
package/README.md CHANGED
@@ -1,4 +1,9 @@
1
- # gasnuki
1
+ # @ciderjs/gasnuki
2
+
3
+ [![Test Coverage](https://img.shields.io/badge/test%20coverage-93.43%25-brightgreen)](https://github.com/luthpg/gasnuki)
4
+ [![License](https://img.shields.io/badge/license-ISC-blue.svg)](LICENSE)
5
+ [![npm version](https://img.shields.io/npm/v/@ciderjs/gasnuki.svg)](https://www.npmjs.com/package/@ciderjs/gasnuki)
6
+ [![GitHub issues](https://img.shields.io/github/issues/luthpg/gasnuki.svg)](https://github.com/luthpg/gasnuki/issues)
2
7
 
3
8
  Type definitions and utilities for Google Apps Script client-side API
4
9
 
@@ -26,11 +31,22 @@ pnpm add @ciderjs/gasnuki
26
31
  npx @ciderjs/gasnuki
27
32
  ```
28
33
 
34
+ ... or, add project's npm-script in `package.json`:
35
+
36
+ ```jsonc
37
+ {
38
+ // others...
39
+ "scripts": {
40
+ "gas": "gasnuki"
41
+ }
42
+ }
43
+ ```
44
+
29
45
  This will generate type definition files in the `types` directory by default.
30
46
 
31
47
  2. Make sure the generated directory (default: `types`) is included in your `tsconfig.json`:
32
48
 
33
- ```json
49
+ ```jsonc
34
50
  {
35
51
  "compilerOptions": {
36
52
  // ... your options ...
@@ -43,6 +59,7 @@ This will generate type definition files in the `types` directory by default.
43
59
  ```
44
60
 
45
61
  3. Then, you can use `google` with Type Definitions.
62
+
46
63
  ```ts
47
64
  // Type-safe access to google.script.run
48
65
  // Example: Call the server-side function getContent
@@ -65,4 +82,4 @@ Bug reports and pull requests are welcome. Please use the `issues` or `pull requ
65
82
 
66
83
  ## License
67
84
 
68
- MIT
85
+ MIT
package/dist/cli.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  const path = require('node:path');
5
5
  const commander = require('commander');
6
- const index = require('./shared/gasnuki.D0Jm2dZh.cjs');
6
+ const index = require('./shared/gasnuki.s61ETQvI.cjs');
7
7
  require('chokidar');
8
8
  require('consola');
9
9
  require('node:fs');
@@ -24,7 +24,7 @@ function _interopNamespaceCompat(e) {
24
24
 
25
25
  const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
26
26
 
27
- const version = "0.2.1";
27
+ const version = "0.2.3";
28
28
 
29
29
  const parseArgs = async (command) => {
30
30
  const cliOpts = command.opts();
package/dist/cli.mjs CHANGED
@@ -1,14 +1,14 @@
1
1
  #! /usr/bin/env node
2
2
  import * as path from 'node:path';
3
3
  import { Command } from 'commander';
4
- import { l as loadConfig, g as generateTypes } from './shared/gasnuki.DjqKPcXI.mjs';
4
+ import { l as loadConfig, g as generateTypes } from './shared/gasnuki.y-_vxcPh.mjs';
5
5
  import 'chokidar';
6
6
  import 'consola';
7
7
  import 'node:fs';
8
8
  import 'ts-morph';
9
9
  import 'jiti';
10
10
 
11
- const version = "0.2.1";
11
+ const version = "0.2.3";
12
12
 
13
13
  const parseArgs = async (command) => {
14
14
  const cliOpts = command.opts();
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  require('node:path');
4
4
  require('chokidar');
5
5
  require('consola');
6
- const index = require('./shared/gasnuki.D0Jm2dZh.cjs');
6
+ const index = require('./shared/gasnuki.s61ETQvI.cjs');
7
7
  require('node:fs');
8
8
  require('ts-morph');
9
9
  require('jiti');
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import 'node:path';
2
2
  import 'chokidar';
3
3
  import 'consola';
4
- export { d as defineConfig, g as generateTypes } from './shared/gasnuki.DjqKPcXI.mjs';
4
+ export { d as defineConfig, g as generateTypes } from './shared/gasnuki.y-_vxcPh.mjs';
5
5
  import 'node:fs';
6
6
  import 'ts-morph';
7
7
  import 'jiti';
package/dist/promise.cjs CHANGED
@@ -1,23 +1,19 @@
1
1
  'use strict';
2
2
 
3
3
  const getPromisedServerScripts = (mockupFunctions = {}) => {
4
- const serverScripts = {
5
- ...mockupFunctions
6
- };
7
- if (!("google" in globalThis)) {
8
- return serverScripts;
9
- }
10
- for (const method of Object.keys(google.script.run)) {
11
- if (["withSuccessHandler", "withFailureHandler", "withUserObject"].includes(
12
- String(method)
13
- )) {
14
- continue;
4
+ return new Proxy(mockupFunctions, {
5
+ get(target, method) {
6
+ if (!("google" in globalThis) || !google?.script?.run) {
7
+ return target[method];
8
+ }
9
+ if (!(method in google.script.run)) {
10
+ throw Error(`Method ${method} not found in AppsScript.`);
11
+ }
12
+ return (...args) => new Promise((resolve, reject) => {
13
+ google.script.run.withSuccessHandler(resolve).withFailureHandler(reject)[method](...args);
14
+ });
15
15
  }
16
- serverScripts[method] = (...args) => new Promise((resolve, reject) => {
17
- google.script.run.withSuccessHandler(resolve).withFailureHandler(reject)[method](...args);
18
- });
19
- }
20
- return serverScripts;
16
+ });
21
17
  };
22
18
 
23
19
  exports.getPromisedServerScripts = getPromisedServerScripts;
package/dist/promise.mjs CHANGED
@@ -1,21 +1,17 @@
1
1
  const getPromisedServerScripts = (mockupFunctions = {}) => {
2
- const serverScripts = {
3
- ...mockupFunctions
4
- };
5
- if (!("google" in globalThis)) {
6
- return serverScripts;
7
- }
8
- for (const method of Object.keys(google.script.run)) {
9
- if (["withSuccessHandler", "withFailureHandler", "withUserObject"].includes(
10
- String(method)
11
- )) {
12
- continue;
2
+ return new Proxy(mockupFunctions, {
3
+ get(target, method) {
4
+ if (!("google" in globalThis) || !google?.script?.run) {
5
+ return target[method];
6
+ }
7
+ if (!(method in google.script.run)) {
8
+ throw Error(`Method ${method} not found in AppsScript.`);
9
+ }
10
+ return (...args) => new Promise((resolve, reject) => {
11
+ google.script.run.withSuccessHandler(resolve).withFailureHandler(reject)[method](...args);
12
+ });
13
13
  }
14
- serverScripts[method] = (...args) => new Promise((resolve, reject) => {
15
- google.script.run.withSuccessHandler(resolve).withFailureHandler(reject)[method](...args);
16
- });
17
- }
18
- return serverScripts;
14
+ });
19
15
  };
20
16
 
21
17
  export { getPromisedServerScripts };
@@ -99,9 +99,17 @@ const generateAppsScriptTypes = async ({
99
99
  consola.consola.info(`Found ${sourceFiles.length} source file(s).`);
100
100
  for (const sourceFile of sourceFiles) {
101
101
  for (const iface of sourceFile.getInterfaces()) {
102
+ const name = iface?.getName?.();
103
+ if (name == null || name.endsWith("_")) {
104
+ continue;
105
+ }
102
106
  globalTypeDefinitions.push(iface.getText());
103
107
  }
104
108
  for (const typeAlias of sourceFile.getTypeAliases()) {
109
+ const name = typeAlias?.getName?.();
110
+ if (name == null || name.endsWith("_")) {
111
+ continue;
112
+ }
105
113
  globalTypeDefinitions.push(typeAlias.getText());
106
114
  }
107
115
  for (const statement of sourceFile.getStatements()) {
@@ -81,9 +81,17 @@ const generateAppsScriptTypes = async ({
81
81
  consola.info(`Found ${sourceFiles.length} source file(s).`);
82
82
  for (const sourceFile of sourceFiles) {
83
83
  for (const iface of sourceFile.getInterfaces()) {
84
+ const name = iface?.getName?.();
85
+ if (name == null || name.endsWith("_")) {
86
+ continue;
87
+ }
84
88
  globalTypeDefinitions.push(iface.getText());
85
89
  }
86
90
  for (const typeAlias of sourceFile.getTypeAliases()) {
91
+ const name = typeAlias?.getName?.();
92
+ if (name == null || name.endsWith("_")) {
93
+ continue;
94
+ }
87
95
  globalTypeDefinitions.push(typeAlias.getText());
88
96
  }
89
97
  for (const statement of sourceFile.getStatements()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciderjs/gasnuki",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
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",
@@ -20,13 +20,16 @@
20
20
  }
21
21
  },
22
22
  "scripts": {
23
- "prebuild": "jiti bin/generate.ts",
23
+ "generate": "jiti .bin/generate.ts",
24
24
  "dev": "pnpm prebuild && jiti src/cli.ts -p playground/react -s src/server",
25
25
  "start": "node dist/cli.mjs -p playground/react -s src/server",
26
26
  "check": "biome check --write",
27
27
  "build": "unbuild",
28
28
  "test": "vitest run",
29
- "prepare": "pnpm run check && pnpm run build",
29
+ "test:coverage": "vitest run --coverage",
30
+ "update-coverage-badge": "jiti scripts/update-coverage-badge.ts README.md README.ja.md",
31
+ "test:coverage:update": "pnpm test:coverage && pnpm update-coverage-badge",
32
+ "prepare": "pnpm run generate && pnpm run check && pnpm run test:coverage:update && pnpm run build",
30
33
  "pg:react": "pnpm -C playground/react",
31
34
  "pg:vue": "pnpm -C playground/vue3"
32
35
  },
@@ -52,6 +55,7 @@
52
55
  "devDependencies": {
53
56
  "@biomejs/biome": "^1.9.4",
54
57
  "@types/node": "^22.15.29",
58
+ "@vitest/coverage-v8": "3.2.1",
55
59
  "typescript": "^5.8.3",
56
60
  "unbuild": "^3.5.0",
57
61
  "vitest": "^3.2.1"
package/bin/generate.ts DELETED
@@ -1,11 +0,0 @@
1
- import * as fs from 'node:fs/promises';
2
-
3
- (async () => {
4
- const file = await fs.readFile('./bin/typedef/clientside.d.ts', 'utf-8');
5
- await fs.writeFile(
6
- './src/modules/clientside.json',
7
- JSON.stringify({
8
- text: file,
9
- }),
10
- );
11
- })();
@@ -1,53 +0,0 @@
1
- export 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
- }