@osdlc/typed-gh 0.14.0 → 0.15.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/CHANGELOG.md +13 -0
- package/README.md +9 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/verbs.d.ts +27 -4
- package/dist/verbs.js +31 -7
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @osdlc/typed-gh
|
|
2
2
|
|
|
3
|
+
## 0.15.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4f764b7: `graphql` (experimental): fill the target's owner or repo name with the new `fromTarget('owner')` / `fromTarget('repo')` markers. **Breaking for `graphql` callers:** a plain string variable is now always sent as written, so a real value of `{owner}` or `{repo}` (a branch name, say) is no longer replaced. Change `{ owner: '{owner}', name: '{repo}' }` to `{ owner: fromTarget('owner'), name: fromTarget('repo') }`. REST endpoints keep the `{owner}/{repo}` path template, which mirrors gh's own syntax.
|
|
8
|
+
|
|
9
|
+
## 0.14.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [e0aaba5]
|
|
14
|
+
- @osdlc/typed-git@0.12.0
|
|
15
|
+
|
|
3
16
|
## 0.14.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -466,6 +466,9 @@ const branches = gh.api('repos/{owner}/{repo}/branches', { paginate: true }).bod
|
|
|
466
466
|
`graphql` (experimental) runs a query and returns each page's `data`. It throws when the
|
|
467
467
|
call failed or any page has `errors` or no `data` (`soft.graphql` is `null`). A partial answer counts as a failure. `nodesAt` joins
|
|
468
468
|
one connection's `nodes` across the pages, and is `null` when any page lacks them.
|
|
469
|
+
`fromTarget('owner')` and `fromTarget('repo')` fill a variable from the client's repo, or let gh
|
|
470
|
+
fill it from the clone. A plain string is always sent as written, so a real value of `{owner}` stays
|
|
471
|
+
`{owner}`.
|
|
469
472
|
|
|
470
473
|
```ts
|
|
471
474
|
const query = `query($owner: String!, $name: String!, $endCursor: String) {
|
|
@@ -476,7 +479,11 @@ const query = `query($owner: String!, $name: String!, $endCursor: String) {
|
|
|
476
479
|
}
|
|
477
480
|
}
|
|
478
481
|
}`
|
|
479
|
-
const pages = gh.graphql(
|
|
482
|
+
const pages = gh.graphql(
|
|
483
|
+
query,
|
|
484
|
+
{ owner: fromTarget('owner'), name: fromTarget('repo') },
|
|
485
|
+
{ paginate: true },
|
|
486
|
+
)
|
|
480
487
|
const prs = nodesAt(pages, ['repository', 'pullRequests'])
|
|
481
488
|
```
|
|
482
489
|
|
|
@@ -663,6 +670,7 @@ The experimental items:
|
|
|
663
670
|
- `nodesAt`
|
|
664
671
|
- `GraphqlOptions`
|
|
665
672
|
- `GraphqlVariable`
|
|
673
|
+
- `fromTarget` and `FromTarget`
|
|
666
674
|
|
|
667
675
|
Every other export and method is stable, `prDiff` included. So is `@osdlc/typed-gh/testing`: its
|
|
668
676
|
builders and their row types. Their default values may change in any minor release.
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export { classifyGhFailure, type GhFailure, type GhFailureKind } from './failure
|
|
|
23
23
|
export { type Soft, type TriedAsync, type TriedSync } from './doors.ts';
|
|
24
24
|
export { runVerb, runVerbAsync, type RunVerbAsyncOptions, type RunVerbOptions } from './run.ts';
|
|
25
25
|
export { Gh, defaultRunnerFactory, type GhOptions, type GhRepoOptions, type RunnerFactory, } from './sync.ts';
|
|
26
|
-
export { api, authStatus, createPr, editPr, editPrBody, graphql, createLabel, createReview, editLabel, installed, issueList, issueView, labelList, nodesAt, openPrsForBranch, pickPrForBranch, prBody, prComment, prSetDraft, issueCommentEdit, prDiff, prList, prMerge, prReviewThreads, prUpdateBranch, prView, repoList, repoView, searchPrs, setIssueLabel, PR_LIST_FIELDS, PR_REF_FIELDS, PR_VIEW_FIELDS, REPO_FIELDS, SEARCH_PR_FIELDS, type ApiOptions, type ApiResponse, type AuthStatus, type CreateLabelOptions, type CreatePrOptions, type CreateReviewOptions, type GhTarget, type GraphqlOptions, type GraphqlVariable, type GhVerb, type IssueListOptions, type ListResult, type PrListOptions, type PrMergeMethod, type RepoListOptions, type ReviewComment, type ReviewThread, type SearchPrsOptions, } from './verbs.ts';
|
|
26
|
+
export { api, authStatus, createPr, editPr, editPrBody, fromTarget, graphql, createLabel, createReview, editLabel, installed, issueList, issueView, labelList, nodesAt, openPrsForBranch, pickPrForBranch, prBody, prComment, prSetDraft, issueCommentEdit, prDiff, prList, prMerge, prReviewThreads, prUpdateBranch, prView, repoList, repoView, searchPrs, setIssueLabel, PR_LIST_FIELDS, PR_REF_FIELDS, PR_VIEW_FIELDS, REPO_FIELDS, SEARCH_PR_FIELDS, type ApiOptions, type ApiResponse, type AuthStatus, type CreateLabelOptions, type CreatePrOptions, type CreateReviewOptions, type FromTarget, type GhTarget, type GraphqlOptions, type GraphqlVariable, type GhVerb, type IssueListOptions, type ListResult, type PrListOptions, type PrMergeMethod, type RepoListOptions, type ReviewComment, type ReviewThread, type SearchPrsOptions, } from './verbs.ts';
|
|
27
27
|
export { anyCheckFailed, normalizeAuthorLogin, parsePullRequest } from './parse.ts';
|
|
28
28
|
export { ownerRepoSlug, parseOwnerRepo, parsePrRef, parsePrUrl, type PrRef, type PullRequestRef, } from './repo.ts';
|
|
29
29
|
export type { Actor, CheckConclusion, CheckRun, Comment, IssueRow, Label, MergeableState, MergeStateStatus, OwnerRepo, PullRequest, PrSearchHit, PullRequestState, Repository, RepositoryVisibility, Review, ReviewDecision, ReviewState, } from './types.ts';
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@ export { classifyGhFailure } from "./failure.js";
|
|
|
23
23
|
export {} from "./doors.js";
|
|
24
24
|
export { runVerb, runVerbAsync } from "./run.js";
|
|
25
25
|
export { Gh, defaultRunnerFactory, } from "./sync.js";
|
|
26
|
-
export { api, authStatus, createPr, editPr, editPrBody, graphql, createLabel, createReview, editLabel, installed, issueList, issueView, labelList, nodesAt, openPrsForBranch, pickPrForBranch, prBody, prComment, prSetDraft, issueCommentEdit, prDiff, prList, prMerge, prReviewThreads, prUpdateBranch, prView, repoList, repoView, searchPrs, setIssueLabel, PR_LIST_FIELDS, PR_REF_FIELDS, PR_VIEW_FIELDS, REPO_FIELDS, SEARCH_PR_FIELDS, } from "./verbs.js";
|
|
26
|
+
export { api, authStatus, createPr, editPr, editPrBody, fromTarget, graphql, createLabel, createReview, editLabel, installed, issueList, issueView, labelList, nodesAt, openPrsForBranch, pickPrForBranch, prBody, prComment, prSetDraft, issueCommentEdit, prDiff, prList, prMerge, prReviewThreads, prUpdateBranch, prView, repoList, repoView, searchPrs, setIssueLabel, PR_LIST_FIELDS, PR_REF_FIELDS, PR_VIEW_FIELDS, REPO_FIELDS, SEARCH_PR_FIELDS, } from "./verbs.js";
|
|
27
27
|
export { anyCheckFailed, normalizeAuthorLogin, parsePullRequest } from "./parse.js";
|
|
28
28
|
export { ownerRepoSlug, parseOwnerRepo, parsePrRef, parsePrUrl, } from "./repo.js";
|
|
29
29
|
// command-seam's error and runner types appear in this package's signatures, so
|
package/dist/verbs.d.ts
CHANGED
|
@@ -223,11 +223,34 @@ export interface ApiOptions {
|
|
|
223
223
|
*/
|
|
224
224
|
export declare function api(endpoint: string, opts?: ApiOptions, target?: GhTarget): GhVerb<ApiResponse>;
|
|
225
225
|
/**
|
|
226
|
-
* A GraphQL variable
|
|
226
|
+
* A GraphQL variable filled from the target's repository: its owner, or its
|
|
227
|
+
* name. Make one with {@link fromTarget}.
|
|
227
228
|
*
|
|
228
229
|
* @experimental
|
|
229
230
|
*/
|
|
230
|
-
export
|
|
231
|
+
export interface FromTarget {
|
|
232
|
+
readonly fromTarget: 'owner' | 'repo';
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* A {@link graphql} variable that holds the target repository's owner or
|
|
236
|
+
* name. With a target repo, the value comes from it. Without one, gh fills
|
|
237
|
+
* it from the clone's repository. A plain string is always sent as written,
|
|
238
|
+
* so a real value of `{owner}` stays `{owner}`.
|
|
239
|
+
*
|
|
240
|
+
* ```ts
|
|
241
|
+
* gh.graphql(query, { owner: fromTarget('owner'), name: fromTarget('repo') })
|
|
242
|
+
* ```
|
|
243
|
+
*
|
|
244
|
+
* @experimental
|
|
245
|
+
*/
|
|
246
|
+
export declare function fromTarget(part: 'owner' | 'repo'): FromTarget;
|
|
247
|
+
/**
|
|
248
|
+
* A GraphQL variable. gh sends a string with `-f`, as written, and the rest
|
|
249
|
+
* with `-F`. A {@link FromTarget} is filled from the target's repository.
|
|
250
|
+
*
|
|
251
|
+
* @experimental
|
|
252
|
+
*/
|
|
253
|
+
export type GraphqlVariable = string | number | boolean | null | FromTarget;
|
|
231
254
|
/**
|
|
232
255
|
* Options for {@link graphql}.
|
|
233
256
|
*
|
|
@@ -249,8 +272,8 @@ export interface GraphqlOptions {
|
|
|
249
272
|
* carries `errors` or lacks `data`. A partial answer counts as a failure. Read one
|
|
250
273
|
* connection across the pages with {@link nodesAt}.
|
|
251
274
|
*
|
|
252
|
-
* A
|
|
253
|
-
*
|
|
275
|
+
* A {@link fromTarget} variable is filled from the target's repo, or by gh
|
|
276
|
+
* from the clone. A plain string is sent as written. A document holding any mutation or
|
|
254
277
|
* subscription throws `RangeError`, as does a variable named `query` or
|
|
255
278
|
* `operationName`, which gh would send as the request's own fields. This is a
|
|
256
279
|
* read, and changes go through `raw`.
|
package/dist/verbs.js
CHANGED
|
@@ -410,6 +410,24 @@ function flattenPages(body) {
|
|
|
410
410
|
return body;
|
|
411
411
|
return body.flat();
|
|
412
412
|
}
|
|
413
|
+
/**
|
|
414
|
+
* A {@link graphql} variable that holds the target repository's owner or
|
|
415
|
+
* name. With a target repo, the value comes from it. Without one, gh fills
|
|
416
|
+
* it from the clone's repository. A plain string is always sent as written,
|
|
417
|
+
* so a real value of `{owner}` stays `{owner}`.
|
|
418
|
+
*
|
|
419
|
+
* ```ts
|
|
420
|
+
* gh.graphql(query, { owner: fromTarget('owner'), name: fromTarget('repo') })
|
|
421
|
+
* ```
|
|
422
|
+
*
|
|
423
|
+
* @experimental
|
|
424
|
+
*/
|
|
425
|
+
export function fromTarget(part) {
|
|
426
|
+
if (part !== 'owner' && part !== 'repo') {
|
|
427
|
+
throw new RangeError(`fromTarget: expected 'owner' or 'repo', got ${JSON.stringify(part)}`);
|
|
428
|
+
}
|
|
429
|
+
return Object.freeze({ fromTarget: part });
|
|
430
|
+
}
|
|
413
431
|
/**
|
|
414
432
|
* True when any operation in a GraphQL document is a `mutation` or a
|
|
415
433
|
* `subscription`. Strings and comments are dropped first, and only the words
|
|
@@ -439,8 +457,8 @@ function writesOrStreams(document) {
|
|
|
439
457
|
* carries `errors` or lacks `data`. A partial answer counts as a failure. Read one
|
|
440
458
|
* connection across the pages with {@link nodesAt}.
|
|
441
459
|
*
|
|
442
|
-
* A
|
|
443
|
-
*
|
|
460
|
+
* A {@link fromTarget} variable is filled from the target's repo, or by gh
|
|
461
|
+
* from the clone. A plain string is sent as written. A document holding any mutation or
|
|
444
462
|
* subscription throws `RangeError`, as does a variable named `query` or
|
|
445
463
|
* `operationName`, which gh would send as the request's own fields. This is a
|
|
446
464
|
* read, and changes go through `raw`.
|
|
@@ -467,14 +485,20 @@ export function graphql(query, variables = {}, opts = {}, target) {
|
|
|
467
485
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key) || key === 'query' || key === 'operationName') {
|
|
468
486
|
throw new RangeError(`graphql: bad variable name ${JSON.stringify(key)}`);
|
|
469
487
|
}
|
|
470
|
-
if (typeof value === '
|
|
471
|
-
const
|
|
488
|
+
if (typeof value === 'object' && value !== null) {
|
|
489
|
+
const part = value.fromTarget;
|
|
490
|
+
if (part !== 'owner' && part !== 'repo') {
|
|
491
|
+
throw new RangeError(`graphql: variable ${key} is not a fromTarget marker`);
|
|
492
|
+
}
|
|
493
|
+
const filled = part === 'owner' ? owner : name;
|
|
494
|
+
// `-F` lets gh fill the placeholder from the clone; `-f` never fills.
|
|
472
495
|
if (filled !== undefined)
|
|
473
496
|
argv.push('-f', `${key}=${filled}`);
|
|
474
|
-
else if (value === '{owner}' || value === '{repo}')
|
|
475
|
-
argv.push('-F', `${key}=${value}`);
|
|
476
497
|
else
|
|
477
|
-
argv.push('-
|
|
498
|
+
argv.push('-F', `${key}={${part}}`);
|
|
499
|
+
}
|
|
500
|
+
else if (typeof value === 'string') {
|
|
501
|
+
argv.push('-f', `${key}=${value}`);
|
|
478
502
|
}
|
|
479
503
|
else {
|
|
480
504
|
argv.push('-F', `${key}=${value === null ? 'null' : String(value)}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdlc/typed-gh",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "A typed GitHub client for TypeScript over the gh CLI. A total PullRequest/Review/CheckRun model, pure argv builders and parsers, and a tri-modal client — queries return parsed values, mutations throw, raw() is the escape hatch. Uses gh's own credentials; reads no token.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": "sksizer",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"LICENSE-APACHE"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@osdlc/
|
|
30
|
-
"@osdlc/
|
|
31
|
-
"@osdlc/
|
|
29
|
+
"@osdlc/command-seam": "^0.14.0",
|
|
30
|
+
"@osdlc/typed-git": "^0.12.0",
|
|
31
|
+
"@osdlc/result": "^0.1.0"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"prettier": "3.9.6",
|
|
59
59
|
"typescript": "~6.0.3",
|
|
60
60
|
"vitest": "^5.0.5",
|
|
61
|
-
"@osdlc/
|
|
62
|
-
"@osdlc/
|
|
61
|
+
"@osdlc/prettier-config": "^0.3.1",
|
|
62
|
+
"@osdlc/tsconfig": "^0.4.1"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "tsc -p tsconfig.build.json",
|