gitx.do 0.0.3 → 0.1.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.
Files changed (150) hide show
  1. package/README.md +319 -92
  2. package/dist/cli/commands/add.d.ts +174 -0
  3. package/dist/cli/commands/add.d.ts.map +1 -0
  4. package/dist/cli/commands/add.js +131 -0
  5. package/dist/cli/commands/add.js.map +1 -0
  6. package/dist/cli/commands/merge.d.ts +106 -0
  7. package/dist/cli/commands/merge.d.ts.map +1 -0
  8. package/dist/cli/commands/merge.js +55 -0
  9. package/dist/cli/commands/merge.js.map +1 -0
  10. package/dist/cli/fsx-cli-adapter.d.ts +359 -0
  11. package/dist/cli/fsx-cli-adapter.d.ts.map +1 -0
  12. package/dist/cli/fsx-cli-adapter.js +619 -0
  13. package/dist/cli/fsx-cli-adapter.js.map +1 -0
  14. package/dist/cli/index.js +0 -0
  15. package/dist/do/BashModule.d.ts +871 -0
  16. package/dist/do/BashModule.d.ts.map +1 -0
  17. package/dist/do/BashModule.js +1143 -0
  18. package/dist/do/BashModule.js.map +1 -0
  19. package/dist/do/FsModule.d.ts +601 -0
  20. package/dist/do/FsModule.d.ts.map +1 -0
  21. package/dist/do/FsModule.js +1120 -0
  22. package/dist/do/FsModule.js.map +1 -0
  23. package/dist/do/GitModule.d.ts +635 -0
  24. package/dist/do/GitModule.d.ts.map +1 -0
  25. package/dist/do/GitModule.js +781 -0
  26. package/dist/do/GitModule.js.map +1 -0
  27. package/dist/do/GitRepoDO.d.ts +281 -0
  28. package/dist/do/GitRepoDO.d.ts.map +1 -0
  29. package/dist/do/GitRepoDO.js +479 -0
  30. package/dist/do/GitRepoDO.js.map +1 -0
  31. package/dist/do/bash-ast.d.ts +246 -0
  32. package/dist/do/bash-ast.d.ts.map +1 -0
  33. package/dist/do/bash-ast.js +888 -0
  34. package/dist/do/bash-ast.js.map +1 -0
  35. package/dist/do/container-executor.d.ts +491 -0
  36. package/dist/do/container-executor.d.ts.map +1 -0
  37. package/dist/do/container-executor.js +730 -0
  38. package/dist/do/container-executor.js.map +1 -0
  39. package/dist/do/index.d.ts +53 -0
  40. package/dist/do/index.d.ts.map +1 -0
  41. package/dist/do/index.js +91 -0
  42. package/dist/do/index.js.map +1 -0
  43. package/dist/do/tiered-storage.d.ts +403 -0
  44. package/dist/do/tiered-storage.d.ts.map +1 -0
  45. package/dist/do/tiered-storage.js +689 -0
  46. package/dist/do/tiered-storage.js.map +1 -0
  47. package/dist/do/withBash.d.ts +231 -0
  48. package/dist/do/withBash.d.ts.map +1 -0
  49. package/dist/do/withBash.js +244 -0
  50. package/dist/do/withBash.js.map +1 -0
  51. package/dist/do/withFs.d.ts +237 -0
  52. package/dist/do/withFs.d.ts.map +1 -0
  53. package/dist/do/withFs.js +387 -0
  54. package/dist/do/withFs.js.map +1 -0
  55. package/dist/do/withGit.d.ts +180 -0
  56. package/dist/do/withGit.d.ts.map +1 -0
  57. package/dist/do/withGit.js +271 -0
  58. package/dist/do/withGit.js.map +1 -0
  59. package/dist/durable-object/object-store.d.ts +157 -15
  60. package/dist/durable-object/object-store.d.ts.map +1 -1
  61. package/dist/durable-object/object-store.js +432 -47
  62. package/dist/durable-object/object-store.js.map +1 -1
  63. package/dist/durable-object/schema.d.ts +12 -1
  64. package/dist/durable-object/schema.d.ts.map +1 -1
  65. package/dist/durable-object/schema.js +87 -2
  66. package/dist/durable-object/schema.js.map +1 -1
  67. package/dist/index.d.ts +29 -1
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +34 -0
  70. package/dist/index.js.map +1 -1
  71. package/dist/mcp/sandbox/miniflare-evaluator.d.ts +22 -0
  72. package/dist/mcp/sandbox/miniflare-evaluator.d.ts.map +1 -0
  73. package/dist/mcp/sandbox/miniflare-evaluator.js +140 -0
  74. package/dist/mcp/sandbox/miniflare-evaluator.js.map +1 -0
  75. package/dist/mcp/sandbox/object-store-proxy.d.ts +32 -0
  76. package/dist/mcp/sandbox/object-store-proxy.d.ts.map +1 -0
  77. package/dist/mcp/sandbox/object-store-proxy.js +30 -0
  78. package/dist/mcp/sandbox/object-store-proxy.js.map +1 -0
  79. package/dist/mcp/sandbox/template.d.ts +17 -0
  80. package/dist/mcp/sandbox/template.d.ts.map +1 -0
  81. package/dist/mcp/sandbox/template.js +71 -0
  82. package/dist/mcp/sandbox/template.js.map +1 -0
  83. package/dist/mcp/sandbox.d.ts.map +1 -1
  84. package/dist/mcp/sandbox.js +16 -4
  85. package/dist/mcp/sandbox.js.map +1 -1
  86. package/dist/mcp/tools/do.d.ts +32 -0
  87. package/dist/mcp/tools/do.d.ts.map +1 -0
  88. package/dist/mcp/tools/do.js +115 -0
  89. package/dist/mcp/tools/do.js.map +1 -0
  90. package/dist/pack/delta.d.ts +8 -0
  91. package/dist/pack/delta.d.ts.map +1 -1
  92. package/dist/pack/delta.js +236 -29
  93. package/dist/pack/delta.js.map +1 -1
  94. package/dist/refs/branch.d.ts +22 -24
  95. package/dist/refs/branch.d.ts.map +1 -1
  96. package/dist/refs/branch.js +409 -66
  97. package/dist/refs/branch.js.map +1 -1
  98. package/dist/refs/storage.d.ts +77 -5
  99. package/dist/refs/storage.d.ts.map +1 -1
  100. package/dist/refs/storage.js +193 -43
  101. package/dist/refs/storage.js.map +1 -1
  102. package/dist/refs/tag.d.ts +44 -24
  103. package/dist/refs/tag.d.ts.map +1 -1
  104. package/dist/refs/tag.js +411 -70
  105. package/dist/refs/tag.js.map +1 -1
  106. package/dist/storage/backend.d.ts +425 -0
  107. package/dist/storage/backend.d.ts.map +1 -0
  108. package/dist/storage/backend.js +41 -0
  109. package/dist/storage/backend.js.map +1 -0
  110. package/dist/storage/fsx-adapter.d.ts +204 -0
  111. package/dist/storage/fsx-adapter.d.ts.map +1 -0
  112. package/dist/storage/fsx-adapter.js +470 -0
  113. package/dist/storage/fsx-adapter.js.map +1 -0
  114. package/dist/types/capability.d.ts +1385 -0
  115. package/dist/types/capability.d.ts.map +1 -0
  116. package/dist/types/capability.js +36 -0
  117. package/dist/types/capability.js.map +1 -0
  118. package/dist/types/index.d.ts +13 -0
  119. package/dist/types/index.d.ts.map +1 -0
  120. package/dist/types/index.js +18 -0
  121. package/dist/types/index.js.map +1 -0
  122. package/dist/types/objects.d.ts +182 -0
  123. package/dist/types/objects.d.ts.map +1 -1
  124. package/dist/types/objects.js +249 -4
  125. package/dist/types/objects.js.map +1 -1
  126. package/dist/types/storage.d.ts +114 -0
  127. package/dist/types/storage.d.ts.map +1 -1
  128. package/dist/types/storage.js +160 -1
  129. package/dist/types/storage.js.map +1 -1
  130. package/dist/types/worker-loader.d.ts +60 -0
  131. package/dist/types/worker-loader.d.ts.map +1 -0
  132. package/dist/types/worker-loader.js +62 -0
  133. package/dist/types/worker-loader.js.map +1 -0
  134. package/dist/utils/hash.d.ts +125 -80
  135. package/dist/utils/hash.d.ts.map +1 -1
  136. package/dist/utils/hash.js +187 -100
  137. package/dist/utils/hash.js.map +1 -1
  138. package/dist/utils/sha1.d.ts +171 -0
  139. package/dist/utils/sha1.d.ts.map +1 -1
  140. package/dist/utils/sha1.js +352 -0
  141. package/dist/utils/sha1.js.map +1 -1
  142. package/dist/wire/path-security.d.ts +157 -0
  143. package/dist/wire/path-security.d.ts.map +1 -0
  144. package/dist/wire/path-security.js +307 -0
  145. package/dist/wire/path-security.js.map +1 -0
  146. package/dist/wire/receive-pack.d.ts +7 -0
  147. package/dist/wire/receive-pack.d.ts.map +1 -1
  148. package/dist/wire/receive-pack.js +29 -1
  149. package/dist/wire/receive-pack.js.map +1 -1
  150. package/package.json +10 -1
