@bg-dev/nuxt-zenstack 0.0.2 → 0.0.4
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 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +29 -14
- package/dist/runtime/composables/common.d.ts +6 -8
- package/dist/runtime/composables/common.js +7 -0
- package/dist/runtime/composables/index.d.ts +1 -0
- package/dist/runtime/composables/index.js +1 -0
- package/dist/runtime/composables/useZenstackCreate/index.d.ts +3 -3
- package/dist/runtime/composables/useZenstackCreate/index.js +10 -8
- package/dist/runtime/composables/useZenstackDelete/index.d.ts +3 -3
- package/dist/runtime/composables/useZenstackDelete/index.js +9 -4
- package/dist/runtime/composables/useZenstackRead/index.d.ts +7 -7
- package/dist/runtime/composables/useZenstackRead/index.js +38 -29
- package/dist/runtime/composables/useZenstackReadMany/index.d.ts +9 -8
- package/dist/runtime/composables/useZenstackReadMany/index.js +54 -34
- package/dist/runtime/composables/useZenstackReadMany/orderBy.d.ts +5 -0
- package/dist/runtime/composables/useZenstackReadMany/orderBy.js +25 -0
- package/dist/runtime/composables/useZenstackReadMany/where.d.ts +2 -0
- package/dist/runtime/composables/useZenstackReadMany/where.js +235 -0
- package/dist/runtime/composables/useZenstackStore/helpers.js +4 -4
- package/dist/runtime/composables/useZenstackStore/index.d.ts +34 -2
- package/dist/runtime/composables/useZenstackStore/index.js +27 -6
- package/dist/runtime/composables/useZenstackStore/normalization.d.ts +16 -3
- package/dist/runtime/composables/useZenstackStore/normalization.js +16 -3
- package/dist/runtime/composables/useZenstackUpdate/index.d.ts +2 -2
- package/dist/runtime/composables/useZenstackUpdate/index.js +10 -8
- package/dist/runtime/server/api/models/[model]/[id].delete.js +4 -1
- package/dist/runtime/server/api/models/[model]/[id].get.js +4 -1
- package/dist/runtime/server/api/models/[model]/[id].patch.js +10 -5
- package/dist/runtime/server/api/models/[model]/index.get.js +4 -1
- package/dist/runtime/server/api/models/[model]/index.post.js +10 -5
- package/dist/runtime/server/utils/error.d.ts +9 -0
- package/dist/runtime/server/utils/error.js +49 -0
- package/dist/runtime/server/utils/index.d.ts +5 -8
- package/dist/runtime/server/utils/index.js +27 -10
- package/dist/runtime/server/utils/parsers.d.ts +2 -2
- package/dist/runtime/server/utils/parsers.js +2 -2
- package/package.json +3 -1
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { zenstackSchema } from "nuxt-zenstack-server.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
export function getClient() {
|
|
7
|
-
if (_client) {
|
|
8
|
-
return _client;
|
|
2
|
+
function getClient(event) {
|
|
3
|
+
if (event.context.zenstack?.client) {
|
|
4
|
+
return event.context.zenstack.client;
|
|
9
5
|
}
|
|
10
6
|
throw new Error("ZenStack client not provided");
|
|
11
7
|
}
|
|
12
|
-
export function getModelOperations(model) {
|
|
13
|
-
const db = getClient();
|
|
8
|
+
export function getModelOperations(event, model) {
|
|
9
|
+
const db = getClient(event);
|
|
14
10
|
return db[model.toString().toLocaleLowerCase()];
|
|
15
11
|
}
|
|
16
12
|
export function getModelDef(model) {
|
|
17
13
|
return zenstackSchema.models[model];
|
|
18
14
|
}
|
|
19
15
|
export function isIdString(model) {
|
|
20
|
-
|
|
16
|
+
const modelDef = getModelDef(model);
|
|
17
|
+
if (!modelDef.uniqueFields.id)
|
|
18
|
+
throw new Error(`Model ${model.toString()} does not have an id as a unique field`);
|
|
19
|
+
return modelDef.uniqueFields.id.type === "String";
|
|
21
20
|
}
|
|
22
21
|
export function getModels() {
|
|
23
22
|
return Object.keys(zenstackSchema.models);
|
|
@@ -25,3 +24,21 @@ export function getModels() {
|
|
|
25
24
|
export function isValidModel(model) {
|
|
26
25
|
return getModels().includes(model);
|
|
27
26
|
}
|
|
27
|
+
export function includeAll(model) {
|
|
28
|
+
const include = {};
|
|
29
|
+
const modelSet = /* @__PURE__ */ new Set();
|
|
30
|
+
function iterate(_model, acc) {
|
|
31
|
+
const modelDef = getModelDef(_model);
|
|
32
|
+
for (const [field, fieldDef] of Object.entries(modelDef.fields)) {
|
|
33
|
+
if (isValidModel(fieldDef.type) && !modelSet.has(fieldDef.type)) {
|
|
34
|
+
acc["include"] ||= {};
|
|
35
|
+
acc["include"][field] = {};
|
|
36
|
+
modelSet.add(fieldDef.type);
|
|
37
|
+
iterate(fieldDef.type, acc["include"][field]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
modelSet.add(model);
|
|
42
|
+
iterate(model, include);
|
|
43
|
+
return include["include"] ?? {};
|
|
44
|
+
}
|
|
@@ -10,10 +10,10 @@ type ReadArgs<Zmodel extends $Zmodel> = {
|
|
|
10
10
|
export declare function parseModel(event: H3Event): string | number | symbol;
|
|
11
11
|
export declare function parseId(event: H3Event, model: $Zmodel): string | number;
|
|
12
12
|
export declare function parseReadArgs<Zmodel extends $Zmodel>(event: H3Event, _model: Zmodel): ReadArgs<Zmodel>;
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function parseCreateArgs<Zmodel extends $Zmodel>(event: H3Event, _model: Zmodel): Promise<{
|
|
14
14
|
data: $ZcreateData<Zmodel>;
|
|
15
15
|
}>;
|
|
16
|
-
export declare function
|
|
16
|
+
export declare function parseUpdateArgs<Zmodel extends $Zmodel>(event: H3Event, _model: Zmodel): Promise<{
|
|
17
17
|
data: $ZupdateData<Zmodel>;
|
|
18
18
|
}>;
|
|
19
19
|
export {};
|
|
@@ -20,9 +20,9 @@ export function parseReadArgs(event, _model) {
|
|
|
20
20
|
const query = getQuery(event);
|
|
21
21
|
return query?.q ? parse(query.q) : {};
|
|
22
22
|
}
|
|
23
|
-
export async function
|
|
23
|
+
export async function parseCreateArgs(event, _model) {
|
|
24
24
|
return readBody(event);
|
|
25
25
|
}
|
|
26
|
-
export async function
|
|
26
|
+
export async function parseUpdateArgs(event, _model) {
|
|
27
27
|
return readBody(event);
|
|
28
28
|
}
|
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.4",
|
|
4
4
|
"description": "ZenStack integration for Nuxt",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://github.com/becem-gharbi/nuxt-zenstack"
|
|
@@ -66,7 +66,9 @@
|
|
|
66
66
|
"@nuxt/test-utils": "^3.23.0",
|
|
67
67
|
"@nuxt/ui": "^4.3.0",
|
|
68
68
|
"@types/node": "latest",
|
|
69
|
+
"@vueuse/core": "^14.1.0",
|
|
69
70
|
"@zenstackhq/cli": "3.2.1",
|
|
71
|
+
"@zenstackhq/plugin-policy": "^3.2.1",
|
|
70
72
|
"changelogen": "^0.6.2",
|
|
71
73
|
"eslint": "^9.39.2",
|
|
72
74
|
"libsql": "^0.5.22",
|