@eskais/app-sdk 0.0.0-stage → 0.2.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.
Files changed (159) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +74 -2
  3. package/dist/action/action.d.ts +133 -0
  4. package/dist/action/action.js +224 -0
  5. package/dist/action/bulk.d.ts +24 -0
  6. package/dist/action/bulk.js +24 -0
  7. package/dist/cli/cli.d.ts +2 -0
  8. package/dist/cli/cli.js +51 -0
  9. package/dist/cli/routes.d.ts +17 -0
  10. package/dist/cli/routes.js +36 -0
  11. package/dist/core/assume.d.ts +1 -0
  12. package/dist/core/assume.js +8 -0
  13. package/dist/core/constants.d.ts +359 -0
  14. package/dist/core/constants.js +187 -0
  15. package/dist/core/contracts.d.ts +107 -0
  16. package/dist/core/contracts.js +3 -0
  17. package/dist/core/data-labels.d.ts +210 -0
  18. package/dist/core/data-labels.js +385 -0
  19. package/dist/core/errors.d.ts +52 -0
  20. package/dist/core/errors.js +209 -0
  21. package/dist/core/guards.d.ts +9 -0
  22. package/dist/core/guards.js +14 -0
  23. package/dist/core/refusal.d.ts +30 -0
  24. package/dist/core/refusal.js +53 -0
  25. package/dist/dialogs/dialogs.d.ts +75 -0
  26. package/dist/dialogs/dialogs.js +66 -0
  27. package/dist/draft/draft.d.ts +36 -0
  28. package/dist/draft/draft.js +87 -0
  29. package/dist/errors/adapters.d.ts +21 -0
  30. package/dist/errors/adapters.js +81 -0
  31. package/dist/errors/define-errors.d.ts +88 -0
  32. package/dist/errors/define-errors.js +168 -0
  33. package/dist/errors/idempotency.d.ts +2 -0
  34. package/dist/errors/idempotency.js +13 -0
  35. package/dist/export/csv.d.ts +25 -0
  36. package/dist/export/csv.js +59 -0
  37. package/dist/i18n/adapters.d.ts +53 -0
  38. package/dist/i18n/adapters.js +56 -0
  39. package/dist/i18n/format.d.ts +10 -0
  40. package/dist/i18n/format.js +273 -0
  41. package/dist/i18n/labels.d.ts +10 -0
  42. package/dist/i18n/labels.js +227 -0
  43. package/dist/i18n/locale.d.ts +73 -0
  44. package/dist/i18n/locale.js +74 -0
  45. package/dist/i18n/messages.d.ts +93 -0
  46. package/dist/i18n/messages.js +16 -0
  47. package/dist/import/csv-parse.d.ts +11 -0
  48. package/dist/import/csv-parse.js +70 -0
  49. package/dist/import/import.d.ts +104 -0
  50. package/dist/import/import.js +266 -0
  51. package/dist/index.d.ts +46 -0
  52. package/dist/index.js +45 -0
  53. package/dist/navigation/nav.d.ts +128 -0
  54. package/dist/navigation/nav.js +301 -0
  55. package/dist/navigation/router.d.ts +81 -0
  56. package/dist/navigation/router.js +249 -0
  57. package/dist/navigation/shortcuts.d.ts +37 -0
  58. package/dist/navigation/shortcuts.js +93 -0
  59. package/dist/next/index.d.ts +3 -0
  60. package/dist/next/index.js +3 -0
  61. package/dist/next/screen-hydration.d.ts +12 -0
  62. package/dist/next/screen-hydration.js +26 -0
  63. package/dist/next/screen.d.ts +25 -0
  64. package/dist/next/screen.js +44 -0
  65. package/dist/next/server/handler.d.ts +39 -0
  66. package/dist/next/server/handler.js +190 -0
  67. package/dist/next/server/index.d.ts +6 -0
  68. package/dist/next/server/index.js +6 -0
  69. package/dist/next/server/page.d.ts +63 -0
  70. package/dist/next/server/page.js +110 -0
  71. package/dist/next/server/prefetch.d.ts +29 -0
  72. package/dist/next/server/prefetch.js +97 -0
  73. package/dist/next/server/session.d.ts +25 -0
  74. package/dist/next/server/session.js +23 -0
  75. package/dist/next/use-next-router.d.ts +21 -0
  76. package/dist/next/use-next-router.js +104 -0
  77. package/dist/permissions/permissions.d.ts +134 -0
  78. package/dist/permissions/permissions.js +121 -0
  79. package/dist/react/data-layer.d.ts +68 -0
  80. package/dist/react/data-layer.js +76 -0
  81. package/dist/react/hooks/use-action-dialog.d.ts +25 -0
  82. package/dist/react/hooks/use-action-dialog.js +31 -0
  83. package/dist/react/hooks/use-action.d.ts +37 -0
  84. package/dist/react/hooks/use-action.js +125 -0
  85. package/dist/react/hooks/use-better-auth.d.ts +12 -0
  86. package/dist/react/hooks/use-better-auth.js +11 -0
  87. package/dist/react/hooks/use-bulk-action.d.ts +20 -0
  88. package/dist/react/hooks/use-bulk-action.js +24 -0
  89. package/dist/react/hooks/use-dialogs.d.ts +14 -0
  90. package/dist/react/hooks/use-dialogs.js +20 -0
  91. package/dist/react/hooks/use-draft.d.ts +5 -0
  92. package/dist/react/hooks/use-draft.js +17 -0
  93. package/dist/react/hooks/use-nav.d.ts +17 -0
  94. package/dist/react/hooks/use-nav.js +35 -0
  95. package/dist/react/hooks/use-new-rows.d.ts +22 -0
  96. package/dist/react/hooks/use-new-rows.js +24 -0
  97. package/dist/react/hooks/use-permissions.d.ts +13 -0
  98. package/dist/react/hooks/use-permissions.js +19 -0
  99. package/dist/react/hooks/use-reauthenticate.d.ts +6 -0
  100. package/dist/react/hooks/use-reauthenticate.js +11 -0
  101. package/dist/react/hooks/use-resource.d.ts +92 -0
  102. package/dist/react/hooks/use-resource.js +255 -0
  103. package/dist/react/hooks/use-view.d.ts +6 -0
  104. package/dist/react/hooks/use-view.js +24 -0
  105. package/dist/react/index.d.ts +15 -0
  106. package/dist/react/index.js +15 -0
  107. package/dist/react/keys.d.ts +60 -0
  108. package/dist/react/keys.js +71 -0
  109. package/dist/react/new-rows.d.ts +22 -0
  110. package/dist/react/new-rows.js +72 -0
  111. package/dist/refresh/new-rows.d.ts +13 -0
  112. package/dist/refresh/new-rows.js +18 -0
  113. package/dist/resource/form-schema.d.ts +11 -0
  114. package/dist/resource/form-schema.js +51 -0
  115. package/dist/resource/relations.d.ts +99 -0
  116. package/dist/resource/relations.js +194 -0
  117. package/dist/resource/resource-relations.d.ts +47 -0
  118. package/dist/resource/resource-relations.js +154 -0
  119. package/dist/resource/resource-schema.d.ts +9 -0
  120. package/dist/resource/resource-schema.js +73 -0
  121. package/dist/resource/resource-texts.d.ts +18 -0
  122. package/dist/resource/resource-texts.js +13 -0
  123. package/dist/resource/resource-types.d.ts +420 -0
  124. package/dist/resource/resource-types.js +1 -0
  125. package/dist/resource/resource-words.d.ts +25 -0
  126. package/dist/resource/resource-words.js +221 -0
  127. package/dist/resource/resource.d.ts +15 -0
  128. package/dist/resource/resource.js +280 -0
  129. package/dist/resource/schema.d.ts +57 -0
  130. package/dist/resource/schema.js +115 -0
  131. package/dist/services/from-page-source.d.ts +15 -0
  132. package/dist/services/from-page-source.js +27 -0
  133. package/dist/services/memory-query.d.ts +8 -0
  134. package/dist/services/memory-query.js +165 -0
  135. package/dist/services/memory-service.d.ts +33 -0
  136. package/dist/services/memory-service.js +291 -0
  137. package/dist/services/read-only-service.d.ts +18 -0
  138. package/dist/services/read-only-service.js +25 -0
  139. package/dist/services/rest-service.d.ts +65 -0
  140. package/dist/services/rest-service.js +222 -0
  141. package/dist/services/rng.d.ts +9 -0
  142. package/dist/services/rng.js +22 -0
  143. package/dist/services/spring-service.d.ts +58 -0
  144. package/dist/services/spring-service.js +132 -0
  145. package/dist/session/better-auth.d.ts +83 -0
  146. package/dist/session/better-auth.js +86 -0
  147. package/dist/session/session.d.ts +45 -0
  148. package/dist/session/session.js +36 -0
  149. package/dist/view/preferences.d.ts +35 -0
  150. package/dist/view/preferences.js +93 -0
  151. package/dist/view/view-types.d.ts +124 -0
  152. package/dist/view/view-types.js +1 -0
  153. package/dist/view/view-url.d.ts +7 -0
  154. package/dist/view/view-url.js +54 -0
  155. package/dist/view/view.d.ts +4 -0
  156. package/dist/view/view.js +392 -0
  157. package/locales/en.json +193 -0
  158. package/locales/es.json +193 -0
  159. package/package.json +88 -4
