@oh-my-ghaad/core 0.0.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.
- package/dist/index.cjs +460 -0
- package/dist/index.d.cts +187 -0
- package/dist/index.d.ts +187 -0
- package/dist/index.js +430 -0
- package/package.json +23 -0
- package/src/adapter.ts +33 -0
- package/src/collection.ts +31 -0
- package/src/engine.ts +527 -0
- package/src/index.ts +5 -0
- package/src/types.ts +84 -0
- package/src/validators.ts +22 -0
- package/tsconfig.json +7 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
Adapter: () => Adapter,
|
|
23
|
+
Collection: () => Collection,
|
|
24
|
+
Engine: () => Engine,
|
|
25
|
+
appConfigSchema: () => appConfigSchema,
|
|
26
|
+
repoConfigSchema: () => repoConfigSchema
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/validators.ts
|
|
31
|
+
var import_zod = require("zod");
|
|
32
|
+
var appConfigSchema = import_zod.z.object({
|
|
33
|
+
appName: import_zod.z.string(),
|
|
34
|
+
appId: import_zod.z.string(),
|
|
35
|
+
persisted: import_zod.z.boolean().default(true),
|
|
36
|
+
persistedTokenKey: import_zod.z.string().default("token"),
|
|
37
|
+
persistedRepoKey: import_zod.z.string().default("repo"),
|
|
38
|
+
persistedOwnerKey: import_zod.z.string().default("owner"),
|
|
39
|
+
persistedAdapterKey: import_zod.z.string().default("adapter")
|
|
40
|
+
});
|
|
41
|
+
var repoConfigSchema = import_zod.z.object({
|
|
42
|
+
prBasedMutations: import_zod.z.boolean().default(true)
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// src/engine.ts
|
|
46
|
+
var storage = typeof window !== "undefined" ? window.localStorage : null;
|
|
47
|
+
var Engine = class {
|
|
48
|
+
status = "unknown";
|
|
49
|
+
subscriptions = /* @__PURE__ */ new Set();
|
|
50
|
+
adapters = [];
|
|
51
|
+
currentAdapter = null;
|
|
52
|
+
collections = [];
|
|
53
|
+
appConfig;
|
|
54
|
+
repoConfig;
|
|
55
|
+
collectionItems = {};
|
|
56
|
+
constructor({
|
|
57
|
+
appConfig,
|
|
58
|
+
adapters,
|
|
59
|
+
collections
|
|
60
|
+
}) {
|
|
61
|
+
this.appConfig = appConfig;
|
|
62
|
+
this.adapters = adapters;
|
|
63
|
+
this.collections = collections;
|
|
64
|
+
if (this.adapters.length === 1) {
|
|
65
|
+
this.setAdapter(this.adapters[0]);
|
|
66
|
+
}
|
|
67
|
+
if (this.appConfig.persisted) {
|
|
68
|
+
const persistedAdapter = storage?.getItem(
|
|
69
|
+
this.appConfig.persistedAdapterKey || "adapter"
|
|
70
|
+
);
|
|
71
|
+
if (persistedAdapter) {
|
|
72
|
+
const adapter = this.adapters.find(
|
|
73
|
+
(adapter2) => adapter2.name === persistedAdapter
|
|
74
|
+
);
|
|
75
|
+
if (adapter) {
|
|
76
|
+
this.setAdapter(adapter);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const persistedToken = storage?.getItem(
|
|
80
|
+
this.appConfig.persistedTokenKey || "token"
|
|
81
|
+
);
|
|
82
|
+
if (persistedToken) {
|
|
83
|
+
this.setToken(persistedToken);
|
|
84
|
+
}
|
|
85
|
+
const persistedRepo = storage?.getItem(
|
|
86
|
+
this.appConfig.persistedRepoKey || "repo"
|
|
87
|
+
);
|
|
88
|
+
if (persistedRepo) {
|
|
89
|
+
this.getAdapter()?.setRepo(persistedRepo);
|
|
90
|
+
}
|
|
91
|
+
const persistedOwner = storage?.getItem(
|
|
92
|
+
this.appConfig.persistedOwnerKey || "owner"
|
|
93
|
+
);
|
|
94
|
+
if (persistedOwner) {
|
|
95
|
+
this.getAdapter()?.setOwner(persistedOwner);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
setUnauthorizedHandler(handler) {
|
|
100
|
+
this.adapters.forEach((adapter) => {
|
|
101
|
+
adapter.setUnauthorizedHandler(handler);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
subscribe(subscription) {
|
|
105
|
+
this.subscriptions.add(subscription);
|
|
106
|
+
}
|
|
107
|
+
unsubscribe(subscription) {
|
|
108
|
+
this.subscriptions.delete(subscription);
|
|
109
|
+
}
|
|
110
|
+
notifySubscribers() {
|
|
111
|
+
this.subscriptions.forEach(
|
|
112
|
+
(subscription) => subscription(this.collections)
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
setRepoOwner(owner) {
|
|
116
|
+
if (this.appConfig.persisted) {
|
|
117
|
+
storage?.setItem(
|
|
118
|
+
this.appConfig.persistedOwnerKey || "owner",
|
|
119
|
+
owner || ""
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
this.adapters.forEach((adapter) => {
|
|
123
|
+
adapter.setOwner(owner);
|
|
124
|
+
});
|
|
125
|
+
this.notifySubscribers();
|
|
126
|
+
}
|
|
127
|
+
setRepoName(name) {
|
|
128
|
+
if (this.appConfig.persisted) {
|
|
129
|
+
storage?.setItem(this.appConfig.persistedRepoKey || "repo", name || "");
|
|
130
|
+
}
|
|
131
|
+
this.adapters.forEach((adapter) => {
|
|
132
|
+
adapter.setRepo(name);
|
|
133
|
+
});
|
|
134
|
+
this.notifySubscribers();
|
|
135
|
+
}
|
|
136
|
+
getRepoStatus() {
|
|
137
|
+
return this.status;
|
|
138
|
+
}
|
|
139
|
+
getAppConfig() {
|
|
140
|
+
return this.appConfig;
|
|
141
|
+
}
|
|
142
|
+
getRepoConfig() {
|
|
143
|
+
return this.repoConfig;
|
|
144
|
+
}
|
|
145
|
+
async fetchRepoConfig() {
|
|
146
|
+
const rawConfigString = await this.currentAdapter?.fetchFile("config.json").catch(() => {
|
|
147
|
+
console.log(
|
|
148
|
+
"OH My GHaaD: Could not fetch the config file, setting status to empty"
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
if (!rawConfigString) {
|
|
152
|
+
this.status = "empty";
|
|
153
|
+
throw new Error("No config file found");
|
|
154
|
+
}
|
|
155
|
+
const rawConfig = JSON.parse(rawConfigString);
|
|
156
|
+
const parsedConfig = repoConfigSchema.safeParse(rawConfig);
|
|
157
|
+
let partialConfig = parsedConfig.data;
|
|
158
|
+
if (parsedConfig.success) {
|
|
159
|
+
this.status = "valid";
|
|
160
|
+
} else {
|
|
161
|
+
this.status = "invalid";
|
|
162
|
+
}
|
|
163
|
+
this.repoConfig = partialConfig;
|
|
164
|
+
return partialConfig;
|
|
165
|
+
}
|
|
166
|
+
async sync() {
|
|
167
|
+
const [repoConfig, ...fetchedCollectionItems] = await Promise.all([
|
|
168
|
+
this.fetchRepoConfig().catch((error) => {
|
|
169
|
+
return {
|
|
170
|
+
prBasedMutations: false
|
|
171
|
+
};
|
|
172
|
+
}),
|
|
173
|
+
...this.collections.map(async (collection) => ({
|
|
174
|
+
collectionId: collection.id,
|
|
175
|
+
items: await this.fetchCollectionItems(collection.id).catch((error) => {
|
|
176
|
+
return [];
|
|
177
|
+
})
|
|
178
|
+
}))
|
|
179
|
+
]);
|
|
180
|
+
this.notifySubscribers();
|
|
181
|
+
}
|
|
182
|
+
getToken() {
|
|
183
|
+
const currentAdapter = this.getAdapter();
|
|
184
|
+
if (currentAdapter) {
|
|
185
|
+
return currentAdapter.token;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
setToken(token) {
|
|
189
|
+
if (this.appConfig.persisted) {
|
|
190
|
+
storage?.setItem(
|
|
191
|
+
this.appConfig.persistedTokenKey || "token",
|
|
192
|
+
token || ""
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
this.adapters.forEach((adapter) => {
|
|
196
|
+
adapter.setToken(token);
|
|
197
|
+
});
|
|
198
|
+
this.notifySubscribers();
|
|
199
|
+
}
|
|
200
|
+
getAdapters() {
|
|
201
|
+
return this.adapters;
|
|
202
|
+
}
|
|
203
|
+
setAdapter(adapter) {
|
|
204
|
+
if (this.appConfig.persisted) {
|
|
205
|
+
storage?.setItem(
|
|
206
|
+
this.appConfig.persistedAdapterKey || "adapter",
|
|
207
|
+
adapter?.name || ""
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
this.currentAdapter = adapter;
|
|
211
|
+
this.notifySubscribers();
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
getAdapter() {
|
|
215
|
+
return this.currentAdapter;
|
|
216
|
+
}
|
|
217
|
+
getCollections() {
|
|
218
|
+
return this.collections;
|
|
219
|
+
}
|
|
220
|
+
getCollection(collectionLookupValue) {
|
|
221
|
+
return this.collections.find(
|
|
222
|
+
(c) => c.id === collectionLookupValue || Object.values(c.names).includes(collectionLookupValue)
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
getCollectionItems(collectionLookupValue) {
|
|
226
|
+
const collection = this.getCollection(collectionLookupValue);
|
|
227
|
+
if (!collection) {
|
|
228
|
+
throw new Error("Collection not found");
|
|
229
|
+
}
|
|
230
|
+
if (!this.collectionItems[collection.id]) {
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
return this.collectionItems[collection.id];
|
|
234
|
+
}
|
|
235
|
+
async fetchCollectionItems(collectionLookupValue, force = false) {
|
|
236
|
+
if (!this.currentAdapter) {
|
|
237
|
+
throw new Error("No adapter selected");
|
|
238
|
+
}
|
|
239
|
+
const collection = this.getCollection(collectionLookupValue);
|
|
240
|
+
if (!collection) {
|
|
241
|
+
throw new Error("Collection not found");
|
|
242
|
+
}
|
|
243
|
+
const rawCollectionItems = await this.currentAdapter.fetchDirectory(
|
|
244
|
+
`collections/${collection.names.path}`
|
|
245
|
+
);
|
|
246
|
+
const collectionItems = rawCollectionItems?.map((item) => {
|
|
247
|
+
return collection.validator.parse(JSON.parse(item));
|
|
248
|
+
}) || [];
|
|
249
|
+
this.collectionItems[collection.id] = collectionItems;
|
|
250
|
+
this.notifySubscribers();
|
|
251
|
+
return collectionItems;
|
|
252
|
+
}
|
|
253
|
+
async fetchCollectionItem(collectionLookupValue, itemId) {
|
|
254
|
+
const collection = this.getCollection(collectionLookupValue);
|
|
255
|
+
if (!collection) {
|
|
256
|
+
throw new Error("Collection not found");
|
|
257
|
+
}
|
|
258
|
+
const rawCollectionItem = await this.currentAdapter.fetchFile(
|
|
259
|
+
`collections/${collection.names.path}/${itemId}.json`
|
|
260
|
+
);
|
|
261
|
+
if (!rawCollectionItem) {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
const collectionItem = collection.validator.parse(
|
|
265
|
+
JSON.parse(rawCollectionItem)
|
|
266
|
+
);
|
|
267
|
+
return collectionItem;
|
|
268
|
+
}
|
|
269
|
+
async addToCollection(collectionLookupValue, data) {
|
|
270
|
+
if (!this.currentAdapter) {
|
|
271
|
+
throw new Error("No adapter selected");
|
|
272
|
+
}
|
|
273
|
+
const collection = this.getCollection(collectionLookupValue);
|
|
274
|
+
if (!collection) {
|
|
275
|
+
throw new Error("Collection not found");
|
|
276
|
+
}
|
|
277
|
+
const rawNewItem = {
|
|
278
|
+
...data,
|
|
279
|
+
id: collection.idFunction()
|
|
280
|
+
};
|
|
281
|
+
const item = collection.validator.parse(rawNewItem);
|
|
282
|
+
let request;
|
|
283
|
+
request = this.currentAdapter.createFile(
|
|
284
|
+
`collections/${collection.names.path}/${item.id}.json`,
|
|
285
|
+
JSON.stringify(item, null, 2),
|
|
286
|
+
`Add ${collection.names.singular} ${item.id}`
|
|
287
|
+
);
|
|
288
|
+
return request.then(() => {
|
|
289
|
+
this.collectionItems[collection.id] = [
|
|
290
|
+
...this.collectionItems[collection.id] || [],
|
|
291
|
+
item
|
|
292
|
+
];
|
|
293
|
+
return this.collectionItems[collection.id];
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
async removeFromCollection(collectionLookupValue, itemId) {
|
|
297
|
+
if (!this.currentAdapter) {
|
|
298
|
+
throw new Error("No adapter selected");
|
|
299
|
+
}
|
|
300
|
+
const collection = this.getCollection(collectionLookupValue);
|
|
301
|
+
if (!collection) {
|
|
302
|
+
throw new Error("Collection not found");
|
|
303
|
+
}
|
|
304
|
+
let request;
|
|
305
|
+
request = this.currentAdapter.deleteFile(
|
|
306
|
+
`collections/${collection.names.path}/${itemId}.json`,
|
|
307
|
+
`Remove ${collection.names.singular} ${itemId}`
|
|
308
|
+
);
|
|
309
|
+
await request.then(() => {
|
|
310
|
+
this.collectionItems[collection.id] = this.collectionItems[collection.id]?.filter(
|
|
311
|
+
(item) => item.id !== itemId
|
|
312
|
+
) || [];
|
|
313
|
+
return this.collectionItems[collection.id];
|
|
314
|
+
});
|
|
315
|
+
this.notifySubscribers();
|
|
316
|
+
return this.collectionItems[collection.id];
|
|
317
|
+
}
|
|
318
|
+
async updateInCollection(collectionLookupValue, itemId, data) {
|
|
319
|
+
if (!this.currentAdapter) {
|
|
320
|
+
throw new Error("No adapter selected");
|
|
321
|
+
}
|
|
322
|
+
const collection = this.getCollection(collectionLookupValue);
|
|
323
|
+
if (!collection) {
|
|
324
|
+
throw new Error("Collection not found");
|
|
325
|
+
}
|
|
326
|
+
const existingItem = this.collectionItems[collection.id].find(
|
|
327
|
+
(item2) => item2.id === itemId
|
|
328
|
+
);
|
|
329
|
+
if (!existingItem) {
|
|
330
|
+
throw new Error("Item not found");
|
|
331
|
+
}
|
|
332
|
+
const item = collection.validator.parse(data);
|
|
333
|
+
await this.currentAdapter.updateFile(
|
|
334
|
+
`collections/${collection.names.path}/${itemId}.json`,
|
|
335
|
+
JSON.stringify(
|
|
336
|
+
{
|
|
337
|
+
...item,
|
|
338
|
+
id: itemId
|
|
339
|
+
},
|
|
340
|
+
null,
|
|
341
|
+
2
|
|
342
|
+
),
|
|
343
|
+
`Update ${collection.names.singular} ${itemId}`
|
|
344
|
+
);
|
|
345
|
+
this.collectionItems[collection.id] = this.collectionItems[collection.id].map((_item) => {
|
|
346
|
+
if (_item.id === itemId) {
|
|
347
|
+
return item;
|
|
348
|
+
}
|
|
349
|
+
return _item;
|
|
350
|
+
});
|
|
351
|
+
this.notifySubscribers();
|
|
352
|
+
return this.collectionItems[collection.id];
|
|
353
|
+
}
|
|
354
|
+
async initializeCollection(collection) {
|
|
355
|
+
const adapter = this.getAdapter();
|
|
356
|
+
if (!adapter) {
|
|
357
|
+
throw new Error("No adapter selected");
|
|
358
|
+
}
|
|
359
|
+
return adapter.createFile(
|
|
360
|
+
`collections/${collection.names.path}/.gitkeep`,
|
|
361
|
+
"",
|
|
362
|
+
`Create collection: ${collection.names.singular}`
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
async initializeRepoConfig(repoConfig) {
|
|
366
|
+
const adapter = this.getAdapter();
|
|
367
|
+
if (!adapter) {
|
|
368
|
+
throw new Error("No adapter selected");
|
|
369
|
+
}
|
|
370
|
+
return adapter.createFile(
|
|
371
|
+
"config.json",
|
|
372
|
+
JSON.stringify(
|
|
373
|
+
repoConfig ?? {
|
|
374
|
+
prBasedMutations: false
|
|
375
|
+
}
|
|
376
|
+
)
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
async initialize() {
|
|
380
|
+
const repoConfig = this.getRepoConfig();
|
|
381
|
+
await this.initializeRepoConfig(repoConfig);
|
|
382
|
+
for (const collection of this.collections) {
|
|
383
|
+
await this.initializeCollection(collection);
|
|
384
|
+
}
|
|
385
|
+
this.status = "valid";
|
|
386
|
+
this.notifySubscribers();
|
|
387
|
+
}
|
|
388
|
+
// Grouping together props and methods for caching PRs
|
|
389
|
+
lastFetchPullRequestTimestamp = 0;
|
|
390
|
+
cachedPullRequests = [];
|
|
391
|
+
async fetchPullRequests(force = false) {
|
|
392
|
+
const adapter = this.getAdapter();
|
|
393
|
+
if (!adapter) {
|
|
394
|
+
throw new Error("No adapter selected");
|
|
395
|
+
}
|
|
396
|
+
if (force) {
|
|
397
|
+
this.lastFetchPullRequestTimestamp = 0;
|
|
398
|
+
}
|
|
399
|
+
if (this.lastFetchPullRequestTimestamp > Date.now() - 1e3 * 60 * 5) {
|
|
400
|
+
return this.cachedPullRequests;
|
|
401
|
+
} else {
|
|
402
|
+
return adapter.fetchPullRequests();
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
// src/collection.ts
|
|
408
|
+
var Collection = class {
|
|
409
|
+
id;
|
|
410
|
+
idFunction;
|
|
411
|
+
names;
|
|
412
|
+
validator;
|
|
413
|
+
constructor({
|
|
414
|
+
id,
|
|
415
|
+
idFunction,
|
|
416
|
+
names,
|
|
417
|
+
validator
|
|
418
|
+
}) {
|
|
419
|
+
this.id = id;
|
|
420
|
+
this.idFunction = idFunction;
|
|
421
|
+
this.names = names;
|
|
422
|
+
this.validator = validator;
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
// src/adapter.ts
|
|
427
|
+
var Adapter = class {
|
|
428
|
+
clientId;
|
|
429
|
+
redirectUri;
|
|
430
|
+
token;
|
|
431
|
+
owner;
|
|
432
|
+
repo;
|
|
433
|
+
accessManagementUrl;
|
|
434
|
+
unauthorizedHandler = null;
|
|
435
|
+
constructor(props) {
|
|
436
|
+
this.clientId = props.clientId;
|
|
437
|
+
this.redirectUri = props.redirectUri;
|
|
438
|
+
this.accessManagementUrl = props.accessManagementUrl;
|
|
439
|
+
}
|
|
440
|
+
setOwner(owner) {
|
|
441
|
+
this.owner = owner;
|
|
442
|
+
}
|
|
443
|
+
setRepo(repo) {
|
|
444
|
+
this.repo = repo;
|
|
445
|
+
}
|
|
446
|
+
setToken(token) {
|
|
447
|
+
this.token = token;
|
|
448
|
+
}
|
|
449
|
+
setUnauthorizedHandler(handler) {
|
|
450
|
+
this.unauthorizedHandler = handler;
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
454
|
+
0 && (module.exports = {
|
|
455
|
+
Adapter,
|
|
456
|
+
Collection,
|
|
457
|
+
Engine,
|
|
458
|
+
appConfigSchema,
|
|
459
|
+
repoConfigSchema
|
|
460
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { ZodType, z } from 'zod';
|
|
2
|
+
|
|
3
|
+
interface CollectionNames {
|
|
4
|
+
singular: string;
|
|
5
|
+
plural: string;
|
|
6
|
+
path: string;
|
|
7
|
+
}
|
|
8
|
+
declare class Collection {
|
|
9
|
+
id: string;
|
|
10
|
+
idFunction: () => string;
|
|
11
|
+
names: CollectionNames;
|
|
12
|
+
validator: ZodType;
|
|
13
|
+
constructor({ id, idFunction, names, validator, }: {
|
|
14
|
+
id: string;
|
|
15
|
+
idFunction: () => string;
|
|
16
|
+
names: CollectionNames;
|
|
17
|
+
validator: ZodType;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type ValidRepoStatus = "valid" | "pending" | "empty";
|
|
22
|
+
type InvalidRepoStatus = "invalid" | "unknown";
|
|
23
|
+
type RepoStatus = ValidRepoStatus | InvalidRepoStatus;
|
|
24
|
+
type CollectionStatus = "uninitialized" | "valid";
|
|
25
|
+
type CollectionItemStatus = "pending" | "valid" | "invalid";
|
|
26
|
+
type PendingCollectionItemType = "create" | "update" | "delete";
|
|
27
|
+
interface AdapterProps {
|
|
28
|
+
clientId: string;
|
|
29
|
+
redirectUri: string;
|
|
30
|
+
accessManagementUrl: string;
|
|
31
|
+
}
|
|
32
|
+
type Subscription = (collections: Collection[]) => void | Promise<void>;
|
|
33
|
+
interface RepositoryResponse {
|
|
34
|
+
id: string;
|
|
35
|
+
org: string;
|
|
36
|
+
name: string;
|
|
37
|
+
url: string;
|
|
38
|
+
}
|
|
39
|
+
interface PrResponse {
|
|
40
|
+
id: string;
|
|
41
|
+
title: string;
|
|
42
|
+
description: string;
|
|
43
|
+
commitSha?: string;
|
|
44
|
+
createdAt: string;
|
|
45
|
+
}
|
|
46
|
+
type PrRequest = Omit<PrResponse, "id" | "createdAt">;
|
|
47
|
+
interface CommitResponse {
|
|
48
|
+
commitSha: string;
|
|
49
|
+
message: string;
|
|
50
|
+
commitDate: string;
|
|
51
|
+
authorName: string;
|
|
52
|
+
authorImageUrl: string;
|
|
53
|
+
}
|
|
54
|
+
type CommitRequest = Pick<CommitResponse, "message">;
|
|
55
|
+
interface IAdapter extends AdapterProps {
|
|
56
|
+
readonly name: string;
|
|
57
|
+
readonly icon: string;
|
|
58
|
+
readonly primaryColor: string;
|
|
59
|
+
readonly secondaryColor: string;
|
|
60
|
+
readonly oauthUrl: string;
|
|
61
|
+
readonly baseUrl: string;
|
|
62
|
+
fetchRepositories(): Promise<RepositoryResponse[]>;
|
|
63
|
+
fetchFile(filePath: string): Promise<string>;
|
|
64
|
+
fetchFileHistory(filePath: string): Promise<CommitResponse[]>;
|
|
65
|
+
fetchDirectory(directoryPath: string): Promise<string[]>;
|
|
66
|
+
createCommit(commitRequest: CommitRequest): Promise<void>;
|
|
67
|
+
createFile(filePath: string, content: string, message?: string): Promise<void>;
|
|
68
|
+
updateFile(filePath: string, content: string, message?: string): Promise<void>;
|
|
69
|
+
deleteFile(filePath: string, message?: string): Promise<void>;
|
|
70
|
+
fetchPullRequests(): Promise<PrResponse[]>;
|
|
71
|
+
createPullRequest(prRequest: PrRequest): Promise<void>;
|
|
72
|
+
fetchPullRequest(): Promise<PrResponse>;
|
|
73
|
+
updatePullRequest(prRequest: PrRequest): Promise<void>;
|
|
74
|
+
deletePullRequest(id: string): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
interface BaseCollectionItem {
|
|
77
|
+
id: string;
|
|
78
|
+
fileName: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
declare class Adapter implements AdapterProps {
|
|
82
|
+
clientId: string;
|
|
83
|
+
redirectUri: string;
|
|
84
|
+
token: string | null;
|
|
85
|
+
owner: string | null;
|
|
86
|
+
repo: string | null;
|
|
87
|
+
accessManagementUrl: string;
|
|
88
|
+
protected unauthorizedHandler: (() => void | Promise<void>) | null;
|
|
89
|
+
constructor(props: AdapterProps);
|
|
90
|
+
setOwner(owner: string | null): void;
|
|
91
|
+
setRepo(repo: string | null): void;
|
|
92
|
+
setToken(token: string | null): void;
|
|
93
|
+
setUnauthorizedHandler(handler: () => void | Promise<void>): void;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare const appConfigSchema: z.ZodObject<{
|
|
97
|
+
appName: z.ZodString;
|
|
98
|
+
appId: z.ZodString;
|
|
99
|
+
persisted: z.ZodDefault<z.ZodBoolean>;
|
|
100
|
+
persistedTokenKey: z.ZodDefault<z.ZodString>;
|
|
101
|
+
persistedRepoKey: z.ZodDefault<z.ZodString>;
|
|
102
|
+
persistedOwnerKey: z.ZodDefault<z.ZodString>;
|
|
103
|
+
persistedAdapterKey: z.ZodDefault<z.ZodString>;
|
|
104
|
+
}, "strip", z.ZodTypeAny, {
|
|
105
|
+
appName?: string;
|
|
106
|
+
appId?: string;
|
|
107
|
+
persisted?: boolean;
|
|
108
|
+
persistedTokenKey?: string;
|
|
109
|
+
persistedRepoKey?: string;
|
|
110
|
+
persistedOwnerKey?: string;
|
|
111
|
+
persistedAdapterKey?: string;
|
|
112
|
+
}, {
|
|
113
|
+
appName?: string;
|
|
114
|
+
appId?: string;
|
|
115
|
+
persisted?: boolean;
|
|
116
|
+
persistedTokenKey?: string;
|
|
117
|
+
persistedRepoKey?: string;
|
|
118
|
+
persistedOwnerKey?: string;
|
|
119
|
+
persistedAdapterKey?: string;
|
|
120
|
+
}>;
|
|
121
|
+
type AppConfig = z.infer<typeof appConfigSchema>;
|
|
122
|
+
declare const repoConfigSchema: z.ZodObject<{
|
|
123
|
+
prBasedMutations: z.ZodDefault<z.ZodBoolean>;
|
|
124
|
+
}, "strip", z.ZodTypeAny, {
|
|
125
|
+
prBasedMutations?: boolean;
|
|
126
|
+
}, {
|
|
127
|
+
prBasedMutations?: boolean;
|
|
128
|
+
}>;
|
|
129
|
+
type RepoConfig = z.infer<typeof repoConfigSchema> & {
|
|
130
|
+
status: RepoStatus;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
declare class Engine {
|
|
134
|
+
private status;
|
|
135
|
+
private subscriptions;
|
|
136
|
+
private adapters;
|
|
137
|
+
private currentAdapter;
|
|
138
|
+
private collections;
|
|
139
|
+
private appConfig;
|
|
140
|
+
private repoConfig;
|
|
141
|
+
private collectionItems;
|
|
142
|
+
constructor({ appConfig, adapters, collections, }: {
|
|
143
|
+
adapters: (Adapter & IAdapter)[];
|
|
144
|
+
collections: Collection[];
|
|
145
|
+
appConfig: AppConfig;
|
|
146
|
+
});
|
|
147
|
+
setUnauthorizedHandler(handler: () => void | Promise<void>): void;
|
|
148
|
+
subscribe(subscription: Subscription): void;
|
|
149
|
+
unsubscribe(subscription: Subscription): void;
|
|
150
|
+
private notifySubscribers;
|
|
151
|
+
setRepoOwner(owner: string | null): void;
|
|
152
|
+
setRepoName(name: string | null): void;
|
|
153
|
+
getRepoStatus(): RepoStatus;
|
|
154
|
+
getAppConfig(): {
|
|
155
|
+
appName?: string;
|
|
156
|
+
appId?: string;
|
|
157
|
+
persisted?: boolean;
|
|
158
|
+
persistedTokenKey?: string;
|
|
159
|
+
persistedRepoKey?: string;
|
|
160
|
+
persistedOwnerKey?: string;
|
|
161
|
+
persistedAdapterKey?: string;
|
|
162
|
+
};
|
|
163
|
+
getRepoConfig(): RepoConfig;
|
|
164
|
+
fetchRepoConfig(): Promise<RepoConfig>;
|
|
165
|
+
sync(): Promise<void>;
|
|
166
|
+
getToken(): string;
|
|
167
|
+
setToken(token: string | null): void;
|
|
168
|
+
getAdapters(): (Adapter & IAdapter)[];
|
|
169
|
+
setAdapter(adapter: (Adapter & IAdapter) | null): this;
|
|
170
|
+
getAdapter(): Adapter & IAdapter;
|
|
171
|
+
getCollections(): Collection[];
|
|
172
|
+
getCollection<T extends Collection>(collectionLookupValue: T["id"] | T["names"]["singular"] | T["names"]["plural"]): Collection | undefined;
|
|
173
|
+
getCollectionItems<T extends Collection>(collectionLookupValue: T["id"] | T["names"]["singular"] | T["names"]["plural"]): z.infer<T["validator"]>[];
|
|
174
|
+
fetchCollectionItems<T extends Collection>(collectionLookupValue: T["id"] | T["names"]["singular"] | T["names"]["plural"], force?: boolean): Promise<z.infer<T["validator"]>[]>;
|
|
175
|
+
fetchCollectionItem<T extends Collection>(collectionLookupValue: T["id"] | T["names"]["singular"] | T["names"]["plural"], itemId: z.infer<T["validator"]>["id"]): Promise<z.infer<T["validator"]> | null>;
|
|
176
|
+
addToCollection<T extends Collection>(collectionLookupValue: T["id"] | T["names"]["singular"] | T["names"]["plural"], data: z.infer<T["validator"]>): Promise<z.infer<T["validator"]>[]>;
|
|
177
|
+
removeFromCollection<T extends Collection>(collectionLookupValue: T["id"] | T["names"]["singular"] | T["names"]["plural"], itemId: z.infer<T["validator"]>["id"]): Promise<z.infer<T["validator"]>[]>;
|
|
178
|
+
updateInCollection<T extends Collection>(collectionLookupValue: T["id"] | T["names"]["singular"] | T["names"]["plural"], itemId: string, data: z.infer<T["validator"]>): Promise<z.infer<T["validator"]>[]>;
|
|
179
|
+
initializeCollection(collection: Collection): Promise<void>;
|
|
180
|
+
initializeRepoConfig(repoConfig: RepoConfig): Promise<void>;
|
|
181
|
+
initialize(): Promise<void>;
|
|
182
|
+
private lastFetchPullRequestTimestamp;
|
|
183
|
+
private cachedPullRequests;
|
|
184
|
+
fetchPullRequests(force?: boolean): Promise<PrResponse[]>;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export { Adapter, type AdapterProps, type AppConfig, type BaseCollectionItem, Collection, type CollectionItemStatus, type CollectionStatus, type CommitRequest, type CommitResponse, Engine, type IAdapter, type InvalidRepoStatus, type PendingCollectionItemType, type PrRequest, type PrResponse, type RepoConfig, type RepoStatus, type RepositoryResponse, type Subscription, type ValidRepoStatus, appConfigSchema, repoConfigSchema };
|