@stacksjs/database 0.75.718 → 0.75.720
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.
|
@@ -24,4 +24,5 @@ export declare function frameworkRouteAdmission(options?: {
|
|
|
24
24
|
liveTables?: () => Promise<Set<string>>
|
|
25
25
|
appActionsRoot?: string
|
|
26
26
|
frameworkActionsRoot?: string
|
|
27
|
+
actionRegistryDirectory?: string
|
|
27
28
|
}): Promise<((handler: string) => string | undefined) | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync,readFileSync}from"node:fs";import{path}from"@stacksjs/path";import{getLiveTables}from"./fk-audit";import{declaredTableName,excludedFrameworkModels}from"./model-sources";const BUILTIN_NAMES=new Set(["Error","Request","Response","URL","Map","Set","Object","Array","Number","String","Date","Promise","Symbol"]);const LIVE_TABLES_TIMEOUT_MS=3000;export async function frameworkRouteAdmission(options={}){const excluded=options.excluded??excludedFrameworkModels();if(excluded.length===0)return;const live=await withTimeout((options.liveTables??getLiveTables)(),LIVE_TABLES_TIMEOUT_MS).catch(()=>{return});if(!live||live.size===0)return;const missing=excluded.map((model)=>({name:model.name,table:declaredTableName(model).toLowerCase()})).filter((model)=>!live.has(model.table));if(missing.length===0)return;const appActionsRoot=options.appActionsRoot??path.appPath("Actions");const frameworkActionsRoot=options.frameworkActionsRoot??path.frameworkPath("defaults/app/Actions");const transpiler=new Bun.Transpiler({loader:"ts",trimUnusedImports:false});const verdicts=new Map;return(handler)=>{if(verdicts.has(handler))return verdicts.get(handler);const verdict=judge(handler);verdicts.set(handler,verdict);return verdict};function judge(handler){if(!handler.startsWith("Actions/"))return;const
|
|
1
|
+
import{existsSync,readFileSync}from"node:fs";import{isAbsolute,relative,sep}from"node:path";import{loadRegisteredActionResolver}from"@stacksjs/path/module-resolution";import{path}from"@stacksjs/path";import{getLiveTables}from"./fk-audit";import{declaredTableName,excludedFrameworkModels}from"./model-sources";const BUILTIN_NAMES=new Set(["Error","Request","Response","URL","Map","Set","Object","Array","Number","String","Date","Promise","Symbol"]);const LIVE_TABLES_TIMEOUT_MS=3000;export async function frameworkRouteAdmission(options={}){const excluded=options.excluded??excludedFrameworkModels();if(excluded.length===0)return;const live=await withTimeout((options.liveTables??getLiveTables)(),LIVE_TABLES_TIMEOUT_MS).catch(()=>{return});if(!live||live.size===0)return;const missing=excluded.map((model)=>({name:model.name,table:declaredTableName(model).toLowerCase()})).filter((model)=>!live.has(model.table));if(missing.length===0)return;const appActionsRoot=options.appActionsRoot??path.appPath("Actions");const frameworkActionsRoot=options.frameworkActionsRoot??path.frameworkPath("defaults/app/Actions");const registryDirectory=options.actionRegistryDirectory??(options.frameworkActionsRoot?undefined:path.storagePath("framework/auto-imports"));const resolveRegisteredAction=registryDirectory?await loadRegisteredActionResolver(registryDirectory).catch(()=>{return}):undefined;const transpiler=new Bun.Transpiler({loader:"ts",trimUnusedImports:false});const verdicts=new Map;return(handler)=>{if(verdicts.has(handler))return verdicts.get(handler);const verdict=judge(handler);verdicts.set(handler,verdict);return verdict};function isAppAction(file){const local=relative(appActionsRoot,file);return Boolean(local)&&local!==".."&&!local.startsWith(`..${sep}`)&&!isAbsolute(local)}function judge(handler){if(!handler.startsWith("Actions/"))return;const actionName=handler.slice("Actions/".length).replace(/\.ts$/,"");if(existsSync(`${appActionsRoot}/${actionName}.ts`)||existsSync(`${appActionsRoot}/${actionName}.js`))return;let code;try{const registered=resolveRegisteredAction?.(`Actions/${actionName}`);if(registered&&isAppAction(registered))return;const file=registered??`${frameworkActionsRoot}/${actionName}.ts`;code=transpiler.transformSync(readFileSync(file,"utf8"))}catch{return}const fromOrm=ormImports(code);const needs=missing.filter((model)=>fromOrm.has(model.name)||!BUILTIN_NAMES.has(model.name)&&new RegExp(`\\b${model.name}\\b`).test(code)||new RegExp(`['"\`]${escapeRegExp(model.table)}['"\`]`).test(code));if(needs.length===0)return;return needs.map((model)=>`${model.name} (table "${model.table}" does not exist)`).join(", ")}}function ormImports(code){const names=new Set;for(const match of code.matchAll(/import\s*\{([^}]*)\}\s*from\s*["']@stacksjs\/orm(?:\/[^"']*)?["']/g)){for(const specifier of(match[1]??"").split(",")){const name=specifier.trim().replace(/^type\s+/,"").split(/\s+as\s+/)[0]?.trim();if(name)names.add(name)}}return names}function escapeRegExp(value){return value.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function withTimeout(promise,ms){let cancel=()=>{};const timeout=new Promise((resolve)=>{const timer=setTimeout(resolve,ms);cancel=()=>clearTimeout(timer)});return Promise.race([promise,timeout]).finally(()=>cancel())}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/database",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.720",
|
|
6
6
|
"description": "The Stacks database integration.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -66,26 +66,26 @@
|
|
|
66
66
|
"prepublishOnly": "bun run build"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@stacksjs/config": "0.75.
|
|
70
|
-
"@stacksjs/env": "0.75.
|
|
71
|
-
"@stacksjs/error-handling": "0.75.
|
|
72
|
-
"@stacksjs/faker": "0.75.
|
|
73
|
-
"@stacksjs/features": "0.75.
|
|
74
|
-
"@stacksjs/logging": "0.75.
|
|
75
|
-
"@stacksjs/model-meta": "0.75.
|
|
76
|
-
"@stacksjs/path": "0.75.
|
|
77
|
-
"@stacksjs/query-builder": "0.75.
|
|
78
|
-
"@stacksjs/security": "0.75.
|
|
79
|
-
"@stacksjs/storage": "0.75.
|
|
80
|
-
"@stacksjs/strings": "0.75.
|
|
69
|
+
"@stacksjs/config": "0.75.720",
|
|
70
|
+
"@stacksjs/env": "0.75.720",
|
|
71
|
+
"@stacksjs/error-handling": "0.75.720",
|
|
72
|
+
"@stacksjs/faker": "0.75.720",
|
|
73
|
+
"@stacksjs/features": "0.75.720",
|
|
74
|
+
"@stacksjs/logging": "0.75.720",
|
|
75
|
+
"@stacksjs/model-meta": "0.75.720",
|
|
76
|
+
"@stacksjs/path": "0.75.720",
|
|
77
|
+
"@stacksjs/query-builder": "0.75.720",
|
|
78
|
+
"@stacksjs/security": "0.75.720",
|
|
79
|
+
"@stacksjs/storage": "0.75.720",
|
|
80
|
+
"@stacksjs/strings": "0.75.720",
|
|
81
81
|
"@stacksjs/ts-validation": "^0.5.7",
|
|
82
82
|
"bun-query-builder": "^0.6.4",
|
|
83
83
|
"dynamodb-tooling": "^0.3.6"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@stacksjs/cli": "0.75.
|
|
87
|
-
"@stacksjs/router": "0.75.
|
|
88
|
-
"@stacksjs/utils": "0.75.
|
|
86
|
+
"@stacksjs/cli": "0.75.720",
|
|
87
|
+
"@stacksjs/router": "0.75.720",
|
|
88
|
+
"@stacksjs/utils": "0.75.720",
|
|
89
89
|
"better-dx": "^0.2.39"
|
|
90
90
|
}
|
|
91
91
|
}
|