pushwork 1.2.3 → 1.2.4

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 (125) hide show
  1. package/dist/browser/browser-sync-engine.d.ts +64 -0
  2. package/dist/browser/browser-sync-engine.d.ts.map +1 -0
  3. package/dist/browser/browser-sync-engine.js +303 -0
  4. package/dist/browser/browser-sync-engine.js.map +1 -0
  5. package/dist/browser/filesystem-adapter.d.ts +84 -0
  6. package/dist/browser/filesystem-adapter.d.ts.map +1 -0
  7. package/dist/browser/filesystem-adapter.js +413 -0
  8. package/dist/browser/filesystem-adapter.js.map +1 -0
  9. package/dist/browser/index.d.ts +36 -0
  10. package/dist/browser/index.d.ts.map +1 -0
  11. package/dist/browser/index.js +90 -0
  12. package/dist/browser/index.js.map +1 -0
  13. package/dist/browser/types.d.ts +70 -0
  14. package/dist/browser/types.d.ts.map +1 -0
  15. package/dist/browser/types.js +6 -0
  16. package/dist/browser/types.js.map +1 -0
  17. package/dist/cli/commands.d.ts +6 -0
  18. package/dist/cli/commands.d.ts.map +1 -1
  19. package/dist/cli/commands.js +114 -4
  20. package/dist/cli/commands.js.map +1 -1
  21. package/dist/cli/output.d.ts +75 -0
  22. package/dist/cli/output.d.ts.map +1 -0
  23. package/dist/cli/output.js +182 -0
  24. package/dist/cli/output.js.map +1 -0
  25. package/dist/config/remote-manager.d.ts +65 -0
  26. package/dist/config/remote-manager.d.ts.map +1 -0
  27. package/dist/config/remote-manager.js +243 -0
  28. package/dist/config/remote-manager.js.map +1 -0
  29. package/dist/config.d.ts +16 -0
  30. package/dist/config.d.ts.map +1 -0
  31. package/dist/config.js +83 -0
  32. package/dist/config.js.map +1 -0
  33. package/dist/core/isomorphic-snapshot.d.ts +58 -0
  34. package/dist/core/isomorphic-snapshot.d.ts.map +1 -0
  35. package/dist/core/isomorphic-snapshot.js +204 -0
  36. package/dist/core/isomorphic-snapshot.js.map +1 -0
  37. package/dist/fs-tree.d.ts +6 -0
  38. package/dist/fs-tree.d.ts.map +1 -0
  39. package/dist/fs-tree.js +99 -0
  40. package/dist/fs-tree.js.map +1 -0
  41. package/dist/ignore.d.ts +6 -0
  42. package/dist/ignore.d.ts.map +1 -0
  43. package/dist/ignore.js +74 -0
  44. package/dist/ignore.js.map +1 -0
  45. package/dist/log.d.ts +3 -0
  46. package/dist/log.d.ts.map +1 -0
  47. package/dist/log.js +14 -0
  48. package/dist/log.js.map +1 -0
  49. package/dist/platform/browser-filesystem.d.ts +26 -0
  50. package/dist/platform/browser-filesystem.d.ts.map +1 -0
  51. package/dist/platform/browser-filesystem.js +91 -0
  52. package/dist/platform/browser-filesystem.js.map +1 -0
  53. package/dist/platform/filesystem.d.ts +29 -0
  54. package/dist/platform/filesystem.d.ts.map +1 -0
  55. package/dist/platform/filesystem.js +65 -0
  56. package/dist/platform/filesystem.js.map +1 -0
  57. package/dist/platform/node-filesystem.d.ts +21 -0
  58. package/dist/platform/node-filesystem.d.ts.map +1 -0
  59. package/dist/platform/node-filesystem.js +93 -0
  60. package/dist/platform/node-filesystem.js.map +1 -0
  61. package/dist/polyfill-node-window.d.ts +13 -0
  62. package/dist/polyfill-node-window.d.ts.map +1 -0
  63. package/dist/polyfill-node-window.js +17 -0
  64. package/dist/polyfill-node-window.js.map +1 -0
  65. package/dist/pushwork.d.ts +97 -0
  66. package/dist/pushwork.d.ts.map +1 -0
  67. package/dist/pushwork.js +726 -0
  68. package/dist/pushwork.js.map +1 -0
  69. package/dist/repo.d.ts +14 -0
  70. package/dist/repo.d.ts.map +1 -0
  71. package/dist/repo.js +60 -0
  72. package/dist/repo.js.map +1 -0
  73. package/dist/shapes/custom.d.ts +3 -0
  74. package/dist/shapes/custom.d.ts.map +1 -0
  75. package/dist/shapes/custom.js +57 -0
  76. package/dist/shapes/custom.js.map +1 -0
  77. package/dist/shapes/file.d.ts +20 -0
  78. package/dist/shapes/file.d.ts.map +1 -0
  79. package/dist/shapes/file.js +140 -0
  80. package/dist/shapes/file.js.map +1 -0
  81. package/dist/shapes/index.d.ts +10 -0
  82. package/dist/shapes/index.d.ts.map +1 -0
  83. package/dist/shapes/index.js +35 -0
  84. package/dist/shapes/index.js.map +1 -0
  85. package/dist/shapes/patchwork-folder.d.ts +3 -0
  86. package/dist/shapes/patchwork-folder.d.ts.map +1 -0
  87. package/dist/shapes/patchwork-folder.js +160 -0
  88. package/dist/shapes/patchwork-folder.js.map +1 -0
  89. package/dist/shapes/types.d.ts +38 -0
  90. package/dist/shapes/types.d.ts.map +1 -0
  91. package/dist/shapes/types.js +52 -0
  92. package/dist/shapes/types.js.map +1 -0
  93. package/dist/shapes/vfs.d.ts +3 -0
  94. package/dist/shapes/vfs.d.ts.map +1 -0
  95. package/dist/shapes/vfs.js +92 -0
  96. package/dist/shapes/vfs.js.map +1 -0
  97. package/dist/snarf.d.ts +21 -0
  98. package/dist/snarf.d.ts.map +1 -0
  99. package/dist/snarf.js +117 -0
  100. package/dist/snarf.js.map +1 -0
  101. package/dist/utils/fs-browser.d.ts +57 -0
  102. package/dist/utils/fs-browser.d.ts.map +1 -0
  103. package/dist/utils/fs-browser.js +311 -0
  104. package/dist/utils/fs-browser.js.map +1 -0
  105. package/dist/utils/fs-node.d.ts +53 -0
  106. package/dist/utils/fs-node.d.ts.map +1 -0
  107. package/dist/utils/fs-node.js +220 -0
  108. package/dist/utils/fs-node.js.map +1 -0
  109. package/dist/utils/isomorphic.d.ts +29 -0
  110. package/dist/utils/isomorphic.d.ts.map +1 -0
  111. package/dist/utils/isomorphic.js +139 -0
  112. package/dist/utils/isomorphic.js.map +1 -0
  113. package/dist/utils/pure.d.ts +25 -0
  114. package/dist/utils/pure.d.ts.map +1 -0
  115. package/dist/utils/pure.js +112 -0
  116. package/dist/utils/pure.js.map +1 -0
  117. package/dist/utils/repo-factory.d.ts.map +1 -1
  118. package/dist/utils/repo-factory.js +0 -1
  119. package/dist/utils/repo-factory.js.map +1 -1
  120. package/dist/version.d.ts +11 -0
  121. package/dist/version.d.ts.map +1 -0
  122. package/dist/version.js +93 -0
  123. package/dist/version.js.map +1 -0
  124. package/package.json +5 -5
  125. package/src/utils/repo-factory.ts +78 -85
