@rebasepro/types 0.1.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/controllers/auth.d.ts +9 -8
- package/dist/controllers/client.d.ts +3 -0
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types/auth_adapter.d.ts +356 -0
- package/dist/types/collections.d.ts +67 -2
- package/dist/types/database_adapter.d.ts +94 -0
- package/dist/types/entity_actions.d.ts +7 -1
- package/dist/types/entity_callbacks.d.ts +1 -1
- package/dist/types/entity_views.d.ts +36 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/plugins.d.ts +1 -1
- package/dist/types/properties.d.ts +24 -5
- package/dist/types/property_config.d.ts +6 -2
- package/dist/types/relations.d.ts +1 -1
- package/dist/types/translations.d.ts +8 -0
- package/dist/users/user.d.ts +5 -0
- package/package.json +13 -10
- package/src/controllers/analytics_controller.d.ts +7 -0
- package/src/controllers/auth.d.ts +125 -0
- package/src/controllers/auth.tsx +2 -5
- package/src/controllers/client.d.ts +183 -0
- package/src/controllers/client.ts +3 -2
- package/src/controllers/collection_registry.d.ts +46 -0
- package/src/controllers/customization_controller.d.ts +60 -0
- package/src/controllers/data.d.ts +168 -0
- package/src/controllers/data_driver.d.ts +195 -0
- package/src/controllers/database_admin.d.ts +11 -0
- package/src/controllers/dialogs_controller.d.ts +36 -0
- package/src/controllers/effective_role.d.ts +4 -0
- package/src/controllers/email.d.ts +34 -0
- package/src/controllers/index.d.ts +18 -0
- package/src/controllers/local_config_persistence.d.ts +20 -0
- package/src/controllers/navigation.d.ts +225 -0
- package/src/controllers/registry.d.ts +62 -0
- package/src/controllers/side_dialogs_controller.d.ts +67 -0
- package/src/controllers/side_entity_controller.d.ts +97 -0
- package/src/controllers/snackbar.d.ts +24 -0
- package/src/controllers/storage.d.ts +171 -0
- package/src/index.d.ts +4 -0
- package/src/rebase_context.d.ts +122 -0
- package/src/types/auth_adapter.d.ts +354 -0
- package/src/types/auth_adapter.ts +410 -0
- package/src/types/backend.d.ts +536 -0
- package/src/types/backend_hooks.d.ts +187 -0
- package/src/types/builders.d.ts +15 -0
- package/src/types/chips.d.ts +5 -0
- package/src/types/collections.d.ts +920 -0
- package/src/types/collections.ts +77 -2
- package/src/types/component_ref.d.ts +47 -0
- package/src/types/cron.d.ts +102 -0
- package/src/types/data_source.d.ts +64 -0
- package/src/types/database_adapter.d.ts +90 -0
- package/src/types/database_adapter.ts +120 -0
- package/src/types/entities.d.ts +145 -0
- package/src/types/entity_actions.d.ts +98 -0
- package/src/types/entity_actions.tsx +8 -1
- package/src/types/entity_callbacks.d.ts +173 -0
- package/src/types/entity_callbacks.ts +1 -1
- package/src/types/entity_link_builder.d.ts +7 -0
- package/src/types/entity_overrides.d.ts +10 -0
- package/src/types/entity_views.d.ts +60 -0
- package/src/types/entity_views.tsx +39 -1
- package/src/types/export_import.d.ts +21 -0
- package/src/types/formex.d.ts +40 -0
- package/src/types/index.d.ts +28 -0
- package/src/types/index.ts +2 -0
- package/src/types/locales.d.ts +4 -0
- package/src/types/modify_collections.d.ts +5 -0
- package/src/types/plugins.d.ts +282 -0
- package/src/types/plugins.tsx +1 -1
- package/src/types/properties.d.ts +1160 -0
- package/src/types/properties.ts +34 -4
- package/src/types/property_config.d.ts +70 -0
- package/src/types/property_config.tsx +6 -3
- package/src/types/relations.d.ts +336 -0
- package/src/types/relations.ts +1 -1
- package/src/types/slots.d.ts +262 -0
- package/src/types/translations.d.ts +882 -0
- package/src/types/translations.ts +11 -0
- package/src/types/user_management_delegate.d.ts +121 -0
- package/src/types/websockets.d.ts +78 -0
- package/src/users/index.d.ts +2 -0
- package/src/users/roles.d.ts +22 -0
- package/src/users/user.d.ts +46 -0
- package/src/users/user.ts +6 -0
package/src/types/properties.ts
CHANGED
|
@@ -2,7 +2,7 @@ import React from "react";
|
|
|
2
2
|
|
|
3
3
|
import type { ComponentRef } from "./component_ref";
|
|
4
4
|
|
|
5
|
-
import type { EntityReference, EntityRelation, EntityValues, GeoPoint, Entity } from "./entities";
|
|
5
|
+
import type { EntityReference, EntityRelation, EntityValues, GeoPoint, Entity, Vector } from "./entities";
|
|
6
6
|
import type { Relation, JoinStep, OnAction } from "./relations";
|
|
7
7
|
import type { EntityCollection, FilterValues } from "./collections";
|
|
8
8
|
import type { ColorKey, ColorScheme } from "./chips";
|
|
@@ -48,7 +48,9 @@ export type DataType =
|
|
|
48
48
|
| "reference"
|
|
49
49
|
| "relation"
|
|
50
50
|
| "array"
|
|
51
|
-
| "map"
|
|
51
|
+
| "map"
|
|
52
|
+
| "vector"
|
|
53
|
+
| "binary";
|
|
52
54
|
|
|
53
55
|
export type Property =
|
|
54
56
|
| StringProperty
|
|
@@ -59,7 +61,9 @@ export type Property =
|
|
|
59
61
|
| ReferenceProperty
|
|
60
62
|
| RelationProperty
|
|
61
63
|
| ArrayProperty
|
|
62
|
-
| MapProperty
|
|
64
|
+
| MapProperty
|
|
65
|
+
| VectorProperty
|
|
66
|
+
| BinaryProperty;
|
|
63
67
|
|
|
64
68
|
export type Properties = {
|
|
65
69
|
[key: string]: Property;
|
|
@@ -89,6 +93,8 @@ export type InferPropertyType<P extends Property> =
|
|
|
89
93
|
P extends RelationProperty ? EntityRelation | EntityRelation[] :
|
|
90
94
|
P extends ArrayProperty ? (P["of"] extends Property ? InferPropertyType<P["of"]>[] : unknown[]) :
|
|
91
95
|
P extends MapProperty ? (P["properties"] extends Properties ? InferEntityType<P["properties"]> : Record<string, unknown>) :
|
|
96
|
+
P extends VectorProperty ? Vector :
|
|
97
|
+
P extends BinaryProperty ? string :
|
|
92
98
|
never;
|
|
93
99
|
|
|
94
100
|
/**
|
|
@@ -185,6 +191,8 @@ export interface BaseProperty<CustomProps = unknown> {
|
|
|
185
191
|
|
|
186
192
|
|
|
187
193
|
|
|
194
|
+
|
|
195
|
+
|
|
188
196
|
/**
|
|
189
197
|
* Rules for validating this property
|
|
190
198
|
*/
|
|
@@ -378,6 +386,28 @@ export interface BooleanProperty extends BaseProperty {
|
|
|
378
386
|
validation?: PropertyValidationSchema;
|
|
379
387
|
}
|
|
380
388
|
|
|
389
|
+
/**
|
|
390
|
+
* @group Entity properties
|
|
391
|
+
*/
|
|
392
|
+
export interface VectorUIConfig extends BaseUIConfig {
|
|
393
|
+
clearable?: boolean;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export interface VectorProperty extends BaseProperty {
|
|
397
|
+
ui?: VectorUIConfig;
|
|
398
|
+
type: "vector";
|
|
399
|
+
dimensions: number;
|
|
400
|
+
validation?: PropertyValidationSchema;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* @group Entity properties
|
|
405
|
+
*/
|
|
406
|
+
export interface BinaryProperty extends BaseProperty {
|
|
407
|
+
type: "binary";
|
|
408
|
+
validation?: PropertyValidationSchema;
|
|
409
|
+
}
|
|
410
|
+
|
|
381
411
|
/**
|
|
382
412
|
* @group Entity properties
|
|
383
413
|
*/
|
|
@@ -503,7 +533,7 @@ export interface RelationProperty extends BaseProperty {
|
|
|
503
533
|
* When set, the framework treats this property as a self-contained relation
|
|
504
534
|
* definition and no separate `relations[]` entry is needed.
|
|
505
535
|
*/
|
|
506
|
-
target?: () => EntityCollection;
|
|
536
|
+
target?: string | (() => EntityCollection | string);
|
|
507
537
|
|
|
508
538
|
/**
|
|
509
539
|
* Whether this property references one or many records.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ArrayProperty, MapProperty, StringProperty, NumberProperty, BooleanProperty, DateProperty, GeopointProperty, ReferenceProperty, RelationProperty } from "./properties";
|
|
3
|
+
import { BaseProperty } from "./properties";
|
|
4
|
+
type CMSBasePropertyNoName = Omit<BaseProperty, "name">;
|
|
5
|
+
export type ConfigProperty = (Omit<StringProperty, "name"> & {
|
|
6
|
+
name?: string;
|
|
7
|
+
} & CMSBasePropertyNoName) | (Omit<NumberProperty, "name"> & {
|
|
8
|
+
name?: string;
|
|
9
|
+
} & CMSBasePropertyNoName) | (Omit<BooleanProperty, "name"> & {
|
|
10
|
+
name?: string;
|
|
11
|
+
} & CMSBasePropertyNoName) | (Omit<DateProperty, "name"> & {
|
|
12
|
+
name?: string;
|
|
13
|
+
} & CMSBasePropertyNoName) | (Omit<GeopointProperty, "name"> & {
|
|
14
|
+
name?: string;
|
|
15
|
+
} & CMSBasePropertyNoName) | (Omit<ReferenceProperty, "name"> & {
|
|
16
|
+
name?: string;
|
|
17
|
+
} & CMSBasePropertyNoName) | (Omit<RelationProperty, "name"> & {
|
|
18
|
+
name?: string;
|
|
19
|
+
} & CMSBasePropertyNoName) | (Omit<ArrayProperty, "name" | "of" | "oneOf"> & {
|
|
20
|
+
name?: string;
|
|
21
|
+
of?: ConfigProperty | ConfigProperty[];
|
|
22
|
+
oneOf?: {
|
|
23
|
+
properties: Record<string, ConfigProperty>;
|
|
24
|
+
typeField?: string;
|
|
25
|
+
valueField?: string;
|
|
26
|
+
propertiesOrder?: string[];
|
|
27
|
+
};
|
|
28
|
+
} & CMSBasePropertyNoName) | (Omit<MapProperty, "name" | "properties"> & {
|
|
29
|
+
name?: string;
|
|
30
|
+
properties?: Record<string, ConfigProperty>;
|
|
31
|
+
} & CMSBasePropertyNoName);
|
|
32
|
+
/**
|
|
33
|
+
* This is the configuration object for a property.
|
|
34
|
+
* These configs are generated by default for the properties defined in your
|
|
35
|
+
* collections' configuration, but you can define your own to be used.
|
|
36
|
+
*/
|
|
37
|
+
export type PropertyConfig = {
|
|
38
|
+
/**
|
|
39
|
+
* Key used to identify this property config.
|
|
40
|
+
*/
|
|
41
|
+
key: PropertyConfigId | string;
|
|
42
|
+
/**
|
|
43
|
+
* Name of this field type.
|
|
44
|
+
* This is not the name of the property.
|
|
45
|
+
*/
|
|
46
|
+
name: string;
|
|
47
|
+
/**
|
|
48
|
+
* Default config for the property.
|
|
49
|
+
* This property or builder will be used as the base values for the resulting property.
|
|
50
|
+
* You can also use a builder function to generate the base property.
|
|
51
|
+
*/
|
|
52
|
+
property: ConfigProperty;
|
|
53
|
+
/**
|
|
54
|
+
* Optional icon to be used in the field selector.
|
|
55
|
+
* Use a 24x24 component, in order not to break the layout.
|
|
56
|
+
* Any Rebase icon can be used.
|
|
57
|
+
*/
|
|
58
|
+
Icon?: React.ComponentType;
|
|
59
|
+
/**
|
|
60
|
+
* CSS color, used only in some plugins like the field selector.
|
|
61
|
+
* e.g. "#2d7ff9"
|
|
62
|
+
*/
|
|
63
|
+
color?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Description of this field type.
|
|
66
|
+
*/
|
|
67
|
+
description?: string;
|
|
68
|
+
};
|
|
69
|
+
export type PropertyConfigId = "text_field" | "multiline" | "markdown" | "url" | "email" | "user_select" | "select" | "multi_select" | "number_input" | "number_select" | "multi_number_select" | "file_upload" | "multi_file_upload" | "group" | "key_value" | "reference" | "reference_as_string" | "multi_references" | "relation" | "switch" | "date_time" | "repeat" | "custom_array" | "block";
|
|
70
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { ArrayProperty, MapProperty, Property, StringProperty, NumberProperty, BooleanProperty, DateProperty, GeopointProperty, ReferenceProperty, RelationProperty } from "./properties";import { BaseProperty } from "./properties";
|
|
2
|
+
import { ArrayProperty, MapProperty, Property, StringProperty, NumberProperty, BooleanProperty, DateProperty, GeopointProperty, ReferenceProperty, RelationProperty, VectorProperty, BinaryProperty } from "./properties";import { BaseProperty } from "./properties";
|
|
3
3
|
|
|
4
4
|
type CMSBasePropertyNoName = Omit<BaseProperty, "name">;
|
|
5
5
|
|
|
@@ -19,7 +19,9 @@ export type ConfigProperty =
|
|
|
19
19
|
| (Omit<MapProperty, "name" | "properties"> & {
|
|
20
20
|
name?: string;
|
|
21
21
|
properties?: Record<string, ConfigProperty>
|
|
22
|
-
} & CMSBasePropertyNoName)
|
|
22
|
+
} & CMSBasePropertyNoName)
|
|
23
|
+
| (Omit<VectorProperty, "name"> & { name?: string } & CMSBasePropertyNoName)
|
|
24
|
+
| (Omit<BinaryProperty, "name"> & { name?: string } & CMSBasePropertyNoName);
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* This is the configuration object for a property.
|
|
@@ -90,4 +92,5 @@ export type PropertyConfigId =
|
|
|
90
92
|
"date_time" |
|
|
91
93
|
"repeat" |
|
|
92
94
|
"custom_array" |
|
|
93
|
-
"block"
|
|
95
|
+
"block" |
|
|
96
|
+
"vector_input";
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import type { EntityCollection } from "./collections";
|
|
2
|
+
/**
|
|
3
|
+
* @group Models
|
|
4
|
+
*/
|
|
5
|
+
export type OnAction = "cascade" | "restrict" | "no action" | "set null" | "set default";
|
|
6
|
+
/**
|
|
7
|
+
* Extended relation that combines base relation with Rebase UI config
|
|
8
|
+
* @group Models
|
|
9
|
+
*/
|
|
10
|
+
export interface Relation {
|
|
11
|
+
/**
|
|
12
|
+
* The application-level name for this relationship.
|
|
13
|
+
* If not provided, it will be inferred from the target collection path.
|
|
14
|
+
* @example "posts"
|
|
15
|
+
*/
|
|
16
|
+
relationName?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The final collection you want to retrieve records from.
|
|
19
|
+
*/
|
|
20
|
+
target: () => EntityCollection;
|
|
21
|
+
/**
|
|
22
|
+
* The nature of the relationship, determining if one or many records are returned.
|
|
23
|
+
*/
|
|
24
|
+
cardinality: "one" | "many";
|
|
25
|
+
/**
|
|
26
|
+
* Which side owns the persistence for this relationship.
|
|
27
|
+
* - "owning": The foreign key (for one-to-one/many-to-one) or the junction table (for many-to-many) is managed by this collection.
|
|
28
|
+
* - "inverse": The foreign key is on the target collection's table. This side of the relation is typically read-only.
|
|
29
|
+
* Defaults to "owning".
|
|
30
|
+
*/
|
|
31
|
+
direction?: "owning" | "inverse";
|
|
32
|
+
/**
|
|
33
|
+
* The name of the inverse relation.
|
|
34
|
+
* This is only needed when the inverse relation is not the same as the relation name.
|
|
35
|
+
* For example, if the relation name is "posts", the inverse relation name might be "author".
|
|
36
|
+
*/
|
|
37
|
+
inverseRelationName?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Column on THIS table that stores the foreign key to the target.
|
|
40
|
+
* Required when `direction` is "owning" and `cardinality` is "one".
|
|
41
|
+
* @example "author_id"
|
|
42
|
+
*/
|
|
43
|
+
localKey?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Column on the TARGET table that stores the foreign key to this entity.
|
|
46
|
+
* Required when `direction` is "inverse".
|
|
47
|
+
* @example "post_id"
|
|
48
|
+
*/
|
|
49
|
+
foreignKeyOnTarget?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Defines the junction table for a many-to-many relationship.
|
|
52
|
+
* Required when `cardinality` is "many" and `direction` is "owning".
|
|
53
|
+
*
|
|
54
|
+
* @example Simple many-to-many between Users and Roles:
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Users collection
|
|
57
|
+
* {
|
|
58
|
+
* relations: [{
|
|
59
|
+
* relationName: "roles",
|
|
60
|
+
* target: () => rolesCollection,
|
|
61
|
+
* cardinality: "many",
|
|
62
|
+
* through: {
|
|
63
|
+
* table: "user_roles", // Junction table name
|
|
64
|
+
* sourceColumn: "user_id", // Column that references this collection's ID
|
|
65
|
+
* targetColumn: "role_id" // Column that references target collection's ID
|
|
66
|
+
* }
|
|
67
|
+
* }]
|
|
68
|
+
* }
|
|
69
|
+
*
|
|
70
|
+
* // This creates a junction table like:
|
|
71
|
+
* // CREATE TABLE user_roles (
|
|
72
|
+
* // user_id INTEGER REFERENCES users(id),
|
|
73
|
+
* // role_id INTEGER REFERENCES roles(id),
|
|
74
|
+
* // PRIMARY KEY (user_id, role_id)
|
|
75
|
+
* // );
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @example Many-to-many with additional junction table data:
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // Students and Courses with enrollment date
|
|
81
|
+
* {
|
|
82
|
+
* relations: [{
|
|
83
|
+
* relationName: "courses",
|
|
84
|
+
* target: () => coursesCollection,
|
|
85
|
+
* cardinality: "many",
|
|
86
|
+
* through: {
|
|
87
|
+
* table: "enrollments",
|
|
88
|
+
* sourceColumn: "student_id",
|
|
89
|
+
* targetColumn: "course_id"
|
|
90
|
+
* }
|
|
91
|
+
* }]
|
|
92
|
+
* }
|
|
93
|
+
*
|
|
94
|
+
* // Junction table can have additional columns:
|
|
95
|
+
* // CREATE TABLE enrollments (
|
|
96
|
+
* // student_id INTEGER REFERENCES students(id),
|
|
97
|
+
* // course_id INTEGER REFERENCES courses(id),
|
|
98
|
+
* // enrolled_at TIMESTAMP DEFAULT NOW(),
|
|
99
|
+
* // grade VARCHAR(2),
|
|
100
|
+
* // PRIMARY KEY (student_id, course_id)
|
|
101
|
+
* // );
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
through?: {
|
|
105
|
+
table: string;
|
|
106
|
+
sourceColumn: string;
|
|
107
|
+
targetColumn: string;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* An explicit, ordered array of JOINs to perform to get from the source
|
|
111
|
+
* to the target. Used for multi-hop relations, composite keys, or when you need
|
|
112
|
+
* fine-grained control over the join logic.
|
|
113
|
+
*
|
|
114
|
+
* When `joinPath` is provided, it overrides all other relation configuration
|
|
115
|
+
* (localKey, foreignKeyOnTarget, through) and gives you complete control
|
|
116
|
+
* over how tables are joined together.
|
|
117
|
+
*
|
|
118
|
+
* @example Simple one-to-one join (equivalent to localKey):
|
|
119
|
+
* ```typescript
|
|
120
|
+
* // Posts -> Authors relationship
|
|
121
|
+
* {
|
|
122
|
+
* relationName: "author",
|
|
123
|
+
* target: () => authorsCollection,
|
|
124
|
+
* cardinality: "one",
|
|
125
|
+
* joinPath: [
|
|
126
|
+
* {
|
|
127
|
+
* table: "authors",
|
|
128
|
+
* on: {
|
|
129
|
+
* from: "author_id", // Column on posts table
|
|
130
|
+
* to: "id" // Column on authors table
|
|
131
|
+
* }
|
|
132
|
+
* }
|
|
133
|
+
* ]
|
|
134
|
+
* }
|
|
135
|
+
*
|
|
136
|
+
* // Generates: SELECT * FROM posts JOIN authors ON posts.author_id = authors.id
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @example Multi-hop relationship (3 tables):
|
|
140
|
+
* ```typescript
|
|
141
|
+
* // Users -> Permissions through Roles
|
|
142
|
+
* {
|
|
143
|
+
* relationName: "permissions",
|
|
144
|
+
* target: () => permissionsCollection,
|
|
145
|
+
* cardinality: "many",
|
|
146
|
+
* joinPath: [
|
|
147
|
+
* {
|
|
148
|
+
* table: "user_roles",
|
|
149
|
+
* on: {
|
|
150
|
+
* from: "id", // users.id
|
|
151
|
+
* to: "user_id" // user_roles.user_id
|
|
152
|
+
* }
|
|
153
|
+
* },
|
|
154
|
+
* {
|
|
155
|
+
* table: "roles",
|
|
156
|
+
* on: {
|
|
157
|
+
* from: "role_id", // user_roles.role_id
|
|
158
|
+
* to: "id" // roles.id
|
|
159
|
+
* }
|
|
160
|
+
* },
|
|
161
|
+
* {
|
|
162
|
+
* table: "role_permissions",
|
|
163
|
+
* on: {
|
|
164
|
+
* from: "id", // roles.id
|
|
165
|
+
* to: "role_id" // role_permissions.role_id
|
|
166
|
+
* }
|
|
167
|
+
* },
|
|
168
|
+
* {
|
|
169
|
+
* table: "permissions",
|
|
170
|
+
* on: {
|
|
171
|
+
* from: "permission_id", // role_permissions.permission_id
|
|
172
|
+
* to: "id" // permissions.id
|
|
173
|
+
* }
|
|
174
|
+
* }
|
|
175
|
+
* ]
|
|
176
|
+
* }
|
|
177
|
+
*
|
|
178
|
+
* // Generates:
|
|
179
|
+
* // SELECT * FROM users
|
|
180
|
+
* // JOIN user_roles ON users.id = user_roles.user_id
|
|
181
|
+
* // JOIN roles ON user_roles.role_id = roles.id
|
|
182
|
+
* // JOIN role_permissions ON roles.id = role_permissions.role_id
|
|
183
|
+
* // JOIN permissions ON role_permissions.permission_id = permissions.id
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* @example Composite key relationship:
|
|
187
|
+
* ```typescript
|
|
188
|
+
* // Orders -> Customer by company_code + region
|
|
189
|
+
* {
|
|
190
|
+
* relationName: "customer",
|
|
191
|
+
* target: () => customersCollection,
|
|
192
|
+
* cardinality: "one",
|
|
193
|
+
* joinPath: [
|
|
194
|
+
* {
|
|
195
|
+
* table: "customers",
|
|
196
|
+
* on: {
|
|
197
|
+
* from: ["company_code", "region_id"], // Multiple columns from orders
|
|
198
|
+
* to: ["code", "region_id"] // Multiple columns on customers
|
|
199
|
+
* }
|
|
200
|
+
* }
|
|
201
|
+
* ]
|
|
202
|
+
* }
|
|
203
|
+
*
|
|
204
|
+
* // Generates:
|
|
205
|
+
* // SELECT * FROM orders
|
|
206
|
+
* // JOIN customers ON orders.company_code = customers.code
|
|
207
|
+
* // AND orders.region_id = customers.region_id
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* @example Self-referencing with intermediate table:
|
|
211
|
+
* ```typescript
|
|
212
|
+
* // Users -> Friends (many-to-many self-reference)
|
|
213
|
+
* {
|
|
214
|
+
* relationName: "friends",
|
|
215
|
+
* target: () => usersCollection, // Same collection
|
|
216
|
+
* cardinality: "many",
|
|
217
|
+
* joinPath: [
|
|
218
|
+
* {
|
|
219
|
+
* table: "friendships",
|
|
220
|
+
* on: {
|
|
221
|
+
* from: "id", // users.id
|
|
222
|
+
* to: "user_id" // friendships.user_id
|
|
223
|
+
* }
|
|
224
|
+
* },
|
|
225
|
+
* {
|
|
226
|
+
* table: "users",
|
|
227
|
+
* on: {
|
|
228
|
+
* from: "friend_id", // friendships.friend_id
|
|
229
|
+
* to: "id" // users.id (target)
|
|
230
|
+
* }
|
|
231
|
+
* }
|
|
232
|
+
* ]
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* @example Complex business logic join:
|
|
237
|
+
* ```typescript
|
|
238
|
+
* // Products -> Active Suppliers (only current, non-expired contracts)
|
|
239
|
+
* {
|
|
240
|
+
* relationName: "activeSuppliers",
|
|
241
|
+
* target: () => suppliersCollection,
|
|
242
|
+
* cardinality: "many",
|
|
243
|
+
* joinPath: [
|
|
244
|
+
* {
|
|
245
|
+
* table: "product_supplier_contracts",
|
|
246
|
+
* on: {
|
|
247
|
+
* from: "id", // products.id
|
|
248
|
+
* to: "product_id" // contracts.product_id
|
|
249
|
+
* }
|
|
250
|
+
* },
|
|
251
|
+
* {
|
|
252
|
+
* table: "suppliers",
|
|
253
|
+
* on: {
|
|
254
|
+
* from: "supplier_id", // contracts.supplier_id
|
|
255
|
+
* to: "id" // suppliers.id
|
|
256
|
+
* }
|
|
257
|
+
* }
|
|
258
|
+
* ]
|
|
259
|
+
* // Note: Additional WHERE conditions for active/non-expired
|
|
260
|
+
* // would be handled in the query logic, not in joinPath
|
|
261
|
+
* }
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
joinPath?: JoinStep[];
|
|
265
|
+
/**
|
|
266
|
+
* Action to perform on update.
|
|
267
|
+
*/
|
|
268
|
+
onUpdate?: OnAction;
|
|
269
|
+
/**
|
|
270
|
+
* Action to perform on delete.
|
|
271
|
+
*/
|
|
272
|
+
onDelete?: OnAction;
|
|
273
|
+
overrides?: Partial<EntityCollection>;
|
|
274
|
+
validation?: {
|
|
275
|
+
required?: boolean;
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Defines a single, explicit step in a multi-join path.
|
|
280
|
+
*
|
|
281
|
+
* Each step represents one JOIN operation in the sequence. The `from` columns
|
|
282
|
+
* refer to the previous table in the chain (or the source table for the first step),
|
|
283
|
+
* and the `to` columns refer to the current table being joined.
|
|
284
|
+
*
|
|
285
|
+
* @example Single column join:
|
|
286
|
+
* ```typescript
|
|
287
|
+
* {
|
|
288
|
+
* table: "authors",
|
|
289
|
+
* on: {
|
|
290
|
+
* from: "author_id", // Column from previous table (e.g., posts.author_id)
|
|
291
|
+
* to: "id" // Column from current table (authors.id)
|
|
292
|
+
* }
|
|
293
|
+
* }
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @example Multi-column composite key join:
|
|
297
|
+
* ```typescript
|
|
298
|
+
* {
|
|
299
|
+
* table: "order_items",
|
|
300
|
+
* on: {
|
|
301
|
+
* from: ["order_id", "store_id"], // Multiple columns from previous table
|
|
302
|
+
* to: ["order_id", "store_id"] // Corresponding columns in current table
|
|
303
|
+
* }
|
|
304
|
+
* }
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
export interface JoinStep {
|
|
308
|
+
/**
|
|
309
|
+
* The database table name to join TO in this step.
|
|
310
|
+
* This is the table you're joining into, not the table you're joining from.
|
|
311
|
+
*
|
|
312
|
+
* @example "authors", "user_roles", "product_categories"
|
|
313
|
+
*/
|
|
314
|
+
table: string;
|
|
315
|
+
/**
|
|
316
|
+
* The join condition for this step. Defines how the previous table
|
|
317
|
+
* connects to the current table.
|
|
318
|
+
*
|
|
319
|
+
* - `from`: Column name(s) on the PREVIOUS table in the join chain
|
|
320
|
+
* - `to`: Column name(s) on the CURRENT table (specified in `table`)
|
|
321
|
+
*
|
|
322
|
+
* For the first step, `from` refers to the source collection's table.
|
|
323
|
+
* For subsequent steps, `from` refers to the table from the previous step.
|
|
324
|
+
*
|
|
325
|
+
* Both `from` and `to` support:
|
|
326
|
+
* - Single column: `"user_id"`
|
|
327
|
+
* - Multiple columns: `["company_id", "region_id"]` for composite keys
|
|
328
|
+
*
|
|
329
|
+
* When using arrays, both `from` and `to` must have the same length,
|
|
330
|
+
* and columns are matched by position (index 0 with index 0, etc.).
|
|
331
|
+
*/
|
|
332
|
+
on: {
|
|
333
|
+
from: string | string[];
|
|
334
|
+
to: string | string[];
|
|
335
|
+
};
|
|
336
|
+
}
|
package/src/types/relations.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface Relation {
|
|
|
20
20
|
/**
|
|
21
21
|
* The final collection you want to retrieve records from.
|
|
22
22
|
*/
|
|
23
|
-
target: () => EntityCollection;
|
|
23
|
+
target: (() => EntityCollection) | any;
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* The nature of the relationship, determining if one or many records are returned.
|