@kcflow/core 1.0.3 → 1.0.4

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
@@ -2,25 +2,28 @@ export type FieldType = 'string' | 'number' | 'boolean' | 'object' | 'array';
2
2
  export interface FieldOptions {
3
3
  required?: boolean;
4
4
  }
5
- export interface FieldDef {
5
+ export interface FieldDef<T = any> {
6
6
  type: FieldType;
7
- required?: boolean;
7
+ required: boolean;
8
8
  properties?: Record<string, FieldDef>;
9
9
  itemType?: FieldDef;
10
+ /** @internal ใช้สำหรับ TypeScript Inference เท่านั้น (ห้ามใส่ค่าจริง) */
11
+ __infer?: T;
10
12
  }
11
13
  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;
14
+ string: (opts?: FieldOptions) => FieldDef<string>;
15
+ number: (opts?: FieldOptions) => FieldDef<number>;
16
+ boolean: (opts?: FieldOptions) => FieldDef<boolean>;
17
+ object: <T extends Record<string, FieldDef>>(props: T, opts?: FieldOptions) => FieldDef<{ [K in keyof T]: T[K]["__infer"]; }>;
18
+ array: <T extends FieldDef>(item: T, opts?: FieldOptions) => FieldDef<T["__infer"][]>;
17
19
  };
18
20
  export interface EndpointDef {
19
- method: 'GET' | 'POST' | 'PUT' | 'DELETE';
21
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
20
22
  path: string;
21
23
  body?: FieldDef;
22
- response?: FieldDef;
24
+ query?: FieldDef;
23
25
  headers?: FieldDef;
26
+ response?: FieldDef;
24
27
  }
25
28
  export interface ResourceDef {
26
29
  [key: string]: EndpointDef | ResourceDef;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.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1
  "use strict";
2
+ // src/index.ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.t = void 0;
4
5
  exports.defineResource = defineResource;
5
- // --- The 't' Builder (ตัวช่วยเขียน) ---
6
+ // 2. ตัวช่วยสร้าง (Builder)
6
7
  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 }),
8
+ string: (opts) => ({
9
+ type: 'string',
10
+ required: opts?.required ?? true
11
+ }),
12
+ number: (opts) => ({
13
+ type: 'number',
14
+ required: opts?.required ?? true
15
+ }),
16
+ boolean: (opts) => ({
17
+ type: 'boolean',
18
+ required: opts?.required ?? true
19
+ }),
20
+ // สำหรับ Object เราต้องรับ Props เข้ามา
10
21
  object: (props, opts) => ({
11
22
  type: 'object',
12
23
  properties: props,
13
24
  required: opts?.required ?? true
14
25
  }),
26
+ // สำหรับ Array
15
27
  array: (item, opts) => ({
16
28
  type: 'array',
17
29
  itemType: item,
18
30
  required: opts?.required ?? true
19
31
  }),
20
32
  };
21
- // Helper function เพื่อให้ TypeScript InteliSense ทำงานดีขึ้น
33
+ // 4. ฟังก์ชันหลักสำหรับ Define
22
34
  function defineResource(spec) {
23
35
  return spec;
24
36
  }
package/dist/index.js.map CHANGED
@@ -1 +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,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IAAmB,EAAiD,EAAE,CAAC,CAAC;QAC7H,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,IAAI,EAAE,QAAQ,IAAI,IAAI;KACjC,CAAC;IACF,eAAe;IACf,KAAK,EAAE,CAAqB,IAAO,EAAE,IAAmB,EAA4B,EAAE,CAAC,CAAC;QACtF,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAI,EAAE,QAAQ,IAAI,IAAI;KACjC,CAAC;CACH,CAAC;AAgBF,+BAA+B;AAC/B,SAAgB,cAAc,CAAC,IAAiB;IAC9C,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,19 +1,24 @@
1
1
  {
2
2
  "name": "@kcflow/core",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "The core type definitions and helper functions for KCFlow.",
5
5
  "license": "ISC",
6
6
  "author": "PRPAG HOLDING LTD.",
7
+
7
8
  "publishConfig": {
8
9
  "access": "public"
9
10
  },
11
+
10
12
  "type": "commonjs",
11
13
  "main": "./dist/index.js",
14
+
12
15
  "types": "./dist/index.d.ts",
16
+
13
17
  "files": [
14
18
  "dist",
15
19
  "README.md"
16
20
  ],
21
+
17
22
  "keywords": [
18
23
  "kcflow",
19
24
  "api-generator",
@@ -21,9 +26,11 @@
21
26
  "schema",
22
27
  "spec"
23
28
  ],
29
+
30
+
24
31
  "scripts": {
25
32
  "build": "tsc",
26
33
  "prepublishOnly": "npm run build",
27
34
  "test": "echo \"Error: no test specified\" && exit 1"
28
35
  }
29
- }
36
+ }