@d1vij/jassm 0.1.18-beta.1 → 0.1.18

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/index.d.ts CHANGED
@@ -55,37 +55,24 @@ type GlobResult<T> = Record<string, T>;
55
55
  /**
56
56
  * Removes `.mdx` extension from a path
57
57
  */
58
- type StripExtension<T extends string> = T extends `${infer P}.mdx` ? P : T;
58
+ type StripExtension<T extends string> = T extends `${infer Rest}.mdx` ? Rest : T;
59
59
  /**
60
- * Replace filesystem root with a virtual route prefix
60
+ * Derives the route keys produced by the registry and
61
+ * replace filesystem root with a virtual route prefix
61
62
  *
62
63
  * Example:
63
64
  *
64
65
  * `/src/content/foo.mdx`
65
66
  * root = `/src/content`
66
67
  * virtual = `/blog`
67
- *
68
68
  * Result:
69
69
  * `/blog/foo`
70
70
  */
71
- type ReplaceRoot<
72
- P extends string,
73
- Root extends string,
74
- Virtual extends string
75
- > = P extends `${Root}${infer Rest}` ? `${Virtual}${StripExtension<Rest>}` : never;
76
- /**
77
- * Derives the route keys produced by the registry
78
- *
79
- * Example:
80
- *
81
- * `/src/blog/foo.mdx`
82
- * → `/blog/foo`
83
- */
84
71
  type RouteKey<
85
72
  Modules extends Record<string, unknown>,
86
73
  Root extends string,
87
74
  Virtual extends string
88
- > = ReplaceRoot<Extract<keyof Modules, string>, Root, Virtual>;
75
+ > = keyof { [K in keyof Modules as K extends `${string}${Root}/${infer Rest}.mdx` ? `${Virtual}/${Rest}` : never] : true } & string;
89
76
  /**
90
77
  * Options passed to {@link generateRegistry}
91
78
  */
@@ -102,7 +89,7 @@ type RegistryOptions<
102
89
  /**
103
90
  * Metadata extracted from each MDX file
104
91
  */
105
- metadataGlob: { [K in keyof Modules] : MetaType };
92
+ metadataGlob: { [K in keyof Modules as `${StripExtension<Extract<K, string>>}.meta.ts`] : MetaType };
106
93
  /**
107
94
  * Filesystem root path
108
95
  */
@@ -123,7 +110,7 @@ type RegistryOptions<
123
110
  */
124
111
  declare function generateRegistry<
125
112
  MetaType,
126
- Modules extends GlobResult<WrappedUnknownPromise>,
113
+ Modules extends Record<string, WrappedUnknownPromise>,
127
114
  Root extends string,
128
115
  Virtual extends string
