alinea 2.0.0-preview.7 → 2.0.0-preview.9

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 (301) hide show
  1. package/dist/.init/content/pages/welcome.json +1 -1
  2. package/dist/LICENSES.md +103 -103
  3. package/dist/adapter/next/cms.d.ts +18 -4
  4. package/dist/adapter/next/cms.js +141 -36
  5. package/dist/adapter/next/handler.d.ts +5 -1
  6. package/dist/adapter/next/handler.js +77 -17
  7. package/dist/adapter/next/node.d.ts +5 -0
  8. package/dist/adapter/next/node.js +16 -0
  9. package/dist/adapter/next/previews.d.ts +4 -1
  10. package/dist/adapter/next/previews.js +13 -1
  11. package/dist/adapter/next/renderStats.d.ts +45 -0
  12. package/dist/adapter/next/renderStats.js +142 -0
  13. package/dist/adapter/next/syncCheck.d.ts +8 -2
  14. package/dist/adapter/next/syncCheck.js +5 -11
  15. package/dist/adapter/next/with-alinea.js +6 -20
  16. package/dist/backend/HandleAction.d.ts +1 -1
  17. package/dist/backend/HandleAction.js +1 -1
  18. package/dist/backend/Handler.d.ts +2 -2
  19. package/dist/backend/Handler.js +45 -47
  20. package/dist/backend/api/CreateBackend.js +15 -3
  21. package/dist/backend/api/DatabaseApi.js +22 -135
  22. package/dist/backend/api/ProxyMedia.d.ts +2 -3
  23. package/dist/backend/api/ProxyMedia.js +7 -22
  24. package/dist/backend/api/database.js +15 -3
  25. package/dist/backend/resolver/ParsePreview.d.ts +2 -2
  26. package/dist/backend/router/NodeHandler.js +2 -0
  27. package/dist/backend/store/GeneratedDatabase.d.ts +8 -0
  28. package/dist/backend/store/GeneratedDatabase.js +33 -0
  29. package/dist/backend/store/GeneratedDatabaseNode.d.ts +4 -0
  30. package/dist/backend/store/GeneratedDatabaseNode.js +35 -0
  31. package/dist/backend/util/ORM.js +4 -2
  32. package/dist/bundled.d.ts +1565 -468
  33. package/dist/chunks/bun-sqlite-5SHXN3AT.js +18 -0
  34. package/dist/chunks/chunk-2BJ2IFQM.js +1085 -0
  35. package/dist/chunks/chunk-2PIFHEYR.js +364 -0
  36. package/dist/chunks/chunk-66YZ47TY.js +94 -0
  37. package/dist/chunks/chunk-76VMZTLN.js +55 -0
  38. package/dist/chunks/chunk-AIU6CMVT.js +495 -0
  39. package/dist/chunks/chunk-ASYKC6IE.js +103 -0
  40. package/dist/chunks/chunk-ATF42T2B.js +35 -0
  41. package/dist/chunks/{chunk-6P4UVRPH.js → chunk-DWR5A5KL.js} +6 -1
  42. package/dist/chunks/{chunk-NWQXN4SB.js → chunk-ETBQTP2S.js} +40 -29
  43. package/dist/chunks/chunk-ETWOY4AL.js +100 -0
  44. package/dist/chunks/chunk-K62JP6HR.js +22 -0
  45. package/dist/chunks/chunk-MOWR65LM.js +610 -0
  46. package/dist/chunks/chunk-N47Y62CI.js +396 -0
  47. package/dist/chunks/chunk-QBPYWU6C.js +24 -0
  48. package/dist/chunks/{chunk-X47OVDF3.js → chunk-QJGGYF6E.js} +356 -1000
  49. package/dist/chunks/chunk-QSN6RH6X.js +94 -0
  50. package/dist/chunks/{chunk-I4GC3E65.js → chunk-UPY2RUZF.js} +0 -1
  51. package/dist/chunks/chunk-XCZXR3C2.js +112 -0
  52. package/dist/chunks/chunk-XTWYBWP2.js +81 -0
  53. package/dist/chunks/node-sqlite-XVNTNMCY.js +18 -0
  54. package/dist/cli/Generate.js +74 -64
  55. package/dist/cli/Serve.js +1 -1
  56. package/dist/cli/bin.js +6 -1
  57. package/dist/cli/generate/CopyStaticFiles.js +17 -14
  58. package/dist/cli/generate/DevDB.d.ts +22 -5
  59. package/dist/cli/generate/DevDB.js +138 -24
  60. package/dist/cli/serve/CreateLocalServer.js +22 -4
  61. package/dist/cli/serve/DevServer.d.ts +2 -0
  62. package/dist/cli/serve/DevServer.js +7 -2
  63. package/dist/cli/serve/LiveReload.d.ts +1 -1
  64. package/dist/cli/serve/LiveReload.js +3 -0
  65. package/dist/cloud/CloudRemote.js +2 -1
  66. package/dist/components/Breadcrumbs.js +2 -2
  67. package/dist/components/Calendar.js +7 -7
  68. package/dist/components/Checkbox.js +1 -1
  69. package/dist/components/ColorSwatchPicker.js +2 -2
  70. package/dist/components/ComboBox.js +14 -14
  71. package/dist/components/DateField.js +1 -1
  72. package/dist/components/DatePicker.js +6 -6
  73. package/dist/components/DateRangePicker.js +4 -4
  74. package/dist/components/Disclosure.js +8 -8
  75. package/dist/components/Label.js +6 -6
  76. package/dist/components/List.js +33 -33
  77. package/dist/components/Menu.js +2 -2
  78. package/dist/components/Modal.js +2 -2
  79. package/dist/components/MultipleSelect.js +23 -23
  80. package/dist/components/NumberField.js +6 -6
  81. package/dist/components/ProgressCircle.js +3 -3
  82. package/dist/components/SearchField.js +8 -8
  83. package/dist/components/Select.js +8 -8
  84. package/dist/components/Surface.js +3 -3
  85. package/dist/components/Switch.js +2 -2
  86. package/dist/components/Table.js +7 -7
  87. package/dist/components/Tabs.js +2 -2
  88. package/dist/components/TagGroup.js +2 -2
  89. package/dist/components/TextField.js +2 -2
  90. package/dist/components/TimeField.js +3 -3
  91. package/dist/components/Toolbar.js +2 -2
  92. package/dist/components/Tooltip.js +4 -4
  93. package/dist/components/Tree.d.ts +2 -1
  94. package/dist/components/Tree.js +6 -6
  95. package/dist/core/Client.d.ts +1 -4
  96. package/dist/core/Client.js +5 -7
  97. package/dist/core/Connection.d.ts +4 -1
  98. package/dist/core/Connection.js +3 -1
  99. package/dist/core/Document.js +15 -3
  100. package/dist/core/Entry.d.ts +3 -0
  101. package/dist/core/Entry.js +4 -0
  102. package/dist/core/EntrySeed.d.ts +19 -0
  103. package/dist/core/EntrySeed.js +136 -0
  104. package/dist/core/Field.d.ts +7 -0
  105. package/dist/core/Field.js +4 -0
  106. package/dist/core/Filter.d.ts +40 -2
  107. package/dist/core/Filter.js +145 -0
  108. package/dist/core/Graph.d.ts +9 -0
  109. package/dist/core/ListRow.d.ts +1 -0
  110. package/dist/core/ListRow.js +1 -0
  111. package/dist/core/Reference.d.ts +1 -0
  112. package/dist/core/Root.js +1 -1
  113. package/dist/core/Scope.d.ts +2 -0
  114. package/dist/core/Scope.js +16 -1
  115. package/dist/core/Type.d.ts +2 -1
  116. package/dist/core/Type.js +13 -1
  117. package/dist/core/db/EntryAliases.js +1 -11
  118. package/dist/core/db/EntryReference.d.ts +0 -6
  119. package/dist/core/db/IndexEvent.d.ts +2 -1
  120. package/dist/core/db/IndexEvent.js +11 -3
  121. package/dist/core/db/LinkResolver.d.ts +6 -6
  122. package/dist/core/db/LinkResolver.js +0 -52
  123. package/dist/core/db/LocalStore.d.ts +27 -0
  124. package/dist/core/field/ListField.js +19 -0
  125. package/dist/core/field/RecordField.js +8 -0
  126. package/dist/core/field/RichTextField.js +42 -0
  127. package/dist/core/field/UnionField.js +8 -0
  128. package/dist/core/source/FSSource.d.ts +14 -2
  129. package/dist/core/source/FSSource.js +58 -13
  130. package/dist/core/source/GitUtils.d.ts +4 -0
  131. package/dist/core/source/GitUtils.js +9 -10
  132. package/dist/core/source/GithubSource.js +60 -21
  133. package/dist/core/source/IndexedDBSource.d.ts +2 -1
  134. package/dist/core/source/IndexedDBSource.js +67 -53
  135. package/dist/core/source/MemorySource.js +5 -3
  136. package/dist/core/source/OverlaySource.d.ts +5 -2
  137. package/dist/core/source/OverlaySource.js +31 -3
  138. package/dist/core/source/Source.d.ts +3 -0
  139. package/dist/core/source/Source.js +15 -2
  140. package/dist/core/source/Tree.d.ts +10 -7
  141. package/dist/core/source/Tree.js +118 -70
  142. package/dist/core/source/Utils.js +6 -3
  143. package/dist/core/util/Arrays.d.ts +1 -0
  144. package/dist/core/util/Arrays.js +10 -0
  145. package/dist/core/util/Async.d.ts +7 -0
  146. package/dist/core/util/Async.js +15 -0
  147. package/dist/core/util/Checks.js +1 -1
  148. package/dist/core/util/EntryFilenames.d.ts +22 -1
  149. package/dist/core/util/EntryFilenames.js +56 -2
  150. package/dist/core/util/IndexedDB.d.ts +4 -0
  151. package/dist/core/util/IndexedDB.js +20 -0
  152. package/dist/core/util/Paths.js +5 -1
  153. package/dist/dashboard/App.js +3 -3
  154. package/dist/dashboard/ViewKeys.d.ts +1 -0
  155. package/dist/dashboard/ViewKeys.js +1 -0
  156. package/dist/dashboard/app/AccessDenied.js +2 -2
  157. package/dist/dashboard/app/ActivityStatus.js +14 -14
  158. package/dist/dashboard/app/AppShell.js +2 -2
  159. package/dist/dashboard/app/AuthView.js +12 -12
  160. package/dist/dashboard/app/CompactField.js +11 -11
  161. package/dist/dashboard/app/DashboardErrorBoundary.js +6 -6
  162. package/dist/dashboard/app/DashboardLayout.js +3 -3
  163. package/dist/dashboard/app/EntryHeader.js +8 -8
  164. package/dist/dashboard/app/EntryReferences.js +8 -8
  165. package/dist/dashboard/app/EntrySidebar.js +15 -15
  166. package/dist/dashboard/app/EntrySidebarPreview.js +7 -7
  167. package/dist/dashboard/app/EntryTranslationBanner.js +5 -5
  168. package/dist/dashboard/app/Explorer.js +39 -39
  169. package/dist/dashboard/app/ExplorerCards.js +31 -31
  170. package/dist/dashboard/app/ExplorerFileCard.js +19 -19
  171. package/dist/dashboard/app/ExplorerList.js +10 -10
  172. package/dist/dashboard/app/ExplorerModal.js +5 -5
  173. package/dist/dashboard/app/ExplorerTable.js +47 -47
  174. package/dist/dashboard/app/LinkPicker.js +5 -5
  175. package/dist/dashboard/app/LocaleMenu.js +4 -4
  176. package/dist/dashboard/app/SidebarTree.js +76 -40
  177. package/dist/dashboard/app/WorkspaceMenu.js +9 -9
  178. package/dist/dashboard/app/WorkspaceRoots.js +22 -22
  179. package/dist/dashboard/app/editor/FileEditor.js +28 -28
  180. package/dist/dashboard/app/editor/FilePreview.js +6 -6
  181. package/dist/dashboard/app/modals/CreateEntry.js +3 -3
  182. package/dist/dashboard/app/pages/EntryPage.js +18 -18
  183. package/dist/dashboard/app/pages/RootPage.js +3 -3
  184. package/dist/dashboard/app/pages/SplashPage.js +45 -45
  185. package/dist/dashboard/app/pages/UsersPage.js +34 -34
  186. package/dist/dashboard/app/ui/DashboardModal.js +18 -18
  187. package/dist/dashboard/app/ui/Rail.js +5 -5
  188. package/dist/dashboard/app/ui/Sidebar.js +2 -2
  189. package/dist/dashboard/atoms/config.d.ts +4 -4
  190. package/dist/dashboard/atoms/entry.d.ts +8 -9
  191. package/dist/dashboard/atoms/entry.js +34 -4
  192. package/dist/dashboard/atoms/explorer.d.ts +2 -0
  193. package/dist/dashboard/atoms/explorer.js +7 -2
  194. package/dist/dashboard/boot/Boot.js +2 -3
  195. package/dist/dashboard/boot/DashboardWorker.d.ts +3 -3
  196. package/dist/dashboard/boot/DashboardWorker.js +82 -27
  197. package/dist/dashboard/boot/LoadWorker.js +2 -3
  198. package/dist/dashboard/boot/WorkerDB.d.ts +2 -2
  199. package/dist/dashboard/icons.d.ts +2 -0
  200. package/dist/dashboard/icons.js +40 -0
  201. package/dist/dashboard/plugins/alineaFixturePlugin.js +14 -3
  202. package/dist/database/BrowserEntryStore.d.ts +42 -0
  203. package/dist/database/BrowserEntryStore.js +182 -0
  204. package/dist/database/DatabaseSource.d.ts +13 -0
  205. package/dist/database/DatabaseSource.js +25 -0
  206. package/dist/database/DatabaseTables.d.ts +38 -0
  207. package/dist/database/DatabaseTables.js +53 -0
  208. package/dist/database/EntryDatabase.d.ts +97 -0
  209. package/dist/database/EntryDatabase.js +528 -0
  210. package/dist/database/EntryStore.d.ts +58 -0
  211. package/dist/database/EntryStore.js +230 -0
  212. package/dist/database/EntryTransaction.d.ts +33 -0
  213. package/dist/database/EntryTransaction.js +907 -0
  214. package/dist/database/EntryUrlAliases.d.ts +2 -0
  215. package/dist/database/EntryUrlAliases.js +69 -0
  216. package/dist/database/LocalDB.d.ts +39 -0
  217. package/dist/database/LocalDB.js +79 -0
  218. package/dist/database/Version.d.ts +9 -0
  219. package/dist/database/Version.js +13 -0
  220. package/dist/database/driver/DatabaseHandle.d.ts +17 -0
  221. package/dist/database/driver/DatabaseHandle.js +0 -0
  222. package/dist/database/driver/OverlayExtension.browser.d.ts +2 -0
  223. package/dist/database/driver/OverlayExtension.browser.js +9 -0
  224. package/dist/database/driver/OverlayExtension.d.ts +1 -0
  225. package/dist/database/driver/OverlayExtension.js +7 -0
  226. package/dist/database/driver/RuntimeDatabase.d.ts +13 -0
  227. package/dist/database/driver/RuntimeDatabase.js +77 -0
  228. package/dist/database/driver/WasmDatabase.d.ts +29 -0
  229. package/dist/database/driver/WasmDatabase.js +46 -0
  230. package/dist/database/entry/EntryData.d.ts +13 -0
  231. package/dist/database/entry/EntryData.js +51 -0
  232. package/dist/database/entry/EntryTable.d.ts +189 -0
  233. package/dist/database/entry/EntryTable.js +186 -0
  234. package/dist/database/query/Condition.d.ts +8 -0
  235. package/dist/database/query/Condition.js +117 -0
  236. package/dist/database/query/EntryQuery.d.ts +44 -0
  237. package/dist/database/query/EntryQuery.js +412 -0
  238. package/dist/database/query/EntryReferences.d.ts +5 -0
  239. package/dist/database/query/EntryReferences.js +70 -0
  240. package/dist/database/query/Relation.d.ts +11 -0
  241. package/dist/database/query/Relation.js +113 -0
  242. package/dist/database/query/ResolveQuery.d.ts +12 -0
  243. package/dist/database/query/ResolveQuery.js +189 -0
  244. package/dist/database/query/Search.d.ts +38 -0
  245. package/dist/database/query/Search.js +149 -0
  246. package/dist/database/sync/Derive.d.ts +8 -0
  247. package/dist/database/sync/Derive.js +270 -0
  248. package/dist/database/sync/EntryParser.d.ts +8 -0
  249. package/dist/database/sync/EntryParser.js +90 -0
  250. package/dist/database/sync/EntrySyncer.d.ts +25 -0
  251. package/dist/database/sync/EntrySyncer.js +89 -0
  252. package/dist/database/sync/Ingest.d.ts +21 -0
  253. package/dist/database/sync/Ingest.js +145 -0
  254. package/dist/database/sync/SyncQueries.d.ts +160 -0
  255. package/dist/database/sync/SyncQueries.js +216 -0
  256. package/dist/field/check/CheckField.view.js +2 -2
  257. package/dist/field/code/CodeField.view.js +10 -10
  258. package/dist/field/link/LinkField.js +23 -0
  259. package/dist/field/link/LinkField.view.js +42 -41
  260. package/dist/field/list/ListField.view.js +172 -150
  261. package/dist/field/metadata/MetadataField.d.ts +28 -3
  262. package/dist/field/metadata/MetadataField.js +44 -7
  263. package/dist/field/metadata/MetadataField.view.d.ts +5 -0
  264. package/dist/field/metadata/MetadataField.view.js +31 -16
  265. package/dist/field/richtext/RichTextDocument.js +4 -3
  266. package/dist/field/richtext/RichTextExtensions.d.ts +1 -1
  267. package/dist/field/richtext/RichTextExtensions.js +33 -29
  268. package/dist/field/richtext/RichTextField.view.js +17 -8
  269. package/dist/field/richtext/RichTextInsertMenu.js +2 -2
  270. package/dist/field/views.js +2 -0
  271. package/dist/next.cjs +6 -20
  272. package/dist/next.d.ts +4 -3
  273. package/dist/next.edge.d.ts +1 -1
  274. package/dist/next.js +1 -2
  275. package/dist/picker/entry/EntryPicker.js +2 -1
  276. package/dist/picker/url/UrlPicker.js +1 -0
  277. package/dist/preview/widget.d.ts +45 -0
  278. package/dist/preview/widget.js +96 -1
  279. package/dist/query.d.ts +28 -0
  280. package/package.json +6 -1
  281. package/dist/adapter/next/DevRemote.d.ts +0 -3
  282. package/dist/adapter/next/DevRemote.js +0 -45
  283. package/dist/backend/store/GeneratedSource.d.ts +0 -2
  284. package/dist/backend/store/GeneratedSource.js +0 -21
  285. package/dist/chunks/chunk-G6E35DMJ.js +0 -1997
  286. package/dist/core/db/EntryDB.d.ts +0 -19
  287. package/dist/core/db/EntryDB.js +0 -48
  288. package/dist/core/db/EntryIndex.d.ts +0 -143
  289. package/dist/core/db/EntryIndex.js +0 -2773
  290. package/dist/core/db/EntryReferenceIndex.d.ts +0 -21
  291. package/dist/core/db/EntryReferenceIndex.js +0 -131
  292. package/dist/core/db/EntryResolver.d.ts +0 -56
  293. package/dist/core/db/EntryResolver.js +0 -699
  294. package/dist/core/db/EntryTarget.d.ts +0 -5
  295. package/dist/core/db/EntryTransaction.d.ts +0 -31
  296. package/dist/core/db/EntryTransaction.js +0 -956
  297. package/dist/core/db/LocalDB.d.ts +0 -42
  298. package/dist/core/db/LocalDB.js +0 -127
  299. package/dist/core/db/TestDB.d.ts +0 -19
  300. package/dist/core/db/TestDB.js +0 -50
  301. /package/dist/core/db/{EntryTarget.js → LocalStore.js} +0 -0
