@nhtio/lucid-resourceful 0.1.0-master-1570171e → 0.1.0-master-3ec631a4

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 (47) hide show
  1. package/{definitions-DgI468dW.cjs → data_type_schemas-BqeljaQB.cjs} +21 -177
  2. package/data_type_schemas-BqeljaQB.cjs.map +1 -0
  3. package/data_type_schemas-Cpco9Zba.js +225 -0
  4. package/data_type_schemas-Cpco9Zba.js.map +1 -0
  5. package/{decorator_utils-U_rZo8tv.cjs → decorator_utils-DSvYjLYD.cjs} +204 -60
  6. package/decorator_utils-DSvYjLYD.cjs.map +1 -0
  7. package/{decorator_utils-YSb1EGJ6.js → decorator_utils-gyymixlk.js} +207 -65
  8. package/decorator_utils-gyymixlk.js.map +1 -0
  9. package/definitions-DcB6B_4d.js +174 -0
  10. package/definitions-DcB6B_4d.js.map +1 -0
  11. package/definitions-DjQRkCeH.cjs +173 -0
  12. package/definitions-DjQRkCeH.cjs.map +1 -0
  13. package/definitions.cjs +1 -1
  14. package/definitions.mjs +11 -11
  15. package/{errors-B1rr67uM.js → errors-C-x5_jRE.js} +162 -27
  16. package/errors-C-x5_jRE.js.map +1 -0
  17. package/{errors-D8jb9VxY.cjs → errors-CNwuNhBV.cjs} +138 -5
  18. package/errors-CNwuNhBV.cjs.map +1 -0
  19. package/errors.cjs +5 -1
  20. package/errors.cjs.map +1 -1
  21. package/errors.d.ts +24 -2
  22. package/errors.mjs +19 -15
  23. package/index.cjs +1471 -771
  24. package/index.cjs.map +1 -1
  25. package/index.mjs +1716 -1016
  26. package/index.mjs.map +1 -1
  27. package/joi.cjs +1854 -3368
  28. package/joi.cjs.map +1 -1
  29. package/joi.mjs +1857 -3371
  30. package/joi.mjs.map +1 -1
  31. package/package.json +1 -1
  32. package/private/decorators.d.ts +8 -8
  33. package/private/lucene_to_lucid_translator.d.ts +21 -175
  34. package/private/mixin.d.ts +68 -5
  35. package/private/services/open_api_schema_service.d.ts +111 -0
  36. package/private/type_guards.d.ts +62 -0
  37. package/private/types.d.ts +1 -1
  38. package/private/utils.d.ts +24 -0
  39. package/utils.cjs +1 -1
  40. package/utils.mjs +2 -2
  41. package/decorator_utils-U_rZo8tv.cjs.map +0 -1
  42. package/decorator_utils-YSb1EGJ6.js.map +0 -1
  43. package/definitions-B88XBTUF.js +0 -381
  44. package/definitions-B88XBTUF.js.map +0 -1
  45. package/definitions-DgI468dW.cjs.map +0 -1
  46. package/errors-B1rr67uM.js.map +0 -1
  47. package/errors-D8jb9VxY.cjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nhtio/lucid-resourceful",
3
- "version": "0.1.0-master-1570171e",
3
+ "version": "0.1.0-master-3ec631a4",
4
4
  "description": "A decorator-driven AdonisJS library that lets you annotate Lucid ORM models with metadata to automatically generate CRUD controllers, validation rules, OpenAPI schemas, and a unified query interface.",
5
5
  "keywords": [],
6
6
  "author": "Jak Giveon <jak@nht.io>",
