@effected/cli 0.25.0 → 0.27.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 (116) hide show
  1. package/README.md +5 -208
  2. package/bin/effected.js +7 -0
  3. package/commands/root.js +14 -0
  4. package/commands/schema/LiveProgress.js +114 -0
  5. package/commands/schema/build.js +9 -0
  6. package/commands/schema/check.js +12 -0
  7. package/commands/schema/errors.js +121 -0
  8. package/commands/schema/execute.js +141 -0
  9. package/commands/schema/flags.js +24 -0
  10. package/commands/schema/index.js +14 -0
  11. package/commands/schema/validate.js +58 -0
  12. package/index.d.ts +85 -3906
  13. package/index.js +4 -26
  14. package/main.d.ts +51 -0
  15. package/main.js +61 -0
  16. package/package.json +18 -50
  17. package/render/DiffDoc.js +51 -0
  18. package/tsdoc-metadata.json +1 -1
  19. package/version.js +11 -0
  20. package/Cancelled.js +0 -43
  21. package/CliAudience.js +0 -177
  22. package/CliColor.js +0 -59
  23. package/CliEnv.js +0 -101
  24. package/CliExit.js +0 -64
  25. package/CliFailure.js +0 -287
  26. package/CliFormat.js +0 -124
  27. package/CliInteractive.js +0 -94
  28. package/CliLinks.js +0 -153
  29. package/CliLog.js +0 -367
  30. package/CliLogger.js +0 -91
  31. package/CliMessage.js +0 -79
  32. package/CliPrompt.js +0 -110
  33. package/CliRuntime.js +0 -254
  34. package/CliTest.js +0 -206
  35. package/CliTheme.js +0 -142
  36. package/ConfigIssueRenderer.js +0 -63
  37. package/Doc.js +0 -548
  38. package/Fmt.js +0 -335
  39. package/GithubAnnotation.js +0 -39
  40. package/Glyphs.js +0 -82
  41. package/NotInteractive.js +0 -41
  42. package/Render.js +0 -280
  43. package/SchemaIssueRenderer.js +0 -47
  44. package/Status.js +0 -165
  45. package/TestTerminal.js +0 -101
  46. package/Token.js +0 -68
  47. package/internal/ExitRequested.js +0 -21
  48. package/internal/HelpRouting.js +0 -35
  49. package/internal/ansi.js +0 -229
  50. package/internal/autoFormat.js +0 -33
  51. package/internal/canPrompt.js +0 -14
  52. package/internal/counts.js +0 -83
  53. package/internal/diagnostics.js +0 -31
  54. package/internal/displayPath.js +0 -46
  55. package/internal/displayWidth.js +0 -42
  56. package/internal/failureTarget.js +0 -195
  57. package/internal/fallbackAnswer.js +0 -17
  58. package/internal/fileSink.js +0 -61
  59. package/internal/format.js +0 -175
  60. package/internal/inspect.js +0 -40
  61. package/internal/isExitCode.js +0 -11
  62. package/internal/layout.js +0 -249
  63. package/internal/linkScheme.js +0 -29
  64. package/internal/linkTarget.js +0 -49
  65. package/internal/logSafety.js +0 -45
  66. package/internal/renderAnsi.js +0 -51
  67. package/internal/renderDoc.js +0 -322
  68. package/internal/renderGithubLog.js +0 -59
  69. package/internal/renderMarkdown.js +0 -367
  70. package/internal/renderPlain.js +0 -49
  71. package/internal/scanAudience.js +0 -105
  72. package/internal/splitFrame.js +0 -55
  73. package/internal/terminalCapabilities.js +0 -23
  74. package/internal/wizardGate.js +0 -17
  75. package/testing.d.ts +0 -246
  76. package/testing.js +0 -4
  77. package/ui/CliUi.js +0 -507
  78. package/ui/CliUiDetached.js +0 -36
  79. package/ui/CliUiLive.js +0 -436
  80. package/ui/CliUiRouteStream.js +0 -72
  81. package/ui/Confirm.js +0 -244
  82. package/ui/DocView.js +0 -76
  83. package/ui/KeyHelp.js +0 -61
  84. package/ui/KeyTable.js +0 -198
  85. package/ui/MultiSelect.js +0 -259
  86. package/ui/Select.js +0 -229
  87. package/ui/Tabs.js +0 -201
  88. package/ui/TextInput.js +0 -289
  89. package/ui/Toggle.js +0 -31
  90. package/ui/UiKey.js +0 -48
  91. package/ui/UiProvider.js +0 -62
  92. package/ui/UiStreams.js +0 -17
  93. package/ui/UiTheme.js +0 -147
  94. package/ui/Viewport.js +0 -203
  95. package/ui/internal/ErrorBoundary.js +0 -29
  96. package/ui/internal/Holder.js +0 -73
  97. package/ui/internal/ScreenContext.js +0 -51
  98. package/ui/internal/UiProviders.js +0 -38
  99. package/ui/internal/ink.js +0 -121
  100. package/ui/internal/inkChalk.js +0 -47
  101. package/ui/internal/inkConsole.js +0 -150
  102. package/ui/internal/lazyView.js +0 -73
  103. package/ui/internal/lineRouter.js +0 -70
  104. package/ui/internal/lineText.js +0 -18
  105. package/ui/internal/mountPermit.js +0 -15
  106. package/ui/internal/processStreams.js +0 -18
  107. package/ui/internal/renderOptions.js +0 -12
  108. package/ui/testing/CliUiTest.js +0 -792
  109. package/ui/testing/fakeStreams.js +0 -104
  110. package/ui/testing/terminalModel.js +0 -67
  111. package/ui-testing-serializer.d.ts +0 -12
  112. package/ui-testing-serializer.js +0 -32
  113. package/ui-testing.d.ts +0 -558
  114. package/ui-testing.js +0 -3
  115. package/ui.d.ts +0 -1990
  116. package/ui.js +0 -17