@@ -1,12 +1,8 @@
1
- import {
2
- type Repo,
3
- type RepoConfig,
4
- type NetworkAdapterInterface,
5
- } from "@automerge/automerge-repo"
6
- import {NodeFSStorageAdapter} from "@automerge/automerge-repo-storage-nodefs"
7
- import * as fs from "fs/promises"
8
- import * as path from "path"
9
- import {DirectoryConfig} from "../types"
1
+ import { type Repo, type RepoConfig, type NetworkAdapterInterface } from "@automerge/automerge-repo";
2
+ import { NodeFSStorageAdapter } from "@automerge/automerge-repo-storage-nodefs";
3
+ import * as fs from "fs/promises";
4
+ import * as path from "path";
5
+ import { DirectoryConfig } from "../types";
10
6
 
11
7
  /**
12
8
  * Perform a real ESM dynamic import that tsc won't rewrite to require().
@@ -22,8 +18,8 @@ import {DirectoryConfig} from "../types"
22
18
  * Repo's internal imports.
23
19
  */
24
20
  const dynamicImport = new Function("specifier", "return import(specifier)") as (
25
- specifier: string
26
- ) => Promise<any>
21
+ specifier: string,
22
+ ) => Promise<any>;
27
23
 
28
24
  /**
29
25
  * Initialize the Subduction Wasm module and return the Repo constructor.
@@ -37,22 +33,22 @@ const dynamicImport = new Function("specifier", "return import(specifier)") as (
37
33
  * Both the Repo and initSubduction must be loaded via ESM dynamic import()
38
34
  * so they share the same module graph as the Repo's internal /slim imports.
39
35
  */
