@kcflow/core 1.0.2

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/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # @kcflow/core
2
+
3
+ The core type definitions and helper utilities for **KCFlow** - The Cloud-Based Type-Safe API Generator.
4
+
5
+ This package provides the `t` builder and `defineResource` function required to define your API specification in `kcflow.spec.ts`.
6
+
7
+ ## 📦 Installation
8
+
9
+ ```bash
10
+ npm install @kcflow/core
11
+ ```
12
+
13
+
14
+ ## 🚀 Usage
15
+
16
+ Create a file named `kcflow.spec.ts` in your project root and define your API structure:
17
+
18
+ ```typescript
19
+ import { defineResource, t } from '@kcflow/core';
20
+
21
+ export default defineResource({
22
+ // Define a resource group (e.g., /users)
23
+ users: {
24
+ // Define an endpoint (GET /users)
25
+ list: {
26
+ method: 'GET',
27
+ path: '/users',
28
+ // Define Query Parameters or Body
29
+ body: t.object({
30
+ limit: t.number({ required: false }),
31
+ page: t.number({ required: false }),
32
+ }),
33
+ // Define Response Structure
34
+ response: t.array(
35
+ t.object({
36
+ id: t.string(),
37
+ name: t.string(),
38
+ email: t.string(),
39
+ role: t.string({ required: false })
40
+ })
41
+ ),
42
+ // Define Required Headers (Optional)
43
+ headers: t.object({
44
+ 'Authorization': t.string()
45
+ })
46
+ },
47
+
48
+ // Define another endpoint (POST /users)
49
+ create: {
50
+ method: 'POST',
51
+ path: '/users',
52
+ body: t.object({
53
+ name: t.string(),
54
+ email: t.string(),
55
+ password: t.string()
56
+ }),
57
+ response: t.object({
58
+ success: t.boolean(),
59
+ id: t.string()
60
+ })
61
+ }
62
+ }
63
+ });
64
+
65
+ ```
66
+
67
+ ## 📚 API Reference
68
+
69
+ ### `defineResource(spec)`
70
+
71
+ The main entry point for defining your API structure.
72
+
73
+ ### `t` (Type Builder)
74
+
75
+ A helper object to define data types easily.
76
+
77
+ | Method | Description | Example |
78
+ | --- | --- | --- |
79
+ | `t.string(options?)` | Defines a string field | `t.string()` |
80
+ | `t.number(options?)` | Defines a number field | `t.number()` |
81
+ | `t.boolean(options?)` | Defines a boolean field | `t.boolean()` |
82
+ | `t.object(props, options?)` | Defines a nested object | `t.object({ id: t.string() })` |
83
+ | `t.array(itemType, options?)` | Defines an array | `t.array(t.string())` |
84
+
85
+ #### Options
86
+
87
+ All types accept an optional options object:
88
+
89
+ * `required` (boolean): Defaults to `true`. Set to `false` for optional fields.
90
+
91
+ ```typescript
92
+ // Example: Optional String
93
+ t.string({ required: false })
94
+ // Output Type: string | undefined
95
+
96
+ ```
97
+
98
+ ## 🤝 Integration
99
+
100
+ This package is designed to work with the **KCFlow CLI**. Once you have defined your spec, run:
101
+
102
+ ```bash
103
+ # Generate types and client code
104
+ npx kcflow gen
105
+
106
+ ```
107
+
108
+ ## 📄 License
109
+
110
+ ISC
111
+
112
+ ```
113
+
114
+ ---
@@ -0,0 +1,29 @@
1
+ export type FieldType = 'string' | 'number' | 'boolean' | 'object' | 'array';
2
+ export interface FieldOptions {
3
+ required?: boolean;
4
+ }
5
+ export interface FieldDef {
6
+ type: FieldType;
7
+ required?: boolean;
8
+ properties?: Record<string, FieldDef>;
9
+ itemType?: FieldDef;
10
+ }
11
+ export declare const t: {
12
+ string: (opts?: FieldOptions) => FieldDef;
13
+ number: (opts?: FieldOptions) => FieldDef;
14
+ boolean: (opts?: FieldOptions) => FieldDef;
15
+ object: (props: Record<string, FieldDef>, opts?: FieldOptions) => FieldDef;
16
+ array: (item: FieldDef, opts?: FieldOptions) => FieldDef;
17
+ };
18
+ export interface EndpointDef {
19
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
20
+ path: string;
21
+ body?: FieldDef;
22
+ response?: FieldDef;
23
+ headers?: FieldDef;
24
+ }
25
+ export interface ResourceDef {
26
+ [key: string]: EndpointDef | ResourceDef;
27
+ }
28
+ export declare function defineResource(spec: ResourceDef): ResourceDef;
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE7E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACtC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAGD,eAAO,MAAM,CAAC;oBACI,YAAY,KAAG,QAAQ;oBACvB,YAAY,KAAG,QAAQ;qBACtB,YAAY,KAAG,QAAQ;oBACxB,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,YAAY,KAAG,QAAQ;kBAK1D,QAAQ,SAAS,YAAY,KAAG,QAAQ;CAKvD,CAAC;AAGF,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,WAAW,CAAC;CAC1C;AAGD,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAE7D"}
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.t = void 0;
4
+ exports.defineResource = defineResource;
5
+ // --- The 't' Builder (ตัวช่วยเขียน) ---
6
+ exports.t = {
7
+ string: (opts) => ({ type: 'string', required: opts?.required ?? true }),
8
+ number: (opts) => ({ type: 'number', required: opts?.required ?? true }),
9
+ boolean: (opts) => ({ type: 'boolean', required: opts?.required ?? true }),
10
+ object: (props, opts) => ({
11
+ type: 'object',
12
+ properties: props,
13
+ required: opts?.required ?? true
14
+ }),
15
+ array: (item, opts) => ({
16
+ type: 'array',
17
+ itemType: item,
18
+ required: opts?.required ?? true
19
+ }),
20
+ };
21
+ // Helper function เพื่อให้ TypeScript InteliSense ทำงานดีขึ้น
22
+ function defineResource(spec) {
23
+ return spec;
24
+ }
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AA6CA,wCAEC;AAjCD,yCAAyC;AAC5B,QAAA,CAAC,GAAG;IACf,MAAM,EAAE,CAAC,IAAmB,EAAY,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,IAAI,IAAI,EAAE,CAAC;IACjG,MAAM,EAAE,CAAC,IAAmB,EAAY,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,IAAI,IAAI,EAAE,CAAC;IACjG,OAAO,EAAE,CAAC,IAAmB,EAAY,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,IAAI,IAAI,EAAE,CAAC;IACnG,MAAM,EAAE,CAAC,KAA+B,EAAE,IAAmB,EAAY,EAAE,CAAC,CAAC;QAC3E,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,IAAI,EAAE,QAAQ,IAAI,IAAI;KACjC,CAAC;IACF,KAAK,EAAE,CAAC,IAAc,EAAE,IAAmB,EAAY,EAAE,CAAC,CAAC;QACzD,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAI,EAAE,QAAQ,IAAI,IAAI;KACjC,CAAC;CACH,CAAC;AAeF,8DAA8D;AAC9D,SAAgB,cAAc,CAAC,IAAiB;IAC9C,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@kcflow/core",
3
+ "version": "1.0.2",
4
+ "description": "The core type definitions and helper functions for KCFlow.",
5
+ "license": "ISC",
6
+ "author": "PRPAG HOLDING LTD.",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "type": "commonjs",
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "files": [
14
+ "dist",
15
+ "README.md"
16
+ ],
17
+ "keywords": [
18
+ "kcflow",
19
+ "api-generator",
20
+ "typescript",
21
+ "schema",
22
+ "spec"
23
+ ],
24
+ "scripts": {
25
+ "build": "tsc",
26
+ "prepublishOnly": "npm run build",
27
+ "test": "echo \"Error: no test specified\" && exit 1"
28
+ },
29
+ "dependencies": {
30
+ "typescript": "^5.9.3"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^25.0.9"
34
+ }
35
+ }