sliftutils 1.7.9 → 1.7.10

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.
Files changed (41) hide show
  1. package/bin/storageserver.js +4 -0
  2. package/{teststorage → examplestorage}/browser.tsx +18 -22
  3. package/{teststorage/server.ts → examplestorage/exampleserver.ts} +5 -5
  4. package/index.d.ts +528 -78
  5. package/misc/https/dns.d.ts +7 -3
  6. package/misc/https/dns.ts +4 -9
  7. package/misc/https/hostServer.d.ts +6 -3
  8. package/misc/https/hostServer.ts +6 -6
  9. package/package.json +2 -1
  10. package/spec.txt +77 -42
  11. package/storage/ArchivesDisk.d.ts +65 -0
  12. package/storage/ArchivesDisk.ts +365 -0
  13. package/storage/IArchives.d.ts +95 -1
  14. package/storage/IArchives.ts +146 -1
  15. package/storage/backblaze.d.ts +14 -2
  16. package/storage/backblaze.ts +18 -2
  17. package/storage/remoteStorage/ArchivesRemote.d.ts +29 -17
  18. package/storage/remoteStorage/ArchivesRemote.ts +63 -63
  19. package/storage/remoteStorage/ArchivesUrl.d.ts +46 -0
  20. package/storage/remoteStorage/ArchivesUrl.ts +74 -0
  21. package/storage/remoteStorage/accessPage.tsx +111 -28
  22. package/storage/remoteStorage/blobStore.d.ts +79 -25
  23. package/storage/remoteStorage/blobStore.ts +441 -287
  24. package/storage/remoteStorage/cliArgs.d.ts +1 -0
  25. package/storage/remoteStorage/cliArgs.ts +9 -0
  26. package/storage/remoteStorage/createArchives.d.ts +64 -0
  27. package/storage/remoteStorage/createArchives.ts +395 -0
  28. package/storage/remoteStorage/grantAccess.js +4 -0
  29. package/storage/remoteStorage/grantAccessCli.d.ts +1 -0
  30. package/storage/remoteStorage/grantAccessCli.ts +27 -0
  31. package/storage/remoteStorage/remoteConfig.d.ts +21 -0
  32. package/storage/remoteStorage/remoteConfig.ts +94 -0
  33. package/storage/remoteStorage/storageController.d.ts +19 -27
  34. package/storage/remoteStorage/storageController.ts +205 -136
  35. package/storage/remoteStorage/storageServer.d.ts +11 -0
  36. package/storage/remoteStorage/storageServer.ts +80 -93
  37. package/storage/remoteStorage/storageServerCli.d.ts +1 -0
  38. package/storage/remoteStorage/storageServerCli.ts +41 -0
  39. package/storage/remoteStorage/storageServerState.d.ts +37 -0
  40. package/storage/remoteStorage/storageServerState.ts +358 -0
  41. package/testsite/server.ts +1 -1
package/index.d.ts CHANGED
@@ -150,10 +150,14 @@ declare module "sliftutils/misc/https/dns" {
150
150
  export declare function setRecord(type: string, key: string, value: string, proxied?: "proxied"): Promise<void>;
151
151
  /** Keeps existing records */
152
152
  export declare function addRecord(type: string, key: string, value: string, proxied?: "proxied"): Promise<void>;
153
- /** Provide Cloudflare credentials directly (an API token, or a path to a file containing one), instead of relying on ./cloudflare.json */
153
+ /** Provide Cloudflare credentials directly instead of relying on ./cloudflare.json. Exactly one of
154
+ * key (the API token itself) or path (a file to read it from) — TypeScript rejects both/neither. */
154
155
  export declare function setCloudflareCredentials(config: {
155
- key?: string;
156
- path?: string;
156
+ value: {
157
+ key: string;
158
+ } | {
159
+ path: string;
160
+ };
157
161
  }): void;
158
162
 
159
163
  }
