datasette-paper 0.0.1a2__tar.gz
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.
- datasette_paper-0.0.1a2/LICENSE +201 -0
- datasette_paper-0.0.1a2/PKG-INFO +128 -0
- datasette_paper-0.0.1a2/README.md +107 -0
- datasette_paper-0.0.1a2/datasette_paper/__init__.py +219 -0
- datasette_paper-0.0.1a2/datasette_paper/db.py +196 -0
- datasette_paper-0.0.1a2/datasette_paper/errors.py +10 -0
- datasette_paper-0.0.1a2/datasette_paper/instance.py +433 -0
- datasette_paper-0.0.1a2/datasette_paper/manifest.json +88 -0
- datasette_paper-0.0.1a2/datasette_paper/markdown.py +214 -0
- datasette_paper-0.0.1a2/datasette_paper/migrations.py +176 -0
- datasette_paper-0.0.1a2/datasette_paper/permissions.py +168 -0
- datasette_paper-0.0.1a2/datasette_paper/pm_schema.py +42 -0
- datasette_paper-0.0.1a2/datasette_paper/router.py +3 -0
- datasette_paper-0.0.1a2/datasette_paper/routes/__init__.py +3 -0
- datasette_paper-0.0.1a2/datasette_paper/routes/docs.py +410 -0
- datasette_paper-0.0.1a2/datasette_paper/routes/events.py +226 -0
- datasette_paper-0.0.1a2/datasette_paper/sql/__init__.py +1 -0
- datasette_paper-0.0.1a2/datasette_paper/sql/_queries.py +270 -0
- datasette_paper-0.0.1a2/datasette_paper/sse.py +14 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/app-BIn5x-nl.css +1 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/app-BY0VpDC-.js +1 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/doc-BoP7MvYn.js +12 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/doc-DZ4XfphE.css +1 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/index-B9R1HmsH.css +1 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/index-DMPtBBwV.js +1 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/index-dR74KGzv.js +25 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
- datasette_paper-0.0.1a2/datasette_paper/static/gen/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
- datasette_paper-0.0.1a2/datasette_paper/templates/paper_base.html +14 -0
- datasette_paper-0.0.1a2/datasette_paper/util.py +31 -0
- datasette_paper-0.0.1a2/datasette_paper.egg-info/PKG-INFO +128 -0
- datasette_paper-0.0.1a2/datasette_paper.egg-info/SOURCES.txt +52 -0
- datasette_paper-0.0.1a2/datasette_paper.egg-info/dependency_links.txt +1 -0
- datasette_paper-0.0.1a2/datasette_paper.egg-info/entry_points.txt +2 -0
- datasette_paper-0.0.1a2/datasette_paper.egg-info/requires.txt +6 -0
- datasette_paper-0.0.1a2/datasette_paper.egg-info/top_level.txt +1 -0
- datasette_paper-0.0.1a2/pyproject.toml +56 -0
- datasette_paper-0.0.1a2/setup.cfg +4 -0
- datasette_paper-0.0.1a2/tests/test_actor.py +203 -0
- datasette_paper-0.0.1a2/tests/test_db.py +123 -0
- datasette_paper-0.0.1a2/tests/test_instance.py +225 -0
- datasette_paper-0.0.1a2/tests/test_markdown.py +349 -0
- datasette_paper-0.0.1a2/tests/test_paper.py +39 -0
- datasette_paper-0.0.1a2/tests/test_permissions.py +317 -0
- datasette_paper-0.0.1a2/tests/test_post_events.py +144 -0
- datasette_paper-0.0.1a2/tests/test_presence.py +111 -0
- datasette_paper-0.0.1a2/tests/test_routes_docs.py +545 -0
- datasette_paper-0.0.1a2/tests/test_share.py +277 -0
- datasette_paper-0.0.1a2/tests/test_sse_events.py +336 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: datasette-paper
|
|
3
|
+
Version: 0.0.1a2
|
|
4
|
+
Author: Alex Garcia
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/datasette/datasette-paper
|
|
7
|
+
Project-URL: Changelog, https://github.com/datasette/datasette-paper/releases
|
|
8
|
+
Project-URL: Issues, https://github.com/datasette/datasette-paper/issues
|
|
9
|
+
Project-URL: CI, https://github.com/datasette/datasette-paper/actions
|
|
10
|
+
Classifier: Framework :: Datasette
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: datasette
|
|
15
|
+
Requires-Dist: datasette-plugin-router>=0.0.1a3
|
|
16
|
+
Requires-Dist: datasette-vite>=0.0.1a2
|
|
17
|
+
Requires-Dist: prosemirror>=0.6.1
|
|
18
|
+
Requires-Dist: sqlite-migrate>=0.1b0
|
|
19
|
+
Requires-Dist: sqlite-utils>=4.0a1
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# datasette-paper
|
|
23
|
+
|
|
24
|
+
[](https://pypi.org/project/datasette-paper/)
|
|
25
|
+
[](https://github.com/datasette/datasette-paper/releases)
|
|
26
|
+
[](https://github.com/datasette/datasette-paper/actions/workflows/test.yml)
|
|
27
|
+
[](https://github.com/datasette/datasette-paper/blob/main/LICENSE)
|
|
28
|
+
|
|
29
|
+
Collaborative document editor for Datasette. ProseMirror frontend, SQLite-backed
|
|
30
|
+
storage in Datasette's internal database, real-time collaboration over SSE.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Install in the same environment as Datasette:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
datasette install datasette-paper
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quickstart
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
datasette --internal papers.db \
|
|
44
|
+
-s permissions.datasette-paper-list true \
|
|
45
|
+
-s permissions.datasette-paper-create true \
|
|
46
|
+
-s permissions.datasette-paper-view true \
|
|
47
|
+
-s permissions.datasette-paper-edit true
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
No user database is required — papers live in Datasette's internal database.
|
|
51
|
+
|
|
52
|
+
**Pass `--internal <path>` to persist papers across restarts.** Without it,
|
|
53
|
+
Datasette uses an ephemeral tempfile for the internal DB that is deleted
|
|
54
|
+
when the process exits. The plugin emits a startup warning when it detects
|
|
55
|
+
this, so you don't lose your papers to a forgotten flag.
|
|
56
|
+
|
|
57
|
+
## Permissions
|
|
58
|
+
|
|
59
|
+
Four actions gate access. The view/edit actions are per-paper; list/create
|
|
60
|
+
are global.
|
|
61
|
+
|
|
62
|
+
| Action | Scope | Gates |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| `datasette-paper-list` | global | The paper index page and the list endpoint. |
|
|
65
|
+
| `datasette-paper-create` | global (also-requires `list`) | Creating new papers. |
|
|
66
|
+
| `datasette-paper-view` | per-paper (`PaperResource`) | Reading a specific paper (bootstrap, SSE, document, tasks). |
|
|
67
|
+
| `datasette-paper-edit` | per-paper (`PaperResource`, also-requires `view`) | Modifying a specific paper (events, presence, rename, snapshot, share). |
|
|
68
|
+
|
|
69
|
+
The plugin registers a `permission_resources_sql` hook that resolves
|
|
70
|
+
per-paper view/edit grants from the `_datasette_paper_doc.created_by`
|
|
71
|
+
column (owners) and the `_datasette_paper_share` table (explicit grants
|
|
72
|
+
+ link-visibility levels).
|
|
73
|
+
|
|
74
|
+
## Sharing
|
|
75
|
+
|
|
76
|
+
Each paper has one of three visibility levels:
|
|
77
|
+
|
|
78
|
+
- `private` — only the owner and explicitly-shared actors can access.
|
|
79
|
+
- `link-view` — any authenticated actor with the link can view.
|
|
80
|
+
- `link-edit` — any authenticated actor with the link can view and edit.
|
|
81
|
+
|
|
82
|
+
Plus per-actor share rows that grant a specific actor a `viewer` or
|
|
83
|
+
`editor` role on a single paper.
|
|
84
|
+
|
|
85
|
+
The owner is whoever created the paper (`created_by`, captured from the
|
|
86
|
+
actor cookie at create time). Only the owner can change visibility or
|
|
87
|
+
mutate shares.
|
|
88
|
+
|
|
89
|
+
## Papers as data
|
|
90
|
+
|
|
91
|
+
Paper data lives in Datasette's internal database under tables prefixed
|
|
92
|
+
with `_datasette_paper_`:
|
|
93
|
+
|
|
94
|
+
- `_datasette_paper_doc` — one row per paper (id, name, visibility, created_by).
|
|
95
|
+
- `_datasette_paper_step` — append-only log of ProseMirror steps.
|
|
96
|
+
- `_datasette_paper_snapshot` — periodic full-document snapshots.
|
|
97
|
+
- `_datasette_paper_share` — per-actor view/edit grants.
|
|
98
|
+
|
|
99
|
+
## Wire protocol
|
|
100
|
+
|
|
101
|
+
JSON API rooted at `/-/paper/api/...` — no per-database segment. List/create
|
|
102
|
+
docs, bootstrap a paper, post step batches, stream updates over SSE, manage
|
|
103
|
+
shares, render markdown / extract tasks. See `CLAUDE.md` for the full
|
|
104
|
+
endpoint table.
|
|
105
|
+
|
|
106
|
+
## Frontend stack
|
|
107
|
+
|
|
108
|
+
Vite + Svelte 5 + ProseMirror. Bundle outputs to `datasette_paper/static/`.
|
|
109
|
+
|
|
110
|
+
## Development
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npm install --prefix frontend
|
|
114
|
+
just frontend # build the bundle
|
|
115
|
+
just dev # run datasette with the plugin + permissions granted
|
|
116
|
+
just dev-with-hmr # vite dev server + watchexec restart
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Run the test layers:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
just test # backend pytest
|
|
123
|
+
just test-frontend # vitest
|
|
124
|
+
just test-e2e # playwright (requires built bundle)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Always invoke Python with `uv run --prerelease=allow …` — `datasette` is on
|
|
128
|
+
a `>=1a23` pre-release pin.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# datasette-paper
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/datasette-paper/)
|
|
4
|
+
[](https://github.com/datasette/datasette-paper/releases)
|
|
5
|
+
[](https://github.com/datasette/datasette-paper/actions/workflows/test.yml)
|
|
6
|
+
[](https://github.com/datasette/datasette-paper/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Collaborative document editor for Datasette. ProseMirror frontend, SQLite-backed
|
|
9
|
+
storage in Datasette's internal database, real-time collaboration over SSE.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Install in the same environment as Datasette:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
datasette install datasette-paper
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quickstart
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
datasette --internal papers.db \
|
|
23
|
+
-s permissions.datasette-paper-list true \
|
|
24
|
+
-s permissions.datasette-paper-create true \
|
|
25
|
+
-s permissions.datasette-paper-view true \
|
|
26
|
+
-s permissions.datasette-paper-edit true
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
No user database is required — papers live in Datasette's internal database.
|
|
30
|
+
|
|
31
|
+
**Pass `--internal <path>` to persist papers across restarts.** Without it,
|
|
32
|
+
Datasette uses an ephemeral tempfile for the internal DB that is deleted
|
|
33
|
+
when the process exits. The plugin emits a startup warning when it detects
|
|
34
|
+
this, so you don't lose your papers to a forgotten flag.
|
|
35
|
+
|
|
36
|
+
## Permissions
|
|
37
|
+
|
|
38
|
+
Four actions gate access. The view/edit actions are per-paper; list/create
|
|
39
|
+
are global.
|
|
40
|
+
|
|
41
|
+
| Action | Scope | Gates |
|
|
42
|
+
|---|---|---|
|
|
43
|
+
| `datasette-paper-list` | global | The paper index page and the list endpoint. |
|
|
44
|
+
| `datasette-paper-create` | global (also-requires `list`) | Creating new papers. |
|
|
45
|
+
| `datasette-paper-view` | per-paper (`PaperResource`) | Reading a specific paper (bootstrap, SSE, document, tasks). |
|
|
46
|
+
| `datasette-paper-edit` | per-paper (`PaperResource`, also-requires `view`) | Modifying a specific paper (events, presence, rename, snapshot, share). |
|
|
47
|
+
|
|
48
|
+
The plugin registers a `permission_resources_sql` hook that resolves
|
|
49
|
+
per-paper view/edit grants from the `_datasette_paper_doc.created_by`
|
|
50
|
+
column (owners) and the `_datasette_paper_share` table (explicit grants
|
|
51
|
+
+ link-visibility levels).
|
|
52
|
+
|
|
53
|
+
## Sharing
|
|
54
|
+
|
|
55
|
+
Each paper has one of three visibility levels:
|
|
56
|
+
|
|
57
|
+
- `private` — only the owner and explicitly-shared actors can access.
|
|
58
|
+
- `link-view` — any authenticated actor with the link can view.
|
|
59
|
+
- `link-edit` — any authenticated actor with the link can view and edit.
|
|
60
|
+
|
|
61
|
+
Plus per-actor share rows that grant a specific actor a `viewer` or
|
|
62
|
+
`editor` role on a single paper.
|
|
63
|
+
|
|
64
|
+
The owner is whoever created the paper (`created_by`, captured from the
|
|
65
|
+
actor cookie at create time). Only the owner can change visibility or
|
|
66
|
+
mutate shares.
|
|
67
|
+
|
|
68
|
+
## Papers as data
|
|
69
|
+
|
|
70
|
+
Paper data lives in Datasette's internal database under tables prefixed
|
|
71
|
+
with `_datasette_paper_`:
|
|
72
|
+
|
|
73
|
+
- `_datasette_paper_doc` — one row per paper (id, name, visibility, created_by).
|
|
74
|
+
- `_datasette_paper_step` — append-only log of ProseMirror steps.
|
|
75
|
+
- `_datasette_paper_snapshot` — periodic full-document snapshots.
|
|
76
|
+
- `_datasette_paper_share` — per-actor view/edit grants.
|
|
77
|
+
|
|
78
|
+
## Wire protocol
|
|
79
|
+
|
|
80
|
+
JSON API rooted at `/-/paper/api/...` — no per-database segment. List/create
|
|
81
|
+
docs, bootstrap a paper, post step batches, stream updates over SSE, manage
|
|
82
|
+
shares, render markdown / extract tasks. See `CLAUDE.md` for the full
|
|
83
|
+
endpoint table.
|
|
84
|
+
|
|
85
|
+
## Frontend stack
|
|
86
|
+
|
|
87
|
+
Vite + Svelte 5 + ProseMirror. Bundle outputs to `datasette_paper/static/`.
|
|
88
|
+
|
|
89
|
+
## Development
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npm install --prefix frontend
|
|
93
|
+
just frontend # build the bundle
|
|
94
|
+
just dev # run datasette with the plugin + permissions granted
|
|
95
|
+
just dev-with-hmr # vite dev server + watchexec restart
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Run the test layers:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
just test # backend pytest
|
|
102
|
+
just test-frontend # vitest
|
|
103
|
+
just test-e2e # playwright (requires built bundle)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Always invoke Python with `uv run --prerelease=allow …` — `datasette` is on
|
|
107
|
+
a `>=1a23` pre-release pin.
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
from datasette import hookimpl, Response
|
|
2
|
+
from datasette.permissions import Action
|
|
3
|
+
from datasette_vite import vite_entry
|
|
4
|
+
from .router import router
|
|
5
|
+
from .permissions import PaperResource, permission_resources_sql # noqa: F401
|
|
6
|
+
from . import routes # noqa: F401 — triggers decorator registration
|
|
7
|
+
from .routes.events import sse_events
|
|
8
|
+
import os
|
|
9
|
+
import logging
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _method_dispatch_routes(raw_routes):
|
|
15
|
+
"""Combine routes with the same path pattern into method-dispatching views.
|
|
16
|
+
|
|
17
|
+
``datasette_plugin_router`` registers GET and POST for the same URL as
|
|
18
|
+
separate ``(pattern, view)`` tuples, but Datasette matches only the *first*
|
|
19
|
+
pattern that fits. Here we group by path and build a single wrapper that
|
|
20
|
+
returns 405 for unsupported methods.
|
|
21
|
+
"""
|
|
22
|
+
from collections import defaultdict
|
|
23
|
+
|
|
24
|
+
by_path = defaultdict(dict) # path -> {METHOD: view_fn}
|
|
25
|
+
order = [] # preserve registration order for first-seen path
|
|
26
|
+
|
|
27
|
+
for entry in router._routes:
|
|
28
|
+
path = entry.path
|
|
29
|
+
method = entry.method.upper()
|
|
30
|
+
if path not in by_path:
|
|
31
|
+
order.append(path)
|
|
32
|
+
by_path[path][method] = entry.fn
|
|
33
|
+
|
|
34
|
+
result = []
|
|
35
|
+
for path in order:
|
|
36
|
+
method_map = by_path[path]
|
|
37
|
+
if len(method_map) == 1:
|
|
38
|
+
# No conflict — use view directly
|
|
39
|
+
result.append((path, next(iter(method_map.values()))))
|
|
40
|
+
else:
|
|
41
|
+
# Build a dispatcher. The inner view fns from datasette_plugin_router
|
|
42
|
+
# have the signature (request, datasette=None, scope=None, receive=None, send=None).
|
|
43
|
+
# Datasette's wrap_view_function will call this dispatcher via
|
|
44
|
+
# async_call_with_supported_arguments, injecting datasette/request/send etc.
|
|
45
|
+
# Use a factory to capture _map in a closure, avoiding default-arg
|
|
46
|
+
# inspection issues with async_call_with_supported_arguments.
|
|
47
|
+
def _make_dispatcher(m):
|
|
48
|
+
async def dispatcher(
|
|
49
|
+
request,
|
|
50
|
+
datasette=None,
|
|
51
|
+
scope=None,
|
|
52
|
+
receive=None,
|
|
53
|
+
send=None,
|
|
54
|
+
):
|
|
55
|
+
method = request.method.upper()
|
|
56
|
+
handler = m.get(method)
|
|
57
|
+
if handler is None:
|
|
58
|
+
allowed = ", ".join(sorted(m.keys()))
|
|
59
|
+
return Response(
|
|
60
|
+
f"Method {method} not allowed",
|
|
61
|
+
status=405,
|
|
62
|
+
headers={"Allow": allowed},
|
|
63
|
+
)
|
|
64
|
+
return await handler(
|
|
65
|
+
request,
|
|
66
|
+
datasette=datasette,
|
|
67
|
+
scope=scope,
|
|
68
|
+
receive=receive,
|
|
69
|
+
send=send,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
return dispatcher
|
|
73
|
+
|
|
74
|
+
result.append((path, _make_dispatcher(dict(method_map))))
|
|
75
|
+
|
|
76
|
+
return result
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@hookimpl
|
|
80
|
+
def extra_template_vars(datasette):
|
|
81
|
+
return {
|
|
82
|
+
"datasette_paper_vite_entry": vite_entry(
|
|
83
|
+
datasette=datasette,
|
|
84
|
+
plugin_package="datasette_paper",
|
|
85
|
+
vite_dev_path=os.environ.get("DATASETTE_PAPER_VITE_PATH"),
|
|
86
|
+
),
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
_EVENTS_PATTERN = r"^/-/paper/api/docs/(?P<doc_id>\d+)/events$"
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@hookimpl
|
|
94
|
+
def register_routes():
|
|
95
|
+
routes_list = _method_dispatch_routes(router._routes)
|
|
96
|
+
|
|
97
|
+
# The SSE GET handler uses raw ASGI (needs send/receive) and cannot go
|
|
98
|
+
# through the decorator router. Merge it into the existing POST dispatcher
|
|
99
|
+
# for the same path so GET → sse_events and POST → post_events both work.
|
|
100
|
+
def _make_events_dispatcher(post_view, get_view):
|
|
101
|
+
async def events_dispatcher(
|
|
102
|
+
request, datasette=None, scope=None, receive=None, send=None
|
|
103
|
+
):
|
|
104
|
+
if request.method.upper() == "GET":
|
|
105
|
+
return await get_view(
|
|
106
|
+
datasette=datasette,
|
|
107
|
+
request=request,
|
|
108
|
+
send=send,
|
|
109
|
+
receive=receive,
|
|
110
|
+
)
|
|
111
|
+
return await post_view(
|
|
112
|
+
request,
|
|
113
|
+
datasette=datasette,
|
|
114
|
+
scope=scope,
|
|
115
|
+
receive=receive,
|
|
116
|
+
send=send,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
return events_dispatcher
|
|
120
|
+
|
|
121
|
+
return [
|
|
122
|
+
(pattern, _make_events_dispatcher(view_fn, sse_events))
|
|
123
|
+
if pattern == _EVENTS_PATTERN
|
|
124
|
+
else (pattern, view_fn)
|
|
125
|
+
for pattern, view_fn in routes_list
|
|
126
|
+
]
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@hookimpl
|
|
130
|
+
def register_actions(datasette):
|
|
131
|
+
return [
|
|
132
|
+
Action(
|
|
133
|
+
name="datasette-paper-list",
|
|
134
|
+
description="Can list papers (see the index page + list endpoint)",
|
|
135
|
+
),
|
|
136
|
+
Action(
|
|
137
|
+
name="datasette-paper-create",
|
|
138
|
+
description="Can create new papers",
|
|
139
|
+
also_requires="datasette-paper-list",
|
|
140
|
+
),
|
|
141
|
+
Action(
|
|
142
|
+
name="datasette-paper-view",
|
|
143
|
+
description="Can view a specific paper",
|
|
144
|
+
resource_class=PaperResource,
|
|
145
|
+
),
|
|
146
|
+
Action(
|
|
147
|
+
name="datasette-paper-edit",
|
|
148
|
+
description="Can edit a specific paper",
|
|
149
|
+
resource_class=PaperResource,
|
|
150
|
+
also_requires="datasette-paper-view",
|
|
151
|
+
),
|
|
152
|
+
]
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
@hookimpl
|
|
156
|
+
def menu_links(datasette, actor, request=None):
|
|
157
|
+
async def inner():
|
|
158
|
+
if await datasette.allowed(action="datasette-paper-list", actor=actor):
|
|
159
|
+
return [
|
|
160
|
+
{
|
|
161
|
+
"href": datasette.urls.path("/-/paper/"),
|
|
162
|
+
"label": "Papers",
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
return []
|
|
166
|
+
|
|
167
|
+
return inner
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
@hookimpl
|
|
171
|
+
async def startup(datasette):
|
|
172
|
+
from .migrations import ensure_migrations
|
|
173
|
+
|
|
174
|
+
internal = datasette.get_internal_database()
|
|
175
|
+
if getattr(internal, "is_temp_disk", False):
|
|
176
|
+
# Datasette's default --internal is an ephemeral tempfile that
|
|
177
|
+
# gets atexit-deleted. Paper data evaporates on every restart in
|
|
178
|
+
# that mode — surface a one-time warning so users persist their
|
|
179
|
+
# internal DB on purpose, not by accident.
|
|
180
|
+
logger.warning(
|
|
181
|
+
"datasette-paper: internal DB is ephemeral (default --internal "
|
|
182
|
+
"is a tempfile that gets deleted on exit). Papers will not "
|
|
183
|
+
"persist across restarts. Pass --internal <path> to retain papers."
|
|
184
|
+
)
|
|
185
|
+
await ensure_migrations(internal)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# bootstrap-icons / file-text-fill — kept in sync with the icon used in
|
|
189
|
+
# DocHeader.svelte to the left of the doc title. If you swap the icon,
|
|
190
|
+
# update both sites.
|
|
191
|
+
PAPER_ICON_SVG = (
|
|
192
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" '
|
|
193
|
+
'fill="currentColor" class="bi bi-file-text-fill" viewBox="0 0 16 16">'
|
|
194
|
+
'<path d="M12 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V2a2 2 '
|
|
195
|
+
"0 0 0-2-2M5 4h6a.5.5 0 0 1 0 1H5a.5.5 0 0 1 0-1m-.5 2.5A.5.5 0 0 1 5 "
|
|
196
|
+
"6h6a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5M5 8h6a.5.5 0 0 1 0 1H5a.5.5 0 "
|
|
197
|
+
'0 1 0-1m0 2h3a.5.5 0 0 1 0 1H5a.5.5 0 0 1 0-1"/></svg>'
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
# Optional integration with `datasette-sidebar` — if the package is
|
|
202
|
+
# installed, register a Papers entry. The try/except keeps the plugin
|
|
203
|
+
# import-clean when datasette-sidebar isn't present.
|
|
204
|
+
try:
|
|
205
|
+
from datasette_sidebar.hookspecs import SidebarApp # type: ignore[import-not-found]
|
|
206
|
+
|
|
207
|
+
@hookimpl
|
|
208
|
+
def datasette_sidebar_apps(datasette):
|
|
209
|
+
return [
|
|
210
|
+
SidebarApp(
|
|
211
|
+
label="Papers",
|
|
212
|
+
description="Collaborative documents",
|
|
213
|
+
href=lambda _db: "/-/paper/",
|
|
214
|
+
icon=PAPER_ICON_SVG,
|
|
215
|
+
color="#276890",
|
|
216
|
+
)
|
|
217
|
+
]
|
|
218
|
+
except ImportError:
|
|
219
|
+
pass
|