@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/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -448,6 +448,17 @@ function concatChunks(a, b) {
|
|
|
448
448
|
return merged;
|
|
449
449
|
}
|
|
450
450
|
|
|
451
|
+
// package.json
|
|
452
|
+
var package_default = {
|
|
453
|
+
version: "0.3.0"};
|
|
454
|
+
|
|
455
|
+
// src/version.ts
|
|
456
|
+
var PACKAGE_NAME = "code-storage-sdk";
|
|
457
|
+
var PACKAGE_VERSION = package_default.version;
|
|
458
|
+
function getUserAgent() {
|
|
459
|
+
return `${PACKAGE_NAME}/${PACKAGE_VERSION}`;
|
|
460
|
+
}
|
|
461
|
+
|
|
451
462
|
// src/commit.ts
|
|
452
463
|
var DEFAULT_TTL_SECONDS = 60 * 60;
|
|
453
464
|
var HEADS_REF_PREFIX = "refs/heads/";
|
|
@@ -620,7 +631,8 @@ var FetchCommitTransport = class {
|
|
|
620
631
|
headers: {
|
|
621
632
|
Authorization: `Bearer ${request.authorization}`,
|
|
622
633
|
"Content-Type": "application/x-ndjson",
|
|
623
|
-
Accept: "application/json"
|
|
634
|
+
Accept: "application/json",
|
|
635
|
+
"Code-Storage-Agent": getUserAgent()
|
|
624
636
|
},
|
|
625
637
|
body,
|
|
626
638
|
signal: request.signal
|
|
@@ -850,7 +862,8 @@ var FetchDiffCommitTransport = class {
|
|
|
850
862
|
headers: {
|
|
851
863
|
Authorization: `Bearer ${request.authorization}`,
|
|
852
864
|
"Content-Type": "application/x-ndjson",
|
|
853
|
-
Accept: "application/json"
|
|
865
|
+
Accept: "application/json",
|
|
866
|
+
"Code-Storage-Agent": getUserAgent()
|
|
854
867
|
},
|
|
855
868
|
body,
|
|
856
869
|
signal: request.signal
|
|
@@ -987,7 +1000,8 @@ var ApiFetcher = class {
|
|
|
987
1000
|
method,
|
|
988
1001
|
headers: {
|
|
989
1002
|
Authorization: `Bearer ${jwt}`,
|
|
990
|
-
"Content-Type": "application/json"
|
|
1003
|
+
"Content-Type": "application/json",
|
|
1004
|
+
"Code-Storage-Agent": getUserAgent()
|
|
991
1005
|
}
|
|
992
1006
|
};
|
|
993
1007
|
if (method !== "GET" && typeof path !== "string" && path.body) {
|
|
@@ -1283,8 +1297,8 @@ function isRecord(value) {
|
|
|
1283
1297
|
}
|
|
1284
1298
|
|
|
1285
1299
|
// src/index.ts
|
|
1286
|
-
var API_BASE_URL = "https://api.code.storage";
|
|
1287
|
-
var STORAGE_BASE_URL = "code.storage";
|
|
1300
|
+
var API_BASE_URL = "https://api.{{org}}.code.storage";
|
|
1301
|
+
var STORAGE_BASE_URL = "{{org}}.code.storage";
|
|
1288
1302
|
var API_VERSION = 1;
|
|
1289
1303
|
var apiInstanceMap = /* @__PURE__ */ new Map();
|
|
1290
1304
|
var DEFAULT_TOKEN_TTL_SECONDS = 60 * 60;
|
|
@@ -1511,21 +1525,19 @@ var RepoImpl = class {
|
|
|
1511
1525
|
this.options = options;
|
|
1512
1526
|
this.generateJWT = generateJWT;
|
|
1513
1527
|
this.api = getApiInstance(
|
|
1514
|
-
this.options.apiBaseUrl ??
|
|
1528
|
+
this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(options.name),
|
|
1515
1529
|
this.options.apiVersion ?? API_VERSION
|
|
1516
1530
|
);
|
|
1517
1531
|
}
|
|
1518
1532
|
api;
|
|
1519
1533
|
async getRemoteURL(urlOptions) {
|
|
1520
|
-
const
|
|
1521
|
-
const url = new URL(`https://${this.options.name}.${storageBaseUrl}/${this.id}.git`);
|
|
1534
|
+
const url = new URL(`https://${this.options.storageBaseUrl}/${this.id}.git`);
|
|
1522
1535
|
url.username = `t`;
|
|
1523
1536
|
url.password = await this.generateJWT(this.id, urlOptions);
|
|
1524
1537
|
return url.toString();
|
|
1525
1538
|
}
|
|
1526
1539
|
async getEphemeralRemoteURL(urlOptions) {
|
|
1527
|
-
const
|
|
1528
|
-
const url = new URL(`https://${this.options.name}.${storageBaseUrl}/${this.id}+ephemeral.git`);
|
|
1540
|
+
const url = new URL(`https://${this.options.storageBaseUrl}/${this.id}+ephemeral.git`);
|
|
1529
1541
|
url.username = `t`;
|
|
1530
1542
|
url.password = await this.generateJWT(this.id, urlOptions);
|
|
1531
1543
|
return url.toString();
|
|
@@ -1545,6 +1557,9 @@ var RepoImpl = class {
|
|
|
1545
1557
|
if (typeof options.ephemeral === "boolean") {
|
|
1546
1558
|
params.ephemeral = String(options.ephemeral);
|
|
1547
1559
|
}
|
|
1560
|
+
if (typeof options.ephemeralBase === "boolean") {
|
|
1561
|
+
params.ephemeral_base = String(options.ephemeralBase);
|
|
1562
|
+
}
|
|
1548
1563
|
return this.api.get({ path: "repos/file", params }, jwt);
|
|
1549
1564
|
}
|
|
1550
1565
|
async listFiles(options) {
|
|
@@ -1630,6 +1645,12 @@ var RepoImpl = class {
|
|
|
1630
1645
|
if (options.base) {
|
|
1631
1646
|
params.base = options.base;
|
|
1632
1647
|
}
|
|
1648
|
+
if (typeof options.ephemeral === "boolean") {
|
|
1649
|
+
params.ephemeral = String(options.ephemeral);
|
|
1650
|
+
}
|
|
1651
|
+
if (typeof options.ephemeralBase === "boolean") {
|
|
1652
|
+
params.ephemeral_base = String(options.ephemeralBase);
|
|
1653
|
+
}
|
|
1633
1654
|
const response = await this.api.get({ path: "repos/branches/diff", params }, jwt);
|
|
1634
1655
|
const raw = branchDiffResponseSchema.parse(await response.json());
|
|
1635
1656
|
return transformBranchDiffResult(raw);
|
|
@@ -1643,6 +1664,9 @@ var RepoImpl = class {
|
|
|
1643
1664
|
const params = {
|
|
1644
1665
|
sha: options.sha
|
|
1645
1666
|
};
|
|
1667
|
+
if (options.baseSha) {
|
|
1668
|
+
params.baseSha = options.baseSha;
|
|
1669
|
+
}
|
|
1646
1670
|
const response = await this.api.get({ path: "repos/diff", params }, jwt);
|
|
1647
1671
|
const raw = commitDiffResponseSchema.parse(await response.json());
|
|
1648
1672
|
return transformCommitDiffResult(raw);
|
|
@@ -1762,7 +1786,7 @@ var RepoImpl = class {
|
|
|
1762
1786
|
}
|
|
1763
1787
|
createCommit(options) {
|
|
1764
1788
|
const version = this.options.apiVersion ?? API_VERSION;
|
|
1765
|
-
const baseUrl = this.options.apiBaseUrl ??
|
|
1789
|
+
const baseUrl = this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(this.options.name);
|
|
1766
1790
|
const transport = new FetchCommitTransport({ baseUrl, version });
|
|
1767
1791
|
const ttl = resolveCommitTtlSeconds(options);
|
|
1768
1792
|
const builderOptions = {
|
|
@@ -1781,7 +1805,7 @@ var RepoImpl = class {
|
|
|
1781
1805
|
}
|
|
1782
1806
|
async createCommitFromDiff(options) {
|
|
1783
1807
|
const version = this.options.apiVersion ?? API_VERSION;
|
|
1784
|
-
const baseUrl = this.options.apiBaseUrl ??
|
|
1808
|
+
const baseUrl = this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(this.options.name);
|
|
1785
1809
|
const transport = new FetchDiffCommitTransport({ baseUrl, version });
|
|
1786
1810
|
const ttl = resolveCommitTtlSeconds(options);
|
|
1787
1811
|
const requestOptions = {
|
|
@@ -1800,7 +1824,6 @@ var RepoImpl = class {
|
|
|
1800
1824
|
}
|
|
1801
1825
|
};
|
|
1802
1826
|
var GitStorage = class _GitStorage {
|
|
1803
|
-
static overrides = {};
|
|
1804
1827
|
options;
|
|
1805
1828
|
api;
|
|
1806
1829
|
constructor(options) {
|
|
@@ -1815,10 +1838,10 @@ var GitStorage = class _GitStorage {
|
|
|
1815
1838
|
if (typeof options.key !== "string" || options.key.trim() === "") {
|
|
1816
1839
|
throw new Error("GitStorage key must be a non-empty string.");
|
|
1817
1840
|
}
|
|
1818
|
-
const resolvedApiBaseUrl = options.apiBaseUrl ?? _GitStorage.
|
|
1819
|
-
const resolvedApiVersion = options.apiVersion ??
|
|
1820
|
-
const resolvedStorageBaseUrl = options.storageBaseUrl ?? _GitStorage.
|
|
1821
|
-
const resolvedDefaultTtl = options.defaultTTL
|
|
1841
|
+
const resolvedApiBaseUrl = options.apiBaseUrl ?? _GitStorage.getDefaultAPIBaseUrl(options.name);
|
|
1842
|
+
const resolvedApiVersion = options.apiVersion ?? API_VERSION;
|
|
1843
|
+
const resolvedStorageBaseUrl = options.storageBaseUrl ?? _GitStorage.getDefaultStorageBaseUrl(options.name);
|
|
1844
|
+
const resolvedDefaultTtl = options.defaultTTL;
|
|
1822
1845
|
this.api = getApiInstance(resolvedApiBaseUrl, resolvedApiVersion);
|
|
1823
1846
|
this.options = {
|
|
1824
1847
|
key: options.key,
|
|
@@ -1829,8 +1852,11 @@ var GitStorage = class _GitStorage {
|
|
|
1829
1852
|
defaultTTL: resolvedDefaultTtl
|
|
1830
1853
|
};
|
|
1831
1854
|
}
|
|
1832
|
-
static
|
|
1833
|
-
|
|
1855
|
+
static getDefaultAPIBaseUrl(name) {
|
|
1856
|
+
return API_BASE_URL.replace("{{org}}", name);
|
|
1857
|
+
}
|
|
1858
|
+
static getDefaultStorageBaseUrl(name) {
|
|
1859
|
+
return STORAGE_BASE_URL.replace("{{org}}", name);
|
|
1834
1860
|
}
|
|
1835
1861
|
/**
|
|
1836
1862
|
* Create a new repository
|
|
@@ -1910,6 +1936,7 @@ function createClient(options) {
|
|
|
1910
1936
|
}
|
|
1911
1937
|
|
|
1912
1938
|
exports.ApiError = ApiError;
|
|
1939
|
+
exports.CodeStorage = GitStorage;
|
|
1913
1940
|
exports.GitStorage = GitStorage;
|
|
1914
1941
|
exports.RefUpdateError = RefUpdateError;
|
|
1915
1942
|
exports.createClient = createClient;
|