@@ -48,7 +48,7 @@ export type RelatedModelRelationOptions<RelatedModel extends LucidModel> = Relat
48
48
  * ```
49
49
  */
50
50
  export type HasManyThroughRelationOptions<RelatedModel extends LucidModel> = Omit<ThroughRelationOptions<RelatedModel, LucidModel, HasManyThrough<RelatedModel>>, 'throughModel'>;
51
- export type DataTypeColumnOptions = Omit<ColumnOptions, 'prepare' | 'consume'>;
51
+ export type DataTypeColumnOptions = ColumnOptions;
52
52
  export type DataTypeComputedOptions = Omit<ComputedOptions, 'prepare' | 'consume'>;
53
53
  /**
54
54
  * Decorator to define a resourceful column on a Lucid model property.
@@ -69,15 +69,15 @@ export type DataTypeComputedOptions = Omit<ComputedOptions, 'prepare' | 'consume
69
69
  */
70
70
  export declare function resourcefulColumn<Schema extends AnySchema = ResourcefulPropertySchema>(options?: Partial<ColumnOptions> & Partial<ResourcefulColumnDefinition<Schema>>): (target: any, propertyKey: string) => void;
71
71
  export declare namespace resourcefulColumn {
72
- var string: (options?: Partial<DataTypeColumnOptions> & Partial<ResourcefulColumnDefinition<StringSchema>>) => (target: any, propertyKey: string) => void;
72
+ var string: (options?: Partial<ColumnOptions> & Partial<ResourcefulColumnDefinition<StringSchema>>) => (target: any, propertyKey: string) => void;
73
73
  var date: (options?: Partial<DateColumnOptions> & Partial<ResourcefulColumnDefinition<DateSchema>>) => (target: any, propertyKey: string) => void;
74
74
  var dateTime: (options?: Partial<DateColumnOptions> & Partial<ResourcefulColumnDefinition<DateSchema>>) => (target: any, propertyKey: string) => void;
75
- var binary: (options?: Partial<DataTypeColumnOptions> & Partial<ResourcefulColumnDefinition<BinarySchema>>) => (target: any, propertyKey: string) => void;
76
- var number: (options?: Partial<DataTypeColumnOptions> & Partial<ResourcefulColumnDefinition<NumberSchema>>) => (target: any, propertyKey: string) => void;
77
- var integer: (options?: Partial<DataTypeColumnOptions> & Partial<ResourcefulColumnDefinition<NumberSchema>>) => (target: any, propertyKey: string) => void;
78
- var bigint: (options?: Partial<DataTypeColumnOptions> & Partial<ResourcefulColumnDefinition<NumberSchema>>) => (target: any, propertyKey: string) => void;
79
- var unsignedint: (options?: Partial<DataTypeColumnOptions> & Partial<ResourcefulColumnDefinition<NumberSchema>>) => (target: any, propertyKey: string) => void;
80
- var boolean: (options?: Partial<DataTypeColumnOptions> & Partial<ResourcefulColumnDefinition<BooleanSchema>>) => (target: any, propertyKey: string) => void;
75
+ var binary: (options?: Partial<ColumnOptions> & Partial<ResourcefulColumnDefinition<BinarySchema>>) => (target: any, propertyKey: string) => void;
76
+ var number: (options?: Partial<ColumnOptions> & Partial<ResourcefulColumnDefinition<NumberSchema>>) => (target: any, propertyKey: string) => void;
77
+ var integer: (options?: Partial<ColumnOptions> & Partial<ResourcefulColumnDefinition<NumberSchema>>) => (target: any, propertyKey: string) => void;
78
+ var bigint: (options?: Partial<ColumnOptions> & Partial<ResourcefulColumnDefinition<NumberSchema>>) => (target: any, propertyKey: string) => void;
79
+ var unsignedint: (options?: Partial<ColumnOptions> & Partial<ResourcefulColumnDefinition<NumberSchema>>) => (target: any, propertyKey: string) => void;
80
+ var boolean: (options?: Partial<ColumnOptions> & Partial<ResourcefulColumnDefinition<BooleanSchema>>) => (target: any, propertyKey: string) => void;
81
81
  var object: (options?: Partial<ColumnOptions> & Partial<ResourcefulColumnDefinition<ObjectSchema>>) => (target: any, propertyKey: string) => void;
82
82
  var array: (options?: Partial<ColumnOptions> & Partial<ResourcefulColumnDefinition<ArraySchema>>) => (target: any, propertyKey: string) => void;
83
83
  }
@@ -1,5 +1,5 @@
1
- import type { ModelKeysContract } from '@adonisjs/lucid/types/model';
2
1
  import type { QueryClientContract } from '@adonisjs/lucid/types/database';
2
+ import type { LucidModel, ModelKeysContract } from '@adonisjs/lucid/types/model';
3
3
  import type { DatabaseQueryBuilderContract } from '@adonisjs/lucid/types/querybuilder';
4
4
  import type { ComparisonOperatorToken, EmptyExpression, FieldToken, ImplicitFieldToken, LiteralExpressionToken, LogicalExpressionToken, RangeExpressionToken, RegexExpressionToken, TagToken, UnaryOperatorToken, ParenthesizedExpressionToken, ExpressionToken, ParserAst } from 'liqe';
5
5
  /**
@@ -9,179 +9,24 @@ import type { ComparisonOperatorToken, EmptyExpression, FieldToken, ImplicitFiel
9
9
  */
10
10
  export interface LuceneFilteredDatabaseQueryBuilderContract extends DatabaseQueryBuilderContract {
11
11
  }
12
- /**
13
- * Applies an empty expression AST node to a database query.
14
- * Empty expressions are no-op operations that don't modify the query.
15
- *
16
- * @template T - The result type for the query builder
17
- * @param _ast - The empty expression AST node
18
- * @param _query - The database query builder to modify
19
- * @param _attributesToColumns - Mapping of model attributes to database columns
20
- * @param _primaryKey - The primary key column name
21
- * @param _tableName - The table name
22
- * @param _allowedColumns - Optional array of allowed column names for filtering
23
- */
24
- export declare const applyLuceneEmptyExpressionAst: (_ast: EmptyExpression, _query: LuceneFilteredDatabaseQueryBuilderContract, _attributesToColumns: ModelKeysContract, _primaryKey: string, _tableName: string, _allowedColumns?: string[] | undefined) => void;
25
- /**
26
- * Applies a logical expression AST node (AND/OR) to a database query.
27
- * Handles logical operations between two expressions with proper SQL grouping.
28
- *
29
- * @template T - The result type for the query builder
30
- * @param ast - The logical expression AST node containing left/right operands and operator
31
- * @param query - The database query builder to modify
32
- * @param attributesToColumns - Mapping of model attributes to database columns
33
- * @param primaryKey - The primary key column name
34
- * @param tableName - The table name
35
- * @param allowedColumns - Optional array of allowed column names for filtering
36
- */
37
- export declare const applyLuceneLogicalExpressionAst: (ast: LogicalExpressionToken, query: LuceneFilteredDatabaseQueryBuilderContract, attributesToColumns: ModelKeysContract, primaryKey: string, tableName: string, allowedColumns?: string[] | undefined) => void;
38
- /**
39
- * Applies a parenthesized expression AST node to a database query.
40
- * Maintains logical grouping by wrapping the inner expression in a WHERE clause.
41
- *
42
- * @template T - The result type for the query builder
43
- * @param ast - The parenthesized expression AST node containing the inner expression
44
- * @param query - The database query builder to modify
45
- * @param attributesToColumns - Mapping of model attributes to database columns
46
- * @param primaryKey - The primary key column name
47
- * @param tableName - The table name
48
- * @param allowedColumns - Optional array of allowed column names for filtering
49
- */
50
- export declare const applyLuceneParenthesizedExpressionAst: (ast: ParenthesizedExpressionToken, query: LuceneFilteredDatabaseQueryBuilderContract, attributesToColumns: ModelKeysContract, primaryKey: string, tableName: string, allowedColumns?: string[] | undefined) => void;
51
- /**
52
- * Applies an empty expression to a database query for a specific column.
53
- * Handles queries for null or empty values.
54
- *
55
- * @template T - The result type for the query builder
56
- * @param column - The database column name to query
57
- * @param _expression - The empty expression (unused)
58
- * @param operator - The comparison operator token
59
- * @param query - The database query builder to modify
60
- * @param _attributesToColumns - Mapping of model attributes to database columns (unused)
61
- * @param _primaryKey - The primary key column name (unused)
62
- * @param _tableName - The table name (unused)
63
- * @param allowedColumns - Optional array of allowed column names for filtering
64
- */
65
- export declare const applyLuceneEmptyExpression: (column: string, _expression: EmptyExpression, operator: ComparisonOperatorToken, query: LuceneFilteredDatabaseQueryBuilderContract, _attributesToColumns: ModelKeysContract, _primaryKey: string, _tableName: string, _allowedColumns?: string[] | undefined) => void;
66
- /**
67
- * Applies a literal expression to a database query for a specific column.
68
- * Handles string, boolean, and null values with appropriate SQL operations.
69
- * Supports quote stripping and handles different comparison operators.
70
- *
71
- * @template T - The result type for the query builder
72
- * @param column - The database column name to query
73
- * @param expression - The literal expression containing the value and quote information
74
- * @param operator - The comparison operator token
75
- * @param query - The database query builder to modify
76
- * @param _attributesToColumns - Mapping of model attributes to database columns (unused)
77
- * @param _primaryKey - The primary key column name (unused)
78
- * @param _tableName - The table name (unused)
79
- * @param allowedColumns - Optional array of allowed column names for filtering
80
- */
81
- export declare const applyLuceneLiteralExpression: (column: string, expression: LiteralExpressionToken, operator: ComparisonOperatorToken, query: LuceneFilteredDatabaseQueryBuilderContract, _attributesToColumns: ModelKeysContract, _primaryKey: string, _tableName: string, _allowedColumns?: string[] | undefined) => void;
82
- /**
83
- * Applies a range expression to a database query for a specific column.
84
- * Converts Lucene range syntax to SQL BETWEEN operations with proper inclusive/exclusive handling.
85
- *
86
- * @template T - The result type for the query builder
87
- * @param column - The database column name to query
88
- * @param expression - The range expression containing min/max values and inclusivity flags
89
- * @param operator - The comparison operator token
90
- * @param query - The database query builder to modify
91
- * @param _attributesToColumns - Mapping of model attributes to database columns (unused)
92
- * @param _primaryKey - The primary key column name (unused)
93
- * @param _tableName - The table name (unused)
94
- * @param allowedColumns - Optional array of allowed column names for filtering
95
- */
96
- export declare const applyLuceneRangeExpression: (column: string, expression: RangeExpressionToken, operator: ComparisonOperatorToken, query: LuceneFilteredDatabaseQueryBuilderContract, _attributesToColumns: ModelKeysContract, _primaryKey: string, _tableName: string, _allowedColumns?: string[] | undefined) => void;
97
- /**
98
- * Applies a regex expression to a database query for a specific column.
99
- * Converts regex patterns to SQL LIKE patterns with proper escaping.
100
- * Transforms * to % and ? to _ for SQL pattern matching.
101
- *
102
- * @template T - The result type for the query builder
103
- * @param column - The database column name to query
104
- * @param expression - The regex expression containing the pattern
105
- * @param operator - The comparison operator token
106
- * @param query - The database query builder to modify
107
- * @param _attributesToColumns - Mapping of model attributes to database columns (unused)
108
- * @param _primaryKey - The primary key column name (unused)
109
- * @param _tableName - The table name (unused)
110
- * @param allowedColumns - Optional array of allowed column names for filtering
111
- */
112
- export declare const applyLuceneRegexExpression: (column: string, expression: RegexExpressionToken, operator: ComparisonOperatorToken, query: LuceneFilteredDatabaseQueryBuilderContract, _attributesToColumns: ModelKeysContract, _primaryKey: string, _tableName: string, _allowedColumns?: string[] | undefined) => void;
113
- /**
114
- * Applies an implicit field AST node to a database query.
115
- * Implicit fields use the primary key column when no specific field is specified.
116
- *
117
- * @template T - The result type for the query builder
118
- * @param _field - The implicit field token (unused)
119
- * @param expression - The expression to apply to the primary key column
120
- * @param operator - The comparison operator token
121
- * @param query - The database query builder to modify
122
- * @param attributesToColumns - Mapping of model attributes to database columns
123
- * @param primaryKey - The primary key column name to use for implicit fields
124
- * @param tableName - The table name
125
- * @param allowedColumns - Optional array of allowed column names for filtering
126
- */
127
- export declare const applyLuceneImplicitFieldAst: (_field: ImplicitFieldToken, expression: ExpressionToken, operator: ComparisonOperatorToken | undefined, query: LuceneFilteredDatabaseQueryBuilderContract, attributesToColumns: ModelKeysContract, primaryKey: string, tableName: string, allowedColumns?: string[] | undefined) => void;
128
- /**
129
- * Applies a field AST node to a database query.
130
- * Maps the field name to the corresponding database column and applies the expression.
131
- *
132
- * @template T - The result type for the query builder
133
- * @param field - The field token containing the field name
134
- * @param expression - The expression to apply to the mapped column
135
- * @param operator - The comparison operator token
136
- * @param query - The database query builder to modify
137
- * @param attributesToColumns - Mapping of model attributes to database columns
138
- * @param primaryKey - The primary key column name
139
- * @param tableName - The table name
140
- * @param allowedColumns - Optional array of allowed column names for filtering
141
- */
142
- export declare const applyLuceneFieldAst: (field: FieldToken, expression: ExpressionToken, operator: ComparisonOperatorToken, query: LuceneFilteredDatabaseQueryBuilderContract, attributesToColumns: ModelKeysContract, primaryKey: string, tableName: string, allowedColumns?: string[] | undefined) => void;
143
- /**
144
- * Applies a tag AST node to a database query.
145
- * Tags represent field:expression pairs in Lucene syntax.
146
- * Delegates to either implicit field or explicit field handlers based on the field type.
147
- *
148
- * @template T - The result type for the query builder
149
- * @param ast - The tag AST node containing field, expression, and operator
150
- * @param query - The database query builder to modify
151
- * @param attributesToColumns - Mapping of model attributes to database columns
152
- * @param primaryKey - The primary key column name
153
- * @param tableName - The table name
154
- * @param allowedColumns - Optional array of allowed column names for filtering
155
- */
156
- export declare const applyLuceneTagAst: (ast: TagToken, query: LuceneFilteredDatabaseQueryBuilderContract, attributesToColumns: ModelKeysContract, primaryKey: string, tableName: string, allowedColumns?: string[] | undefined) => void;
157
- /**
158
- * Applies a unary operator AST node to a database query.
159
- * Handles NOT and negation (-) operators by wrapping the operand in a WHERE NOT clause.
160
- *
161
- * @template T - The result type for the query builder
162
- * @param ast - The unary operator AST node containing operator and operand
163
- * @param query - The database query builder to modify
164
- * @param attributesToColumns - Mapping of model attributes to database columns
165
- * @param primaryKey - The primary key column name
166
- * @param tableName - The table name
167
- * @param allowedColumns - Optional array of allowed column names for filtering
168
- */
169
- export declare const applyLuceneUnaryOperatorAst: (ast: UnaryOperatorToken, query: LuceneFilteredDatabaseQueryBuilderContract, attributesToColumns: ModelKeysContract, primaryKey: string, tableName: string, allowedColumns?: string[] | undefined) => void;
170
- /**
171
- * Applies any Lucene AST node to a database query.
172
- * This is the main dispatcher function that routes different AST node types
173
- * to their appropriate handler functions.
174
- *
175
- * @template T - The result type for the query builder
176
- * @param ast - The AST node to apply
177
- * @param query - The database query builder to modify
178
- * @param attributesToColumns - Mapping of model attributes to database columns
179
- * @param primaryKey - The primary key column name
180
- * @param tableName - The table name
181
- * @param allowedColumns - Optional array of allowed column names for filtering
182
- * @param throwOnInvalidType - Whether to throw an error for unrecognized AST node types
183
- */
184
- export declare const applyLuceneAst: (ast: ParserAst, query: LuceneFilteredDatabaseQueryBuilderContract, attributesToColumns: ModelKeysContract, primaryKey: string, tableName: string, allowedColumns: string[] | undefined, throwOnInvalidType?: boolean) => void;
12
+ export declare class LuceneLucidQueryBuilder {
13
+ #private;
14
+ constructor(connection: QueryClientContract, query: LuceneFilteredDatabaseQueryBuilderContract, attributesToColumns: ModelKeysContract, primaryKey: string, tableName: string, allowedColumns?: string[] | undefined, model?: LucidModel | undefined);
15
+ applyLuceneAst(ast: ParserAst, query: LuceneFilteredDatabaseQueryBuilderContract, throwOnInvalidType?: boolean): void;
16
+ applyLuceneEmptyExpressionAst(_ast: EmptyExpression, _query: LuceneFilteredDatabaseQueryBuilderContract): void;
17
+ applyLuceneLogicalExpressionAst(ast: LogicalExpressionToken, query: LuceneFilteredDatabaseQueryBuilderContract): void;
18
+ applyLuceneParenthesizedExpressionAst(ast: ParenthesizedExpressionToken, query: LuceneFilteredDatabaseQueryBuilderContract): void;
19
+ applyLuceneUnaryOperatorAst(ast: UnaryOperatorToken, query: LuceneFilteredDatabaseQueryBuilderContract): void;
20
+ applyLuceneTagAst(ast: TagToken, query: LuceneFilteredDatabaseQueryBuilderContract): void;
21
+ applyLuceneImplicitFieldAst(_field: ImplicitFieldToken, expression: ExpressionToken, operator: ComparisonOperatorToken | undefined, query: LuceneFilteredDatabaseQueryBuilderContract): void;
22
+ applyLuceneFieldAst(field: FieldToken, expression: ExpressionToken, operator: ComparisonOperatorToken, query: LuceneFilteredDatabaseQueryBuilderContract, forModel?: LucidModel | undefined): void;
23
+ applyLuceneRelatedFieldAst(relationship: string, relatedProperty: string, expression: ExpressionToken, operator: ComparisonOperatorToken, query: LuceneFilteredDatabaseQueryBuilderContract, forModel?: LucidModel | undefined): void;
24
+ applyLuceneEmptyExpression(column: string, _expression: EmptyExpression, operator: ComparisonOperatorToken, query: LuceneFilteredDatabaseQueryBuilderContract): void;
25
+ applyLuceneLiteralExpression(column: string, expression: LiteralExpressionToken, operator: ComparisonOperatorToken, query: LuceneFilteredDatabaseQueryBuilderContract): void;
26
+ applyLuceneRangeExpression(column: string, expression: RangeExpressionToken, operator: ComparisonOperatorToken, query: LuceneFilteredDatabaseQueryBuilderContract): void;
27
+ applyLuceneRegexExpression(column: string, expression: RegexExpressionToken, operator: ComparisonOperatorToken, query: LuceneFilteredDatabaseQueryBuilderContract): void;
28
+ static get(luceneQuery: string, connection: QueryClientContract, attributesToColumns: ModelKeysContract, primaryKey: string, tableName: string, allowedColumns?: string[] | undefined, model?: LucidModel | undefined): LuceneFilteredDatabaseQueryBuilderContract;
29
+ }
185
30
  /**
186
31
  * Converts a Lucene query string to a Lucid database query builder.
187
32
  * Parses the Lucene syntax and applies the resulting AST to generate SQL conditions.
@@ -193,9 +38,10 @@ export declare const applyLuceneAst: (ast: ParserAst, query: LuceneFilteredDatab
193
38
  * @param primaryKey - The primary key column name for implicit field queries
194
39
  * @param tableName - The database table name to query
195
40
  * @param allowedColumns - Optional array of allowed column names for security filtering
41
+ * @param model - Optional The lucid model which the query is being built for. When passed, allows relationship-based filtration.
196
42
  * @returns A database query builder with the Lucene conditions applied
197
43
  * @throws {E_LUCENE_SYNTAX_EXCEPTION} When the Lucene query has syntax errors
198
44
  * @throws {E_LUCENE_UNEXPECTED_EXCEPTION} When an unexpected error occurs during parsing
199
45
  * @throws {E_LUCENE_INVALID_TYPE} When an unrecognized AST node type is encountered
200
46
  */
201
- export declare const luceneToLucid: (luceneQuery: string, connection: QueryClientContract, attributesToColumns: ModelKeysContract, primaryKey: string, tableName: string, allowedColumns?: string[] | undefined) => LuceneFilteredDatabaseQueryBuilderContract;
47
+ export declare const luceneToLucid: (luceneQuery: string, connection: QueryClientContract, attributesToColumns: ModelKeysContract, primaryKey: string, tableName: string, allowedColumns?: string[] | undefined, model?: LucidModel | undefined) => LuceneFilteredDatabaseQueryBuilderContract;
@@ -6,7 +6,7 @@ import type { EventMap, Key, Listener } from '@nhtio/tiny-typed-emitter';
6
6
  import type { NormalizeConstructor } from '@adonisjs/core/types/helpers';
7
7
  import type { DatabaseQueryBuilderContract } from '@adonisjs/lucid/types/querybuilder';
8
8
  import type { LucidModel } from '@adonisjs/lucid/types/model';
9
- import type { ExternalDocumentationObject, PromiseAble, ResourcefulColumnDefinition, ResourcefulComputedAccessorDefinition, ResourcefulDataType, ResourcefulGeneralAccessControlFilter, ResourcefulModelOpenApiSchema, ResourcefulPropertySchema, ResourcefulRelationshipDefinition, ResourcefulResourceAccessControlFilter, ResourcefulModelSerializableAttributes } from '@nhtio/lucid-resourceful/types';
9
+ import type { ExternalDocumentationObject, PromiseAble, ResourcefulColumnDefinition, ResourcefulComputedAccessorDefinition, ResourcefulDataType, ResourcefulGeneralAccessControlFilter, ResourcefulModelOpenApiSchema, ResourcefulPropertySchema, ResourcefulRelationshipDefinition, ResourcefulResourceAccessControlFilter } from '@nhtio/lucid-resourceful/types';
10
10
  /**
11
11
  * Result object returned by the resourceful index/list operation.
12
12
  *
@@ -280,10 +280,9 @@ export interface ResourcefulModel extends LucidModel {
280
280
  * );
281
281
  * ```
