sliftutils 0.35.0 → 0.37.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/builders/webBuild.ts +8 -1
- package/index.d.ts +26 -25
- package/package.json +1 -1
- package/spec.txt +3 -0
- package/storage/CBORStorage.d.ts +16 -0
- package/storage/CBORStorage.ts +37 -0
- package/storage/DiskCollection.d.ts +6 -25
- package/storage/DiskCollection.ts +17 -74
package/builders/webBuild.ts
CHANGED
|
@@ -38,8 +38,8 @@ async function main() {
|
|
|
38
38
|
// Collect all files to copy
|
|
39
39
|
let filesToCopy: string[] = [];
|
|
40
40
|
|
|
41
|
+
filesToCopy.push(yargObj.indexHtml);
|
|
41
42
|
if (hasIndexHtml) {
|
|
42
|
-
filesToCopy.push(yargObj.indexHtml);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// Add assets folder files if it exists
|
|
@@ -59,6 +59,8 @@ async function main() {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
let indexHtmlOutput = "";
|
|
63
|
+
|
|
62
64
|
let filesCopied = 0;
|
|
63
65
|
let root = path.resolve(".");
|
|
64
66
|
for (const file of filesToCopy) {
|
|
@@ -70,6 +72,10 @@ async function main() {
|
|
|
70
72
|
let relativePath = path.relative(root, sourcePath);
|
|
71
73
|
let destPath = path.join(yargObj.outputFolder, relativePath);
|
|
72
74
|
|
|
75
|
+
if (file === yargObj.indexHtml) {
|
|
76
|
+
indexHtmlOutput = destPath;
|
|
77
|
+
}
|
|
78
|
+
|
|
73
79
|
let sourceTimestamp = await getTimestamp(sourcePath);
|
|
74
80
|
let destTimestamp = await getTimestamp(destPath);
|
|
75
81
|
if (sourceTimestamp > destTimestamp) {
|
|
@@ -84,6 +90,7 @@ async function main() {
|
|
|
84
90
|
|
|
85
91
|
let duration = Date.now() - time;
|
|
86
92
|
console.log(`Web build completed in ${formatTime(duration)}`);
|
|
93
|
+
console.log(`file://${path.resolve(indexHtmlOutput).replaceAll("\\", "/")}`);
|
|
87
94
|
}
|
|
88
95
|
main().catch(console.error).finally(() => process.exit());
|
|
89
96
|
|
package/index.d.ts
CHANGED
|
@@ -417,6 +417,26 @@ declare module "sliftutils/render-utils/observer" {
|
|
|
417
417
|
|
|
418
418
|
}
|
|
419
419
|
|
|
420
|
+
declare module "sliftutils/storage/CBORStorage" {
|
|
421
|
+
/// <reference types="node" />
|
|
422
|
+
/// <reference types="node" />
|
|
423
|
+
import { IStorage } from "./IStorage";
|
|
424
|
+
export declare class CBORStorage<T> implements IStorage<T> {
|
|
425
|
+
private storage;
|
|
426
|
+
constructor(storage: IStorage<Buffer>);
|
|
427
|
+
get(key: string): Promise<T | undefined>;
|
|
428
|
+
set(key: string, value: T): Promise<void>;
|
|
429
|
+
remove(key: string): Promise<void>;
|
|
430
|
+
getKeys(): Promise<string[]>;
|
|
431
|
+
getInfo(key: string): Promise<{
|
|
432
|
+
size: number;
|
|
433
|
+
lastModified: number;
|
|
434
|
+
} | undefined>;
|
|
435
|
+
reset(): Promise<void>;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
}
|
|
439
|
+
|
|
420
440
|
declare module "sliftutils/storage/CachedStorage" {
|
|
421
441
|
import { StorageSync } from "./StorageObservable";
|
|
422
442
|
export declare function newCachedStrStorage<T>(folder: string, getValue: (key: string) => Promise<T>): StorageSync<T>;
|
|
@@ -449,31 +469,12 @@ declare module "sliftutils/storage/DiskCollection" {
|
|
|
449
469
|
import { TransactionStorage } from "./TransactionStorage";
|
|
450
470
|
export declare class DiskCollection<T> implements IStorageSync<T> {
|
|
451
471
|
private collectionName;
|
|
452
|
-
private
|
|
453
|
-
constructor(collectionName: string,
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
get(key: string): T | undefined;
|
|
459
|
-
getPromise(key: string): Promise<T | undefined>;
|
|
460
|
-
set(key: string, value: T): void;
|
|
461
|
-
remove(key: string): void;
|
|
462
|
-
getKeys(): string[];
|
|
463
|
-
getKeysPromise(): Promise<string[]>;
|
|
464
|
-
getEntries(): [string, T][];
|
|
465
|
-
getValues(): T[];
|
|
466
|
-
getValuesPromise(): Promise<T[]>;
|
|
467
|
-
getInfo(key: string): {
|
|
468
|
-
size: number;
|
|
469
|
-
lastModified: number;
|
|
470
|
-
} | undefined;
|
|
471
|
-
reset(): Promise<void>;
|
|
472
|
-
}
|
|
473
|
-
export declare class DiskCollectionBrowser<T> implements IStorageSync<T> {
|
|
474
|
-
private collectionName;
|
|
475
|
-
private writeDelay?;
|
|
476
|
-
constructor(collectionName: string, writeDelay?: number | undefined);
|
|
472
|
+
private config?;
|
|
473
|
+
constructor(collectionName: string, config?: {
|
|
474
|
+
writeDelay?: number | undefined;
|
|
475
|
+
cbor?: boolean | undefined;
|
|
476
|
+
browserOnly?: boolean | undefined;
|
|
477
|
+
} | undefined);
|
|
477
478
|
transactionStorage: TransactionStorage | undefined;
|
|
478
479
|
initStorage(): Promise<IStorage<T>>;
|
|
479
480
|
baseStorage: Promise<IStorage<T>>;
|
package/package.json
CHANGED
package/spec.txt
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
TODO: Take the half finished apiServer code in vidfrontend, finish the todos, and move it here.
|
|
2
|
+
- Having an alternate version, where we run a server that does watching is nice, it's heavier and does require setting up certificates. but it makes hot reloading faster. And... It can be used to run an actual site that's public.
|
|
3
|
+
|
|
1
4
|
ALSO, go fix our typings in socket-function as well
|
|
2
5
|
|
|
3
6
|
TODO:
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { IStorage } from "./IStorage";
|
|
4
|
+
export declare class CBORStorage<T> implements IStorage<T> {
|
|
5
|
+
private storage;
|
|
6
|
+
constructor(storage: IStorage<Buffer>);
|
|
7
|
+
get(key: string): Promise<T | undefined>;
|
|
8
|
+
set(key: string, value: T): Promise<void>;
|
|
9
|
+
remove(key: string): Promise<void>;
|
|
10
|
+
getKeys(): Promise<string[]>;
|
|
11
|
+
getInfo(key: string): Promise<{
|
|
12
|
+
size: number;
|
|
13
|
+
lastModified: number;
|
|
14
|
+
} | undefined>;
|
|
15
|
+
reset(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { lazy } from "socket-function/src/caching";
|
|
2
|
+
import { IStorage } from "./IStorage";
|
|
3
|
+
import cborx from "cbor-x";
|
|
4
|
+
const cborEncoder = lazy(() => new cborx.Encoder({ structuredClone: true }));
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export class CBORStorage<T> implements IStorage<T> {
|
|
8
|
+
constructor(private storage: IStorage<Buffer>) { }
|
|
9
|
+
public async get(key: string): Promise<T | undefined> {
|
|
10
|
+
let buffer = await this.storage.get(key);
|
|
11
|
+
if (buffer === undefined) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
return cborEncoder().decode(buffer);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.warn(`Failed to parse CBOR for key: ${key}`, e);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
public async set(key: string, value: T): Promise<void> {
|
|
21
|
+
await this.storage.set(key, cborEncoder().encode(value));
|
|
22
|
+
}
|
|
23
|
+
public async remove(key: string): Promise<void> {
|
|
24
|
+
await this.storage.remove(key);
|
|
25
|
+
}
|
|
26
|
+
public async getKeys(): Promise<string[]> {
|
|
27
|
+
return await this.storage.getKeys();
|
|
28
|
+
}
|
|
29
|
+
public async getInfo(key: string) {
|
|
30
|
+
return await this.storage.getInfo(key);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public async reset() {
|
|
34
|
+
await this.storage.reset();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
@@ -5,31 +5,12 @@ import { StorageSync } from "./StorageObservable";
|
|
|
5
5
|
import { TransactionStorage } from "./TransactionStorage";
|
|
6
6
|
export declare class DiskCollection<T> implements IStorageSync<T> {
|
|
7
7
|
private collectionName;
|
|
8
|
-
private
|
|
9
|
-
constructor(collectionName: string,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
get(key: string): T | undefined;
|
|
15
|
-
getPromise(key: string): Promise<T | undefined>;
|
|
16
|
-
set(key: string, value: T): void;
|
|
17
|
-
remove(key: string): void;
|
|
18
|
-
getKeys(): string[];
|
|
19
|
-
getKeysPromise(): Promise<string[]>;
|
|
20
|
-
getEntries(): [string, T][];
|
|
21
|
-
getValues(): T[];
|
|
22
|
-
getValuesPromise(): Promise<T[]>;
|
|
23
|
-
getInfo(key: string): {
|
|
24
|
-
size: number;
|
|
25
|
-
lastModified: number;
|
|
26
|
-
} | undefined;
|
|
27
|
-
reset(): Promise<void>;
|
|
28
|
-
}
|
|
29
|
-
export declare class DiskCollectionBrowser<T> implements IStorageSync<T> {
|
|
30
|
-
private collectionName;
|
|
31
|
-
private writeDelay?;
|
|
32
|
-
constructor(collectionName: string, writeDelay?: number | undefined);
|
|
8
|
+
private config?;
|
|
9
|
+
constructor(collectionName: string, config?: {
|
|
10
|
+
writeDelay?: number | undefined;
|
|
11
|
+
cbor?: boolean | undefined;
|
|
12
|
+
browserOnly?: boolean | undefined;
|
|
13
|
+
} | undefined);
|
|
33
14
|
transactionStorage: TransactionStorage | undefined;
|
|
34
15
|
initStorage(): Promise<IStorage<T>>;
|
|
35
16
|
baseStorage: Promise<IStorage<T>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isNode } from "typesafecss";
|
|
2
2
|
import { DelayedStorage } from "./DelayedStorage";
|
|
3
3
|
import { FileStorage, getFileStorage, getFileStorageNested } from "./FileFolderAPI";
|
|
4
|
-
import { IStorage, IStorageSync } from "./IStorage";
|
|
4
|
+
import { IStorage, IStorageRaw, IStorageSync } from "./IStorage";
|
|
5
5
|
import { JSONStorage } from "./JSONStorage";
|
|
6
6
|
import { StorageSync } from "./StorageObservable";
|
|
7
7
|
import { TransactionStorage } from "./TransactionStorage";
|
|
@@ -9,23 +9,33 @@ import { PendingStorage } from "./PendingStorage";
|
|
|
9
9
|
import { isDefined } from "../misc/types";
|
|
10
10
|
import { PrivateFileSystemStorage } from "./PrivateFileSystemStorage";
|
|
11
11
|
import { isInChromeExtension } from "../misc/environment";
|
|
12
|
+
import { CBORStorage } from "./CBORStorage";
|
|
12
13
|
|
|
13
14
|
export class DiskCollection<T> implements IStorageSync<T> {
|
|
14
15
|
constructor(
|
|
15
16
|
private collectionName: string,
|
|
16
|
-
private
|
|
17
|
+
private config?: {
|
|
18
|
+
writeDelay?: number;
|
|
19
|
+
cbor?: boolean;
|
|
20
|
+
browserOnly?: boolean;
|
|
21
|
+
}
|
|
17
22
|
) {
|
|
18
23
|
}
|
|
19
24
|
public transactionStorage: TransactionStorage | undefined;
|
|
20
25
|
async initStorage(): Promise<IStorage<T>> {
|
|
21
26
|
// If a Chrome extension, just return null.
|
|
22
27
|
if (isInChromeExtension()) return null as any;
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
let curCollection: IStorageRaw;
|
|
29
|
+
if (this.config?.browserOnly) {
|
|
30
|
+
curCollection = await new PrivateFileSystemStorage(`collections/${this.collectionName}`);
|
|
31
|
+
} else {
|
|
32
|
+
let fileStorage = await getFileStorage();
|
|
33
|
+
let collections = await fileStorage.folder.getStorage("collections");
|
|
34
|
+
curCollection = await collections.folder.getStorage(this.collectionName);
|
|
35
|
+
}
|
|
36
|
+
let baseStorage = new TransactionStorage(curCollection, this.collectionName, this.config?.writeDelay);
|
|
27
37
|
this.transactionStorage = baseStorage;
|
|
28
|
-
return new JSONStorage<T>(baseStorage);
|
|
38
|
+
return this.config?.cbor ? new CBORStorage<T>(baseStorage) : new JSONStorage<T>(baseStorage);
|
|
29
39
|
}
|
|
30
40
|
public baseStorage = this.initStorage();
|
|
31
41
|
private synced = new StorageSync(
|
|
@@ -82,73 +92,6 @@ export class DiskCollection<T> implements IStorageSync<T> {
|
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
|
|
85
|
-
export class DiskCollectionBrowser<T> implements IStorageSync<T> {
|
|
86
|
-
constructor(
|
|
87
|
-
private collectionName: string,
|
|
88
|
-
private writeDelay?: number,
|
|
89
|
-
) {
|
|
90
|
-
}
|
|
91
|
-
public transactionStorage: TransactionStorage | undefined;
|
|
92
|
-
async initStorage(): Promise<IStorage<T>> {
|
|
93
|
-
if (isNode()) return undefined as any;
|
|
94
|
-
let curCollection = await new PrivateFileSystemStorage(`collections/${this.collectionName}`);
|
|
95
|
-
let baseStorage = new TransactionStorage(curCollection, this.collectionName);
|
|
96
|
-
return new JSONStorage<T>(baseStorage);
|
|
97
|
-
}
|
|
98
|
-
public baseStorage = this.initStorage();
|
|
99
|
-
private synced = new StorageSync(
|
|
100
|
-
new PendingStorage(`Collection (${this.collectionName})`,
|
|
101
|
-
new DelayedStorage<T>(this.baseStorage)
|
|
102
|
-
)
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
public get(key: string): T | undefined {
|
|
106
|
-
return this.synced.get(key);
|
|
107
|
-
}
|
|
108
|
-
public async getPromise(key: string): Promise<T | undefined> {
|
|
109
|
-
let base = await this.baseStorage;
|
|
110
|
-
return base.get(key);
|
|
111
|
-
}
|
|
112
|
-
public set(key: string, value: T): void {
|
|
113
|
-
this.synced.set(key, value);
|
|
114
|
-
}
|
|
115
|
-
public remove(key: string): void {
|
|
116
|
-
this.synced.remove(key);
|
|
117
|
-
}
|
|
118
|
-
public getKeys(): string[] {
|
|
119
|
-
return this.synced.getKeys();
|
|
120
|
-
}
|
|
121
|
-
public getKeysPromise(): Promise<string[]> {
|
|
122
|
-
return this.synced.getKeysPromise();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public getEntries(): [string, T][] {
|
|
126
|
-
let keys = this.getKeys();
|
|
127
|
-
return keys.map(key => [key, this.get(key)]).filter(([_, value]) => isDefined(value)) as [string, T][];
|
|
128
|
-
}
|
|
129
|
-
public getValues(): T[] {
|
|
130
|
-
let keys = this.getKeys();
|
|
131
|
-
return keys.map(key => this.get(key)).filter(isDefined);
|
|
132
|
-
}
|
|
133
|
-
public async getValuesPromise(): Promise<T[]> {
|
|
134
|
-
let keys = await this.getKeysPromise();
|
|
135
|
-
let values: T[] = [];
|
|
136
|
-
for (let key of keys) {
|
|
137
|
-
let value = await this.getPromise(key);
|
|
138
|
-
if (isDefined(value)) {
|
|
139
|
-
values.push(value);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return values;
|
|
143
|
-
}
|
|
144
|
-
public getInfo(key: string) {
|
|
145
|
-
return this.synced.getInfo(key);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
public async reset() {
|
|
149
|
-
await this.synced.reset();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
95
|
|
|
153
96
|
export class DiskCollectionPromise<T> implements IStorage<T> {
|
|
154
97
|
constructor(
|