sproutboat 0.5.0 → 0.6.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/src/manifest.ts CHANGED
@@ -30,9 +30,7 @@ export type ArtifactManifest = {
30
30
  builtAt: string;
31
31
  };
32
32
 
33
- export type ManifestValidation =
34
- | { ok: true; value: ArtifactManifest }
35
- | { ok: false; errors: string[] };
33
+ export type ManifestValidation = { ok: true; value: ArtifactManifest } | { ok: false; errors: string[] };
36
34
 
37
35
  type JsonValue = string | number | boolean | null | ManifestJsonObject | JsonValue[];
38
36
 
@@ -43,8 +41,7 @@ interface ManifestJsonObject {
43
41
  type ManifestInput = JsonValue | undefined;
44
42
 
45
43
  function isRecord(value: ManifestInput): value is ManifestJsonObject {
46
- return value !== null && Object(value) === value && !Array.isArray(value)
47
- && !(value instanceof Function);
44
+ return value !== null && Object(value) === value && !Array.isArray(value) && !(value instanceof Function);
48
45
  }
49
46
 
50
47
  function isString(value: ManifestInput): value is string {
@@ -62,27 +59,47 @@ function isPositiveInteger(value: ManifestInput): value is number {
62
59
  export function validateManifest(value: ManifestInput): ManifestValidation {
63
60
  if (!isRecord(value)) return { ok: false, errors: ["manifest must be an object"] };
64
61
  const errors: string[] = [];
65
- const required = ["schemaVersion", "project", "target", "runtime", "capabilityProfile", "porfforVersion", "esbuildVersion", "buildImage", "sourceHash", "binaryHash", "binarySize", "builtAt"];
62
+ const required = [
63
+ "schemaVersion",
64
+ "project",
65
+ "target",
66
+ "runtime",
67
+ "capabilityProfile",
68
+ "porfforVersion",
69
+ "esbuildVersion",
70
+ "buildImage",
71
+ "sourceHash",
72
+ "binaryHash",
73
+ "binarySize",
74
+ "builtAt",
75
+ ];
66
76
  for (const field of required) if (!(field in value)) errors.push(`missing manifest field: ${field}`);
67
77
  const schemaVersion = value.schemaVersion === ARTIFACT_SCHEMA_VERSION ? ARTIFACT_SCHEMA_VERSION : null;
68
78
  if (schemaVersion === null) errors.push("schemaVersion must be 2");
69
- const project = isString(value.project) && /^[a-z0-9](?:[a-z0-9-]{1,30}[a-z0-9])?$/.test(value.project) ? value.project : null;
79
+ const project =
80
+ isString(value.project) && /^[a-z0-9](?:[a-z0-9-]{1,30}[a-z0-9])?$/.test(value.project) ? value.project : null;
70
81
  if (project === null) errors.push("project must be a valid slug");
71
82
  const target = value.target === DEPLOY_TARGET ? value.target : null;
72
83
  if (target === null) {
73
84
  // A `--target host` artifact lands here: runnable where it was built, not
74
85
  // on a box. Name that, so the failure reads as "wrong build" not "corrupt".
75
- errors.push(isString(value.target) && value.target !== DEPLOY_TARGET
76
- ? `target must be ${DEPLOY_TARGET}, got ${value.target} \`--target host\` builds are for local dev and cannot be deployed`
77
- : `target must be ${DEPLOY_TARGET}`);
86
+ errors.push(
87
+ isString(value.target) && value.target !== DEPLOY_TARGET
88
+ ? `target must be ${DEPLOY_TARGET}, got ${value.target} — \`--target host\` builds are for local dev and cannot be deployed`
89
+ : `target must be ${DEPLOY_TARGET}`,
90
+ );
78
91
  }
79
92
  const runtime = value.runtime === RUNTIME ? value.runtime : null;
80
93
  if (runtime === null) errors.push("runtime must be native-fetch");
81
94
  const capabilityProfile = value.capabilityProfile === CAPABILITY_PROFILE ? value.capabilityProfile : null;
82
95
  if (capabilityProfile === null) errors.push("capabilityProfile must be http-sync-v0");
83
96
  const versions = ["porfforVersion", "esbuildVersion", "buildImage"] as const;
84
- const [porfforVersion, esbuildVersion, buildImage] = versions.map((field) => isString(value[field]) && value[field] ? value[field] : null);
85
- for (const [field, version] of versions.map((field, index) => [field, [porfforVersion, esbuildVersion, buildImage][index]] as const)) {
97
+ const [porfforVersion, esbuildVersion, buildImage] = versions.map((field) =>
98
+ isString(value[field]) && value[field] ? value[field] : null,
99
+ );
100
+ for (const [field, version] of versions.map(
101
+ (field, index) => [field, [porfforVersion, esbuildVersion, buildImage][index]] as const,
102
+ )) {
86
103
  if (version === null) errors.push(`${field} must be a non-empty string`);
87
104
  }
88
105
  const sourceHash = sha256(value.sourceHash) ? value.sourceHash : null;
@@ -93,6 +110,38 @@ export function validateManifest(value: ManifestInput): ManifestValidation {
93
110
  if (binarySize === null) errors.push("binarySize must be a positive integer");
94
111
  const builtAt = isString(value.builtAt) && !Number.isNaN(Date.parse(value.builtAt)) ? value.builtAt : null;
95
112
  if (builtAt === null) errors.push("builtAt must be an ISO-8601 timestamp");
96
- if (errors.length || schemaVersion === null || project === null || target === null || runtime === null || capabilityProfile === null || porfforVersion === null || esbuildVersion === null || buildImage === null || sourceHash === null || binaryHash === null || binarySize === null || builtAt === null) return { ok: false, errors };
97
- return { ok: true, value: { ...value, schemaVersion, project, target, runtime, capabilityProfile, porfforVersion, esbuildVersion, buildImage, sourceHash, binaryHash, binarySize, builtAt } };
113
+ if (
114
+ errors.length ||
115
+ schemaVersion === null ||
116
+ project === null ||
117
+ target === null ||
118
+ runtime === null ||
119
+ capabilityProfile === null ||
120
+ porfforVersion === null ||
121
+ esbuildVersion === null ||
122
+ buildImage === null ||
123
+ sourceHash === null ||
124
+ binaryHash === null ||
125
+ binarySize === null ||
126
+ builtAt === null
127
+ )
128
+ return { ok: false, errors };
129
+ return {
130
+ ok: true,
131
+ value: {
132
+ ...value,
133
+ schemaVersion,
134
+ project,
135
+ target,
136
+ runtime,
137
+ capabilityProfile,
138
+ porfforVersion,
139
+ esbuildVersion,
140
+ buildImage,
141
+ sourceHash,
142
+ binaryHash,
143
+ binarySize,
144
+ builtAt,
145
+ },
146
+ };
98
147
  }