@@ -163,9 +167,12 @@ declare module "sliftutils/misc/https/hostServer" {
163
167
  /** Full domain to host on (e.g. "testsite.example.com"). The HTTPS cert is created for this domain and *.domain, so using a subdomain never touches the root domain (beyond its _acme-challenge TXT record). */
164
168
  domain: string;
165
169
  port: number;
166
- /** Cloudflare API token (or a path to a file containing one). If neither is given, ./cloudflare.json is used. */
167
- cloudflareApiToken?: string;
168
- cloudflareApiTokenPath?: string;
170
+ /** Cloudflare API token: either the token string ({ key }) or a path to a file containing it ({ path }). Required pass { path: "./cloudflare.json" } explicitly for the on-disk file. */
171
+ cloudflareApiToken: {
172
+ key: string;
173
+ } | {
174
+ path: string;
175
+ };
169
176
  /** Creates an unproxied A record pointing domain at this machine (publicIp, or our detected external IP) */
170
177
  setDNSRecord?: boolean;
171
178
  publicIp?: string;
@@ -796,6 +803,75 @@ declare module "sliftutils/render-utils/observer" {
796
803
 
797
804
  }
798
805
 
806
+ declare module "sliftutils/storage/ArchivesDisk" {
807
+ /// <reference types="node" />
808
+ /// <reference types="node" />
809
+ import { IArchives, ArchiveFileInfo, ArchivesConfig } from "./IArchives";
810
+ export declare class ArchivesDisk implements IArchives {
811
+ private folder;
812
+ constructor(folder: string);
813
+ private filesDir;
814
+ private uploadsDir;
815
+ private handles;
816
+ private largeUploads;
817
+ private nextLargeUploadId;
818
+ init: {
819
+ (): Promise<void>;
820
+ reset(): void;
821
+ set(newValue: Promise<void>): void;
822
+ };
823
+ getDebugName(): string;
824
+ getConfig(): Promise<ArchivesConfig>;
825
+ private filePath;
826
+ set(key: string, data: Buffer, config?: {
827
+ lastModified?: number;
828
+ }): Promise<void>;
829
+ del(key: string): Promise<void>;
830
+ get(key: string, config?: {
831
+ range?: {
832
+ start: number;
833
+ end: number;
834
+ };
835
+ }): Promise<Buffer | undefined>;
836
+ get2(key: string, config?: {
837
+ range?: {
838
+ start: number;
839
+ end: number;
840
+ };
841
+ }): Promise<{
842
+ data: Buffer;
843
+ writeTime: number;
844
+ } | undefined>;
845
+ getInfo(key: string): Promise<{
846
+ writeTime: number;
847
+ size: number;
848
+ } | undefined>;
849
+ find(prefix: string, config?: {
850
+ shallow?: boolean;
851
+ type: "files" | "folders";
852
+ }): Promise<string[]>;
853
+ findInfo(prefix: string, config?: {
854
+ shallow?: boolean;
855
+ type?: "files" | "folders";
856
+ }): Promise<ArchiveFileInfo[]>;
857
+ private collectFiles;
858
+ setLargeFile(config: {
859
+ path: string;
860
+ getNextData(): Promise<Buffer | undefined>;
861
+ }): Promise<void>;
862
+ startLargeUpload(): Promise<string>;
863
+ appendLargeUpload(id: string, data: Buffer): Promise<void>;
864
+ finishLargeUpload(id: string, key: string): Promise<void>;
865
+ cancelLargeUpload(id: string): Promise<void>;
866
+ getURL(path: string): Promise<string>;
867
+ }
868
+ export declare function applyFindInfoShape(files: ArchiveFileInfo[], prefix: string, config?: {
869
+ shallow?: boolean;
870
+ type?: "files" | "folders";
871
+ }): ArchiveFileInfo[];
872
+
873
+ }
874
+
799
875
  declare module "sliftutils/storage/BulkDatabase2/BulkDatabase2" {
800
876
  import { BulkDatabaseBase, ReactiveDeps, BulkDatabase2Config, BulkFileInfoListing, MergeAttemptResult } from "./BulkDatabaseBase";
801
877
  export { BulkDatabaseBase, noopReactiveDeps, bulkDatabase2Timing } from "./BulkDatabaseBase";
@@ -1972,11 +2048,78 @@ declare module "sliftutils/storage/FileFolderAPI" {
1972
2048
  declare module "sliftutils/storage/IArchives" {
1973
2049
  /// <reference types="node" />
1974
2050
  /// <reference types="node" />
2051
+ export declare const MAX_LAST_MODIFIED_FUTURE: number;
2052
+ export declare function assertValidLastModified(lastModified: number): void;
2053
+ export type RemoteConfig = {
2054
+ version?: number;
2055
+ sources: RemoteConfigBase[];
2056
+ };
2057
+ /**
2058
+ string arguments will be a url, looking like:
2059
+ https://storage2.vidgridweb.com:4445/file/exampleaccount/examplebucket/storage/storagerouting.json
2060
+ https://f002.backblazeb2.com/file/querysubtest-com-public-immutable/storage/storagerouting.json
2061
+ - These map to { url }, with the type inferred from the url
2062
+ - Hosted urls are /file/<account>/<bucketName>/..., backblaze urls are /file/<bucketName>/...
2063
+
2064
+ NOTE: If we do not have right access to these, then it becomes a read-only IArchives, where we solely read using the url form (which might throw due to not having access as well). UNLESS Our configuration explicitly has public: false, in which case, we don't even hit the URL and we throw on access.
2065
+
2066
+ NOTE: If we're in the browser, we should allow downloading the files via the URL form (if it's a public bucket), however, we won't allow writing, because their servers do not allow secure browser writes.
2067
+ */
2068
+ export type RemoteConfigBase = string | HostedConfig | BackblazeConfig;
2069
+ export type CommonConfig = {
2070
+ /** The default options for the first config in a list is DEFAULT_BASE_SYNC_OPTIONS. The rest default to DEFAULT_SYNC_OPTIONS. */
2071
+ syncOptions?: SyncOptions;
2072
+ };
2073
+ export type HostedConfig = CommonConfig & {
2074
+ type: "remote";
2075
+ url: string;
2076
+ accountName?: string;
2077
+ public?: boolean;
2078
+ fast?: boolean;
2079
+ writeDelay?: number;
2080
+ rawDisk?: boolean;
2081
+ immutable?: boolean;
2082
+ };
2083
+ export type BackblazeConfig = CommonConfig & {
2084
+ type: "backblaze";
2085
+ url: string;
2086
+ bucketName: string;
2087
+ public?: boolean;
2088
+ immutable?: boolean;
2089
+ };
2090
+ export declare const DEFAULT_BASE_SYNC_OPTIONS: SyncOptions;
2091
+ export declare const DEFAULT_SYNC_OPTIONS: SyncOptions;
1975
2092
  export type ArchiveFileInfo = {
1976
2093
  path: string;
1977
2094
  createTime: number;
1978
2095
  size: number;
1979
2096
  };
2097
+ export type ArchivesConfig = {
2098
+ supportsChangesAfter?: boolean;
2099
+ };
2100
+ export type SyncOptions = {
2101
+ copyFiles?: boolean;
2102
+ noWriteBack?: boolean;
2103
+ cacheReads?: boolean;
2104
+ validWindow: [number, number];
2105
+ required?: boolean;
2106
+ };
2107
+ export type ArchivesSource = {
2108
+ source: IArchives;
2109
+ options: SyncOptions;
2110
+ };
2111
+ export type ArchivesSyncSourceStatus = {
2112
+ debugName: string;
2113
+ options: SyncOptions;
2114
+ supportsChangesAfter: boolean;
2115
+ initialScanComplete: boolean;
2116
+ scannedCount: number;
2117
+ };
2118
+ export type ArchivesSyncStatus = {
2119
+ allScansComplete: boolean;
2120
+ indexSize: number;
2121
+ sources: ArchivesSyncSourceStatus[];
2122
+ };
1980
2123
  export interface IArchives {
1981
2124
  getDebugName(): string;
1982
2125
  get(fileName: string, config?: {
@@ -1985,13 +2128,31 @@ declare module "sliftutils/storage/IArchives" {
1985
2128
  end: number;
1986
2129
  };
1987
2130
  }): Promise<Buffer | undefined>;
1988
- set(fileName: string, data: Buffer): Promise<void>;
2131
+ /** Like get, but also returns the last-write time of the file. get just calls get2. */
2132
+ get2(fileName: string, config?: {
2133
+ range?: {
2134
+ start: number;
2135
+ end: number;
2136
+ };
2137
+ }): Promise<{
2138
+ data: Buffer;
2139
+ writeTime: number;
2140
+ } | undefined>;
2141
+ /**
2142
+ * lastModified stamps the write with that last-write time instead of now. If it is OLDER than
2143
+ * the file's current last-write time the write no-ops (so delayed / synchronized writes can
2144
+ * never clobber newer data). Times more than 15 minutes in the future are rejected.
2145
+ */
2146
+ set(fileName: string, data: Buffer, config?: {
2147
+ lastModified?: number;
2148
+ }): Promise<void>;
1989
2149
  del(fileName: string): Promise<void>;
1990
2150
  /** Streams a file too large to hold in memory. getNextData returns undefined when done. */
1991
2151
  setLargeFile(config: {
1992
2152
  path: string;
1993
2153
  getNextData(): Promise<Buffer | undefined>;
1994
2154
  }): Promise<void>;
2155
+ /** writeTime is the last-write time — see ArchiveFileInfo.createTime, which is the same value. */
1995
2156
  getInfo(fileName: string): Promise<{
1996
2157
  writeTime: number;
1997
2158
  size: number;
@@ -2006,6 +2167,15 @@ declare module "sliftutils/storage/IArchives" {
2006
2167
  }): Promise<ArchiveFileInfo[]>;
2007
2168
  /** Only works for public buckets (private buckets are API-access only). */
2008
2169
  getURL(path: string): Promise<string>;
2170
+ /** The bucket's configuration, which tells whether the optional functions are supported. */
2171
+ getConfig(): Promise<ArchivesConfig>;
2172
+ /**
2173
+ * All files changed after the given time. Only exists when getConfig().supportsChangesAfter;
2174
+ * backed by an index, so it is fast (unlike a full findInfo scan). Deletions are not reported.
2175
+ */
2176
+ getChangesAfter?(time: number): Promise<ArchiveFileInfo[]>;
2177
+ /** Synchronization introspection, for backends that synchronize from sources (see BlobStore). */
2178
+ getSyncStatus?(): Promise<ArchivesSyncStatus>;
2009
2179
  }
2010
2180
 
2011
2181
  }
@@ -2266,7 +2436,7 @@ declare module "sliftutils/storage/TransactionStorage" {
2266
2436
  declare module "sliftutils/storage/backblaze" {
2267
2437
  /// <reference types="node" />
2268
2438
  /// <reference types="node" />
2269
- import { IArchives } from "./IArchives";
2439
+ import { IArchives, ArchivesConfig } from "./IArchives";
2270
2440
  export declare class ArchivesBackblaze implements IArchives {
2271
2441
  private config;
2272
2442
  constructor(config: {
@@ -2291,7 +2461,19 @@ declare module "sliftutils/storage/backblaze" {
2291
2461
  };
2292
2462
  retryCount?: number;
2293
2463
  }): Promise<Buffer | undefined>;
2294
- set(fileName: string, data: Buffer): Promise<void>;
2464
+ get2(fileName: string, config?: {
2465
+ range?: {
2466
+ start: number;
2467
+ end: number;
2468
+ };
2469
+ }): Promise<{
2470
+ data: Buffer;
2471
+ writeTime: number;
2472
+ } | undefined>;
2473
+ getConfig(): Promise<ArchivesConfig>;
2474
+ set(fileName: string, data: Buffer, config?: {
2475
+ lastModified?: number;
2476
+ }): Promise<void>;
2295
2477
  del(fileName: string): Promise<void>;
2296
2478
  setLargeFile(config: {
2297
2479
  path: string;
@@ -2574,23 +2756,16 @@ declare module "sliftutils/storage/remoteFileStorage" {
2574
2756
  declare module "sliftutils/storage/remoteStorage/ArchivesRemote" {
2575
2757
  /// <reference types="node" />
2576
2758
  /// <reference types="node" />
2577
- import { IArchives, ArchiveFileInfo } from "../IArchives";
2759
+ import { IArchives, ArchiveFileInfo, ArchivesConfig, ArchivesSyncStatus } from "../IArchives";
2578
2760
  export type ArchivesRemoteConfig = {
2579
- address: string;
2580
- port: number;
2581
- account: string;
2582
- bucketName: string;
2583
- public?: boolean;
2584
- fast?: boolean;
2585
- writeDelay?: number;
2761
+ url: string;
2762
+ accountName?: string;
2763
+ waitForAccess?: boolean;
2586
2764
  };
2587
- export declare function buildPublicFileURL(config: {
2765
+ export declare function parseStorageUrl(url: string): {
2588
2766
  address: string;
2589
2767
  port: number;
2590
- account: string;
2591
- bucketName: string;
2592
- path: string;
2593
- }): string;
2768
+ };
2594
2769
  export declare function authenticateStorage(config: {
2595
2770
  address: string;
2596
2771
  port: number;
@@ -2602,16 +2777,21 @@ declare module "sliftutils/storage/remoteStorage/ArchivesRemote" {
2602
2777
  export declare class ArchivesRemote implements IArchives {
2603
2778
  private config;
2604
2779
  constructor(config: ArchivesRemoteConfig);
2780
+ private parsed;
2781
+ private account;
2782
+ private bucketName;
2605
2783
  private nodeId;
2606
2784
  private controller;
2607
- private setupDone;
2608
2785
  private lastDeniedLog;
2609
2786
  getDebugName(): string;
2610
2787
  private authenticate;
2611
2788
  private callAuthed;
2612
- waitingForAccess(): Promise<string | undefined>;
2789
+ waitingForAccess(): Promise<{
2790
+ link: string;
2791
+ machineId: string;
2792
+ ip: string;
2793
+ } | undefined>;
2613
2794
  private onAccessDenied;
2614
- private ensureSetup;
2615
2795
  private call;
2616
2796
  get(fileName: string, config?: {
2617
2797
  range?: {
@@ -2619,7 +2799,18 @@ declare module "sliftutils/storage/remoteStorage/ArchivesRemote" {
2619
2799
  end: number;
2620
2800
  };
2621
2801
  }): Promise<Buffer | undefined>;
2622
- set(fileName: string, data: Buffer): Promise<void>;
2802
+ get2(fileName: string, config?: {
2803
+ range?: {
2804
+ start: number;
2805
+ end: number;
2806
+ };
2807
+ }): Promise<{
2808
+ data: Buffer;
2809
+ writeTime: number;
2810
+ } | undefined>;
2811
+ set(fileName: string, data: Buffer, config?: {
2812
+ lastModified?: number;
2813
+ }): Promise<void>;
2623
2814
  del(fileName: string): Promise<void>;
2624
2815
  getInfo(fileName: string): Promise<{
2625
2816
  writeTime: number;
@@ -2633,11 +2824,64 @@ declare module "sliftutils/storage/remoteStorage/ArchivesRemote" {
2633
2824
  shallow?: boolean;
2634
2825
  type: "files" | "folders";
2635
2826
  }): Promise<string[]>;
2827
+ getChangesAfter(time: number): Promise<ArchiveFileInfo[]>;
2828
+ getConfig(): Promise<ArchivesConfig>;
2829
+ getSyncStatus(): Promise<ArchivesSyncStatus>;
2830
+ setLargeFile(config: {
2831
+ path: string;
2832
+ getNextData(): Promise<Buffer | undefined>;
2833
+ }): Promise<void>;
2834
+ getURL(path: string): Promise<string>;
2835
+ }
2836
+
2837
+ }
2838
+
2839
+ declare module "sliftutils/storage/remoteStorage/ArchivesUrl" {
2840
+ /// <reference types="node" />
2841
+ /// <reference types="node" />
2842
+ import { IArchives, ArchiveFileInfo, ArchivesConfig } from "../IArchives";
2843
+ export declare class ArchivesUrl implements IArchives {
2844
+ private base;
2845
+ constructor(base: string);
2846
+ getDebugName(): string;
2847
+ private readOnlyError;
2848
+ get(fileName: string, config?: {
2849
+ range?: {
2850
+ start: number;
2851
+ end: number;
2852
+ };
2853
+ }): Promise<Buffer | undefined>;
2854
+ get2(fileName: string, config?: {
2855
+ range?: {
2856
+ start: number;
2857
+ end: number;
2858
+ };
2859
+ }): Promise<{
2860
+ data: Buffer;
2861
+ writeTime: number;
2862
+ } | undefined>;
2863
+ getInfo(fileName: string): Promise<{
2864
+ writeTime: number;
2865
+ size: number;
2866
+ } | undefined>;
2867
+ set(fileName: string, data: Buffer, config?: {
2868
+ lastModified?: number;
2869
+ }): Promise<void>;
2870
+ del(fileName: string): Promise<void>;
2636
2871
  setLargeFile(config: {
2637
2872
  path: string;
2638
2873
  getNextData(): Promise<Buffer | undefined>;
2639
2874
  }): Promise<void>;
2875
+ find(prefix: string, config?: {
2876
+ shallow?: boolean;
2877
+ type: "files" | "folders";
2878
+ }): Promise<string[]>;
2879
+ findInfo(prefix: string, config?: {
2880
+ shallow?: boolean;
2881
+ type: "files" | "folders";
2882
+ }): Promise<ArchiveFileInfo[]>;
2640
2883
  getURL(path: string): Promise<string>;
2884
+ getConfig(): Promise<ArchivesConfig>;
2641
2885
  }
2642
2886
 
2643
2887
  }
@@ -2650,45 +2894,97 @@ declare module "sliftutils/storage/remoteStorage/accessPage" {
2650
2894
  declare module "sliftutils/storage/remoteStorage/blobStore" {
2651
2895
  /// <reference types="node" />
2652
2896
  /// <reference types="node" />
2653
- import { ArchiveFileInfo } from "../IArchives";
2897
+ import { ArchiveFileInfo, ArchivesSource, ArchivesSyncStatus } from "../IArchives";
2654
2898
  export declare const DEFAULT_FAST_WRITE_DELAY: number;
2655
2899
  export type WriteConfig = {
2656
2900
  fast?: boolean;
2657
2901
  writeDelay?: number;
2902
+ lastModified?: number;
2658
2903
  };
2659
- export declare class BlobStore {
2904
+ export type IBucketStore = {
2905
+ get(fileName: string, config?: {
2906
+ range?: {
2907
+ start: number;
2908
+ end: number;
2909
+ };
2910
+ }): Promise<Buffer | undefined>;
2911
+ get2(fileName: string, config?: {
2912
+ range?: {
2913
+ start: number;
2914
+ end: number;
2915
+ };
2916
+ }): Promise<{
2917
+ data: Buffer;
2918
+ writeTime: number;
2919
+ } | undefined>;
2920
+ set(fileName: string, data: Buffer, config?: WriteConfig): Promise<void>;
2921
+ del(fileName: string, config?: WriteConfig): Promise<void>;
2922
+ getInfo(fileName: string): Promise<{
2923
+ writeTime: number;
2924
+ size: number;
2925
+ } | undefined>;
2926
+ findInfo(prefix: string, config?: {
2927
+ shallow?: boolean;
2928
+ type?: "files" | "folders";
2929
+ }): Promise<ArchiveFileInfo[]>;
2930
+ getChangesAfter?(time: number): Promise<ArchiveFileInfo[]>;
2931
+ getSyncStatus?(): Promise<ArchivesSyncStatus>;
2932
+ startLargeUpload(): Promise<string>;
2933
+ appendLargeUpload(id: string, data: Buffer): Promise<void>;
2934
+ finishLargeUpload(id: string, key: string): Promise<void>;
2935
+ cancelLargeUpload(id: string): Promise<void>;
2936
+ };
2937
+ export declare class BlobStore implements IBucketStore {
2660
2938
  private folder;
2661
- constructor(folder: string);
2662
- private memCache;
2663
- private overlay;
2664
- private writeQueue;
2665
- private openBlobs;
2666
- private largeUploads;
2667
- private nextLargeUploadId;
2668
- private currentBlobNumber;
2669
- private currentBlobOffset;
2670
- private currentBlobFd;
2939
+ private sources;
2940
+ private config?;
2941
+ constructor(folder: string, sources: ArchivesSource[], config?: {
2942
+ onIndexChanged?: ((key: string) => void) | undefined;
2943
+ } | undefined);
2944
+ private stopped;
2671
2945
  private index;
2672
- private deadBytes;
2673
- private blobsDir;
2946
+ private mem;
2947
+ private dirty;
2948
+ private overlay;
2949
+ private sourceStates;
2674
2950
  init: {
2675
2951
  (): Promise<void>;
2676
2952
  reset(): void;
2677
2953
  set(newValue: Promise<void>): void;
2678
2954
  };
2679
- private blobName;
2680
- private blobPath;
2681
- private getBlobHandle;
2682
- private closeBlobHandle;
2683
- private addDeadBytes;
2684
- private appendData;
2955
+ dispose(): Promise<void>;
2956
+ private loadIndex;
2685
2957
  private setIndexEntry;
2958
+ private deleteIndexEntry;
2959
+ private flushIndex;
2960
+ private runSourceSync;
2961
+ private scanSource;
2962
+ private applyScanned;
2963
+ private pollChanges;
2964
+ private copySourceFiles;
2965
+ private waitForRequiredScans;
2966
+ private checkMissingKey;
2967
+ private getIndexEntry;
2968
+ get(key: string, config?: {
2969
+ range?: {
2970
+ start: number;
2971
+ end: number;
2972
+ };
2973
+ }): Promise<Buffer | undefined>;
2974
+ get2(key: string, config?: {
2975
+ range?: {
2976
+ start: number;
2977
+ end: number;
2978
+ };
2979
+ }): Promise<{
2980
+ data: Buffer;
2981
+ writeTime: number;
2982
+ } | undefined>;
2983
+ private cacheRead;
2686
2984
  set(key: string, data: Buffer, config?: WriteConfig): Promise<void>;
2985
+ private writeToSources;
2687
2986
  del(key: string, config?: WriteConfig): Promise<void>;
2688
- get(key: string, range?: {
2689
- start: number;
2690
- end: number;
2691
- }): Promise<Buffer | undefined>;
2987
+ private deleteFromSources;
2692
2988
  getInfo(key: string): Promise<{
2693
2989
  writeTime: number;
2694
2990
  size: number;
@@ -2697,22 +2993,125 @@ declare module "sliftutils/storage/remoteStorage/blobStore" {
2697
2993
  shallow?: boolean;
2698
2994
  type?: "files" | "folders";
2699
2995
  }): Promise<ArchiveFileInfo[]>;
2996
+ getChangesAfter(time: number): Promise<ArchiveFileInfo[]>;
2997
+ getSyncStatus(): Promise<ArchivesSyncStatus>;
2998
+ private getDiskSource;
2700
2999
  startLargeUpload(): Promise<string>;
2701
3000
  appendLargeUpload(id: string, data: Buffer): Promise<void>;
2702
3001
  finishLargeUpload(id: string, key: string): Promise<void>;
2703
3002
  cancelLargeUpload(id: string): Promise<void>;
2704
3003
  private flushOverlay;
2705
- private compact;
2706
3004
  }
2707
3005
 
2708
3006
  }
2709
3007
 
3008
+ declare module "sliftutils/storage/remoteStorage/cliArgs" {
3009
+ export declare function getArg(name: string): string | undefined;
3010
+
3011
+ }
3012
+
3013
+ declare module "sliftutils/storage/remoteStorage/createArchives" {
3014
+ /// <reference types="node" />
3015
+ /// <reference types="node" />
3016
+ import { IArchives, RemoteConfig, RemoteConfigBase, HostedConfig, BackblazeConfig, ArchiveFileInfo, ArchivesConfig, ArchivesSyncStatus } from "../IArchives";
3017
+ export declare function createApiArchives(source: HostedConfig | BackblazeConfig): IArchives;
3018
+ export declare class ArchivesChain implements IArchives {
3019
+ private normalized;
3020
+ private adopted;
3021
+ private sourcesPromise;
3022
+ constructor(config: RemoteConfig | RemoteConfigBase);
3023
+ getDebugName(): string;
3024
+ private getSourceConfigs;
3025
+ private getSources;
3026
+ private init;
3027
+ private ensureRouting;
3028
+ private readFromSource;
3029
+ private read;
3030
+ private getAccessHelp;
3031
+ private write;
3032
+ waitingForAccess(): Promise<{
3033
+ link: string;
3034
+ machineId: string;
3035
+ ip: string;
3036
+ } | undefined>;
3037
+ get(fileName: string, config?: {
3038
+ range?: {
3039
+ start: number;
3040
+ end: number;
3041
+ };
3042
+ }): Promise<Buffer | undefined>;
3043
+ get2(fileName: string, config?: {
3044
+ range?: {
3045
+ start: number;
3046
+ end: number;
3047
+ };
3048
+ }): Promise<{
3049
+ data: Buffer;
3050
+ writeTime: number;
3051
+ } | undefined>;
3052
+ getInfo(fileName: string): Promise<{
3053
+ writeTime: number;
3054
+ size: number;
3055
+ } | undefined>;
3056
+ find(prefix: string, config?: {
3057
+ shallow?: boolean;
3058
+ type: "files" | "folders";
3059
+ }): Promise<string[]>;
3060
+ findInfo(prefix: string, config?: {
3061
+ shallow?: boolean;
3062
+ type: "files" | "folders";
3063
+ }): Promise<ArchiveFileInfo[]>;
3064
+ getChangesAfter(time: number): Promise<ArchiveFileInfo[]>;
3065
+ getSyncStatus(): Promise<ArchivesSyncStatus>;
3066
+ getConfig(): Promise<ArchivesConfig>;
3067
+ set(fileName: string, data: Buffer, config?: {
3068
+ lastModified?: number;
3069
+ }): Promise<void>;
3070
+ del(fileName: string): Promise<void>;
3071
+ setLargeFile(config: {
3072
+ path: string;
3073
+ getNextData(): Promise<Buffer | undefined>;
3074
+ }): Promise<void>;
3075
+ getURL(path: string): Promise<string>;
3076
+ }
3077
+ export declare function createArchives(config: RemoteConfig | RemoteConfigBase): ArchivesChain;
3078
+
3079
+ }
3080
+
3081
+ declare module "sliftutils/storage/remoteStorage/grantAccessCli" {
3082
+ export {};
3083
+
3084
+ }
3085
+
3086
+ declare module "sliftutils/storage/remoteStorage/remoteConfig" {
3087
+ /// <reference types="node" />
3088
+ /// <reference types="node" />
3089
+ import { RemoteConfig, RemoteConfigBase, HostedConfig, BackblazeConfig } from "../IArchives";
3090
+ export declare const ROUTING_FILE = "storage/storagerouting.json";
3091
+ export declare function getConfigVersion(config: RemoteConfig): number;
3092
+ /** Strips the routing-file suffix, leaving the bucket's public base URL (file paths append to it). */
3093
+ export declare function getBucketBaseUrl(url: string): string;
3094
+ export declare function buildFileUrl(baseUrl: string, filePath: string): string;
3095
+ export declare function parseHostedUrl(url: string): {
3096
+ address: string;
3097
+ port: number;
3098
+ account: string;
3099
+ bucketName: string;
3100
+ };
3101
+ export declare function parseBackblazeUrl(url: string): {
3102
+ bucketName: string;
3103
+ };
3104
+ export declare function normalizeSource(source: RemoteConfigBase): HostedConfig | BackblazeConfig;
3105
+ export declare function normalizeRemoteConfig(config: RemoteConfig | RemoteConfigBase): RemoteConfig;
3106
+ export declare function parseRoutingData(data: Buffer): RemoteConfig;
3107
+ export declare function serializeRemoteConfig(config: RemoteConfig): Buffer;
3108
+
3109
+ }
3110
+
2710
3111
  declare module "sliftutils/storage/remoteStorage/storageController" {
2711
3112
  /// <reference types="node" />
2712
3113
  /// <reference types="node" />
2713
- import { ArchiveFileInfo } from "../IArchives";
2714
- import type { BlobStore } from "./blobStore";
2715
- import type { IStorage } from "../IStorage";
3114
+ import { ArchiveFileInfo, ArchivesConfig, ArchivesSyncStatus } from "../IArchives";
2716
3115
  export declare const REMOTE_STORAGE_CLASS_GUID = "RemoteStorageController-b7e42a91";
2717
3116
  export declare const STORAGE_AUTH_PURPOSE = "remoteStorage-auth-1";
2718
3117
  export declare const STORAGE_NOT_AUTHENTICATED = "REMOTE_STORAGE_NOT_AUTHENTICATED_cf2f7b1e";
@@ -2735,33 +3134,13 @@ declare module "sliftutils/storage/remoteStorage/storageController" {
2735
3134
  ip: string;
2736
3135
  time: number;
2737
3136
  };
2738
- export type BucketConfig = {
2739
- public?: boolean;
2740
- fast?: boolean;
2741
- writeDelay?: number;
2742
- };
2743
3137
  export type AccessState = {
2744
3138
  machineId: string;
2745
3139
  ip: string;
2746
3140
  hasAccess: boolean;
2747
- listAccessCommand: string;
2748
3141
  grantAccessCommand?: string;
2749
- machines?: (AccessRequest & {
2750
- trusted: boolean;
2751
- })[];
2752
- };
2753
- export type StorageServerState = {
2754
- domain: string;
2755
- port: number;
2756
- rootDomain: string;
2757
- sshTarget: string;
2758
- serverCommand: string;
2759
- blobStore: BlobStore;
2760
- trust: IStorage<TrustRecord>;
2761
- requests: IStorage<AccessRequest[]>;
2762
- buckets: IStorage<BucketConfig>;
3142
+ trustedMachines?: TrustRecord[];
2763
3143
  };
2764
- export declare function setStorageServerState(state: StorageServerState): void;
2765
3144
  export declare const RemoteStorageController: import("socket-function/SocketFunctionTypes").SocketRegistered<{
2766
3145
  authenticate: (token: AuthToken) => Promise<{
2767
3146
  machineId: string;
@@ -2774,14 +3153,22 @@ declare module "sliftutils/storage/remoteStorage/storageController" {
2774
3153
  grantAccessCommand: string;
2775
3154
  }>;
2776
3155
  getAccessState: (account: string) => Promise<AccessState>;
3156
+ listRequestsForIP: (account: string, ip: string) => Promise<AccessRequest[]>;
3157
+ grantAccess: (requestId: string) => Promise<TrustRecord>;
2777
3158
  adminListRequests: (ip: string) => Promise<AccessRequest[]>;
2778
3159
  adminGrantAccess: (requestId: string) => Promise<TrustRecord>;
2779
- ensureBucket: (account: string, bucketName: string, config: BucketConfig) => Promise<void>;
2780
3160
  get: (account: string, bucketName: string, path: string, range?: {
2781
3161
  start: number;
2782
3162
  end: number;
2783
3163
  }) => Promise<Buffer | undefined>;
2784
- set: (account: string, bucketName: string, path: string, data: Buffer) => Promise<void>;
3164
+ get2: (account: string, bucketName: string, path: string, range?: {
3165
+ start: number;
3166
+ end: number;
3167
+ }) => Promise<{
3168
+ data: Buffer;
3169
+ writeTime: number;
3170
+ } | undefined>;
3171
+ set: (account: string, bucketName: string, path: string, data: Buffer, lastModified?: number) => Promise<void>;
2785
3172
  del: (account: string, bucketName: string, path: string) => Promise<void>;
2786
3173
  getInfo: (account: string, bucketName: string, path: string) => Promise<{
2787
3174
  writeTime: number;
@@ -2791,17 +3178,80 @@ declare module "sliftutils/storage/remoteStorage/storageController" {
2791
3178
  shallow?: boolean;
2792
3179
  type?: "files" | "folders";
2793
3180
  }) => Promise<ArchiveFileInfo[]>;
3181
+ getChangesAfter: (account: string, bucketName: string, time: number) => Promise<ArchiveFileInfo[]>;
3182
+ getArchivesConfig: (account: string, bucketName: string) => Promise<ArchivesConfig>;
3183
+ getSyncStatus: (account: string, bucketName: string) => Promise<ArchivesSyncStatus>;
2794
3184
  startLargeFile: (account: string, bucketName: string, path: string) => Promise<string>;
2795
3185
  uploadPart: (uploadId: string, data: Buffer) => Promise<void>;
2796
3186
  finishLargeFile: (uploadId: string) => Promise<void>;
2797
3187
  cancelLargeFile: (uploadId: string) => Promise<void>;
2798
- getPublicFile: (account: string, bucketName: string, path: string) => Promise<Buffer>;
3188
+ httpEntry: (config?: {
3189
+ requireCalls?: string[];
3190
+ cacheTime?: number;
3191
+ }) => Promise<Buffer>;
2799
3192
  }>;
2800
3193
 
2801
3194
  }
2802
3195
 
2803
3196
  declare module "sliftutils/storage/remoteStorage/storageServer" {
2804
3197
  import "./accessPage";
3198
+ export type HostStorageServerConfig = {
3199
+ url: string;
3200
+ folder: string;
3201
+ cloudflareApiToken?: {
3202
+ key: string;
3203
+ } | {
3204
+ path: string;
3205
+ };
3206
+ lowSpaceThresholdBytes?: number;
3207
+ };
3208
+ export declare function hostStorageServer(config: HostStorageServerConfig): Promise<void>;
3209
+
3210
+ }
3211
+
3212
+ declare module "sliftutils/storage/remoteStorage/storageServerCli" {
3213
+ export {};
3214
+
3215
+ }
3216
+
3217
+ declare module "sliftutils/storage/remoteStorage/storageServerState" {
3218
+ /// <reference types="node" />
3219
+ /// <reference types="node" />
3220
+ import { IBucketStore } from "./blobStore";
3221
+ import { RemoteConfig, HostedConfig, IArchives } from "../IArchives";
3222
+ import type { IStorage } from "../IStorage";
3223
+ import type { AccessRequest, TrustRecord } from "./storageController";
3224
+ export type StorageServerConfig = {
3225
+ domain: string;
3226
+ port: number;
3227
+ rootDomain: string;
3228
+ sshTarget: string;
3229
+ serverCommand: string;
3230
+ folder: string;
3231
+ };
3232
+ export declare function setStorageServerConfig(value: StorageServerConfig): void;
3233
+ export declare function getStorageServerConfig(): StorageServerConfig;
3234
+ export declare function getStorageServerConfigOptional(): StorageServerConfig | undefined;
3235
+ export declare function setWritesRejectedReason(reason: string | undefined): void;
3236
+ export declare function getWritesRejectedReason(): string | undefined;
3237
+ export declare function assertWritesAllowed(): void;
3238
+ export declare function getTrust(): Promise<IStorage<TrustRecord>>;
3239
+ export declare function getRequests(): Promise<IStorage<AccessRequest[]>>;
3240
+ export type LoadedBucket = {
3241
+ account: string;
3242
+ bucketName: string;
3243
+ routing: RemoteConfig;
3244
+ routingJSON: string;
3245
+ self: HostedConfig | undefined;
3246
+ store: IBucketStore;
3247
+ };
3248
+ export declare function getLoadedBucket(account: string, bucketName: string): Promise<LoadedBucket | undefined>;
3249
+ export declare function assertMutable(bucket: LoadedBucket, filePath: string): Promise<void>;
3250
+ export declare function writeBucketFile(account: string, bucketName: string, filePath: string, data: Buffer, config?: {
3251
+ lastModified?: number;
3252
+ }): Promise<void>;
3253
+ export declare function deleteBucketFile(account: string, bucketName: string, filePath: string): Promise<void>;
3254
+ export declare function getLocalArchives(account: string, bucketName: string): IArchives;
2805
3255
 
2806
3256
  }
2807
3257