@kosmojs/lib 0.0.26

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present, Slee Woo and KosmoJS contributors.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @kosmojs/lib
2
+
3
+ TODO: Add package description
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install -D @kosmojs/lib
9
+ ```
10
+
11
+ ## Documentation
12
+
13
+ See [kosmojs.dev](https://kosmojs.dev)
14
+
15
+ ## License
16
+
17
+ MIT
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "type": "module",
3
+ "name": "@kosmojs/lib",
4
+ "version": "0.0.26",
5
+ "author": "Slee Woo",
6
+ "license": "MIT",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "files": [
11
+ "pkg/*"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./pkg/index.d.ts",
16
+ "default": "./pkg/index.js"
17
+ }
18
+ },
19
+ "dependencies": {
20
+ "@topcli/spinner": "^4.2.1",
21
+ "crc": "^4.3.2",
22
+ "handlebars": "^4.7.8",
23
+ "mime-types": "^3.0.2",
24
+ "path-to-regexp": "^8.3.0",
25
+ "picomatch": "^4.0.4",
26
+ "tfusion": "^0.0.23",
27
+ "ts-morph": "^27.0.2",
28
+ "@kosmojs/api": "^0.0.26"
29
+ },
30
+ "devDependencies": {
31
+ "@types/mime-types": "^3.0.1",
32
+ "@types/picomatch": "^4.0.2",
33
+ "vite": "^8.0.2"
34
+ },
35
+ "scripts": {
36
+ "build": "esbuilder src/index.ts",
37
+ "test": "vitest --root ../../.. --project core/lib"
38
+ }
39
+ }
package/pkg/ast.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { flattener } from "tfusion";
2
+ import { type CallExpression, Project, type ProjectOptions, type SourceFile } from "ts-morph";
3
+ import { type HTTPMethod } from "@kosmojs/api";
4
+ import type { ApiRoute, SourceFolder, TypeDeclaration, ValidationDefinition } from "./types";
5
+ type PathResolver = (path: string) => string;
6
+ export declare const astFactory: () => {
7
+ createProject: (opts?: ProjectOptions) => Project;
8
+ extractDefaultExport: (sourceFile: SourceFile) => CallExpression | undefined;
9
+ extractParamsRefinements: (callExpression: CallExpression) => Array<{
10
+ index: number;
11
+ text: string;
12
+ }> | undefined;
13
+ extractRouteMethods: (route: Pick<ApiRoute, "id" | "name">, callExpression: CallExpression) => Array<{
14
+ method: HTTPMethod;
15
+ validationDefinitions: Array<ValidationDefinition>;
16
+ }>;
17
+ extractTypeDeclarations: (sourceFile: SourceFile, opts?: {
18
+ relpathResolver?: PathResolver;
19
+ withReferencedFiles?: boolean;
20
+ }) => [d: Array<TypeDeclaration>, f?: Array<string>];
21
+ resolveRouteSignature: (route: Pick<ApiRoute, "id" | "name" | "fileFullpath" | "optionalParams">, opts?: {
22
+ relpathResolver?: PathResolver;
23
+ sourceFile?: SourceFile;
24
+ withReferencedFiles?: boolean;
25
+ }) => Promise<{
26
+ typeDeclarations: TypeDeclaration[];
27
+ paramsRefinements: {
28
+ index: number;
29
+ text: string;
30
+ }[] | undefined;
31
+ methods: ("HEAD" | "OPTIONS" | "GET" | "PUT" | "PATCH" | "POST" | "DELETE")[];
32
+ validationDefinitions: ValidationDefinition[];
33
+ referencedFiles: string[] | undefined;
34
+ }>;
35
+ typeResolverFactory: ({ root }: SourceFolder) => {
36
+ getSourceFile: (fileFullpath: string) => SourceFile;
37
+ refreshSourceFile: (fileFullpath: string) => Promise<void>;
38
+ literalTypesResolver: (literalTypes: string, options: Parameters<typeof flattener>[2]) => import("tfusion").ResolvedType[];
39
+ };
40
+ };
41
+ export {};
@@ -0,0 +1,14 @@
1
+ export declare const defaults: {
2
+ appPrefix: string;
3
+ srcPrefix: string;
4
+ libPrefix: string;
5
+ coreDir: string;
6
+ srcDir: string;
7
+ libDir: string;
8
+ configDir: string;
9
+ apiDir: string;
10
+ pagesDir: string;
11
+ entryDir: string;
12
+ fetchDir: string;
13
+ refineTypeName: string;
14
+ };
@@ -0,0 +1,58 @@
1
+ import type { DefineGenerator, DefineGeneratorFactory, GeneratorMeta } from "./types";
2
+ export declare const GENERATOR_META: unique symbol;
3
+ /**
4
+ * Define a generator with metadata stored internally.
5
+ *
6
+ * Metadata is attached to both the generator module and its instances,
7
+ * accessible via `getGeneratorMeta()`
8
+ *
9
+ * **User-facing API:**
10
+ * ```ts
11
+ * import { defineConfig, ssrGenerator } from "@kosmojs/dev";
12
+ *
13
+ * export default defineConfig({
14
+ * generators: [ssrGenerator()], // Clean instantiation
15
+ * });
16
+ * ```
17
+ *
18
+ * **Internal dev plugin usage:**
19
+ * ```ts
20
+ * import { getGeneratorMeta } from "@kosmojs/lib";
21
+ *
22
+ * // Read module metadata before instantiation
23
+ * const meta = getGeneratorMeta(ssrGenerator);
24
+ * console.log(meta?.slot); // "ssr"
25
+ *
26
+ * // Read instance metadata after instantiation
27
+ * for (const generator of config.generators) {
28
+ * const meta = getGeneratorMeta(generator);
29
+ * if (meta?.dependencies) {
30
+ * // Check/install dependencies
31
+ * }
32
+ * }
33
+ * ```
34
+ *
35
+ * @example Define a generator
36
+ * ```ts
37
+ * import { defineGenerator } from "@kosmojs/lib";
38
+ *
39
+ * export default defineGenerator(
40
+ * () => {
41
+ * return async (sourceFolder) => {
42
+ * // Generator logic
43
+ * };
44
+ * },
45
+ * {
46
+ * name: "Example",
47
+ * slot: "example",
48
+ * dependencies: {
49
+ * "some-package": "^1.0.0"
50
+ * }
51
+ * }
52
+ * );
53
+ * ```
54
+ * */
55
+ export declare const defineGenerator: DefineGenerator;
56
+ export declare const isGenerator: (fn: Function) => fn is Function & Record<typeof GENERATOR_META, unknown>;
57
+ export declare const getGeneratorMeta: (fn: Function) => GeneratorMeta | undefined;
58
+ export declare const defineGeneratorFactory: DefineGeneratorFactory;
package/pkg/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from "./ast";
2
+ export * from "./defaults";
3
+ export * from "./generators";
4
+ export * from "./paths";
5
+ export * from "./render";
6
+ export * from "./routes";
7
+ export * from "./spinner";
8
+ export * from "./typebox";
9
+ export * from "./types";