alinea 2.0.0-preview.7 → 2.0.0-preview.8

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 (283) hide show
  1. package/dist/.init/content/pages/welcome.json +1 -1
  2. package/dist/LICENSES.md +120 -120
  3. package/dist/adapter/next/cms.d.ts +18 -4
  4. package/dist/adapter/next/cms.js +125 -36
  5. package/dist/adapter/next/handler.d.ts +5 -1
  6. package/dist/adapter/next/handler.js +14 -7
  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 +24 -0
  12. package/dist/adapter/next/renderStats.js +74 -0
  13. package/dist/adapter/next/syncCheck.d.ts +8 -2
  14. package/dist/adapter/next/syncCheck.js +3 -3
  15. package/dist/adapter/next/with-alinea.js +0 -18
  16. package/dist/backend/Handler.d.ts +2 -2
  17. package/dist/backend/Handler.js +33 -12
  18. package/dist/backend/api/CreateBackend.js +15 -3
  19. package/dist/backend/api/DatabaseApi.js +22 -135
  20. package/dist/backend/api/database.js +15 -3
  21. package/dist/backend/resolver/ParsePreview.d.ts +2 -2
  22. package/dist/backend/router/NodeHandler.js +2 -0
  23. package/dist/backend/store/GeneratedDatabase.d.ts +5 -0
  24. package/dist/backend/store/GeneratedDatabase.js +31 -0
  25. package/dist/backend/store/GeneratedDatabaseNode.d.ts +4 -0
  26. package/dist/backend/store/GeneratedDatabaseNode.js +35 -0
  27. package/dist/backend/util/ORM.js +4 -2
  28. package/dist/bundled.d.ts +1470 -442
  29. package/dist/chunks/bun-sqlite-ZZDB7YQQ.js +18 -0
  30. package/dist/chunks/chunk-2BJ2IFQM.js +1085 -0
  31. package/dist/chunks/chunk-2PIFHEYR.js +364 -0
  32. package/dist/chunks/{chunk-X47OVDF3.js → chunk-2U43BB6P.js} +356 -1000
  33. package/dist/chunks/chunk-76VMZTLN.js +55 -0
  34. package/dist/chunks/chunk-A42DP5T7.js +94 -0
  35. package/dist/chunks/chunk-ATF42T2B.js +35 -0
  36. package/dist/chunks/{chunk-NWQXN4SB.js → chunk-ETBQTP2S.js} +40 -29
  37. package/dist/chunks/chunk-IL7FJQAY.js +94 -0
  38. package/dist/chunks/chunk-K62JP6HR.js +22 -0
  39. package/dist/chunks/chunk-K7LHQXI4.js +103 -0
  40. package/dist/chunks/chunk-M7KDJEGH.js +495 -0
  41. package/dist/chunks/chunk-N47Y62CI.js +396 -0
  42. package/dist/chunks/chunk-NLZLRQ5U.js +100 -0
  43. package/dist/chunks/chunk-QBPYWU6C.js +24 -0
  44. package/dist/chunks/{chunk-6P4UVRPH.js → chunk-RWWYUNVX.js} +2 -1
  45. package/dist/chunks/chunk-TFMUSWGG.js +605 -0
  46. package/dist/chunks/{chunk-I4GC3E65.js → chunk-UPY2RUZF.js} +0 -1
  47. package/dist/chunks/chunk-XCZXR3C2.js +112 -0
  48. package/dist/chunks/chunk-XTWYBWP2.js +81 -0
  49. package/dist/chunks/node-sqlite-7CSGL27V.js +18 -0
  50. package/dist/cli/Generate.js +74 -64
  51. package/dist/cli/Serve.js +1 -1
  52. package/dist/cli/bin.js +2 -1
  53. package/dist/cli/generate/CopyStaticFiles.js +17 -14
  54. package/dist/cli/generate/DevDB.d.ts +22 -5
  55. package/dist/cli/generate/DevDB.js +136 -24
  56. package/dist/cli/serve/CreateLocalServer.js +22 -4
  57. package/dist/cli/serve/LiveReload.d.ts +1 -1
  58. package/dist/cli/serve/LiveReload.js +3 -0
  59. package/dist/cloud/CloudRemote.js +2 -1
  60. package/dist/components/Calendar.js +6 -6
  61. package/dist/components/Checkbox.js +3 -3
  62. package/dist/components/ColorSwatchPicker.js +2 -2
  63. package/dist/components/ComboBox.js +9 -9
  64. package/dist/components/DateField.js +1 -1
  65. package/dist/components/DatePicker.js +6 -6
  66. package/dist/components/DateRangePicker.js +6 -6
  67. package/dist/components/Disclosure.js +9 -9
  68. package/dist/components/Label.js +5 -5
  69. package/dist/components/List.js +33 -33
  70. package/dist/components/Menu.js +3 -3
  71. package/dist/components/Modal.js +3 -3
  72. package/dist/components/MultipleSelect.js +25 -25
  73. package/dist/components/NumberField.js +6 -6
  74. package/dist/components/ProgressCircle.js +3 -3
  75. package/dist/components/RadioGroup.js +2 -2
  76. package/dist/components/SearchField.js +5 -5
  77. package/dist/components/Select.js +7 -7
  78. package/dist/components/Surface.js +2 -2
  79. package/dist/components/Table.js +6 -6
  80. package/dist/components/Tabs.js +2 -2
  81. package/dist/components/TextField.js +6 -6
  82. package/dist/components/Toggle.js +2 -2
  83. package/dist/components/Toolbar.js +2 -2
  84. package/dist/components/Tooltip.js +4 -4
  85. package/dist/components/Tree.d.ts +2 -1
  86. package/dist/components/Tree.js +5 -5
  87. package/dist/core/Document.js +15 -3
  88. package/dist/core/Entry.d.ts +3 -0
  89. package/dist/core/Entry.js +4 -0
  90. package/dist/core/EntrySeed.d.ts +19 -0
  91. package/dist/core/EntrySeed.js +136 -0
  92. package/dist/core/Field.d.ts +7 -0
  93. package/dist/core/Field.js +4 -0
  94. package/dist/core/Filter.d.ts +40 -2
  95. package/dist/core/Filter.js +145 -0
  96. package/dist/core/Graph.d.ts +9 -0
  97. package/dist/core/ListRow.d.ts +1 -0
  98. package/dist/core/ListRow.js +1 -0
  99. package/dist/core/Reference.d.ts +1 -0
  100. package/dist/core/Root.js +1 -1
  101. package/dist/core/Scope.d.ts +2 -0
  102. package/dist/core/Scope.js +16 -1
  103. package/dist/core/Type.d.ts +2 -1
  104. package/dist/core/Type.js +13 -1
  105. package/dist/core/db/EntryAliases.js +1 -11
  106. package/dist/core/db/EntryReference.d.ts +0 -6
  107. package/dist/core/db/IndexEvent.d.ts +2 -1
  108. package/dist/core/db/IndexEvent.js +11 -3
  109. package/dist/core/db/LinkResolver.d.ts +6 -6
  110. package/dist/core/db/LinkResolver.js +0 -52
  111. package/dist/core/db/LocalStore.d.ts +25 -0
  112. package/dist/core/field/ListField.js +19 -0
  113. package/dist/core/field/RecordField.js +8 -0
  114. package/dist/core/field/RichTextField.js +42 -0
  115. package/dist/core/field/UnionField.js +8 -0
  116. package/dist/core/source/FSSource.d.ts +14 -2
  117. package/dist/core/source/FSSource.js +58 -13
  118. package/dist/core/source/GitUtils.d.ts +4 -0
  119. package/dist/core/source/GitUtils.js +9 -10
  120. package/dist/core/source/GithubSource.js +22 -11
  121. package/dist/core/source/IndexedDBSource.d.ts +2 -1
  122. package/dist/core/source/IndexedDBSource.js +67 -53
  123. package/dist/core/source/MemorySource.js +5 -3
  124. package/dist/core/source/OverlaySource.d.ts +5 -2
  125. package/dist/core/source/OverlaySource.js +31 -3
  126. package/dist/core/source/Source.d.ts +3 -0
  127. package/dist/core/source/Source.js +15 -2
  128. package/dist/core/source/Tree.d.ts +10 -7
  129. package/dist/core/source/Tree.js +118 -70
  130. package/dist/core/source/Utils.js +6 -3
  131. package/dist/core/util/Arrays.d.ts +1 -0
  132. package/dist/core/util/Arrays.js +10 -0
  133. package/dist/core/util/Async.d.ts +7 -0
  134. package/dist/core/util/Async.js +15 -0
  135. package/dist/core/util/Checks.js +1 -1
  136. package/dist/core/util/EntryFilenames.d.ts +22 -1
  137. package/dist/core/util/EntryFilenames.js +56 -2
  138. package/dist/core/util/IndexedDB.d.ts +4 -0
  139. package/dist/core/util/IndexedDB.js +20 -0
  140. package/dist/core/util/Paths.js +5 -1
  141. package/dist/dashboard/App.js +3 -3
  142. package/dist/dashboard/ViewKeys.d.ts +1 -0
  143. package/dist/dashboard/ViewKeys.js +1 -0
  144. package/dist/dashboard/app/AccessDenied.js +4 -4
  145. package/dist/dashboard/app/ActivityStatus.js +11 -11
  146. package/dist/dashboard/app/AppShell.js +2 -2
  147. package/dist/dashboard/app/AuthView.js +9 -9
  148. package/dist/dashboard/app/Badge.js +2 -2
  149. package/dist/dashboard/app/CompactField.js +10 -10
  150. package/dist/dashboard/app/DashboardErrorBoundary.js +6 -6
  151. package/dist/dashboard/app/EntryFields.js +2 -2
  152. package/dist/dashboard/app/EntryHeader.js +10 -10
  153. package/dist/dashboard/app/EntryReferences.js +8 -8
  154. package/dist/dashboard/app/EntrySidebar.js +8 -8
  155. package/dist/dashboard/app/EntrySidebarPreview.js +11 -11
  156. package/dist/dashboard/app/EntryTranslationBanner.js +6 -6
  157. package/dist/dashboard/app/Explorer.js +44 -44
  158. package/dist/dashboard/app/ExplorerCards.js +30 -30
  159. package/dist/dashboard/app/ExplorerFileCard.js +17 -17
  160. package/dist/dashboard/app/ExplorerList.js +14 -14
  161. package/dist/dashboard/app/ExplorerModal.js +5 -5
  162. package/dist/dashboard/app/ExplorerTable.js +47 -47
  163. package/dist/dashboard/app/LinkPicker.js +2 -2
  164. package/dist/dashboard/app/LocaleMenu.js +6 -6
  165. package/dist/dashboard/app/SidebarTree.js +76 -40
  166. package/dist/dashboard/app/WorkspaceMenu.js +10 -10
  167. package/dist/dashboard/app/WorkspaceRoots.js +27 -27
  168. package/dist/dashboard/app/editor/FileEditor.js +24 -24
  169. package/dist/dashboard/app/editor/FilePreview.js +6 -6
  170. package/dist/dashboard/app/modals/CreateEntry.js +4 -4
  171. package/dist/dashboard/app/pages/EntryPage.js +15 -15
  172. package/dist/dashboard/app/pages/RootPage.js +3 -3
  173. package/dist/dashboard/app/pages/SplashPage.js +47 -47
  174. package/dist/dashboard/app/pages/UsersPage.js +36 -36
  175. package/dist/dashboard/app/ui/DashboardModal.js +17 -17
  176. package/dist/dashboard/app/ui/Rail.js +4 -4
  177. package/dist/dashboard/atoms/config.d.ts +4 -4
  178. package/dist/dashboard/atoms/entry.d.ts +8 -9
  179. package/dist/dashboard/atoms/entry.js +34 -4
  180. package/dist/dashboard/atoms/explorer.d.ts +2 -0
  181. package/dist/dashboard/atoms/explorer.js +7 -2
  182. package/dist/dashboard/boot/Boot.js +2 -3
  183. package/dist/dashboard/boot/DashboardWorker.d.ts +3 -3
  184. package/dist/dashboard/boot/DashboardWorker.js +78 -27
  185. package/dist/dashboard/boot/LoadWorker.js +2 -3
  186. package/dist/dashboard/icons.d.ts +2 -0
  187. package/dist/dashboard/icons.js +40 -0
  188. package/dist/dashboard/plugins/alineaFixturePlugin.js +14 -3
  189. package/dist/database/BrowserEntryStore.d.ts +30 -0
  190. package/dist/database/BrowserEntryStore.js +168 -0
  191. package/dist/database/DatabaseSource.d.ts +13 -0
  192. package/dist/database/DatabaseSource.js +25 -0
  193. package/dist/database/DatabaseTables.d.ts +38 -0
  194. package/dist/database/DatabaseTables.js +53 -0
  195. package/dist/database/EntryDatabase.d.ts +21 -0
  196. package/dist/database/EntryDatabase.js +138 -0
  197. package/dist/database/EntryLayer.d.ts +93 -0
  198. package/dist/database/EntryLayer.js +459 -0
  199. package/dist/database/EntryStore.d.ts +60 -0
  200. package/dist/database/EntryStore.js +269 -0
  201. package/dist/database/EntryTransaction.d.ts +33 -0
  202. package/dist/database/EntryTransaction.js +889 -0
  203. package/dist/database/EntryUrlAliases.d.ts +2 -0
  204. package/dist/database/EntryUrlAliases.js +69 -0
  205. package/dist/database/LocalDB.d.ts +39 -0
  206. package/dist/database/LocalDB.js +79 -0
  207. package/dist/database/Version.d.ts +9 -0
  208. package/dist/database/Version.js +13 -0
  209. package/dist/database/driver/RuntimeDatabase.d.ts +8 -0
  210. package/dist/database/driver/RuntimeDatabase.js +33 -0
  211. package/dist/database/driver/WasmDatabase.d.ts +8 -0
  212. package/dist/database/driver/WasmDatabase.js +33 -0
  213. package/dist/database/entry/EntryData.d.ts +13 -0
  214. package/dist/database/entry/EntryData.js +51 -0
  215. package/dist/database/entry/EntryTable.d.ts +173 -0
  216. package/dist/database/entry/EntryTable.js +137 -0
  217. package/dist/database/entry/EntryView.d.ts +22 -0
  218. package/dist/database/entry/EntryView.js +106 -0
  219. package/dist/database/query/Condition.d.ts +8 -0
  220. package/dist/database/query/Condition.js +117 -0
  221. package/dist/database/query/EntryQuery.d.ts +43 -0
  222. package/dist/database/query/EntryQuery.js +414 -0
  223. package/dist/database/query/EntryReferences.d.ts +6 -0
  224. package/dist/database/query/EntryReferences.js +68 -0
  225. package/dist/database/query/Relation.d.ts +11 -0
  226. package/dist/database/query/Relation.js +113 -0
  227. package/dist/database/query/ResolveQuery.d.ts +15 -0
  228. package/dist/database/query/ResolveQuery.js +154 -0
  229. package/dist/database/query/Search.d.ts +47 -0
  230. package/dist/database/query/Search.js +169 -0
  231. package/dist/database/sync/Derive.d.ts +8 -0
  232. package/dist/database/sync/Derive.js +270 -0
  233. package/dist/database/sync/EntryParser.d.ts +4 -0
  234. package/dist/database/sync/EntryParser.js +87 -0
  235. package/dist/database/sync/EntrySyncer.d.ts +37 -0
  236. package/dist/database/sync/EntrySyncer.js +117 -0
  237. package/dist/database/sync/Ingest.d.ts +21 -0
  238. package/dist/database/sync/Ingest.js +136 -0
  239. package/dist/database/sync/SyncQueries.d.ts +157 -0
  240. package/dist/database/sync/SyncQueries.js +192 -0
  241. package/dist/field/code/CodeField.view.js +12 -12
  242. package/dist/field/link/LinkField.js +23 -0
  243. package/dist/field/link/LinkField.view.js +41 -40
  244. package/dist/field/list/ListField.view.js +177 -155
  245. package/dist/field/metadata/MetadataField.d.ts +28 -3
  246. package/dist/field/metadata/MetadataField.js +44 -7
  247. package/dist/field/metadata/MetadataField.view.d.ts +5 -0
  248. package/dist/field/metadata/MetadataField.view.js +34 -19
  249. package/dist/field/richtext/RichTextBlock.js +2 -2
  250. package/dist/field/richtext/RichTextDocument.js +4 -3
  251. package/dist/field/richtext/RichTextExtensions.d.ts +1 -1
  252. package/dist/field/richtext/RichTextExtensions.js +32 -28
  253. package/dist/field/richtext/RichTextField.view.js +15 -6
  254. package/dist/field/views.js +2 -0
  255. package/dist/next.cjs +0 -18
  256. package/dist/next.d.ts +4 -3
  257. package/dist/next.edge.d.ts +1 -1
  258. package/dist/next.js +1 -2
  259. package/dist/picker/entry/EntryPicker.js +2 -1
  260. package/dist/picker/url/UrlPicker.js +1 -0
  261. package/dist/preview/widget.d.ts +16 -0
  262. package/dist/preview/widget.js +70 -1
  263. package/dist/query.d.ts +28 -0
  264. package/package.json +2 -1
  265. package/dist/backend/store/GeneratedSource.d.ts +0 -2
  266. package/dist/backend/store/GeneratedSource.js +0 -21
  267. package/dist/chunks/chunk-G6E35DMJ.js +0 -1997
  268. package/dist/core/db/EntryDB.d.ts +0 -19
  269. package/dist/core/db/EntryDB.js +0 -48
  270. package/dist/core/db/EntryIndex.d.ts +0 -143
  271. package/dist/core/db/EntryIndex.js +0 -2773
  272. package/dist/core/db/EntryReferenceIndex.d.ts +0 -21
  273. package/dist/core/db/EntryReferenceIndex.js +0 -131
  274. package/dist/core/db/EntryResolver.d.ts +0 -56
  275. package/dist/core/db/EntryResolver.js +0 -699
  276. package/dist/core/db/EntryTarget.d.ts +0 -5
  277. package/dist/core/db/EntryTransaction.d.ts +0 -31
  278. package/dist/core/db/EntryTransaction.js +0 -956
  279. package/dist/core/db/LocalDB.d.ts +0 -42
  280. package/dist/core/db/LocalDB.js +0 -127
  281. package/dist/core/db/TestDB.d.ts +0 -19
  282. package/dist/core/db/TestDB.js +0 -50
  283. /package/dist/core/db/{EntryTarget.js → LocalStore.js} +0 -0
