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
@@ -1,699 +0,0 @@
1
- import {
2
- any,
3
- array,
4
- object
5
- } from "../../chunks/chunk-I4GC3E65.js";
6
- import "../../chunks/chunk-CQ52GEHY.js";
7
-
8
- // src/core/db/EntryResolver.ts
9
- import { Entry as EntryExprs } from "alinea/core/Entry";
10
- import { EntryFields } from "alinea/core/EntryFields";
11
- import { Field } from "alinea/core/Field";
12
- import {
13
- querySource as queryEdge
14
- } from "alinea/core/Graph";
15
- import {
16
- getExpr,
17
- hasExpr,
18
- hasField,
19
- hasRoot,
20
- hasWorkspace
21
- } from "alinea/core/Internal";
22
- import { getScope } from "alinea/core/Scope";
23
- import { hasExact } from "alinea/core/util/Checks";
24
- import { entries, fromEntries, isRecord } from "alinea/core/util/Objects";
25
- import { unreachable } from "alinea/core/util/Types";
26
- import { createRecord } from "../EntryRecord.js";
27
- import { compareStrings } from "../source/Utils.js";
28
- import { assert } from "../util/Assert.js";
29
- import { aliasesFromData, aliasUrl } from "./EntryAliases.js";
30
- import {
31
- combineConditions
32
- } from "./EntryIndex.js";
33
- import { LinkResolver } from "./LinkResolver.js";
34
- var orFilter = object({ or: array(any) }).and(hasExact(["or"]));
35
- var andFilter = object({ and: array(any) }).and(hasExact(["and"]));
36
- var EntryResolver = class {
37
- constructor(config, index) {
38
- this.config = config;
39
- this.#scope = getScope(config);
40
- this.index = index;
41
- }
42
- config;
43
- index;
44
- #scope;
45
- #previewGraphs = /* @__PURE__ */ new WeakMap();
46
- call(ctx, entry, internal) {
47
- switch (internal.method) {
48
- case "snippet": {
49
- if (!ctx.searchTerms)
50
- throw new Error("Snippet method requires search terms to be provided");
51
- const start = this.expr(ctx, entry, internal.args[0]);
52
- const end = this.expr(ctx, entry, internal.args[1]);
53
- const cutOff = this.expr(ctx, entry, internal.args[2]);
54
- const limit = this.expr(ctx, entry, internal.args[3]);
55
- return snippet(
56
- entry.searchableText,
57
- ctx.searchTerms,
58
- start,
59
- end,
60
- cutOff,
61
- limit
62
- );
63
- }
64
- default:
65
- throw new Error(`Unknown method: "${internal.method}"`);
66
- }
67
- }
68
- field(entry, field) {
69
- const name = this.#scope.nameOf(field);
70
- if (!name) throw new Error(`Expression has no name ${field}`);
71
- return entry.data[name];
72
- }
73
- expr(ctx, entry, expr) {
74
- const internal = getExpr(expr);
75
- switch (internal.type) {
76
- case "field": {
77
- const result = this.field(entry, expr);
78
- if (result && typeof result === "object") {
79
- return structuredClone(result);
80
- }
81
- return result;
82
- }
83
- case "entryField":
84
- return entryFieldValue(entry, internal.name, internal.path);
85
- case "call":
86
- return this.call(ctx, entry, internal);
87
- case "value":
88
- return internal.value;
89
- default:
90
- unreachable(internal);
91
- }
92
- }
93
- projectTypes(types) {
94
- return entries(EntryFields).concat(types.flatMap(entries));
95
- }
96
- projection(query) {
97
- return query.select ?? fromEntries(
98
- (query.type ? this.projectTypes(
99
- Array.isArray(query.type) ? query.type : [query.type]
100
- ) : []).concat(entries(EntryFields)).concat(query.include ? entries(query.include) : [])
101
- );
102
- }
103
- sourceFilter(ctx, entry, query) {
104
- switch (query.edge) {
105
- case "parent": {
106
- return {
107
- nodes: entry.parentId ? [ctx.graph.byId(entry.parentId)] : [],
108
- language: (lang) => lang.locale === entry.locale
109
- };
110
- }
111
- case "next": {
112
- const parent = entry.parentId ? ctx.graph.byId(entry.parentId) : void 0;
113
- const [next] = Array.from(
114
- ctx.graph.filter({
115
- nodes: parent?.children() ?? [],
116
- node: (node) => node.index > entry.index,
117
- language: (lang) => lang.locale === entry.locale
118
- })
119
- ).sort((a, b) => compareStrings(a.index, b.index));
120
- const nodes = next ? [ctx.graph.byId(next.id)] : [];
121
- return { nodes };
122
- }
123
- case "previous": {
124
- const parent = entry.parentId ? ctx.graph.byId(entry.parentId) : void 0;
125
- const [previous] = Array.from(
126
- ctx.graph.filter({
127
- nodes: parent?.children() ?? [],
128
- node: (node) => node.index < entry.index,
129
- language: (lang) => lang.locale === entry.locale
130
- })
131
- ).sort((a, b) => compareStrings(b.index, a.index));
132
- const nodes = previous ? [ctx.graph.byId(previous.id)] : [];
133
- return { nodes };
134
- }
135
- case "siblings": {
136
- const parent = entry.parentId ? ctx.graph.byId(entry.parentId) : void 0;
137
- return {
138
- nodes: parent?.children() ?? [],
139
- node: (node) => query.includeSelf || node.id !== entry.id,
140
- language: (lang) => lang.locale === entry.locale
141
- };
142
- }
143
- case "translations": {
144
- const self = ctx.graph.byId(entry.id);
145
- assert(self);
146
- return {
147
- nodes: [self],
148
- language: (lang) => query.includeSelf || lang.locale !== entry.locale
149
- };
150
- }
151
- case "children": {
152
- const depth = query?.depth ?? 1;
153
- const self = ctx.graph.byId(entry.id);
154
- return {
155
- nodes: ctx.graph.candidateNodes({
156
- ids: descendantIds(self, depth)
157
- }),
158
- language: (language) => language.locale === entry.locale
159
- };
160
- }
161
- case "parents": {
162
- const depth = query?.depth ?? Number.POSITIVE_INFINITY;
163
- const ids = entry.parents.slice(-depth);
164
- const nodes = ids.map((id) => ctx.graph.byId(id));
165
- return { nodes, language: (lang) => lang.locale === entry.locale };
166
- }
167
- case "entryMultiple": {
168
- const fieldValue = this.field(entry, query.field);
169
- const ids = Array.isArray(fieldValue) ? fieldValue.map((item) => item._entry).filter(Boolean) : [];
170
- const nodes = ids.map((id) => ctx.graph.byId(id)).filter(Boolean);
171
- return { nodes };
172
- }
173
- case "entrySingle": {
174
- const fieldValue = this.field(entry, query.field);
175
- const entryId = fieldValue?._entry;
176
- const node = ctx.graph.byId(entryId);
177
- return { nodes: node ? [node] : [] };
178
- }
179
- default:
180
- return {};
181
- }
182
- }
183
- selectProjection(ctx, entry, value) {
184
- if (value && hasExpr(value)) return this.expr(ctx, entry, value);
185
- const source = queryEdge(value);
186
- if (!source)
187
- return fromEntries(
188
- entries(value).map(([key, value2]) => {
189
- return [key, this.selectProjection(ctx, entry, value2)];
190
- })
191
- );
192
- const related = value;
193
- const isEntryLink = related.edge === "entryMultiple" || related.edge === "entrySingle";
194
- const relatedQuery = isEntryLink ? { preferredLocale: entry.locale ?? void 0, ...related } : related;
195
- return this.query(
196
- { ...ctx, locale: isEntryLink ? void 0 : entry.locale },
197
- relatedQuery,
198
- this.sourceFilter(ctx, entry, related)
199
- ).getUnprocessed();
200
- }
201
- select(ctx, entry, query) {
202
- if (!entry) return null;
203
- if (query.select && hasExpr(query.select))
204
- return this.expr(ctx, entry, query.select);
205
- const fields = this.projection(query);
206
- return this.selectProjection(ctx, entry, fields);
207
- }
208
- condition(ctx, query) {
209
- const location = Array.isArray(query.location) ? query.location : query.location && this.#scope.locationOf(query.location);
210
- const checkStatus = statusChecker(ctx.status);
211
- const checkLocation = location && locationChecker(location);
212
- const locale = query.locale ?? ctx.locale;
213
- let checkLocale = locale !== void 0 && query.edge !== "translations" && localeChecker(
214
- typeof locale === "string" ? locale.toLowerCase() : null,
215
- false
216
- );
217
- if (!checkLocale && query.preferredLocale)
218
- checkLocale = localeChecker(query.preferredLocale.toLowerCase(), true);
219
- const checkType = Boolean(query.type) && typeChecker(
220
- Array.isArray(query.type) ? query.type.map((type) => this.#scope.nameOf(type)) : this.#scope.nameOf(query.type)
221
- );
222
- const source = queryEdge(query);
223
- const checkEntry = entryChecker(this.#scope, query);
224
- const checkFilter = query.filter && filterChecker(query.filter, (entry, name) => {
225
- if (name.startsWith("_")) return entryFieldValue(entry, name.slice(1));
226
- return entry.data[name];
227
- });
228
- const ids = equalityValues(query.id);
229
- return {
230
- ids,
231
- condition(entry) {
232
- if (!checkStatus(entry)) return false;
233
- if (checkLocation && !checkLocation(entry)) return false;
234
- if (checkType && !checkType(entry)) return false;
235
- const matchesLocale = checkLocale ? checkLocale(entry) : true;
236
- if (source !== "translations" && !matchesLocale) return false;
237
- if (checkEntry && !checkEntry(entry)) return false;
238
- if (checkFilter && !checkFilter(entry)) return false;
239
- return true;
240
- }
241
- };
242
- }
243
- isSingleResult(query) {
244
- return Boolean(
245
- query.first || query.get || query.count || query.edge === "parent" || query.edge === "next" || query.edge === "previous"
246
- );
247
- }
248
- query(ctx, query, preFilter) {
249
- const edge = query;
250
- const { skip, take, orderBy, groupBy, search, count } = query;
251
- const { ids, condition } = this.condition(ctx, edge);
252
- const filter = {
253
- search: Array.isArray(search) ? search.join(" ") : search,
254
- nodes: preFilter?.nodes ? void 0 : this.#candidateNodes(ctx.graph, query, ids),
255
- entry: condition
256
- };
257
- let entries2 = Array.from(
258
- ctx.graph.filter(
259
- preFilter ? combineConditions(filter, preFilter) : filter
260
- )
261
- );
262
- if (groupBy) {
263
- assert(!Array.isArray(groupBy), "groupBy must be a single field");
264
- const groups = /* @__PURE__ */ new Map();
265
- for (const entry of entries2) {
266
- const value = this.expr(ctx, entry, groupBy);
267
- if (!groups.has(value)) groups.set(value, entry);
268
- }
269
- entries2 = Array.from(groups.values());
270
- }
271
- if (orderBy) {
272
- const orders = Array.isArray(orderBy) ? orderBy : [orderBy];
273
- entries2.sort((a, b) => {
274
- for (const order of orders) {
275
- const ascending = order.asc !== void 0;
276
- const descending = order.desc !== void 0;
277
- assert(
278
- ascending !== descending,
279
- "orderBy must specify exactly one direction"
280
- );
281
- const expr = ascending ? order.asc : order.desc;
282
- const valueA = this.expr(ctx, a, expr);
283
- const valueB = this.expr(ctx, b, expr);
284
- const nullishA = valueA === null || valueA === void 0;
285
- const nullishB = valueB === null || valueB === void 0;
286
- if (nullishA || nullishB) {
287
- if (nullishA !== nullishB) return nullishA ? 1 : -1;
288
- continue;
289
- }
290
- const strings = typeof valueA === "string" && typeof valueB === "string";
291
- const numbers = typeof valueA === "number" && typeof valueB === "number";
292
- const booleans = typeof valueA === "boolean" && typeof valueB === "boolean";
293
- if (strings) {
294
- const compare = order.caseSensitive ? compareStrings(valueA, valueB) : valueA.localeCompare(valueB, void 0, { numeric: true });
295
- if (compare !== 0) return ascending ? compare : -compare;
296
- } else if (numbers) {
297
- if (valueA !== valueB)
298
- return ascending ? valueA - valueB : valueB - valueA;
299
- } else if (booleans && valueA !== valueB) {
300
- const compare = Number(valueA) - Number(valueB);
301
- return ascending ? compare : -compare;
302
- }
303
- }
304
- return 0;
305
- });
306
- } else if (edge.edge === "parents") {
307
- entries2.sort((a, b) => a.level - b.level);
308
- }
309
- if (skip) entries2.splice(0, skip);
310
- if (take) entries2.splice(take);
311
- const isSingle = this.isSingleResult(query);
312
- const asEdge = query;
313
- const getSelected = () => entries2.map((entry) => this.select(ctx, entry, query));
314
- const getUnprocessed = () => {
315
- if (count) return entries2.length;
316
- const results = getSelected();
317
- if (isSingle) return results[0];
318
- return results;
319
- };
320
- const getProcessed = async () => {
321
- if (count) return entries2.length;
322
- const results = getSelected();
323
- if (isSingle) {
324
- const entry = entries2[0];
325
- if (results[0]) {
326
- const linkResolver = new LinkResolver(this, ctx, entry.locale);
327
- return await this.postRow({ linkResolver }, results[0], asEdge);
328
- }
329
- return results[0];
330
- }
331
- if (results.length > 0) {
332
- await Promise.all(
333
- results.map((result, index) => {
334
- if (!result) return;
335
- const linkResolver = new LinkResolver(
336
- this,
337
- ctx,
338
- entries2[index].locale
339
- );
340
- return this.postRow({ linkResolver }, result, asEdge).then(
341
- (processed) => {
342
- results[index] = processed;
343
- }
344
- );
345
- }).filter(Boolean)
346
- );
347
- }
348
- return results;
349
- };
350
- return {
351
- entries: entries2,
352
- getUnprocessed,
353
- getProcessed
354
- };
355
- }
356
- #candidateNodes(graph, query, ids) {
357
- const location = Array.isArray(query.location) ? query.location : query.location && this.#scope.locationOf(query.location);
358
- const indexedLocation = location && location.length >= 1 && location.length <= 3 ? location : void 0;
359
- const workspaceQuery = isRecord(query.workspace) && hasWorkspace(query.workspace) ? this.#scope.nameOf(query.workspace) : query.workspace;
360
- const rootQuery = isRecord(query.root) && hasRoot(query.root) ? this.#scope.nameOf(query.root) : query.root;
361
- const workspaces = intersectValues(
362
- equalityValues(workspaceQuery),
363
- indexedLocation?.[0] ? [indexedLocation[0]] : void 0
364
- );
365
- const roots = intersectValues(
366
- equalityValues(rootQuery),
367
- indexedLocation?.[1] ? [indexedLocation[1]] : void 0
368
- );
369
- const types = query.type ? (Array.isArray(query.type) ? query.type : [query.type]).map(
370
- (type) => this.#scope.nameOf(type)
371
- ) : void 0;
372
- return graph.candidateNodes({
373
- ids,
374
- parentIds: equalityValues(query.parentId),
375
- urls: equalityValues(query.url),
376
- workspaces,
377
- roots,
378
- types
379
- });
380
- }
381
- async postField(ctx, interim, field) {
382
- return Field.queryValue(field, interim, ctx.linkResolver);
383
- }
384
- async postExpr(ctx, interim, expr) {
385
- if (hasField(expr)) return this.postField(ctx, interim, expr);
386
- return interim;
387
- }
388
- async postRow(ctx, interim, query) {
389
- if (!interim) return interim;
390
- const selected = this.projection(query);
391
- if (hasExpr(selected)) return this.postExpr(ctx, interim, selected);
392
- if (queryEdge(selected))
393
- return this.post(ctx, interim, selected);
394
- await Promise.all(
395
- entries(selected).map(async ([key, value]) => {
396
- const source = queryEdge(value);
397
- if (source)
398
- interim[key] = await this.post(
399
- ctx,
400
- interim[key],
401
- value
402
- );
403
- else
404
- interim[key] = await this.postExpr(ctx, interim[key], value);
405
- })
406
- );
407
- return interim;
408
- }
409
- async post(ctx, interim, input) {
410
- if (input.count === true) return interim;
411
- const isSingle = this.isSingleResult(input);
412
- if (isSingle) return this.postRow(ctx, interim, input);
413
- await Promise.all(
414
- interim.map(async (row, index) => {
415
- interim[index] = await this.postRow(ctx, row, input);
416
- })
417
- );
418
- return interim;
419
- }
420
- async resolve(query) {
421
- const graph = this.#graphFor(query.preview);
422
- const ctx = {
423
- status: query.status ?? "published",
424
- locale: query.locale,
425
- graph,
426
- searchTerms: Array.isArray(query.search) ? query.search.join(" ") : query.search
427
- };
428
- return this.query(ctx, query).getProcessed();
429
- }
430
- #graphFor(preview) {
431
- const baseGraph = this.index.graph;
432
- if (!preview || !("entry" in preview)) return baseGraph;
433
- const cached = this.#previewGraphs.get(preview);
434
- if (cached?.baseGraph === baseGraph) return cached.previewGraph;
435
- const previewEntry = preview.entry;
436
- const previewGraph = baseGraph.withChanges({
437
- fromSha: this.index.tree.sha,
438
- changes: [
439
- {
440
- op: "add",
441
- path: previewEntry.filePath,
442
- sha: previewEntry.fileHash,
443
- contents: new TextEncoder().encode(
444
- JSON.stringify(
445
- createRecord(previewEntry, previewEntry.status),
446
- null,
447
- 2
448
- )
449
- )
450
- }
451
- ]
452
- });
453
- this.#previewGraphs.set(preview, { baseGraph, previewGraph });
454
- return previewGraph;
455
- }
456
- };
457
- function statusChecker(status) {
458
- switch (status) {
459
- case "published":
460
- return (entry) => entry.status === "published";
461
- case "draft":
462
- return (entry) => entry.status === "draft";
463
- case "archived":
464
- return (entry) => entry.status === "archived";
465
- case "preferDraft":
466
- return (entry) => entry.active;
467
- case "preferPublished":
468
- return (entry) => entry.main;
469
- case "all":
470
- return (entry) => true;
471
- }
472
- }
473
- function descendantIds(node, depth) {
474
- if (!node || depth <= 0) return [];
475
- const result = [];
476
- let level = [node];
477
- for (let currentDepth = 1; currentDepth <= depth; currentDepth++) {
478
- level = level.flatMap((parent) => Array.from(parent.children()));
479
- if (level.length === 0) break;
480
- for (const child of level) result.push(child.id);
481
- }
482
- return result;
483
- }
484
- function equalityValues(condition) {
485
- if (condition === void 0) return void 0;
486
- if (typeof condition !== "object" || condition === null)
487
- return [condition];
488
- const operations = condition;
489
- if (operations.is !== void 0) return [operations.is];
490
- if (Array.isArray(operations.in)) return operations.in;
491
- return void 0;
492
- }
493
- function intersectValues(a, b) {
494
- if (!a) return b;
495
- if (!b) return a;
496
- return Array.from(new Set(a).intersection(new Set(b)));
497
- }
498
- function entryChecker(scope, query) {
499
- const root = isRecord(query.root) && hasRoot(query.root) ? scope.nameOf(query.root) : query.root;
500
- const workspace = isRecord(query.workspace) && hasWorkspace(query.workspace) ? scope.nameOf(query.workspace) : query.workspace;
501
- const base = filterChecker(
502
- {
503
- id: query.id,
504
- parentId: query.parentId,
505
- path: query.path,
506
- url: query.url,
507
- createdAt: query.createdAt,
508
- updatedAt: query.updatedAt,
509
- level: query.level,
510
- workspace,
511
- root
512
- },
513
- entryFieldValue
514
- );
515
- if (query.alias === void 0) return base;
516
- const hasAlias = aliasChecker(query.alias);
517
- return (entry) => base(entry) && hasAlias(entry);
518
- }
519
- function entryFieldValue(entry, name, path) {
520
- if (name === "aliases") return aliasesFromData(entry.data);
521
- if (path) return valueAtPath(entry.data, [...path, name]);
522
- const expr = EntryExprs[name];
523
- if (expr) {
524
- const internal = getExpr(expr);
525
- if (internal.type === "entryField" && internal.path)
526
- return valueAtPath(entry.data, [...internal.path, internal.name]);
527
- }
528
- return entry[name];
529
- }
530
- function valueAtPath(value, path) {
531
- let current = value;
532
- for (const segment of path) {
533
- if (!isRecord(current)) return void 0;
534
- current = current[segment];
535
- }
536
- return current;
537
- }
538
- function aliasChecker(alias) {
539
- return filterChecker({ aliases: { includes: { url: alias } } }, (entry) => {
540
- const aliases = aliasesFromData(entry.data) ?? [];
541
- return aliases.flatMap((row) => {
542
- const url = aliasUrl(row);
543
- return url === void 0 ? [] : [{ url }];
544
- });
545
- });
546
- }
547
- function typeChecker(type) {
548
- if (Array.isArray(type)) {
549
- return (entry) => type.includes(entry.type);
550
- }
551
- return (entry) => entry.type === type;
552
- }
553
- function locationChecker(location) {
554
- switch (location.length) {
555
- case 1:
556
- return (entry) => entry.workspace === location[0];
557
- case 2:
558
- return (entry) => entry.workspace === location[0] && entry.root === location[1];
559
- case 3: {
560
- return (entry) => {
561
- if (entry.workspace !== location[0]) return false;
562
- if (entry.root !== location[1]) return false;
563
- if (entry.level === 0) return false;
564
- if (entry.level === 1)
565
- return entry.parentDir.endsWith(`/${location[2]}`);
566
- const segment = entry.parentDir.split("/").at(-entry.level);
567
- return segment === location[2];
568
- };
569
- }
570
- default:
571
- return (entry) => true;
572
- }
573
- }
574
- function localeChecker(locale, preferred) {
575
- return (entry) => {
576
- if (preferred && entry.locale === null) return true;
577
- if (typeof entry.locale === "string")
578
- return entry.locale.toLowerCase() === locale;
579
- return entry.locale === locale;
580
- };
581
- }
582
- function filterChecker(filter, getField = (input, name) => input?.[name]) {
583
- const isOrFilter = orFilter.check(filter);
584
- if (isOrFilter) {
585
- const or = filter.or.filter(Boolean).map((op) => filterChecker(op, getField));
586
- return (input) => {
587
- for (const fn of or) if (fn(input)) return true;
588
- return false;
589
- };
590
- }
591
- const isAndFilter = andFilter.check(filter);
592
- if (isAndFilter) {
593
- const and = filter.and.filter(Boolean).map((op) => filterChecker(op, getField));
594
- return (input) => {
595
- for (const fn of and) if (!fn(input)) return false;
596
- return true;
597
- };
598
- }
599
- if (typeof filter !== "object" || filter === null) {
600
- return (input) => input === filter;
601
- }
602
- const conditions = createConditions(filter, getField);
603
- return (input) => {
604
- for (const condition of conditions) if (!condition(input)) return false;
605
- return true;
606
- };
607
- }
608
- function createConditions(ops, getField) {
609
- const conditions = Array();
610
- for (const [name, op] of entries(ops)) {
611
- if (op === void 0) continue;
612
- if (typeof op !== "object" || op === null) {
613
- conditions.push((input) => getField(input, name) === op);
614
- continue;
615
- }
616
- const inner = op;
617
- if (inner.is !== void 0)
618
- conditions.push((input) => getField(input, name) === inner.is);
619
- if (inner.isNot !== void 0)
620
- conditions.push((input) => getField(input, name) !== inner.isNot);
621
- const inOp = inner.in;
622
- if (Array.isArray(inOp))
623
- conditions.push((input) => input && inOp.includes(getField(input, name)));
624
- const notInOp = inner.notIn;
625
- if (Array.isArray(notInOp))
626
- conditions.push(
627
- (input) => input && !notInOp.includes(getField(input, name))
628
- );
629
- if (inner.gt !== void 0)
630
- conditions.push((input) => getField(input, name) > inner.gt);
631
- if (inner.gte !== void 0)
632
- conditions.push((input) => getField(input, name) >= inner.gte);
633
- if (inner.lt !== void 0)
634
- conditions.push((input) => getField(input, name) < inner.lt);
635
- if (inner.lte !== void 0)
636
- conditions.push((input) => getField(input, name) <= inner.lte);
637
- if (inner.startsWith)
638
- conditions.push((input) => {
639
- const field = getField(input, name);
640
- return typeof field === "string" && field.startsWith(inner.startsWith);
641
- });
642
- const orOp = inner.or;
643
- if (orOp) {
644
- const inner2 = Array.isArray(orOp) ? orOp.flatMap((op2) => createConditions(op2, getField)) : createConditions(orOp, getField);
645
- conditions.push((input) => {
646
- for (const condition of inner2) if (condition(input)) return true;
647
- return false;
648
- });
649
- }
650
- if (inner.has) {
651
- const has = filterChecker(inner.has);
652
- conditions.push((input) => has(getField(input, name)));
653
- }
654
- if (inner.includes) {
655
- const includes = filterChecker(inner.includes);
656
- conditions.push((input) => {
657
- const field = getField(input, name);
658
- if (!Array.isArray(field)) return false;
659
- for (const item of field) if (includes(item)) return true;
660
- return false;
661
- });
662
- }
663
- }
664
- return conditions;
665
- }
666
- function snippet(body, searchTerms, start, end, cutOff, limit) {
667
- if (limit <= 0 || limit > 64)
668
- throw new Error(
669
- "The 'limit' parameter must be greater than zero and less than or equal to 64."
670
- );
671
- const terms = searchTerms.toLowerCase().split(/\s+/).filter((term) => term !== "");
672
- const words = body.split(/\s+/);
673
- const highlightedWords = Array();
674
- let firstMatchIndex = -1;
675
- for (let i = 0; i < words.length; i++) {
676
- const lowerCaseWord = words[i].toLowerCase();
677
- const isMatch = terms.some((term) => lowerCaseWord.includes(term));
678
- if (isMatch && firstMatchIndex === -1) firstMatchIndex = i;
679
- if (isMatch) highlightedWords.push(`${start}${words[i]}${end}`);
680
- else highlightedWords.push(words[i]);
681
- }
682
- if (firstMatchIndex === -1)
683
- return words.slice(0, Math.min(limit, words.length)).join(" ");
684
- const idealStartIndex = Math.max(0, firstMatchIndex - Math.floor(limit / 2));
685
- const snippetResultWords = highlightedWords.slice(
686
- idealStartIndex,
687
- idealStartIndex + limit
688
- );
689
- let snippetResult = snippetResultWords.join(" ");
690
- if (idealStartIndex > 0) snippetResult = `${cutOff}${snippetResult}`;
691
- if (idealStartIndex + limit < highlightedWords.length)
692
- snippetResult = `${snippetResult}${cutOff}`;
693
- return snippetResult;
694
- }
695
- export {
696
- EntryResolver,
697
- filterChecker,
698
- statusChecker
699
- };
@@ -1,5 +0,0 @@
1
- import type { RemoteSource } from '../source/Source.js';
2
- import type { CommitRequest } from './CommitRequest.js';
3
- export interface EntryTarget extends RemoteSource {
4
- commit(request: CommitRequest): Promise<string>;
5
- }