@diphyx/harlemify 5.2.0 → 5.4.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/README.md +95 -31
- package/dist/module.json +2 -2
- package/dist/module.mjs +5 -3
- package/dist/runtime/composables/action.d.ts +4 -4
- package/dist/runtime/composables/compose.d.ts +9 -0
- package/dist/runtime/composables/compose.js +10 -0
- package/dist/runtime/composables/model.d.ts +3 -3
- package/dist/runtime/composables/view.d.ts +3 -4
- package/dist/runtime/composables/view.js +2 -14
- package/dist/runtime/core/layers/model.js +36 -7
- package/dist/runtime/core/store.d.ts +2 -1
- package/dist/runtime/core/store.js +41 -24
- package/dist/runtime/core/types/action.d.ts +43 -30
- package/dist/runtime/core/types/action.js +5 -0
- package/dist/runtime/core/types/base.d.ts +1 -2
- package/dist/runtime/core/types/compose.d.ts +18 -0
- package/dist/runtime/core/types/compose.js +0 -0
- package/dist/runtime/core/types/model.d.ts +61 -30
- package/dist/runtime/core/types/model.js +15 -5
- package/dist/runtime/core/types/shape.d.ts +0 -6
- package/dist/runtime/core/types/store.d.ts +6 -2
- package/dist/runtime/core/utils/action.js +4 -1
- package/dist/runtime/core/utils/base.d.ts +2 -1
- package/dist/runtime/core/utils/base.js +4 -5
- package/dist/runtime/core/utils/compose.d.ts +3 -0
- package/dist/runtime/core/utils/compose.js +37 -0
- package/dist/runtime/core/utils/model.js +174 -165
- package/dist/runtime/core/utils/shape.d.ts +4 -3
- package/dist/runtime/core/utils/shape.js +84 -124
- package/dist/runtime/core/utils/store.d.ts +1 -1
- package/dist/runtime/core/utils/store.js +5 -6
- package/dist/runtime/core/utils/view.js +1 -1
- package/dist/runtime/index.d.ts +5 -2
- package/dist/runtime/index.js +3 -2
- package/dist/runtime/plugin.js +3 -17
- package/dist/runtime/plugins/ssr.d.ts +9 -0
- package/dist/runtime/plugins/ssr.js +53 -0
- package/package.json +17 -18
|
@@ -3,9 +3,13 @@ import type { Shape, ShapeType } from "./shape.js";
|
|
|
3
3
|
export interface RuntimeModelConfig {
|
|
4
4
|
identifier?: string;
|
|
5
5
|
}
|
|
6
|
-
export declare enum
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export declare enum ModelType {
|
|
7
|
+
ONE = "one",
|
|
8
|
+
MANY = "many"
|
|
9
|
+
}
|
|
10
|
+
export declare enum ModelManyKind {
|
|
11
|
+
LIST = "list",
|
|
12
|
+
RECORD = "record"
|
|
9
13
|
}
|
|
10
14
|
export declare enum ModelOneMode {
|
|
11
15
|
SET = "set",
|
|
@@ -19,27 +23,35 @@ export declare enum ModelManyMode {
|
|
|
19
23
|
REMOVE = "remove",
|
|
20
24
|
ADD = "add"
|
|
21
25
|
}
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
export declare enum ModelSilent {
|
|
27
|
+
PRE = "pre",
|
|
28
|
+
POST = "post"
|
|
25
29
|
}
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
export type ModelDefaultIdentifier<S extends Shape> = "id" extends keyof S ? "id" : keyof S;
|
|
31
|
+
export type AtLeastOne<S extends Shape> = {
|
|
32
|
+
[K in keyof S]: Pick<S, K>;
|
|
33
|
+
}[keyof S];
|
|
34
|
+
export interface ModelDefinitionOptions {
|
|
35
|
+
pre?: () => void;
|
|
36
|
+
post?: () => void;
|
|
29
37
|
}
|
|
30
38
|
export interface ModelOneDefinition<S extends Shape> extends BaseDefinition {
|
|
31
39
|
shape: ShapeType<S>;
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
type: ModelType.ONE;
|
|
41
|
+
default: () => S;
|
|
42
|
+
options?: ModelDefinitionOptions;
|
|
34
43
|
}
|
|
35
|
-
export interface ModelManyDefinition<S extends Shape> extends BaseDefinition {
|
|
44
|
+
export interface ModelManyDefinition<S extends Shape, I extends keyof S = ModelDefaultIdentifier<S>, T extends ModelManyKind = ModelManyKind.LIST> extends BaseDefinition {
|
|
36
45
|
shape: ShapeType<S>;
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
type: ModelType.MANY;
|
|
47
|
+
kind: T;
|
|
48
|
+
identifier: [T] extends [ModelManyKind.LIST] ? I : never;
|
|
49
|
+
default: () => [T] extends [ModelManyKind.LIST] ? S[] : Record<string, S[]>;
|
|
50
|
+
options?: ModelDefinitionOptions;
|
|
39
51
|
}
|
|
40
|
-
export type ModelDefinition<S extends Shape> = ModelOneDefinition<S> | ModelManyDefinition<S>;
|
|
52
|
+
export type ModelDefinition<S extends Shape> = ModelOneDefinition<S> | ModelManyDefinition<S, any, any>;
|
|
41
53
|
export type ModelDefinitions = Record<string, ModelDefinition<any>>;
|
|
42
|
-
export type ModelDefinitionInfer<MD extends ModelDefinitions, K extends keyof MD> = MD[K] extends ModelOneDefinition<infer S> ? S
|
|
54
|
+
export type ModelDefinitionInfer<MD extends ModelDefinitions, K extends keyof MD> = MD[K] extends ModelOneDefinition<infer S> ? S : MD[K] extends ModelManyDefinition<infer S, any, infer T> ? [T] extends [ModelManyKind.LIST] ? S[] : Record<string, S[]> : never;
|
|
43
55
|
export type ModelDefinitionInferTuple<MD extends ModelDefinitions, K extends readonly (keyof MD)[]> = {
|
|
44
56
|
[I in keyof K]: K[I] extends keyof MD ? ModelDefinitionInfer<MD, K[I]> : never;
|
|
45
57
|
};
|
|
@@ -47,39 +59,58 @@ export type ModelDefinitionsInfer<MD extends ModelDefinitions> = {
|
|
|
47
59
|
[K in keyof MD]: ModelDefinitionInfer<MD, K>;
|
|
48
60
|
};
|
|
49
61
|
export interface ModelFactory {
|
|
50
|
-
one<S extends Shape>(shape: ShapeType<S>, options?:
|
|
51
|
-
|
|
62
|
+
one<S extends Shape>(shape: ShapeType<S>, options?: ModelDefinitionOptions & {
|
|
63
|
+
default?: () => S;
|
|
64
|
+
}): ModelOneDefinition<S>;
|
|
65
|
+
many<S extends Shape, I extends keyof S = ModelDefaultIdentifier<S>, T extends ModelManyKind = ModelManyKind.LIST>(shape: ShapeType<S>, options?: ModelDefinitionOptions & {
|
|
66
|
+
kind?: T;
|
|
67
|
+
identifier?: [T] extends [ModelManyKind.LIST] ? I : never;
|
|
68
|
+
default?: () => [T] extends [ModelManyKind.LIST] ? S[] : Record<string, S[]>;
|
|
69
|
+
}): ModelManyDefinition<S, I, T>;
|
|
52
70
|
}
|
|
53
71
|
export interface ModelOneCommitOptions {
|
|
54
72
|
deep?: boolean;
|
|
73
|
+
silent?: true | ModelSilent;
|
|
55
74
|
}
|
|
56
75
|
export interface ModelManyCommitOptions {
|
|
57
76
|
by?: string;
|
|
58
77
|
prepend?: boolean;
|
|
59
78
|
unique?: boolean;
|
|
60
79
|
deep?: boolean;
|
|
80
|
+
silent?: true | ModelSilent;
|
|
61
81
|
}
|
|
62
82
|
export interface ModelOneCommit<S extends Shape> {
|
|
63
|
-
set: (
|
|
64
|
-
reset: () => void;
|
|
65
|
-
patch: (
|
|
83
|
+
set: (payload: S, options?: Pick<ModelOneCommitOptions, "silent">) => void;
|
|
84
|
+
reset: (options?: Pick<ModelOneCommitOptions, "silent">) => void;
|
|
85
|
+
patch: (payload: Partial<S>, options?: Pick<ModelOneCommitOptions, "deep" | "silent">) => void;
|
|
86
|
+
}
|
|
87
|
+
export interface ModelManyListCommit<S extends Shape, I extends keyof S = ModelDefaultIdentifier<S>> {
|
|
88
|
+
set: (payload: S[], options?: Pick<ModelManyCommitOptions, "silent">) => void;
|
|
89
|
+
reset: (options?: Pick<ModelManyCommitOptions, "silent">) => void;
|
|
90
|
+
patch: (payload: Partial<S> | Partial<S>[], options?: Pick<ModelManyCommitOptions, "by" | "deep" | "silent">) => void;
|
|
91
|
+
remove: (payload: Pick<S, I> | Pick<S, I>[] | AtLeastOne<S> | AtLeastOne<S>[], options?: Pick<ModelManyCommitOptions, "silent">) => void;
|
|
92
|
+
add: (payload: S | S[], options?: Pick<ModelManyCommitOptions, "by" | "prepend" | "unique" | "silent">) => void;
|
|
66
93
|
}
|
|
67
|
-
export interface
|
|
68
|
-
set: (
|
|
69
|
-
reset: () => void;
|
|
70
|
-
patch: (
|
|
71
|
-
remove: (
|
|
72
|
-
add: (
|
|
94
|
+
export interface ModelManyRecordCommit<S extends Shape> {
|
|
95
|
+
set: (payload: Record<string, S[]>, options?: Pick<ModelOneCommitOptions, "silent">) => void;
|
|
96
|
+
reset: (options?: Pick<ModelOneCommitOptions, "silent">) => void;
|
|
97
|
+
patch: (payload: Record<string, S[]>, options?: Pick<ModelOneCommitOptions, "deep" | "silent">) => void;
|
|
98
|
+
remove: (payload: string, options?: Pick<ModelOneCommitOptions, "silent">) => void;
|
|
99
|
+
add: (payload: {
|
|
100
|
+
key: string;
|
|
101
|
+
value: S[];
|
|
102
|
+
}, options?: Pick<ModelOneCommitOptions, "silent">) => void;
|
|
73
103
|
}
|
|
104
|
+
export type ModelManyCommit<S extends Shape, I extends keyof S = ModelDefaultIdentifier<S>, T extends ModelManyKind = ModelManyKind.LIST> = [T] extends [ModelManyKind.LIST] ? ModelManyListCommit<S, I> : ModelManyRecordCommit<S>;
|
|
74
105
|
export type ModelOneCall<S extends Shape> = ModelOneCommit<S> & {
|
|
75
106
|
commit(mode: string, value?: unknown, options?: unknown): void;
|
|
76
107
|
aliases(): Record<string, string>;
|
|
77
108
|
};
|
|
78
|
-
export type ModelManyCall<S extends Shape> = ModelManyCommit<S> & {
|
|
109
|
+
export type ModelManyCall<S extends Shape, I extends keyof S = ModelDefaultIdentifier<S>, T extends ModelManyKind = ModelManyKind.LIST> = ModelManyCommit<S, I, T> & {
|
|
79
110
|
commit(mode: string, value?: unknown, options?: unknown): void;
|
|
80
111
|
aliases(): Record<string, string>;
|
|
81
112
|
};
|
|
82
|
-
export type ModelCall<S extends Shape> = ModelOneCall<S> | ModelManyCall<S>;
|
|
113
|
+
export type ModelCall<S extends Shape> = ModelOneCall<S> | ModelManyCall<S, any, any>;
|
|
83
114
|
export type StoreModel<MD extends ModelDefinitions> = {
|
|
84
|
-
[K in keyof MD]: MD[K] extends ModelOneDefinition<infer S> ? ModelOneCall<S> : MD[K] extends ModelManyDefinition<infer S> ? ModelManyCall<S> : never;
|
|
115
|
+
[K in keyof MD]: MD[K] extends ModelOneDefinition<infer S> ? ModelOneCall<S> : MD[K] extends ModelManyDefinition<infer S, infer I, infer T> ? ModelManyCall<S, I, T> : never;
|
|
85
116
|
};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
export var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return
|
|
5
|
-
})(
|
|
1
|
+
export var ModelType = /* @__PURE__ */ ((ModelType2) => {
|
|
2
|
+
ModelType2["ONE"] = "one";
|
|
3
|
+
ModelType2["MANY"] = "many";
|
|
4
|
+
return ModelType2;
|
|
5
|
+
})(ModelType || {});
|
|
6
|
+
export var ModelManyKind = /* @__PURE__ */ ((ModelManyKind2) => {
|
|
7
|
+
ModelManyKind2["LIST"] = "list";
|
|
8
|
+
ModelManyKind2["RECORD"] = "record";
|
|
9
|
+
return ModelManyKind2;
|
|
10
|
+
})(ModelManyKind || {});
|
|
6
11
|
export var ModelOneMode = /* @__PURE__ */ ((ModelOneMode2) => {
|
|
7
12
|
ModelOneMode2["SET"] = "set";
|
|
8
13
|
ModelOneMode2["RESET"] = "reset";
|
|
@@ -17,3 +22,8 @@ export var ModelManyMode = /* @__PURE__ */ ((ModelManyMode2) => {
|
|
|
17
22
|
ModelManyMode2["ADD"] = "add";
|
|
18
23
|
return ModelManyMode2;
|
|
19
24
|
})(ModelManyMode || {});
|
|
25
|
+
export var ModelSilent = /* @__PURE__ */ ((ModelSilent2) => {
|
|
26
|
+
ModelSilent2["PRE"] = "pre";
|
|
27
|
+
ModelSilent2["POST"] = "post";
|
|
28
|
+
return ModelSilent2;
|
|
29
|
+
})(ModelSilent || {});
|
|
@@ -7,12 +7,6 @@ export type ShapeInfer<T extends z.ZodType<any>> = z.infer<T>;
|
|
|
7
7
|
export type ShapeCall<T extends ShapeRawDefinition> = z.ZodObject<T> & {
|
|
8
8
|
defaults: (overrides?: Partial<z.infer<z.ZodObject<T>>>) => z.infer<z.ZodObject<T>>;
|
|
9
9
|
};
|
|
10
|
-
export interface ShapeResolved<T extends ShapeDefinition = ShapeDefinition> {
|
|
11
|
-
identifier?: keyof T["shape"] & string;
|
|
12
|
-
defaults: Record<string, unknown>;
|
|
13
|
-
fields: (keyof T["shape"] & string)[];
|
|
14
|
-
aliases: Record<string, string>;
|
|
15
|
-
}
|
|
16
10
|
export interface ShapeFieldDefinition {
|
|
17
11
|
meta?: {
|
|
18
12
|
identifier?: boolean;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import type { ModelDefinitions, ModelFactory, StoreModel } from "./model.js";
|
|
2
2
|
import type { ViewDefinitions, ViewFactory, StoreView } from "./view.js";
|
|
3
3
|
import type { ActionDefinitions, ActionFactory, StoreAction } from "./action.js";
|
|
4
|
-
|
|
4
|
+
import type { ComposeDefinitions, ComposeContext, StoreCompose } from "./compose.js";
|
|
5
|
+
export interface StoreConfig<MD extends ModelDefinitions, VD extends ViewDefinitions<MD>, AD extends ActionDefinitions<MD, VD>, CD extends ComposeDefinitions = ComposeDefinitions> {
|
|
5
6
|
name: string;
|
|
6
7
|
model: (factory: ModelFactory) => MD;
|
|
7
8
|
view: (factory: ViewFactory<MD>) => VD;
|
|
8
9
|
action: (factory: ActionFactory<MD, VD>) => AD;
|
|
10
|
+
compose?: (context: ComposeContext<MD, VD, AD>) => CD;
|
|
11
|
+
lazy?: boolean;
|
|
9
12
|
}
|
|
10
|
-
export interface Store<MD extends ModelDefinitions, VD extends ViewDefinitions<MD>, AD extends ActionDefinitions<MD, VD
|
|
13
|
+
export interface Store<MD extends ModelDefinitions, VD extends ViewDefinitions<MD>, AD extends ActionDefinitions<MD, VD>, CD extends ComposeDefinitions = ComposeDefinitions> {
|
|
11
14
|
model: StoreModel<MD>;
|
|
12
15
|
view: StoreView<MD, VD>;
|
|
13
16
|
action: StoreAction<MD, VD, AD>;
|
|
17
|
+
compose: StoreCompose<CD>;
|
|
14
18
|
}
|
|
@@ -2,6 +2,7 @@ import { defu } from "defu";
|
|
|
2
2
|
import { ref, computed, readonly, toValue, nextTick } from "vue";
|
|
3
3
|
import {
|
|
4
4
|
ActionApiMethod,
|
|
5
|
+
ActionType,
|
|
5
6
|
ActionStatus,
|
|
6
7
|
ActionConcurrent
|
|
7
8
|
} from "../types/action.js";
|
|
@@ -211,9 +212,10 @@ function executeCommit(definition, target, mode, data) {
|
|
|
211
212
|
}
|
|
212
213
|
}
|
|
213
214
|
export function createAction(definition, model, view) {
|
|
215
|
+
const actionType = isApiDefinition(definition) ? ActionType.API : ActionType.HANDLER;
|
|
214
216
|
definition.logger?.debug("Registering action", {
|
|
215
217
|
action: definition.key,
|
|
216
|
-
type:
|
|
218
|
+
type: actionType
|
|
217
219
|
});
|
|
218
220
|
let currentController = null;
|
|
219
221
|
let abortController = null;
|
|
@@ -304,6 +306,7 @@ export function createAction(definition, model, view) {
|
|
|
304
306
|
return currentController;
|
|
305
307
|
}
|
|
306
308
|
const action = Object.assign(execute, {
|
|
309
|
+
actionType,
|
|
307
310
|
get error() {
|
|
308
311
|
return readonly(globalError);
|
|
309
312
|
},
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { BaseDefinition } from "../types/base.js";
|
|
2
|
-
export declare function wrapBaseDefinition<T extends Omit<BaseDefinition, "key"
|
|
2
|
+
export declare function wrapBaseDefinition<T extends Omit<BaseDefinition, "key">>(definition: T): T & BaseDefinition;
|
|
3
3
|
export declare function trimStart(value: string, char: string): string;
|
|
4
4
|
export declare function trimEnd(value: string, char: string): string;
|
|
5
|
+
export declare function ensureArray<T>(value: T | T[]): T[];
|
|
5
6
|
export declare function isObject(value: unknown): value is object;
|
|
6
7
|
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
7
8
|
export declare function isEmptyRecord(record: Record<string, unknown> | undefined): record is undefined;
|
|
@@ -5,11 +5,7 @@ export function wrapBaseDefinition(definition) {
|
|
|
5
5
|
get() {
|
|
6
6
|
return key;
|
|
7
7
|
},
|
|
8
|
-
|
|
9
|
-
configurable: true
|
|
10
|
-
},
|
|
11
|
-
setKey: {
|
|
12
|
-
value(value) {
|
|
8
|
+
set(value) {
|
|
13
9
|
key = value;
|
|
14
10
|
},
|
|
15
11
|
enumerable: true,
|
|
@@ -23,6 +19,9 @@ export function trimStart(value, char) {
|
|
|
23
19
|
export function trimEnd(value, char) {
|
|
24
20
|
return value.replace(new RegExp(`${char}+$`), "");
|
|
25
21
|
}
|
|
22
|
+
export function ensureArray(value) {
|
|
23
|
+
return Array.isArray(value) ? value : [value];
|
|
24
|
+
}
|
|
26
25
|
export function isObject(value) {
|
|
27
26
|
return value != null && typeof value === "object";
|
|
28
27
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ConsolaInstance } from "consola";
|
|
2
|
+
import type { ComposeDefinitions, StoreCompose } from "../types/compose.js";
|
|
3
|
+
export declare function createStoreCompose<CD extends ComposeDefinitions>(composeConfig: ((...args: any[]) => CD) | undefined, context: Record<string, unknown>, logger?: ConsolaInstance): StoreCompose<CD>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ref, readonly } from "vue";
|
|
2
|
+
function createComposeAction(key, callback, logger) {
|
|
3
|
+
logger?.debug("Registering compose action", {
|
|
4
|
+
action: key
|
|
5
|
+
});
|
|
6
|
+
const active = ref(false);
|
|
7
|
+
async function execute(...args) {
|
|
8
|
+
active.value = true;
|
|
9
|
+
try {
|
|
10
|
+
logger?.debug("Compose action executing", {
|
|
11
|
+
action: key
|
|
12
|
+
});
|
|
13
|
+
await callback(...args);
|
|
14
|
+
logger?.debug("Compose action success", {
|
|
15
|
+
action: key
|
|
16
|
+
});
|
|
17
|
+
} finally {
|
|
18
|
+
active.value = false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return Object.assign(execute, {
|
|
22
|
+
get active() {
|
|
23
|
+
return readonly(active);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export function createStoreCompose(composeConfig, context, logger) {
|
|
28
|
+
const output = {};
|
|
29
|
+
if (!composeConfig) {
|
|
30
|
+
return output;
|
|
31
|
+
}
|
|
32
|
+
const composeDefinitions = composeConfig(context);
|
|
33
|
+
for (const [key, callback] of Object.entries(composeDefinitions)) {
|
|
34
|
+
output[key] = createComposeAction(key, callback, logger);
|
|
35
|
+
}
|
|
36
|
+
return output;
|
|
37
|
+
}
|