@hygraph/cli 0.0.15 → 0.0.16
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 +34 -24
- package/dist/define.d.ts +1 -7
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -11904,12 +11904,11 @@ function createComponentUnionField({ parent }, field) {
|
|
|
11904
11904
|
}
|
|
11905
11905
|
/**
|
|
11906
11906
|
* Only the attributes that change are sent. A rename is `newApiId`; the
|
|
11907
|
-
* members are sent whole and replace the old ones. `list`
|
|
11908
|
-
*
|
|
11909
|
-
* instead.
|
|
11907
|
+
* members are sent whole and replace the old ones. `list` cannot change:
|
|
11908
|
+
* the diff deletes and creates the field instead.
|
|
11910
11909
|
*/
|
|
11911
11910
|
function updateComponentUnionField(change) {
|
|
11912
|
-
const { apiId, displayName, description, components, visibilityCondition, variantEnabled, position } = change.changes;
|
|
11911
|
+
const { apiId, displayName, description, components, visibility, visibilityCondition, variantEnabled, position } = change.changes;
|
|
11913
11912
|
const input = {
|
|
11914
11913
|
apiId: change.apiId,
|
|
11915
11914
|
parentApiId: change.parent
|
|
@@ -11918,6 +11917,7 @@ function updateComponentUnionField(change) {
|
|
|
11918
11917
|
if (displayName) input.displayName = displayName.to;
|
|
11919
11918
|
if (description) input.description = description.to;
|
|
11920
11919
|
if (components) input.componentApiIds = components.to;
|
|
11920
|
+
if (visibility) input.visibility = visibility.to;
|
|
11921
11921
|
if (visibilityCondition) input.visibilityCondition = visibilityCondition.to;
|
|
11922
11922
|
if (variantEnabled) input.isVariantEnabled = variantEnabled.to;
|
|
11923
11923
|
if (position) input.position = position.to;
|
|
@@ -20360,9 +20360,9 @@ function basesFirst(creates) {
|
|
|
20360
20360
|
/**
|
|
20361
20361
|
* Hygraph cannot change a field's type or its `list` once it exists, nor an
|
|
20362
20362
|
* enumeration field's enumeration or `localized`, a taxonomy field's
|
|
20363
|
-
* taxonomy, a component field's component
|
|
20364
|
-
*
|
|
20365
|
-
*
|
|
20363
|
+
* taxonomy, a component field's component or the model a reference
|
|
20364
|
+
* references, nor turn a rich text's embeds off. A two-way pair is decided
|
|
20365
|
+
* as a whole, in `pairTwoWayReferences`.
|
|
20366
20366
|
*/
|
|
20367
20367
|
function changesInPlace(from, to) {
|
|
20368
20368
|
if (from.kind === "unsupported" || to.kind === "unsupported") return from.kind === "unsupported" && to.kind === "unsupported" && from.type === to.type;
|
|
@@ -20370,7 +20370,6 @@ function changesInPlace(from, to) {
|
|
|
20370
20370
|
if (from.kind === "taxonomy" && to.kind === "taxonomy") return from.list === to.list && from.taxonomy === to.taxonomy;
|
|
20371
20371
|
if (from.kind === "remote" && to.kind === "remote") return from.list === to.list && from.type === to.type;
|
|
20372
20372
|
if (from.kind === "component" && to.kind === "component") return from.list === to.list && from.component === to.component;
|
|
20373
|
-
if (from.kind === "componentUnion" && to.kind === "componentUnion") return from.list === to.list && from.visibility === to.visibility;
|
|
20374
20373
|
if (from.kind === "referenceOneWay" && to.kind === "referenceOneWay") return from.list === to.list && from.to === to.to;
|
|
20375
20374
|
if (from.kind === "richText" && to.kind === "richText") return from.list === to.list && (from.embeds === null || to.embeds !== null);
|
|
20376
20375
|
return from.kind === to.kind && from.list === to.list;
|
|
@@ -24221,6 +24220,17 @@ async function formatSource(source) {
|
|
|
24221
24220
|
function string(value) {
|
|
24222
24221
|
return JSON.stringify(value);
|
|
24223
24222
|
}
|
|
24223
|
+
/** The characters of Hygraph's apiId rule, without its length limit. */
|
|
24224
|
+
const NAME = /^[A-Z][A-Za-z0-9_]*$/;
|
|
24225
|
+
/**
|
|
24226
|
+
* A name in code, such as a const. Only an apiId made of the characters of
|
|
24227
|
+
* Hygraph's rule is written as one; anything else could be code, so it is
|
|
24228
|
+
* refused. `kind` names the value in the error.
|
|
24229
|
+
*/
|
|
24230
|
+
function identifier(name, kind = "apiId") {
|
|
24231
|
+
if (!NAME.test(name)) throw new Failure(`${string(name)} is not a valid ${kind}, so it cannot name a const in the config.`);
|
|
24232
|
+
return name;
|
|
24233
|
+
}
|
|
24224
24234
|
/** A template literal, for text that spans lines. Nothing in it is interpolated. */
|
|
24225
24235
|
function template(value) {
|
|
24226
24236
|
return `\`${value.replaceAll(/[\\`]|\$\{/g, (match) => `\\${match}`)}\``;
|
|
@@ -24284,7 +24294,7 @@ function oAuthSecretEnvName(prefix) {
|
|
|
24284
24294
|
}
|
|
24285
24295
|
/** The name of the const `printRemoteSource` declares. */
|
|
24286
24296
|
function remoteSourceConstName(source) {
|
|
24287
|
-
return `${source.prefix}RemoteSource`;
|
|
24297
|
+
return `${identifier(source.prefix, "remote source prefix")}RemoteSource`;
|
|
24288
24298
|
}
|
|
24289
24299
|
/**
|
|
24290
24300
|
* Every header value is a read of the variable `headerEnvNames` names,
|
|
@@ -24343,7 +24353,7 @@ function printAssetModelField(field) {
|
|
|
24343
24353
|
return printBuilder("assetReverseField", [
|
|
24344
24354
|
["apiId", string(field.apiId)],
|
|
24345
24355
|
["displayName", string(field.displayName)],
|
|
24346
|
-
["to", `() => ${field.to}`],
|
|
24356
|
+
["to", `() => ${identifier(field.to)}`],
|
|
24347
24357
|
["reverse", string(field.reverse)],
|
|
24348
24358
|
["description", field.description === null ? void 0 : string(field.description)],
|
|
24349
24359
|
["visibility", field.visibility === "API_ONLY" ? void 0 : string(field.visibility)]
|
|
@@ -24364,7 +24374,7 @@ function printField(parent, field) {
|
|
|
24364
24374
|
return printBuilder("enumeration", [
|
|
24365
24375
|
apiId,
|
|
24366
24376
|
displayName,
|
|
24367
|
-
["enumeration", field.enumeration],
|
|
24377
|
+
["enumeration", identifier(field.enumeration)],
|
|
24368
24378
|
...options
|
|
24369
24379
|
]);
|
|
24370
24380
|
}
|
|
@@ -24373,13 +24383,13 @@ function printField(parent, field) {
|
|
|
24373
24383
|
return printBuilder("taxonomy", [
|
|
24374
24384
|
apiId,
|
|
24375
24385
|
displayName,
|
|
24376
|
-
["taxonomy", field.taxonomy],
|
|
24386
|
+
["taxonomy", identifier(field.taxonomy)],
|
|
24377
24387
|
...options
|
|
24378
24388
|
]);
|
|
24379
24389
|
}
|
|
24380
24390
|
case "richText": return printBuilder(customOf("richText", field.formRenderer), [
|
|
24381
24391
|
...fieldOptions(field, FIELD_DEFAULTS),
|
|
24382
|
-
["embeds", field.embeds === null ? void 0 : `[${field.embeds.map((apiId) => `() => ${apiId}`).join(", ")}]`],
|
|
24392
|
+
["embeds", field.embeds === null ? void 0 : `[${field.embeds.map((apiId) => `() => ${identifier(apiId)}`).join(", ")}]`],
|
|
24383
24393
|
["actions", field.actions === null ? void 0 : `[${field.actions.map(string).join(", ")}]`],
|
|
24384
24394
|
rendererOption(field.formRenderer)
|
|
24385
24395
|
]);
|
|
@@ -24399,16 +24409,16 @@ function printField(parent, field) {
|
|
|
24399
24409
|
const [builder, defaults] = BUILDERS[formRenderer];
|
|
24400
24410
|
return printBuilder(builder, [...fieldOptions(field, defaults), ...stringOptions(field)]);
|
|
24401
24411
|
}
|
|
24402
|
-
case "component": return printBuilder("component", referenceOptions(field, ["component", `() => ${field.component}`]));
|
|
24403
|
-
case "componentUnion": return printBuilder("componentUnion", referenceOptions(field, ["components", `[${field.components.map((apiId) => `() => ${apiId}`).join(", ")}]`]));
|
|
24412
|
+
case "component": return printBuilder("component", referenceOptions(field, ["component", `() => ${identifier(field.component)}`]));
|
|
24413
|
+
case "componentUnion": return printBuilder("componentUnion", referenceOptions(field, ["components", `[${field.components.map((apiId) => `() => ${identifier(apiId)}`).join(", ")}]`]));
|
|
24404
24414
|
case "asset": return printBuilder(customOf("asset", field.formRenderer), [...referenceOptions(field, ["reverse", field.reverse === void 0 ? void 0 : string(field.reverse)]), rendererOption(field.formRenderer)]);
|
|
24405
24415
|
case "referenceOneWay": return printBuilder(customOf("referenceOneWay", field.formRenderer), [
|
|
24406
|
-
...referenceOptions(field, ["to", `() => ${field.to}`]),
|
|
24416
|
+
...referenceOptions(field, ["to", `() => ${identifier(field.to)}`]),
|
|
24407
24417
|
["rules", printRules(field.rules)],
|
|
24408
24418
|
rendererOption(field.formRenderer)
|
|
24409
24419
|
]);
|
|
24410
24420
|
case "referenceTwoWay": {
|
|
24411
|
-
const [apiId, displayName, to, ...options] = referenceOptions(field, ["to", `() => ${field.to}`]);
|
|
24421
|
+
const [apiId, displayName, to, ...options] = referenceOptions(field, ["to", `() => ${identifier(field.to)}`]);
|
|
24412
24422
|
return printBuilder(customOf("referenceTwoWay", field.formRenderer), [
|
|
24413
24423
|
apiId,
|
|
24414
24424
|
displayName,
|
|
@@ -24420,7 +24430,7 @@ function printField(parent, field) {
|
|
|
24420
24430
|
]);
|
|
24421
24431
|
}
|
|
24422
24432
|
case "referenceUnion": {
|
|
24423
|
-
const [apiId, displayName, to, ...options] = referenceOptions(field, ["to", `[${field.to.map((apiId) => `() => ${apiId}`).join(", ")}]`]);
|
|
24433
|
+
const [apiId, displayName, to, ...options] = referenceOptions(field, ["to", `[${field.to.map((apiId) => `() => ${identifier(apiId)}`).join(", ")}]`]);
|
|
24424
24434
|
return printBuilder("referenceUnion", [
|
|
24425
24435
|
apiId,
|
|
24426
24436
|
displayName,
|
|
@@ -24431,7 +24441,7 @@ function printField(parent, field) {
|
|
|
24431
24441
|
]);
|
|
24432
24442
|
}
|
|
24433
24443
|
case "referenceUnionMember": {
|
|
24434
|
-
const [apiId, displayName, to, ...options] = referenceOptions(field, ["to", `() => ${field.to}`]);
|
|
24444
|
+
const [apiId, displayName, to, ...options] = referenceOptions(field, ["to", `() => ${identifier(field.to)}`]);
|
|
24435
24445
|
return printBuilder("referenceUnionMember", [
|
|
24436
24446
|
apiId,
|
|
24437
24447
|
displayName,
|
|
@@ -24614,7 +24624,7 @@ function printRegex(regex) {
|
|
|
24614
24624
|
* const. Attributes at their default are left out.
|
|
24615
24625
|
*/
|
|
24616
24626
|
function printComponent(component) {
|
|
24617
|
-
return `const ${component.apiId} = define.component(${object([
|
|
24627
|
+
return `const ${identifier(component.apiId)} = define.component(${object([
|
|
24618
24628
|
["apiId", string(component.apiId)],
|
|
24619
24629
|
["apiIdPlural", string(component.apiIdPlural)],
|
|
24620
24630
|
["displayName", string(component.displayName)],
|
|
@@ -24632,7 +24642,7 @@ function printComponent(component) {
|
|
|
24632
24642
|
*/
|
|
24633
24643
|
function printEnumeration(enumeration) {
|
|
24634
24644
|
const values = enumeration.values.map((value) => `{ apiId: ${string(value.apiId)}, displayName: ${string(value.displayName)} }`);
|
|
24635
|
-
return `const ${enumeration.apiId} = define.enumeration(${object([
|
|
24645
|
+
return `const ${identifier(enumeration.apiId)} = define.enumeration(${object([
|
|
24636
24646
|
["apiId", string(enumeration.apiId)],
|
|
24637
24647
|
["displayName", string(enumeration.displayName)],
|
|
24638
24648
|
["description", enumeration.description === null ? void 0 : string(enumeration.description)],
|
|
@@ -24695,7 +24705,7 @@ function printPreviewUrls(urls) {
|
|
|
24695
24705
|
* out, as is a sidebar the IR leaves to Hygraph.
|
|
24696
24706
|
*/
|
|
24697
24707
|
function printModel(model) {
|
|
24698
|
-
return `const ${model.apiId} = define.model(${object([
|
|
24708
|
+
return `const ${identifier(model.apiId)} = define.model(${object([
|
|
24699
24709
|
["apiId", string(model.apiId)],
|
|
24700
24710
|
["apiIdPlural", string(model.apiIdPlural)],
|
|
24701
24711
|
["displayName", string(model.displayName)],
|
|
@@ -24777,7 +24787,7 @@ function printTaxonomy(taxonomy) {
|
|
|
24777
24787
|
["children", `[${below.map(printNode).join(", ")}]`]
|
|
24778
24788
|
]);
|
|
24779
24789
|
};
|
|
24780
|
-
return `const ${taxonomy.apiId} = define.taxonomy(${object([
|
|
24790
|
+
return `const ${identifier(taxonomy.apiId)} = define.taxonomy(${object([
|
|
24781
24791
|
["apiId", string(taxonomy.apiId)],
|
|
24782
24792
|
["displayName", string(taxonomy.displayName)],
|
|
24783
24793
|
["description", taxonomy.description === null ? void 0 : string(taxonomy.description)],
|
|
@@ -24867,7 +24877,7 @@ async function printConfig(target, environment) {
|
|
|
24867
24877
|
* when live has it.
|
|
24868
24878
|
*/
|
|
24869
24879
|
function printEnvironment({ locales, stages, enumerations, taxonomies, remoteSources, components, models, asset, segment }) {
|
|
24870
|
-
const list = (resources) => `[${resources.map((resource) => resource.apiId).join(", ")}]`;
|
|
24880
|
+
const list = (resources) => `[${resources.map((resource) => identifier(resource.apiId)).join(", ")}]`;
|
|
24871
24881
|
return `const environment = define.environment({ ${[
|
|
24872
24882
|
`locales: [${locales.map(printLocale).join(", ")}]`,
|
|
24873
24883
|
`stages: [${stages.toSorted((a, b) => a.position - b.position).map(printStage).join(", ")}]`,
|
package/dist/define.d.ts
CHANGED
|
@@ -567,7 +567,7 @@ declare function component$1(input: ComponentInput): Component;
|
|
|
567
567
|
* The options `componentUnion` takes. Hygraph stores a union as never
|
|
568
568
|
* required, so it takes no `required`.
|
|
569
569
|
*/
|
|
570
|
-
type ComponentUnionFieldInput = Omit<FieldInput, "required"
|
|
570
|
+
type ComponentUnionFieldInput = Omit<FieldInput, "required"> & {
|
|
571
571
|
/**
|
|
572
572
|
* The components editors choose from, as `define.component` returns them,
|
|
573
573
|
* each behind a function: `[() => Hero, () => Banner]`. At least one, and
|
|
@@ -582,12 +582,6 @@ type ComponentUnionFieldInput = Omit<FieldInput, "required" | "visibility"> & {
|
|
|
582
582
|
* @default false
|
|
583
583
|
*/
|
|
584
584
|
list?: boolean;
|
|
585
|
-
/**
|
|
586
|
-
* Cannot change once the field exists: changing it deletes the field and
|
|
587
|
-
* its content.
|
|
588
|
-
* @default "READ_WRITE"
|
|
589
|
-
*/
|
|
590
|
-
visibility?: FieldVisibility;
|
|
591
585
|
};
|
|
592
586
|
/**
|
|
593
587
|
* What `define.field.componentUnion` hands back: the input with every
|
package/dist/version.js
CHANGED