@narumitw/pi-sync 0.31.0 → 0.34.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/src/types.ts CHANGED
@@ -1,72 +1,190 @@
1
- export type StorageProfileKind = "r2" | "s3-compatible";
2
- export type TargetSwitchAction = "ask" | "pull" | "switch-only";
3
-
4
- export interface StorageProfileSettings {
5
- kind?: StorageProfileKind;
6
- endpoint?: string;
7
- region?: string;
8
- accessKeyId?: string;
9
- secretAccessKey?: string;
1
+ export type StorageConnectionType = "s3" | "git" | "webdav";
2
+ export type OnSwitchAction = "ask-before-pull" | "pull-after-switch" | "switch-only";
3
+
4
+ export interface S3CredentialsSettings {
5
+ accessKeyId: string;
6
+ secretAccessKey: string;
10
7
  sessionToken?: string;
8
+ [key: string]: unknown;
11
9
  }
12
10
 
13
- export interface SyncTargetSettings {
14
- profile?: string;
15
- bucket?: string;
16
- prefix?: string;
17
- namespace?: string;
18
- autoSync?: boolean;
19
- syncFiles?: unknown;
20
- syncSessions?: boolean;
21
- extraFiles?: unknown;
11
+ export interface WebDavCredentialsSettings {
12
+ username: string;
13
+ password: string;
14
+ [key: string]: unknown;
22
15
  }
23
16
 
24
- export interface PiSyncSettingsV2 {
25
- version: 2;
26
- activeTarget?: string;
27
- targetSwitchAction?: TargetSwitchAction;
28
- profiles?: Record<string, StorageProfileSettings>;
29
- targets?: Record<string, SyncTargetSettings>;
17
+ export interface S3StorageConnectionSettings {
18
+ type: "s3";
19
+ endpoint: string;
20
+ region: string;
21
+ credentials: S3CredentialsSettings;
22
+ remote?: never;
23
+ url?: never;
30
24
  [key: string]: unknown;
31
25
  }
32
26
 
33
- export interface SyncConfig {
34
- endpoint: string;
27
+ export interface GitStorageConnectionSettings {
28
+ type: "git";
29
+ remote: string;
30
+ endpoint?: never;
31
+ region?: never;
32
+ credentials?: never;
33
+ url?: never;
34
+ [key: string]: unknown;
35
+ }
36
+
37
+ export interface WebDavStorageConnectionSettings {
38
+ type: "webdav";
39
+ url: string;
40
+ credentials: WebDavCredentialsSettings;
41
+ endpoint?: never;
42
+ region?: never;
43
+ remote?: never;
44
+ [key: string]: unknown;
45
+ }
46
+
47
+ export type StorageConnectionSettings =
48
+ | S3StorageConnectionSettings
49
+ | GitStorageConnectionSettings
50
+ | WebDavStorageConnectionSettings;
51
+
52
+ export interface CommonSyncSetupStorageSettings {
53
+ connection: string;
54
+ path: string;
55
+ [key: string]: unknown;
56
+ }
57
+
58
+ export interface S3SyncSetupStorageSettings extends CommonSyncSetupStorageSettings {
35
59
  bucket: string;
60
+ branch?: never;
61
+ }
62
+
63
+ export interface GitSyncSetupStorageSettings extends CommonSyncSetupStorageSettings {
64
+ branch: string;
65
+ bucket?: never;
66
+ }
67
+
68
+ export interface WebDavSyncSetupStorageSettings extends CommonSyncSetupStorageSettings {
69
+ bucket?: never;
70
+ branch?: never;
71
+ }
72
+
73
+ export type SyncSetupStorageSettings =
74
+ | S3SyncSetupStorageSettings
75
+ | GitSyncSetupStorageSettings
76
+ | WebDavSyncSetupStorageSettings;
77
+
78
+ export interface SyncPolicySettings {
79
+ include: string[];
80
+ automatic: boolean;
81
+ [key: string]: unknown;
82
+ }
83
+
84
+ export interface SyncSetupSettings {
85
+ storage: SyncSetupStorageSettings;
86
+ sync: SyncPolicySettings;
87
+ [key: string]: unknown;
88
+ }
89
+
90
+ export interface PiSyncSettingsV3 {
91
+ version: 3;
92
+ activeSyncSetup?: string;
93
+ onSwitch: OnSwitchAction;
94
+ storageConnections: Record<string, StorageConnectionSettings>;
95
+ syncSetups: Record<string, SyncSetupSettings>;
96
+ [key: string]: unknown;
97
+ }
98
+
99
+ /** Backend-only resolved S3 connection fields. */
100
+ export interface ResolvedS3StorageProfile {
101
+ kind: "r2" | "s3-compatible";
102
+ endpoint: string;
36
103
  region: string;
37
104
  accessKeyId: string;
38
105
  secretAccessKey: string;
39
106
  sessionToken?: string;
40
- /** Remote namespace retained as `profile` for snapshot/wire compatibility. */
41
- profile: string;
107
+ }
108
+
109
+ /** Backend-only coordinates. `prefix` is the complete reviewed v3 storage path. */
110
+ export interface ResolvedS3Destination {
111
+ bucket: string;
42
112
  prefix: string;
43
- target?: string;
44
- storageProfile?: string;
45
- storageKind?: StorageProfileKind;
46
- autoSync?: boolean;
47
- settingsVersion?: 1 | 2;
48
- syncFiles?: string[];
49
- syncSessions: boolean;
50
- extraFiles: string[];
113
+ /** Snapshot/wire identity; never derived from the local setup name. */
114
+ namespace: string;
115
+ }
116
+
117
+ export interface ResolvedS3Backend {
118
+ type: "s3";
119
+ profile: ResolvedS3StorageProfile;
120
+ destination: ResolvedS3Destination;
121
+ }
122
+
123
+ export interface ResolvedWebDavStorageProfile {
124
+ kind: "webdav";
125
+ url: string;
126
+ username: string;
127
+ password: string;
128
+ }
129
+
130
+ /** Backend-only coordinates. `path` is the complete reviewed v3 storage path. */
131
+ export interface ResolvedWebDavDestination {
132
+ path: string;
133
+ namespace: string;
134
+ }
135
+
136
+ export interface ResolvedWebDavBackend {
137
+ type: "webdav";
138
+ profile: ResolvedWebDavStorageProfile;
139
+ destination: ResolvedWebDavDestination;
140
+ }
141
+
142
+ export interface ResolvedGitStorageProfile {
143
+ kind: "git";
144
+ remote: string;
145
+ }
146
+
147
+ /** Backend-only coordinates. `directory` is the complete reviewed v3 storage path. */
148
+ export interface ResolvedGitDestination {
149
+ branch: string;
150
+ directory: string;
151
+ namespace: string;
152
+ }
153
+
154
+ export interface ResolvedGitBackend {
155
+ type: "git";
156
+ profile: ResolvedGitStorageProfile;
157
+ destination: ResolvedGitDestination;
158
+ }
159
+
160
+ export type ResolvedSyncBackend = ResolvedS3Backend | ResolvedWebDavBackend | ResolvedGitBackend;
161
+
162
+ export interface SyncConfig<Backend extends ResolvedSyncBackend = ResolvedS3Backend> {
163
+ setupName: string;
164
+ connectionName: string;
165
+ storagePath: string;
166
+ /** Snapshot/wire identity retained behind the settings normalization boundary. */
167
+ snapshotIdentity: string;
168
+ include: string[];
169
+ automatic: boolean;
170
+ onSwitch: OnSwitchAction;
171
+ backend: Backend;
51
172
  }
52
173
 
174
+ export type AnySyncConfig = SyncConfig<ResolvedSyncBackend>;
175
+ export type CommonSyncConfig = Omit<AnySyncConfig, "backend">;
176
+
177
+ /** UI projection over a fully validated v3 setup; it is never persisted directly. */
53
178
  export interface PartialConfig {
54
- target?: string;
55
- storageProfile?: string;
56
- storageKind?: StorageProfileKind;
57
- settingsVersion?: 1 | 2;
58
- endpoint?: string;
179
+ setupName: string;
180
+ connectionName: string;
181
+ storageKind: StorageConnectionType;
182
+ storagePath: string;
183
+ include: string[];
184
+ automatic: boolean;
185
+ onSwitch: OnSwitchAction;
59
186
  bucket?: string;
60
- region?: string;
61
- accessKeyId?: string;
62
- secretAccessKey?: string;
63
- sessionToken?: string;
64
- profile?: string;
65
- prefix?: string;
66
- autoSync?: boolean | string;
67
- syncFiles?: unknown;
68
- syncSessions?: boolean | string;
69
- extraFiles?: unknown;
187
+ branch?: string;
70
188
  }
71
189
 
72
190
  export interface SnapshotFile {
@@ -80,6 +198,7 @@ export interface Snapshot {
80
198
  id: string;
81
199
  createdAt: string;
82
200
  machine: string;
201
+ /** Backend-scoped remote identity retained in the snapshot wire format. */
83
202
  profile: string;
84
203
  syncSessions?: boolean;
85
204
  files: SnapshotFile[];
@@ -105,8 +224,11 @@ export interface SyncState {
105
224
  version: number;
106
225
  profile: string;
107
226
  lastAppliedSnapshot?: string;
227
+ lastRemoteRevision?: string;
108
228
  lastRemoteEtag?: string;
109
229
  lastFileHashes: Record<string, string>;
230
+ include?: string[];
231
+ /** Legacy state fields are read only so v3 can detect and replace stale policy state. */
110
232
  syncFiles?: string[];
111
233
  syncSessions?: boolean;
112
234
  extraFiles?: string[];
@@ -126,7 +248,7 @@ export interface CommandOptions {
126
248
  silent: boolean;
127
249
  reload: boolean;
128
250
  auto: boolean;
129
- target?: string;
251
+ setup?: string;
130
252
  signal?: AbortSignal;
131
253
  onCommit?: () => void;
132
254
  args: string[];
@@ -139,9 +261,11 @@ export interface CommandArgumentCompletion {
139
261
  }
140
262
 
141
263
  export interface SnapshotOptions {
264
+ include?: string[];
265
+ sessionDir?: string;
266
+ /** Temporary internal projections while snapshot storage remains wire-compatible. */
142
267
  syncFiles?: string[];
143
268
  syncSessions?: boolean;
144
- sessionDir?: string;
145
269
  extraFiles?: string[];
146
270
  }
147
271