proxylang 0.1.5 → 0.1.6

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/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { R as requestSchema, a as explain, i as compile, l as targetCatalog, p as StaticRuleSetUnknownError, t as buildToDirectory } from "./host-Bea3np6i.js";
2
+ import { G as requestSchema, b as StaticRuleSetUnknownError, c as buildToDirectory, d as compile, f as explain, g as targetCatalog, n as runSurgeBuild, r as surgeBuildFailure } from "./surge-build-DbQ9Ddhc.js";
3
3
  import { open } from "node:fs/promises";
4
4
  import { resolve } from "node:path";
5
5
  import { pathToFileURL } from "node:url";
@@ -15,6 +15,7 @@ const failure = (code) => {
15
15
  return 1;
16
16
  };
17
17
  const usages = {
18
+ "surge-build": ["proxylang surge-build config.ts --out DIRECTORY [--validation]"],
18
19
  targets: ["proxylang targets"],
19
20
  check: ["proxylang check config.ts"],
20
21
  explain: ["proxylang explain config.ts --target ID --request JSON", "proxylang explain config.ts --target ID --request-file FILE"],
@@ -83,6 +84,7 @@ async function main(args) {
83
84
  });
84
85
  return 0;
85
86
  }
87
+ if (command === "surge-build") return surgeBuildCommand(file, rest);
86
88
  if (![
87
89
  "check",
88
90
  "explain",
@@ -163,6 +165,39 @@ async function main(args) {
163
165
  });
164
166
  return built.exitCode;
165
167
  }
168
+ async function surgeBuildCommand(file, args) {
169
+ const invalid = () => {
170
+ print(surgeBuildFailure("INVALID_ARGUMENTS"));
171
+ return 1;
172
+ };
173
+ if (!file?.trim() || file.startsWith("-")) return invalid();
174
+ let output;
175
+ let validation = false;
176
+ for (let i = 0; i < args.length; i++) {
177
+ const arg = args[i];
178
+ if (arg === "--out" && output === void 0) {
179
+ const value = args[++i];
180
+ if (!value?.trim() || value.startsWith("-")) return invalid();
181
+ output = value;
182
+ } else if (arg === "--validation" && !validation) validation = true;
183
+ else if (arg === "--" && output !== void 0 && !validation && i === args.length - 2 && args[i + 1] === "--validation") {
184
+ validation = true;
185
+ i++;
186
+ } else return invalid();
187
+ }
188
+ if (output === void 0) return invalid();
189
+ let config;
190
+ try {
191
+ const loaded = await tsImport(pathToFileURL(resolve(file)).href, import.meta.url);
192
+ config = loaded.default?.__esModule === true ? loaded.default.default : loaded.default;
193
+ } catch {
194
+ print(surgeBuildFailure("PROFILE_DEFINITION_FAILED", validation));
195
+ return 1;
196
+ }
197
+ const result = await runSurgeBuild(config, output, { validation });
198
+ print(result);
199
+ return result.exitCode;
200
+ }
166
201
  try {
167
202
  process.exitCode = await main(process.argv.slice(2));
168
203
  } catch (cause) {
package/dist/index.d.ts CHANGED
@@ -873,7 +873,6 @@ type ProxyGroupDefinition = {
873
873
  };
874
874
  type RouteDefinition = {
875
875
  readonly type: "route";
876
- readonly id: string;
877
876
  readonly when: SurgeCondition;
878
877
  readonly to: Destination;
879
878
  };
@@ -905,6 +904,10 @@ export declare const outbound: {
905
904
  };
906
905
  export declare function defineProxyGroup(input: Omit<ProxyGroupDefinition, "type">): ProxyGroupDefinition;
907
906
  export declare function defineRoute(input: Omit<RouteDefinition, "type">): RouteDefinition;
907
+ export declare function defineRoutes(input: {
908
+ readonly when: readonly SurgeCondition[];
909
+ readonly to: Destination;
910
+ }): RouteDefinition[];
908
911
  export declare function selectProxies(nodes: readonly ProxyNode[], query?: {
909
912
  ids?: readonly string[];
910
913
  regions?: readonly string[];
@@ -913,4 +916,25 @@ export declare function selectProxies(nodes: readonly ProxyNode[], query?: {
913
916
  }): ProxyNode[];
914
917
  export declare function defineSurgeProfile(input: SurgeProfileDefinition): SurgeProfileInput;
915
918
  //#endregion
916
- export type { Artifact, BuildResult, CaseResult, Compilation, Destination, ProxyBuilder, ProxyGroupDefinition, ProxyNodeArtifact, ProxyNodeCompilation, ProxyNodeInput, RouteDefinition, StrategyGroupCompilation, StrategyGroupInput, SurgeCondition, SurgeGeneral, SurgeGroup, SurgeHost, SurgePolicy, SurgeProfileArtifact, SurgeProfileCompilation, SurgeProfileDefinition, SurgeProfileInput, SurgeRule, SurgeTunnel, TargetPlan };
919
+ //#region src/surge-build.d.ts
920
+ type SurgeBuildContext = {
921
+ readonly validation: boolean;
922
+ };
923
+ type SurgeBuildDefinition = {
924
+ readonly profiles: Readonly<Record<string, SurgeProfileInput>>;
925
+ readonly preflight?: () => readonly string[];
926
+ readonly resolveSecret?: (token: Secret, context: SurgeBuildContext) => string | undefined;
927
+ };
928
+ type SurgeBuildResult = BuildResult & {
929
+ readonly warnings: Readonly<Record<string, number>>;
930
+ readonly validation: boolean;
931
+ readonly profileCount: number;
932
+ };
933
+ /** Capture data and callback references before application preflight can change its source. */
934
+ export declare function defineSurgeBuild(input: SurgeBuildDefinition): SurgeBuildDefinition;
935
+ /** Pure orchestration result; the CLI owns stdout and process exit status. */
936
+ export declare function runSurgeBuild(input: SurgeBuildDefinition, output: string, options?: {
937
+ readonly validation?: boolean;
938
+ }): Promise<SurgeBuildResult>;
939
+ //#endregion
940
+ export type { Artifact, BuildResult, CaseResult, Compilation, Destination, ProxyBuilder, ProxyGroupDefinition, ProxyNodeArtifact, ProxyNodeCompilation, ProxyNodeInput, RouteDefinition, StrategyGroupCompilation, StrategyGroupInput, SurgeBuildContext, SurgeBuildDefinition, SurgeBuildResult, SurgeCondition, SurgeGeneral, SurgeGroup, SurgeHost, SurgePolicy, SurgeProfileArtifact, SurgeProfileCompilation, SurgeProfileDefinition, SurgeProfileInput, SurgeRule, SurgeTunnel, TargetPlan };