40
- let cachedRepoClass: typeof Repo | undefined
36
+ let cachedRepoClass: typeof Repo | undefined;
41
37
 
42
38
  async function getRepoClass(): Promise<typeof Repo> {
43
- if (cachedRepoClass) return cachedRepoClass
39
+ if (cachedRepoClass) return cachedRepoClass;
44
40
 
45
- // Import Repo and initialize Subduction Wasm via automerge-repo's
46
- // initSubduction() helper. This must happen before new Repo() because
47
- // the constructor calls set_subduction_logger() and new MemorySigner()
48
- // which require the Wasm module to be ready.
49
- //
50
- // Both imports use the ESM dynamic import wrapper so they share the
51
- // same module graph as the Repo's internal /slim imports.
52
- const repoMod = await dynamicImport("@automerge/automerge-repo")
53
- await repoMod.initSubduction()
54
- cachedRepoClass = repoMod.Repo as typeof Repo
55
- return cachedRepoClass
41
+ // Import Repo and initialize Subduction Wasm via automerge-repo's
42
+ // initSubduction() helper. This must happen before new Repo() because
43
+ // the constructor calls set_subduction_logger() and new MemorySigner()
44
+ // which require the Wasm module to be ready.
45
+ //
46
+ // Both imports use the ESM dynamic import wrapper so they share the
47
+ // same module graph as the Repo's internal /slim imports.
48
+ const repoMod = await dynamicImport("@automerge/automerge-repo");
49
+ await repoMod.initSubduction();
50
+ cachedRepoClass = repoMod.Repo as typeof Repo;
51
+ return cachedRepoClass;
56
52
  }
57
53
 
58
54
  /**
@@ -61,23 +57,23 @@ async function getRepoClass(): Promise<typeof Repo> {
61
57
  * if any are found.
62
58
  */
63
59
  async function hasCorruptStorage(dir: string): Promise<boolean> {
64
- try {
65
- await fs.access(dir)
66
- } catch {
67
- return false
68
- }
60
+ try {
61
+ await fs.access(dir);
62
+ } catch {
63
+ return false;
64
+ }
69
65
 
70
- const entries = await fs.readdir(dir, {withFileTypes: true})
71
- for (const entry of entries) {
72
- const fullPath = path.join(dir, entry.name)
73
- if (entry.isDirectory()) {
74
- if (await hasCorruptStorage(fullPath)) return true
75
- } else if (entry.isFile()) {
76
- const stat = await fs.stat(fullPath)
77
- if (stat.size === 0) return true
78
- }
79
- }
80
- return false
66
+ const entries = await fs.readdir(dir, { withFileTypes: true });
67
+ for (const entry of entries) {
68
+ const fullPath = path.join(dir, entry.name);
69
+ if (entry.isDirectory()) {
70
+ if (await hasCorruptStorage(fullPath)) return true;
71
+ } else if (entry.isFile()) {
72
+ const stat = await fs.stat(fullPath);
73
+ if (stat.size === 0) return true;
74
+ }
75
+ }
76
+ return false;
81
77
  }
82
78
 
83
79
  /**
@@ -92,58 +88,55 @@ async function hasCorruptStorage(dir: string): Promise<boolean> {
92
88
  * adapter for sync via the automerge sync server.
93
89
  */