282
282
  */
283
- $onResourcefulIndex<SelectedFields extends Array<keyof ResourcefulModelSerializableAttributes<InstanceType<LucidModel>>>, SelectedSingleField extends keyof ResourcefulModelSerializableAttributes<InstanceType<LucidModel>>, ReturnType = Pick<ResourcefulModelSerializableAttributes<InstanceType<LucidModel>>, SelectedFields[number]>>(filter: string | null | undefined, page: number, perPage: number, fields: SelectedFields | SelectedSingleField | null | undefined, sort: Array<[
284
- Extract<keyof ResourcefulModelSerializableAttributes<InstanceType<LucidModel>>, string>,
285
- 'asc' | 'desc'
286
- ]> | null | undefined, ctx: HttpContext, app: ApplicationService, hooks?: ResourcefulScopeHooks): Promise<ResourcefulIndexResult<ReturnType>>;
283
+ $onResourcefulIndex(filter: string | null | undefined, page: number, perPage: number, fields: string | string[] | null | undefined, sort: Array<[string, 'asc' | 'desc']> | null | undefined, ctx: HttpContext, app: ApplicationService, hooks?: ResourcefulScopeHooks): Promise<ResourcefulIndexResult<{
284
+ [key: string]: any;
285
+ }>>;
287
286
  /**
288
287
  * Retrieves a single model record by its unique identifier with access control.
289
288
  *
@@ -315,6 +314,64 @@ export interface ResourcefulModel extends LucidModel {
315
314
  * ```
316
315
  */
