@pierre/storage 0.4.0 → 0.4.1
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 +12 -1
- package/dist/index.cjs +99 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -1
- package/dist/index.d.ts +53 -1
- package/dist/index.js +99 -1
- package/dist/index.js.map +1 -1
- package/package.json +39 -38
- package/src/index.ts +108 -0
- package/src/schemas.ts +26 -0
- package/src/types.ts +57 -0
package/README.md
CHANGED
|
@@ -52,6 +52,17 @@ if (foundRepo) {
|
|
|
52
52
|
}
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
### Grep
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const result = await foundRepo.grep({
|
|
59
|
+
ref: 'main',
|
|
60
|
+
query: { pattern: 'TODO', caseSensitive: true },
|
|
61
|
+
paths: ['src/'],
|
|
62
|
+
});
|
|
63
|
+
console.log(result.matches);
|
|
64
|
+
```
|
|
65
|
+
|
|
55
66
|
### Getting Remote URLs
|
|
56
67
|
|
|
57
68
|
The SDK generates secure URLs with JWT authentication for Git operations:
|
|
@@ -166,7 +177,7 @@ const result = await repo
|
|
|
166
177
|
commitMessage: 'Update docs',
|
|
167
178
|
author: { name: 'Docs Bot', email: 'docs@example.com' },
|
|
168
179
|
})
|
|
169
|
-
.addFileFromString('docs/changelog.md', '# v2.0.
|
|
180
|
+
.addFileFromString('docs/changelog.md', '# v2.0.2\n- add streaming SDK\n')
|
|
170
181
|
.addFile('docs/readme.md', await fs.readFile('README.md'))
|
|
171
182
|
.deletePath('docs/legacy.txt')
|
|
172
183
|
.send();
|
package/dist/index.cjs
CHANGED
|
@@ -156,6 +156,28 @@ var restoreCommitResponseSchema = zod.z.object({
|
|
|
156
156
|
commit: restoreCommitCommitSchema.partial().optional().nullable(),
|
|
157
157
|
result: refUpdateResultWithOptionalsSchema
|
|
158
158
|
});
|
|
159
|
+
var grepLineSchema = zod.z.object({
|
|
160
|
+
line_number: zod.z.number(),
|
|
161
|
+
text: zod.z.string(),
|
|
162
|
+
type: zod.z.string()
|
|
163
|
+
});
|
|
164
|
+
var grepFileMatchSchema = zod.z.object({
|
|
165
|
+
path: zod.z.string(),
|
|
166
|
+
lines: zod.z.array(grepLineSchema)
|
|
167
|
+
});
|
|
168
|
+
var grepResponseSchema = zod.z.object({
|
|
169
|
+
query: zod.z.object({
|
|
170
|
+
pattern: zod.z.string(),
|
|
171
|
+
case_sensitive: zod.z.boolean()
|
|
172
|
+
}),
|
|
173
|
+
repo: zod.z.object({
|
|
174
|
+
ref: zod.z.string(),
|
|
175
|
+
commit: zod.z.string()
|
|
176
|
+
}),
|
|
177
|
+
matches: zod.z.array(grepFileMatchSchema),
|
|
178
|
+
next_cursor: zod.z.string().nullable().optional(),
|
|
179
|
+
has_more: zod.z.boolean()
|
|
180
|
+
});
|
|
159
181
|
var errorEnvelopeSchema = zod.z.object({
|
|
160
182
|
error: zod.z.string()
|
|
161
183
|
});
|
|
@@ -450,7 +472,7 @@ function concatChunks(a, b) {
|
|
|
450
472
|
|
|
451
473
|
// package.json
|
|
452
474
|
var package_default = {
|
|
453
|
-
version: "0.4.
|
|
475
|
+
version: "0.4.1"};
|
|
454
476
|
|
|
455
477
|
// src/version.ts
|
|
456
478
|
var PACKAGE_NAME = "code-storage-sdk";
|
|
@@ -1519,6 +1541,19 @@ function transformCreateBranchResult(raw) {
|
|
|
1519
1541
|
commitSha: raw.commit_sha ?? void 0
|
|
1520
1542
|
};
|
|
1521
1543
|
}
|
|
1544
|
+
function transformGrepLine(raw) {
|
|
1545
|
+
return {
|
|
1546
|
+
lineNumber: raw.line_number,
|
|
1547
|
+
text: raw.text,
|
|
1548
|
+
type: raw.type
|
|
1549
|
+
};
|
|
1550
|
+
}
|
|
1551
|
+
function transformGrepFileMatch(raw) {
|
|
1552
|
+
return {
|
|
1553
|
+
path: raw.path,
|
|
1554
|
+
lines: raw.lines.map(transformGrepLine)
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1522
1557
|
var RepoImpl = class {
|
|
1523
1558
|
constructor(id, options, generateJWT) {
|
|
1524
1559
|
this.id = id;
|
|
@@ -1671,6 +1706,69 @@ var RepoImpl = class {
|
|
|
1671
1706
|
const raw = commitDiffResponseSchema.parse(await response.json());
|
|
1672
1707
|
return transformCommitDiffResult(raw);
|
|
1673
1708
|
}
|
|
1709
|
+
async grep(options) {
|
|
1710
|
+
const pattern = options?.query?.pattern?.trim();
|
|
1711
|
+
if (!pattern) {
|
|
1712
|
+
throw new Error("grep query.pattern is required");
|
|
1713
|
+
}
|
|
1714
|
+
const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
|
|
1715
|
+
const jwt = await this.generateJWT(this.id, {
|
|
1716
|
+
permissions: ["git:read"],
|
|
1717
|
+
ttl
|
|
1718
|
+
});
|
|
1719
|
+
const body = {
|
|
1720
|
+
query: {
|
|
1721
|
+
pattern,
|
|
1722
|
+
...typeof options.query.caseSensitive === "boolean" ? { case_sensitive: options.query.caseSensitive } : {}
|
|
1723
|
+
}
|
|
1724
|
+
};
|
|
1725
|
+
if (options.ref) {
|
|
1726
|
+
body.rev = options.ref;
|
|
1727
|
+
}
|
|
1728
|
+
if (Array.isArray(options.paths) && options.paths.length > 0) {
|
|
1729
|
+
body.paths = options.paths;
|
|
1730
|
+
}
|
|
1731
|
+
if (options.fileFilters) {
|
|
1732
|
+
body.file_filters = {
|
|
1733
|
+
...options.fileFilters.includeGlobs ? { include_globs: options.fileFilters.includeGlobs } : {},
|
|
1734
|
+
...options.fileFilters.excludeGlobs ? { exclude_globs: options.fileFilters.excludeGlobs } : {},
|
|
1735
|
+
...options.fileFilters.extensionFilters ? { extension_filters: options.fileFilters.extensionFilters } : {}
|
|
1736
|
+
};
|
|
1737
|
+
}
|
|
1738
|
+
if (options.context) {
|
|
1739
|
+
body.context = {
|
|
1740
|
+
...typeof options.context.before === "number" ? { before: options.context.before } : {},
|
|
1741
|
+
...typeof options.context.after === "number" ? { after: options.context.after } : {}
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
if (options.limits) {
|
|
1745
|
+
body.limits = {
|
|
1746
|
+
...typeof options.limits.maxLines === "number" ? { max_lines: options.limits.maxLines } : {},
|
|
1747
|
+
...typeof options.limits.maxMatchesPerFile === "number" ? { max_matches_per_file: options.limits.maxMatchesPerFile } : {}
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
if (options.pagination) {
|
|
1751
|
+
body.pagination = {
|
|
1752
|
+
...typeof options.pagination.cursor === "string" && options.pagination.cursor.trim() !== "" ? { cursor: options.pagination.cursor } : {},
|
|
1753
|
+
...typeof options.pagination.limit === "number" ? { limit: options.pagination.limit } : {}
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
const response = await this.api.post({ path: "repos/grep", body }, jwt);
|
|
1757
|
+
const raw = grepResponseSchema.parse(await response.json());
|
|
1758
|
+
return {
|
|
1759
|
+
query: {
|
|
1760
|
+
pattern: raw.query.pattern,
|
|
1761
|
+
caseSensitive: raw.query.case_sensitive
|
|
1762
|
+
},
|
|
1763
|
+
repo: {
|
|
1764
|
+
ref: raw.repo.ref,
|
|
1765
|
+
commit: raw.repo.commit
|
|
1766
|
+
},
|
|
1767
|
+
matches: raw.matches.map(transformGrepFileMatch),
|
|
1768
|
+
nextCursor: raw.next_cursor ?? void 0,
|
|
1769
|
+
hasMore: raw.has_more
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1674
1772
|
async pullUpstream(options = {}) {
|
|
1675
1773
|
const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
|
|
1676
1774
|
const jwt = await this.generateJWT(this.id, {
|