@stonecrop/nuxt 0.35.0 → 0.36.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/README.md +3 -1
- package/dist/module.json +1 -1
- package/package.json +14 -13
- package/src/cli/installers/frontend.ts +2 -1
- package/src/cli/installers/grafserv.ts +2 -0
- package/templates/resolvers.ts +17 -7
- package/templates/schema.graphql +2 -0
package/README.md
CHANGED
|
@@ -427,7 +427,7 @@ await dispatchAction({ name: 'plan' }, 'SUBMIT', [recordId])
|
|
|
427
427
|
| `setMeta(fn)` | `(fn: (ctx) => Doctype \| Promise<Doctype>) => void` | Sets the `getMeta` function on the Registry. Called by `useStonecrop({ doctype: 'slug' })` to lazy-load that doctype's metadata. `ctx` = `{ path, segments }`. |
|
|
428
428
|
| `setClient(client)` | `(client: DataClient) => void` | Set the data client for record fetching. Throws if stonecrop not available. |
|
|
429
429
|
| `getClient()` | `() => DataClient \| undefined` | Get the currently configured client. |
|
|
430
|
-
| `dispatchAction(doctype, action, args)` | `Promise<{ success, data, error }>` | Dispatch an action via the configured client. Returns error if doctype not found in registry. |
|
|
430
|
+
| `dispatchAction(doctype, action, args)` | `Promise<{ success, data, error }>` | Dispatch an action via the configured client, storing the result's `record` (the server's read of the record after the action). Returns error if doctype not found in registry. |
|
|
431
431
|
|
|
432
432
|
## Advanced Features
|
|
433
433
|
|
|
@@ -570,8 +570,10 @@ The CLI will detect that you're in a Nuxt project and prompt for features:
|
|
|
570
570
|
|
|
571
571
|
? Select features to install
|
|
572
572
|
◉ @stonecrop/nuxt - Frontend module
|
|
573
|
+
◯ @stonecrop/graphql-client - GraphQL client
|
|
573
574
|
◯ @stonecrop/nuxt-grafserv - GraphQL server
|
|
574
575
|
◯ @stonecrop/casl-middleware - Authorization
|
|
576
|
+
◯ @stonecrop/rockfoil - PostGraphile middleware
|
|
575
577
|
◉ Sample doctypes
|
|
576
578
|
```
|
|
577
579
|
|
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.36.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/
|
|
64
|
-
"@stonecrop/
|
|
65
|
-
"@stonecrop/casl-middleware": "0.
|
|
66
|
-
"@stonecrop/
|
|
67
|
-
"@stonecrop/
|
|
68
|
-
"@stonecrop/graphql-client": "0.
|
|
69
|
-
"@stonecrop/
|
|
70
|
-
"@stonecrop/
|
|
71
|
-
"@stonecrop/
|
|
72
|
-
"@stonecrop/
|
|
73
|
-
"@stonecrop/
|
|
74
|
-
"@stonecrop/
|
|
63
|
+
"@stonecrop/atable": "0.36.0",
|
|
64
|
+
"@stonecrop/code-editor": "0.36.0",
|
|
65
|
+
"@stonecrop/casl-middleware": "0.36.0",
|
|
66
|
+
"@stonecrop/desktop": "0.36.0",
|
|
67
|
+
"@stonecrop/aform": "0.36.0",
|
|
68
|
+
"@stonecrop/graphql-client": "0.36.0",
|
|
69
|
+
"@stonecrop/graphql-middleware": "0.36.0",
|
|
70
|
+
"@stonecrop/nuxt-grafserv": "0.36.0",
|
|
71
|
+
"@stonecrop/schema": "0.36.0",
|
|
72
|
+
"@stonecrop/stonecrop": "0.36.0",
|
|
73
|
+
"@stonecrop/themes": "0.36.0",
|
|
74
|
+
"@stonecrop/node-editor": "0.36.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@eslint/js": "^10.0.1",
|
|
@@ -95,6 +95,7 @@
|
|
|
95
95
|
"nuxt": "^4.4.8",
|
|
96
96
|
"nuxt-graphql-middleware": "^5.4.0",
|
|
97
97
|
"postgraphile": "^5.0.3",
|
|
98
|
+
"temporal-polyfill": "^1.0.5",
|
|
98
99
|
"typescript": "^6.0.3",
|
|
99
100
|
"typescript-eslint": "^8.62.1",
|
|
100
101
|
"vite": "^8.2.2",
|
|
@@ -26,11 +26,12 @@ export async function installFrontend(options: FrontendInstallerOptions): Promis
|
|
|
26
26
|
|
|
27
27
|
try {
|
|
28
28
|
// Add @stonecrop/nuxt and its required peer dependencies
|
|
29
|
-
// These packages are imported by the Nuxt module and need to be available at runtime
|
|
29
|
+
// These packages are imported by the Nuxt module or the scaffolded app files and need to be available at runtime
|
|
30
30
|
await addDependencies(cwd, {
|
|
31
31
|
'@stonecrop/nuxt': 'latest',
|
|
32
32
|
'@stonecrop/aform': 'latest',
|
|
33
33
|
'@stonecrop/atable': 'latest',
|
|
34
|
+
'@stonecrop/graphql-client': 'latest',
|
|
34
35
|
'@stonecrop/stonecrop': 'latest',
|
|
35
36
|
'@stonecrop/node-editor': 'latest',
|
|
36
37
|
'@stonecrop/schema': 'latest',
|
|
@@ -39,8 +39,10 @@ export async function installGrafserv(options: GrafservInstallerOptions): Promis
|
|
|
39
39
|
await addDependencies(cwd, {
|
|
40
40
|
'@stonecrop/nuxt-grafserv': 'latest',
|
|
41
41
|
'@stonecrop/graphql-middleware': 'latest',
|
|
42
|
+
'@stonecrop/schema': 'latest',
|
|
42
43
|
graphql: '^16.11.0',
|
|
43
44
|
grafast: '^1.0.1',
|
|
45
|
+
'temporal-polyfill': '^1.0.5',
|
|
44
46
|
})
|
|
45
47
|
|
|
46
48
|
// Update nuxt.config.ts
|
package/templates/resolvers.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { constant, lambda, loadOne, object } from 'grafast'
|
|
|
22
22
|
import { getMeta, getAllMeta, applyGuardedTransition } from '@stonecrop/graphql-middleware'
|
|
23
23
|
import { getRecordIdField } from '@stonecrop/schema'
|
|
24
24
|
import type { DoctypeMeta } from '@stonecrop/schema'
|
|
25
|
+
import { Temporal } from 'temporal-polyfill'
|
|
25
26
|
import { projects, tasks, type Project, type Task } from './data'
|
|
26
27
|
|
|
27
28
|
// ============================================================
|
|
@@ -142,8 +143,8 @@ function nextId(doctype: string): string {
|
|
|
142
143
|
// `selfTransition` has nothing for the dispatcher to apply, and without an entry here it fails
|
|
143
144
|
// loudly rather than reporting a false success.
|
|
144
145
|
//
|
|
145
|
-
// Add your own by registering under the doctype's `name`. Throwing rejects the action;
|
|
146
|
-
// the
|
|
146
|
+
// Add your own by registering under the doctype's `name`. Throwing rejects the action; what it
|
|
147
|
+
// returns becomes the result's `data`, while the client stores the record as a read returns it.
|
|
147
148
|
|
|
148
149
|
type ActionHandler = (context: {
|
|
149
150
|
recordId?: string
|
|
@@ -165,9 +166,9 @@ export const actionHandlers: Record<string, Record<string, ActionHandler>> = {
|
|
|
165
166
|
const task = recordId != null ? tasks.get(recordId) : undefined
|
|
166
167
|
if (!task) throw new Error(`Task ${recordId ?? '(none)'} not found`)
|
|
167
168
|
|
|
168
|
-
|
|
169
|
-
from.
|
|
170
|
-
const updated: Task = { ...task, dueDate: from.
|
|
169
|
+
// A task with no due date is snoozed from the server's today.
|
|
170
|
+
const from = task.dueDate ? Temporal.PlainDate.from(task.dueDate) : Temporal.Now.plainDateISO()
|
|
171
|
+
const updated: Task = { ...task, dueDate: from.add({ weeks: 1 }).toString() }
|
|
171
172
|
tasks.set(task.id, updated)
|
|
172
173
|
return Promise.resolve(updated)
|
|
173
174
|
},
|
|
@@ -278,7 +279,7 @@ export const resolvers = {
|
|
|
278
279
|
// The server owns the transition: read current state, guard against allowedStates,
|
|
279
280
|
// write nextState. Reads/writes go straight to the in-memory Maps; a PostGraphile
|
|
280
281
|
// setup swaps in pgClient SQL instead.
|
|
281
|
-
|
|
282
|
+
const outcome = await applyGuardedTransition(
|
|
282
283
|
actionDef,
|
|
283
284
|
{
|
|
284
285
|
readState: async () => {
|
|
@@ -302,7 +303,7 @@ export const resolvers = {
|
|
|
302
303
|
// untouched); creating derives the identity from the doctype's declared
|
|
303
304
|
// primary key when the submitted data carries it, which is how a
|
|
304
305
|
// natural-keyed doctype is identified, and mints one only otherwise.
|
|
305
|
-
// Either way the full record comes back
|
|
306
|
+
// Either way the full record comes back, stating its identity.
|
|
306
307
|
writeData: async (patch: Record<string, unknown>, exists: boolean) => {
|
|
307
308
|
if (exists) {
|
|
308
309
|
if (recordId == null) return {}
|
|
@@ -340,6 +341,15 @@ export const resolvers = {
|
|
|
340
341
|
},
|
|
341
342
|
recordData
|
|
342
343
|
)
|
|
344
|
+
// The record as `stonecropRecord` returns it: the client stores this, never
|
|
345
|
+
// `data`. Keyed by the identity the reply states, since a save may create it.
|
|
346
|
+
const repliedId: unknown =
|
|
347
|
+
outcome.data !== null && typeof outcome.data === 'object'
|
|
348
|
+
? Reflect.get(outcome.data, lookupField)
|
|
349
|
+
: undefined
|
|
350
|
+
const readId = repliedId ?? recordId
|
|
351
|
+
const record = outcome.success && readId != null ? getRecord(d, String(readId), lookupField) : null
|
|
352
|
+
return { ...outcome, record }
|
|
343
353
|
} catch (err) {
|
|
344
354
|
return { success: false, data: null, error: err instanceof Error ? err.message : String(err) }
|
|
345
355
|
}
|
package/templates/schema.graphql
CHANGED
|
@@ -101,6 +101,8 @@ type ActionResult {
|
|
|
101
101
|
success: Boolean!
|
|
102
102
|
data: JSON
|
|
103
103
|
error: String
|
|
104
|
+
"The record as stonecropRecord returns it after the action. Null when the action failed or targets no record."
|
|
105
|
+
record: JSON
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
# ============================================
|