@diphyx/harlemify 0.0.2 → 1.0.0
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/LICENSE +1 -1
- package/README.md +25 -27
- package/dist/module.json +1 -1
- package/dist/module.mjs +2 -0
- package/dist/runtime/composables/use.d.ts +30 -0
- package/dist/runtime/composables/use.js +25 -0
- package/dist/runtime/core/api.d.ts +14 -17
- package/dist/runtime/core/api.js +9 -15
- package/dist/runtime/core/store.d.ts +66 -98
- package/dist/runtime/core/store.js +179 -370
- package/dist/runtime/index.d.ts +7 -4
- package/dist/runtime/index.js +3 -14
- package/dist/runtime/plugin.js +1 -5
- package/dist/runtime/utils/endpoint.d.ts +14 -50
- package/dist/runtime/utils/endpoint.js +18 -19
- package/dist/runtime/utils/schema.d.ts +9 -4
- package/dist/runtime/utils/schema.js +6 -6
- package/dist/runtime/utils/transform.d.ts +6 -0
- package/dist/runtime/utils/transform.js +20 -0
- package/package.json +3 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
# Harlemify
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Schema-driven state management for Nuxt powered by [Harlem](https://harlemjs.com/)
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
7
|
+
Define your data schema once with Zod, and Harlemify handles the rest: type-safe API calls, reactive state, request monitoring, and automatic memory management. Your schema becomes the single source of truth for types, validation, and API payloads.
|
|
8
|
+
|
|
7
9
|
## Features
|
|
8
10
|
|
|
9
|
-
- Zod schema validation
|
|
10
|
-
- Automatic API client with runtime
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- SSR
|
|
11
|
+
- **Schema-Driven** - Zod schema defines types, validation, and API payloads
|
|
12
|
+
- **Automatic API Client** - Built-in HTTP client with runtime configuration
|
|
13
|
+
- **Reactive Memory** - Unit and collection caching with Vue reactivity
|
|
14
|
+
- **Request Monitoring** - Track pending, success, and failed states
|
|
15
|
+
- **SSR Support** - Server-side rendering via Harlem SSR plugin
|
|
14
16
|
|
|
15
17
|
## Installation
|
|
16
18
|
|
|
@@ -34,39 +36,35 @@ export default defineNuxtConfig({
|
|
|
34
36
|
|
|
35
37
|
```typescript
|
|
36
38
|
// stores/user.ts
|
|
37
|
-
import { z
|
|
39
|
+
import { z } from "zod";
|
|
40
|
+
import { createStore, Endpoint, EndpointMethod } from "@diphyx/harlemify";
|
|
38
41
|
|
|
39
42
|
const UserSchema = z.object({
|
|
40
|
-
id: z.number().meta({
|
|
41
|
-
indicator: true,
|
|
42
|
-
}),
|
|
43
|
+
id: z.number().meta({ indicator: true }),
|
|
43
44
|
name: z.string().meta({
|
|
44
|
-
|
|
45
|
+
methods: [EndpointMethod.POST, EndpointMethod.PATCH],
|
|
45
46
|
}),
|
|
46
47
|
});
|
|
47
48
|
|
|
48
49
|
export type User = z.infer<typeof UserSchema>;
|
|
49
50
|
|
|
50
51
|
export const userStore = createStore("user", UserSchema, {
|
|
51
|
-
[Endpoint.GET_UNITS]: {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
[Endpoint.POST_UNITS]: {
|
|
56
|
-
action: ApiAction.POST,
|
|
57
|
-
url: "/users",
|
|
58
|
-
},
|
|
59
|
-
[Endpoint.PATCH_UNITS]: {
|
|
60
|
-
action: ApiAction.PATCH,
|
|
61
|
-
url: (params) => `/users/${params.id}`,
|
|
62
|
-
},
|
|
63
|
-
[Endpoint.DELETE_UNITS]: {
|
|
64
|
-
action: ApiAction.DELETE,
|
|
65
|
-
url: (params) => `/users/${params.id}`,
|
|
66
|
-
},
|
|
52
|
+
[Endpoint.GET_UNITS]: { method: EndpointMethod.GET, url: "/users" },
|
|
53
|
+
[Endpoint.POST_UNITS]: { method: EndpointMethod.POST, url: "/users" },
|
|
54
|
+
[Endpoint.PATCH_UNITS]: { method: EndpointMethod.PATCH, url: (p) => `/users/${p.id}` },
|
|
55
|
+
[Endpoint.DELETE_UNITS]: { method: EndpointMethod.DELETE, url: (p) => `/users/${p.id}` },
|
|
67
56
|
});
|
|
68
57
|
```
|
|
69
58
|
|
|
59
|
+
## Why Harlemify?
|
|
60
|
+
|
|
61
|
+
| | |
|
|
62
|
+
| --------------- | ------------------------------------------------- |
|
|
63
|
+
| **Type-Safe** | Full TypeScript support with Zod schema inference |
|
|
64
|
+
| **Declarative** | Define schema once, derive everything else |
|
|
65
|
+
| **Reactive** | Powered by Vue's reactivity through Harlem |
|
|
66
|
+
| **Simple** | Minimal boilerplate, maximum productivity |
|
|
67
|
+
|
|
70
68
|
## Documentation
|
|
71
69
|
|
|
72
70
|
Full documentation available at [https://diphyx.github.io/harlemify/](https://diphyx.github.io/harlemify/)
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -15,6 +15,8 @@ const module = defineNuxtModule({
|
|
|
15
15
|
const { resolve } = createResolver(import.meta.url);
|
|
16
16
|
addPlugin(resolve("./runtime", "plugin"));
|
|
17
17
|
addImportsDir(resolve("./runtime", "core"));
|
|
18
|
+
addImportsDir(resolve("./runtime", "composables"));
|
|
19
|
+
addImportsDir(resolve("./runtime", "utils"));
|
|
18
20
|
updateRuntimeConfig({
|
|
19
21
|
public: {
|
|
20
22
|
harlemify: options
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ComputedRef } from "vue";
|
|
2
|
+
import { EndpointMethod } from "../utils/endpoint.js";
|
|
3
|
+
import type { Store } from "../core/store.js";
|
|
4
|
+
import type { Pluralize, Capitalize } from "../utils/transform.js";
|
|
5
|
+
import type { EndpointStatusFlag } from "../utils/endpoint.js";
|
|
6
|
+
type Indicator<T, I extends keyof T> = Required<Pick<T, I>>;
|
|
7
|
+
type PartialWithIndicator<T, I extends keyof T> = Indicator<T, I> & Partial<T>;
|
|
8
|
+
type MemoryState<E extends string, T> = {
|
|
9
|
+
[P in E]: ComputedRef<T | null>;
|
|
10
|
+
} & {
|
|
11
|
+
[P in Pluralize<E>]: ComputedRef<T[]>;
|
|
12
|
+
};
|
|
13
|
+
type MemoryAction<A extends string, E extends string, U> = {
|
|
14
|
+
[K in `${A}${Capitalize<E>}`]: (unit: U) => void;
|
|
15
|
+
} & {
|
|
16
|
+
[K in `${A}${Capitalize<Pluralize<E>>}`]: (units: U[]) => void;
|
|
17
|
+
};
|
|
18
|
+
type EndpointAction<E extends string, T> = {
|
|
19
|
+
[M in EndpointMethod as `${M}${Capitalize<E>}`]: (unit?: Partial<T>) => Promise<T>;
|
|
20
|
+
} & {
|
|
21
|
+
[M in EndpointMethod as `${M}${Capitalize<Pluralize<E>>}`]: (units?: Partial<T>[]) => Promise<T[]>;
|
|
22
|
+
};
|
|
23
|
+
type EndpointMonitor<E extends string> = {
|
|
24
|
+
[M in EndpointMethod as `${M}${Capitalize<E>}${EndpointStatusFlag}`]: ComputedRef<boolean>;
|
|
25
|
+
} & {
|
|
26
|
+
[M in EndpointMethod as `${M}${Capitalize<Pluralize<E>>}${EndpointStatusFlag}`]: ComputedRef<boolean>;
|
|
27
|
+
};
|
|
28
|
+
type StoreAlias<E extends string, T, I extends keyof T = keyof T> = MemoryState<E, T> & MemoryAction<"set", E, T | null> & MemoryAction<"edit", E, PartialWithIndicator<T, I>> & MemoryAction<"drop", E, PartialWithIndicator<T, I>> & EndpointAction<E, T> & EndpointMonitor<E>;
|
|
29
|
+
export declare function useStoreAlias<E extends string, T, I extends keyof T = keyof T>(store: Store<E, T, I>): StoreAlias<E, T, I>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { capitalize } from "../utils/transform.js";
|
|
2
|
+
import { EndpointMethod, EndpointStatus, makeEndpointStatusFlag } from "../utils/endpoint.js";
|
|
3
|
+
import { StoreMemoryAction } from "../core/store.js";
|
|
4
|
+
export function useStoreAlias(store) {
|
|
5
|
+
const capitalizedUnit = capitalize(store.alias.unit);
|
|
6
|
+
const capitalizedUnits = capitalize(store.alias.units);
|
|
7
|
+
const output = {
|
|
8
|
+
[store.alias.unit]: store.unit,
|
|
9
|
+
[store.alias.units]: store.units
|
|
10
|
+
};
|
|
11
|
+
for (const action of Object.values(StoreMemoryAction)) {
|
|
12
|
+
output[`${action}${capitalizedUnit}`] = store.memory[`${action}Unit`];
|
|
13
|
+
output[`${action}${capitalizedUnits}`] = store.memory[`${action}Units`];
|
|
14
|
+
}
|
|
15
|
+
for (const method of Object.values(EndpointMethod)) {
|
|
16
|
+
output[`${method}${capitalizedUnit}`] = store.endpoint[`${method}Unit`];
|
|
17
|
+
output[`${method}${capitalizedUnits}`] = store.endpoint[`${method}Units`];
|
|
18
|
+
for (const status of Object.values(EndpointStatus)) {
|
|
19
|
+
const statusFlag = makeEndpointStatusFlag(status);
|
|
20
|
+
output[`${method}${capitalizedUnit}${statusFlag}`] = store.monitor[`${method}Unit${statusFlag}`];
|
|
21
|
+
output[`${method}${capitalizedUnits}${statusFlag}`] = store.monitor[`${method}Units${statusFlag}`];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return output;
|
|
25
|
+
}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
GET = "get",
|
|
4
|
-
POST = "post",
|
|
5
|
-
PUT = "put",
|
|
6
|
-
PATCH = "patch",
|
|
7
|
-
DELETE = "delete"
|
|
8
|
-
}
|
|
1
|
+
import type { MaybeRefOrGetter } from "vue";
|
|
2
|
+
import { EndpointMethod } from "../utils/endpoint.js";
|
|
9
3
|
export declare enum ApiResponseType {
|
|
10
4
|
JSON = "json",
|
|
11
5
|
TEXT = "text",
|
|
@@ -19,15 +13,17 @@ export declare enum ApiErrorSource {
|
|
|
19
13
|
export type ApiRequestHeader = MaybeRefOrGetter<Record<string, unknown>>;
|
|
20
14
|
export type ApiRequestQuery = MaybeRefOrGetter<Record<string, unknown>>;
|
|
21
15
|
export type ApiRequestBody = MaybeRefOrGetter<string | number | ArrayBuffer | FormData | Blob | Record<string, any>>;
|
|
22
|
-
export interface ApiRequestOptions<A extends
|
|
16
|
+
export interface ApiRequestOptions<A extends EndpointMethod = EndpointMethod, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery, B extends ApiRequestBody = ApiRequestBody> {
|
|
23
17
|
action?: A;
|
|
24
18
|
headers?: H;
|
|
25
19
|
query?: Q;
|
|
26
20
|
body?: B;
|
|
21
|
+
timeout?: number;
|
|
27
22
|
responseType?: ApiResponseType;
|
|
28
23
|
retry?: number | false;
|
|
29
24
|
retryDelay?: number;
|
|
30
25
|
retryStatusCodes?: number[];
|
|
26
|
+
signal?: AbortSignal;
|
|
31
27
|
}
|
|
32
28
|
export interface ApiOptions {
|
|
33
29
|
url?: string;
|
|
@@ -35,7 +31,7 @@ export interface ApiOptions {
|
|
|
35
31
|
query?: ApiRequestQuery;
|
|
36
32
|
timeout?: number;
|
|
37
33
|
}
|
|
38
|
-
export type
|
|
34
|
+
export type EndpointMethodOptions<A extends EndpointMethod, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery, B extends ApiRequestBody = ApiRequestBody> = Omit<ApiRequestOptions<A, H, Q, B>, "action">;
|
|
39
35
|
export interface ApiErrorOptions {
|
|
40
36
|
source: ApiErrorSource;
|
|
41
37
|
method: string;
|
|
@@ -54,10 +50,11 @@ export declare class ApiRequestError extends ApiError {
|
|
|
54
50
|
export declare class ApiResponseError extends ApiError {
|
|
55
51
|
constructor(options: Omit<ApiErrorOptions, "source">);
|
|
56
52
|
}
|
|
57
|
-
export
|
|
58
|
-
get: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery>(url: string, options?:
|
|
59
|
-
post: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery, B extends ApiRequestBody = ApiRequestBody>(url: string, options?:
|
|
60
|
-
put: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery, B extends ApiRequestBody = ApiRequestBody>(url: string, options?:
|
|
61
|
-
patch: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery, B extends ApiRequestBody = ApiRequestBody>(url: string, options?:
|
|
62
|
-
del: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery>(url: string, options?:
|
|
63
|
-
}
|
|
53
|
+
export interface Api {
|
|
54
|
+
get: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery>(url: string, options?: EndpointMethodOptions<EndpointMethod.GET, H, Q, never>) => Promise<T>;
|
|
55
|
+
post: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery, B extends ApiRequestBody = ApiRequestBody>(url: string, options?: EndpointMethodOptions<EndpointMethod.POST, H, Q, B>) => Promise<T>;
|
|
56
|
+
put: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery, B extends ApiRequestBody = ApiRequestBody>(url: string, options?: EndpointMethodOptions<EndpointMethod.PUT, H, Q, B>) => Promise<T>;
|
|
57
|
+
patch: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery, B extends ApiRequestBody = ApiRequestBody>(url: string, options?: EndpointMethodOptions<EndpointMethod.PATCH, H, Q, B>) => Promise<T>;
|
|
58
|
+
del: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery>(url: string, options?: EndpointMethodOptions<EndpointMethod.DELETE, H, Q, never>) => Promise<T>;
|
|
59
|
+
}
|
|
60
|
+
export declare function createApi(options?: ApiOptions): Api;
|
package/dist/runtime/core/api.js
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { toValue } from "vue";
|
|
2
|
-
|
|
3
|
-
ApiAction2["GET"] = "get";
|
|
4
|
-
ApiAction2["POST"] = "post";
|
|
5
|
-
ApiAction2["PUT"] = "put";
|
|
6
|
-
ApiAction2["PATCH"] = "patch";
|
|
7
|
-
ApiAction2["DELETE"] = "delete";
|
|
8
|
-
return ApiAction2;
|
|
9
|
-
})(ApiAction || {});
|
|
2
|
+
import { EndpointMethod } from "../utils/endpoint.js";
|
|
10
3
|
export var ApiResponseType = /* @__PURE__ */ ((ApiResponseType2) => {
|
|
11
4
|
ApiResponseType2["JSON"] = "json";
|
|
12
5
|
ApiResponseType2["TEXT"] = "text";
|
|
@@ -24,7 +17,7 @@ export class ApiError extends Error {
|
|
|
24
17
|
method;
|
|
25
18
|
url;
|
|
26
19
|
constructor(options) {
|
|
27
|
-
super(options.message
|
|
20
|
+
super(options.message ?? "Unknown error");
|
|
28
21
|
this.name = "ApiError";
|
|
29
22
|
this.source = options.source;
|
|
30
23
|
this.method = options.method;
|
|
@@ -51,7 +44,7 @@ export function createApi(options) {
|
|
|
51
44
|
async function request(url, requestOptions) {
|
|
52
45
|
return $fetch(url, {
|
|
53
46
|
baseURL: options?.url,
|
|
54
|
-
method: requestOptions?.action ??
|
|
47
|
+
method: requestOptions?.action ?? EndpointMethod.GET,
|
|
55
48
|
headers: {
|
|
56
49
|
...toValue(options?.headers),
|
|
57
50
|
...toValue(requestOptions?.headers)
|
|
@@ -66,6 +59,7 @@ export function createApi(options) {
|
|
|
66
59
|
retry: requestOptions?.retry,
|
|
67
60
|
retryDelay: requestOptions?.retryDelay,
|
|
68
61
|
retryStatusCodes: requestOptions?.retryStatusCodes,
|
|
62
|
+
signal: requestOptions?.signal,
|
|
69
63
|
onRequestError({ request: request2, options: options2, error }) {
|
|
70
64
|
throw new ApiRequestError({
|
|
71
65
|
method: options2.method,
|
|
@@ -85,31 +79,31 @@ export function createApi(options) {
|
|
|
85
79
|
async function get(url, options2) {
|
|
86
80
|
return request(url, {
|
|
87
81
|
...options2,
|
|
88
|
-
action:
|
|
82
|
+
action: EndpointMethod.GET
|
|
89
83
|
});
|
|
90
84
|
}
|
|
91
85
|
async function post(url, options2) {
|
|
92
86
|
return request(url, {
|
|
93
87
|
...options2,
|
|
94
|
-
action:
|
|
88
|
+
action: EndpointMethod.POST
|
|
95
89
|
});
|
|
96
90
|
}
|
|
97
91
|
async function put(url, options2) {
|
|
98
92
|
return request(url, {
|
|
99
93
|
...options2,
|
|
100
|
-
action:
|
|
94
|
+
action: EndpointMethod.PUT
|
|
101
95
|
});
|
|
102
96
|
}
|
|
103
97
|
async function patch(url, options2) {
|
|
104
98
|
return request(url, {
|
|
105
99
|
...options2,
|
|
106
|
-
action:
|
|
100
|
+
action: EndpointMethod.PATCH
|
|
107
101
|
});
|
|
108
102
|
}
|
|
109
103
|
async function del(url, options2) {
|
|
110
104
|
return request(url, {
|
|
111
105
|
...options2,
|
|
112
|
-
action:
|
|
106
|
+
action: EndpointMethod.DELETE
|
|
113
107
|
});
|
|
114
108
|
}
|
|
115
109
|
return {
|
|
@@ -1,106 +1,74 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { ComputedRef } from "vue";
|
|
3
|
+
import type { Extension, BaseState } from "@harlem/core";
|
|
4
|
+
import { Endpoint, EndpointStatus } from "../utils/endpoint.js";
|
|
5
|
+
import type { EndpointMethodOptions, ApiOptions } from "./api.js";
|
|
6
|
+
import type { EndpointDefinition, EndpointStatusName } from "../utils/endpoint.js";
|
|
7
|
+
import type { Pluralize } from "../utils/transform.js";
|
|
8
|
+
export declare enum StoreMemoryAction {
|
|
9
|
+
SET = "set",
|
|
10
|
+
EDIT = "edit",
|
|
11
|
+
DROP = "drop"
|
|
12
|
+
}
|
|
4
13
|
export declare enum StoreMemoryPosition {
|
|
5
14
|
FIRST = "first",
|
|
6
15
|
LAST = "last"
|
|
7
16
|
}
|
|
8
|
-
|
|
9
|
-
|
|
17
|
+
export interface StoreHooks {
|
|
18
|
+
before?: () => Promise<void> | void;
|
|
19
|
+
after?: (error?: Error) => Promise<void> | void;
|
|
20
|
+
}
|
|
21
|
+
export interface StoreOptions {
|
|
10
22
|
api?: ApiOptions;
|
|
23
|
+
indicator?: string;
|
|
24
|
+
hooks?: StoreHooks;
|
|
11
25
|
extensions?: Extension<BaseState>[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
putUnitsIsIdle: import("@vue/reactivity").ComputedRef<boolean>;
|
|
52
|
-
putUnitsIsPending: import("@vue/reactivity").ComputedRef<boolean>;
|
|
53
|
-
putUnitsIsSuccess: import("@vue/reactivity").ComputedRef<boolean>;
|
|
54
|
-
putUnitsIsFailed: import("@vue/reactivity").ComputedRef<boolean>;
|
|
55
|
-
patchUnitIsIdle: import("@vue/reactivity").ComputedRef<boolean>;
|
|
56
|
-
patchUnitIsPending: import("@vue/reactivity").ComputedRef<boolean>;
|
|
57
|
-
patchUnitIsSuccess: import("@vue/reactivity").ComputedRef<boolean>;
|
|
58
|
-
patchUnitIsFailed: import("@vue/reactivity").ComputedRef<boolean>;
|
|
59
|
-
patchUnitsIsIdle: import("@vue/reactivity").ComputedRef<boolean>;
|
|
60
|
-
patchUnitsIsPending: import("@vue/reactivity").ComputedRef<boolean>;
|
|
61
|
-
patchUnitsIsSuccess: import("@vue/reactivity").ComputedRef<boolean>;
|
|
62
|
-
patchUnitsIsFailed: import("@vue/reactivity").ComputedRef<boolean>;
|
|
63
|
-
deleteUnitIsIdle: import("@vue/reactivity").ComputedRef<boolean>;
|
|
64
|
-
deleteUnitIsPending: import("@vue/reactivity").ComputedRef<boolean>;
|
|
65
|
-
deleteUnitIsSuccess: import("@vue/reactivity").ComputedRef<boolean>;
|
|
66
|
-
deleteUnitIsFailed: import("@vue/reactivity").ComputedRef<boolean>;
|
|
67
|
-
deleteUnitsIsIdle: import("@vue/reactivity").ComputedRef<boolean>;
|
|
68
|
-
deleteUnitsIsPending: import("@vue/reactivity").ComputedRef<boolean>;
|
|
69
|
-
deleteUnitsIsSuccess: import("@vue/reactivity").ComputedRef<boolean>;
|
|
70
|
-
deleteUnitsIsFailed: import("@vue/reactivity").ComputedRef<boolean>;
|
|
26
|
+
}
|
|
27
|
+
type Indicator<T, I extends keyof T> = Required<Pick<T, I>>;
|
|
28
|
+
type WithIndicator<T, I extends keyof T> = Indicator<T, I> & T;
|
|
29
|
+
type PartialWithIndicator<T, I extends keyof T> = Indicator<T, I> & Partial<T>;
|
|
30
|
+
type StoreEndpointReadOptions = Omit<EndpointMethodOptions<any>, "body">;
|
|
31
|
+
type StoreEndpointWriteOptions = EndpointMethodOptions<any> & {
|
|
32
|
+
validate?: boolean;
|
|
33
|
+
};
|
|
34
|
+
type StoreEndpointWriteMultipleOptions = StoreEndpointWriteOptions & {
|
|
35
|
+
position?: StoreMemoryPosition;
|
|
36
|
+
};
|
|
37
|
+
type StoreMemory<T = unknown, I extends keyof T = keyof T> = {
|
|
38
|
+
setUnit: (unit: T | null) => void;
|
|
39
|
+
setUnits: (units: T[]) => void;
|
|
40
|
+
editUnit: (unit: PartialWithIndicator<T, I>) => void;
|
|
41
|
+
editUnits: (units: PartialWithIndicator<T, I>[]) => void;
|
|
42
|
+
dropUnit: (unit: PartialWithIndicator<T, I>) => void;
|
|
43
|
+
dropUnits: (units: PartialWithIndicator<T, I>[]) => void;
|
|
44
|
+
};
|
|
45
|
+
type StoreEndpoint<T = unknown, I extends keyof T = keyof T> = {
|
|
46
|
+
getUnit: (unit?: PartialWithIndicator<T, I>, options?: StoreEndpointReadOptions) => Promise<T>;
|
|
47
|
+
getUnits: (options?: StoreEndpointReadOptions) => Promise<T[]>;
|
|
48
|
+
postUnit: (unit: WithIndicator<T, I>, options?: StoreEndpointWriteOptions) => Promise<T>;
|
|
49
|
+
postUnits: (units: WithIndicator<T, I>[], options?: StoreEndpointWriteMultipleOptions) => Promise<T[]>;
|
|
50
|
+
putUnit: (unit: WithIndicator<T, I>, options?: StoreEndpointWriteOptions) => Promise<T>;
|
|
51
|
+
putUnits: (units: WithIndicator<T, I>[], options?: StoreEndpointWriteOptions) => Promise<T[]>;
|
|
52
|
+
patchUnit: (unit: PartialWithIndicator<T, I>, options?: StoreEndpointWriteOptions) => Promise<Partial<T>>;
|
|
53
|
+
patchUnits: (units: PartialWithIndicator<T, I>[], options?: StoreEndpointWriteOptions) => Promise<Partial<T>[]>;
|
|
54
|
+
deleteUnit: (unit: PartialWithIndicator<T, I>, options?: StoreEndpointReadOptions) => Promise<boolean>;
|
|
55
|
+
deleteUnits: (units: PartialWithIndicator<T, I>[], options?: StoreEndpointReadOptions) => Promise<boolean>;
|
|
56
|
+
};
|
|
57
|
+
type StoreMonitor = {
|
|
58
|
+
[K in Endpoint as EndpointStatusName<K, EndpointStatus>]: ComputedRef<boolean>;
|
|
59
|
+
};
|
|
60
|
+
export type Store<E extends string = string, T = unknown, I extends keyof T = keyof T> = {
|
|
61
|
+
store: any;
|
|
62
|
+
alias: {
|
|
63
|
+
unit: E;
|
|
64
|
+
units: Pluralize<E>;
|
|
71
65
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
patchEndpointMemory: (payload: {
|
|
79
|
-
key: Endpoint;
|
|
80
|
-
memory: EndpointMemory;
|
|
81
|
-
}) => void;
|
|
82
|
-
purgeEndpointMemory: (payload?: unknown) => void;
|
|
83
|
-
getUnit: (unit?: Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & Partial<z.core.$InferObjectOutput<T, {}>>, options?: Omit<ApiActionOptions<ApiAction.GET>, "body">) => Promise<z.core.$InferObjectOutput<T, {}>>;
|
|
84
|
-
getUnits: (options?: Omit<ApiActionOptions<ApiAction.GET>, "body">) => Promise<z.core.$InferObjectOutput<T, {}>[]>;
|
|
85
|
-
postUnit: (unit: Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & z.core.$InferObjectOutput<T, {}>, options?: ApiActionOptions<ApiAction.POST> & {
|
|
86
|
-
validate?: boolean;
|
|
87
|
-
}) => Promise<Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & z.core.$InferObjectOutput<T, {}>>;
|
|
88
|
-
postUnits: (units: (Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & z.core.$InferObjectOutput<T, {}>)[], options?: ApiActionOptions<ApiAction.POST> & {
|
|
89
|
-
validate?: boolean;
|
|
90
|
-
position?: StoreMemoryPosition;
|
|
91
|
-
}) => Promise<(Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & z.core.$InferObjectOutput<T, {}>)[]>;
|
|
92
|
-
putUnit: (unit: Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & z.core.$InferObjectOutput<T, {}>, options?: ApiActionOptions<ApiAction.PUT> & {
|
|
93
|
-
validate?: boolean;
|
|
94
|
-
}) => Promise<Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & z.core.$InferObjectOutput<T, {}>>;
|
|
95
|
-
putUnits: (units: (Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & z.core.$InferObjectOutput<T, {}>)[], options?: ApiActionOptions<ApiAction.PUT> & {
|
|
96
|
-
validate?: boolean;
|
|
97
|
-
}) => Promise<(Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & z.core.$InferObjectOutput<T, {}>)[]>;
|
|
98
|
-
patchUnit: (unit: Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & Partial<z.core.$InferObjectOutput<T, {}>>, options?: ApiActionOptions<ApiAction.PATCH> & {
|
|
99
|
-
validate?: boolean;
|
|
100
|
-
}) => Promise<Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & Partial<z.core.$InferObjectOutput<T, {}>>>;
|
|
101
|
-
patchUnits: (units: (Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & Partial<z.core.$InferObjectOutput<T, {}>>)[], options?: ApiActionOptions<ApiAction.PATCH> & {
|
|
102
|
-
validate?: boolean;
|
|
103
|
-
}) => Promise<(Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & Partial<z.core.$InferObjectOutput<T, {}>>)[]>;
|
|
104
|
-
deleteUnit: (unit: Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & Partial<z.core.$InferObjectOutput<T, {}>>, options?: Omit<ApiActionOptions<ApiAction.DELETE>, "body">) => Promise<boolean>;
|
|
105
|
-
deleteUnits: (units: (Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & Partial<z.core.$InferObjectOutput<T, {}>>)[], options?: Omit<ApiActionOptions<ApiAction.DELETE>, "body">) => Promise<boolean>;
|
|
66
|
+
indicator: I;
|
|
67
|
+
unit: ComputedRef<T | null>;
|
|
68
|
+
units: ComputedRef<T[]>;
|
|
69
|
+
memory: StoreMemory<T, I>;
|
|
70
|
+
endpoint: StoreEndpoint<T, I>;
|
|
71
|
+
monitor: StoreMonitor;
|
|
106
72
|
};
|
|
73
|
+
export declare function createStore<E extends string, T extends z.ZodRawShape, S extends z.infer<z.ZodObject<T>> = z.infer<z.ZodObject<T>>, I extends keyof S = "id" & keyof S>(entity: E, schema: z.ZodObject<T>, endpoints?: Partial<Record<Endpoint, EndpointDefinition<Partial<S>>>>, options?: StoreOptions): Store<E, S, I>;
|
|
74
|
+
export {};
|