317
316
  $onResourcefulRead(uid: number, ctx: HttpContext, app: ApplicationService, hooks?: ResourcefulScopeHooks): Promise<any>;
317
+ /**
318
+ * Loads a specific relationship for a model record with pagination, filtering, and access control.
319
+ *
320
+ * This method provides paginated relationship loading by leveraging the related model's
321
+ * $onResourcefulIndex method with automatically generated relationship constraints.
322
+ * It supports full filtering, sorting, and pagination capabilities while maintaining
323
+ * proper access control and scoping.
324
+ *
325
+ * @param uid - The unique identifier of the parent record
326
+ * @param relationshipKey - The name of the relationship property to load
327
+ * @param filter - Lucene-style query string for filtering related records
328
+ * @param page - The page number for pagination (must be ≥ 1)
329
+ * @param perPage - Number of records per page (must be ≥ 1 and ≤ 100)
330
+ * @param fields - Array of field names to include in the response from the related model
331
+ * @param sort - Array of sort criteria as [field, direction] tuples
332
+ * @param ctx - HTTP context containing request information and authentication
333
+ * @param app - Application service instance for accessing app-level services
334
+ * @param hooks - Optional array of additional query scope callbacks
335
+ *
336
+ * @returns Promise resolving to paginated relationship results
337
+ *
338
+ * @throws {E_MISSING_PRIMARY_KEY_EXCEPTION} When the model has no identifiable primary key
339
+ * @throws {E_INVALID_RELATIONSHIP_EXCEPTION} When the specified relationship doesn't exist
340
+ * @throws {E_FORBIDDEN} When access is denied by model-level or field-level ACL filters
341
+ * @throws {E_INVALID_RESOUREFUL_INDEX_REQUEST_EXCEPTION} When input validation fails
342
+ *
343
+ * @example
344
+ * ```typescript
345
+ * // Load user's posts with filtering and pagination
346
+ * const userPosts = await Post.$onResourcefulReadRelationship(
347
+ * 123, // user ID
348
+ * 'posts', // relationship name
349
+ * 'status:published', // filter
350
+ * 1, // page
351
+ * 10, // perPage
352
+ * ['id', 'title'], // fields
353
+ * [['createdAt', 'desc']], // sort
354
+ * ctx,
355
+ * app
356
+ * );
357
+ *
358
+ * // Load user's skills (many-to-many)
359
+ * const userSkills = await Skill.$onResourcefulReadRelationship(
360
+ * 123,
361
+ * 'skills',
362
+ * null, // no filter
363
+ * 1,
364
+ * 50,
365
+ * null, // all fields
366
+ * null, // default sort
367
+ * ctx,
368
+ * app
369
+ * );
370
+ * ```
371
+ */
372
+ $onResourcefulReadRelationship(uid: any, relationshipKey: string, filter: string | null | undefined, page: number, perPage: number, fields: string | string[] | null | undefined, sort: Array<[string, 'asc' | 'desc']> | null | undefined, ctx: HttpContext, app: ApplicationService, hooks?: ResourcefulScopeHooks): Promise<ResourcefulIndexResult<{
373
+ [key: string]: any;
374
+ }>>;
318
375
  /**
319
376
  * Creates a new model record with payload validation and access control.
320
377
  *
@@ -417,6 +474,12 @@ export interface ResourcefulModel extends LucidModel {
417
474
  * ```
418
475
  */