@@ -0,0 +1,180 @@
1
+ /**
2
+ * @fileoverview withGit Mixin Function for DO Composition
3
+ *
4
+ * This module provides a mixin function that adds git capability to any
5
+ * Durable Object class. The mixin supports lazy initialization of the
6
+ * GitModule for optimal performance.
7
+ *
8
+ * @module do/withGit
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { withGit } from 'gitx.do/do'
13
+ * import { DO } from 'dotdo'
14
+ *
15
+ * // Basic usage - adds this.git property
16
+ * class MyDO extends withGit(DO, { repo: 'org/repo' }) {
17
+ * async handleRequest() {
18
+ * await this.git.sync()
19
+ * const status = await this.git.status()
20
+ * return new Response(JSON.stringify(status))
21
+ * }
22
+ * }
23
+ *
24
+ * // With $.git context integration
25
+ * class WorkflowDO extends withGit(DO, {
26
+ * repo: 'org/repo',
27
+ * contextMode: true
28
+ * }) {
29
+ * async handleRequest() {
30
+ * // Access via $.git when contextMode is enabled
31
+ * await this.$.git.sync()
32
+ * }
33
+ * }
34
+ * ```
35
+ */
36
+ import { GitModule, type GitModuleOptions, type GitBinding, type GitStatus, type SyncResult, type PushResult, type FsCapability, type R2BucketLike } from './GitModule';
37
+ /**
38
+ * Type for a class constructor.
39
+ * @template T - The type that the constructor creates
40
+ */
41
+ export type Constructor<T = object> = new (...args: any[]) => T;
42
+ /**
43
+ * Interface for DOs that have git capability.
44
+ * This is the shape of a class after applying the withGit mixin.
45
+ */
46
+ export interface WithGitCapability {
47
+ /** The GitModule instance providing git operations */
48
+ git: GitModule;
49
+ }
50
+ /**
51
+ * Interface for the extended WorkflowContext with git capability.
52
+ * Used when contextMode is enabled.
53
+ */
54
+ export interface WithGitContext {
55
+ git: GitModule;
56
+ [key: string]: unknown;
57
+ }
58
+ /**
59
+ * Configuration options for the withGit mixin.
60
+ */
61
+ export interface WithGitOptions {
62
+ /**
63
+ * Repository identifier (e.g., 'org/repo' or full URL)
64
+ */
65
+ repo: string;
66
+ /**
67
+ * Branch to track
68
+ * @default 'main'
69
+ */
70
+ branch?: string;
71
+ /**
72
+ * Path prefix within the repository
73
+ */
74
+ path?: string;
75
+ /**
76
+ * R2 binding name in env to use for object storage
77
+ * @default 'R2_BUCKET'
78
+ */
79
+ r2Binding?: string;
80
+ /**
81
+ * Custom object key prefix in R2
82
+ * @default 'git/objects'
83
+ */
84
+ objectPrefix?: string;
85
+ /**
86
+ * Whether to extend the $ WorkflowContext with git capability.
87
+ * When true, this.$.git will be available in addition to this.git.
88
+ * @default false
89
+ */
90
+ contextMode?: boolean;
91
+ /**
92
+ * Whether to auto-initialize the GitModule on construction.
93
+ * When false (default), GitModule is lazily initialized on first access.
94
+ * @default false
95
+ */
96
+ autoInit?: boolean;
97
+ }
98
+ /**
99
+ * Mixin function to add git capability to a DO class.
100
+ *
101
+ * @description
102
+ * Composes git functionality into a Durable Object class using the mixin pattern.
103
+ * The resulting class will have a `git` property that provides GitModule functionality.
104
+ *
105
+ * Features:
106
+ * - Lazy initialization: GitModule is only created when first accessed
107
+ * - R2 integration: Automatically resolves R2 bucket from env bindings
108
+ * - Context mode: Optionally extends the $ WorkflowContext with git capability
109
+ * - Composable: Can be combined with other mixins like withBash
110
+ *
111
+ * @param Base - Base class to extend
112
+ * @param options - Git configuration options
113
+ * @returns Extended class with git capability
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * // Basic usage
118
+ * import { withGit } from 'gitx.do/do'
119
+ * import { DO } from 'dotdo'
120
+ *
121
+ * class MyDO extends withGit(DO, { repo: 'org/repo' }) {
122
+ * async syncAndCommit() {
123
+ * await this.git.sync()
124
+ * await this.git.add('.')
125
+ * await this.git.commit('Update files')
126
+ * await this.git.push()
127
+ * }
128
+ * }
129
+ * ```
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * // With custom R2 binding
134
+ * class MyDO extends withGit(DO, {
135
+ * repo: 'org/repo',
136
+ * branch: 'develop',
137
+ * r2Binding: 'GIT_OBJECTS'
138
+ * }) {
139
+ * async handleRequest() {
140
+ * await this.git.sync()
141
+ * return new Response('Synced!')
142
+ * }
143
+ * }
144
+ * ```
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // Composing with other mixins
149
+ * import { withGit, withBash } from 'gitx.do/do'
150
+ *
151
+ * class DevDO extends withBash(withGit(DO, { repo: 'org/repo' }), {
152
+ * cwd: '/workspace'
153
+ * }) {
154
+ * async buildAndPush() {
155
+ * await this.git.sync()
156
+ * await this.bash.exec('npm', ['run', 'build'])
157
+ * await this.git.add('dist/')
158
+ * await this.git.commit('Build: update dist')
159
+ * await this.git.push()
160
+ * }
161
+ * }
162
+ * ```
163
+ */
164
+ export declare function withGit<TBase extends Constructor>(Base: TBase, options: WithGitOptions): TBase & Constructor<WithGitCapability>;
165
+ /**
166
+ * Check if a value has git capability.
167
+ *
168
+ * @param value - Value to check
169
+ * @returns True if value has the git property and it's a GitModule
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * if (hasGitCapability(instance)) {
174
+ * await instance.git.sync()
175
+ * }
176
+ * ```
177
+ */
178
+ export declare function hasGitCapability(value: unknown): value is WithGitCapability;
179
+ export { GitModule, type GitModuleOptions, type GitBinding, type GitStatus, type SyncResult, type PushResult, type FsCapability, type R2BucketLike, };
180
+ //# sourceMappingURL=withGit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withGit.d.ts","sourceRoot":"","sources":["../../src/do/withGit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EACL,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,aAAa,CAAA;AAMpB;;;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,iBAAiB;IAChC,sDAAsD;IACtD,GAAG,EAAE,SAAS,CAAA;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,SAAS,CAAA;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IAErB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AA8BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,wBAAgB,OAAO,CAAC,KAAK,SAAS,WAAW,EAC/C,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,cAAc,GACtB,KAAK,GAAG,WAAW,CAAC,iBAAiB,CAAC,CA+IxC;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAO3E;AAMD,OAAO,EACL,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,YAAY,GAClB,CAAA"}
@@ -0,0 +1,271 @@
1
+ /**
2
+ * @fileoverview withGit Mixin Function for DO Composition
3
+ *
4
+ * This module provides a mixin function that adds git capability to any
5
+ * Durable Object class. The mixin supports lazy initialization of the
6
+ * GitModule for optimal performance.
7
+ *
8
+ * @module do/withGit
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { withGit } from 'gitx.do/do'
13
+ * import { DO } from 'dotdo'
14
+ *
15
+ * // Basic usage - adds this.git property
16
+ * class MyDO extends withGit(DO, { repo: 'org/repo' }) {
17
+ * async handleRequest() {
18
+ * await this.git.sync()
19
+ * const status = await this.git.status()
20
+ * return new Response(JSON.stringify(status))
21
+ * }
22
+ * }
23
+ *
24
+ * // With $.git context integration
25
+ * class WorkflowDO extends withGit(DO, {
26
+ * repo: 'org/repo',
27
+ * contextMode: true
28
+ * }) {
29
+ * async handleRequest() {
30
+ * // Access via $.git when contextMode is enabled
31
+ * await this.$.git.sync()
32
+ * }
33
+ * }
34
+ * ```
35
+ */
36
+ import { GitModule, } from './GitModule';
37
+ // ============================================================================
38
+ // Symbol for Lazy Initialization Cache
39
+ // ============================================================================
40
+ /**
41
+ * Symbol key for caching the GitModule instance.
42
+ * Using a symbol prevents property name collisions.
43
+ */
44
+ const GIT_MODULE_CACHE = Symbol('gitModuleCache');
45
+ /**
46
+ * Symbol key for storing resolved options.
47
+ */
48
+ const GIT_OPTIONS = Symbol('gitOptions');
49
+ // ============================================================================
50
+ // withGit Mixin Function
51
+ // ============================================================================
52
+ /**
53
+ * Mixin function to add git capability to a DO class.
54
+ *
55
+ * @description
56
+ * Composes git functionality into a Durable Object class using the mixin pattern.
57
+ * The resulting class will have a `git` property that provides GitModule functionality.
58
+ *
59
+ * Features:
60
+ * - Lazy initialization: GitModule is only created when first accessed
61
+ * - R2 integration: Automatically resolves R2 bucket from env bindings
62
+ * - Context mode: Optionally extends the $ WorkflowContext with git capability
63
+ * - Composable: Can be combined with other mixins like withBash
64
+ *
65
+ * @param Base - Base class to extend
66
+ * @param options - Git configuration options
67
+ * @returns Extended class with git capability
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * // Basic usage
72
+ * import { withGit } from 'gitx.do/do'
73
+ * import { DO } from 'dotdo'
74
+ *
75
+ * class MyDO extends withGit(DO, { repo: 'org/repo' }) {
76
+ * async syncAndCommit() {
77
+ * await this.git.sync()
78
+ * await this.git.add('.')
79
+ * await this.git.commit('Update files')
80
+ * await this.git.push()
81
+ * }
82
+ * }
83
+ * ```
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * // With custom R2 binding
88
+ * class MyDO extends withGit(DO, {
89
+ * repo: 'org/repo',
90
+ * branch: 'develop',
91
+ * r2Binding: 'GIT_OBJECTS'
92
+ * }) {
93
+ * async handleRequest() {
94
+ * await this.git.sync()
95
+ * return new Response('Synced!')
96
+ * }
97
+ * }
98
+ * ```
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * // Composing with other mixins
103
+ * import { withGit, withBash } from 'gitx.do/do'
104
+ *
105
+ * class DevDO extends withBash(withGit(DO, { repo: 'org/repo' }), {
106
+ * cwd: '/workspace'
107
+ * }) {
108
+ * async buildAndPush() {
109
+ * await this.git.sync()
110
+ * await this.bash.exec('npm', ['run', 'build'])
111
+ * await this.git.add('dist/')
112
+ * await this.git.commit('Build: update dist')
113
+ * await this.git.push()
114
+ * }
115
+ * }
116
+ * ```
117
+ */
118
+ export function withGit(Base, options) {
119
+ // Validate required options
120
+ if (!options.repo) {
121
+ throw new Error('withGit: repo option is required');
122
+ }
123
+ return class WithGitMixin extends Base {
124
+ /**
125
+ * Static list of capabilities for introspection.
126
+ */
127
+ static capabilities = [...(Base.capabilities || []), 'git'];
128
+ /**
129
+ * Cached GitModule instance (lazy initialized).
130
+ */
131
+ [GIT_MODULE_CACHE];
132
+ /**
133
+ * Resolved options for GitModule creation.
134
+ */
135
+ [GIT_OPTIONS];
136
+ /**
137
+ * Whether the git module has been initialized.
138
+ */
139
+ gitInitialized = false;
140
+ /**
141
+ * The git property provides access to the GitModule.
142
+ * Implements lazy initialization - the module is only created
143
+ * when this property is first accessed.
144
+ */
145
+ get git() {
146
+ if (!this[GIT_MODULE_CACHE]) {
147
+ this[GIT_MODULE_CACHE] = this.createGitModule();
148
+ }
149
+ return this[GIT_MODULE_CACHE];
150
+ }
151
+ /**
152
+ * Check if this DO class has a specific capability.
153
+ * @param name - Capability name to check
154
+ * @returns True if the capability is available
155
+ */
156
+ hasCapability(name) {
157
+ if (name === 'git')
158
+ return true;
159
+ // Check if parent class has the hasCapability method
160
+ const baseProto = Base.prototype;
161
+ if (baseProto && typeof baseProto.hasCapability === 'function') {
162
+ return baseProto.hasCapability.call(this, name);
163
+ }
164
+ return false;
165
+ }
166
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
167
+ constructor(...args) {
168
+ super(...args);
169
+ // Resolve R2 bucket from env if available
170
+ const env = this.env;
171
+ const r2BindingName = options.r2Binding ?? 'R2_BUCKET';
172
+ const r2 = env?.[r2BindingName];
173
+ // Get filesystem capability if available from $ context
174
+ const dollarContext = this.$;
175
+ const fs = dollarContext?.fs;
176
+ // Store resolved options
177
+ this[GIT_OPTIONS] = {
178
+ ...options,
179
+ r2,
180
+ fs,
181
+ };
182
+ // Extend $ context if contextMode is enabled
183
+ if (options.contextMode && dollarContext) {
184
+ const self = this;
185
+ const original$ = dollarContext;
186
+ this.$ = new Proxy(original$, {
187
+ get(target, prop) {
188
+ if (prop === 'git') {
189
+ return self.git;
190
+ }
191
+ // Forward to original context
192
+ const value = target[prop];
193
+ if (typeof value === 'function') {
194
+ return value.bind(target);
195
+ }
196
+ return value;
197
+ },
198
+ });
199
+ }
200
+ // Auto-initialize if requested
201
+ if (options.autoInit) {
202
+ // Access git to trigger lazy initialization
203
+ void this.git.initialize();
204
+ this.gitInitialized = true;
205
+ }
206
+ }
207
+ /**
208
+ * Creates the GitModule instance with resolved options.
209
+ * @returns A new GitModule instance
210
+ */
211
+ createGitModule() {
212
+ const opts = this[GIT_OPTIONS];
213
+ return new GitModule({
214
+ repo: opts.repo,
215
+ branch: opts.branch,
216
+ path: opts.path,
217
+ r2: opts.r2,
218
+ fs: opts.fs,
219
+ objectPrefix: opts.objectPrefix,
220
+ });
221
+ }
222
+ /**
223
+ * Initialize the git module explicitly.
224
+ * This is useful when you need to ensure the module is ready
225
+ * before performing operations.
226
+ */
227
+ async initializeGit() {
228
+ if (!this.gitInitialized) {
229
+ await this.git.initialize();
230
+ this.gitInitialized = true;
231
+ }
232
+ }
233
+ /**
234
+ * Dispose the git module and clean up resources.
235
+ */
236
+ async disposeGit() {
237
+ if (this[GIT_MODULE_CACHE]) {
238
+ await this[GIT_MODULE_CACHE].dispose();
239
+ this[GIT_MODULE_CACHE] = undefined;
240
+ this.gitInitialized = false;
241
+ }
242
+ }
243
+ };
244
+ }
245
+ // ============================================================================
246
+ // Type Guards
247
+ // ============================================================================
248
+ /**
249
+ * Check if a value has git capability.
250
+ *
251
+ * @param value - Value to check
252
+ * @returns True if value has the git property and it's a GitModule
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * if (hasGitCapability(instance)) {
257
+ * await instance.git.sync()
258
+ * }
259
+ * ```
260
+ */
261
+ export function hasGitCapability(value) {
262
+ return (typeof value === 'object' &&
263
+ value !== null &&
264
+ 'git' in value &&
265
+ value.git instanceof GitModule);
266
+ }
267
+ // ============================================================================
268
+ // Re-exports for Convenience
269
+ // ============================================================================
270
+ export { GitModule, };
271
+ //# sourceMappingURL=withGit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withGit.js","sourceRoot":"","sources":["../../src/do/withGit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EACL,SAAS,GAQV,MAAM,aAAa,CAAA;AAuFpB,+EAA+E;AAC/E,uCAAuC;AACvC,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAA;AAEjD;;GAEG;AACH,MAAM,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;AAExC,+EAA+E;AAC/E,yBAAyB;AACzB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,MAAM,UAAU,OAAO,CACrB,IAAW,EACX,OAAuB;IAEvB,4BAA4B;IAC5B,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;IACrD,CAAC;IAED,OAAO,MAAM,YAAa,SAAQ,IAAI;QACpC;;WAEG;QACH,MAAM,CAAC,YAAY,GAAG,CAAC,GAAG,CAAE,IAAgC,CA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