@velastack/patterns 0.14.3 → 0.15.1

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.
Files changed (161) hide show
  1. package/README.md +28 -0
  2. package/dist/chunks/_page-Cg7LjaOE.js +5 -0
  3. package/dist/chunks/{_page-44USwLXO.js.map → _page-Cg7LjaOE.js.map} +1 -1
  4. package/dist/chunks/auth-pages-DSBqKjO0.js +311 -0
  5. package/dist/chunks/auth-pages-DSBqKjO0.js.map +1 -0
  6. package/dist/chunks/{collections-B_-NTtLW.js → collections-D2_2cxWD.js} +70 -73
  7. package/dist/chunks/collections-D2_2cxWD.js.map +1 -0
  8. package/dist/chunks/{constants-CTp-0HKk.js → constants-DbpctM1D.js} +21 -21
  9. package/dist/chunks/constants-DbpctM1D.js.map +1 -0
  10. package/dist/chunks/{currency.server-DOX4Rzyb.js → currency.server-CFrwmYra.js} +4 -4
  11. package/dist/chunks/{currency.server-DOX4Rzyb.js.map → currency.server-CFrwmYra.js.map} +1 -1
  12. package/dist/chunks/{env-vars-BbS_mWyP.js → env-vars-Dm3Xy4rl.js} +4 -4
  13. package/dist/chunks/{env-vars-BbS_mWyP.js.map → env-vars-Dm3Xy4rl.js.map} +1 -1
  14. package/dist/chunks/{generate-CKuUg3p-.js → generate-BDGmczK8.js} +2 -2
  15. package/dist/chunks/{generate-CKuUg3p-.js.map → generate-BDGmczK8.js.map} +1 -1
  16. package/dist/chunks/{generate-Bwkx_usZ.js → generate-BMWoD9E2.js} +4 -4
  17. package/dist/chunks/{generate-Bwkx_usZ.js.map → generate-BMWoD9E2.js.map} +1 -1
  18. package/dist/chunks/{generate-4iujJNAW.js → generate-BRTIGlqT.js} +5 -5
  19. package/dist/chunks/{generate-4iujJNAW.js.map → generate-BRTIGlqT.js.map} +1 -1
  20. package/dist/chunks/{generate-DYq5Oj58.js → generate-BrO9MOgL.js} +2 -2
  21. package/dist/chunks/{generate-DYq5Oj58.js.map → generate-BrO9MOgL.js.map} +1 -1
  22. package/dist/chunks/{generate-BJY8AtAp.js → generate-BvQ6VwYH.js} +5 -5
  23. package/dist/chunks/{generate-BJY8AtAp.js.map → generate-BvQ6VwYH.js.map} +1 -1
  24. package/dist/chunks/{generate-B4uDCW5D.js → generate-Cs_fdfD7.js} +4 -4
  25. package/dist/chunks/{generate-B4uDCW5D.js.map → generate-Cs_fdfD7.js.map} +1 -1
  26. package/dist/chunks/{generate-JkvSNTy-.js → generate-DZ9kT3iC.js} +31 -188
  27. package/dist/chunks/generate-DZ9kT3iC.js.map +1 -0
  28. package/dist/chunks/{generate.runtime-D9OC1RXu.js → generate.runtime-1eTnPFmA.js} +3 -3
  29. package/dist/chunks/{generate.runtime-D9OC1RXu.js.map → generate.runtime-1eTnPFmA.js.map} +1 -1
  30. package/dist/chunks/{generate.runtime-27KTIg_o.js → generate.runtime-B-H2F-sH.js} +48 -53
  31. package/dist/chunks/generate.runtime-B-H2F-sH.js.map +1 -0
  32. package/dist/chunks/{generate.runtime-DhSH1o8H.js → generate.runtime-B4mQEW54.js} +3 -3
  33. package/dist/chunks/{generate.runtime-DhSH1o8H.js.map → generate.runtime-B4mQEW54.js.map} +1 -1
  34. package/dist/chunks/{generate.runtime-BFX_8erf.js → generate.runtime-B4rG6gSK.js} +10 -9
  35. package/dist/chunks/{generate.runtime-BFX_8erf.js.map → generate.runtime-B4rG6gSK.js.map} +1 -1
  36. package/dist/chunks/{generate.runtime-DuAYqKxl.js → generate.runtime-B9nVU5iO.js} +2 -2
  37. package/dist/chunks/{generate.runtime-DuAYqKxl.js.map → generate.runtime-B9nVU5iO.js.map} +1 -1
  38. package/dist/chunks/{generate.runtime-D6l6uLiY.js → generate.runtime-BC1GJUXE.js} +2 -2
  39. package/dist/chunks/{generate.runtime-D6l6uLiY.js.map → generate.runtime-BC1GJUXE.js.map} +1 -1
  40. package/dist/chunks/{generate.runtime-Duw_JI_b.js → generate.runtime-BJwSyslL.js} +2 -2
  41. package/dist/chunks/{generate.runtime-Duw_JI_b.js.map → generate.runtime-BJwSyslL.js.map} +1 -1
  42. package/dist/chunks/{generate.runtime-CBVcsole.js → generate.runtime-Bda2_WK7.js} +2 -2
  43. package/dist/chunks/{generate.runtime-CBVcsole.js.map → generate.runtime-Bda2_WK7.js.map} +1 -1
  44. package/dist/chunks/{generate.runtime-sjFAWbZc.js → generate.runtime-BkQPchHe.js} +7 -7
  45. package/dist/chunks/{generate.runtime-sjFAWbZc.js.map → generate.runtime-BkQPchHe.js.map} +1 -1
  46. package/dist/chunks/{generate.runtime-bsuqrKOm.js → generate.runtime-BuQASx9Y.js} +2 -2
  47. package/dist/chunks/{generate.runtime-bsuqrKOm.js.map → generate.runtime-BuQASx9Y.js.map} +1 -1
  48. package/dist/chunks/{generate.runtime-D77ueFKY.js → generate.runtime-BvHK8IN-.js} +118 -134
  49. package/dist/chunks/generate.runtime-BvHK8IN-.js.map +1 -0
  50. package/dist/chunks/{generate.runtime-BXNBWGYr.js → generate.runtime-C1HlZnLC.js} +2 -2
  51. package/dist/chunks/{generate.runtime-BXNBWGYr.js.map → generate.runtime-C1HlZnLC.js.map} +1 -1
  52. package/dist/chunks/{generate.runtime-wiWdXXPi.js → generate.runtime-C62ChKGg.js} +6 -6
  53. package/dist/chunks/{generate.runtime-wiWdXXPi.js.map → generate.runtime-C62ChKGg.js.map} +1 -1
  54. package/dist/chunks/{generate.runtime-B8-ORwxT.js → generate.runtime-CIOi-XSm.js} +6 -6
  55. package/dist/chunks/{generate.runtime-B8-ORwxT.js.map → generate.runtime-CIOi-XSm.js.map} +1 -1
  56. package/dist/chunks/{generate.runtime-nXjFqHyb.js → generate.runtime-CQ_U4YTJ.js} +4 -4
  57. package/dist/chunks/{generate.runtime-nXjFqHyb.js.map → generate.runtime-CQ_U4YTJ.js.map} +1 -1
  58. package/dist/chunks/{generate.runtime-D0lI3Gt8.js → generate.runtime-CZA46Ghe.js} +5 -5
  59. package/dist/chunks/{generate.runtime-D0lI3Gt8.js.map → generate.runtime-CZA46Ghe.js.map} +1 -1
  60. package/dist/chunks/{generate.runtime-XT_JQlTk.js → generate.runtime-Cd742Yqf.js} +2 -2
  61. package/dist/chunks/{generate.runtime-XT_JQlTk.js.map → generate.runtime-Cd742Yqf.js.map} +1 -1
  62. package/dist/chunks/{generate.runtime-BlEy2fFF.js → generate.runtime-CfCDLJ6Y.js} +3 -3
  63. package/dist/chunks/{generate.runtime-BlEy2fFF.js.map → generate.runtime-CfCDLJ6Y.js.map} +1 -1
  64. package/dist/chunks/{generate.runtime-RTGpwxcS.js → generate.runtime-CjLath7N.js} +6 -12
  65. package/dist/chunks/generate.runtime-CjLath7N.js.map +1 -0
  66. package/dist/chunks/{generate.runtime-UtkANHk1.js → generate.runtime-CnNtG_x5.js} +3 -3
  67. package/dist/chunks/{generate.runtime-UtkANHk1.js.map → generate.runtime-CnNtG_x5.js.map} +1 -1
  68. package/dist/chunks/{generate.runtime-CCaCaXNu.js → generate.runtime-D8G8cwCr.js} +2 -2
  69. package/dist/chunks/{generate.runtime-CCaCaXNu.js.map → generate.runtime-D8G8cwCr.js.map} +1 -1
  70. package/dist/chunks/{generate.runtime-Cm75waRD.js → generate.runtime-DBQvnQmR.js} +2 -2
  71. package/dist/chunks/{generate.runtime-Cm75waRD.js.map → generate.runtime-DBQvnQmR.js.map} +1 -1
  72. package/dist/chunks/{generate.runtime-PDnSxiek.js → generate.runtime-DE-vPcn4.js} +6 -6
  73. package/dist/chunks/{generate.runtime-PDnSxiek.js.map → generate.runtime-DE-vPcn4.js.map} +1 -1
  74. package/dist/chunks/{generate.runtime-DLoYscQO.js → generate.runtime-DFSsgOmB.js} +3 -3
  75. package/dist/chunks/{generate.runtime-DLoYscQO.js.map → generate.runtime-DFSsgOmB.js.map} +1 -1
  76. package/dist/chunks/{generate.runtime-DiEiFoxR.js → generate.runtime-DNjyaFml.js} +3 -3
  77. package/dist/chunks/{generate.runtime-DiEiFoxR.js.map → generate.runtime-DNjyaFml.js.map} +1 -1
  78. package/dist/chunks/{generate.runtime-CuvdtjKc.js → generate.runtime-DQI69jkX.js} +2 -2
  79. package/dist/chunks/{generate.runtime-CuvdtjKc.js.map → generate.runtime-DQI69jkX.js.map} +1 -1
  80. package/dist/chunks/{generate.runtime-B7XOa9_A.js → generate.runtime-DQUZRJH8.js} +3 -3
  81. package/dist/chunks/{generate.runtime-B7XOa9_A.js.map → generate.runtime-DQUZRJH8.js.map} +1 -1
  82. package/dist/chunks/generate.runtime-DR8z6DyZ.js +169 -0
  83. package/dist/chunks/generate.runtime-DR8z6DyZ.js.map +1 -0
  84. package/dist/chunks/{generate.runtime-XpYi9SlM.js → generate.runtime-Diix70x4.js} +3 -3
  85. package/dist/chunks/{generate.runtime-XpYi9SlM.js.map → generate.runtime-Diix70x4.js.map} +1 -1
  86. package/dist/chunks/{generate.runtime-BU-4sjyu.js → generate.runtime-Doumu0TL.js} +110 -113
  87. package/dist/chunks/generate.runtime-Doumu0TL.js.map +1 -0
  88. package/dist/chunks/{generate.runtime-TQmspB4Z.js → generate.runtime-Dtum580c.js} +27 -34
  89. package/dist/chunks/generate.runtime-Dtum580c.js.map +1 -0
  90. package/dist/chunks/{generate.runtime-BROXlbeJ.js → generate.runtime-GmsldrGj.js} +3 -3
  91. package/dist/chunks/{generate.runtime-BROXlbeJ.js.map → generate.runtime-GmsldrGj.js.map} +1 -1
  92. package/dist/chunks/{generate.runtime-ZgLxGWuy.js → generate.runtime-lP4eoera.js} +3 -3
  93. package/dist/chunks/{generate.runtime-ZgLxGWuy.js.map → generate.runtime-lP4eoera.js.map} +1 -1
  94. package/dist/chunks/{generate.runtime-Dm7IEo2h.js → generate.runtime-liAz2TOE.js} +5 -5
  95. package/dist/chunks/{generate.runtime-Dm7IEo2h.js.map → generate.runtime-liAz2TOE.js.map} +1 -1
  96. package/dist/chunks/{generate.runtime-DxyQqNpu.js → generate.runtime-rxzMCECc.js} +5 -11
  97. package/dist/chunks/generate.runtime-rxzMCECc.js.map +1 -0
  98. package/dist/chunks/{generate.runtime-VMTLHWLk.js → generate.runtime-ufoTIUXA.js} +55 -60
  99. package/dist/chunks/generate.runtime-ufoTIUXA.js.map +1 -0
  100. package/dist/chunks/gitignore-2XpeEFmr.js +139 -0
  101. package/dist/chunks/gitignore-2XpeEFmr.js.map +1 -0
  102. package/dist/chunks/{i18n-mnzzcYhz.js → i18n-CxT1kz8Y.js} +3 -3
  103. package/dist/chunks/{i18n-mnzzcYhz.js.map → i18n-CxT1kz8Y.js.map} +1 -1
  104. package/dist/chunks/{modify-file-CgJIza72.js → modify-file-BX9-aZD1.js} +3 -3
  105. package/dist/chunks/{modify-file-CgJIza72.js.map → modify-file-BX9-aZD1.js.map} +1 -1
  106. package/dist/chunks/pocketbase-Dq9UdK_j.js +232 -0
  107. package/dist/chunks/pocketbase-Dq9UdK_j.js.map +1 -0
  108. package/dist/chunks/{providers-CDUFaOeQ.js → providers-2UgxXRJW.js} +3 -3
  109. package/dist/chunks/{providers-CDUFaOeQ.js.map → providers-2UgxXRJW.js.map} +1 -1
  110. package/dist/chunks/{providers-tjlFH5di.js → providers-DrK_hjSr.js} +2 -2
  111. package/dist/chunks/{providers-tjlFH5di.js.map → providers-DrK_hjSr.js.map} +1 -1
  112. package/dist/chunks/route-BDhlro0V.js +162 -0
  113. package/dist/chunks/route-BDhlro0V.js.map +1 -0
  114. package/dist/chunks/schema-2frI_BS2.js +116 -0
  115. package/dist/chunks/schema-2frI_BS2.js.map +1 -0
  116. package/dist/chunks/{shared-BjTRQ5QH.js → shared-BOFCKWJs.js} +3 -3
  117. package/dist/chunks/{shared-BjTRQ5QH.js.map → shared-BOFCKWJs.js.map} +1 -1
  118. package/dist/chunks/shared-DJ4KvhTb.js +1182 -0
  119. package/dist/chunks/shared-DJ4KvhTb.js.map +1 -0
  120. package/dist/chunks/{site-C8Wcg6LT.js → site-qASrdyUt.js} +3 -3
  121. package/dist/chunks/{site-C8Wcg6LT.js.map → site-qASrdyUt.js.map} +1 -1
  122. package/dist/chunks/{table-core-RvMjoXpT.js → table-core-s2xjYgRD.js} +3 -3
  123. package/dist/chunks/{table-core-RvMjoXpT.js.map → table-core-s2xjYgRD.js.map} +1 -1
  124. package/dist/chunks/test-setup-jqVMmL83.js +103 -0
  125. package/dist/chunks/test-setup-jqVMmL83.js.map +1 -0
  126. package/dist/chunks/{translations-CiJnl574.js → translations-B5hX0Qq-.js} +5 -2
  127. package/dist/chunks/{translations-CiJnl574.js.map → translations-B5hX0Qq-.js.map} +1 -1
  128. package/dist/chunks/{ui-CE-8llQS.js → ui-DZuwcswv.js} +3 -3
  129. package/dist/chunks/{ui-CE-8llQS.js.map → ui-DZuwcswv.js.map} +1 -1
  130. package/dist/chunks/{util-ILWdjRAd.js → util-mXrQ89nG.js} +8 -2
  131. package/dist/chunks/util-mXrQ89nG.js.map +1 -0
  132. package/dist/chunks/{whatsapp-DT10x76l.js → whatsapp-BytvTPlS.js} +2 -2
  133. package/dist/chunks/{whatsapp-DT10x76l.js.map → whatsapp-BytvTPlS.js.map} +1 -1
  134. package/dist/chunks/write-result-BhfLWAXf.js +539 -0
  135. package/dist/chunks/write-result-BhfLWAXf.js.map +1 -0
  136. package/dist/index.d.ts +81 -0
  137. package/dist/index.js +2388 -3276
  138. package/dist/index.js.map +1 -1
  139. package/package.json +4 -4
  140. package/dist/chunks/_page-44USwLXO.js +0 -5
  141. package/dist/chunks/auth-pages-BW3_yluN.js +0 -285
  142. package/dist/chunks/auth-pages-BW3_yluN.js.map +0 -1
  143. package/dist/chunks/collections-B_-NTtLW.js.map +0 -1
  144. package/dist/chunks/constants-CTp-0HKk.js.map +0 -1
  145. package/dist/chunks/generate-JkvSNTy-.js.map +0 -1
  146. package/dist/chunks/generate.runtime-27KTIg_o.js.map +0 -1
  147. package/dist/chunks/generate.runtime-BU-4sjyu.js.map +0 -1
  148. package/dist/chunks/generate.runtime-D77ueFKY.js.map +0 -1
  149. package/dist/chunks/generate.runtime-Dn0_y2iV.js +0 -161
  150. package/dist/chunks/generate.runtime-Dn0_y2iV.js.map +0 -1
  151. package/dist/chunks/generate.runtime-DxyQqNpu.js.map +0 -1
  152. package/dist/chunks/generate.runtime-RTGpwxcS.js.map +0 -1
  153. package/dist/chunks/generate.runtime-TQmspB4Z.js.map +0 -1
  154. package/dist/chunks/generate.runtime-VMTLHWLk.js.map +0 -1
  155. package/dist/chunks/pocketbase-S8lUt0nI.js +0 -219
  156. package/dist/chunks/pocketbase-S8lUt0nI.js.map +0 -1
  157. package/dist/chunks/test-setup-CpjhQSl-.js +0 -176
  158. package/dist/chunks/test-setup-CpjhQSl-.js.map +0 -1
  159. package/dist/chunks/util-ILWdjRAd.js.map +0 -1
  160. package/dist/chunks/write-result-BguSfKV-.js +0 -499
  161. package/dist/chunks/write-result-BguSfKV-.js.map +0 -1
