@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
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { createModel } from "./model.js";
|
|
2
2
|
import { createView } from "./view.js";
|
|
3
3
|
import { createAction } from "./action.js";
|
|
4
|
-
import { ModelKind } from "../types/model.js";
|
|
5
4
|
export function createStoreState(modelDefinitions) {
|
|
6
5
|
const output = {};
|
|
7
|
-
for (const [key,
|
|
8
|
-
output[key] =
|
|
6
|
+
for (const [key, definition] of Object.entries(modelDefinitions)) {
|
|
7
|
+
output[key] = definition.default();
|
|
9
8
|
}
|
|
10
9
|
return output;
|
|
11
10
|
}
|
|
12
11
|
export function createStoreModel(modelDefinitions, source) {
|
|
13
12
|
const output = {};
|
|
14
13
|
for (const [key, definition] of Object.entries(modelDefinitions)) {
|
|
15
|
-
definition.
|
|
14
|
+
definition.key = key;
|
|
16
15
|
output[key] = createModel(definition, source);
|
|
17
16
|
}
|
|
18
17
|
return output;
|
|
@@ -20,7 +19,7 @@ export function createStoreModel(modelDefinitions, source) {
|
|
|
20
19
|
export function createStoreView(viewDefinitions, source) {
|
|
21
20
|
const output = {};
|
|
22
21
|
for (const [key, definition] of Object.entries(viewDefinitions)) {
|
|
23
|
-
definition.
|
|
22
|
+
definition.key = key;
|
|
24
23
|
output[key] = createView(definition, source);
|
|
25
24
|
}
|
|
26
25
|
return output;
|
|
@@ -28,7 +27,7 @@ export function createStoreView(viewDefinitions, source) {
|
|
|
28
27
|
export function createStoreAction(actionDefinitions, model, view) {
|
|
29
28
|
const output = {};
|
|
30
29
|
for (const [key, definition] of Object.entries(actionDefinitions)) {
|
|
31
|
-
definition.
|
|
30
|
+
definition.key = key;
|
|
32
31
|
output[key] = createAction(definition, model, view);
|
|
33
32
|
}
|
|
34
33
|
return output;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ViewClone } from "../types/view.js";
|
|
2
2
|
function resolveClonedValue(definition, value) {
|
|
3
|
-
if (!definition.options?.clone
|
|
3
|
+
if (!definition.options?.clone) {
|
|
4
4
|
return value;
|
|
5
5
|
}
|
|
6
6
|
if (definition.options.clone === ViewClone.DEEP) {
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -2,13 +2,16 @@ export { createStore } from "./core/store.js";
|
|
|
2
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 {
|
|
5
|
+
export { ModelType, ModelManyKind, ModelOneMode, ModelManyMode, ModelSilent } from "./core/types/model.js";
|
|
6
6
|
export type { ModelOneCommitOptions, ModelManyCommitOptions } from "./core/types/model.js";
|
|
7
7
|
export { ViewClone } from "./core/types/view.js";
|
|
8
8
|
export type { ViewDefinitionOptions } from "./core/types/view.js";
|
|
9
|
-
export { ActionStatus, ActionConcurrent, ActionApiMethod } from "./core/types/action.js";
|
|
9
|
+
export { ActionStatus, ActionConcurrent, ActionType, ActionApiMethod } from "./core/types/action.js";
|
|
10
10
|
export type { ActionCall, ActionApiCall, ActionHandlerCall, ActionCallOptions, ActionCallBaseOptions, ActionApiCallOptions, ActionHandlerCallOptions, ActionCallTransformerOptions, ActionCallBindOptions, ActionCallCommitOptions, ActionHandlerOptions, ActionResolvedApi, } from "./core/types/action.js";
|
|
11
11
|
export { ActionApiError, ActionHandlerError, ActionCommitError, ActionConcurrentError } from "./core/utils/error.js";
|
|
12
|
+
export type { ComposeCallback, ComposeCall, ComposeDefinitions, ComposeContext, StoreCompose, } from "./core/types/compose.js";
|
|
13
|
+
export { useStoreCompose } from "./composables/compose.js";
|
|
14
|
+
export type { UseStoreCompose } from "./composables/compose.js";
|
|
12
15
|
export { useIsolatedActionStatus, useIsolatedActionError, useStoreAction } from "./composables/action.js";
|
|
13
16
|
export type { UseStoreActionOptions, UseStoreAction } from "./composables/action.js";
|
|
14
17
|
export { useStoreModel } from "./composables/model.js";
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { createStore } from "./core/store.js";
|
|
2
2
|
export { shape } from "./core/layers/shape.js";
|
|
3
|
-
export {
|
|
3
|
+
export { ModelType, ModelManyKind, ModelOneMode, ModelManyMode, ModelSilent } from "./core/types/model.js";
|
|
4
4
|
export { ViewClone } from "./core/types/view.js";
|
|
5
|
-
export { ActionStatus, ActionConcurrent, ActionApiMethod } from "./core/types/action.js";
|
|
5
|
+
export { ActionStatus, ActionConcurrent, ActionType, ActionApiMethod } from "./core/types/action.js";
|
|
6
6
|
export { ActionApiError, ActionHandlerError, ActionCommitError, ActionConcurrentError } from "./core/utils/error.js";
|
|
7
|
+
export { useStoreCompose } from "./composables/compose.js";
|
|
7
8
|
export { useIsolatedActionStatus, useIsolatedActionError, useStoreAction } from "./composables/action.js";
|
|
8
9
|
export { useStoreModel } from "./composables/model.js";
|
|
9
10
|
export { useStoreView } from "./composables/view.js";
|
package/dist/runtime/plugin.js
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
import { createVuePlugin } from "@harlem/core";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { defineNuxtPlugin } from "#imports";
|
|
3
|
+
import { createServerSideRenderingPlugin } from "./plugins/ssr.js";
|
|
4
4
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
5
|
-
const plugins = [];
|
|
6
|
-
if (import.meta.server) {
|
|
7
|
-
plugins.push(createServerSSRPlugin());
|
|
8
|
-
}
|
|
9
|
-
if (import.meta.client && window["__harlemState"]) {
|
|
10
|
-
plugins.push(createClientSSRPlugin());
|
|
11
|
-
}
|
|
12
5
|
const harlem = createVuePlugin({
|
|
13
|
-
plugins
|
|
6
|
+
plugins: [createServerSideRenderingPlugin(nuxtApp)]
|
|
14
7
|
});
|
|
15
8
|
nuxtApp.vueApp.use(harlem);
|
|
16
|
-
useHead({
|
|
17
|
-
script: [
|
|
18
|
-
{
|
|
19
|
-
innerHTML: getBridgingScript()
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
});
|
|
23
9
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HarlemPlugin } from "@harlem/core";
|
|
2
|
+
interface ServerSideRenderingContext {
|
|
3
|
+
hooks: {
|
|
4
|
+
hook: (name: "app:rendered", fn: () => void) => void;
|
|
5
|
+
};
|
|
6
|
+
payload: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export declare function createServerSideRenderingPlugin(nuxtApp: ServerSideRenderingContext): HarlemPlugin;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
function handleServer(nuxtApp, stores) {
|
|
2
|
+
for (const store of stores.values()) {
|
|
3
|
+
const mutations = store.registrations["mutations"];
|
|
4
|
+
if (!mutations) {
|
|
5
|
+
continue;
|
|
6
|
+
}
|
|
7
|
+
for (const [name, registration] of mutations) {
|
|
8
|
+
if (!name.endsWith(":reset")) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
registration.producer()({});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
nuxtApp.hooks.hook("app:rendered", () => {
|
|
15
|
+
const snapshot = {};
|
|
16
|
+
for (const store of stores.values()) {
|
|
17
|
+
snapshot[store.name] = store.state;
|
|
18
|
+
}
|
|
19
|
+
nuxtApp.payload.harlemifyState = snapshot;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function handleClient(nuxtApp, eventEmitter, stores) {
|
|
23
|
+
const harlemifyState = nuxtApp.payload.harlemifyState;
|
|
24
|
+
if (!harlemifyState) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
eventEmitter.on("ssr:init:client", (payload) => {
|
|
28
|
+
if (!payload) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const store = stores.get(payload.store);
|
|
32
|
+
if (!store) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const snapshot = harlemifyState[store.name];
|
|
36
|
+
if (!snapshot) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
store.write("harlemify:ssr:init", "harlemify", (state) => {
|
|
40
|
+
Object.assign(state, snapshot);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function createServerSideRenderingPlugin(nuxtApp) {
|
|
45
|
+
return (app, eventEmitter, stores) => {
|
|
46
|
+
if (import.meta.server) {
|
|
47
|
+
handleServer(nuxtApp, stores);
|
|
48
|
+
}
|
|
49
|
+
if (import.meta.client) {
|
|
50
|
+
handleClient(nuxtApp, eventEmitter, stores);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diphyx/harlemify",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "API state management for Nuxt powered by Harlem",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -41,26 +41,25 @@
|
|
|
41
41
|
"dist"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@harlem/core": "^3.
|
|
45
|
-
"@
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"zod": "^4.0.0"
|
|
44
|
+
"@harlem/core": "^3.1.8",
|
|
45
|
+
"@nuxt/kit": "^3.14.0 || ^4.0.0",
|
|
46
|
+
"consola": "^3.4.2",
|
|
47
|
+
"defu": "^6.1.4",
|
|
48
|
+
"zod": "^4.3.6"
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
|
-
"@nuxt/eslint-config": "^0.6.
|
|
53
|
-
"@nuxt/module-builder": "^0.8.
|
|
54
|
-
"@nuxt/schema": "^3.
|
|
55
|
-
"@nuxt/test-utils": "^3.
|
|
56
|
-
"@playwright/test": "^1.
|
|
57
|
-
"@types/node": "^22.
|
|
51
|
+
"@nuxt/eslint-config": "^0.6.2",
|
|
52
|
+
"@nuxt/module-builder": "^0.8.4",
|
|
53
|
+
"@nuxt/schema": "^4.3.1",
|
|
54
|
+
"@nuxt/test-utils": "^3.23.0",
|
|
55
|
+
"@playwright/test": "^1.58.2",
|
|
56
|
+
"@types/node": "^22.19.11",
|
|
58
57
|
"@vitest/coverage-v8": "^2.1.9",
|
|
59
|
-
"eslint": "^9.
|
|
60
|
-
"nuxt": "^3.
|
|
61
|
-
"typescript": "^5.
|
|
62
|
-
"vitest": "^2.
|
|
63
|
-
"vue": "^3.5.
|
|
58
|
+
"eslint": "^9.39.2",
|
|
59
|
+
"nuxt": "^4.3.1",
|
|
60
|
+
"typescript": "^5.9.3",
|
|
61
|
+
"vitest": "^2.1.9",
|
|
62
|
+
"vue": "^3.5.28"
|
|
64
63
|
},
|
|
65
64
|
"scripts": {
|
|
66
65
|
"cleanup": "pnpm nuxt cleanup && pnpm nuxt cleanup playground",
|