@hygraph/cli 0.0.18 → 0.0.19
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 +10 -0
- package/README.md +12 -4
- package/dist/cli.js +413 -101
- 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,15 @@
|
|
|
1
1
|
# @hygraph/cli
|
|
2
2
|
|
|
3
|
+
## 0.0.19
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 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.
|
|
8
|
+
- 6793077: A remote field can be renamed with `renamedFrom`, as other fields are.
|
|
9
|
+
- 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.
|
|
10
|
+
- 8acaeb4: Rich text `embeds` takes `system.model.asset`, so a field that embeds assets is planned, applied and exported like the others.
|
|
11
|
+
- 5cdab20: `apply --prune` now deletes stages, with the entries in them. Before, `plan` refused a stage delete.
|
|
12
|
+
|
|
3
13
|
## 0.0.18
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -193,12 +193,20 @@ The CLI reports errors and usage to Hygraph, so that we can fix bugs and
|
|
|
193
193
|
see which commands people use. It tells you so the first time it runs.
|
|
194
194
|
|
|
195
195
|
- **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
|
|
196
|
+
message, and a migration that failed, with its id, the error Hygraph
|
|
197
|
+
gave for it and the kinds of its changes with their counts, such as
|
|
198
|
+
`createModel: 2`. That error can name models and fields. An apply that
|
|
199
|
+
worked, but left changes in the plan, is reported with the same kinds
|
|
200
|
+
and counts, and with the names of the attributes that still differ,
|
|
201
|
+
such as `field.position`. If a check refuses the plan after it, the code of the check
|
|
202
|
+
is reported. An answer of Hygraph that is a server error is reported
|
|
203
|
+
with its operation name, status, error codes and request ids, not its
|
|
204
|
+
message.
|
|
198
205
|
- **Usage:** one event per command: the command, the names of the flags you
|
|
199
206
|
gave, how long it took, whether it worked, the codes of the checks that
|
|
200
|
-
refused a plan,
|
|
201
|
-
|
|
207
|
+
refused a plan, how many fields of each type the CLI could not read and
|
|
208
|
+
why, how many models have a sidebar panel it could not read, and the
|
|
209
|
+
project id, environment and endpoint host of each target.
|
|
202
210
|
|
|
203
211
|
To turn it off, set `HYGRAPH_TELEMETRY=0` or `DO_NOT_TRACK=1`.
|
|
204
212
|
|
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) {
|
|
@@ -29718,10 +29946,13 @@ function _safeDecodeURI(filename) {
|
|
|
29718
29946
|
//#region src/telemetry/consent.ts
|
|
29719
29947
|
const NOTICE = `The Hygraph CLI sends error reports and usage data to Hygraph: the command,
|
|
29720
29948
|
the names of its flags, how long it took, whether it worked, the codes of
|
|
29721
|
-
refused checks,
|
|
29722
|
-
|
|
29723
|
-
|
|
29724
|
-
|
|
29949
|
+
refused checks, how many fields it could not read, by type and reason, how
|
|
29950
|
+
many models have a sidebar panel it could not read, the kinds of changes in
|
|
29951
|
+
a migration that failed or left changes behind, the error of a failed one,
|
|
29952
|
+
the operation, status, codes and request ids of a Hygraph server error, each
|
|
29953
|
+
target's project id, environment and endpoint host, the CLI and Node
|
|
29954
|
+
versions, the OS, and a random id for this machine. It never sends your auth
|
|
29955
|
+
token. Turn it off with HYGRAPH_TELEMETRY=0 or DO_NOT_TRACK=1.
|
|
29725
29956
|
|
|
29726
29957
|
`;
|
|
29727
29958
|
/**
|
|
@@ -29875,6 +30106,7 @@ function trackCall({ command, flags, durationMs, outcome, run, ci, cliEnvironmen
|
|
|
29875
30106
|
environment,
|
|
29876
30107
|
endpoint_host: endpointHost(endpoint)
|
|
29877
30108
|
})),
|
|
30109
|
+
...unsupportedProperties(run),
|
|
29878
30110
|
cli_version: VERSION,
|
|
29879
30111
|
cli_environment: cliEnvironment,
|
|
29880
30112
|
node_version: process.version,
|
|
@@ -29892,11 +30124,35 @@ function trackCall({ command, flags, durationMs, outcome, run, ci, cliEnvironmen
|
|
|
29892
30124
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
29893
30125
|
};
|
|
29894
30126
|
}
|
|
30127
|
+
/**
|
|
30128
|
+
* The unsupported fields over all targets, counted by type and reason, and
|
|
30129
|
+
* the models with a panel the CLI cannot read. None when nothing read live.
|
|
30130
|
+
*/
|
|
30131
|
+
function unsupportedProperties({ unsupported }) {
|
|
30132
|
+
if (unsupported.size === 0) return {};
|
|
30133
|
+
const reads = [...unsupported.values()];
|
|
30134
|
+
const counts = /* @__PURE__ */ new Map();
|
|
30135
|
+
for (const { type, reason } of reads.flatMap(({ fields }) => fields)) {
|
|
30136
|
+
const key = `${type} ${reason}`;
|
|
30137
|
+
const entry = counts.get(key) ?? {
|
|
30138
|
+
type,
|
|
30139
|
+
reason,
|
|
30140
|
+
count: 0
|
|
30141
|
+
};
|
|
30142
|
+
entry.count += 1;
|
|
30143
|
+
counts.set(key, entry);
|
|
30144
|
+
}
|
|
30145
|
+
return {
|
|
30146
|
+
unsupported_fields: [...counts.values()].toSorted((a, b) => a.type.localeCompare(b.type) || a.reason.localeCompare(b.reason)),
|
|
30147
|
+
models_with_unsupported_sidebar: reads.reduce((sum, read) => sum + read.modelsWithUnsupportedSidebar, 0)
|
|
30148
|
+
};
|
|
30149
|
+
}
|
|
29895
30150
|
//#endregion
|
|
29896
30151
|
//#region src/telemetry/telemetry.ts
|
|
29897
30152
|
/**
|
|
29898
30153
|
* Runs the command with reporting around it and hands back its exit code.
|
|
29899
|
-
* A crash
|
|
30154
|
+
* A crash, every failed migration, every apply that did not converge and
|
|
30155
|
+
* every fault of the management API go to Sentry; the crash is rethrown. A
|
|
29900
30156
|
* command that got as far as its action sends one usage event. Sends never
|
|
29901
30157
|
* fail the command and are dropped after `timeoutMs`.
|
|
29902
30158
|
*/
|
|
@@ -29959,7 +30215,7 @@ function outcomeOf({ crash, run, exitCode }) {
|
|
|
29959
30215
|
return "failure";
|
|
29960
30216
|
}
|
|
29961
30217
|
async function reportErrors(run, crash, { cliEnvironment, fetch, timeoutMs, tags }) {
|
|
29962
|
-
if (crash === void 0 && run.failedMigrations.length === 0) return;
|
|
30218
|
+
if (crash === void 0 && run.failedMigrations.length === 0 && run.unconverged.length === 0 && run.serverFaults.length === 0) return;
|
|
29963
30219
|
const client = createSentryClient({
|
|
29964
30220
|
cliEnvironment,
|
|
29965
30221
|
fetch,
|
|
@@ -29967,15 +30223,71 @@ async function reportErrors(run, crash, { cliEnvironment, fetch, timeoutMs, tags
|
|
|
29967
30223
|
});
|
|
29968
30224
|
const scope = scopeOf(run, tags);
|
|
29969
30225
|
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
|
-
|
|
30226
|
+
for (const { target, id, migration, changes } of run.failedMigrations) {
|
|
30227
|
+
const cause = migration?.errors == null ? void 0 : causeOf(migration.errors);
|
|
30228
|
+
client.captureMessage(cause === void 0 ? "migration failed" : `migration failed: ${cause}`, "warning", void 0, scope.clone().setTags({
|
|
30229
|
+
project: target.project,
|
|
30230
|
+
hygraph_environment: target.environment,
|
|
30231
|
+
endpoint_host: endpointHost(target.endpoint),
|
|
30232
|
+
migration_id: id,
|
|
30233
|
+
migration_status: migration?.status ?? "unknown"
|
|
30234
|
+
}).setContext("migration", {
|
|
30235
|
+
errors: migration?.errors ?? null,
|
|
30236
|
+
changes
|
|
30237
|
+
}).setFingerprint(cause === void 0 ? ["migration-failed"] : ["migration-failed", cause]));
|
|
30238
|
+
}
|
|
30239
|
+
for (const unconverged of run.unconverged) {
|
|
30240
|
+
const { target, id, applied, remaining, attributes, refused } = unconverged;
|
|
30241
|
+
client.captureMessage("apply did not converge", "warning", void 0, scope.clone().setTags({
|
|
30242
|
+
project: target.project,
|
|
30243
|
+
hygraph_environment: target.environment,
|
|
30244
|
+
endpoint_host: endpointHost(target.endpoint),
|
|
30245
|
+
migration_id: id,
|
|
30246
|
+
migration_status: "SUCCESS"
|
|
30247
|
+
}).setContext("migration", { changes: applied }).setContext("remaining", {
|
|
30248
|
+
changes: remaining,
|
|
30249
|
+
attributes,
|
|
30250
|
+
refused
|
|
30251
|
+
}).setFingerprint(["apply-did-not-converge", ...causesOf(unconverged)]));
|
|
30252
|
+
}
|
|
30253
|
+
for (const fault of run.serverFaults) client.captureMessage("management API fault", "error", void 0, scope.clone().setTags({
|
|
30254
|
+
endpoint_host: endpointHost(fault.endpoint),
|
|
30255
|
+
operation: fault.operation,
|
|
30256
|
+
status: fault.status
|
|
30257
|
+
}).setContext("response", {
|
|
30258
|
+
status: fault.status,
|
|
30259
|
+
codes: fault.codes,
|
|
30260
|
+
request_ids: fault.requestIds
|
|
30261
|
+
}).setFingerprint([
|
|
30262
|
+
"management-api-fault",
|
|
30263
|
+
fault.operation,
|
|
30264
|
+
String(fault.status),
|
|
30265
|
+
...fault.codes
|
|
30266
|
+
]));
|
|
29977
30267
|
await client.flush(timeoutMs);
|
|
29978
30268
|
}
|
|
30269
|
+
/**
|
|
30270
|
+
* What an apply left behind, to group by: the attributes of the updates, the
|
|
30271
|
+
* kinds of the other changes, and the codes of the refusals.
|
|
30272
|
+
*/
|
|
30273
|
+
function causesOf({ remaining, attributes, refused }) {
|
|
30274
|
+
const updated = Object.keys(attributes);
|
|
30275
|
+
const kinds = Object.keys(remaining).filter((kind) => updated.length === 0 || !kind.startsWith("update"));
|
|
30276
|
+
return [.../* @__PURE__ */ new Set([
|
|
30277
|
+
...updated,
|
|
30278
|
+
...kinds,
|
|
30279
|
+
...refused
|
|
30280
|
+
])].toSorted();
|
|
30281
|
+
}
|
|
30282
|
+
/**
|
|
30283
|
+
* The server's message without the parts that change from one project to the
|
|
30284
|
+
* next, so that one cause is one Sentry issue with its own title. Quoted text and every word
|
|
30285
|
+
* that is not plain lowercase become `*`. A constraint name stays; so does
|
|
30286
|
+
* an apiId that is one lowercase word.
|
|
30287
|
+
*/
|
|
30288
|
+
function causeOf(errors) {
|
|
30289
|
+
return errors.replace(/"[^"]*"|`[^`]*`/g, "*").split(/\s+/).filter((word) => word !== "").map((word, index) => (index === 0 ? /^[A-Z]?[a-z_]+[.,:;]?$/ : /^[a-z_]+[.,:;]?$/).test(word) ? word : "*").join(" ");
|
|
30290
|
+
}
|
|
29979
30291
|
function scopeOf(run, { command, ci }) {
|
|
29980
30292
|
const join = (values) => [...new Set(values)].join(",");
|
|
29981
30293
|
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