@joplo-app/server 0.8.0 → 0.8.2

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/dev.js CHANGED
@@ -754,7 +754,7 @@ export async function createHub(opts = {}) {
754
754
  optimizeDeps: web.mode === 'dist'
755
755
  ? { noDiscovery: true, include: [] }
756
756
  : {
757
- include: ['react', 'react-dom', 'react-dom/client', 'react/jsx-dev-runtime', 'react/jsx-runtime', 'motion', 'motion/react', 'roughjs', 'lucide-react', 'clsx', 'tailwind-merge', 'modern-screenshot', '@joplo-app/core > zod'],
757
+ include: ['react', 'react-dom', 'react-dom/client', 'react/jsx-dev-runtime', 'react/jsx-runtime', 'motion', 'motion/react', 'roughjs', 'lucide-react', 'clsx', 'tailwind-merge', 'modern-screenshot', '@tokenroll/juice/primitives', '@tokenroll/juice/core', '@joplo-app/core > zod'],
758
758
  },
759
759
  server: {
760
760
  host: '127.0.0.1',
@@ -762,7 +762,7 @@ export async function createHub(opts = {}) {
762
762
  strictPort: true,
763
763
  open: false,
764
764
  ...(web.mode === 'dist' ? { fs: { allow: [web.webDir] } } : {}),
765
- ...(watch ? { watch: { ignored: (p) => { const s = slotOfFile(p) ?? [...slots.values()].find((x) => p.startsWith(x.dir + path.sep)); return !!s && p !== s.dir && !isProjectSource(s.dir, p, s.watchIgnore ?? []); } } } : { watch: null }),
765
+ ...(watch ? { watch: { ignored: (p) => { const s = slotOfFile(p) ?? [...slots.values()].find((x) => p.startsWith(x.dir + path.sep)); return !!s && p !== s.dir && !isProjectSource(s.dir, p, s.watchIgnore ?? []); } } } : { watch: null, hmr: false }),
766
766
  },
767
767
  });
