@lovable.dev/workflows-sdk 0.0.0-dev.59 → 0.0.0-dev.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{branch-metadata-D1b9OmsG.js → branch-metadata-C8JF4mRD.js} +1 -1
- package/dist/cli/generate-manifests.d.ts +1 -0
- package/dist/cli/generate-manifests.js +30 -0
- package/dist/{context-escapes-CcYvmmKH.js → context-escapes-CaWQZiKA.js} +1 -1
- package/dist/{duplicate-ids-BZhMnS7n.js → duplicate-ids-piCSoy97.js} +1 -1
- package/dist/durable-ids-B8WBvR9R.js +2 -0
- package/dist/durable-ids-CdlFkNKw.js +4 -0
- package/dist/generate-DGdzUQcG.js +1251 -0
- package/dist/graph-C_Y_mGVf.js +2 -0
- package/dist/{graph-CwRl2SGh.js → graph-DSYE4aER.js} +2 -2
- package/dist/index.js +3 -3
- package/dist/{nested-operations-CoaLLZl0.js → nested-operations-CEA4t4q_.js} +1 -1
- package/dist/{operation-descriptions-DlYyD27h.js → operation-descriptions-BtUOwQoK.js} +1 -1
- package/dist/plugin-CXlzS4_y.js +379 -0
- package/dist/{step-metadata-CCsEws4V.js → step-metadata-DvieDJGl.js} +1 -1
- package/dist/vite.js +1 -360
- package/dist/{wait-deadlines-CCgWwxqQ.js → wait-deadlines-DULtPtuu.js} +1 -1
- package/dist/{generate-DI9qaUrI.js → workflow_manifest_pb-DnavtUll.js} +26 -1275
- package/package.json +4 -1
- package/dist/durable-ids-Cx341nJQ.js +0 -17
|
@@ -0,0 +1,1251 @@
|
|
|
1
|
+
import { $ as protoInt64, A as WorkflowManifestWeeklyCadenceV1Schema, B as base64Decode, F as fileDesc, G as BinaryReader, H as reflect, I as fromBinary, J as FieldError, K as BinaryWriter, L as readField$1, M as NullValue, N as StructSchema, O as WorkflowManifestV1Schema, P as ValueSchema, Q as scalarZeroValue, R as messageDesc, T as WorkflowManifestTriggerV1Schema, U as checkField, V as base64Encode, W as formatVal, X as create, Y as isFieldError, Z as isWrapperDesc, b as WorkflowManifestScheduleTriggerV1Schema, et as ScalarType, i as WorkflowManifestCadenceV1Schema, j as ListValueSchema, o as WorkflowManifestDailyCadenceV1Schema, p as WorkflowManifestMinutesCadenceV1Schema, q as WireType, u as WorkflowManifestHourlyCadenceV1Schema, z as protoCamelCase } from "./workflow_manifest_pb-DnavtUll.js";
|
|
2
|
+
import { createMiddleware, createWorkflow } from "@tanstack/workflow-core";
|
|
3
|
+
//#region src/core/identifier.ts
|
|
4
|
+
const WORKFLOW_ID_PATTERN = /^[a-z0-9][a-z0-9_-]{0,127}$/;
|
|
5
|
+
function assertIdentifier(kind, id) {
|
|
6
|
+
if (typeof id !== "string" || id.trim() === "" || id !== id.trim()) throw new Error(`@lovable.dev/workflows-sdk: ${kind} IDs must be non-empty and have no surrounding whitespace`);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/core/cadence.ts
|
|
10
|
+
const WEEKDAYS = [
|
|
11
|
+
"mon",
|
|
12
|
+
"tue",
|
|
13
|
+
"wed",
|
|
14
|
+
"thu",
|
|
15
|
+
"fri",
|
|
16
|
+
"sat",
|
|
17
|
+
"sun"
|
|
18
|
+
];
|
|
19
|
+
const MINUTE_INTERVALS = [
|
|
20
|
+
5,
|
|
21
|
+
10,
|
|
22
|
+
15,
|
|
23
|
+
20,
|
|
24
|
+
30
|
|
25
|
+
];
|
|
26
|
+
const WEEKDAY_NAMES = {
|
|
27
|
+
mon: "mon",
|
|
28
|
+
monday: "mon",
|
|
29
|
+
tue: "tue",
|
|
30
|
+
tuesday: "tue",
|
|
31
|
+
wed: "wed",
|
|
32
|
+
wednesday: "wed",
|
|
33
|
+
thu: "thu",
|
|
34
|
+
thursday: "thu",
|
|
35
|
+
fri: "fri",
|
|
36
|
+
friday: "fri",
|
|
37
|
+
sat: "sat",
|
|
38
|
+
saturday: "sat",
|
|
39
|
+
sun: "sun",
|
|
40
|
+
sunday: "sun"
|
|
41
|
+
};
|
|
42
|
+
function fail$1(message) {
|
|
43
|
+
throw new Error(`@lovable.dev/workflows-sdk: ${message}`);
|
|
44
|
+
}
|
|
45
|
+
function parseWeekday(value, label) {
|
|
46
|
+
const day = typeof value === "string" ? WEEKDAY_NAMES[value.toLowerCase()] : void 0;
|
|
47
|
+
if (day === void 0) fail$1(`${label} names an unknown day "${String(value)}"; use ${WEEKDAYS.join(", ")}`);
|
|
48
|
+
return day;
|
|
49
|
+
}
|
|
50
|
+
function parseWeekdays(value, label) {
|
|
51
|
+
if (!Array.isArray(value) || value.length === 0) fail$1(`${label} must be a non-empty list of days`);
|
|
52
|
+
return [...new Set(value.map((entry) => parseWeekday(entry, label)))].sort((a, b) => WEEKDAYS.indexOf(a) - WEEKDAYS.indexOf(b));
|
|
53
|
+
}
|
|
54
|
+
function parseHoursOfDay(value, label) {
|
|
55
|
+
if (!Array.isArray(value) || value.length === 0) fail$1(`${label} must be a non-empty list of hours`);
|
|
56
|
+
const entries = value;
|
|
57
|
+
for (const entry of entries) if (!Number.isInteger(entry) || entry < 0 || entry > 23) fail$1(`${label}: ${JSON.stringify(entry)} must be a whole hour from 0 to 23; the platform picks the minute`);
|
|
58
|
+
return [...new Set(entries)].sort((a, b) => a - b);
|
|
59
|
+
}
|
|
60
|
+
function hourly(options) {
|
|
61
|
+
if (options !== void 0) fail$1(`hourly() takes no options; the platform decides where in the hour a schedule runs`);
|
|
62
|
+
return { kind: "hourly" };
|
|
63
|
+
}
|
|
64
|
+
function every(options) {
|
|
65
|
+
if (typeof options === "string") fail$1(`every(${JSON.stringify(options)}) takes an object; write every({ minutes: 5 })`);
|
|
66
|
+
const intervals = MINUTE_INTERVALS.join(", ");
|
|
67
|
+
if (typeof options !== "object" || options === null || Object.keys(options).length !== 1 || !MINUTE_INTERVALS.includes(options.minutes)) fail$1(`every({ minutes }) takes exactly { minutes: ${intervals} }, got ${JSON.stringify(options)}; use hourly() or daily({ at }) for longer intervals`);
|
|
68
|
+
return {
|
|
69
|
+
kind: "minutes",
|
|
70
|
+
interval: options.minutes
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function daily(options) {
|
|
74
|
+
if (typeof options !== "object" || options === null || options.at === void 0) fail$1(`daily() requires { at: [9] }`);
|
|
75
|
+
return {
|
|
76
|
+
kind: "daily",
|
|
77
|
+
at: parseHoursOfDay(options.at, "daily({ at })")
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function weekly(options) {
|
|
81
|
+
if (typeof options !== "object" || options === null || options.on === void 0 || options.at === void 0) fail$1(`weekly() requires { on: ["mon"], at: [9] }`);
|
|
82
|
+
return {
|
|
83
|
+
kind: "weekly",
|
|
84
|
+
on: parseWeekdays(options.on, "weekly({ on })"),
|
|
85
|
+
at: parseHoursOfDay(options.at, "weekly({ at })")
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function isHourSet(value) {
|
|
89
|
+
if (!Array.isArray(value) || value.length === 0) return false;
|
|
90
|
+
return value.every((hour, index) => Number.isInteger(hour) && hour >= 0 && hour <= 23 && (index === 0 || hour > value[index - 1]));
|
|
91
|
+
}
|
|
92
|
+
function isWeekdaySet(value) {
|
|
93
|
+
if (!Array.isArray(value) || value.length === 0) return false;
|
|
94
|
+
return value.every((day, index) => WEEKDAYS.includes(day) && (index === 0 || WEEKDAYS.indexOf(day) > WEEKDAYS.indexOf(value[index - 1])));
|
|
95
|
+
}
|
|
96
|
+
function isCadence(value) {
|
|
97
|
+
if (typeof value !== "object" || value === null) return false;
|
|
98
|
+
const cadence = value;
|
|
99
|
+
if (cadence.kind === "hourly") return Object.keys(cadence).length === 1;
|
|
100
|
+
if (cadence.kind === "minutes") return Object.keys(cadence).length === 2 && MINUTE_INTERVALS.includes(cadence.interval);
|
|
101
|
+
if (cadence.kind === "daily") return Object.keys(cadence).length === 2 && isHourSet(cadence.at);
|
|
102
|
+
if (cadence.kind === "weekly") return Object.keys(cadence).length === 3 && isWeekdaySet(cadence.on) && isHourSet(cadence.at);
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/core/schedule.ts
|
|
107
|
+
const OVERLAP_POLICIES = [
|
|
108
|
+
"skip",
|
|
109
|
+
"allow",
|
|
110
|
+
"buffer-one"
|
|
111
|
+
];
|
|
112
|
+
function fail(message) {
|
|
113
|
+
throw new Error(`@lovable.dev/workflows-sdk: ${message}`);
|
|
114
|
+
}
|
|
115
|
+
const CANONICAL_ZONES = new Set(typeof Intl.supportedValuesOf === "function" ? Intl.supportedValuesOf("timeZone") : []);
|
|
116
|
+
function resolveTimeZone(schedule) {
|
|
117
|
+
const timeZone = schedule.timeZone;
|
|
118
|
+
if (typeof timeZone !== "string" || timeZone === "") fail(`schedule "${schedule.id}" needs a timeZone, such as "Europe/Stockholm" or "UTC"`);
|
|
119
|
+
if (timeZone !== "UTC" && CANONICAL_ZONES.size > 0 && !CANONICAL_ZONES.has(timeZone)) fail(`schedule "${schedule.id}" timeZone "${timeZone}" must be "UTC" or a canonical IANA name such as "Europe/Stockholm"; fixed offsets and aliases such as "EST", "GMT", "Etc/GMT+5", and "US/Pacific" are not accepted`);
|
|
120
|
+
new Intl.DateTimeFormat("en", { timeZone });
|
|
121
|
+
return timeZone;
|
|
122
|
+
}
|
|
123
|
+
function defineSchedule(schedule) {
|
|
124
|
+
assertIdentifier("schedule", schedule.id);
|
|
125
|
+
if (!isCadence(schedule.cadence)) fail(`schedule "${schedule.id}" cadence must come from every({ minutes }), hourly(), daily({ at }), or weekly({ on, at })`);
|
|
126
|
+
const cadence = schedule.cadence;
|
|
127
|
+
const timeZone = resolveTimeZone(schedule);
|
|
128
|
+
const overlapPolicy = schedule.overlapPolicy ?? "skip";
|
|
129
|
+
if (!OVERLAP_POLICIES.includes(overlapPolicy)) fail(`schedule "${schedule.id}" overlapPolicy must be one of ${OVERLAP_POLICIES.join(", ")}`);
|
|
130
|
+
const enabled = schedule.enabled ?? true;
|
|
131
|
+
if (typeof enabled !== "boolean") fail(`schedule "${schedule.id}" enabled must be a boolean`);
|
|
132
|
+
return {
|
|
133
|
+
...schedule,
|
|
134
|
+
type: "schedule",
|
|
135
|
+
cadence,
|
|
136
|
+
timeZone,
|
|
137
|
+
overlapPolicy,
|
|
138
|
+
enabled
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/core/workflow.ts
|
|
143
|
+
function createWorkflow$1(config) {
|
|
144
|
+
return createWorkflow(config);
|
|
145
|
+
}
|
|
146
|
+
function workflowVersions(current) {
|
|
147
|
+
const versions = /* @__PURE__ */ new Map();
|
|
148
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
149
|
+
const visit = (workflow) => {
|
|
150
|
+
if (visiting.has(workflow)) throw new Error(`@lovable.dev/workflows-sdk: workflow "${current.id}" has cyclic previousVersions`);
|
|
151
|
+
if (workflow.__kind !== "workflow" || typeof workflow.handler !== "function" || workflow.id !== current.id) throw new Error(`@lovable.dev/workflows-sdk: previousVersions must be completed definitions of workflow "${current.id}"`);
|
|
152
|
+
if (typeof workflow.version !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/.test(workflow.version)) throw new Error(`@lovable.dev/workflows-sdk: workflow "${current.id}" version must be 1–128 letters, digits, dots, hyphens or underscores, starting with a letter or digit`);
|
|
153
|
+
if (`${workflow.id}.${workflow.version}.json`.length > 255) throw new Error(`@lovable.dev/workflows-sdk: workflow "${current.id}" and version exceed the 255-character manifest filename limit`);
|
|
154
|
+
const version = workflow.version;
|
|
155
|
+
const existing = versions.get(version);
|
|
156
|
+
if (existing === workflow) return;
|
|
157
|
+
if (existing) throw new Error(`@lovable.dev/workflows-sdk: duplicate workflow version "${version}" for "${current.id}"`);
|
|
158
|
+
versions.set(version, workflow);
|
|
159
|
+
visiting.add(workflow);
|
|
160
|
+
for (const previous of workflow.previousVersions ?? []) visit(previous);
|
|
161
|
+
visiting.delete(workflow);
|
|
162
|
+
};
|
|
163
|
+
visit(current);
|
|
164
|
+
return [...versions.values()];
|
|
165
|
+
}
|
|
166
|
+
function registerWorkflows(definition) {
|
|
167
|
+
for (const key of Object.keys(definition)) {
|
|
168
|
+
if (key === "workflows" || key === "triggers") continue;
|
|
169
|
+
throw new Error(key === "schedules" ? `@lovable.dev/workflows-sdk: registerWorkflows() no longer takes "schedules"; rename the key to "triggers"` : `@lovable.dev/workflows-sdk: registerWorkflows() does not take "${key}"`);
|
|
170
|
+
}
|
|
171
|
+
const { workflows, triggers = [] } = definition;
|
|
172
|
+
const ids = /* @__PURE__ */ new Set();
|
|
173
|
+
for (const workflow of workflows) {
|
|
174
|
+
if (workflow.__kind !== "workflow" || typeof workflow.handler !== "function") throw new Error("@lovable.dev/workflows-sdk: expected a completed createWorkflow().handler() definition");
|
|
175
|
+
assertIdentifier("workflow", workflow.id);
|
|
176
|
+
if (!WORKFLOW_ID_PATTERN.test(workflow.id)) throw new Error("@lovable.dev/workflows-sdk: workflow names must be 1–128 lowercase letters, digits, hyphens or underscores, starting with a letter or digit");
|
|
177
|
+
if (ids.has(workflow.id)) throw new Error(`@lovable.dev/workflows-sdk: duplicate workflow ID "${workflow.id}"`);
|
|
178
|
+
ids.add(workflow.id);
|
|
179
|
+
workflowVersions(workflow);
|
|
180
|
+
}
|
|
181
|
+
const scheduleIds = /* @__PURE__ */ new Set();
|
|
182
|
+
const registeredTriggers = triggers.map((trigger) => {
|
|
183
|
+
const definition = defineSchedule(trigger);
|
|
184
|
+
if (scheduleIds.has(definition.id)) throw new Error(`@lovable.dev/workflows-sdk: duplicate schedule ID "${definition.id}"`);
|
|
185
|
+
if (!workflows.includes(definition.workflow)) throw new Error(`@lovable.dev/workflows-sdk: schedule "${definition.id}" references an unregistered workflow`);
|
|
186
|
+
scheduleIds.add(definition.id);
|
|
187
|
+
return definition;
|
|
188
|
+
});
|
|
189
|
+
return {
|
|
190
|
+
workflows: [...workflows],
|
|
191
|
+
triggers: registeredTriggers
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Describes the message google.protobuf.Any.
|
|
196
|
+
* Use `create(AnySchema)` to create a new message.
|
|
197
|
+
*/
|
|
198
|
+
const AnySchema = /*@__PURE__*/ messageDesc(/* @__PURE__ */ fileDesc("Chlnb29nbGUvcHJvdG9idWYvYW55LnByb3RvEg9nb29nbGUucHJvdG9idWYiJgoDQW55EhAKCHR5cGVfdXJsGAEgASgJEg0KBXZhbHVlGAIgASgMQnYKE2NvbS5nb29nbGUucHJvdG9idWZCCEFueVByb3RvUAFaLGdvb2dsZS5nb2xhbmcub3JnL3Byb3RvYnVmL3R5cGVzL2tub3duL2FueXBiogIDR1BCqgIeR29vZ2xlLlByb3RvYnVmLldlbGxLbm93blR5cGVzYgZwcm90bzM"), 0);
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@bufbuild/protobuf/2.10.1/b0955b226816adda68977638196f96a6e65cec2605734621338f49f7ea29042e/node_modules/@bufbuild/protobuf/dist/esm/to-binary.js
|
|
201
|
+
const LEGACY_REQUIRED$1 = 3;
|
|
202
|
+
const writeDefaults = { writeUnknownFields: true };
|
|
203
|
+
function makeWriteOptions$1(options) {
|
|
204
|
+
return options ? Object.assign(Object.assign({}, writeDefaults), options) : writeDefaults;
|
|
205
|
+
}
|
|
206
|
+
function toBinary(schema, message, options) {
|
|
207
|
+
return writeFields(new BinaryWriter(), makeWriteOptions$1(options), reflect(schema, message)).finish();
|
|
208
|
+
}
|
|
209
|
+
function writeFields(writer, opts, msg) {
|
|
210
|
+
var _a;
|
|
211
|
+
for (const f of msg.sortedFields) {
|
|
212
|
+
if (!msg.isSet(f)) {
|
|
213
|
+
if (f.presence == LEGACY_REQUIRED$1) throw new Error(`cannot encode ${f} to binary: required field not set`);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
writeField(writer, opts, msg, f);
|
|
217
|
+
}
|
|
218
|
+
if (opts.writeUnknownFields) for (const { no, wireType, data } of (_a = msg.getUnknown()) !== null && _a !== void 0 ? _a : []) writer.tag(no, wireType).raw(data);
|
|
219
|
+
return writer;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* @private
|
|
223
|
+
*/
|
|
224
|
+
function writeField(writer, opts, msg, field) {
|
|
225
|
+
var _a;
|
|
226
|
+
switch (field.fieldKind) {
|
|
227
|
+
case "scalar":
|
|
228
|
+
case "enum":
|
|
229
|
+
writeScalar(writer, msg.desc.typeName, field.name, (_a = field.scalar) !== null && _a !== void 0 ? _a : ScalarType.INT32, field.number, msg.get(field));
|
|
230
|
+
break;
|
|
231
|
+
case "list":
|
|
232
|
+
writeListField(writer, opts, field, msg.get(field));
|
|
233
|
+
break;
|
|
234
|
+
case "message":
|
|
235
|
+
writeMessageField(writer, opts, field, msg.get(field));
|
|
236
|
+
break;
|
|
237
|
+
case "map":
|
|
238
|
+
for (const [key, val] of msg.get(field)) writeMapEntry(writer, opts, field, key, val);
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function writeScalar(writer, msgName, fieldName, scalarType, fieldNo, value) {
|
|
243
|
+
writeScalarValue(writer.tag(fieldNo, writeTypeOfScalar(scalarType)), msgName, fieldName, scalarType, value);
|
|
244
|
+
}
|
|
245
|
+
function writeMessageField(writer, opts, field, message) {
|
|
246
|
+
if (field.delimitedEncoding) writeFields(writer.tag(field.number, WireType.StartGroup), opts, message).tag(field.number, WireType.EndGroup);
|
|
247
|
+
else writeFields(writer.tag(field.number, WireType.LengthDelimited).fork(), opts, message).join();
|
|
248
|
+
}
|
|
249
|
+
function writeListField(writer, opts, field, list) {
|
|
250
|
+
var _a;
|
|
251
|
+
if (field.listKind == "message") {
|
|
252
|
+
for (const item of list) writeMessageField(writer, opts, field, item);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const scalarType = (_a = field.scalar) !== null && _a !== void 0 ? _a : ScalarType.INT32;
|
|
256
|
+
if (field.packed) {
|
|
257
|
+
if (!list.size) return;
|
|
258
|
+
writer.tag(field.number, WireType.LengthDelimited).fork();
|
|
259
|
+
for (const item of list) writeScalarValue(writer, field.parent.typeName, field.name, scalarType, item);
|
|
260
|
+
writer.join();
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
for (const item of list) writeScalar(writer, field.parent.typeName, field.name, scalarType, field.number, item);
|
|
264
|
+
}
|
|
265
|
+
function writeMapEntry(writer, opts, field, key, value) {
|
|
266
|
+
var _a;
|
|
267
|
+
writer.tag(field.number, WireType.LengthDelimited).fork();
|
|
268
|
+
writeScalar(writer, field.parent.typeName, field.name, field.mapKey, 1, key);
|
|
269
|
+
switch (field.mapKind) {
|
|
270
|
+
case "scalar":
|
|
271
|
+
case "enum":
|
|
272
|
+
writeScalar(writer, field.parent.typeName, field.name, (_a = field.scalar) !== null && _a !== void 0 ? _a : ScalarType.INT32, 2, value);
|
|
273
|
+
break;
|
|
274
|
+
case "message":
|
|
275
|
+
writeFields(writer.tag(2, WireType.LengthDelimited).fork(), opts, value).join();
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
writer.join();
|
|
279
|
+
}
|
|
280
|
+
function writeScalarValue(writer, msgName, fieldName, type, value) {
|
|
281
|
+
try {
|
|
282
|
+
switch (type) {
|
|
283
|
+
case ScalarType.STRING:
|
|
284
|
+
writer.string(value);
|
|
285
|
+
break;
|
|
286
|
+
case ScalarType.BOOL:
|
|
287
|
+
writer.bool(value);
|
|
288
|
+
break;
|
|
289
|
+
case ScalarType.DOUBLE:
|
|
290
|
+
writer.double(value);
|
|
291
|
+
break;
|
|
292
|
+
case ScalarType.FLOAT:
|
|
293
|
+
writer.float(value);
|
|
294
|
+
break;
|
|
295
|
+
case ScalarType.INT32:
|
|
296
|
+
writer.int32(value);
|
|
297
|
+
break;
|
|
298
|
+
case ScalarType.INT64:
|
|
299
|
+
writer.int64(value);
|
|
300
|
+
break;
|
|
301
|
+
case ScalarType.UINT64:
|
|
302
|
+
writer.uint64(value);
|
|
303
|
+
break;
|
|
304
|
+
case ScalarType.FIXED64:
|
|
305
|
+
writer.fixed64(value);
|
|
306
|
+
break;
|
|
307
|
+
case ScalarType.BYTES:
|
|
308
|
+
writer.bytes(value);
|
|
309
|
+
break;
|
|
310
|
+
case ScalarType.FIXED32:
|
|
311
|
+
writer.fixed32(value);
|
|
312
|
+
break;
|
|
313
|
+
case ScalarType.SFIXED32:
|
|
314
|
+
writer.sfixed32(value);
|
|
315
|
+
break;
|
|
316
|
+
case ScalarType.SFIXED64:
|
|
317
|
+
writer.sfixed64(value);
|
|
318
|
+
break;
|
|
319
|
+
case ScalarType.SINT64:
|
|
320
|
+
writer.sint64(value);
|
|
321
|
+
break;
|
|
322
|
+
case ScalarType.UINT32:
|
|
323
|
+
writer.uint32(value);
|
|
324
|
+
break;
|
|
325
|
+
case ScalarType.SINT32:
|
|
326
|
+
writer.sint32(value);
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
} catch (e) {
|
|
330
|
+
if (e instanceof Error) throw new Error(`cannot encode field ${msgName}.${fieldName} to binary: ${e.message}`);
|
|
331
|
+
throw e;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function writeTypeOfScalar(type) {
|
|
335
|
+
switch (type) {
|
|
336
|
+
case ScalarType.BYTES:
|
|
337
|
+
case ScalarType.STRING: return WireType.LengthDelimited;
|
|
338
|
+
case ScalarType.DOUBLE:
|
|
339
|
+
case ScalarType.FIXED64:
|
|
340
|
+
case ScalarType.SFIXED64: return WireType.Bit64;
|
|
341
|
+
case ScalarType.FIXED32:
|
|
342
|
+
case ScalarType.SFIXED32:
|
|
343
|
+
case ScalarType.FLOAT: return WireType.Bit32;
|
|
344
|
+
default: return WireType.Varint;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@bufbuild/protobuf/2.10.1/b0955b226816adda68977638196f96a6e65cec2605734621338f49f7ea29042e/node_modules/@bufbuild/protobuf/dist/esm/wkt/any.js
|
|
349
|
+
function anyPack(schema, message, into) {
|
|
350
|
+
let ret = false;
|
|
351
|
+
if (!into) {
|
|
352
|
+
into = create(AnySchema);
|
|
353
|
+
ret = true;
|
|
354
|
+
}
|
|
355
|
+
into.value = toBinary(schema, message);
|
|
356
|
+
into.typeUrl = typeNameToUrl(message.$typeName);
|
|
357
|
+
return ret ? into : void 0;
|
|
358
|
+
}
|
|
359
|
+
function anyIs(any, descOrTypeName) {
|
|
360
|
+
if (any.typeUrl === "") return false;
|
|
361
|
+
return (typeof descOrTypeName == "string" ? descOrTypeName : descOrTypeName.typeName) === typeUrlToName(any.typeUrl);
|
|
362
|
+
}
|
|
363
|
+
function anyUnpack(any, registryOrMessageDesc) {
|
|
364
|
+
if (any.typeUrl === "") return;
|
|
365
|
+
const desc = registryOrMessageDesc.kind == "message" ? registryOrMessageDesc : registryOrMessageDesc.getMessage(typeUrlToName(any.typeUrl));
|
|
366
|
+
if (!desc || !anyIs(any, desc)) return;
|
|
367
|
+
return fromBinary(desc, any.value);
|
|
368
|
+
}
|
|
369
|
+
function typeNameToUrl(name) {
|
|
370
|
+
return `type.googleapis.com/${name}`;
|
|
371
|
+
}
|
|
372
|
+
function typeUrlToName(url) {
|
|
373
|
+
const slash = url.lastIndexOf("/");
|
|
374
|
+
const name = slash >= 0 ? url.substring(slash + 1) : url;
|
|
375
|
+
if (!name.length) throw new Error(`invalid type url: ${url}`);
|
|
376
|
+
return name;
|
|
377
|
+
}
|
|
378
|
+
//#endregion
|
|
379
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@bufbuild/protobuf/2.10.1/b0955b226816adda68977638196f96a6e65cec2605734621338f49f7ea29042e/node_modules/@bufbuild/protobuf/dist/esm/extensions.js
|
|
380
|
+
/**
|
|
381
|
+
* Retrieve an extension value from a message.
|
|
382
|
+
*
|
|
383
|
+
* The function never returns undefined. Use hasExtension() to check whether an
|
|
384
|
+
* extension is set. If the extension is not set, this function returns the
|
|
385
|
+
* default value (if one was specified in the protobuf source), or the zero value
|
|
386
|
+
* (for example `0` for numeric types, `[]` for repeated extension fields, and
|
|
387
|
+
* an empty message instance for message fields).
|
|
388
|
+
*
|
|
389
|
+
* Extensions are stored as unknown fields on a message. To mutate an extension
|
|
390
|
+
* value, make sure to store the new value with setExtension() after mutating.
|
|
391
|
+
*
|
|
392
|
+
* If the extension does not extend the given message, an error is raised.
|
|
393
|
+
*/
|
|
394
|
+
function getExtension(message, extension) {
|
|
395
|
+
assertExtendee(extension, message);
|
|
396
|
+
const ufs = filterUnknownFields(message.$unknown, extension);
|
|
397
|
+
const [container, field, get] = createExtensionContainer(extension);
|
|
398
|
+
for (const uf of ufs) readField$1(container, new BinaryReader(uf.data), field, uf.wireType, { readUnknownFields: true });
|
|
399
|
+
return get();
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Set an extension value on a message. If the message already has a value for
|
|
403
|
+
* this extension, the value is replaced.
|
|
404
|
+
*
|
|
405
|
+
* If the extension does not extend the given message, an error is raised.
|
|
406
|
+
*/
|
|
407
|
+
function setExtension(message, extension, value) {
|
|
408
|
+
var _a;
|
|
409
|
+
assertExtendee(extension, message);
|
|
410
|
+
const ufs = ((_a = message.$unknown) !== null && _a !== void 0 ? _a : []).filter((uf) => uf.no !== extension.number);
|
|
411
|
+
const [container, field] = createExtensionContainer(extension, value);
|
|
412
|
+
const writer = new BinaryWriter();
|
|
413
|
+
writeField(writer, { writeUnknownFields: true }, container, field);
|
|
414
|
+
const reader = new BinaryReader(writer.finish());
|
|
415
|
+
while (reader.pos < reader.len) {
|
|
416
|
+
const [no, wireType] = reader.tag();
|
|
417
|
+
const data = reader.skip(wireType, no);
|
|
418
|
+
ufs.push({
|
|
419
|
+
no,
|
|
420
|
+
wireType,
|
|
421
|
+
data
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
message.$unknown = ufs;
|
|
425
|
+
}
|
|
426
|
+
function filterUnknownFields(unknownFields, extension) {
|
|
427
|
+
if (unknownFields === void 0) return [];
|
|
428
|
+
if (extension.fieldKind === "enum" || extension.fieldKind === "scalar") {
|
|
429
|
+
for (let i = unknownFields.length - 1; i >= 0; --i) if (unknownFields[i].no == extension.number) return [unknownFields[i]];
|
|
430
|
+
return [];
|
|
431
|
+
}
|
|
432
|
+
return unknownFields.filter((uf) => uf.no === extension.number);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* @private
|
|
436
|
+
*/
|
|
437
|
+
function createExtensionContainer(extension, value) {
|
|
438
|
+
const localName = extension.typeName;
|
|
439
|
+
const field = Object.assign(Object.assign({}, extension), {
|
|
440
|
+
kind: "field",
|
|
441
|
+
parent: extension.extendee,
|
|
442
|
+
localName
|
|
443
|
+
});
|
|
444
|
+
const desc = Object.assign(Object.assign({}, extension.extendee), {
|
|
445
|
+
fields: [field],
|
|
446
|
+
members: [field],
|
|
447
|
+
oneofs: []
|
|
448
|
+
});
|
|
449
|
+
const container = create(desc, value !== void 0 ? { [localName]: value } : void 0);
|
|
450
|
+
return [
|
|
451
|
+
reflect(desc, container),
|
|
452
|
+
field,
|
|
453
|
+
() => {
|
|
454
|
+
const value = container[localName];
|
|
455
|
+
if (value === void 0) {
|
|
456
|
+
const desc = extension.message;
|
|
457
|
+
if (isWrapperDesc(desc)) return scalarZeroValue(desc.fields[0].scalar, desc.fields[0].longAsString);
|
|
458
|
+
return create(desc);
|
|
459
|
+
}
|
|
460
|
+
return value;
|
|
461
|
+
}
|
|
462
|
+
];
|
|
463
|
+
}
|
|
464
|
+
function assertExtendee(extension, message) {
|
|
465
|
+
if (extension.extendee.typeName != message.$typeName) throw new Error(`extension ${extension.typeName} can only be applied to message ${extension.extendee.typeName}`);
|
|
466
|
+
}
|
|
467
|
+
//#endregion
|
|
468
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@bufbuild/protobuf/2.10.1/b0955b226816adda68977638196f96a6e65cec2605734621338f49f7ea29042e/node_modules/@bufbuild/protobuf/dist/esm/to-json.js
|
|
469
|
+
const LEGACY_REQUIRED = 3;
|
|
470
|
+
const IMPLICIT = 2;
|
|
471
|
+
const jsonWriteDefaults = {
|
|
472
|
+
alwaysEmitImplicit: false,
|
|
473
|
+
enumAsInteger: false,
|
|
474
|
+
useProtoFieldName: false
|
|
475
|
+
};
|
|
476
|
+
function makeWriteOptions(options) {
|
|
477
|
+
return options ? Object.assign(Object.assign({}, jsonWriteDefaults), options) : jsonWriteDefaults;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Serialize the message to a JSON value, a JavaScript value that can be
|
|
481
|
+
* passed to JSON.stringify().
|
|
482
|
+
*/
|
|
483
|
+
function toJson$1(schema, message, options) {
|
|
484
|
+
return reflectToJson(reflect(schema, message), makeWriteOptions(options));
|
|
485
|
+
}
|
|
486
|
+
function reflectToJson(msg, opts) {
|
|
487
|
+
var _a;
|
|
488
|
+
const wktJson = tryWktToJson(msg, opts);
|
|
489
|
+
if (wktJson !== void 0) return wktJson;
|
|
490
|
+
const json = {};
|
|
491
|
+
for (const f of msg.sortedFields) {
|
|
492
|
+
if (!msg.isSet(f)) {
|
|
493
|
+
if (f.presence == LEGACY_REQUIRED) throw new Error(`cannot encode ${f} to JSON: required field not set`);
|
|
494
|
+
if (!opts.alwaysEmitImplicit || f.presence !== IMPLICIT) continue;
|
|
495
|
+
}
|
|
496
|
+
const jsonValue = fieldToJson(f, msg.get(f), opts);
|
|
497
|
+
if (jsonValue !== void 0) json[jsonName(f, opts)] = jsonValue;
|
|
498
|
+
}
|
|
499
|
+
if (opts.registry) {
|
|
500
|
+
const tagSeen = /* @__PURE__ */ new Set();
|
|
501
|
+
for (const { no } of (_a = msg.getUnknown()) !== null && _a !== void 0 ? _a : []) if (!tagSeen.has(no)) {
|
|
502
|
+
tagSeen.add(no);
|
|
503
|
+
const extension = opts.registry.getExtensionFor(msg.desc, no);
|
|
504
|
+
if (!extension) continue;
|
|
505
|
+
const [container, field] = createExtensionContainer(extension, getExtension(msg.message, extension));
|
|
506
|
+
const jsonValue = fieldToJson(field, container.get(field), opts);
|
|
507
|
+
if (jsonValue !== void 0) json[extension.jsonName] = jsonValue;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return json;
|
|
511
|
+
}
|
|
512
|
+
function fieldToJson(f, val, opts) {
|
|
513
|
+
switch (f.fieldKind) {
|
|
514
|
+
case "scalar": return scalarToJson(f, val);
|
|
515
|
+
case "message": return reflectToJson(val, opts);
|
|
516
|
+
case "enum": return enumToJsonInternal(f.enum, val, opts.enumAsInteger);
|
|
517
|
+
case "list": return listToJson(val, opts);
|
|
518
|
+
case "map": return mapToJson(val, opts);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
function mapToJson(map, opts) {
|
|
522
|
+
const f = map.field();
|
|
523
|
+
const jsonObj = {};
|
|
524
|
+
switch (f.mapKind) {
|
|
525
|
+
case "scalar":
|
|
526
|
+
for (const [entryKey, entryValue] of map) jsonObj[entryKey] = scalarToJson(f, entryValue);
|
|
527
|
+
break;
|
|
528
|
+
case "message":
|
|
529
|
+
for (const [entryKey, entryValue] of map) jsonObj[entryKey] = reflectToJson(entryValue, opts);
|
|
530
|
+
break;
|
|
531
|
+
case "enum":
|
|
532
|
+
for (const [entryKey, entryValue] of map) jsonObj[entryKey] = enumToJsonInternal(f.enum, entryValue, opts.enumAsInteger);
|
|
533
|
+
break;
|
|
534
|
+
}
|
|
535
|
+
return opts.alwaysEmitImplicit || map.size > 0 ? jsonObj : void 0;
|
|
536
|
+
}
|
|
537
|
+
function listToJson(list, opts) {
|
|
538
|
+
const f = list.field();
|
|
539
|
+
const jsonArr = [];
|
|
540
|
+
switch (f.listKind) {
|
|
541
|
+
case "scalar":
|
|
542
|
+
for (const item of list) jsonArr.push(scalarToJson(f, item));
|
|
543
|
+
break;
|
|
544
|
+
case "enum":
|
|
545
|
+
for (const item of list) jsonArr.push(enumToJsonInternal(f.enum, item, opts.enumAsInteger));
|
|
546
|
+
break;
|
|
547
|
+
case "message":
|
|
548
|
+
for (const item of list) jsonArr.push(reflectToJson(item, opts));
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
return opts.alwaysEmitImplicit || jsonArr.length > 0 ? jsonArr : void 0;
|
|
552
|
+
}
|
|
553
|
+
function enumToJsonInternal(desc, value, enumAsInteger) {
|
|
554
|
+
var _a;
|
|
555
|
+
if (typeof value != "number") throw new Error(`cannot encode ${desc} to JSON: expected number, got ${formatVal(value)}`);
|
|
556
|
+
if (desc.typeName == "google.protobuf.NullValue") return null;
|
|
557
|
+
if (enumAsInteger) return value;
|
|
558
|
+
const val = desc.value[value];
|
|
559
|
+
return (_a = val === null || val === void 0 ? void 0 : val.name) !== null && _a !== void 0 ? _a : value;
|
|
560
|
+
}
|
|
561
|
+
function scalarToJson(field, value) {
|
|
562
|
+
var _a, _b, _c, _d, _e, _f;
|
|
563
|
+
switch (field.scalar) {
|
|
564
|
+
case ScalarType.INT32:
|
|
565
|
+
case ScalarType.SFIXED32:
|
|
566
|
+
case ScalarType.SINT32:
|
|
567
|
+
case ScalarType.FIXED32:
|
|
568
|
+
case ScalarType.UINT32:
|
|
569
|
+
if (typeof value != "number") throw new Error(`cannot encode ${field} to JSON: ${(_a = checkField(field, value)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
570
|
+
return value;
|
|
571
|
+
case ScalarType.FLOAT:
|
|
572
|
+
case ScalarType.DOUBLE:
|
|
573
|
+
if (typeof value != "number") throw new Error(`cannot encode ${field} to JSON: ${(_b = checkField(field, value)) === null || _b === void 0 ? void 0 : _b.message}`);
|
|
574
|
+
if (Number.isNaN(value)) return "NaN";
|
|
575
|
+
if (value === Number.POSITIVE_INFINITY) return "Infinity";
|
|
576
|
+
if (value === Number.NEGATIVE_INFINITY) return "-Infinity";
|
|
577
|
+
return value;
|
|
578
|
+
case ScalarType.STRING:
|
|
579
|
+
if (typeof value != "string") throw new Error(`cannot encode ${field} to JSON: ${(_c = checkField(field, value)) === null || _c === void 0 ? void 0 : _c.message}`);
|
|
580
|
+
return value;
|
|
581
|
+
case ScalarType.BOOL:
|
|
582
|
+
if (typeof value != "boolean") throw new Error(`cannot encode ${field} to JSON: ${(_d = checkField(field, value)) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
583
|
+
return value;
|
|
584
|
+
case ScalarType.UINT64:
|
|
585
|
+
case ScalarType.FIXED64:
|
|
586
|
+
case ScalarType.INT64:
|
|
587
|
+
case ScalarType.SFIXED64:
|
|
588
|
+
case ScalarType.SINT64:
|
|
589
|
+
if (typeof value != "bigint" && typeof value != "string") throw new Error(`cannot encode ${field} to JSON: ${(_e = checkField(field, value)) === null || _e === void 0 ? void 0 : _e.message}`);
|
|
590
|
+
return value.toString();
|
|
591
|
+
case ScalarType.BYTES:
|
|
592
|
+
if (value instanceof Uint8Array) return base64Encode(value);
|
|
593
|
+
throw new Error(`cannot encode ${field} to JSON: ${(_f = checkField(field, value)) === null || _f === void 0 ? void 0 : _f.message}`);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
function jsonName(f, opts) {
|
|
597
|
+
return opts.useProtoFieldName ? f.name : f.jsonName;
|
|
598
|
+
}
|
|
599
|
+
function tryWktToJson(msg, opts) {
|
|
600
|
+
if (!msg.desc.typeName.startsWith("google.protobuf.")) return;
|
|
601
|
+
switch (msg.desc.typeName) {
|
|
602
|
+
case "google.protobuf.Any": return anyToJson(msg.message, opts);
|
|
603
|
+
case "google.protobuf.Timestamp": return timestampToJson(msg.message);
|
|
604
|
+
case "google.protobuf.Duration": return durationToJson(msg.message);
|
|
605
|
+
case "google.protobuf.FieldMask": return fieldMaskToJson(msg.message);
|
|
606
|
+
case "google.protobuf.Struct": return structToJson(msg.message);
|
|
607
|
+
case "google.protobuf.Value": return valueToJson(msg.message);
|
|
608
|
+
case "google.protobuf.ListValue": return listValueToJson(msg.message);
|
|
609
|
+
default:
|
|
610
|
+
if (isWrapperDesc(msg.desc)) {
|
|
611
|
+
const valueField = msg.desc.fields[0];
|
|
612
|
+
return scalarToJson(valueField, msg.get(valueField));
|
|
613
|
+
}
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
function anyToJson(val, opts) {
|
|
618
|
+
if (val.typeUrl === "") return {};
|
|
619
|
+
const { registry } = opts;
|
|
620
|
+
let message;
|
|
621
|
+
let desc;
|
|
622
|
+
if (registry) {
|
|
623
|
+
message = anyUnpack(val, registry);
|
|
624
|
+
if (message) desc = registry.getMessage(message.$typeName);
|
|
625
|
+
}
|
|
626
|
+
if (!desc || !message) throw new Error(`cannot encode message ${val.$typeName} to JSON: "${val.typeUrl}" is not in the type registry`);
|
|
627
|
+
let json = reflectToJson(reflect(desc, message), opts);
|
|
628
|
+
if (desc.typeName.startsWith("google.protobuf.") || json === null || Array.isArray(json) || typeof json !== "object") json = { value: json };
|
|
629
|
+
json["@type"] = val.typeUrl;
|
|
630
|
+
return json;
|
|
631
|
+
}
|
|
632
|
+
function durationToJson(val) {
|
|
633
|
+
const seconds = Number(val.seconds);
|
|
634
|
+
const nanos = val.nanos;
|
|
635
|
+
if (seconds > 315576e6 || seconds < -315576e6) throw new Error(`cannot encode message ${val.$typeName} to JSON: value out of range`);
|
|
636
|
+
if (seconds > 0 && nanos < 0 || seconds < 0 && nanos > 0) throw new Error(`cannot encode message ${val.$typeName} to JSON: nanos sign must match seconds sign`);
|
|
637
|
+
let text = val.seconds.toString();
|
|
638
|
+
if (nanos !== 0) {
|
|
639
|
+
let nanosStr = Math.abs(nanos).toString();
|
|
640
|
+
nanosStr = "0".repeat(9 - nanosStr.length) + nanosStr;
|
|
641
|
+
if (nanosStr.substring(3) === "000000") nanosStr = nanosStr.substring(0, 3);
|
|
642
|
+
else if (nanosStr.substring(6) === "000") nanosStr = nanosStr.substring(0, 6);
|
|
643
|
+
text += "." + nanosStr;
|
|
644
|
+
if (nanos < 0 && seconds == 0) text = "-" + text;
|
|
645
|
+
}
|
|
646
|
+
return text + "s";
|
|
647
|
+
}
|
|
648
|
+
function fieldMaskToJson(val) {
|
|
649
|
+
return val.paths.map((p) => {
|
|
650
|
+
if (p.match(/_[0-9]?_/g) || p.match(/[A-Z]/g)) throw new Error(`cannot encode message ${val.$typeName} to JSON: lowerCamelCase of path name "` + p + "\" is irreversible");
|
|
651
|
+
return protoCamelCase(p);
|
|
652
|
+
}).join(",");
|
|
653
|
+
}
|
|
654
|
+
function structToJson(val) {
|
|
655
|
+
const json = {};
|
|
656
|
+
for (const [k, v] of Object.entries(val.fields)) json[k] = valueToJson(v);
|
|
657
|
+
return json;
|
|
658
|
+
}
|
|
659
|
+
function valueToJson(val) {
|
|
660
|
+
switch (val.kind.case) {
|
|
661
|
+
case "nullValue": return null;
|
|
662
|
+
case "numberValue":
|
|
663
|
+
if (!Number.isFinite(val.kind.value)) throw new Error(`${val.$typeName} cannot be NaN or Infinity`);
|
|
664
|
+
return val.kind.value;
|
|
665
|
+
case "boolValue": return val.kind.value;
|
|
666
|
+
case "stringValue": return val.kind.value;
|
|
667
|
+
case "structValue": return structToJson(val.kind.value);
|
|
668
|
+
case "listValue": return listValueToJson(val.kind.value);
|
|
669
|
+
default: throw new Error(`${val.$typeName} must have a value`);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
function listValueToJson(val) {
|
|
673
|
+
return val.values.map(valueToJson);
|
|
674
|
+
}
|
|
675
|
+
function timestampToJson(val) {
|
|
676
|
+
const ms = Number(val.seconds) * 1e3;
|
|
677
|
+
if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z")) throw new Error(`cannot encode message ${val.$typeName} to JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`);
|
|
678
|
+
if (val.nanos < 0) throw new Error(`cannot encode message ${val.$typeName} to JSON: nanos must not be negative`);
|
|
679
|
+
if (val.nanos > 999999999) throw new Error(`cannot encode message ${val.$typeName} to JSON: nanos must not be greater than 99999999`);
|
|
680
|
+
let z = "Z";
|
|
681
|
+
if (val.nanos > 0) {
|
|
682
|
+
const nanosStr = (val.nanos + 1e9).toString().substring(1);
|
|
683
|
+
if (nanosStr.substring(3) === "000000") z = "." + nanosStr.substring(0, 3) + "Z";
|
|
684
|
+
else if (nanosStr.substring(6) === "000") z = "." + nanosStr.substring(0, 6) + "Z";
|
|
685
|
+
else z = "." + nanosStr + "Z";
|
|
686
|
+
}
|
|
687
|
+
return new Date(ms).toISOString().replace(".000Z", z);
|
|
688
|
+
}
|
|
689
|
+
//#endregion
|
|
690
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@bufbuild/protobuf/2.10.1/b0955b226816adda68977638196f96a6e65cec2605734621338f49f7ea29042e/node_modules/@bufbuild/protobuf/dist/esm/from-json.js
|
|
691
|
+
const jsonReadDefaults = { ignoreUnknownFields: false };
|
|
692
|
+
function makeReadOptions(options) {
|
|
693
|
+
return options ? Object.assign(Object.assign({}, jsonReadDefaults), options) : jsonReadDefaults;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Parse a message from a JSON value.
|
|
697
|
+
*/
|
|
698
|
+
function fromJson(schema, json, options) {
|
|
699
|
+
const msg = reflect(schema);
|
|
700
|
+
try {
|
|
701
|
+
readMessage(msg, json, makeReadOptions(options));
|
|
702
|
+
} catch (e) {
|
|
703
|
+
if (isFieldError(e)) throw new Error(`cannot decode ${e.field()} from JSON: ${e.message}`, { cause: e });
|
|
704
|
+
throw e;
|
|
705
|
+
}
|
|
706
|
+
return msg.message;
|
|
707
|
+
}
|
|
708
|
+
function readMessage(msg, json, opts) {
|
|
709
|
+
var _a;
|
|
710
|
+
if (tryWktFromJson(msg, json, opts)) return;
|
|
711
|
+
if (json == null || Array.isArray(json) || typeof json != "object") throw new Error(`cannot decode ${msg.desc} from JSON: ${formatVal(json)}`);
|
|
712
|
+
const oneofSeen = /* @__PURE__ */ new Map();
|
|
713
|
+
const jsonNames = /* @__PURE__ */ new Map();
|
|
714
|
+
for (const field of msg.desc.fields) jsonNames.set(field.name, field).set(field.jsonName, field);
|
|
715
|
+
for (const [jsonKey, jsonValue] of Object.entries(json)) {
|
|
716
|
+
const field = jsonNames.get(jsonKey);
|
|
717
|
+
if (field) {
|
|
718
|
+
if (field.oneof) {
|
|
719
|
+
if (jsonValue === null && field.fieldKind == "scalar") continue;
|
|
720
|
+
const seen = oneofSeen.get(field.oneof);
|
|
721
|
+
if (seen !== void 0) throw new FieldError(field.oneof, `oneof set multiple times by ${seen.name} and ${field.name}`);
|
|
722
|
+
oneofSeen.set(field.oneof, field);
|
|
723
|
+
}
|
|
724
|
+
readField(msg, field, jsonValue, opts);
|
|
725
|
+
} else {
|
|
726
|
+
let extension = void 0;
|
|
727
|
+
if (jsonKey.startsWith("[") && jsonKey.endsWith("]") && (extension = (_a = opts.registry) === null || _a === void 0 ? void 0 : _a.getExtension(jsonKey.substring(1, jsonKey.length - 1))) && extension.extendee.typeName === msg.desc.typeName) {
|
|
728
|
+
const [container, field, get] = createExtensionContainer(extension);
|
|
729
|
+
readField(container, field, jsonValue, opts);
|
|
730
|
+
setExtension(msg.message, extension, get());
|
|
731
|
+
}
|
|
732
|
+
if (!extension && !opts.ignoreUnknownFields) throw new Error(`cannot decode ${msg.desc} from JSON: key "${jsonKey}" is unknown`);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
function readField(msg, field, json, opts) {
|
|
737
|
+
switch (field.fieldKind) {
|
|
738
|
+
case "scalar":
|
|
739
|
+
readScalarField(msg, field, json);
|
|
740
|
+
break;
|
|
741
|
+
case "enum":
|
|
742
|
+
readEnumField(msg, field, json, opts);
|
|
743
|
+
break;
|
|
744
|
+
case "message":
|
|
745
|
+
readMessageField(msg, field, json, opts);
|
|
746
|
+
break;
|
|
747
|
+
case "list":
|
|
748
|
+
readListField(msg.get(field), json, opts);
|
|
749
|
+
break;
|
|
750
|
+
case "map":
|
|
751
|
+
readMapField(msg.get(field), json, opts);
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
function readMapField(map, json, opts) {
|
|
756
|
+
if (json === null) return;
|
|
757
|
+
const field = map.field();
|
|
758
|
+
if (typeof json != "object" || Array.isArray(json)) throw new FieldError(field, "expected object, got " + formatVal(json));
|
|
759
|
+
for (const [jsonMapKey, jsonMapValue] of Object.entries(json)) {
|
|
760
|
+
if (jsonMapValue === null) throw new FieldError(field, "map value must not be null");
|
|
761
|
+
let value;
|
|
762
|
+
switch (field.mapKind) {
|
|
763
|
+
case "message":
|
|
764
|
+
const msgValue = reflect(field.message);
|
|
765
|
+
readMessage(msgValue, jsonMapValue, opts);
|
|
766
|
+
value = msgValue;
|
|
767
|
+
break;
|
|
768
|
+
case "enum":
|
|
769
|
+
value = readEnum(field.enum, jsonMapValue, opts.ignoreUnknownFields, true);
|
|
770
|
+
if (value === tokenIgnoredUnknownEnum) return;
|
|
771
|
+
break;
|
|
772
|
+
case "scalar":
|
|
773
|
+
value = scalarFromJson(field, jsonMapValue, true);
|
|
774
|
+
break;
|
|
775
|
+
}
|
|
776
|
+
const key = mapKeyFromJson(field.mapKey, jsonMapKey);
|
|
777
|
+
map.set(key, value);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
function readListField(list, json, opts) {
|
|
781
|
+
if (json === null) return;
|
|
782
|
+
const field = list.field();
|
|
783
|
+
if (!Array.isArray(json)) throw new FieldError(field, "expected Array, got " + formatVal(json));
|
|
784
|
+
for (const jsonItem of json) {
|
|
785
|
+
if (jsonItem === null) throw new FieldError(field, "list item must not be null");
|
|
786
|
+
switch (field.listKind) {
|
|
787
|
+
case "message":
|
|
788
|
+
const msgValue = reflect(field.message);
|
|
789
|
+
readMessage(msgValue, jsonItem, opts);
|
|
790
|
+
list.add(msgValue);
|
|
791
|
+
break;
|
|
792
|
+
case "enum":
|
|
793
|
+
const enumValue = readEnum(field.enum, jsonItem, opts.ignoreUnknownFields, true);
|
|
794
|
+
if (enumValue !== tokenIgnoredUnknownEnum) list.add(enumValue);
|
|
795
|
+
break;
|
|
796
|
+
case "scalar":
|
|
797
|
+
list.add(scalarFromJson(field, jsonItem, true));
|
|
798
|
+
break;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
function readMessageField(msg, field, json, opts) {
|
|
803
|
+
if (json === null && field.message.typeName != "google.protobuf.Value") {
|
|
804
|
+
msg.clear(field);
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
const msgValue = msg.isSet(field) ? msg.get(field) : reflect(field.message);
|
|
808
|
+
readMessage(msgValue, json, opts);
|
|
809
|
+
msg.set(field, msgValue);
|
|
810
|
+
}
|
|
811
|
+
function readEnumField(msg, field, json, opts) {
|
|
812
|
+
const enumValue = readEnum(field.enum, json, opts.ignoreUnknownFields, false);
|
|
813
|
+
if (enumValue === tokenNull) msg.clear(field);
|
|
814
|
+
else if (enumValue !== tokenIgnoredUnknownEnum) msg.set(field, enumValue);
|
|
815
|
+
}
|
|
816
|
+
function readScalarField(msg, field, json) {
|
|
817
|
+
const scalarValue = scalarFromJson(field, json, false);
|
|
818
|
+
if (scalarValue === tokenNull) msg.clear(field);
|
|
819
|
+
else msg.set(field, scalarValue);
|
|
820
|
+
}
|
|
821
|
+
const tokenIgnoredUnknownEnum = Symbol();
|
|
822
|
+
function readEnum(desc, json, ignoreUnknownFields, nullAsZeroValue) {
|
|
823
|
+
if (json === null) {
|
|
824
|
+
if (desc.typeName == "google.protobuf.NullValue") return 0;
|
|
825
|
+
return nullAsZeroValue ? desc.values[0].number : tokenNull;
|
|
826
|
+
}
|
|
827
|
+
switch (typeof json) {
|
|
828
|
+
case "number":
|
|
829
|
+
if (Number.isInteger(json)) return json;
|
|
830
|
+
break;
|
|
831
|
+
case "string":
|
|
832
|
+
const value = desc.values.find((ev) => ev.name === json);
|
|
833
|
+
if (value !== void 0) return value.number;
|
|
834
|
+
if (ignoreUnknownFields) return tokenIgnoredUnknownEnum;
|
|
835
|
+
break;
|
|
836
|
+
}
|
|
837
|
+
throw new Error(`cannot decode ${desc} from JSON: ${formatVal(json)}`);
|
|
838
|
+
}
|
|
839
|
+
const tokenNull = Symbol();
|
|
840
|
+
function scalarFromJson(field, json, nullAsZeroValue) {
|
|
841
|
+
if (json === null) {
|
|
842
|
+
if (nullAsZeroValue) return scalarZeroValue(field.scalar, false);
|
|
843
|
+
return tokenNull;
|
|
844
|
+
}
|
|
845
|
+
switch (field.scalar) {
|
|
846
|
+
case ScalarType.DOUBLE:
|
|
847
|
+
case ScalarType.FLOAT:
|
|
848
|
+
if (json === "NaN") return NaN;
|
|
849
|
+
if (json === "Infinity") return Number.POSITIVE_INFINITY;
|
|
850
|
+
if (json === "-Infinity") return Number.NEGATIVE_INFINITY;
|
|
851
|
+
if (typeof json == "number") {
|
|
852
|
+
if (Number.isNaN(json)) throw new FieldError(field, "unexpected NaN number");
|
|
853
|
+
if (!Number.isFinite(json)) throw new FieldError(field, "unexpected infinite number");
|
|
854
|
+
break;
|
|
855
|
+
}
|
|
856
|
+
if (typeof json == "string") {
|
|
857
|
+
if (json === "") break;
|
|
858
|
+
if (json.trim().length !== json.length) break;
|
|
859
|
+
const float = Number(json);
|
|
860
|
+
if (!Number.isFinite(float)) break;
|
|
861
|
+
return float;
|
|
862
|
+
}
|
|
863
|
+
break;
|
|
864
|
+
case ScalarType.INT32:
|
|
865
|
+
case ScalarType.FIXED32:
|
|
866
|
+
case ScalarType.SFIXED32:
|
|
867
|
+
case ScalarType.SINT32:
|
|
868
|
+
case ScalarType.UINT32: return int32FromJson(json);
|
|
869
|
+
case ScalarType.BYTES:
|
|
870
|
+
if (typeof json == "string") {
|
|
871
|
+
if (json === "") return /* @__PURE__ */ new Uint8Array(0);
|
|
872
|
+
try {
|
|
873
|
+
return base64Decode(json);
|
|
874
|
+
} catch (e) {
|
|
875
|
+
throw new FieldError(field, e instanceof Error ? e.message : String(e));
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
break;
|
|
879
|
+
}
|
|
880
|
+
return json;
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* Try to parse a JSON value to a map key for the reflect API.
|
|
884
|
+
*
|
|
885
|
+
* Returns the input if the JSON value cannot be converted.
|
|
886
|
+
*/
|
|
887
|
+
function mapKeyFromJson(type, json) {
|
|
888
|
+
switch (type) {
|
|
889
|
+
case ScalarType.BOOL:
|
|
890
|
+
switch (json) {
|
|
891
|
+
case "true": return true;
|
|
892
|
+
case "false": return false;
|
|
893
|
+
}
|
|
894
|
+
return json;
|
|
895
|
+
case ScalarType.INT32:
|
|
896
|
+
case ScalarType.FIXED32:
|
|
897
|
+
case ScalarType.UINT32:
|
|
898
|
+
case ScalarType.SFIXED32:
|
|
899
|
+
case ScalarType.SINT32: return int32FromJson(json);
|
|
900
|
+
default: return json;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Try to parse a JSON value to a 32-bit integer for the reflect API.
|
|
905
|
+
*
|
|
906
|
+
* Returns the input if the JSON value cannot be converted.
|
|
907
|
+
*/
|
|
908
|
+
function int32FromJson(json) {
|
|
909
|
+
if (typeof json == "string") {
|
|
910
|
+
if (json === "") return json;
|
|
911
|
+
if (json.trim().length !== json.length) return json;
|
|
912
|
+
const num = Number(json);
|
|
913
|
+
if (Number.isNaN(num)) return json;
|
|
914
|
+
return num;
|
|
915
|
+
}
|
|
916
|
+
return json;
|
|
917
|
+
}
|
|
918
|
+
function tryWktFromJson(msg, jsonValue, opts) {
|
|
919
|
+
if (!msg.desc.typeName.startsWith("google.protobuf.")) return false;
|
|
920
|
+
switch (msg.desc.typeName) {
|
|
921
|
+
case "google.protobuf.Any":
|
|
922
|
+
anyFromJson(msg.message, jsonValue, opts);
|
|
923
|
+
return true;
|
|
924
|
+
case "google.protobuf.Timestamp":
|
|
925
|
+
timestampFromJson(msg.message, jsonValue);
|
|
926
|
+
return true;
|
|
927
|
+
case "google.protobuf.Duration":
|
|
928
|
+
durationFromJson(msg.message, jsonValue);
|
|
929
|
+
return true;
|
|
930
|
+
case "google.protobuf.FieldMask":
|
|
931
|
+
fieldMaskFromJson(msg.message, jsonValue);
|
|
932
|
+
return true;
|
|
933
|
+
case "google.protobuf.Struct":
|
|
934
|
+
structFromJson(msg.message, jsonValue);
|
|
935
|
+
return true;
|
|
936
|
+
case "google.protobuf.Value":
|
|
937
|
+
valueFromJson(msg.message, jsonValue);
|
|
938
|
+
return true;
|
|
939
|
+
case "google.protobuf.ListValue":
|
|
940
|
+
listValueFromJson(msg.message, jsonValue);
|
|
941
|
+
return true;
|
|
942
|
+
default:
|
|
943
|
+
if (isWrapperDesc(msg.desc)) {
|
|
944
|
+
const valueField = msg.desc.fields[0];
|
|
945
|
+
if (jsonValue === null) msg.clear(valueField);
|
|
946
|
+
else msg.set(valueField, scalarFromJson(valueField, jsonValue, true));
|
|
947
|
+
return true;
|
|
948
|
+
}
|
|
949
|
+
return false;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
function anyFromJson(any, json, opts) {
|
|
953
|
+
var _a;
|
|
954
|
+
if (json === null || Array.isArray(json) || typeof json != "object") throw new Error(`cannot decode message ${any.$typeName} from JSON: expected object but got ${formatVal(json)}`);
|
|
955
|
+
if (Object.keys(json).length == 0) return;
|
|
956
|
+
const typeUrl = json["@type"];
|
|
957
|
+
if (typeof typeUrl != "string" || typeUrl == "") throw new Error(`cannot decode message ${any.$typeName} from JSON: "@type" is empty`);
|
|
958
|
+
const typeName = typeUrl.includes("/") ? typeUrl.substring(typeUrl.lastIndexOf("/") + 1) : typeUrl;
|
|
959
|
+
if (!typeName.length) throw new Error(`cannot decode message ${any.$typeName} from JSON: "@type" is invalid`);
|
|
960
|
+
const desc = (_a = opts.registry) === null || _a === void 0 ? void 0 : _a.getMessage(typeName);
|
|
961
|
+
if (!desc) throw new Error(`cannot decode message ${any.$typeName} from JSON: ${typeUrl} is not in the type registry`);
|
|
962
|
+
const msg = reflect(desc);
|
|
963
|
+
if (typeName.startsWith("google.protobuf.") && Object.prototype.hasOwnProperty.call(json, "value")) {
|
|
964
|
+
const value = json.value;
|
|
965
|
+
readMessage(msg, value, opts);
|
|
966
|
+
} else {
|
|
967
|
+
const copy = Object.assign({}, json);
|
|
968
|
+
delete copy["@type"];
|
|
969
|
+
readMessage(msg, copy, opts);
|
|
970
|
+
}
|
|
971
|
+
anyPack(msg.desc, msg.message, any);
|
|
972
|
+
}
|
|
973
|
+
function timestampFromJson(timestamp, json) {
|
|
974
|
+
if (typeof json !== "string") throw new Error(`cannot decode message ${timestamp.$typeName} from JSON: ${formatVal(json)}`);
|
|
975
|
+
const matches = json.match(/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:\.([0-9]{1,9}))?(?:Z|([+-][0-9][0-9]:[0-9][0-9]))$/);
|
|
976
|
+
if (!matches) throw new Error(`cannot decode message ${timestamp.$typeName} from JSON: invalid RFC 3339 string`);
|
|
977
|
+
const ms = Date.parse(matches[1] + "-" + matches[2] + "-" + matches[3] + "T" + matches[4] + ":" + matches[5] + ":" + matches[6] + (matches[8] ? matches[8] : "Z"));
|
|
978
|
+
if (Number.isNaN(ms)) throw new Error(`cannot decode message ${timestamp.$typeName} from JSON: invalid RFC 3339 string`);
|
|
979
|
+
if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z")) throw new Error(`cannot decode message ${timestamp.$typeName} from JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`);
|
|
980
|
+
timestamp.seconds = protoInt64.parse(ms / 1e3);
|
|
981
|
+
timestamp.nanos = 0;
|
|
982
|
+
if (matches[7]) timestamp.nanos = parseInt("1" + matches[7] + "0".repeat(9 - matches[7].length)) - 1e9;
|
|
983
|
+
}
|
|
984
|
+
function durationFromJson(duration, json) {
|
|
985
|
+
if (typeof json !== "string") throw new Error(`cannot decode message ${duration.$typeName} from JSON: ${formatVal(json)}`);
|
|
986
|
+
const match = json.match(/^(-?[0-9]+)(?:\.([0-9]+))?s/);
|
|
987
|
+
if (match === null) throw new Error(`cannot decode message ${duration.$typeName} from JSON: ${formatVal(json)}`);
|
|
988
|
+
const longSeconds = Number(match[1]);
|
|
989
|
+
if (longSeconds > 315576e6 || longSeconds < -315576e6) throw new Error(`cannot decode message ${duration.$typeName} from JSON: ${formatVal(json)}`);
|
|
990
|
+
duration.seconds = protoInt64.parse(longSeconds);
|
|
991
|
+
if (typeof match[2] !== "string") return;
|
|
992
|
+
const nanosStr = match[2] + "0".repeat(9 - match[2].length);
|
|
993
|
+
duration.nanos = parseInt(nanosStr);
|
|
994
|
+
if (longSeconds < 0 || Object.is(longSeconds, -0)) duration.nanos = -duration.nanos;
|
|
995
|
+
}
|
|
996
|
+
function fieldMaskFromJson(fieldMask, json) {
|
|
997
|
+
if (typeof json !== "string") throw new Error(`cannot decode message ${fieldMask.$typeName} from JSON: ${formatVal(json)}`);
|
|
998
|
+
if (json === "") return;
|
|
999
|
+
function camelToSnake(str) {
|
|
1000
|
+
if (str.includes("_")) throw new Error(`cannot decode message ${fieldMask.$typeName} from JSON: path names must be lowerCamelCase`);
|
|
1001
|
+
const sc = str.replace(/[A-Z]/g, (letter) => "_" + letter.toLowerCase());
|
|
1002
|
+
return sc[0] === "_" ? sc.substring(1) : sc;
|
|
1003
|
+
}
|
|
1004
|
+
fieldMask.paths = json.split(",").map(camelToSnake);
|
|
1005
|
+
}
|
|
1006
|
+
function structFromJson(struct, json) {
|
|
1007
|
+
if (typeof json != "object" || json == null || Array.isArray(json)) throw new Error(`cannot decode message ${struct.$typeName} from JSON ${formatVal(json)}`);
|
|
1008
|
+
for (const [k, v] of Object.entries(json)) {
|
|
1009
|
+
const parsedV = create(ValueSchema);
|
|
1010
|
+
valueFromJson(parsedV, v);
|
|
1011
|
+
struct.fields[k] = parsedV;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
function valueFromJson(value, json) {
|
|
1015
|
+
switch (typeof json) {
|
|
1016
|
+
case "number":
|
|
1017
|
+
value.kind = {
|
|
1018
|
+
case: "numberValue",
|
|
1019
|
+
value: json
|
|
1020
|
+
};
|
|
1021
|
+
break;
|
|
1022
|
+
case "string":
|
|
1023
|
+
value.kind = {
|
|
1024
|
+
case: "stringValue",
|
|
1025
|
+
value: json
|
|
1026
|
+
};
|
|
1027
|
+
break;
|
|
1028
|
+
case "boolean":
|
|
1029
|
+
value.kind = {
|
|
1030
|
+
case: "boolValue",
|
|
1031
|
+
value: json
|
|
1032
|
+
};
|
|
1033
|
+
break;
|
|
1034
|
+
case "object":
|
|
1035
|
+
if (json === null) value.kind = {
|
|
1036
|
+
case: "nullValue",
|
|
1037
|
+
value: NullValue.NULL_VALUE
|
|
1038
|
+
};
|
|
1039
|
+
else if (Array.isArray(json)) {
|
|
1040
|
+
const listValue = create(ListValueSchema);
|
|
1041
|
+
listValueFromJson(listValue, json);
|
|
1042
|
+
value.kind = {
|
|
1043
|
+
case: "listValue",
|
|
1044
|
+
value: listValue
|
|
1045
|
+
};
|
|
1046
|
+
} else {
|
|
1047
|
+
const struct = create(StructSchema);
|
|
1048
|
+
structFromJson(struct, json);
|
|
1049
|
+
value.kind = {
|
|
1050
|
+
case: "structValue",
|
|
1051
|
+
value: struct
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
break;
|
|
1055
|
+
default: throw new Error(`cannot decode message ${value.$typeName} from JSON ${formatVal(json)}`);
|
|
1056
|
+
}
|
|
1057
|
+
return value;
|
|
1058
|
+
}
|
|
1059
|
+
function listValueFromJson(listValue, json) {
|
|
1060
|
+
if (!Array.isArray(json)) throw new Error(`cannot decode message ${listValue.$typeName} from JSON ${formatVal(json)}`);
|
|
1061
|
+
for (const e of json) {
|
|
1062
|
+
const value = create(ValueSchema);
|
|
1063
|
+
valueFromJson(value, e);
|
|
1064
|
+
listValue.values.push(value);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
//#endregion
|
|
1068
|
+
//#region package.json
|
|
1069
|
+
var version = "0.0.0-dev.60";
|
|
1070
|
+
//#endregion
|
|
1071
|
+
//#region src/manifests/json.ts
|
|
1072
|
+
function toJson(value, jsonPath, ancestors = /* @__PURE__ */ new Set()) {
|
|
1073
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
1074
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
1075
|
+
if (typeof value !== "object" || ancestors.has(value)) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must contain finite, acyclic JSON values`);
|
|
1076
|
+
ancestors.add(value);
|
|
1077
|
+
try {
|
|
1078
|
+
if (Object.getOwnPropertySymbols(value).length > 0) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must not contain symbol keys`);
|
|
1079
|
+
if (Array.isArray(value)) {
|
|
1080
|
+
if (Object.keys(value).length !== value.length) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must be a dense JSON array without extra properties`);
|
|
1081
|
+
return Array.from(value, (item, index) => toJson(item, `${jsonPath}[${index}]`, ancestors));
|
|
1082
|
+
}
|
|
1083
|
+
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must contain plain JSON objects`);
|
|
1084
|
+
return Object.fromEntries(Object.keys(value).sort().map((key) => [key, toJson(value[key], `${jsonPath}.${key}`, ancestors)]));
|
|
1085
|
+
} finally {
|
|
1086
|
+
ancestors.delete(value);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
//#endregion
|
|
1090
|
+
//#region src/manifests/generate.ts
|
|
1091
|
+
function protoValue(value) {
|
|
1092
|
+
return fromJson(ValueSchema, value);
|
|
1093
|
+
}
|
|
1094
|
+
const MANIFEST_WEEKDAYS = {
|
|
1095
|
+
mon: 1,
|
|
1096
|
+
tue: 2,
|
|
1097
|
+
wed: 3,
|
|
1098
|
+
thu: 4,
|
|
1099
|
+
fri: 5,
|
|
1100
|
+
sat: 6,
|
|
1101
|
+
sun: 7
|
|
1102
|
+
};
|
|
1103
|
+
function manifestCadence(cadence) {
|
|
1104
|
+
if (cadence.kind === "hourly") return create(WorkflowManifestCadenceV1Schema, { kind: {
|
|
1105
|
+
case: "hourly",
|
|
1106
|
+
value: create(WorkflowManifestHourlyCadenceV1Schema)
|
|
1107
|
+
} });
|
|
1108
|
+
if (cadence.kind === "minutes") return create(WorkflowManifestCadenceV1Schema, { kind: {
|
|
1109
|
+
case: "minutes",
|
|
1110
|
+
value: create(WorkflowManifestMinutesCadenceV1Schema, { interval: cadence.interval })
|
|
1111
|
+
} });
|
|
1112
|
+
if (cadence.kind === "daily") return create(WorkflowManifestCadenceV1Schema, { kind: {
|
|
1113
|
+
case: "daily",
|
|
1114
|
+
value: create(WorkflowManifestDailyCadenceV1Schema, { hours: [...cadence.at] })
|
|
1115
|
+
} });
|
|
1116
|
+
return create(WorkflowManifestCadenceV1Schema, { kind: {
|
|
1117
|
+
case: "weekly",
|
|
1118
|
+
value: create(WorkflowManifestWeeklyCadenceV1Schema, {
|
|
1119
|
+
days: cadence.on.map((day) => MANIFEST_WEEKDAYS[day]),
|
|
1120
|
+
hours: [...cadence.at]
|
|
1121
|
+
})
|
|
1122
|
+
} });
|
|
1123
|
+
}
|
|
1124
|
+
function serializeSchema(schema, direction, label) {
|
|
1125
|
+
if (!schema) return void 0;
|
|
1126
|
+
const standard = schema["~standard"];
|
|
1127
|
+
if (typeof standard.jsonSchema?.[direction] !== "function") throw new Error(`@lovable.dev/workflows-sdk: ${label} must support Standard JSON Schema conversion`);
|
|
1128
|
+
try {
|
|
1129
|
+
return protoValue(toJson(standard.jsonSchema[direction]({ target: "draft-2020-12" }), label));
|
|
1130
|
+
} catch (cause) {
|
|
1131
|
+
throw new Error(`@lovable.dev/workflows-sdk: cannot serialize ${label}`, { cause });
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
async function generateManifests(definition, options = {}) {
|
|
1135
|
+
const { extractWorkflowGraph } = await import("./graph-C_Y_mGVf.js");
|
|
1136
|
+
const { findBranchMetadataIssues } = await import("./branch-metadata-C8JF4mRD.js");
|
|
1137
|
+
const { findWorkflowContextEscapes } = await import("./context-escapes-CaWQZiKA.js");
|
|
1138
|
+
const { findDuplicateOperationIds } = await import("./duplicate-ids-piCSoy97.js");
|
|
1139
|
+
const { DURABLE_ID_REQUIRED } = await import("./durable-ids-B8WBvR9R.js");
|
|
1140
|
+
const { findNestedDurableOperations } = await import("./nested-operations-CEA4t4q_.js");
|
|
1141
|
+
const { findOperationDescriptionIssues } = await import("./operation-descriptions-BtUOwQoK.js");
|
|
1142
|
+
const { findStepMetadataIssues } = await import("./step-metadata-DvieDJGl.js");
|
|
1143
|
+
const { findWaitDeadlineIssues } = await import("./wait-deadlines-DULtPtuu.js");
|
|
1144
|
+
const { WAIT_DEADLINE_REQUIRED } = await import("./wait-deadlines-DpK-Fgnd.js");
|
|
1145
|
+
const collection = registerWorkflows(definition);
|
|
1146
|
+
const manifests = [];
|
|
1147
|
+
for (const workflow of collection.workflows.flatMap(workflowVersions)) {
|
|
1148
|
+
const contextEscape = (await findWorkflowContextEscapes(workflow.handler))[0];
|
|
1149
|
+
if (contextEscape?.kind === "destructured") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" destructures its workflow context parameter; accept one context identifier and read its properties directly in the workflow handler`);
|
|
1150
|
+
if (contextEscape?.kind === "method") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses ${contextEscape.context}.${contextEscape.method} as a value; durable context methods must be called directly in the workflow handler`);
|
|
1151
|
+
if (contextEscape?.kind === "context") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses ${contextEscape.context} as a value; the workflow context cannot be passed or aliased, so pass only extracted values such as ${contextEscape.context}.input to helpers`);
|
|
1152
|
+
const nested = (await findNestedDurableOperations(workflow.handler))[0];
|
|
1153
|
+
if (nested) {
|
|
1154
|
+
const parent = `ctx.${nested.parentMethod}(${nested.parentStepId ? JSON.stringify(nested.parentStepId) : ""})`;
|
|
1155
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" calls ctx.${nested.method}() inside ${parent}; step bodies are atomic and cannot contain durable operations`);
|
|
1156
|
+
}
|
|
1157
|
+
const duplicates = await findDuplicateOperationIds(workflow.handler);
|
|
1158
|
+
if (!Array.isArray(duplicates)) {
|
|
1159
|
+
const remedy = duplicates.unchecked === "typescript" ? "install the \"typescript\" peer dependency" : "define the workflow handler as a function in the workflow file";
|
|
1160
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" could not be checked for durable operation ids; ${remedy}, because ${DURABLE_ID_REQUIRED}`);
|
|
1161
|
+
}
|
|
1162
|
+
for (const duplicate of duplicates) {
|
|
1163
|
+
if (duplicate.reason === "missing") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" calls ctx.${duplicate.method}() without an id; ${DURABLE_ID_REQUIRED}`);
|
|
1164
|
+
const where = duplicate.reason === "loop" ? "inside a loop or callback" : "more than once";
|
|
1165
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses id ${JSON.stringify(duplicate.id)} ${where}; every durable operation id must be unique within a workflow`);
|
|
1166
|
+
}
|
|
1167
|
+
const deadlineIssue = (await findWaitDeadlineIssues(workflow.handler))[0];
|
|
1168
|
+
if (deadlineIssue) {
|
|
1169
|
+
const call = `ctx.${deadlineIssue.method}()`;
|
|
1170
|
+
const fault = deadlineIssue.reason === "missing" ? "without timeoutMs" : deadlineIssue.reason === "dynamic" ? "with a timeoutMs the manifest cannot record" : deadlineIssue.reason === "absolute" ? "with the unsupported absolute deadline option" : "with a timeoutMs that is not a finite duration of at least 60000 milliseconds (one minute)";
|
|
1171
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" calls ${call} ${fault}; ${WAIT_DEADLINE_REQUIRED}`);
|
|
1172
|
+
}
|
|
1173
|
+
const metadataIssue = (await findStepMetadataIssues(workflow.handler))[0];
|
|
1174
|
+
if (metadataIssue?.kind === "description") {
|
|
1175
|
+
const step = metadataIssue.method === "llm" ? "ctx.llm()" : metadataIssue.stepId ? `ctx.${metadataIssue.method}(${JSON.stringify(metadataIssue.stepId)})` : `ctx.${metadataIssue.method}()`;
|
|
1176
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ${step} must include a static { meta: { description: "..." } }`);
|
|
1177
|
+
}
|
|
1178
|
+
if (metadataIssue?.kind === "group") {
|
|
1179
|
+
const step = metadataIssue.method === "llm" ? "ctx.llm()" : metadataIssue.stepId ? `ctx.${metadataIssue.method}(${JSON.stringify(metadataIssue.stepId)})` : `ctx.${metadataIssue.method}()`;
|
|
1180
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ${step} is declared in a loop or callback and must include a static { meta: { group: { id: "...", label: "..." } } }`);
|
|
1181
|
+
}
|
|
1182
|
+
if (metadataIssue?.kind === "loop-form") {
|
|
1183
|
+
const step = metadataIssue.method === "llm" ? "ctx.llm()" : metadataIssue.stepId ? `ctx.${metadataIssue.method}(${JSON.stringify(metadataIssue.stepId)})` : `ctx.${metadataIssue.method}()`;
|
|
1184
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ${step} uses an unsupported loop form; await the operation directly as the only statement in a for...of loop for sequential execution, or use Promise.all(items.map(...)) for parallel execution`);
|
|
1185
|
+
}
|
|
1186
|
+
if (metadataIssue?.kind === "duplicate-group") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses group id ${JSON.stringify(metadataIssue.groupId)} at more than one repeated step callsite; every group id must identify one callsite`);
|
|
1187
|
+
const operationDescriptionIssue = (await findOperationDescriptionIssues(workflow.handler))[0];
|
|
1188
|
+
if (operationDescriptionIssue) {
|
|
1189
|
+
const { method } = operationDescriptionIssue;
|
|
1190
|
+
const description = method === "approve" ? "{ description: \"...\" }" : "{ meta: { description: \"...\" } }";
|
|
1191
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ctx.${method}() must include a static ${description}`);
|
|
1192
|
+
}
|
|
1193
|
+
const branchMetadataIssue = (await findBranchMetadataIssues(workflow.handler))[0];
|
|
1194
|
+
if (branchMetadataIssue?.kind === "path") {
|
|
1195
|
+
const operation = branchMetadataIssue.stepId ? `ctx.${branchMetadataIssue.method}(${JSON.stringify(branchMetadataIssue.stepId)})` : `ctx.${branchMetadataIssue.method}()`;
|
|
1196
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ${operation} must include a static meta.branches path matching its enclosing if/else branches; each entry needs { id, description }`);
|
|
1197
|
+
}
|
|
1198
|
+
if (branchMetadataIssue?.kind === "inconsistent") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses inconsistent metadata for branch ${JSON.stringify(branchMetadataIssue.branchId)}; every operation under one if statement must use the same branch id and description`);
|
|
1199
|
+
if (branchMetadataIssue?.kind === "duplicate-id") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses branch id ${JSON.stringify(branchMetadataIssue.branchId)} for more than one if statement; every branch id must identify one condition`);
|
|
1200
|
+
const metadata = {
|
|
1201
|
+
workflowId: workflow.id,
|
|
1202
|
+
...workflow.description === void 0 ? {} : { description: workflow.description },
|
|
1203
|
+
workflowVersion: workflow.version,
|
|
1204
|
+
...workflow.inputSchema ? { inputSchema: serializeSchema(workflow.inputSchema, "input", `${workflow.id}.input`) } : {},
|
|
1205
|
+
...workflow.outputSchema ? { outputSchema: serializeSchema(workflow.outputSchema, "output", `${workflow.id}.output`) } : {},
|
|
1206
|
+
...workflow.stateSchema ? { stateSchema: serializeSchema(workflow.stateSchema, "output", `${workflow.id}.state`) } : {}
|
|
1207
|
+
};
|
|
1208
|
+
const triggers = [];
|
|
1209
|
+
for (const schedule of collection.triggers.filter((trigger) => trigger.workflow === workflow)) {
|
|
1210
|
+
const input = toJson(schedule.input, `schedule "${schedule.id}" input`);
|
|
1211
|
+
const schema = schedule.workflow.inputSchema;
|
|
1212
|
+
if (schema) {
|
|
1213
|
+
const result = await schema["~standard"].validate(input);
|
|
1214
|
+
if (result.issues) throw new Error(`@lovable.dev/workflows-sdk: schedule "${schedule.id}" input is invalid: ${result.issues.map((issue) => issue.message).join("; ")}`);
|
|
1215
|
+
}
|
|
1216
|
+
triggers.push(create(WorkflowManifestTriggerV1Schema, {
|
|
1217
|
+
id: schedule.id,
|
|
1218
|
+
kind: {
|
|
1219
|
+
case: "schedule",
|
|
1220
|
+
value: create(WorkflowManifestScheduleTriggerV1Schema, {
|
|
1221
|
+
cadence: manifestCadence(schedule.cadence),
|
|
1222
|
+
timeZone: schedule.timeZone,
|
|
1223
|
+
enabled: schedule.enabled,
|
|
1224
|
+
overlapPolicy: schedule.overlapPolicy,
|
|
1225
|
+
input: protoValue(input)
|
|
1226
|
+
})
|
|
1227
|
+
}
|
|
1228
|
+
}));
|
|
1229
|
+
}
|
|
1230
|
+
triggers.sort((a, b) => {
|
|
1231
|
+
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
1232
|
+
});
|
|
1233
|
+
const manifest = toJson$1(WorkflowManifestV1Schema, create(WorkflowManifestV1Schema, {
|
|
1234
|
+
manifestVersion: 1,
|
|
1235
|
+
sdkVersion: version,
|
|
1236
|
+
current: collection.workflows.includes(workflow),
|
|
1237
|
+
...options.routePath === void 0 ? {} : { routePath: options.routePath },
|
|
1238
|
+
...metadata,
|
|
1239
|
+
triggers,
|
|
1240
|
+
graph: await extractWorkflowGraph(workflow)
|
|
1241
|
+
}), { alwaysEmitImplicit: true });
|
|
1242
|
+
manifests.push(manifest);
|
|
1243
|
+
}
|
|
1244
|
+
return manifests.sort((a, b) => {
|
|
1245
|
+
const left = `${a.workflowId}.${a.workflowVersion}`;
|
|
1246
|
+
const right = `${b.workflowId}.${b.workflowVersion}`;
|
|
1247
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
//#endregion
|
|
1251
|
+
export { workflowVersions as a, every as c, WORKFLOW_ID_PATTERN as d, registerWorkflows as i, hourly as l, createMiddleware as n, defineSchedule as o, createWorkflow$1 as r, daily as s, generateManifests as t, weekly as u };
|