@chill-sharp/vue-client 1.1.12

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.
@@ -0,0 +1,450 @@
1
+ /*
2
+ * ChillSharp is a lightweight .NET library that sits on top of Entity Framework Core
3
+ * and turns an existing data model into a fully working REST API with almost no setup.
4
+ * Copyright (C) 2025 Andrea Piovesan
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU Affero General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Affero General Public License
17
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
18
+ */
19
+ import { onScopeDispose, ref, shallowRef, watch, watchEffect } from "vue";
20
+ import { CHILL_SHARP_VUE_CLIENT_VERSION } from "./version.js";
21
+ import { useChillSharpClient } from "./plugin.js";
22
+ export function useSchema(chillType, chillViewCode = "default", cultureName, update = false) {
23
+ const client = useChillSharpClient();
24
+ const data = ref(null);
25
+ const error = ref(null);
26
+ const isLoading = ref(true);
27
+ const load = async () => {
28
+ isLoading.value = true;
29
+ error.value = null;
30
+ try {
31
+ const response = await client.getSchema(readRef(chillType), readRef(chillViewCode), cultureName === undefined ? undefined : readRef(cultureName), readRef(update) ?? false);
32
+ data.value = response;
33
+ return response;
34
+ }
35
+ catch (err) {
36
+ error.value = err;
37
+ throw err;
38
+ }
39
+ finally {
40
+ isLoading.value = false;
41
+ }
42
+ };
43
+ watchEffect(() => {
44
+ void load();
45
+ });
46
+ return {
47
+ data,
48
+ error,
49
+ isLoading,
50
+ reload: load
51
+ };
52
+ }
53
+ export function useSchemaList(cultureName) {
54
+ const client = useChillSharpClient();
55
+ const data = ref(null);
56
+ const error = ref(null);
57
+ const isLoading = ref(true);
58
+ const load = async () => {
59
+ isLoading.value = true;
60
+ error.value = null;
61
+ try {
62
+ const response = await client.getSchemaList(cultureName === undefined ? undefined : readRef(cultureName));
63
+ data.value = response;
64
+ return response;
65
+ }
66
+ catch (err) {
67
+ error.value = err;
68
+ throw err;
69
+ }
70
+ finally {
71
+ isLoading.value = false;
72
+ }
73
+ };
74
+ watchEffect(() => {
75
+ void load();
76
+ });
77
+ return {
78
+ data,
79
+ error,
80
+ isLoading,
81
+ reload: load
82
+ };
83
+ }
84
+ export function useText(request) {
85
+ const client = useChillSharpClient();
86
+ const data = ref(null);
87
+ const error = ref(null);
88
+ const isLoading = ref(true);
89
+ const load = async () => {
90
+ isLoading.value = true;
91
+ error.value = null;
92
+ try {
93
+ const response = await client.getText(readRef(request));
94
+ data.value = response;
95
+ return response;
96
+ }
97
+ catch (err) {
98
+ error.value = err;
99
+ throw err;
100
+ }
101
+ finally {
102
+ isLoading.value = false;
103
+ }
104
+ };
105
+ watchEffect(() => {
106
+ void load();
107
+ });
108
+ return {
109
+ data,
110
+ error,
111
+ isLoading,
112
+ reload: load
113
+ };
114
+ }
115
+ export function useTexts(requests) {
116
+ const client = useChillSharpClient();
117
+ const data = ref(null);
118
+ const error = ref(null);
119
+ const isLoading = ref(true);
120
+ const load = async () => {
121
+ isLoading.value = true;
122
+ error.value = null;
123
+ try {
124
+ const response = await client.getTexts(readRef(requests));
125
+ data.value = response;
126
+ return response;
127
+ }
128
+ catch (err) {
129
+ error.value = err;
130
+ throw err;
131
+ }
132
+ finally {
133
+ isLoading.value = false;
134
+ }
135
+ };
136
+ watchEffect(() => {
137
+ void load();
138
+ });
139
+ return {
140
+ data,
141
+ error,
142
+ isLoading,
143
+ reload: load
144
+ };
145
+ }
146
+ export function useVersion() {
147
+ return CHILL_SHARP_VUE_CLIENT_VERSION;
148
+ }
149
+ export function useTest() {
150
+ const client = useChillSharpClient();
151
+ const data = ref(null);
152
+ const error = ref(null);
153
+ const isLoading = ref(true);
154
+ const load = async () => {
155
+ isLoading.value = true;
156
+ error.value = null;
157
+ try {
158
+ const response = await client.test();
159
+ data.value = response;
160
+ return response;
161
+ }
162
+ catch (err) {
163
+ error.value = err;
164
+ throw err;
165
+ }
166
+ finally {
167
+ isLoading.value = false;
168
+ }
169
+ };
170
+ watchEffect(() => {
171
+ void load();
172
+ });
173
+ return {
174
+ data,
175
+ error,
176
+ isLoading,
177
+ reload: load
178
+ };
179
+ }
180
+ export function useCurrentUserPreferences() {
181
+ const client = useChillSharpClient();
182
+ // ChillUserPreferences extends the recursive JsonObject type. Keep it shallow so Vue
183
+ // does not recursively unwrap that type while inferring the composable return value.
184
+ const data = shallowRef(null);
185
+ const error = ref(null);
186
+ const isLoading = ref(true);
187
+ const load = async () => {
188
+ isLoading.value = true;
189
+ error.value = null;
190
+ try {
191
+ const response = await client.getCurrentUserPreferences();
192
+ data.value = response;
193
+ return response;
194
+ }
195
+ catch (err) {
196
+ error.value = err;
197
+ throw err;
198
+ }
199
+ finally {
200
+ isLoading.value = false;
201
+ }
202
+ };
203
+ watchEffect(() => { void load(); });
204
+ return { data, error, isLoading, reload: load };
205
+ }
206
+ export function useQueryMutation() {
207
+ const client = useChillSharpClient();
208
+ const data = ref(null);
209
+ const error = ref(null);
210
+ const isLoading = ref(false);
211
+ const execute = async (...args) => {
212
+ const payload = args[0];
213
+ isLoading.value = true;
214
+ error.value = null;
215
+ try {
216
+ const response = await client.query(payload);
217
+ data.value = response;
218
+ return response;
219
+ }
220
+ catch (err) {
221
+ error.value = err;
222
+ throw err;
223
+ }
224
+ finally {
225
+ isLoading.value = false;
226
+ }
227
+ };
228
+ return {
229
+ data,
230
+ error,
231
+ isLoading,
232
+ execute,
233
+ reset: () => {
234
+ data.value = null;
235
+ error.value = null;
236
+ isLoading.value = false;
237
+ }
238
+ };
239
+ }
240
+ export function useLookupMutation() {
241
+ const client = useChillSharpClient();
242
+ const data = ref(null);
243
+ const error = ref(null);
244
+ const isLoading = ref(false);
245
+ const execute = async (...args) => {
246
+ const payload = args[0];
247
+ isLoading.value = true;
248
+ error.value = null;
249
+ try {
250
+ const response = await client.lookup(payload);
251
+ data.value = response;
252
+ return response;
253
+ }
254
+ catch (err) {
255
+ error.value = err;
256
+ throw err;
257
+ }
258
+ finally {
259
+ isLoading.value = false;
260
+ }
261
+ };
262
+ return {
263
+ data,
264
+ error,
265
+ isLoading,
266
+ execute,
267
+ reset: () => {
268
+ data.value = null;
269
+ error.value = null;
270
+ isLoading.value = false;
271
+ }
272
+ };
273
+ }
274
+ export function useAutocompleteMutation() {
275
+ const client = useChillSharpClient();
276
+ const data = ref(null);
277
+ const error = ref(null);
278
+ const isLoading = ref(false);
279
+ const execute = async (...args) => {
280
+ const payload = args[0];
281
+ isLoading.value = true;
282
+ error.value = null;
283
+ try {
284
+ const response = await client.autocomplete(payload);
285
+ data.value = response;
286
+ return response;
287
+ }
288
+ catch (err) {
289
+ error.value = err;
290
+ throw err;
291
+ }
292
+ finally {
293
+ isLoading.value = false;
294
+ }
295
+ };
296
+ return {
297
+ data,
298
+ error,
299
+ isLoading,
300
+ execute,
301
+ reset: () => {
302
+ data.value = null;
303
+ error.value = null;
304
+ isLoading.value = false;
305
+ }
306
+ };
307
+ }
308
+ export function useValidateMutation() {
309
+ const client = useChillSharpClient();
310
+ const data = ref(null);
311
+ const error = ref(null);
312
+ const isLoading = ref(false);
313
+ const execute = async (...args) => {
314
+ const payload = args[0];
315
+ isLoading.value = true;
316
+ error.value = null;
317
+ try {
318
+ const response = await client.validate(payload);
319
+ data.value = response;
320
+ return response;
321
+ }
322
+ catch (err) {
323
+ error.value = err;
324
+ throw err;
325
+ }
326
+ finally {
327
+ isLoading.value = false;
328
+ }
329
+ };
330
+ return {
331
+ data,
332
+ error,
333
+ isLoading,
334
+ execute,
335
+ reset: () => {
336
+ data.value = null;
337
+ error.value = null;
338
+ isLoading.value = false;
339
+ }
340
+ };
341
+ }
342
+ export function useEntityMutation(action) {
343
+ const client = useChillSharpClient();
344
+ const data = ref(null);
345
+ const error = ref(null);
346
+ const isLoading = ref(false);
347
+ const execute = async (...args) => {
348
+ const payload = args[0];
349
+ isLoading.value = true;
350
+ error.value = null;
351
+ try {
352
+ let response;
353
+ switch (action) {
354
+ case "find":
355
+ response = await client.find(payload);
356
+ break;
357
+ case "create":
358
+ response = await client.create(payload);
359
+ break;
360
+ case "update":
361
+ response = await client.update(payload);
362
+ break;
363
+ default:
364
+ await client.delete(payload);
365
+ response = null;
366
+ break;
367
+ }
368
+ data.value = response;
369
+ return response;
370
+ }
371
+ catch (err) {
372
+ error.value = err;
373
+ throw err;
374
+ }
375
+ finally {
376
+ isLoading.value = false;
377
+ }
378
+ };
379
+ return {
380
+ data,
381
+ error,
382
+ isLoading,
383
+ execute,
384
+ reset: () => {
385
+ data.value = null;
386
+ error.value = null;
387
+ isLoading.value = false;
388
+ }
389
+ };
390
+ }
391
+ export function useEntityChanges(chillType, onChanges, guid) {
392
+ const client = useChillSharpClient();
393
+ const error = ref(null);
394
+ const isSubscribed = ref(false);
395
+ let subscription = null;
396
+ const release = async () => {
397
+ const currentSubscription = subscription;
398
+ subscription = null;
399
+ isSubscribed.value = false;
400
+ if (currentSubscription) {
401
+ await currentSubscription.unsubscribe();
402
+ }
403
+ };
404
+ watch([
405
+ () => readRef(chillType),
406
+ () => (guid === undefined ? null : (readRef(guid) ?? null)),
407
+ () => readRef(onChanges)
408
+ ], async ([nextChillType, nextGuid, nextOnChanges], _previousValue, onCleanup) => {
409
+ error.value = null;
410
+ await release();
411
+ let isActive = true;
412
+ onCleanup(() => {
413
+ isActive = false;
414
+ void release();
415
+ });
416
+ try {
417
+ const nextSubscription = await client.subscribeToEntityChanges(nextChillType, async (changes) => {
418
+ await nextOnChanges(changes);
419
+ }, nextGuid);
420
+ if (!isActive) {
421
+ await nextSubscription.unsubscribe();
422
+ return;
423
+ }
424
+ subscription = nextSubscription;
425
+ isSubscribed.value = true;
426
+ }
427
+ catch (err) {
428
+ if (isActive) {
429
+ error.value = err;
430
+ isSubscribed.value = false;
431
+ }
432
+ }
433
+ }, { immediate: true });
434
+ onScopeDispose(() => {
435
+ void release();
436
+ });
437
+ return {
438
+ error,
439
+ isSubscribed
440
+ };
441
+ }
442
+ function asReadonlyRef(value) {
443
+ return value;
444
+ }
445
+ function readRef(value) {
446
+ if (typeof value === "object" && value !== null && "value" in value) {
447
+ return value.value;
448
+ }
449
+ return value;
450
+ }
@@ -0,0 +1,7 @@
1
+ export { createChillSharpClient, createChillSharpPlugin, useChillSharpClient } from "./plugin.js";
2
+ export { useAutocompleteMutation, useCurrentUserPreferences, useEntityChanges, useEntityMutation, useQueryMutation, useSchema, useSchemaList, useTest, useText, useTexts, useValidateMutation, useVersion } from "./composables.js";
3
+ export type { ChillSharpVueOptions } from "./plugin.js";
4
+ export type { UseChillAsyncState, UseChillMutationState, UseChillSubscriptionState } from "./composables.js";
5
+ export { API_BASE_PATH, ChillSharpClient, ChillSharpClientError, PermissionAction, PermissionEffect, PermissionScope } from "@chill-sharp/ts-client";
6
+ export { CHILL_SHARP_VUE_CLIENT_VERSION } from "./version.js";
7
+ export type { AuthPermissionRule, AuthPermissionRuleItem, AuthRoleDetailsResponse, AuthRoleListItem, AuthRolePermissions, AuthTokenResponse, AuthUserDetailsResponse, AuthUserListItem, ChillDtoEntity, ChillUserPreferences, ChillDtoEntityOptions, ChillDtoMenuItem, ChillDtoProperty, ChillDtoPropertySchema, ChillDtoQuery, ChillDtoSchema, ChillDtoSchemaRelation, ChillDtoSchemaRelationLabel, ChillDtoSchemaListItem, ChillAttachmentUploadFile, ChillAttachmentUploadOptions, ChillEntityChangeAction, ChillEntityChangeCallback, ChillEntityChangeNotification, ChillEntityChangeSubscription, ChillOrdering, ChillPagination, ChillSharpClientOptions, GetAuthPermissionsResponse, GetTextRequest, GetTextResponse, JsonObject, JsonPrimitive, JsonValue, RegisterAuthIdentityRequest, SetAuthRoleRequest, SetAuthUserRequest } from "@chill-sharp/ts-client";
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ /*
2
+ * ChillSharp is a lightweight .NET library that sits on top of Entity Framework Core
3
+ * and turns an existing data model into a fully working REST API with almost no setup.
4
+ * Copyright (C) 2025 Andrea Piovesan
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU Affero General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Affero General Public License
17
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
18
+ */
19
+ export { createChillSharpClient, createChillSharpPlugin, useChillSharpClient } from "./plugin.js";
20
+ export { useAutocompleteMutation, useCurrentUserPreferences, useEntityChanges, useEntityMutation, useQueryMutation, useSchema, useSchemaList, useTest, useText, useTexts, useValidateMutation, useVersion } from "./composables.js";
21
+ export { API_BASE_PATH, ChillSharpClient, ChillSharpClientError, PermissionAction, PermissionEffect, PermissionScope } from "@chill-sharp/ts-client";
22
+ export { CHILL_SHARP_VUE_CLIENT_VERSION } from "./version.js";
@@ -0,0 +1,12 @@
1
+ import type { InjectionKey, Plugin } from "vue";
2
+ import { ChillSharpClient } from "@chill-sharp/ts-client";
3
+ import type { ChillSharpClientOptions } from "@chill-sharp/ts-client";
4
+ export interface ChillSharpVueOptions {
5
+ baseUrl: string;
6
+ client?: ChillSharpClient;
7
+ options?: ChillSharpClientOptions;
8
+ }
9
+ export declare const chillSharpClientKey: InjectionKey<ChillSharpClient>;
10
+ export declare function createChillSharpClient(options: ChillSharpVueOptions): ChillSharpClient;
11
+ export declare function createChillSharpPlugin(options: ChillSharpVueOptions): Plugin;
12
+ export declare function useChillSharpClient(): ChillSharpClient;
package/dist/plugin.js ADDED
@@ -0,0 +1,42 @@
1
+ /*
2
+ * ChillSharp is a lightweight .NET library that sits on top of Entity Framework Core
3
+ * and turns an existing data model into a fully working REST API with almost no setup.
4
+ * Copyright (C) 2025 Andrea Piovesan
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU Affero General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Affero General Public License
17
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
18
+ */
19
+ import { inject } from "vue";
20
+ import { ChillSharpClient } from "@chill-sharp/ts-client";
21
+ export const chillSharpClientKey = Symbol("ChillSharpClient");
22
+ export function createChillSharpClient(options) {
23
+ if (options.client) {
24
+ return options.client;
25
+ }
26
+ return new ChillSharpClient(options.baseUrl, options.options);
27
+ }
28
+ export function createChillSharpPlugin(options) {
29
+ const client = createChillSharpClient(options);
30
+ return {
31
+ install(app) {
32
+ app.provide(chillSharpClientKey, client);
33
+ }
34
+ };
35
+ }
36
+ export function useChillSharpClient() {
37
+ const client = inject(chillSharpClientKey, null);
38
+ if (!client) {
39
+ throw new Error("useChillSharpClient requires createChillSharpPlugin() to be installed.");
40
+ }
41
+ return client;
42
+ }
@@ -0,0 +1 @@
1
+ export declare const CHILL_SHARP_VUE_CLIENT_VERSION = "0.1.0";
@@ -0,0 +1,19 @@
1
+ /*
2
+ * ChillSharp is a lightweight .NET library that sits on top of Entity Framework Core
3
+ * and turns an existing data model into a fully working REST API with almost no setup.
4
+ * Copyright (C) 2025 Andrea Piovesan
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU Affero General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Affero General Public License
17
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
18
+ */
19
+ export const CHILL_SHARP_VUE_CLIENT_VERSION = "0.1.0";
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@chill-sharp/vue-client",
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "git+https://github.com/e-500/chill-sharp.git",
6
+ "directory": "extra/chill-sharp-vue-client"
7
+ },
8
+ "version": "1.1.12",
9
+ "description": "Vue client helpers for generic ChillSharp services",
10
+ "license": "AGPL-3.0-or-later",
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "src",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsc -p tsconfig.json",
27
+ "check": "tsc -p tsconfig.json --noEmit",
28
+ "prepare": "npm run build",
29
+ "prepack": "npm run build"
30
+ },
31
+ "keywords": [
32
+ "chillsharp",
33
+ "vue",
34
+ "typescript",
35
+ "client",
36
+ "composables"
37
+ ],
38
+ "author": "Andrea Piovesan",
39
+ "peerDependencies": {
40
+ "vue": "^3.4.0",
41
+ "@chill-sharp/ts-client": "^1.1.12"
42
+ },
43
+ "devDependencies": {
44
+ "typescript": "^5.8.2",
45
+ "@chill-sharp/ts-client": "file:../chill-sharp-ts-client"
46
+ }
47
+ }
48
+