419
476
  $onResourcefulDelete(uid: number, ctx: HttpContext, app: ApplicationService, hooks?: ResourcefulScopeHooks): Promise<void>;
477
+ $onResourcefulBulkUpdate(filter: string | null | undefined, payload: any, ctx: HttpContext, app: ApplicationService, hooks?: Partial<ResourcefulHooks>): Promise<{
478
+ [key: string]: any | Error;
479
+ } | Error>;
480
+ $onResourcefulBulkUpdateByUid(uids: (number | string)[], payload: any, ctx: HttpContext, app: ApplicationService, hooks?: Partial<ResourcefulHooks>): Promise<{
481
+ [key: string]: any | Error;
482
+ }>;
420
483
  /**
421
484
  * Generates an OpenAPI schema object for this model with context-aware field filtering.
422
485
  *
@@ -0,0 +1,111 @@
1
+ import type { ResourcefulModel } from '../mixin';
2
+ import type { ResourcefulModelColumnMetaSchema, ResourcefulModelComputedAccessorMetaSchema, ResourcefulModelRelationshipMetaSchema, ResourcefulModelMetaSchema, ResourcefulModelOpenApiSchema, ResourcefulModelOpenApiRelatedSchema } from '../types';
3
+ /**
4
+ * Service class for generating OpenAPI schema objects from resourceful model metadata.
5
+ *
6
+ * This service encapsulates all OpenAPI-related functionality that was previously
7
+ * embedded in the resourceful mixin, providing better code organization and
8
+ * easier testing. It handles the extraction of data type information from
9
+ * resourceful data types and generates proper OpenAPI schema objects.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const service = new OpenApiSchemaService()
14
+ * const schema = await service.generateModelSchema(model, ctx, app)
15
+ * ```
16
+ */
17
+ export declare class OpenApiSchemaService {
18
+ #private;
19
+ /**
20
+ * Generates a complete OpenAPI schema object for a resourceful model.
21
+ *
22
+ * This method creates a comprehensive OpenAPI v3 schema representation of the model
23
+ * by processing the provided metadata schema. The metadata should already have
24
+ * field-level access control permissions evaluated for the given request context.
25
+ *
26
+ * @param resourcefulModelMetaSchema - The resourceful model metadata with ACL filtering applied
27
+ * @returns Complete OpenAPI schema object
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const service = new OpenApiSchemaService()
32
+ * const schema = service.generateModelSchema(metaSchema)
33
+ * // Returns complete OpenAPI schema with accessible fields only
34
+ * ```
35
+ */
36
+ generateModelSchema(operation: "read" | "write" | undefined, resourcefulModelMetaSchema: ResourcefulModelMetaSchema, model?: ResourcefulModel): ResourcefulModelOpenApiSchema;
37
+ /**
38
+ * Generates OpenAPI schema for a column property.
39
+ *
40
+ * This method converts resourceful column metadata into an OpenAPI schema object,
41
+ * properly extracting data type information and preserving all existing schema
42
+ * properties such as validation constraints, nullability, and access modifiers.
43
+ *
44
+ * @param propertyKey - The name of the column property
45
+ * @param propertyMeta - The resourceful metadata for the column
46
+ * @returns OpenAPI schema object for the column
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const service = new OpenApiSchemaService()
51
+ * const schema = service.generateColumnSchema('name', columnMeta)
52
+ * // Returns: { type: 'string', minLength: 1, maxLength: 100, ... }
53
+ * ```
54
+ */
55
+ generateColumnSchema(propertyKey: string, propertyMeta: ResourcefulModelColumnMetaSchema): ResourcefulModelOpenApiSchema;
56
+ /**
57
+ * Generates OpenAPI schema for a computed accessor property.
58
+ *
59
+ * This method converts resourceful computed accessor metadata into an OpenAPI
60
+ * schema object, applying the same data type extraction improvements as column
61
+ * schema generation while maintaining all existing functionality.
62
+ *
63
+ * @param propertyKey - The name of the computed accessor property
64
+ * @param propertyMeta - The resourceful metadata for the computed accessor
65
+ * @returns OpenAPI schema object for the computed accessor
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const service = new OpenApiSchemaService()
70
+ * const schema = service.generateComputedAccessorSchema('fullName', accessorMeta)
71
+ * // Returns: { type: 'string', readOnly: true, ... }
72
+ * ```
73
+ */
74
+ generateComputedAccessorSchema(propertyKey: string, propertyMeta: ResourcefulModelComputedAccessorMetaSchema): ResourcefulModelOpenApiSchema;
75
+ /**
76
+ * Generates OpenAPI schema for a relationship property.
77
+ *
78
+ * This method converts resourceful relationship metadata into an OpenAPI
79
+ * reference object, preserving existing relationship reference generation
80
+ * logic and ensuring proper handling of related model references.
81
+ *
82
+ * @param propertyKey - The name of the relationship property
83
+ * @param propertyMeta - The resourceful metadata for the relationship
84
+ * @returns OpenAPI reference object for the relationship, or undefined if not applicable
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const service = new OpenApiSchemaService()
89
+ * const schema = service.generateRelationshipSchema('user', relationshipMeta)
90
+ * // Returns: { $ref: '#/components/schemas/User' }
91
+ * ```
92
+ */
93
+ generateRelationshipSchema(_propertyKey: string, propertyMeta: ResourcefulModelRelationshipMetaSchema): ResourcefulModelOpenApiRelatedSchema | undefined;
94
+ /**
95
+ * Extracts default value from property metadata using Joi description.
96
+ *
97
+ * This protected method provides access to the default value extraction logic
98
+ * that was previously part of the mixin. It examines the Joi validator
99
+ * description to find default values specified in the schema.
100
+ *
101
+ * @param propertyMeta - The resourceful metadata containing the validator
102
+ * @returns The default value if found, undefined otherwise
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const service = new OpenApiSchemaService()
107
+ * const defaultValue = service.getDefaultValueFromPropertyMeta(propertyMeta)
108
+ * ```
109
+ */
110
+ protected getDefaultValueFromPropertyMeta(propertyMeta: ResourcefulModelColumnMetaSchema | ResourcefulModelComputedAccessorMetaSchema): unknown | undefined;
111
+ }
@@ -1,6 +1,7 @@
1
1
  import { DateTime } from 'luxon';
