@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Amir Reza Dalir
3
+ Copyright (c) 2026 DiPhyx
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,16 +1,18 @@
1
1
  # Harlemify
2
2
 
3
- API state management for Nuxt powered by [Harlem](https://harlemjs.com/)
3
+ > Schema-driven state management for Nuxt powered by [Harlem](https://harlemjs.com/)
4
4
 
5
5
  ![Harlemify](https://raw.githubusercontent.com/diphyx/harlemify/main/docs/_media/icon.svg)
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 with field metadata
10
- - Automatic API client with runtime config
11
- - CRUD operations with endpoint status tracking
12
- - Type-safe endpoint URL parameters
13
- - SSR support via Harlem SSR plugin
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, createStore, Endpoint, ApiAction } from "@diphyx/harlemify";
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
- actions: [ApiAction.POST, ApiAction.PATCH],
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
- action: ApiAction.GET,
53
- url: "/users",
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
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0 || >=4.0.0"
6
6
  },
7
- "version": "0.0.2",
7
+ "version": "1.0.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "unknown"
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 { type MaybeRefOrGetter } from "vue";
2
- export declare enum ApiAction {
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 ApiAction = ApiAction, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery, B extends ApiRequestBody = ApiRequestBody> {
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 ApiActionOptions<A extends ApiAction, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery, B extends ApiRequestBody = ApiRequestBody> = Omit<ApiRequestOptions<A, H, Q, B>, "action">;
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 declare function createApi(options?: ApiOptions): {
58
- get: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery>(url: string, options?: ApiActionOptions<ApiAction.GET, H, Q, never>) => Promise<T>;
59
- post: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery, B extends ApiRequestBody = ApiRequestBody>(url: string, options?: ApiActionOptions<ApiAction.POST, H, Q, B>) => Promise<T>;
60
- put: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery, B extends ApiRequestBody = ApiRequestBody>(url: string, options?: ApiActionOptions<ApiAction.PUT, H, Q, B>) => Promise<T>;
61
- patch: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery, B extends ApiRequestBody = ApiRequestBody>(url: string, options?: ApiActionOptions<ApiAction.PATCH, H, Q, B>) => Promise<T>;
62
- del: <T, H extends ApiRequestHeader = ApiRequestHeader, Q extends ApiRequestQuery = ApiRequestQuery>(url: string, options?: ApiActionOptions<ApiAction.DELETE, H, Q, never>) => Promise<T>;
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;
@@ -1,12 +1,5 @@
1
1
  import { toValue } from "vue";
2
- export var ApiAction = /* @__PURE__ */ ((ApiAction2) => {
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 || "Unknown error");
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 ?? "get" /* GET */,
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: "get" /* GET */
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: "post" /* POST */
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: "put" /* PUT */
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: "patch" /* PATCH */
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: "delete" /* DELETE */
106
+ action: EndpointMethod.DELETE
113
107
  });
114
108
  }
115
109
  return {
@@ -1,106 +1,74 @@
1
- import { z } from "zod";
2
- import { type Extension, type BaseState } from "@harlem/core";
3
- import { Endpoint, type EndpointDefinition, type EndpointMemory } from "../utils/endpoint.js";
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
- import { ApiAction, type ApiActionOptions, type ApiOptions } from "./api.js";
9
- export declare function createStore<T extends z.ZodRawShape, K extends keyof z.infer<z.ZodObject<T>> = "id" & keyof z.infer<z.ZodObject<T>>>(name: string, schema: z.ZodObject<T>, endpoints?: Partial<Record<Endpoint, EndpointDefinition<Partial<z.infer<z.ZodObject<T>>>>>>, options?: {
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
- api: () => {
14
- get: <T_1, H extends import("./api").ApiRequestHeader = import("./api").ApiRequestHeader, Q extends import("./api").ApiRequestQuery = import("./api").ApiRequestQuery>(url: string, options?: ApiActionOptions<ApiAction.GET, H, Q, never>) => Promise<T_1>;
15
- post: <T_1, H extends import("./api").ApiRequestHeader = import("./api").ApiRequestHeader, Q extends import("./api").ApiRequestQuery = import("./api").ApiRequestQuery, B extends import("./api").ApiRequestBody = import("./api").ApiRequestBody>(url: string, options?: ApiActionOptions<ApiAction.POST, H, Q, B>) => Promise<T_1>;
16
- put: <T_1, H extends import("./api").ApiRequestHeader = import("./api").ApiRequestHeader, Q extends import("./api").ApiRequestQuery = import("./api").ApiRequestQuery, B extends import("./api").ApiRequestBody = import("./api").ApiRequestBody>(url: string, options?: ApiActionOptions<ApiAction.PUT, H, Q, B>) => Promise<T_1>;
17
- patch: <T_1, H extends import("./api").ApiRequestHeader = import("./api").ApiRequestHeader, Q extends import("./api").ApiRequestQuery = import("./api").ApiRequestQuery, B extends import("./api").ApiRequestBody = import("./api").ApiRequestBody>(url: string, options?: ApiActionOptions<ApiAction.PATCH, H, Q, B>) => Promise<T_1>;
18
- del: <T_1, H extends import("./api").ApiRequestHeader = import("./api").ApiRequestHeader, Q extends import("./api").ApiRequestQuery = import("./api").ApiRequestQuery>(url: string, options?: ApiActionOptions<ApiAction.DELETE, H, Q, never>) => Promise<T_1>;
19
- };
20
- store: Omit<import("@harlem/core").Store<{
21
- memory: {
22
- unit: z.core.$InferObjectOutput<T, {}> | null;
23
- units: z.core.$InferObjectOutput<T, {}>[];
24
- };
25
- endpoints: Record<Endpoint, EndpointMemory>;
26
- }>, never>;
27
- memorizedUnit: import("@vue/reactivity").ComputedRef<import("@vue/reactivity").DeepReadonly<z.core.$InferObjectOutput<T, {}>> | null>;
28
- memorizedUnits: import("@vue/reactivity").ComputedRef<readonly import("@vue/reactivity").DeepReadonly<z.core.$InferObjectOutput<T, {}>>[]>;
29
- hasMemorizedUnits: (...units: (Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & Partial<z.core.$InferObjectOutput<T, {}>>)[]) => Record<string | number, boolean>;
30
- endpointsStatus: {
31
- getUnitIsIdle: import("@vue/reactivity").ComputedRef<boolean>;
32
- getUnitIsPending: import("@vue/reactivity").ComputedRef<boolean>;
33
- getUnitIsSuccess: import("@vue/reactivity").ComputedRef<boolean>;
34
- getUnitIsFailed: import("@vue/reactivity").ComputedRef<boolean>;
35
- getUnitsIsIdle: import("@vue/reactivity").ComputedRef<boolean>;
36
- getUnitsIsPending: import("@vue/reactivity").ComputedRef<boolean>;
37
- getUnitsIsSuccess: import("@vue/reactivity").ComputedRef<boolean>;
38
- getUnitsIsFailed: import("@vue/reactivity").ComputedRef<boolean>;
39
- postUnitIsIdle: import("@vue/reactivity").ComputedRef<boolean>;
40
- postUnitIsPending: import("@vue/reactivity").ComputedRef<boolean>;
41
- postUnitIsSuccess: import("@vue/reactivity").ComputedRef<boolean>;
42
- postUnitIsFailed: import("@vue/reactivity").ComputedRef<boolean>;
43
- postUnitsIsIdle: import("@vue/reactivity").ComputedRef<boolean>;
44
- postUnitsIsPending: import("@vue/reactivity").ComputedRef<boolean>;
45
- postUnitsIsSuccess: import("@vue/reactivity").ComputedRef<boolean>;
46
- postUnitsIsFailed: import("@vue/reactivity").ComputedRef<boolean>;
47
- putUnitIsIdle: import("@vue/reactivity").ComputedRef<boolean>;
48
- putUnitIsPending: import("@vue/reactivity").ComputedRef<boolean>;
49
- putUnitIsSuccess: import("@vue/reactivity").ComputedRef<boolean>;
50
- putUnitIsFailed: import("@vue/reactivity").ComputedRef<boolean>;
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
- setMemorizedUnit: import("@harlem/core").Mutation<z.core.$InferObjectOutput<T, {}> | null, void>;
73
- setMemorizedUnits: (payload: z.core.$InferObjectOutput<T, {}>[]) => void;
74
- editMemorizedUnit: import("@harlem/core").Mutation<Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & Partial<z.core.$InferObjectOutput<T, {}>>, void>;
75
- editMemorizedUnits: (payload: (Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & Partial<z.core.$InferObjectOutput<T, {}>>)[]) => void;
76
- dropMemorizedUnit: import("@harlem/core").Mutation<Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & Partial<z.core.$InferObjectOutput<T, {}>>, void>;
77
- dropMemorizedUnits: (payload: (Required<Pick<z.core.$InferObjectOutput<T, {}>, K>> & Partial<z.core.$InferObjectOutput<T, {}>>)[]) => void;
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 {};