@hygraph/cli 0.0.18 → 0.0.20
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/CHANGELOG.md +18 -0
- package/README.md +60 -4
- package/dist/cli.js +460 -106
- package/dist/define.d.ts +10 -15
- package/dist/define2.js +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @hygraph/cli
|
|
2
2
|
|
|
3
|
+
## 0.0.20
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ecd2855: On a terminal, `export` asks before it replaces a config file that is already there, and writes nothing when you answer no. In CI, or when stdin is not a terminal, `export --out` replaces the file without a question, as before.
|
|
8
|
+
- fea7184: `export` now asks for the target's name as "Name for this environment in the config (used with --target)", and the `--name` help says the same. The new Targets section of the README says what a target is and how `--target` selects one.
|
|
9
|
+
- 2587a4e: When live differs from the config, `pull` now ends with the next steps: give the diff to a coding agent, or run `hygraph export --out <config>` to replace the config with the live schema. `pull --help` and the README show how to save the diff with `hygraph pull > drift.diff`.
|
|
10
|
+
|
|
11
|
+
## 0.0.19
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 511852f: Error reports now say more about a failed migration, an apply that left changes behind, and a Hygraph server error. The Telemetry section of the README lists what they hold.
|
|
16
|
+
- 6793077: A remote field can be renamed with `renamedFrom`, as other fields are.
|
|
17
|
+
- b1a7377: The usage event now counts the fields the CLI cannot read yet, by type and reason, and the models with a sidebar panel it cannot read. It sends no apiIds.
|
|
18
|
+
- 8acaeb4: Rich text `embeds` takes `system.model.asset`, so a field that embeds assets is planned, applied and exported like the others.
|
|
19
|
+
- 5cdab20: `apply --prune` now deletes stages, with the entries in them. Before, `plan` refused a stage delete.
|
|
20
|
+
|
|
3
21
|
## 0.0.18
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -86,6 +86,30 @@ npx hygraph plan
|
|
|
86
86
|
|
|
87
87
|
Commit `hygraph.config.ts`. From here on it is the source of your schema.
|
|
88
88
|
|
|
89
|
+
## Targets
|
|
90
|
+
|
|
91
|
+
A target is one environment of one project that the config manages. The
|
|
92
|
+
config exports one target, or a list of targets:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
const kaffa = define.target({ name: "kaffa" /* … */ });
|
|
96
|
+
const sencha = define.target({ name: "sencha" /* … */ });
|
|
97
|
+
|
|
98
|
+
export default [kaffa, sencha];
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Each target has a `name`. `--name` sets it on `export`. Without the flag,
|
|
102
|
+
`export` asks for it in a terminal, with the environment as the default, and
|
|
103
|
+
uses the environment elsewhere. Two targets cannot have the same name or the
|
|
104
|
+
same environment of the same project.
|
|
105
|
+
|
|
106
|
+
`plan`, `apply`, `pull` and `whoami` use every target in the config. To use
|
|
107
|
+
only one, give its name with `--target`. Repeat the flag to select more:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npx hygraph plan --target kaffa
|
|
111
|
+
```
|
|
112
|
+
|
|
89
113
|
## Make a change
|
|
90
114
|
|
|
91
115
|
Edit the config. To add a field to a model you already have, add it to the
|
|
@@ -160,6 +184,30 @@ project, so the plan alone does not let anyone test a guessed value.
|
|
|
160
184
|
`apply` refuses the saved plan when one of these values changed after
|
|
161
185
|
`plan`, or when the project's key changed. Run `plan` again in that case.
|
|
162
186
|
|
|
187
|
+
## Bring live changes into your config
|
|
188
|
+
|
|
189
|
+
When someone changes the schema in Studio, the config no longer matches the
|
|
190
|
+
project. `pull` shows what changed live, as a diff against the config:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
npx hygraph pull
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
To save the diff to a file, redirect it. The file holds the diff only, without
|
|
197
|
+
colours:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
npx hygraph pull > drift.diff
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Then bring the changes into the config in one of two ways:
|
|
204
|
+
|
|
205
|
+
- **Give the diff to a coding agent.** It edits your config in place. For
|
|
206
|
+
example, ask it: "Bring the live changes in drift.diff into
|
|
207
|
+
hygraph.config.ts, then run `npx hygraph plan` until it shows no changes."
|
|
208
|
+
- **Export again.** `npx hygraph export --out hygraph.config.ts` replaces the
|
|
209
|
+
config with the live schema. Your own edits to the file are lost.
|
|
210
|
+
|
|
163
211
|
## What's supported
|
|
164
212
|
|
|
165
213
|
- **Schema:** models, components, enumerations, taxonomies, locales and
|
|
@@ -193,12 +241,20 @@ The CLI reports errors and usage to Hygraph, so that we can fix bugs and
|
|
|
193
241
|
see which commands people use. It tells you so the first time it runs.
|
|
194
242
|
|
|
195
243
|
- **Errors:** a crash, with its error type and stack trace but not its
|
|
196
|
-
message, and a migration that failed, with its id
|
|
197
|
-
gave for it
|
|
244
|
+
message, and a migration that failed, with its id, the error Hygraph
|
|
245
|
+
gave for it and the kinds of its changes with their counts, such as
|
|
246
|
+
`createModel: 2`. That error can name models and fields. An apply that
|
|
247
|
+
worked, but left changes in the plan, is reported with the same kinds
|
|
248
|
+
and counts, and with the names of the attributes that still differ,
|
|
249
|
+
such as `field.position`. If a check refuses the plan after it, the code of the check
|
|
250
|
+
is reported. An answer of Hygraph that is a server error is reported
|
|
251
|
+
with its operation name, status, error codes and request ids, not its
|
|
252
|
+
message.
|
|
198
253
|
- **Usage:** one event per command: the command, the names of the flags you
|
|
199
254
|
gave, how long it took, whether it worked, the codes of the checks that
|
|
200
|
-
refused a plan,
|
|
201
|
-
|
|
255
|
+
refused a plan, how many fields of each type the CLI could not read and
|
|
256
|
+
why, how many models have a sidebar panel it could not read, and the
|
|
257
|
+
project id, environment and endpoint host of each target.
|
|
202
258
|
|
|
203
259
|
To turn it off, set `HYGRAPH_TELEMETRY=0` or `DO_NOT_TRACK=1`.
|
|
204
260
|
|
package/dist/cli.js
CHANGED
|
@@ -3103,6 +3103,96 @@ var Failure = class extends Error {
|
|
|
3103
3103
|
}
|
|
3104
3104
|
};
|
|
3105
3105
|
//#endregion
|
|
3106
|
+
//#region src/telemetry/record.ts
|
|
3107
|
+
/** Counts the batch entries by their key. Leaves out what they hold. */
|
|
3108
|
+
function changeKinds(changes) {
|
|
3109
|
+
const kinds = {};
|
|
3110
|
+
for (const kind of changes.flatMap((change) => Object.keys(change))) kinds[kind] = (kinds[kind] ?? 0) + 1;
|
|
3111
|
+
return kinds;
|
|
3112
|
+
}
|
|
3113
|
+
/**
|
|
3114
|
+
* Counts the attributes that the updates change, by resource and name, such
|
|
3115
|
+
* as `{ "field.position": 2 }`. Leaves out their values.
|
|
3116
|
+
*/
|
|
3117
|
+
function changedAttributes(changes) {
|
|
3118
|
+
const attributes = {};
|
|
3119
|
+
for (const change of changes) {
|
|
3120
|
+
if (change.action !== "update") continue;
|
|
3121
|
+
for (const name of Object.keys(change.changes)) {
|
|
3122
|
+
const key = `${change.resource}.${name}`;
|
|
3123
|
+
attributes[key] = (attributes[key] ?? 0) + 1;
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
return attributes;
|
|
3127
|
+
}
|
|
3128
|
+
let current;
|
|
3129
|
+
/** Until this is called, and after `stopRun`, the record calls do nothing. */
|
|
3130
|
+
function startRun() {
|
|
3131
|
+
current = {
|
|
3132
|
+
targets: [],
|
|
3133
|
+
changes: void 0,
|
|
3134
|
+
codes: [],
|
|
3135
|
+
failures: [],
|
|
3136
|
+
cancelled: false,
|
|
3137
|
+
failedMigrations: [],
|
|
3138
|
+
unconverged: [],
|
|
3139
|
+
serverFaults: [],
|
|
3140
|
+
unsupported: /* @__PURE__ */ new Map()
|
|
3141
|
+
};
|
|
3142
|
+
return current;
|
|
3143
|
+
}
|
|
3144
|
+
function stopRun() {
|
|
3145
|
+
current = void 0;
|
|
3146
|
+
}
|
|
3147
|
+
function isRecording() {
|
|
3148
|
+
return current !== void 0;
|
|
3149
|
+
}
|
|
3150
|
+
/** Runs `task` with the record calls turned off. */
|
|
3151
|
+
async function unrecorded(task) {
|
|
3152
|
+
const run = current;
|
|
3153
|
+
current = void 0;
|
|
3154
|
+
try {
|
|
3155
|
+
return await task();
|
|
3156
|
+
} finally {
|
|
3157
|
+
current = run;
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3160
|
+
function recordTargets(targets) {
|
|
3161
|
+
current?.targets.push(...targets);
|
|
3162
|
+
}
|
|
3163
|
+
function recordChanges(count) {
|
|
3164
|
+
if (current !== void 0) current.changes = (current.changes ?? 0) + count;
|
|
3165
|
+
}
|
|
3166
|
+
function recordRefusals(validations) {
|
|
3167
|
+
current?.codes.push(...validations.map(({ code }) => code));
|
|
3168
|
+
}
|
|
3169
|
+
/** Records a `Failure`; a crash is reported on its own when the run ends. */
|
|
3170
|
+
function recordFailure(error) {
|
|
3171
|
+
if (error instanceof Failure) current?.failures.push(error.name);
|
|
3172
|
+
}
|
|
3173
|
+
function recordCancelled() {
|
|
3174
|
+
if (current !== void 0) current.cancelled = true;
|
|
3175
|
+
}
|
|
3176
|
+
/** A submitted migration that did not end in SUCCESS, or whose end is unknown. */
|
|
3177
|
+
function recordFailedMigration(target, id, migration, changes = {}) {
|
|
3178
|
+
current?.failedMigrations.push({
|
|
3179
|
+
target,
|
|
3180
|
+
id,
|
|
3181
|
+
migration,
|
|
3182
|
+
changes
|
|
3183
|
+
});
|
|
3184
|
+
}
|
|
3185
|
+
function recordUnconverged(unconverged) {
|
|
3186
|
+
current?.unconverged.push(unconverged);
|
|
3187
|
+
}
|
|
3188
|
+
function recordServerFault(fault) {
|
|
3189
|
+
current?.serverFaults.push(fault);
|
|
3190
|
+
}
|
|
3191
|
+
/** A later read of the same target replaces the earlier one. */
|
|
3192
|
+
function recordUnsupported(target, unsupported) {
|
|
3193
|
+
current?.unsupported.set(target.name, unsupported);
|
|
3194
|
+
}
|
|
3195
|
+
//#endregion
|
|
3106
3196
|
//#region src/utils/pause.ts
|
|
3107
3197
|
/** Resolves after `ms` milliseconds. Uses the global `setTimeout`, which fake timers replace. */
|
|
3108
3198
|
function pause(ms) {
|
|
@@ -3143,6 +3233,19 @@ function isTransient(error) {
|
|
|
3143
3233
|
if (error instanceof ManagementApiError) return TRANSIENT_STATUSES.has(error.status);
|
|
3144
3234
|
return error instanceof TypeError && (error.message === "fetch failed" || error.message === "terminated") && !TIMEOUT_CODES.has(causeCode(error));
|
|
3145
3235
|
}
|
|
3236
|
+
/** How the server starts the message of an error it did not expect. */
|
|
3237
|
+
const UNEXPECTED_ERROR_MESSAGE = "Something went wrong (RequestID:";
|
|
3238
|
+
/**
|
|
3239
|
+
* A 5xx status, or an error the server did not expect. The server answers
|
|
3240
|
+
* the second with status 200 and the code INTERNAL_SERVER_ERROR. A refusal
|
|
3241
|
+
* with no code of its own has this code too, so the message decides.
|
|
3242
|
+
*/
|
|
3243
|
+
function isServerFault(error) {
|
|
3244
|
+
return error instanceof ManagementApiError && (error.status >= 500 || error.errors.some(({ message, extensions }) => extensions?.code === "INTERNAL_SERVER_ERROR" && message.startsWith(UNEXPECTED_ERROR_MESSAGE)));
|
|
3245
|
+
}
|
|
3246
|
+
function strings(values) {
|
|
3247
|
+
return values.filter((value) => typeof value === "string");
|
|
3248
|
+
}
|
|
3146
3249
|
function causeCode(error) {
|
|
3147
3250
|
return error.cause instanceof Error && "code" in error.cause ? error.cause.code : void 0;
|
|
3148
3251
|
}
|
|
@@ -3152,7 +3255,8 @@ function causeCode(error) {
|
|
|
3152
3255
|
*
|
|
3153
3256
|
* A request that fails on the way, or that a load balancer or a restarting
|
|
3154
3257
|
* server turns away (429, 502, 503, 504), is sent again, up to three attempts
|
|
3155
|
-
* in all. A request that timed out is not sent again. A
|
|
3258
|
+
* in all. A request that timed out is not sent again. A fault of the server
|
|
3259
|
+
* that ends the attempts goes to telemetry. A mutation is sent again too: the caller makes it safe to repeat.
|
|
3156
3260
|
*/
|
|
3157
3261
|
function createManagementClient({ endpoint, token, fetch = globalThis.fetch, sleep = pause }) {
|
|
3158
3262
|
async function send(query, variables) {
|
|
@@ -3177,11 +3281,25 @@ function createManagementClient({ endpoint, token, fetch = globalThis.fetch, sle
|
|
|
3177
3281
|
for (let attempt = 1;; attempt++) try {
|
|
3178
3282
|
return await send(document.toString(), variables);
|
|
3179
3283
|
} catch (error) {
|
|
3180
|
-
if (attempt === MAX_ATTEMPTS || !isTransient(error))
|
|
3284
|
+
if (attempt === MAX_ATTEMPTS || !isTransient(error)) {
|
|
3285
|
+
if (isServerFault(error)) recordServerFault({
|
|
3286
|
+
endpoint,
|
|
3287
|
+
operation: /\b(?:query|mutation)\s+(\w+)/.exec(document.toString())?.[1] ?? "unknown",
|
|
3288
|
+
status: error.status,
|
|
3289
|
+
codes: strings(error.errors.map(({ extensions }) => extensions?.code)),
|
|
3290
|
+
requestIds: requestIdsOf(error.errors)
|
|
3291
|
+
});
|
|
3292
|
+
throw error;
|
|
3293
|
+
}
|
|
3181
3294
|
await sleep(backoff(attempt));
|
|
3182
3295
|
}
|
|
3183
3296
|
} };
|
|
3184
3297
|
}
|
|
3298
|
+
/** The ids from the extensions and from the message of an unexpected error. */
|
|
3299
|
+
function requestIdsOf(errors) {
|
|
3300
|
+
const ids = errors.flatMap(({ message, extensions }) => [extensions?.requestID, /^Something went wrong \(RequestID: ([\w-]+)\)/.exec(message)?.[1]]);
|
|
3301
|
+
return [...new Set(strings(ids))];
|
|
3302
|
+
}
|
|
3185
3303
|
function parseBody(text) {
|
|
3186
3304
|
try {
|
|
3187
3305
|
return JSON.parse(text);
|
|
@@ -15437,8 +15555,7 @@ const createRichTextFieldSchema = object$1({
|
|
|
15437
15555
|
* field from the config, position as Hygraph stores it. `null` for one the
|
|
15438
15556
|
* CLI cannot express yet, which is read as an unsupported field: an app's
|
|
15439
15557
|
* editor it cannot read, another editor than Studio's, an embedded model
|
|
15440
|
-
* that is not one of `models
|
|
15441
|
-
* not offer. The setup is looked at first, so such a field is never checked
|
|
15558
|
+
* that is not one of `models`, or an action Studio does not offer. The setup is looked at first, so such a field is never checked
|
|
15442
15559
|
* and cannot stop the plan. An app's element replaces the toolbar, so the
|
|
15443
15560
|
* field has no actions; what `formConfig` holds besides the app's apiIds is
|
|
15444
15561
|
* the element's settings.
|
|
@@ -15924,6 +16041,109 @@ function findUnsupportedUnions(ops, environment, unions = NO_UNION_LOOKUP) {
|
|
|
15924
16041
|
}];
|
|
15925
16042
|
});
|
|
15926
16043
|
}
|
|
16044
|
+
/** The simple types `convertCreateSimpleFieldToIR` has a resource for. */
|
|
16045
|
+
const SIMPLE_TYPES = /* @__PURE__ */ new Set([
|
|
16046
|
+
"BOOLEAN",
|
|
16047
|
+
"STRING",
|
|
16048
|
+
"DATE",
|
|
16049
|
+
"DATETIME",
|
|
16050
|
+
"INT",
|
|
16051
|
+
"FLOAT",
|
|
16052
|
+
"JSON",
|
|
16053
|
+
"COLOR",
|
|
16054
|
+
"LOCATION",
|
|
16055
|
+
"RICHTEXT"
|
|
16056
|
+
]);
|
|
16057
|
+
/**
|
|
16058
|
+
* Every field `environment` holds as unsupported, by its type and why, for
|
|
16059
|
+
* the usage event. Both sides of a two-way relation count. A union counts
|
|
16060
|
+
* once: its members do not. `setup` is any other reason. A field gets the
|
|
16061
|
+
* first reason its converter refuses it for, so a field with two blockers
|
|
16062
|
+
* stays unsupported when only the reported one is fixed.
|
|
16063
|
+
*/
|
|
16064
|
+
function reportUnsupportedFields(ops, environment, partners) {
|
|
16065
|
+
const parents = new Map([
|
|
16066
|
+
environment.segment,
|
|
16067
|
+
...environment.models,
|
|
16068
|
+
...environment.components,
|
|
16069
|
+
environment.asset,
|
|
16070
|
+
environment.query
|
|
16071
|
+
].flatMap((parent) => parent ? [[parent.apiId, parent]] : []));
|
|
16072
|
+
const unsupported = (parent, apiId) => {
|
|
16073
|
+
const field = parents.get(parent)?.fields[apiId];
|
|
16074
|
+
return field?.kind === "unsupported" ? field : void 0;
|
|
16075
|
+
};
|
|
16076
|
+
const models = new Set(environment.models.map(({ apiId }) => apiId));
|
|
16077
|
+
const embeddable = /* @__PURE__ */ new Set([...models, "Asset"]);
|
|
16078
|
+
const components = new Set(environment.components.map(({ apiId }) => apiId));
|
|
16079
|
+
return ops.flatMap((op) => {
|
|
16080
|
+
const [operation] = Object.keys(op);
|
|
16081
|
+
const input = op[operation ?? ""];
|
|
16082
|
+
const slot = createUnsupportedFieldSchema.safeParse(input);
|
|
16083
|
+
if (!slot.success) return [];
|
|
16084
|
+
const field = unsupported(slot.data.parentApiId, slot.data.apiId);
|
|
16085
|
+
switch (operation) {
|
|
16086
|
+
case "createSimpleField": return field ? [{
|
|
16087
|
+
type: field.type,
|
|
16088
|
+
reason: simpleFieldReason(input, embeddable)
|
|
16089
|
+
}] : [];
|
|
16090
|
+
case "createEnumerableField": return field ? [{
|
|
16091
|
+
type: field.type,
|
|
16092
|
+
reason: "editor"
|
|
16093
|
+
}] : [];
|
|
16094
|
+
case "createRelationalField": {
|
|
16095
|
+
const relation = createRelationalFieldSchema.safeParse(input);
|
|
16096
|
+
if (!relation.success) return [];
|
|
16097
|
+
const { reverseField } = relation.data;
|
|
16098
|
+
const reason = relationReason(input, partners.get(`${reverseField.modelApiId}.${reverseField.apiId}`), models, components);
|
|
16099
|
+
return [field, reverseField.isUnidirectional ? void 0 : unsupported(reverseField.modelApiId, reverseField.apiId)].flatMap((side) => side ? [{
|
|
16100
|
+
type: side.type,
|
|
16101
|
+
reason
|
|
16102
|
+
}] : []);
|
|
16103
|
+
}
|
|
16104
|
+
case "createUnionField": return field ? [{
|
|
16105
|
+
type: field.type,
|
|
16106
|
+
reason: unionReason(input, models, components)
|
|
16107
|
+
}] : [];
|
|
16108
|
+
default: return [];
|
|
16109
|
+
}
|
|
16110
|
+
});
|
|
16111
|
+
}
|
|
16112
|
+
function simpleFieldReason(input, embeddable) {
|
|
16113
|
+
const type = input.type;
|
|
16114
|
+
if (typeof type === "string" && !SIMPLE_TYPES.has(type)) return "type";
|
|
16115
|
+
return type === "RICHTEXT" ? richTextReason(input, embeddable) : "editor";
|
|
16116
|
+
}
|
|
16117
|
+
/** The checks of `convertCreateRichTextFieldToIR`, in its order. */
|
|
16118
|
+
function richTextReason(input, embeddable) {
|
|
16119
|
+
if (!convertRendererToIR(input).supported) return "editor";
|
|
16120
|
+
const { formRenderer, formConfig, embedsEnabled, embeddableModels } = input;
|
|
16121
|
+
if (formRenderer !== "CUSTOM" && (typeof formRenderer === "string" && !isEmpty(formRenderer) && formRenderer !== "GCMS" || typeof formConfig?.appApiId === "string" && !isEmpty(formConfig.appApiId))) return "editor";
|
|
16122
|
+
const embedded = Array.isArray(embeddableModels) ? embeddableModels : [];
|
|
16123
|
+
return embedsEnabled === true && (embedded.length === 0 || !embedded.every((apiId) => embeddable.has(apiId))) ? "embeds" : "setup";
|
|
16124
|
+
}
|
|
16125
|
+
function relationReason(input, partner, models, components) {
|
|
16126
|
+
const parsed = referenceSetupSchema.safeParse(input);
|
|
16127
|
+
const parent = createUnsupportedFieldSchema.safeParse(input);
|
|
16128
|
+
if (!parsed.success || !parent.success) return "setup";
|
|
16129
|
+
const { type, isRequired, relationalFieldRules, reverseField } = parsed.data;
|
|
16130
|
+
const { parentApiId } = parent.data;
|
|
16131
|
+
if (type === "ASSET") {
|
|
16132
|
+
if ((relationalFieldRules ?? null) !== null) return "rules";
|
|
16133
|
+
if (!convertRendererToIR(input).supported) return "editor";
|
|
16134
|
+
return reverseField.isUnidirectional === true && !components.has(parentApiId) ? "one_way" : "setup";
|
|
16135
|
+
}
|
|
16136
|
+
if (isRequired === true) return "required";
|
|
16137
|
+
if (!models.has(reverseField.modelApiId)) return "system_model";
|
|
16138
|
+
if (reverseField.isUnidirectional !== true && !models.has(parentApiId)) return components.has(parentApiId) ? "component" : "system_model";
|
|
16139
|
+
return convertRendererToIR(input).supported && convertRendererToIR(partner ?? {}).supported ? "setup" : "editor";
|
|
16140
|
+
}
|
|
16141
|
+
function unionReason(input, models, components) {
|
|
16142
|
+
const parsed = createUnionFieldSchema.safeParse(input);
|
|
16143
|
+
if (!parsed.success) return "setup";
|
|
16144
|
+
const { parentApiId, reverseField } = parsed.data;
|
|
16145
|
+
return !models.has(parentApiId) && !components.has(parentApiId) || !reverseField.positions.every(({ modelApiId }) => models.has(modelApiId)) ? "system_model" : "setup";
|
|
16146
|
+
}
|
|
15927
16147
|
/**
|
|
15928
16148
|
* The union's field, and its other side on each member model, under the
|
|
15929
16149
|
* apiId `unions` finds it by. A union on one of `components` has hidden
|
|
@@ -16028,12 +16248,13 @@ function convertSchemaDefinitionToIR(ops, partners = /* @__PURE__ */ new Map(),
|
|
|
16028
16248
|
[query.apiId, query]
|
|
16029
16249
|
]);
|
|
16030
16250
|
const modelApiIds = new Set(models.map((model) => model.apiId));
|
|
16251
|
+
const embeddable = /* @__PURE__ */ new Set([...modelApiIds, asset.apiId]);
|
|
16031
16252
|
const componentApiIds = new Set(components.map((component) => component.apiId));
|
|
16032
16253
|
for (const op of ops) {
|
|
16033
16254
|
const [operationName] = Object.keys(op);
|
|
16034
16255
|
switch (operationName) {
|
|
16035
16256
|
case "createSimpleField":
|
|
16036
|
-
addField(parents, convertCreateSimpleFieldToIR(op.createSimpleField,
|
|
16257
|
+
addField(parents, convertCreateSimpleFieldToIR(op.createSimpleField, embeddable));
|
|
16037
16258
|
break;
|
|
16038
16259
|
case "createComponentField":
|
|
16039
16260
|
addField(parents, convertCreateComponentFieldToIR(op.createComponentField));
|
|
@@ -16164,8 +16385,7 @@ function convertSidebarToIR(model, elements) {
|
|
|
16164
16385
|
}
|
|
16165
16386
|
/**
|
|
16166
16387
|
* Whether the model has a panel the CLI cannot read: one of a legacy UI
|
|
16167
|
-
* extension
|
|
16168
|
-
* in the positions of the others.
|
|
16388
|
+
* extension. Hygraph counts it in the positions of the others.
|
|
16169
16389
|
*/
|
|
16170
16390
|
function hasUnsupportedSidebarElement(elements) {
|
|
16171
16391
|
return !elements.every(isSupported);
|
|
@@ -16278,7 +16498,8 @@ var LiveSchemaFailure = class extends Failure {};
|
|
|
16278
16498
|
* two-way relation's other side without its rules and condition, and a
|
|
16279
16499
|
* union's members with the first one's settings, so they come from its
|
|
16280
16500
|
* `models`, as every model's sidebar does. Whether Segment exists comes
|
|
16281
|
-
* from its system models. The project's hash key comes with it.
|
|
16501
|
+
* from its system models. The project's hash key comes with it. The
|
|
16502
|
+
* fields and panels it cannot read go to the usage event.
|
|
16282
16503
|
*/
|
|
16283
16504
|
async function readLiveEnvironment(target, fetch) {
|
|
16284
16505
|
if (isEmpty(target.token)) throw new LiveSchemaFailure(`target "${target.name}" has no token. An exported config reads it from HYGRAPH_TOKEN.`);
|
|
@@ -16295,10 +16516,30 @@ async function readLiveEnvironment(target, fetch) {
|
|
|
16295
16516
|
}
|
|
16296
16517
|
const { environment } = extractProject(result.viewer, target);
|
|
16297
16518
|
const unions = unionLookup(environment.contentModel.models);
|
|
16298
|
-
const
|
|
16519
|
+
const partners = partnerLookup(environment.contentModel.models);
|
|
16520
|
+
const { segment, ...live } = convertSchemaDefinitionToIR(environment.schemaDefinition, partners, unions);
|
|
16299
16521
|
const hasSegment = environment.contentModel.systemModels.some((model) => model.__typename === "SegmentModel");
|
|
16300
16522
|
const components = new Set(environment.contentModel.components.map(({ apiId }) => apiId));
|
|
16301
16523
|
const sidebars = new Map(environment.contentModel.models.map((model) => [model.apiId, convertSidebarToIR(model.apiId, model.sidebarElements)]));
|
|
16524
|
+
const ir = {
|
|
16525
|
+
locales: convertLocalesToIR(environment.contentModel.locales),
|
|
16526
|
+
stages: convertStagesToIR(environment.contentModel.stages),
|
|
16527
|
+
...live,
|
|
16528
|
+
models: live.models.map((model) => ({
|
|
16529
|
+
...model,
|
|
16530
|
+
sidebar: sidebars.get(model.apiId) ?? []
|
|
16531
|
+
})),
|
|
16532
|
+
...hasSegment && { segment: segment ?? {
|
|
16533
|
+
apiId: "Segment",
|
|
16534
|
+
fields: {}
|
|
16535
|
+
} },
|
|
16536
|
+
components: live.components.filter(({ apiId }) => components.has(apiId))
|
|
16537
|
+
};
|
|
16538
|
+
const modelsWithUnsupportedSidebarElements = environment.contentModel.models.filter((model) => hasUnsupportedSidebarElement(model.sidebarElements)).map(({ apiId }) => apiId);
|
|
16539
|
+
recordUnsupported(target, {
|
|
16540
|
+
fields: reportUnsupportedFields(environment.schemaDefinition, ir, partners),
|
|
16541
|
+
modelsWithUnsupportedSidebar: modelsWithUnsupportedSidebarElements.length
|
|
16542
|
+
});
|
|
16302
16543
|
return {
|
|
16303
16544
|
environmentId: environment.id,
|
|
16304
16545
|
hashKey: {
|
|
@@ -16321,21 +16562,8 @@ async function readLiveEnvironment(target, fetch) {
|
|
|
16321
16562
|
return Object.keys(titles).length > 0 ? [[model.apiId, titles]] : [];
|
|
16322
16563
|
})),
|
|
16323
16564
|
newModelSidebar: newModelSidebar(environment.contentModel.taxonomies.some(({ apiId }) => apiId === "EntryTag")),
|
|
16324
|
-
modelsWithUnsupportedSidebarElements
|
|
16325
|
-
environment:
|
|
16326
|
-
locales: convertLocalesToIR(environment.contentModel.locales),
|
|
16327
|
-
stages: convertStagesToIR(environment.contentModel.stages),
|
|
16328
|
-
...live,
|
|
16329
|
-
models: live.models.map((model) => ({
|
|
16330
|
-
...model,
|
|
16331
|
-
sidebar: sidebars.get(model.apiId) ?? []
|
|
16332
|
-
})),
|
|
16333
|
-
...hasSegment && { segment: segment ?? {
|
|
16334
|
-
apiId: "Segment",
|
|
16335
|
-
fields: {}
|
|
16336
|
-
} },
|
|
16337
|
-
components: live.components.filter(({ apiId }) => components.has(apiId))
|
|
16338
|
-
}
|
|
16565
|
+
modelsWithUnsupportedSidebarElements,
|
|
16566
|
+
environment: ir
|
|
16339
16567
|
};
|
|
16340
16568
|
}
|
|
16341
16569
|
/** Every relational field's rules, condition and editor, by `Model.field`. */
|
|
@@ -16628,7 +16856,10 @@ function toBatchStageChange(change) {
|
|
|
16628
16856
|
color: change.stage.color
|
|
16629
16857
|
} };
|
|
16630
16858
|
case "update": return { updateStage: updateStage(change) };
|
|
16631
|
-
case "delete": return { deleteStage: {
|
|
16859
|
+
case "delete": return { deleteStage: {
|
|
16860
|
+
apiId: change.apiId,
|
|
16861
|
+
force: true
|
|
16862
|
+
} };
|
|
16632
16863
|
}
|
|
16633
16864
|
}
|
|
16634
16865
|
/**
|
|
@@ -16870,7 +17101,6 @@ const messages = {
|
|
|
16870
17101
|
["field.enumerationMissing"]: (field, enumeration) => `Field "${field}" uses enumeration "${enumeration}", which is not in the environment.`,
|
|
16871
17102
|
["field.enumerationValueInvalid"]: (field, attribute, value) => `Field "${field}" has ${JSON.stringify(value)} in its ${attribute}, which is not a value of its enumeration.`,
|
|
16872
17103
|
["field.remoteSourceMissing"]: (field, prefix) => `Field "${field}" uses remote source "${prefix}", which is not in the environment.`,
|
|
16873
|
-
["field.remoteRenameUnsupported"]: (field) => `Field "${field}" is a remote field with renamedFrom, which Hygraph cannot rename.`,
|
|
16874
17104
|
["field.remoteOnComponent"]: (field) => `Field "${field}" is a remote field on a component, which Hygraph does not take.`,
|
|
16875
17105
|
["field.remoteQueryMissing"]: (field, prefix) => `Field "${field}" is on GraphQL remote source "${prefix}" but has no query.`,
|
|
16876
17106
|
["field.remoteQueryOnRest"]: (field, prefix) => `Field "${field}" has a query, but remote source "${prefix}" is a REST source.`,
|
|
@@ -16949,7 +17179,6 @@ const messages = {
|
|
|
16949
17179
|
["change.localeDisplayNameInUse"]: (displayName) => `The locale displayName "${displayName}" is already in use at that point of the migration.`,
|
|
16950
17180
|
["change.localeDeleteDefault"]: (apiId) => `Cannot delete locale "${apiId}": it is the environment's default locale.`,
|
|
16951
17181
|
["change.localeDefaultChange"]: (apiId) => `Cannot make locale "${apiId}" the default: Hygraph cannot change an environment's default locale yet.`,
|
|
16952
|
-
["change.stageDeleteUnsupported"]: (apiId) => `Cannot delete stage "${apiId}": deleting a stage is not supported yet.`,
|
|
16953
17182
|
["change.taxonomyNodeRenameBothInUse"]: (taxonomy, renamedFrom, apiId) => `Cannot rename node "${renamedFrom}" to "${apiId}" in taxonomy "${taxonomy}": both exist there.`,
|
|
16954
17183
|
["change.apiIdInUse"]: (apiId) => `The apiId "${apiId}" is already in use at that point of the migration.`,
|
|
16955
17184
|
["change.apiIdPluralInUse"]: (apiIdPlural) => `The apiIdPlural "${apiIdPlural}" is already in use at that point of the migration.`,
|
|
@@ -17096,7 +17325,6 @@ const fixes = {
|
|
|
17096
17325
|
["field.enumerationMissing"]: "Add the enumeration to enumerations in define.environment.",
|
|
17097
17326
|
["field.enumerationValueInvalid"]: "Use a value apiId of the field's enumeration, or add the value to it.",
|
|
17098
17327
|
["field.remoteSourceMissing"]: "Add the source to remoteSources in define.environment.",
|
|
17099
|
-
["field.remoteRenameUnsupported"]: "Remove renamedFrom and keep the new apiId: the plan deletes the field and creates it again, which loses nothing.",
|
|
17100
17328
|
["field.remoteOnComponent"]: "Move the remote field to a model.",
|
|
17101
17329
|
["field.remoteQueryMissing"]: "Write the query sent to the source: a named operation that spreads ...EntryPoint where returnType is.",
|
|
17102
17330
|
["field.remoteQueryOnRest"]: "Give a REST source's field a path, or use a GraphQL source.",
|
|
@@ -17175,7 +17403,6 @@ const fixes = {
|
|
|
17175
17403
|
["change.localeDisplayNameInUse"]: "Rename or delete the locale that has it first, in a plan of its own if needed.",
|
|
17176
17404
|
["change.localeDeleteDefault"]: "Keep the locale. Hygraph cannot change an environment's default locale yet, so the default stays.",
|
|
17177
17405
|
["change.localeDefaultChange"]: (_apiId, current) => `Keep isDefault: true on "${current}", the environment's default locale now.`,
|
|
17178
|
-
["change.stageDeleteUnsupported"]: "Keep the stage in stages, under the apiId it has in Hygraph. To delete it, delete it in Studio, then plan again.",
|
|
17179
17406
|
["change.taxonomyNodeRenameBothInUse"]: "Delete one of the two nodes first, in a plan of its own, or remove renamedFrom.",
|
|
17180
17407
|
["change.apiIdInUse"]: "Rename or delete the model, component, enumeration or taxonomy that has it first, in a plan of its own if needed.",
|
|
17181
17408
|
["change.apiIdPluralInUse"]: "Rename or delete the model or component that has it first, in a plan of its own if needed.",
|
|
@@ -17331,48 +17558,6 @@ function missingOAuthSecrets(changes) {
|
|
|
17331
17558
|
return changes.flatMap((change) => change.resource === "remoteSource" && change.action !== "delete" && change.clientSecret === null ? [remoteSourcePrefixOf(change)] : []);
|
|
17332
17559
|
}
|
|
17333
17560
|
//#endregion
|
|
17334
|
-
//#region src/telemetry/record.ts
|
|
17335
|
-
let current;
|
|
17336
|
-
/** Until this is called, and after `stopRun`, the record calls do nothing. */
|
|
17337
|
-
function startRun() {
|
|
17338
|
-
current = {
|
|
17339
|
-
targets: [],
|
|
17340
|
-
changes: void 0,
|
|
17341
|
-
codes: [],
|
|
17342
|
-
failures: [],
|
|
17343
|
-
cancelled: false,
|
|
17344
|
-
failedMigrations: []
|
|
17345
|
-
};
|
|
17346
|
-
return current;
|
|
17347
|
-
}
|
|
17348
|
-
function stopRun() {
|
|
17349
|
-
current = void 0;
|
|
17350
|
-
}
|
|
17351
|
-
function recordTargets(targets) {
|
|
17352
|
-
current?.targets.push(...targets);
|
|
17353
|
-
}
|
|
17354
|
-
function recordChanges(count) {
|
|
17355
|
-
if (current !== void 0) current.changes = (current.changes ?? 0) + count;
|
|
17356
|
-
}
|
|
17357
|
-
function recordRefusals(validations) {
|
|
17358
|
-
current?.codes.push(...validations.map(({ code }) => code));
|
|
17359
|
-
}
|
|
17360
|
-
/** Records a `Failure`; a crash is reported on its own when the run ends. */
|
|
17361
|
-
function recordFailure(error) {
|
|
17362
|
-
if (error instanceof Failure) current?.failures.push(error.name);
|
|
17363
|
-
}
|
|
17364
|
-
function recordCancelled() {
|
|
17365
|
-
if (current !== void 0) current.cancelled = true;
|
|
17366
|
-
}
|
|
17367
|
-
/** A submitted migration that did not end in SUCCESS, or whose end is unknown. */
|
|
17368
|
-
function recordFailedMigration(target, id, migration) {
|
|
17369
|
-
current?.failedMigrations.push({
|
|
17370
|
-
target,
|
|
17371
|
-
id,
|
|
17372
|
-
migration
|
|
17373
|
-
});
|
|
17374
|
-
}
|
|
17375
|
-
//#endregion
|
|
17376
17561
|
//#region src/define/fields/validation.shared.ts
|
|
17377
17562
|
/**
|
|
17378
17563
|
* Where a field attribute sits in the config, as every report points at it:
|
|
@@ -17988,7 +18173,7 @@ const REST_SCALARS = /* @__PURE__ */ new Set([
|
|
|
17988
18173
|
const PLACEHOLDER = /\{\{\s*(doc|args)\.([A-Za-z0-9_]+)[^}]*\}\}/g;
|
|
17989
18174
|
/**
|
|
17990
18175
|
* What a remote field can tell about itself: Hygraph takes it on a model
|
|
17991
|
-
* only,
|
|
18176
|
+
* only, sends a GraphQL source a query, which it needs,
|
|
17992
18177
|
* and calls a REST one at a path, caches for 0 or at least 60 seconds, and sends no header
|
|
17993
18178
|
* empty. Each argument is declared once, and every `{{args.x}}` names one.
|
|
17994
18179
|
*/
|
|
@@ -18002,7 +18187,6 @@ function validateRemoteField(parent, field) {
|
|
|
18002
18187
|
fix: fixes[code]
|
|
18003
18188
|
});
|
|
18004
18189
|
if (parent.kind === "component") report("field.remoteOnComponent", "source", messages["field.remoteOnComponent"](field.apiId));
|
|
18005
|
-
if (field.renamedFrom !== null) report("field.remoteRenameUnsupported", "renamedFrom", messages["field.remoteRenameUnsupported"](field.apiId));
|
|
18006
18190
|
const graphql = field.source.__typename === "GraphQLRemoteSource";
|
|
18007
18191
|
if (!graphql && field.query !== null) report("field.remoteQueryOnRest", "query", messages["field.remoteQueryOnRest"](field.apiId, field.source.prefix));
|
|
18008
18192
|
if (graphql && field.query === null) report("field.remoteQueryMissing", "query", messages["field.remoteQueryMissing"](field.apiId, field.source.prefix));
|
|
@@ -18131,8 +18315,9 @@ function validateRichTextField(parent, field) {
|
|
|
18131
18315
|
}
|
|
18132
18316
|
/**
|
|
18133
18317
|
* Every model rich text embeds must be in the environment's `models`, or
|
|
18134
|
-
* the plan would embed a model it never creates.
|
|
18135
|
-
*
|
|
18318
|
+
* the plan would embed a model it never creates. Asset is there once
|
|
18319
|
+
* `models` lists `system.model.asset`. A component is refused on its own:
|
|
18320
|
+
* only the types keep it out of `embeds`.
|
|
18136
18321
|
*/
|
|
18137
18322
|
function validateRichTextEmbedReferences(parent, fields, models) {
|
|
18138
18323
|
return fields.flatMap((field) => {
|
|
@@ -19763,7 +19948,7 @@ function validateEnvironment(environment) {
|
|
|
19763
19948
|
kind: parent.kind,
|
|
19764
19949
|
apiId: parent.apiId
|
|
19765
19950
|
};
|
|
19766
|
-
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), ...validateAssetReverseFields(fieldParent, parent.fields, withAsset), ...validateRichTextEmbedReferences(fieldParent, parent.fields, new Set(
|
|
19951
|
+
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), ...validateAssetReverseFields(fieldParent, parent.fields, withAsset), ...validateRichTextEmbedReferences(fieldParent, parent.fields, new Set(withAsset.keys())), ...validateReferenceUnionMembers(fieldParent, parent.fields, models), ...validateTaxonomyFieldReferences(fieldParent, parent.fields, taxonomies), ...validateRemoteFieldReferences(fieldParent, parent.fields, sources, { entries: parent.__typename !== "SystemQuery" }));
|
|
19767
19952
|
}
|
|
19768
19953
|
return validations;
|
|
19769
19954
|
}
|
|
@@ -22636,10 +22821,7 @@ function validateChangeSet({ from, changes, fieldsBackOnAsset = [] }) {
|
|
|
22636
22821
|
case "component":
|
|
22637
22822
|
validateComponentChange(change);
|
|
22638
22823
|
break;
|
|
22639
|
-
case "model":
|
|
22640
|
-
validateModelChange(change);
|
|
22641
|
-
break;
|
|
22642
|
-
case "stage": if (change.action === "delete") report("change.stageDeleteUnsupported", ["stages", change.apiId], change.apiId);
|
|
22824
|
+
case "model": validateModelChange(change);
|
|
22643
22825
|
}
|
|
22644
22826
|
function validateComponentsUsed(change) {
|
|
22645
22827
|
const used = change.action === "create" ? change.field.kind === "component" ? [change.field.component] : change.field.kind === "componentUnion" ? change.field.components : [] : change.action === "update" && change.kind === "componentUnion" ? change.changes.components?.to ?? [] : [];
|
|
@@ -22652,6 +22834,7 @@ function validateChangeSet({ from, changes, fieldsBackOnAsset = [] }) {
|
|
|
22652
22834
|
], `${change.action} a field that uses`, apiId);
|
|
22653
22835
|
}
|
|
22654
22836
|
function validateModelsEmbedded(change) {
|
|
22837
|
+
const exists = (apiId) => apiId === "Asset" || models.has(apiId);
|
|
22655
22838
|
const embedded = change.action === "create" ? change.field.kind === "richText" ? change.field.embeds ?? [] : [] : change.action === "update" && change.kind === "richText" ? change.changes.embeds?.to ?? [] : [];
|
|
22656
22839
|
const path = [
|
|
22657
22840
|
componentApiIds.has(change.parent) ? "components" : "models",
|
|
@@ -22660,11 +22843,11 @@ function validateChangeSet({ from, changes, fieldsBackOnAsset = [] }) {
|
|
|
22660
22843
|
fieldApiIdOf(change)
|
|
22661
22844
|
];
|
|
22662
22845
|
const had = change.action === "update" && change.kind === "richText" ? change.changes.embeds?.from ?? [] : [];
|
|
22663
|
-
if (had.length > 0 && had.every((apiId) => !
|
|
22846
|
+
if (had.length > 0 && had.every((apiId) => !exists(apiId))) {
|
|
22664
22847
|
report("change.embedsReplaced", path, fieldApiIdOf(change), had.join(", "));
|
|
22665
22848
|
return;
|
|
22666
22849
|
}
|
|
22667
|
-
for (const apiId of embedded.filter((each) => !
|
|
22850
|
+
for (const apiId of embedded.filter((each) => !exists(each))) report("change.modelMissing", path, `${change.action} a field that embeds`, apiId);
|
|
22668
22851
|
}
|
|
22669
22852
|
function validateModelReferenced(change) {
|
|
22670
22853
|
const referenced = change.action === "create" ? change.field.kind === "referenceOneWay" || change.field.kind === "referenceTwoWay" ? [change.field.to] : change.field.kind === "referenceUnion" ? change.field.to : [] : change.action === "update" && change.kind === "referenceUnion" ? change.changes.to?.to ?? [] : [];
|
|
@@ -23826,7 +24009,14 @@ function selectTargets(targets, names) {
|
|
|
23826
24009
|
//#endregion
|
|
23827
24010
|
//#region src/commands/plan.ts
|
|
23828
24011
|
/** What only plan can find out is wrong. The command prints it and exits 1. */
|
|
23829
|
-
var PlanFailure = class extends Failure {
|
|
24012
|
+
var PlanFailure = class extends Failure {
|
|
24013
|
+
/** The codes of the checks that refused the plan; empty for another cause. */
|
|
24014
|
+
codes;
|
|
24015
|
+
constructor(message, codes = []) {
|
|
24016
|
+
super(message);
|
|
24017
|
+
this.codes = codes;
|
|
24018
|
+
}
|
|
24019
|
+
};
|
|
23830
24020
|
function registerPlan(program) {
|
|
23831
24021
|
program.command("plan").description("show what would change against the target environments").argument("[config]", "path to the config", "hygraph.config.ts").option("-t, --target <name>", "plan only this target (repeatable, default: every target)", collect, []).option("--out <file>", `write the plan artifact to a file (${TARGET_PLACEHOLDER} stands for the target name)`).option("--rotate-secret <prefix>", "send the remote source's OAuth secret again, after it changed (repeatable)", collect, []).option("--no-color", "print without colours").action(async function(config, options) {
|
|
23832
24022
|
const output = this.configureOutput();
|
|
@@ -24034,7 +24224,7 @@ function maybeRefuse(validations, lead) {
|
|
|
24034
24224
|
const errors = validations.filter((validation) => validation.severity === "error");
|
|
24035
24225
|
if (errors.length === 0) return;
|
|
24036
24226
|
recordRefusals(errors);
|
|
24037
|
-
throw new PlanFailure(`${lead} ${errors.length === 1 ? "1 error" : `${errors.length} errors`}:\n\n${renderValidations(errors)}
|
|
24227
|
+
throw new PlanFailure(`${lead} ${errors.length === 1 ? "1 error" : `${errors.length} errors`}:\n\n${renderValidations(errors)}`, errors.map(({ code }) => code));
|
|
24038
24228
|
}
|
|
24039
24229
|
//#endregion
|
|
24040
24230
|
//#region src/commands/apply.ts
|
|
@@ -24217,13 +24407,15 @@ async function execute({ target, plan, changes, environmentId }, { colors, write
|
|
|
24217
24407
|
});
|
|
24218
24408
|
const name = migrationName(plan.planHash, /* @__PURE__ */ new Date());
|
|
24219
24409
|
const started = Date.now();
|
|
24220
|
-
const
|
|
24410
|
+
const input = toBatchMigrationInput({
|
|
24221
24411
|
...plan,
|
|
24222
24412
|
changes
|
|
24223
24413
|
}, {
|
|
24224
24414
|
environmentId,
|
|
24225
24415
|
name
|
|
24226
|
-
})
|
|
24416
|
+
});
|
|
24417
|
+
const kinds = changeKinds(input.changes);
|
|
24418
|
+
const { id } = await submitMigration(client, target, input);
|
|
24227
24419
|
write(renderCheck("migration submitted", name, colors));
|
|
24228
24420
|
const spinner = startSpinner({
|
|
24229
24421
|
write,
|
|
@@ -24237,16 +24429,52 @@ async function execute({ target, plan, changes, environmentId }, { colors, write
|
|
|
24237
24429
|
spinner.update(`migration ${polled.status.toLowerCase()}`);
|
|
24238
24430
|
} });
|
|
24239
24431
|
} catch (error) {
|
|
24240
|
-
recordFailedMigration(target, id, last);
|
|
24432
|
+
recordFailedMigration(target, id, last, kinds);
|
|
24241
24433
|
throw error;
|
|
24242
24434
|
} finally {
|
|
24243
24435
|
spinner.stop();
|
|
24244
24436
|
}
|
|
24245
24437
|
if (migration.status !== "SUCCESS") {
|
|
24246
|
-
recordFailedMigration(target, id, migration);
|
|
24438
|
+
recordFailedMigration(target, id, migration, kinds);
|
|
24247
24439
|
throw new ApplyFailure(renderFailedMigration(migration));
|
|
24248
24440
|
}
|
|
24249
24441
|
write(renderCheck(`SUCCESS in ${((Date.now() - started) / 1e3).toFixed(1)}s`, describeOutcome(plan.summary), colors));
|
|
24442
|
+
await checkConverged(target, id, kinds);
|
|
24443
|
+
}
|
|
24444
|
+
const CONVERGE_TIMEOUT_MS = 1e4;
|
|
24445
|
+
/**
|
|
24446
|
+
* Plans the target again after its migration succeeded. Changes that remain,
|
|
24447
|
+
* or the codes of the checks that refuse the plan, go to telemetry and
|
|
24448
|
+
* nothing is printed. Costs one read of the live schema, so it only runs
|
|
24449
|
+
* when telemetry is on. A read that fails, or that takes longer than the
|
|
24450
|
+
* time limit, is dropped: it says nothing about the apply.
|
|
24451
|
+
*/
|
|
24452
|
+
async function checkConverged(target, id, applied) {
|
|
24453
|
+
if (!isRecording()) return;
|
|
24454
|
+
const signal = AbortSignal.timeout(CONVERGE_TIMEOUT_MS);
|
|
24455
|
+
try {
|
|
24456
|
+
const { changes } = await unrecorded(() => computePlan(target, (input, init) => fetch(input, {
|
|
24457
|
+
...init,
|
|
24458
|
+
signal
|
|
24459
|
+
})));
|
|
24460
|
+
if (changes.length > 0) recordUnconverged({
|
|
24461
|
+
target,
|
|
24462
|
+
id,
|
|
24463
|
+
applied,
|
|
24464
|
+
remaining: changeKinds(changes.map(toBatchChange)),
|
|
24465
|
+
attributes: changedAttributes(changes),
|
|
24466
|
+
refused: []
|
|
24467
|
+
});
|
|
24468
|
+
} catch (error) {
|
|
24469
|
+
if (error instanceof PlanFailure && error.codes.length > 0) recordUnconverged({
|
|
24470
|
+
target,
|
|
24471
|
+
id,
|
|
24472
|
+
applied,
|
|
24473
|
+
remaining: {},
|
|
24474
|
+
attributes: {},
|
|
24475
|
+
refused: error.codes
|
|
24476
|
+
});
|
|
24477
|
+
}
|
|
24250
24478
|
}
|
|
24251
24479
|
/** One go-ahead for every target that has changes. */
|
|
24252
24480
|
async function approve(ready, { skipped, total }, options) {
|
|
@@ -25084,12 +25312,15 @@ function writable(write) {
|
|
|
25084
25312
|
//#region src/commands/export.ts
|
|
25085
25313
|
/** What only export can find out is wrong. The command prints it and exits 1. */
|
|
25086
25314
|
var ExportFailure = class extends Failure {};
|
|
25315
|
+
/** The user answered no. Printed as is, exit 1, and not counted as a failure. */
|
|
25316
|
+
var ExportCancelled = class extends Failure {};
|
|
25087
25317
|
function registerExport(program) {
|
|
25088
|
-
program.command("export").description("write a live environment out as TypeScript").option("--project <id>", "project to export (default: the token's)").option("--endpoint <url>", "the project's management API endpoint (default: the token's)").option("--environment <name>", "environment to export (default: the token's, else master)").option("--name <name>", "
|
|
25318
|
+
program.command("export").description("write a live environment out as TypeScript").option("--project <id>", "project to export (default: the token's)").option("--endpoint <url>", "the project's management API endpoint (default: the token's)").option("--environment <name>", "environment to export (default: the token's, else master)").option("--name <name>", "name for this environment in the config, used with --target (default: the environment)").option("--out <file>", "write to a file instead of stdout").option("--no-color", "print without colours").action(async function(options) {
|
|
25089
25319
|
const write = (text) => this.configureOutput().writeOut?.(text);
|
|
25090
25320
|
const writeErr = (text) => this.configureOutput().writeErr?.(text);
|
|
25091
25321
|
try {
|
|
25092
25322
|
const input = await readInput(options, writeErr);
|
|
25323
|
+
if (input.out !== void 0) await confirmReplace(input.out);
|
|
25093
25324
|
const { config, environment } = await exportEnvironment(input);
|
|
25094
25325
|
const headers = renderHeaderNote(remoteHeaderEnvNames(environment)) + renderSecretNote(oAuthSecretEnvNames(environment));
|
|
25095
25326
|
if (input.out === void 0) {
|
|
@@ -25103,6 +25334,10 @@ function registerExport(program) {
|
|
|
25103
25334
|
write(headers);
|
|
25104
25335
|
write(input.tokenTyped ? `\nSet HYGRAPH_TOKEN to the token, then run \`hygraph plan ${input.out}\`. It should show no changes.\n` : `\nRun \`hygraph plan ${input.out}\` next. It should show no changes.\n`);
|
|
25105
25336
|
} catch (error) {
|
|
25337
|
+
if (error instanceof ExportCancelled) this.error(error.message, {
|
|
25338
|
+
exitCode: 1,
|
|
25339
|
+
code: "hygraph.export"
|
|
25340
|
+
});
|
|
25106
25341
|
recordFailure(error);
|
|
25107
25342
|
if (error instanceof Failure) this.error(`error: ${error.message}`, {
|
|
25108
25343
|
exitCode: 1,
|
|
@@ -25157,7 +25392,7 @@ async function readInput(options, writeErr) {
|
|
|
25157
25392
|
writeErr(`Environment: ${environment} (from the token)\n`);
|
|
25158
25393
|
}
|
|
25159
25394
|
environment ??= terminal === void 0 ? "master" : await askWithDefault("Environment", "master", terminal);
|
|
25160
|
-
const name = options.name ?? (terminal === void 0 ? environment : await askWithDefault("
|
|
25395
|
+
const name = options.name ?? (terminal === void 0 ? environment : await askWithDefault("Name for this environment in the config (used with --target)", environment, terminal));
|
|
25161
25396
|
const out = options.out ?? (terminal !== void 0 && process.stdout.isTTY === true ? await askWithDefault("Write the config to", "hygraph.config.ts", terminal) : void 0);
|
|
25162
25397
|
return {
|
|
25163
25398
|
project,
|
|
@@ -25242,7 +25477,25 @@ function renderSecretNote(names) {
|
|
|
25242
25477
|
if (names.length === 0) return "";
|
|
25243
25478
|
return `\nThe config reads OAuth secrets from ${names.join(", ")}. Set each to its API client's secret before a plan that sends it, such as one that creates the source. Hygraph keeps the secrets and never shows them.\n`;
|
|
25244
25479
|
}
|
|
25245
|
-
/**
|
|
25480
|
+
/**
|
|
25481
|
+
* On a terminal outside CI, asks before an existing file is replaced. Else
|
|
25482
|
+
* the file is replaced without a question.
|
|
25483
|
+
*/
|
|
25484
|
+
async function confirmReplace(path) {
|
|
25485
|
+
if (approvalMode({
|
|
25486
|
+
yes: false,
|
|
25487
|
+
env: process.env,
|
|
25488
|
+
stdinIsTTY: process.stdin.isTTY === true
|
|
25489
|
+
}) !== "ask" || !existsSync(resolve(process.cwd(), path))) return;
|
|
25490
|
+
if (!await confirm(`${path} exists. Replace it? [y/N]: `, {
|
|
25491
|
+
input: process.stdin,
|
|
25492
|
+
output: process.stderr
|
|
25493
|
+
}).catch(() => false)) {
|
|
25494
|
+
recordCancelled();
|
|
25495
|
+
throw new ExportCancelled(`kept ${path}, nothing written`);
|
|
25496
|
+
}
|
|
25497
|
+
}
|
|
25498
|
+
/** Replaces a file that is already there; on a terminal `confirmReplace` asks first. */
|
|
25246
25499
|
function writeConfigFile(config, path) {
|
|
25247
25500
|
try {
|
|
25248
25501
|
writeFileSync(resolve(process.cwd(), path), config);
|
|
@@ -25349,6 +25602,19 @@ function colorLine(line, colors) {
|
|
|
25349
25602
|
if (line.startsWith("-")) return colors.red(line);
|
|
25350
25603
|
return line;
|
|
25351
25604
|
}
|
|
25605
|
+
/**
|
|
25606
|
+
* After the diffs when live differs from the config, on stderr like the
|
|
25607
|
+
* header, so `hygraph pull > drift.diff` saves the diff alone.
|
|
25608
|
+
*/
|
|
25609
|
+
function renderNextSteps(config, colors) {
|
|
25610
|
+
return [
|
|
25611
|
+
"",
|
|
25612
|
+
colors.bold("Next steps"),
|
|
25613
|
+
" - Give the diff to a coding agent to bring the live changes into your config.",
|
|
25614
|
+
` - Run \`hygraph export --out ${config}\` to replace the config with the live schema.`,
|
|
25615
|
+
""
|
|
25616
|
+
].join("\n");
|
|
25617
|
+
}
|
|
25352
25618
|
//#endregion
|
|
25353
25619
|
//#region src/commands/pull.ts
|
|
25354
25620
|
/** What only pull can find out is wrong. The command prints it and exits 1. */
|
|
@@ -25372,6 +25638,7 @@ function registerPull(program) {
|
|
|
25372
25638
|
["hygraph pull", "report drift against the default config"],
|
|
25373
25639
|
["hygraph pull --target uk", "pull one target of several"],
|
|
25374
25640
|
["hygraph pull --full", "see each change among the lines around it"],
|
|
25641
|
+
["hygraph pull > drift.diff", "save the diff to review it or give it to a coding agent"],
|
|
25375
25642
|
["hygraph pull brands/kaffa.ts", "report drift against another config"]
|
|
25376
25643
|
]));
|
|
25377
25644
|
}
|
|
@@ -25385,16 +25652,17 @@ async function pull(config, options, write, writeErr) {
|
|
|
25385
25652
|
const targets = await loadTargets(config, options.target, PullFailure);
|
|
25386
25653
|
const full = options.full === true;
|
|
25387
25654
|
if (targets.length === 1) {
|
|
25388
|
-
await pullTarget(targets[0], {
|
|
25655
|
+
if (await pullTarget(targets[0], {
|
|
25389
25656
|
config,
|
|
25390
25657
|
colors,
|
|
25391
25658
|
full,
|
|
25392
25659
|
write,
|
|
25393
25660
|
writeErr
|
|
25394
|
-
});
|
|
25661
|
+
}) !== void 0) writeErr(renderNextSteps(config, colors));
|
|
25395
25662
|
return;
|
|
25396
25663
|
}
|
|
25397
25664
|
const outcomes = [];
|
|
25665
|
+
let differs = false;
|
|
25398
25666
|
for (const target of targets) {
|
|
25399
25667
|
writeErr(renderTargetHeading(target, colors));
|
|
25400
25668
|
try {
|
|
@@ -25405,6 +25673,7 @@ async function pull(config, options, write, writeErr) {
|
|
|
25405
25673
|
write,
|
|
25406
25674
|
writeErr
|
|
25407
25675
|
});
|
|
25676
|
+
differs ||= diff !== void 0;
|
|
25408
25677
|
outcomes.push({
|
|
25409
25678
|
name: target.name,
|
|
25410
25679
|
ok: true,
|
|
@@ -25422,6 +25691,7 @@ async function pull(config, options, write, writeErr) {
|
|
|
25422
25691
|
}
|
|
25423
25692
|
}
|
|
25424
25693
|
writeErr(renderTargetOutcomes(outcomes, colors));
|
|
25694
|
+
if (differs) writeErr(renderNextSteps(config, colors));
|
|
25425
25695
|
const failed = outcomes.filter(({ ok }) => !ok).length;
|
|
25426
25696
|
if (failed > 0) throw new PullFailure(`${failed} of ${targets.length} targets could not be pulled`);
|
|
25427
25697
|
}
|
|
@@ -29718,10 +29988,13 @@ function _safeDecodeURI(filename) {
|
|
|
29718
29988
|
//#region src/telemetry/consent.ts
|
|
29719
29989
|
const NOTICE = `The Hygraph CLI sends error reports and usage data to Hygraph: the command,
|
|
29720
29990
|
the names of its flags, how long it took, whether it worked, the codes of
|
|
29721
|
-
refused checks,
|
|
29722
|
-
|
|
29723
|
-
|
|
29724
|
-
|
|
29991
|
+
refused checks, how many fields it could not read, by type and reason, how
|
|
29992
|
+
many models have a sidebar panel it could not read, the kinds of changes in
|
|
29993
|
+
a migration that failed or left changes behind, the error of a failed one,
|
|
29994
|
+
the operation, status, codes and request ids of a Hygraph server error, each
|
|
29995
|
+
target's project id, environment and endpoint host, the CLI and Node
|
|
29996
|
+
versions, the OS, and a random id for this machine. It never sends your auth
|
|
29997
|
+
token. Turn it off with HYGRAPH_TELEMETRY=0 or DO_NOT_TRACK=1.
|
|
29725
29998
|
|
|
29726
29999
|
`;
|
|
29727
30000
|
/**
|
|
@@ -29875,6 +30148,7 @@ function trackCall({ command, flags, durationMs, outcome, run, ci, cliEnvironmen
|
|
|
29875
30148
|
environment,
|
|
29876
30149
|
endpoint_host: endpointHost(endpoint)
|
|
29877
30150
|
})),
|
|
30151
|
+
...unsupportedProperties(run),
|
|
29878
30152
|
cli_version: VERSION,
|
|
29879
30153
|
cli_environment: cliEnvironment,
|
|
29880
30154
|
node_version: process.version,
|
|
@@ -29892,11 +30166,35 @@ function trackCall({ command, flags, durationMs, outcome, run, ci, cliEnvironmen
|
|
|
29892
30166
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
29893
30167
|
};
|
|
29894
30168
|
}
|
|
30169
|
+
/**
|
|
30170
|
+
* The unsupported fields over all targets, counted by type and reason, and
|
|
30171
|
+
* the models with a panel the CLI cannot read. None when nothing read live.
|
|
30172
|
+
*/
|
|
30173
|
+
function unsupportedProperties({ unsupported }) {
|
|
30174
|
+
if (unsupported.size === 0) return {};
|
|
30175
|
+
const reads = [...unsupported.values()];
|
|
30176
|
+
const counts = /* @__PURE__ */ new Map();
|
|
30177
|
+
for (const { type, reason } of reads.flatMap(({ fields }) => fields)) {
|
|
30178
|
+
const key = `${type} ${reason}`;
|
|
30179
|
+
const entry = counts.get(key) ?? {
|
|
30180
|
+
type,
|
|
30181
|
+
reason,
|
|
30182
|
+
count: 0
|
|
30183
|
+
};
|
|
30184
|
+
entry.count += 1;
|
|
30185
|
+
counts.set(key, entry);
|
|
30186
|
+
}
|
|
30187
|
+
return {
|
|
30188
|
+
unsupported_fields: [...counts.values()].toSorted((a, b) => a.type.localeCompare(b.type) || a.reason.localeCompare(b.reason)),
|
|
30189
|
+
models_with_unsupported_sidebar: reads.reduce((sum, read) => sum + read.modelsWithUnsupportedSidebar, 0)
|
|
30190
|
+
};
|
|
30191
|
+
}
|
|
29895
30192
|
//#endregion
|
|
29896
30193
|
//#region src/telemetry/telemetry.ts
|
|
29897
30194
|
/**
|
|
29898
30195
|
* Runs the command with reporting around it and hands back its exit code.
|
|
29899
|
-
* A crash
|
|
30196
|
+
* A crash, every failed migration, every apply that did not converge and
|
|
30197
|
+
* every fault of the management API go to Sentry; the crash is rethrown. A
|
|
29900
30198
|
* command that got as far as its action sends one usage event. Sends never
|
|
29901
30199
|
* fail the command and are dropped after `timeoutMs`.
|
|
29902
30200
|
*/
|
|
@@ -29959,7 +30257,7 @@ function outcomeOf({ crash, run, exitCode }) {
|
|
|
29959
30257
|
return "failure";
|
|
29960
30258
|
}
|
|
29961
30259
|
async function reportErrors(run, crash, { cliEnvironment, fetch, timeoutMs, tags }) {
|
|
29962
|
-
if (crash === void 0 && run.failedMigrations.length === 0) return;
|
|
30260
|
+
if (crash === void 0 && run.failedMigrations.length === 0 && run.unconverged.length === 0 && run.serverFaults.length === 0) return;
|
|
29963
30261
|
const client = createSentryClient({
|
|
29964
30262
|
cliEnvironment,
|
|
29965
30263
|
fetch,
|
|
@@ -29967,15 +30265,71 @@ async function reportErrors(run, crash, { cliEnvironment, fetch, timeoutMs, tags
|
|
|
29967
30265
|
});
|
|
29968
30266
|
const scope = scopeOf(run, tags);
|
|
29969
30267
|
if (crash !== void 0) client.captureException(crash.error, void 0, scope);
|
|
29970
|
-
for (const { target, id, migration } of run.failedMigrations)
|
|
29971
|
-
|
|
29972
|
-
|
|
29973
|
-
|
|
29974
|
-
|
|
29975
|
-
|
|
29976
|
-
|
|
30268
|
+
for (const { target, id, migration, changes } of run.failedMigrations) {
|
|
30269
|
+
const cause = migration?.errors == null ? void 0 : causeOf(migration.errors);
|
|
30270
|
+
client.captureMessage(cause === void 0 ? "migration failed" : `migration failed: ${cause}`, "warning", void 0, scope.clone().setTags({
|
|
30271
|
+
project: target.project,
|
|
30272
|
+
hygraph_environment: target.environment,
|
|
30273
|
+
endpoint_host: endpointHost(target.endpoint),
|
|
30274
|
+
migration_id: id,
|
|
30275
|
+
migration_status: migration?.status ?? "unknown"
|
|
30276
|
+
}).setContext("migration", {
|
|
30277
|
+
errors: migration?.errors ?? null,
|
|
30278
|
+
changes
|
|
30279
|
+
}).setFingerprint(cause === void 0 ? ["migration-failed"] : ["migration-failed", cause]));
|
|
30280
|
+
}
|
|
30281
|
+
for (const unconverged of run.unconverged) {
|
|
30282
|
+
const { target, id, applied, remaining, attributes, refused } = unconverged;
|
|
30283
|
+
client.captureMessage("apply did not converge", "warning", void 0, scope.clone().setTags({
|
|
30284
|
+
project: target.project,
|
|
30285
|
+
hygraph_environment: target.environment,
|
|
30286
|
+
endpoint_host: endpointHost(target.endpoint),
|
|
30287
|
+
migration_id: id,
|
|
30288
|
+
migration_status: "SUCCESS"
|
|
30289
|
+
}).setContext("migration", { changes: applied }).setContext("remaining", {
|
|
30290
|
+
changes: remaining,
|
|
30291
|
+
attributes,
|
|
30292
|
+
refused
|
|
30293
|
+
}).setFingerprint(["apply-did-not-converge", ...causesOf(unconverged)]));
|
|
30294
|
+
}
|
|
30295
|
+
for (const fault of run.serverFaults) client.captureMessage("management API fault", "error", void 0, scope.clone().setTags({
|
|
30296
|
+
endpoint_host: endpointHost(fault.endpoint),
|
|
30297
|
+
operation: fault.operation,
|
|
30298
|
+
status: fault.status
|
|
30299
|
+
}).setContext("response", {
|
|
30300
|
+
status: fault.status,
|
|
30301
|
+
codes: fault.codes,
|
|
30302
|
+
request_ids: fault.requestIds
|
|
30303
|
+
}).setFingerprint([
|
|
30304
|
+
"management-api-fault",
|
|
30305
|
+
fault.operation,
|
|
30306
|
+
String(fault.status),
|
|
30307
|
+
...fault.codes
|
|
30308
|
+
]));
|
|
29977
30309
|
await client.flush(timeoutMs);
|
|
29978
30310
|
}
|
|
30311
|
+
/**
|
|
30312
|
+
* What an apply left behind, to group by: the attributes of the updates, the
|
|
30313
|
+
* kinds of the other changes, and the codes of the refusals.
|
|
30314
|
+
*/
|
|
30315
|
+
function causesOf({ remaining, attributes, refused }) {
|
|
30316
|
+
const updated = Object.keys(attributes);
|
|
30317
|
+
const kinds = Object.keys(remaining).filter((kind) => updated.length === 0 || !kind.startsWith("update"));
|
|
30318
|
+
return [.../* @__PURE__ */ new Set([
|
|
30319
|
+
...updated,
|
|
30320
|
+
...kinds,
|
|
30321
|
+
...refused
|
|
30322
|
+
])].toSorted();
|
|
30323
|
+
}
|
|
30324
|
+
/**
|
|
30325
|
+
* The server's message without the parts that change from one project to the
|
|
30326
|
+
* next, so that one cause is one Sentry issue with its own title. Quoted text and every word
|
|
30327
|
+
* that is not plain lowercase become `*`. A constraint name stays; so does
|
|
30328
|
+
* an apiId that is one lowercase word.
|
|
30329
|
+
*/
|
|
30330
|
+
function causeOf(errors) {
|
|
30331
|
+
return errors.replace(/"[^"]*"|`[^`]*`/g, "*").split(/\s+/).filter((word) => word !== "").map((word, index) => (index === 0 ? /^[A-Z]?[a-z_]+[.,:;]?$/ : /^[a-z_]+[.,:;]?$/).test(word) ? word : "*").join(" ");
|
|
30332
|
+
}
|
|
29979
30333
|
function scopeOf(run, { command, ci }) {
|
|
29980
30334
|
const join = (values) => [...new Set(values)].join(",");
|
|
29981
30335
|
return new Scope().setTags({
|
package/dist/define.d.ts
CHANGED
|
@@ -1332,13 +1332,7 @@ type RemoteFieldArgInput = {
|
|
|
1332
1332
|
list?: boolean;
|
|
1333
1333
|
};
|
|
1334
1334
|
/** The options every remote field takes, whatever its source. */
|
|
1335
|
-
type RemoteFieldBaseInput = Omit<FieldInput, "visibility" | "visibilityCondition" | "variantEnabled"
|
|
1336
|
-
/**
|
|
1337
|
-
* Hygraph cannot rename a remote field. Change `apiId` alone instead; the
|
|
1338
|
-
* plan deletes the field and creates it again, which loses nothing, since
|
|
1339
|
-
* a remote field holds no content.
|
|
1340
|
-
*/
|
|
1341
|
-
renamedFrom?: never;
|
|
1335
|
+
type RemoteFieldBaseInput = Omit<FieldInput, "visibility" | "visibilityCondition" | "variantEnabled"> & {
|
|
1342
1336
|
/**
|
|
1343
1337
|
* The name of the type the field returns, without the prefix: one of the
|
|
1344
1338
|
* source's types, or a scalar.
|
|
@@ -1454,14 +1448,15 @@ type RichTextFieldInput = FieldInput & ValueFieldInput<RichTextValue> & UniqueFi
|
|
|
1454
1448
|
title?: never;
|
|
1455
1449
|
/**
|
|
1456
1450
|
* The models whose entries editors can embed, as `define.model` returns
|
|
1457
|
-
* them, behind a function: `[() => Author]`.
|
|
1458
|
-
*
|
|
1459
|
-
*
|
|
1460
|
-
*
|
|
1461
|
-
*
|
|
1451
|
+
* them, behind a function: `[() => Author]`. Assets too, with
|
|
1452
|
+
* `system.model.asset`: `[() => Author, () => Asset]`. Leave it out to
|
|
1453
|
+
* turn embeds off. List each model, Asset included, in the
|
|
1454
|
+
* environment's `models` too. Once the field has embeds they cannot be
|
|
1455
|
+
* turned off: leaving it out then deletes the field and its content.
|
|
1456
|
+
* Taking a model out deletes the embeds of its entries.
|
|
1462
1457
|
* @default null
|
|
1463
1458
|
*/
|
|
1464
|
-
embeds?: (() => Model)[];
|
|
1459
|
+
embeds?: (() => Model | SystemAsset)[];
|
|
1465
1460
|
/**
|
|
1466
1461
|
* The toolbar actions Studio shows. Leave it out to show every action;
|
|
1467
1462
|
* `[]` shows none. Embeds have a button of their own, shown while the
|
|
@@ -1492,7 +1487,7 @@ type RichTextField = {
|
|
|
1492
1487
|
* created required. A list of values on a list field.
|
|
1493
1488
|
*/
|
|
1494
1489
|
migrationValue: RichTextValue | RichTextValue[] | null;
|
|
1495
|
-
embeds: (() => Model)[] | null;
|
|
1490
|
+
embeds: (() => Model | SystemAsset)[] | null;
|
|
1496
1491
|
actions: RichTextAction[] | null;
|
|
1497
1492
|
/**
|
|
1498
1493
|
* The field's editor: `null` for Hygraph's own, or an app's element,
|
|
@@ -1503,7 +1498,7 @@ type RichTextField = {
|
|
|
1503
1498
|
};
|
|
1504
1499
|
/**
|
|
1505
1500
|
* Formatted text, such as an article's body, with embedded entries of
|
|
1506
|
-
* other models when `embeds` lists them. Allowed on components.
|
|
1501
|
+
* other models and assets when `embeds` lists them. Allowed on components.
|
|
1507
1502
|
*
|
|
1508
1503
|
* Nothing here is validated, and the models are not looked at until the
|
|
1509
1504
|
* plan: the checks run at plan time with the model's or component's own.
|
package/dist/define2.js
CHANGED
|
@@ -5089,7 +5089,7 @@ const RICH_TEXT_ACTIONS = [
|
|
|
5089
5089
|
];
|
|
5090
5090
|
/**
|
|
5091
5091
|
* Formatted text, such as an article's body, with embedded entries of
|
|
5092
|
-
* other models when `embeds` lists them. Allowed on components.
|
|
5092
|
+
* other models and assets when `embeds` lists them. Allowed on components.
|
|
5093
5093
|
*
|
|
5094
5094
|
* Nothing here is validated, and the models are not looked at until the
|
|
5095
5095
|
* plan: the checks run at plan time with the model's or component's own.
|
package/dist/version.js
CHANGED