@pierre/storage 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/index.cjs +46 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +46 -20
- package/dist/index.js.map +1 -1
- package/package.json +39 -38
- package/src/commit.ts +2 -0
- package/src/diff-commit.ts +2 -0
- package/src/fetch.ts +2 -0
- package/src/index.ts +31 -16
- package/src/types.ts +4 -0
- package/src/version.ts +8 -0
package/package.json
CHANGED
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
2
|
+
"name": "@pierre/storage",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Pierre Git Storage SDK",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"src"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"dev": "tsup --watch",
|
|
25
|
+
"prepublishOnly": "pnpm build"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"jose": "^5.10.0",
|
|
29
|
+
"snakecase-keys": "^9.0.2",
|
|
30
|
+
"zod": "^3.23.8"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsup": "8.5.0",
|
|
34
|
+
"typescript": "5.8.3",
|
|
35
|
+
"vitest": "3.2.4"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/commit.ts
CHANGED
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
CreateCommitOptions,
|
|
21
21
|
LegacyCreateCommitOptions,
|
|
22
22
|
} from './types';
|
|
23
|
+
import { getUserAgent } from './version';
|
|
23
24
|
|
|
24
25
|
const DEFAULT_TTL_SECONDS = 60 * 60;
|
|
25
26
|
const HEADS_REF_PREFIX = 'refs/heads/';
|
|
@@ -294,6 +295,7 @@ export class FetchCommitTransport implements CommitTransport {
|
|
|
294
295
|
Authorization: `Bearer ${request.authorization}`,
|
|
295
296
|
'Content-Type': 'application/x-ndjson',
|
|
296
297
|
Accept: 'application/json',
|
|
298
|
+
'Code-Storage-Agent': getUserAgent(),
|
|
297
299
|
},
|
|
298
300
|
body: body as any,
|
|
299
301
|
signal: request.signal,
|
package/src/diff-commit.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
CreateCommitFromDiffOptions,
|
|
17
17
|
DiffSource,
|
|
18
18
|
} from './types';
|
|
19
|
+
import { getUserAgent } from './version';
|
|
19
20
|
|
|
20
21
|
interface DiffCommitMetadataPayload {
|
|
21
22
|
target_branch: string;
|
|
@@ -190,6 +191,7 @@ export class FetchDiffCommitTransport implements DiffCommitTransport {
|
|
|
190
191
|
Authorization: `Bearer ${request.authorization}`,
|
|
191
192
|
'Content-Type': 'application/x-ndjson',
|
|
192
193
|
Accept: 'application/json',
|
|
194
|
+
'Code-Storage-Agent': getUserAgent(),
|
|
193
195
|
},
|
|
194
196
|
body: body as any,
|
|
195
197
|
signal: request.signal,
|
package/src/fetch.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { errorEnvelopeSchema } from './schemas';
|
|
2
2
|
import type { ValidAPIVersion, ValidMethod, ValidPath } from './types';
|
|
3
|
+
import { getUserAgent } from './version';
|
|
3
4
|
|
|
4
5
|
interface RequestOptions {
|
|
5
6
|
allowedStatus?: number[];
|
|
@@ -59,6 +60,7 @@ export class ApiFetcher {
|
|
|
59
60
|
headers: {
|
|
60
61
|
Authorization: `Bearer ${jwt}`,
|
|
61
62
|
'Content-Type': 'application/json',
|
|
63
|
+
'Code-Storage-Agent': getUserAgent(),
|
|
62
64
|
},
|
|
63
65
|
};
|
|
64
66
|
|
package/src/index.ts
CHANGED
|
@@ -53,7 +53,6 @@ import type {
|
|
|
53
53
|
ListCommitsResult,
|
|
54
54
|
ListFilesOptions,
|
|
55
55
|
ListFilesResult,
|
|
56
|
-
OverrideableGitStorageOptions,
|
|
57
56
|
PullUpstreamOptions,
|
|
58
57
|
RawBranchInfo,
|
|
59
58
|
RawCommitInfo,
|
|
@@ -346,22 +345,20 @@ class RepoImpl implements Repo {
|
|
|
346
345
|
) => Promise<string>,
|
|
347
346
|
) {
|
|
348
347
|
this.api = getApiInstance(
|
|
349
|
-
this.options.apiBaseUrl ??
|
|
348
|
+
this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(options.name),
|
|
350
349
|
this.options.apiVersion ?? API_VERSION,
|
|
351
350
|
);
|
|
352
351
|
}
|
|
353
352
|
|
|
354
353
|
async getRemoteURL(urlOptions?: GetRemoteURLOptions): Promise<string> {
|
|
355
|
-
const
|
|
356
|
-
const url = new URL(`https://${this.options.name}.${storageBaseUrl}/${this.id}.git`);
|
|
354
|
+
const url = new URL(`https://${this.options.storageBaseUrl}/${this.id}.git`);
|
|
357
355
|
url.username = `t`;
|
|
358
356
|
url.password = await this.generateJWT(this.id, urlOptions);
|
|
359
357
|
return url.toString();
|
|
360
358
|
}
|
|
361
359
|
|
|
362
360
|
async getEphemeralRemoteURL(urlOptions?: GetRemoteURLOptions): Promise<string> {
|
|
363
|
-
const
|
|
364
|
-
const url = new URL(`https://${this.options.name}.${storageBaseUrl}/${this.id}+ephemeral.git`);
|
|
361
|
+
const url = new URL(`https://${this.options.storageBaseUrl}/${this.id}+ephemeral.git`);
|
|
365
362
|
url.username = `t`;
|
|
366
363
|
url.password = await this.generateJWT(this.id, urlOptions);
|
|
367
364
|
return url.toString();
|
|
@@ -384,6 +381,9 @@ class RepoImpl implements Repo {
|
|
|
384
381
|
if (typeof options.ephemeral === 'boolean') {
|
|
385
382
|
params.ephemeral = String(options.ephemeral);
|
|
386
383
|
}
|
|
384
|
+
if (typeof options.ephemeralBase === 'boolean') {
|
|
385
|
+
params.ephemeral_base = String(options.ephemeralBase);
|
|
386
|
+
}
|
|
387
387
|
|
|
388
388
|
// Return the raw fetch Response for streaming
|
|
389
389
|
return this.api.get({ path: 'repos/file', params }, jwt);
|
|
@@ -488,6 +488,12 @@ class RepoImpl implements Repo {
|
|
|
488
488
|
if (options.base) {
|
|
489
489
|
params.base = options.base;
|
|
490
490
|
}
|
|
491
|
+
if (typeof options.ephemeral === 'boolean') {
|
|
492
|
+
params.ephemeral = String(options.ephemeral);
|
|
493
|
+
}
|
|
494
|
+
if (typeof options.ephemeralBase === 'boolean') {
|
|
495
|
+
params.ephemeral_base = String(options.ephemeralBase);
|
|
496
|
+
}
|
|
491
497
|
|
|
492
498
|
const response = await this.api.get({ path: 'repos/branches/diff', params }, jwt);
|
|
493
499
|
|
|
@@ -506,6 +512,10 @@ class RepoImpl implements Repo {
|
|
|
506
512
|
sha: options.sha,
|
|
507
513
|
};
|
|
508
514
|
|
|
515
|
+
if (options.baseSha) {
|
|
516
|
+
params.baseSha = options.baseSha;
|
|
517
|
+
}
|
|
518
|
+
|
|
509
519
|
const response = await this.api.get({ path: 'repos/diff', params }, jwt);
|
|
510
520
|
|
|
511
521
|
const raw = commitDiffResponseSchema.parse(await response.json());
|
|
@@ -653,7 +663,7 @@ class RepoImpl implements Repo {
|
|
|
653
663
|
|
|
654
664
|
createCommit(options: CreateCommitOptions): CommitBuilder {
|
|
655
665
|
const version = this.options.apiVersion ?? API_VERSION;
|
|
656
|
-
const baseUrl = this.options.apiBaseUrl ??
|
|
666
|
+
const baseUrl = this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(this.options.name);
|
|
657
667
|
const transport = new FetchCommitTransport({ baseUrl, version });
|
|
658
668
|
const ttl = resolveCommitTtlSeconds(options);
|
|
659
669
|
const builderOptions: CreateCommitOptions = {
|
|
@@ -675,7 +685,7 @@ class RepoImpl implements Repo {
|
|
|
675
685
|
|
|
676
686
|
async createCommitFromDiff(options: CreateCommitFromDiffOptions): Promise<CommitResult> {
|
|
677
687
|
const version = this.options.apiVersion ?? API_VERSION;
|
|
678
|
-
const baseUrl = this.options.apiBaseUrl ??
|
|
688
|
+
const baseUrl = this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(this.options.name);
|
|
679
689
|
const transport = new FetchDiffCommitTransport({ baseUrl, version });
|
|
680
690
|
const ttl = resolveCommitTtlSeconds(options);
|
|
681
691
|
const requestOptions: CreateCommitFromDiffOptions = {
|
|
@@ -697,7 +707,6 @@ class RepoImpl implements Repo {
|
|
|
697
707
|
}
|
|
698
708
|
|
|
699
709
|
export class GitStorage {
|
|
700
|
-
private static overrides: OverrideableGitStorageOptions = {};
|
|
701
710
|
private options: GitStorageOptions;
|
|
702
711
|
private api: ApiFetcher;
|
|
703
712
|
|
|
@@ -722,12 +731,11 @@ export class GitStorage {
|
|
|
722
731
|
throw new Error('GitStorage key must be a non-empty string.');
|
|
723
732
|
}
|
|
724
733
|
|
|
725
|
-
const resolvedApiBaseUrl =
|
|
726
|
-
|
|
727
|
-
const resolvedApiVersion = options.apiVersion ?? GitStorage.overrides.apiVersion ?? API_VERSION;
|
|
734
|
+
const resolvedApiBaseUrl = options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(options.name);
|
|
735
|
+
const resolvedApiVersion = options.apiVersion ?? API_VERSION;
|
|
728
736
|
const resolvedStorageBaseUrl =
|
|
729
|
-
options.storageBaseUrl ?? GitStorage.
|
|
730
|
-
const resolvedDefaultTtl = options.defaultTTL
|
|
737
|
+
options.storageBaseUrl ?? GitStorage.getDefaultStorageBaseUrl(options.name);
|
|
738
|
+
const resolvedDefaultTtl = options.defaultTTL;
|
|
731
739
|
|
|
732
740
|
this.api = getApiInstance(resolvedApiBaseUrl, resolvedApiVersion);
|
|
733
741
|
|
|
@@ -741,8 +749,12 @@ export class GitStorage {
|
|
|
741
749
|
};
|
|
742
750
|
}
|
|
743
751
|
|
|
744
|
-
static
|
|
745
|
-
|
|
752
|
+
static getDefaultAPIBaseUrl(name: string): string {
|
|
753
|
+
return API_BASE_URL.replace('{{org}}', name);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
static getDefaultStorageBaseUrl(name: string): string {
|
|
757
|
+
return STORAGE_BASE_URL.replace('{{org}}', name);
|
|
746
758
|
}
|
|
747
759
|
|
|
748
760
|
/**
|
|
@@ -853,5 +865,8 @@ export function createClient(options: GitStorageOptions): GitStorage {
|
|
|
853
865
|
return new GitStorage(options);
|
|
854
866
|
}
|
|
855
867
|
|
|
868
|
+
// Export CodeStorage as an alias for GitStorage
|
|
869
|
+
export { GitStorage as CodeStorage };
|
|
870
|
+
|
|
856
871
|
// Type alias for backward compatibility
|
|
857
872
|
export type StorageOptions = GitStorageOptions;
|
package/src/types.ts
CHANGED
|
@@ -93,6 +93,7 @@ export interface GetFileOptions extends GitStorageInvocationOptions {
|
|
|
93
93
|
path: string;
|
|
94
94
|
ref?: string;
|
|
95
95
|
ephemeral?: boolean;
|
|
96
|
+
ephemeralBase?: boolean;
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
export interface PullUpstreamOptions extends GitStorageInvocationOptions {
|
|
@@ -184,6 +185,8 @@ export interface ListCommitsResult {
|
|
|
184
185
|
export interface GetBranchDiffOptions extends GitStorageInvocationOptions {
|
|
185
186
|
branch: string;
|
|
186
187
|
base?: string;
|
|
188
|
+
ephemeral?: boolean;
|
|
189
|
+
ephemeralBase?: boolean;
|
|
187
190
|
}
|
|
188
191
|
|
|
189
192
|
export type GetBranchDiffResponse = GetBranchDiffResponseRaw;
|
|
@@ -199,6 +202,7 @@ export interface GetBranchDiffResult {
|
|
|
199
202
|
// Commit Diff API types
|
|
200
203
|
export interface GetCommitDiffOptions extends GitStorageInvocationOptions {
|
|
201
204
|
sha: string;
|
|
205
|
+
baseSha?: string;
|
|
202
206
|
}
|
|
203
207
|
|
|
204
208
|
export type GetCommitDiffResponse = GetCommitDiffResponseRaw;
|
package/src/version.ts
ADDED