@famgia/omnify 0.11.0 → 0.12.0
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 +89 -165
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime/hooks/useFormSubmit.d.ts +36 -0
- package/dist/runtime/hooks/useFormSubmit.d.ts.map +1 -0
- package/dist/runtime/hooks/useFormSubmit.js +86 -0
- package/dist/runtime/hooks/useFormSubmit.js.map +1 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/lib/axios.d.ts +7 -0
- package/dist/runtime/lib/axios.d.ts.map +1 -0
- package/dist/runtime/lib/axios.js +54 -0
- package/dist/runtime/lib/axios.js.map +1 -0
- package/package.json +20 -2
package/README.md
CHANGED
|
@@ -1,211 +1,135 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @famgia/omnify
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Complete Laravel + React solution: Schema-to-TypeScript generation + Runtime helpers for forms
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
|
|
8
|
-
A standalone code generator that reads Omnify schema files and generates TypeScript type definitions, enum constants, and React context providers.
|
|
5
|
+
## Features
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
### 🎯 Build-time (Code Generation)
|
|
8
|
+
- ✅ Convert Omnify `schema-lock.json` to TypeScript types
|
|
9
|
+
- ✅ Generate enum types and options
|
|
10
|
+
- ✅ Generate model interfaces with relations
|
|
11
|
+
- ✅ Generate Enums Context Provider with type-safe helpers
|
|
12
|
+
- ✅ Watch mode for auto-regeneration
|
|
11
13
|
|
|
12
|
-
###
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
### 🚀 Runtime (React Helpers)
|
|
15
|
+
- ✅ `useFormSubmit` - Auto Laravel validation error mapping
|
|
16
|
+
- ✅ `createLaravelAxios` - Pre-configured axios for Laravel
|
|
17
|
+
- ✅ `getCsrfCookie` - CSRF token helper
|
|
18
|
+
- ✅ Full TypeScript support
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
```json
|
|
19
|
-
{
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"@omnifyjp/omnify": "file:../packages/omnify"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
```
|
|
20
|
+
## Installation
|
|
25
21
|
|
|
26
|
-
Then run:
|
|
27
22
|
```bash
|
|
28
|
-
npm install
|
|
23
|
+
npm install @famgia/omnify
|
|
29
24
|
```
|
|
30
25
|
|
|
31
26
|
## Usage
|
|
32
27
|
|
|
33
|
-
|
|
34
|
-
omnify-build [--schema <path>] --output <output-directory> [--watch]
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Options
|
|
38
|
-
|
|
39
|
-
- `--schema <path>` - Path to schema-lock.json file (optional, auto-detects from `.omnify/`)
|
|
40
|
-
- `--output <dir>` - Output directory for generated files (required)
|
|
41
|
-
- `--watch` - Watch for schema changes and rebuild automatically
|
|
42
|
-
- `--help` - Show help message
|
|
43
|
-
|
|
44
|
-
### Auto-detection
|
|
45
|
-
|
|
46
|
-
If `--schema` is not provided, the tool will automatically search for `schema-lock.json` in:
|
|
47
|
-
1. `../backend/.omnify/schema-lock.json` (from frontend directory)
|
|
48
|
-
2. `./backend/.omnify/schema-lock.json` (from project root)
|
|
49
|
-
3. `./.omnify/schema-lock.json` (current directory)
|
|
50
|
-
|
|
51
|
-
### Examples
|
|
28
|
+
### 1. Generate Types (Build-time)
|
|
52
29
|
|
|
53
30
|
```bash
|
|
54
|
-
#
|
|
55
|
-
omnify-build --output src/omnify
|
|
56
|
-
|
|
57
|
-
# Explicit schema path
|
|
58
|
-
omnify-build --schema backend/.omnify/schema-lock.json --output src/omnify
|
|
31
|
+
# In frontend project
|
|
32
|
+
npx omnify-build --output src/omnify
|
|
59
33
|
|
|
60
|
-
# Watch mode
|
|
61
|
-
omnify-build --output src/omnify --watch
|
|
34
|
+
# Watch mode
|
|
35
|
+
npx omnify-build --output src/omnify --watch
|
|
62
36
|
```
|
|
63
37
|
|
|
64
|
-
|
|
38
|
+
### 2. Use Generated Types & Enums
|
|
65
39
|
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Package.json Scripts
|
|
80
|
-
|
|
81
|
-
Add to your project's `package.json`:
|
|
82
|
-
|
|
83
|
-
```json
|
|
84
|
-
{
|
|
85
|
-
"scripts": {
|
|
86
|
-
"omnify:build": "omnify-build --output src/omnify",
|
|
87
|
-
"omnify:dev": "omnify-build --output src/omnify --watch"
|
|
88
|
-
}
|
|
40
|
+
```typescript
|
|
41
|
+
import { User, Company } from '@/omnify/models';
|
|
42
|
+
import { useEnums } from '@/omnify';
|
|
43
|
+
|
|
44
|
+
function MyForm() {
|
|
45
|
+
const { getOptions, getPrefecturesAsNumbers } = useEnums();
|
|
46
|
+
|
|
47
|
+
const accountTypeOptions = getOptions('ApplicationForm', 'account_type');
|
|
48
|
+
const prefectureOptions = getPrefecturesAsNumbers();
|
|
49
|
+
|
|
50
|
+
return <Select options={accountTypeOptions} />;
|
|
89
51
|
}
|
|
90
52
|
```
|
|
91
53
|
|
|
92
|
-
|
|
54
|
+
### 3. Use Runtime Helpers
|
|
93
55
|
|
|
94
56
|
```typescript
|
|
95
|
-
|
|
96
|
-
import {
|
|
97
|
-
|
|
57
|
+
import { useFormSubmit, getCsrfCookie } from '@famgia/omnify';
|
|
58
|
+
import { Form, Button } from 'antd';
|
|
59
|
+
|
|
60
|
+
function MyForm() {
|
|
61
|
+
const [form] = Form.useForm();
|
|
62
|
+
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
|
|
63
|
+
|
|
64
|
+
const { handleSubmit, loading } = useFormSubmit({
|
|
65
|
+
form,
|
|
66
|
+
submitFn: createUser,
|
|
67
|
+
getCsrfToken: () => getCsrfCookie(apiUrl!),
|
|
68
|
+
onSuccess: (response) => {
|
|
69
|
+
message.success('Success!');
|
|
70
|
+
},
|
|
71
|
+
});
|
|
98
72
|
|
|
99
|
-
// Import enum options
|
|
100
|
-
import { entity_typeOptions, account_typeOptions } from '@/omnify/types';
|
|
101
|
-
|
|
102
|
-
// Use in React
|
|
103
|
-
function MySelect() {
|
|
104
|
-
return (
|
|
105
|
-
<select>
|
|
106
|
-
{Object.entries(entity_typeOptions).map(([value, label]) => (
|
|
107
|
-
<option key={value} value={value}>{label}</option>
|
|
108
|
-
))}
|
|
109
|
-
</select>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Import context provider
|
|
114
|
-
import { EnumsProvider, useEnums } from '@/omnify/contexts';
|
|
115
|
-
|
|
116
|
-
function App() {
|
|
117
73
|
return (
|
|
118
|
-
<
|
|
119
|
-
<
|
|
120
|
-
|
|
74
|
+
<Form form={form} onFinish={handleSubmit}>
|
|
75
|
+
<Form.Item name="email">
|
|
76
|
+
<Input />
|
|
77
|
+
</Form.Item>
|
|
78
|
+
<Button type="primary" htmlType="submit" loading={loading}>
|
|
79
|
+
Submit
|
|
80
|
+
</Button>
|
|
81
|
+
</Form>
|
|
121
82
|
);
|
|
122
83
|
}
|
|
123
|
-
|
|
124
|
-
function Component() {
|
|
125
|
-
const { enums } = useEnums();
|
|
126
|
-
return <div>{enums.entity_type.CORPORATION}</div>;
|
|
127
|
-
}
|
|
128
84
|
```
|
|
129
85
|
|
|
130
|
-
##
|
|
131
|
-
|
|
132
|
-
- ✅ Generates TypeScript interfaces from Omnify models
|
|
133
|
-
- ✅ Creates enum union types
|
|
134
|
-
- ✅ Generates enum constant objects for easy use
|
|
135
|
-
- ✅ Creates React context provider with static enum data
|
|
136
|
-
- ✅ Watch mode for development
|
|
137
|
-
- ✅ Type-safe enum usage
|
|
138
|
-
- ✅ No runtime dependencies (enums are static)
|
|
139
|
-
- ✅ Standalone package - works with any project structure
|
|
140
|
-
- ✅ Supports composite types (JapanAddress, JapanPersonName)
|
|
141
|
-
- ✅ Includes prefectures enum (47 prefectures)
|
|
142
|
-
|
|
143
|
-
## Supported Omnify Types
|
|
86
|
+
## API
|
|
144
87
|
|
|
145
|
-
###
|
|
146
|
-
- `Id`, `Int`, `TinyInt`, `BigInt`, `Float` → `number`
|
|
88
|
+
### `useFormSubmit<TResponse>(options)`
|
|
147
89
|
|
|
148
|
-
|
|
149
|
-
- `String`, `Text`, `LongText`, `Email`, `Password`, `JapanPhone`, `Color`, `Time` → `string`
|
|
90
|
+
Hook for form submission with automatic Laravel validation error mapping.
|
|
150
91
|
|
|
151
|
-
|
|
152
|
-
- `
|
|
92
|
+
**Options:**
|
|
93
|
+
- `form: FormInstance` - Ant Design form instance
|
|
94
|
+
- `submitFn: (values) => Promise<TResponse>` - API call function
|
|
95
|
+
- `getCsrfToken?: () => Promise<void>` - CSRF token getter
|
|
96
|
+
- `onSuccess?: (response, values) => void` - Success callback
|
|
97
|
+
- `onError?: (error, values) => void` - Custom error handler
|
|
98
|
+
- `errorMessages?: { 500?, 401?, 403?, default? }` - Custom error messages
|
|
153
99
|
|
|
154
|
-
|
|
155
|
-
- `
|
|
100
|
+
**Returns:**
|
|
101
|
+
- `handleSubmit: (values) => Promise<void>` - Submit handler
|
|
102
|
+
- `loading: boolean` - Loading state
|
|
103
|
+
- `setLoading: (loading) => void` - Set loading manually
|
|
156
104
|
|
|
157
|
-
###
|
|
158
|
-
- `Json` → `Record<string, any>`
|
|
105
|
+
### `createLaravelAxios(baseURL)`
|
|
159
106
|
|
|
160
|
-
|
|
161
|
-
- `Enum` → Generated union types
|
|
107
|
+
Create pre-configured axios instance for Laravel API.
|
|
162
108
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
### Select Types
|
|
167
|
-
- `Select`, `SingleSelect`, `MultiSelect` → `string`
|
|
168
|
-
|
|
169
|
-
### File Types
|
|
170
|
-
- `File`, `MultiFile` → `string` (file path/URL)
|
|
171
|
-
|
|
172
|
-
### Composite Types
|
|
173
|
-
- `JapanAddress` → Expanded to flat fields (postal_code, prefecture_id, address1-3)
|
|
174
|
-
- `JapanPersonName` → Expanded to flat fields (lastname, firstname, kana_lastname, kana_firstname)
|
|
175
|
-
|
|
176
|
-
## Requirements
|
|
177
|
-
|
|
178
|
-
- Node.js >= 16
|
|
179
|
-
- TypeScript >= 5.0 (peer dependency)
|
|
109
|
+
```typescript
|
|
110
|
+
import { createLaravelAxios } from '@famgia/omnify';
|
|
180
111
|
|
|
181
|
-
|
|
112
|
+
const axios = createLaravelAxios('https://api.example.com');
|
|
113
|
+
```
|
|
182
114
|
|
|
183
|
-
###
|
|
115
|
+
### `getCsrfCookie(baseURL)`
|
|
184
116
|
|
|
185
|
-
|
|
186
|
-
# Run all tests
|
|
187
|
-
npm test
|
|
117
|
+
Get CSRF cookie for Laravel Sanctum.
|
|
188
118
|
|
|
189
|
-
|
|
190
|
-
|
|
119
|
+
```typescript
|
|
120
|
+
import { getCsrfCookie } from '@famgia/omnify';
|
|
191
121
|
|
|
192
|
-
|
|
193
|
-
npm run test:coverage
|
|
122
|
+
await getCsrfCookie('https://api.example.com');
|
|
194
123
|
```
|
|
195
124
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
The package includes comprehensive tests for:
|
|
199
|
-
- Type mapping (Omnify types to TypeScript)
|
|
200
|
-
- Enum generation
|
|
201
|
-
- Model generation
|
|
202
|
-
- Context generation with helper methods
|
|
125
|
+
## Benefits
|
|
203
126
|
|
|
204
|
-
|
|
205
|
-
-
|
|
206
|
-
-
|
|
207
|
-
-
|
|
208
|
-
-
|
|
127
|
+
- 🚀 Reduce 100+ lines of boilerplate per form
|
|
128
|
+
- 🛡️ Type-safe enums and models
|
|
129
|
+
- 🔄 Auto-sync with backend schema
|
|
130
|
+
- 📝 Consistent error handling
|
|
131
|
+
- ⚡ Build-time code generation
|
|
132
|
+
- 🎯 Runtime helpers for common tasks
|
|
209
133
|
|
|
210
134
|
## License
|
|
211
135
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AAGxB,cAAc,WAAW,CAAC;AAC1B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
|
+
// Runtime helpers (for use in app)
|
|
19
|
+
__exportStar(require("./runtime"), exports);
|
|
18
20
|
__exportStar(require("./generators/enumGenerator"), exports);
|
|
19
21
|
__exportStar(require("./generators/modelGenerator"), exports);
|
|
20
22
|
__exportStar(require("./generators/contextGenerator"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AAExB,mCAAmC;AACnC,4CAA0B;AAC1B,6DAA2C;AAC3C,8DAA4C;AAC5C,gEAA8C;AAC9C,qDAAmC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FormInstance } from 'antd';
|
|
2
|
+
export interface UseFormSubmitOptions<TResponse = any> {
|
|
3
|
+
form: FormInstance;
|
|
4
|
+
submitFn: (values: any) => Promise<TResponse>;
|
|
5
|
+
onSuccess?: (response: TResponse, values: any) => void | Promise<void>;
|
|
6
|
+
onError?: (error: any, values: any) => void | Promise<void>;
|
|
7
|
+
getCsrfToken?: () => Promise<void>;
|
|
8
|
+
errorMessages?: {
|
|
9
|
+
500?: string;
|
|
10
|
+
401?: string;
|
|
11
|
+
403?: string;
|
|
12
|
+
default?: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface UseFormSubmitResult {
|
|
16
|
+
handleSubmit: (values: any) => Promise<void>;
|
|
17
|
+
loading: boolean;
|
|
18
|
+
setLoading: (loading: boolean) => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Custom hook for handling form submission with automatic Laravel validation error mapping
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* const { handleSubmit, loading } = useFormSubmit({
|
|
26
|
+
* form,
|
|
27
|
+
* submitFn: createUser,
|
|
28
|
+
* getCsrfToken: () => getCsrfCookie(apiUrl),
|
|
29
|
+
* onSuccess: (response) => {
|
|
30
|
+
* message.success('Success!');
|
|
31
|
+
* },
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function useFormSubmit<TResponse = any>(options: UseFormSubmitOptions<TResponse>): UseFormSubmitResult;
|
|
36
|
+
//# sourceMappingURL=useFormSubmit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormSubmit.d.ts","sourceRoot":"","sources":["../../../src/runtime/hooks/useFormSubmit.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAO,MAAM,MAAM,CAAC;AAEzC,MAAM,WAAW,oBAAoB,CAAC,SAAS,GAAG,GAAG;IACjD,IAAI,EAAE,YAAY,CAAC;IACnB,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;IAC9C,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,aAAa,CAAC,EAAE;QACZ,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACL;AAED,MAAM,WAAW,mBAAmB;IAChC,YAAY,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,SAAS,GAAG,GAAG,EACzC,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC,GACzC,mBAAmB,CAsFrB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFormSubmit = useFormSubmit;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const antd_1 = require("antd");
|
|
6
|
+
/**
|
|
7
|
+
* Custom hook for handling form submission with automatic Laravel validation error mapping
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const { handleSubmit, loading } = useFormSubmit({
|
|
12
|
+
* form,
|
|
13
|
+
* submitFn: createUser,
|
|
14
|
+
* getCsrfToken: () => getCsrfCookie(apiUrl),
|
|
15
|
+
* onSuccess: (response) => {
|
|
16
|
+
* message.success('Success!');
|
|
17
|
+
* },
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function useFormSubmit(options) {
|
|
22
|
+
const { form, submitFn, onSuccess, onError, getCsrfToken, errorMessages = {}, } = options;
|
|
23
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
24
|
+
const { message: messageApi } = antd_1.App.useApp();
|
|
25
|
+
const handleSubmit = async (values) => {
|
|
26
|
+
setLoading(true);
|
|
27
|
+
try {
|
|
28
|
+
if (getCsrfToken) {
|
|
29
|
+
await getCsrfToken();
|
|
30
|
+
}
|
|
31
|
+
const response = await submitFn(values);
|
|
32
|
+
if (onSuccess) {
|
|
33
|
+
await onSuccess(response, values);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error('Form submission error:', error);
|
|
38
|
+
if (onError) {
|
|
39
|
+
await onError(error, values);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
// Handle validation errors (422)
|
|
43
|
+
if (error.response?.status === 422 && error.response?.data?.errors) {
|
|
44
|
+
const errors = error.response.data.errors;
|
|
45
|
+
// Set field errors
|
|
46
|
+
const formErrors = Object.keys(errors).map((field) => ({
|
|
47
|
+
name: field,
|
|
48
|
+
errors: errors[field],
|
|
49
|
+
}));
|
|
50
|
+
form.setFields(formErrors);
|
|
51
|
+
// Show error message
|
|
52
|
+
const errorCount = Object.keys(errors).length;
|
|
53
|
+
const errorList = Object.values(errors)
|
|
54
|
+
.map((msgs) => msgs[0])
|
|
55
|
+
.join(' / ');
|
|
56
|
+
messageApi.error({
|
|
57
|
+
content: `入力内容にエラーがあります(${errorCount}件): ${errorList}`,
|
|
58
|
+
duration: 8,
|
|
59
|
+
});
|
|
60
|
+
console.error('Validation errors:', errors);
|
|
61
|
+
}
|
|
62
|
+
// Handle server errors
|
|
63
|
+
else if (error.response?.status >= 500) {
|
|
64
|
+
messageApi.error(errorMessages[500] || 'サーバーエラーが発生しました。しばらくしてから再度お試しください。');
|
|
65
|
+
}
|
|
66
|
+
// Handle auth errors
|
|
67
|
+
else if (error.response?.status === 401 || error.response?.status === 403) {
|
|
68
|
+
const status = error.response.status;
|
|
69
|
+
messageApi.error(errorMessages[status] || '認証エラーが発生しました。再度ログインしてください。');
|
|
70
|
+
}
|
|
71
|
+
// Handle generic errors
|
|
72
|
+
else {
|
|
73
|
+
messageApi.error(error.response?.data?.message || errorMessages.default || '送信に失敗しました');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
setLoading(false);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
handleSubmit,
|
|
82
|
+
loading,
|
|
83
|
+
setLoading,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=useFormSubmit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormSubmit.js","sourceRoot":"","sources":["../../../src/runtime/hooks/useFormSubmit.tsx"],"names":[],"mappings":";;AAsCA,sCAwFC;AA9HD,iCAAiC;AACjC,+BAAyC;AAsBzC;;;;;;;;;;;;;;GAcG;AACH,SAAgB,aAAa,CACzB,OAAwC;IAExC,MAAM,EACF,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,OAAO,EACP,YAAY,EACZ,aAAa,GAAG,EAAE,GACrB,GAAG,OAAO,CAAC;IAEZ,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,UAAG,C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AAC;AACtD,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEvF,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCsrfCookie = exports.createLaravelAxios = exports.useFormSubmit = void 0;
|
|
4
|
+
// Runtime helpers for React + Laravel + Ant Design
|
|
5
|
+
var useFormSubmit_1 = require("./hooks/useFormSubmit");
|
|
6
|
+
Object.defineProperty(exports, "useFormSubmit", { enumerable: true, get: function () { return useFormSubmit_1.useFormSubmit; } });
|
|
7
|
+
var axios_1 = require("./lib/axios");
|
|
8
|
+
Object.defineProperty(exports, "createLaravelAxios", { enumerable: true, get: function () { return axios_1.createLaravelAxios; } });
|
|
9
|
+
Object.defineProperty(exports, "getCsrfCookie", { enumerable: true, get: function () { return axios_1.getCsrfCookie; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":";;;AAAA,mDAAmD;AACnD,uDAAsD;AAA7C,8GAAA,aAAa,OAAA;AAGtB,qCAAgE;AAAvD,2GAAA,kBAAkB,OAAA;AAAE,sGAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const createLaravelAxios: (baseURL: string) => import("axios").AxiosInstance;
|
|
2
|
+
/**
|
|
3
|
+
* Get CSRF cookie before making authenticated requests
|
|
4
|
+
* Required for Laravel Sanctum cookie-based authentication
|
|
5
|
+
*/
|
|
6
|
+
export declare const getCsrfCookie: (baseURL: string) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=axios.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axios.d.ts","sourceRoot":"","sources":["../../../src/runtime/lib/axios.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,kCAqCjD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,IAAI,CAIjE,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getCsrfCookie = exports.createLaravelAxios = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
// Create axios instance for Laravel API
|
|
9
|
+
const createLaravelAxios = (baseURL) => {
|
|
10
|
+
const axiosInstance = axios_1.default.create({
|
|
11
|
+
baseURL,
|
|
12
|
+
timeout: 30000,
|
|
13
|
+
withCredentials: true,
|
|
14
|
+
headers: {
|
|
15
|
+
'Accept': 'application/json',
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
},
|
|
18
|
+
xsrfCookieName: 'XSRF-TOKEN',
|
|
19
|
+
xsrfHeaderName: 'X-XSRF-TOKEN',
|
|
20
|
+
});
|
|
21
|
+
// Helper to get cookie value by name
|
|
22
|
+
function getCookie(name) {
|
|
23
|
+
if (typeof document === 'undefined')
|
|
24
|
+
return null;
|
|
25
|
+
const value = `; ${document.cookie}`;
|
|
26
|
+
const parts = value.split(`; ${name}=`);
|
|
27
|
+
if (parts.length === 2)
|
|
28
|
+
return parts.pop()?.split(';').shift() || null;
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
// Request interceptor
|
|
32
|
+
axiosInstance.interceptors.request.use((config) => {
|
|
33
|
+
const token = getCookie('XSRF-TOKEN');
|
|
34
|
+
if (token) {
|
|
35
|
+
config.headers['X-XSRF-TOKEN'] = decodeURIComponent(token);
|
|
36
|
+
}
|
|
37
|
+
return config;
|
|
38
|
+
}, (error) => {
|
|
39
|
+
return Promise.reject(error);
|
|
40
|
+
});
|
|
41
|
+
return axiosInstance;
|
|
42
|
+
};
|
|
43
|
+
exports.createLaravelAxios = createLaravelAxios;
|
|
44
|
+
/**
|
|
45
|
+
* Get CSRF cookie before making authenticated requests
|
|
46
|
+
* Required for Laravel Sanctum cookie-based authentication
|
|
47
|
+
*/
|
|
48
|
+
const getCsrfCookie = async (baseURL) => {
|
|
49
|
+
await axios_1.default.get(`${baseURL}/sanctum/csrf-cookie`, {
|
|
50
|
+
withCredentials: true,
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
exports.getCsrfCookie = getCsrfCookie;
|
|
54
|
+
//# sourceMappingURL=axios.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axios.js","sourceRoot":"","sources":["../../../src/runtime/lib/axios.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAsE;AAEtE,wCAAwC;AACjC,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,EAAE;IAClD,MAAM,aAAa,GAAG,eAAK,CAAC,MAAM,CAAC;QAC/B,OAAO;QACP,OAAO,EAAE,KAAK;QACd,eAAe,EAAE,IAAI;QACrB,OAAO,EAAE;YACL,QAAQ,EAAE,kBAAkB;YAC5B,cAAc,EAAE,kBAAkB;SACrC;QACD,cAAc,EAAE,YAAY;QAC5B,cAAc,EAAE,cAAc;KACjC,CAAC,CAAC;IAEH,qCAAqC;IACrC,SAAS,SAAS,CAAC,IAAY;QAC3B,IAAI,OAAO,QAAQ,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QACjD,MAAM,KAAK,GAAG,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC;QACxC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,IAAI,CAAC;QACvE,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,sBAAsB;IACtB,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAClC,CAAC,MAAkC,EAAE,EAAE;QACnC,MAAM,KAAK,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;QACtC,IAAI,KAAK,EAAE,CAAC;YACR,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC/D,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC,EACD,CAAC,KAAiB,EAAE,EAAE;QAClB,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC,CACJ,CAAC;IAEF,OAAO,aAAa,CAAC;AACzB,CAAC,CAAC;AArCW,QAAA,kBAAkB,sBAqC7B;AAEF;;;GAGG;AACI,MAAM,aAAa,GAAG,KAAK,EAAE,OAAe,EAAiB,EAAE;IAClE,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,OAAO,sBAAsB,EAAE;QAC9C,eAAe,EAAE,IAAI;KACxB,CAAC,CAAC;AACP,CAAC,CAAC;AAJW,QAAA,aAAa,iBAIxB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@famgia/omnify",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.12.0",
|
|
4
|
+
"description": "Complete Laravel + React solution: Schema-to-TypeScript generation + Runtime helpers for forms",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"bin": {
|
|
@@ -39,7 +39,11 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/jest": "^30.0.0",
|
|
41
41
|
"@types/node": "^20.19.24",
|
|
42
|
+
"@types/react": "^19.2.2",
|
|
43
|
+
"antd": "^5.28.0",
|
|
44
|
+
"axios": "^1.13.2",
|
|
42
45
|
"jest": "^30.2.0",
|
|
46
|
+
"react": "^19.2.0",
|
|
43
47
|
"ts-jest": "^29.4.5",
|
|
44
48
|
"typescript": "^5.0.0"
|
|
45
49
|
},
|
|
@@ -47,8 +51,22 @@
|
|
|
47
51
|
"chokidar": "^3.6.0"
|
|
48
52
|
},
|
|
49
53
|
"peerDependencies": {
|
|
54
|
+
"antd": ">=5.0.0",
|
|
55
|
+
"axios": ">=1.0.0",
|
|
56
|
+
"react": ">=18.0.0",
|
|
50
57
|
"typescript": ">=5.0.0"
|
|
51
58
|
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"react": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"antd": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"axios": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
69
|
+
},
|
|
52
70
|
"files": [
|
|
53
71
|
"dist",
|
|
54
72
|
"README.md",
|