@trylight/app 0.1.7 → 0.1.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.
- package/dist/client.js +1 -1
- package/dist/server/entities.js +13 -6
- package/package.json +2 -2
package/dist/client.js
CHANGED
|
@@ -97,7 +97,7 @@ function tableClient(entity) {
|
|
|
97
97
|
mutationFn: ({ id, patch }) => update(id, patch),
|
|
98
98
|
onMutate: async ({ id, patch }) => {
|
|
99
99
|
await client.cancelQueries({ queryKey: keys.all });
|
|
100
|
-
//
|
|
100
|
+
// A value set here loses its old source until the server answers with who set it; sources sent merge in.
|
|
101
101
|
const patched = (row) => row.id === id
|
|
102
102
|
? {
|
|
103
103
|
...row,
|
package/dist/server/entities.js
CHANGED
|
@@ -79,7 +79,9 @@ export function createEntitiesHandler(options) {
|
|
|
79
79
|
const patch = await readBody(request, table.update);
|
|
80
80
|
if (!patch.success)
|
|
81
81
|
return refuse(400, "invalid", z.prettifyError(patch.error));
|
|
82
|
-
|
|
82
|
+
// The page's own address: behind the platform's proxy the request's host is an internal hop, Origin (checked above) is not.
|
|
83
|
+
const origin = request.headers.get("origin");
|
|
84
|
+
return answer(() => update(db, table, actor, origin === null ? url.origin : origin, id, patch.data));
|
|
83
85
|
}
|
|
84
86
|
if (id !== null && method === "DELETE")
|
|
85
87
|
return answer(() => remove(db, table, actor, id));
|
|
@@ -160,15 +162,21 @@ async function create(db, table, actor, data) {
|
|
|
160
162
|
.returning());
|
|
161
163
|
});
|
|
162
164
|
}
|
|
163
|
-
async function update(db, table, actor,
|
|
165
|
+
async function update(db, table, actor,
|
|
166
|
+
/** This app's own address: where a person's edit was said. */
|
|
167
|
+
origin, id, patch) {
|
|
164
168
|
return db.transaction(async (tx) => {
|
|
165
169
|
await nameActor(tx, actor);
|
|
166
170
|
const before = atMostOne(await tx.select().from(table.entity).where(eq(table.id, id)).for("update"));
|
|
167
171
|
if (before === null)
|
|
168
172
|
return null;
|
|
169
173
|
const changed = Object.keys(patch).filter((key) => !isDeepStrictEqual(patch[key], before[key]));
|
|
170
|
-
// A value a person sets is no longer what its source said
|
|
171
|
-
const
|
|
174
|
+
// A sourced value a person sets is no longer what its source said: its source is now them. Sources sent are merged in.
|
|
175
|
+
const stored = storedSources.parse(before.field_sources);
|
|
176
|
+
const edited = changed
|
|
177
|
+
.filter((column) => column in stored)
|
|
178
|
+
.map((column) => [column, { url: origin, evidence: `Edited by ${actor.name}` }]);
|
|
179
|
+
const field_sources = { ...withoutSources(stored, changed), ...Object.fromEntries(edited), ...patch.field_sources };
|
|
172
180
|
return exactlyOne(await tx
|
|
173
181
|
.update(table.entity)
|
|
174
182
|
.set({ ...patch, field_sources })
|
|
@@ -204,8 +212,7 @@ function exactlyOne(rows) {
|
|
|
204
212
|
// What's stored may come from an agent's own write: read as it is, never refused here.
|
|
205
213
|
const storedSources = z.record(z.string(), z.unknown());
|
|
206
214
|
function withoutSources(stored, columns) {
|
|
207
|
-
|
|
208
|
-
return Object.fromEntries(Object.entries(sources).filter(([column]) => !columns.includes(column)));
|
|
215
|
+
return Object.fromEntries(Object.entries(stored).filter(([column]) => !columns.includes(column)));
|
|
209
216
|
}
|
|
210
217
|
function signedIn(session) {
|
|
211
218
|
return session.user === null ? null : { id: session.user.id, name: session.user.name };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trylight/app",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "The Light SDK every v2 org app depends on: entities (Drizzle tables with a typed client), sign-in, contracts and in-app chat.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/shubh9/mii.git",
|
|
13
|
-
"directory": "packages/
|
|
13
|
+
"directory": "packages/app-sdk"
|
|
14
14
|
},
|
|
15
15
|
"packageManager": "pnpm@11.0.9",
|
|
16
16
|
"files": [
|