@radicaltools/cli 0.3.4 → 0.5.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 (66) hide show
  1. package/README.md +152 -27
  2. package/dist/chunk-J5ULJOOY.js +28 -0
  3. package/dist/dist-TKLLLHVM.js +219 -0
  4. package/dist/hub-catalogue/concern/concern-api-collections.radical +24 -12
  5. package/dist/hub-catalogue/concern/concern-api-errors.radical +26 -13
  6. package/dist/hub-catalogue/concern/concern-api-evolution.radical +26 -13
  7. package/dist/hub-catalogue/concern/concern-api-idempotency.radical +28 -14
  8. package/dist/hub-catalogue/concern/concern-api-resource-design.radical +24 -12
  9. package/dist/hub-catalogue/concern/concern-api-style-guide.radical +26 -13
  10. package/dist/hub-catalogue/concern/concern-architecture-style.radical +26 -13
  11. package/dist/hub-catalogue/concern/concern-audit-trail.radical +26 -13
  12. package/dist/hub-catalogue/concern/concern-authentication.radical +18 -9
  13. package/dist/hub-catalogue/concern/concern-authorization.radical +34 -17
  14. package/dist/hub-catalogue/concern/concern-availability.radical +20 -10
  15. package/dist/hub-catalogue/concern/concern-backend-stack.radical +16 -8
  16. package/dist/hub-catalogue/concern/concern-backup-recovery.radical +30 -15
  17. package/dist/hub-catalogue/concern/concern-caching.radical +28 -14
  18. package/dist/hub-catalogue/concern/concern-capacity.radical +18 -9
  19. package/dist/hub-catalogue/concern/concern-code-documentation.radical +32 -16
  20. package/dist/hub-catalogue/concern/concern-code-quality-gate.radical +30 -15
  21. package/dist/hub-catalogue/concern/concern-code-review-branching.radical +32 -16
  22. package/dist/hub-catalogue/concern/concern-code-style.radical +24 -12
  23. package/dist/hub-catalogue/concern/concern-communication-style.radical +28 -14
  24. package/dist/hub-catalogue/concern/concern-data-classification.radical +20 -10
  25. package/dist/hub-catalogue/concern/concern-data-consistency.radical +20 -10
  26. package/dist/hub-catalogue/concern/concern-data-store.radical +24 -12
  27. package/dist/hub-catalogue/concern/concern-decomposition.radical +28 -14
  28. package/dist/hub-catalogue/concern/concern-definition-of-done.radical +26 -13
  29. package/dist/hub-catalogue/concern/concern-delivery-metrics.radical +22 -11
  30. package/dist/hub-catalogue/concern/concern-dependency-hygiene.radical +28 -14
  31. package/dist/hub-catalogue/concern/concern-deployment.radical +24 -12
  32. package/dist/hub-catalogue/concern/concern-encryption.radical +28 -14
  33. package/dist/hub-catalogue/concern/concern-error-handling-logging.radical +28 -14
  34. package/dist/hub-catalogue/concern/concern-eu-dora.radical +26 -13
  35. package/dist/hub-catalogue/concern/concern-frontend-stack.radical +28 -14
  36. package/dist/hub-catalogue/concern/concern-incident-management.radical +26 -13
  37. package/dist/hub-catalogue/concern/concern-infrastructure.radical +34 -17
  38. package/dist/hub-catalogue/concern/concern-integration-resilience.radical +26 -13
  39. package/dist/hub-catalogue/concern/concern-messaging.radical +18 -9
  40. package/dist/hub-catalogue/concern/concern-module-boundaries.radical +18 -9
  41. package/dist/hub-catalogue/concern/concern-observability.radical +22 -11
  42. package/dist/hub-catalogue/concern/concern-operational-readiness.radical +28 -14
  43. package/dist/hub-catalogue/concern/concern-personal-data.radical +42 -21
  44. package/dist/hub-catalogue/concern/concern-quality-priorities.radical +24 -12
  45. package/dist/hub-catalogue/concern/concern-rate-limiting.radical +30 -15
  46. package/dist/hub-catalogue/concern/concern-release-versioning.radical +28 -14
  47. package/dist/hub-catalogue/concern/concern-retention.radical +28 -14
  48. package/dist/hub-catalogue/concern/concern-secrets.radical +32 -16
  49. package/dist/hub-catalogue/concern/concern-secure-coding.radical +28 -14
  50. package/dist/hub-catalogue/concern/concern-secure-development.radical +26 -13
  51. package/dist/hub-catalogue/concern/concern-security-detection.radical +22 -11
  52. package/dist/hub-catalogue/concern/concern-supply-chain.radical +28 -14
  53. package/dist/hub-catalogue/concern/concern-technical-debt.radical +30 -15
  54. package/dist/hub-catalogue/concern/concern-technology-lifecycle.radical +26 -13
  55. package/dist/hub-catalogue/concern/concern-tenant-isolation.radical +26 -13
  56. package/dist/hub-catalogue/concern/concern-test-strategy.radical +26 -13
  57. package/dist/hub-catalogue/concern/concern-threat-modelling.radical +26 -13
  58. package/dist/index.js +11911 -567
  59. package/dist/pdfjs-SWTQBTNZ.js +33203 -0
  60. package/dist/tree-sitter/tree-sitter-c-sharp.wasm +0 -0
  61. package/dist/tree-sitter/tree-sitter-go.wasm +0 -0
  62. package/dist/tree-sitter/tree-sitter-java.wasm +0 -0
  63. package/dist/tree-sitter/tree-sitter.cjs +4075 -0
  64. package/dist/tree-sitter/tree-sitter.wasm +0 -0
  65. package/dist/undici-ZXQJUQQA.js +18990 -0
  66. package/package.json +2 -1
