@20baht/engine 0.0.0-stage → 0.1.1

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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -2
  3. package/dist/approval.d.ts +15 -0
  4. package/dist/approval.js +18 -0
  5. package/dist/dates.d.ts +34 -0
  6. package/dist/dates.js +91 -0
  7. package/dist/defaults.d.ts +6 -0
  8. package/dist/defaults.js +37 -0
  9. package/dist/display.d.ts +33 -0
  10. package/dist/display.js +110 -0
  11. package/dist/engine/conditions.d.ts +27 -0
  12. package/dist/engine/conditions.js +123 -0
  13. package/dist/engine/evaluate.d.ts +8 -0
  14. package/dist/engine/evaluate.js +368 -0
  15. package/dist/engine/expressions.d.ts +3 -0
  16. package/dist/engine/expressions.js +70 -0
  17. package/dist/engine/form-session.d.ts +135 -0
  18. package/dist/engine/form-session.js +313 -0
  19. package/dist/engine/graph.d.ts +40 -0
  20. package/dist/engine/graph.js +59 -0
  21. package/dist/engine/runtime.d.ts +194 -0
  22. package/dist/engine/runtime.js +268 -0
  23. package/dist/engine/scripts.d.ts +34 -0
  24. package/dist/engine/scripts.js +98 -0
  25. package/dist/flags.d.ts +19 -0
  26. package/dist/flags.js +49 -0
  27. package/dist/form-values.d.ts +78 -0
  28. package/dist/form-values.js +6 -0
  29. package/dist/i18n.d.ts +177 -0
  30. package/dist/i18n.js +310 -0
  31. package/dist/index.d.ts +25 -0
  32. package/dist/index.js +23 -0
  33. package/dist/keys.d.ts +14 -0
  34. package/dist/keys.js +4 -0
  35. package/dist/legacy.d.ts +14 -0
  36. package/dist/legacy.js +47 -0
  37. package/dist/pattern-safety.d.ts +34 -0
  38. package/dist/pattern-safety.js +267 -0
  39. package/dist/same-data.d.ts +5 -0
  40. package/dist/same-data.js +23 -0
  41. package/dist/shortcut.d.ts +44 -0
  42. package/dist/shortcut.js +176 -0
  43. package/dist/types.d.ts +541 -0
  44. package/dist/types.js +1 -0
  45. package/dist/urls.d.ts +8 -0
  46. package/dist/urls.js +30 -0
  47. package/dist/validators.d.ts +39 -0
  48. package/dist/validators.js +372 -0
  49. package/dist/views.d.ts +12 -0
  50. package/dist/views.js +11 -0
  51. package/package.json +52 -4
