@stacksjs/server 0.70.95 → 0.70.97

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/imports.d.ts CHANGED
@@ -11,6 +11,8 @@ export declare function generateAutoImportFiles(): Promise<void>;
11
11
  * available globally without explicit imports.
12
12
  */
13
13
  export declare function initiateImports(): void;
14
+ /** Generate TypeScript declarations for the globals injected by the server. */
15
+ export declare function generateServerAutoImportTypes(): Promise<void>;
14
16
  /**
15
17
  * Import and inject all auto-imports into globalThis for runtime access.
16
18
  * Call this early in your application startup.
package/dist/imports.js CHANGED
@@ -5,6 +5,7 @@ import { log } from "@stacksjs/logging";
5
5
  import { path } from "@stacksjs/path";
6
6
  import { autoImports, generateRuntimeIndex, generateGlobalsScript } from "bun-plugin-auto-imports";
7
7
  import { globSync } from "@stacksjs/storage";
8
+ import { primitiveAutoImportEntries, primitiveModules } from "./primitive-imports";
8
9
  const OPTIONAL_MODEL_MODULES = {
9
10
  commerce: ["config/commerce.ts"],
10
11
  Content: ["config/cms.ts", "config/blog.ts"],
@@ -91,6 +92,7 @@ async function generateDefineModelIndex(entries, outputPath) {
91
92
  `);
92
93
  }
93
94
  export async function generateAutoImportFiles() {
95
+ await generateServerAutoImportTypes();
94
96
  const userFunctionsPath = path.resourcesPath("functions"), defaultFunctionsPath = path.storagePath("framework/defaults/functions"), functionsPath = userFunctionsPath, outputDir = path.storagePath("framework/auto-imports"), userModelsPath = path.userModelsPath(), defaultModelDirs = resolveDefaultModelDirs(), [defaultsRoot = path.storagePath("framework/defaults/app/Models"), ...enabledSubdirs] = defaultModelDirs, userJobsPath = path.userJobsPath(), userControllersPath = path.userControllersPath(), defaultControllersPath = path.storagePath("framework/defaults/app/Controllers");
95
97
  await Bun.write(`${outputDir}/.gitkeep`, "");
96
98
  const functionsIndexPath = `${outputDir}/functions.ts`;
@@ -148,7 +150,12 @@ export function initiateImports() {
148
150
  as: exp.name
149
151
  })), options = {
150
152
  dts: path.storagePath("framework/types/server-auto-imports.d.ts"),
151
- imports: [...defineModelImports, ...jobImports, ...controllerImports],
153
+ imports: [
154
+ ...primitiveAutoImportEntries(),
155
+ ...defineModelImports,
156
+ ...jobImports,
157
+ ...controllerImports
158
+ ],
152
159
  dirs: [functionsPath, defaultFunctionsPath],
153
160
  eslint: {
154
161
  enabled: !0,
@@ -160,37 +167,41 @@ export function initiateImports() {
160
167
  console.error("[Server] Failed to generate auto-import files:", err);
161
168
  });
162
169
  }
170
+ export async function generateServerAutoImportTypes() {
171
+ const userModelsPath = path.userModelsPath(), defaultModelDirs = resolveDefaultModelDirs(), [defaultsRoot = path.storagePath("framework/defaults/app/Models"), ...enabledSubdirs] = defaultModelDirs, modelExports = [
172
+ ...scanDefineModelExports(userModelsPath),
173
+ ...scanDefineModelExports(defaultsRoot, { recursive: !1 }),
174
+ ...enabledSubdirs.flatMap((dir) => scanDefineModelExports(dir))
175
+ ], jobExports = scanDefineModelExports(path.userJobsPath()), controllerExports = [
176
+ ...scanDefineModelExports(path.userControllersPath()),
177
+ ...scanDefineModelExports(path.storagePath("framework/defaults/app/Controllers"))
178
+ ], seen = new Set, valueExports = [...modelExports, ...jobExports, ...controllerExports].filter((exp) => !GLOBAL_SHADOW_BLOCKLIST.has(exp.name)).filter((exp) => {
179
+ if (seen.has(exp.name))
180
+ return !1;
181
+ seen.add(exp.name);
182
+ return !0;
183
+ }), outputPath = path.storagePath("framework/types/server-auto-imports.d.ts"), outputDir = dirname(outputPath), declaredValues = new Set(valueExports.map((exp) => exp.name)), lines = [
184
+ "// Generated by Stacks server auto-imports",
185
+ "// This file is regenerated automatically when the API starts.",
186
+ "export {}",
187
+ "declare global {"
188
+ ];
189
+ for (const { from, name, as } of primitiveAutoImportEntries())
190
+ if (!declaredValues.has(as))
191
+ lines.push(` const ${as}: typeof import('${from}')['${name}']`);
192
+ for (const exp of valueExports) {
193
+ const importPath = relative(outputDir, exp.file).replace(/\\/g, "/").replace(/\.ts$/, ""), relativePath = importPath.startsWith(".") ? importPath : `./${importPath}`;
194
+ lines.push(` const ${exp.name}: typeof import('${relativePath}')['default']`);
195
+ }
196
+ lines.push("}", "");
197
+ await Bun.write(outputPath, lines.join(`
198
+ `));
199
+ }
163
200
  export async function injectGlobalAutoImports() {
164
201
  if (globalThis.__stacksAutoImportsInjected)
165
202
  return;
166
203
  globalThis.__stacksAutoImportsInjected = !0;
167
- const errors = [], primitiveModules = [
168
- ["@stacksjs/types", ["Every", "ExitCode"]],
169
- ["@stacksjs/path", ["path"]],
170
- ["@stacksjs/error-handling", ["HttpError", "handleError"]],
171
- ["@stacksjs/logging", ["log"]],
172
- ["@stacksjs/config", ["config"]],
173
- ["@stacksjs/validation", ["schema"]],
174
- ["@stacksjs/router", ["response", "request", "route", "Middleware", "url"]],
175
- ["@stacksjs/storage", ["storage", "fs"]],
176
- ["@stacksjs/orm", ["defineModel", "toAttrs"]],
177
- ["@stacksjs/database", ["db", "sql"]],
178
- ["@stacksjs/email", ["mail", "template"]],
179
- ["@stacksjs/queue", ["Job"]],
180
- ["@stacksjs/scheduler", ["schedule"]],
181
- ["@stacksjs/actions", ["Action"]],
182
- ["@stacksjs/auth", ["Auth", "register", "sessionCheck"]],
183
- ["@stacksjs/events", ["dispatch", "listen", "emitter"]],
184
- ["@stacksjs/feature-flags", ["Feature"]],
185
- ["@stacksjs/security", ["makeHash", "verifyHash"]],
186
- ["@stacksjs/collections", ["collect"]],
187
- ["@stacksjs/cli", ["quotes"]],
188
- ["@stacksjs/notifications", ["notify", "useNotification", "useEmail", "useSMS", "useChat", "useDatabase"]],
189
- ["@stacksjs/realtime", ["emit", "emitToUser", "emitToUsers", "createChannel", "dispatchBroadcast"]],
190
- ["@stacksjs/i18n", ["I18n", "t", "tc", "te", "setLocale", "getLocale"]],
191
- ["@stacksjs/stx", ["state", "derived", "effect"]],
192
- ["@stacksjs/browser", ["useDark", "usePreferredDark", "useToggle", "useStorage"]]
193
- ], importWithTimeout = async (pkg) => {
204
+ const errors = [], importWithTimeout = async (pkg) => {
194
205
  return Promise.race([
195
206
  import(pkg),
196
207
  new Promise((_, reject) => setTimeout(() => reject(Error(`auto-import timed out: ${pkg}`)), 4000))
@@ -0,0 +1,10 @@
1
+ export declare function primitiveAutoImportEntries(): void;
2
+ /**
3
+ * Runtime values Stacks makes available as server-side globals.
4
+ *
5
+ * This list is shared by runtime injection and the auto-import declaration
6
+ * generator so globals such as `db` have the same behavior in Bun and in the
7
+ * TypeScript language service.
8
+ */
9
+ export declare const primitiveModules: readonly PrimitiveModule[];
10
+ export type PrimitiveModule = readonly [module: string, names: readonly string[]];
@@ -0,0 +1,29 @@
1
+ export const primitiveModules = [
2
+ ["@stacksjs/path", ["path"]],
3
+ ["@stacksjs/error-handling", ["HttpError", "handleError"]],
4
+ ["@stacksjs/logging", ["log"]],
5
+ ["@stacksjs/config", ["config"]],
6
+ ["@stacksjs/validation", ["schema"]],
7
+ ["@stacksjs/router", ["response", "request", "route", "Middleware", "url"]],
8
+ ["@stacksjs/storage", ["storage", "fs"]],
9
+ ["@stacksjs/orm", ["defineModel", "toAttrs"]],
10
+ ["@stacksjs/database", ["db", "sql"]],
11
+ ["@stacksjs/email", ["mail", "template"]],
12
+ ["@stacksjs/queue", ["Job"]],
13
+ ["@stacksjs/scheduler", ["schedule"]],
14
+ ["@stacksjs/actions", ["Action"]],
15
+ ["@stacksjs/auth", ["Auth", "register", "sessionCheck"]],
16
+ ["@stacksjs/events", ["dispatch", "listen", "emitter"]],
17
+ ["@stacksjs/feature-flags", ["Feature"]],
18
+ ["@stacksjs/security", ["makeHash", "verifyHash"]],
19
+ ["@stacksjs/collections", ["collect"]],
20
+ ["@stacksjs/cli", ["quotes"]],
21
+ ["@stacksjs/notifications", ["notify", "useNotification", "useEmail", "useSMS", "useChat", "useDatabase"]],
22
+ ["@stacksjs/realtime", ["emit", "emitToUser", "emitToUsers", "createChannel", "dispatchBroadcast"]],
23
+ ["@stacksjs/i18n", ["I18n", "t", "tc", "te", "setLocale", "getLocale"]],
24
+ ["@stacksjs/stx", ["state", "derived", "effect"]],
25
+ ["@stacksjs/browser", ["useDark", "usePreferredDark", "useToggle", "useStorage"]]
26
+ ];
27
+ export function primitiveAutoImportEntries() {
28
+ return primitiveModules.flatMap(([from, names]) => names.map((name) => ({ from, name, as: name })));
29
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/server",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.70.95",
5
+ "version": "0.70.97",
6
6
  "description": "Local development and production-ready.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -53,11 +53,11 @@
53
53
  "prepublishOnly": "bun run build"
54
54
  },
55
55
  "devDependencies": {
56
- "@stacksjs/config": "0.70.95",
56
+ "@stacksjs/config": "0.70.97",
57
57
  "better-dx": "^0.2.16",
58
- "@stacksjs/path": "0.70.95",
59
- "@stacksjs/router": "0.70.95",
60
- "@stacksjs/validation": "0.70.95"
58
+ "@stacksjs/path": "0.70.97",
59
+ "@stacksjs/router": "0.70.97",
60
+ "@stacksjs/validation": "0.70.97"
61
61
  },
62
62
  "dependencies": {
63
63
  "bun-plugin-auto-imports": "^0.4.0"