@foxford/den 3.1.0 → 3.1.2

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.
Files changed (58) hide show
  1. package/README.mdx +66 -15
  2. package/adapter.cjs +1 -1
  3. package/adapter.d.cts +1 -1
  4. package/adapter.d.ts +1 -1
  5. package/adapter.js +1 -1
  6. package/bin/den.cjs +88 -0
  7. package/bin/den.d.cts +2 -0
  8. package/bin/den.d.ts +2 -0
  9. package/bin/den.js +88 -0
  10. package/builder/index.cjs +12 -0
  11. package/builder/index.d.cts +124 -0
  12. package/builder/index.d.ts +124 -0
  13. package/builder/index.js +12 -0
  14. package/{chunk-KJ6NDOOL.js → chunk-3RX2OSUL.js} +1 -25
  15. package/{chunk-HJO26HIQ.js → chunk-6FNC3XMI.js} +4 -0
  16. package/{chunk-CZVYVNLI.cjs → chunk-6QV4L6R2.cjs} +1 -25
  17. package/chunk-A6ZPAM6Z.cjs +26 -0
  18. package/chunk-LW7IN57F.cjs +358 -0
  19. package/chunk-MCMYOVGT.js +358 -0
  20. package/{chunk-PZVUKTZG.js → chunk-MCN4GFEQ.js} +4 -2
  21. package/{chunk-XHYR3SGG.cjs → chunk-T5QVCXVB.cjs} +5 -1
  22. package/chunk-TPBI6TOU.js +26 -0
  23. package/{chunk-7M5OAOQ4.js → chunk-TPHJUDHG.js} +20 -4
  24. package/{chunk-P4QJCHMM.cjs → chunk-Z5BL4DJA.cjs} +11 -9
  25. package/{chunk-6ZFVV3AV.cjs → chunk-ZOU6W6ZQ.cjs} +31 -15
  26. package/{define-repository-MDEWHqM7.d.cts → define-repository-CwAXed2X.d.cts} +1 -1
  27. package/{define-repository-Ca62_YCy.d.ts → define-repository-q_T4hqeP.d.ts} +1 -1
  28. package/{define-slot-Dil8Kr1A.d.ts → define-slot-Cngzae6i.d.ts} +1 -1
  29. package/{define-slot-BKvArA02.d.cts → define-slot-DYNCLDJY.d.cts} +1 -1
  30. package/define.cjs +6 -4
  31. package/define.d.cts +3 -3
  32. package/define.d.ts +3 -3
  33. package/define.js +6 -4
  34. package/den.js +60 -0
  35. package/{descriptor-DZDNH7R5.d.ts → descriptor-DQ6Gi7A_.d.ts} +31 -3
  36. package/{descriptor-h0JE9jFx.d.cts → descriptor-Dujg_1on.d.cts} +31 -3
  37. package/index.cjs +23 -22
  38. package/index.d.cts +7 -6
  39. package/index.d.ts +7 -6
  40. package/index.js +4 -3
  41. package/island/index.cjs +6 -5
  42. package/island/index.d.cts +13 -6
  43. package/island/index.d.ts +13 -6
  44. package/island/index.js +4 -3
  45. package/package.json +52 -26
  46. package/{routes-CWpIqVAM.d.ts → routes-0uXJ0fux.d.ts} +1 -1
  47. package/{routes-BqIoqbt1.d.cts → routes-B0hDrkiF.d.cts} +1 -1
  48. package/serve/index.cjs +11 -10
  49. package/serve/index.d.cts +4 -4
  50. package/serve/index.d.ts +4 -4
  51. package/serve/index.js +4 -3
  52. package/server-render-CocWXQKC.d.cts +48 -0
  53. package/server-render-CocWXQKC.d.ts +48 -0
  54. package/{types-COwVwgzE.d.cts → types-Dx5qGiwk.d.cts} +1 -1
  55. package/{types-COwVwgzE.d.ts → types-Dx5qGiwk.d.ts} +1 -1
  56. package/{view-adapter-CPI8056c.d.ts → view-adapter-B4gEb-ms.d.ts} +4 -50
  57. package/{view-adapter-D2597RJZ.d.cts → view-adapter-DJ7yB6Ml.d.cts} +4 -50
  58. package/den-serve.js +0 -146