2
2
  import type { LucidBinaryValue } from './types';
3
3
  import type { ResourcefulModel } from './mixin';
4
+ import type { ResourcefulStringType, ResourcefulDateType, ResourcefulDateTimeType, ResourcefulBinaryType, ResourcefulNumberType, ResourcefulIntegerType, ResourcefulBigintType, ResourcefulUnsignedIntegerType, ResourcefulBooleanType, ResourcefulObjectType, ResourcefulArrayType } from '@nhtio/lucid-resourceful/definitions';
4
5
  /**
5
6
  * Type guard to check if a value is a Luxon DateTime instance
6
7
  * @param value - The value to check
@@ -40,3 +41,64 @@ export declare const isInstanceOf: <T>(value: unknown, type: string, ctor?: new
40
41
  * @returns True if the value is a ResourcefulModel, false otherwise
41
42
  */
42
43
  export declare const isResourcefulModel: (value: unknown) => value is ResourcefulModel;
44
+ export declare const isResourcefulStringType: (value: unknown) => value is ResourcefulStringType;
45
+ /**
46
+ * Type guard to check if a value is a ResourcefulDateType
47
+ * @param value - The value to check
48
+ * @returns True if the value is a ResourcefulDateType, false otherwise
49
+ */
50
+ export declare const isResourcefulDateType: (value: unknown) => value is ResourcefulDateType;
51
+ /**
52
+ * Type guard to check if a value is a ResourcefulDateTimeType
53
+ * @param value - The value to check
54
+ * @returns True if the value is a ResourcefulDateTimeType, false otherwise
55
+ */
56
+ export declare const isResourcefulDateTimeType: (value: unknown) => value is ResourcefulDateTimeType;
57
+ /**
58
+ * Type guard to check if a value is a ResourcefulBinaryType
59
+ * @param value - The value to check
60
+ * @returns True if the value is a ResourcefulBinaryType, false otherwise
61
+ */
62
+ export declare const isResourcefulBinaryType: (value: unknown) => value is ResourcefulBinaryType;
63
+ /**
64
+ * Type guard to check if a value is a ResourcefulNumberType
65
+ * @param value - The value to check
66
+ * @returns True if the value is a ResourcefulNumberType, false otherwise
67
+ */
68
+ export declare const isResourcefulNumberType: (value: unknown) => value is ResourcefulNumberType;
69
+ /**
70
+ * Type guard to check if a value is a ResourcefulIntegerType
71
+ * @param value - The value to check
72
+ * @returns True if the value is a ResourcefulIntegerType, false otherwise
73
+ */
74
+ export declare const isResourcefulIntegerType: (value: unknown) => value is ResourcefulIntegerType;
75
+ /**
76
+ * Type guard to check if a value is a ResourcefulBigintType
77
+ * @param value - The value to check
78
+ * @returns True if the value is a ResourcefulBigintType, false otherwise
79
+ */
80
+ export declare const isResourcefulBigintType: (value: unknown) => value is ResourcefulBigintType;
81
+ /**
82
+ * Type guard to check if a value is a ResourcefulUnsignedIntegerType
83
+ * @param value - The value to check
84
+ * @returns True if the value is a ResourcefulUnsignedIntegerType, false otherwise
85
+ */
86
+ export declare const isResourcefulUnsignedIntegerType: (value: unknown) => value is ResourcefulUnsignedIntegerType;
87
+ /**
88
+ * Type guard to check if a value is a ResourcefulBooleanType
89
+ * @param value - The value to check
90
+ * @returns True if the value is a ResourcefulBooleanType, false otherwise
91
+ */
92
+ export declare const isResourcefulBooleanType: (value: unknown) => value is ResourcefulBooleanType;
93
+ /**
94
+ * Type guard to check if a value is a ResourcefulObjectType
95
+ * @param value - The value to check
96
+ * @returns True if the value is a ResourcefulObjectType, false otherwise
97
+ */
98
+ export declare const isResourcefulObjectType: (value: unknown) => value is ResourcefulObjectType;
99
+ /**
100
+ * Type guard to check if a value is a ResourcefulArrayType
101
+ * @param value - The value to check
102
+ * @returns True if the value is a ResourcefulArrayType, false otherwise
103
+ */
104
+ export declare const isResourcefulArrayType: (value: unknown) => value is ResourcefulArrayType;
@@ -1,4 +1,4 @@
1
- import { CustomConsumeFunction, CustomPrepareFunction } from '@/private/prepare_consume_chain_builder.ts';
1
+ import { CustomConsumeFunction, CustomPrepareFunction } from '@/private/prepare_consume_chain_builder';
2
2
  import type { OpenAPIV3 } from 'openapi-types';
