@fluixi/start 0.1.0-alpha.73 → 0.1.0-alpha.75
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/dist/adapter.cjs +750 -0
- package/dist/adapter.d.ts +9 -9
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +10 -10
- package/dist/adapter.mjs +719 -0
- package/dist/adapters/entry.cjs +122 -0
- package/dist/adapters/entry.js +1 -1
- package/dist/adapters/entry.mjs +95 -0
- package/dist/adapters/platforms.cjs +311 -0
- package/dist/adapters/platforms.d.ts +2 -2
- package/dist/adapters/platforms.js +8 -8
- package/dist/adapters/platforms.mjs +284 -0
- package/dist/api-HD7KU3BS.mjs +114 -0
- package/dist/api.cjs +145 -0
- package/dist/api.js +1 -1
- package/dist/api.mjs +116 -0
- package/dist/commands/api-HD7KU3BS.mjs +114 -0
- package/dist/commands/api-PBT4QZ34.mjs +16 -0
- package/dist/commands/api-PJL37LV3.mjs +17 -0
- package/dist/commands/build.cjs +877 -0
- package/dist/commands/build.js +6 -6
- package/dist/commands/build.mjs +717 -0
- package/dist/commands/chunk-GFQ4MUIC.mjs +117 -0
- package/dist/commands/chunk-MTM6M3TC.mjs +115 -0
- package/dist/commands/dev.cjs +670 -0
- package/dist/commands/dev.js +3 -3
- package/dist/commands/dev.mjs +512 -0
- package/dist/commands/index.cjs +1145 -0
- package/dist/commands/index.d.ts +1 -1
- package/dist/commands/index.js +1 -1
- package/dist/commands/index.mjs +982 -0
- package/dist/commands/prerender.cjs +404 -0
- package/dist/commands/prerender.d.ts +1 -1
- package/dist/commands/prerender.js +2 -2
- package/dist/commands/prerender.mjs +377 -0
- package/dist/commands/start.cjs +463 -0
- package/dist/commands/start.d.ts +1 -1
- package/dist/commands/start.js +2 -2
- package/dist/commands/start.mjs +428 -0
- package/dist/config.cjs +150 -0
- package/dist/config.d.ts +24 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +8 -6
- package/dist/config.mjs +114 -0
- package/dist/define-config.cjs +32 -0
- package/dist/define-config.d.ts +12 -0
- package/dist/define-config.d.ts.map +1 -0
- package/dist/define-config.js +3 -0
- package/dist/define-config.mjs +7 -0
- package/dist/di.cjs +200 -0
- package/dist/di.d.ts +4 -4
- package/dist/di.d.ts.map +1 -1
- package/dist/di.js +9 -9
- package/dist/di.mjs +169 -0
- package/dist/document.cjs +115 -0
- package/dist/document.d.ts +1 -1
- package/dist/document.js +1 -1
- package/dist/document.mjs +86 -0
- package/dist/generated-api.cjs +43 -0
- package/dist/generated-api.js +1 -1
- package/dist/generated-api.mjs +18 -0
- package/dist/generated-server-fns.cjs +43 -0
- package/dist/generated-server-fns.mjs +18 -0
- package/dist/handler-core.cjs +211 -0
- package/dist/handler-core.d.ts +2 -2
- package/dist/handler-core.js +2 -2
- package/dist/handler-core.mjs +185 -0
- package/dist/handler.cjs +182 -0
- package/dist/handler.d.ts +3 -3
- package/dist/handler.js +3 -3
- package/dist/handler.mjs +152 -0
- package/dist/head.cjs +25 -0
- package/dist/head.d.ts +1 -1
- package/dist/head.js +1 -1
- package/dist/head.mjs +4 -0
- package/dist/image-loader.cjs +37 -0
- package/dist/image-loader.d.ts +25 -0
- package/dist/image-loader.d.ts.map +1 -0
- package/dist/image-loader.js +18 -0
- package/dist/image-loader.mjs +12 -0
- package/dist/image.cjs +151 -0
- package/dist/image.d.ts +2 -19
- package/dist/image.d.ts.map +1 -1
- package/dist/image.js +5 -21
- package/dist/image.mjs +126 -0
- package/dist/index.cjs +303 -0
- package/dist/index.d.ts +28 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -17
- package/dist/index.mjs +262 -0
- package/dist/interceptors.cjs +72 -0
- package/dist/interceptors.js +1 -1
- package/dist/interceptors.mjs +44 -0
- package/dist/internal.cjs +393 -0
- package/dist/internal.d.ts +6 -6
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +23 -15
- package/dist/internal.mjs +223 -0
- package/dist/middleware.cjs +58 -0
- package/dist/middleware.d.ts +3 -3
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +1 -1
- package/dist/middleware.mjs +31 -0
- package/dist/preload.cjs +42 -0
- package/dist/preload.js +1 -1
- package/dist/preload.mjs +18 -0
- package/dist/router.cjs +25 -0
- package/dist/router.d.ts +3 -3
- package/dist/router.js +3 -3
- package/dist/router.mjs +4 -0
- package/dist/server-fn-setup.cjs +46 -0
- package/dist/server-fn-setup.d.ts +1 -1
- package/dist/server-fn-setup.js +2 -2
- package/dist/server-fn-setup.mjs +22 -0
- package/dist/server-fn.cjs +109 -0
- package/dist/server-fn.d.ts +2 -2
- package/dist/server-fn.js +2 -2
- package/dist/server-fn.mjs +79 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/ui.cjs +123 -0
- package/dist/ui.js +1 -1
- package/dist/ui.mjs +93 -0
- package/package.json +63 -25
package/dist/config.js
CHANGED
|
@@ -3,9 +3,9 @@ import { existsSync } from 'node:fs';
|
|
|
3
3
|
import { writeFile, unlink } from 'node:fs/promises';
|
|
4
4
|
import { resolve, isAbsolute } from 'node:path';
|
|
5
5
|
/** Identity helper for editor types in `fluixi.config.ts`. */
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
6
|
+
// One implementation, re-exported: the root entry needs it without this module's
|
|
7
|
+
// `node:fs`, and two copies of an identity function is how their signatures drift.
|
|
8
|
+
export { defineConfig } from './define-config.js';
|
|
9
9
|
/** Apply defaults. */
|
|
10
10
|
export function resolveConfig(config = {}) {
|
|
11
11
|
const root = resolve(config.root ?? process.cwd());
|
|
@@ -22,6 +22,8 @@ export function resolveConfig(config = {}) {
|
|
|
22
22
|
middleware: config.middleware ?? 'src/middleware.ts',
|
|
23
23
|
ssrNoExternal: config.ssrNoExternal ?? [],
|
|
24
24
|
resolve: config.resolve ?? [],
|
|
25
|
+
vitePlugin: config.vitePlugin ?? {},
|
|
26
|
+
plugins: config.plugins ?? [],
|
|
25
27
|
adapter: config.adapter,
|
|
26
28
|
i18n: resolveI18n(config.i18n),
|
|
27
29
|
prerender: resolvePrerender(config.prerender),
|
|
@@ -59,7 +61,7 @@ const CONFIG_NAMES = [
|
|
|
59
61
|
/**
|
|
60
62
|
* Load `fluixi.config.{ts,mts,mjs,js}` from the app root. TypeScript configs are
|
|
61
63
|
* bundled on the fly with esbuild and imported; plain ESM is imported directly.
|
|
62
|
-
* No config is fine too
|
|
64
|
+
* No config is fine too: every field has a default.
|
|
63
65
|
*/
|
|
64
66
|
export async function loadConfig(root = process.cwd()) {
|
|
65
67
|
for (const name of CONFIG_NAMES) {
|
|
@@ -70,12 +72,12 @@ export async function loadConfig(root = process.cwd()) {
|
|
|
70
72
|
return {};
|
|
71
73
|
}
|
|
72
74
|
async function loadConfigFile(file) {
|
|
73
|
-
// Plain ESM (.mjs/.js)
|
|
75
|
+
// Plain ESM (.mjs/.js), import directly, no transform needed.
|
|
74
76
|
if (!/\.[mc]?ts$/.test(file)) {
|
|
75
77
|
const mod = await import(/* @vite-ignore */ pathToFileURL(file).href);
|
|
76
78
|
return (mod.default ?? mod);
|
|
77
79
|
}
|
|
78
|
-
// TypeScript
|
|
80
|
+
// TypeScript: bundle with esbuild, keeping bare specifiers external so
|
|
79
81
|
// `import { defineConfig } from '@fluixi/start'` and node builtins resolve from
|
|
80
82
|
// the app. Relative imports (shared constants, env helpers) ARE bundled in. The
|
|
81
83
|
// output is written to a temp `.mjs` beside the source so those externals resolve
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*! @fluixi/start v0.1.0-alpha.75 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
|
|
3
|
+
// src/config.ts
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { writeFile, unlink } from "node:fs/promises";
|
|
7
|
+
import { resolve, isAbsolute } from "node:path";
|
|
8
|
+
|
|
9
|
+
// src/define-config.ts
|
|
10
|
+
function defineConfig(config) {
|
|
11
|
+
return config;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/config.ts
|
|
15
|
+
function resolveConfig(config = {}) {
|
|
16
|
+
const root = resolve(config.root ?? process.cwd());
|
|
17
|
+
return {
|
|
18
|
+
root,
|
|
19
|
+
ssr: config.ssr ?? true,
|
|
20
|
+
port: config.port ?? 3e3,
|
|
21
|
+
serverEntry: config.serverEntry ?? "src/entry-server.ts",
|
|
22
|
+
clientEntry: config.clientEntry ?? "src/entry-client.ts",
|
|
23
|
+
template: config.template ?? "index.html",
|
|
24
|
+
mountId: config.mountId ?? "root",
|
|
25
|
+
routesDir: config.routesDir ?? "src/routes",
|
|
26
|
+
apiDir: config.apiDir ?? "src/api",
|
|
27
|
+
middleware: config.middleware ?? "src/middleware.ts",
|
|
28
|
+
ssrNoExternal: config.ssrNoExternal ?? [],
|
|
29
|
+
resolve: config.resolve ?? [],
|
|
30
|
+
vitePlugin: config.vitePlugin ?? {},
|
|
31
|
+
plugins: config.plugins ?? [],
|
|
32
|
+
adapter: config.adapter,
|
|
33
|
+
i18n: resolveI18n(config.i18n),
|
|
34
|
+
prerender: resolvePrerender(config.prerender)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function resolvePrerender(prerender) {
|
|
38
|
+
if (!prerender) return false;
|
|
39
|
+
const opts = typeof prerender === "object" ? prerender : {};
|
|
40
|
+
return {
|
|
41
|
+
routes: opts.routes?.length ? opts.routes : ["/"],
|
|
42
|
+
crawl: opts.crawl ?? true
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function resolveI18n(i18n) {
|
|
46
|
+
if (i18n === false) return false;
|
|
47
|
+
const opts = typeof i18n === "object" ? i18n : {};
|
|
48
|
+
return {
|
|
49
|
+
dir: opts.dir ?? "src/i18n",
|
|
50
|
+
defaultLocale: opts.defaultLocale,
|
|
51
|
+
locales: opts.locales
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
var CONFIG_NAMES = [
|
|
55
|
+
"fluixi.config.ts",
|
|
56
|
+
"fluixi.config.mts",
|
|
57
|
+
"fluixi.config.mjs",
|
|
58
|
+
"fluixi.config.js"
|
|
59
|
+
];
|
|
60
|
+
async function loadConfig(root = process.cwd()) {
|
|
61
|
+
for (const name of CONFIG_NAMES) {
|
|
62
|
+
const file = resolve(root, name);
|
|
63
|
+
if (existsSync(file)) return loadConfigFile(file);
|
|
64
|
+
}
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
async function loadConfigFile(file) {
|
|
68
|
+
if (!/\.[mc]?ts$/.test(file)) {
|
|
69
|
+
const mod = await import(
|
|
70
|
+
/* @vite-ignore */
|
|
71
|
+
pathToFileURL(file).href
|
|
72
|
+
);
|
|
73
|
+
return mod.default ?? mod;
|
|
74
|
+
}
|
|
75
|
+
const esbuild = await import("esbuild");
|
|
76
|
+
const { outputFiles } = await esbuild.build({
|
|
77
|
+
entryPoints: [file],
|
|
78
|
+
bundle: true,
|
|
79
|
+
write: false,
|
|
80
|
+
format: "esm",
|
|
81
|
+
platform: "node",
|
|
82
|
+
target: `node${process.versions.node.split(".")[0]}`,
|
|
83
|
+
sourcemap: "inline",
|
|
84
|
+
plugins: [
|
|
85
|
+
{
|
|
86
|
+
name: "fluixi:externalize-bare",
|
|
87
|
+
setup(b) {
|
|
88
|
+
b.onResolve({ filter: /.*/ }, (args) => {
|
|
89
|
+
if (args.kind === "entry-point") return null;
|
|
90
|
+
if (args.path.startsWith(".") || isAbsolute(args.path)) return null;
|
|
91
|
+
return { path: args.path, external: true };
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
});
|
|
97
|
+
const tempFile = `${file}.timestamp-${Date.now()}-${Math.random().toString(16).slice(2)}.mjs`;
|
|
98
|
+
await writeFile(tempFile, outputFiles[0].text);
|
|
99
|
+
try {
|
|
100
|
+
const mod = await import(
|
|
101
|
+
/* @vite-ignore */
|
|
102
|
+
pathToFileURL(tempFile).href
|
|
103
|
+
);
|
|
104
|
+
return mod.default ?? mod;
|
|
105
|
+
} finally {
|
|
106
|
+
await unlink(tempFile).catch(() => {
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
defineConfig,
|
|
112
|
+
loadConfig,
|
|
113
|
+
resolveConfig
|
|
114
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/define-config.ts
|
|
21
|
+
var define_config_exports = {};
|
|
22
|
+
__export(define_config_exports, {
|
|
23
|
+
defineConfig: () => defineConfig
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(define_config_exports);
|
|
26
|
+
function defineConfig(config) {
|
|
27
|
+
return config;
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
defineConfig
|
|
32
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `defineConfig`, alone, away from the loader.
|
|
3
|
+
*
|
|
4
|
+
* It is an identity function that exists for the types, and it belongs to the root
|
|
5
|
+
* export because a config file is the first thing an app writes. Keeping it here rather
|
|
6
|
+
* than in `config.ts` is what lets the root entry stay importable in a browser: that
|
|
7
|
+
* module reads the filesystem to find and load a config, and a single value imported
|
|
8
|
+
* from it drags `node:fs` into the client bundle.
|
|
9
|
+
*/
|
|
10
|
+
import type { FluixiConfig } from './config.js';
|
|
11
|
+
export declare function defineConfig(config: FluixiConfig): FluixiConfig;
|
|
12
|
+
//# sourceMappingURL=define-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-config.d.ts","sourceRoot":"","sources":["../src/define-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAE/D"}
|
package/dist/di.cjs
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/*! @fluixi/start v0.1.0-alpha.75 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __typeError = (msg) => {
|
|
8
|
+
throw TypeError(msg);
|
|
9
|
+
};
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
24
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
26
|
+
|
|
27
|
+
// src/di.ts
|
|
28
|
+
var di_exports = {};
|
|
29
|
+
__export(di_exports, {
|
|
30
|
+
Injector: () => Injector,
|
|
31
|
+
createInjector: () => createInjector,
|
|
32
|
+
getInjector: () => getInjector,
|
|
33
|
+
inject: () => inject,
|
|
34
|
+
injectionToken: () => injectionToken,
|
|
35
|
+
provide: () => provide,
|
|
36
|
+
provideRoot: () => provideRoot,
|
|
37
|
+
runInInjectionContext: () => runInInjectionContext
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(di_exports);
|
|
40
|
+
var import_core = require("@fluixi/core");
|
|
41
|
+
var import_dom = require("@fluixi/dom");
|
|
42
|
+
function injectionToken(name, options) {
|
|
43
|
+
return { id: Symbol(name), name, factory: options?.factory };
|
|
44
|
+
}
|
|
45
|
+
var _Injector_instances, build_fn, fromFactory_fn;
|
|
46
|
+
var Injector = class {
|
|
47
|
+
constructor(parent = null) {
|
|
48
|
+
this.parent = parent;
|
|
49
|
+
__privateAdd(this, _Injector_instances);
|
|
50
|
+
this.records = /* @__PURE__ */ new Map();
|
|
51
|
+
}
|
|
52
|
+
register(providers) {
|
|
53
|
+
for (const p of providers) {
|
|
54
|
+
this.records.set(p.provide.id, { provider: p, built: false, building: false, value: void 0 });
|
|
55
|
+
}
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/** Resolve a token from this injector, walking up the parent chain, then the token's factory. */
|
|
59
|
+
get(token) {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
let inj = this;
|
|
62
|
+
while (inj) {
|
|
63
|
+
const rec = inj.records.get(token.id);
|
|
64
|
+
if (rec) return __privateMethod(_a = inj, _Injector_instances, build_fn).call(_a, token, rec);
|
|
65
|
+
inj = inj.parent;
|
|
66
|
+
}
|
|
67
|
+
if (token.factory) return __privateMethod(_b = rootOf(this), _Injector_instances, fromFactory_fn).call(_b, token);
|
|
68
|
+
throw new Error(
|
|
69
|
+
`[fluixi/di] No provider for "${token.name}". Register it with provide()/provideRoot(), or give the token a { factory } to self-provide.`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
/** Run every built service's `onDestroy()`. Owner-scoped injectors call this on cleanup. */
|
|
73
|
+
dispose() {
|
|
74
|
+
for (const rec of this.records.values()) {
|
|
75
|
+
const v = rec.value;
|
|
76
|
+
if (rec.built && v && typeof v.onDestroy === "function") {
|
|
77
|
+
try {
|
|
78
|
+
v.onDestroy();
|
|
79
|
+
} catch (e) {
|
|
80
|
+
console.error("[fluixi/di] onDestroy threw —", e);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
this.records.clear();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
_Injector_instances = new WeakSet();
|
|
88
|
+
build_fn = function(token, rec) {
|
|
89
|
+
if (rec.built) return rec.value;
|
|
90
|
+
if (rec.building) throw new Error(`[fluixi/di] Circular dependency while resolving "${token.name}".`);
|
|
91
|
+
rec.building = true;
|
|
92
|
+
const p = rec.provider;
|
|
93
|
+
try {
|
|
94
|
+
if ("useValue" in p) rec.value = p.useValue;
|
|
95
|
+
else if ("useExisting" in p) rec.value = this.get(p.useExisting);
|
|
96
|
+
else {
|
|
97
|
+
const deps = (p.deps ?? []).map((d) => this.get(d));
|
|
98
|
+
rec.value = "useClass" in p ? new p.useClass(...deps) : p.useFactory(...deps);
|
|
99
|
+
}
|
|
100
|
+
} finally {
|
|
101
|
+
rec.building = false;
|
|
102
|
+
}
|
|
103
|
+
rec.built = true;
|
|
104
|
+
return rec.value;
|
|
105
|
+
};
|
|
106
|
+
fromFactory_fn = function(token) {
|
|
107
|
+
let rec = this.records.get(token.id);
|
|
108
|
+
if (!rec) {
|
|
109
|
+
rec = { provider: { provide: token, useFactory: token.factory }, built: false, building: false, value: void 0 };
|
|
110
|
+
this.records.set(token.id, rec);
|
|
111
|
+
}
|
|
112
|
+
return __privateMethod(this, _Injector_instances, build_fn).call(this, token, rec);
|
|
113
|
+
};
|
|
114
|
+
function rootOf(inj) {
|
|
115
|
+
let i = inj;
|
|
116
|
+
while (i.parent) i = i.parent;
|
|
117
|
+
return i;
|
|
118
|
+
}
|
|
119
|
+
var _rootProviders = [];
|
|
120
|
+
var _reqInjectors = /* @__PURE__ */ new WeakMap();
|
|
121
|
+
var _ownerInjectors = /* @__PURE__ */ new WeakMap();
|
|
122
|
+
var _clientRoot = null;
|
|
123
|
+
var _explicit = null;
|
|
124
|
+
function rootInjector() {
|
|
125
|
+
const ctx = (0, import_dom.getRequestContext)();
|
|
126
|
+
if (ctx) {
|
|
127
|
+
let inj = _reqInjectors.get(ctx);
|
|
128
|
+
if (!inj) _reqInjectors.set(ctx, inj = new Injector(null).register(_rootProviders));
|
|
129
|
+
return inj;
|
|
130
|
+
}
|
|
131
|
+
return _clientRoot ??= new Injector(null).register(_rootProviders);
|
|
132
|
+
}
|
|
133
|
+
function parentInjectorOf(owner) {
|
|
134
|
+
let o = owner?.parent;
|
|
135
|
+
while (o) {
|
|
136
|
+
const inj = _ownerInjectors.get(o);
|
|
137
|
+
if (inj) return inj;
|
|
138
|
+
o = o.parent;
|
|
139
|
+
}
|
|
140
|
+
return rootInjector();
|
|
141
|
+
}
|
|
142
|
+
function currentInjector() {
|
|
143
|
+
if (_explicit) return _explicit;
|
|
144
|
+
let o = (0, import_core.getOwner)();
|
|
145
|
+
while (o) {
|
|
146
|
+
const inj = _ownerInjectors.get(o);
|
|
147
|
+
if (inj) return inj;
|
|
148
|
+
o = o.parent;
|
|
149
|
+
}
|
|
150
|
+
return rootInjector();
|
|
151
|
+
}
|
|
152
|
+
function inject(token) {
|
|
153
|
+
return currentInjector().get(token);
|
|
154
|
+
}
|
|
155
|
+
function provide(providers) {
|
|
156
|
+
const owner = (0, import_core.getOwner)();
|
|
157
|
+
if (!owner) {
|
|
158
|
+
throw new Error("[fluixi/di] provide() must run inside a component/owner scope. Use provideRoot() for app-wide services.");
|
|
159
|
+
}
|
|
160
|
+
let inj = _ownerInjectors.get(owner);
|
|
161
|
+
if (!inj) {
|
|
162
|
+
inj = new Injector(parentInjectorOf(owner));
|
|
163
|
+
_ownerInjectors.set(owner, inj);
|
|
164
|
+
(0, import_core.onCleanup)(() => inj.dispose());
|
|
165
|
+
}
|
|
166
|
+
inj.register(providers);
|
|
167
|
+
return inj;
|
|
168
|
+
}
|
|
169
|
+
function provideRoot(providers) {
|
|
170
|
+
_rootProviders.push(...providers);
|
|
171
|
+
_clientRoot?.register(providers);
|
|
172
|
+
const ctx = (0, import_dom.getRequestContext)();
|
|
173
|
+
if (ctx) _reqInjectors.get(ctx)?.register(providers);
|
|
174
|
+
}
|
|
175
|
+
function runInInjectionContext(injector, fn) {
|
|
176
|
+
const prev = _explicit;
|
|
177
|
+
_explicit = injector;
|
|
178
|
+
try {
|
|
179
|
+
return fn();
|
|
180
|
+
} finally {
|
|
181
|
+
_explicit = prev;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function getInjector() {
|
|
185
|
+
return currentInjector();
|
|
186
|
+
}
|
|
187
|
+
function createInjector(providers, parent) {
|
|
188
|
+
return new Injector(parent === void 0 ? rootInjector() : parent).register(providers);
|
|
189
|
+
}
|
|
190
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
191
|
+
0 && (module.exports = {
|
|
192
|
+
Injector,
|
|
193
|
+
createInjector,
|
|
194
|
+
getInjector,
|
|
195
|
+
inject,
|
|
196
|
+
injectionToken,
|
|
197
|
+
provide,
|
|
198
|
+
provideRoot,
|
|
199
|
+
runInInjectionContext
|
|
200
|
+
});
|
package/dist/di.d.ts
CHANGED
|
@@ -44,20 +44,20 @@ export declare class Injector {
|
|
|
44
44
|
export declare function inject<T>(token: Token<T>): T;
|
|
45
45
|
/**
|
|
46
46
|
* Provide services for the CURRENT component/route and its descendants (owner-scoped). The
|
|
47
|
-
* injector is disposed
|
|
47
|
+
* injector is disposed: running each service's `onDestroy()`, when the component unmounts.
|
|
48
48
|
*/
|
|
49
49
|
export declare function provide(providers: ReadonlyArray<Provider>): Injector;
|
|
50
50
|
/**
|
|
51
51
|
* Provide app-wide services. On the client these are singletons; during SSR each request gets
|
|
52
|
-
* its OWN instances (the root injector is per-request)
|
|
52
|
+
* its OWN instances (the root injector is per-request), so a stateful root service can never
|
|
53
53
|
* leak between concurrent requests. Call at module load (e.g. in entry-client / entry-server).
|
|
54
54
|
*/
|
|
55
55
|
export declare function provideRoot(providers: ReadonlyArray<Provider>): void;
|
|
56
56
|
/** Run `fn` with an explicit injector as the injection context (e.g. inside a server function). */
|
|
57
57
|
export declare function runInInjectionContext<R>(injector: Injector, fn: () => R): R;
|
|
58
|
-
/** The injector for the current scope (advanced
|
|
58
|
+
/** The injector for the current scope (advanced: for passing to runInInjectionContext later). */
|
|
59
59
|
export declare function getInjector(): Injector;
|
|
60
|
-
/** A standalone injector (parent defaults to the root)
|
|
60
|
+
/** A standalone injector (parent defaults to the root), for tests / manual hierarchies. */
|
|
61
61
|
export declare function createInjector(providers: ReadonlyArray<Provider>, parent?: Injector | null): Injector;
|
|
62
62
|
export {};
|
|
63
63
|
//# sourceMappingURL=di.d.ts.map
|
package/dist/di.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"di.d.ts","sourceRoot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AAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAE5C;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAapE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,IAAI,CAKpE;AAED,mGAAmG;AACnG,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAQ3E;AAED,iGAAiG;AACjG,wBAAgB,WAAW,IAAI,QAAQ,CAEtC;AAED,2FAA2F;AAC3F,wBAAgB,cAAc,CAAC,SAAS,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,IAAI,GAAG,QAAQ,CAErG"}
|
package/dist/di.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fluixi/start/di
|
|
2
|
+
* @fluixi/start/di: dependency injection, the Angular way, but SSR-correct and reactive.
|
|
3
3
|
*
|
|
4
4
|
* Three things make this distinct from Angular's DI:
|
|
5
5
|
*
|
|
6
6
|
* 1. **SSR request isolation, for free.** A "root" provider is a singleton on the CLIENT but
|
|
7
|
-
* a fresh instance PER REQUEST on the server
|
|
7
|
+
* a fresh instance PER REQUEST on the server, because the root injector lives in the
|
|
8
8
|
* per-request `RequestContext` (the same machinery that isolates resources/markers). So
|
|
9
9
|
* a stateful root service (a per-user cache, a DB unit-of-work) never leaks across two
|
|
10
10
|
* concurrent SSR requests. No zone, no `providedIn` ceremony, no manual request injectors.
|
|
11
11
|
*
|
|
12
12
|
* 2. **The reactive owner tree IS the injector hierarchy.** `provide()` in a component
|
|
13
13
|
* attaches a child injector to that component's reactive owner; descendants `inject()`
|
|
14
|
-
* by walking the owner chain
|
|
14
|
+
* by walking the owner chain: exactly how context resolves. Component-scoped services
|
|
15
15
|
* are disposed with the component (their `onDestroy()` runs on owner cleanup).
|
|
16
16
|
*
|
|
17
17
|
* 3. **Function injection, tree-shakable tokens.** No decorators/reflect-metadata. A token
|
|
@@ -119,7 +119,7 @@ const _reqInjectors = new WeakMap(); // per-request root (server)
|
|
|
119
119
|
const _ownerInjectors = new WeakMap(); // per reactive owner (component scope)
|
|
120
120
|
let _clientRoot = null;
|
|
121
121
|
let _explicit = null;
|
|
122
|
-
/** The root injector
|
|
122
|
+
/** The root injector: per-request during SSR (isolated), a module singleton on the client. */
|
|
123
123
|
function rootInjector() {
|
|
124
124
|
const ctx = getRequestContext();
|
|
125
125
|
if (ctx) {
|
|
@@ -130,7 +130,7 @@ function rootInjector() {
|
|
|
130
130
|
}
|
|
131
131
|
return (_clientRoot ??= new Injector(null).register(_rootProviders));
|
|
132
132
|
}
|
|
133
|
-
/** Nearest ancestor owner injector, else the root
|
|
133
|
+
/** Nearest ancestor owner injector, else the root, the parent of a new component injector. */
|
|
134
134
|
function parentInjectorOf(owner) {
|
|
135
135
|
let o = owner?.parent;
|
|
136
136
|
while (o) {
|
|
@@ -161,7 +161,7 @@ export function inject(token) {
|
|
|
161
161
|
}
|
|
162
162
|
/**
|
|
163
163
|
* Provide services for the CURRENT component/route and its descendants (owner-scoped). The
|
|
164
|
-
* injector is disposed
|
|
164
|
+
* injector is disposed: running each service's `onDestroy()`, when the component unmounts.
|
|
165
165
|
*/
|
|
166
166
|
export function provide(providers) {
|
|
167
167
|
const owner = getOwner();
|
|
@@ -179,7 +179,7 @@ export function provide(providers) {
|
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
181
|
* Provide app-wide services. On the client these are singletons; during SSR each request gets
|
|
182
|
-
* its OWN instances (the root injector is per-request)
|
|
182
|
+
* its OWN instances (the root injector is per-request), so a stateful root service can never
|
|
183
183
|
* leak between concurrent requests. Call at module load (e.g. in entry-client / entry-server).
|
|
184
184
|
*/
|
|
185
185
|
export function provideRoot(providers) {
|
|
@@ -200,11 +200,11 @@ export function runInInjectionContext(injector, fn) {
|
|
|
200
200
|
_explicit = prev;
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
-
/** The injector for the current scope (advanced
|
|
203
|
+
/** The injector for the current scope (advanced: for passing to runInInjectionContext later). */
|
|
204
204
|
export function getInjector() {
|
|
205
205
|
return currentInjector();
|
|
206
206
|
}
|
|
207
|
-
/** A standalone injector (parent defaults to the root)
|
|
207
|
+
/** A standalone injector (parent defaults to the root), for tests / manual hierarchies. */
|
|
208
208
|
export function createInjector(providers, parent) {
|
|
209
209
|
return new Injector(parent === undefined ? rootInjector() : parent).register(providers);
|
|
210
210
|
}
|