@@ -0,0 +1,364 @@
1
+ import {
2
+ cached,
3
+ getData,
4
+ getField,
5
+ getSelection,
6
+ getSql,
7
+ getTable,
8
+ hasField,
9
+ hasSelection,
10
+ hasSql,
11
+ hasTable,
12
+ internalData,
13
+ internalField,
14
+ internalSql,
15
+ internalTarget,
16
+ sql
17
+ } from "./chunk-ETBQTP2S.js";
18
+
19
+ // node_modules/rado/dist/core/Index.js
20
+ var IndexData = class {
21
+ name;
22
+ fields;
23
+ concurrently;
24
+ unique;
25
+ only;
26
+ using;
27
+ order;
28
+ nulls;
29
+ where;
30
+ };
31
+ var IndexApi = class extends IndexData {
32
+ toSql(tableName, indexName, ifNotExists) {
33
+ const fields = this.fields.map(
34
+ (field) => sql.join([
35
+ field,
36
+ this.order && sql.unsafe(this.order),
37
+ this.nulls && sql`nulls ${sql.unsafe(this.nulls)}`
38
+ ])
39
+ );
40
+ return sql.join([
41
+ sql`create`,
42
+ this.unique && sql`unique`,
43
+ sql`index`,
44
+ this.concurrently && sql`concurrently`,
45
+ ifNotExists && sql`if not exists`,
46
+ sql.identifier(indexName),
47
+ sql`on`,
48
+ this.only && sql`only`,
49
+ sql.identifier(tableName),
50
+ this.using && sql`using ${this.using}`,
51
+ sql`(${sql.join(fields, sql`, `)})`,
52
+ this.where && sql`where ${this.where}`
53
+ ]).inlineFields(false);
54
+ }
55
+ };
56
+ var Index = class _Index {
57
+ [internalData];
58
+ constructor(data) {
59
+ this[internalData] = Object.assign(new IndexApi(), data);
60
+ }
61
+ on(...fields) {
62
+ return new _Index({ ...getData(this), fields });
63
+ }
64
+ concurrently() {
65
+ return new _Index({ ...getData(this), concurrently: true });
66
+ }
67
+ only() {
68
+ return new _Index({ ...getData(this), only: true });
69
+ }
70
+ using(using) {
71
+ return new _Index({ ...getData(this), using });
72
+ }
73
+ asc() {
74
+ return new _Index({ ...getData(this), order: "asc" });
75
+ }
76
+ desc() {
77
+ return new _Index({ ...getData(this), order: "desc" });
78
+ }
79
+ nullsFirst() {
80
+ return new _Index({ ...getData(this), nulls: "first" });
81
+ }
82
+ nullsLast() {
83
+ return new _Index({ ...getData(this), nulls: "last" });
84
+ }
85
+ where(where) {
86
+ return new _Index({ ...getData(this), where });
87
+ }
88
+ };
89
+ function index(name) {
90
+ return new Index({ name, fields: [] });
91
+ }
92
+
93
+ // node_modules/rado/dist/core/expr/Field.js
94
+ var Field = class {
95
+ [internalField];
96
+ [internalSql];
97
+ constructor(targetName, fieldName, source = {}) {
98
+ const field = { targetName, fieldName, source };
99
+ this[internalField] = field;
100
+ const expr = sql.field(field).as(fieldName).mapWith(source);
101
+ this[internalSql] = expr;
102
+ }
103
+ };
104
+
105
+ // node_modules/rado/dist/core/Virtual.js
106
+ function virtualFields(alias, source) {
107
+ return Object.fromEntries(
108
+ Object.entries(source).map(([key, value]) => {
109
+ if (value && typeof value === "object" && !hasSql(value))
110
+ return [key, virtualFields(alias, value)];
111
+ return [key, new Field(alias, key, getSql(value))];
112
+ })
113
+ );
114
+ }
115
+ function virtualTarget(alias, source) {
116
+ const target = {
117
+ [internalTarget]: sql.identifier(alias)
118
+ };
119
+ if (!source || typeof source !== "object")
120
+ throw new Error("Cannot alias a non-object");
121
+ if (hasSql(source)) {
122
+ const expr = getSql(source);
123
+ const name = expr.alias;
124
+ if (!name) throw new Error("Cannot alias a virtual field without a name");
125
+ return Object.assign(new Field(alias, name, expr), target);
126
+ }
127
+ return {
128
+ ...target,
129
+ ...virtualFields(alias, source)
130
+ };
131
+ }
132
+
133
+ // node_modules/rado/dist/core/Selection.js
134
+ var SqlColumn = class {
135
+ constructor(sql2, targetName) {
136
+ this.sql = sql2;
137
+ this.targetName = targetName;
138
+ }
139
+ sql;
140
+ targetName;
141
+ result(ctx) {
142
+ const value = ctx.values[ctx.index++];
143
+ if (!this.sql.mapFromDriverValue) return value;
144
+ return this.sql.mapFromDriverValue(value, ctx.specs);
145
+ }
146
+ };
147
+ var ObjectColumn = class {
148
+ constructor(nullable, entries) {
149
+ this.nullable = nullable;
150
+ this.entries = entries;
151
+ }
152
+ nullable;
153
+ entries;
154
+ result(ctx) {
155
+ const result = {};
156
+ let isNullable = this.nullable.size > 0;
157
+ for (const entry of this.entries) {
158
+ const name = entry[0];
159
+ const col = entry[1];
160
+ const value = col.result(ctx);
161
+ result[name] = value;
162
+ if (isNullable) {
163
+ if (value === null) {
164
+ if (col.targetName && !this.nullable.has(col.targetName))
165
+ isNullable = false;
166
+ } else {
167
+ isNullable = false;
168
+ }
169
+ }
170
+ }
171
+ if (isNullable) return null;
172
+ return result;
173
+ }
174
+ };
175
+ function firstTargetName(input) {
176
+ const expr = getSql(input);
177
+ if (expr) return hasField(input) ? getField(input).targetName : void 0;
178
+ if (!input || typeof input !== "object") return;
179
+ for (const value of Object.values(input)) {
180
+ const name = firstTargetName(value);
181
+ if (name) return name;
182
+ }
183
+ }
184
+ var Selection = class _Selection {
185
+ constructor(input, nullable = /* @__PURE__ */ new Set()) {
186
+ this.input = input;
187
+ this.nullable = nullable;
188
+ const root = this.#defineColumn(nullable, input);
189
+ this.mapRow = root.result.bind(root);
190
+ }
191
+ input;
192
+ nullable;
193
+ mapRow;
194
+ makeVirtual(name) {
195
+ return virtualTarget(name, this.input);
196
+ }
197
+ #defineColumn(nullable, input) {
198
+ const expr = getSql(input);
199
+ if (expr) return new SqlColumn(expr, getField(input)?.targetName);
200
+ return new ObjectColumn(
201
+ nullable,
202
+ Object.entries(input).map(([name, value]) => [
203
+ name,
204
+ this.#defineColumn(nullable, value)
205
+ ])
206
+ );
207
+ }
208
+ #columns;
209
+ #aliases;
210
+ // Flattened selected expressions with their deduplicated output names
211
+ #selected() {
212
+ if (this.#columns) return this.#columns;
213
+ const columns = [];
214
+ const names = /* @__PURE__ */ new Set();
215
+ const collect = (input, name) => {
216
+ const expr = getSql(input);
217
+ if (expr) {
218
+ let exprName = name ?? expr.alias;
219
+ if (exprName) {
220
+ while (names.has(exprName)) exprName = `${exprName}_`;
221
+ names.add(exprName);
222
+ }
223
+ columns.push({ input, expr, name: exprName });
224
+ return;
225
+ }
226
+ for (const [name2, value] of Object.entries(input)) collect(value, name2);
227
+ };
228
+ collect(this.input);
229
+ return this.#columns = columns;
230
+ }
231
+ fieldNames() {
232
+ return this.#selected().map((column) => {
233
+ if (!column.name) throw new Error("Missing field name");
234
+ return column.name;
235
+ });
236
+ }
237
+ aliasOf(input) {
238
+ if (!this.#aliases) {
239
+ this.#aliases = /* @__PURE__ */ new Map();
240
+ for (const { expr, name } of this.#selected())
241
+ if (name && !this.#aliases.has(expr)) this.#aliases.set(expr, name);
242
+ }
243
+ return this.#aliases.get(getSql(input));
244
+ }
245
+ get [internalSql]() {
246
+ return cached(this, internalSql, () => {
247
+ const parts = this.#selected().map(({ input, expr, name }) => {
248
+ if (!name) return expr;
249
+ if (hasField(input) && getField(input).fieldName === name) return expr;
250
+ return sql`${expr.forSelection()} as ${sql.identifier(name)}`;
251
+ });
252
+ return sql.join(parts, sql`, `);
253
+ });
254
+ }
255
+ #collectTargetNames(input, names) {
256
+ const expr = getSql(input);
257
+ if (expr) {
258
+ if (hasField(input)) names.add(getField(input).targetName);
259
+ return;
260
+ }
261
+ for (const value of Object.values(input))
262
+ this.#collectTargetNames(value, names);
263
+ }
264
+ #targetNames() {
265
+ const names = /* @__PURE__ */ new Set();
266
+ this.#collectTargetNames(this.input, names);
267
+ return names;
268
+ }
269
+ join(right, operator) {
270
+ if (hasSelection(right)) {
271
+ const selected2 = getSelection(right);
272
+ const alias = firstTargetName(selected2.input);
273
+ if (!alias) return this;
274
+ const nullable2 = new Set(this.nullable);
275
+ if (operator === "leftJoin" || operator === "fullJoin")
276
+ nullable2.add(alias);
277
+ if (operator === "rightJoin" || operator === "fullJoin")
278
+ for (const name of this.#targetNames()) nullable2.add(name);
279
+ return new _Selection(this.input, nullable2);
280
+ }
281
+ if (!hasTable(right)) return this;
282
+ const rightTable = getTable(right);
283
+ const nullable = new Set(this.nullable);
284
+ if (operator === "leftJoin" || operator === "fullJoin")
285
+ nullable.add(rightTable.aliased);
286
+ if (operator === "rightJoin" || operator === "fullJoin")
287
+ for (const name of this.#targetNames()) nullable.add(name);
288
+ return new _Selection(this.input, nullable);
289
+ }
290
+ };
291
+ var TableSelection = class extends Selection {
292
+ constructor(table) {
293
+ super(table, /* @__PURE__ */ new Set());
294
+ this.table = table;
295
+ }
296
+ table;
297
+ join(right, operator) {
298
+ const leftTable = getTable(this.table);
299
+ if (hasSelection(right)) {
300
+ const selected2 = getSelection(right);
301
+ const alias = firstTargetName(selected2.input);
302
+ if (!alias) return this;
303
+ const nullable2 = new Set(this.nullable);
304
+ if (operator === "rightJoin" || operator === "fullJoin")
305
+ nullable2.add(leftTable.aliased);
306
+ if (operator === "leftJoin" || operator === "fullJoin")
307
+ nullable2.add(alias);
308
+ return new Selection(
309
+ { [leftTable.aliased]: this.table, [alias]: selected2.input },
310
+ nullable2
311
+ );
312
+ }
313
+ if (!hasTable(right)) return this;
314
+ const rightTable = getTable(right);
315
+ const nullable = new Set(this.nullable);
316
+ if (operator === "rightJoin" || operator === "fullJoin")
317
+ nullable.add(leftTable.aliased);
318
+ if (operator === "leftJoin" || operator === "fullJoin")
319
+ nullable.add(rightTable.aliased);
320
+ return new JoinSelection([this.table, right], nullable);
321
+ }
322
+ };
323
+ var JoinSelection = class _JoinSelection extends Selection {
324
+ constructor(tables, nullable) {
325
+ super(
326
+ Object.fromEntries(tables.map((table) => [getTable(table).aliased, table])),
327
+ nullable
328
+ );
329
+ this.tables = tables;
330
+ }
331
+ tables;
332
+ join(right, operator) {
333
+ if (!hasTable(right)) return this;
334
+ const rightTable = getTable(right);
335
+ const nullable = new Set(this.nullable);
336
+ if (operator === "rightJoin" || operator === "fullJoin")
337
+ for (const table of this.tables) nullable.add(getTable(table).aliased);
338
+ if (operator === "leftJoin" || operator === "fullJoin")
339
+ nullable.add(rightTable.aliased);
340
+ return new _JoinSelection([...this.tables, right], nullable);
341
+ }
342
+ };
343
+ var StarSelection = class extends Selection {
344
+ get [internalSql]() {
345
+ return sql`*`;
346
+ }
347
+ };
348
+ var selected = /* @__PURE__ */ new WeakMap();
349
+ function selection(input) {
350
+ if (input instanceof Selection) return input;
351
+ if (selected.has(input)) return selected.get(input);
352
+ const selection2 = hasTable(input) ? new TableSelection(input) : new Selection(input);
353
+ selected.set(input, selection2);
354
+ return selection2;
355
+ }
356
+
357
+ export {
358
+ Field,
359
+ virtualTarget,
360
+ StarSelection,
361
+ selection,
362
+ Index,
363
+ index
364
+ };
@@ -0,0 +1,94 @@
1
+ import {
2
+ ReusedStatement,
3
+ StatementCache,
4
+ execTransaction,
5
+ sqliteDialect,
6
+ sqliteDiff
7
+ } from "./chunk-AIU6CMVT.js";
8
+ import {
9
+ Batch,
10
+ SyncDatabase
11
+ } from "./chunk-N47Y62CI.js";
12
+
13
+ // node_modules/rado/dist/driver/sql.js.js
14
+ var PreparedStatement = class extends ReusedStatement {
15
+ constructor(client, statements, sql) {
16
+ super(statements, sql);
17
+ this.client = client;
18
+ }
19
+ client;
20
+ *iterate(params) {
21
+ this.stmt.bind(params);
22
+ while (this.stmt.step()) yield this.stmt.getAsObject();
23
+ this.stmt.reset();
24
+ }
25
+ *iterateValues(params) {
26
+ this.stmt.bind(params);
27
+ while (this.stmt.step()) yield this.stmt.get();
28
+ this.stmt.reset();
29
+ }
30
+ all(params) {
31
+ return Array.from(this.iterate(params));
32
+ }
33
+ run(params) {
34
+ this.stmt.run(params);
35
+ this.stmt.reset();
36
+ return { affectedRows: this.client.getRowsModified() };
37
+ }
38
+ get(params) {
39
+ return this.all(params)[0] ?? null;
40
+ }
41
+ values(params) {
42
+ return Array.from(this.iterateValues(params));
43
+ }
44
+ };
45
+ var SqlJsDriver = class _SqlJsDriver {
46
+ constructor(client, depth = 0, statements = new StatementCache(
47
+ (sql) => client.prepare(sql),
48
+ (stmt) => stmt.free()
49
+ )) {
50
+ this.client = client;
51
+ this.depth = depth;
52
+ this.statements = statements;
53
+ }
54
+ client;
55
+ depth;
56
+ statements;
57
+ parsesJson = false;
58
+ supportsTransactions = true;
59
+ exec(query) {
60
+ this.statements.invalidate(query);
61
+ this.client.exec(query);
62
+ }
63
+ close() {
64
+ this.statements.clear();
65
+ this.client.close();
66
+ }
67
+ prepare(sql) {
68
+ return new PreparedStatement(this.client, this.statements, sql);
69
+ }
70
+ batch(queries) {
71
+ return this.transaction((tx) => Batch.run(tx, queries), {});
72
+ }
73
+ transaction(run, options) {
74
+ return execTransaction(
75
+ this,
76
+ this.depth,
77
+ (depth) => new _SqlJsDriver(this.client, depth, this.statements),
78
+ run,
79
+ options
80
+ );
81
+ }
82
+ };
83
+ function connect(db, options) {
84
+ return new SyncDatabase(
85
+ new SqlJsDriver(db),
86
+ sqliteDialect,
87
+ sqliteDiff,
88
+ options
89
+ );
90
+ }
91
+
92
+ export {
93
+ connect
94
+ };
@@ -0,0 +1,55 @@
1
+ import {
2
+ callFunction
3
+ } from "./chunk-K62JP6HR.js";
4
+ import {
5
+ getSql,
6
+ sql
7
+ } from "./chunk-ETBQTP2S.js";
8
+
9
+ // node_modules/rado/dist/core/expr/Json.js
10
+ var INDEX_PROPERTY = /^\d+$/;
11
+ function jsonExpr(e) {
12
+ return new Proxy(e, {
13
+ get(target, prop) {
14
+ if (typeof prop !== "string") return Reflect.get(target, prop);
15
+ const isNumber = INDEX_PROPERTY.test(prop);
16
+ return jsonExpr(
17
+ sql.jsonPath({
18
+ target: getSql(target),
19
+ segments: [isNumber ? Number(prop) : prop],
20
+ asSql: true
21
+ }).mapWith({
22
+ mapFromDriverValue(value, specs) {
23
+ return specs.parsesJson ? value : JSON.parse(value);
24
+ }
25
+ })
26
+ );
27
+ }
28
+ });
29
+ }
30
+ function jsonAggregateArray(...args) {
31
+ return callFunction(
32
+ sql.universal({
33
+ // Once sqlite 3.45+ is more commonplace we can use jsonb_group_array
34
+ sqlite: sql`json_group_array`,
35
+ postgres: sql`jsonb_agg`,
36
+ mysql: sql`json_arrayagg`
37
+ }),
38
+ args
39
+ );
40
+ }
41
+ function jsonArray(...args) {
42
+ return callFunction(
43
+ sql.universal({
44
+ postgres: sql`jsonb_build_array`,
45
+ default: sql`json_array`
46
+ }),
47
+ args
48
+ );
49
+ }
50
+
51
+ export {
52
+ jsonExpr,
53
+ jsonAggregateArray,
54
+ jsonArray
55
+ };