@rex0220/formula-authoring-tools 0.1.0 → 0.2.1

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,126 @@
1
+ import { ConnectionError, type ConnectionSet, type Env, type ProfileDef } from "./connections.ts";
2
+ export declare const KINTONE_ROOT = "kintone";
3
+ export declare const INBOX = "inbox";
4
+ /** 1.x の作業フォルダーの環境の定義(2.0.0 から読まない。あれば移行を求めて止まる) */
5
+ export declare const LEGACY_WORKSPACE_FILE = "environments.json";
6
+ /** アプリのフォルダーの印(15.5) */
7
+ export declare const APP_MARKER = ".formula-app.json";
8
+ /** 設定画面のダウンロードのファイル名の接頭辞(kit の exportFileName。計算式プラグインの src/config/main.ts の exportPrefix) */
9
+ export declare const SNAPSHOT_PREFIX = "rex0220-formula";
10
+ export declare const SNAPSHOT_RE: RegExp;
11
+ export declare const EDIT_RE: RegExp;
12
+ export declare class WorkspaceError extends Error {
13
+ }
14
+ /**
15
+ * 動く形(15.4、15.11。r3 MAJOR 7): single(1 接続の形。CLI だけ)、profiles(接続のファイルがある)、not-configured(MCP で接続のファイルが無い)、
16
+ * legacy-blocked(接続のファイルが無く environments.json がある)。どの形でも settings/ などのローカルの操作は動く。kintone/** を読む・書くのは profiles だけ
17
+ */
18
+ export type WorkspaceMode = {
19
+ kind: "single";
20
+ } | {
21
+ kind: "profiles";
22
+ connections: ProfilesContext;
23
+ } | {
24
+ kind: "not-configured";
25
+ } | {
26
+ kind: "legacy-blocked";
27
+ };
28
+ /** profile の形の文脈: 呼び出しの初めに読んだ接続(秘密を含む。外に出さない)と、確定の前に読み直す関数 */
29
+ export interface ProfilesContext {
30
+ set: ConnectionSet;
31
+ reload: () => ConnectionSet;
32
+ }
33
+ export interface ModeOptions {
34
+ /** 接続のファイルの絶対パス(設定されていなければ undefined、設定されていて空なら "") */
35
+ configFile: string | undefined;
36
+ /** そのプロセスが知っている作業フォルダー(この中の接続のファイルは使わない) */
37
+ workspaceRoots: readonly string[];
38
+ /** env: と passwordEnv を引く環境変数 */
39
+ env: Env;
40
+ /** 接続のファイルが無いときの形: CLI は single(.env の 1 接続)、MCP は not-configured */
41
+ surface: "cli" | "mcp";
42
+ }
43
+ /** 1.x の environments.json があるか(リンク切れの symlink も「ある」) */
44
+ export declare function hasLegacyConfig(cwd: string): boolean;
45
+ /** 移行で止まっているときの誤り(kintone を使う操作と kintone/** の操作が投げる) */
46
+ export declare function legacyBlockedError(): ConnectionError;
47
+ /**
48
+ * 動く形を決める(15.4 の表)。接続のファイルが設定されていれば読む(空・読めない・形が違うのは誤り。1 接続の形に戻らない)。
49
+ * 設定されていなければ、environments.json があれば legacy-blocked、無ければ CLI は single、MCP は not-configured
50
+ */
51
+ export declare function modeOf(cwd: string, opt: ModeOptions): WorkspaceMode;
52
+ /** kintone を使う操作・アプリのフォルダーの操作の前に: profile の形でなければ止める(未設定・移行で止まっている・1 接続の形の理由で) */
53
+ export declare function requireProfiles(mode: WorkspaceMode, what: string): ProfilesContext;
54
+ /** アプリのフォルダーの名前(番号-アプリ名。名前が使えなければ番号だけ) */
55
+ export declare function folderNameOf(appId: number, appName: string): string;
56
+ export declare function profileDirOf(cwd: string, profile: string): string;
57
+ /**
58
+ * フォルダー・ファイルの実体(symlink を解いたもの)が作業フォルダーの中か。外なら一覧を作らず・読まずに PathError。リンク切れ・ループも PathError
59
+ * (kintone/<profile> や inbox が外への symlink のとき、外のファイルの名前を出さない。B1 の Codex レビュー BLOCKER 1)
60
+ */
61
+ export declare function assertInsideWorkspace(cwd: string, p: string): void;
62
+ /** 今あるアプリのフォルダー(番号で探す。無ければ null。同じ番号が 2 つあれば止まる)。kintone/ と profile のフォルダーの実体が作業フォルダーの中のときだけ一覧する */
63
+ export declare function findAppDir(cwd: string, profile: string, appId: number): string | null;
64
+ /** アプリのフォルダー(あればそれ、無ければ 番号-アプリ名 で作る場所。作るのは ensureAppFolder) */
65
+ export declare function appDirFor(cwd: string, profile: string, appId: number, appName: string): string;
66
+ /** ファイルが kintone/<profile>/<番号>-…/ の中(records/ などの下を含む)なら、そのフォルダーと profile と番号 */
67
+ export declare function appFolderOfFile(cwd: string, file: string): {
68
+ dir: string;
69
+ profile: string;
70
+ appId: number;
71
+ } | null;
72
+ /** ダウンロードと同じ名前(kit の exportFileName と同じ。日時はこの PC の時刻) */
73
+ export declare function snapshotNameOf(appId: number, now?: Date): string;
74
+ export declare function editNameOf(snapshotFile: string): string;
75
+ export interface AppMark {
76
+ schemaVersion: 1;
77
+ profile: string;
78
+ origin: string;
79
+ guestSpaceId: number | null;
80
+ appId: number;
81
+ }
82
+ export declare function markOf(def: ProfileDef, appId: number): AppMark;
83
+ export type AppMarkState = {
84
+ state: "missing";
85
+ } | {
86
+ state: "invalid";
87
+ } | {
88
+ state: "ok";
89
+ mark: AppMark;
90
+ };
91
+ /** 印を読む(無い・壊れている・読めた) */
92
+ export declare function readAppMark(dir: string): AppMarkState;
93
+ /** アプリのフォルダーの印が、今の接続のこのアプリのものか(無い・壊れている・違うは ConnectionError。conflict) */
94
+ export declare function assertAppMark(dir: string, def: ProfileDef, appId: number): void;
95
+ /**
96
+ * アプリのフォルダーを使う(fields / pull / take だけが呼ぶ。15.5)。あれば印を確かめる。無ければ、同じ親の一時フォルダー(. で始まる名前)に印を置いてから
97
+ * 最後の名前に付け替える(途中で止まっても印の無いフォルダーを残さない。r3 MINOR 1)。付け替えの先が既にあれば(同時に作った)、その印を確かめて使う。
98
+ * dir は appDirFor の値(書ける場所と許可は呼ぶ側が先に確かめる)
99
+ */
100
+ export declare function ensureAppFolder(dir: string, def: ProfileDef, appId: number): void;
101
+ /**
102
+ * kintone/** の中のファイル・フォルダーを通常の操作で読む・一覧する前に(15.5、r3 MAJOR 3): profile の形で、フォルダーの profile が接続のファイルにあり、
103
+ * 印が今の接続のこのアプリのものか。kintone/ の外なら何もしない。profile が無い = denied(PermissionError)、印 = conflict(ConnectionError)
104
+ */
105
+ export declare function assertUsableInKintone(cwd: string, file: string, mode: WorkspaceMode): void;
106
+ export interface AppFolderList {
107
+ dir: string;
108
+ hasFields: boolean;
109
+ /** ダウンロードと pull(新しい順) */
110
+ snapshots: string[];
111
+ /** 直したもの(新しい順) */
112
+ edits: string[];
113
+ /** AI が作った設定など、その他の json(. で始まる印などは出さない) */
114
+ others: string[];
115
+ records: string[];
116
+ }
117
+ /** アプリのフォルダーの一覧。cwd を渡すと、フォルダーと records の実体が作業フォルダーの中か確かめてから一覧する */
118
+ export declare function listAppFolder(dir: string, cwd?: string): AppFolderList;
119
+ /** profile のフォルダーの中のアプリのフォルダーと印の状態(診断と files の一覧。中身は返さない。15.5) */
120
+ export declare function appFoldersOf(cwd: string, def: ProfileDef): Array<{
121
+ name: string;
122
+ appId: number | null;
123
+ mark: "ok" | "missing" | "invalid" | "conflict";
124
+ }>;
125
+ /** kintone/ の下の profile のフォルダーのうち、接続のファイルに無いもの(使われていないフォルダー。診断で名前だけ示す) */
126
+ export declare function unusedProfileDirs(cwd: string, set: ConnectionSet): string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rex0220/formula-authoring-tools",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "rex0220 計算式プラグイン(kintone)の設定を AI で作るための CLI。利用者のプラグインの zip から authoring API と計算式エンジンを読んで Node で動く",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -34,6 +34,7 @@
34
34
  "prepack": "node scripts/vendor.mjs && node scripts/build.mjs",
35
35
  "gen-docs": "node scripts/gen-docs.mjs"
36
36
  },
37
+ "publishConfig": { "access": "public" },
37
38
  "homepage": "https://github.com/rex0220/formula-authoring#readme",
38
39
  "repository": {
39
40
  "type": "git",