@@ -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
+ };
@@ -0,0 +1,94 @@
1
+ import {
2
+ ReusedStatement,
3
+ StatementCache,
4
+ execTransaction,
5
+ sqliteDialect,
6
+ sqliteDiff
7
+ } from "./chunk-M7KDJEGH.js";
8
+ import {
9
+ Batch,
10
+ SyncDatabase
11
+ } from "./chunk-N47Y62CI.js";
12
+
13
+ // node_modules/rado/dist/driver/bun-sqlite.js
14
+ var PreparedStatement = class extends ReusedStatement {
15
+ constructor(statements, sql, isSelection) {
16
+ super(statements, sql);
17
+ this.isSelection = isSelection;
18
+ }
19
+ isSelection;
20
+ all(params) {
21
+ return this.stmt.all(...params);
22
+ }
23
+ run(params) {
24
+ const result = this.stmt.run(...params);
25
+ return {
26
+ affectedRows: result.changes,
27
+ insertId: result.lastInsertRowid
28
+ };
29
+ }
30
+ get(params) {
31
+ return this.stmt.get(...params);
32
+ }
33
+ values(params) {
34
+ if (!this.isSelection) {
35
+ this.stmt.run(...params);
36
+ return [];
37
+ }
38
+ return this.stmt.values(...params);
39
+ }
40
+ };
41
+ var BunSqliteDriver = class _BunSqliteDriver {
42
+ constructor(client, depth = 0, statements = new StatementCache(
43
+ (sql) => client.prepare(sql),
44
+ (stmt) => stmt.finalize()
45
+ )) {
46
+ this.client = client;
47
+ this.depth = depth;
48
+ this.statements = statements;
49
+ }
50
+ client;
51
+ depth;
52
+ statements;
53
+ parsesJson = false;
54
+ supportsTransactions = true;
55
+ exec(query) {
56
+ this.statements.invalidate(query);
57
+ this.client.exec(query);
58
+ }
59
+ close() {
60
+ this.statements.clear();
61
+ this.client.close();
62
+ }
63
+ prepare(sql, options) {
64
+ return new PreparedStatement(
65
+ this.statements,
66
+ sql,
67
+ options?.isSelection ?? false
68
+ );
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 _BunSqliteDriver(this.client, depth, this.statements),
78
+ run,
79
+ options
80
+ );
81
+ }
82
+ };
83
+ function connect(db, options) {
84
+ return new SyncDatabase(
85
+ new BunSqliteDriver(db),
86
+ sqliteDialect,
87
+ sqliteDiff,
88
+ options
89
+ );
90
+ }
91
+
92
+ export {
93
+ connect
94
+ };
@@ -0,0 +1,35 @@
1
+ import {
2
+ getField,
3
+ getSql,
4
+ getTable,
5
+ hasField,
6
+ hasSql,
7
+ hasTable,
8
+ sql
9
+ } from "./chunk-ETBQTP2S.js";
10
+
11
+ // node_modules/rado/dist/core/expr/Input.js
12
+ function input(value, maybeField) {
13
+ const isObject = value && typeof value === "object";
14
+ if (isObject && hasTable(value))
15
+ return sql.identifier(getTable(value).aliased);
16
+ if (isObject && hasSql(value)) return getSql(value);
17
+ const fieldSource = maybeField && typeof maybeField === "object" && hasField(maybeField) && getField(maybeField).source;
18
+ return fieldSource && "mapToDriverValue" in fieldSource ? mapToColumn(fieldSource, value) : sql.value(value);
19
+ }
20
+ function mapToColumn({ mapToDriverValue, type }, expr) {
21
+ const isObject = expr && typeof expr === "object";
22
+ if (isObject && hasSql(expr)) return getSql(expr);
23
+ if (Array.isArray(expr) && type.kind === "array") {
24
+ if (!mapToDriverValue) return input(expr);
25
+ return input(mapToDriverValue(expr));
26
+ }
27
+ return input(
28
+ expr !== null && mapToDriverValue ? mapToDriverValue(expr) : expr
29
+ );
30
+ }
31
+
32
+ export {
33
+ input,
34
+ mapToColumn
35
+ };
@@ -11,6 +11,15 @@ var internalConstraint = /* @__PURE__ */ Symbol();
11
11
  var internalEnum = /* @__PURE__ */ Symbol();
