moonflower 1.4.3 → 1.4.5

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.
@@ -1,8 +1,8 @@
1
1
  import { SyntaxKind as e } from "ts-morph";
2
2
  import { Logger as K } from "../../utils/logger.mjs";
3
3
  import { OpenApiManager as v } from "../manager/OpenApiManager.mjs";
4
- const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
5
- const i = L.get(t);
4
+ const w = /* @__PURE__ */ new WeakMap(), h = (t) => {
5
+ const i = w.get(t);
6
6
  if (i)
7
7
  return i;
8
8
  if (t.getKind() === e.Identifier) {
@@ -12,7 +12,7 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
12
12
  if (o === t)
13
13
  throw new Error("Recursive implementation found");
14
14
  const d = h(o);
15
- return L.set(t, d), d;
15
+ return w.set(t, d), d;
16
16
  }
17
17
  const l = t.asKind(e.Identifier).getDefinitions()[0]?.getNode();
18
18
  if (l) {
@@ -20,12 +20,12 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
20
20
  if (o === t)
21
21
  throw new Error("Recursive implementation found");
22
22
  const d = h(o);
23
- return L.set(t, d), d;
23
+ return w.set(t, d), d;
24
24
  }
25
25
  throw new Error("No implementation nor definition available");
26
26
  }