@@ -0,0 +1,358 @@
1
+ import {
2
+ logger
3
+ } from "./chunk-TPBI6TOU.js";
4
+ import {
5
+ __async,
6
+ __spreadProps,
7
+ __spreadValues
8
+ } from "./chunk-6FNC3XMI.js";
9
+
10
+ // src/builder/config.ts
11
+ function defineAppConfig(config) {
12
+ return config;
13
+ }
14
+
15
+ // src/builder/build.ts
16
+ import fs2 from "fs";
17
+ import path2 from "path";
18
+
19
+ // src/builder/assets.ts
20
+ import fs from "fs";
21
+ import path from "path";
22
+ var MANIFEST_PATH = ".vite/manifest.json";
23
+ function readManifest(outDir) {
24
+ const manifestPath = path.join(outDir, MANIFEST_PATH);
25
+ if (!fs.existsSync(manifestPath)) {
26
+ return null;
27
+ }
28
+ return JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
29
+ }
30
+ function collectAssets(outDir, base) {
31
+ const manifest = readManifest(outDir);
32
+ if (manifest === null) {
33
+ return { css: [], js: [] };
34
+ }
35
+ const css = [];
36
+ const js = [];
37
+ const seen = /* @__PURE__ */ new Set();
38
+ const prefix = base.endsWith("/") ? base : `${base}/`;
39
+ function walk(key) {
40
+ var _a, _b;
41
+ if (seen.has(key)) {
42
+ return;
43
+ }
44
+ seen.add(key);
45
+ const chunk = manifest == null ? void 0 : manifest[key];
46
+ if (!chunk) {
47
+ return;
48
+ }
49
+ for (const imported of (_a = chunk.imports) != null ? _a : []) {
50
+ walk(imported);
51
+ }
52
+ for (const href of (_b = chunk.css) != null ? _b : []) {
53
+ css.push(`${prefix}${href}`);
54
+ }
55
+ js.push(`${prefix}${chunk.file}`);
56
+ }
57
+ for (const [key, chunk] of Object.entries(manifest)) {
58
+ if (chunk.isEntry === true) {
59
+ walk(key);
60
+ }
61
+ }
62
+ return { css, js };
63
+ }
64
+
65
+ // src/builder/entries.ts
66
+ var VIRTUAL_CLIENT = "virtual:den/client";
67
+ var VIRTUAL_SERVER_APP = "virtual:den/server-app";
68
+ var VIRTUAL_SERVER_PROCESS = "virtual:den/server-process";
69
+ var DEFAULT_PORT = 3e3;
70
+ function toResolvedId(id) {
71
+ return `\0${id}`;
72
+ }
73
+ function generateClientEntry(entry, clientEntry) {
74
+ return `import app from ${JSON.stringify(entry)}
75
+ import { hydrateApp } from ${JSON.stringify(clientEntry)}
76
+
77
+ hydrateApp(app)
78
+ `;
79
+ }
80
+ function generateServerApp(entry, configPath, assets) {
81
+ return `import { getAppContainer, viewAdapterOf } from '@foxford/den/island'
82
+
83
+ import app from ${JSON.stringify(entry)}
84
+ import config from ${JSON.stringify(configPath)}
85
+
86
+ const server = config.server ?? {}
87
+
88
+ async function setup() {
89
+ viewAdapterOf(app.viewLayer).installResolver()
90
+ server.container?.(getAppContainer())
91
+ await server.setup?.()
92
+ }
93
+
94
+ const descriptor = { ...app, assets: ${JSON.stringify(assets)}, setup }
95
+
96
+ if (server.render) {
97
+ descriptor.serverRender = server.render
98
+ }
99
+
100
+ export default descriptor
101
+ `;
102
+ }
103
+ function generateServerProcess(configPath) {
104
+ return `import { serveApp } from '@foxford/den/serve'
105
+
106
+ import app from ${JSON.stringify(VIRTUAL_SERVER_APP)}
107
+ import config from ${JSON.stringify(configPath)}
108
+
109
+ await serveApp(app, {
110
+ configure: config.server?.configure,
111
+ host: process.env.HOST,
112
+ port: Number(process.env.PORT ?? ${String(DEFAULT_PORT)}),
113
+ })
114
+ `;
115
+ }
116
+
117
+ // src/builder/plugin.ts
118
+ function denAppModules(options) {
119
+ const { assets, config, configPath, entry } = options;
120
+ const sources = {
121
+ [VIRTUAL_CLIENT]: () => generateClientEntry(entry, config.preset.clientEntry),
122
+ [VIRTUAL_SERVER_APP]: () => generateServerApp(entry, configPath, assets),
123
+ [VIRTUAL_SERVER_PROCESS]: () => generateServerProcess(configPath)
124
+ };
125
+ return {
126
+ load: (id) => {
127
+ for (const [virtual, source] of Object.entries(sources)) {
128
+ if (id === toResolvedId(virtual)) {
129
+ return source();
130
+ }
131
+ }
132
+ return null;
133
+ },
134
+ name: "den:app-modules",
135
+ resolveId: (id) => id in sources ? toResolvedId(id) : null
136
+ };
137
+ }
138
+
139
+ // src/builder/build.ts
140
+ var CONFIG_FILE = "den.config.ts";
141
+ var OUT_ROOT = "build";
142
+ var OUT_CLIENT = "build/client";
143
+ var OUT_SERVER = "build/server";
144
+ var ENGINE = /^@foxford\/den(\/|$)/;
145
+ function loadAppConfig(root) {
146
+ return __async(this, null, function* () {
147
+ const configPath = path2.join(root, CONFIG_FILE);
148
+ if (!fs2.existsSync(configPath)) {
149
+ throw new Error(`den: ${CONFIG_FILE} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D \u0432 \xAB${root}\xBB`);
150
+ }
151
+ const { createServer } = yield import("vite");
152
+ const server = yield createServer({
153
+ appType: "custom",
154
+ configFile: false,
155
+ logLevel: "silent",
156
+ root,
157
+ server: { middlewareMode: true }
158
+ });
159
+ try {
160
+ const loaded = yield server.ssrLoadModule(configPath);
161
+ const config = loaded.default;
162
+ if (!(config == null ? void 0 : config.preset)) {
163
+ throw new Error(`den: ${CONFIG_FILE} \u043D\u0435 \u043E\u0431\u044A\u044F\u0432\u043B\u044F\u0435\u0442 \u043F\u0440\u0435\u0441\u0435\u0442 \u0444\u0440\u0435\u0439\u043C\u0432\u043E\u0440\u043A\u0430 \u2014 \u0441\u043E\u0431\u0438\u0440\u0430\u0442\u044C \u043D\u0435\u0447\u0435\u043C`);
164
+ }
165
+ return { config, configPath };
166
+ } finally {
167
+ yield server.close();
168
+ }
169
+ });
170
+ }
171
+ function dependenciesOf(root) {
172
+ var _a, _b;
173
+ const manifestPath = path2.join(root, "package.json");
174
+ if (!fs2.existsSync(manifestPath)) {
175
+ return [];
176
+ }
177
+ const manifest = JSON.parse(fs2.readFileSync(manifestPath, "utf-8"));
178
+ return [...Object.keys((_a = manifest.dependencies) != null ? _a : {}), ...Object.keys((_b = manifest.devDependencies) != null ? _b : {})];
179
+ }
180
+ function viteConfigFor(options) {
181
+ var _a, _b, _c;
182
+ const { assets, base, config, configPath, entryFileNames, input, mode, outDir, root, target } = options;
183
+ const entry = (_a = config.entry) != null ? _a : "src/index.ts";
184
+ const composed = {
185
+ base,
186
+ build: {
187
+ // Клиентский выход чистит свой каталог сам, серверные — нет: они пишут рядом с уже
188
+ // собранным клиентским, и очистка снесла бы его вместе с манифестом
189
+ emptyOutDir: target === "client",
190
+ manifest: target === "client",
191
+ outDir: path2.join(root, outDir),
192
+ // Вход задаётся `input`, а не `build.ssr`: строку в `build.ssr` сборщик понимает как путь
193
+ // к файлу, а входы у нас виртуальные — их резолвит плагин
194
+ rollupOptions: __spreadValues(__spreadValues({
195
+ input
196
+ }, target === "server" ? { external: [ENGINE] } : {}), entryFileNames === void 0 ? {} : { output: { entryFileNames } }),
197
+ ssr: target === "server"
198
+ },
199
+ configFile: false,
200
+ // Режим объявляем явно: плагины сборщика выбирают по нему рантайм фреймворка, а через
201
+ // программный вызов он иначе не доедет.
202
+ mode,
203
+ plugins: [...config.preset.plugins, denAppModules({ assets, config, configPath, entry: path2.join(root, entry) })],
204
+ root,
205
+ ssr: { noExternal: (_c = (_b = config.server) == null ? void 0 : _b.noExternal) != null ? _c : [] }
206
+ };
207
+ return config.vite ? config.vite(composed, target) : composed;
208
+ }
209
+ function buildApp(options) {
210
+ return __async(this, null, function* () {
211
+ var _a, _b;
212
+ const { base = "/", mode = "production" } = options;
213
+ process.env["NODE_ENV"] = mode;
214
+ const root = path2.resolve(options.root);
215
+ const { config, configPath } = yield loadAppConfig(root);
216
+ const refusal = (_b = (_a = config.preset).validate) == null ? void 0 : _b.call(_a, dependenciesOf(root));
217
+ if (refusal !== void 0 && refusal !== null) {
218
+ throw new Error(`den: ${refusal}`);
219
+ }
220
+ const { build } = yield import("vite");
221
+ const shared = { base, config, configPath, mode, root };
222
+ const empty = { css: [], js: [] };
223
+ logger.info(`\u0441\u0431\u043E\u0440\u043A\u0430 \u043A\u043B\u0438\u0435\u043D\u0442\u0441\u043A\u043E\u0433\u043E \u0432\u044B\u0445\u043E\u0434\u0430 (${config.preset.view})`);
224
+ yield build(viteConfigFor(__spreadProps(__spreadValues({}, shared), { assets: empty, input: VIRTUAL_CLIENT, outDir: OUT_CLIENT, target: "client" })));
225
+ const assets = collectAssets(path2.join(root, OUT_CLIENT), base);
226
+ logger.info(`\u0430\u0440\u0442\u0435\u0444\u0430\u043A\u0442\u044B: ${String(assets.js.length)} js, ${String(assets.css.length)} css`);
227
+ logger.info("\u0441\u0431\u043E\u0440\u043A\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u043D\u043E\u0433\u043E \u0434\u0435\u0441\u043A\u0440\u0438\u043F\u0442\u043E\u0440\u0430");
228
+ yield build(
229
+ viteConfigFor(__spreadProps(__spreadValues({}, shared), {
230
+ assets,
231
+ entryFileNames: "index.mjs",
232
+ input: VIRTUAL_SERVER_APP,
233
+ outDir: OUT_SERVER,
234
+ target: "server"
235
+ }))
236
+ );
237
+ logger.info("\u0441\u0431\u043E\u0440\u043A\u0430 \u0442\u043E\u0447\u043A\u0438 \u0432\u0445\u043E\u0434\u0430 \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u0430");
238
+ yield build(
239
+ viteConfigFor(__spreadProps(__spreadValues({}, shared), {
240
+ assets,
241
+ entryFileNames: "server.mjs",
242
+ input: VIRTUAL_SERVER_PROCESS,
243
+ outDir: OUT_ROOT,
244
+ target: "server"
245
+ }))
246
+ );
247
+ });
248
+ }
249
+
250
+ // src/builder/dev.ts
251
+ import { spawn } from "child_process";
252
+ import fs3 from "fs";
253
+ import path3 from "path";
254
+ var SERVER_ENTRY = "build/server.mjs";
255
+ var WATCHED = ["src", "den.config.ts"];
256
+ var DEBOUNCE_MS = 150;
257
+ var SHUTDOWN_TIMEOUT_MS = 5e3;
258
+ function devApp(options) {
259
+ return __async(this, null, function* () {
260
+ const root = path3.resolve(options.root);
261
+ const entry = path3.join(root, SERVER_ENTRY);
262
+ let child = null;
263
+ let pending = null;
264
+ let building = false;
265
+ let dirty = false;
266
+ function signalGroup(pid, signal) {
267
+ try {
268
+ process.kill(-pid, signal);
269
+ } catch (e) {
270
+ }
271
+ }
272
+ function stop() {
273
+ return __async(this, null, function* () {
274
+ const running = child;
275
+ child = null;
276
+ if (!running || running.exitCode !== null || running.pid === void 0) {
277
+ return;
278
+ }
279
+ const { pid } = running;
280
+ yield new Promise((resolve) => {
281
+ const forced = setTimeout(() => signalGroup(pid, "SIGKILL"), SHUTDOWN_TIMEOUT_MS);
282
+ running.once("exit", () => {
283
+ clearTimeout(forced);
284
+ resolve();
285
+ });
286
+ signalGroup(pid, "SIGTERM");
287
+ });
288
+ });
289
+ }
290
+ function start() {
291
+ const started = spawn(process.execPath, [...process.execArgv, entry], {
292
+ detached: true,
293
+ stdio: "inherit"
294
+ });
295
+ child = started;
296
+ started.on("exit", (code, signal) => {
297
+ if (child !== started) {
298
+ return;
299
+ }
300
+ child = null;
301
+ logger.error(`\u043F\u0440\u043E\u0446\u0435\u0441\u0441 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u044F \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0441\u044F \u0441\u0430\u043C (\u043A\u043E\u0434 ${String(code)}, \u0441\u0438\u0433\u043D\u0430\u043B ${String(signal)})`);
302
+ });
303
+ }
304
+ function rebuild() {
305
+ return __async(this, null, function* () {
306
+ if (building) {
307
+ dirty = true;
308
+ return;
309
+ }
310
+ building = true;
311
+ try {
312
+ do {
313
+ dirty = false;
314
+ yield stop();
315
+ try {
316
+ yield buildApp(__spreadProps(__spreadValues({}, options), { mode: "development" }));
317
+ start();
318
+ } catch (error) {
319
+ logger.error("\u0441\u0431\u043E\u0440\u043A\u0430 \u043D\u0435 \u043F\u0440\u043E\u0448\u043B\u0430, \u0436\u0434\u0443 \u043F\u0440\u0430\u0432\u043A\u0438:", error);
320
+ }
321
+ } while (dirty);
322
+ } finally {
323
+ building = false;
324
+ }
325
+ });
326
+ }
327
+ yield rebuild();
328
+ for (const target of WATCHED) {
329
+ const watched = path3.join(root, target);
330
+ if (!fs3.existsSync(watched)) {
331
+ continue;
332
+ }
333
+ fs3.watch(watched, { recursive: true }, () => {
334
+ if (pending) {
335
+ clearTimeout(pending);
336
+ }
337
+ pending = setTimeout(() => void rebuild(), DEBOUNCE_MS);
338
+ });
339
+ }
340
+ logger.info(`\u0436\u0434\u0443 \u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u0439 \u0432 ${WATCHED.join(", ")}`);
341
+ for (const signal of ["SIGINT", "SIGTERM"]) {
342
+ process.once(signal, () => {
343
+ void stop().then(() => process.exit(0));
344
+ });
345
+ }
346
+ process.on("exit", () => {
347
+ if ((child == null ? void 0 : child.pid) !== void 0) {
348
+ signalGroup(child.pid, "SIGTERM");
349
+ }
350
+ });
351
+ });
352
+ }
353
+
354
+ export {
355
+ defineAppConfig,
356
+ buildApp,
357
+ devApp
358
+ };
@@ -3,9 +3,11 @@ import {
3
3
  } from "./chunk-WBHHHICS.js";
