@hygraph/cli 0.0.6 → 0.0.8

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/define.d.ts CHANGED
@@ -352,6 +352,60 @@ type ReferenceTwoWayField = {
352
352
  */
353
353
  declare function referenceTwoWay(input: ReferenceTwoWayFieldInput): ReferenceTwoWayField;
354
354
  //#endregion
355
+ //#region src/define/fields/referenceUnionMember.d.ts
356
+ /** The options `referenceUnionMember` takes. A reference cannot be required. */
357
+ type ReferenceUnionMemberFieldInput = Omit<FieldInput, "required"> & {
358
+ /**
359
+ * The model the union reference is on, as `define.model` returns it,
360
+ * behind a function: `() => Page`. List the model in the environment's
361
+ * `models` too. Cannot change once the field exists.
362
+ */
363
+ to: () => Model;
364
+ /**
365
+ * The apiId of the union reference on `to`, a
366
+ * `define.field.referenceUnion` that lists this model and has this
367
+ * field's apiId as its `reverse`. Cannot change once the field exists.
368
+ */
369
+ reverse: string;
370
+ /**
371
+ * Whether the field connects to a list of entries. Every model of the
372
+ * union has the same. Cannot change once the field exists: changing it
373
+ * deletes the union reference, every field back and their connections.
374
+ * @default false
375
+ */
376
+ list?: boolean;
377
+ };
378
+ /**
379
+ * What `define.field.referenceUnionMember` hands back: the input with every
380
+ * default filled in.
381
+ */
382
+ type ReferenceUnionMemberField = {
383
+ __typename: "ReferenceUnionMemberField";
384
+ apiId: string;
385
+ displayName: string;
386
+ description: string | null;
387
+ to: () => Model;
388
+ reverse: string;
389
+ list: boolean;
390
+ /** Always `false`: a reference cannot be required. */
391
+ required: false;
392
+ visibility: FieldVisibility;
393
+ visibilityCondition: FieldVisibilityCondition | null;
394
+ renamedFrom: string | null;
395
+ };
396
+ /**
397
+ * The entries whose union reference connects to this one: the field back
398
+ * of a `define.field.referenceUnion`, on each model it lists. Every one
399
+ * has the same apiId, the union's `reverse`; each has its own name,
400
+ * visibility and condition. To rename them, set `renamedFrom` on one that
401
+ * already exists: the others follow. Models only: a component cannot have
402
+ * one.
403
+ *
404
+ * Nothing here is validated, and the model is not looked at until the
405
+ * plan: the checks run at plan time with the model's own.
406
+ */
407
+ declare function referenceUnionMember(input: ReferenceUnionMemberFieldInput): ReferenceUnionMemberField;
408
+ //#endregion
355
409
  //#region src/define/resources/component.d.ts
356
410
  type ComponentInput = {
357
411
  /**
@@ -374,9 +428,9 @@ type ComponentInput = {
374
428
  /**
375
429
  * The component's fields, built with `define.field.*`. The order here is
376
430
  * the order editors see them in. May be empty. Every field type but
377
- * `referenceTwoWay`, which only models have.
431
+ * `referenceTwoWay` and `referenceUnionMember`, which only models have.
378
432
  */
379
- fields: Exclude<Field, ReferenceTwoWayField>[];
433
+ fields: Exclude<Field, ReferenceTwoWayField | ReferenceUnionMemberField>[];
380
434
  /**
381
435
  * The apiId this component has in Hygraph right now, when you are
382
436
  * renaming it. The rename keeps the component's fields and content
@@ -814,6 +868,80 @@ type NumberValidationRules = {
814
868
  listItemCount: RangeRule | null;
815
869
  };
816
870
  //#endregion
871
+ //#region src/define/fields/referenceUnion.d.ts
872
+ /**
873
+ * The options `referenceUnion` takes. A reference cannot be required. To
874
+ * make editors connect an entry, set `rules: { connections: { min: 1 } }`.
875
+ */
876
+ type ReferenceUnionFieldInput = Omit<FieldInput, "required"> & {
877
+ /**
878
+ * The models whose entries the field connects to, as `define.model`
879
+ * returns them, each behind a function: `[() => Video, () => Image]`.
880
+ * The functions let a model be one of its own, and two files use each
881
+ * other in any order. List each model once, and in the environment's
882
+ * `models` too. Adding a model gives it its field back; removing one
883
+ * deletes that field and its connections. Replacing every model deletes
884
+ * the field, every field back and their connections, and creates them
885
+ * again.
886
+ */
887
+ to: (() => Model)[];
888
+ /**
889
+ * The apiId of the field each model in `to` has back to this one, its
890
+ * `define.field.referenceUnionMember`. Every one of them has this apiId. Set
891
+ * it on a model, and leave it out on a component: a component's union has no
892
+ * field back that you see. To rename the fields back, set `renamedFrom` on
893
+ * one of them that already exists, and set this to the new apiId. Any other
894
+ * change deletes the field, every field back and their connections, and
895
+ * creates them again.
896
+ * @default null
897
+ */
898
+ reverse?: string;
899
+ /**
900
+ * Whether the field connects to a list of entries. Cannot change once
901
+ * the field exists: changing it deletes the field, every field back and
902
+ * their connections.
903
+ * @default false
904
+ */
905
+ list?: boolean;
906
+ /**
907
+ * What Studio asks of editors before they save an entry. The API does
908
+ * not check it. To require a connected entry, set
909
+ * `{ connections: { min: 1 } }`. That is the only rule a single
910
+ * reference takes; a list takes any `min` and `max`.
911
+ * @default null
912
+ */
913
+ rules?: ReferenceRulesInput;
914
+ };
915
+ /**
916
+ * What `define.field.referenceUnion` hands back: the input with every
917
+ * default filled in.
918
+ */
919
+ type ReferenceUnionField = {
920
+ __typename: "ReferenceUnionField";
921
+ apiId: string;
922
+ displayName: string;
923
+ description: string | null;
924
+ to: (() => Model)[];
925
+ reverse: string | null;
926
+ list: boolean;
927
+ /** Always `false`: a reference cannot be required. */
928
+ required: false;
929
+ rules: ReferenceRules | null;
930
+ visibility: FieldVisibility;
931
+ visibilityCondition: FieldVisibilityCondition | null;
932
+ renamedFrom: string | null;
933
+ };
934
+ /**
935
+ * Entries of several models, which editors choose from, such as a video or an
936
+ * image. On a model, each of those models shows the connection back in a field
937
+ * of its own: declare it there with `define.field.referenceUnionMember`, and
938
+ * name it here in `reverse`. On a component, leave `reverse` out.
939
+ *
940
+ * Nothing here is validated, and the models are not looked at until the
941
+ * plan: the checks run at plan time with the model's own.
942
+ */
943
+ declare function referenceUnion(input: ReferenceUnionFieldInput): ReferenceUnionField;
944
+ //#endregion
817
945
  //#region src/define/fields/richText.d.ts
818
946
  /**
819
947
  * Rich text as Hygraph stores it: the root of a Slate document, such as
@@ -1107,7 +1235,7 @@ declare function unsupported(input: UnsupportedFieldInput): UnsupportedField;
1107
1235
  //#endregion
1108
1236
  //#region src/define/fields/field.d.ts
1109
1237
  /** One field of any type, as a `define.field.*` builder returns it. */
1110
- type Field = BooleanField | StringField | DateField | DateTimeField | IntField | FloatField | EnumerationField | TaxonomyField | JsonField | RichTextField | ColorField | LocationField | ComponentField | ComponentUnionField | ReferenceOneWayField | ReferenceTwoWayField | AssetField | UnsupportedField;
1238
+ type Field = BooleanField | StringField | DateField | DateTimeField | IntField | FloatField | EnumerationField | TaxonomyField | JsonField | RichTextField | ColorField | LocationField | ComponentField | ComponentUnionField | ReferenceOneWayField | ReferenceTwoWayField | ReferenceUnionField | ReferenceUnionMemberField | AssetField | UnsupportedField;
1111
1239
  /**
1112
1240
  * Who sees the field. `READ_WRITE` shows it to editors and the API,
1113
1241
  * `READ_ONLY` shows it without letting editors change it, `HIDDEN` hides
@@ -1288,10 +1416,6 @@ declare function markdown(input: StringFieldInput): MarkdownField;
1288
1416
  */
1289
1417
  declare function multiline(input: StringFieldInput): MultilineField;
1290
1418
  //#endregion
1291
- //#region src/define/fields/referenceUnion.d.ts
1292
- /** A reference to several models. On models every member declares `unionMember`. */
1293
- declare function referenceUnion(_options: unknown): never;
1294
- //#endregion
1295
1419
  //#region src/define/fields/remote.d.ts
1296
1420
  /** A field resolved from a remote source. `visibility` defaults to READ_ONLY. */
1297
1421
  declare function remote(_options: unknown): never;
@@ -1351,15 +1475,11 @@ type SlugFieldInput = FieldInput & LocalizedFieldInput & {
1351
1475
  */
1352
1476
  declare function slug(input: SlugFieldInput): SlugField;
1353
1477
  //#endregion
1354
- //#region src/define/fields/unionMember.d.ts
1355
- /** The slot a union's member model declares. All members share one `apiId`. Models only. */
1356
- declare function unionMember(_options: unknown): never;
1357
- //#endregion
1358
1478
  //#region src/define/fields/vector.d.ts
1359
1479
  /** An embedding. `dimension` is required (1 to 3072); `index` is refused above 2000. */
1360
1480
  declare function vector(_options: unknown): never;
1361
1481
  declare namespace index_d_exports$2 {
1362
- export { asset$1 as asset, boolean, color, component, componentUnion, date, dateTime, enumeration, float, int, json, location, markdown, multiline, referenceOneWay, referenceTwoWay, referenceUnion, remote, richText, singleLine, slug, string, taxonomy, unionMember, unsupported, vector };
1482
+ export { asset$1 as asset, boolean, color, component, componentUnion, date, dateTime, enumeration, float, int, json, location, markdown, multiline, referenceOneWay, referenceTwoWay, referenceUnion, referenceUnionMember, remote, richText, singleLine, slug, string, taxonomy, unsupported, vector };
1363
1483
  }
1364
1484
  //#endregion
1365
1485
  //#region src/define/system/stage.d.ts
package/dist/define2.js CHANGED
@@ -603,6 +603,97 @@ function convertReferenceTwoWayFieldToIR(field, position) {
603
603
  };
604
604
  }
605
605
  //#endregion
606
+ //#region src/define/fields/referenceUnion.ts
607
+ /**
608
+ * Entries of several models, which editors choose from, such as a video or an
609
+ * image. On a model, each of those models shows the connection back in a field
610
+ * of its own: declare it there with `define.field.referenceUnionMember`, and
611
+ * name it here in `reverse`. On a component, leave `reverse` out.
612
+ *
613
+ * Nothing here is validated, and the models are not looked at until the
614
+ * plan: the checks run at plan time with the model's own.
615
+ */
616
+ function referenceUnion(input) {
617
+ return {
618
+ __typename: "ReferenceUnionField",
619
+ apiId: input.apiId,
620
+ displayName: input.displayName,
621
+ description: isEmpty(input.description) ? null : input.description,
622
+ to: [...input.to],
623
+ reverse: isEmpty(input.reverse) ? null : input.reverse,
624
+ list: input.list ?? FIELD_DEFAULTS.list,
625
+ required: false,
626
+ rules: input.rules === void 0 ? null : referenceRules(input.rules),
627
+ visibility: input.visibility ?? FIELD_DEFAULTS.visibility,
628
+ visibilityCondition: input.visibilityCondition ?? null,
629
+ renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
630
+ };
631
+ }
632
+ /**
633
+ * The IR names the models by their apiIds, sorted: Hygraph keeps no order
634
+ * for them. `renamedFrom` stays out.
635
+ */
636
+ function convertReferenceUnionFieldToIR(field, position) {
637
+ return {
638
+ kind: "referenceUnion",
639
+ apiId: field.apiId,
640
+ displayName: field.displayName,
641
+ description: field.description,
642
+ to: field.to.map((model) => model().apiId).toSorted(),
643
+ reverse: field.reverse,
644
+ rules: field.rules,
645
+ position,
646
+ list: field.list,
647
+ required: false,
648
+ visibility: field.visibility,
649
+ visibilityCondition: field.visibilityCondition
650
+ };
651
+ }
652
+ //#endregion
653
+ //#region src/define/fields/referenceUnionMember.ts
654
+ /**
655
+ * The entries whose union reference connects to this one: the field back
656
+ * of a `define.field.referenceUnion`, on each model it lists. Every one
657
+ * has the same apiId, the union's `reverse`; each has its own name,
658
+ * visibility and condition. To rename them, set `renamedFrom` on one that
659
+ * already exists: the others follow. Models only: a component cannot have
660
+ * one.
661
+ *
662
+ * Nothing here is validated, and the model is not looked at until the
663
+ * plan: the checks run at plan time with the model's own.
664
+ */
665
+ function referenceUnionMember(input) {
666
+ return {
667
+ __typename: "ReferenceUnionMemberField",
668
+ apiId: input.apiId,
669
+ displayName: input.displayName,
670
+ description: isEmpty(input.description) ? null : input.description,
671
+ to: input.to,
672
+ reverse: input.reverse,
673
+ list: input.list ?? FIELD_DEFAULTS.list,
674
+ required: false,
675
+ visibility: input.visibility ?? FIELD_DEFAULTS.visibility,
676
+ visibilityCondition: input.visibilityCondition ?? null,
677
+ renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
678
+ };
679
+ }
680
+ /** The IR names the model by its apiId. `renamedFrom` stays out. */
681
+ function convertReferenceUnionMemberFieldToIR(field, position) {
682
+ return {
683
+ kind: "referenceUnionMember",
684
+ apiId: field.apiId,
685
+ displayName: field.displayName,
686
+ description: field.description,
687
+ to: field.to().apiId,
688
+ reverse: field.reverse,
689
+ position,
690
+ list: field.list,
691
+ required: false,
692
+ visibility: field.visibility,
693
+ visibilityCondition: field.visibilityCondition
694
+ };
695
+ }
696
+ //#endregion
606
697
  //#region src/define/fields/richText.ts
607
698
  /** Every toolbar action, in the order Studio's form lists them. */
608
699
  const RICH_TEXT_ACTIONS = [
@@ -939,6 +1030,8 @@ function convertTypeToIR(field, position) {
939
1030
  case "ComponentUnionField": return convertComponentUnionFieldToIR(field, position);
940
1031
  case "ReferenceOneWayField": return convertReferenceOneWayFieldToIR(field, position);
941
1032
  case "ReferenceTwoWayField": return convertReferenceTwoWayFieldToIR(field, position);
1033
+ case "ReferenceUnionField": return convertReferenceUnionFieldToIR(field, position);
1034
+ case "ReferenceUnionMemberField": return convertReferenceUnionMemberFieldToIR(field, position);
942
1035
  case "AssetField": return convertAssetFieldToIR(field, position);
943
1036
  case "SingleLineField":
944
1037
  case "MultilineField":
@@ -1332,12 +1425,6 @@ function multiline(input) {
1332
1425
  };
1333
1426
  }
1334
1427
  //#endregion
1335
- //#region src/define/fields/referenceUnion.ts
1336
- /** A reference to several models. On models every member declares `unionMember`. */
1337
- function referenceUnion(_options) {
1338
- return notImplemented("define.field.referenceUnion");
1339
- }
1340
- //#endregion
1341
1428
  //#region src/define/fields/remote.ts
1342
1429
  /** A field resolved from a remote source. `visibility` defaults to READ_ONLY. */
1343
1430
  function remote(_options) {
@@ -1381,12 +1468,6 @@ function slug(input) {
1381
1468
  };
1382
1469
  }
1383
1470
  //#endregion
1384
- //#region src/define/fields/unionMember.ts
1385
- /** The slot a union's member model declares. All members share one `apiId`. Models only. */
1386
- function unionMember(_options) {
1387
- return notImplemented("define.field.unionMember");
1388
- }
1389
- //#endregion
1390
1471
  //#region src/define/fields/vector.ts
1391
1472
  /** An embedding. `dimension` is required (1 to 3072); `index` is refused above 2000. */
1392
1473
  function vector(_options) {
@@ -1412,13 +1493,13 @@ var fields_exports = /* @__PURE__ */ __exportAll({
1412
1493
  referenceOneWay: () => referenceOneWay,
1413
1494
  referenceTwoWay: () => referenceTwoWay,
1414
1495
  referenceUnion: () => referenceUnion,
1496
+ referenceUnionMember: () => referenceUnionMember,
1415
1497
  remote: () => remote,
1416
1498
  richText: () => richText,
1417
1499
  singleLine: () => singleLine,
1418
1500
  slug: () => slug,
1419
1501
  string: () => string,
1420
1502
  taxonomy: () => taxonomy$1,
1421
- unionMember: () => unionMember,
1422
1503
  unsupported: () => unsupported,
1423
1504
  vector: () => vector
1424
1505
  });
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/version.ts
2
- const VERSION = "0.0.6";
2
+ const VERSION = "0.0.8";
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.6",
3
+ "version": "0.0.8",
4
4
  "description": "Manage your Hygraph schema as code",
5
5
  "license": "MIT",
6
6
  "author": "Hygraph GmbH",