@diagonal-hq/cli 0.28.0 → 0.28.1
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.mjs +39 -33
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -311113,28 +311113,8 @@ function readDomains(value, nodes, domainReferences) {
|
|
|
311113
311113
|
const domains = [];
|
|
311114
311114
|
for (const [key, declaration] of Object.entries(declared)) {
|
|
311115
311115
|
const node = propertyNode(nodes.domains, key);
|
|
311116
|
-
if (!KEY_PATTERN.test(key)) {
|
|
311117
|
-
throw new SourceError(
|
|
311118
|
-
`The domain key "${key}" must start with a lower-case letter and contain only letters and digits`,
|
|
311119
|
-
node
|
|
311120
|
-
);
|
|
311121
|
-
}
|
|
311122
|
-
if (key.length > KEY_MAX_LENGTH) {
|
|
311123
|
-
throw new SourceError(`The domain key "${key}" must be at most ${KEY_MAX_LENGTH} characters`, node);
|
|
311124
|
-
}
|
|
311125
|
-
if (!isPlainObject2(declaration)) {
|
|
311126
|
-
throw new SourceError(`The domain "${key}" must be an object, such as ${key}: {}`, node);
|
|
311127
|
-
}
|
|
311128
|
-
for (const option of Object.keys(declaration)) {
|
|
311129
|
-
if (option !== "fallback") {
|
|
311130
|
-
throw new SourceError(`Unknown domain option "${option}"`, propertyNode(node, option));
|
|
311131
|
-
}
|
|
311132
|
-
}
|
|
311133
|
-
if (Object.hasOwn(declaration, "fallback") && declaration.fallback !== "primary") {
|
|
311134
|
-
throw new SourceError(`"fallback" must be 'primary'`, propertyNode(node, "fallback"));
|
|
311135
|
-
}
|
|
311136
311116
|
domainNodes[key] = node;
|
|
311137
|
-
domains.push(
|
|
311117
|
+
domains.push(readDomainDeclaration(key, declaration, node));
|
|
311138
311118
|
}
|
|
311139
311119
|
if (primary === void 0) {
|
|
311140
311120
|
throw new SourceError('Add "primaryDomain" with one of the keys of "domains"', nodes.domains);
|
|
@@ -311142,25 +311122,51 @@ function readDomains(value, nodes, domainReferences) {
|
|
|
311142
311122
|
if (!isDomainsReference(nodes.primaryDomain.value, domainReferences)) {
|
|
311143
311123
|
throw new SourceError(DOMAIN_REFERENCE_MESSAGE, nodes.primaryDomain);
|
|
311144
311124
|
}
|
|
311145
|
-
|
|
311146
|
-
|
|
311125
|
+
checkPrimaryDomain(domains, primary, nodes.primaryDomain, domainNodes);
|
|
311126
|
+
return {
|
|
311127
|
+
domains,
|
|
311128
|
+
primary_domain: primary,
|
|
311129
|
+
domainNodes,
|
|
311130
|
+
primaryDomainNode: nodes.primaryDomain
|
|
311131
|
+
};
|
|
311132
|
+
}
|
|
311133
|
+
function readDomainDeclaration(key, declaration, node = null) {
|
|
311134
|
+
if (!KEY_PATTERN.test(key)) {
|
|
311135
|
+
throw new SourceError(
|
|
311136
|
+
`The domain key "${key}" must start with a lower-case letter and contain only letters and digits`,
|
|
311137
|
+
node
|
|
311138
|
+
);
|
|
311139
|
+
}
|
|
311140
|
+
if (key.length > KEY_MAX_LENGTH) {
|
|
311141
|
+
throw new SourceError(`The domain key "${key}" must be at most ${KEY_MAX_LENGTH} characters`, node);
|
|
311142
|
+
}
|
|
311143
|
+
if (!isPlainObject2(declaration)) {
|
|
311144
|
+
throw new SourceError(`The domain "${key}" must be an object, such as ${key}: {}`, node);
|
|
311145
|
+
}
|
|
311146
|
+
for (const option of Object.keys(declaration)) {
|
|
311147
|
+
if (option !== "fallback") {
|
|
311148
|
+
throw new SourceError(`Unknown domain option "${option}"`, propertyNode(node, option));
|
|
311149
|
+
}
|
|
311150
|
+
}
|
|
311151
|
+
if (Object.hasOwn(declaration, "fallback") && declaration.fallback !== "primary") {
|
|
311152
|
+
throw new SourceError(`"fallback" must be 'primary'`, propertyNode(node, "fallback"));
|
|
311153
|
+
}
|
|
311154
|
+
return { key, fallback: Object.hasOwn(declaration, "fallback") ? "primary" : null };
|
|
311155
|
+
}
|
|
311156
|
+
function checkPrimaryDomain(domains, primary, primaryNode = null, domainNodes = null) {
|
|
311157
|
+
const declaration = domains.find((domain) => domain.key === primary);
|
|
311158
|
+
if (typeof primary !== "string" || declaration === void 0) {
|
|
311147
311159
|
throw new SourceError(
|
|
311148
|
-
|
|
311149
|
-
|
|
311160
|
+
domains.length === 0 ? '"primaryDomain" must name a key of "domains". Declare a domain in "domains"' : `"primaryDomain" must be one of: ${domains.map((domain) => domain.key).join(", ")}`,
|
|
311161
|
+
primaryNode
|
|
311150
311162
|
);
|
|
311151
311163
|
}
|
|
311152
|
-
if (
|
|
311164
|
+
if (declaration.fallback !== null) {
|
|
311153
311165
|
throw new SourceError(
|
|
311154
311166
|
`The primary domain "${primary}" cannot fall back to itself. Remove "fallback"`,
|
|
311155
|
-
propertyNode(domainNodes[primary], "fallback")
|
|
311167
|
+
domainNodes === null ? null : propertyNode(domainNodes[primary], "fallback")
|
|
311156
311168
|
);
|
|
311157
311169
|
}
|
|
311158
|
-
return {
|
|
311159
|
-
domains,
|
|
311160
|
-
primary_domain: primary,
|
|
311161
|
-
domainNodes,
|
|
311162
|
-
primaryDomainNode: nodes.primaryDomain
|
|
311163
|
-
};
|
|
311164
311170
|
}
|
|
311165
311171
|
function hostKey(domainKey, domains, primaryDomain) {
|
|
311166
311172
|
if (domainKey === null || domainKey === primaryDomain) {
|