package/README.md CHANGED
@@ -214,13 +214,19 @@ radical implement "Orders API" --path services/orders-api
214
214
  radical implement 8c66e024-… --path apps/cli --path apps/cli-shared
215
215
  radical implement "Orders API" # where it is built
216
216
  radical implement "Orders API" --remove
217
+ radical implement 8c66e024-… --remove # an element the model no longer has
217
218
  ```
218
219
 
219
220
  The element is its id or its name (an element of another model of the
220
221
  federation, as fetched, too); a name two elements share needs the id. Paths
221
222
  are from the working directory and kept from the repository's root; they
222
223
  replace the element's paths. An element without an entry is built where its
223
- nearest parent with one is.
224
+ nearest parent with one is. `--remove` also takes out an entry whose element
225
+ the model no longer has, by its id or name (`radical verify --remove` too).
226
+ The file is the one `radical check` reads: found from the model folder up to
227
+ the repository's root, else a new one in the repository's `.radical/` (outside
228
+ a repository, beside the model folder), where the MCP server and Studio write
229
+ it too. Keys the command does not know (`$schema`, an `owner`) stay.
224
230
 
225
231
  ## radical diff
226
232
 
@@ -283,7 +289,7 @@ installs the hooks for `.radical/model/` and saves its base once.
283
289
  ## radical federation
284
290
 
285
291
  ```sh
286
- node apps/cli/dist/index.js federation open|sync|watch path/to/model [--force]
292
+ node apps/cli/dist/index.js federation fetch [path/to/model] [--quiet] [--detach]
287
293
  ```
288
294
 
289
295
  One model across many repositories. A model folder names the models it
@@ -299,27 +305,22 @@ depends on in `deps.json`:
299
305
  ```
300
306
 
301
307
  `repo` is a git address or a path relative to the model folder, `path` the
302
- model folder in that repository, `ref` a branch, tag or commit.
303
-
304
- - `open` fetches each dependency at its ref into the cache (`$RADICAL_CACHE`,
305
- else the user's cache directory; one bare partial clone per repository, so
306
- only the model files are downloaded) and composes one model folder in
307
- `.radical/federation/`: the folder's own elements, relations, views and
308
- metamodel as they are, and every dependency's elements and relations with
309
- `origin: "<name>@<commit>"`. Studio and the MCP server open that folder;
310
- they draw elements with an origin dashed and refuse every change to them
311
- but their place. The composed folder gets a base composed the same way
312
- (Changes on branch shows only this model's changes), `check.json` and the
313
- test results. Changes not carried home yet are carried first.
314
- - `sync` writes what has no origin back to the model folder, and names each
315
- change to an element or relation with an origin, which it keeps out and
316
- undoes in the composed folder (exit 1). When the model folder changed too,
317
- nothing is carried unless `--force`; `open --force` composes again from the
318
- model folder and drops the composed folder's changes.
319
- - `watch` opens, then keeps both in step until stopped (Ctrl-C).
320
-
321
- Dependencies are not composed transitively. With a `deps.json`,
322
- `radical check` checks the model composed with its dependencies (see below).
308
+ model folder in that repository, `ref` a branch, tag or commit, or `latest`
309
+ (the newest version tag, else the default branch, at each fetch).
310
+
311
+ `fetch` fetches each dependency at its ref into the cache (`$RADICAL_CACHE`,
312
+ else the user's cache directory; one bare partial clone per repository, so
313
+ only the model files are downloaded), and the models it depends on in turn
314
+ (a model pinned twice at the nearest pin: the folder's own `deps.json`
315
+ first). It writes their elements, relations and views, each with
316
+ `origin: "<name>@<commit>"`, into `.state/federation.json` in the model
317
+ folder, out of git. Studio and the MCP server open the model folder itself
318
+ and show them beside its own, read-only; they never write them into the
319
+ folder. Without a `deps.json` there is nothing to fetch (exit 0). `--quiet`
320
+ prints nothing, `--detach` fetches in the background and returns at once:
321
+ `radical hooks install` runs `fetch --quiet --detach` after a checkout, a
322
+ commit, a pull and a rebase. With a `deps.json`, `radical check` checks the
323
+ model composed with its dependencies (see below).
323
324
 
324
325
  ## radical check
325
326
 
@@ -374,7 +375,14 @@ check, so an existing model can adopt a rule before every gap is closed.
374
375
  `--ratchet` lowers each `max` to the count found now and writes the config
375
376
  back; it never raises one. A rule that did not run keeps its `max`: the
376
377
  `test-*` rules without `--report` (the output marks them `–` and "not run"),
377
- every rule but the folder's when the folder is no model.
378
+ every rule but the folder's when the folder is no model. In a repository
379
+ that judges only its part of a model kept in a repository of its own
380
+ (`"model": { "repo": … }` in `.radical/radical.json`), the model's
381
+ `check.json` holds the whole model's baselines: `--ratchet` refuses to lower
382
+ them (exit 2), and lowers only a config of the repository's own named with
383
+ `--config`. With `--alone` or `--trigger`, which leave part of the model out
384
+ (the models `deps.json` names, the metric conditions of other events),
385
+ `--ratchet` lowers no baseline (exit 2).
378
386
 
379
387
  ### Goals
380
388
 
@@ -421,7 +429,10 @@ The model names no test: the repository binds its tests to the model's
421
429
  scenarios and fitness functions in `.radical/radical.json` ("verifies"), and
422
430
  a scenario or fitness function passes when every test bound to it passed and
423
431
  its `metrics` (metric conditions only) hold. A test is named as Vitest and
424
- Playwright print it, from the repository's root:
432
+ Playwright print it, from the repository's root, its parts joined by `›`
433
+ (Vitest's `>` is read too, and `radical verify` keeps it with `›`; the
434
+ project Playwright or Vitest prints before the file, `[chromium] › ` or
435
+ `|unit| `, and the line and column after it, `:2:3`, are left out):
425
436
 
426
437
  ```sh
427
438
  radical verify "Prints JSON" --test "apps/cli/src/cli.test.ts › radical check › prints the result as JSON"
@@ -432,6 +443,14 @@ radical verify "Prints JSON" # its tests
432
443
  radical verify "Prints JSON" --drop "<test>" # take one off
433
444
  ```
434
445
 
446
+ A test may be bound to a scenario or fitness function of another model of
447
+ the federation (a consumer contract test): it is this repository's, so
448
+ `radical check` judges it with the model's own (a failed or missing test is
449
+ an error here), and `--trace` shows that scenario's path, with the other
450
+ model's requirement above a failed one broken, as the check says. Before any
451
+ results, `--trace` lists the tests bound to each scenario and fitness function
452
+ with no outcome yet.
453
+
435
454
  `radical check` warns about a scenario the repository must verify (an
436
455
  element it builds satisfies its requirement) that has no test bound and no
