@gzl10/nexus-sdk 0.12.7 → 0.13.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/dist/chunk-6WVPKBUS.js +364 -0
- package/dist/chunk-JIEVWBDA.js +256 -0
- package/dist/chunk-WZM5DHUI.js +377 -0
- package/dist/collection/index.d.ts +506 -0
- package/dist/collection/index.js +1501 -0
- package/dist/entity-kPgsCMdR.d.ts +1504 -0
- package/dist/field-CngHXora.d.ts +375 -0
- package/dist/fields/index.d.ts +1305 -0
- package/dist/fields/index.js +58 -0
- package/dist/index.d.ts +387 -2302
- package/dist/index.js +25 -69
- package/dist/masters/index.d.ts +120 -0
- package/dist/masters/index.js +689 -0
- package/package.json +23 -2
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Localization (i18n) types and helpers
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Localized string supporting multiple languages.
|
|
6
|
+
* Can be a simple string (single language) or object with language codes.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Simple string (backward compatible)
|
|
10
|
+
* label: 'Users'
|
|
11
|
+
*
|
|
12
|
+
* // Multi-language object
|
|
13
|
+
* label: { en: 'Users', es: 'Usuarios' }
|
|
14
|
+
*/
|
|
15
|
+
type LocalizedString = string | Record<string, string>;
|
|
16
|
+
/**
|
|
17
|
+
* Auth provider information for dynamic login buttons.
|
|
18
|
+
* Plugins register this info so the UI can render buttons without knowing provider details.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* ctx.registerService('google.provider', {
|
|
23
|
+
* getInfo: () => ({
|
|
24
|
+
* code: 'GOOGLE_AUTH',
|
|
25
|
+
* provider: 'google',
|
|
26
|
+
* icon: 'mdi:google',
|
|
27
|
+
* label: { en: 'Sign in with Google', es: 'Iniciar sesión con Google' },
|
|
28
|
+
* color: '#4285F4',
|
|
29
|
+
* authorizeEndpoint: '/api/v1/google/authorize'
|
|
30
|
+
* })
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
interface AuthProviderInfo {
|
|
35
|
+
/** Unique code for this auth method (e.g., 'GOOGLE_AUTH') */
|
|
36
|
+
code: string;
|
|
37
|
+
/** Provider identifier (e.g., 'google', 'github') */
|
|
38
|
+
provider: string;
|
|
39
|
+
/** Iconify icon name (e.g., 'mdi:google') */
|
|
40
|
+
icon: string;
|
|
41
|
+
/** Button label in multiple languages */
|
|
42
|
+
label: LocalizedString;
|
|
43
|
+
/** Brand color for the button (hex) */
|
|
44
|
+
color: string;
|
|
45
|
+
/** Endpoint to start OAuth flow */
|
|
46
|
+
authorizeEndpoint: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Service interface for auth providers.
|
|
50
|
+
* Plugins implement this to expose their button info.
|
|
51
|
+
*/
|
|
52
|
+
interface AuthProviderService {
|
|
53
|
+
/** Returns the provider info for UI rendering (null if disabled) */
|
|
54
|
+
getInfo(): Promise<AuthProviderInfo | null>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Resolves a LocalizedString to the appropriate language.
|
|
58
|
+
* Falls back to 'en', then first available, then empty string.
|
|
59
|
+
*
|
|
60
|
+
* @param value - The localized string to resolve
|
|
61
|
+
* @param locale - The target locale (e.g., 'en', 'es')
|
|
62
|
+
* @returns The resolved string for the given locale
|
|
63
|
+
*/
|
|
64
|
+
declare function resolveLocalized(value: LocalizedString | undefined, locale: string): string;
|
|
65
|
+
/**
|
|
66
|
+
* Gets the appropriate label based on count (pluralization).
|
|
67
|
+
* Returns labelPlural for count !== 1, label otherwise.
|
|
68
|
+
*
|
|
69
|
+
* @param label - Singular form
|
|
70
|
+
* @param labelPlural - Plural form (optional, defaults to label)
|
|
71
|
+
* @param count - The count to determine singular/plural
|
|
72
|
+
* @param locale - The target locale
|
|
73
|
+
* @returns The resolved string for the given count and locale
|
|
74
|
+
*/
|
|
75
|
+
declare function getCountLabel(label: LocalizedString | undefined, labelPlural: LocalizedString | undefined, count: number, locale: string): string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Field definition types for entity schemas
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Database column types for Knex migrations.
|
|
83
|
+
*
|
|
84
|
+
* Maps to SQL column types:
|
|
85
|
+
* - `string` → VARCHAR(size) - Use with `db.size` for length
|
|
86
|
+
* - `text` → TEXT - Unlimited length text
|
|
87
|
+
* - `integer` → INTEGER - Whole numbers
|
|
88
|
+
* - `decimal` → DECIMAL(p,s) - Use with `db.precision` for scale
|
|
89
|
+
* - `boolean` → BOOLEAN - True/false values
|
|
90
|
+
* - `date` → DATE - Date without time
|
|
91
|
+
* - `datetime` → DATETIME/TIMESTAMP - Date with time
|
|
92
|
+
* - `json` → JSON/JSONB - Structured data (use for LocalizedString)
|
|
93
|
+
* - `uuid` → UUID - Universally unique identifier
|
|
94
|
+
* - `array` → Virtual only - No database column generated
|
|
95
|
+
*/
|
|
96
|
+
type DbType = 'string' | 'text' | 'integer' | 'decimal' | 'boolean' | 'date' | 'datetime' | 'json' | 'uuid' | 'array';
|
|
97
|
+
/**
|
|
98
|
+
* UI input types that determine which form component renders.
|
|
99
|
+
*
|
|
100
|
+
* **Text inputs:**
|
|
101
|
+
* - `text` → NInput - Single line text
|
|
102
|
+
* - `email` → NInput with email validation
|
|
103
|
+
* - `password` → NInput with password mask
|
|
104
|
+
* - `url` → NInput with URL validation
|
|
105
|
+
* - `tel` → NInput for phone numbers
|
|
106
|
+
*
|
|
107
|
+
* **Numeric inputs:**
|
|
108
|
+
* - `number` → NInputNumber - Integer values
|
|
109
|
+
* - `decimal` → NInputNumber with decimal precision
|
|
110
|
+
*
|
|
111
|
+
* **Rich text:**
|
|
112
|
+
* - `textarea` → NInput multiline
|
|
113
|
+
* - `markdown` → MarkdownInput with preview
|
|
114
|
+
* - `json` → JsonInput with syntax highlighting
|
|
115
|
+
*
|
|
116
|
+
* **Selection:**
|
|
117
|
+
* - `select` → NSelect - Single selection dropdown
|
|
118
|
+
* - `multiselect` → NSelect with multiple - Multiple selection
|
|
119
|
+
* - `autocomplete` → NAutoComplete - Text input with suggestions
|
|
120
|
+
* - `transfer` → NTransfer - Dual list selection
|
|
121
|
+
* - `tags` → NSelect with tags - Free-form tags input
|
|
122
|
+
*
|
|
123
|
+
* **Boolean:**
|
|
124
|
+
* - `checkbox` → NCheckbox
|
|
125
|
+
* - `switch` → NSwitch - Toggle switch
|
|
126
|
+
*
|
|
127
|
+
* **Date/Time:**
|
|
128
|
+
* - `date` → NDatePicker - Date only
|
|
129
|
+
* - `datetime` → NDatePicker with time
|
|
130
|
+
*
|
|
131
|
+
* **Files:**
|
|
132
|
+
* - `file` → FileInput - Single file upload
|
|
133
|
+
* - `multifile` → MultiFileInput - Multiple files
|
|
134
|
+
* - `image` → ImageInput - Single image with preview
|
|
135
|
+
* - `multiimage` → MultiImageInput - Image gallery
|
|
136
|
+
*
|
|
137
|
+
* **Other:**
|
|
138
|
+
* - `icon` → IconPicker - Icon selection from library
|
|
139
|
+
*/
|
|
140
|
+
type InputType = 'text' | 'email' | 'password' | 'url' | 'tel' | 'number' | 'decimal' | 'rate' | 'textarea' | 'markdown' | 'json' | 'select' | 'multiselect' | 'autocomplete' | 'transfer' | 'tags' | 'radio' | 'checkbox' | 'switch' | 'date' | 'datetime' | 'file' | 'multifile' | 'image' | 'multiimage' | 'icon' | 'color' | 'otp' | 'qr' | 'cron' | 'uuid' | 'slug' | 'tree' | 'time' | 'range' | 'hidden' | 'code';
|
|
141
|
+
/**
|
|
142
|
+
* Database column configuration for Knex migrations.
|
|
143
|
+
*/
|
|
144
|
+
interface FieldDbConfig {
|
|
145
|
+
/** Column type for the database */
|
|
146
|
+
type: DbType;
|
|
147
|
+
/** If true, no database column is created (for computed/virtual fields) */
|
|
148
|
+
virtual?: boolean;
|
|
149
|
+
/** String length for VARCHAR columns */
|
|
150
|
+
size?: number;
|
|
151
|
+
/** Precision and scale for DECIMAL: [precision, scale] e.g., [10, 2] */
|
|
152
|
+
precision?: [number, number];
|
|
153
|
+
/** Allow NULL values. Inferred from `required` if not specified */
|
|
154
|
+
nullable?: boolean;
|
|
155
|
+
/** Create unique constraint on this column */
|
|
156
|
+
unique?: boolean;
|
|
157
|
+
/** Static default value for the column */
|
|
158
|
+
default?: unknown;
|
|
159
|
+
/** Database function for default value: 'now' for timestamps, 'uuid' for auto-generated UUIDs */
|
|
160
|
+
defaultFn?: 'now' | 'uuid';
|
|
161
|
+
/** Create index on this column for faster queries */
|
|
162
|
+
index?: boolean;
|
|
163
|
+
/** Auto-increment for integer primary keys */
|
|
164
|
+
autoIncrement?: boolean;
|
|
165
|
+
/** Mark as primary key */
|
|
166
|
+
primary?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* ID generation strategy for primary key fields.
|
|
169
|
+
* Used by BaseEntityService to generate IDs at runtime.
|
|
170
|
+
* - 'ulid': Time-sortable, 26 chars (default)
|
|
171
|
+
* - 'uuid': Standard UUID v4, 36 chars
|
|
172
|
+
* - 'nanoid': URL-safe, 21 chars
|
|
173
|
+
* - 'cuid2': Collision-resistant, 24 chars
|
|
174
|
+
* - 'auto': Database auto-increment
|
|
175
|
+
* - 'custom': User-provided ID
|
|
176
|
+
* - 'pattern': Sequential with pattern (e.g., TP-2025-000001)
|
|
177
|
+
*/
|
|
178
|
+
idType?: 'ulid' | 'uuid' | 'nanoid' | 'cuid2' | 'auto' | 'custom' | 'pattern';
|
|
179
|
+
/**
|
|
180
|
+
* Pattern configuration for 'pattern' ID type.
|
|
181
|
+
* Required when idType is 'pattern'.
|
|
182
|
+
*/
|
|
183
|
+
patternConfig?: {
|
|
184
|
+
/** Pattern template with tokens: {prefix}, {year}, {seq:N}, etc. */
|
|
185
|
+
pattern: string;
|
|
186
|
+
/** Static prefix for {prefix} token */
|
|
187
|
+
prefix?: string;
|
|
188
|
+
/** Static suffix for {suffix} token */
|
|
189
|
+
suffix?: string;
|
|
190
|
+
/** When to reset sequence: 'never' | 'year' | 'month' | 'day' */
|
|
191
|
+
resetOn?: 'never' | 'year' | 'month' | 'day';
|
|
192
|
+
/** Starting number for sequence (default: 1) */
|
|
193
|
+
startAt?: number;
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Foreign key relationship configuration.
|
|
198
|
+
*/
|
|
199
|
+
interface FieldRelation {
|
|
200
|
+
/** Target table name */
|
|
201
|
+
table: string;
|
|
202
|
+
/** Target column name (default: 'id') */
|
|
203
|
+
column?: string;
|
|
204
|
+
/** Action when referenced row is deleted */
|
|
205
|
+
onDelete?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'NO ACTION';
|
|
206
|
+
/** Action when referenced row's key is updated */
|
|
207
|
+
onUpdate?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'NO ACTION';
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Validation rules for runtime and form validation.
|
|
211
|
+
*/
|
|
212
|
+
interface FieldValidationConfig {
|
|
213
|
+
/** Minimum value (numbers) or minimum length (strings) */
|
|
214
|
+
min?: number;
|
|
215
|
+
/** Maximum value (numbers) or maximum length (strings) */
|
|
216
|
+
max?: number;
|
|
217
|
+
/** Regular expression pattern for validation */
|
|
218
|
+
pattern?: string;
|
|
219
|
+
/** Allowed values (creates enum constraint) */
|
|
220
|
+
enum?: string[];
|
|
221
|
+
/** Format hint for OpenAPI schema (e.g., 'email', 'uri', 'date-time') */
|
|
222
|
+
format?: 'email' | 'uri' | 'date' | 'date-time' | 'uuid' | string;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Configuration for select, multiselect, and dropdown fields.
|
|
226
|
+
*/
|
|
227
|
+
interface FieldOptions {
|
|
228
|
+
/** API endpoint for dynamic options (GET request) */
|
|
229
|
+
endpoint?: string;
|
|
230
|
+
/** Field to use as option value (default: 'id') */
|
|
231
|
+
valueField?: string;
|
|
232
|
+
/** Field to use as option label (default: 'name') */
|
|
233
|
+
labelField?: string;
|
|
234
|
+
/** Static list of options */
|
|
235
|
+
static?: Array<{
|
|
236
|
+
value: string;
|
|
237
|
+
label: LocalizedString;
|
|
238
|
+
icon?: string;
|
|
239
|
+
}>;
|
|
240
|
+
/** Allow creating new options on-the-fly (renders combobox) */
|
|
241
|
+
allowCreate?: boolean;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Storage configuration for file and image upload fields.
|
|
245
|
+
*/
|
|
246
|
+
interface FieldStorageConfig {
|
|
247
|
+
/** Accepted MIME types (e.g., 'image/*', 'application/pdf') */
|
|
248
|
+
accept?: string;
|
|
249
|
+
/** Maximum file size in bytes (default: 10MB = 10485760) */
|
|
250
|
+
maxSize?: number;
|
|
251
|
+
/** Maximum number of files for array types (multifile, multiimage) */
|
|
252
|
+
maxFiles?: number;
|
|
253
|
+
/** Folder/prefix in storage bucket (e.g., 'avatars', 'documents/contracts') */
|
|
254
|
+
folder?: string;
|
|
255
|
+
/** Thumbnail sizes to auto-generate for images */
|
|
256
|
+
thumbnails?: Array<{
|
|
257
|
+
width: number;
|
|
258
|
+
height: number;
|
|
259
|
+
}>;
|
|
260
|
+
/** Enable SHA256 hash deduplication */
|
|
261
|
+
dedupe?: boolean;
|
|
262
|
+
/** If true, files are publicly accessible without authentication */
|
|
263
|
+
isPublic?: boolean;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Field metadata for UI behavior and data operations.
|
|
267
|
+
*/
|
|
268
|
+
interface FieldMeta {
|
|
269
|
+
/** Enable sorting by this field in table columns */
|
|
270
|
+
sortable?: boolean;
|
|
271
|
+
/** Include this field in search/filter operations */
|
|
272
|
+
searchable?: boolean;
|
|
273
|
+
/** Include this field in CSV/Excel exports */
|
|
274
|
+
exportable?: boolean;
|
|
275
|
+
/** Mark as audit field (auto-populated with user ID on create/update) */
|
|
276
|
+
auditField?: 'created_by' | 'updated_by';
|
|
277
|
+
/** Show in display components (Table, List, Masonry). Default: true */
|
|
278
|
+
showInDisplay?: boolean;
|
|
279
|
+
/** Show in forms. Use 'create'/'edit' for conditional display. Default: true */
|
|
280
|
+
showInForm?: boolean | 'create' | 'edit';
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Serializable field condition for dynamic visibility/required/disabled.
|
|
284
|
+
* Evaluated in the frontend based on current form data.
|
|
285
|
+
*/
|
|
286
|
+
interface FieldCondition {
|
|
287
|
+
/** Field name to evaluate */
|
|
288
|
+
field: string;
|
|
289
|
+
/** Equal (value === $eq) */
|
|
290
|
+
$eq?: unknown;
|
|
291
|
+
/** Not equal (value !== $ne) */
|
|
292
|
+
$ne?: unknown;
|
|
293
|
+
/** In array (array.includes(value)) */
|
|
294
|
+
$in?: unknown[];
|
|
295
|
+
/** Not in array (!array.includes(value)) */
|
|
296
|
+
$nin?: unknown[];
|
|
297
|
+
/** Is null/undefined/empty (true = is empty, false = is not empty) */
|
|
298
|
+
$isnull?: boolean;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Conditional boolean - can be static, function, or serializable condition.
|
|
302
|
+
*/
|
|
303
|
+
type ConditionalBoolean = boolean | FieldCondition | ((record: Record<string, unknown>) => boolean);
|
|
304
|
+
/**
|
|
305
|
+
* Complete field definition for entity fields.
|
|
306
|
+
*
|
|
307
|
+
* This is the core building block for defining entity schemas in Nexus.
|
|
308
|
+
* Contains all the information needed for:
|
|
309
|
+
* - **UI**: Form inputs, table columns, list displays
|
|
310
|
+
* - **Database**: Knex migrations, column types, constraints
|
|
311
|
+
* - **Validation**: Zod schemas, runtime validation rules
|
|
312
|
+
*/
|
|
313
|
+
interface FieldDefinition {
|
|
314
|
+
/** Human-readable label displayed in forms, tables, and lists */
|
|
315
|
+
label: LocalizedString;
|
|
316
|
+
/** Input type that determines which UI component renders this field */
|
|
317
|
+
input: InputType;
|
|
318
|
+
/** Placeholder text shown in empty input fields */
|
|
319
|
+
placeholder?: LocalizedString;
|
|
320
|
+
/** Help text displayed below the input field */
|
|
321
|
+
hint?: LocalizedString;
|
|
322
|
+
/** Controls field visibility in the UI */
|
|
323
|
+
hidden?: ConditionalBoolean;
|
|
324
|
+
/** Controls whether the field is read-only in forms */
|
|
325
|
+
disabled?: ConditionalBoolean;
|
|
326
|
+
/** Marks the field as required for form validation */
|
|
327
|
+
required?: ConditionalBoolean;
|
|
328
|
+
/** Default value used when creating new records */
|
|
329
|
+
defaultValue?: unknown;
|
|
330
|
+
/** Database column configuration for Knex migrations */
|
|
331
|
+
db?: FieldDbConfig;
|
|
332
|
+
/** Foreign key relationship configuration */
|
|
333
|
+
relation?: FieldRelation;
|
|
334
|
+
/** Validation rules applied during form submission and API requests */
|
|
335
|
+
validation?: FieldValidationConfig;
|
|
336
|
+
/** Configuration for select inputs and relationship dropdowns */
|
|
337
|
+
options?: FieldOptions;
|
|
338
|
+
/** Storage configuration for file and image inputs */
|
|
339
|
+
storage?: FieldStorageConfig;
|
|
340
|
+
/** Additional metadata for categorization and UI organization */
|
|
341
|
+
meta?: FieldMeta;
|
|
342
|
+
/** Additional props passed directly to the form input component */
|
|
343
|
+
inputProps?: Record<string, unknown>;
|
|
344
|
+
/** Additional props passed to display components (table columns, list items) */
|
|
345
|
+
displayProps?: Record<string, unknown>;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Composite table index definition for database migrations.
|
|
349
|
+
*/
|
|
350
|
+
interface EntityIndex {
|
|
351
|
+
/** Column names to include in the composite index */
|
|
352
|
+
columns: string[];
|
|
353
|
+
/** Create unique constraint on the column combination */
|
|
354
|
+
unique?: boolean;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Creates options configuration for a reference field pointing to a reference entity.
|
|
358
|
+
* When entity is omitted, the endpoint is `/{module}` (entity mounted at module root).
|
|
359
|
+
*/
|
|
360
|
+
declare function refOptions(module: string, entityOrLabel?: string, labelField?: string): {
|
|
361
|
+
endpoint: string;
|
|
362
|
+
valueField: string;
|
|
363
|
+
labelField: string;
|
|
364
|
+
};
|
|
365
|
+
/**
|
|
366
|
+
* Creates a field definition that references a master table.
|
|
367
|
+
*/
|
|
368
|
+
declare function refMaster(master: string, options?: {
|
|
369
|
+
default?: string;
|
|
370
|
+
label?: LocalizedString;
|
|
371
|
+
required?: boolean;
|
|
372
|
+
input?: 'select' | 'autocomplete';
|
|
373
|
+
}): FieldDefinition;
|
|
374
|
+
|
|
375
|
+
export { type AuthProviderInfo as A, type ConditionalBoolean as C, type DbType as D, type EntityIndex as E, type FieldCondition as F, type InputType as I, type LocalizedString as L, type FieldMeta as a, type AuthProviderService as b, type FieldDbConfig as c, type FieldRelation as d, type FieldValidationConfig as e, type FieldOptions as f, getCountLabel as g, type FieldStorageConfig as h, type FieldDefinition as i, refOptions as j, refMaster as k, resolveLocalized as r };
|