@bg-dev/nuxt-zenstack 0.0.5 → 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.d.mts +2 -6
- package/dist/module.json +1 -1
- package/dist/module.mjs +8 -57
- package/dist/runtime/composables/common.d.ts +2 -4
- package/dist/runtime/composables/useZenstackCreate/index.d.ts +1 -1
- package/dist/runtime/composables/useZenstackDelete/index.d.ts +1 -1
- package/dist/runtime/composables/useZenstackRead/index.d.ts +1 -1
- package/dist/runtime/composables/useZenstackReadMany/index.d.ts +1 -1
- package/dist/runtime/composables/useZenstackReadMany/index.js +1 -1
- package/dist/runtime/composables/useZenstackUpdate/index.d.ts +1 -1
- package/dist/runtime/server/api/models/[model]/[id].delete.js +7 -2
- package/dist/runtime/server/api/models/[model]/[id].get.js +7 -2
- package/dist/runtime/server/api/models/[model]/[id].patch.js +7 -2
- package/dist/runtime/server/api/models/[model]/index.get.js +7 -2
- package/dist/runtime/server/api/models/[model]/index.post.js +7 -2
- package/dist/runtime/server/routes/realtime.js +6 -1
- package/dist/runtime/server/utils/helpers.d.ts +2 -0
- package/dist/runtime/server/utils/helpers.js +5 -0
- 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/index.d.ts +12 -0
- package/dist/runtime/types/index.js +0 -0
- package/dist/runtime/types/template.d.ts +52 -0
- package/package.json +3 -3
- package/README.md +0 -75
package/dist/module.d.mts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import {
|
|
2
|
+
import { PublicModuleOptions, PrivateModuleOptions } from '../dist/runtime/types/index.js';
|
|
3
3
|
|
|
4
|
-
interface ModuleOptions {
|
|
5
|
-
apiPath: string;
|
|
6
|
-
fetchPolicy: FetchPolicy;
|
|
7
|
-
realtime: boolean;
|
|
8
|
-
baseUrl: string;
|
|
4
|
+
interface ModuleOptions extends PublicModuleOptions, PrivateModuleOptions {
|
|
9
5
|
}
|
|
10
6
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
11
7
|
|
package/dist/module.json
CHANGED
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
|
+
const version = "0.0.7";
|
|
7
7
|
|
|
8
8
|
const module$1 = defineNuxtModule({
|
|
9
9
|
meta: {
|
|
@@ -16,7 +16,8 @@ const module$1 = defineNuxtModule({
|
|
|
16
16
|
apiPath: "/api/_zenstack",
|
|
17
17
|
fetchPolicy: "cache-first",
|
|
18
18
|
realtime: false,
|
|
19
|
-
baseUrl: "http://localhost:3000"
|
|
19
|
+
baseUrl: "http://localhost:3000",
|
|
20
|
+
expose: {}
|
|
20
21
|
},
|
|
21
22
|
setup(_options, _nuxt) {
|
|
22
23
|
_nuxt.options.runtimeConfig.public = defu(_nuxt.options.runtimeConfig.public, {
|
|
@@ -27,6 +28,10 @@ const module$1 = defineNuxtModule({
|
|
|
27
28
|
baseUrl: _options.baseUrl
|
|
28
29
|
}
|
|
29
30
|
});
|
|
31
|
+
_nuxt.options.runtimeConfig.zenstack = {
|
|
32
|
+
expose: _options.expose,
|
|
33
|
+
..._nuxt.options.runtimeConfig.zenstack ?? {}
|
|
34
|
+
};
|
|
30
35
|
const resolver = createResolver(import.meta.url);
|
|
31
36
|
addTemplate({
|
|
32
37
|
write: true,
|
|
@@ -43,61 +48,7 @@ export { schema as zenstackSchema } from '~~/zenstack/schema'
|
|
|
43
48
|
});
|
|
44
49
|
addTypeTemplate({
|
|
45
50
|
filename: "types/nuxt-zenstack.d.ts",
|
|
46
|
-
|
|
47
|
-
import type { ClientContract, ModelOperations, ModelResult, IncludeInput, WhereInput, FindManyArgs, SimplifiedPlainResult, SelectIncludeOmit, QueryOptions, CreateArgs, UpdateArgs } from '@zenstackhq/orm'
|
|
48
|
-
import type { SchemaType } from '~~/zenstack/schema'
|
|
49
|
-
import type { ModelDef } from '@zenstackhq/orm/schema'
|
|
50
|
-
import type { H3Error } from 'h3'
|
|
51
|
-
import { ORMError, RejectedByPolicyReason, ORMErrorReason } from '@zenstackhq/orm'
|
|
52
|
-
|
|
53
|
-
type ItemGetPayload<Zmodel extends $Zmodel, Args extends SelectIncludeOmit<SchemaType, Zmodel, true>, Options extends QueryOptions<SchemaType> = QueryOptions<SchemaType>> = SimplifiedPlainResult<SchemaType, Zmodel, Args, Options>
|
|
54
|
-
|
|
55
|
-
export type $Zschema = SchemaType
|
|
56
|
-
export type $Zclient = ClientContract<SchemaType>
|
|
57
|
-
export type $Zmodel = keyof SchemaType['models']
|
|
58
|
-
export type $Zdef = ModelDef
|
|
59
|
-
export type $Zoperations<Zmodel extends $Zmodel> = ModelOperations<SchemaType, Zmodel>
|
|
60
|
-
export type $Zid<Zmodel extends $Zmodel> = ModelResult<SchemaType, Zmodel> extends { id: infer Id } ? Id : never
|
|
61
|
-
export type $Zinclude<Zmodel extends $Zmodel> = IncludeInput<SchemaType, Zmodel> | undefined
|
|
62
|
-
export type $Zitem<Zmodel extends $Zmodel, Zinclude extends $Zinclude = undefined> = ItemGetPayload<Zmodel, { include: Zinclude }>
|
|
63
|
-
export type $Zwhere<Zmodel extends $Zmodel> = WhereInput<SchemaType, Zmodel> | undefined
|
|
64
|
-
export type $ZorderBy<Zmodel extends $Zmodel> = FindManyArgs<SchemaType, Zmodel>['orderBy'] | undefined
|
|
65
|
-
|
|
66
|
-
type NonRelationalFields<Zmodel extends $Zmodel> = keyof $Zitem<Zmodel>
|
|
67
|
-
type CreateData<Zmodel extends $Zmodel> = CreateArgs<SchemaType, Zmodel>['data']
|
|
68
|
-
type UpdateData<Zmodel extends $Zmodel> = UpdateArgs<SchemaType, Zmodel>['data']
|
|
69
|
-
|
|
70
|
-
export type $ZcreateData<Zmodel extends $Zmodel> = Pick<CreateData<Zmodel>, NonRelationalFields<Zmodel>>
|
|
71
|
-
export type $ZupdateData<Zmodel extends $Zmodel> = Pick<UpdateData<Zmodel>, NonRelationalFields<Zmodel>>
|
|
72
|
-
export type $ZormError = ORMError
|
|
73
|
-
export type $Zerror = H3Error<{
|
|
74
|
-
ormErrorReason: ORMErrorReason
|
|
75
|
-
dbErrorCode?: unknown
|
|
76
|
-
dbErrorMessage?: string
|
|
77
|
-
model?: string
|
|
78
|
-
rejectedByPolicyReason?: RejectedByPolicyReason
|
|
79
|
-
}>
|
|
80
|
-
|
|
81
|
-
declare module 'h3' {
|
|
82
|
-
interface H3EventContext {
|
|
83
|
-
zenstack: {
|
|
84
|
-
client: ClientContract<SchemaType>
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
type RealtimeData = {
|
|
90
|
-
action: 'create' | 'update' | 'delete'
|
|
91
|
-
model: $Zmodel
|
|
92
|
-
ids: Array<number | string>
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
declare module 'nitropack' {
|
|
96
|
-
interface NitroRuntimeHooks {
|
|
97
|
-
'zenstack:after_mutation': (action: 'create' | 'update' | 'delete', model: $Zmodel, items: Record<string, unknown>[]) => Promise<void> | void
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
`
|
|
51
|
+
src: resolver.resolve("./runtime/types/template.d.ts")
|
|
101
52
|
});
|
|
102
53
|
addServerHandler({
|
|
103
54
|
route: joinURL(_options.apiPath, "models/:model"),
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export
|
|
3
|
-
export type FetchPolicy = 'cache-first' | 'fetch-only' | 'cache-only' | 'cache-and-fetch';
|
|
4
|
-
export declare function getConfig(): ModuleOptions;
|
|
1
|
+
import type { PublicModuleOptions } from '../types/index.js';
|
|
2
|
+
export declare function getConfig(): PublicModuleOptions;
|
|
5
3
|
/**
|
|
6
4
|
* @param instance a custom fetch method created by `$fetch.create`
|
|
7
5
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { $Zmodel, $Zitem, $ZcreateData, $Zerror } from '#build/types/nuxt-zenstack';
|
|
2
|
-
import type { Status } from '
|
|
2
|
+
import type { Status } from '../../types/index.js';
|
|
3
3
|
import { type Ref } from '#imports';
|
|
4
4
|
export declare function useZenstackCreate<Zmodel extends $Zmodel, Zitem extends $Zitem<Zmodel>>(model: Zmodel): {
|
|
5
5
|
data: Ref<Zitem | null>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { $Zmodel, $Zitem, $Zid, $Zerror } from '#build/types/nuxt-zenstack';
|
|
2
|
-
import type { Status } from '
|
|
2
|
+
import type { Status } from '../../types/index.js';
|
|
3
3
|
import { type Ref } from '#imports';
|
|
4
4
|
export declare function useZenstackDelete<Zmodel extends $Zmodel, Zitem extends $Zitem<Zmodel>>(model: Zmodel): {
|
|
5
5
|
data: Ref<Zitem | null>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { $Zmodel, $Zitem, $Zid, $Zinclude, $Zerror } from '#build/types/nuxt-zenstack';
|
|
2
|
-
import type { Status, FetchPolicy } from '
|
|
2
|
+
import type { Status, FetchPolicy } from '../../types/index.js';
|
|
3
3
|
import type { Ref } from '#imports';
|
|
4
4
|
type Options<Zinclude> = {
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { $Zmodel, $Zitem, $Zinclude, $Zwhere, $ZorderBy, $Zerror } from '#build/types/nuxt-zenstack';
|
|
2
|
-
import type { Status, FetchPolicy } from '
|
|
2
|
+
import type { Status, FetchPolicy } from '../../types/index.js';
|
|
3
3
|
import type { MaybeRefOrGetter, Ref } from '#imports';
|
|
4
4
|
type Options<Zinclude, Zwhere, ZorderBy> = {
|
|
5
5
|
/**
|
|
@@ -81,7 +81,7 @@ export async function useZenstackReadMany(model, opts = {}) {
|
|
|
81
81
|
} catch (err) {
|
|
82
82
|
error.value = err.data;
|
|
83
83
|
status.value = "error";
|
|
84
|
-
canFetchMore.value =
|
|
84
|
+
canFetchMore.value = false;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
return { data, error, status, canFetchMore, refetch };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { $Zmodel, $Zitem, $ZupdateData, $Zid, $Zerror } from '#build/types/nuxt-zenstack';
|
|
2
|
-
import type { Status } from '
|
|
2
|
+
import type { Status } from '../../types/index.js';
|
|
3
3
|
import type { Ref } from '#imports';
|
|
4
4
|
export declare function useZenstackUpdate<Zmodel extends $Zmodel, Zitem extends $Zitem<Zmodel>>(model: Zmodel): {
|
|
5
5
|
data: Ref<Zitem | null>;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { defineEventHandler } from "h3";
|
|
1
|
+
import { defineEventHandler, createError } from "h3";
|
|
2
2
|
import { parseModel, parseId, parseClient } from "../../../utils/parsers.js";
|
|
3
3
|
import { useZenstack } from "../../../utils/index.js";
|
|
4
|
+
import { getConfig } from "../../../utils/helpers.js";
|
|
4
5
|
export default defineEventHandler(async (event) => {
|
|
5
|
-
const client = parseClient(event);
|
|
6
6
|
const model = parseModel(event);
|
|
7
|
+
const config = getConfig();
|
|
8
|
+
if (!config.expose[model]?.find((permission) => permission === "delete")) {
|
|
9
|
+
throw createError({ statusCode: 403, statusMessage: "Forbidden" });
|
|
10
|
+
}
|
|
11
|
+
const client = parseClient(event);
|
|
7
12
|
const id = parseId(event, model);
|
|
8
13
|
const zenstack = useZenstack();
|
|
9
14
|
return zenstack.delete({ client, model, id });
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { parseModel, parseId, parseReadArgs, parseClient } from "../../../utils/parsers.js";
|
|
2
|
-
import { defineEventHandler } from "h3";
|
|
2
|
+
import { defineEventHandler, createError } from "h3";
|
|
3
3
|
import { useZenstack } from "../../../utils/index.js";
|
|
4
|
+
import { getConfig } from "../../../utils/helpers.js";
|
|
4
5
|
export default defineEventHandler(async (event) => {
|
|
5
|
-
const client = parseClient(event);
|
|
6
6
|
const model = parseModel(event);
|
|
7
|
+
const config = getConfig();
|
|
8
|
+
if (!config.expose[model]?.find((permission) => permission === "read")) {
|
|
9
|
+
throw createError({ statusCode: 403, statusMessage: "Forbidden" });
|
|
10
|
+
}
|
|
11
|
+
const client = parseClient(event);
|
|
7
12
|
const id = parseId(event, model);
|
|
8
13
|
const readArgs = parseReadArgs(event, model);
|
|
9
14
|
const zenstack = useZenstack();
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { parseModel, parseId, parseUpdateArgs, parseClient } from "../../../utils/parsers.js";
|
|
2
|
-
import { defineEventHandler } from "h3";
|
|
2
|
+
import { defineEventHandler, createError } from "h3";
|
|
3
3
|
import { useZenstack } from "../../../utils/index.js";
|
|
4
|
+
import { getConfig } from "../../../utils/helpers.js";
|
|
4
5
|
export default defineEventHandler(async (event) => {
|
|
5
|
-
const client = parseClient(event);
|
|
6
6
|
const model = parseModel(event);
|
|
7
|
+
const config = getConfig();
|
|
8
|
+
if (!config.expose[model]?.find((permission) => permission === "update")) {
|
|
9
|
+
throw createError({ statusCode: 403, statusMessage: "Forbidden" });
|
|
10
|
+
}
|
|
11
|
+
const client = parseClient(event);
|
|
7
12
|
const id = parseId(event, model);
|
|
8
13
|
const updateArgs = await parseUpdateArgs(event, model);
|
|
9
14
|
const zenstack = useZenstack();
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { parseClient, parseModel, parseReadArgs } from "../../../utils/parsers.js";
|
|
2
|
-
import { defineEventHandler } from "h3";
|
|
2
|
+
import { defineEventHandler, createError } from "h3";
|
|
3
3
|
import { useZenstack } from "../../../utils/index.js";
|
|
4
|
+
import { getConfig } from "../../../utils/helpers.js";
|
|
4
5
|
export default defineEventHandler(async (event) => {
|
|
5
|
-
const client = parseClient(event);
|
|
6
6
|
const model = parseModel(event);
|
|
7
|
+
const config = getConfig();
|
|
8
|
+
if (!config.expose[model]?.find((permission) => permission === "read")) {
|
|
9
|
+
throw createError({ statusCode: 403, statusMessage: "Forbidden" });
|
|
10
|
+
}
|
|
11
|
+
const client = parseClient(event);
|
|
7
12
|
const readArgs = parseReadArgs(event, model);
|
|
8
13
|
const zenstack = useZenstack();
|
|
9
14
|
return zenstack.findMany({
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { parseModel, parseCreateArgs, parseClient } from "../../../utils/parsers.js";
|
|
2
|
-
import { defineEventHandler } from "h3";
|
|
2
|
+
import { defineEventHandler, createError } from "h3";
|
|
3
3
|
import { useZenstack } from "../../../utils/index.js";
|
|
4
|
+
import { getConfig } from "../../../utils/helpers.js";
|
|
4
5
|
export default defineEventHandler(async (event) => {
|
|
5
|
-
const client = parseClient(event);
|
|
6
6
|
const model = parseModel(event);
|
|
7
|
+
const config = getConfig();
|
|
8
|
+
if (!config.expose[model]?.find((permission) => permission === "create")) {
|
|
9
|
+
throw createError({ statusCode: 403, statusMessage: "Forbidden" });
|
|
10
|
+
}
|
|
11
|
+
const client = parseClient(event);
|
|
7
12
|
const createArgs = await parseCreateArgs(event, model);
|
|
8
13
|
const zenstack = useZenstack();
|
|
9
14
|
return zenstack.create({ client, model, data: createArgs.data });
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { defineEventHandler, createEventStream } from "h3";
|
|
2
2
|
import { useNitroApp } from "nitropack/runtime";
|
|
3
|
+
import { getConfig } from "../utils/helpers.js";
|
|
3
4
|
export default defineEventHandler(async (event) => {
|
|
4
5
|
const eventStream = createEventStream(event);
|
|
5
6
|
const nitroApp = useNitroApp();
|
|
6
|
-
|
|
7
|
+
const config = getConfig();
|
|
8
|
+
nitroApp.hooks.hook("zenstack:publish", (action, model, items) => {
|
|
9
|
+
if (!config.expose[model]?.find((permission) => permission === "read")) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
7
12
|
const message = {
|
|
8
13
|
model,
|
|
9
14
|
action,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { $Zmodel, $Zdef, $ZcreateData, $ZupdateData } from '#build/types/nuxt-zenstack';
|
|
2
|
+
import type { PrivateModuleOptions } from '../../types/index.js';
|
|
2
3
|
export declare function getModelDef(model: $Zmodel): $Zdef;
|
|
3
4
|
export declare function isIdString(model: $Zmodel): boolean;
|
|
4
5
|
export declare function getModels(): $Zmodel[];
|
|
5
6
|
export declare function isValidModel(model: $Zmodel): boolean;
|
|
6
7
|
export declare function sanitizeCreateData<Zmodel extends $Zmodel>(model: Zmodel, data: $ZcreateData<Zmodel>): $ZcreateData<Zmodel>;
|
|
7
8
|
export declare function sanitizeUpdateData<Zmodel extends $Zmodel>(model: Zmodel, data: $ZupdateData<Zmodel>): $ZupdateData<Zmodel>;
|
|
9
|
+
export declare function getConfig(): PrivateModuleOptions;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { zenstackSchema } from "nuxt-zenstack-server.mjs";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
3
|
export function getModelDef(model) {
|
|
3
4
|
return zenstackSchema.models[model];
|
|
4
5
|
}
|
|
@@ -32,3 +33,7 @@ export function sanitizeUpdateData(model, data) {
|
|
|
32
33
|
});
|
|
33
34
|
return data;
|
|
34
35
|
}
|
|
36
|
+
export function getConfig() {
|
|
37
|
+
const config = useRuntimeConfig();
|
|
38
|
+
return config.zenstack;
|
|
39
|
+
}
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { $Zmodel } from '#build/types/nuxt-zenstack';
|
|
2
|
+
export type Status = 'idle' | 'pending' | 'success' | 'error';
|
|
3
|
+
export type FetchPolicy = 'cache-first' | 'fetch-only' | 'cache-only' | 'cache-and-fetch';
|
|
4
|
+
export interface PublicModuleOptions {
|
|
5
|
+
apiPath: string;
|
|
6
|
+
fetchPolicy: FetchPolicy;
|
|
7
|
+
realtime: boolean;
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
}
|
|
10
|
+
export interface PrivateModuleOptions {
|
|
11
|
+
expose: Partial<Record<$Zmodel, Array<'create' | 'read' | 'update' | 'delete'>>>;
|
|
12
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ClientContract, ModelOperations, ModelResult, IncludeInput, WhereInput, FindManyArgs, SimplifiedPlainResult, SelectIncludeOmit, QueryOptions, CreateArgs, UpdateArgs, ORMError, RejectedByPolicyReason, ORMErrorReason } from '@zenstackhq/orm'
|
|
2
|
+
import type { SchemaType } from '~~/zenstack/schema'
|
|
3
|
+
import type { ModelDef } from '@zenstackhq/orm/schema'
|
|
4
|
+
import type { H3Error } from 'h3'
|
|
5
|
+
|
|
6
|
+
type ItemGetPayload<Zmodel extends $Zmodel, Args extends SelectIncludeOmit<SchemaType, Zmodel, true>, Options extends QueryOptions<SchemaType> = QueryOptions<SchemaType>> = SimplifiedPlainResult<SchemaType, Zmodel, Args, Options>
|
|
7
|
+
|
|
8
|
+
export type $Zschema = SchemaType
|
|
9
|
+
export type $Zclient = ClientContract<SchemaType>
|
|
10
|
+
export type $Zmodel = keyof SchemaType['models']
|
|
11
|
+
export type $Zdef = ModelDef
|
|
12
|
+
export type $Zoperations<Zmodel extends $Zmodel> = ModelOperations<SchemaType, Zmodel>
|
|
13
|
+
export type $Zid<Zmodel extends $Zmodel> = ModelResult<SchemaType, Zmodel> extends { id: infer Id } ? Id : never
|
|
14
|
+
export type $Zinclude<Zmodel extends $Zmodel> = IncludeInput<SchemaType, Zmodel> | undefined
|
|
15
|
+
export type $Zitem<Zmodel extends $Zmodel, Zinclude extends $Zinclude = undefined> = ItemGetPayload<Zmodel, { include: Zinclude }>
|
|
16
|
+
export type $Zwhere<Zmodel extends $Zmodel> = WhereInput<SchemaType, Zmodel> | undefined
|
|
17
|
+
export type $ZorderBy<Zmodel extends $Zmodel> = FindManyArgs<SchemaType, Zmodel>['orderBy'] | undefined
|
|
18
|
+
|
|
19
|
+
type NonRelationalFields<Zmodel extends $Zmodel> = keyof $Zitem<Zmodel>
|
|
20
|
+
type CreateData<Zmodel extends $Zmodel> = CreateArgs<SchemaType, Zmodel>['data']
|
|
21
|
+
type UpdateData<Zmodel extends $Zmodel> = UpdateArgs<SchemaType, Zmodel>['data']
|
|
22
|
+
|
|
23
|
+
export type $ZcreateData<Zmodel extends $Zmodel> = Pick<CreateData<Zmodel>, NonRelationalFields<Zmodel>>
|
|
24
|
+
export type $ZupdateData<Zmodel extends $Zmodel> = Pick<UpdateData<Zmodel>, NonRelationalFields<Zmodel>>
|
|
25
|
+
export type $ZormError = ORMError
|
|
26
|
+
export type $Zerror = H3Error<{
|
|
27
|
+
ormErrorReason: ORMErrorReason
|
|
28
|
+
dbErrorCode?: unknown
|
|
29
|
+
dbErrorMessage?: string
|
|
30
|
+
model?: string
|
|
31
|
+
rejectedByPolicyReason?: RejectedByPolicyReason
|
|
32
|
+
}>
|
|
33
|
+
|
|
34
|
+
declare module 'h3' {
|
|
35
|
+
interface H3EventContext {
|
|
36
|
+
zenstack: {
|
|
37
|
+
client: ClientContract<SchemaType>
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type RealtimeData = {
|
|
43
|
+
action: 'create' | 'update' | 'delete'
|
|
44
|
+
model: $Zmodel
|
|
45
|
+
ids: Array<number | string>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare module 'nitropack' {
|
|
49
|
+
interface NitroRuntimeHooks {
|
|
50
|
+
'zenstack:publish': (action: 'create' | 'update' | 'delete', model: $Zmodel, items: Record<string, unknown>[]) => Promise<void> | void
|
|
51
|
+
}
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bg-dev/nuxt-zenstack",
|
|
3
|
-
"version": "0.0.
|
|
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"
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"dev:db:push": "cd playground && zen db push",
|
|
43
43
|
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
44
44
|
"lint": "eslint .",
|
|
45
|
-
"test": "vitest run",
|
|
45
|
+
"test": "vitest run --no-file-parallelism",
|
|
46
46
|
"test:watch": "vitest watch",
|
|
47
47
|
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
|
|
48
48
|
"test:db:push": "cd test/fixtures/basic && zen db push",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"eslint": "^9.39.2",
|
|
74
74
|
"libsql": "^0.5.22",
|
|
75
75
|
"nuxt": "^4.2.2",
|
|
76
|
-
"playwright-core": "^1.
|
|
76
|
+
"playwright-core": "^1.58.0",
|
|
77
77
|
"typescript": "~5.9.3",
|
|
78
78
|
"vitest": "^4.0.17",
|
|
79
79
|
"vue-tsc": "^3.2.2"
|
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
|