@diagonal-hq/cli 0.41.5 → 0.41.7

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.
@@ -2,7 +2,156 @@ import { createRequire as __diagonalCreateRequire } from 'node:module';
2
2
  const require = __diagonalCreateRequire(import.meta.url);
3
3
  import {
4
4
  stringFacts
5
- } from "./cli-chunk-WPC3DBHX.mjs";
5
+ } from "./cli-chunk-25JQRNTW.mjs";
6
+ import {
7
+ readUid
8
+ } from "./cli-chunk-ES45EAOO.mjs";
9
+ import {
10
+ SourceError,
11
+ declaredSlug,
12
+ propertyKey
13
+ } from "./cli-chunk-NEXRHJ3X.mjs";
14
+
15
+ // scripts/lib/runtime-build/workflow-config.mjs
16
+ var WORKFLOW_STAGE = "workflow";
17
+ var TRIGGER_TYPES = {
18
+ request: "request",
19
+ recordEvent: "event.record",
20
+ recordLifecycle: "lifecycle.record",
21
+ recordSchedule: "schedule.record",
22
+ scheduled: "scheduled",
23
+ workflowEvent: "event.workflow",
24
+ manual: "manual"
25
+ };
26
+ function unwrap(node) {
27
+ let current = node;
28
+ while (current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSNonNullExpression" || current.type === "ParenthesizedExpression") {
29
+ current = current.expression;
30
+ }
31
+ return current;
32
+ }
33
+ function propertyNodes(node) {
34
+ const unwrapped = node === void 0 ? null : unwrap(node);
35
+ const nodes = /* @__PURE__ */ new Map();
36
+ if (unwrapped?.type !== "ObjectExpression") {
37
+ return nodes;
38
+ }
39
+ for (const property of unwrapped.properties) {
40
+ if (property.type === "ObjectProperty") {
41
+ nodes.set(propertyKey(property), property);
42
+ }
43
+ }
44
+ return nodes;
45
+ }
46
+ function defineConfigArgument(ast) {
47
+ const statement = ast.program.body.find((item) => item.type === "ExportDefaultDeclaration");
48
+ const call = statement === void 0 ? null : unwrap(statement.declaration);
49
+ const argument = call?.type === "CallExpression" ? call.arguments[0] : void 0;
50
+ return argument !== void 0 && unwrap(argument).type === "ObjectExpression" ? argument : null;
51
+ }
52
+ function workflowConfigObject(ast) {
53
+ const argument = defineConfigArgument(ast);
54
+ if (argument !== null) {
55
+ return unwrap(argument);
56
+ }
57
+ const statements = ast.program.body.filter(isConfigExport);
58
+ const declarations = statements[0]?.declaration.declarations ?? [];
59
+ const init = statements.length === 1 && declarations.length === 1 ? declarations[0].init : null;
60
+ const object = init === null || init === void 0 ? null : unwrap(init);
61
+ return object?.type === "ObjectExpression" ? object : null;
62
+ }
63
+ function workflowMetadata(ast) {
64
+ const configObject = workflowConfigObject(ast);
65
+ const metadata = { uid: configObject === null ? null : configUid(configObject) };
66
+ const slug = declaredSlug(configObject).slug;
67
+ if (slug !== null) {
68
+ metadata.slug = slug;
69
+ }
70
+ const config = propertyNodes(configObject ?? void 0);
71
+ const name = stringLiteral((config.get("name") ?? config.get("title"))?.value);
72
+ if (name !== null && name.trim() !== "") {
73
+ metadata.name = name;
74
+ }
75
+ const trigger = stringLiteral(propertyNodes(config.get("trigger")?.value).get("type")?.value);
76
+ if (trigger !== null && Object.hasOwn(TRIGGER_TYPES, trigger)) {
77
+ metadata.trigger = trigger;
78
+ }
79
+ const inputs = inputKeys(ast);
80
+ if (inputs !== null) {
81
+ metadata.inputs = inputs;
82
+ }
83
+ return metadata;
84
+ }
85
+ function configUid(configObject) {
86
+ try {
87
+ return readUid(configObject);
88
+ } catch (error) {
89
+ if (error instanceof SourceError) {
90
+ return null;
91
+ }
92
+ throw error;
93
+ }
94
+ }
95
+ function stringLiteral(node) {
96
+ const value = node === void 0 ? null : unwrap(node);
97
+ if (value?.type === "StringLiteral") {
98
+ return value.value;
99
+ }
100
+ return value?.type === "TemplateLiteral" && value.expressions.length === 0 ? value.quasis[0].value.cooked : null;
101
+ }
102
+ function inputKeys(ast) {
103
+ const statement = ast.program.body.find((item) => item.type === "ExportDefaultDeclaration");
104
+ const call = statement === void 0 ? null : unwrap(statement.declaration);
105
+ if (call?.type !== "CallExpression") {
106
+ return null;
107
+ }
108
+ if (call.arguments.length < 2) {
109
+ return [];
110
+ }
111
+ const argument = unwrap(call.arguments[0]);
112
+ const node = argument.type === "ObjectExpression" ? propertyNodes(argument).get("input")?.value : argument;
113
+ if (node === void 0) {
114
+ return [];
115
+ }
116
+ let schema = unwrap(node);
117
+ if (schema.type === "Identifier") {
118
+ schema = topLevelConst(ast, schema.name);
119
+ }
120
+ const shape = schema === null || !isVObjectCall(schema) ? null : unwrap(schema.arguments[0]);
121
+ if (shape?.type !== "ObjectExpression") {
122
+ return null;
123
+ }
124
+ const keys = [];
125
+ for (const property of shape.properties) {
126
+ if (property.type !== "ObjectProperty" || property.computed) {
127
+ return null;
128
+ }
129
+ keys.push(propertyKey(property));
130
+ }
131
+ return keys;
132
+ }
133
+ function topLevelConst(ast, name) {
134
+ for (const statement of ast.program.body) {
135
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
136
+ if (declaration?.type !== "VariableDeclaration" || declaration.kind !== "const") {
137
+ continue;
138
+ }
139
+ for (const declarator of declaration.declarations) {
140
+ if (declarator.id.type === "Identifier" && declarator.id.name === name && declarator.init) {
141
+ return unwrap(declarator.init);
142
+ }
143
+ }
144
+ }
145
+ return null;
146
+ }
147
+ function isVObjectCall(node) {
148
+ return node.type === "CallExpression" && node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.object.type === "Identifier" && node.callee.object.name === "v" && node.callee.property.type === "Identifier" && node.callee.property.name === "object" && node.arguments.length === 1;
149
+ }
150
+ function isConfigExport(statement) {
151
+ return statement.type === "ExportNamedDeclaration" && statement.declaration?.type === "VariableDeclaration" && statement.declaration.declarations.some(
152
+ (declarator) => declarator.id.type === "Identifier" && declarator.id.name === "config"
153
+ );
154
+ }
6
155
 
7
156
  // scripts/lib/npm-package.mjs
8
157
  function tarballName(name, version) {
@@ -267,6 +416,9 @@ function runCompilerAsync(input, args) {
267
416
  }
268
417
 
269
418
  export {
419
+ WORKFLOW_STAGE,
420
+ workflowConfigObject,
421
+ workflowMetadata,
270
422
  tarballName,
271
423
  isVersion,
272
424
  compareVersions,