437
456
  metric condition (`scenario-not-verified-here`), and about a test still
@@ -556,6 +575,104 @@ of its tool's real output; `src/sensors/contract.test.ts` runs every adapter on
556
575
  its fixture and checks that it writes valid radical-metrics/1 and takes no
557
576
  threshold. Pull requests welcome.
558
577
 
578
+ ## radical assay
579
+
580
+ Radical Assay finds the model in existing code (experimental). `extract` is
581
+ its deterministic part: it reads the facts of each code repository in the
582
+ directories given, each with its file and line, and writes no model; an agent
583
+ turns the facts into one over MCP (`assay_start`, see the MCP server's
584
+ README).
585
+
586
+ ```bash
587
+ radical assay extract ../shop # every repository in ../shop
588
+ radical assay extract orders storefront --report storefront=reports/unit.json
589
+ radical assay extract . --json # the facts and links as JSON
590
+ radical assay extract ~/handover/billing.zip # code handed over as an archive
591
+ ```
592
+
593
+ A directory is a repository when it has a `.git`; one that is not stands for
594
+ the repositories directly inside it, or is a folder of code itself when it
595
+ holds none. A directory of nothing but folders is searched three levels down. A
596
+ `.zip` file is unpacked into `.radical/assay/unpacked/` first, without any
597
+ `.git` folder it holds (and refused whole when an entry would land outside
598
+ it). A folder of code is left as it was: its facts go to
599
+ `.radical/assay/facts/` of the current directory. Nothing is fetched or
600
+ cloned. For each repository it reads, from the files git lists:
601
+
602
+ - units, wherever they are: npm packages, Nx projects (`project.json`),
603
+ Composer projects (PHP, Laravel), Maven and Gradle projects, Go modules (or
604
+ main packages before modules), .NET projects and SQL Server database
605
+ projects (`.sqlproj`), Python projects, VB6 projects, and a folder with a
606
+ Dockerfile no manifest claims (not a `.devcontainer`, nor one that copies
607
+ other units' projects: it builds them, nor a runner image whose compose
608
+ service mounts a unit's folder: that service runs the unit); not a
609
+ workspace's root (a `pyproject.toml` without `[project]`, a `go.mod` with
610
+ no Go code of its own) nor a library vendored in `wwwroot/lib`; each an app, a library or tests,
611
+ with its stack and the frameworks it names;
612
+ - each unit's dependencies, and its references to other units by path (a
613
+ .NET `ProjectReference`, also those `Directory.Build.props` and
614
+ `.targets` add by conditions on the project's name and path, a VB6
615
+ `Reference=*\A…vbp`, a Gradle `project(':x')`, a Go `replace` to a
616
+ folder);
617
+ a VB6 reference to a COM binary another unit builds counts as one;
618
+ - solutions and VB6 groups (`.sln`, `.vbg`);
619
+ - what runs: the services of docker-compose files, Kubernetes manifests and
620
+ .NET Aspire AppHosts, each built from a unit or running a database, queue,
621
+ cache or observability image, with what it depends on or references;
622
+ - calls: OpenAPI operations, gRPC services (`.proto`) with the units that
623
+ register and call them, and addresses in code and configuration (a URL or
624
+ `host:port` naming another unit or service, `lb://name`, a host given as a
625
+ default or named in a variable such as `${CART_HOST}`, a local port only
626
+ one unit listens on or publishes from compose, a gateway's `serviceId`, a
627
+ Feign client's name); a Spring Cloud Config server's files are read as the
628
+ configuration of the applications they are named for, its
629
+ `application.yml` as every client's (a client library's settings only for
630
+ units depending on that library); a gRPC client a library's function makes
631
+ is a client of each unit calling that function; a migrator or seeder
632
+ another service depends on is no call of it; a VB6 socket's host and port and a
633
+ connection string's server and database are followed through the
634
+ constants, variables, record fields and INI settings that hold them;
635
+ - data: the databases connection strings name (ADO and OLE DB, ODBC, JDBC,
636
+ .NET, PDO, Go's MySQL driver, database URLs, a `.env` file's
637
+ `DB_CONNECTION` (or Laravel's default connection) and `DB_DATABASE`, a
638
+ compose service's environment, a Prisma datasource, an SQLite URL; not a
639
+ commented line, nor a placeholder name, which a dump's database stands in
640
+ for) and the tables SQL names; a table SQL creates or alters, Laravel's
641
+ migrations create, or an ORM class maps (JPA, Entity Framework Core, Django
642
+ with Wagtail's models, SQLAlchemy, TypeORM, Prisma, Doctrine), with its
643
+ columns and the table each foreign key references, and many-to-many join
644
+ tables;
645
+ migrations count in order, so a table a later one drops is gone; a table
646
+ in a schema is named by schema and name only where two schemas hold its
647
+ name. An Access file's own tables are read by the
648
+ MCP server only: the CLI notes each Access file a unit uses;
649
+ - statuses: the values an enum named for a status, a `CHECK … IN` list, an
650
+ SQL `ENUM`, a table's flags (boolean columns, nullable dates of an event)
651
+ or a field set to quoted values (`!Paid = "Y"`) give, and the lines that
652
+ set each value;
653
+ - screens: each VB6 form and ActiveX document, with its caption, size, controls at their
654
+ positions and the forms its code opens;
655
+ - entry points: HTTP routes in code (Express, NestJS, Spring, ASP.NET Core,
656
+ Flask, FastAPI, Go), a VB6 form's caption, menu items and any control with
657
+ a Click handler, VB6 Timers that do more than change the screen and `Handle…` procedures, scheduled jobs and
658
+ message handlers; and each unit's test framework;
659
+ - the tests its reports name (Vitest, Jest or Playwright JSON, JUnit XML; by
660
+ default its `reports/`), as `<file> › <title>` from its root;
661
+ - its documents: READMEs, the documents of `docs/` and decisions folders and
662
+ its ADR records, each with its title and headings.
663
+
664
+ Documentation from outside the code (folders, `.zip` files, public links) is
665
+ taken over MCP (`assay_start`'s `sources`, `assay_add_sources`).
666
+
667
+ They go to the repository's `.radical/assay/facts.json`. Then the units are
668
+ linked across the repositories: references, dependencies, `depends_on` and
669
+ connection strings as observed; OpenAPI paths, gRPC clients and addresses as
670
+ inferred. Each link cites the facts of both sides.
671
+
672
+ `packages/assay/bench` measures it on pinned public repositories of several
673
+ stacks and ages: `npx tsx packages/assay/bench/bench.ts` (and `--held-out`
674
+ for the ones no rule was tuned on).
675
+
559
676
  ## radical fuzz
560
677
 
561
678
  Runs a project's fuzz files (Radical Crucible): tests that do random sequences
@@ -660,12 +777,20 @@ ports (`<ports>+NN`, `+100+NN`, `+200+NN`) and a `PROMPT.md` with its area;
660
777
  `BRIEF.md` names the commit, the commits and the model elements changed since
661
778
  the last round (by area), the open findings, the setup, the rules and the
662
779
  report's JSON form. `--since`, `--from` and `--no-build` change what it
663
- counts from, the first run's number and whether it builds. The brief asks
780
+ counts from, the first run's number and whether it builds; a run number an
781
+ earlier round has is refused (exit 2). The brief asks
664
782
  that scripts name no absolute path (they find the repository by walking up to
665
783
  `.radical/crucible/crucible.json`), since a finding's script is copied out of the round.
666
784
  `verify` serves a run's build on its ports (each server `serve` lists, on the
667
785
  run's port it names: `app`, `hub` or `other`), runs its scripts from its
668
- folder and stops the servers. `record` writes a report's findings (`open`, or
786
+ folder and stops the servers; a script not in the folder stops it before
787
+ anything runs (exit 2). A script shows the bug when it exits 1, and
788
+ says so in a line of its own (`REPRODUCED: yes` or `REPRODUCED: no`; `BUG: …`
789
+ and `FINDING: …` count as yes, whatever they say): `verify` prints those lines and whether the
790
+ bug shows for each script (the line wins, as a script that throws exits 1
791
+ too, and it says when exit and line disagree), keeps both in `round.json`, and
792
+ ends with the scripts that show the bug and those that do not. A run's folder
793
+ is `run-NN` in its round's folder, wherever the rounds folder is now. `record` writes a report's findings (`open`, or
669
794
  `question`) with copies of their scripts and of the screenshot each names,
670
795
  and warns about a copied script that names the repository's or the round's
671
796
  absolute paths.
@@ -0,0 +1,28 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __commonJS = (cb, mod) => function __require2() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
14
+
15
+ // <define:__RADICAL_BUILD__>
16
+ var define_RADICAL_BUILD_default;
17
+ var init_define_RADICAL_BUILD = __esm({
18
+ "<define:__RADICAL_BUILD__>"() {
19
+ define_RADICAL_BUILD_default = { version: "0.5.0", commit: "166db2f", date: "2026-11-16", release: true };
20
+ }
21
+ });
22
+
23
+ export {
24
+ __require,
25
+ __commonJS,
26
+ init_define_RADICAL_BUILD,
27
+ define_RADICAL_BUILD_default
28
+ };
@@ -0,0 +1,219 @@
1
+ import {
2
+ init_define_RADICAL_BUILD
3
+ } from "./chunk-J5ULJOOY.js";
4
+
5
+ // ../../packages/assay/node_modules/unpdf/dist/index.mjs
6
+ init_define_RADICAL_BUILD();
7
+ var resolvedModule;
8
+ var isNode = globalThis.process?.release?.name === "node";
9
+ var isBrowser = typeof window !== "undefined";
10
+ async function getDocumentProxy(data, options = {}) {
11
+ const { getDocument } = await getResolvedPDFJS();
12
+ const pdf = await getDocument({
13
+ data,
14
+ isEvalSupported: false,
15
+ // See: https://github.com/mozilla/pdf.js/issues/4244#issuecomment-1479534301
16
+ useSystemFonts: true,
17
+ ...options
18
+ }).promise;
19
+ return pdf;
20
+ }
21
+ async function getResolvedPDFJS() {
22
+ if (!resolvedModule) {
23
+ await resolvePDFJSImports();
24
+ }
25
+ return resolvedModule;
26
+ }
27
+ async function resolvePDFJSImports(pdfjsResolver, { force = false } = {}) {
28
+ if (resolvedModule && !force) {
29
+ return;
30
+ }
31
+ if (pdfjsResolver) {
32
+ try {
33
+ resolvedModule = await interopDefault(pdfjsResolver());
34
+ if (resolvedModule && "resolvePDFJS" in resolvedModule) {
35
+ resolvedModule = await resolvedModule.resolvePDFJS();
36
+ }
37
+ return;
38
+ } catch (error) {
39
+ console.error(error);
40
+ throw new Error("Resolving failed. Please check the provided configuration.");
41
+ }
42
+ }
43
+ try {
44
+ const { resolvePDFJS } = await import("./pdfjs-SWTQBTNZ.js");
45
+ resolvedModule = await resolvePDFJS();
46
+ } catch (error) {
47
+ console.error(error);
48
+ throw new Error("PDF.js is not available. Please add the package as a dependency.");
49
+ }
50
+ }
51
+ function isPDFDocumentProxy(data) {
52
+ return typeof data === "object" && data !== null && "_pdfInfo" in data;
53
+ }
54
+ async function interopDefault(m) {
55
+ const resolved = await m;
56
+ return resolved.default || resolved;
57
+ }
58
+ async function extractImages$1(data, pageNumber) {
59
+ const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
60
+ if (pageNumber < 1 || pageNumber > pdf.numPages) {
61
+ throw new Error(`Invalid page number. Must be between 1 and ${pdf.numPages}.`);
62
+ }
63
+ const page = await pdf.getPage(pageNumber);
64
+ const operatorList = await page.getOperatorList();
65
+ const { OPS } = await getResolvedPDFJS();
66
+ const images = [];
67
+ for (let i = 0; i < operatorList.fnArray.length; i++) {
68
+ const op = operatorList.fnArray[i];
69
+ if (op !== OPS.paintImageXObject) {
70
+ continue;
71
+ }
72
+ const imageKey = operatorList.argsArray[i][0];
73
+ const image = await page.objs.get(imageKey);
74
+ if (!image || !image.data || !image.width || !image.height) {
75
+ continue;
76
+ }
77
+ const { width, height, data: data2 } = image;
78
+ const calculatedChannels = data2.length / (width * height);
79
+ if (![1, 3, 4].includes(calculatedChannels)) {
80
+ continue;
81
+ }
82
+ const channels = calculatedChannels;
83
+ images.push({
84
+ data: data2,
85
+ width,
86
+ height,
87
+ channels,
88
+ key: imageKey
89
+ });
90
+ }
91
+ return images;
92
+ }
93
+ async function renderPageAsImage$1(data, pageNumber, options = {}) {
94
+ const canvasFactory = await createIsomorphicCanvasFactory(options.canvas);
95
+ const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data, { canvasFactory });
96
+ const page = await pdf.getPage(pageNumber);
97
+ if (pageNumber < 1 || pageNumber > pdf.numPages) {
98
+ throw new Error(`Invalid page number. Must be between 1 and ${pdf.numPages}.`);
99
+ }
100
+ let outputScale = options.scale || 1;
101
+ let viewport = page.getViewport({ scale: outputScale });
102
+ if (options.width) {
103
+ outputScale = options.width / viewport.width;
104
+ } else if (options.height) {
105
+ outputScale = options.height / viewport.height;
106
+ }
107
+ if (outputScale !== 1 && outputScale > 0) {
108
+ viewport = page.getViewport({ scale: outputScale });
109
+ }
110
+ const ctx = canvasFactory.create(viewport.width, viewport.height);
111
+ await page.render({
112
+ canvasContext: ctx.context,
113
+ viewport
114
+ }).promise;
115
+ const dataUrl = isBrowser ? ctx.canvas.toDataURL() : ctx.canvas.toDataURL();
116
+ const response = await fetch(dataUrl);
117
+ return await response.arrayBuffer();
118
+ }
119
+ async function createIsomorphicCanvasFactory(canvas) {
120
+ const _canvas = canvas ? await interopDefault(canvas()) : void 0;
121
+ return {
122
+ _createCanvas(width, height) {
123
+ if (isBrowser) {
124
+ const canvas2 = document.createElement("canvas");
125
+ canvas2.width = width;
126
+ canvas2.height = height;
127
+ return canvas2;
128
+ }
129
+ if (isNode) {
130
+ if (!_canvas) {
131
+ throw new Error('Failed to resolve "canvas" package.');
132
+ }
133
+ return _canvas.createCanvas(width, height);
134
+ }
135
+ throw new Error("Unsupported environment for canvas creation.");
136
+ },
137
+ create(width, height) {
138
+ const _canvas2 = this._createCanvas(width, height);
139
+ const context = _canvas2.getContext(
140
+ "2d"
141
+ );
142
+ return {
143
+ canvas: _canvas2,
144
+ context
145
+ };
146
+ },
147
+ reset(ctx, width, height) {
148
+ if (ctx.canvas) {
149
+ ctx.canvas.width = width;
150
+ ctx.canvas.height = height;
151
+ }
152
+ },
153
+ destroy(ctx) {
154
+ if (ctx.canvas) {
155
+ ctx.canvas.width = 0;
156
+ ctx.canvas.height = 0;
157
+ }
158
+ ctx.canvas = void 0;
159
+ ctx.context = void 0;
160
+ }
161
+ };
162
+ }
163
+ async function getMeta$1(data) {
164
+ const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
165
+ const meta = await pdf.getMetadata();
166
+ return {
167
+ info: meta?.info ?? {},
168
+ metadata: meta?.metadata?.getAll() ?? {}
169
+ };
170
+ }
171
+ async function extractText$1(data, options = {}) {
172
+ const { mergePages = false } = { ...options };
173
+ const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
174
+ const texts = await Promise.all(
175
+ Array.from({ length: pdf.numPages }, (_, i) => getPageText(pdf, i + 1))
176
+ );
177
+ return {
178
+ totalPages: pdf.numPages,
179
+ text: mergePages ? texts.join("\n").replace(/\s+/g, " ") : texts
180
+ };
181
+ }
182
+ async function getPageText(document2, pageNumber) {
183
+ const page = await document2.getPage(pageNumber);
184
+ const content = await page.getTextContent();
185
+ return content.items.filter((item) => item.str != null).map((item) => item.str + (item.hasEOL ? "\n" : "")).join("");
186
+ }
187
+ async function configureUnPDF(options) {
188
+ const { pdfjs } = { ...options };
189
+ if (pdfjs) {
190
+ await resolvePDFJSImports(pdfjs, { force: true });
191
+ }
192
+ }
193
+ var getMeta = async (...args) => {
194
+ await resolvePDFJSImports();
195
+ return await getMeta$1(...args);
196
+ };
197
+ var extractText = async (...args) => {
198
+ await resolvePDFJSImports();
199
+ return await extractText$1(...args);
200
+ };
201
+ var extractImages = async (...args) => {
202
+ await resolvePDFJSImports();
203
+ return await extractImages$1(...args);
204
+ };
205
+ var renderPageAsImage = async (...args) => {
206
+ await resolvePDFJSImports();
207
+ return await renderPageAsImage$1(...args);
208
+ };
209
+ export {
210
+ configureUnPDF,
211
+ createIsomorphicCanvasFactory,
212
+ extractImages,
213
+ extractText,
214
+ getDocumentProxy,
215
+ getMeta,
216
+ getResolvedPDFJS,
217
+ renderPageAsImage,
218
+ resolvePDFJSImports
219
+ };
@@ -842,73 +842,85 @@
842
842
  "id": "req-paged--derives--need",
843
843
  "sourceId": "req-paged",
844
844
  "targetId": "need",
845
- "relationType": "derives"
845
+ "relationType": "derives",
846
+ "quote": "Callers read collections from this element over HTTP, and the collections grow. Every list has to come back in bounded time and size however large its collection gets, show each item once to a caller who reads it page by page, apply exactly the filters and order the caller asked for or refuse the request, and hand out nothing callers could come to depend on by accident, such as ids or offsets inside a page token. The snippets assume the OpenAPI document at api/openapi.yaml, the application exported from src/app with requests validated against that document, page tokens sealed by src/collections/pageToken, and the tests under tests/ with their fixtures in tests/collections (a seeded /orders collection and a walk helper that reads every page of a list). Names are written in snake_case as Google AIP-158 writes them (page_size, page_token, next_page_token, order_by); where the Resource design pack chose camelCase, read pageSize, pageToken, nextPageToken and orderBy."
846
847
  },
847
848
  {
848
849
  "id": "req-token-opaque--derives--need",
849
850
  "sourceId": "req-token-opaque",
850
851
  "targetId": "need",
851
- "relationType": "derives"
852
+ "relationType": "derives",
853
+ "quote": "Callers read collections from this element over HTTP, and the collections grow. Every list has to come back in bounded time and size however large its collection gets, show each item once to a caller who reads it page by page, apply exactly the filters and order the caller asked for or refuse the request, and hand out nothing callers could come to depend on by accident, such as ids or offsets inside a page token. The snippets assume the OpenAPI document at api/openapi.yaml, the application exported from src/app with requests validated against that document, page tokens sealed by src/collections/pageToken, and the tests under tests/ with their fixtures in tests/collections (a seeded /orders collection and a walk helper that reads every page of a list). Names are written in snake_case as Google AIP-158 writes them (page_size, page_token, next_page_token, order_by); where the Resource design pack chose camelCase, read pageSize, pageToken, nextPageToken and orderBy."
852
854
  },
853
855
  {
854
856
  "id": "req-token-refused--derives--need",
855
857
  "sourceId": "req-token-refused",
856
858
  "targetId": "need",
857
- "relationType": "derives"
859
+ "relationType": "derives",
860
+ "quote": "Callers read collections from this element over HTTP, and the collections grow. Every list has to come back in bounded time and size however large its collection gets, show each item once to a caller who reads it page by page, apply exactly the filters and order the caller asked for or refuse the request, and hand out nothing callers could come to depend on by accident, such as ids or offsets inside a page token. The snippets assume the OpenAPI document at api/openapi.yaml, the application exported from src/app with requests validated against that document, page tokens sealed by src/collections/pageToken, and the tests under tests/ with their fixtures in tests/collections (a seeded /orders collection and a walk helper that reads every page of a list). Names are written in snake_case as Google AIP-158 writes them (page_size, page_token, next_page_token, order_by); where the Resource design pack chose camelCase, read pageSize, pageToken, nextPageToken and orderBy."
858
861
  },
859
862
  {
860
863
  "id": "req-cursor-consistent--derives--need",
861
864
  "sourceId": "req-cursor-consistent",
862
865
  "targetId": "need",
863
- "relationType": "derives"
866
+ "relationType": "derives",
867
+ "quote": "Callers read collections from this element over HTTP, and the collections grow. Every list has to come back in bounded time and size however large its collection gets, show each item once to a caller who reads it page by page, apply exactly the filters and order the caller asked for or refuse the request, and hand out nothing callers could come to depend on by accident, such as ids or offsets inside a page token. The snippets assume the OpenAPI document at api/openapi.yaml, the application exported from src/app with requests validated against that document, page tokens sealed by src/collections/pageToken, and the tests under tests/ with their fixtures in tests/collections (a seeded /orders collection and a walk helper that reads every page of a list). Names are written in snake_case as Google AIP-158 writes them (page_size, page_token, next_page_token, order_by); where the Resource design pack chose camelCase, read pageSize, pageToken, nextPageToken and orderBy."
864
868
  },
865
869
  {
866
870
  "id": "req-offset-cap--derives--need",
867
871
  "sourceId": "req-offset-cap",
868
872
  "targetId": "need",
869
- "relationType": "derives"
873
+ "relationType": "derives",
874
+ "quote": "Callers read collections from this element over HTTP, and the collections grow. Every list has to come back in bounded time and size however large its collection gets, show each item once to a caller who reads it page by page, apply exactly the filters and order the caller asked for or refuse the request, and hand out nothing callers could come to depend on by accident, such as ids or offsets inside a page token. The snippets assume the OpenAPI document at api/openapi.yaml, the application exported from src/app with requests validated against that document, page tokens sealed by src/collections/pageToken, and the tests under tests/ with their fixtures in tests/collections (a seeded /orders collection and a walk helper that reads every page of a list). Names are written in snake_case as Google AIP-158 writes them (page_size, page_token, next_page_token, order_by); where the Resource design pack chose camelCase, read pageSize, pageToken, nextPageToken and orderBy."
870
875
  },
871
876
  {
872
877
  "id": "req-bounded--derives--need",
873
878
  "sourceId": "req-bounded",
874
879
  "targetId": "need",
875
- "relationType": "derives"
880
+ "relationType": "derives",
881
+ "quote": "Callers read collections from this element over HTTP, and the collections grow. Every list has to come back in bounded time and size however large its collection gets, show each item once to a caller who reads it page by page, apply exactly the filters and order the caller asked for or refuse the request, and hand out nothing callers could come to depend on by accident, such as ids or offsets inside a page token. The snippets assume the OpenAPI document at api/openapi.yaml, the application exported from src/app with requests validated against that document, page tokens sealed by src/collections/pageToken, and the tests under tests/ with their fixtures in tests/collections (a seeded /orders collection and a walk helper that reads every page of a list). Names are written in snake_case as Google AIP-158 writes them (page_size, page_token, next_page_token, order_by); where the Resource design pack chose camelCase, read pageSize, pageToken, nextPageToken and orderBy."
876
882
  },
877
883
  {
878
884
  "id": "req-order--derives--need",
879
885
  "sourceId": "req-order",
880
886
  "targetId": "need",
881
- "relationType": "derives"
887
+ "relationType": "derives",
888
+ "quote": "Callers read collections from this element over HTTP, and the collections grow. Every list has to come back in bounded time and size however large its collection gets, show each item once to a caller who reads it page by page, apply exactly the filters and order the caller asked for or refuse the request, and hand out nothing callers could come to depend on by accident, such as ids or offsets inside a page token. The snippets assume the OpenAPI document at api/openapi.yaml, the application exported from src/app with requests validated against that document, page tokens sealed by src/collections/pageToken, and the tests under tests/ with their fixtures in tests/collections (a seeded /orders collection and a walk helper that reads every page of a list). Names are written in snake_case as Google AIP-158 writes them (page_size, page_token, next_page_token, order_by); where the Resource design pack chose camelCase, read pageSize, pageToken, nextPageToken and orderBy."
882
889
  },
883
890
  {
884
891
  "id": "req-unknown--derives--need",
885
892
  "sourceId": "req-unknown",
886
893
  "targetId": "need",
887
- "relationType": "derives"
894
+ "relationType": "derives",
895
+ "quote": "Callers read collections from this element over HTTP, and the collections grow. Every list has to come back in bounded time and size however large its collection gets, show each item once to a caller who reads it page by page, apply exactly the filters and order the caller asked for or refuse the request, and hand out nothing callers could come to depend on by accident, such as ids or offsets inside a page token. The snippets assume the OpenAPI document at api/openapi.yaml, the application exported from src/app with requests validated against that document, page tokens sealed by src/collections/pageToken, and the tests under tests/ with their fixtures in tests/collections (a seeded /orders collection and a walk helper that reads every page of a list). Names are written in snake_case as Google AIP-158 writes them (page_size, page_token, next_page_token, order_by); where the Resource design pack chose camelCase, read pageSize, pageToken, nextPageToken and orderBy."
888
896
  },
889
897
  {
890
898
  "id": "req-filter--derives--need",
891
899
  "sourceId": "req-filter",
892
900
  "targetId": "need",
893
- "relationType": "derives"
901
+ "relationType": "derives",
902
+ "quote": "Callers read collections from this element over HTTP, and the collections grow. Every list has to come back in bounded time and size however large its collection gets, show each item once to a caller who reads it page by page, apply exactly the filters and order the caller asked for or refuse the request, and hand out nothing callers could come to depend on by accident, such as ids or offsets inside a page token. The snippets assume the OpenAPI document at api/openapi.yaml, the application exported from src/app with requests validated against that document, page tokens sealed by src/collections/pageToken, and the tests under tests/ with their fixtures in tests/collections (a seeded /orders collection and a walk helper that reads every page of a list). Names are written in snake_case as Google AIP-158 writes them (page_size, page_token, next_page_token, order_by); where the Resource design pack chose camelCase, read pageSize, pageToken, nextPageToken and orderBy."
894
903
  },
895
904
  {
896
905
  "id": "req-sort--derives--need",
897
906
  "sourceId": "req-sort",
898
907
  "targetId": "need",
899
- "relationType": "derives"
908
+ "relationType": "derives",
909
+ "quote": "Callers read collections from this element over HTTP, and the collections grow. Every list has to come back in bounded time and size however large its collection gets, show each item once to a caller who reads it page by page, apply exactly the filters and order the caller asked for or refuse the request, and hand out nothing callers could come to depend on by accident, such as ids or offsets inside a page token. The snippets assume the OpenAPI document at api/openapi.yaml, the application exported from src/app with requests validated against that document, page tokens sealed by src/collections/pageToken, and the tests under tests/ with their fixtures in tests/collections (a seeded /orders collection and a walk helper that reads every page of a list). Names are written in snake_case as Google AIP-158 writes them (page_size, page_token, next_page_token, order_by); where the Resource design pack chose camelCase, read pageSize, pageToken, nextPageToken and orderBy."
900
910
  },
901
911
  {
902
912
  "id": "req-fields--derives--need",
903
913
  "sourceId": "req-fields",
904
914
  "targetId": "need",
905
- "relationType": "derives"
915
+ "relationType": "derives",
916
+ "quote": "Callers read collections from this element over HTTP, and the collections grow. Every list has to come back in bounded time and size however large its collection gets, show each item once to a caller who reads it page by page, apply exactly the filters and order the caller asked for or refuse the request, and hand out nothing callers could come to depend on by accident, such as ids or offsets inside a page token. The snippets assume the OpenAPI document at api/openapi.yaml, the application exported from src/app with requests validated against that document, page tokens sealed by src/collections/pageToken, and the tests under tests/ with their fixtures in tests/collections (a seeded /orders collection and a walk helper that reads every page of a list). Names are written in snake_case as Google AIP-158 writes them (page_size, page_token, next_page_token, order_by); where the Resource design pack chose camelCase, read pageSize, pageToken, nextPageToken and orderBy."
906
917
  },
907
918
  {
908
919
  "id": "req-latency--derives--need",
909
920
  "sourceId": "req-latency",
910
921
  "targetId": "need",
911
- "relationType": "derives"
922
+ "relationType": "derives",
923
+ "quote": "Callers read collections from this element over HTTP, and the collections grow. Every list has to come back in bounded time and size however large its collection gets, show each item once to a caller who reads it page by page, apply exactly the filters and order the caller asked for or refuse the request, and hand out nothing callers could come to depend on by accident, such as ids or offsets inside a page token. The snippets assume the OpenAPI document at api/openapi.yaml, the application exported from src/app with requests validated against that document, page tokens sealed by src/collections/pageToken, and the tests under tests/ with their fixtures in tests/collections (a seeded /orders collection and a walk helper that reads every page of a list). Names are written in snake_case as Google AIP-158 writes them (page_size, page_token, next_page_token, order_by); where the Resource design pack chose camelCase, read pageSize, pageToken, nextPageToken and orderBy."
912
924
  },
913
925
  {
914
926
  "id": "sc-paged--verifies--req-paged",