@diphyx/harlemify 4.0.1 → 5.1.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 +30 -44
- package/dist/module.d.mts +5 -0
- package/dist/module.d.ts +5 -0
- package/dist/module.json +1 -1
- package/dist/runtime/composables/action.d.ts +16 -3
- package/dist/runtime/composables/action.js +47 -3
- package/dist/runtime/composables/model.d.ts +22 -0
- package/dist/runtime/composables/model.js +32 -0
- package/dist/runtime/composables/view.d.ts +33 -0
- package/dist/runtime/composables/view.js +54 -0
- package/dist/runtime/core/layers/action.d.ts +3 -2
- package/dist/runtime/core/layers/action.js +37 -69
- package/dist/runtime/core/layers/model.js +14 -0
- package/dist/runtime/core/layers/shape.d.ts +2 -2
- package/dist/runtime/core/layers/shape.js +3 -2
- package/dist/runtime/core/layers/view.d.ts +2 -2
- package/dist/runtime/core/layers/view.js +27 -5
- package/dist/runtime/core/store.d.ts +5 -23
- package/dist/runtime/core/store.js +8 -28
- package/dist/runtime/core/types/action.d.ts +79 -121
- package/dist/runtime/core/types/action.js +0 -16
- package/dist/runtime/core/types/base.d.ts +6 -0
- package/dist/runtime/core/types/base.js +0 -0
- package/dist/runtime/core/types/model.d.ts +47 -32
- package/dist/runtime/core/types/model.js +14 -0
- package/dist/runtime/core/types/shape.d.ts +30 -5
- package/dist/runtime/core/types/store.d.ts +14 -0
- package/dist/runtime/core/types/store.js +0 -0
- package/dist/runtime/core/types/view.d.ts +35 -24
- package/dist/runtime/core/types/view.js +5 -0
- package/dist/runtime/core/utils/action.d.ts +4 -4
- package/dist/runtime/core/utils/action.js +217 -207
- package/dist/runtime/core/utils/base.d.ts +14 -0
- package/dist/runtime/core/utils/base.js +109 -0
- package/dist/runtime/core/utils/error.d.ts +21 -0
- package/dist/runtime/core/utils/error.js +36 -0
- package/dist/runtime/core/utils/model.d.ts +3 -11
- package/dist/runtime/core/utils/model.js +104 -110
- package/dist/runtime/core/utils/shape.d.ts +6 -3
- package/dist/runtime/core/utils/shape.js +218 -14
- package/dist/runtime/core/utils/store.d.ts +8 -0
- package/dist/runtime/core/utils/store.js +35 -0
- package/dist/runtime/core/utils/view.d.ts +3 -4
- package/dist/runtime/core/utils/view.js +35 -14
- package/dist/runtime/index.d.ts +14 -5
- package/dist/runtime/index.js +7 -10
- package/package.json +2 -1
|
@@ -1,19 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { ViewClone } from "../types/view.js";
|
|
2
|
+
function resolveClonedValue(definition, value) {
|
|
3
|
+
if (!definition.options?.clone || value === null || value === void 0) {
|
|
4
|
+
return value;
|
|
5
|
+
}
|
|
6
|
+
if (definition.options.clone === ViewClone.DEEP) {
|
|
7
|
+
return JSON.parse(JSON.stringify(value));
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
return [...value];
|
|
11
|
+
}
|
|
12
|
+
if (typeof value === "object") {
|
|
13
|
+
return { ...value };
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
function resolveModels(definition) {
|
|
18
|
+
return "model" in definition ? definition.model : definition.models;
|
|
19
|
+
}
|
|
20
|
+
export function createView(definition, source) {
|
|
21
|
+
const models = resolveModels(definition);
|
|
22
|
+
definition.logger?.debug("Registering view", {
|
|
23
|
+
view: definition.key,
|
|
24
|
+
models
|
|
25
|
+
});
|
|
26
|
+
const view = source.getter(definition.key, (state) => {
|
|
27
|
+
const values = models.map((sourceKey) => {
|
|
28
|
+
const value = state[sourceKey];
|
|
12
29
|
if (definition.resolver) {
|
|
13
|
-
return definition
|
|
30
|
+
return resolveClonedValue(definition, value);
|
|
14
31
|
}
|
|
15
|
-
return
|
|
32
|
+
return value;
|
|
16
33
|
});
|
|
17
|
-
|
|
34
|
+
if (definition.resolver) {
|
|
35
|
+
return definition.resolver(...values);
|
|
36
|
+
}
|
|
37
|
+
return values[0];
|
|
38
|
+
});
|
|
18
39
|
return view;
|
|
19
40
|
}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
export { createStore } from "./core/store.js";
|
|
2
|
-
export type { Store, StoreConfig } from "./core/store.js";
|
|
2
|
+
export type { Store, StoreConfig } from "./core/types/store.js";
|
|
3
3
|
export { shape } from "./core/layers/shape.js";
|
|
4
4
|
export type { ShapeInfer } from "./core/types/shape.js";
|
|
5
|
-
export { ModelKind } from "./core/types/model.js";
|
|
6
|
-
export {
|
|
7
|
-
export
|
|
8
|
-
export {
|
|
5
|
+
export { ModelKind, ModelOneMode, ModelManyMode } from "./core/types/model.js";
|
|
6
|
+
export type { ModelOneCommitOptions, ModelManyCommitOptions } from "./core/types/model.js";
|
|
7
|
+
export { ViewClone } from "./core/types/view.js";
|
|
8
|
+
export type { ViewDefinitionOptions } from "./core/types/view.js";
|
|
9
|
+
export { ActionStatus, ActionConcurrent, ActionApiMethod } from "./core/types/action.js";
|
|
10
|
+
export type { ActionCall, ActionCallOptions, ActionCallTransformerOptions, ActionCallBindOptions, ActionCallCommitOptions, ActionResolvedApi, } from "./core/types/action.js";
|
|
11
|
+
export { ActionApiError, ActionHandlerError, ActionCommitError, ActionConcurrentError } from "./core/utils/error.js";
|
|
12
|
+
export { useIsolatedActionStatus, useIsolatedActionError, useStoreAction } from "./composables/action.js";
|
|
13
|
+
export type { UseStoreActionOptions, UseStoreAction } from "./composables/action.js";
|
|
14
|
+
export { useStoreModel } from "./composables/model.js";
|
|
15
|
+
export type { UseStoreModelOptions, UseStoreModel } from "./composables/model.js";
|
|
16
|
+
export { useStoreView } from "./composables/view.js";
|
|
17
|
+
export type { UseStoreViewOptions, UseStoreViewProxy, UseStoreViewComputed, UseStoreViewData, UseStoreViewTrackOptions, } from "./composables/view.js";
|
|
9
18
|
export type { RuntimeConfig } from "./config.js";
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
export { createStore } from "./core/store.js";
|
|
2
2
|
export { shape } from "./core/layers/shape.js";
|
|
3
|
-
export { ModelKind } from "./core/types/model.js";
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
ActionApiMethod
|
|
11
|
-
} from "./core/types/action.js";
|
|
12
|
-
export { useIsolatedActionStatus, useIsolatedActionError } from "./composables/action.js";
|
|
3
|
+
export { ModelKind, ModelOneMode, ModelManyMode } from "./core/types/model.js";
|
|
4
|
+
export { ViewClone } from "./core/types/view.js";
|
|
5
|
+
export { ActionStatus, ActionConcurrent, ActionApiMethod } from "./core/types/action.js";
|
|
6
|
+
export { ActionApiError, ActionHandlerError, ActionCommitError, ActionConcurrentError } from "./core/utils/error.js";
|
|
7
|
+
export { useIsolatedActionStatus, useIsolatedActionError, useStoreAction } from "./composables/action.js";
|
|
8
|
+
export { useStoreModel } from "./composables/model.js";
|
|
9
|
+
export { useStoreView } from "./composables/view.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diphyx/harlemify",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "API state management for Nuxt powered by Harlem",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"@nuxt/test-utils": "^3.14.0",
|
|
56
56
|
"@playwright/test": "^1.50.0",
|
|
57
57
|
"@types/node": "^22.0.0",
|
|
58
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
58
59
|
"eslint": "^9.0.0",
|
|
59
60
|
"nuxt": "^3.14.0",
|
|
60
61
|
"typescript": "^5.6.0",
|