@stacksjs/browser 0.74.48 → 0.74.51
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/model-glob.d.ts +30 -0
- package/dist/model-glob.js +1 -0
- package/dist/model-loader.d.ts +8 -1
- package/dist/model-loader.js +1 -1
- package/package.json +11 -5
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { BrowserModelDefinition } from './model-loader';
|
|
2
|
+
/**
|
|
3
|
+
* The `import.meta.glob` half of browser model loading, kept in its own module
|
|
4
|
+
* on purpose.
|
|
5
|
+
*
|
|
6
|
+
* `import.meta` is a SyntaxError outside a module, and it is a PARSE error —
|
|
7
|
+
* it cannot be guarded, defaulted or caught, because nothing in the file runs.
|
|
8
|
+
* model-loader.ts used to read it behind `typeof import.meta.glob ===
|
|
9
|
+
* 'function'`, which looks like a runtime check and is not one: the file fails
|
|
10
|
+
* before that expression is ever evaluated.
|
|
11
|
+
*
|
|
12
|
+
* That mattered because this package is transpiled file-by-file rather than
|
|
13
|
+
* bundled, so the token travels verbatim into an application's client bundle.
|
|
14
|
+
* Any page whose bundle is emitted as a classic script then fails to parse —
|
|
15
|
+
* taking down every feature on it, not just models. It surfaced as a public
|
|
16
|
+
* share page stuck on a spinner with one SyntaxError in the console.
|
|
17
|
+
*
|
|
18
|
+
* Isolating it here means the default path in model-loader.ts cannot carry the
|
|
19
|
+
* token at all, while Vite consumers keep the build-time glob by importing
|
|
20
|
+
* this module and handing the result over:
|
|
21
|
+
*
|
|
22
|
+
* import { modelModules } from '@stacksjs/browser/model-glob'
|
|
23
|
+
* import { loadBrowserModels } from '@stacksjs/browser'
|
|
24
|
+
*
|
|
25
|
+
* loadBrowserModels(modelModules)
|
|
26
|
+
*
|
|
27
|
+
* Importing this module outside a module context is the one thing that will
|
|
28
|
+
* still throw, which is correct: that is precisely where the glob cannot work.
|
|
29
|
+
*/
|
|
30
|
+
export declare const modelModules: Record<string, { default: BrowserModelDefinition }>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const modelModules=typeof import.meta.glob==="function"?import.meta.glob("~/app/Models/*.ts",{eager:!0}):{};
|
package/dist/model-loader.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add model definitions for `loadBrowserModels()` to pick up.
|
|
3
|
+
*
|
|
4
|
+
* Additive rather than replacing, so several sources can contribute and a
|
|
5
|
+
* second call cannot silently drop the first one's models.
|
|
6
|
+
*/
|
|
7
|
+
export declare function registerModelModules(modules: Record<string, { default: BrowserModelDefinition }>): void;
|
|
1
8
|
/**
|
|
2
9
|
* Load all models and register them on window.StacksBrowser
|
|
3
10
|
*/
|
|
4
|
-
export declare function loadBrowserModels(): void;
|
|
11
|
+
export declare function loadBrowserModels(modules?: Record<string, { default: BrowserModelDefinition }>): void;
|
|
5
12
|
/**
|
|
6
13
|
* Get a loaded model by name
|
|
7
14
|
*/
|
package/dist/model-loader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createBrowserModel}from"bun-query-builder/browser";function isBrowserModel(value){return value!=null&&typeof value.all==="function"&&typeof value.find==="function"}const
|
|
1
|
+
import{createBrowserModel}from"bun-query-builder/browser";function isBrowserModel(value){return value!=null&&typeof value.all==="function"&&typeof value.find==="function"}const registeredModules={};export function registerModelModules(modules){Object.assign(registeredModules,modules)}export function loadBrowserModels(modules){if(typeof window>"u")return;if(modules)registerModelModules(modules);const modelModules=registeredModules;if(!window.StacksBrowser)window.StacksBrowser={};for(const[path,module]of Object.entries(modelModules)){const definition=module.default;if(!definition||!definition.name){console.warn(`[model-loader] Skipping ${path}: no valid model definition`);continue}if(!definition.traits?.useApi?.uri)continue;try{const browserModel=createBrowserModel({name:definition.name,table:definition.table??definition.name.toLowerCase(),primaryKey:definition.primaryKey||"id",traits:{useUuid:definition.traits?.useUuid??!1,useTimestamps:definition.traits?.useTimestamps??!0,useSoftDeletes:definition.traits?.useSoftDeletes??!1,useApi:definition.traits?.useApi},attributes:extractBrowserAttributes(definition.attributes??{})});window.StacksBrowser[definition.name]=browserModel}catch(error){console.error(`[model-loader] Failed to create browser model for ${definition.name}:`,error)}}}function extractBrowserAttributes(attributes){const browserAttrs={};for(const[name,attr]of Object.entries(attributes))browserAttrs[name]={fillable:attr.fillable??!1,hidden:attr.hidden??!1,guarded:attr.guarded??!1,nullable:attr.nullable??!1};return browserAttrs}export function getBrowserModel(name){if(typeof window>"u")return null;const entry=window.StacksBrowser?.[name];return isBrowserModel(entry)?entry:null}export function getBrowserModelNames(){if(typeof window>"u")return[];const stacksBrowser=window.StacksBrowser;if(!stacksBrowser)return[];return Object.keys(stacksBrowser).filter((key)=>isBrowserModel(stacksBrowser[key]))}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/browser",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.74.
|
|
5
|
+
"version": "0.74.51",
|
|
6
6
|
"description": "Stacks core frontend/browser functionalities.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -32,6 +32,12 @@
|
|
|
32
32
|
"import": "./dist/index.js",
|
|
33
33
|
"default": "./dist/index.js"
|
|
34
34
|
},
|
|
35
|
+
"./model-glob": {
|
|
36
|
+
"types": "./dist/model-glob.d.ts",
|
|
37
|
+
"bun": "./dist/model-glob.js",
|
|
38
|
+
"import": "./dist/model-glob.js",
|
|
39
|
+
"default": "./dist/model-glob.js"
|
|
40
|
+
},
|
|
35
41
|
"./composables": {
|
|
36
42
|
"types": "./dist/composables/index.d.ts",
|
|
37
43
|
"bun": "./dist/composables/index.js",
|
|
@@ -69,9 +75,9 @@
|
|
|
69
75
|
"prepublishOnly": "bun run build"
|
|
70
76
|
},
|
|
71
77
|
"dependencies": {
|
|
72
|
-
"@stacksjs/composables": "0.74.
|
|
73
|
-
"@stacksjs/datetime": "0.74.
|
|
74
|
-
"@stacksjs/strings": "0.74.
|
|
78
|
+
"@stacksjs/composables": "0.74.51",
|
|
79
|
+
"@stacksjs/datetime": "0.74.51",
|
|
80
|
+
"@stacksjs/strings": "0.74.51",
|
|
75
81
|
"@stacksjs/stx": "^0.2.286",
|
|
76
82
|
"bun-query-builder": "^0.2.70"
|
|
77
83
|
},
|
|
@@ -84,7 +90,7 @@
|
|
|
84
90
|
}
|
|
85
91
|
},
|
|
86
92
|
"devDependencies": {
|
|
87
|
-
"@stacksjs/utils": "0.74.
|
|
93
|
+
"@stacksjs/utils": "0.74.51",
|
|
88
94
|
"@stripe/stripe-js": "^9.10.0",
|
|
89
95
|
"better-dx": "^0.2.24"
|
|
90
96
|
}
|