@nickpaustian/tela 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/bin/tela.ts +160 -0
  4. package/lib/index.js +751 -0
  5. package/lib/vite.js +64 -0
  6. package/package.json +71 -4
  7. package/routes/_layout.html +15 -0
  8. package/routes/_plain.html +17 -0
  9. package/routes/collections/[collection]/[id].html +3 -0
  10. package/routes/collections/[collection]/index.html +3 -0
  11. package/routes/index.html +3 -0
  12. package/routes/login.html +6 -0
  13. package/routes/media.html +3 -0
  14. package/routes/unpublished.html +3 -0
  15. package/scripts/check-components.ts +9 -0
  16. package/scripts/create-user.ts +50 -0
  17. package/scripts/media-words.ts +79 -0
  18. package/scripts/set-password.ts +72 -0
  19. package/src/api.ts +172 -0
  20. package/src/auth/login.ts +41 -0
  21. package/src/auth/sessions.ts +131 -0
  22. package/src/auth/setup.ts +47 -0
  23. package/src/collections/exhibitions/StatusSummary.lsp +76 -0
  24. package/src/collections/exhibitions/panels.ts +53 -0
  25. package/src/collections/exhibitions/schema.ts +203 -0
  26. package/src/collections/index.ts +20 -0
  27. package/src/collections/people/schema.ts +16 -0
  28. package/src/collections/users/schema.ts +18 -0
  29. package/src/collections/venues/schema.ts +37 -0
  30. package/src/components/BlockField.lsp +275 -0
  31. package/src/components/CharacterCount.lsp +161 -0
  32. package/src/components/ChoiceField.lsp +129 -0
  33. package/src/components/ChoiceSummary.lsp +32 -0
  34. package/src/components/CollectionList.lsp +100 -0
  35. package/src/components/DateField.lsp +46 -0
  36. package/src/components/DateRangeField.lsp +174 -0
  37. package/src/components/EntryCompare.lsp +815 -0
  38. package/src/components/EntryEditor.lsp +2948 -0
  39. package/src/components/EntryList.lsp +913 -0
  40. package/src/components/Field.lsp +293 -0
  41. package/src/components/FilterBar.lsp +237 -0
  42. package/src/components/GroupField.lsp +290 -0
  43. package/src/components/LoginForm.lsp +321 -0
  44. package/src/components/MarkdownField.lsp +1858 -0
  45. package/src/components/MediaLibrary.lsp +119 -0
  46. package/src/components/MediaPickerField.lsp +326 -0
  47. package/src/components/MediaUpload.lsp +226 -0
  48. package/src/components/NoteField.lsp +31 -0
  49. package/src/components/NumberField.lsp +37 -0
  50. package/src/components/ReferenceField.lsp +588 -0
  51. package/src/components/ReferenceSummary.lsp +87 -0
  52. package/src/components/RepeaterField.lsp +1517 -0
  53. package/src/components/SharePreviewField.lsp +631 -0
  54. package/src/components/Sidebar.lsp +467 -0
  55. package/src/components/SlugField.lsp +183 -0
  56. package/src/components/TextField.lsp +36 -0
  57. package/src/components/ThumbnailSummary.lsp +75 -0
  58. package/src/components/UnpublishedList.lsp +272 -0
  59. package/src/components/UseWordsField.lsp +59 -0
  60. package/src/components/chips.css +32 -0
  61. package/src/components/control-focus.css +13 -0
  62. package/src/components/control.css +32 -0
  63. package/src/components/disclosure.css +42 -0
  64. package/src/components/reorder.ts +184 -0
  65. package/src/components/visibility.ts +33 -0
  66. package/src/config/check.ts +122 -0
  67. package/src/config/components.ts +232 -0
  68. package/src/config/fields.ts +103 -0
  69. package/src/config/icons.ts +122 -0
  70. package/src/config/load.ts +17 -0
  71. package/src/config/navigation.ts +54 -0
  72. package/src/config/permissions.ts +418 -0
  73. package/src/config/seo.ts +163 -0
  74. package/src/config/types.ts +1384 -0
  75. package/src/content/access.ts +212 -0
  76. package/src/content/anchors.ts +34 -0
  77. package/src/content/changes.ts +139 -0
  78. package/src/content/collections.ts +20 -0
  79. package/src/content/compare-page.ts +206 -0
  80. package/src/content/compare.ts +269 -0
  81. package/src/content/counter.ts +139 -0
  82. package/src/content/derive-values.ts +117 -0
  83. package/src/content/derive.ts +108 -0
  84. package/src/content/dialect-extras.ts +110 -0
  85. package/src/content/entries.ts +349 -0
  86. package/src/content/entry.ts +155 -0
  87. package/src/content/export.ts +508 -0
  88. package/src/content/filters.ts +113 -0
  89. package/src/content/git.ts +216 -0
  90. package/src/content/governing.ts +23 -0
  91. package/src/content/history.ts +160 -0
  92. package/src/content/links.ts +55 -0
  93. package/src/content/markdown.ts +270 -0
  94. package/src/content/person.ts +24 -0
  95. package/src/content/preview.ts +31 -0
  96. package/src/content/references.ts +490 -0
  97. package/src/content/releases.ts +350 -0
  98. package/src/content/richtext.ts +885 -0
  99. package/src/content/rules.ts +274 -0
  100. package/src/content/sharing.ts +237 -0
  101. package/src/content/store.ts +142 -0
  102. package/src/content/summary.ts +409 -0
  103. package/src/content/surface-markdown.ts +169 -0
  104. package/src/content/unpublished.ts +115 -0
  105. package/src/content/url.ts +120 -0
  106. package/src/content/users.ts +235 -0
  107. package/src/content/validate.ts +305 -0
  108. package/src/content/visibility.ts +26 -0
  109. package/src/content/workflow.ts +531 -0
  110. package/src/db/client.ts +46 -0
  111. package/src/db/migrate.ts +122 -0
  112. package/src/db/migrations/001-initial.sql +69 -0
  113. package/src/db/migrations/002-releases.sql +58 -0
  114. package/src/db/migrations/003-soft-delete.sql +15 -0
  115. package/src/db/migrations/004-roles.sql +10 -0
  116. package/src/db/migrations/005-approvals.sql +55 -0
  117. package/src/db/migrations/006-version-author.sql +9 -0
  118. package/src/db/migrations/007-draft-saves.sql +17 -0
  119. package/src/editor.ts +11 -0
  120. package/src/index.ts +32 -0
  121. package/src/main.ts +74 -0
  122. package/src/media/image.ts +111 -0
  123. package/src/media/index.ts +147 -0
  124. package/src/media/local.ts +82 -0
  125. package/src/media/pseudolux.ts +504 -0
  126. package/src/media/s3.ts +154 -0
  127. package/src/media/sigv4.ts +157 -0
  128. package/src/media/store.ts +298 -0
  129. package/src/media-library.ts +177 -0
  130. package/src/project.ts +46 -0
  131. package/src/server/index.ts +2034 -0
  132. package/src/server/library-routes.ts +496 -0
  133. package/src/styles/base.css +197 -0
  134. package/src/styles/fonts/LICENSE-inter.txt +93 -0
  135. package/src/styles/fonts/inter-latin-ext-wght-italic.woff2 +0 -0
  136. package/src/styles/fonts/inter-latin-ext-wght-normal.woff2 +0 -0
  137. package/src/styles/fonts/inter-latin-wght-italic.woff2 +0 -0
  138. package/src/styles/fonts/inter-latin-wght-normal.woff2 +0 -0
  139. package/src/styles/fonts.css +40 -0
  140. package/src/styles/icons.css +63 -0
  141. package/src/styles/tokens.css +177 -0
  142. package/src/styles/type-icons.css +50 -0
  143. package/src/styles/ui.css +605 -0
  144. package/src/tooltip.ts +343 -0
  145. package/src/types.d.ts +7 -0
  146. package/src/ui.ts +252 -0
  147. package/src/vite.ts +77 -0
  148. package/src/waiting.ts +24 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nick Paustian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,51 @@
