@hygraph/cli 0.0.12 → 0.0.14
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/README.md +32 -10
- package/dist/cli.js +5550 -4628
- package/dist/define.d.ts +150 -15
- package/dist/define2.js +140 -24
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/define2.js
CHANGED
|
@@ -9,6 +9,33 @@ function isEmpty(value) {
|
|
|
9
9
|
return value === void 0 || value === null || value === "";
|
|
10
10
|
}
|
|
11
11
|
//#endregion
|
|
12
|
+
//#region src/define/fields/renderer.ts
|
|
13
|
+
/**
|
|
14
|
+
* An app's element with its defaults filled in. Nothing is checked here: a
|
|
15
|
+
* config that leaves it out, which only an untyped one can, gets empty
|
|
16
|
+
* apiIds, which the plan's config checks report.
|
|
17
|
+
*/
|
|
18
|
+
function appRenderer(input) {
|
|
19
|
+
return { app: {
|
|
20
|
+
appApiId: input?.app?.appApiId ?? "",
|
|
21
|
+
appElementApiId: input?.app?.appElementApiId ?? "",
|
|
22
|
+
config: { ...input?.app?.config }
|
|
23
|
+
} };
|
|
24
|
+
}
|
|
25
|
+
/** The renderer as the IR holds it, `null` for Hygraph's editor. */
|
|
26
|
+
function convertFieldRendererToIR(renderer) {
|
|
27
|
+
return renderer === null ? null : convertAppRendererToIR(renderer);
|
|
28
|
+
}
|
|
29
|
+
/** An app's element as the IR holds it: no settings is `null`. */
|
|
30
|
+
function convertAppRendererToIR(renderer) {
|
|
31
|
+
const { appApiId, appElementApiId, config } = renderer.app;
|
|
32
|
+
return { app: {
|
|
33
|
+
appApiId,
|
|
34
|
+
appElementApiId,
|
|
35
|
+
config: Object.keys(config).length === 0 ? null : { ...config }
|
|
36
|
+
} };
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
12
39
|
//#region src/define/fields/asset.ts
|
|
13
40
|
/**
|
|
14
41
|
* One asset, or a list of them, that editors connect to the entry. Hygraph
|
|
@@ -32,6 +59,7 @@ function asset$1(input) {
|
|
|
32
59
|
visibilityCondition: input.visibilityCondition ?? null,
|
|
33
60
|
variantEnabled: input.variantEnabled ?? FIELD_DEFAULTS.variantEnabled,
|
|
34
61
|
reverse: isEmpty(input.reverse) ? null : input.reverse,
|
|
62
|
+
renderer: null,
|
|
35
63
|
renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
|
|
36
64
|
};
|
|
37
65
|
}
|
|
@@ -48,6 +76,7 @@ function convertAssetFieldToIR(field, position) {
|
|
|
48
76
|
visibility: field.visibility,
|
|
49
77
|
visibilityCondition: field.visibilityCondition,
|
|
50
78
|
variantEnabled: field.variantEnabled,
|
|
79
|
+
formRenderer: convertFieldRendererToIR(field.renderer),
|
|
51
80
|
...field.reverse !== null && { reverse: field.reverse }
|
|
52
81
|
};
|
|
53
82
|
}
|
|
@@ -103,7 +132,8 @@ function convertAssetReverseFieldToIR(field, position) {
|
|
|
103
132
|
required: false,
|
|
104
133
|
visibility: field.visibility,
|
|
105
134
|
visibilityCondition: null,
|
|
106
|
-
variantEnabled: false
|
|
135
|
+
variantEnabled: false,
|
|
136
|
+
formRenderer: null
|
|
107
137
|
};
|
|
108
138
|
}
|
|
109
139
|
//#endregion
|
|
@@ -131,6 +161,7 @@ function boolean(input) {
|
|
|
131
161
|
variantEnabled: input.variantEnabled ?? FIELD_DEFAULTS.variantEnabled,
|
|
132
162
|
initialValue: booleanValue(input.initialValue),
|
|
133
163
|
migrationValue: booleanValue(input.migrationValue),
|
|
164
|
+
renderer: null,
|
|
134
165
|
renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
|
|
135
166
|
};
|
|
136
167
|
}
|
|
@@ -150,6 +181,7 @@ function convertBooleanFieldToIR(field, position) {
|
|
|
150
181
|
visibility: field.visibility,
|
|
151
182
|
visibilityCondition: field.visibilityCondition,
|
|
152
183
|
variantEnabled: field.variantEnabled,
|
|
184
|
+
formRenderer: convertFieldRendererToIR(field.renderer),
|
|
153
185
|
initialValue: field.initialValue
|
|
154
186
|
};
|
|
155
187
|
}
|
|
@@ -180,6 +212,7 @@ function color(input) {
|
|
|
180
212
|
variantEnabled: input.variantEnabled ?? FIELD_DEFAULTS.variantEnabled,
|
|
181
213
|
initialValue: colorValue(input.initialValue),
|
|
182
214
|
migrationValue: colorValue(input.migrationValue),
|
|
215
|
+
renderer: null,
|
|
183
216
|
renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
|
|
184
217
|
};
|
|
185
218
|
}
|
|
@@ -199,6 +232,7 @@ function convertColorFieldToIR(field, position) {
|
|
|
199
232
|
visibility: field.visibility,
|
|
200
233
|
visibilityCondition: field.visibilityCondition,
|
|
201
234
|
variantEnabled: field.variantEnabled,
|
|
235
|
+
formRenderer: convertFieldRendererToIR(field.renderer),
|
|
202
236
|
initialValue: field.initialValue
|
|
203
237
|
};
|
|
204
238
|
}
|
|
@@ -315,6 +349,7 @@ function dateFieldAttributes(input) {
|
|
|
315
349
|
variantEnabled: input.variantEnabled ?? FIELD_DEFAULTS.variantEnabled,
|
|
316
350
|
initialValue: dateValue(input.initialValue),
|
|
317
351
|
migrationValue: dateValue(input.migrationValue),
|
|
352
|
+
renderer: null,
|
|
318
353
|
renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
|
|
319
354
|
};
|
|
320
355
|
}
|
|
@@ -337,6 +372,7 @@ function convertDateFieldToIR(field, position) {
|
|
|
337
372
|
visibility: field.visibility,
|
|
338
373
|
visibilityCondition: field.visibilityCondition,
|
|
339
374
|
variantEnabled: field.variantEnabled,
|
|
375
|
+
formRenderer: convertFieldRendererToIR(field.renderer),
|
|
340
376
|
initialValue: field.initialValue
|
|
341
377
|
};
|
|
342
378
|
}
|
|
@@ -426,6 +462,7 @@ function json(input) {
|
|
|
426
462
|
variantEnabled: input.variantEnabled ?? FIELD_DEFAULTS.variantEnabled,
|
|
427
463
|
initialValue: jsonValue(input.initialValue),
|
|
428
464
|
migrationValue: jsonValue(input.migrationValue),
|
|
465
|
+
renderer: null,
|
|
429
466
|
renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
|
|
430
467
|
};
|
|
431
468
|
}
|
|
@@ -445,6 +482,7 @@ function convertJsonFieldToIR(field, position) {
|
|
|
445
482
|
visibility: field.visibility,
|
|
446
483
|
visibilityCondition: field.visibilityCondition,
|
|
447
484
|
variantEnabled: field.variantEnabled,
|
|
485
|
+
formRenderer: convertFieldRendererToIR(field.renderer),
|
|
448
486
|
initialValue: field.initialValue
|
|
449
487
|
};
|
|
450
488
|
}
|
|
@@ -479,6 +517,7 @@ function location(input) {
|
|
|
479
517
|
variantEnabled: input.variantEnabled ?? FIELD_DEFAULTS.variantEnabled,
|
|
480
518
|
initialValue: locationValue(input.initialValue),
|
|
481
519
|
migrationValue: locationValue(input.migrationValue),
|
|
520
|
+
renderer: null,
|
|
482
521
|
renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
|
|
483
522
|
};
|
|
484
523
|
}
|
|
@@ -498,6 +537,7 @@ function convertLocationFieldToIR(field, position) {
|
|
|
498
537
|
visibility: field.visibility,
|
|
499
538
|
visibilityCondition: field.visibilityCondition,
|
|
500
539
|
variantEnabled: field.variantEnabled,
|
|
540
|
+
formRenderer: convertFieldRendererToIR(field.renderer),
|
|
501
541
|
initialValue: field.initialValue
|
|
502
542
|
};
|
|
503
543
|
}
|
|
@@ -539,6 +579,7 @@ function numberFieldAttributes(input) {
|
|
|
539
579
|
initialValue: numberValue(input.initialValue),
|
|
540
580
|
migrationValue: numberValue(input.migrationValue),
|
|
541
581
|
validations: numberValidationRules(input.validations),
|
|
582
|
+
renderer: null,
|
|
542
583
|
renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
|
|
543
584
|
};
|
|
544
585
|
}
|
|
@@ -561,6 +602,7 @@ function convertNumberFieldToIR(field, position) {
|
|
|
561
602
|
visibility: field.visibility,
|
|
562
603
|
visibilityCondition: field.visibilityCondition,
|
|
563
604
|
variantEnabled: field.variantEnabled,
|
|
605
|
+
formRenderer: convertFieldRendererToIR(field.renderer),
|
|
564
606
|
initialValue: field.initialValue,
|
|
565
607
|
validations: field.validations
|
|
566
608
|
};
|
|
@@ -602,6 +644,7 @@ function referenceOneWay(input) {
|
|
|
602
644
|
visibility: input.visibility ?? FIELD_DEFAULTS.visibility,
|
|
603
645
|
visibilityCondition: input.visibilityCondition ?? null,
|
|
604
646
|
variantEnabled: input.variantEnabled ?? FIELD_DEFAULTS.variantEnabled,
|
|
647
|
+
renderer: null,
|
|
605
648
|
renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
|
|
606
649
|
};
|
|
607
650
|
}
|
|
@@ -626,7 +669,8 @@ function convertReferenceOneWayFieldToIR(field, position) {
|
|
|
626
669
|
required: false,
|
|
627
670
|
visibility: field.visibility,
|
|
628
671
|
visibilityCondition: field.visibilityCondition,
|
|
629
|
-
variantEnabled: field.variantEnabled
|
|
672
|
+
variantEnabled: field.variantEnabled,
|
|
673
|
+
formRenderer: convertFieldRendererToIR(field.renderer)
|
|
630
674
|
};
|
|
631
675
|
}
|
|
632
676
|
//#endregion
|
|
@@ -656,6 +700,7 @@ function referenceTwoWay(input) {
|
|
|
656
700
|
visibility: input.visibility ?? FIELD_DEFAULTS.visibility,
|
|
657
701
|
visibilityCondition: input.visibilityCondition ?? null,
|
|
658
702
|
variantEnabled: input.variantEnabled ?? FIELD_DEFAULTS.variantEnabled,
|
|
703
|
+
renderer: null,
|
|
659
704
|
renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
|
|
660
705
|
};
|
|
661
706
|
}
|
|
@@ -674,7 +719,8 @@ function convertReferenceTwoWayFieldToIR(field, position) {
|
|
|
674
719
|
required: false,
|
|
675
720
|
visibility: field.visibility,
|
|
676
721
|
visibilityCondition: field.visibilityCondition,
|
|
677
|
-
variantEnabled: field.variantEnabled
|
|
722
|
+
variantEnabled: field.variantEnabled,
|
|
723
|
+
formRenderer: convertFieldRendererToIR(field.renderer)
|
|
678
724
|
};
|
|
679
725
|
}
|
|
680
726
|
//#endregion
|
|
@@ -5051,6 +5097,7 @@ function richText(input) {
|
|
|
5051
5097
|
migrationValue: richTextValue(input.migrationValue),
|
|
5052
5098
|
embeds: input.embeds === void 0 ? null : [...input.embeds],
|
|
5053
5099
|
actions: input.actions === void 0 ? null : [...input.actions],
|
|
5100
|
+
renderer: null,
|
|
5054
5101
|
renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
|
|
5055
5102
|
};
|
|
5056
5103
|
}
|
|
@@ -5074,6 +5121,7 @@ function convertRichTextFieldToIR(field, position) {
|
|
|
5074
5121
|
visibility: field.visibility,
|
|
5075
5122
|
visibilityCondition: field.visibilityCondition,
|
|
5076
5123
|
variantEnabled: field.variantEnabled,
|
|
5124
|
+
formRenderer: convertFieldRendererToIR(field.renderer),
|
|
5077
5125
|
initialValue: field.initialValue,
|
|
5078
5126
|
embeds: field.embeds?.map((model) => model().apiId).toSorted() ?? null,
|
|
5079
5127
|
actions: richTextActions(field.actions)
|
|
@@ -5106,17 +5154,6 @@ function richTextValue(value) {
|
|
|
5106
5154
|
return value === void 0 || isEmptyRichText(value) ? null : value;
|
|
5107
5155
|
}
|
|
5108
5156
|
//#endregion
|
|
5109
|
-
//#region src/define/not-implemented.ts
|
|
5110
|
-
/**
|
|
5111
|
-
* Every builder is declared so the authoring surface is fixed, but none of
|
|
5112
|
-
* them are implemented yet. They throw rather than returning a half-shaped
|
|
5113
|
-
* object: a config that silently produced the wrong schema would be worse
|
|
5114
|
-
* than one that refuses to load.
|
|
5115
|
-
*/
|
|
5116
|
-
function notImplemented(builder) {
|
|
5117
|
-
throw new Error(`${builder} is not implemented yet`);
|
|
5118
|
-
}
|
|
5119
|
-
//#endregion
|
|
5120
5157
|
//#region src/define/fields/string.ts
|
|
5121
5158
|
/**
|
|
5122
5159
|
* The attributes every editor's builder returns, filling in its
|
|
@@ -5142,7 +5179,10 @@ function stringFieldAttributes(input, defaults = FIELD_DEFAULTS) {
|
|
|
5142
5179
|
renamedFrom: isEmpty(input.renamedFrom) ? null : input.renamedFrom
|
|
5143
5180
|
};
|
|
5144
5181
|
}
|
|
5145
|
-
/**
|
|
5182
|
+
/**
|
|
5183
|
+
* The form renderer each of Hygraph's text editors' `__typename` stands
|
|
5184
|
+
* for, in the IR. `StringField` is an app's, `define.field.custom.string`.
|
|
5185
|
+
*/
|
|
5146
5186
|
const FORM_RENDERERS = {
|
|
5147
5187
|
SingleLineField: "GCMS_SINGLE_LINE",
|
|
5148
5188
|
MultilineField: "GCMS_MULTI_LINE",
|
|
@@ -5150,13 +5190,14 @@ const FORM_RENDERERS = {
|
|
|
5150
5190
|
SlugField: "GCMS_SLUG"
|
|
5151
5191
|
};
|
|
5152
5192
|
/**
|
|
5153
|
-
* The IR names the form renderer, which the config says by `__typename
|
|
5154
|
-
* `renamedFrom` and `migrationValue` are intent, not
|
|
5193
|
+
* The IR names the form renderer, which the config says by `__typename`,
|
|
5194
|
+
* or the app's element. `renamedFrom` and `migrationValue` are intent, not
|
|
5195
|
+
* schema, and stay out.
|
|
5155
5196
|
*/
|
|
5156
5197
|
function convertStringFieldToIR(field, position) {
|
|
5157
5198
|
return {
|
|
5158
5199
|
kind: "string",
|
|
5159
|
-
formRenderer: FORM_RENDERERS[field.__typename],
|
|
5200
|
+
formRenderer: field.__typename === "StringField" ? convertAppRendererToIR(field.renderer) : FORM_RENDERERS[field.__typename],
|
|
5160
5201
|
apiId: field.apiId,
|
|
5161
5202
|
displayName: field.displayName,
|
|
5162
5203
|
description: field.description,
|
|
@@ -5183,10 +5224,6 @@ function textValue(value) {
|
|
|
5183
5224
|
if (value === void 0 || value === "") return null;
|
|
5184
5225
|
return Array.isArray(value) && value.length === 0 ? null : value;
|
|
5185
5226
|
}
|
|
5186
|
-
/** Text rendered by an installed app's element. `renderer` is required. */
|
|
5187
|
-
function string(_options) {
|
|
5188
|
-
return notImplemented("define.field.string");
|
|
5189
|
-
}
|
|
5190
5227
|
/** The validations with every default filled in, `null` when there are none. */
|
|
5191
5228
|
function stringValidationRules(input) {
|
|
5192
5229
|
if (input === void 0) return null;
|
|
@@ -5352,7 +5389,8 @@ function convertTypeToIR(field, position) {
|
|
|
5352
5389
|
case "SingleLineField":
|
|
5353
5390
|
case "MultilineField":
|
|
5354
5391
|
case "MarkdownField":
|
|
5355
|
-
case "SlugField":
|
|
5392
|
+
case "SlugField":
|
|
5393
|
+
case "StringField": return convertStringFieldToIR(field, position);
|
|
5356
5394
|
case "UnsupportedField": return convertUnsupportedFieldToIR(field, position);
|
|
5357
5395
|
}
|
|
5358
5396
|
}
|
|
@@ -5736,6 +5774,73 @@ function int(input) {
|
|
|
5736
5774
|
};
|
|
5737
5775
|
}
|
|
5738
5776
|
//#endregion
|
|
5777
|
+
//#region src/define/fields/custom.ts
|
|
5778
|
+
/**
|
|
5779
|
+
* Fields whose editor in Studio is an installed app's element, in place of
|
|
5780
|
+
* Hygraph's own. Each builder takes what its type's builder takes, and the
|
|
5781
|
+
* element as `renderer`. Install the app in the environment in Studio;
|
|
5782
|
+
* the element must be made for the field's type.
|
|
5783
|
+
*
|
|
5784
|
+
* @example define.field.custom.int({ apiId: "rating", displayName: "Rating", renderer: { app: { appApiId: "stars", appElementApiId: "stars", config: { max: 5 } } } })
|
|
5785
|
+
*/
|
|
5786
|
+
const custom = {
|
|
5787
|
+
/** Text. Takes what `singleLine` takes. */
|
|
5788
|
+
string: (input) => ({
|
|
5789
|
+
__typename: "StringField",
|
|
5790
|
+
...stringFieldAttributes(input),
|
|
5791
|
+
renderer: appRenderer(input.renderer)
|
|
5792
|
+
}),
|
|
5793
|
+
int: (input) => ({
|
|
5794
|
+
...int(input),
|
|
5795
|
+
renderer: appRenderer(input.renderer)
|
|
5796
|
+
}),
|
|
5797
|
+
float: (input) => ({
|
|
5798
|
+
...float(input),
|
|
5799
|
+
renderer: appRenderer(input.renderer)
|
|
5800
|
+
}),
|
|
5801
|
+
boolean: (input) => ({
|
|
5802
|
+
...boolean(input),
|
|
5803
|
+
renderer: appRenderer(input.renderer)
|
|
5804
|
+
}),
|
|
5805
|
+
date: (input) => ({
|
|
5806
|
+
...date(input),
|
|
5807
|
+
renderer: appRenderer(input.renderer)
|
|
5808
|
+
}),
|
|
5809
|
+
dateTime: (input) => ({
|
|
5810
|
+
...dateTime(input),
|
|
5811
|
+
renderer: appRenderer(input.renderer)
|
|
5812
|
+
}),
|
|
5813
|
+
json: (input) => ({
|
|
5814
|
+
...json(input),
|
|
5815
|
+
renderer: appRenderer(input.renderer)
|
|
5816
|
+
}),
|
|
5817
|
+
color: (input) => ({
|
|
5818
|
+
...color(input),
|
|
5819
|
+
renderer: appRenderer(input.renderer)
|
|
5820
|
+
}),
|
|
5821
|
+
location: (input) => ({
|
|
5822
|
+
...location(input),
|
|
5823
|
+
renderer: appRenderer(input.renderer)
|
|
5824
|
+
}),
|
|
5825
|
+
/** Rich text without `actions`: the element replaces the toolbar. */
|
|
5826
|
+
richText: (input) => ({
|
|
5827
|
+
...richText(input),
|
|
5828
|
+
renderer: appRenderer(input.renderer)
|
|
5829
|
+
}),
|
|
5830
|
+
referenceOneWay: (input) => ({
|
|
5831
|
+
...referenceOneWay(input),
|
|
5832
|
+
renderer: appRenderer(input.renderer)
|
|
5833
|
+
}),
|
|
5834
|
+
referenceTwoWay: (input) => ({
|
|
5835
|
+
...referenceTwoWay(input),
|
|
5836
|
+
renderer: appRenderer(input.renderer)
|
|
5837
|
+
}),
|
|
5838
|
+
asset: (input) => ({
|
|
5839
|
+
...asset$1(input),
|
|
5840
|
+
renderer: appRenderer(input.renderer)
|
|
5841
|
+
})
|
|
5842
|
+
};
|
|
5843
|
+
//#endregion
|
|
5739
5844
|
//#region src/define/fields/markdown.ts
|
|
5740
5845
|
/**
|
|
5741
5846
|
* Text written in Markdown. Studio's Markdown editor. Same options and
|
|
@@ -5797,6 +5902,17 @@ function slug(input) {
|
|
|
5797
5902
|
};
|
|
5798
5903
|
}
|
|
5799
5904
|
//#endregion
|
|
5905
|
+
//#region src/define/not-implemented.ts
|
|
5906
|
+
/**
|
|
5907
|
+
* Every builder is declared so the authoring surface is fixed, but none of
|
|
5908
|
+
* them are implemented yet. They throw rather than returning a half-shaped
|
|
5909
|
+
* object: a config that silently produced the wrong schema would be worse
|
|
5910
|
+
* than one that refuses to load.
|
|
5911
|
+
*/
|
|
5912
|
+
function notImplemented(builder) {
|
|
5913
|
+
throw new Error(`${builder} is not implemented yet`);
|
|
5914
|
+
}
|
|
5915
|
+
//#endregion
|
|
5800
5916
|
//#region src/define/fields/vector.ts
|
|
5801
5917
|
/** An embedding. `dimension` is required (1 to 3072); `index` is refused above 2000. */
|
|
5802
5918
|
function vector(_options) {
|
|
@@ -5811,6 +5927,7 @@ var fields_exports = /* @__PURE__ */ __exportAll({
|
|
|
5811
5927
|
color: () => color,
|
|
5812
5928
|
component: () => component$1,
|
|
5813
5929
|
componentUnion: () => componentUnion,
|
|
5930
|
+
custom: () => custom,
|
|
5814
5931
|
date: () => date,
|
|
5815
5932
|
dateTime: () => dateTime,
|
|
5816
5933
|
enumeration: () => enumeration$1,
|
|
@@ -5828,7 +5945,6 @@ var fields_exports = /* @__PURE__ */ __exportAll({
|
|
|
5828
5945
|
richText: () => richText,
|
|
5829
5946
|
singleLine: () => singleLine,
|
|
5830
5947
|
slug: () => slug,
|
|
5831
|
-
string: () => string,
|
|
5832
5948
|
taxonomy: () => taxonomy$1,
|
|
5833
5949
|
unsupported: () => unsupported,
|
|
5834
5950
|
vector: () => vector
|
package/dist/version.js
CHANGED