gitx.do 0.1.0 → 0.1.2
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/README.md +40 -353
- package/dist/do/logger.d.ts +50 -0
- package/dist/do/logger.d.ts.map +1 -0
- package/dist/do/logger.js +122 -0
- package/dist/do/logger.js.map +1 -0
- package/dist/{durable-object → do}/schema.d.ts +3 -3
- package/dist/do/schema.d.ts.map +1 -0
- package/dist/{durable-object → do}/schema.js +4 -3
- package/dist/do/schema.js.map +1 -0
- package/dist/do/types.d.ts +267 -0
- package/dist/do/types.d.ts.map +1 -0
- package/dist/do/types.js +62 -0
- package/dist/do/types.js.map +1 -0
- package/dist/index.d.ts +15 -415
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -483
- package/dist/index.js.map +1 -1
- package/package.json +13 -21
- package/dist/cli/commands/add.d.ts +0 -174
- package/dist/cli/commands/add.d.ts.map +0 -1
- package/dist/cli/commands/add.js +0 -131
- package/dist/cli/commands/add.js.map +0 -1
- package/dist/cli/commands/blame.d.ts +0 -259
- package/dist/cli/commands/blame.d.ts.map +0 -1
- package/dist/cli/commands/blame.js +0 -609
- package/dist/cli/commands/blame.js.map +0 -1
- package/dist/cli/commands/branch.d.ts +0 -249
- package/dist/cli/commands/branch.d.ts.map +0 -1
- package/dist/cli/commands/branch.js +0 -693
- package/dist/cli/commands/branch.js.map +0 -1
- package/dist/cli/commands/commit.d.ts +0 -182
- package/dist/cli/commands/commit.d.ts.map +0 -1
- package/dist/cli/commands/commit.js +0 -437
- package/dist/cli/commands/commit.js.map +0 -1
- package/dist/cli/commands/diff.d.ts +0 -464
- package/dist/cli/commands/diff.d.ts.map +0 -1
- package/dist/cli/commands/diff.js +0 -958
- package/dist/cli/commands/diff.js.map +0 -1
- package/dist/cli/commands/log.d.ts +0 -239
- package/dist/cli/commands/log.d.ts.map +0 -1
- package/dist/cli/commands/log.js +0 -535
- package/dist/cli/commands/log.js.map +0 -1
- package/dist/cli/commands/merge.d.ts +0 -106
- package/dist/cli/commands/merge.d.ts.map +0 -1
- package/dist/cli/commands/merge.js +0 -55
- package/dist/cli/commands/merge.js.map +0 -1
- package/dist/cli/commands/review.d.ts +0 -457
- package/dist/cli/commands/review.d.ts.map +0 -1
- package/dist/cli/commands/review.js +0 -533
- package/dist/cli/commands/review.js.map +0 -1
- package/dist/cli/commands/status.d.ts +0 -269
- package/dist/cli/commands/status.d.ts.map +0 -1
- package/dist/cli/commands/status.js +0 -493
- package/dist/cli/commands/status.js.map +0 -1
- package/dist/cli/commands/web.d.ts +0 -199
- package/dist/cli/commands/web.d.ts.map +0 -1
- package/dist/cli/commands/web.js +0 -696
- package/dist/cli/commands/web.js.map +0 -1
- package/dist/cli/fs-adapter.d.ts +0 -656
- package/dist/cli/fs-adapter.d.ts.map +0 -1
- package/dist/cli/fs-adapter.js +0 -1179
- package/dist/cli/fs-adapter.js.map +0 -1
- package/dist/cli/fsx-cli-adapter.d.ts +0 -359
- package/dist/cli/fsx-cli-adapter.d.ts.map +0 -1
- package/dist/cli/fsx-cli-adapter.js +0 -619
- package/dist/cli/fsx-cli-adapter.js.map +0 -1
- package/dist/cli/index.d.ts +0 -387
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js +0 -523
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/ui/components/DiffView.d.ts +0 -7
- package/dist/cli/ui/components/DiffView.d.ts.map +0 -1
- package/dist/cli/ui/components/DiffView.js +0 -11
- package/dist/cli/ui/components/DiffView.js.map +0 -1
- package/dist/cli/ui/components/ErrorDisplay.d.ts +0 -6
- package/dist/cli/ui/components/ErrorDisplay.d.ts.map +0 -1
- package/dist/cli/ui/components/ErrorDisplay.js +0 -11
- package/dist/cli/ui/components/ErrorDisplay.js.map +0 -1
- package/dist/cli/ui/components/FuzzySearch.d.ts +0 -9
- package/dist/cli/ui/components/FuzzySearch.d.ts.map +0 -1
- package/dist/cli/ui/components/FuzzySearch.js +0 -12
- package/dist/cli/ui/components/FuzzySearch.js.map +0 -1
- package/dist/cli/ui/components/LoadingSpinner.d.ts +0 -6
- package/dist/cli/ui/components/LoadingSpinner.d.ts.map +0 -1
- package/dist/cli/ui/components/LoadingSpinner.js +0 -10
- package/dist/cli/ui/components/LoadingSpinner.js.map +0 -1
- package/dist/cli/ui/components/NavigationList.d.ts +0 -9
- package/dist/cli/ui/components/NavigationList.d.ts.map +0 -1
- package/dist/cli/ui/components/NavigationList.js +0 -11
- package/dist/cli/ui/components/NavigationList.js.map +0 -1
- package/dist/cli/ui/components/ScrollableContent.d.ts +0 -8
- package/dist/cli/ui/components/ScrollableContent.d.ts.map +0 -1
- package/dist/cli/ui/components/ScrollableContent.js +0 -11
- package/dist/cli/ui/components/ScrollableContent.js.map +0 -1
- package/dist/cli/ui/components/index.d.ts +0 -7
- package/dist/cli/ui/components/index.d.ts.map +0 -1
- package/dist/cli/ui/components/index.js +0 -9
- package/dist/cli/ui/components/index.js.map +0 -1
- package/dist/cli/ui/terminal-ui.d.ts +0 -52
- package/dist/cli/ui/terminal-ui.d.ts.map +0 -1
- package/dist/cli/ui/terminal-ui.js +0 -121
- package/dist/cli/ui/terminal-ui.js.map +0 -1
- package/dist/do/BashModule.d.ts +0 -871
- package/dist/do/BashModule.d.ts.map +0 -1
- package/dist/do/BashModule.js +0 -1143
- package/dist/do/BashModule.js.map +0 -1
- package/dist/do/FsModule.d.ts +0 -601
- package/dist/do/FsModule.d.ts.map +0 -1
- package/dist/do/FsModule.js +0 -1120
- package/dist/do/FsModule.js.map +0 -1
- package/dist/do/GitModule.d.ts +0 -635
- package/dist/do/GitModule.d.ts.map +0 -1
- package/dist/do/GitModule.js +0 -781
- package/dist/do/GitModule.js.map +0 -1
- package/dist/do/GitRepoDO.d.ts +0 -281
- package/dist/do/GitRepoDO.d.ts.map +0 -1
- package/dist/do/GitRepoDO.js +0 -479
- package/dist/do/GitRepoDO.js.map +0 -1
- package/dist/do/bash-ast.d.ts +0 -246
- package/dist/do/bash-ast.d.ts.map +0 -1
- package/dist/do/bash-ast.js +0 -888
- package/dist/do/bash-ast.js.map +0 -1
- package/dist/do/container-executor.d.ts +0 -491
- package/dist/do/container-executor.d.ts.map +0 -1
- package/dist/do/container-executor.js +0 -730
- package/dist/do/container-executor.js.map +0 -1
- package/dist/do/index.d.ts +0 -53
- package/dist/do/index.d.ts.map +0 -1
- package/dist/do/index.js +0 -91
- package/dist/do/index.js.map +0 -1
- package/dist/do/tiered-storage.d.ts +0 -403
- package/dist/do/tiered-storage.d.ts.map +0 -1
- package/dist/do/tiered-storage.js +0 -689
- package/dist/do/tiered-storage.js.map +0 -1
- package/dist/do/withBash.d.ts +0 -231
- package/dist/do/withBash.d.ts.map +0 -1
- package/dist/do/withBash.js +0 -244
- package/dist/do/withBash.js.map +0 -1
- package/dist/do/withFs.d.ts +0 -237
- package/dist/do/withFs.d.ts.map +0 -1
- package/dist/do/withFs.js +0 -387
- package/dist/do/withFs.js.map +0 -1
- package/dist/do/withGit.d.ts +0 -180
- package/dist/do/withGit.d.ts.map +0 -1
- package/dist/do/withGit.js +0 -271
- package/dist/do/withGit.js.map +0 -1
- package/dist/durable-object/object-store.d.ts +0 -633
- package/dist/durable-object/object-store.d.ts.map +0 -1
- package/dist/durable-object/object-store.js +0 -1161
- package/dist/durable-object/object-store.js.map +0 -1
- package/dist/durable-object/schema.d.ts.map +0 -1
- package/dist/durable-object/schema.js.map +0 -1
- package/dist/durable-object/wal.d.ts +0 -416
- package/dist/durable-object/wal.d.ts.map +0 -1
- package/dist/durable-object/wal.js +0 -445
- package/dist/durable-object/wal.js.map +0 -1
- package/dist/mcp/adapter.d.ts +0 -772
- package/dist/mcp/adapter.d.ts.map +0 -1
- package/dist/mcp/adapter.js +0 -895
- package/dist/mcp/adapter.js.map +0 -1
- package/dist/mcp/sandbox/miniflare-evaluator.d.ts +0 -22
- package/dist/mcp/sandbox/miniflare-evaluator.d.ts.map +0 -1
- package/dist/mcp/sandbox/miniflare-evaluator.js +0 -140
- package/dist/mcp/sandbox/miniflare-evaluator.js.map +0 -1
- package/dist/mcp/sandbox/object-store-proxy.d.ts +0 -32
- package/dist/mcp/sandbox/object-store-proxy.d.ts.map +0 -1
- package/dist/mcp/sandbox/object-store-proxy.js +0 -30
- package/dist/mcp/sandbox/object-store-proxy.js.map +0 -1
- package/dist/mcp/sandbox/template.d.ts +0 -17
- package/dist/mcp/sandbox/template.d.ts.map +0 -1
- package/dist/mcp/sandbox/template.js +0 -71
- package/dist/mcp/sandbox/template.js.map +0 -1
- package/dist/mcp/sandbox.d.ts +0 -764
- package/dist/mcp/sandbox.d.ts.map +0 -1
- package/dist/mcp/sandbox.js +0 -1362
- package/dist/mcp/sandbox.js.map +0 -1
- package/dist/mcp/sdk-adapter.d.ts +0 -835
- package/dist/mcp/sdk-adapter.d.ts.map +0 -1
- package/dist/mcp/sdk-adapter.js +0 -974
- package/dist/mcp/sdk-adapter.js.map +0 -1
- package/dist/mcp/tools/do.d.ts +0 -32
- package/dist/mcp/tools/do.d.ts.map +0 -1
- package/dist/mcp/tools/do.js +0 -115
- package/dist/mcp/tools/do.js.map +0 -1
- package/dist/mcp/tools.d.ts +0 -548
- package/dist/mcp/tools.d.ts.map +0 -1
- package/dist/mcp/tools.js +0 -1934
- package/dist/mcp/tools.js.map +0 -1
- package/dist/ops/blame.d.ts +0 -551
- package/dist/ops/blame.d.ts.map +0 -1
- package/dist/ops/blame.js +0 -1037
- package/dist/ops/blame.js.map +0 -1
- package/dist/ops/branch.d.ts +0 -766
- package/dist/ops/branch.d.ts.map +0 -1
- package/dist/ops/branch.js +0 -950
- package/dist/ops/branch.js.map +0 -1
- package/dist/ops/commit-traversal.d.ts +0 -349
- package/dist/ops/commit-traversal.d.ts.map +0 -1
- package/dist/ops/commit-traversal.js +0 -821
- package/dist/ops/commit-traversal.js.map +0 -1
- package/dist/ops/commit.d.ts +0 -555
- package/dist/ops/commit.d.ts.map +0 -1
- package/dist/ops/commit.js +0 -826
- package/dist/ops/commit.js.map +0 -1
- package/dist/ops/merge-base.d.ts +0 -397
- package/dist/ops/merge-base.d.ts.map +0 -1
- package/dist/ops/merge-base.js +0 -691
- package/dist/ops/merge-base.js.map +0 -1
- package/dist/ops/merge.d.ts +0 -855
- package/dist/ops/merge.d.ts.map +0 -1
- package/dist/ops/merge.js +0 -1551
- package/dist/ops/merge.js.map +0 -1
- package/dist/ops/tag.d.ts +0 -247
- package/dist/ops/tag.d.ts.map +0 -1
- package/dist/ops/tag.js +0 -649
- package/dist/ops/tag.js.map +0 -1
- package/dist/ops/tree-builder.d.ts +0 -178
- package/dist/ops/tree-builder.d.ts.map +0 -1
- package/dist/ops/tree-builder.js +0 -271
- package/dist/ops/tree-builder.js.map +0 -1
- package/dist/ops/tree-diff.d.ts +0 -291
- package/dist/ops/tree-diff.d.ts.map +0 -1
- package/dist/ops/tree-diff.js +0 -705
- package/dist/ops/tree-diff.js.map +0 -1
- package/dist/pack/delta.d.ts +0 -248
- package/dist/pack/delta.d.ts.map +0 -1
- package/dist/pack/delta.js +0 -736
- package/dist/pack/delta.js.map +0 -1
- package/dist/pack/format.d.ts +0 -446
- package/dist/pack/format.d.ts.map +0 -1
- package/dist/pack/format.js +0 -572
- package/dist/pack/format.js.map +0 -1
- package/dist/pack/full-generation.d.ts +0 -612
- package/dist/pack/full-generation.d.ts.map +0 -1
- package/dist/pack/full-generation.js +0 -1378
- package/dist/pack/full-generation.js.map +0 -1
- package/dist/pack/generation.d.ts +0 -441
- package/dist/pack/generation.d.ts.map +0 -1
- package/dist/pack/generation.js +0 -707
- package/dist/pack/generation.js.map +0 -1
- package/dist/pack/index.d.ts +0 -502
- package/dist/pack/index.d.ts.map +0 -1
- package/dist/pack/index.js +0 -833
- package/dist/pack/index.js.map +0 -1
- package/dist/refs/branch.d.ts +0 -668
- package/dist/refs/branch.d.ts.map +0 -1
- package/dist/refs/branch.js +0 -897
- package/dist/refs/branch.js.map +0 -1
- package/dist/refs/storage.d.ts +0 -833
- package/dist/refs/storage.d.ts.map +0 -1
- package/dist/refs/storage.js +0 -1023
- package/dist/refs/storage.js.map +0 -1
- package/dist/refs/tag.d.ts +0 -860
- package/dist/refs/tag.d.ts.map +0 -1
- package/dist/refs/tag.js +0 -996
- package/dist/refs/tag.js.map +0 -1
- package/dist/storage/backend.d.ts +0 -425
- package/dist/storage/backend.d.ts.map +0 -1
- package/dist/storage/backend.js +0 -41
- package/dist/storage/backend.js.map +0 -1
- package/dist/storage/fsx-adapter.d.ts +0 -204
- package/dist/storage/fsx-adapter.d.ts.map +0 -1
- package/dist/storage/fsx-adapter.js +0 -470
- package/dist/storage/fsx-adapter.js.map +0 -1
- package/dist/storage/lru-cache.d.ts +0 -691
- package/dist/storage/lru-cache.d.ts.map +0 -1
- package/dist/storage/lru-cache.js +0 -813
- package/dist/storage/lru-cache.js.map +0 -1
- package/dist/storage/object-index.d.ts +0 -585
- package/dist/storage/object-index.d.ts.map +0 -1
- package/dist/storage/object-index.js +0 -532
- package/dist/storage/object-index.js.map +0 -1
- package/dist/storage/r2-pack.d.ts +0 -1257
- package/dist/storage/r2-pack.d.ts.map +0 -1
- package/dist/storage/r2-pack.js +0 -1770
- package/dist/storage/r2-pack.js.map +0 -1
- package/dist/tiered/cdc-pipeline.d.ts +0 -1888
- package/dist/tiered/cdc-pipeline.d.ts.map +0 -1
- package/dist/tiered/cdc-pipeline.js +0 -1880
- package/dist/tiered/cdc-pipeline.js.map +0 -1
- package/dist/tiered/migration.d.ts +0 -1104
- package/dist/tiered/migration.d.ts.map +0 -1
- package/dist/tiered/migration.js +0 -1214
- package/dist/tiered/migration.js.map +0 -1
- package/dist/tiered/parquet-writer.d.ts +0 -1145
- package/dist/tiered/parquet-writer.d.ts.map +0 -1
- package/dist/tiered/parquet-writer.js +0 -1183
- package/dist/tiered/parquet-writer.js.map +0 -1
- package/dist/tiered/read-path.d.ts +0 -835
- package/dist/tiered/read-path.d.ts.map +0 -1
- package/dist/tiered/read-path.js +0 -487
- package/dist/tiered/read-path.js.map +0 -1
- package/dist/types/capability.d.ts +0 -1385
- package/dist/types/capability.d.ts.map +0 -1
- package/dist/types/capability.js +0 -36
- package/dist/types/capability.js.map +0 -1
- package/dist/types/index.d.ts +0 -13
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -18
- package/dist/types/index.js.map +0 -1
- package/dist/types/objects.d.ts +0 -692
- package/dist/types/objects.d.ts.map +0 -1
- package/dist/types/objects.js +0 -837
- package/dist/types/objects.js.map +0 -1
- package/dist/types/storage.d.ts +0 -603
- package/dist/types/storage.d.ts.map +0 -1
- package/dist/types/storage.js +0 -191
- package/dist/types/storage.js.map +0 -1
- package/dist/types/worker-loader.d.ts +0 -60
- package/dist/types/worker-loader.d.ts.map +0 -1
- package/dist/types/worker-loader.js +0 -62
- package/dist/types/worker-loader.js.map +0 -1
- package/dist/utils/hash.d.ts +0 -197
- package/dist/utils/hash.d.ts.map +0 -1
- package/dist/utils/hash.js +0 -268
- package/dist/utils/hash.js.map +0 -1
- package/dist/utils/sha1.d.ts +0 -290
- package/dist/utils/sha1.d.ts.map +0 -1
- package/dist/utils/sha1.js +0 -582
- package/dist/utils/sha1.js.map +0 -1
- package/dist/wire/capabilities.d.ts +0 -1044
- package/dist/wire/capabilities.d.ts.map +0 -1
- package/dist/wire/capabilities.js +0 -941
- package/dist/wire/capabilities.js.map +0 -1
- package/dist/wire/path-security.d.ts +0 -157
- package/dist/wire/path-security.d.ts.map +0 -1
- package/dist/wire/path-security.js +0 -307
- package/dist/wire/path-security.js.map +0 -1
- package/dist/wire/pkt-line.d.ts +0 -345
- package/dist/wire/pkt-line.d.ts.map +0 -1
- package/dist/wire/pkt-line.js +0 -381
- package/dist/wire/pkt-line.js.map +0 -1
- package/dist/wire/receive-pack.d.ts +0 -1059
- package/dist/wire/receive-pack.d.ts.map +0 -1
- package/dist/wire/receive-pack.js +0 -1414
- package/dist/wire/receive-pack.js.map +0 -1
- package/dist/wire/smart-http.d.ts +0 -799
- package/dist/wire/smart-http.d.ts.map +0 -1
- package/dist/wire/smart-http.js +0 -945
- package/dist/wire/smart-http.js.map +0 -1
- package/dist/wire/upload-pack.d.ts +0 -727
- package/dist/wire/upload-pack.d.ts.map +0 -1
- package/dist/wire/upload-pack.js +0 -1138
- package/dist/wire/upload-pack.js.map +0 -1
package/dist/do/withFs.d.ts
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview withFs Mixin for DO Composition
|
|
3
|
-
*
|
|
4
|
-
* This module provides a mixin function that adds filesystem capability
|
|
5
|
-
* to any Durable Object class. The mixin follows the TypeScript mixin pattern
|
|
6
|
-
* and supports lazy initialization of the FsModule.
|
|
7
|
-
*
|
|
8
|
-
* @module do/withFs
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { withFs } from 'gitx.do/do'
|
|
13
|
-
* import { DO } from 'dotdo'
|
|
14
|
-
*
|
|
15
|
-
* // Basic usage with defaults
|
|
16
|
-
* class MyDO extends withFs(DO) {
|
|
17
|
-
* async loadConfig() {
|
|
18
|
-
* const content = await this.fs.readFile('/config.json', { encoding: 'utf-8' })
|
|
19
|
-
* return JSON.parse(content as string)
|
|
20
|
-
* }
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* // With custom options
|
|
24
|
-
* class StorageDO extends withFs(DO, {
|
|
25
|
-
* basePath: '/data',
|
|
26
|
-
* hotMaxSize: 512 * 1024, // 512KB
|
|
27
|
-
* getR2: (instance) => instance.env?.R2_BUCKET
|
|
28
|
-
* }) {
|
|
29
|
-
* async saveFile(name: string, data: string) {
|
|
30
|
-
* await this.fs.writeFile(name, data)
|
|
31
|
-
* }
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
import { FsModule, type FsModuleOptions, type SqlStorage, type R2BucketLike, type Stats, type Dirent, type ReadOptions, type WriteOptions, type MkdirOptions, type RmdirOptions, type RemoveOptions, type ReaddirOptions, type MoveOptions, type CopyOptions } from './FsModule';
|
|
36
|
-
/**
|
|
37
|
-
* Type for a class constructor.
|
|
38
|
-
* Used as the base constraint for mixin composition.
|
|
39
|
-
*/
|
|
40
|
-
export type Constructor<T = object> = new (...args: any[]) => T;
|
|
41
|
-
/**
|
|
42
|
-
* Interface for DOs that have filesystem capability.
|
|
43
|
-
* Classes extended with withFs will implement this interface.
|
|
44
|
-
*/
|
|
45
|
-
export interface WithFsCapability {
|
|
46
|
-
/**
|
|
47
|
-
* The FsModule instance providing filesystem functionality.
|
|
48
|
-
* Lazily initialized on first access.
|
|
49
|
-
*/
|
|
50
|
-
readonly fs: FsModule;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Options for the withFs mixin.
|
|
54
|
-
* These options configure the FsModule that will be created.
|
|
55
|
-
*/
|
|
56
|
-
export interface WithFsOptions {
|
|
57
|
-
/**
|
|
58
|
-
* Base path prefix for all filesystem operations.
|
|
59
|
-
* @default '/'
|
|
60
|
-
*/
|
|
61
|
-
basePath?: string;
|
|
62
|
-
/**
|
|
63
|
-
* Hot tier maximum size in bytes.
|
|
64
|
-
* Files larger than this are stored in R2 when available.
|
|
65
|
-
* @default 1048576 (1MB)
|
|
66
|
-
*/
|
|
67
|
-
hotMaxSize?: number;
|
|
68
|
-
/**
|
|
69
|
-
* Default file mode (permissions).
|
|
70
|
-
* @default 0o644
|
|
71
|
-
*/
|
|
72
|
-
defaultMode?: number;
|
|
73
|
-
/**
|
|
74
|
-
* Default directory mode (permissions).
|
|
75
|
-
* @default 0o755
|
|
76
|
-
*/
|
|
77
|
-
defaultDirMode?: number;
|
|
78
|
-
/**
|
|
79
|
-
* Whether to extend the $ WorkflowContext with fs capability.
|
|
80
|
-
* When true, this.$.fs will be available in addition to this.fs.
|
|
81
|
-
* @default false
|
|
82
|
-
*/
|
|
83
|
-
contextMode?: boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Whether to auto-initialize the FsModule on construction.
|
|
86
|
-
* When false (default), FsModule is lazily initialized on first access.
|
|
87
|
-
* @default false
|
|
88
|
-
*/
|
|
89
|
-
autoInit?: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* Factory function to get the SQL storage from the DO instance.
|
|
92
|
-
* This enables lazy binding of the storage based on the DO's context.
|
|
93
|
-
*
|
|
94
|
-
* @param instance - The DO instance
|
|
95
|
-
* @returns The SqlStorage to use, or undefined if none available
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```typescript
|
|
99
|
-
* withFs(DO, {
|
|
100
|
-
* getSql: (instance) => instance.ctx?.storage?.sql
|
|
101
|
-
* })
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
getSql?: (instance: object) => SqlStorage | undefined;
|
|
105
|
-
/**
|
|
106
|
-
* Factory function to get the R2 bucket for warm tier storage.
|
|
107
|
-
* This enables lazy binding of R2 based on the DO's environment.
|
|
108
|
-
*
|
|
109
|
-
* @param instance - The DO instance
|
|
110
|
-
* @returns The R2 bucket to use, or undefined if none available
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```typescript
|
|
114
|
-
* withFs(DO, {
|
|
115
|
-
* getR2: (instance) => instance.env?.R2_BUCKET
|
|
116
|
-
* })
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
getR2?: (instance: object) => R2BucketLike | undefined;
|
|
120
|
-
/**
|
|
121
|
-
* Factory function to get the archive R2 bucket for cold tier storage.
|
|
122
|
-
*
|
|
123
|
-
* @param instance - The DO instance
|
|
124
|
-
* @returns The archive R2 bucket to use, or undefined if none available
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* ```typescript
|
|
128
|
-
* withFs(DO, {
|
|
129
|
-
* getArchive: (instance) => instance.env?.ARCHIVE_BUCKET
|
|
130
|
-
* })
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
getArchive?: (instance: object) => R2BucketLike | undefined;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Interface for the extended WorkflowContext with fs capability.
|
|
137
|
-
* Used when contextMode is enabled.
|
|
138
|
-
*/
|
|
139
|
-
export interface WithFsContext {
|
|
140
|
-
fs: FsModule;
|
|
141
|
-
[key: string]: unknown;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Mixin function to add filesystem capability to a DO class.
|
|
145
|
-
*
|
|
146
|
-
* @description
|
|
147
|
-
* Composes filesystem functionality into a Durable Object class.
|
|
148
|
-
* The resulting class will have a `fs` property that provides
|
|
149
|
-
* FsModule functionality for POSIX-like file operations.
|
|
150
|
-
*
|
|
151
|
-
* The FsModule is lazily initialized on first access to the `fs`
|
|
152
|
-
* property. This means:
|
|
153
|
-
* - No overhead if filesystem is never used
|
|
154
|
-
* - Factory functions (getSql, getR2, getArchive) are called at first access
|
|
155
|
-
* - The module can be properly initialized with DO-specific context
|
|
156
|
-
*
|
|
157
|
-
* The mixin supports:
|
|
158
|
-
* - File operations: readFile, writeFile, appendFile, unlink, rename, copyFile
|
|
159
|
-
* - Directory operations: mkdir, rmdir, readdir, rm
|
|
160
|
-
* - Metadata operations: stat, lstat, exists, access, chmod, chown, utimes
|
|
161
|
-
* - Symbolic links: symlink, link, readlink, realpath
|
|
162
|
-
* - Tiered storage: promote, demote, getTier
|
|
163
|
-
*
|
|
164
|
-
* @param Base - Base class to extend
|
|
165
|
-
* @param options - Filesystem configuration options (optional)
|
|
166
|
-
* @returns Extended class with filesystem capability
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```typescript
|
|
170
|
-
* import { withFs } from 'gitx.do/do'
|
|
171
|
-
* import { DO } from 'dotdo'
|
|
172
|
-
*
|
|
173
|
-
* // Basic usage with defaults
|
|
174
|
-
* class MyDO extends withFs(DO) {
|
|
175
|
-
* async loadConfig() {
|
|
176
|
-
* const content = await this.fs.readFile('/config.json', { encoding: 'utf-8' })
|
|
177
|
-
* return JSON.parse(content as string)
|
|
178
|
-
* }
|
|
179
|
-
* }
|
|
180
|
-
*
|
|
181
|
-
* // With custom options and lazy binding
|
|
182
|
-
* class StorageDO extends withFs(DO, {
|
|
183
|
-
* basePath: '/data',
|
|
184
|
-
* hotMaxSize: 512 * 1024,
|
|
185
|
-
* getSql: (instance) => (instance as any).ctx?.storage?.sql,
|
|
186
|
-
* getR2: (instance) => (instance as any).env?.R2_BUCKET
|
|
187
|
-
* }) {
|
|
188
|
-
* async saveDocument(name: string, content: string) {
|
|
189
|
-
* await this.fs.mkdir('/documents', { recursive: true })
|
|
190
|
-
* await this.fs.writeFile(`/documents/${name}`, content)
|
|
191
|
-
* }
|
|
192
|
-
* }
|
|
193
|
-
* ```
|
|
194
|
-
*
|
|
195
|
-
* @example
|
|
196
|
-
* ```typescript
|
|
197
|
-
* // Combining with withGit and withBash
|
|
198
|
-
* import { withGit, withBash, withFs } from 'gitx.do/do'
|
|
199
|
-
* import { DO } from 'dotdo'
|
|
200
|
-
*
|
|
201
|
-
* class DevDO extends withFs(withBash(withGit(DO, { repo: 'org/repo' }), {
|
|
202
|
-
* cwd: '/workspace'
|
|
203
|
-
* })) {
|
|
204
|
-
* async setupProject() {
|
|
205
|
-
* // Sync git repository
|
|
206
|
-
* await this.git.sync()
|
|
207
|
-
*
|
|
208
|
-
* // Create workspace directories
|
|
209
|
-
* await this.fs.mkdir('/workspace/output', { recursive: true })
|
|
210
|
-
*
|
|
211
|
-
* // Run build commands
|
|
212
|
-
* await this.bash.exec('npm', ['run', 'build'])
|
|
213
|
-
*
|
|
214
|
-
* // Read build output
|
|
215
|
-
* const files = await this.fs.readdir('/workspace/output')
|
|
216
|
-
* return files
|
|
217
|
-
* }
|
|
218
|
-
* }
|
|
219
|
-
* ```
|
|
220
|
-
*/
|
|
221
|
-
export declare function withFs<TBase extends Constructor>(Base: TBase, options?: WithFsOptions): TBase & Constructor<WithFsCapability>;
|
|
222
|
-
/**
|
|
223
|
-
* Check if a value has filesystem capability.
|
|
224
|
-
*
|
|
225
|
-
* @param value - Value to check
|
|
226
|
-
* @returns True if value has the fs property and it's an FsModule
|
|
227
|
-
*
|
|
228
|
-
* @example
|
|
229
|
-
* ```typescript
|
|
230
|
-
* if (hasFsCapability(instance)) {
|
|
231
|
-
* const content = await instance.fs.readFile('/config.json')
|
|
232
|
-
* }
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
export declare function hasFsCapability(value: unknown): value is WithFsCapability;
|
|
236
|
-
export { FsModule, type FsModuleOptions, type SqlStorage, type R2BucketLike, type Stats, type Dirent, type ReadOptions, type WriteOptions, type MkdirOptions, type RmdirOptions, type RemoveOptions, type ReaddirOptions, type MoveOptions, type CopyOptions, };
|
|
237
|
-
//# sourceMappingURL=withFs.d.ts.map
|
package/dist/do/withFs.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withFs.d.ts","sourceRoot":"","sources":["../../src/do/withFs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EACL,QAAQ,EACR,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,WAAW,EACjB,MAAM,YAAY,CAAA;AAMnB;;;GAGG;AAEH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,MAAM,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;AAE/D;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAA;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;;OAIG;IACH,UAAU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ClB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,WAAW,GACjB,CAAA"}
|
package/dist/do/withFs.js
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview withFs Mixin for DO Composition
|
|
3
|
-
*
|
|
4
|
-
* This module provides a mixin function that adds filesystem capability
|
|
5
|
-
* to any Durable Object class. The mixin follows the TypeScript mixin pattern
|
|
6
|
-
* and supports lazy initialization of the FsModule.
|
|
7
|
-
*
|
|
8
|
-
* @module do/withFs
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { withFs } from 'gitx.do/do'
|
|
13
|
-
* import { DO } from 'dotdo'
|
|
14
|
-
*
|
|
15
|
-
* // Basic usage with defaults
|
|
16
|
-
* class MyDO extends withFs(DO) {
|
|
17
|
-
* async loadConfig() {
|
|
18
|
-
* const content = await this.fs.readFile('/config.json', { encoding: 'utf-8' })
|
|
19
|
-
* return JSON.parse(content as string)
|
|
20
|
-
* }
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* // With custom options
|
|
24
|
-
* class StorageDO extends withFs(DO, {
|
|
25
|
-
* basePath: '/data',
|
|
26
|
-
* hotMaxSize: 512 * 1024, // 512KB
|
|
27
|
-
* getR2: (instance) => instance.env?.R2_BUCKET
|
|
28
|
-
* }) {
|
|
29
|
-
* async saveFile(name: string, data: string) {
|
|
30
|
-
* await this.fs.writeFile(name, data)
|
|
31
|
-
* }
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
import { FsModule, } from './FsModule';
|
|
36
|
-
// ============================================================================
|
|
37
|
-
// Mixin Implementation
|
|
38
|
-
// ============================================================================
|
|
39
|
-
/**
|
|
40
|
-
* Symbol used to store the FsModule instance for lazy initialization.
|
|
41
|
-
* Using a symbol prevents name collisions with user-defined properties.
|
|
42
|
-
*/
|
|
43
|
-
const FS_MODULE_SYMBOL = Symbol('fsModule');
|
|
44
|
-
/**
|
|
45
|
-
* Symbol used to store the options for lazy initialization.
|
|
46
|
-
*/
|
|
47
|
-
const FS_OPTIONS_SYMBOL = Symbol('fsOptions');
|
|
48
|
-
/**
|
|
49
|
-
* Symbol to track if the module has been initialized.
|
|
50
|
-
*/
|
|
51
|
-
const FS_INITIALIZED_SYMBOL = Symbol('fsInitialized');
|
|
52
|
-
/**
|
|
53
|
-
* Mixin function to add filesystem capability to a DO class.
|
|
54
|
-
*
|
|
55
|
-
* @description
|
|
56
|
-
* Composes filesystem functionality into a Durable Object class.
|
|
57
|
-
* The resulting class will have a `fs` property that provides
|
|
58
|
-
* FsModule functionality for POSIX-like file operations.
|
|
59
|
-
*
|
|
60
|
-
* The FsModule is lazily initialized on first access to the `fs`
|
|
61
|
-
* property. This means:
|
|
62
|
-
* - No overhead if filesystem is never used
|
|
63
|
-
* - Factory functions (getSql, getR2, getArchive) are called at first access
|
|
64
|
-
* - The module can be properly initialized with DO-specific context
|
|
65
|
-
*
|
|
66
|
-
* The mixin supports:
|
|
67
|
-
* - File operations: readFile, writeFile, appendFile, unlink, rename, copyFile
|
|
68
|
-
* - Directory operations: mkdir, rmdir, readdir, rm
|
|
69
|
-
* - Metadata operations: stat, lstat, exists, access, chmod, chown, utimes
|
|
70
|
-
* - Symbolic links: symlink, link, readlink, realpath
|
|
71
|
-
* - Tiered storage: promote, demote, getTier
|
|
72
|
-
*
|
|
73
|
-
* @param Base - Base class to extend
|
|
74
|
-
* @param options - Filesystem configuration options (optional)
|
|
75
|
-
* @returns Extended class with filesystem capability
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```typescript
|
|
79
|
-
* import { withFs } from 'gitx.do/do'
|
|
80
|
-
* import { DO } from 'dotdo'
|
|
81
|
-
*
|
|
82
|
-
* // Basic usage with defaults
|
|
83
|
-
* class MyDO extends withFs(DO) {
|
|
84
|
-
* async loadConfig() {
|
|
85
|
-
* const content = await this.fs.readFile('/config.json', { encoding: 'utf-8' })
|
|
86
|
-
* return JSON.parse(content as string)
|
|
87
|
-
* }
|
|
88
|
-
* }
|
|
89
|
-
*
|
|
90
|
-
* // With custom options and lazy binding
|
|
91
|
-
* class StorageDO extends withFs(DO, {
|
|
92
|
-
* basePath: '/data',
|
|
93
|
-
* hotMaxSize: 512 * 1024,
|
|
94
|
-
* getSql: (instance) => (instance as any).ctx?.storage?.sql,
|
|
95
|
-
* getR2: (instance) => (instance as any).env?.R2_BUCKET
|
|
96
|
-
* }) {
|
|
97
|
-
* async saveDocument(name: string, content: string) {
|
|
98
|
-
* await this.fs.mkdir('/documents', { recursive: true })
|
|
99
|
-
* await this.fs.writeFile(`/documents/${name}`, content)
|
|
100
|
-
* }
|
|
101
|
-
* }
|
|
102
|
-
* ```
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```typescript
|
|
106
|
-
* // Combining with withGit and withBash
|
|
107
|
-
* import { withGit, withBash, withFs } from 'gitx.do/do'
|
|
108
|
-
* import { DO } from 'dotdo'
|
|
109
|
-
*
|
|
110
|
-
* class DevDO extends withFs(withBash(withGit(DO, { repo: 'org/repo' }), {
|
|
111
|
-
* cwd: '/workspace'
|
|
112
|
-
* })) {
|
|
113
|
-
* async setupProject() {
|
|
114
|
-
* // Sync git repository
|
|
115
|
-
* await this.git.sync()
|
|
116
|
-
*
|
|
117
|
-
* // Create workspace directories
|
|
118
|
-
* await this.fs.mkdir('/workspace/output', { recursive: true })
|
|
119
|
-
*
|
|
120
|
-
* // Run build commands
|
|
121
|
-
* await this.bash.exec('npm', ['run', 'build'])
|
|
122
|
-
*
|
|
123
|
-
* // Read build output
|
|
124
|
-
* const files = await this.fs.readdir('/workspace/output')
|
|
125
|
-
* return files
|
|
126
|
-
* }
|
|
127
|
-
* }
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
export function withFs(Base, options = {}) {
|
|
131
|
-
// Create the extended class
|
|
132
|
-
class WithFsClass extends Base {
|
|
133
|
-
/**
|
|
134
|
-
* Static list of capabilities for introspection.
|
|
135
|
-
*/
|
|
136
|
-
static capabilities = [...(Base.capabilities || []), 'fs'];
|
|
137
|
-
/**
|
|
138
|
-
* Internal storage for the lazily initialized FsModule.
|
|
139
|
-
*/
|
|
140
|
-
[FS_MODULE_SYMBOL];
|
|
141
|
-
/**
|
|
142
|
-
* Internal storage for the options.
|
|
143
|
-
*/
|
|
144
|
-
[FS_OPTIONS_SYMBOL];
|
|
145
|
-
/**
|
|
146
|
-
* Tracks whether initialization has been attempted.
|
|
147
|
-
*/
|
|
148
|
-
[FS_INITIALIZED_SYMBOL] = false;
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
150
|
-
constructor(...args) {
|
|
151
|
-
super(...args);
|
|
152
|
-
this[FS_OPTIONS_SYMBOL] = options;
|
|
153
|
-
// Extend $ context if contextMode is enabled
|
|
154
|
-
if (options.contextMode) {
|
|
155
|
-
const dollarContext = this.$;
|
|
156
|
-
if (dollarContext) {
|
|
157
|
-
const self = this;
|
|
158
|
-
this.$ = new Proxy(dollarContext, {
|
|
159
|
-
get(target, prop) {
|
|
160
|
-
if (prop === 'fs') {
|
|
161
|
-
return self.fs;
|
|
162
|
-
}
|
|
163
|
-
// Forward to original context
|
|
164
|
-
const value = target[prop];
|
|
165
|
-
if (typeof value === 'function') {
|
|
166
|
-
return value.bind(target);
|
|
167
|
-
}
|
|
168
|
-
return value;
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
// Auto-initialize if requested
|
|
174
|
-
if (options.autoInit) {
|
|
175
|
-
// Access fs to trigger lazy initialization
|
|
176
|
-
void this.fs.initialize();
|
|
177
|
-
this[FS_INITIALIZED_SYMBOL] = true;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Get the FsModule instance, creating it lazily on first access.
|
|
182
|
-
*
|
|
183
|
-
* @returns The FsModule instance
|
|
184
|
-
*/
|
|
185
|
-
get fs() {
|
|
186
|
-
if (!this[FS_MODULE_SYMBOL]) {
|
|
187
|
-
this[FS_MODULE_SYMBOL] = this._createFsModule();
|
|
188
|
-
}
|
|
189
|
-
return this[FS_MODULE_SYMBOL];
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Create the FsModule instance with resolved options.
|
|
193
|
-
*
|
|
194
|
-
* @returns A new FsModule instance
|
|
195
|
-
* @private
|
|
196
|
-
*/
|
|
197
|
-
_createFsModule() {
|
|
198
|
-
const opts = this[FS_OPTIONS_SYMBOL];
|
|
199
|
-
// Resolve SQL storage
|
|
200
|
-
let sql;
|
|
201
|
-
if (opts.getSql) {
|
|
202
|
-
sql = opts.getSql(this);
|
|
203
|
-
}
|
|
204
|
-
// If no SQL factory provided, try common patterns
|
|
205
|
-
if (!sql) {
|
|
206
|
-
const ctx = this.ctx;
|
|
207
|
-
const state = this.state;
|
|
208
|
-
// Try ctx.storage.sql (dotdo pattern)
|
|
209
|
-
sql = ctx?.storage?.sql;
|
|
210
|
-
// Try state.storage.sql (CF DO pattern)
|
|
211
|
-
if (!sql) {
|
|
212
|
-
sql = state?.storage?.sql;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
// Create a mock SQL storage if none available (for testing)
|
|
216
|
-
if (!sql) {
|
|
217
|
-
sql = createMockSqlStorage();
|
|
218
|
-
}
|
|
219
|
-
// Resolve R2 if factory provided
|
|
220
|
-
let r2;
|
|
221
|
-
if (opts.getR2) {
|
|
222
|
-
r2 = opts.getR2(this);
|
|
223
|
-
}
|
|
224
|
-
// Resolve archive if factory provided
|
|
225
|
-
let archive;
|
|
226
|
-
if (opts.getArchive) {
|
|
227
|
-
archive = opts.getArchive(this);
|
|
228
|
-
}
|
|
229
|
-
// Build module options
|
|
230
|
-
const moduleOptions = {
|
|
231
|
-
sql,
|
|
232
|
-
r2,
|
|
233
|
-
archive,
|
|
234
|
-
basePath: opts.basePath,
|
|
235
|
-
hotMaxSize: opts.hotMaxSize,
|
|
236
|
-
defaultMode: opts.defaultMode,
|
|
237
|
-
defaultDirMode: opts.defaultDirMode,
|
|
238
|
-
};
|
|
239
|
-
return new FsModule(moduleOptions);
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Check if this DO class has a specific capability.
|
|
243
|
-
* @param name - Capability name to check
|
|
244
|
-
* @returns True if the capability is available
|
|
245
|
-
*/
|
|
246
|
-
hasCapability(name) {
|
|
247
|
-
if (name === 'fs')
|
|
248
|
-
return true;
|
|
249
|
-
// Check if parent class has the hasCapability method
|
|
250
|
-
const baseProto = Base.prototype;
|
|
251
|
-
if (baseProto && typeof baseProto.hasCapability === 'function') {
|
|
252
|
-
return baseProto.hasCapability.call(this, name);
|
|
253
|
-
}
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Initialize the filesystem module asynchronously.
|
|
258
|
-
* This should be called if you need the schema to be created before operations.
|
|
259
|
-
*
|
|
260
|
-
* @returns Promise that resolves when initialization is complete
|
|
261
|
-
*/
|
|
262
|
-
async initializeFs() {
|
|
263
|
-
if (this[FS_INITIALIZED_SYMBOL])
|
|
264
|
-
return;
|
|
265
|
-
// Ensure fs module is created
|
|
266
|
-
const fs = this.fs;
|
|
267
|
-
// Initialize the module
|
|
268
|
-
await fs.initialize();
|
|
269
|
-
this[FS_INITIALIZED_SYMBOL] = true;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Dispose the filesystem module and clean up resources.
|
|
273
|
-
*/
|
|
274
|
-
async disposeFs() {
|
|
275
|
-
if (this[FS_MODULE_SYMBOL]) {
|
|
276
|
-
await this[FS_MODULE_SYMBOL].dispose();
|
|
277
|
-
this[FS_MODULE_SYMBOL] = undefined;
|
|
278
|
-
this[FS_INITIALIZED_SYMBOL] = false;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
// Return the class with proper typing
|
|
283
|
-
return WithFsClass;
|
|
284
|
-
}
|
|
285
|
-
// ============================================================================
|
|
286
|
-
// Mock SQL Storage for Testing
|
|
287
|
-
// ============================================================================
|
|
288
|
-
/**
|
|
289
|
-
* Creates a simple in-memory mock SQL storage for testing.
|
|
290
|
-
* This allows withFs to work even without a real Durable Object context.
|
|
291
|
-
*/
|
|
292
|
-
function createMockSqlStorage() {
|
|
293
|
-
const tables = new Map();
|
|
294
|
-
let idCounter = 1;
|
|
295
|
-
return {
|
|
296
|
-
exec(sql, ...params) {
|
|
297
|
-
// Simple parsing for basic operations
|
|
298
|
-
const sqlLower = sql.toLowerCase().trim();
|
|
299
|
-
if (sqlLower.startsWith('create table')) {
|
|
300
|
-
// Table creation - no-op in mock
|
|
301
|
-
return {
|
|
302
|
-
one: () => null,
|
|
303
|
-
toArray: () => [],
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
if (sqlLower.startsWith('create index')) {
|
|
307
|
-
// Index creation - no-op in mock
|
|
308
|
-
return {
|
|
309
|
-
one: () => null,
|
|
310
|
-
toArray: () => [],
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
if (sqlLower.startsWith('insert')) {
|
|
314
|
-
// Handle INSERT
|
|
315
|
-
const match = sql.match(/INSERT.*INTO\s+(\w+)/i);
|
|
316
|
-
const tableName = match?.[1] || 'unknown';
|
|
317
|
-
if (!tables.has(tableName)) {
|
|
318
|
-
tables.set(tableName, []);
|
|
319
|
-
}
|
|
320
|
-
const table = tables.get(tableName);
|
|
321
|
-
const id = idCounter++;
|
|
322
|
-
const row = { id, ...Object.fromEntries(params.map((p, i) => [`param${i}`, p])) };
|
|
323
|
-
table.push(row);
|
|
324
|
-
return {
|
|
325
|
-
one: () => row,
|
|
326
|
-
toArray: () => [row],
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
if (sqlLower.startsWith('select')) {
|
|
330
|
-
// Handle SELECT
|
|
331
|
-
const match = sql.match(/FROM\s+(\w+)/i);
|
|
332
|
-
const tableName = match?.[1] || 'unknown';
|
|
333
|
-
const table = tables.get(tableName) || [];
|
|
334
|
-
return {
|
|
335
|
-
one: () => table[0] || null,
|
|
336
|
-
toArray: () => table,
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
if (sqlLower.startsWith('update')) {
|
|
340
|
-
// Handle UPDATE - simplified
|
|
341
|
-
return {
|
|
342
|
-
one: () => null,
|
|
343
|
-
toArray: () => [],
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
if (sqlLower.startsWith('delete')) {
|
|
347
|
-
// Handle DELETE - simplified
|
|
348
|
-
return {
|
|
349
|
-
one: () => null,
|
|
350
|
-
toArray: () => [],
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
// Default fallback
|
|
354
|
-
return {
|
|
355
|
-
one: () => null,
|
|
356
|
-
toArray: () => [],
|
|
357
|
-
};
|
|
358
|
-
},
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
// ============================================================================
|
|
362
|
-
// Type Guards
|
|
363
|
-
// ============================================================================
|
|
364
|
-
/**
|
|
365
|
-
* Check if a value has filesystem capability.
|
|
366
|
-
*
|
|
367
|
-
* @param value - Value to check
|
|
368
|
-
* @returns True if value has the fs property and it's an FsModule
|
|
369
|
-
*
|
|
370
|
-
* @example
|
|
371
|
-
* ```typescript
|
|
372
|
-
* if (hasFsCapability(instance)) {
|
|
373
|
-
* const content = await instance.fs.readFile('/config.json')
|
|
374
|
-
* }
|
|
375
|
-
* ```
|
|
376
|
-
*/
|
|
377
|
-
export function hasFsCapability(value) {
|
|
378
|
-
return (typeof value === 'object' &&
|
|
379
|
-
value !== null &&
|
|
380
|
-
'fs' in value &&
|
|
381
|
-
value.fs instanceof FsModule);
|
|
382
|
-
}
|
|
383
|
-
// ============================================================================
|
|
384
|
-
// Re-exports for Convenience
|
|
385
|
-
// ============================================================================
|
|
386
|
-
export { FsModule, };
|
|
387
|
-
//# sourceMappingURL=withFs.js.map
|
package/dist/do/withFs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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