@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bg-dev/nuxt-zenstack",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "configKey": "zenstack",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
package/dist/module.mjs CHANGED
@@ -3,7 +3,7 @@ import { joinURL } from 'ufo';
3
3
  import { defu } from 'defu';
4
4
 
5
5
  const name = "@bg-dev/nuxt-zenstack";
6
- const version = "0.0.6";
6
+ const version = "0.0.7";
7
7
 
8
8
  const module$1 = defineNuxtModule({
9
9
  meta: {
@@ -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:after_mutation", (action, model, items) => {
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
- return { delete: _delete, update, findUnique, findMany, create, setSessionClient };
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
  }
@@ -3,6 +3,7 @@ type CreateArgs<Zmodel extends $Zmodel> = {
3
3
  client: $Zclient;
4
4
  model: Zmodel;
5
5
  data: $ZcreateData<Zmodel>;
6
+ publish?: boolean;
6
7
  };
7
8
  export declare function create<Zmodel extends $Zmodel>(args: CreateArgs<Zmodel>): Promise<{
8
9
  data: $Zitem<Zmodel>;
@@ -1,6 +1,6 @@
1
1
  import { getModelOperations, createError } from "./common.js";
2
2
  import { sanitizeCreateData } from "../helpers.js";
3
- import { useNitroApp } from "nitropack/runtime";
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
- const nitroApp = useNitroApp();
13
- await nitroApp.hooks.callHook("zenstack:after_mutation", "create", args.model, [data]);
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
  }
@@ -3,6 +3,7 @@ type DeleteArgs<Zmodel extends $Zmodel> = {
3
3
  client: $Zclient;
4
4
  model: Zmodel;
5
5
  id: $Zid<Zmodel>;
6
+ publish?: boolean;
6
7
  };
7
8
  export declare function _delete<Zmodel extends $Zmodel>(args: DeleteArgs<Zmodel>): Promise<{
8
9
  data: $Zitem<Zmodel>;
@@ -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
- const nitroApp = useNitroApp();
14
- await nitroApp.hooks.callHook("zenstack:after_mutation", "delete", args.model, [data]);
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
  }
@@ -4,6 +4,7 @@ type UpdateArgs<Zmodel extends $Zmodel> = {
4
4
  model: Zmodel;
5
5
  id: $Zid<Zmodel>;
6
6
  data: $ZupdateData<Zmodel>;
7
+ publish?: boolean;
7
8
  };
8
9
  export declare function update<Zmodel extends $Zmodel>(args: UpdateArgs<Zmodel>): Promise<{
9
10
  data: $Zitem<Zmodel>;
@@ -1,6 +1,6 @@
1
1
  import { getModelOperations, createError } from "./common.js";
2
2
  import { sanitizeUpdateData } from "../helpers.js";
3
- import { useNitroApp } from "nitropack/runtime";
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
- const nitroApp = useNitroApp();
17
- await nitroApp.hooks.callHook("zenstack:after_mutation", "update", args.model, [data]);
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:after_mutation': (action: 'create' | 'update' | 'delete', model: $Zmodel, items: Record<string, unknown>[]) => Promise<void> | void
50
+ 'zenstack:publish': (action: 'create' | 'update' | 'delete', model: $Zmodel, items: Record<string, unknown>[]) => Promise<void> | void
51
51
  }
52
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bg-dev/nuxt-zenstack",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "ZenStack integration for Nuxt",
5
5
  "repository": {
6
6
  "url": "https://github.com/becem-gharbi/nuxt-zenstack"
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
- - [✨ &nbsp;Release Notes](/CHANGELOG.md)
11
- <!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/@bg-dev/nuxt-zenstack?file=playground%2Fapp.vue) -->
12
- <!-- - [📖 &nbsp;Documentation](https://example.com) -->
13
-
14
- ## Features
15
-
16
- <!-- Highlight some of the features your module provide here -->
17
- - ⛰ &nbsp;Foo
18
- - 🚠 &nbsp;Bar
19
- - 🌲 &nbsp;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