@@ -0,0 +1,1182 @@
1
+ import { i as e, r as t, t as n } from "./rolldown-runtime-CwxnZyOB.js";
2
+ import { a as r, c as i, l as a, o } from "./route-BDhlro0V.js";
3
+ import { t as s } from "./dedent-CCUOcPFW.js";
4
+ import { t as c } from "./errors-DdSUZI8f.js";
5
+ // src/parse/syntax.ts
6
+ var l = [
7
+ {
8
+ type: "text",
9
+ aliases: ["string"],
10
+ help: "a line of text"
11
+ },
12
+ {
13
+ type: "number",
14
+ aliases: [
15
+ "integer",
16
+ "int",
17
+ "float",
18
+ "decimal",
19
+ "double"
20
+ ],
21
+ help: "a number"
22
+ },
23
+ {
24
+ type: "bool",
25
+ aliases: ["boolean"],
26
+ help: "a checkbox"
27
+ },
28
+ {
29
+ type: "date",
30
+ aliases: ["datetime", "timestamp"],
31
+ help: "a date"
32
+ },
33
+ {
34
+ type: "email",
35
+ aliases: [],
36
+ help: "an email address"
37
+ },
38
+ {
39
+ type: "url",
40
+ aliases: [],
41
+ help: "a URL"
42
+ },
43
+ {
44
+ type: "password",
45
+ aliases: [],
46
+ help: "a password, stored hashed"
47
+ },
48
+ {
49
+ type: "editor",
50
+ aliases: [],
51
+ help: "rich text (HTML)"
52
+ },
53
+ {
54
+ type: "json",
55
+ aliases: [],
56
+ help: "any JSON value"
57
+ },
58
+ {
59
+ type: "geoPoint",
60
+ aliases: ["geopoint"],
61
+ help: "a latitude and longitude"
62
+ },
63
+ {
64
+ type: "select",
65
+ aliases: [],
66
+ help: "one of a list of options; see select below"
67
+ },
68
+ {
69
+ type: "file",
70
+ aliases: ["files"],
71
+ help: "an upload; a plural field name takes several"
72
+ },
73
+ {
74
+ type: "relation",
75
+ aliases: ["references"],
76
+ help: "a record of the collection the field names"
77
+ },
78
+ {
79
+ type: "autodate",
80
+ aliases: [],
81
+ help: "set by PocketBase; see autodate below"
82
+ }
83
+ ], u = [{
84
+ type: "current_user",
85
+ aliases: [],
86
+ help: "the signed-in user, set on create (needs auth)"
87
+ }, {
88
+ type: "current_team",
89
+ aliases: [],
90
+ help: "the user's active team, set on create (needs teams)"
91
+ }], d = ["unique"], f = Object.fromEntries(l.flatMap(({ type: e, aliases: t }) => t.map((t) => [t, e]))), p = /^[a-zA-Z][a-zA-Z0-9_]*$/, m = "Must start with a letter and contain only letters, digits and underscores", h = 80;
92
+ function g(e, t, n = t) {
93
+ let r = [], i = n;
94
+ for (let n of e.split(" ")) {
95
+ let e = i.trim() === "" ? i + n : `${i} ${n}`;
96
+ e.length > h && i.trim() !== "" ? (r.push(i), i = t + n) : i = e;
97
+ }
98
+ return r.push(i), r;
99
+ }
100
+ function _(e) {
101
+ let t = Math.max(...[...l, ...u].map(({ type: e }) => e.length)) + 1, n = " ".repeat(2 + t + 1);
102
+ return e.flatMap(({ type: e, aliases: r, help: i }) => g(`${i}${r.length > 0 ? ` (also: ${r.join(", ")})` : ""}`, n, ` ${e.padEnd(t)}`));
103
+ }
104
+ function v(e, t) {
105
+ return [
106
+ "",
107
+ `${e}:`,
108
+ ...t
109
+ ];
110
+ }
111
+ function y(e) {
112
+ return g(e, " ");
113
+ }
114
+ var b = [
115
+ "Fields are written name:type, one argument each:",
116
+ "",
117
+ " title:text! body:editor state:select(draft,published) author:current_user",
118
+ "",
119
+ ...y("A name starts with a letter and holds letters, digits and underscores. Leave the fields out to use the ones an existing collection has.").map((e) => e.slice(2)),
120
+ ...v("Types", _(l)),
121
+ ...v("Modifiers", [
122
+ " ! after the type: the field is required name:text!",
123
+ " :unique a third segment: no two records share it slug:text!:unique",
124
+ ...g("An empty value counts as a value: make a unique field required, or only one record can leave it blank.", " ")
125
+ ]),
126
+ ...v("select", [
127
+ ...y("Options go in parentheses, as value or value:Label. Quote a value or label that holds a comma or a colon, and quote the whole argument for the shell. A plural field name takes several options, a singular one takes one."),
128
+ "",
129
+ " state:select(draft,published)",
130
+ " 'size:select(s:Small,m:Medium,l:Large)!'",
131
+ " tags:select(red,green,blue)"
132
+ ]),
133
+ ...v("Relations", [
134
+ ...y("Name the collection as the type, singular or plural, or use relation (or references) to take the collection from the field name. A plural field name holds several records, a singular one holds one."),
135
+ "",
136
+ " owner:user one record of users, in a field named owner",
137
+ " members:users several records of users",
138
+ " category:relation one record of categories",
139
+ " tags:references several records of tags"
140
+ ]),
141
+ ...v("Set by the server", _(u)),
142
+ "",
143
+ " author:current_user team:current_team",
144
+ ...v("autodate", [...y("The name says when PocketBase sets it: with \"create\" in it, when the record is created; with \"update\", then and on every update. created_at and updatedAt both work. Every new collection gets a created and an updated field of its own.")])
145
+ ].join("\n"), x = /* @__PURE__ */ n(((e, n, r) => {
146
+ (function(r, i) {
147
+ /* istanbul ignore else */
148
+ typeof t == "function" && typeof e == "object" && typeof n == "object" ? n.exports = i() : typeof define == "function" && define.amd ? define(function() {
149
+ return i();
150
+ }) : r.pluralize = i();
151
+ })(r, function() {
152
+ var e = [], t = [], n = {}, r = {}, i = {};
153
+ function a(e) {
154
+ return typeof e == "string" ? RegExp("^" + e + "$", "i") : e;
155
+ }
156
+ function o(e, t) {
157
+ return e === t ? t : e === e.toLowerCase() ? t.toLowerCase() : e === e.toUpperCase() ? t.toUpperCase() : e[0] === e[0].toUpperCase() ? t.charAt(0).toUpperCase() + t.substr(1).toLowerCase() : t.toLowerCase();
158
+ }
159
+ function s(e, t) {
160
+ return e.replace(/\$(\d{1,2})/g, function(e, n) {
161
+ return t[n] || "";
162
+ });
163
+ }
164
+ function c(e, t) {
165
+ return e.replace(t[0], function(n, r) {
166
+ var i = s(t[1], arguments);
167
+ return o(n === "" ? e[r - 1] : n, i);
168
+ });
169
+ }
170
+ function l(e, t, r) {
171
+ if (!e.length || n.hasOwnProperty(e)) return t;
172
+ for (var i = r.length; i--;) {
173
+ var a = r[i];
174
+ if (a[0].test(t)) return c(t, a);
175
+ }
176
+ return t;
177
+ }
178
+ function u(e, t, n) {
179
+ return function(r) {
180
+ var i = r.toLowerCase();
181
+ return t.hasOwnProperty(i) ? o(r, i) : e.hasOwnProperty(i) ? o(r, e[i]) : l(i, r, n);
182
+ };
183
+ }
184
+ function d(e, t, n, r) {
185
+ return function(r) {
186
+ var i = r.toLowerCase();
187
+ return t.hasOwnProperty(i) ? !0 : !e.hasOwnProperty(i) && l(i, i, n) === i;
188
+ };
189
+ }
190
+ function f(e, t, n) {
191
+ var r = t === 1 ? f.singular(e) : f.plural(e);
192
+ return (n ? t + " " : "") + r;
193
+ }
194
+ return f.plural = u(i, r, e), f.isPlural = d(i, r, e), f.singular = u(r, i, t), f.isSingular = d(r, i, t), f.addPluralRule = function(t, n) {
195
+ e.push([a(t), n]);
196
+ }, f.addSingularRule = function(e, n) {
197
+ t.push([a(e), n]);
198
+ }, f.addUncountableRule = function(e) {
199
+ typeof e == "string" ? n[e.toLowerCase()] = !0 : (f.addPluralRule(e, "$0"), f.addSingularRule(e, "$0"));
200
+ }, f.addIrregularRule = function(e, t) {
201
+ t = t.toLowerCase(), e = e.toLowerCase(), i[e] = t, r[t] = e;
202
+ }, [
203
+ ["I", "we"],
204
+ ["me", "us"],
205
+ ["he", "they"],
206
+ ["she", "they"],
207
+ ["them", "them"],
208
+ ["myself", "ourselves"],
209
+ ["yourself", "yourselves"],
210
+ ["itself", "themselves"],
211
+ ["herself", "themselves"],
212
+ ["himself", "themselves"],
213
+ ["themself", "themselves"],
214
+ ["is", "are"],
215
+ ["was", "were"],
216
+ ["has", "have"],
217
+ ["this", "these"],
218
+ ["that", "those"],
219
+ ["echo", "echoes"],
220
+ ["dingo", "dingoes"],
221
+ ["volcano", "volcanoes"],
222
+ ["tornado", "tornadoes"],
223
+ ["torpedo", "torpedoes"],
224
+ ["genus", "genera"],
225
+ ["viscus", "viscera"],
226
+ ["stigma", "stigmata"],
227
+ ["stoma", "stomata"],
228
+ ["dogma", "dogmata"],
229
+ ["lemma", "lemmata"],
230
+ ["schema", "schemata"],
231
+ ["anathema", "anathemata"],
232
+ ["ox", "oxen"],
233
+ ["axe", "axes"],
234
+ ["die", "dice"],
235
+ ["yes", "yeses"],
236
+ ["foot", "feet"],
237
+ ["eave", "eaves"],
238
+ ["goose", "geese"],
239
+ ["tooth", "teeth"],
240
+ ["quiz", "quizzes"],
241
+ ["human", "humans"],
242
+ ["proof", "proofs"],
243
+ ["carve", "carves"],
244
+ ["valve", "valves"],
245
+ ["looey", "looies"],
246
+ ["thief", "thieves"],
247
+ ["groove", "grooves"],
248
+ ["pickaxe", "pickaxes"],
249
+ ["passerby", "passersby"]
250
+ ].forEach(function(e) {
251
+ return f.addIrregularRule(e[0], e[1]);
252
+ }), [
253
+ [/s?$/i, "s"],
254
+ [/[^\u0000-\u007F]$/i, "$0"],
255
+ [/([^aeiou]ese)$/i, "$1"],
256
+ [/(ax|test)is$/i, "$1es"],
257
+ [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, "$1es"],
258
+ [/(e[mn]u)s?$/i, "$1s"],
259
+ [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, "$1"],
260
+ [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, "$1i"],
261
+ [/(alumn|alg|vertebr)(?:a|ae)$/i, "$1ae"],
262
+ [/(seraph|cherub)(?:im)?$/i, "$1im"],
263
+ [/(her|at|gr)o$/i, "$1oes"],
264
+ [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, "$1a"],
265
+ [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, "$1a"],
266
+ [/sis$/i, "ses"],
267
+ [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, "$1$2ves"],
268
+ [/([^aeiouy]|qu)y$/i, "$1ies"],
269
+ [/([^ch][ieo][ln])ey$/i, "$1ies"],
270
+ [/(x|ch|ss|sh|zz)$/i, "$1es"],
271
+ [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, "$1ices"],
272
+ [/\b((?:tit)?m|l)(?:ice|ouse)$/i, "$1ice"],
273
+ [/(pe)(?:rson|ople)$/i, "$1ople"],
274
+ [/(child)(?:ren)?$/i, "$1ren"],
275
+ [/eaux$/i, "$0"],
276
+ [/m[ae]n$/i, "men"],
277
+ ["thou", "you"]
278
+ ].forEach(function(e) {
279
+ return f.addPluralRule(e[0], e[1]);
280
+ }), [
281
+ [/s$/i, ""],
282
+ [/(ss)$/i, "$1"],
283
+ [/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, "$1fe"],
284
+ [/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, "$1f"],
285
+ [/ies$/i, "y"],
286
+ [/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i, "$1ie"],
287
+ [/\b(mon|smil)ies$/i, "$1ey"],
288
+ [/\b((?:tit)?m|l)ice$/i, "$1ouse"],
289
+ [/(seraph|cherub)im$/i, "$1"],
290
+ [/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, "$1"],
291
+ [/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, "$1sis"],
292
+ [/(movie|twelve|abuse|e[mn]u)s$/i, "$1"],
293
+ [/(test)(?:is|es)$/i, "$1is"],
294
+ [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, "$1us"],
295
+ [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, "$1um"],
296
+ [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, "$1on"],
297
+ [/(alumn|alg|vertebr)ae$/i, "$1a"],
298
+ [/(cod|mur|sil|vert|ind)ices$/i, "$1ex"],
299
+ [/(matr|append)ices$/i, "$1ix"],
300
+ [/(pe)(rson|ople)$/i, "$1rson"],
301
+ [/(child)ren$/i, "$1"],
302
+ [/(eau)x?$/i, "$1"],
303
+ [/men$/i, "man"]
304
+ ].forEach(function(e) {
305
+ return f.addSingularRule(e[0], e[1]);
306
+ }), [
307
+ "adulthood",
308
+ "advice",
309
+ "agenda",
310
+ "aid",
311
+ "aircraft",
312
+ "alcohol",
313
+ "ammo",
314
+ "analytics",
315
+ "anime",
316
+ "athletics",
317
+ "audio",
318
+ "bison",
319
+ "blood",
320
+ "bream",
321
+ "buffalo",
322
+ "butter",
323
+ "carp",
324
+ "cash",
325
+ "chassis",
326
+ "chess",
327
+ "clothing",
328
+ "cod",
329
+ "commerce",
330
+ "cooperation",
331
+ "corps",
332
+ "debris",
333
+ "diabetes",
334
+ "digestion",
335
+ "elk",
336
+ "energy",
337
+ "equipment",
338
+ "excretion",
339
+ "expertise",
340
+ "firmware",
341
+ "flounder",
342
+ "fun",
343
+ "gallows",
344
+ "garbage",
345
+ "graffiti",
346
+ "hardware",
347
+ "headquarters",
348
+ "health",
349
+ "herpes",
350
+ "highjinks",
351
+ "homework",
352
+ "housework",
353
+ "information",
354
+ "jeans",
355
+ "justice",
356
+ "kudos",
357
+ "labour",
358
+ "literature",
359
+ "machinery",
360
+ "mackerel",
361
+ "mail",
362
+ "media",
363
+ "mews",
364
+ "moose",
365
+ "music",
366
+ "mud",
367
+ "manga",
368
+ "news",
369
+ "only",
370
+ "personnel",
371
+ "pike",
372
+ "plankton",
373
+ "pliers",
374
+ "police",
375
+ "pollution",
376
+ "premises",
377
+ "rain",
378
+ "research",
379
+ "rice",
380
+ "salmon",
381
+ "scissors",
382
+ "series",
383
+ "sewage",
384
+ "shambles",
385
+ "shrimp",
386
+ "software",
387
+ "species",
388
+ "staff",
389
+ "swine",
390
+ "tennis",
391
+ "traffic",
392
+ "transportation",
393
+ "trout",
394
+ "tuna",
395
+ "wealth",
396
+ "welfare",
397
+ "whiting",
398
+ "wildebeest",
399
+ "wildlife",
400
+ "you",
401
+ /pok[eé]mon$/i,
402
+ /[^aeiou]ese$/i,
403
+ /deer$/i,
404
+ /fish$/i,
405
+ /measles$/i,
406
+ /o[iu]s$/i,
407
+ /pox$/i,
408
+ /sheep$/i
409
+ ].forEach(f.addUncountableRule), f;
410
+ });
411
+ })), S = /* @__PURE__ */ e(x(), 1), ee = /* @__PURE__ */ new Set(/* @__PURE__ */ "break.case.catch.class.const.continue.debugger.default.delete.do.else.export.extends.finally.for.function.if.import.in.instanceof.new.return.super.switch.this.throw.try.typeof.var.void.while.with.yield.let.static.package.protected.private.public.interface.enum.implements.type.namespace.null.true.false.await.async.arguments.constructor".split(".")), te = {
412
+ function: "fn",
413
+ interface: "iface",
414
+ type: "type_",
415
+ enum: "enum_",
416
+ const: "const_",
417
+ let: "let_",
418
+ var: "var_",
419
+ class: "class_",
420
+ default: "default_",
421
+ delete: "delete_",
422
+ new: "new_",
423
+ import: "import_",
424
+ export: "export_",
425
+ extends: "extends_",
426
+ super: "super_",
427
+ return: "return_",
428
+ case: "case_",
429
+ switch: "switch_",
430
+ try: "try_",
431
+ catch: "catch_",
432
+ finally: "finally_",
433
+ do: "do_",
434
+ while: "while_",
435
+ for: "for_",
436
+ if: "if_",
437
+ in: "in_",
438
+ of: "of_",
439
+ with: "with_",
440
+ this: "this_",
441
+ throw: "throw_",
442
+ void: "void_",
443
+ typeof: "typeOf",
444
+ instanceof: "instanceOf",
445
+ yield: "yield_",
446
+ await: "await_",
447
+ async: "async_",
448
+ implements: "implements_",
449
+ package: "package_",
450
+ private: "private_",
451
+ protected: "protected_",
452
+ public: "public_",
453
+ namespace: "namespace_",
454
+ null: "nullValue",
455
+ true: "trueValue",
456
+ false: "falseValue",
457
+ arguments: "args",
458
+ constructor: "ctor"
459
+ };
460
+ function C(e) {
461
+ return ee.has(e) ? te[e] ?? `${e}_` : e;
462
+ }
463
+ function w(e) {
464
+ if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(e)) throw new c("Model name must start with a letter and contain only alphanumeric characters, dash, or underscore. Use --route to specify a custom route path.");
465
+ }
466
+ function T(e) {
467
+ let t = S.default.singular(o(e)), n = S.default.plural(t), s = r(t);
468
+ return {
469
+ name: C(s),
470
+ pluralName: C(r(n)),
471
+ typeName: i(t),
472
+ tableName: a(n),
473
+ displayName: t,
474
+ pluralDisplayName: n,
475
+ schemaName: `${C(s)}Schema`
476
+ };
477
+ }
478
+ // src/parse/collections.ts
479
+ var E = /* @__PURE__ */ "title.name.label.display.display_name.full_name.first_name.last_name.given_name.surname.family_name.username.handle.nickname.email.phone.phone_number.headline.subject.caption.summary.description.sku.code.key.identifier.ref.reference.slug.path.url.id".split(".");
480
+ function ne(e) {
481
+ for (let t of E) if (e.some((e) => e.name === t)) return t;
482
+ return "id";
483
+ }
484
+ function re(e) {
485
+ return e.map((e) => e.name).filter((e) => !e.startsWith("_"));
486
+ }
487
+ function ie(e) {
488
+ return Object.fromEntries(e.map((e) => [e.name, e.id]));
489
+ }
490
+ function D(e) {
491
+ return Object.fromEntries(e.map((e) => [e.name, ne(e.fields)]));
492
+ }
493
+ // src/parse/permissions.ts
494
+ var ae = [
495
+ "user",
496
+ "owner",
497
+ "created_by",
498
+ "author",
499
+ "member",
500
+ "account",
501
+ "creator"
502
+ ];
503
+ function O(e) {
504
+ return e.toLowerCase();
505
+ }
506
+ function k(e) {
507
+ return {
508
+ rule: "@request.auth.id != \"\"",
509
+ ownershipChainCollections: [e],
510
+ ownershipChainFields: [],
511
+ operator: "="
512
+ };
513
+ }
514
+ function A(e, t, n = {}) {
515
+ let r = new Set((n.authCollections ?? ["users"]).map(O)), i = new Set((n.userFieldHints ?? ae).map(O)), a = n.maxDepth ?? 8, o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
516
+ for (let t of e) o.set(t.name, t), s.set(t.id, t);
517
+ if (!o.has(t)) return k(t);
518
+ if (r.has(O(t))) return {
519
+ rule: "@request.auth.id = id",
520
+ ownershipChainCollections: [t],
521
+ ownershipChainFields: [],
522
+ operator: "="
523
+ };
524
+ function c(e) {
525
+ let t = O(e);
526
+ return t === "user" ? 50 : i.has(t) ? 20 : 0;
527
+ }
528
+ function l(e) {
529
+ let t = o.get(e);
530
+ if (!t?.fields) return [];
531
+ let n = [];
532
+ for (let r of t.fields) {
533
+ if (r.type !== "relation" || !r.collectionId) continue;
534
+ let t = s.get(r.collectionId);
535
+ t && n.push({
536
+ from: e,
537
+ fieldName: r.name,
538
+ to: t.name,
539
+ isMulti: !!(r.maxSelect && r.maxSelect > 1),
540
+ hintScore: c(r.name)
541
+ });
542
+ }
543
+ return n.sort((e, t) => e.fieldName.localeCompare(t.fieldName)), n;
544
+ }
545
+ function u(e) {
546
+ return r.has(O(e));
547
+ }
548
+ function d(e) {
549
+ if (e.length === 0) return !1;
550
+ for (let t = 0; t < e.length - 1; t++) if (e[t].isMulti) return !1;
551
+ return u(e[e.length - 1].to);
552
+ }
553
+ function f(e) {
554
+ let t = e[e.length - 1], n = +!!t.isMulti, r = +!!e.every((e) => !e.isMulti), i = e.reduce((e, t) => e + t.hintScore, 0), a = +(O(t.fieldName) === "user");
555
+ return 100 * e.length + 50 * n - 40 * a - 15 * r - i;
556
+ }
557
+ function p(e) {
558
+ return e.map((e) => `${e.from}.${e.fieldName}->${e.to}`).join("|");
559
+ }
560
+ let m = [], h = /* @__PURE__ */ new Set([t]);
561
+ function g(e, t, n) {
562
+ if (!(n > a)) {
563
+ if (t.length > 0 && u(t[t.length - 1].to) && d(t)) m.push([...t]);
564
+ else for (let r of l(e)) h.has(r.to) || (!r.isMulti || u(r.to)) && (h.add(r.to), t.push(r), g(r.to, t, n + 1), t.pop(), h.delete(r.to));
565
+ }
566
+ }
567
+ if (g(t, [], 0), m.length === 0) return k(t);
568
+ m.sort((e, t) => {
569
+ let n = f(e) - f(t);
570
+ return n === 0 ? p(e).localeCompare(p(t)) : n;
571
+ });
572
+ let _ = m[0], v = _.map((e) => e.fieldName), y = [t, ..._.map((e) => e.to)], b = _[_.length - 1].isMulti ? "?=" : "=", x = v.join(".");
573
+ return {
574
+ rule: `@request.auth.id ${b} ${n.includeRootPrefix ? (n.rootPrefix ?? t) + "." : ""}${x}.id`,
575
+ ownershipChainCollections: y,
576
+ ownershipChainFields: v,
577
+ operator: b
578
+ };
579
+ }
580
+ // src/parse/fields.ts
581
+ function j(e) {
582
+ let t = null, n = !1, r = 0;
583
+ for (let i = 0; i < e.length; i++) {
584
+ let a = e[i];
585
+ if (n) n = !1;
586
+ else if (t) {
587
+ if (a === "\\") {
588
+ n = !0;
589
+ continue;
590
+ }
591
+ a === t && (t = null);
592
+ } else if (a === "\"" || a === "'") t = a;
593
+ else if (a === "(") r++;
594
+ else if (a === ")") r = Math.max(0, r - 1);
595
+ else if (a === ":" && r === 0) return [e.slice(0, i), e.slice(i + 1)];
596
+ }
597
+ return [e, ""];
598
+ }
599
+ function oe(e) {
600
+ let [t, n] = j(e), [r, i] = j(n), a = [], o = i;
601
+ for (; o !== "";) {
602
+ let [e, t] = j(o);
603
+ a.push(e), o = t;
604
+ }
605
+ return {
606
+ name: t,
607
+ type: r,
608
+ modifiers: a
609
+ };
610
+ }
611
+ function M(e) {
612
+ let t = e.trim();
613
+ return t.startsWith("\"") && t.endsWith("\"") || t.startsWith("'") && t.endsWith("'") ? t.slice(1, -1).replace(/\\(["'])/g, "$1") : t;
614
+ }
615
+ function N(e) {
616
+ let t = -1, n = null, r = !1;
617
+ for (let i = 0; i < e.length; i++) {
618
+ let a = e[i];
619
+ if (r) r = !1;
620
+ else if (n) {
621
+ if (a === "\\") {
622
+ r = !0;
623
+ continue;
624
+ }
625
+ a === n && (n = null);
626
+ } else if (a === "\"" || a === "'") n = a;
627
+ else if (a === ":") {
628
+ t = i;
629
+ break;
630
+ }
631
+ }
632
+ let i, a;
633
+ return t >= 0 ? (i = e.slice(0, t).trim(), a = e.slice(t + 1).trim()) : (i = e.trim(), a = i), {
634
+ label: M(a),
635
+ value: M(i)
636
+ };
637
+ }
638
+ function se(e) {
639
+ let t = [], n = "", r = null, i = !1;
640
+ for (let a = 0; a < e.length; a++) {
641
+ let o = e[a];
642
+ if (i) n += o, i = !1;
643
+ else if (r) {
644
+ if (o === "\\") {
645
+ i = !0, n += o;
646
+ continue;
647
+ }
648
+ if (o === r) {
649
+ r = null, n += o;
650
+ continue;
651
+ }
652
+ n += o;
653
+ } else if (o === "\"" || o === "'") r = o, n += o;
654
+ else if (o === ",") {
655
+ let e = n.trim();
656
+ e.length > 0 && t.push(N(e)), n = "";
657
+ } else n += o;
658
+ }
659
+ let a = n.trim();
660
+ return a.length > 0 && t.push(N(a)), t;
661
+ }
662
+ function P(e) {
663
+ let t = e.toLowerCase(), n = t.includes("update"), r = n || t.includes("create");
664
+ return r ? {
665
+ onCreate: r,
666
+ onUpdate: n
667
+ } : void 0;
668
+ }
669
+ function ce(e) {
670
+ let t = e.endsWith("!"), n = t ? e.slice(0, -1) : e, r = [];
671
+ return n.startsWith("select(") && n.endsWith(")") && (r = se(n.slice(7, -1)), n = "select"), Object.prototype.hasOwnProperty.call(f, n) && (n = f[n]), {
672
+ type: n,
673
+ required: t,
674
+ selectOptions: r
675
+ };
676
+ }
677
+ function F(e) {
678
+ let t = S.default.singular(e);
679
+ return e === S.default.plural(t) ? 99 : 1;
680
+ }
681
+ function I(e, t, n, i, a) {
682
+ let o = T(t), s = S.default.singular(e), c = S.default.plural(s);
683
+ return {
684
+ collectionId: i[t],
685
+ displayField: a[t] ?? "id",
686
+ relatedModel: o,
687
+ singularRelationName: r(`${n.displayName} ${o.displayName}`),
688
+ pluralRelationName: r(`${n.displayName} ${o.pluralDisplayName}`),
689
+ maxSelect: e === c ? 999 : 1
690
+ };
691
+ }
692
+ var le = [
693
+ "text",
694
+ "number",
695
+ "bool",
696
+ "date",
697
+ "email",
698
+ "password",
699
+ "url",
700
+ "editor",
701
+ "json",
702
+ "geoPoint"
703
+ ], L = [
704
+ "json",
705
+ "geoPoint",
706
+ "file",
707
+ "password",
708
+ "autodate",
709
+ "bool"
710
+ ];
711
+ function R(e, t, n) {
712
+ for (let r of t) {
713
+ if (!d.includes(r)) throw new c(`Invalid field modifier: "${r}" in ${n}. Valid modifiers are: ${d.join(", ")} (written name:type:modifier)`);
714
+ if (r === "unique") {
715
+ if (L.includes(e.type)) throw new c(`Invalid field modifier: a ${e.type} field cannot be unique (${n})`);
716
+ if ("maxSelect" in e && e.maxSelect > 1) throw new c(`Invalid field modifier: "${e.name}" holds several values, so it cannot be unique (${n})`);
717
+ e.unique = !0;
718
+ }
719
+ }
720
+ return e;
721
+ }
722
+ function z(e, t, n, r, i) {
723
+ let a = o(e), { type: s, required: u, selectOptions: d } = t, f = re(r), p = ie(r), m = D(r), h = f.map((e) => S.default.singular(e));
724
+ if (s === "current_user") {
725
+ if (!i.features.auth) throw new c("Field type \"current_user\" requires the auth feature. Run `vela enable auth` to enable it.");
726
+ if (!p.users) throw new c("Field type \"current_user\" requires a \"users\" collection but none was found.");
727
+ let t = I(e, "users", n, p, m);
728
+ return {
729
+ type: "relation",
730
+ name: e,
731
+ title: a,
732
+ required: !0,
733
+ collectionId: t.collectionId,
734
+ maxSelect: 1,
735
+ displayField: t.displayField,
736
+ relatedModel: t.relatedModel,
737
+ singularRelationName: t.singularRelationName,
738
+ pluralRelationName: t.pluralRelationName,
739
+ isCurrentUser: !0,
740
+ isCurrentTeam: !1
741
+ };
742
+ }
743
+ if (s === "current_team") {
744
+ if (!i.features.teams) throw new c("Field type \"current_team\" requires the teams feature. Run `vela enable teams` to enable it.");
745
+ if (!p.teams) throw new c("Field type \"current_team\" requires a \"teams\" collection but none was found.");
746
+ let t = I(e, "teams", n, p, m);
747
+ return {
748
+ type: "relation",
749
+ name: e,
750
+ title: a,
751
+ required: !0,
752
+ collectionId: t.collectionId,
753
+ maxSelect: 1,
754
+ displayField: t.displayField,
755
+ relatedModel: t.relatedModel,
756
+ singularRelationName: t.singularRelationName,
757
+ pluralRelationName: t.pluralRelationName,
758
+ isCurrentUser: !1,
759
+ isCurrentTeam: !0
760
+ };
761
+ }
762
+ if (s === "autodate") {
763
+ let t = P(e);
764
+ if (!t) throw new c(`Invalid autodate field: ${e}. The name says when the field is set, so it has to hold "create" or "update": created, created_at, updated, updated_at.`);
765
+ return {
766
+ type: "autodate",
767
+ name: e,
768
+ title: a,
769
+ required: u,
770
+ ...t
771
+ };
772
+ }
773
+ if (s === "select") return {
774
+ type: "select",
775
+ name: e,
776
+ title: a,
777
+ required: u,
778
+ maxSelect: Math.max(1, Math.min(F(e), d.length)),
779
+ options: d
780
+ };
781
+ if (s === "file") return {
782
+ type: "file",
783
+ name: e,
784
+ title: a,
785
+ required: u,
786
+ maxSelect: F(e)
787
+ };
788
+ if (s === "relation") {
789
+ let t = S.default.singular(e), r = S.default.plural(t);
790
+ if (!f.includes(r)) throw new c(`Invalid relation field: ${e}. Must be one of ${f.join(", ")} (singular or plural)`);
791
+ return {
792
+ type: "relation",
793
+ name: e,
794
+ title: a,
795
+ required: u,
796
+ ...I(e, r, n, p, m),
797
+ isCurrentUser: !1,
798
+ isCurrentTeam: !1
799
+ };
800
+ }
801
+ if (f.includes(s)) return {
802
+ type: "relation",
803
+ name: e,
804
+ title: a,
805
+ required: u,
806
+ ...I(e, s, n, p, m),
807
+ isCurrentUser: !1,
808
+ isCurrentTeam: !1
809
+ };
810
+ if (h.includes(s)) {
811
+ let t = S.default.plural(s);
812
+ if (f.includes(t)) {
813
+ let r = I(e, t, n, p, m);
814
+ return {
815
+ type: "relation",
816
+ name: e,
817
+ title: a,
818
+ required: u,
819
+ collectionId: r.collectionId,
820
+ displayField: r.displayField,
821
+ relatedModel: r.relatedModel,
822
+ singularRelationName: r.singularRelationName,
823
+ pluralRelationName: r.pluralRelationName,
824
+ maxSelect: 1,
825
+ isCurrentUser: !1,
826
+ isCurrentTeam: !1
827
+ };
828
+ }
829
+ }
830
+ if (!le.includes(s)) {
831
+ let e = [.../* @__PURE__ */ new Set([
832
+ ...l.map((e) => e.type === "relation" ? "references" : e.type),
833
+ ...i.features.auth ? ["current_user"] : [],
834
+ ...i.features.teams ? ["current_team"] : [],
835
+ ...f
836
+ ])];
837
+ throw new c(`Invalid field type: ${s}. Valid types are: ${e.join(", ")}`);
838
+ }
839
+ return {
840
+ type: s,
841
+ name: e,
842
+ title: a,
843
+ required: u
844
+ };
845
+ }
846
+ function B(e, t, n, r) {
847
+ let i = [];
848
+ for (let a of e) {
849
+ let { name: e, type: o, modifiers: s } = oe(a);
850
+ if (!e || !o) throw new c(`Invalid field format: ${a}. Expected format: name:type, name:type! or name:type:unique`);
851
+ if (!p.test(e)) throw new c(`Invalid field name: ${e}. ${m}`);
852
+ let l = ce(o);
853
+ i.push(R(z(e, l, t, n, r), s, a));
854
+ }
855
+ return {
856
+ fields: i,
857
+ auth: r.features.auth ? A([...n, {
858
+ id: "new",
859
+ name: t.tableName,
860
+ type: "base",
861
+ fields: i.map((e) => ({
862
+ name: e.name,
863
+ type: e.type,
864
+ collectionId: e.type === "relation" ? e.collectionId : void 0,
865
+ maxSelect: "maxSelect" in e ? e.maxSelect : void 0
866
+ }))
867
+ }], t.tableName) : void 0
868
+ };
869
+ }
870
+ // src/core/shared.ts
871
+ var V = ["text"], H = Object.fromEntries(l.flatMap(({ type: e, aliases: t }) => [e, ...t].map((t) => [t, e])));
872
+ function U(e) {
873
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e) ? e : `'${e}'`;
874
+ }
875
+ function W(e, t) {
876
+ let n = e.type === "select" ? `[${(e.options ?? []).map((e) => JSON.stringify(e.value)).join(", ")}]` : "", r;
877
+ switch (e.type) {
878
+ case "text":
879
+ r = "z.string()";
880
+ break;
881
+ case "number":
882
+ r = "z.number()";
883
+ break;
884
+ case "bool":
885
+ r = "z.boolean().default(false)";
886
+ break;
887
+ case "date":
888
+ r = t.forForm ? "z.string()" : "z.date()";
889
+ break;
890
+ case "email":
891
+ r = "z.email()";
892
+ break;
893
+ case "password":
894
+ r = "z.string()";
895
+ break;
896
+ case "url":
897
+ r = "z.url()";
898
+ break;
899
+ case "editor":
900
+ r = "z.string()";
901
+ break;
902
+ case "autodate":
903
+ r = t.forForm ? "z.string()" : "z.date()";
904
+ break;
905
+ case "select":
906
+ r = n ? (e.maxSelect ?? 1) > 1 ? `z.array(z.enum(${n}))` : `z.enum(${n})` : "z.string()";
907
+ break;
908
+ case "file":
909
+ r = (e.maxSelect ?? 1) > 1 ? "z.string().array()" : "z.union([z.instanceof(File), z.string()])";
910
+ break;
911
+ case "json":
912
+ r = t.remote ? "z.string()" : "z.any()";
913
+ break;
914
+ case "geoPoint":
915
+ r = t.forForm ? `z.preprocess((val) => {
916
+ if (typeof val === "string") {
917
+ return val;
918
+ }
919
+ return JSON.stringify(val);
920
+ }, z.string()${e.required ? "" : ".optional()"})` : s`
921
+ z.object({
922
+ lat: z.number().min(-90).max(90),
923
+ lon: z.number().min(-180).max(180)
924
+ })
925
+ `;
926
+ break;
927
+ case "relation":
928
+ r = (e.maxSelect ?? 1) > 1 ? "z.array(z.string())" : "z.string()";
929
+ break;
930
+ default: return e.type;
931
+ }
932
+ return V.includes(e.type) ? e.required ? `${r}.nonempty()` : `${r}.optional()` : e.required || e.type === "geoPoint" ? r : e.type === "file" && (e.maxSelect ?? 1) <= 1 ? `${r}.optional().default("")` : `${r}.optional()`;
933
+ }
934
+ async function G(e) {
935
+ if (e.env === "runtime") {
936
+ if (!e.getCollections) throw Error("A `getCollections` provider is required when env is \"runtime\". It is supplied by the vela CLI; upgrade to vela >= 0.10.0.");
937
+ return await e.getCollections();
938
+ }
939
+ let { getPreviewCollections: t } = await import("./env.preview-C676UTOP.js");
940
+ return t(e);
941
+ }
942
+ async function ue(e, t, n) {
943
+ w(t);
944
+ let r = T(t), i = e.features.backend ? await G(e) : [];
945
+ if (n.length > 0) {
946
+ let { fields: t, auth: a } = B(n, r, i, e);
947
+ return {
948
+ model: r,
949
+ fields: t,
950
+ auth: a,
951
+ shouldCreateCollection: !0,
952
+ collections: i
953
+ };
954
+ }
955
+ if (!e.features.backend) throw new c("Cannot derive fields from a collection without a backend. Pass field definitions (e.g. `name:text email:email`) or run `vela enable backend` first.");
956
+ return {
957
+ model: r,
958
+ fields: pe(r, i, e),
959
+ auth: void 0,
960
+ shouldCreateCollection: !1,
961
+ collections: i
962
+ };
963
+ }
964
+ function K(e, t) {
965
+ let n = [];
966
+ for (let r of e) r.type === "file" && r.maxSelect > 1 ? (n.push({
967
+ name: r.name,
968
+ schema: W({
969
+ ...r,
970
+ required: !1
971
+ }, t)
972
+ }), n.push({
973
+ name: `${r.name}+`,
974
+ schema: "z.instanceof(File).array().optional()"
975
+ }), n.push({
976
+ name: `${r.name}-`,
977
+ schema: "z.string().array().optional()"
978
+ })) : n.push({
979
+ name: r.name,
980
+ schema: W(r, t)
981
+ });
982
+ return n;
983
+ }
984
+ function de(e, t, n) {
985
+ let r = [];
986
+ n.includeModelFields && (r.push({
987
+ name: "id",
988
+ schema: W({
989
+ name: "id",
990
+ type: "text",
991
+ required: !1
992
+ }, n)
993
+ }), r.push({
994
+ name: "collectionId",
995
+ schema: W({
996
+ name: "collectionId",
997
+ type: "text",
998
+ required: !1
999
+ }, n)
1000
+ })), r.push(...K(t, n));
1001
+ let i = r.map((e) => `${U(e.name)}: ${e.schema}`).join(",\n "), a = n.includeModelFields ? "\nimport type { Schemas } from \"@velastack/pocketbase\";" : "", o = n.includeModelFields ? ` satisfies Schemas["${e.tableName}"]` : "";
1002
+ return s`
1003
+ import { z } from "zod";${a}
1004
+
1005
+ export const ${e.schemaName} = z.object({
1006
+ ${i}
1007
+ })${o};
1008
+ `;
1009
+ }
1010
+ function fe(e) {
1011
+ let t = Object.prototype.hasOwnProperty.call(H, e) ? H[e] : void 0;
1012
+ if (!t) throw Error(`Unsupported collection field type "${e}" when generating from collection`);
1013
+ return t;
1014
+ }
1015
+ function pe(e, t, n) {
1016
+ let i = t.find((t) => t.name === e.tableName);
1017
+ if (!i) throw Error(`Collection "${e.tableName}" not found`);
1018
+ let a = D(t), s = new Map(t.map((e) => [e.id, e])), c = [];
1019
+ for (let t of i.fields) {
1020
+ if (t.name === "id" || t.system || t.type === "autodate" && X(t.name)) continue;
1021
+ let i = fe(t.type), l = !!t.required, u = o(t.name);
1022
+ if (i === "relation") {
1023
+ let i = t.collectionId ? s.get(t.collectionId) : void 0;
1024
+ if (!i) continue;
1025
+ let o = T(i.name);
1026
+ c.push({
1027
+ name: t.name,
1028
+ title: u,
1029
+ type: "relation",
1030
+ required: l,
1031
+ collectionId: i.id,
1032
+ maxSelect: t.maxSelect ?? 1,
1033
+ displayField: a[i.name] ?? "id",
1034
+ relatedModel: o,
1035
+ singularRelationName: r(`${e.displayName} ${o.displayName}`),
1036
+ pluralRelationName: r(`${e.displayName} ${o.pluralDisplayName}`),
1037
+ isCurrentUser: n.features.auth && i.name === "users" && /user|owner|author/i.test(t.name),
1038
+ isCurrentTeam: n.features.teams && i.name === "teams" && /team/i.test(t.name)
1039
+ });
1040
+ } else i === "select" ? c.push({
1041
+ name: t.name,
1042
+ title: u,
1043
+ type: "select",
1044
+ required: l,
1045
+ maxSelect: t.maxSelect ?? 1,
1046
+ options: (t.values ?? []).map((e) => ({
1047
+ label: e,
1048
+ value: e
1049
+ }))
1050
+ }) : i === "file" ? c.push({
1051
+ name: t.name,
1052
+ title: u,
1053
+ type: "file",
1054
+ required: l,
1055
+ maxSelect: t.maxSelect ?? 1
1056
+ }) : i === "autodate" ? c.push({
1057
+ name: t.name,
1058
+ title: u,
1059
+ type: "autodate",
1060
+ required: l,
1061
+ onCreate: t.onCreate ?? P(t.name)?.onCreate ?? !1,
1062
+ onUpdate: t.onUpdate ?? P(t.name)?.onUpdate ?? !1
1063
+ }) : c.push({
1064
+ name: t.name,
1065
+ title: u,
1066
+ type: i,
1067
+ required: l
1068
+ });
1069
+ }
1070
+ return c.filter((e) => e.name !== "id");
1071
+ }
1072
+ function me(e) {
1073
+ let t = e.filter((e) => e.type === "relation").map((e) => e.name);
1074
+ return t.length > 0 ? t.join(",") : void 0;
1075
+ }
1076
+ function q(e) {
1077
+ let t = /* @__PURE__ */ new Set(), n = [];
1078
+ for (let r of e) r.type === "relation" && (t.has(r.relatedModel.tableName) || (t.add(r.relatedModel.tableName), n.push(r.relatedModel)));
1079
+ return n;
1080
+ }
1081
+ function he(e, t) {
1082
+ return q(e).map((e) => `const ${e.pluralName} = await ${t}.collection("${e.tableName}").getFullList();`).join("\n ");
1083
+ }
1084
+ function ge(e) {
1085
+ return q(e).map((e) => e.pluralName).join(", ");
1086
+ }
1087
+ function J(e) {
1088
+ let t = {
1089
+ name: e.name,
1090
+ type: e.type,
1091
+ required: e.required
1092
+ };
1093
+ return e.type === "relation" ? {
1094
+ ...t,
1095
+ collectionId: e.collectionId,
1096
+ maxSelect: e.maxSelect
1097
+ } : e.type === "file" ? {
1098
+ ...t,
1099
+ maxSelect: e.maxSelect
1100
+ } : e.type === "select" ? {
1101
+ ...t,
1102
+ maxSelect: e.maxSelect,
1103
+ values: e.options.map((e) => e.value)
1104
+ } : e.type === "autodate" ? {
1105
+ ...t,
1106
+ onCreate: e.onCreate,
1107
+ onUpdate: e.onUpdate
1108
+ } : t;
1109
+ }
1110
+ var Y = [{
1111
+ name: "created",
1112
+ type: "autodate",
1113
+ onCreate: !0,
1114
+ onUpdate: !1
1115
+ }, {
1116
+ name: "updated",
1117
+ type: "autodate",
1118
+ onCreate: !0,
1119
+ onUpdate: !0
1120
+ }];
1121
+ function X(e) {
1122
+ return Y.some((t) => t.name === e);
1123
+ }
1124
+ var Z = [
1125
+ "auth",
1126
+ "owner",
1127
+ "superuser"
1128
+ ], _e = "@request.auth.id != \"\"";
1129
+ function ve(e) {
1130
+ let t = e.input?.rules;
1131
+ if (t == null || t === "") return;
1132
+ if (!Z.includes(t)) throw new c(`Invalid rules: ${JSON.stringify(t)}. Valid values are: ${Z.join(", ")}`);
1133
+ let n = t;
1134
+ if (n !== "superuser" && !e.features.auth) throw new c(`Rules "${n}" need the auth feature. Run \`vela enable auth\` first, or use "superuser" to keep the collection to the server's superuser client.`);
1135
+ return n;
1136
+ }
1137
+ function Q(e) {
1138
+ return {
1139
+ listRule: e,
1140
+ viewRule: e,
1141
+ createRule: e,
1142
+ updateRule: e,
1143
+ deleteRule: e
1144
+ };
1145
+ }
1146
+ function ye(e, t, n) {
1147
+ switch (n) {
1148
+ case void 0: return t ? Q(t.rule) : {};
1149
+ case "auth": return Q(_e);
1150
+ case "superuser": return Q(null);
1151
+ case "owner":
1152
+ if (!t || t.ownershipChainFields.length === 0) throw new c(`Rules "owner" need a relation from "${e.tableName}" to users, directly or through another collection, and none of its fields has one. Add one (for example \`user:current_user\`), or use rules "auth".`);
1153
+ return Q(t.rule);
1154
+ }
1155
+ }
1156
+ function be(e, t) {
1157
+ return t === "superuser" ? [`"${e.tableName}" has no API rules: only the superuser client can read or write it. Use \`locals.admin\` on the server; \`locals.pb\` and the browser get nothing.`] : [];
1158
+ }
1159
+ function xe(e, t, n) {
1160
+ let r = ve(e);
1161
+ if (r && !n) throw new c(`Rules are set when a collection is created, and "${t.tableName}" is not being created. Leave rules out, and change the collection's rules in a migration.`);
1162
+ return r;
1163
+ }
1164
+ function Se(e, t) {
1165
+ return `CREATE UNIQUE INDEX \`idx_${e}_${t}\` ON \`${e}\` (\`${t}\`)`;
1166
+ }
1167
+ function $(e, t) {
1168
+ return t.filter((e) => e.unique).map((t) => Se(e.tableName, t.name));
1169
+ }
1170
+ function Ce(e, t, n, r) {
1171
+ let i = new Set(t.map((e) => e.name)), a = Y.filter((e) => !i.has(e.name)), o = $(e, t);
1172
+ return {
1173
+ name: e.tableName,
1174
+ type: "base",
1175
+ ...ye(e, n, r),
1176
+ fields: [...t.map(J), ...a],
1177
+ ...o.length > 0 ? { indexes: o } : {}
1178
+ };
1179
+ }
1180
+ export { w as _, me as a, ue as c, K as d, J as f, T as g, B as h, G as i, xe as l, q as m, Ce as n, he as o, $ as p, de as r, ge as s, Z as t, be as u, x as v, b as y };
1181
+
1182
+ //# sourceMappingURL=shared-DJ4KvhTb.js.map