@@ -0,0 +1,24 @@
1
+ import { Argument, Flag } from "effect/cli";
2
+
3
+ // src/commands/schema/flags.ts
4
+ /** The optional positional config path; omitted, the config is discovered upward from the working directory. */
5
+ const configArgument = Argument.String("config").pipe(Argument.withDescription("Path to a schemastore config module; omitted, schemastore.config.{ts,mts,js,mjs} is searched upward from the working directory"), Argument.optional);
6
+ /** `--format`: absent, JSON for an agent and human text for everyone else. */
7
+ const formatFlag = Flag.Literals("format", ["human", "json"]).pipe(Flag.withDescription("Output format, by default json for an agent and human otherwise; json writes one document to stdout and moves human text to stderr"), Flag.optional);
8
+ /** `--ignore-version-mismatch`: run on past a config from another `@effected/schemastore`. */
9
+ const ignoreVersionMismatchFlag = Flag.Boolean("ignore-version-mismatch").pipe(Flag.withDefault(false), Flag.withDescription("Run even when the config's values come from a different @effected/schemastore than this tool's; warns loudly"));
10
+ /** What `build` and `check` take. */
11
+ const commandFlags = {
12
+ config: configArgument,
13
+ drift: Flag.Literals("drift", [
14
+ "strict",
15
+ "semantic",
16
+ "allow"
17
+ ]).pipe(Flag.withDescription("Drift tolerance for published schemas; overrides every schema's drift"), Flag.optional),
18
+ onDrift: Flag.Literals("on-drift", ["error", "warn"]).pipe(Flag.withDescription("What drift does: refuse every write (error) or write and warn; overrides the config's onDrift"), Flag.optional),
19
+ force: Flag.Boolean("force").pipe(Flag.withDefault(false), Flag.withDescription("Shorthand for --drift=allow")),
20
+ format: formatFlag,
21
+ ignoreVersionMismatch: ignoreVersionMismatchFlag
22
+ };
23
+
24
+ export { commandFlags, configArgument, formatFlag, ignoreVersionMismatchFlag };
@@ -0,0 +1,14 @@
1
+ import { makeBuildCommand } from "./build.js";
2
+ import { makeCheckCommand } from "./check.js";
3
+ import { makeValidateCommand } from "./validate.js";
4
+ import { Command } from "effect/cli";
5
+
6
+ // src/commands/schema/index.ts
7
+ /** `effected schema`: the group, closed over the process boundary it runs against. */
8
+ const makeSchemaCommand = (deps) => Command.make("schema", {}).pipe(Command.withDescription("Build and check SchemaStore-shaped JSON Schema documents from a schemastore.config.ts, and validate payloads against them"), Command.withSubcommands([
9
+ makeBuildCommand(deps),
10
+ makeCheckCommand(deps),
11
+ makeValidateCommand(deps)
12
+ ]));
13
+
14
+ export { makeSchemaCommand };
@@ -0,0 +1,58 @@
1
+ import { ValidationFailedError } from "./errors.js";
2
+ import { configFailures, resolveFormat, warnVersionMismatch } from "./execute.js";
3
+ import { configArgument, formatFlag, ignoreVersionMismatchFlag } from "./flags.js";
4
+ import { CliRuntime, Doc } from "@effected/cli-kit";
5
+ import { Argument, Command, Flag } from "effect/cli";
6
+ import { SchemaValidate, ValidateReport } from "@effected/engine/schema";
7
+ import { Console, Effect, Option, Schema } from "effect";
8
+
9
+ // src/commands/schema/validate.ts
10
+ const findingLine = (finding) => {
11
+ const at = finding.location;
12
+ const where = at !== void 0 ? `${at.file}:${at.line}:${at.column}: ` : " ";
13
+ const keyword = finding.keyword !== void 0 ? ` [${finding.keyword}]` : "";
14
+ return `${where}${finding.path === "" ? "(root)" : finding.path}: ${finding.message}${keyword}`;
15
+ };
16
+ const humanLines = (report) => report.valid ? [`valid ${report.payload} against ${report.source}`] : [...report.findings.map(findingLine), `${report.findings.length} finding(s): ${report.payload} does not conform to ${report.$ref}`];
17
+ /** Run one `validate`. */
18
+ const runValidate = Effect.fn("effected.schema.validate")(function* (input, deps) {
19
+ const format = yield* resolveFormat(input.format);
20
+ const report = yield* SchemaValidate.run({
21
+ payload: input.payload,
22
+ versionMismatch: input.ignoreVersionMismatch ? "warn" : "fail",
23
+ ...Option.isSome(input.config) ? { config: input.config.value } : {},
24
+ ...Option.isSome(input.schema) ? { schema: input.schema.value } : {}
25
+ }, {
26
+ ...deps,
27
+ onProgress: (event) => event._tag === "Started" && event.versionMismatch !== void 0 ? warnVersionMismatch(event.versionMismatch) : Effect.void
28
+ }).pipe(Effect.catchTags({
29
+ ...configFailures("validate payload.json lib/schemastore.config.ts", input.config),
30
+ VersionMismatchError: (error) => Effect.fail(CliRuntime.reported(error, 2)),
31
+ PayloadError: (error) => Effect.fail(CliRuntime.reported(error, 2)),
32
+ SchemaResolutionError: (error) => Effect.fail(CliRuntime.reported(error, 2)),
33
+ MissingSchemaRefError: (error) => Effect.fail(CliRuntime.reported(error, 64))
34
+ }));
35
+ const lines = humanLines(report);
36
+ if (format === "json") {
37
+ yield* Console.log(JSON.stringify(Schema.encodeSync(ValidateReport.Json)(report)));
38
+ for (const line of lines) yield* Effect.logInfo(line);
39
+ } else yield* Doc.print([Doc.lines(lines.map((line, index) => Doc.text(line, report.valid ? "success" : index === lines.length - 1 ? "emphasis" : "error")), { wrap: false })]);
40
+ if (!report.valid) return yield* Effect.fail(CliRuntime.reported(new ValidationFailedError({
41
+ count: report.findings.length,
42
+ payload: report.payload,
43
+ schema: report.$ref
44
+ }), 1));
45
+ });
46
+ /**
47
+ * `effected schema validate`: check a payload against a published schema document, named by `--schema` or the payload's
48
+ * `$schema`: a file path, or an identity the config derives. No network is involved.
49
+ */
50
+ const makeValidateCommand = (deps) => Command.make("validate", {
51
+ payload: Argument.String("payload").pipe(Argument.withDescription("Path to the JSON payload to validate")),
52
+ schema: Flag.String("schema").pipe(Flag.optional, Flag.withDescription("The document to validate against: a file path, or a $id/url a config schema derives; omitted, the payload's own $schema property")),
53
+ config: configArgument,
54
+ format: formatFlag,
55
+ ignoreVersionMismatch: ignoreVersionMismatchFlag
56
+ }, (input) => runValidate(input, deps)).pipe(Command.withDescription("Validate a JSON payload against a published schema document, resolved by path or by the config's derived $id/url identities"));
57
+
58
+ export { makeValidateCommand, runValidate };