768
768
  try {
@@ -1,7 +1,7 @@
1
1
  import { entriesOf, projectThemes } from '@joplo-app/core';
2
2
  import crypto from 'node:crypto';
3
- import { JoploError, LOCAL_REVIEW_VERSION, LOCAL_REVIEW_MAX_EVENTS, LOCAL_REVIEW_MAX_FILE_BYTES, LocalReviewSession, localReviewStatus, stateAt } from '@joplo-app/core';
4
- import { localReviewFile, localReviewWatcherCount, writeLocalReview } from '@joplo-app/core/node';
3
+ import { JoploError, LOCAL_REVIEW_VERSION, LOCAL_REVIEW_MAX_EVENTS, LOCAL_REVIEW_MAX_FILE_BYTES, LocalReviewEventId, LocalReviewSession, localReviewStatus, stateAt } from '@joplo-app/core';
4
+ import { listLocalReviews, readLocalReview, localReviewFile, localReviewWatcherCount, writeLocalReview } from '@joplo-app/core/node';
5
5
  /** 对象键的插入顺序不构成新版本;数组顺序属于方案内容。 */
6
6
  function stable(value) {
7
7
  if (Array.isArray(value))
@@ -59,7 +59,7 @@ export class LocalReviewHub {
59
59
  persist(session) {
60
60
  if (!LocalReviewSession.safeParse(session).success)
61
61
  throw new JoploError('INVALID_SCHEMA', 'Invalid local review record');
62
- if (Buffer.byteLength(JSON.stringify(session)) > LOCAL_REVIEW_MAX_FILE_BYTES - (session.events.at(-1)?.type === 'feedback' ? 16_384 : 0))
62
+ if (Buffer.byteLength(JSON.stringify(session)) > LOCAL_REVIEW_MAX_FILE_BYTES - (localReviewStatus(session) === 'open' ? 16_384 : 0))
63
63
  throw new JoploError('USAGE', 'Local review storage limit reached. Confirm this review before starting another');
64
64
  writeLocalReview(localReviewFile(session.projectDir, session.id), session);
65
65
  this.sessions.set(session.id, session);
@@ -107,7 +107,11 @@ export class LocalReviewHub {
107
107
  const session = this.current.get(this.key(dir, workId));
108
108
  if (!session)
109
109
  throw new JoploError('NOT_FOUND', 'No current review for this option. Wait for a successful compilation');
110
- return { session, watchers: localReviewWatcherCount(dir, session.id) };
110
+ const older = listLocalReviews(dir).filter(s => s.id !== session.id && s.workId === workId && s.createdAt <= session.createdAt && s.events.some(e => e.type === 'feedback'));
111
+ const previous = older.find(s => localReviewStatus(s) !== 'open') ?? older[0];
112
+ const previousFeedback = previous?.events.flatMap(e => e.type === 'feedback'
113
+ ? [{ eventId: `${previous.id}:${e.seq}`, sessionId: previous.id, seq: e.seq, body: e.body, createdAt: e.createdAt, context: e.context }] : []);
114
+ return { session, watchers: localReviewWatcherCount(dir, session.id), ...(previousFeedback ? { previousFeedback } : {}) };
111
115
  }
112
116
  write(dir, project, input) {
113
117
  const session = this.sessions.get(input.sessionId);
@@ -115,11 +119,15 @@ export class LocalReviewHub {
115
119
  throw new JoploError('NOT_FOUND', 'Review session does not belong to this project and instance');
116
120
  const previous = session.events.find(e => e.requestId === input.requestId);
117
121
  if (previous) {
118
- const same = previous.type === input.type && (previous.type !== 'feedback' || input.type === 'feedback' && previous.body === input.body &&
119
- previous.context.sceneId === input.context.sceneId && previous.context.scenarioId === input.context.scenarioId && previous.context.position === input.context.position);
122
+ const sameLocation = (a, b) => a === null || b === null ? a === b : a.sceneId === b.sceneId && a.scenarioId === b.scenarioId && a.position === b.position;
123
+ const same = previous.type === input.type && (previous.type === 'feedback'
124
+ ? input.type === 'feedback' && previous.body === input.body && sameLocation(previous.context, input.context)
125
+ : previous.type === 'receipt' ? input.type === 'receipt' && previous.targetEventId === input.targetEventId && previous.status === input.status && previous.note === (input.note ?? null) && sameLocation(previous.target, input.target ?? null)
126
+ : true);
120
127
  if (!same)
121
128
  throw new JoploError('IDEMPOTENCY_MISMATCH', 'Request id was already used for different feedback');
122
- return { session, watchers: localReviewWatcherCount(dir, session.id) };
129
+ return this.current.get(this.key(dir, session.workId))?.id === session.id
130
+ ? this.state(dir, session.workId) : { session, watchers: localReviewWatcherCount(dir, session.id) };
123
131
  }
124
132
  if (this.current.get(this.key(dir, session.workId))?.id !== session.id || localReviewRevision(project, session.workId) !== session.revision)
125
133
  throw new JoploError('REVISION_CONFLICT', 'The option changed. Open its current review before submitting');
@@ -127,12 +135,32 @@ export class LocalReviewHub {
127
135
  return this.state(dir, session.workId);
128
136
  if (localReviewStatus(session) !== 'open')
129
137
  throw new JoploError('REVISION_CONFLICT', 'This review has ended');
130
- if (input.type === 'feedback' && session.events.length >= LOCAL_REVIEW_MAX_EVENTS - 1)
138
+ if (input.type !== 'approved' && session.events.length >= LOCAL_REVIEW_MAX_EVENTS - 1)
131
139
  throw new JoploError('USAGE', 'This review has reached its feedback limit. Confirm it before starting a new review');
132
140
  const base = { sessionId: session.id, seq: session.events.length + 1, requestId: input.requestId, createdAt: new Date().toISOString() };
133
- const event = input.type === 'feedback'
141
+ let receipt;
142
+ if (input.type === 'receipt') {
143
+ if (!LocalReviewEventId.safeParse(input.targetEventId).success)
144
+ throw new JoploError('INVALID_REFERENCE', 'Invalid feedback event id');
145
+ const [sourceSessionId, seq] = input.targetEventId.split(':');
146
+ let source;
147
+ try {
148
+ source = readLocalReview(dir, sourceSessionId);
149
+ }
150
+ catch (e) {
151
+ if (e.code === 'ENOENT' || e instanceof JoploError && e.code === 'NOT_FOUND')
152
+ throw new JoploError('INVALID_REFERENCE', 'Referenced feedback was not found in this project');
153
+ throw e;
154
+ }
155
+ const feedback = source.events.find(e => e.seq === Number(seq));
156
+ if (source.workId !== session.workId || feedback?.type !== 'feedback')
157
+ throw new JoploError('INVALID_REFERENCE', 'Referenced event must be feedback for the same work');
158
+ receipt = { ...base, type: 'receipt', targetEventId: input.targetEventId, targetBody: feedback.body, status: input.status, note: input.note ?? null,
159
+ target: input.target ? localReviewContext(project, session.workId, input.target) : null };
160
+ }
161
+ const event = receipt ?? (input.type === 'feedback'
134
162
  ? { ...base, type: 'feedback', body: input.body, context: localReviewContext(project, session.workId, input.context) }
135
- : { ...base, type: 'approved' };
163
+ : { ...base, type: 'approved' });
136
164
  this.persist({ ...session, events: [...session.events, event] });
137
165
  return this.state(dir, session.workId);
138
166
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joplo-app/server",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Joplo 作品本地服务:dev 看板、build 静态发布站、render 截图,服务链接与嵌入交付",
5
5
  "license": "PolyForm-Shield-1.0.0",
6
6
  "type": "module",
@@ -15,9 +15,9 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@joplo-app/core": "0.8.0",
19
- "@joplo-app/kit": "0.8.0",
20
- "@joplo-app/web": "0.8.0",
18
+ "@joplo-app/core": "0.8.2",
19
+ "@joplo-app/kit": "0.8.2",
20
+ "@joplo-app/web": "0.8.2",
21
21
  "@tailwindcss/vite": "4.3.4",
22
22
  "mediabunny": "1.65.2",
23
23
  "tailwindcss": "4.3.4",