@hygraph/cli 0.0.4 → 0.0.5

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,6 +1,6 @@
1
1
  import { r as __toESM, t as __commonJSMin } from "./rolldown-runtime.js";
2
2
  import { t as VERSION } from "./version.js";
3
- import { a as SLUG_DEFAULTS, c as environment, d as assetReverseApiId, f as isEmpty, i as target, l as byApiId$1, n as stage, o as collectIntents, s as convertEnvironmentToIR, u as FIELD_DEFAULTS } from "./define2.js";
3
+ import { a as SLUG_DEFAULTS, c as environment, d as RICH_TEXT_ACTIONS, f as isEmptyRichText, h as isEmpty, i as target, l as byApiId$1, m as assetReverseApiId, n as stage, o as collectIntents, p as richTextActions, s as convertEnvironmentToIR, u as FIELD_DEFAULTS } from "./define2.js";
4
4
  import { EventEmitter } from "node:events";
5
5
  import childProcess from "node:child_process";
6
6
  import path, { resolve } from "node:path";
@@ -3559,10 +3559,11 @@ function isRename(change) {
3559
3559
  * enumeration or a taxonomy deletes every field that uses it. Deleting a
3560
3560
  * value or a node is counted too, although Hygraph refuses it while entries
3561
3561
  * hold the value or a node of the subtree. A union
3562
- * update that drops a member deletes that member's content.
3562
+ * update that drops a member deletes that member's content, and a rich text
3563
+ * update that drops an embedded model deletes the embeds of its entries.
3563
3564
  */
3564
3565
  function isDestructive(change) {
3565
- return change.action === "delete" || dropsUnionMember(change);
3566
+ return change.action === "delete" || dropsUnionMember(change) || dropsEmbed(change);
3566
3567
  }
3567
3568
  /**
3568
3569
  * An asset field update that makes it required. It is not destructive, but
@@ -3573,6 +3574,16 @@ function makesAssetRequired(change) {
3573
3574
  return change.resource === "field" && change.action === "update" && change.kind === "asset" && change.changes.required?.to === true;
3574
3575
  }
3575
3576
  /**
3577
+ * A rich text update whose embeds leave out a model they had: Hygraph
3578
+ * deletes the embeds of that model's entries from every value of the
3579
+ * field. Embeds turned off are a delete, never an update.
3580
+ */
3581
+ function dropsEmbed(change) {
3582
+ if (change.resource !== "field" || change.action !== "update" || change.kind !== "richText") return false;
3583
+ const embeds = change.changes.embeds;
3584
+ return embeds?.from !== void 0 && embeds.from !== null && embeds.from.some((apiId) => !embeds.to?.includes(apiId));
3585
+ }
3586
+ /**
3576
3587
  * A union update whose new members leave out an old one: Hygraph deletes
3577
3588
  * that component's content from every entry.
3578
3589
  */
@@ -5427,6 +5438,7 @@ const FIELD_FAMILY = {
5427
5438
  json: "Simple",
5428
5439
  color: "Simple",
5429
5440
  location: "Simple",
5441
+ richText: "Simple",
5430
5442
  enumeration: "Enumerable",
5431
5443
  referenceOneWay: "Relational",
5432
5444
  referenceTwoWay: "Relational",
@@ -5538,6 +5550,7 @@ function simpleFieldType$1(kind) {
5538
5550
  case "json": return "JSON";
5539
5551
  case "color": return "COLOR";
5540
5552
  case "location": return "LOCATION";
5553
+ case "richText": return "RICHTEXT";
5541
5554
  }
5542
5555
  }
5543
5556
  function createSimpleField({ parent, migrationValue }, field) {
@@ -5562,13 +5575,18 @@ function createSimpleField({ parent, migrationValue }, field) {
5562
5575
  input.tableRenderer = field.formRenderer;
5563
5576
  if (field.slug !== null) input.formConfig = slugFormConfig(field.slug);
5564
5577
  }
5578
+ if (field.kind === "richText") {
5579
+ input.embedsEnabled = field.embeds !== null;
5580
+ if (field.embeds !== null) input.embeddableModels = field.embeds;
5581
+ if (field.actions !== null) input.formConfig = { actions: field.actions };
5582
+ }
5565
5583
  if ("validations" in field && field.validations !== null) input.validations = validationsInput(field.kind, field.validations);
5566
5584
  if (migrationValue !== void 0) input.migrationValue = jsonValue(migrationValue);
5567
5585
  return input;
5568
5586
  }
5569
5587
  /** Only the attributes that change are sent. A rename is `newApiId`. */
5570
5588
  function updateSimpleField(change) {
5571
- const { apiId, formRenderer, displayName, description, required, unique, localized, title, visibility, visibilityCondition, initialValue, position, validations, slug } = change.changes;
5589
+ const { apiId, formRenderer, displayName, description, required, unique, localized, title, visibility, visibilityCondition, initialValue, position, validations, slug, embeds, actions } = change.changes;
5572
5590
  const input = {
5573
5591
  apiId: change.apiId,
5574
5592
  parentApiId: change.parent
@@ -5590,6 +5608,11 @@ function updateSimpleField(change) {
5590
5608
  if (position) input.position = position.to;
5591
5609
  if (validations) input.validations = validations.to === null ? null : validationsInput(change.kind, validations.to);
5592
5610
  if (slug?.to) input.formConfig = { config: slugFormConfig(slug.to) };
5611
+ if (embeds?.to) {
5612
+ if (embeds.from === null) input.embedsEnabled = true;
5613
+ input.embeddableModels = embeddableModelsInput(embeds.from ?? [], embeds.to);
5614
+ }
5615
+ if (actions) input.formConfig = { config: actions.to === null ? {} : { actions: actions.to } };
5593
5616
  if (change.migrationValue !== void 0) {
5594
5617
  input.migrationValue = jsonValue(change.migrationValue);
5595
5618
  input.isList = Array.isArray(change.migrationValue);
@@ -5888,6 +5911,15 @@ function updateRelationalField(change) {
5888
5911
  if (rules) input.relationalFieldRules = rules.to;
5889
5912
  return input;
5890
5913
  }
5914
+ /** The models an update adds and removes, each key only when it has some. */
5915
+ function embeddableModelsInput(from, to) {
5916
+ const modelsToAdd = to.filter((apiId) => !from.includes(apiId));
5917
+ const modelsToRemove = from.filter((apiId) => !to.includes(apiId));
5918
+ return {
5919
+ ...modelsToAdd.length > 0 ? { modelsToAdd } : {},
5920
+ ...modelsToRemove.length > 0 ? { modelsToRemove } : {}
5921
+ };
5922
+ }
5891
5923
  /**
5892
5924
  * A slug's settings under Studio's names. A create takes them as the
5893
5925
  * `formConfig`, an update as its `config`: the server ignores them
@@ -6221,7 +6253,7 @@ function renderFieldChange(change, width, colors) {
6221
6253
  case "update": {
6222
6254
  if (unsupportedFieldMove(change)) return [` ${colors.yellow(`~ ${op}`)} ${subject} ${colors.dim(change.type)}`, ...renderAttributes(change.changes, colors)];
6223
6255
  const { apiId, ...attributes } = change.changes;
6224
- const warning = dropsUnionMember(change) ? ` ${colors.yellow(`⚠ deletes the content of the members it drops`)}` : makesAssetRequired(change) ? ` ${colors.yellow(`⚠ API creates must set it; entries without an asset may fail to read`)}` : "";
6256
+ const warning = dropsUnionMember(change) ? ` ${colors.yellow(`⚠ deletes the content of the members it drops`)}` : dropsEmbed(change) ? ` ${colors.yellow(`⚠ deletes the embeds of the models it drops`)}` : makesAssetRequired(change) ? ` ${colors.yellow(`⚠ API creates must set it; entries without an asset may fail to read`)}` : "";
6225
6257
  return [` ${colors.yellow(`~ ${op}`)} ${apiId ? `${subject} → ${apiId.to}` : subject}${warning}`, ...renderAttributes(attributes, colors, change.migrationValue)];
6226
6258
  }
6227
6259
  case "delete": {
@@ -6291,13 +6323,21 @@ function settingRow(attribute, setting) {
6291
6323
  entries: Object.entries(setting).flatMap(([key, entry]) => entry === null ? [] : [[key, value(entry)]])
6292
6324
  };
6293
6325
  }
6326
+ /**
6327
+ * How `null` reads on the attributes where it is not "none": rich text
6328
+ * without `actions` shows every action.
6329
+ */
6330
+ const NULL_TEXT = { actions: "(all)" };
6294
6331
  /** A nested attribute lists only the entries that changed. */
6295
6332
  function changeRow(attribute, change) {
6296
6333
  const { from, to } = change;
6297
- if (!NESTED.has(attribute) || !(isRecord(from) || isRecord(to))) return {
6298
- attribute,
6299
- text: `${value(from)} → ${value(to)}`
6300
- };
6334
+ if (!NESTED.has(attribute) || !(isRecord(from) || isRecord(to))) {
6335
+ const text = (side) => side === null ? NULL_TEXT[attribute] ?? value(side) : value(side);
6336
+ return {
6337
+ attribute,
6338
+ text: `${text(from)} → ${text(to)}`
6339
+ };
6340
+ }
6301
6341
  const before = isRecord(from) ? from : {};
6302
6342
  const after = isRecord(to) ? to : {};
6303
6343
  return {
@@ -12207,6 +12247,29 @@ const locationFieldSchema = strictObject({
12207
12247
  renamedFrom: string$1().nullable()
12208
12248
  });
12209
12249
  //#endregion
12250
+ //#region src/define/fields/richText.zod.ts
12251
+ /** The root of a Slate document. Its nodes are not checked. */
12252
+ const richTextValueSchema = strictObject({ children: array(json()) });
12253
+ const richTextValuesSchema = union([richTextValueSchema, array(richTextValueSchema)]).nullable();
12254
+ const richTextFieldSchema = strictObject({
12255
+ __typename: literal("RichTextField"),
12256
+ apiId: string$1(),
12257
+ displayName: string$1(),
12258
+ description: string$1().nullable(),
12259
+ list: boolean(),
12260
+ required: boolean(),
12261
+ unique: boolean(),
12262
+ localized: boolean(),
12263
+ title: literal(false),
12264
+ visibility: fieldVisibilitySchema,
12265
+ visibilityCondition: visibilityConditionSchema.nullable(),
12266
+ initialValue: richTextValuesSchema,
12267
+ migrationValue: richTextValuesSchema,
12268
+ embeds: array(custom((value) => typeof value === "function")).nullable(),
12269
+ actions: array(_enum(RICH_TEXT_ACTIONS)).nullable(),
12270
+ renamedFrom: string$1().nullable()
12271
+ });
12272
+ //#endregion
12210
12273
  //#region src/define/resources/stage.zod.ts
12211
12274
  /** Shared by the stage's schema and by the plan artifact. */
12212
12275
  const stageColorSchema = _enum([
@@ -12474,6 +12537,7 @@ const valueSchema = union([
12474
12537
  record(string$1(), json())
12475
12538
  ]);
12476
12539
  const initialValueSchema = valueSchema.nullable();
12540
+ const richTextActionsSchema = array(_enum(RICH_TEXT_ACTIONS));
12477
12541
  const migrationValueSchema = valueSchema;
12478
12542
  const rangeRuleSchema$1 = strictObject({
12479
12543
  min: number().nullable(),
@@ -12591,6 +12655,16 @@ const fieldSchema$1 = discriminatedUnion("kind", [
12591
12655
  title: literal(false),
12592
12656
  initialValue: union([json(), array(json())]).nullable()
12593
12657
  }),
12658
+ strictObject({
12659
+ ...fieldAttributes,
12660
+ kind: literal("richText"),
12661
+ unique: boolean(),
12662
+ localized: boolean(),
12663
+ title: literal(false),
12664
+ initialValue: union([richTextValueSchema, array(richTextValueSchema)]).nullable(),
12665
+ embeds: array(string$1()).nullable(),
12666
+ actions: richTextActionsSchema.nullable()
12667
+ }),
12594
12668
  strictObject({
12595
12669
  ...fieldAttributes,
12596
12670
  kind: literal("color"),
@@ -12668,6 +12742,7 @@ const changeSchema = discriminatedUnion("resource", [
12668
12742
  "enumeration",
12669
12743
  "taxonomy",
12670
12744
  "json",
12745
+ "richText",
12671
12746
  "color",
12672
12747
  "location",
12673
12748
  "component",
@@ -12692,7 +12767,9 @@ const changeSchema = discriminatedUnion("resource", [
12692
12767
  validations: attributeChangeSchema(union([stringValidationRulesSchema$1, numberValidationRulesSchema]).nullable()),
12693
12768
  slug: attributeChangeSchema(slugSettingsSchema.nullable()),
12694
12769
  components: attributeChangeSchema(array(string$1())),
12695
- rules: attributeChangeSchema(referenceRulesSchema.nullable())
12770
+ rules: attributeChangeSchema(referenceRulesSchema.nullable()),
12771
+ embeds: attributeChangeSchema(array(string$1()).nullable()),
12772
+ actions: attributeChangeSchema(richTextActionsSchema.nullable())
12696
12773
  }).partial(),
12697
12774
  migrationValue: migrationValueSchema.optional()
12698
12775
  }), strictObject({
@@ -13431,6 +13508,7 @@ const fieldSchema = discriminatedUnion("__typename", [
13431
13508
  renamedFrom: string$1().nullable()
13432
13509
  }),
13433
13510
  jsonFieldSchema,
13511
+ richTextFieldSchema,
13434
13512
  colorFieldSchema,
13435
13513
  locationFieldSchema,
13436
13514
  strictObject({
@@ -13647,7 +13725,14 @@ const messages = {
13647
13725
  ["field.referenceSelfPartner"]: (field) => `Field "${field}" names itself as its partner.`,
13648
13726
  ["field.requiredNotVisible"]: (field, visibility) => `Field "${field}" is required and ${visibility}, so editors cannot fill it in.`,
13649
13727
  ["field.assetReverseInvalid"]: (field, reverse) => `Field "${field}" gets the field "${reverse}" on Asset, which is not a valid apiId.`,
13728
+ ["field.richTextEmbedsEmpty"]: (field) => `Field "${field}" has embeds, but names no model to embed.`,
13729
+ ["field.richTextEmbedDuplicate"]: (field, model) => `Field "${field}" lists model "${model}" more than once in embeds.`,
13730
+ ["field.richTextEmbedMissing"]: (field, model) => `Field "${field}" embeds model "${model}", which is not in the environment.`,
13731
+ ["field.richTextEmbedComponent"]: (field, component) => `Field "${field}" embeds component "${component}". Rich text embeds entries of a model.`,
13732
+ ["field.richTextUniqueEmbeds"]: (field) => `Field "${field}" is unique and has embeds, which Hygraph refuses on a model.`,
13733
+ ["field.richTextRequiredList"]: (field) => `Field "${field}" is a required list, which Hygraph refuses on rich text.`,
13650
13734
  ["change.modelMissing"]: (action, apiId) => `Cannot ${action} model "${apiId}": it does not exist at that point of the migration.`,
13735
+ ["change.embedsReplaced"]: (field, models) => `Field "${field}" embeds only ${models}, which the plan deletes, and embeds a model the plan creates. It can embed the new model only after the create, and Hygraph refuses to delete a field's last embedded model before that.`,
13651
13736
  ["change.componentMissing"]: (action, apiId) => `Cannot ${action} component "${apiId}": it does not exist at that point of the migration.`,
13652
13737
  ["change.enumerationMissing"]: (action, apiId) => `Cannot ${action} enumeration "${apiId}": it does not exist at that point of the migration.`,
13653
13738
  ["change.taxonomyMissing"]: (action, apiId) => `Cannot ${action} taxonomy "${apiId}": it does not exist at that point of the migration.`,
@@ -13790,7 +13875,14 @@ const fixes = {
13790
13875
  ["field.referenceSelfPartner"]: "A two-way reference to its own model still has two fields. Set reverse to the apiId of another field on the model, which names this one back.",
13791
13876
  ["field.requiredNotVisible"]: "Set required: false, or make the field READ_WRITE or READ_ONLY.",
13792
13877
  ["field.assetReverseInvalid"]: "Use a valid field apiId, and keep it and its model's or component's apiId within 64 characters together: shorten either one if they are too long.",
13878
+ ["field.richTextEmbedsEmpty"]: "List at least one model in embeds, or remove embeds to turn them off.",
13879
+ ["field.richTextEmbedDuplicate"]: "List each model once in embeds.",
13880
+ ["field.richTextEmbedMissing"]: "Add the model to models in define.environment.",
13881
+ ["field.richTextEmbedComponent"]: "List only models in embeds. To hold a component, use define.field.component.",
13882
+ ["field.richTextUniqueEmbeds"]: "Remove unique, or remove embeds.",
13883
+ ["field.richTextRequiredList"]: "Remove required, or set list: false.",
13793
13884
  ["change.modelMissing"]: "An earlier change deletes or renames it. Plan against the current environment, and rename a model from one place only.",
13885
+ ["change.embedsReplaced"]: "Create the new models in one apply. Then change embeds and delete the old models in the next.",
13794
13886
  ["change.componentMissing"]: "An earlier change deletes or renames it. Plan against the current environment, and rename a component from one place only.",
13795
13887
  ["change.enumerationMissing"]: "An earlier change deletes or renames it. Plan against the current environment, and rename an enumeration from one place only.",
13796
13888
  ["change.taxonomyMissing"]: "An earlier change deletes or renames it. Plan against the current environment, and rename a taxonomy from one place only.",
@@ -14124,6 +14216,55 @@ function validateReferenceTwoWayPartners(parent, fields, models) {
14124
14216
  return validations;
14125
14217
  }
14126
14218
  //#endregion
14219
+ //#region src/define/fields/richText.validation.ts
14220
+ /**
14221
+ * What only rich text checks, from the server's rules and Studio's form:
14222
+ * embeds name at least one model, each once; a field with embeds on a
14223
+ * model is not unique; and a list is not required.
14224
+ */
14225
+ function validateRichTextField(parent, field) {
14226
+ const validations = [];
14227
+ const report = (code, attribute, message) => {
14228
+ validations.push({
14229
+ code,
14230
+ severity: "error",
14231
+ path: fieldPath(parent, field.apiId, attribute),
14232
+ message,
14233
+ fix: fixes[code]
14234
+ });
14235
+ };
14236
+ if (field.embeds !== null) {
14237
+ if (field.embeds.length === 0) report("field.richTextEmbedsEmpty", "embeds", messages["field.richTextEmbedsEmpty"](field.apiId));
14238
+ const apiIds = field.embeds.map((model) => model().apiId);
14239
+ for (const apiId of new Set(apiIds.filter((apiId, index) => apiIds.indexOf(apiId) !== index))) report("field.richTextEmbedDuplicate", "embeds", messages["field.richTextEmbedDuplicate"](field.apiId, apiId));
14240
+ if (field.unique && parent.kind === "model") report("field.richTextUniqueEmbeds", "unique", messages["field.richTextUniqueEmbeds"](field.apiId));
14241
+ }
14242
+ if (field.list && field.required) report("field.richTextRequiredList", "required", messages["field.richTextRequiredList"](field.apiId));
14243
+ return validations;
14244
+ }
14245
+ /**
14246
+ * Every model rich text embeds must be in the environment's `models`, or
14247
+ * the plan would embed a model it never creates. A component is refused on
14248
+ * its own: only the types keep it out of `embeds`.
14249
+ */
14250
+ function validateRichTextEmbedReferences(parent, fields, models) {
14251
+ return fields.flatMap((field) => {
14252
+ if (field.__typename !== "RichTextField" || field.embeds === null) return [];
14253
+ const path = fieldPath(parent, field.apiId, "embeds");
14254
+ return field.embeds.flatMap((embed) => {
14255
+ const target = embed();
14256
+ const code = target.__typename === "Component" ? "field.richTextEmbedComponent" : models.has(target.apiId) ? null : "field.richTextEmbedMissing";
14257
+ return code === null ? [] : [{
14258
+ code,
14259
+ severity: "error",
14260
+ path,
14261
+ message: messages[code](field.apiId, target.apiId),
14262
+ fix: fixes[code]
14263
+ }];
14264
+ });
14265
+ });
14266
+ }
14267
+ //#endregion
14127
14268
  //#region src/define/fields/taxonomy.validation.ts
14128
14269
  /**
14129
14270
  * What only taxonomy fields check on their own: a list can be neither
@@ -14491,6 +14632,7 @@ function validateTypeOptions(parent, field) {
14491
14632
  case "ReferenceOneWayField":
14492
14633
  case "ReferenceTwoWayField": return validateReferenceField(parent, field);
14493
14634
  case "AssetField": return validateAssetField(parent, field);
14635
+ case "RichTextField": return validateRichTextField(parent, field);
14494
14636
  case "ColorField": return validateColorField(parent, field);
14495
14637
  case "EnumerationField": return validateEnumerationField(parent, field);
14496
14638
  case "TaxonomyField": return validateTaxonomyField(parent, field);
@@ -15280,7 +15422,7 @@ function validateEnvironment(environment) {
15280
15422
  kind: parent.kind,
15281
15423
  apiId: parent.apiId
15282
15424
  };
15283
- validations.push(...validateEnumerationFieldReferences(fieldParent, parent.fields, enumerations), ...validateComponentFieldReferences(fieldParent, parent.fields, components), ...validateReferenceModelReferences(fieldParent, parent.fields, new Set(models.keys())), ...validateReferenceTwoWayPartners(fieldParent, parent.fields, models), ...validateTaxonomyFieldReferences(fieldParent, parent.fields, taxonomies));
15425
+ validations.push(...validateEnumerationFieldReferences(fieldParent, parent.fields, enumerations), ...validateComponentFieldReferences(fieldParent, parent.fields, components), ...validateReferenceModelReferences(fieldParent, parent.fields, new Set(models.keys())), ...validateReferenceTwoWayPartners(fieldParent, parent.fields, models), ...validateRichTextEmbedReferences(fieldParent, parent.fields, new Set(models.keys())), ...validateTaxonomyFieldReferences(fieldParent, parent.fields, taxonomies));
15284
15426
  }
15285
15427
  return validations;
15286
15428
  }
@@ -15665,9 +15807,9 @@ function basesFirst(creates) {
15665
15807
  /**
15666
15808
  * Hygraph cannot change a field's type or its `list` once it exists, nor an
15667
15809
  * enumeration field's enumeration or `localized`, a taxonomy field's
15668
- * taxonomy, a component field's component, a union's visibility, or the
15669
- * model a reference references. A two-way pair is decided as a whole, in
15670
- * `pairTwoWayReferences`.
15810
+ * taxonomy, a component field's component, a union's visibility or the
15811
+ * model a reference references, nor turn a rich text's embeds off. A
15812
+ * two-way pair is decided as a whole, in `pairTwoWayReferences`.
15671
15813
  */
15672
15814
  function changesInPlace(from, to) {
15673
15815
  if (from.kind === "unsupported" || to.kind === "unsupported") return from.kind === "unsupported" && to.kind === "unsupported" && from.type === to.type;
@@ -15676,6 +15818,7 @@ function changesInPlace(from, to) {
15676
15818
  if (from.kind === "component" && to.kind === "component") return from.list === to.list && from.component === to.component;
15677
15819
  if (from.kind === "componentUnion" && to.kind === "componentUnion") return from.list === to.list && from.visibility === to.visibility;
15678
15820
  if (from.kind === "referenceOneWay" && to.kind === "referenceOneWay") return from.list === to.list && from.to === to.to;
15821
+ if (from.kind === "richText" && to.kind === "richText") return from.list === to.list && (from.embeds === null || to.embeds !== null);
15679
15822
  return from.kind === to.kind && from.list === to.list;
15680
15823
  }
15681
15824
  /**
@@ -15733,6 +15876,16 @@ function diffField(from, to) {
15733
15876
  from: from.components,
15734
15877
  to: to.components
15735
15878
  };
15879
+ if (from.kind === "richText" && to.kind === "richText") {
15880
+ if (hashJSON(from.embeds) !== hashJSON(to.embeds)) changes.embeds = {
15881
+ from: from.embeds,
15882
+ to: to.embeds
15883
+ };
15884
+ if (hashJSON(from.actions) !== hashJSON(to.actions)) changes.actions = {
15885
+ from: from.actions,
15886
+ to: to.actions
15887
+ };
15888
+ }
15736
15889
  if ("rules" in from && "rules" in to && hashJSON(from.rules) !== hashJSON(to.rules)) changes.rules = {
15737
15890
  from: from.rules,
15738
15891
  to: to.rules
@@ -16058,7 +16211,9 @@ function parentsFirst(nodes) {
16058
16211
  * 1. locale renames, enumeration renames, value renames, taxonomy renames,
16059
16212
  * node renames, component renames, model renames, then field renames,
16060
16213
  * so that everything after them uses the new names;
16061
- * 2. field deletes, model deletes, value deletes, enumeration deletes,
16214
+ * 2. field deletes, the updates of rich text that drops a model the plan
16215
+ * deletes (see `orderEmbeds`), model deletes, value deletes,
16216
+ * enumeration deletes,
16062
16217
  * taxonomy deletes, locale deletes, then stage deletes, which free the
16063
16218
  * names a create may claim. A two-way pair has one delete, from the side
16064
16219
  * on the lower model, so the side it takes along is gone before that
@@ -16086,7 +16241,8 @@ function parentsFirst(nodes) {
16086
16241
  * updates that drop them;
16087
16242
  * 7. model creates, then field creates, so a new field's parent exists. A
16088
16243
  * base field is created before the fields whose condition names it;
16089
- * 8. conditions that name a field created in step 7, on fields that stay.
16244
+ * 8. conditions that name a field created in step 7, on fields that stay,
16245
+ * and the updates of rich text that embeds a model created in step 7.
16090
16246
  *
16091
16247
  * Locales, stages, enumerations, taxonomies, components and models follow
16092
16248
  * apiId order within each step, but stage creates and moves follow the
@@ -16176,9 +16332,11 @@ function diffEnvironment({ from, to, intents = {
16176
16332
  const stages = diffStages(renamed.stages, to.stages);
16177
16333
  const enumerations = diffEnumerations(renamed, to);
16178
16334
  const taxonomies = diffTaxonomies(renamed, to);
16335
+ const embeds = orderEmbeds(fieldUpdates, new Set(modelDeletes.flatMap((change) => change.resource === "model" && change.action === "delete" ? [change.apiId] : [])), new Set(to.models.filter((model) => !fromModels.has(model.apiId)).map((model) => model.apiId)));
16179
16336
  return [
16180
16337
  ...renames,
16181
16338
  ...fieldDeletes,
16339
+ ...embeds.beforeModelDeletes,
16182
16340
  ...modelDeletes,
16183
16341
  ...enumerations.valueDeletes,
16184
16342
  ...enumerations.deletes,
@@ -16203,14 +16361,45 @@ function diffEnvironment({ from, to, intents = {
16203
16361
  ...componentUpdates,
16204
16362
  ...componentCreates,
16205
16363
  ...modelUpdates,
16206
- ...fieldUpdates,
16364
+ ...embeds.updates,
16207
16365
  ...componentDeletes,
16208
16366
  ...modelCreates,
16209
16367
  ...fieldCreates,
16210
- ...fieldConditions
16368
+ ...fieldConditions,
16369
+ ...embeds.afterModelCreates
16211
16370
  ];
16212
16371
  }
16213
16372
  /**
16373
+ * The field updates, with rich text whose embeds the usual place would
16374
+ * fail moved out whole. Field updates run after the model deletes and
16375
+ * before the model creates, and the server cannot follow either:
16376
+ *
16377
+ * - it drops a model it cannot find from an update without an error, so a
16378
+ * field that embeds a created model goes after the model creates;
16379
+ * - it refuses to delete a model that is a field's last embed, so any
16380
+ * other field that drops a deleted model goes after the field deletes,
16381
+ * before the model deletes.
16382
+ *
16383
+ * Both places keep a move right: positions count after the field deletes,
16384
+ * and the model deletes renumber no other model's fields. A field whose
16385
+ * embeds were all deleted and that embeds a created model goes after the
16386
+ * creates, which `validateChangeSet` refuses.
16387
+ */
16388
+ function orderEmbeds(changes, deleted, created) {
16389
+ const order = {
16390
+ beforeModelDeletes: [],
16391
+ updates: [],
16392
+ afterModelCreates: []
16393
+ };
16394
+ for (const change of changes) {
16395
+ const embeds = change.resource === "field" && change.action === "update" && change.kind === "richText" ? change.changes.embeds : void 0;
16396
+ if ((embeds?.to ?? []).some((apiId) => created.has(apiId))) order.afterModelCreates.push(change);
16397
+ else if ((embeds?.from ?? []).some((apiId) => deleted.has(apiId))) order.beforeModelDeletes.push(change);
16398
+ else order.updates.push(change);
16399
+ }
16400
+ return order;
16401
+ }
16402
+ /**
16214
16403
  * `from` with every rename intent applied, and the renames as changes:
16215
16404
  * locales, enumerations, their values, taxonomies, their nodes,
16216
16405
  * components, models, then fields. Values, nodes and fields find their
@@ -16544,10 +16733,17 @@ function applyModelRenames(from, intents) {
16544
16733
  } }
16545
16734
  }));
16546
16735
  const rename = (apiId) => newApiIds.get(apiId) ?? apiId;
16547
- const parents = mapFields(from, (field) => field.kind === "referenceOneWay" || field.kind === "referenceTwoWay" ? {
16548
- ...field,
16549
- to: rename(field.to)
16550
- } : field);
16736
+ const parents = mapFields(from, (field) => {
16737
+ if (field.kind === "referenceOneWay" || field.kind === "referenceTwoWay") return {
16738
+ ...field,
16739
+ to: rename(field.to)
16740
+ };
16741
+ if (field.kind === "richText" && field.embeds !== null) return {
16742
+ ...field,
16743
+ embeds: field.embeds.map(rename).toSorted()
16744
+ };
16745
+ return field;
16746
+ });
16551
16747
  const models = parents.models.map((model) => ({
16552
16748
  ...model,
16553
16749
  apiId: rename(model.apiId)
@@ -17129,6 +17325,7 @@ function validateChangeSet({ from, changes }) {
17129
17325
  case "field": {
17130
17326
  validateComponentsUsed(change);
17131
17327
  validateModelReferenced(change);
17328
+ validateModelsEmbedded(change);
17132
17329
  if (models.has(change.parent) || components.has(change.parent)) break;
17133
17330
  const onComponent = componentApiIds.has(change.parent);
17134
17331
  report(onComponent ? "change.componentMissing" : "change.modelMissing", [
@@ -17180,6 +17377,21 @@ function validateChangeSet({ from, changes }) {
17180
17377
  fieldApiIdOf(change)
17181
17378
  ], `${change.action} a field that uses`, apiId);
17182
17379
  }
17380
+ function validateModelsEmbedded(change) {
17381
+ const embedded = change.action === "create" ? change.field.kind === "richText" ? change.field.embeds ?? [] : [] : change.action === "update" && change.kind === "richText" ? change.changes.embeds?.to ?? [] : [];
17382
+ const path = [
17383
+ componentApiIds.has(change.parent) ? "components" : "models",
17384
+ change.parent,
17385
+ "fields",
17386
+ fieldApiIdOf(change)
17387
+ ];
17388
+ const had = change.action === "update" && change.kind === "richText" ? change.changes.embeds?.from ?? [] : [];
17389
+ if (had.length > 0 && had.every((apiId) => !models.has(apiId))) {
17390
+ report("change.embedsReplaced", path, fieldApiIdOf(change), had.join(", "));
17391
+ return;
17392
+ }
17393
+ for (const apiId of embedded.filter((each) => !models.has(each))) report("change.modelMissing", path, `${change.action} a field that embeds`, apiId);
17394
+ }
17183
17395
  function validateModelReferenced(change) {
17184
17396
  if (change.action !== "create" || change.field.kind !== "referenceOneWay" && change.field.kind !== "referenceTwoWay" || models.has(change.field.to)) return;
17185
17397
  const kind = componentApiIds.has(change.parent) ? "components" : "models";
@@ -18130,6 +18342,90 @@ function convertRules(rules) {
18130
18342
  return connections === null ? null : { connections };
18131
18343
  }
18132
18344
  //#endregion
18345
+ //#region src/live/resources/richText.zod.ts
18346
+ /**
18347
+ * What tells whether the CLI can express the field, read before the op is
18348
+ * checked. A value it does not expect keeps the field unsupported instead
18349
+ * of failing the plan. The editor's config is strict: an update replaces
18350
+ * it whole, so a setting the CLI does not know would be lost.
18351
+ */
18352
+ const richTextSetupSchema = object$1({
18353
+ formRenderer: string$1().nullish(),
18354
+ formConfig: strictObject({
18355
+ actions: array(_enum(RICH_TEXT_ACTIONS)).nullish(),
18356
+ appApiId: string$1().nullish(),
18357
+ appElementApiId: string$1().nullish()
18358
+ }).nullish(),
18359
+ embedsEnabled: boolean().nullish(),
18360
+ embeddableModels: array(string$1()).nullish()
18361
+ });
18362
+ const createRichTextFieldSchema = object$1({
18363
+ ...simpleFieldShape,
18364
+ type: literal("RICHTEXT"),
18365
+ embedsEnabled: boolean().nullish(),
18366
+ embeddableModels: array(string$1()).nullish(),
18367
+ formConfig: object$1({ actions: array(_enum(RICH_TEXT_ACTIONS)).nullish() }).nullish()
18368
+ });
18369
+ //#endregion
18370
+ //#region src/live/resources/richText.ts
18371
+ /**
18372
+ * Rich text in the same canonical form `convertRichTextFieldToIR` gives a
18373
+ * field from the config, position as Hygraph stores it. `null` for one the
18374
+ * CLI cannot express yet, which is read as an unsupported field: an app's
18375
+ * editor, an embedded model that is not one of `models` (Asset among
18376
+ * them), or an action Studio does not offer. The setup is looked at first,
18377
+ * so such a field is never checked and cannot stop the plan.
18378
+ */
18379
+ function convertCreateRichTextFieldToIR(input, models) {
18380
+ if (!isSupported$1(input, models)) return null;
18381
+ const parsed = createRichTextFieldSchema.safeParse(input);
18382
+ if (!parsed.success) throw new Error(`Invalid createSimpleField params: \n${renderIssues(parsed.error.issues)}`);
18383
+ const field = parsed.data;
18384
+ const list = field.isList ?? false;
18385
+ const initialValue = parseValue({
18386
+ apiId: field.apiId,
18387
+ list
18388
+ }, field.initialValue, {
18389
+ one: richTextValueSchema,
18390
+ list: array(richTextValueSchema),
18391
+ expected: ["rich text", "a list of rich text"]
18392
+ });
18393
+ return {
18394
+ parentApiId: field.parentApiId,
18395
+ field: {
18396
+ kind: "richText",
18397
+ apiId: field.apiId,
18398
+ displayName: field.displayName,
18399
+ description: isEmpty(field.description) ? null : field.description,
18400
+ position: field.position,
18401
+ list,
18402
+ required: field.isRequired ?? false,
18403
+ unique: field.isUnique ?? false,
18404
+ localized: field.isLocalized ?? false,
18405
+ title: false,
18406
+ visibility: field.visibility ?? "READ_WRITE",
18407
+ visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
18408
+ initialValue: isEmptyRichText(initialValue) ? null : initialValue,
18409
+ embeds: field.embedsEnabled === true ? (field.embeddableModels ?? []).toSorted() : null,
18410
+ actions: richTextActions(field.formConfig?.actions ?? null)
18411
+ }
18412
+ };
18413
+ }
18414
+ /**
18415
+ * Whether the CLI can express the field's editor and embeds. Studio's
18416
+ * renderer is `GCMS`, or none in an op the batch wrote; an app sets its
18417
+ * own, or names itself in `formConfig`.
18418
+ */
18419
+ function isSupported$1(input, models) {
18420
+ const setup = richTextSetupSchema.safeParse(input);
18421
+ if (!setup.success) return false;
18422
+ const { formRenderer, formConfig, embedsEnabled, embeddableModels } = setup.data;
18423
+ if (!isEmpty(formRenderer) && formRenderer !== "GCMS" || !isEmpty(formConfig?.appApiId)) return false;
18424
+ if (embedsEnabled !== true) return true;
18425
+ const embedded = embeddableModels ?? [];
18426
+ return embedded.length > 0 && embedded.every((apiId) => models.has(apiId));
18427
+ }
18428
+ //#endregion
18133
18429
  //#region src/live/resources/string.zod.ts
18134
18430
  const liveRegexSchema = object$1({
18135
18431
  regex: string$1().nullish(),
@@ -18483,7 +18779,7 @@ function convertSchemaDefinitionToIR(ops, partners = /* @__PURE__ */ new Map())
18483
18779
  const [operationName] = Object.keys(op);
18484
18780
  switch (operationName) {
18485
18781
  case "createSimpleField":
18486
- addField(parents, convertCreateSimpleFieldToIR(op.createSimpleField));
18782
+ addField(parents, convertCreateSimpleFieldToIR(op.createSimpleField, modelApiIds));
18487
18783
  break;
18488
18784
  case "createComponentField":
18489
18785
  addField(parents, convertCreateComponentFieldToIR(op.createComponentField));
@@ -18536,7 +18832,8 @@ function addField(parents, live) {
18536
18832
  * type the CLI does not read, or a text editor it has no builder for, is
18537
18833
  * an unsupported field of that type.
18538
18834
  */
18539
- function convertCreateSimpleFieldToIR(value) {
18835
+ /** `models` are the ones rich text can embed and the CLI reads. */
18836
+ function convertCreateSimpleFieldToIR(value, models) {
18540
18837
  const type = simpleFieldType(value);
18541
18838
  switch (type) {
18542
18839
  case "BOOLEAN": return convertCreateBooleanFieldToIR(value);
@@ -18548,6 +18845,7 @@ function convertCreateSimpleFieldToIR(value) {
18548
18845
  case "JSON": return convertCreateJsonFieldToIR(value);
18549
18846
  case "COLOR": return convertCreateColorFieldToIR(value);
18550
18847
  case "LOCATION": return convertCreateLocationFieldToIR(value);
18848
+ case "RICHTEXT": return convertCreateRichTextFieldToIR(value, models) ?? convertCreateUnsupportedFieldToIR("createSimpleField", value, type);
18551
18849
  default: return convertCreateUnsupportedSimpleFieldToIR(value);
18552
18850
  }
18553
18851
  }
@@ -18945,6 +19243,11 @@ function printField(field) {
18945
19243
  ]);
18946
19244
  }
18947
19245
  case "json": return printBuilder("json", fieldOptions(field, FIELD_DEFAULTS));
19246
+ case "richText": return printBuilder("richText", [
19247
+ ...fieldOptions(field, FIELD_DEFAULTS),
19248
+ ["embeds", field.embeds === null ? void 0 : `[${field.embeds.map((apiId) => `() => ${apiId}`).join(", ")}]`],
19249
+ ["actions", field.actions === null ? void 0 : `[${field.actions.map(string).join(", ")}]`]
19250
+ ]);
18948
19251
  case "color": return printBuilder("color", fieldOptions(field, FIELD_DEFAULTS));
18949
19252
  case "location": return printBuilder("location", fieldOptions(field, FIELD_DEFAULTS));
18950
19253
  case "int":
package/dist/define.d.ts CHANGED
@@ -77,6 +77,12 @@ type IRLocation = {
77
77
  type IRJsonValue = string | number | boolean | null | IRJsonValue[] | {
78
78
  [key: string]: IRJsonValue;
79
79
  };
80
+ /** A toolbar action of Studio's rich text editor, by Studio's id. */
81
+ type IRRichTextAction = "heading-one" | "heading-two" | "heading-three" | "heading-four" | "heading-five" | "heading-six" | "bold" | "italic" | "underline" | "link" | "block-quote" | "code" | "asset" | "bulleted-list" | "numbered-list" | "code-block" | "iframe" | "class" | "table" | "superscript" | "subscript";
82
+ /** Rich text as Hygraph stores it: the root of a Slate document. */
83
+ type IRRichTextValue = {
84
+ children: IRJsonValue[];
85
+ };
80
86
  /** The flags Studio offers on a pattern: case insensitive, multiline, single line. */
81
87
  type IRRegexFlag = "i" | "m" | "s";
82
88
  //#endregion
@@ -808,6 +814,66 @@ type NumberValidationRules = {
808
814
  listItemCount: RangeRule | null;
809
815
  };
810
816
  //#endregion
817
+ //#region src/define/fields/richText.d.ts
818
+ /**
819
+ * Rich text as Hygraph stores it: the root of a Slate document, such as
820
+ * `{ children: [{ type: "paragraph", children: [{ text: "Hello" }] }] }`.
821
+ */
822
+ type RichTextValue = IRRichTextValue;
823
+ /** A toolbar action of Studio's rich text editor. */
824
+ type RichTextAction = IRRichTextAction;
825
+ /** The options `richText` takes. Hygraph refuses rich text as the title. */
826
+ type RichTextFieldInput = FieldInput & ValueFieldInput<RichTextValue> & UniqueFieldInput & LocalizedFieldInput & {
827
+ title?: never;
828
+ /**
829
+ * The models whose entries editors can embed, as `define.model` returns
830
+ * them, behind a function: `[() => Author]`. Leave it out to turn
831
+ * embeds off. List each model in the environment's `models` too. Once
832
+ * the field has embeds they cannot be turned off: leaving it out then
833
+ * deletes the field and its content. Taking a model out deletes the
834
+ * embeds of its entries.
835
+ * @default null
836
+ */
837
+ embeds?: (() => Model)[];
838
+ /**
839
+ * The toolbar actions Studio shows. Leave it out to show every action;
840
+ * `[]` shows none. Embeds have a button of their own, shown while the
841
+ * field has `embeds`.
842
+ * @default null
843
+ */
844
+ actions?: RichTextAction[];
845
+ };
846
+ /** What `define.field.richText` hands back: the input with every default filled in. */
847
+ type RichTextField = {
848
+ __typename: "RichTextField";
849
+ apiId: string;
850
+ displayName: string;
851
+ description: string | null;
852
+ list: boolean;
853
+ required: boolean;
854
+ unique: boolean;
855
+ localized: boolean;
856
+ /** Always `false`: Hygraph refuses rich text as the title. */
857
+ title: false;
858
+ visibility: FieldVisibility;
859
+ visibilityCondition: FieldVisibilityCondition | null;
860
+ /** A list of values on a list field, one value otherwise. */
861
+ initialValue: RichTextValue | RichTextValue[] | null;
862
+ /** Intent, like `renamedFrom`: read by the plan, never part of the IR. */
863
+ migrationValue: RichTextValue | RichTextValue[] | null;
864
+ embeds: (() => Model)[] | null;
865
+ actions: RichTextAction[] | null;
866
+ renamedFrom: string | null;
867
+ };
868
+ /**
869
+ * Formatted text, such as an article's body, with embedded entries of
870
+ * other models when `embeds` lists them. Allowed on components.
871
+ *
872
+ * Nothing here is validated, and the models are not looked at until the
873
+ * plan: the checks run at plan time with the model's or component's own.
874
+ */
875
+ declare function richText(input: RichTextFieldInput): RichTextField;
876
+ //#endregion
811
877
  //#region src/define/fields/string.d.ts
812
878
  /**
813
879
  * The options every text editor takes. Each editor's builder adds its own,
@@ -1041,7 +1107,7 @@ declare function unsupported(input: UnsupportedFieldInput): UnsupportedField;
1041
1107
  //#endregion
1042
1108
  //#region src/define/fields/field.d.ts
1043
1109
  /** One field of any type, as a `define.field.*` builder returns it. */
1044
- type Field = BooleanField | StringField | DateField | DateTimeField | IntField | FloatField | EnumerationField | TaxonomyField | JsonField | ColorField | LocationField | ComponentField | ComponentUnionField | ReferenceOneWayField | ReferenceTwoWayField | AssetField | UnsupportedField;
1110
+ type Field = BooleanField | StringField | DateField | DateTimeField | IntField | FloatField | EnumerationField | TaxonomyField | JsonField | RichTextField | ColorField | LocationField | ComponentField | ComponentUnionField | ReferenceOneWayField | ReferenceTwoWayField | AssetField | UnsupportedField;
1045
1111
  /**
1046
1112
  * Who sees the field. `READ_WRITE` shows it to editors and the API,
1047
1113
  * `READ_ONLY` shows it without letting editors change it, `HIDDEN` hides
@@ -1230,10 +1296,6 @@ declare function referenceUnion(_options: unknown): never;
1230
1296
  /** A field resolved from a remote source. `visibility` defaults to READ_ONLY. */
1231
1297
  declare function remote(_options: unknown): never;
1232
1298
  //#endregion
1233
- //#region src/define/fields/richText.d.ts
1234
- /** Rich text. `embeds` enables embedding; `actions` picks the toolbar. */
1235
- declare function richText(_options: unknown): never;
1236
- //#endregion
1237
1299
  //#region src/define/fields/singleLine.d.ts
1238
1300
  /**
1239
1301
  * One line of text, such as a heading or a title. Studio's single line
package/dist/define2.js CHANGED
@@ -603,6 +603,109 @@ function convertReferenceTwoWayFieldToIR(field, position) {
603
603
  };
604
604
  }
605
605
  //#endregion
606
+ //#region src/define/fields/richText.ts
607
+ /** Every toolbar action, in the order Studio's form lists them. */
608
+ const RICH_TEXT_ACTIONS = [
609
+ "heading-one",
610
+ "heading-two",
611
+ "heading-three",
612
+ "heading-four",
613
+ "heading-five",
614
+ "heading-six",
615
+ "bold",
616
+ "italic",
617
+ "underline",
618
+ "link",
619
+ "block-quote",
620
+ "code",
621
+ "asset",
622
+ "bulleted-list",
623
+ "numbered-list",
624
+ "code-block",
625
+ "iframe",
626
+ "class",
627
+ "table",
628
+ "superscript",
629
+ "subscript"
630
+ ];
631
+ /**
632
+ * Formatted text, such as an article's body, with embedded entries of
633
+ * other models when `embeds` lists them. Allowed on components.
634
+ *
635
+ * Nothing here is validated, and the models are not looked at until the
636
+ * plan: the checks run at plan time with the model's or component's own.
637
+ */
638
+ function richText(input) {
639
+ return {
640
+ __typename: "RichTextField",
641
+ apiId: input.apiId,
642
+ displayName: input.displayName,
643
+ description: isEmpty(input.description) ? null : input.description,
644
+ list: input.list ?? FIELD_DEFAULTS.list,
645
+ required: input.required ?? FIELD_DEFAULTS.required,
646
+ unique: input.unique ?? FIELD_DEFAULTS.unique,
647
+ localized: input.localized ?? FIELD_DEFAULTS.localized,
648
+ title: false,
649
+ visibility: input.visibility ?? FIELD_DEFAULTS.visibility,
650
+ visibilityCondition: input.visibilityCondition ?? null,
651
+ initialValue: richTextValue(input.initialValue),
652
+ migrationValue: richTextValue(input.migrationValue),
653
+ embeds: input.embeds === void 0 ? null : [...input.embeds],
654
+ actions: input.actions === void 0 ? null : [...input.actions],
655
+ renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
656
+ };
657
+ }
658
+ /**
659
+ * The IR names the models by apiId. Embeds and actions have no order, so
660
+ * the IR sorts them, each action once. `renamedFrom` and `migrationValue`
661
+ * are intent, not schema, and stay out.
662
+ */
663
+ function convertRichTextFieldToIR(field, position) {
664
+ return {
665
+ kind: "richText",
666
+ apiId: field.apiId,
667
+ displayName: field.displayName,
668
+ description: field.description,
669
+ position,
670
+ list: field.list,
671
+ required: field.required,
672
+ unique: field.unique,
673
+ localized: field.localized,
674
+ title: false,
675
+ visibility: field.visibility,
676
+ visibilityCondition: field.visibilityCondition,
677
+ initialValue: field.initialValue,
678
+ embeds: field.embeds?.map((model) => model().apiId).toSorted() ?? null,
679
+ actions: richTextActions(field.actions)
680
+ };
681
+ }
682
+ /** Sorted and each once, as the live reader reads them. */
683
+ function richTextActions(actions) {
684
+ return actions === null ? null : [...new Set(actions)].toSorted();
685
+ }
686
+ /**
687
+ * Whether a value is no value: `null`, an empty list, or what Studio's
688
+ * editor holds when nothing is written, one empty paragraph:
689
+ * `{ children: [{ type: "paragraph", children: [{ text: "" }] }] }`.
690
+ * Studio refuses that as a value. The live reader reads them the same way.
691
+ */
692
+ function isEmptyRichText(value) {
693
+ if (value === void 0 || value === null) return true;
694
+ if (Array.isArray(value)) return value.length === 0;
695
+ return Object.keys(value).length === 1 && Array.isArray(value.children) && value.children.length === 1 && isEmptyParagraph(value.children[0]);
696
+ }
697
+ function isEmptyParagraph(node) {
698
+ if (typeof node !== "object" || node === null || Array.isArray(node)) return false;
699
+ const { type, children, ...rest } = node;
700
+ if (type !== "paragraph" || Object.keys(rest).length > 0) return false;
701
+ if (!Array.isArray(children) || children.length !== 1) return false;
702
+ const [leaf] = children;
703
+ return typeof leaf === "object" && leaf !== null && Object.keys(leaf).length === 1 && leaf.text === "";
704
+ }
705
+ function richTextValue(value) {
706
+ return value === void 0 || isEmptyRichText(value) ? null : value;
707
+ }
708
+ //#endregion
606
709
  //#region src/define/not-implemented.ts
607
710
  /**
608
711
  * Every builder is declared so the authoring surface is fixed, but none of
@@ -829,6 +932,7 @@ function convertTypeToIR(field, position) {
829
932
  case "EnumerationField": return convertEnumerationFieldToIR(field, position);
830
933
  case "TaxonomyField": return convertTaxonomyFieldToIR(field, position);
831
934
  case "JsonField": return convertJsonFieldToIR(field, position);
935
+ case "RichTextField": return convertRichTextFieldToIR(field, position);
832
936
  case "ColorField": return convertColorFieldToIR(field, position);
833
937
  case "LocationField": return convertLocationFieldToIR(field, position);
834
938
  case "ComponentField": return convertComponentFieldToIR(field, position);
@@ -1240,12 +1344,6 @@ function remote(_options) {
1240
1344
  return notImplemented("define.field.remote");
1241
1345
  }
1242
1346
  //#endregion
1243
- //#region src/define/fields/richText.ts
1244
- /** Rich text. `embeds` enables embedding; `actions` picks the toolbar. */
1245
- function richText(_options) {
1246
- return notImplemented("define.field.richText");
1247
- }
1248
- //#endregion
1249
1347
  //#region src/define/fields/singleLine.ts
1250
1348
  /**
1251
1349
  * One line of text, such as a heading or a title. Studio's single line
@@ -1408,4 +1506,4 @@ var system_exports = /* @__PURE__ */ __exportAll({
1408
1506
  stage: () => stage
1409
1507
  });
1410
1508
  //#endregion
1411
- export { SLUG_DEFAULTS as a, environment as c, assetReverseApiId as d, isEmpty as f, target as i, byApiId as l, stage as n, collectIntents as o, define_exports as r, convertEnvironmentToIR as s, system_exports as t, FIELD_DEFAULTS as u };
1509
+ export { SLUG_DEFAULTS as a, environment as c, RICH_TEXT_ACTIONS as d, isEmptyRichText as f, isEmpty as h, target as i, byApiId as l, assetReverseApiId as m, stage as n, collectIntents as o, richTextActions as p, define_exports as r, convertEnvironmentToIR as s, system_exports as t, FIELD_DEFAULTS as u };
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/version.ts
2
- const VERSION = "0.0.4";
2
+ const VERSION = "0.0.5";
3
3
  //#endregion
4
4
  export { VERSION as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hygraph/cli",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Manage your Hygraph schema as code",
5
5
  "license": "MIT",
6
6
  "author": "Hygraph GmbH",
@@ -26,7 +26,7 @@
26
26
  "./package.json": "./package.json"
27
27
  },
28
28
  "publishConfig": {
29
- "access": "restricted"
29
+ "access": "public"
30
30
  },
31
31
  "dependencies": {
32
32
  "jiti": "^2.7.0",