1
- # Temporary Holding Version
1
+ # Tela
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A micro headless CMS. Tela is the core: Postgres storage, drafts and releases, publishing to a site repo, permissions, the admin, and the built-in field types. A project is a `tela.config.ts` that declares its collections, plus any field inputs of its own.
4
+
5
+ ## Using Tela from a project
6
+
7
+ ```
8
+ my-cms/
9
+ tela.config.ts defineConfig({ collections, ... })
10
+ vite.config.ts import config from "./tela.config.ts"
11
+ import { telaVite } from "@nickpaustian/tela/vite"
12
+ export default telaVite(config)
13
+ src/collections/ one folder per collection
14
+ src/components/ the project's own field inputs (.lsp), scanned like Tela's
15
+ .env DATABASE_URL and the rest; see .env.example here
16
+ ```
17
+
18
+ ```sh
19
+ bun add @nickpaustian/tela @lightspeed-js/core
20
+ bunx tela server --watch # the API, on PORT
21
+ bunx tela dev # the admin, proxying /api to it
22
+ bunx tela build # checks components, builds the admin into ./dist
23
+ bunx tela create-user you@example.com # or open the admin: a fresh database offers to create the first admin
24
+ ```
25
+
26
+ A project component with the same name as one of Tela's fails the build unless the project names it in `overrides`, which is how a project replaces an input on purpose.
27
+
28
+ `tela dev` and `tela build` run Vite under Node 22.6 or later. The two entry points Vite's config loads (`@nickpaustian/tela` and `/vite`) ship compiled to `lib/`, since Node will not load TypeScript from `node_modules`; Bun reads the source. `bun run build:lib` rebuilds them, and packing does it first.
29
+
30
+ ## Working on Tela and a project together
31
+
32
+ A linked Tela is live in the project with no build step (outside `node_modules`, Node loads its source):
33
+
34
+ ```sh
35
+ cd tela && bun link
36
+ cd ../my-cms && bun link @nickpaustian/tela # or "@nickpaustian/tela": "link:@nickpaustian/tela" in package.json
37
+ ```
38
+
39
+ Bun's `file:` protocol copies rather than links, so it is not what you want here.
40
+
41
+ ## Developing Tela itself
42
+
43
+ This repo is also a valid project: its `tela.config.ts` and `src/collections/` are the example the tests run against.
44
+
45
+ ```sh
46
+ docker compose up -d
47
+ bun install
48
+ bun run server # API with --watch
49
+ bun run dev # admin
50
+ bun test
51
+ ```
package/bin/tela.ts ADDED
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env bun
2
+ import { existsSync } from "fs"
3
+ import { createRequire } from "module"
4
+ import { dirname, resolve } from "path"
5
+ import { fileURLToPath } from "url"
6
+
7
+ /**
8
+ * `tela <command>`, run from a project.
9
+ *
10
+ * The project is the current directory - that is where `tela.config.ts` and
11
+ * `.env` are read from - and Tela is wherever this file is installed. Each
12
+ * command is the script this repo already had, run with the project as its
13
+ * working directory, so nothing here knows anything the scripts do not.
14
+ */
15
+ const TELA_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..")
16
+ const require = createRequire(import.meta.url)
17
+ const [command, ...rest] = process.argv.slice(2)
18
+
19
+ const MIN_BUN = "1.2.3"
20
+ if (command === "server" && Bun.semver.order(Bun.version, MIN_BUN) < 0) {
21
+ console.error(
22
+ `tela server needs Bun ${MIN_BUN} or later; found ${Bun.version}. Run \`bun upgrade\`.\n` +
23
+ `(Bun.serve ignores \`routes\` before ${MIN_BUN}, so every request would be a 404.)`,
24
+ )
25
+ process.exit(1)
26
+ }
27
+
28
+ const USAGE = `tela <command>
29
+
30
+ dev the admin, with live reload (the API runs separately)
31
+ server [--watch] the API, serving the built admin in production
32
+ build check components, then build the admin into ./dist
33
+ check every field and summary names a component that exists
34
+ migrate run Tela's migrations (the server does this on boot)
35
+ create-user <email> [--editor]
36
+ set-password <email>
37
+ media-words [--apply] move words on media records into the library
38
+
39
+ Run from the folder holding tela.config.ts, or set TELA_CONFIG.`
40
+
41
+ async function run(args: string[], cwd = process.cwd(), env = process.env): Promise<number> {
42
+ const child = Bun.spawn(args, { cwd, stdio: ["inherit", "inherit", "inherit"], env })
43
+ const forward = (signal: NodeJS.Signals) => child.kill(signal)
44
+ process.on("SIGINT", forward)
45
+ process.on("SIGTERM", forward)
46
+ try {
47
+ return await child.exited
48
+ } finally {
49
+ process.off("SIGINT", forward)
50
+ process.off("SIGTERM", forward)
51
+ }
52
+ }
53
+
54
+ const script = (name: string) => resolve(TELA_ROOT, name)
55
+
56
+ /**
57
+ * Vite, as the CLI, under Node.
58
+ *
59
+ * Not Vite's JavaScript API under Bun: the Lightspeed plugin is exercised
60
+ * under Node, and under Bun its build lost Tela's own components and never
61
+ * finished rendering. The project's `vite.config.ts` is three lines -
62
+ * `telaVite(config)` - and is required, so the config stays a file Vite can
63
+ * bundle, with the project's `tela.config.ts` statically imported.
64
+ */
65
+ async function vite(sub: "dev" | "build"): Promise<number> {
66
+ const configFile = resolve(process.cwd(), "vite.config.ts")
67
+
68
+ if (!existsSync(configFile)) {
69
+ console.error(
70
+ `No vite.config.ts in ${process.cwd()}. Tela's admin builds with Vite; add one:\n\n` +
71
+ ` import config from "./tela.config.ts"\n` +
72
+ ` import { telaVite } from "@nickpaustian/tela/vite"\n\n` +
73
+ ` export default telaVite(config)\n`,
74
+ )
75
+ return 1
76
+ }
77
+
78
+ const pkg = require.resolve("vite/package.json")
79
+ const viteBin = resolve(dirname(pkg), (await Bun.file(pkg).json()).bin.vite)
80
+ const args = sub === "build" ? ["build"] : []
81
+
82
+ /**
83
+ * Tela is TypeScript source, and a project reaches it by package name. Vite
84
+ * bundles the relative imports in a config file and leaves packages to Node,
85
+ * so Node has to be able to load `.ts` - which it can, from 22.6, for a
86
+ * linked package (it refuses inside node_modules, so the published package
87
+ * ships compiled JavaScript for these entry points in `lib/`).
88
+ */
89
+ const node = await nodeVersion()
90
+ const recentEnough = node && (node.major > 22 || (node.major === 22 && node.minor >= 6))
91
+ if (!recentEnough) {
92
+ console.error(
93
+ `tela ${sub} needs Node 22.6 or later on the PATH to load TypeScript config; ` +
94
+ `found ${node ? `v${node.major}.${node.minor}` : "none"}.`,
95
+ )
96
+ return 1
97
+ }
98
+
99
+ const options = ["--experimental-strip-types", "--disable-warning=ExperimentalWarning"]
100
+ const env = {
101
+ ...process.env,
102
+ NODE_OPTIONS: [process.env.NODE_OPTIONS, ...options].filter(Boolean).join(" "),
103
+ }
104
+
105
+ return run(["node", viteBin, ...args, "--config", configFile], process.cwd(), env)
106
+ }
107
+
108
+ async function nodeVersion(): Promise<{ major: number; minor: number } | null> {
109
+ try {
110
+ const out = await new Response(Bun.spawn(["node", "--version"], { stdout: "pipe" }).stdout).text()
111
+ const [, major, minor] = out.trim().match(/^v(\d+)\.(\d+)/) ?? []
112
+ return major ? { major: Number(major), minor: Number(minor) } : null
113
+ } catch {
114
+ return null
115
+ }
116
+ }
117
+
118
+ let code: number
119
+
120
+ switch (command) {
121
+ case "dev":
122
+ code = await vite("dev")
123
+ break
124
+ case "build": {
125
+ code = await run(["bun", script("scripts/check-components.ts")])
126
+ if (code === 0) code = await vite("build")
127
+ break
128
+ }
129
+ case "check":
130
+ code = await run(["bun", script("scripts/check-components.ts")])
131
+ break
132
+ case "server": {
133
+ const watch = rest.includes("--watch") ? ["--watch"] : []
134
+ code = await run(["bun", ...watch, script("src/server/index.ts")])
135
+ break
136
+ }
137
+ case "migrate":
138
+ code = await run(["bun", script("src/db/migrate.ts")])
139
+ break
140
+ case "create-user":
141
+ code = await run(["bun", script("scripts/create-user.ts"), ...rest])
142
+ break
143
+ case "set-password":
144
+ code = await run(["bun", script("scripts/set-password.ts"), ...rest])
145
+ break
146
+ case "media-words":
147
+ code = await run(["bun", script("scripts/media-words.ts"), ...rest])
148
+ break
149
+ case undefined:
150
+ case "help":
151
+ case "--help":
152
+ console.log(USAGE)
153
+ code = 0
154
+ break
155
+ default:
156
+ console.error(`Unknown command "${command}".\n\n${USAGE}`)
157
+ code = 1
158
+ }
159
+
160
+ process.exit(code)