supatool 0.1.23 → 0.3.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.
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateTypesFromModel = generateTypesFromModel;
7
+ // TypeScript型定義自動生成(最小雛形)
8
+ // 日本語コメント
9
+ const path_1 = __importDefault(require("path"));
10
+ const fs_1 = __importDefault(require("fs"));
11
+ /**
12
+ * モデルからTypeScript型定義ファイルを生成
13
+ * @param model モデルオブジェクト
14
+ * @param outPath 出力先パス
15
+ */
16
+ function generateTypesFromModel(model, outPath) {
17
+ const dir = path_1.default.dirname(outPath);
18
+ if (!fs_1.default.existsSync(dir)) {
19
+ fs_1.default.mkdirSync(dir, { recursive: true });
20
+ }
21
+ let code = '// 自動生成: モデル型定義\n\n';
22
+ for (const m of model.models) {
23
+ const tables = m.tables || {};
24
+ for (const [tableName, table] of Object.entries(tables)) {
25
+ const t = table;
26
+ if (t.skipCreate)
27
+ continue;
28
+ code += `export type ${tableName} = {\n`;
29
+ for (const [colName, col] of Object.entries(t.fields || {})) {
30
+ const c = col;
31
+ code += ` ${colName}: ${toTsType(c.type)};\n`;
32
+ }
33
+ code += `}\n\n`;
34
+ }
35
+ }
36
+ fs_1.default.writeFileSync(outPath, code);
37
+ }
38
+ // 型変換ユーティリティ
39
+ function toTsType(type) {
40
+ if (!type)
41
+ return 'any';
42
+ switch (type) {
43
+ case 'uuid':
44
+ case 'text':
45
+ case 'timestamp':
46
+ return 'string';
47
+ case 'int':
48
+ case 'integer':
49
+ return 'number';
50
+ case 'boolean':
51
+ return 'boolean';
52
+ default:
53
+ return 'any';
54
+ }
55
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseModelYaml = parseModelYaml;
7
+ // モデルYAMLパース用(最小雛形)
8
+ // 日本語コメント
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const js_yaml_1 = __importDefault(require("js-yaml"));
11
+ /**
12
+ * モデルYAMLファイルをパースしてJSオブジェクトを返す
13
+ * @param filePath YAMLファイルパス
14
+ */
15
+ function parseModelYaml(filePath) {
16
+ const file = fs_1.default.readFileSync(filePath, 'utf8');
17
+ return js_yaml_1.default.load(file);
18
+ }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.loadConfig = loadConfig;
37
+ exports.resolveConfig = resolveConfig;
38
+ exports.createConfigTemplate = createConfigTemplate;
39
+ const fs = __importStar(require("fs"));
40
+ const path = __importStar(require("path"));
41
+ const dotenv_1 = require("dotenv");
42
+ // プロジェクト内の.env/.env.localファイルを読み込み
43
+ const envPath = path.join(process.cwd(), '.env');
44
+ const envLocalPath = path.join(process.cwd(), '.env.local');
45
+ // .env.local が優先される
46
+ if (fs.existsSync(envLocalPath)) {
47
+ (0, dotenv_1.config)({ path: envLocalPath });
48
+ }
49
+ else if (fs.existsSync(envPath)) {
50
+ (0, dotenv_1.config)({ path: envPath });
51
+ }
52
+ /**
53
+ * 設定ファイルから設定を読み込み
54
+ */
55
+ function loadConfig(configPath) {
56
+ const defaultConfigPath = path.join(process.cwd(), 'supatool.config.json');
57
+ const finalConfigPath = configPath || defaultConfigPath;
58
+ if (fs.existsSync(finalConfigPath)) {
59
+ try {
60
+ const configData = fs.readFileSync(finalConfigPath, 'utf-8');
61
+ return JSON.parse(configData);
62
+ }
63
+ catch (error) {
64
+ console.warn(`設定ファイル読み込みエラー: ${finalConfigPath}`);
65
+ return {};
66
+ }
67
+ }
68
+ return {};
69
+ }
70
+ /**
71
+ * 環境変数と設定ファイルから最終設定を取得
72
+ */
73
+ function resolveConfig(options, configPath) {
74
+ const fileConfig = loadConfig(configPath);
75
+ return {
76
+ connectionString: options.connectionString ||
77
+ process.env.SUPABASE_CONNECTION_STRING ||
78
+ process.env.DATABASE_URL ||
79
+ fileConfig.connectionString,
80
+ schemaDir: options.schemaDir || fileConfig.schemaDir || './supabase/schemas',
81
+ tablePattern: options.tablePattern || fileConfig.tablePattern || '*'
82
+ };
83
+ }
84
+ /**
85
+ * 設定ファイル雛形を生成
86
+ */
87
+ function createConfigTemplate(outputPath) {
88
+ const template = {
89
+ connectionString: "postgresql://user:password@host:port/database",
90
+ schemaDir: "./supabase/schemas",
91
+ tablePattern: "*",
92
+ "_comment": "接続文字列は .env または .env.local ファイルでSUPABASE_CONNECTION_STRINGまたはDATABASE_URLで設定することを推奨"
93
+ };
94
+ fs.writeFileSync(outputPath, JSON.stringify(template, null, 2), 'utf-8');
95
+ console.log(`設定ファイル雛形を生成: ${outputPath}`);
96
+ console.log('⚠️ 設定ファイルを.gitignoreに追加することを忘れずに!');
97
+ console.log('💡 接続文字列は .env または .env.local ファイルで管理してください');
98
+ }