27
- return L.set(t, t), t;
28
- }, S = (t) => {
27
+ return w.set(t, t), t;
28
+ }, A = (t) => {
29
29
  const i = t.getChildrenOfKind(e.Identifier);
30
30
  return i.length === 2 ? h(i[1]) : t.getChildren().reverse().find(
31
31
  (l) => l.getKind() !== e.GreaterThanToken && l.getKind() !== e.CommaToken && l.getKind() !== e.SemicolonToken
@@ -64,7 +64,7 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
64
64
  const r = s.asKind(e.TypeLiteral);
65
65
  if (r)
66
66
  return r.getFirstChildByKind(e.SyntaxList).getChildrenOfKind(e.PropertySignature).map((I) => {
67
- const k = I.getFirstChildByKind(e.Identifier), O = S(I), U = k.getNextSiblingIfKind(e.QuestionToken);
67
+ const k = I.getFirstChildByKind(e.Identifier), O = A(I), U = k.getNextSiblingIfKind(e.QuestionToken);
68
68
  return {
69
69
  role: "property",
70
70
  identifier: k.getText(),
@@ -77,26 +77,26 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
77
77
  return m(a.getFirstChild());
78
78
  if (s.asKind(e.PropertyAccessExpression)) {
79
79
  const E = h(s.getLastChild());
80
- return f(E.asKind(e.CallExpression).getReturnType(), E);
80
+ return c(E.asKind(e.CallExpression).getReturnType(), E);
81
81
  }
82
- const c = s.asKind(e.UnionType);
83
- if (c)
84
- return f(c.getType(), s);
82
+ const f = s.asKind(e.UnionType);
83
+ if (f)
84
+ return c(f.getType(), s);
85
85
  const y = s.asKind(e.TypeQuery);
86
86
  if (y)
87
87
  return m(y.getLastChild());
88
- const A = s.asKind(e.QualifiedName);
89
- if (A)
90
- return m(A.getLastChild());
88
+ const F = s.asKind(e.QualifiedName);
89
+ if (F)
90
+ return m(F.getLastChild());
91
91
  const C = s.asKind(e.CallExpression);
92
92
  if (C)
93
- return f(C.getReturnType(), C);
94
- const F = s.asKind(e.AwaitExpression);
95
- if (F)
96
- return m(F.getChildAtIndex(1));
97
- const b = s.asKind(e.AsExpression);
93
+ return c(C.getReturnType(), C);
94
+ const b = s.asKind(e.AwaitExpression);
98
95
  if (b)
99
- return m(b.getChildAtIndex(2));
96
+ return m(b.getChildAtIndex(1));
97
+ const L = s.asKind(e.AsExpression);
98
+ if (L)
99
+ return m(L.getChildAtIndex(2));
100
100
  const V = s.getSourceFile().getFilePath().split("/").pop();
101
101
  return K.warn(`[${V}] Unknown node type: ${s.getKindName()}`), "unknown_1";
102
102
  }, z = (t) => t.getFirstDescendantByKind(e.SyntaxList).getChildrenOfKind(e.PropertyAssignment).map((n) => {
@@ -107,19 +107,19 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
107
107
  return o.getLiteralText();
108
108
  const r = n.getSourceFile().getFilePath().split("/").pop();
109
109
  return K.warn(`[${r}] Unknown identifier name: ${o.getText()}`), "unknown_30";
110
- })(), u = n.getLastChild(), g = h(u);
110
+ })(), g = n.getLastChild(), u = h(g);
111
111
  return {
112
112
  role: "property",
113
113
  identifier: d,
114
- shape: x(g),
115
- optional: _(g),
116
- description: N(g, "description"),
117
- errorMessage: N(g, "errorMessage")
114
+ shape: x(u),
115
+ optional: _(u),
116
+ description: T(u, "description"),
117
+ errorMessage: T(u, "errorMessage")
118
118
  };
119
- }) || [], T = (t) => {
119
+ }) || [], N = (t) => {
120
120
  const i = t.asKind(e.CallExpression);
121
121
  return i ? (i.getReturnType().getSymbol()?.getName() ?? "").startsWith("Zod") : !1;
122
- }, w = (t) => {
122
+ }, S = (t) => {
123
123
  const i = t.asKind(e.CallExpression), s = i.getReturnType(), l = s.getSymbol()?.getName() ?? "";
124
124
  if (l === "ZodNumber")
125
125
  return "number";
@@ -133,23 +133,32 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
133
133
  const d = i.getFirstChildByKind(e.SyntaxList)?.getFirstChild()?.asKind(e.ObjectLiteralExpression);
134
134
  if (!d)
135
135
  return "unknown_zod_object";
136
- const u = d.getFirstChildByKind(e.SyntaxList);
137
- return u ? u.getChildrenOfKind(e.PropertyAssignment).map((r) => {
136
+ const g = d.getFirstChildByKind(e.SyntaxList);
137
+ return g ? g.getChildrenOfKind(e.PropertyAssignment).map((r) => {
138
138
  const a = r.getFirstChildByKind(e.Identifier).getText(), p = r.getLastChild();
139
139
  return {
140
140
  role: "property",
141
141
  identifier: a,
142
- shape: T(p) ? w(p) : x(p),
142
+ shape: N(p) ? S(p) : x(p),
143
143
  optional: !1
144
144
  };
145
145
  }) : [];
146
146
  }
147
147
  if (l === "ZodArray") {
148
148
  const o = i.getFirstChildByKind(e.SyntaxList)?.getFirstChild();
149
- return o ? [
149
+ if (o)
150
+ return [
151
+ {
152
+ role: "array",
153
+ shape: N(o) ? S(o) : x(o),
154
+ optional: !1
155
+ }
156
+ ];
157
+ const g = i.getFirstChildByKind(e.PropertyAccessExpression)?.getFirstChildByKind(e.CallExpression);
158
+ return g && N(g) ? [
150
159
  {
151
160
  role: "array",
152
- shape: T(o) ? w(o) : x(o),
161
+ shape: S(g),
153
162
  optional: !1
154
163
  }
155
164
  ] : "unknown_zod_array";
@@ -157,18 +166,18 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
157
166
  if (l === "ZodEnum") {
158
167
  const o = s.getTypeArguments();
159
168
  if (o.length > 0) {
160
- const g = o[0].getProperties().map((r) => ({
169
+ const u = o[0].getProperties().map((r) => ({
161
170
  role: "union_entry",
162
- shape: f(r.getTypeAtLocation(i), i, []),
171
+ shape: c(r.getTypeAtLocation(i), i, []),
163
172
  optional: !1
164
173
  }));
165
- if (g.length === 1)
166
- return g[0].shape;
167
- if (g.length > 1)
174
+ if (u.length === 1)
175
+ return u[0].shape;
176
+ if (u.length > 1)
168
177
  return [
169
178
  {
170
179
  role: "union",
171
- shape: g,
180
+ shape: u,
172
181
  optional: !1
173
182
  }
174
183
  ];
@@ -177,13 +186,13 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
177
186
  }
178
187
  if (l === "ZodOptional") {
179
188
  const o = i.getFirstChildByKind(e.PropertyAccessExpression)?.getFirstChildByKind(e.CallExpression);
180
- return o && T(o) ? w(o) : "unknown_zod_optional";
189
+ return o && N(o) ? S(o) : "unknown_zod_optional";
181
190
  }
182
191
  const n = t.getSourceFile().getFilePath().split("/").pop();
183
192
  return K.warn(`[${n}] Unknown zod type: ${l}`), "unknown_zod";
184
193
  }, x = (t) => {
185
- if (T(t))
186
- return w(t);
194
+ if (N(t))
195
+ return S(t);
187
196
  const i = t.getParent().getFirstChildByKind(e.AsExpression);
188
197
  if (i) {
189
198
  const r = i.getLastChildByKind(e.TypeReference);
@@ -202,35 +211,35 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
202
211
  l.getFirstChildByKind(e.SyntaxList).getFirstChild()
203
212
  ), a = r.getParent().getFirstChildByKind(e.TypeReference);
204
213
  if (a)
205
- return f(a.getType(), a, []);
214
+ return c(a.getType(), a, []);
206
215
  const p = r.getParent().getFirstChildByKind(e.ObjectLiteralExpression);
207
216
  if (p)
208
217
  return x(p);
209
218
  if (r.getKind() === e.CallExpression || r.getKind() === e.IntersectionType)
210
219
  return x(r);
211
- const c = t.getSourceFile().getFilePath().split("/").pop();
212
- return K.warn(`[${c}] Unknown call expression argument: ${r.getKindName()}`), "unknown_3";
220
+ const f = t.getSourceFile().getFilePath().split("/").pop();
221
+ return K.warn(`[${f}] Unknown call expression argument: ${r.getKindName()}`), "unknown_3";
213
222
  }
214
223
  const o = t.getFirstChildByKind(e.SyntaxList).getChildrenOfKind(e.PropertyAssignment).find((r) => r.getFirstChildByKind(e.Identifier)?.getText() === "parse");
215
224
  if (o) {
216
- const r = S(o).asKind(e.ArrowFunction).getReturnType();
217
- return f(r, o);
225
+ const r = A(o).asKind(e.ArrowFunction).getReturnType();
226
+ return c(r, o);
218
227
  }
219
228
  const d = t.getFirstChildByKind(e.SyntaxList)?.getFirstChildByKind(e.ImportType);
220
229
  if (d) {
221
230
  const r = d.getLastChildByKind(e.GreaterThanToken).getChildIndex(), a = d.getChildAtIndex(r - 1);
222
231
  return m(a.getFirstChild());
223
232
  }
224
- const u = t.isKind(e.IntersectionType) ? t : t.getParent()?.isKind(e.VariableDeclaration) ? t.getParent()?.getFirstChildByKind(e.IntersectionType) : null;
225
- if (u) {
226
- const r = u.getFirstChildByKind(e.TypeReference);
233
+ const g = t.isKind(e.IntersectionType) ? t : t.getParent()?.isKind(e.VariableDeclaration) ? t.getParent()?.getFirstChildByKind(e.IntersectionType) : null;
234
+ if (g) {
235
+ const r = g.getFirstChildByKind(e.TypeReference);
227
236
  if (r)
228
237
  return P(r);
229
238
  }
230
- const g = t.getSourceFile().getFilePath().split("/").pop();
231
- return K.warn(`[${g}] Unknown import type node`), "unknown_2";
239
+ const u = t.getSourceFile().getFilePath().split("/").pop();
240
+ return K.warn(`[${u}] Unknown import type node`), "unknown_2";
232
241
  }, _ = (t) => {
233
- if (T(t))
242
+ if (N(t))
234
243
  return (t.asKind(e.CallExpression).getReturnType().getSymbol()?.getName() ?? "") === "ZodOptional";
235
244
  const i = t.asKind(e.CallExpression);
236
245
  if (i) {
@@ -242,32 +251,32 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
242
251
  const o = i.getFirstChildByKind(e.SyntaxList), d = h(o.getFirstChild());
243
252
  return _(d);
244
253
  }
245
- return t.getFirstDescendantByKind(e.SyntaxList).getChildrenOfKind(e.PropertyAssignment).some((n) => n.getFirstDescendantByKind(e.Identifier).getText() === "optional" ? S(n).getKind() === e.TrueKeyword : !1);
246
- }, N = (t, i) => {
247
- if (T(t))
254
+ return t.getFirstDescendantByKind(e.SyntaxList).getChildrenOfKind(e.PropertyAssignment).some((n) => n.getFirstDescendantByKind(e.Identifier).getText() === "optional" ? A(n).getKind() === e.TrueKeyword : !1);
255
+ }, T = (t, i) => {
256
+ if (N(t))
248
257
  return "";
249
258
  const s = h(t), l = s.asKind(e.CallExpression);
250
259
  if (l) {
251
260
  const a = l.getLastChildByKind(e.SyntaxList);
252
- return N(a, i);
261
+ return T(a, i);
253
262
  }
254
263
  const n = s.asKind(e.SyntaxList);
255
264
  if (n)
256
- return n.getChildren().map((p) => N(p, i)).find((p) => !!p && p !== "unknown_25") || "";
265
+ return n.getChildren().map((p) => T(p, i)).find((p) => !!p && p !== "unknown_25") || "";
257
266
  const o = s.asKind(e.ObjectLiteralExpression);
258
267
  if (o) {
259
- const p = R(o).find((c) => c.identifier === i);
268
+ const p = R(o).find((f) => f.identifier === i);
260
269
  return p ? Array.isArray(p.value) ? "array" : p.value || "" : "";
261
270
  }
262
271
  const d = s.asKind(e.IntersectionType);
263
272
  if (d)
264
- return d.getTypeNodes().flatMap((a) => N(a, i)).filter((a) => !!a && a !== "unknown_25")[0] || "unknown_27";
265
- const u = s.asKind(e.TypeLiteral);
266
- if (u)
267
- return N(u.getFirstChildByKind(e.SyntaxList), i);
268
- const g = s.asKind(e.PropertySignature);
269
- if (g && s.getFirstDescendantByKind(e.Identifier).getText() === i)
270
- return S(g).getFirstDescendantByKind(
273
+ return d.getTypeNodes().flatMap((a) => T(a, i)).filter((a) => !!a && a !== "unknown_25")[0] || "unknown_27";
274
+ const g = s.asKind(e.TypeLiteral);
275
+ if (g)
276
+ return T(g.getFirstChildByKind(e.SyntaxList), i);
277
+ const u = s.asKind(e.PropertySignature);
278
+ if (u && s.getFirstDescendantByKind(e.Identifier).getText() === i)
279
+ return A(u).getFirstDescendantByKind(
271
280
  e.StringLiteral
272
281
  ).getLiteralText();
273
282
  const r = s.getSourceFile().getFilePath().split("/").pop();
@@ -278,7 +287,7 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
278
287
  return !1;
279
288
  const s = t.getTypeArguments();
280
289
  return i.getName() === "Promise" && s.length === 1;
281
- }, f = (t, i, s = []) => {
290
+ }, c = (t, i, s = []) => {
282
291
  const l = t.getAliasSymbol()?.getName();
283
292
  if (l && v.getInstance().hasExposedModel(l))
284
293
  return [
@@ -332,7 +341,7 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
332
341
  role: "tuple",
333
342
  shape: n.getTupleElements().map((r) => ({
334
343
  role: "tuple_entry",
335
- shape: f(r, i, o),
344
+ shape: c(r, i, o),
336
345
  optional: !1
337
346
  })),
338
347
  optional: !1
@@ -342,17 +351,17 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
342
351
  return [
343
352
  {
344
353
  role: "array",
345
- shape: f(n.getArrayElementType(), i, o),
354
+ shape: c(n.getArrayElementType(), i, o),
346
355
  optional: !1
347
356
  }
348
357
  ];
349
358
  if (n.isObject()) {
350
- const r = n.getNumberIndexType(), p = n.getBaseTypes()?.find((c) => c.isArray());
359
+ const r = n.getNumberIndexType(), p = n.getBaseTypes()?.find((f) => f.isArray());
351
360
  if (p)
352
361
  return [
353
362
  {
354
363
  role: "array",
355
- shape: f(
364
+ shape: c(
356
365
  p.getArrayElementType() ?? r,
357
366
  i,
358
367
  o
@@ -361,7 +370,7 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
361
370
  }
362
371
  ];
363
372
  }
364
- const d = n.getSymbol()?.getName(), u = /* @__PURE__ */ new Set([
373
+ const d = n.getSymbol()?.getName(), g = /* @__PURE__ */ new Set([
365
374
  "Buffer",
366
375
  "Uint8Array",
367
376
  "Int8Array",
@@ -378,7 +387,7 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
378
387
  "SharedArrayBuffer",
379
388
  "ReadableStream"
380
389
  ]);
381
- if (n.isObject() && d && u.has(d))
390
+ if (n.isObject() && d && g.has(d))
382
391
  return [
383
392
  {
384
393
  role: "buffer",
@@ -393,7 +402,7 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
393
402
  return [
394
403
  {
395
404
  role: "record",
396
- shape: a ? f(a, i, o) : "unknown",
405
+ shape: a ? c(a, i, o) : "unknown",
397
406
  optional: !1
398
407
  }
399
408
  ];
@@ -403,7 +412,7 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
403
412
  return [
404
413
  {
405
414
  role: "array",
406
- shape: a ? f(a, i, o) : "unknown",
415
+ shape: a ? c(a, i, o) : "unknown",
407
416
  optional: !1
408
417
  }
409
418
  ];
@@ -414,7 +423,7 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
414
423
  return [
415
424
  {
416
425
  role: "record",
417
- shape: f(r, i, o),
426
+ shape: c(r, i, o),
418
427
  optional: !1
419
428
  }
420
429
  ];
@@ -426,44 +435,44 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
426
435
  return {
427
436
  role: "property",
428
437
  identifier: r.getName(),
429
- shape: f(r.getTypeAtLocation(i), i, o),
438
+ shape: c(r.getTypeAtLocation(i), i, o),
430
439
  optional: !1
431
440
  };
432
441
  if (!(a.asKind(e.PropertySignature) || a.asKind(e.PropertyAssignment) || a.asKind(e.ShorthandPropertyAssignment)))
433
442
  return {
434
443
  role: "property",
435
444
  identifier: r.getName(),
436
- shape: f(r.getTypeAtLocation(i), i, o),
445
+ shape: c(r.getTypeAtLocation(i), i, o),
437
446
  optional: !1
438
447
  };
439
- const c = r.getTypeAtLocation(i).isNullable(), y = f(r.getTypeAtLocation(i), i, o);
448
+ const f = r.getTypeAtLocation(i).isNullable(), y = c(r.getTypeAtLocation(i), i, o);
440
449
  return {
441
450
  role: "property",
442
451
  identifier: r.getName(),
443
452
  shape: y,
444
- optional: c
453
+ optional: f
445
454
  };
446
455
  }).filter((r) => r.shape !== "undefined");
447
456
  if (n.isUnion()) {
448
457
  const a = n.getUnionTypes().map((y) => ({
449
458
  role: "union_entry",
450
- shape: f(y, i, o),
459
+ shape: c(y, i, o),
451
460
  optional: !1
452
461
  })).filter(
453
- (y, A, C) => !C.find((F, b) => F.shape === y.shape && b > A)
454
- ), p = a.some((y) => y.shape === "undefined"), c = a.filter((y) => y.shape !== "undefined");
455
- return c.length === 1 ? c[0].shape : [
462
+ (y, F, C) => !C.find((b, L) => b.shape === y.shape && L > F)
463
+ ), p = a.some((y) => y.shape === "undefined"), f = a.filter((y) => y.shape !== "undefined");
464
+ return f.length === 1 ? f[0].shape : [
456
465
  {
457
466
  role: "union",
458
- shape: c,
467
+ shape: f,
459
468
  optional: p
460
469
  }
461
470
  ];
462
471
  }
463
472
  if (n.isIntersection())
464
- return n.getIntersectionTypes().map((p) => f(p, i, o)).filter((p) => typeof p != "string").reduce((p, c) => [...p, ...c], []);
465
- const g = i.getSourceFile().getFilePath().split("/").pop();
466
- return K.warn(`[${g}] Unknown type shape node ${t.getText()}`), "unknown_5";
473
+ return n.getIntersectionTypes().map((p) => c(p, i, o)).filter((p) => typeof p != "string").reduce((p, f) => [...p, ...f], []);
474
+ const u = i.getSourceFile().getFilePath().split("/").pop();
475
+ return K.warn(`[${u}] Unknown type shape node ${t.getText()}`), "unknown_5";
467
476
  }, B = (t) => {
468
477
  if (t.isKind(e.Identifier))
469
478
  return B(h(t));
@@ -472,7 +481,7 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
472
481
  if (t.isKind(e.ArrayLiteralExpression))
473
482
  return t.forEachChildAsArray().map((s) => B(s));
474
483
  if (t.isKind(e.PropertyAccessExpression))
475
- return B(S(t));
484
+ return B(A(t));
476
485
  if (t.isKind(e.ObjectLiteralExpression))
477
486
  return R(t);
478
487
  const i = t.getSourceFile().getFilePath().split("/").pop();
@@ -485,7 +494,7 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
485
494
  const l = s.getType();
486
495
  return l.isStringLiteral() ? l.getLiteralValue() : null;
487
496
  }, R = (t) => t.getFirstDescendantByKind(e.SyntaxList).getChildrenOfKind(e.PropertyAssignment).map((n) => {
488
- const d = n.getFirstDescendantByKind(e.Identifier).getText(), u = n.getLastChild(), g = h(u), r = B(g);
497
+ const d = n.getFirstDescendantByKind(e.Identifier).getText(), g = n.getLastChild(), u = h(g), r = B(u);
489
498
  return {
490
499
  identifier: d,
491
500
  value: r
@@ -493,14 +502,14 @@ const L = /* @__PURE__ */ new WeakMap(), h = (t) => {
493
502
  }) || [];
494
503
  export {
495
504
  h as findNodeImplementation,
496
- S as findPropertyAssignmentValueNode,
497
- f as getProperTypeShape,
505
+ A as findPropertyAssignmentValueNode,
506
+ c as getProperTypeShape,
498
507
  m as getRecursiveNodeShape,
499
508
  z as getShapeOfValidatorLiteral,
500
509
  P as getTypeReferenceShape,
501
510
  _ as getValidatorPropertyOptionality,
502
511
  x as getValidatorPropertyShape,
503
- N as getValidatorPropertyStringValue,
512
+ T as getValidatorPropertyStringValue,
504
513
  R as getValuesOfObjectLiteral,
505
514
  Q as resolveEndpointPath
506
515
  };