3
3
  import type { HttpContext } from '@adonisjs/core/http';
4
4
  import type { ApplicationService } from '@adonisjs/core/types';
@@ -8,7 +8,31 @@ export declare const isString: (value: unknown) => value is string;
8
8
  * Checks if a value is a function
9
9
  */
10
10
  export declare const isFunction: (value: unknown) => value is Function;
11
+ /**
12
+ * Type guard to check if a value is an object.
13
+ *
14
+ * @param value - The value to check
15
+ * @returns True if the value is an object, false otherwise
16
+ */
17
+ export declare const isObject: (value: unknown) => value is Record<string, any>;
11
18
  /**
12
19
  * Prepares and returns fields in a consistent format based on the input type and primary key.
13
20
  */
14
21
  export declare const prepareFields: <T>(fields: unknown, primaryKey: string) => T;
22
+ /**
23
+ * Strips undefined values from an object, returning a new object with only defined values.
24
+ *
25
+ * @param obj - The object to strip undefined values from
26
+ * @returns A new object with undefined values removed
27
+ */
28
+ export declare const stripUndefinedValuesFromObject: <T extends Record<string, any>>(obj: T) => T;
29
+ /**
30
+ * Formats a syntax error message for a specific line and column in a source string.
31
+ *
32
+ * @param source - The source string to search for the error
33
+ * @param line - The line number where the error occurred (1-based)
34
+ * @param column - The column number where the error occurred (1-based)
35
+ * @param offset - The character offset where the error occurred (0-based)
36
+ * @returns A formatted error message
37
+ */
38
+ export declare const formatSyntaxError: (source: string, line: number, column: number, offset: number) => string;
package/utils.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const decorator_utils = require("./decorator_utils-U_rZo8tv.cjs");
3
+ const decorator_utils = require("./decorator_utils-DSvYjLYD.cjs");
4
4
  const casters = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5