@@ -0,0 +1,210 @@
1
+ import type { ErrorReason } from "./constants.js";
2
+ export type ImportCounts = {
3
+ created: number;
4
+ updated: number;
5
+ failed: number;
6
+ cancelled: boolean;
7
+ };
8
+ /** Text of the Eskais UI controls the blocks render: list status, filters, comboboxes, file and date fields. */
9
+ export type ControlLabels = {
10
+ refreshing: string;
11
+ filters: {
12
+ chip: (field: string, summary: string) => string;
13
+ selected: (count: number, locale?: string) => string;
14
+ any: string;
15
+ from: string;
16
+ to: string;
17
+ min: string;
18
+ max: string;
19
+ value: string;
20
+ comparison: string;
21
+ operators: {
22
+ eq: string;
23
+ neq: string;
24
+ lt: string;
25
+ lte: string;
26
+ gt: string;
27
+ gte: string;
28
+ between: string;
29
+ };
30
+ };
31
+ combobox: {
32
+ trigger: string;
33
+ clear: string;
34
+ remove: (label: string) => string;
35
+ error: string;
36
+ empty: (query: string) => string;
37
+ count: (count: number, hasMore: boolean, locale?: string) => string;
38
+ };
39
+ files: {
40
+ list: string;
41
+ remove: (name: string) => string;
42
+ rejected: (name: string) => string;
43
+ };
44
+ date: {
45
+ clear: string;
46
+ previousMonth: string;
47
+ nextMonth: string;
48
+ start: string;
49
+ end: string;
50
+ };
51
+ time: string;
52
+ colorValue: string;
53
+ };
54
+ /** A schema issue as forms read it: a code (`required`, `email`, `minLength`…) with its params and the field's label. */
55
+ export type IssueText = {
56
+ code: string;
57
+ params: Record<string, unknown>;
58
+ label?: string;
59
+ message?: string;
60
+ };
61
+ export type RowRange = {
62
+ from: number;
63
+ to: number;
64
+ total?: number | undefined;
65
+ estimate?: boolean | undefined;
66
+ };
67
+ /**
68
+ * Every generic text the App SDK shows, passed to `DataLayer`. `{ one }` and `{ other }` are the resource's label in
69
+ * the singular and the plural. Nothing has a default in any language: pass `dataLabelsEn`, `dataLabelsEs` or yours.
70
+ */
71
+ export type DataLabels = {
72
+ create: (one: string) => string;
73
+ edit: string;
74
+ editRecord: (title: string) => string;
75
+ remove: string;
76
+ restore: string;
77
+ save: string;
78
+ cancel: string;
79
+ undo: string;
80
+ open: string;
81
+ back: string;
82
+ retry: string;
83
+ records: (other: string) => string;
84
+ listTool: (other: string) => string;
85
+ removeRecords: (other: string) => string;
86
+ rowActions: (title: string) => string;
87
+ /** The group agents create a record through from a combobox: "Quick create country". */
88
+ quickCreate: (one: string) => string;
89
+ createOption: (text: string) => string;
90
+ creatingOption: (text: string) => string;
91
+ empty: (other: string) => string;
92
+ errorTitle: (other: string) => string;
93
+ notFound: (one: string) => string;
94
+ forbidden: (one: string) => string;
95
+ notAllowed: string;
96
+ /** A route guard's page, when the session may not open the path. */
97
+ forbiddenPage: string;
98
+ /** The banner that shows rows a background reload held back. */
99
+ newRows: (count: number, locale?: string) => string;
100
+ /** `useDialogs`: confirm's yes, and alert's button. */
101
+ confirm: string;
102
+ ok: string;
103
+ range: (range: RowRange, locale?: string) => string;
104
+ loading: string;
105
+ search: (other: string) => string;
106
+ filters: (other: string) => string;
107
+ pageSize: string;
108
+ addFilter: string;
109
+ resetFilters: string;
110
+ removeFilter: (field: string) => string;
111
+ previousPage: string;
112
+ nextPage: string;
113
+ page: (page: number) => string;
114
+ pagination: (other: string) => string;
115
+ loadMore: string;
116
+ showDeleted: string;
117
+ columns: string;
118
+ views: (other: string) => string;
119
+ allRows: string;
120
+ saveView: string;
121
+ viewName: string;
122
+ removeView: (label: string) => string;
123
+ removeViews: (other: string) => string;
124
+ confirmRemoveView: (label: string) => string;
125
+ viewOptions: (label: string) => string;
126
+ viewModified: string;
127
+ saveViewChanges: string;
128
+ renameView: string;
129
+ defaultView: string;
130
+ setDefaultView: string;
131
+ unsetDefaultView: string;
132
+ onlyThisBrowser: string;
133
+ selected: (count: number, locale?: string) => string;
134
+ selectAllMatching: (count: number, other: string, locale?: string) => string;
135
+ allMatchingSelected: (count: number, other: string, locale?: string) => string;
136
+ clearSelection: string;
137
+ exportCsv: string;
138
+ importCsv: string;
139
+ importTitle: (other: string) => string;
140
+ /** The group agents import rows through, apart from the dialog's name. */
141
+ importTool: (other: string) => string;
142
+ importNoRows: string;
143
+ columnField: (column: string) => string;
144
+ skipColumn: string;
145
+ next: string;
146
+ close: string;
147
+ importReady: (valid: number, invalid: number, locale?: string) => string;
148
+ importRows: (count: number, locale?: string) => string;
149
+ downloadErrors: string;
150
+ importing: (done: number, total: number, locale?: string) => string;
151
+ stop: string;
152
+ importSummary: (counts: ImportCounts, locale?: string) => string;
153
+ line: string;
154
+ errorColumn: string;
155
+ exportTooLarge: (count: number, limit: number, locale?: string) => string;
156
+ confirmRemove: (target: string) => string;
157
+ confirmRemoveDescription: string;
158
+ removeAgentConfirm: (target: string) => string;
159
+ removed: (count: number, other: string, locale?: string) => string;
160
+ created: (title: string) => string;
161
+ saved: (title: string) => string;
162
+ restored: (count: number, locale?: string) => string;
163
+ failed: string;
164
+ unsavedChanges: string;
165
+ discard: string;
166
+ keepEditing: string;
167
+ draftFound: (date: Date, locale?: string) => string;
168
+ draft: (title: string) => string;
169
+ restoreDraft: string;
170
+ discardDraft: string;
171
+ favorites: string;
172
+ recents: string;
173
+ pin: (label: string) => string;
174
+ unpin: (label: string) => string;
175
+ goTo: string;
176
+ pages: string;
177
+ actions: string;
178
+ breadcrumb: string;
179
+ audit: {
180
+ createdAt: string;
181
+ createdBy: string;
182
+ updatedAt: string;
183
+ updatedBy: string;
184
+ };
185
+ yes: string;
186
+ no: string;
187
+ notSet: string;
188
+ /** The drop zone of a file or image field. */
189
+ dropFile: string;
190
+ browseFiles: string;
191
+ controls: ControlLabels;
192
+ /**
193
+ * A schema issue's text in the dictionary's language, for forms (their `messages`) and the importer;
194
+ * `undefined` keeps the form's own English text.
195
+ */
196
+ issues: (issue: IssueText) => string | undefined;
197
+ /** An id that no related record has, in an import. */
198
+ missingRecord: (id: string) => string;
199
+ addRow: string;
200
+ removeRow: (row: number) => string;
201
+ invalidDuration: string;
202
+ /** What a person reads about a failed call, by its reason; `defineErrors` can word one otherwise. */
203
+ errors: Readonly<Record<ErrorReason, string>>;
204
+ /** A bulk action's outcome: "3 done, 2 failed". */
205
+ bulkResult: (succeeded: number, failed: number, locale?: string) => string;
206
+ /** The button that runs a bulk action again on the rows that failed. */
207
+ retryFailed: (count: number, locale?: string) => string;
208
+ };
209
+ export declare const dataLabelsEn: DataLabels;
210
+ export declare const dataLabelsEs: DataLabels;
@@ -0,0 +1,385 @@
1
+ const count = (value, locale) => new Intl.NumberFormat(locale).format(value);
2
+ const day = (date, locale) => new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeStyle: "short" }).format(date);
3
+ export const dataLabelsEn = {
4
+ create: (one) => `New ${one.toLocaleLowerCase()}`,
5
+ edit: "Edit",
6
+ editRecord: (title) => `Edit ${title}`,
7
+ remove: "Delete",
8
+ restore: "Restore",
9
+ save: "Save",
10
+ cancel: "Cancel",
11
+ undo: "Undo",
12
+ open: "Open",
13
+ back: "Back",
14
+ retry: "Try again",
15
+ records: (other) => `${other} records`,
16
+ listTool: (other) => `${other} list`,
17
+ removeRecords: (other) => `Remove ${other.toLocaleLowerCase()}`,
18
+ rowActions: (title) => `Actions for ${title}`,
19
+ quickCreate: (one) => `Quick create ${one.toLocaleLowerCase()}`,
20
+ createOption: (text) => `Create “${text}”`,
21
+ creatingOption: (text) => `Creating “${text}”…`,
22
+ empty: (other) => `No ${other.toLocaleLowerCase()}`,
23
+ errorTitle: (other) => `Couldn't load ${other.toLocaleLowerCase()}`,
24
+ notFound: (one) => `This ${one.toLocaleLowerCase()} doesn't exist`,
25
+ forbidden: (one) => `You can't see this ${one.toLocaleLowerCase()}`,
26
+ notAllowed: "You don't have permission",
27
+ forbiddenPage: "You don't have access to this page",
28
+ newRows: (value, locale) => `Show ${count(value, locale)} new ${value === 1 ? "row" : "rows"}`,
29
+ confirm: "Confirm",
30
+ ok: "OK",
31
+ range: ({ from, to, total, estimate }, locale) => {
32
+ const shown = `Showing ${count(from, locale)}–${count(to, locale)}`;
33
+ if (total === undefined)
34
+ return shown;
35
+ return `${shown} of ${estimate === true ? "about " : ""}${count(total, locale)}`;
36
+ },
37
+ loading: "Loading…",
38
+ search: (other) => `Search ${other.toLocaleLowerCase()}`,
39
+ filters: (other) => `${other} filters`,
40
+ pageSize: "Rows per page",
41
+ addFilter: "Add filter",
42
+ resetFilters: "Reset filters",
43
+ removeFilter: (field) => `Remove ${field} filter`,
44
+ previousPage: "Previous page",
45
+ nextPage: "Next page",
46
+ page: (page) => `Page ${String(page)}`,
47
+ pagination: (other) => `${other} pages`,
48
+ loadMore: "Load more",
49
+ showDeleted: "Show deleted",
50
+ columns: "Columns",
51
+ views: (other) => `${other} views`,
52
+ allRows: "All",
53
+ saveView: "Save view",
54
+ viewName: "View name",
55
+ removeView: (label) => `Delete view ${label}`,
56
+ removeViews: (other) => `Delete ${other.toLocaleLowerCase()} views`,
57
+ confirmRemoveView: (label) => `Delete the view ${label}?`,
58
+ viewOptions: (label) => `Options for view ${label}`,
59
+ viewModified: "Modified",
60
+ saveViewChanges: "Save changes",
61
+ renameView: "Rename",
62
+ defaultView: "Default",
63
+ setDefaultView: "Make default",
64
+ unsetDefaultView: "Stop using as default",
65
+ onlyThisBrowser: "Only in this browser",
66
+ selected: (value, locale) => `${count(value, locale)} selected`,
67
+ selectAllMatching: (value, other, locale) => `Select all ${count(value, locale)} ${other.toLocaleLowerCase()}`,
68
+ allMatchingSelected: (value, other, locale) => `All ${count(value, locale)} ${other.toLocaleLowerCase()} that match are selected`,
69
+ clearSelection: "Clear selection",
70
+ exportCsv: "Export CSV",
71
+ importCsv: "Import CSV",
72
+ importTitle: (other) => `Import ${other.toLocaleLowerCase()}`,
73
+ importTool: (other) => `${other} import`,
74
+ importNoRows: "The file has no rows under its header.",
75
+ columnField: (column) => `Field for ${column}`,
76
+ skipColumn: "Don't import",
77
+ next: "Next",
78
+ close: "Close",
79
+ importReady: (valid, invalid, locale) => `${count(valid, locale)} ${valid === 1 ? "row" : "rows"} ready, ${count(invalid, locale)} with errors`,
80
+ importRows: (value, locale) => `Import ${count(value, locale)} ${value === 1 ? "row" : "rows"}`,
81
+ downloadErrors: "Download rows with errors",
82
+ importing: (done, total, locale) => `Imported ${count(done, locale)} of ${count(total, locale)}`,
83
+ stop: "Stop",
84
+ importSummary: ({ created, updated, failed, cancelled }, locale) => `${cancelled ? "Stopped. " : ""}${count(created, locale)} created, ${count(updated, locale)} updated, ${count(failed, locale)} failed.`,
85
+ line: "Row",
86
+ errorColumn: "Error",
87
+ exportTooLarge: (value, limit, locale) => `${count(value, locale)} rows exceed the ${count(limit, locale)}-row limit of a browser export`,
88
+ confirmRemove: (target) => `Delete ${target}?`,
89
+ confirmRemoveDescription: "This can't be undone.",
90
+ removeAgentConfirm: (target) => `Deletes ${target}`,
91
+ removed: (value, other, locale) => `${count(value, locale)} ${other.toLocaleLowerCase()} deleted`,
92
+ created: (title) => `${title} created`,
93
+ saved: (title) => `${title} saved`,
94
+ restored: (value, locale) => `${count(value, locale)} restored`,
95
+ failed: "Something went wrong",
96
+ unsavedChanges: "Discard your unsaved changes?",
97
+ discard: "Discard",
98
+ keepEditing: "Keep editing",
99
+ draftFound: (date, locale) => `You have unsaved changes from ${day(date, locale)}.`,
100
+ draft: (title) => `${title} draft`,
101
+ restoreDraft: "Restore",
102
+ discardDraft: "Discard",
103
+ favorites: "Favorites",
104
+ recents: "Recent",
105
+ pin: (label) => `Pin ${label}`,
106
+ unpin: (label) => `Unpin ${label}`,
107
+ goTo: "Go to",
108
+ pages: "Pages",
109
+ actions: "Actions",
110
+ breadcrumb: "Breadcrumb",
111
+ audit: { createdAt: "Created", createdBy: "Created by", updatedAt: "Updated", updatedBy: "Updated by" },
112
+ yes: "Yes",
113
+ no: "No",
114
+ notSet: "Not set",
115
+ dropFile: "Drop a file here",
116
+ browseFiles: "Browse files",
117
+ controls: {
118
+ refreshing: "Refreshing",
119
+ filters: {
120
+ chip: (field, summary) => (summary === "" ? field : `${field}: ${summary}`),
121
+ selected: (value, locale) => `${count(value, locale)} selected`,
122
+ any: "Any",
123
+ from: "From",
124
+ to: "To",
125
+ min: "Minimum",
126
+ max: "Maximum",
127
+ value: "Value",
128
+ comparison: "Comparison",
129
+ operators: {
130
+ eq: "Equals",
131
+ neq: "Is not",
132
+ lt: "Less than",
133
+ lte: "At most",
134
+ gt: "More than",
135
+ gte: "At least",
136
+ between: "Between",
137
+ },
138
+ },
139
+ combobox: {
140
+ trigger: "Show options",
141
+ clear: "Clear",
142
+ remove: (label) => `Remove ${label}`,
143
+ error: "Couldn't load options",
144
+ empty: (query) => (query === "" ? "No options" : `Nothing matches “${query}”`),
145
+ count: (value, hasMore, locale) => `${count(value, locale)}${hasMore ? "+" : ""} ${value === 1 ? "option" : "options"}`,
146
+ },
147
+ files: { list: "Files", remove: (name) => `Remove ${name}`, rejected: (name) => `${name} can't be added` },
148
+ date: {
149
+ clear: "Clear date",
150
+ previousMonth: "Previous month",
151
+ nextMonth: "Next month",
152
+ start: "Start date",
153
+ end: "End date",
154
+ },
155
+ time: "Time",
156
+ colorValue: "Colour value",
157
+ },
158
+ issues: () => undefined,
159
+ missingRecord: (id) => `No record with the id ${id}`,
160
+ addRow: "Add row",
161
+ removeRow: (row) => `Remove row ${String(row)}`,
162
+ invalidDuration: "Enter a duration, like 1:30",
163
+ errors: {
164
+ network: "Couldn't reach the server. Check your connection and try again.",
165
+ timeout: "The server took too long to answer. Try again.",
166
+ unauthorized: "Sign in to continue.",
167
+ "session-expired": "Your session has expired. Sign in again.",
168
+ forbidden: "You don't have permission to do this.",
169
+ "not-found": "It doesn't exist anymore.",
170
+ conflict: "Someone changed this in the meantime. Review it and try again.",
171
+ validation: "Check the highlighted fields.",
172
+ "rate-limited": "Too many requests. Wait a moment and try again.",
173
+ server: "The server ran into a problem. Try again later.",
174
+ unknown: "Something went wrong.",
175
+ aborted: "Cancelled.",
176
+ },
177
+ bulkResult: (succeeded, failed, locale) => `${count(succeeded, locale)} done, ${count(failed, locale)} failed`,
178
+ retryFailed: (value, locale) => `Retry failed (${count(value, locale)})`,
179
+ };
180
+ const several = (value, one, other) => (value === 1 ? one : other);
181
+ function issueTextEs({ code, params }) {
182
+ switch (code) {
183
+ case "required":
184
+ return "Este campo es obligatorio.";
185
+ case "minLength":
186
+ return `Escribe al menos ${String(params.min)} ${several(params.min, "carácter", "caracteres")}.`;
187
+ case "maxLength":
188
+ return `Escribe como máximo ${String(params.max)} ${several(params.max, "carácter", "caracteres")}.`;
189
+ case "minItems":
190
+ return `Elige al menos ${String(params.min)}.`;
191
+ case "maxItems":
192
+ return `Elige como máximo ${String(params.max)}.`;
193
+ case "min":
194
+ return `Introduce ${String(params.min)} o más.`;
195
+ case "max":
196
+ return `Introduce ${String(params.max)} o menos.`;
197
+ case "email":
198
+ return "Introduce un correo electrónico válido.";
199
+ case "url":
200
+ return "Introduce una URL válida.";
201
+ case "pattern":
202
+ return "Usa el formato indicado.";
203
+ case "invalid":
204
+ return "Este valor no es válido.";
205
+ default:
206
+ return undefined;
207
+ }
208
+ }
209
+ export const dataLabelsEs = {
210
+ create: (one) => `Nuevo ${one.toLocaleLowerCase()}`,
211
+ edit: "Editar",
212
+ editRecord: (title) => `Editar ${title}`,
213
+ remove: "Eliminar",
214
+ restore: "Restaurar",
215
+ save: "Guardar",
216
+ cancel: "Cancelar",
217
+ undo: "Deshacer",
218
+ open: "Abrir",
219
+ back: "Volver",
220
+ retry: "Reintentar",
221
+ records: (other) => `Registros de ${other.toLocaleLowerCase()}`,
222
+ listTool: (other) => `Lista de ${other.toLocaleLowerCase()}`,
223
+ removeRecords: (other) => `Borrar ${other.toLocaleLowerCase()}`,
224
+ rowActions: (title) => `Acciones de ${title}`,
225
+ quickCreate: (one) => `Alta rápida de ${one.toLocaleLowerCase()}`,
226
+ createOption: (text) => `Crear «${text}»`,
227
+ creatingOption: (text) => `Creando «${text}»…`,
228
+ empty: (other) => `No hay ${other.toLocaleLowerCase()}`,
229
+ errorTitle: (other) => `No se han podido cargar los ${other.toLocaleLowerCase()}`,
230
+ notFound: (one) => `Este ${one.toLocaleLowerCase()} no existe`,
231
+ forbidden: (one) => `No tienes permiso para ver este ${one.toLocaleLowerCase()}`,
232
+ notAllowed: "No tienes permiso",
233
+ forbiddenPage: "No tienes acceso a esta página",
234
+ newRows: (value, locale) => `Mostrar ${count(value, locale)} ${value === 1 ? "fila nueva" : "filas nuevas"}`,
235
+ confirm: "Confirmar",
236
+ ok: "Aceptar",
237
+ range: ({ from, to, total, estimate }, locale) => {
238
+ const shown = `Mostrando ${count(from, locale)}–${count(to, locale)}`;
239
+ if (total === undefined)
240
+ return shown;
241
+ return `${shown} de ${estimate === true ? "unos " : ""}${count(total, locale)}`;
242
+ },
243
+ loading: "Cargando…",
244
+ search: (other) => `Buscar ${other.toLocaleLowerCase()}`,
245
+ filters: (other) => `Filtros de ${other.toLocaleLowerCase()}`,
246
+ pageSize: "Filas por página",
247
+ addFilter: "Añadir filtro",
248
+ resetFilters: "Quitar filtros",
249
+ removeFilter: (field) => `Quitar el filtro ${field}`,
250
+ previousPage: "Página anterior",
251
+ nextPage: "Página siguiente",
252
+ page: (page) => `Página ${String(page)}`,
253
+ pagination: (other) => `Páginas de ${other.toLocaleLowerCase()}`,
254
+ loadMore: "Cargar más",
255
+ showDeleted: "Ver eliminados",
256
+ columns: "Columnas",
257
+ views: (other) => `Vistas de ${other.toLocaleLowerCase()}`,
258
+ allRows: "Todos",
259
+ saveView: "Guardar vista",
260
+ viewName: "Nombre de la vista",
261
+ removeView: (label) => `Eliminar la vista ${label}`,
262
+ removeViews: (other) => `Eliminar vistas de ${other.toLocaleLowerCase()}`,
263
+ confirmRemoveView: (label) => `¿Eliminar la vista ${label}?`,
264
+ viewOptions: (label) => `Opciones de la vista ${label}`,
265
+ viewModified: "Modificada",
266
+ saveViewChanges: "Guardar cambios",
267
+ renameView: "Cambiar nombre",
268
+ defaultView: "Por defecto",
269
+ setDefaultView: "Usar por defecto",
270
+ unsetDefaultView: "Dejar de usar por defecto",
271
+ onlyThisBrowser: "Solo en este navegador",
272
+ selected: (value, locale) => `${count(value, locale)} seleccionados`,
273
+ selectAllMatching: (value, other, locale) => `Seleccionar los ${count(value, locale)} ${other.toLocaleLowerCase()}`,
274
+ allMatchingSelected: (value, other, locale) => `Seleccionados los ${count(value, locale)} ${other.toLocaleLowerCase()} que cumplen el filtro`,
275
+ clearSelection: "Quitar la selección",
276
+ exportCsv: "Exportar CSV",
277
+ importCsv: "Importar CSV",
278
+ importTitle: (other) => `Importar ${other.toLocaleLowerCase()}`,
279
+ importTool: (other) => `Importación de ${other.toLocaleLowerCase()}`,
280
+ importNoRows: "El fichero no tiene filas bajo la cabecera.",
281
+ columnField: (column) => `Campo para ${column}`,
282
+ skipColumn: "No importar",
283
+ next: "Siguiente",
284
+ close: "Cerrar",
285
+ importReady: (valid, invalid, locale) => `${count(valid, locale)} ${valid === 1 ? "fila lista" : "filas listas"}, ${count(invalid, locale)} con errores`,
286
+ importRows: (value, locale) => `Importar ${count(value, locale)} ${value === 1 ? "fila" : "filas"}`,
287
+ downloadErrors: "Descargar las filas con errores",
288
+ importing: (done, total, locale) => `Importadas ${count(done, locale)} de ${count(total, locale)}`,
289
+ stop: "Detener",
290
+ importSummary: ({ created, updated, failed, cancelled }, locale) => `${cancelled ? "Detenida. " : ""}${count(created, locale)} creadas, ${count(updated, locale)} actualizadas, ${count(failed, locale)} con error.`,
291
+ line: "Fila",
292
+ errorColumn: "Error",
293
+ exportTooLarge: (value, limit, locale) => `${count(value, locale)} filas superan el límite de ${count(limit, locale)} de una exportación en el navegador`,
294
+ confirmRemove: (target) => `¿Eliminar ${target}?`,
295
+ confirmRemoveDescription: "No se puede deshacer.",
296
+ removeAgentConfirm: (target) => `Elimina ${target}`,
297
+ removed: (value, other, locale) => `${count(value, locale)} ${other.toLocaleLowerCase()} eliminados`,
298
+ created: (title) => `${title} creado`,
299
+ saved: (title) => `${title} guardado`,
300
+ restored: (value, locale) => `${count(value, locale)} restaurados`,
301
+ failed: "Algo ha fallado",
302
+ unsavedChanges: "¿Descartar los cambios sin guardar?",
303
+ discard: "Descartar",
304
+ keepEditing: "Seguir editando",
305
+ draftFound: (date, locale) => `Tienes cambios sin guardar del ${day(date, locale)}.`,
306
+ draft: (title) => `Borrador de ${title.toLocaleLowerCase()}`,
307
+ restoreDraft: "Recuperar",
308
+ discardDraft: "Descartar",
309
+ favorites: "Favoritos",
310
+ recents: "Recientes",
311
+ pin: (label) => `Fijar ${label}`,
312
+ unpin: (label) => `Quitar ${label} de favoritos`,
313
+ goTo: "Ir a",
314
+ pages: "Páginas",
315
+ actions: "Acciones",
316
+ breadcrumb: "Migas de pan",
317
+ audit: { createdAt: "Alta", createdBy: "Creado por", updatedAt: "Modificado", updatedBy: "Modificado por" },
318
+ yes: "Sí",
319
+ no: "No",
320
+ notSet: "Sin valor",
321
+ dropFile: "Suelta un archivo aquí",
322
+ browseFiles: "Elegir archivos",
323
+ controls: {
324
+ refreshing: "Actualizando",
325
+ filters: {
326
+ chip: (field, summary) => (summary === "" ? field : `${field}: ${summary}`),
327
+ selected: (value, locale) => `${count(value, locale)} seleccionados`,
328
+ any: "Cualquiera",
329
+ from: "Desde",
330
+ to: "Hasta",
331
+ min: "Mínimo",
332
+ max: "Máximo",
333
+ value: "Valor",
334
+ comparison: "Comparación",
335
+ operators: {
336
+ eq: "Igual a",
337
+ neq: "Distinto de",
338
+ lt: "Menos de",
339
+ lte: "Como mucho",
340
+ gt: "Más de",
341
+ gte: "Como mínimo",
342
+ between: "Entre",
343
+ },
344
+ },
345
+ combobox: {
346
+ trigger: "Mostrar opciones",
347
+ clear: "Borrar",
348
+ remove: (label) => `Quitar ${label}`,
349
+ error: "No se han podido cargar las opciones",
350
+ empty: (query) => (query === "" ? "No hay opciones" : `Nada coincide con «${query}»`),
351
+ count: (value, hasMore, locale) => `${count(value, locale)}${hasMore ? "+" : ""} ${value === 1 ? "opción" : "opciones"}`,
352
+ },
353
+ files: { list: "Archivos", remove: (name) => `Quitar ${name}`, rejected: (name) => `No se puede añadir ${name}` },
354
+ date: {
355
+ clear: "Borrar la fecha",
356
+ previousMonth: "Mes anterior",
357
+ nextMonth: "Mes siguiente",
358
+ start: "Fecha de inicio",
359
+ end: "Fecha de fin",
360
+ },
361
+ time: "Hora",
362
+ colorValue: "Valor del color",
363
+ },
364
+ issues: issueTextEs,
365
+ missingRecord: (id) => `No hay ningún registro con el id ${id}`,
366
+ addRow: "Añadir fila",
367
+ removeRow: (row) => `Quitar la fila ${String(row)}`,
368
+ invalidDuration: "Escribe una duración, como 1:30",
369
+ errors: {
370
+ network: "No se ha podido conectar con el servidor. Comprueba la conexión y vuelve a intentarlo.",
371
+ timeout: "El servidor ha tardado demasiado en responder. Vuelve a intentarlo.",
372
+ unauthorized: "Inicia sesión para continuar.",
373
+ "session-expired": "Tu sesión ha caducado. Vuelve a iniciar sesión.",
374
+ forbidden: "No tienes permiso para hacer esto.",
375
+ "not-found": "Ya no existe.",
376
+ conflict: "Alguien lo ha cambiado mientras tanto. Revísalo y vuelve a intentarlo.",
377
+ validation: "Revisa los campos marcados.",
378
+ "rate-limited": "Demasiadas peticiones. Espera un momento y vuelve a intentarlo.",
379
+ server: "El servidor ha tenido un problema. Vuelve a intentarlo más tarde.",
380
+ unknown: "Algo ha fallado.",
381
+ aborted: "Cancelado.",
382
+ },
383
+ bulkResult: (succeeded, failed, locale) => `${count(succeeded, locale)} correctos, ${count(failed, locale)} con error`,
384
+ retryFailed: (value, locale) => `Reintentar los fallidos (${count(value, locale)})`,
385
+ };
@@ -0,0 +1,52 @@
1
+ import { ErrorReason, ServiceErrorKind } from "./constants.js";
2
+ export type ServiceFieldError = {
3
+ path: string;
4
+ message: string;
5
+ code?: string;
6
+ };
7
+ export type ServiceError = {
8
+ kind: ServiceErrorKind;
9
+ message: string;
10
+ retryable: boolean;
11
+ fields?: readonly ServiceFieldError[];
12
+ current?: unknown;
13
+ status?: number;
14
+ cause?: unknown;
15
+ /** Why it failed, when the transport says more than `kind`: `session-expired`, `rate-limited`, `timeout`. */
16
+ reason?: ErrorReason;
17
+ /** The backend's own stable code (`card_declined`), which `defineErrors({ codes })` words and classifies. */
18
+ code?: string;
19
+ };
20
+ export declare function isServiceError(value: unknown): value is ServiceError;
21
+ /**
22
+ * A `ServiceError` you can throw: services and adapters reject with it, so `toServiceError` gets the same object
23
+ * back, and `status` and `retryable` stay readable by retry rules (`isTransientError` from `server-data`).
24
+ */
25
+ export declare class ServiceFailure extends Error {
26
+ name: string;
27
+ readonly error: ServiceError;
28
+ readonly kind: ServiceErrorKind;
29
+ readonly retryable: boolean;
30
+ readonly status: number | undefined;
31
+ readonly fields: readonly ServiceFieldError[] | undefined;
32
+ constructor(error: ServiceError);
33
+ }
34
+ export declare function serviceError(kind: ServiceErrorKind, message: string, extra?: Partial<Omit<ServiceError, "kind" | "message">>): ServiceError;
35
+ export declare function kindOfStatus(status: number): ServiceErrorKind;
36
+ export declare function isErrorReason(value: unknown): value is ErrorReason;
37
+ /** Its `reason`, or the one its status and kind tell: a 401 is `unauthorized`, a 429 `rate-limited`. */
38
+ export declare function reasonOf(error: ServiceError): ErrorReason;
39
+ /**
40
+ * Field errors from the shapes servers send: Spring's `errors`/`fieldErrors` (`field`, `defaultMessage`) and
41
+ * constraint violations (`propertyPath`), RFC 9457
42
+ * `invalid-params` or `violations`, JSON:API `errors[].source.pointer`, and `{ fieldErrors: { name: message } }`.
43
+ */
44
+ export declare function fieldErrorsOf(body: unknown): ServiceFieldError[] | undefined;
45
+ export declare function httpServiceError(status: number, body: unknown, statusText?: string): ServiceError;
46
+ export declare function problemDetailError(response: Response): Promise<ServiceFailure>;
47
+ /**
48
+ * Normalizes anything a service threw: a `ServiceFailure` or `ServiceError` as it is, an abort `aborted`, a timeout
49
+ * and fetch's `TypeError` `network`, an HTTP `status` by status (`kindOfStatus`), anything else `server` with the
50
+ * `unknown` reason.
51
+ */
52
+ export declare function toServiceError(error: unknown): ServiceError;