4
4
  import {
5
5
  SlotRegistryToken,
6
- StateRegistryToken,
6
+ StateRegistryToken
7
+ } from "./chunk-3RX2OSUL.js";
8
+ import {
7
9
  unitLogger
8
- } from "./chunk-KJ6NDOOL.js";
10
+ } from "./chunk-TPBI6TOU.js";
9
11
 
10
12
  // src/core/slot-registry.ts
11
13
  var SlotRegistry = class {
@@ -1,4 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
4
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
14
16
  }
15
17
  return a;
16
18
  };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
17
20
  var __async = (__this, __arguments, generator) => {
18
21
  return new Promise((resolve, reject) => {
19
22
  var fulfilled = (value) => {
@@ -38,4 +41,5 @@ var __async = (__this, __arguments, generator) => {
38
41
 
39
42
 
40
43
 
41
- exports.__spreadValues = __spreadValues; exports.__async = __async;
44
+
45
+ exports.__spreadValues = __spreadValues; exports.__spreadProps = __spreadProps; exports.__async = __async;
@@ -0,0 +1,26 @@
1
+ // src/logger.ts
2
+ import { createToken } from "@foxford/ioc";
3
+ import { log } from "@foxford/logger";
4
+ var logger = log.getLogger("@foxford/den");
5
+ var LoggerToken = createToken("den:Logger");
6
+ function scopeLogger(container) {
7
+ if (container.has(LoggerToken)) {
8
+ const resolved = container.resolve(LoggerToken);
9
+ if (!(resolved instanceof Promise)) {
10
+ return resolved;
11
+ }
12
+ }
13
+ return logger;
14
+ }
15
+ function unitLogger(container, name) {
16
+ var _a;
17
+ const base = scopeLogger(container);
18
+ return (_a = base.getLogger(name)) != null ? _a : base;
19
+ }
20
+
21
+ export {
22
+ logger,
23
+ LoggerToken,
24
+ scopeLogger,
25
+ unitLogger
26
+ };
@@ -1,16 +1,18 @@
1
1
  import {
2
2
  resolveViewAdapter
3
3
  } from "./chunk-E23E2VUC.js";
4
+ import {
5
+ RequestContextToken
6
+ } from "./chunk-3RX2OSUL.js";
4
7
  import {
5
8
  LoggerToken,
6
- RequestContextToken,
7
9
  logger,
8
10
  unitLogger
9
- } from "./chunk-KJ6NDOOL.js";
11
+ } from "./chunk-TPBI6TOU.js";
10
12
  import {
11
13
  __async,
12
14
  __spreadValues
13
- } from "./chunk-HJO26HIQ.js";
15
+ } from "./chunk-6FNC3XMI.js";
14
16
 
15
17
  // src/island/document.ts
16
18
  function isDocumentSource(value) {
@@ -132,9 +134,23 @@ function resolveEagerUnits(container, descriptor) {
132
134
 
133
135
  // src/island/render.ts
134
136
  var STATUS_OK = 200;
137
+ var processSetup = /* @__PURE__ */ new WeakMap();
138
+ function setupOnce(descriptor) {
139
+ const { setup } = descriptor;
140
+ if (!setup) {
141
+ return Promise.resolve();
142
+ }
143
+ let started = processSetup.get(descriptor);
144
+ if (!started) {
145
+ started = Promise.resolve(setup());
146
+ processSetup.set(descriptor, started);
147
+ }
148
+ return started;
149
+ }
135
150
  function renderApp(descriptor, request) {
136
151
  return __async(this, null, function* () {
137
152
  var _a, _b;
153
+ yield setupOnce(descriptor);
138
154
  const route = {
139
155
  params: (_a = request.params) != null ? _a : {},
140
156
  pathname: request.pathname,
@@ -158,7 +174,7 @@ function renderApp(descriptor, request) {
158
174
  container,
159
175
  slots: request.slots
160
176
  });
161
- return { head, headHtml: rendered.head, html: rendered.html, state, status };
177
+ return { assets: descriptor.assets, head, headHtml: rendered.head, html: rendered.html, state, status };
162
178
  } finally {
163
179
  yield container.dispose();
164
180
  }
@@ -4,8 +4,10 @@ var _chunkC7BM4DGXcjs = require('./chunk-C7BM4DGX.cjs');
4
4
 
5
5
 
6
6
 
7
+ var _chunk6QV4L6R2cjs = require('./chunk-6QV4L6R2.cjs');
7
8
 
8
- var _chunkCZVYVNLIcjs = require('./chunk-CZVYVNLI.cjs');
9
+
10
+ var _chunkA6ZPAM6Zcjs = require('./chunk-A6ZPAM6Z.cjs');
9
11
 
10
12
  // src/core/slot-registry.ts
11
13
  var SlotRegistry = class {
@@ -53,7 +55,7 @@ function defineService(token, options) {
53
55
  * @param container - Контейнер для регистрации
54
56
  */
55
57
  register(container) {
56
- const unitLog = _chunkCZVYVNLIcjs.unitLogger.call(void 0, container, token.description);
58
+ const unitLog = _chunkA6ZPAM6Zcjs.unitLogger.call(void 0, container, token.description);
57
59
  const factory = _ioc.inject.call(void 0, requireTokens, (...args) => {
58
60
  unitLog.debug(`\u0441\u043E\u0437\u0434\u0430\u043D\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (${create ? "\u0444\u0430\u0431\u0440\u0438\u043A\u0430" : "lifecycle-\u043E\u0431\u0451\u0440\u0442\u043A\u0430"})`);
59
61
  let instance;
@@ -83,10 +85,10 @@ function defineService(token, options) {
83
85
  };
84
86
  }
85
87
  function registerStateParticipant(container, token, instance, deps, serialize, deserialize) {
86
- if (!container.has(_chunkCZVYVNLIcjs.StateRegistryToken)) {
88
+ if (!container.has(_chunk6QV4L6R2cjs.StateRegistryToken)) {
87
89
  return;
88
90
  }
89
- const resolved = container.resolve(_chunkCZVYVNLIcjs.StateRegistryToken);
91
+ const resolved = container.resolve(_chunk6QV4L6R2cjs.StateRegistryToken);
90
92
  if (resolved instanceof Promise) {
91
93
  return;
92
94
  }
@@ -115,7 +117,7 @@ function defineViewModel(token, options) {
115
117
  * @param container - Контейнер для регистрации
116
118
  */
117
119
  register(container) {
118
- const unitLog = _chunkCZVYVNLIcjs.unitLogger.call(void 0, container, token.description);
120
+ const unitLog = _chunkA6ZPAM6Zcjs.unitLogger.call(void 0, container, token.description);
119
121
  const factory = _ioc.inject.call(void 0, requireTokens, (...args) => {
120
122
  unitLog.debug("\u0441\u043E\u0437\u0434\u0430\u043D\u0438\u0435 view-model");
121
123
  return create(args);
@@ -162,7 +164,7 @@ function defineRepository(token, options) {
162
164
  * @param container - Контейнер для регистрации
163
165
  */
164
166
  register(container) {
165
- const unitLog = _chunkCZVYVNLIcjs.unitLogger.call(void 0, container, token.description);
167
+ const unitLog = _chunkA6ZPAM6Zcjs.unitLogger.call(void 0, container, token.description);
166
168
  const factory = _ioc.inject.call(void 0, requireTokens, (...args) => {
167
169
  unitLog.debug("\u0441\u043E\u0437\u0434\u0430\u043D\u0438\u0435 \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u044F");
168
170
  return create(args);
@@ -179,13 +181,13 @@ function defineSlot({ view, units = [], viewLayer } = {}) {
179
181
  return {
180
182
  __type: "slot",
181
183
  register(container, name) {
182
- const slotLog = _chunkCZVYVNLIcjs.unitLogger.call(void 0, container, `slot:${name}`);
184
+ const slotLog = _chunkA6ZPAM6Zcjs.unitLogger.call(void 0, container, `slot:${name}`);
183
185
  for (const unit of units) {
184
186
  unit.register(container);
185
187
  }
186
- const registry = container.has(_chunkCZVYVNLIcjs.SlotRegistryToken) ? container.resolve(_chunkCZVYVNLIcjs.SlotRegistryToken) : (() => {
188
+ const registry = container.has(_chunk6QV4L6R2cjs.SlotRegistryToken) ? container.resolve(_chunk6QV4L6R2cjs.SlotRegistryToken) : (() => {
187
189
  const created = new SlotRegistry();
188
- container.bind(_chunkCZVYVNLIcjs.SlotRegistryToken).toValue(created);
190
+ container.bind(_chunk6QV4L6R2cjs.SlotRegistryToken).toValue(created);
189
191
  slotLog.debug("\u0441\u043E\u0437\u0434\u0430\u043D SlotRegistry \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440\u0430");
190
192
  return created;
191
193
  })();
@@ -3,14 +3,16 @@
3
3
  var _chunkXOJ2VWX4cjs = require('./chunk-XOJ2VWX4.cjs');
4
4
 
5
5
 
6
+ var _chunk6QV4L6R2cjs = require('./chunk-6QV4L6R2.cjs');
6
7
 
7
8
 
8
9
 
9
- var _chunkCZVYVNLIcjs = require('./chunk-CZVYVNLI.cjs');
10
10
 
11
+ var _chunkA6ZPAM6Zcjs = require('./chunk-A6ZPAM6Z.cjs');
11
12
 
12
13
 
13
- var _chunkXHYR3SGGcjs = require('./chunk-XHYR3SGG.cjs');
14
+
15
+ var _chunkT5QVCXVBcjs = require('./chunk-T5QVCXVB.cjs');
14
16
 
15
17
  // src/island/document.ts
16
18
  function isDocumentSource(value) {
@@ -24,7 +26,7 @@ function getAppContainer() {
24
26
  var _a;
25
27
  if (appContainer === null) {
26
28
  appContainer = new (0, _ioc.Container)();
27
- ((_a = _chunkCZVYVNLIcjs.logger.getLogger("island:runtime")) != null ? _a : _chunkCZVYVNLIcjs.logger).debug("app-\u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440 \u0441\u043E\u0437\u0434\u0430\u043D");
29
+ ((_a = _chunkA6ZPAM6Zcjs.logger.getLogger("island:runtime")) != null ? _a : _chunkA6ZPAM6Zcjs.logger).debug("app-\u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440 \u0441\u043E\u0437\u0434\u0430\u043D");
28
30
  }
29
31
  return appContainer;
30
32
  }
@@ -36,11 +38,11 @@ var REDIRECT_FOUND = 302;
36
38
  function createIslandContainer(descriptor, options = {}) {
37
39
  var _a, _b, _c, _d, _e;
38
40
  const { parent = getAppContainer() } = options;
39
- const appLog = (_b = _logger.log.getLogger((_a = descriptor.name) != null ? _a : "app")) != null ? _b : _chunkCZVYVNLIcjs.logger;
41
+ const appLog = (_b = _logger.log.getLogger((_a = descriptor.name) != null ? _a : "app")) != null ? _b : _chunkA6ZPAM6Zcjs.logger;
40
42
  const islandLog = (_c = appLog.getLogger("client")) != null ? _c : appLog;
41
43
  try {
42
44
  const container = parent.createChild();
43
- container.bind(_chunkCZVYVNLIcjs.LoggerToken).toValue(islandLog);
45
+ container.bind(_chunkA6ZPAM6Zcjs.LoggerToken).toValue(islandLog);
44
46
  descriptor.viewLayer.register(container);
45
47
  const viewModels = (_d = descriptor.viewModels) != null ? _d : [];
46
48
  const slots = Object.entries((_e = descriptor.slots) != null ? _e : {});
@@ -68,19 +70,19 @@ function hydrateIslandState(container, descriptor, denState) {
68
70
  const instance = container.resolve(vm.token);
69
71
  const saved = denState[vm.token.description];
70
72
  if (saved !== void 0 && typeof ((_b = instance.state) == null ? void 0 : _b.set) === "function") {
71
- _chunkCZVYVNLIcjs.unitLogger.call(void 0, container, vm.token.description).debug("\u0433\u0438\u0434\u0440\u0430\u0446\u0438\u044F VM \u0438\u0437 denState");
73
+ _chunkA6ZPAM6Zcjs.unitLogger.call(void 0, container, vm.token.description).debug("\u0433\u0438\u0434\u0440\u0430\u0446\u0438\u044F VM \u0438\u0437 denState");
72
74
  instance.state.set(saved);
73
75
  }
74
76
  }
75
77
  }
76
78
  function activateIslandViewModels(_0, _1) {
77
- return _chunkXHYR3SGGcjs.__async.call(void 0, this, arguments, function* (container, descriptor, route = EMPTY_ROUTE) {
79
+ return _chunkT5QVCXVBcjs.__async.call(void 0, this, arguments, function* (container, descriptor, route = EMPTY_ROUTE) {
78
80
  var _a;
79
81
  yield Promise.all(
80
- ((_a = descriptor.viewModels) != null ? _a : []).map((vm) => _chunkXHYR3SGGcjs.__async.call(void 0, null, null, function* () {
82
+ ((_a = descriptor.viewModels) != null ? _a : []).map((vm) => _chunkT5QVCXVBcjs.__async.call(void 0, null, null, function* () {
81
83
  var _a2;
82
84
  const instance = container.resolve(vm.token);
83
- _chunkCZVYVNLIcjs.unitLogger.call(void 0, container, vm.token.description).debug(`\u0430\u043A\u0442\u0438\u0432\u0430\u0446\u0438\u044F VM (${route.pathname || "\u2014"})`);
85
+ _chunkA6ZPAM6Zcjs.unitLogger.call(void 0, container, vm.token.description).debug(`\u0430\u043A\u0442\u0438\u0432\u0430\u0446\u0438\u044F VM (${route.pathname || "\u2014"})`);
84
86
  yield (_a2 = instance.activate) == null ? void 0 : _a2.call(instance, route);
85
87
  }))
86
88
  );
@@ -107,7 +109,7 @@ function collectDocumentContribution(container, descriptor) {
107
109
  }
108
110
  const part = instance.describeDocument();
109
111
  if (part.head) {
110
- contribution.head = _chunkXHYR3SGGcjs.__spreadValues.call(void 0, _chunkXHYR3SGGcjs.__spreadValues.call(void 0, {}, contribution.head), part.head);
112
+ contribution.head = _chunkT5QVCXVBcjs.__spreadValues.call(void 0, _chunkT5QVCXVBcjs.__spreadValues.call(void 0, {}, contribution.head), part.head);
111
113
  }
112
114
  const declared = part.status !== void 0 || part.redirect !== void 0;
113
115
  if (declared && contribution.status === void 0) {
@@ -121,10 +123,10 @@ function resolveEagerUnits(container, descriptor) {
121
123
  var _a;
122
124
  for (const token of (_a = descriptor.eager) != null ? _a : []) {
123
125
  const instance = container.resolve(token);
124
- _chunkCZVYVNLIcjs.unitLogger.call(void 0, container, token.description).debug("eager: \u0435\u0434\u0438\u043D\u0438\u0446\u0430 \u043F\u043E\u0434\u043D\u044F\u0442\u0430 \u043F\u0440\u0438 \u043C\u043E\u043D\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0438");
126
+ _chunkA6ZPAM6Zcjs.unitLogger.call(void 0, container, token.description).debug("eager: \u0435\u0434\u0438\u043D\u0438\u0446\u0430 \u043F\u043E\u0434\u043D\u044F\u0442\u0430 \u043F\u0440\u0438 \u043C\u043E\u043D\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0438");
125
127
  if (instance instanceof Promise) {
126
128
  instance.catch(
127
- (error) => _chunkCZVYVNLIcjs.unitLogger.call(void 0, container, token.description).error("eager: \u0435\u0434\u0438\u043D\u0438\u0446\u0430 \u043D\u0435 \u043F\u043E\u0434\u043D\u044F\u043B\u0430\u0441\u044C", error)
129
+ (error) => _chunkA6ZPAM6Zcjs.unitLogger.call(void 0, container, token.description).error("eager: \u0435\u0434\u0438\u043D\u0438\u0446\u0430 \u043D\u0435 \u043F\u043E\u0434\u043D\u044F\u043B\u0430\u0441\u044C", error)
128
130
  );
129
131
  }
130
132
  }
@@ -132,9 +134,23 @@ function resolveEagerUnits(container, descriptor) {
132
134
 
133
135
  // src/island/render.ts
134
136
  var STATUS_OK = 200;
137
+ var processSetup = /* @__PURE__ */ new WeakMap();
138
+ function setupOnce(descriptor) {
139
+ const { setup } = descriptor;
140
+ if (!setup) {
141
+ return Promise.resolve();
142
+ }
143
+ let started = processSetup.get(descriptor);
144
+ if (!started) {
145
+ started = Promise.resolve(setup());
146
+ processSetup.set(descriptor, started);
147
+ }
148
+ return started;
149
+ }
135
150
  function renderApp(descriptor, request) {
136
- return _chunkXHYR3SGGcjs.__async.call(void 0, this, null, function* () {
151
+ return _chunkT5QVCXVBcjs.__async.call(void 0, this, null, function* () {
137
152
  var _a, _b;
153
+ yield setupOnce(descriptor);
138
154
  const route = {
139
155
  params: (_a = request.params) != null ? _a : {},
140
156
  pathname: request.pathname,
@@ -146,7 +162,7 @@ function renderApp(descriptor, request) {
146
162
  }
147
163
  try {
148
164
  if (request.context) {
149
- container.bind(_chunkCZVYVNLIcjs.RequestContextToken).toValue(request.context);
165
+ container.bind(_chunk6QV4L6R2cjs.RequestContextToken).toValue(request.context);
150
166
  }
151
167
  yield activateIslandViewModels(container, descriptor, route);
152
168
  const { head, redirect, status = STATUS_OK } = collectDocumentContribution(container, descriptor);
@@ -158,7 +174,7 @@ function renderApp(descriptor, request) {
158
174
  container,
159
175
  slots: request.slots
160
176
  });
161
- return { head, headHtml: rendered.head, html: rendered.html, state, status };
177
+ return { assets: descriptor.assets, head, headHtml: rendered.head, html: rendered.html, state, status };
162
178
  } finally {
163
179
  yield container.dispose();
164
180
  }
@@ -1,4 +1,4 @@
1
- import { v as DefineServiceOptions, H as ServiceDefinition, w as DefineViewModelOptions, V as ViewModelDefinition, u as DefineRepositoryOptions, B as RepositoryDefinition } from './types-COwVwgzE.cjs';
1
+ import { a as DefineServiceOptions, S as ServiceDefinition, b as DefineViewModelOptions, V as ViewModelDefinition, D as DefineRepositoryOptions, d as RepositoryDefinition } from './types-Dx5qGiwk.cjs';
2
2
  import { Token } from '@foxford/ioc';
3
3
 
4
4
  /**