5
  __proto__: null,
6
6
  castValueAsArray: decorator_utils.castValueAsArray,
package/utils.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { c as castValueAsArray, a as castValueAsBigint, b as castValueAsBinary, d as castValueAsBoolean, e as castValueAsDate, f as castValueAsDateTime, g as castValueAsInteger, h as castValueAsNumber, i as castValueAsObject, j as castValueAsString, k as castValueAsUnsignedInt, p as prepareArray, l as prepareBigint, m as prepareBinary, n as prepareBoolean, o as prepareDate, q as prepareDateTime, r as prepareInteger, s as prepareNumber, t as prepareObject, u as prepareString, v as prepareUnsignedint, w as consumeArray, x as consumeBigint, y as consumeBinary, z as consumeBoolean, A as consumeDate, B as consumeDateTime, C as consumeInteger, D as consumeNumber, E as consumeObject, F as consumeString, G as consumeUnsignedint } from "./decorator_utils-YSb1EGJ6.js";
2
- import { H } from "./decorator_utils-YSb1EGJ6.js";
1
+ import { c as castValueAsArray, a as castValueAsBigint, b as castValueAsBinary, d as castValueAsBoolean, e as castValueAsDate, f as castValueAsDateTime, g as castValueAsInteger, h as castValueAsNumber, i as castValueAsObject, j as castValueAsString, k as castValueAsUnsignedInt, p as prepareArray, l as prepareBigint, m as prepareBinary, n as prepareBoolean, o as prepareDate, q as prepareDateTime, r as prepareInteger, s as prepareNumber, t as prepareObject, u as prepareString, v as prepareUnsignedint, w as consumeArray, x as consumeBigint, y as consumeBinary, z as consumeBoolean, A as consumeDate, B as consumeDateTime, C as consumeInteger, D as consumeNumber, E as consumeObject, F as consumeString, G as consumeUnsignedint } from "./decorator_utils-gyymixlk.js";
2
+ import { H } from "./decorator_utils-gyymixlk.js";
3
3
  const casters = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4
4
  __proto__: null,
5
5
  castValueAsArray,