12
12
  var internalCreate = /* @__PURE__ */ Symbol();
13
13
  var internalDrop = /* @__PURE__ */ Symbol();
14
+ var caches = /* @__PURE__ */ new Map();
15
+ function cached(instance, key, create) {
16
+ let cache = caches.get(key);
17
+ if (!cache) caches.set(key, cache = /* @__PURE__ */ new WeakMap());
18
+ if (cache.has(instance)) return cache.get(instance);
19
+ const value = create();
20
+ cache.set(instance, value);
21
+ return value;
22
+ }
14
23
  var hasData = (obj) => internalData in obj;
15
24
  var getData = (obj) => obj[internalData];
16
25
  var hasSql = (obj) => internalSql in obj;
@@ -37,7 +46,7 @@ var getDrop = (obj) => obj[internalDrop];
37
46
  var noop = () => {
38
47
  };
39
48
  var Sql = class _Sql {
40
- constructor(emit) {
49
+ constructor(emit = noop) {
41
50
  this.emit = emit;
42
51
  }
43
52
  emit;
@@ -51,9 +60,18 @@ var Sql = class _Sql {
51
60
  }
52
61
  mapWith(decoder) {
53
62
  const res = this;
54
- res.mapFromDriverValue = typeof decoder === "function" ? (input2) => input2 === null ? null : decoder(input2) : decoder.mapFromDriverValue;
63
+ res.mapFromDriverValue = typeof decoder === "function" ? (input) => input === null ? null : decoder(input) : decoder.mapFromDriverValue;
55
64
  return res;
56
65
  }
66
+ asScalar(selection) {
67
+ const scalar = sql`(${this})`;
68
+ if (!selection || typeof selection !== "object") return scalar;
69
+ if (hasSql(selection)) return scalar.mapWith(getSql(selection));
70
+ const values = Object.values(selection);
71
+ if (values.length !== 1) return scalar;
72
+ const first = values[0];
73
+ return first && typeof first === "object" && hasSql(first) ? scalar.mapWith(getSql(first)) : scalar;
74
+ }
57
75
  inlineFields(withTableName) {
58
76
  return new _Sql((emitter) => emitter.inlineFields(this, withTableName));
59
77
  }
@@ -69,6 +87,9 @@ var Sql = class _Sql {
69
87
  if(condition) {
70
88
  return condition ? this : void 0;
71
89
  }
90
+ get isEmpty() {
91
+ return this.emit === noop;
92
+ }
72
93
  };
73
94
  var JsonPathSql = class extends Sql {
74
95
  constructor(path) {
@@ -97,7 +118,7 @@ function sql(strings, ...inner) {
97
118
  }
98
119
  ((sql2) => {
99
120
  function empty() {
100
- return new Sql(noop);
121
+ return new Sql();
101
122
  }
102
123
  sql2.empty = empty;
103
124
  function unsafe(directSql) {
@@ -120,6 +141,12 @@ function sql(strings, ...inner) {
120
141
  return new Sql((emitter) => emitter.emitIdentifierOrSelf(identifier2));
121
142
  }
122
143
  sql2.identifier = identifier;
144
+ function functionName(name) {
145
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name))
146
+ throw new Error(`Invalid SQL function name: ${name}`);
147
+ return new Sql((emitter) => emitter.emitUnsafe(name));
148
+ }
149
+ sql2.functionName = functionName;
123
150
  function field(field2) {
124
151
  return new Sql((emitter) => emitter.emitField(field2));
125
152
  }
@@ -155,38 +182,23 @@ function sql(strings, ...inner) {
155
182
  }
156
183
  sql2.query = query;
157
184
  function join(items, separator = sql2` `) {
158
- const parts = items.filter(Boolean);
185
+ const parts = [];
186
+ for (const item of items) {
187
+ if (!item) continue;
188
+ const inner = getSql(item);
189
+ if (!inner.isEmpty) parts.push(inner);
190
+ }
191
+ if (parts.length === 0) return empty();
159
192
  return new Sql((emitter) => {
160
193
  for (let i = 0; i < parts.length; i++) {
161
194
  if (i > 0) separator.emit(emitter);
162
- getSql(parts[i]).emit(emitter);
195
+ parts[i].emit(emitter);
163
196
  }
164
197
  });
165
198
  }
166
199
  sql2.join = join;
167
200
  })(sql || (sql = {}));
168
201
 
169
- // node_modules/rado/dist/core/expr/Input.js
170
- function input(value, maybeField) {
171
- const isObject = value && typeof value === "object";
172
- if (isObject && hasTable(value))
173
- return sql.identifier(getTable(value).aliased);
174
- if (isObject && hasSql(value)) return getSql(value);
175
- const fieldSource = maybeField && typeof maybeField === "object" && hasField(maybeField) && getField(maybeField).source;
176
- return fieldSource && "mapToDriverValue" in fieldSource ? mapToColumn(fieldSource, value) : sql.value(value);
177
- }
178
- function mapToColumn({ mapToDriverValue, type }, expr) {
179
- const isObject = expr && typeof expr === "object";
180
- if (isObject && hasSql(expr)) return getSql(expr);
181
- if (Array.isArray(expr) && type.kind === "array") {
182
- if (!mapToDriverValue) return input(expr);
183
- return input(mapToDriverValue(expr));
184
- }
185
- return input(
186
- expr !== null && mapToDriverValue ? mapToDriverValue(expr) : expr
187
- );
188
- }
189
-
190
202
  export {
191
203
  internalData,
192
204
  internalSql,
@@ -199,6 +211,7 @@ export {
199
211
  internalConstraint,
200
212
  internalCreate,
201
213
  internalDrop,
214
+ cached,
202
215
  hasData,
203
216
  getData,
204
217
  hasSql,
@@ -221,7 +234,5 @@ export {
221
234
  getCreate,
222
235
  getDrop,
223
236
  Sql,
224
- sql,
225
- input,
226
- mapToColumn
237
+ sql
227
238
  };
@@ -0,0 +1,94 @@
1
+ import {
2
+ ReusedStatement,
3
+ StatementCache,
4
+ execTransaction,
5
+ sqliteDialect,
6
+ sqliteDiff
7
+ } from "./chunk-M7KDJEGH.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,22 @@
1
+ import {
2
+ input
3
+ } from "./chunk-ATF42T2B.js";
4
+ import {
5
+ sql
6
+ } from "./chunk-ETBQTP2S.js";
7
+
8
+ // node_modules/rado/dist/core/expr/Functions.js
9
+ function callFunction(name, args) {
10
+ return sql`${name}(${sql.join(args.map(input), sql`, `)})`;
11
+ }
12
+ function get(target, method) {
13
+ return target[method] ??= (...args) => {
14
+ return callFunction(sql.functionName(method), args);
15
+ };
16
+ }
17
+ var Functions = new Proxy(/* @__PURE__ */ Object.create(null), { get });
18
+
19
+ export {
20
+ callFunction,
21
+ Functions
22
+ };
@@ -0,0 +1,103 @@
1
+ import {
2
+ Column,
3
+ ColumnType,
4
+ JsonColumn,
5
+ column
6
+ } from "./chunk-TFMUSWGG.js";
7
+ import {
8
+ sql
9
+ } from "./chunk-ETBQTP2S.js";
10
+
11
+ // node_modules/rado/dist/universal/columns.js
12
+ var idType = new ColumnType(
13
+ "id",
14
+ [],
15
+ sql.universal({
16
+ sqlite: sql`integer`,
17
+ postgres: sql`integer generated always as identity`,
18
+ mysql: sql`int not null auto_increment`
19
+ })
20
+ );
21
+ var blobType = new ColumnType(
22
+ "blob",
23
+ [],
24
+ sql.universal({
25
+ postgres: sql`bytea`,
26
+ default: sql`blob`
27
+ })
28
+ );
29
+ var numberType = new ColumnType(
30
+ "number",
31
+ [],
32
+ sql.universal({
33
+ mysql: sql`double`,
34
+ default: sql`numeric`
35
+ })
36
+ );
37
+ var jsonbType = new ColumnType(
38
+ "json",
39
+ [],
40
+ sql.universal({
41
+ mysql: sql`json`,
42
+ default: sql`jsonb`
43
+ })
44
+ );
45
+ function id(name) {
46
+ return new Column({
47
+ name,
48
+ type: idType,
49
+ primary: true,
50
+ notNull: true
51
+ });
52
+ }
53
+ function text(name) {
54
+ return new Column({ name, type: column.text() });
55
+ }
56
+ function varchar(name, options) {
57
+ return new Column({ name, type: column.varchar(options?.length) });
58
+ }
59
+ function integer(name) {
60
+ return new Column({ name, type: column.integer() });
61
+ }
62
+ function number(name) {
63
+ return new Column({ name, type: numberType, mapFromDriverValue: Number });
64
+ }
65
+ function boolean(name) {
66
+ return new Column({
67
+ name,
68
+ type: column.boolean(),
69
+ mapFromDriverValue: Boolean
70
+ });
71
+ }
72
+ function json(name) {
73
+ return new JsonColumn({
74
+ name,
75
+ type: column.json(),
76
+ mapToDriverValue(value) {
77
+ return JSON.stringify(value);
78
+ },
79
+ mapFromDriverValue(value, { parsesJson }) {
80
+ return parsesJson ? value : JSON.parse(value);
81
+ }
82
+ });
83
+ }
84
+ function blob(name) {
85
+ return new Column({
86
+ name,
87
+ type: blobType,
88
+ mapFromDriverValue(value) {
89
+ return new Uint8Array(value);
90
+ }
91
+ });
92
+ }
93
+
94
+ export {
95
+ id,
96
+ text,
97
+ varchar,
98
+ integer,
99
+ number,
100
+ boolean,
101
+ json,
102
+ blob
103
+ };