@bg-dev/nuxt-zenstack 0.0.6 → 0.0.7
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/dist/module.mjs +1 -1
- package/dist/runtime/server/routes/realtime.js +1 -1
- package/dist/runtime/server/utils/index.d.ts +2 -1
- package/dist/runtime/server/utils/index.js +6 -1
- package/dist/runtime/server/utils/operations/create.d.ts +1 -0
- package/dist/runtime/server/utils/operations/create.js +6 -3
- package/dist/runtime/server/utils/operations/delete.d.ts +1 -0
- package/dist/runtime/server/utils/operations/delete.js +6 -3
- package/dist/runtime/server/utils/operations/update.d.ts +1 -0
- package/dist/runtime/server/utils/operations/update.js +6 -3
- package/dist/runtime/types/template.d.ts +1 -1
- package/package.json +1 -1
- package/README.md +0 -75
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -5,7 +5,7 @@ export default defineEventHandler(async (event) => {
|
|
|
5
5
|
const eventStream = createEventStream(event);
|
|
6
6
|
const nitroApp = useNitroApp();
|
|
7
7
|
const config = getConfig();
|
|
8
|
-
nitroApp.hooks.hook("zenstack:
|
|
8
|
+
nitroApp.hooks.hook("zenstack:publish", (action, model, items) => {
|
|
9
9
|
if (!config.expose[model]?.find((permission) => permission === "read")) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
@@ -3,7 +3,7 @@ import { update } from './operations/update.js';
|
|
|
3
3
|
import { findUnique } from './operations/findUnique.js';
|
|
4
4
|
import { findMany } from './operations/findMany.js';
|
|
5
5
|
import { create } from './operations/create.js';
|
|
6
|
-
import type { $Zclient } from '#build/types/nuxt-zenstack';
|
|
6
|
+
import type { $Zclient, $Zmodel } from '#build/types/nuxt-zenstack';
|
|
7
7
|
import type { H3Event } from 'h3';
|
|
8
8
|
export declare function useZenstack(): {
|
|
9
9
|
delete: typeof _delete;
|
|
@@ -12,4 +12,5 @@ export declare function useZenstack(): {
|
|
|
12
12
|
findMany: typeof findMany;
|
|
13
13
|
create: typeof create;
|
|
14
14
|
setSessionClient: (event: H3Event, client: $Zclient) => void;
|
|
15
|
+
publish: (action: "create" | "update" | "delete", model: $Zmodel, items: Record<string, unknown>[]) => Promise<any>;
|
|
15
16
|
};
|
|
@@ -3,6 +3,7 @@ import { update } from "./operations/update.js";
|
|
|
3
3
|
import { findUnique } from "./operations/findUnique.js";
|
|
4
4
|
import { findMany } from "./operations/findMany.js";
|
|
5
5
|
import { create } from "./operations/create.js";
|
|
6
|
+
import { useNitroApp } from "nitropack/runtime";
|
|
6
7
|
export function useZenstack() {
|
|
7
8
|
function setSessionClient(event, client) {
|
|
8
9
|
if (event.context.zenstack)
|
|
@@ -10,5 +11,9 @@ export function useZenstack() {
|
|
|
10
11
|
else
|
|
11
12
|
event.context.zenstack = { client };
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
function publish(action, model, items) {
|
|
15
|
+
const nitroApp = useNitroApp();
|
|
16
|
+
return nitroApp.hooks.callHook("zenstack:publish", action, model, items);
|
|
17
|
+
}
|
|
18
|
+
return { delete: _delete, update, findUnique, findMany, create, setSessionClient, publish };
|
|
14
19
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getModelOperations, createError } from "./common.js";
|
|
2
2
|
import { sanitizeCreateData } from "../helpers.js";
|
|
3
|
-
import {
|
|
3
|
+
import { useZenstack } from "../index.js";
|
|
4
4
|
export async function create(args) {
|
|
5
5
|
const operations = getModelOperations(args.client, args.model);
|
|
6
6
|
const sanitizedData = sanitizeCreateData(args.model, args.data);
|
|
@@ -9,7 +9,10 @@ export async function create(args) {
|
|
|
9
9
|
}).catch((err) => {
|
|
10
10
|
throw createError(err);
|
|
11
11
|
});
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
args.publish ??= true;
|
|
13
|
+
if (args.publish) {
|
|
14
|
+
const zenstack = useZenstack();
|
|
15
|
+
await zenstack.publish("create", args.model, [data]);
|
|
16
|
+
}
|
|
14
17
|
return { data };
|
|
15
18
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { useZenstack } from "../index.js";
|
|
1
2
|
import { getModelOperations, createError } from "./common.js";
|
|
2
|
-
import { useNitroApp } from "nitropack/runtime";
|
|
3
3
|
export async function _delete(args) {
|
|
4
4
|
const operations = getModelOperations(args.client, args.model);
|
|
5
5
|
const data = await operations.delete({
|
|
@@ -10,7 +10,10 @@ export async function _delete(args) {
|
|
|
10
10
|
}).catch((err) => {
|
|
11
11
|
throw createError(err);
|
|
12
12
|
});
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
args.publish ??= true;
|
|
14
|
+
if (args.publish) {
|
|
15
|
+
const zenstack = useZenstack();
|
|
16
|
+
await zenstack.publish("delete", args.model, [data]);
|
|
17
|
+
}
|
|
15
18
|
return { data };
|
|
16
19
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getModelOperations, createError } from "./common.js";
|
|
2
2
|
import { sanitizeUpdateData } from "../helpers.js";
|
|
3
|
-
import {
|
|
3
|
+
import { useZenstack } from "../index.js";
|
|
4
4
|
export async function update(args) {
|
|
5
5
|
const operations = getModelOperations(args.client, args.model);
|
|
6
6
|
const sanitizedData = sanitizeUpdateData(args.model, args.data);
|
|
@@ -13,7 +13,10 @@ export async function update(args) {
|
|
|
13
13
|
}).catch((err) => {
|
|
14
14
|
throw createError(err);
|
|
15
15
|
});
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
args.publish ??= true;
|
|
17
|
+
if (args.publish) {
|
|
18
|
+
const zenstack = useZenstack();
|
|
19
|
+
await zenstack.publish("update", args.model, [data]);
|
|
20
|
+
}
|
|
18
21
|
return { data };
|
|
19
22
|
}
|
|
@@ -47,6 +47,6 @@ type RealtimeData = {
|
|
|
47
47
|
|
|
48
48
|
declare module 'nitropack' {
|
|
49
49
|
interface NitroRuntimeHooks {
|
|
50
|
-
'zenstack:
|
|
50
|
+
'zenstack:publish': (action: 'create' | 'update' | 'delete', model: $Zmodel, items: Record<string, unknown>[]) => Promise<void> | void
|
|
51
51
|
}
|
|
52
52
|
}
|
package/package.json
CHANGED
package/README.md
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# Nuxt ZenStack
|
|
2
|
-
|
|
3
|
-
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
-
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
-
[![License][license-src]][license-href]
|
|
6
|
-
[![Nuxt][nuxt-src]][nuxt-href]
|
|
7
|
-
|
|
8
|
-
ZenStack integration for Nuxt for doing amazing things.
|
|
9
|
-
|
|
10
|
-
- [✨ Release Notes](/CHANGELOG.md)
|
|
11
|
-
<!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/@bg-dev/nuxt-zenstack?file=playground%2Fapp.vue) -->
|
|
12
|
-
<!-- - [📖 Documentation](https://example.com) -->
|
|
13
|
-
|
|
14
|
-
## Features
|
|
15
|
-
|
|
16
|
-
<!-- Highlight some of the features your module provide here -->
|
|
17
|
-
- ⛰ Foo
|
|
18
|
-
- 🚠 Bar
|
|
19
|
-
- 🌲 Baz
|
|
20
|
-
|
|
21
|
-
## Quick Setup
|
|
22
|
-
|
|
23
|
-
Install the module to your Nuxt application with one command:
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
npx nuxt module add @bg-dev/nuxt-zenstack
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
That's it! You can now use Nuxt ZenStack in your Nuxt app ✨
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
## Contribution
|
|
33
|
-
|
|
34
|
-
<details>
|
|
35
|
-
<summary>Local development</summary>
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
# Install dependencies
|
|
39
|
-
npm install
|
|
40
|
-
|
|
41
|
-
# Generate type stubs
|
|
42
|
-
npm run dev:prepare
|
|
43
|
-
|
|
44
|
-
# Develop with the playground
|
|
45
|
-
npm run dev
|
|
46
|
-
|
|
47
|
-
# Build the playground
|
|
48
|
-
npm run dev:build
|
|
49
|
-
|
|
50
|
-
# Run ESLint
|
|
51
|
-
npm run lint
|
|
52
|
-
|
|
53
|
-
# Run Vitest
|
|
54
|
-
npm run test
|
|
55
|
-
npm run test:watch
|
|
56
|
-
|
|
57
|
-
# Release new version
|
|
58
|
-
npm run release
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
</details>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
<!-- Badges -->
|
|
65
|
-
[npm-version-src]: https://img.shields.io/npm/v/@bg-dev/nuxt-zenstack/latest.svg?style=flat&colorA=020420&colorB=00DC82
|
|
66
|
-
[npm-version-href]: https://npmjs.com/package/@bg-dev/nuxt-zenstack
|
|
67
|
-
|
|
68
|
-
[npm-downloads-src]: https://img.shields.io/npm/dm/@bg-dev/nuxt-zenstack.svg?style=flat&colorA=020420&colorB=00DC82
|
|
69
|
-
[npm-downloads-href]: https://npm.chart.dev/@bg-dev/nuxt-zenstack
|
|
70
|
-
|
|
71
|
-
[license-src]: https://img.shields.io/npm/l/@bg-dev/nuxt-zenstack.svg?style=flat&colorA=020420&colorB=00DC82
|
|
72
|
-
[license-href]: https://npmjs.com/package/@bg-dev/nuxt-zenstack
|
|
73
|
-
|
|
74
|
-
[nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt
|
|
75
|
-
[nuxt-href]: https://nuxt.com
|