@cascateer/database 0.0.5 → 0.0.7
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/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/table.ts +25 -21
- package/src/types.ts +6 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/table.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { defaults } from "./defaults";
|
|
|
21
21
|
import { File } from "./file";
|
|
22
22
|
import { reduceActions } from "./observables/reduceActions";
|
|
23
23
|
import {
|
|
24
|
+
FileTable,
|
|
24
25
|
FileTableRecord,
|
|
25
26
|
TableAction,
|
|
26
27
|
TableActionCreator,
|
|
@@ -266,20 +267,22 @@ export const createTable = memoize(
|
|
|
266
267
|
constructor() {
|
|
267
268
|
super(id, key, records, TableInstance.actions);
|
|
268
269
|
|
|
269
|
-
TableInstance.actionsSubscription ??=
|
|
270
|
-
.
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
270
|
+
TableInstance.actionsSubscription ??=
|
|
271
|
+
(console.log(id, key),
|
|
272
|
+
TableInstance.actions
|
|
273
|
+
.pipe(
|
|
274
|
+
reduceActions(this.applyActions, this.readActions),
|
|
275
|
+
mergeMap(async (action) => {
|
|
276
|
+
const path = resolve(this.path, `${action.id}.json`);
|
|
274
277
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
+
if (!existsSync(path)) {
|
|
279
|
+
await writeFile(path, JSON.stringify(action));
|
|
280
|
+
}
|
|
278
281
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
282
|
+
return action;
|
|
283
|
+
}),
|
|
284
|
+
)
|
|
285
|
+
.subscribe());
|
|
283
286
|
}
|
|
284
287
|
},
|
|
285
288
|
nthArg(0),
|
|
@@ -287,13 +290,14 @@ export const createTable = memoize(
|
|
|
287
290
|
|
|
288
291
|
export const createFileTable = (
|
|
289
292
|
id: string,
|
|
290
|
-
key: "url",
|
|
291
293
|
records: TableRecordCreator<FileTableRecord, "url">,
|
|
292
|
-
) =>
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
294
|
+
) =>
|
|
295
|
+
class
|
|
296
|
+
extends createTable<FileTableRecord, "url">(id, "url", records)
|
|
297
|
+
implements FileTable
|
|
298
|
+
{
|
|
299
|
+
toFile = (url: string, spinner?: Ora) =>
|
|
300
|
+
this.accessSome([url], spinner).then(([{ name, checksum }]) =>
|
|
301
|
+
new File(name).verified(checksum),
|
|
302
|
+
);
|
|
303
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { MaybePromise } from "@cascateer/lib";
|
|
|
2
2
|
import { LazyPromise } from "@cascateer/lib/promises";
|
|
3
3
|
import { Function1 } from "lodash";
|
|
4
4
|
import { Ora } from "ora";
|
|
5
|
+
import { File } from "./file";
|
|
6
|
+
import { Table } from "./table";
|
|
5
7
|
|
|
6
8
|
interface BaseTableAction<Type> {
|
|
7
9
|
id: string;
|
|
@@ -72,3 +74,7 @@ export interface FileTableRecord {
|
|
|
72
74
|
name: string;
|
|
73
75
|
checksum: string;
|
|
74
76
|
}
|
|
77
|
+
|
|
78
|
+
export interface FileTable extends Table<FileTableRecord, "url"> {
|
|
79
|
+
toFile: (url: string, spinner?: Ora) => Promise<File>;
|
|
80
|
+
}
|