@hygraph/cli 0.0.4 → 0.0.6
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 +5948 -5390
- package/dist/define.d.ts +67 -5
- package/dist/define2.js +105 -7
- package/dist/version.js +1 -1
- package/package.json +2 -2
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,
|
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hygraph/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
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": "
|
|
29
|
+
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"jiti": "^2.7.0",
|