@stonecrop/nuxt 0.50.1 → 0.52.0
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/module.json +1 -1
- package/package.json +13 -13
- package/templates/index.vue +2 -2
- package/templates/resolvers.ts +25 -3
- package/templates/useDoctypes.ts +1 -1
package/dist/module.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/nuxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.0",
|
|
4
4
|
"description": "Nuxt module for Stonecrop",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -60,18 +60,18 @@
|
|
|
60
60
|
"pathe": "^2.0.3",
|
|
61
61
|
"pinia": "^3.0.4",
|
|
62
62
|
"prompts": "^2.4.2",
|
|
63
|
-
"@stonecrop/aform": "0.
|
|
64
|
-
"@stonecrop/
|
|
65
|
-
"@stonecrop/
|
|
66
|
-
"@stonecrop/
|
|
67
|
-
"@stonecrop/
|
|
68
|
-
"@stonecrop/graphql-
|
|
69
|
-
"@stonecrop/
|
|
70
|
-
"@stonecrop/node-editor": "0.
|
|
71
|
-
"@stonecrop/
|
|
72
|
-
"@stonecrop/
|
|
73
|
-
"@stonecrop/
|
|
74
|
-
"@stonecrop/
|
|
63
|
+
"@stonecrop/aform": "0.52.0",
|
|
64
|
+
"@stonecrop/atable": "0.52.0",
|
|
65
|
+
"@stonecrop/code-editor": "0.52.0",
|
|
66
|
+
"@stonecrop/desktop": "0.52.0",
|
|
67
|
+
"@stonecrop/casl-middleware": "0.52.0",
|
|
68
|
+
"@stonecrop/graphql-client": "0.52.0",
|
|
69
|
+
"@stonecrop/graphql-middleware": "0.52.0",
|
|
70
|
+
"@stonecrop/node-editor": "0.52.0",
|
|
71
|
+
"@stonecrop/nuxt-grafserv": "0.52.0",
|
|
72
|
+
"@stonecrop/schema": "0.52.0",
|
|
73
|
+
"@stonecrop/themes": "0.52.0",
|
|
74
|
+
"@stonecrop/stonecrop": "0.52.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@eslint/js": "^10.0.1",
|
package/templates/index.vue
CHANGED
|
@@ -18,8 +18,8 @@ import { doctypeMap } from '~/composables/useDoctypes'
|
|
|
18
18
|
const routeAdapter = useRouteAdapter()
|
|
19
19
|
// Shared action executor, auto-imported from @stonecrop/nuxt: it runs an action's clientHandler
|
|
20
20
|
// when the doctype declares one, otherwise dispatches to the server, and writes the result back
|
|
21
|
-
// into the store under the identity the server settled on — a Save
|
|
22
|
-
//
|
|
21
|
+
// into the store under the identity the server settled on — a Save on a record not created yet
|
|
22
|
+
// creates it, so that identity is not always the one the form dispatched. Bound straight to
|
|
23
23
|
// Desktop's @action; a host-written wrapper would have to restate all of that.
|
|
24
24
|
const { run } = useClientAction()
|
|
25
25
|
|
package/templates/resolvers.ts
CHANGED
|
@@ -145,12 +145,14 @@ function nextId(doctype: string): string {
|
|
|
145
145
|
//
|
|
146
146
|
// Add your own by registering under the doctype's `name`. Throwing rejects the action; what it
|
|
147
147
|
// returns becomes the result's `data`, while the client stores the record as a read returns it.
|
|
148
|
+
// A handler on a Save (`selfTransition`) is the whole save, creating the record when it has no
|
|
149
|
+
// `recordId`, and must return the record it saved.
|
|
148
150
|
|
|
149
151
|
type ActionHandler = (context: {
|
|
150
152
|
recordId?: string
|
|
151
153
|
/** Record field data the client sent. Unvalidated browser input — validate before trusting it. */
|
|
152
154
|
data: Record<string, unknown>
|
|
153
|
-
/** The state the guard read, or undefined when nothing
|
|
155
|
+
/** The state the guard read ('' for a record with no state), or undefined when nothing required reading it or the record does not exist yet. */
|
|
154
156
|
currentState?: string
|
|
155
157
|
}) => Promise<unknown>
|
|
156
158
|
|
|
@@ -284,12 +286,22 @@ export const resolvers = {
|
|
|
284
286
|
{
|
|
285
287
|
readState: async () => {
|
|
286
288
|
// `null` means "no such record" and `undefined` means "exists, no
|
|
287
|
-
// state"
|
|
289
|
+
// state": the dispatcher refuses an action on the first, except a
|
|
290
|
+
// self-transition, which creates the record. Returning
|
|
288
291
|
// `undefined` for both is what let a Save on a record that was
|
|
289
292
|
// never created report success while persisting nothing.
|
|
290
293
|
if (recordId == null) return null
|
|
291
294
|
const record = getRecord(d, recordId, lookupField)
|
|
292
|
-
if (!record)
|
|
295
|
+
if (!record) {
|
|
296
|
+
// An id that matches nothing is a record deleted since it was read, and
|
|
297
|
+
// saving it as a create would report a lost update as a success.
|
|
298
|
+
if (actionDef.selfTransition === true) {
|
|
299
|
+
throw new Error(
|
|
300
|
+
`${actionDef.label ?? spec.action} failed: record ${recordId} no longer exists.`
|
|
301
|
+
)
|
|
302
|
+
}
|
|
303
|
+
return null
|
|
304
|
+
}
|
|
293
305
|
return record.status == null ? undefined : String(record.status)
|
|
294
306
|
},
|
|
295
307
|
writeState: async (nextState: string) => {
|
|
@@ -345,6 +357,16 @@ export const resolvers = {
|
|
|
345
357
|
: undefined
|
|
346
358
|
const readId = repliedId ?? recordId
|
|
347
359
|
const record = outcome.success && readId != null ? getRecord(d, String(readId), lookupField) : null
|
|
360
|
+
// A save with no record to file leaves the page on its draft, whose next save
|
|
361
|
+
// creates a second record. This store cannot undo what a handler wrote.
|
|
362
|
+
if (outcome.success && actionDef.selfTransition === true && record === null) {
|
|
363
|
+
return {
|
|
364
|
+
success: false,
|
|
365
|
+
data: null,
|
|
366
|
+
error: `${actionDef.label ?? spec.action} failed: the server did not say which record it saved.`,
|
|
367
|
+
record: null,
|
|
368
|
+
}
|
|
369
|
+
}
|
|
348
370
|
return { ...outcome, record }
|
|
349
371
|
} catch (err) {
|
|
350
372
|
return { success: false, data: null, error: err instanceof Error ? err.message : String(err) }
|
package/templates/useDoctypes.ts
CHANGED
|
@@ -30,5 +30,5 @@ export function useDoctypeConfig(slug: string): DoctypeConfig | undefined {
|
|
|
30
30
|
|
|
31
31
|
// Actions are deliberately not dispatched from here. Dispatching is only half the job: the result
|
|
32
32
|
// has to land in the store under the identity the server settled on, which is not always the id
|
|
33
|
-
// that was dispatched — a Save
|
|
33
|
+
// that was dispatched — a Save on a record not created yet creates it. `useClientAction`
|
|
34
34
|
// (auto-imported from @stonecrop/nuxt) owns both halves; app/pages/index.vue binds it directly.
|