94
90
  export async function createRepo(
95
- workingDir: string,
96
- config: DirectoryConfig,
97
- sub: boolean = false
91
+ workingDir: string,
92
+ config: DirectoryConfig,
93
+ sub: boolean = false
98
94
  ): Promise<Repo> {
99
- const RepoClass = await getRepoClass()
95
+ const RepoClass = await getRepoClass();
100
96
 
101
- const syncToolDir = path.join(workingDir, ".pushwork")
102
- const automergeDir = path.join(syncToolDir, "automerge")
97
+ const syncToolDir = path.join(workingDir, ".pushwork");
98
+ const automergeDir = path.join(syncToolDir, "automerge");
103
99
 
104
- // Detect and recover from corrupt local storage (0-byte files left by
105
- // incomplete writes from a previous run). Wipe the cache so the Repo
106
- // hydrates cleanly from the sync server.
107
- if (await hasCorruptStorage(automergeDir)) {
108
- console.warn("[pushwork] Corrupt local storage detected, clearing cache...")
109
- await fs.rm(automergeDir, {recursive: true, force: true})
110
- await fs.mkdir(automergeDir, {recursive: true})
111
- }
100
+ // Detect and recover from corrupt local storage (0-byte files left by
101
+ // incomplete writes from a previous run). Wipe the cache so the Repo
102
+ // hydrates cleanly from the sync server.
103
+ if (await hasCorruptStorage(automergeDir)) {
104
+ console.warn("[pushwork] Corrupt local storage detected, clearing cache...");
105
+ await fs.rm(automergeDir, { recursive: true, force: true });
106
+ await fs.mkdir(automergeDir, { recursive: true });
107
+ }
112
108
 
113
- const storage = new NodeFSStorageAdapter(automergeDir)
109
+ const storage = new NodeFSStorageAdapter(automergeDir);
114
110
 
115
- if (sub) {
116
- const endpoints: string[] = []
117
- if (config.sync_enabled && config.sync_server) {
118
- endpoints.push(config.sync_server)
119
- }
111
+ if (sub) {
112
+ const endpoints: string[] = [];
113
+ if (config.sync_enabled && config.sync_server) {
114
+ endpoints.push(config.sync_server);
115
+ }
120
116
 
121
- return new RepoClass({
122
- storage,
123
- // @ts-expect-error i don't know why
124
- subductionWebsocketEndpoints: endpoints,
125
- })
126
- }
117
+ return new RepoClass({
118
+ storage,
119
+ subductionWebsocketEndpoints: endpoints,
120
+ });
121
+ }
127
122
 
128
- // Default: WebSocket sync adapter
129
- const repoConfig: RepoConfig = {storage}
123
+ // Default: WebSocket sync adapter
124
+ const repoConfig: RepoConfig = { storage };
130
125
 
131
- if (config.sync_enabled && config.sync_server) {
132
- // Load the WebSocket adapter via ESM dynamic import to stay in the
133
- // same module graph as the Repo.
134
- const wsMod = await dynamicImport(
135
- "@automerge/automerge-repo-network-websocket"
136
- )
137
- // The websocket adapter package (subduction.8) hasn't updated its
138
- // NetworkAdapter base-class types to match the repo's new
139
- // NetworkAdapterInterface (which added state() and stricter
140
- // EventEmitter generics). At runtime the adapter has all required
141
- // methods; this is purely a declaration mismatch.
142
- const networkAdapter = new wsMod.BrowserWebSocketClientAdapter(
143
- config.sync_server
144
- ) as unknown as NetworkAdapterInterface
145
- repoConfig.network = [networkAdapter]
146
- }
126
+ if (config.sync_enabled && config.sync_server) {
127
+ // Load the WebSocket adapter via ESM dynamic import to stay in the
128
+ // same module graph as the Repo.
129
+ const wsMod = await dynamicImport("@automerge/automerge-repo-network-websocket");
130
+ // The websocket adapter package (subduction.8) hasn't updated its
131
+ // NetworkAdapter base-class types to match the repo's new
132
+ // NetworkAdapterInterface (which added state() and stricter
133
+ // EventEmitter generics). At runtime the adapter has all required
134
+ // methods; this is purely a declaration mismatch.
135
+ const networkAdapter = new wsMod.BrowserWebSocketClientAdapter(
136
+ config.sync_server
137
+ ) as unknown as NetworkAdapterInterface;
138
+ repoConfig.network = [networkAdapter];
139
+ }
147
140
 
148
- return new RepoClass(repoConfig)
141
+ return new RepoClass(repoConfig);
149
142
  }