129
116
  >({ modulesGlob, metadataGlob, root, virtual }: RegistryOptions<MetaType, Modules, Root, Virtual>): {
@@ -153,15 +140,15 @@ declare function generateRegistry<
153
140
  * - metadata
154
141
  */
155
142
  declare abstract class AbstractRegistry<
156
- Keys extends string,
157
- Components extends Record<Keys, React.LazyExoticComponent<React.ComponentType>>,
158
- Exports extends Record<Keys, unknown>,
159
- Metadata extends Record<Keys, unknown>
143
+ Key extends string,
144
+ Components extends Record<Key, React.LazyExoticComponent<React.ComponentType>>,
145
+ Exports extends Record<Key, unknown>,
146
+ Metadata extends Record<Key, unknown>
160
147
  > {
161
148
  /**
162
149
  * List of registry keys
163
150
  */
164
- abstract readonly keys: readonly Keys[];
151
+ abstract readonly keys: readonly Key[];
165
152
  /**
166
153
  * Lazy component registry
167
154
  */
@@ -174,18 +161,19 @@ declare abstract class AbstractRegistry<
174
161
  * Metadata registry
175
162
  */
176
163
  abstract readonly metadata: Metadata;
164
+ private get;
177
165
  /**
178
166
  * Retrieve a React component by route key
179
167
  */
180
- getComponent<Key extends Keys>(key: Key): Components[Key];
168
+ getComponent(key: string): Components[keyof Components];
181
169
  /**
182
170
  * Retrieve raw module exports for a route
183
171
  */
184
- getExport<Key extends Keys>(key: Key): Exports[Key];
172
+ getExport(key: string): Exports[keyof Exports];
185
173
  /**
186
174
  * Retrieve metadata for a route
187
175
  */
188
- getMetadata<Key extends Keys>(key: Key): Metadata[Key];
176
+ getMetadata(key: string): Metadata[keyof Metadata];
189
177
  }
190
178
  /**
191
179
  * Primary registry implementation.
@@ -195,7 +183,7 @@ declare abstract class AbstractRegistry<
195
183
  */
196
184
  declare class Registry<
197
185
  MetaType,
198
- Modules extends GlobResult<WrappedUnknownPromise>,
186
+ Modules extends Record<`${Root}/${string}.mdx`, WrappedUnknownPromise>,
199
187
  Root extends string,
200
188
  Virtual extends string
201
189
  > extends AbstractRegistry<RouteKey<Modules, Root, Virtual>, Record<RouteKey<Modules, Root, Virtual>, React.LazyExoticComponent<React.ComponentType>>, Record<RouteKey<Modules, Root, Virtual>, unknown>, Record<RouteKey<Modules, Root, Virtual>, MetaType>> {
@@ -232,7 +220,7 @@ declare class CoalescedRegistry<Registries extends AbstractRegistry<any, any, an
232
220
  */
233
221
  declare const StyleClassesList: readonly ["header", "header_button", "header_1", "header_2", "header_3", "header_4", "header_5", "header_6", "header_icon", "anchor", "button", "bold", "italic", "span", "striked", "paragraph", "code", "preformatted", "blockquote", "horizontal_line", "image", "list", "unordered_list", "ordered_list", "list_item", "table", "table_head", "table_head_cell", "table_body", "table_row", "table_data", "table_container", "table_action_buttons_details", "table_action_buttons_summary", "table_action_button", "table_action_button_html", "table_action_button_csv", "table_action_button_json", "table_action_button_markdown"];
234
222
  type StyleClasses = (typeof StyleClassesList)[number];
235
- type StyleClassesMap = { [K in StyleClasses] : string };
223
+ type StyleClassesMap = Partial<{ [K in StyleClasses] : string }>;
236
224
  /**
237
225
  * Context which defines styles for the loaded component(s)
238
226
  */
@@ -244,7 +232,7 @@ declare const StyleContext: React.Context<StyleClassesMap | null>;
244
232
  declare function useStyles(): StyleClassesMap;
245
233
  type MDXFromComponentProps = {
246
234
  source: React.ComponentType<MDXProps>;
247
- styles: StyleClassesMap;
235
+ styles: Partial<StyleClassesMap>;
248
236
  elements?: MDXComponents2;
249
237
  fallback?: React.ReactNode;
250
238
  };
package/dist/index.js CHANGED
@@ -512,17 +512,20 @@ function generateRegistry({
512
512
  virtual
513
513
  }) {
514
514
  const paths = Object.keys(modulesGlob);
515
- const keys = new Array(paths.length);
515
+ const keys = [];
516
516
  const _components = [];
517
517
  const _exports = [];
518
518
  const _metadata = [];
519
- for (const [idx, path] of paths.entries()) {
519
+ console.log(metadataGlob);
520
+ for (const path of paths) {
520
521
  const route = path.replace(root, virtual).replace(".mdx", "");
521
522
  const loader = modulesGlob[path];
522
- keys[idx] = route;
523
+ keys.push(route);
523
524
  _components.push([route, lazy(loader)]);
524
525
  _exports.push([route, loader()]);
525
- _metadata.push([route, metadataGlob[path]]);
526
+ const metaLoader = metadataGlob[path.replace(".mdx", ".meta.ts")];
527
+ console.log(typeof metaLoader);
528
+ _metadata.push([route, metaLoader]);
526
529
  }
527
530
  return {
528
531
  keys,
@@ -533,14 +536,21 @@ function generateRegistry({
533
536
  }
534
537
 
535
538
  class AbstractRegistry {
539
+ get(_from, key) {
540
+ const value = _from[key];
541
+ if (!value) {
542
+ throw new Error(`Invalid key passed ${key.toString()} to access whatever the fuck we were extractign`);
543
+ }
544
+ return value;
545
+ }
536
546
  getComponent(key) {
537
- return this.components[key];
547
+ return this.get(this.components, key);
538
548
  }
539
549
  getExport(key) {
540
- return this.exports[key];
550
+ return this.get(this.exports, key);
541
551
  }
542
552
  getMetadata(key) {
543
- return this.metadata[key];
553
+ return this.get(this.metadata, key);
544
554
  }
545
555
  }
546
556
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d1vij/jassm",
3
- "version": "0.1.18-beta.1",
3
+ "version": "0.1.18",
4
4
  "description": "Just another static site maker. Create simple content driven sites using MDX and React along with Typescript safety.",
5
5
  "homepage": "https://github.com/d1vij/jassm",
6
6
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  "scripts": {
34
34
  "build": "bunup",
35
35
  "dev:ui": "cd test/ui && vite",
36
- "dev": "bunup --watch",
36
+ "dev": "vite",
37
37
  "prepare": "bun simple-git-hooks",
38
38
  "type-check": "tsc --noEmit",
39
39
  "prepack": "bun run build",
@@ -41,9 +41,7 @@
41
41
  "lint": "biome check --fix --unsafe && tsc -b",
42
42
  "format": "biome format --write"
43
43
  },
44
- "dependencies": {
45
- "@d1vij/shit-i-always-use": "^0.1.3"
46
- },
44
+ "dependencies": {},
47
45
  "devDependencies": {
48
46
  "@biomejs/biome": "^2.4.6",
49
47
  "@types/bun": "^1.3.9",
@@ -60,12 +58,11 @@
60
58
  "react": "^19.2.4",
61
59
  "react-dom": "^19.2.4",
62
60
  "remark-gfm": "^4.0.1",
63
- "typescript": ">=4.5.0",
64
- "vite": "^7.3.1"
61
+ "@d1vij/shit-i-always-use": "^0.1.9"
65
62
  },
66
63
  "peerDependenciesMeta": {
67
64
  "typescript": {
68
- "optional": true
65
+ "optional": false
69
66
  }
70
67
  },
71
68
  "simple-git-hooks": {