package/dist/i18n.d.ts ADDED
@@ -0,0 +1,177 @@
1
+ export interface MessageCatalog {
2
+ required: string;
3
+ minLength: string;
4
+ maxLength: string;
5
+ min: string;
6
+ max: string;
7
+ pattern: string;
8
+ email: string;
9
+ /** `url` validator: not an absolute URL with an allowed scheme. */
10
+ url: string;
11
+ /** currency: more than two decimal places. */
12
+ decimals: string;
13
+ /** number with `integer: true`: a fraction. */
14
+ integer: string;
15
+ dateDisabled: string;
16
+ /** time: not a 24-hour `HH:mm`. */
17
+ timeInvalid: string;
18
+ compareEq: string;
19
+ compareNe: string;
20
+ compareGt: string;
21
+ compareGte: string;
22
+ compareLt: string;
23
+ compareLte: string;
24
+ fileTooLarge: string;
25
+ fileTypeNotAllowed: string;
26
+ fileRejectedTooLarge: string;
27
+ uploading: string;
28
+ uploadFailed: string;
29
+ markdownWrite: string;
30
+ markdownPreview: string;
31
+ markdownEmpty: string;
32
+ markdownHint: string;
33
+ markdownAttach: string;
34
+ removeFile: string;
35
+ chooseFile: string;
36
+ chooseFiles: string;
37
+ orDropHere: string;
38
+ uploadMaxSize: string;
39
+ retry: string;
40
+ addRow: string;
41
+ refColumn: string;
42
+ refSearch: string;
43
+ refColumnSearch: string;
44
+ refFilter: string;
45
+ refRun: string;
46
+ refClearFilter: string;
47
+ refFirst: string;
48
+ refPrevious: string;
49
+ refNext: string;
50
+ refLast: string;
51
+ refPage: string;
52
+ refRange: string;
53
+ refEmpty: string;
54
+ refLoading: string;
55
+ refFailed: string;
56
+ filterNavigator: string;
57
+ /** `<baht-search>`: the accessible name when no `label` is given. */
58
+ search: string;
59
+ filterHeading: string;
60
+ filterAdd: string;
61
+ filterSaved: string;
62
+ filterSaveName: string;
63
+ filterDelete: string;
64
+ filterStale: string;
65
+ filterAnd: string;
66
+ filterOr: string;
67
+ filterRemove: string;
68
+ filterMatch: string;
69
+ filterMatchAll: string;
70
+ filterMatchAny: string;
71
+ filterField: string;
72
+ filterComparison: string;
73
+ filterValue: string;
74
+ filterContains: string;
75
+ filterIs: string;
76
+ filterIsNot: string;
77
+ filterGreater: string;
78
+ filterLess: string;
79
+ filterEmpty: string;
80
+ filterNotEmpty: string;
81
+ editRowN: string;
82
+ saveRow: string;
83
+ cancelRow: string;
84
+ removeRow: string;
85
+ minRows: string;
86
+ maxRows: string;
87
+ /** `min_rows: 1`, where "{n} rows" would read "1 rows". */
88
+ minRowsOne: string;
89
+ /** `max_rows: 1`. */
90
+ maxRowsOne: string;
91
+ maxItems: string;
92
+ ratingRange: string;
93
+ ratingValue: string;
94
+ stepOf: string;
95
+ referenceNotFound: string;
96
+ tagTooLong: string;
97
+ tagNotAllowed: string;
98
+ tagDuplicate: string;
99
+ removeTag: string;
100
+ next: string;
101
+ submit: string;
102
+ back: string;
103
+ step: string;
104
+ approve: string;
105
+ reject: string;
106
+ decision: string;
107
+ comment: string;
108
+ commentRequiredSuffix: string;
109
+ decisionRequired: string;
110
+ commentRequired: string;
111
+ nothingToReview: string;
112
+ /** A `submit` script returned false without adding an error message. */
113
+ scriptBlocked: string;
114
+ yes: string;
115
+ no: string;
116
+ emptyValue: string;
117
+ /** Placeholder option of a dropdown. */
118
+ choose: string;
119
+ rowCount: string;
120
+ results: string;
121
+ columns: string;
122
+ selectAll: string;
123
+ selectRow: string;
124
+ sortBy: string;
125
+ rowActions: string;
126
+ optional: string;
127
+ close: string;
128
+ dismiss: string;
129
+ moreActions: string;
130
+ darkTheme: string;
131
+ opensInNewTab: string;
132
+ otpCharacter: string;
133
+ row: string;
134
+ removeRowN: string;
135
+ stepDone: string;
136
+ stepCurrent: string;
137
+ today: string;
138
+ now: string;
139
+ clear: string;
140
+ searching: string;
141
+ noMatches: string;
142
+ searchPlaceholder: string;
143
+ openRecord: string;
144
+ previous: string;
145
+ allDay: string;
146
+ calendarMore: string;
147
+ rowNumber: string;
148
+ }
149
+ export type MessageKey = keyof MessageCatalog;
150
+ export type Locale = 'en' | 'th';
151
+ /**
152
+ * Switch every built-in string to a locale, optionally patching single keys:
153
+ *
154
+ * setLocale('th') // all Thai
155
+ * setLocale('th', { required: 'ห้ามว่าง' }) // Thai + one custom message
156
+ *
157
+ * Global and synchronous — set it before mounting (or before validating on
158
+ * the server). Components read the catalog at render time.
159
+ */
160
+ export declare function setLocale(locale: Locale, overrides?: Partial<MessageCatalog>): void;
161
+ /**
162
+ * Snapshot of the active catalog. The catalog is module-global — on a server
163
+ * handling concurrent requests with different locales, wrap the locale switch:
164
+ * snapshot, setLocale, do the synchronous work, then setCatalog the snapshot
165
+ * back (@20baht/validator's `locale` option does exactly this).
166
+ */
167
+ export declare function getCatalog(): MessageCatalog;
168
+ /** Restore a catalog snapshot taken with getCatalog(). */
169
+ export declare function setCatalog(catalog: MessageCatalog): void;
170
+ /**
171
+ * Run `fn` with the catalog switched to `locale`, the previous catalog put back after (also when
172
+ * it throws). The catalog is module-global; `fn` is synchronous, so two requests or two form
173
+ * sessions in different locales never see each other's. Unset: `fn` runs in the catalog as it is.
174
+ */
175
+ export declare function withLocale<T>(locale: Locale | undefined, fn: () => T): T;
176
+ /** Resolve one catalog string, interpolating `{param}` placeholders. */
177
+ export declare function t(key: MessageKey, params?: Record<string, unknown>): string;
package/dist/i18n.js ADDED
@@ -0,0 +1,310 @@
1
+ const en = {
2
+ required: 'This field is required',
3
+ minLength: 'Must be at least {n} characters',
4
+ maxLength: 'Must be at most {n} characters',
5
+ min: 'Must be at least {n}',
6
+ max: 'Must be at most {n}',
7
+ pattern: 'Invalid format',
8
+ email: 'Invalid email address',
9
+ url: 'Invalid URL',
10
+ decimals: 'Use at most 2 decimal places',
11
+ integer: 'Must be a whole number',
12
+ dateDisabled: 'This date cannot be selected',
13
+ timeInvalid: 'Enter a time as HH:mm',
14
+ compareEq: 'Must match {other}',
15
+ compareNe: 'Must differ from {other}',
16
+ compareGt: 'Must be greater than {other}',
17
+ compareGte: 'Must be at least {other}',
18
+ compareLt: 'Must be less than {other}',
19
+ compareLte: 'Must be at most {other}',
20
+ fileTooLarge: 'File is too large',
21
+ fileTypeNotAllowed: 'File type not allowed',
22
+ fileRejectedTooLarge: 'Too large, not added: {names}',
23
+ uploading: 'Uploading…',
24
+ uploadFailed: 'Upload failed, try again',
25
+ markdownWrite: 'Write',
26
+ markdownPreview: 'Preview',
27
+ markdownEmpty: 'Nothing to preview',
28
+ markdownHint: 'Markdown supported.',
29
+ markdownAttach: 'Paste, drop, or choose files to attach.',
30
+ removeFile: 'Remove file',
31
+ chooseFile: 'Choose a file',
32
+ chooseFiles: 'Choose files',
33
+ orDropHere: 'or drop it here',
34
+ uploadMaxSize: 'up to {size}',
35
+ retry: 'Retry',
36
+ addRow: 'Add row',
37
+ refColumn: 'Column',
38
+ refSearch: 'Search',
39
+ refColumnSearch: 'Search by column',
40
+ refFilter: 'Filter',
41
+ refRun: 'Run',
42
+ refClearFilter: 'Clear',
43
+ refFirst: 'First page',
44
+ refPrevious: 'Previous page',
45
+ refNext: 'Next page',
46
+ refLast: 'Last page',
47
+ refPage: 'Page',
48
+ refRange: '{from} to {to} of {total}',
49
+ refEmpty: 'No records match',
50
+ refLoading: 'Loading',
51
+ refFailed: 'The records could not be loaded',
52
+ filterNavigator: 'Filter navigator',
53
+ search: 'Search',
54
+ filterHeading: 'Filter',
55
+ filterAdd: 'Add condition',
56
+ filterSaved: 'Saved filters',
57
+ filterSaveName: 'Filter name',
58
+ filterDelete: 'Delete {name}',
59
+ filterStale: 'A column in this filter is no longer available',
60
+ filterAnd: 'and',
61
+ filterOr: 'or',
62
+ filterRemove: 'Remove {condition}',
63
+ filterMatch: 'Match',
64
+ filterMatchAll: 'All of these',
65
+ filterMatchAny: 'Any of these',
66
+ filterField: 'Field',
67
+ filterComparison: 'Comparison',
68
+ filterValue: 'Value',
69
+ filterContains: 'contains',
70
+ filterIs: 'is',
71
+ filterIsNot: 'is not',
72
+ filterGreater: 'more than',
73
+ filterLess: 'less than',
74
+ filterEmpty: 'is empty',
75
+ filterNotEmpty: 'is not empty',
76
+ editRowN: 'Edit row {n}',
77
+ saveRow: 'Save',
78
+ cancelRow: 'Cancel',
79
+ removeRow: 'Remove row',
80
+ minRows: 'Add at least {n} rows',
81
+ maxRows: 'Add at most {n} rows',
82
+ minRowsOne: 'Add at least one row',
83
+ maxRowsOne: 'Add at most one row',
84
+ maxItems: 'Add at most {n} tags',
85
+ ratingRange: 'Pick 1 to {max} stars',
86
+ ratingValue: '{n} of {max}',
87
+ stepOf: 'Use steps of {step}',
88
+ referenceNotFound: 'Record not found',
89
+ tagTooLong: 'Must be at most {n} characters',
90
+ tagNotAllowed: 'Pick one of the suggestions',
91
+ tagDuplicate: 'Already added',
92
+ removeTag: 'Remove {tag}',
93
+ next: 'Next',
94
+ submit: 'Submit',
95
+ back: 'Back',
96
+ step: 'Step {current} of {total}',
97
+ approve: 'Approve',
98
+ reject: 'Reject',
99
+ decision: 'Decision',
100
+ comment: 'Comment',
101
+ commentRequiredSuffix: ' (required)',
102
+ decisionRequired: 'A decision is required.',
103
+ commentRequired: 'A comment is required.',
104
+ nothingToReview: 'Nothing to review.',
105
+ scriptBlocked: 'Submission blocked',
106
+ yes: 'Yes',
107
+ no: 'No',
108
+ emptyValue: 'Not provided',
109
+ choose: 'Select',
110
+ rowCount: '{n} rows',
111
+ results: '{n} results',
112
+ columns: 'Columns',
113
+ selectAll: 'Select all',
114
+ selectRow: 'Select row {n}',
115
+ sortBy: 'Sort by {label}',
116
+ rowActions: 'Actions',
117
+ optional: '(optional)',
118
+ close: 'Close',
119
+ dismiss: 'Dismiss',
120
+ moreActions: 'More actions',
121
+ darkTheme: 'Dark theme',
122
+ opensInNewTab: 'opens in new tab',
123
+ otpCharacter: 'Character {i} of {n}',
124
+ row: 'Row {n}',
125
+ removeRowN: 'Remove row {n}',
126
+ stepDone: 'completed',
127
+ stepCurrent: 'current step',
128
+ today: 'Today',
129
+ now: 'Now',
130
+ clear: 'Clear',
131
+ searching: 'Searching…',
132
+ noMatches: 'No matches',
133
+ searchPlaceholder: 'Search…',
134
+ openRecord: 'Open record',
135
+ previous: 'Previous',
136
+ allDay: 'All day',
137
+ calendarMore: '+{n} more',
138
+ rowNumber: 'No.',
139
+ };
140
+ const th = {
141
+ required: 'กรุณากรอกข้อมูลนี้',
142
+ minLength: 'ต้องมีอย่างน้อย {n} ตัวอักษร',
143
+ maxLength: 'ต้องไม่เกิน {n} ตัวอักษร',
144
+ min: 'ต้องไม่น้อยกว่า {n}',
145
+ max: 'ต้องไม่เกิน {n}',
146
+ pattern: 'รูปแบบไม่ถูกต้อง',
147
+ email: 'อีเมลไม่ถูกต้อง',
148
+ url: 'URL ไม่ถูกต้อง',
149
+ decimals: 'ทศนิยมได้ไม่เกิน 2 ตำแหน่ง',
150
+ integer: 'ต้องเป็นจำนวนเต็ม',
151
+ dateDisabled: 'ไม่สามารถเลือกวันที่นี้ได้',
152
+ timeInvalid: 'ระบุเวลาเป็น ชช:นน',
153
+ compareEq: 'ต้องตรงกับ {other}',
154
+ compareNe: 'ต้องไม่ตรงกับ {other}',
155
+ compareGt: 'ต้องมากกว่า {other}',
156
+ compareGte: 'ต้องไม่น้อยกว่า {other}',
157
+ compareLt: 'ต้องน้อยกว่า {other}',
158
+ compareLte: 'ต้องไม่เกิน {other}',
159
+ fileTooLarge: 'ไฟล์มีขนาดใหญ่เกินไป',
160
+ fileTypeNotAllowed: 'ชนิดไฟล์ไม่ได้รับอนุญาต',
161
+ fileRejectedTooLarge: 'ขนาดใหญ่เกินไป ไม่ถูกเพิ่ม: {names}',
162
+ uploading: 'กำลังอัปโหลด…',
163
+ uploadFailed: 'อัปโหลดไม่สำเร็จ ลองอีกครั้ง',
164
+ markdownWrite: 'เขียน',
165
+ markdownPreview: 'ตัวอย่าง',
166
+ markdownEmpty: 'ยังไม่มีเนื้อหา',
167
+ markdownHint: 'รองรับ Markdown',
168
+ markdownAttach: 'วาง ลาก หรือเลือกไฟล์เพื่อแนบ',
169
+ removeFile: 'ลบไฟล์',
170
+ chooseFile: 'เลือกไฟล์',
171
+ chooseFiles: 'เลือกไฟล์',
172
+ orDropHere: 'หรือลากมาวางที่นี่',
173
+ uploadMaxSize: 'ไม่เกิน {size}',
174
+ retry: 'ลองใหม่',
175
+ addRow: 'เพิ่มแถว',
176
+ refColumn: 'คอลัมน์',
177
+ refSearch: 'ค้นหา',
178
+ refColumnSearch: 'ค้นหาตามคอลัมน์',
179
+ refFilter: 'ตัวกรอง',
180
+ refRun: 'ใช้ตัวกรอง',
181
+ refClearFilter: 'ล้าง',
182
+ refFirst: 'หน้าแรก',
183
+ refPrevious: 'หน้าก่อน',
184
+ refNext: 'หน้าถัดไป',
185
+ refLast: 'หน้าสุดท้าย',
186
+ refPage: 'หน้า',
187
+ refRange: '{from} ถึง {to} จาก {total}',
188
+ refEmpty: 'ไม่พบรายการที่ตรงกัน',
189
+ refLoading: 'กำลังโหลด',
190
+ refFailed: 'โหลดรายการไม่สำเร็จ',
191
+ filterNavigator: 'กรองเมนู',
192
+ search: 'ค้นหา',
193
+ filterHeading: 'ตัวกรอง',
194
+ filterAdd: 'เพิ่มเงื่อนไข',
195
+ filterSaved: 'ตัวกรองที่บันทึกไว้',
196
+ filterSaveName: 'ชื่อตัวกรอง',
197
+ filterDelete: 'ลบ {name}',
198
+ filterStale: 'คอลัมน์ในตัวกรองนี้ไม่มีแล้ว',
199
+ filterAnd: 'และ',
200
+ filterOr: 'หรือ',
201
+ filterRemove: 'ลบ {condition}',
202
+ filterMatch: 'ตรงกับ',
203
+ filterMatchAll: 'ทุกเงื่อนไข',
204
+ filterMatchAny: 'เงื่อนไขใดก็ได้',
205
+ filterField: 'ฟิลด์',
206
+ filterComparison: 'การเปรียบเทียบ',
207
+ filterValue: 'ค่า',
208
+ filterContains: 'มีคำว่า',
209
+ filterIs: 'เท่ากับ',
210
+ filterIsNot: 'ไม่เท่ากับ',
211
+ filterGreater: 'มากกว่า',
212
+ filterLess: 'น้อยกว่า',
213
+ filterEmpty: 'ว่าง',
214
+ filterNotEmpty: 'ไม่ว่าง',
215
+ editRowN: 'แก้ไขแถวที่ {n}',
216
+ saveRow: 'บันทึก',
217
+ cancelRow: 'ยกเลิก',
218
+ removeRow: 'ลบแถว',
219
+ minRows: 'ต้องมีอย่างน้อย {n} แถว',
220
+ maxRows: 'ต้องไม่เกิน {n} แถว',
221
+ minRowsOne: 'ต้องมีอย่างน้อย 1 แถว',
222
+ maxRowsOne: 'ต้องไม่เกิน 1 แถว',
223
+ maxItems: 'เพิ่มได้ไม่เกิน {n} แท็ก',
224
+ ratingRange: 'เลือก 1 ถึง {max} ดาว',
225
+ ratingValue: '{n} จาก {max}',
226
+ stepOf: 'ใช้ค่าทีละ {step}',
227
+ referenceNotFound: 'ไม่พบรายการนี้',
228
+ tagTooLong: 'ต้องไม่เกิน {n} ตัวอักษร',
229
+ tagNotAllowed: 'กรุณาเลือกจากตัวเลือกที่แนะนำ',
230
+ tagDuplicate: 'เพิ่มไว้แล้ว',
231
+ removeTag: 'ลบ {tag}',
232
+ next: 'ถัดไป',
233
+ submit: 'ส่งข้อมูล',
234
+ back: 'ย้อนกลับ',
235
+ step: 'ขั้นตอนที่ {current} จาก {total}',
236
+ approve: 'อนุมัติ',
237
+ reject: 'ไม่อนุมัติ',
238
+ decision: 'ผลการพิจารณา',
239
+ comment: 'ความคิดเห็น',
240
+ commentRequiredSuffix: ' (จำเป็น)',
241
+ decisionRequired: 'ต้องเลือกผลการพิจารณา',
242
+ commentRequired: 'ต้องกรอกความคิดเห็น',
243
+ nothingToReview: 'ไม่มีข้อมูลให้ตรวจสอบ',
244
+ scriptBlocked: 'ไม่สามารถส่งได้',
245
+ yes: 'ใช่',
246
+ no: 'ไม่ใช่',
247
+ emptyValue: 'ไม่ได้ระบุ',
248
+ choose: 'เลือก',
249
+ rowCount: '{n} แถว',
250
+ results: '{n} รายการ',
251
+ columns: 'คอลัมน์',
252
+ selectAll: 'เลือกทั้งหมด',
253
+ selectRow: 'เลือกแถวที่ {n}',
254
+ sortBy: 'เรียงตาม {label}',
255
+ rowActions: 'การทำงาน',
256
+ optional: '(ไม่บังคับ)',
257
+ close: 'ปิด',
258
+ dismiss: 'ปิดข้อความ',
259
+ moreActions: 'ตัวเลือกเพิ่มเติม',
260
+ darkTheme: 'ธีมมืด',
261
+ opensInNewTab: 'เปิดในแท็บใหม่',
262
+ otpCharacter: 'ตัวอักษรที่ {i} จาก {n}',
263
+ row: 'แถวที่ {n}',
264
+ removeRowN: 'ลบแถวที่ {n}',
265
+ stepDone: 'เสร็จแล้ว',
266
+ stepCurrent: 'ขั้นตอนปัจจุบัน',
267
+ today: 'วันนี้',
268
+ now: 'ตอนนี้',
269
+ clear: 'ล้างค่า',
270
+ searching: 'กำลังค้นหา…',
271
+ noMatches: 'ไม่พบรายการ',
272
+ searchPlaceholder: 'ค้นหา…',
273
+ openRecord: 'เปิดรายการ',
274
+ previous: 'ก่อนหน้า',
275
+ allDay: 'ทั้งวัน',
276
+ calendarMore: '+อีก {n} รายการ',
277
+ rowNumber: 'ลำดับ',
278
+ };
279
+ const BUILTIN = { en, th };
280
+ let current = en;
281
+ export function setLocale(locale, overrides) {
282
+ current = { ...BUILTIN[locale], ...overrides };
283
+ }
284
+ export function getCatalog() {
285
+ return current;
286
+ }
287
+ export function setCatalog(catalog) {
288
+ current = catalog;
289
+ }
290
+ export function withLocale(locale, fn) {
291
+ if (locale === undefined)
292
+ return fn();
293
+ const prev = current;
294
+ setLocale(locale);
295
+ try {
296
+ return fn();
297
+ }
298
+ finally {
299
+ current = prev;
300
+ }
301
+ }
302
+ export function t(key, params) {
303
+ let out = current[key] ?? en[key];
304
+ if (params) {
305
+ for (const [k, v] of Object.entries(params)) {
306
+ out = out.replaceAll(`{${k}}`, () => String(v));
307
+ }
308
+ }
309
+ return out;
310
+ }
@@ -0,0 +1,25 @@
1
+ export * from './types.js';
2
+ export { defineForm, defineWorkflow, type FormValues } from './form-values.js';
3
+ export { defaultValue } from './defaults.js';
4
+ export { approvalCommentRequired, approvalFields } from './approval.js';
5
+ export { isBlank, validateField, normalizeTagsValue, optionKeyLookup, rangeBounds, ratingMax, isTimeOfDay, isUploadedFile, } from './validators.js';
6
+ export { isUnsafePattern } from './pattern-safety.js';
7
+ export { isSafeUrl } from './urls.js';
8
+ export { UNSAFE_KEYS, rowSubFields } from './keys.js';
9
+ export { resolveViewFields } from './views.js';
10
+ export { applyFlags, flagEnabled } from './flags.js';
11
+ export { getCatalog, setCatalog, setLocale, t, withLocale } from './i18n.js';
12
+ export type { Locale, MessageCatalog, MessageKey } from './i18n.js';
13
+ export { evaluate } from './engine/evaluate.js';
14
+ export { resolveNext, stepFieldStates, visibleForms, walkPath } from './engine/graph.js';
15
+ export { currentForm, nextTarget, replayWorkflow, snapshotOf, updateWorkflow, type StepDirection, type WorkflowEnd, type WorkflowEvent, type WorkflowEventMap, type WorkflowMsg, type WorkflowSnapshot, type WorkflowState, type WorkflowTransition, type WorkflowUpdate, } from './engine/runtime.js';
16
+ export { emptyFormState, formData, formFieldState, submitScriptErrors, updateForm, validateShownField, type FormEvent, type FormEventMap, type FormHost, type FormInput, type FormMsg, type FormState, type FormUpdate, } from './engine/form-session.js';
17
+ export { sameData } from './same-data.js';
18
+ export { conditionRowRefs, evalCondition, parseRowRef, readRef } from './engine/conditions.js';
19
+ export type { RowRef, RowScope } from './engine/conditions.js';
20
+ export { evalValueExpr } from './engine/expressions.js';
21
+ export { createScriptContext, hasScripts, runScripts, MAX_SCRIPT_DEPTH, type ScriptFieldState, type ScriptSink, } from './engine/scripts.js';
22
+ export { displayValue, type DisplayValue } from './display.js';
23
+ export { LEGACY_KEY_MAP, normalizeLegacySchema, type NormalizeResult } from './legacy.js';
24
+ export { formatIsoDate, formatIsoDateTime, dateModeOf, isDateDisabled, isoDaysOf, parseDisabledEntry, parseIsoDate, parseIsoDateTime, } from './dates.js';
25
+ export { ariaKeyshortcuts, formatShortcut, matchShortcut, parseShortcut, type ParsedShortcut, type ShortcutKeyEvent, type ShortcutPlatform, } from './shortcut.js';
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ export * from './types.js';
2
+ export { defineForm, defineWorkflow } from './form-values.js';
3
+ export { defaultValue } from './defaults.js';
4
+ export { approvalCommentRequired, approvalFields } from './approval.js';
5
+ export { isBlank, validateField, normalizeTagsValue, optionKeyLookup, rangeBounds, ratingMax, isTimeOfDay, isUploadedFile, } from './validators.js';
6
+ export { isUnsafePattern } from './pattern-safety.js';
7
+ export { isSafeUrl } from './urls.js';
8
+ export { UNSAFE_KEYS, rowSubFields } from './keys.js';
9
+ export { resolveViewFields } from './views.js';
10
+ export { applyFlags, flagEnabled } from './flags.js';
11
+ export { getCatalog, setCatalog, setLocale, t, withLocale } from './i18n.js';
12
+ export { evaluate } from './engine/evaluate.js';
13
+ export { resolveNext, stepFieldStates, visibleForms, walkPath } from './engine/graph.js';
14
+ export { currentForm, nextTarget, replayWorkflow, snapshotOf, updateWorkflow, } from './engine/runtime.js';
15
+ export { emptyFormState, formData, formFieldState, submitScriptErrors, updateForm, validateShownField, } from './engine/form-session.js';
16
+ export { sameData } from './same-data.js';
17
+ export { conditionRowRefs, evalCondition, parseRowRef, readRef } from './engine/conditions.js';
18
+ export { evalValueExpr } from './engine/expressions.js';
19
+ export { createScriptContext, hasScripts, runScripts, MAX_SCRIPT_DEPTH, } from './engine/scripts.js';
20
+ export { displayValue } from './display.js';
21
+ export { LEGACY_KEY_MAP, normalizeLegacySchema } from './legacy.js';
22
+ export { formatIsoDate, formatIsoDateTime, dateModeOf, isDateDisabled, isoDaysOf, parseDisabledEntry, parseIsoDate, parseIsoDateTime, } from './dates.js';
23
+ export { ariaKeyshortcuts, formatShortcut, matchShortcut, parseShortcut, } from './shortcut.js';
package/dist/keys.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { FieldDescriptor } from './types.js';
2
+ /**
3
+ * Keys that would address the prototype instead of an own property. A field,
4
+ * form or row key named like one is authoring-invalid (`parseSchema` rejects
5
+ * it) and skipped wherever untrusted data is read or written, so input can
6
+ * never reach an `Object.prototype` setter. One list for the engine and the
7
+ * server validator: a second copy would be the one that drifts.
8
+ */
9
+ export declare const UNSAFE_KEYS: ReadonlySet<string>;
10
+ /**
11
+ * The sub-fields a repeater row carries values for: no static blocks, and no
12
+ * nested repeater (repeaters nest one level only, spec 01 §10).
13
+ */
14
+ export declare function rowSubFields(repeater: FieldDescriptor): FieldDescriptor[];
package/dist/keys.js ADDED
@@ -0,0 +1,4 @@
1
+ export const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
2
+ export function rowSubFields(repeater) {
3
+ return (repeater.fields ?? []).filter((f) => f.type !== 'label' && f.type !== 'section' && f.type !== 'repeater');
4
+ }
@@ -0,0 +1,14 @@
1
+ /** camelCase key → 0.3.0 snake_case key, for every renamed schema key. */
2
+ export declare const LEGACY_KEY_MAP: Readonly<Record<string, string>>;
3
+ export interface NormalizeResult<T> {
4
+ schema: T;
5
+ /** Legacy keys that were renamed, as `path.key` strings — empty when the input was already current. */
6
+ renamed: string[];
7
+ }
8
+ /**
9
+ * Returns a copy of `json` with every legacy camelCase schema key renamed to
10
+ * its snake_case form, recursively (forms, fields, repeater sub-fields,
11
+ * approval config, rule conditions). Non-object input is returned as-is. A
12
+ * key present in BOTH spellings keeps the snake_case value.
13
+ */
14
+ export declare function normalizeLegacySchema<T = unknown>(json: T): NormalizeResult<T>;
package/dist/legacy.js ADDED
@@ -0,0 +1,47 @@
1
+ export const LEGACY_KEY_MAP = {
2
+ formId: 'form_id',
3
+ formName: 'form_name',
4
+ field_data: 'fields',
5
+ workflowId: 'workflow_id',
6
+ optionsFrom: 'options_from',
7
+ optionsDeps: 'options_deps',
8
+ maxLength: 'max_length',
9
+ minLength: 'min_length',
10
+ dateMode: 'date_mode',
11
+ dateFormat: 'date_format',
12
+ disabledDates: 'disabled_dates',
13
+ disabledWeekdays: 'disabled_weekdays',
14
+ maxSize: 'max_size',
15
+ minRows: 'min_rows',
16
+ maxRows: 'max_rows',
17
+ addLabel: 'add_label',
18
+ summaryForms: 'summary_forms',
19
+ approveLabel: 'approve_label',
20
+ rejectLabel: 'reject_label',
21
+ onReject: 'on_reject',
22
+ valueField: 'value_field',
23
+ };
24
+ export function normalizeLegacySchema(json) {
25
+ const renamed = [];
26
+ const walk = (value, path) => {
27
+ if (Array.isArray(value))
28
+ return value.map((v, i) => walk(v, `${path}[${i}]`));
29
+ if (typeof value !== 'object' || value === null)
30
+ return value;
31
+ const out = {};
32
+ const src = value;
33
+ for (const [key, v] of Object.entries(src)) {
34
+ const target = LEGACY_KEY_MAP[key];
35
+ if (target === undefined) {
36
+ out[key] = walk(v, path ? `${path}.${key}` : key);
37
+ continue;
38
+ }
39
+ renamed.push(path ? `${path}.${key}` : key);
40
+ if (Object.hasOwn(src, target))
41
+ continue;
42
+ out[target] = walk(v, path ? `${path}.${target}` : target);
43
+ }
44
+ return out;
45
+ };
46
+ return { schema: walk(json, ''), renamed };
47
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * ReDoS guard for `pattern` validators (CLAUDE.md engine invariant: patterns
3
+ * nesting unbounded quantifiers are rejected). A small tokenizer turns the
4
+ * source into groups/alternatives/quantified items, then flags any group
5
+ * repeated more than twice whose body can be split between iterations in
6
+ * more than one way — the shape that makes a backtracking engine go
7
+ * exponential (or high-degree polynomial for a large bounded repeat):
8
+ *
9
+ * - every mandatory item of an alternative varies in length, unbounded or as
10
+ * a bounded range: `(a+)+`, `((a+))+`, `(?<n>a+)+`, `(\w+\s?)+`, `(x+x+)+`,
11
+ * `(a*)*`, `(\d{1,3},?)+`, `(a{1,30})+`
12
+ * - one alternative varies on its own: `(a+|b)+`
13
+ * - two alternatives are spelled the same: `(a|a)+`
14
+ * - two alternatives can start on the same character, or one can match
15
+ * nothing: `(\w|\d)+`, `(a|ab)+`, `(a|a?)+`
16
+ * - an item of varying length can swallow the character that ends its
17
+ * iteration: `(.*a){12}`, `(a+b?)+`, `(\d{1,3}\d)+`
18
+ * - three or more adjacent unbounded runs share a character: `\d*\d*\d*x`
19
+ * (cubic and worse; two runs stay quadratic and are left to the length cap)
20
+ *
21
+ * Character overlap is decided by testing each atom against a fixed sample of
22
+ * characters (ASCII plus a few non-ASCII classes), so it can miss an overlap
23
+ * that lives only outside the sample. A mandatory fixed-length atom that the
24
+ * varying part cannot consume (`(-[a-z]+)*`, `(abc+)+`) anchors each
25
+ * iteration and is accepted. Patterns are builder-authored: the guard
26
+ * catches authoring mistakes at save time, and the validator also caps the
27
+ * input length a pattern runs on. A linear-time engine is the real fix.
28
+ */
29
+ /**
30
+ * True when `source` backtracks catastrophically on hostile input (see module
31
+ * doc). Sources that do not compile return false — callers report those as
32
+ * invalid separately.
33
+ */
34
+ export declare function isUnsafePattern(source: string): boolean;