remult 0.23.0-exp.12 → 0.23.0-exp.14
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/esm/index.d.ts +1 -1
- package/esm/remult-express.js +1 -1
- package/esm/remult-knex/index.js +2 -1
- package/esm/remult-mongo.js +2 -1
- package/esm/server/expressBridge.js +1 -1
- package/esm/src/column.d.ts +2 -3
- package/esm/src/column.js +4 -3
- package/esm/src/data-providers/sql-database.js +2 -1
- package/esm/src/entity.js +0 -1
- package/esm/src/live-query/LiveQueryClient.js +2 -1
- package/esm/src/live-query/SubscriptionChannel.js +3 -2
- package/esm/src/remult-proxy.js +6 -4
- package/esm/src/remult3/Fields.d.ts +24 -19
- package/esm/src/remult3/Fields.js +1 -4
- package/esm/src/remult3/RepositoryImplementation.d.ts +2 -11
- package/esm/src/remult3/RepositoryImplementation.js +31 -9
- package/esm/src/remult3/entity.d.ts +1 -1
- package/esm/src/remult3/entity.js +0 -1
- package/esm/src/remult3/remult3.d.ts +13 -1
- package/esm/src/remult3/repository-internals.d.ts +14 -0
- package/esm/src/remult3/repository-internals.js +7 -0
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/remult-express.js +1 -1
- package/remult-knex/index.js +2 -1
- package/remult-mongo.js +2 -1
- package/server/expressBridge.js +1 -1
- package/src/column.d.ts +2 -3
- package/src/column.js +4 -3
- package/src/data-providers/sql-database.js +2 -1
- package/src/entity.js +0 -1
- package/src/live-query/LiveQueryClient.js +2 -1
- package/src/live-query/SubscriptionChannel.js +3 -2
- package/src/remult-proxy.js +38 -32
- package/src/remult3/Fields.d.ts +24 -19
- package/src/remult3/Fields.js +0 -3
- package/src/remult3/RepositoryImplementation.d.ts +2 -11
- package/src/remult3/RepositoryImplementation.js +30 -8
- package/src/remult3/entity.d.ts +1 -1
- package/src/remult3/entity.js +0 -1
- package/src/remult3/remult3.d.ts +13 -1
- package/src/remult3/repository-internals.d.ts +14 -0
- package/src/remult3/repository-internals.js +11 -0
package/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClassType } from './classType';
|
|
2
|
-
export { OmitEB, FieldsMetadata, FieldRef, IdFieldRef, FieldsRef, EntityMetadata, EntityOrderBy, EntityFilter, FindOptions, QueryResult, QueryOptions, Repository, FindFirstOptions, ComparisonValueFilter, ValueFilter, IdFilter, ContainsStringValueFilter, EntityRef, SortSegments, Paginator, LiveQuery, LiveQueryChangeInfo, Subscribable, RefSubscriber, RefSubscriberBase, RelationOptions, RelationOptionsBase, ObjectMembersOnly, MembersToInclude, RepositoryRelations, EntityIdFields, } from './src/remult3/remult3';
|
|
2
|
+
export { OmitEB, FieldsMetadata, FieldRef, IdFieldRef, FieldsRef, EntityMetadata, EntityOrderBy, EntityFilter, FindOptions, QueryResult, QueryOptions, Repository, FindFirstOptions, ComparisonValueFilter, ValueFilter, IdFilter, ContainsStringValueFilter, EntityRef, SortSegments, Paginator, LiveQuery, LiveQueryChangeInfo, Subscribable, RefSubscriber, RefSubscriberBase, RelationOptions, RelationOptionsBase, ObjectMembersOnly, MembersToInclude, RepositoryRelations, EntityIdFields, ClassFieldDecorator as MemberDecorator, ClassFieldDecoratorContextStub, } from './src/remult3/remult3';
|
|
3
3
|
export { EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListFieldOptions, ValueListInfo, CaptionTransformer, } from './src/remult3/RepositoryImplementation';
|
|
4
4
|
export { Entity } from './src/remult3/entity';
|
|
5
5
|
export { getEntityRef } from './src/remult3/getEntityRef';
|
package/esm/remult-express.js
CHANGED
|
@@ -21,6 +21,6 @@ export function remultExpress(options) {
|
|
|
21
21
|
getRemult: (req) => server.getRemult(req),
|
|
22
22
|
openApiDoc: (options) => server.openApiDoc(options),
|
|
23
23
|
withRemult: (req, res, next) => server.withRemult(req, res, next),
|
|
24
|
-
// [ ]
|
|
24
|
+
// [ ] V1.5 add with remult promise
|
|
25
25
|
});
|
|
26
26
|
}
|
package/esm/remult-knex/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { getRepository, isAutoIncrement, } from '../src/remult3/RepositoryImplem
|
|
|
7
7
|
import { Sort } from '../src/sort';
|
|
8
8
|
import { ValueConverters } from '../src/valueConverters';
|
|
9
9
|
import { resultCompoundIdFilter as resultCompoundIdFilter } from '../src/resultCompoundIdFilter';
|
|
10
|
+
import { getRepositoryInternals } from '../src/remult3/repository-internals';
|
|
10
11
|
export class KnexDataProvider {
|
|
11
12
|
knex;
|
|
12
13
|
constructor(knex) {
|
|
@@ -54,7 +55,7 @@ export class KnexDataProvider {
|
|
|
54
55
|
const repo = getRepository(entity);
|
|
55
56
|
var b = new FilterConsumerBridgeToKnexRequest(await dbNamesOf(repo.metadata));
|
|
56
57
|
b._addWhere = false;
|
|
57
|
-
await (await repo.translateWhereToFilter(condition)).__applyToConsumer(b);
|
|
58
|
+
await (await getRepositoryInternals(repo).translateWhereToFilter(condition)).__applyToConsumer(b);
|
|
58
59
|
let r = await b.resolveWhere();
|
|
59
60
|
return (knex) => r.forEach((y) => y(knex));
|
|
60
61
|
}
|
package/esm/remult-mongo.js
CHANGED
|
@@ -3,6 +3,7 @@ import { dbNamesOf } from './src/filter/filter-consumer-bridge-to-sql-request';
|
|
|
3
3
|
import { remult as remultContext } from './src/remult-proxy';
|
|
4
4
|
import { getRepository } from './src/remult3/RepositoryImplementation';
|
|
5
5
|
import { resultCompoundIdFilter } from './src/resultCompoundIdFilter';
|
|
6
|
+
import { getRepositoryInternals } from './src/remult3/repository-internals';
|
|
6
7
|
export class MongoDataProvider {
|
|
7
8
|
db;
|
|
8
9
|
client;
|
|
@@ -50,7 +51,7 @@ export class MongoDataProvider {
|
|
|
50
51
|
const repo = getRepository(entity);
|
|
51
52
|
var b = new FilterConsumerBridgeToMongo(await dbNamesOf(repo.metadata));
|
|
52
53
|
b._addWhere = false;
|
|
53
|
-
await (await repo.translateWhereToFilter(condition)).__applyToConsumer(b);
|
|
54
|
+
await (await getRepositoryInternals(repo).translateWhereToFilter(condition)).__applyToConsumer(b);
|
|
54
55
|
let r = await b.resolveWhere();
|
|
55
56
|
return r;
|
|
56
57
|
}
|
|
@@ -116,7 +116,7 @@ export class RemultServerImplementation {
|
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
getEntities() {
|
|
119
|
-
//TODO - consider using entitiesMetaData - but it may require making it all awaitable
|
|
119
|
+
//TODO V2 - consider using entitiesMetaData - but it may require making it all awaitable
|
|
120
120
|
var r = new Remult();
|
|
121
121
|
return this.options.entities.map((x) => r.repo(x).metadata);
|
|
122
122
|
}
|
package/esm/src/column.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { idType } from './remult3/remult3';
|
|
2
|
-
import type { RepositoryImplementation } from './remult3/RepositoryImplementation';
|
|
1
|
+
import type { idType, Repository } from './remult3/remult3';
|
|
3
2
|
export declare function makeTitle(name: string): string;
|
|
4
3
|
export declare class LookupColumn<T> {
|
|
5
4
|
private repository;
|
|
@@ -13,7 +12,7 @@ export declare class LookupColumn<T> {
|
|
|
13
12
|
};
|
|
14
13
|
set(item: T): void;
|
|
15
14
|
id: idType<T>;
|
|
16
|
-
constructor(repository:
|
|
15
|
+
constructor(repository: Repository<T>, isReferenceRelation: any);
|
|
17
16
|
get item(): T;
|
|
18
17
|
waitLoad(): Promise<T>;
|
|
19
18
|
}
|
package/esm/src/column.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getEntityRef } from './remult3/getEntityRef';
|
|
2
|
+
import { getRepositoryInternals } from './remult3/repository-internals';
|
|
2
3
|
export function makeTitle(name) {
|
|
3
4
|
// insert a space before all caps
|
|
4
5
|
return (name
|
|
@@ -26,14 +27,14 @@ export class LookupColumn {
|
|
|
26
27
|
waitLoadOf(id) {
|
|
27
28
|
if (id === undefined || id === null)
|
|
28
29
|
return null;
|
|
29
|
-
return this.repository.getCachedByIdAsync(id, false);
|
|
30
|
+
return getRepositoryInternals(this.repository).getCachedByIdAsync(id, false);
|
|
30
31
|
}
|
|
31
32
|
get(id) {
|
|
32
33
|
if (id === undefined || id === null)
|
|
33
34
|
return null;
|
|
34
35
|
if (this.isReferenceRelation && !this.storedItem)
|
|
35
36
|
return undefined;
|
|
36
|
-
return this.repository.getCachedById(id, this.isReferenceRelation);
|
|
37
|
+
return getRepositoryInternals(this.repository).getCachedById(id, this.isReferenceRelation);
|
|
37
38
|
}
|
|
38
39
|
storedItem;
|
|
39
40
|
set(item) {
|
|
@@ -44,7 +45,7 @@ export class LookupColumn {
|
|
|
44
45
|
else {
|
|
45
46
|
let eo = getEntityRef(item, false);
|
|
46
47
|
if (eo && !this.isReferenceRelation) {
|
|
47
|
-
this.repository.addToCache(item);
|
|
48
|
+
getRepositoryInternals(this.repository).addToCache(item);
|
|
48
49
|
this.id = eo.getId();
|
|
49
50
|
}
|
|
50
51
|
else {
|
|
@@ -5,6 +5,7 @@ import { remult as defaultRemult } from '../remult-proxy';
|
|
|
5
5
|
import { getRepository } from '../remult3/RepositoryImplementation';
|
|
6
6
|
import { Sort } from '../sort';
|
|
7
7
|
import { ValueConverters } from '../valueConverters';
|
|
8
|
+
import { getRepositoryInternals } from '../remult3/repository-internals';
|
|
8
9
|
// @dynamic
|
|
9
10
|
export class SqlDatabase {
|
|
10
11
|
sql;
|
|
@@ -89,7 +90,7 @@ export class SqlDatabase {
|
|
|
89
90
|
const r = getRepository(repo);
|
|
90
91
|
var b = new FilterConsumerBridgeToSqlRequest(sqlCommand, await dbNamesOf(r.metadata));
|
|
91
92
|
b._addWhere = false;
|
|
92
|
-
await (await r.translateWhereToFilter(condition)).__applyToConsumer(b);
|
|
93
|
+
await (await getRepositoryInternals(r).translateWhereToFilter(condition)).__applyToConsumer(b);
|
|
93
94
|
return await b.resolveWhere();
|
|
94
95
|
}
|
|
95
96
|
/**
|
package/esm/src/entity.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { buildRestDataProvider } from '../buildRestDataProvider';
|
|
2
2
|
import { RestDataProvider } from '../data-providers/rest-data-provider';
|
|
3
|
+
import { getRepositoryInternals } from '../remult3/repository-internals';
|
|
3
4
|
import { liveQueryKeepAliveRoute, LiveQuerySubscriber, } from './SubscriptionChannel';
|
|
4
5
|
/* @internal*/
|
|
5
6
|
export class LiveQueryClient {
|
|
@@ -79,7 +80,7 @@ export class LiveQueryClient {
|
|
|
79
80
|
let onUnsubscribe = () => {
|
|
80
81
|
alive = false;
|
|
81
82
|
};
|
|
82
|
-
this.runPromise(repo
|
|
83
|
+
this.runPromise(getRepositoryInternals(repo)
|
|
83
84
|
.buildEntityDataProviderFindOptions(options)
|
|
84
85
|
.then((opts) => {
|
|
85
86
|
if (!alive)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { v4 as uuid } from 'uuid';
|
|
2
2
|
import { Sort } from '../sort';
|
|
3
3
|
import { remult as defaultRemult } from '../remult-proxy';
|
|
4
|
+
import { getRepositoryInternals } from '../remult3/repository-internals';
|
|
4
5
|
export const streamUrl = 'stream';
|
|
5
6
|
//@internal
|
|
6
7
|
export class LiveQuerySubscriber {
|
|
@@ -13,7 +14,7 @@ export class LiveQuerySubscriber {
|
|
|
13
14
|
subscribeCode;
|
|
14
15
|
unsubscribe = () => { };
|
|
15
16
|
async setAllItems(result) {
|
|
16
|
-
const items = await this.repo.fromJsonArray(result, this.query.options);
|
|
17
|
+
const items = await getRepositoryInternals(this.repo).fromJsonArray(result, this.query.options);
|
|
17
18
|
this.forListeners((listener) => {
|
|
18
19
|
listener(() => {
|
|
19
20
|
return items;
|
|
@@ -54,7 +55,7 @@ export class LiveQuerySubscriber {
|
|
|
54
55
|
async handle(messages) {
|
|
55
56
|
{
|
|
56
57
|
let x = messages.filter(({ type }) => type == 'add' || type == 'replace');
|
|
57
|
-
let loadedItems = await this.repo.fromJsonArray(x.map((m) => m.data.item), this.query.options);
|
|
58
|
+
let loadedItems = await getRepositoryInternals(this.repo).fromJsonArray(x.map((m) => m.data.item), this.query.options);
|
|
58
59
|
for (let index = 0; index < x.length; index++) {
|
|
59
60
|
const element = x[index];
|
|
60
61
|
element.data.item = loadedItems[index];
|
package/esm/src/remult-proxy.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getInternalKey } from './remult3/repository-internals';
|
|
1
2
|
let defaultRemult;
|
|
2
3
|
function defaultFactory() {
|
|
3
4
|
if (!defaultRemult) {
|
|
@@ -81,6 +82,11 @@ export class RemultProxy {
|
|
|
81
82
|
get fields() {
|
|
82
83
|
return self.remultFactory().repo(...args).metadata.fields;
|
|
83
84
|
},
|
|
85
|
+
[getInternalKey]() {
|
|
86
|
+
return self
|
|
87
|
+
.remultFactory()
|
|
88
|
+
.repo(...args)[getInternalKey]();
|
|
89
|
+
},
|
|
84
90
|
relations: (args2) => self
|
|
85
91
|
.remultFactory()
|
|
86
92
|
.repo(...args)
|
|
@@ -138,10 +144,6 @@ export class RemultProxy {
|
|
|
138
144
|
.remultFactory()
|
|
139
145
|
.repo(...args)
|
|
140
146
|
.liveQuery(...args2),
|
|
141
|
-
//@ts-ignore
|
|
142
|
-
addToCache: (a) => self
|
|
143
|
-
.remultFactory()
|
|
144
|
-
.repo(...args).addToCache(a),
|
|
145
147
|
get metadata() {
|
|
146
148
|
return self.remultFactory().repo(...args).metadata;
|
|
147
149
|
},
|
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
import type { ClassType } from '../../classType';
|
|
2
2
|
import type { FieldOptions } from '../column-interfaces';
|
|
3
3
|
import type { Remult } from '../context';
|
|
4
|
-
import type { FindOptions, RelationOptions } from './remult3';
|
|
5
|
-
import { type ClassFieldDecoratorContextStub } from './RepositoryImplementation';
|
|
4
|
+
import type { FindOptions, RelationOptions, ClassFieldDecorator, ClassFieldDecoratorContextStub } from './remult3';
|
|
6
5
|
export declare class Fields {
|
|
7
6
|
/**
|
|
8
7
|
* Stored as a JSON.stringify - to store as json use Fields.json
|
|
9
8
|
*/
|
|
10
|
-
static object<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]):
|
|
11
|
-
static json<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]):
|
|
12
|
-
static dateOnly<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]):
|
|
13
|
-
static date<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]):
|
|
14
|
-
static integer<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]):
|
|
15
|
-
static autoIncrement<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]):
|
|
16
|
-
static number<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]):
|
|
17
|
-
static createdAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]):
|
|
18
|
-
static updatedAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]):
|
|
19
|
-
static uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]):
|
|
20
|
-
static cuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]):
|
|
21
|
-
static string<entityType = any>(...options: (StringFieldOptions<entityType> | ((options: StringFieldOptions<entityType>, remult: Remult) => void))[]):
|
|
22
|
-
static boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]):
|
|
9
|
+
static object<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
|
|
10
|
+
static json<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
|
|
11
|
+
static dateOnly<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
12
|
+
static date<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
13
|
+
static integer<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
|
|
14
|
+
static autoIncrement<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
|
|
15
|
+
static number<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
|
|
16
|
+
static createdAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
17
|
+
static updatedAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
18
|
+
static uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
|
|
19
|
+
static cuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
|
|
20
|
+
static string<entityType = any>(...options: (StringFieldOptions<entityType> | ((options: StringFieldOptions<entityType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
|
|
21
|
+
static boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, boolean | undefined>;
|
|
23
22
|
}
|
|
24
23
|
export declare class Relations {
|
|
25
|
-
|
|
26
|
-
static
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
/** A to one relation with an automatically generated field */
|
|
25
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: FieldOptions<entityType, toEntityType> & Pick<RelationOptions<entityType, toEntityType, any, any>, 'defaultIncluded'>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
26
|
+
/** A to one relation with fields defined in the second parameter */
|
|
27
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInMyEntity?: keyof entityType): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
28
|
+
/** A to one relation with fields defined in the field/fields parameter */
|
|
29
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: Omit<RelationOptions<entityType, toEntityType, entityType>, keyof Pick<RelationOptions<entityType, toEntityType, entityType>, 'field'>>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
30
|
+
/** A to one relation with fields defined in the field/fields parameter */
|
|
31
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: Omit<RelationOptions<entityType, toEntityType, entityType>, keyof Pick<RelationOptions<entityType, toEntityType, entityType>, 'fields'>>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
32
|
+
static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInToEntity?: keyof toEntityType): ClassFieldDecorator<entityType, toEntityType[] | undefined>;
|
|
33
|
+
static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>>): ClassFieldDecorator<entityType, toEntityType[] | undefined>;
|
|
29
34
|
}
|
|
30
35
|
/**Decorates fields that should be used as fields.
|
|
31
36
|
* for more info see: [Field Types](https://remult.dev/docs/field-types.html)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createId } from '@paralleldrive/cuid2';
|
|
2
2
|
import { v4 as uuid } from 'uuid';
|
|
3
3
|
import { ValueConverters } from '../valueConverters';
|
|
4
|
-
import { buildOptions, columnsOfType
|
|
4
|
+
import { buildOptions, columnsOfType } from './RepositoryImplementation';
|
|
5
5
|
import { relationInfoMember } from './relationInfoMember';
|
|
6
6
|
export class Fields {
|
|
7
7
|
/**
|
|
@@ -193,6 +193,3 @@ export function checkTarget(target) {
|
|
|
193
193
|
if (!target)
|
|
194
194
|
throw new Error("Set the 'experimentalDecorators:true' option in your 'tsconfig' or 'jsconfig' (target undefined)");
|
|
195
195
|
}
|
|
196
|
-
//[ ] I think JY finds it confusing that the field options and relation options are together - but I still think it's good - not sure if it's a transition faze or not
|
|
197
|
-
//[ ] I wish that when you define a toOne we automagically get the toMany on the other side! 😉
|
|
198
|
-
//[ ] implement to many inference based on to one
|
|
@@ -10,12 +10,14 @@ import type { DataProvider, EntityDataProvider, EntityDataProviderFindOptions, E
|
|
|
10
10
|
import type { Unsubscribe } from '../live-query/SubscriptionChannel';
|
|
11
11
|
import type { columnInfo } from './columnInfo';
|
|
12
12
|
import { RelationLoader } from './relation-loader';
|
|
13
|
+
import { getInternalKey } from './repository-internals';
|
|
13
14
|
export declare class RepositoryImplementation<entityType> implements Repository<entityType> {
|
|
14
15
|
private entity;
|
|
15
16
|
remult: Remult;
|
|
16
17
|
private dataProvider;
|
|
17
18
|
private _info;
|
|
18
19
|
private defaultFindOptions?;
|
|
20
|
+
[getInternalKey](): this;
|
|
19
21
|
createAfterFilter(orderBy: EntityOrderBy<entityType>, lastRow: entityType): Promise<EntityFilter<entityType>>;
|
|
20
22
|
relations(item: entityType): RepositoryRelations<entityType>;
|
|
21
23
|
private __edp;
|
|
@@ -252,17 +254,6 @@ export declare class ValueListInfo<T extends ValueListItem> implements ValueConv
|
|
|
252
254
|
export declare function getValueList<T>(field: FieldRef<T>): T[];
|
|
253
255
|
export declare function getValueList<T>(field: FieldMetadata<T>): T[];
|
|
254
256
|
export declare function getValueList<T>(type: ClassType<T>): T[];
|
|
255
|
-
export interface ClassFieldDecoratorContextStub<entityType, valueType> {
|
|
256
|
-
readonly access: {
|
|
257
|
-
set(object: entityType, value: valueType): void;
|
|
258
|
-
};
|
|
259
|
-
readonly name: string;
|
|
260
|
-
}
|
|
261
|
-
export interface ClassDecoratorContextStub<Class extends new (...args: any) => any = new (...args: any) => any> {
|
|
262
|
-
readonly kind: 'class';
|
|
263
|
-
readonly name: string | undefined;
|
|
264
|
-
addInitializer(initializer: (this: Class) => void): void;
|
|
265
|
-
}
|
|
266
257
|
export declare const storableMember: unique symbol;
|
|
267
258
|
export declare function buildOptions<entityType = any, valueType = any>(options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[], remult: Remult): FieldOptions<entityType, valueType>;
|
|
268
259
|
export declare function decorateColumnSettings<valueType>(settings: FieldOptions<any, valueType>, remult: Remult): FieldOptions<any, valueType>;
|
|
@@ -11,6 +11,7 @@ import { entityMember, getEntityKey, getEntityRef, getEntitySettings, } from './
|
|
|
11
11
|
import { __updateEntityBasedOnWhere } from './__updateEntityBasedOnWhere';
|
|
12
12
|
import { getRelationInfo, relationInfoMember } from './relationInfoMember';
|
|
13
13
|
import { RelationLoader } from './relation-loader';
|
|
14
|
+
import { getInternalKey } from './repository-internals';
|
|
14
15
|
//import { remult } from "../remult-proxy";
|
|
15
16
|
let classValidatorValidate = undefined;
|
|
16
17
|
// import ("class-validator".toString())
|
|
@@ -36,6 +37,9 @@ export class RepositoryImplementation {
|
|
|
36
37
|
dataProvider;
|
|
37
38
|
_info;
|
|
38
39
|
defaultFindOptions;
|
|
40
|
+
[getInternalKey]() {
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
39
43
|
async createAfterFilter(orderBy, lastRow) {
|
|
40
44
|
let values = new Map();
|
|
41
45
|
for (const s of Sort.translateOrderByToSort(this.metadata, orderBy)
|
|
@@ -350,9 +354,12 @@ export class RepositoryImplementation {
|
|
|
350
354
|
options.orderBy = this._info.entityInfo.defaultOrderBy;
|
|
351
355
|
}
|
|
352
356
|
opt.where = await this.translateWhereToFilter(options.where);
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
357
|
+
if (options.orderBy !== undefined)
|
|
358
|
+
opt.orderBy = Sort.translateOrderByToSort(this.metadata, options.orderBy);
|
|
359
|
+
if (options.limit !== undefined)
|
|
360
|
+
opt.limit = options.limit;
|
|
361
|
+
if (options.page !== undefined)
|
|
362
|
+
opt.page = options.page;
|
|
356
363
|
return opt;
|
|
357
364
|
}
|
|
358
365
|
async fromJsonArray(jsonItems, loadOptions) {
|
|
@@ -473,9 +480,14 @@ export class RepositoryImplementation {
|
|
|
473
480
|
findOptions[key] = source[key];
|
|
474
481
|
}
|
|
475
482
|
}
|
|
476
|
-
|
|
483
|
+
function buildError(what) {
|
|
484
|
+
return Error(`Error for relation: "${field.key}" to "${otherRepo.metadata.key}": ` +
|
|
485
|
+
what);
|
|
486
|
+
}
|
|
487
|
+
let hasFields = () => options.field || options.fields;
|
|
488
|
+
if (rel.type === 'toMany' && !hasFields()) {
|
|
477
489
|
for (const fieldInOtherRepo of otherRepo.fields.toArray()) {
|
|
478
|
-
if (!
|
|
490
|
+
if (!hasFields()) {
|
|
479
491
|
const reverseRel = getRelationInfo(fieldInOtherRepo.options);
|
|
480
492
|
const relOp = fieldInOtherRepo.options;
|
|
481
493
|
if (reverseRel)
|
|
@@ -497,17 +509,25 @@ export class RepositoryImplementation {
|
|
|
497
509
|
}
|
|
498
510
|
options = { ...options, fields };
|
|
499
511
|
}
|
|
500
|
-
else
|
|
501
|
-
throw Error(`Could not infer fields for the "toMany" relation named:${fieldInOtherRepo.key}. Please specify field/fields`);
|
|
502
512
|
}
|
|
503
513
|
}
|
|
504
514
|
}
|
|
515
|
+
if (!hasFields())
|
|
516
|
+
throw buildError(`No matching field found on target. Please specify field/fields`);
|
|
517
|
+
}
|
|
518
|
+
function requireField(field, meta) {
|
|
519
|
+
const result = meta.fields.find(field);
|
|
520
|
+
if (!result)
|
|
521
|
+
throw buildError(`Field "${field}" was not found in "${meta.key}".`);
|
|
522
|
+
return result;
|
|
505
523
|
}
|
|
506
524
|
if (options.field) {
|
|
507
525
|
if (rel.type === 'toOne') {
|
|
526
|
+
requireField(options.field, this.metadata);
|
|
508
527
|
where.push(otherRepo.metadata.idMetadata.getIdFilter(row[options.field]));
|
|
509
528
|
}
|
|
510
529
|
else {
|
|
530
|
+
requireField(options.field, otherRepo.metadata);
|
|
511
531
|
where.push({
|
|
512
532
|
[options.field]: this.metadata.idMetadata.getId(row),
|
|
513
533
|
});
|
|
@@ -516,13 +536,15 @@ export class RepositoryImplementation {
|
|
|
516
536
|
else if (options.fields) {
|
|
517
537
|
for (const key in options.fields) {
|
|
518
538
|
if (Object.prototype.hasOwnProperty.call(options.fields, key)) {
|
|
539
|
+
requireField(options.fields[key], this.metadata);
|
|
540
|
+
requireField(key, otherRepo.metadata);
|
|
519
541
|
where.push({ [key]: row[options.fields[key]] });
|
|
520
542
|
}
|
|
521
543
|
}
|
|
522
544
|
}
|
|
523
545
|
else if (rel.type === 'toOne' || rel.type === 'reference') {
|
|
524
546
|
let val = rel.type === 'reference'
|
|
525
|
-
? getEntityRef(row).fields.find(field.key).getId()
|
|
547
|
+
? getEntityRef(row).fields.find(requireField(field.key, this.metadata)).getId()
|
|
526
548
|
: row[field.key];
|
|
527
549
|
if (val === null)
|
|
528
550
|
returnNull = true;
|
|
@@ -1308,7 +1330,7 @@ export class rowHelperImplementation extends rowHelperBase {
|
|
|
1308
1330
|
}
|
|
1309
1331
|
async calcServerExpression() {
|
|
1310
1332
|
if (isBackend())
|
|
1311
|
-
//
|
|
1333
|
+
//y2 should be changed to be based on data provider - consider naming
|
|
1312
1334
|
for (const col of this.info.columnsInfo) {
|
|
1313
1335
|
if (col.serverExpression) {
|
|
1314
1336
|
this.instance[col.key] = await col.serverExpression(this.instance);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Remult } from '../context';
|
|
2
2
|
import type { EntityOptions } from '../entity';
|
|
3
|
-
import type { ClassDecoratorContextStub } from './
|
|
3
|
+
import type { ClassDecoratorContextStub } from './remult3';
|
|
4
4
|
/**Decorates classes that should be used as entities.
|
|
5
5
|
* Receives a key and an array of EntityOptions.
|
|
6
6
|
* @example
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { allEntities, setControllerSettings } from '../context';
|
|
2
2
|
import { entityInfo, entityInfo_key, getEntitySettings } from './getEntityRef';
|
|
3
|
-
//[ ] YONI - in Typescript 5 I do get the name of the class, what would we like to change because of that?
|
|
4
3
|
/**Decorates classes that should be used as entities.
|
|
5
4
|
* Receives a key and an array of EntityOptions.
|
|
6
5
|
* @example
|
|
@@ -422,7 +422,7 @@ export type RelationOptions<fromEntity, toEntity, matchIdEntity, optionsType ext
|
|
|
422
422
|
export type RelationOptionsBase<fromEntity, toEntity, optionsType extends LoadOptions<toEntity> = LoadOptions<toEntity>> = {
|
|
423
423
|
findOptions?: optionsType | ((entity: fromEntity) => optionsType);
|
|
424
424
|
defaultIncluded?: boolean;
|
|
425
|
-
} & FieldOptions
|
|
425
|
+
} & Pick<FieldOptions, 'caption'>;
|
|
426
426
|
export type ObjectMembersOnly<T> = {
|
|
427
427
|
[K in keyof Pick<T, {
|
|
428
428
|
[K in keyof T]: T[K] extends object | undefined | null ? T[K] extends Date | undefined | null ? never : K : never;
|
|
@@ -439,3 +439,15 @@ export type RepositoryRelations<entityType> = {
|
|
|
439
439
|
export declare type EntityIdFields<entityType> = {
|
|
440
440
|
[Properties in keyof Partial<OmitEB<entityType>>]?: true;
|
|
441
441
|
};
|
|
442
|
+
export interface ClassFieldDecoratorContextStub<entityType, valueType> {
|
|
443
|
+
readonly access: {
|
|
444
|
+
set(object: entityType, value: valueType): void;
|
|
445
|
+
};
|
|
446
|
+
readonly name: string;
|
|
447
|
+
}
|
|
448
|
+
export interface ClassDecoratorContextStub<Class extends new (...args: any) => any = new (...args: any) => any> {
|
|
449
|
+
readonly kind: 'class';
|
|
450
|
+
readonly name: string | undefined;
|
|
451
|
+
addInitializer(initializer: (this: Class) => void): void;
|
|
452
|
+
}
|
|
453
|
+
export type ClassFieldDecorator<entityType, valueType> = (target: any, context: string | ClassFieldDecoratorContextStub<entityType, valueType | undefined>, c?: any) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EntityDataProviderFindOptions } from '../data-interfaces';
|
|
2
|
+
import type { Filter } from '../filter/filter-interfaces';
|
|
3
|
+
import type { EntityFilter, EntityOrderBy, FindOptions, LoadOptions, Repository } from './remult3';
|
|
4
|
+
export interface RepositoryInternal<entityType> {
|
|
5
|
+
createAfterFilter(orderBy: EntityOrderBy<entityType>, lastRow: entityType): Promise<EntityFilter<entityType>>;
|
|
6
|
+
fromJsonArray(jsonItems: any[], loadOptions: LoadOptions<entityType>): Promise<entityType[]>;
|
|
7
|
+
buildEntityDataProviderFindOptions(options: FindOptions<entityType>): Promise<EntityDataProviderFindOptions>;
|
|
8
|
+
translateWhereToFilter(where: EntityFilter<entityType>): Promise<Filter>;
|
|
9
|
+
getCachedById(id: any, doNotLoadIfNotFound: boolean): entityType;
|
|
10
|
+
getCachedByIdAsync(id: any, doNotLoadIfNotFound: boolean): Promise<entityType>;
|
|
11
|
+
addToCache(item: entityType): any;
|
|
12
|
+
}
|
|
13
|
+
export declare function getRepositoryInternals<entityType>(repo: Repository<entityType>): RepositoryInternal<entityType>;
|
|
14
|
+
export declare const getInternalKey = "getInternal";
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClassType } from './classType';
|
|
2
|
-
export { OmitEB, FieldsMetadata, FieldRef, IdFieldRef, FieldsRef, EntityMetadata, EntityOrderBy, EntityFilter, FindOptions, QueryResult, QueryOptions, Repository, FindFirstOptions, ComparisonValueFilter, ValueFilter, IdFilter, ContainsStringValueFilter, EntityRef, SortSegments, Paginator, LiveQuery, LiveQueryChangeInfo, Subscribable, RefSubscriber, RefSubscriberBase, RelationOptions, RelationOptionsBase, ObjectMembersOnly, MembersToInclude, RepositoryRelations, EntityIdFields, } from './src/remult3/remult3';
|
|
2
|
+
export { OmitEB, FieldsMetadata, FieldRef, IdFieldRef, FieldsRef, EntityMetadata, EntityOrderBy, EntityFilter, FindOptions, QueryResult, QueryOptions, Repository, FindFirstOptions, ComparisonValueFilter, ValueFilter, IdFilter, ContainsStringValueFilter, EntityRef, SortSegments, Paginator, LiveQuery, LiveQueryChangeInfo, Subscribable, RefSubscriber, RefSubscriberBase, RelationOptions, RelationOptionsBase, ObjectMembersOnly, MembersToInclude, RepositoryRelations, EntityIdFields, ClassFieldDecorator as MemberDecorator, ClassFieldDecoratorContextStub, } from './src/remult3/remult3';
|
|
3
3
|
export { EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListFieldOptions, ValueListInfo, CaptionTransformer, } from './src/remult3/RepositoryImplementation';
|
|
4
4
|
export { Entity } from './src/remult3/entity';
|
|
5
5
|
export { getEntityRef } from './src/remult3/getEntityRef';
|
package/package.json
CHANGED
package/remult-express.js
CHANGED
|
@@ -28,7 +28,7 @@ function remultExpress(options) {
|
|
|
28
28
|
getRemult: function (req) { return server.getRemult(req); },
|
|
29
29
|
openApiDoc: function (options) { return server.openApiDoc(options); },
|
|
30
30
|
withRemult: function (req, res, next) { return server.withRemult(req, res, next); },
|
|
31
|
-
// [ ]
|
|
31
|
+
// [ ] V1.5 add with remult promise
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
exports.remultExpress = remultExpress;
|
package/remult-knex/index.js
CHANGED
|
@@ -11,6 +11,7 @@ var RepositoryImplementation_1 = require("../src/remult3/RepositoryImplementatio
|
|
|
11
11
|
var sort_1 = require("../src/sort");
|
|
12
12
|
var valueConverters_1 = require("../src/valueConverters");
|
|
13
13
|
var resultCompoundIdFilter_1 = require("../src/resultCompoundIdFilter");
|
|
14
|
+
var repository_internals_1 = require("../src/remult3/repository-internals");
|
|
14
15
|
var KnexDataProvider = /** @class */ (function () {
|
|
15
16
|
function KnexDataProvider(knex) {
|
|
16
17
|
this.knex = knex;
|
|
@@ -91,7 +92,7 @@ var KnexDataProvider = /** @class */ (function () {
|
|
|
91
92
|
case 1:
|
|
92
93
|
b = new (_a.apply(FilterConsumerBridgeToKnexRequest, [void 0, _b.sent()]))();
|
|
93
94
|
b._addWhere = false;
|
|
94
|
-
return [4 /*yield*/, repo.translateWhereToFilter(condition)];
|
|
95
|
+
return [4 /*yield*/, (0, repository_internals_1.getRepositoryInternals)(repo).translateWhereToFilter(condition)];
|
|
95
96
|
case 2: return [4 /*yield*/, (_b.sent()).__applyToConsumer(b)];
|
|
96
97
|
case 3:
|
|
97
98
|
_b.sent();
|
package/remult-mongo.js
CHANGED
|
@@ -7,6 +7,7 @@ var filter_consumer_bridge_to_sql_request_1 = require("./src/filter/filter-consu
|
|
|
7
7
|
var remult_proxy_1 = require("./src/remult-proxy");
|
|
8
8
|
var RepositoryImplementation_1 = require("./src/remult3/RepositoryImplementation");
|
|
9
9
|
var resultCompoundIdFilter_1 = require("./src/resultCompoundIdFilter");
|
|
10
|
+
var repository_internals_1 = require("./src/remult3/repository-internals");
|
|
10
11
|
var MongoDataProvider = /** @class */ (function () {
|
|
11
12
|
function MongoDataProvider(db, client, options) {
|
|
12
13
|
this.db = db;
|
|
@@ -80,7 +81,7 @@ var MongoDataProvider = /** @class */ (function () {
|
|
|
80
81
|
case 1:
|
|
81
82
|
b = new (_a.apply(FilterConsumerBridgeToMongo, [void 0, _b.sent()]))();
|
|
82
83
|
b._addWhere = false;
|
|
83
|
-
return [4 /*yield*/, repo.translateWhereToFilter(condition)];
|
|
84
|
+
return [4 /*yield*/, (0, repository_internals_1.getRepositoryInternals)(repo).translateWhereToFilter(condition)];
|
|
84
85
|
case 2: return [4 /*yield*/, (_b.sent()).__applyToConsumer(b)];
|
|
85
86
|
case 3:
|
|
86
87
|
_b.sent();
|
package/server/expressBridge.js
CHANGED
|
@@ -255,7 +255,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
255
255
|
});
|
|
256
256
|
};
|
|
257
257
|
RemultServerImplementation.prototype.getEntities = function () {
|
|
258
|
-
//TODO - consider using entitiesMetaData - but it may require making it all awaitable
|
|
258
|
+
//TODO V2 - consider using entitiesMetaData - but it may require making it all awaitable
|
|
259
259
|
var r = new context_1.Remult();
|
|
260
260
|
return this.options.entities.map(function (x) { return r.repo(x).metadata; });
|
|
261
261
|
};
|
package/src/column.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { idType } from './remult3/remult3';
|
|
2
|
-
import type { RepositoryImplementation } from './remult3/RepositoryImplementation';
|
|
1
|
+
import type { idType, Repository } from './remult3/remult3';
|
|
3
2
|
export declare function makeTitle(name: string): string;
|
|
4
3
|
export declare class LookupColumn<T> {
|
|
5
4
|
private repository;
|
|
@@ -13,7 +12,7 @@ export declare class LookupColumn<T> {
|
|
|
13
12
|
};
|
|
14
13
|
set(item: T): void;
|
|
15
14
|
id: idType<T>;
|
|
16
|
-
constructor(repository:
|
|
15
|
+
constructor(repository: Repository<T>, isReferenceRelation: any);
|
|
17
16
|
get item(): T;
|
|
18
17
|
waitLoad(): Promise<T>;
|
|
19
18
|
}
|
package/src/column.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LookupColumn = exports.makeTitle = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var getEntityRef_1 = require("./remult3/getEntityRef");
|
|
6
|
+
var repository_internals_1 = require("./remult3/repository-internals");
|
|
6
7
|
function makeTitle(name) {
|
|
7
8
|
// insert a space before all caps
|
|
8
9
|
return (name
|
|
@@ -33,14 +34,14 @@ var LookupColumn = /** @class */ (function () {
|
|
|
33
34
|
LookupColumn.prototype.waitLoadOf = function (id) {
|
|
34
35
|
if (id === undefined || id === null)
|
|
35
36
|
return null;
|
|
36
|
-
return this.repository.getCachedByIdAsync(id, false);
|
|
37
|
+
return (0, repository_internals_1.getRepositoryInternals)(this.repository).getCachedByIdAsync(id, false);
|
|
37
38
|
};
|
|
38
39
|
LookupColumn.prototype.get = function (id) {
|
|
39
40
|
if (id === undefined || id === null)
|
|
40
41
|
return null;
|
|
41
42
|
if (this.isReferenceRelation && !this.storedItem)
|
|
42
43
|
return undefined;
|
|
43
|
-
return this.repository.getCachedById(id, this.isReferenceRelation);
|
|
44
|
+
return (0, repository_internals_1.getRepositoryInternals)(this.repository).getCachedById(id, this.isReferenceRelation);
|
|
44
45
|
};
|
|
45
46
|
LookupColumn.prototype.set = function (item) {
|
|
46
47
|
this.storedItem = undefined;
|
|
@@ -50,7 +51,7 @@ var LookupColumn = /** @class */ (function () {
|
|
|
50
51
|
else {
|
|
51
52
|
var eo = (0, getEntityRef_1.getEntityRef)(item, false);
|
|
52
53
|
if (eo && !this.isReferenceRelation) {
|
|
53
|
-
this.repository.addToCache(item);
|
|
54
|
+
(0, repository_internals_1.getRepositoryInternals)(this.repository).addToCache(item);
|
|
54
55
|
this.id = eo.getId();
|
|
55
56
|
}
|
|
56
57
|
else {
|
|
@@ -9,6 +9,7 @@ var remult_proxy_1 = require("../remult-proxy");
|
|
|
9
9
|
var RepositoryImplementation_1 = require("../remult3/RepositoryImplementation");
|
|
10
10
|
var sort_1 = require("../sort");
|
|
11
11
|
var valueConverters_1 = require("../valueConverters");
|
|
12
|
+
var repository_internals_1 = require("../remult3/repository-internals");
|
|
12
13
|
// @dynamic
|
|
13
14
|
var SqlDatabase = /** @class */ (function () {
|
|
14
15
|
function SqlDatabase(sql) {
|
|
@@ -159,7 +160,7 @@ var SqlDatabase = /** @class */ (function () {
|
|
|
159
160
|
case 1:
|
|
160
161
|
b = new (_a.apply(filter_consumer_bridge_to_sql_request_1.FilterConsumerBridgeToSqlRequest, _b.concat([_c.sent()])))();
|
|
161
162
|
b._addWhere = false;
|
|
162
|
-
return [4 /*yield*/, r.translateWhereToFilter(condition)];
|
|
163
|
+
return [4 /*yield*/, (0, repository_internals_1.getRepositoryInternals)(r).translateWhereToFilter(condition)];
|
|
163
164
|
case 2: return [4 /*yield*/, (_c.sent()).__applyToConsumer(b)];
|
|
164
165
|
case 3:
|
|
165
166
|
_c.sent();
|
package/src/entity.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.LiveQueryClient = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var buildRestDataProvider_1 = require("../buildRestDataProvider");
|
|
6
6
|
var rest_data_provider_1 = require("../data-providers/rest-data-provider");
|
|
7
|
+
var repository_internals_1 = require("../remult3/repository-internals");
|
|
7
8
|
var SubscriptionChannel_1 = require("./SubscriptionChannel");
|
|
8
9
|
/* @internal*/
|
|
9
10
|
var LiveQueryClient = /** @class */ (function () {
|
|
@@ -100,7 +101,7 @@ var LiveQueryClient = /** @class */ (function () {
|
|
|
100
101
|
var onUnsubscribe = function () {
|
|
101
102
|
alive = false;
|
|
102
103
|
};
|
|
103
|
-
this.runPromise(repo
|
|
104
|
+
this.runPromise((0, repository_internals_1.getRepositoryInternals)(repo)
|
|
104
105
|
.buildEntityDataProviderFindOptions(options)
|
|
105
106
|
.then(function (opts) {
|
|
106
107
|
if (!alive)
|
|
@@ -5,6 +5,7 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
var uuid_1 = require("uuid");
|
|
6
6
|
var sort_1 = require("../sort");
|
|
7
7
|
var remult_proxy_1 = require("../remult-proxy");
|
|
8
|
+
var repository_internals_1 = require("../remult3/repository-internals");
|
|
8
9
|
exports.streamUrl = 'stream';
|
|
9
10
|
//@internal
|
|
10
11
|
var LiveQuerySubscriber = /** @class */ (function () {
|
|
@@ -27,7 +28,7 @@ var LiveQuerySubscriber = /** @class */ (function () {
|
|
|
27
28
|
var items;
|
|
28
29
|
return tslib_1.__generator(this, function (_a) {
|
|
29
30
|
switch (_a.label) {
|
|
30
|
-
case 0: return [4 /*yield*/, this.repo.fromJsonArray(result, this.query.options)];
|
|
31
|
+
case 0: return [4 /*yield*/, (0, repository_internals_1.getRepositoryInternals)(this.repo).fromJsonArray(result, this.query.options)];
|
|
31
32
|
case 1:
|
|
32
33
|
items = _a.sent();
|
|
33
34
|
this.forListeners(function (listener) {
|
|
@@ -97,7 +98,7 @@ var LiveQuerySubscriber = /** @class */ (function () {
|
|
|
97
98
|
var type = _a.type;
|
|
98
99
|
return type == 'add' || type == 'replace';
|
|
99
100
|
});
|
|
100
|
-
return [4 /*yield*/, this.repo.fromJsonArray(x.map(function (m) { return m.data.item; }), this.query.options)];
|
|
101
|
+
return [4 /*yield*/, (0, repository_internals_1.getRepositoryInternals)(this.repo).fromJsonArray(x.map(function (m) { return m.data.item; }), this.query.options)];
|
|
101
102
|
case 1:
|
|
102
103
|
loadedItems = _a.sent();
|
|
103
104
|
for (index = 0; index < x.length; index++) {
|
package/src/remult-proxy.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.remult = exports.RemultProxy = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
+
var repository_internals_1 = require("./remult3/repository-internals");
|
|
5
6
|
var defaultRemult;
|
|
6
7
|
function defaultFactory() {
|
|
7
8
|
if (!defaultRemult) {
|
|
@@ -18,6 +19,7 @@ var RemultProxy = /** @class */ (function () {
|
|
|
18
19
|
this.repoCache = new Map();
|
|
19
20
|
//@ts-ignore
|
|
20
21
|
this.repo = function () {
|
|
22
|
+
var _a;
|
|
21
23
|
var args = [];
|
|
22
24
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
23
25
|
args[_i] = arguments[_i];
|
|
@@ -30,24 +32,31 @@ var RemultProxy = /** @class */ (function () {
|
|
|
30
32
|
var result = entityCache.get(args[1]);
|
|
31
33
|
if (result)
|
|
32
34
|
return result;
|
|
33
|
-
result = {
|
|
34
|
-
|
|
35
|
+
result = (_a = {
|
|
36
|
+
get fields() {
|
|
37
|
+
var _a;
|
|
38
|
+
return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).metadata.fields;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
_a[repository_internals_1.getInternalKey] = function () {
|
|
35
42
|
var _a;
|
|
36
|
-
return (_a = self
|
|
43
|
+
return (_a = self
|
|
44
|
+
.remultFactory())
|
|
45
|
+
.repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false))[repository_internals_1.getInternalKey]();
|
|
37
46
|
},
|
|
38
|
-
relations
|
|
47
|
+
_a.relations = function (args2) {
|
|
39
48
|
var _a;
|
|
40
49
|
return (_a = self
|
|
41
50
|
.remultFactory())
|
|
42
51
|
.repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).relations(args2);
|
|
43
52
|
},
|
|
44
|
-
validate
|
|
53
|
+
_a.validate = function (a, b) {
|
|
45
54
|
var _a;
|
|
46
55
|
return (_a = self
|
|
47
56
|
.remultFactory())
|
|
48
57
|
.repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).validate(a, b);
|
|
49
58
|
},
|
|
50
|
-
addEventListener
|
|
59
|
+
_a.addEventListener = function () {
|
|
51
60
|
var _a, _b;
|
|
52
61
|
var args2 = [];
|
|
53
62
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -58,7 +67,7 @@ var RemultProxy = /** @class */ (function () {
|
|
|
58
67
|
.repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
|
|
59
68
|
.addEventListener.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
|
|
60
69
|
},
|
|
61
|
-
count
|
|
70
|
+
_a.count = function () {
|
|
62
71
|
var _a, _b;
|
|
63
72
|
var args2 = [];
|
|
64
73
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -69,7 +78,7 @@ var RemultProxy = /** @class */ (function () {
|
|
|
69
78
|
.repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
|
|
70
79
|
.count.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
|
|
71
80
|
},
|
|
72
|
-
create
|
|
81
|
+
_a.create = function () {
|
|
73
82
|
var _a, _b;
|
|
74
83
|
var args2 = [];
|
|
75
84
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -80,13 +89,13 @@ var RemultProxy = /** @class */ (function () {
|
|
|
80
89
|
.repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
|
|
81
90
|
.create.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
|
|
82
91
|
},
|
|
83
|
-
delete
|
|
92
|
+
_a.delete = function (args2) {
|
|
84
93
|
var _a;
|
|
85
94
|
return (_a = self
|
|
86
95
|
.remultFactory())
|
|
87
96
|
.repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).delete(args2);
|
|
88
97
|
},
|
|
89
|
-
find
|
|
98
|
+
_a.find = function () {
|
|
90
99
|
var _a, _b;
|
|
91
100
|
var args2 = [];
|
|
92
101
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -97,7 +106,7 @@ var RemultProxy = /** @class */ (function () {
|
|
|
97
106
|
.repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
|
|
98
107
|
.find.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
|
|
99
108
|
},
|
|
100
|
-
findFirst
|
|
109
|
+
_a.findFirst = function () {
|
|
101
110
|
var _a, _b;
|
|
102
111
|
var args2 = [];
|
|
103
112
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -108,26 +117,26 @@ var RemultProxy = /** @class */ (function () {
|
|
|
108
117
|
.repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
|
|
109
118
|
.findFirst.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
|
|
110
119
|
},
|
|
111
|
-
findId
|
|
120
|
+
_a.findId = function (a, b) {
|
|
112
121
|
var _a;
|
|
113
122
|
return (_a = self
|
|
114
123
|
.remultFactory())
|
|
115
124
|
.repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).findId(a, b);
|
|
116
125
|
},
|
|
117
126
|
//@ts-ignore
|
|
118
|
-
toJson
|
|
127
|
+
_a.toJson = function (json) {
|
|
119
128
|
var _a;
|
|
120
129
|
return (_a = self
|
|
121
130
|
.remultFactory())
|
|
122
131
|
.repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).toJson(json);
|
|
123
132
|
},
|
|
124
|
-
fromJson
|
|
133
|
+
_a.fromJson = function (item, isNew) {
|
|
125
134
|
var _a;
|
|
126
135
|
return (_a = self
|
|
127
136
|
.remultFactory())
|
|
128
137
|
.repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).fromJson(item, isNew);
|
|
129
138
|
},
|
|
130
|
-
getEntityRef
|
|
139
|
+
_a.getEntityRef = function () {
|
|
131
140
|
var _a, _b;
|
|
132
141
|
var args2 = [];
|
|
133
142
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -138,13 +147,13 @@ var RemultProxy = /** @class */ (function () {
|
|
|
138
147
|
.repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
|
|
139
148
|
.getEntityRef.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
|
|
140
149
|
},
|
|
141
|
-
insert
|
|
150
|
+
_a.insert = function (args2) {
|
|
142
151
|
var _a;
|
|
143
152
|
return (_a = self
|
|
144
153
|
.remultFactory())
|
|
145
154
|
.repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).insert(args2);
|
|
146
155
|
},
|
|
147
|
-
liveQuery
|
|
156
|
+
_a.liveQuery = function () {
|
|
148
157
|
var _a, _b;
|
|
149
158
|
var args2 = [];
|
|
150
159
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -155,18 +164,15 @@ var RemultProxy = /** @class */ (function () {
|
|
|
155
164
|
.repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
|
|
156
165
|
.liveQuery.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
|
|
157
166
|
},
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).metadata;
|
|
168
|
-
},
|
|
169
|
-
query: function () {
|
|
167
|
+
Object.defineProperty(_a, "metadata", {
|
|
168
|
+
get: function () {
|
|
169
|
+
var _a;
|
|
170
|
+
return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).metadata;
|
|
171
|
+
},
|
|
172
|
+
enumerable: false,
|
|
173
|
+
configurable: true
|
|
174
|
+
}),
|
|
175
|
+
_a.query = function () {
|
|
170
176
|
var _a, _b;
|
|
171
177
|
var args2 = [];
|
|
172
178
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -177,19 +183,19 @@ var RemultProxy = /** @class */ (function () {
|
|
|
177
183
|
.repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
|
|
178
184
|
.query.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
|
|
179
185
|
},
|
|
180
|
-
save
|
|
186
|
+
_a.save = function (args2) {
|
|
181
187
|
var _a;
|
|
182
188
|
return (_a = self
|
|
183
189
|
.remultFactory())
|
|
184
190
|
.repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).save(args2);
|
|
185
191
|
},
|
|
186
|
-
update
|
|
192
|
+
_a.update = function (a, b) {
|
|
187
193
|
var _a;
|
|
188
194
|
return (_a = self
|
|
189
195
|
.remultFactory())
|
|
190
196
|
.repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).update(a, b);
|
|
191
197
|
},
|
|
192
|
-
|
|
198
|
+
_a);
|
|
193
199
|
entityCache.set(args[1], result);
|
|
194
200
|
return result;
|
|
195
201
|
};
|
package/src/remult3/Fields.d.ts
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
import type { ClassType } from '../../classType';
|
|
2
2
|
import type { FieldOptions } from '../column-interfaces';
|
|
3
3
|
import type { Remult } from '../context';
|
|
4
|
-
import type { FindOptions, RelationOptions } from './remult3';
|
|
5
|
-
import { type ClassFieldDecoratorContextStub } from './RepositoryImplementation';
|
|
4
|
+
import type { FindOptions, RelationOptions, ClassFieldDecorator, ClassFieldDecoratorContextStub } from './remult3';
|
|
6
5
|
export declare class Fields {
|
|
7
6
|
/**
|
|
8
7
|
* Stored as a JSON.stringify - to store as json use Fields.json
|
|
9
8
|
*/
|
|
10
|
-
static object<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]):
|
|
11
|
-
static json<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]):
|
|
12
|
-
static dateOnly<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]):
|
|
13
|
-
static date<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]):
|
|
14
|
-
static integer<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]):
|
|
15
|
-
static autoIncrement<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]):
|
|
16
|
-
static number<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]):
|
|
17
|
-
static createdAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]):
|
|
18
|
-
static updatedAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]):
|
|
19
|
-
static uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]):
|
|
20
|
-
static cuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]):
|
|
21
|
-
static string<entityType = any>(...options: (StringFieldOptions<entityType> | ((options: StringFieldOptions<entityType>, remult: Remult) => void))[]):
|
|
22
|
-
static boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]):
|
|
9
|
+
static object<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
|
|
10
|
+
static json<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
|
|
11
|
+
static dateOnly<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
12
|
+
static date<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
13
|
+
static integer<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
|
|
14
|
+
static autoIncrement<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
|
|
15
|
+
static number<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
|
|
16
|
+
static createdAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
17
|
+
static updatedAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
18
|
+
static uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
|
|
19
|
+
static cuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
|
|
20
|
+
static string<entityType = any>(...options: (StringFieldOptions<entityType> | ((options: StringFieldOptions<entityType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
|
|
21
|
+
static boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, boolean | undefined>;
|
|
23
22
|
}
|
|
24
23
|
export declare class Relations {
|
|
25
|
-
|
|
26
|
-
static
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
/** A to one relation with an automatically generated field */
|
|
25
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: FieldOptions<entityType, toEntityType> & Pick<RelationOptions<entityType, toEntityType, any, any>, 'defaultIncluded'>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
26
|
+
/** A to one relation with fields defined in the second parameter */
|
|
27
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInMyEntity?: keyof entityType): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
28
|
+
/** A to one relation with fields defined in the field/fields parameter */
|
|
29
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: Omit<RelationOptions<entityType, toEntityType, entityType>, keyof Pick<RelationOptions<entityType, toEntityType, entityType>, 'field'>>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
30
|
+
/** A to one relation with fields defined in the field/fields parameter */
|
|
31
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: Omit<RelationOptions<entityType, toEntityType, entityType>, keyof Pick<RelationOptions<entityType, toEntityType, entityType>, 'fields'>>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
32
|
+
static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInToEntity?: keyof toEntityType): ClassFieldDecorator<entityType, toEntityType[] | undefined>;
|
|
33
|
+
static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>>): ClassFieldDecorator<entityType, toEntityType[] | undefined>;
|
|
29
34
|
}
|
|
30
35
|
/**Decorates fields that should be used as fields.
|
|
31
36
|
* for more info see: [Field Types](https://remult.dev/docs/field-types.html)
|
package/src/remult3/Fields.js
CHANGED
|
@@ -257,6 +257,3 @@ function checkTarget(target) {
|
|
|
257
257
|
throw new Error("Set the 'experimentalDecorators:true' option in your 'tsconfig' or 'jsconfig' (target undefined)");
|
|
258
258
|
}
|
|
259
259
|
exports.checkTarget = checkTarget;
|
|
260
|
-
//[ ] I think JY finds it confusing that the field options and relation options are together - but I still think it's good - not sure if it's a transition faze or not
|
|
261
|
-
//[ ] I wish that when you define a toOne we automagically get the toMany on the other side! 😉
|
|
262
|
-
//[ ] implement to many inference based on to one
|
|
@@ -10,12 +10,14 @@ import type { DataProvider, EntityDataProvider, EntityDataProviderFindOptions, E
|
|
|
10
10
|
import type { Unsubscribe } from '../live-query/SubscriptionChannel';
|
|
11
11
|
import type { columnInfo } from './columnInfo';
|
|
12
12
|
import { RelationLoader } from './relation-loader';
|
|
13
|
+
import { getInternalKey } from './repository-internals';
|
|
13
14
|
export declare class RepositoryImplementation<entityType> implements Repository<entityType> {
|
|
14
15
|
private entity;
|
|
15
16
|
remult: Remult;
|
|
16
17
|
private dataProvider;
|
|
17
18
|
private _info;
|
|
18
19
|
private defaultFindOptions?;
|
|
20
|
+
[getInternalKey](): this;
|
|
19
21
|
createAfterFilter(orderBy: EntityOrderBy<entityType>, lastRow: entityType): Promise<EntityFilter<entityType>>;
|
|
20
22
|
relations(item: entityType): RepositoryRelations<entityType>;
|
|
21
23
|
private __edp;
|
|
@@ -252,17 +254,6 @@ export declare class ValueListInfo<T extends ValueListItem> implements ValueConv
|
|
|
252
254
|
export declare function getValueList<T>(field: FieldRef<T>): T[];
|
|
253
255
|
export declare function getValueList<T>(field: FieldMetadata<T>): T[];
|
|
254
256
|
export declare function getValueList<T>(type: ClassType<T>): T[];
|
|
255
|
-
export interface ClassFieldDecoratorContextStub<entityType, valueType> {
|
|
256
|
-
readonly access: {
|
|
257
|
-
set(object: entityType, value: valueType): void;
|
|
258
|
-
};
|
|
259
|
-
readonly name: string;
|
|
260
|
-
}
|
|
261
|
-
export interface ClassDecoratorContextStub<Class extends new (...args: any) => any = new (...args: any) => any> {
|
|
262
|
-
readonly kind: 'class';
|
|
263
|
-
readonly name: string | undefined;
|
|
264
|
-
addInitializer(initializer: (this: Class) => void): void;
|
|
265
|
-
}
|
|
266
257
|
export declare const storableMember: unique symbol;
|
|
267
258
|
export declare function buildOptions<entityType = any, valueType = any>(options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[], remult: Remult): FieldOptions<entityType, valueType>;
|
|
268
259
|
export declare function decorateColumnSettings<valueType>(settings: FieldOptions<any, valueType>, remult: Remult): FieldOptions<any, valueType>;
|
|
@@ -15,6 +15,7 @@ var getEntityRef_1 = require("./getEntityRef");
|
|
|
15
15
|
var __updateEntityBasedOnWhere_1 = require("./__updateEntityBasedOnWhere");
|
|
16
16
|
var relationInfoMember_1 = require("./relationInfoMember");
|
|
17
17
|
var relation_loader_1 = require("./relation-loader");
|
|
18
|
+
var repository_internals_1 = require("./repository-internals");
|
|
18
19
|
//import { remult } from "../remult-proxy";
|
|
19
20
|
var classValidatorValidate = undefined;
|
|
20
21
|
// import ("class-validator".toString())
|
|
@@ -44,6 +45,9 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
44
45
|
this.idCache = new Map();
|
|
45
46
|
this.cache = new Map();
|
|
46
47
|
}
|
|
48
|
+
RepositoryImplementation.prototype[repository_internals_1.getInternalKey] = function () {
|
|
49
|
+
return this;
|
|
50
|
+
};
|
|
47
51
|
RepositoryImplementation.prototype.createAfterFilter = function (orderBy, lastRow) {
|
|
48
52
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
49
53
|
var values, _a, _b, s, existingVal, r, equalToColumn, _c, _d, s, f, equalToColumn_1, equalToColumn_1_1, c;
|
|
@@ -546,9 +550,12 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
546
550
|
return [4 /*yield*/, this.translateWhereToFilter(options.where)];
|
|
547
551
|
case 1:
|
|
548
552
|
_a.where = _b.sent();
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
553
|
+
if (options.orderBy !== undefined)
|
|
554
|
+
opt.orderBy = sort_1.Sort.translateOrderByToSort(this.metadata, options.orderBy);
|
|
555
|
+
if (options.limit !== undefined)
|
|
556
|
+
opt.limit = options.limit;
|
|
557
|
+
if (options.page !== undefined)
|
|
558
|
+
opt.page = options.page;
|
|
552
559
|
return [2 /*return*/, opt];
|
|
553
560
|
}
|
|
554
561
|
});
|
|
@@ -816,11 +823,16 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
816
823
|
}
|
|
817
824
|
finally { if (e_13) throw e_13.error; }
|
|
818
825
|
}
|
|
819
|
-
|
|
826
|
+
function buildError(what) {
|
|
827
|
+
return Error("Error for relation: \"".concat(field.key, "\" to \"").concat(otherRepo.metadata.key, "\": ") +
|
|
828
|
+
what);
|
|
829
|
+
}
|
|
830
|
+
var hasFields = function () { return options.field || options.fields; };
|
|
831
|
+
if (rel.type === 'toMany' && !hasFields()) {
|
|
820
832
|
try {
|
|
821
833
|
for (var _h = tslib_1.__values(otherRepo.fields.toArray()), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
822
834
|
var fieldInOtherRepo = _j.value;
|
|
823
|
-
if (!
|
|
835
|
+
if (!hasFields()) {
|
|
824
836
|
var reverseRel = (0, relationInfoMember_1.getRelationInfo)(fieldInOtherRepo.options);
|
|
825
837
|
var relOp = fieldInOtherRepo.options;
|
|
826
838
|
if (reverseRel)
|
|
@@ -842,8 +854,6 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
842
854
|
}
|
|
843
855
|
options = tslib_1.__assign(tslib_1.__assign({}, options), { fields: fields });
|
|
844
856
|
}
|
|
845
|
-
else
|
|
846
|
-
throw Error("Could not infer fields for the \"toMany\" relation named:".concat(fieldInOtherRepo.key, ". Please specify field/fields"));
|
|
847
857
|
}
|
|
848
858
|
}
|
|
849
859
|
}
|
|
@@ -855,12 +865,22 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
855
865
|
}
|
|
856
866
|
finally { if (e_15) throw e_15.error; }
|
|
857
867
|
}
|
|
868
|
+
if (!hasFields())
|
|
869
|
+
throw buildError("No matching field found on target. Please specify field/fields");
|
|
870
|
+
}
|
|
871
|
+
function requireField(field, meta) {
|
|
872
|
+
var result = meta.fields.find(field);
|
|
873
|
+
if (!result)
|
|
874
|
+
throw buildError("Field \"".concat(field, "\" was not found in \"").concat(meta.key, "\"."));
|
|
875
|
+
return result;
|
|
858
876
|
}
|
|
859
877
|
if (options.field) {
|
|
860
878
|
if (rel.type === 'toOne') {
|
|
879
|
+
requireField(options.field, this.metadata);
|
|
861
880
|
where.push(otherRepo.metadata.idMetadata.getIdFilter(row[options.field]));
|
|
862
881
|
}
|
|
863
882
|
else {
|
|
883
|
+
requireField(options.field, otherRepo.metadata);
|
|
864
884
|
where.push((_d = {},
|
|
865
885
|
_d[options.field] = this.metadata.idMetadata.getId(row),
|
|
866
886
|
_d));
|
|
@@ -869,13 +889,15 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
869
889
|
else if (options.fields) {
|
|
870
890
|
for (var key in options.fields) {
|
|
871
891
|
if (Object.prototype.hasOwnProperty.call(options.fields, key)) {
|
|
892
|
+
requireField(options.fields[key], this.metadata);
|
|
893
|
+
requireField(key, otherRepo.metadata);
|
|
872
894
|
where.push((_e = {}, _e[key] = row[options.fields[key]], _e));
|
|
873
895
|
}
|
|
874
896
|
}
|
|
875
897
|
}
|
|
876
898
|
else if (rel.type === 'toOne' || rel.type === 'reference') {
|
|
877
899
|
var val = rel.type === 'reference'
|
|
878
|
-
? (0, getEntityRef_1.getEntityRef)(row).fields.find(field.key).getId()
|
|
900
|
+
? (0, getEntityRef_1.getEntityRef)(row).fields.find(requireField(field.key, this.metadata)).getId()
|
|
879
901
|
: row[field.key];
|
|
880
902
|
if (val === null)
|
|
881
903
|
returnNull = true;
|
package/src/remult3/entity.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Remult } from '../context';
|
|
2
2
|
import type { EntityOptions } from '../entity';
|
|
3
|
-
import type { ClassDecoratorContextStub } from './
|
|
3
|
+
import type { ClassDecoratorContextStub } from './remult3';
|
|
4
4
|
/**Decorates classes that should be used as entities.
|
|
5
5
|
* Receives a key and an array of EntityOptions.
|
|
6
6
|
* @example
|
package/src/remult3/entity.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.Entity = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var context_1 = require("../context");
|
|
6
6
|
var getEntityRef_1 = require("./getEntityRef");
|
|
7
|
-
//[ ] YONI - in Typescript 5 I do get the name of the class, what would we like to change because of that?
|
|
8
7
|
/**Decorates classes that should be used as entities.
|
|
9
8
|
* Receives a key and an array of EntityOptions.
|
|
10
9
|
* @example
|
package/src/remult3/remult3.d.ts
CHANGED
|
@@ -422,7 +422,7 @@ export type RelationOptions<fromEntity, toEntity, matchIdEntity, optionsType ext
|
|
|
422
422
|
export type RelationOptionsBase<fromEntity, toEntity, optionsType extends LoadOptions<toEntity> = LoadOptions<toEntity>> = {
|
|
423
423
|
findOptions?: optionsType | ((entity: fromEntity) => optionsType);
|
|
424
424
|
defaultIncluded?: boolean;
|
|
425
|
-
} & FieldOptions
|
|
425
|
+
} & Pick<FieldOptions, 'caption'>;
|
|
426
426
|
export type ObjectMembersOnly<T> = {
|
|
427
427
|
[K in keyof Pick<T, {
|
|
428
428
|
[K in keyof T]: T[K] extends object | undefined | null ? T[K] extends Date | undefined | null ? never : K : never;
|
|
@@ -439,3 +439,15 @@ export type RepositoryRelations<entityType> = {
|
|
|
439
439
|
export declare type EntityIdFields<entityType> = {
|
|
440
440
|
[Properties in keyof Partial<OmitEB<entityType>>]?: true;
|
|
441
441
|
};
|
|
442
|
+
export interface ClassFieldDecoratorContextStub<entityType, valueType> {
|
|
443
|
+
readonly access: {
|
|
444
|
+
set(object: entityType, value: valueType): void;
|
|
445
|
+
};
|
|
446
|
+
readonly name: string;
|
|
447
|
+
}
|
|
448
|
+
export interface ClassDecoratorContextStub<Class extends new (...args: any) => any = new (...args: any) => any> {
|
|
449
|
+
readonly kind: 'class';
|
|
450
|
+
readonly name: string | undefined;
|
|
451
|
+
addInitializer(initializer: (this: Class) => void): void;
|
|
452
|
+
}
|
|
453
|
+
export type ClassFieldDecorator<entityType, valueType> = (target: any, context: string | ClassFieldDecoratorContextStub<entityType, valueType | undefined>, c?: any) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EntityDataProviderFindOptions } from '../data-interfaces';
|
|
2
|
+
import type { Filter } from '../filter/filter-interfaces';
|
|
3
|
+
import type { EntityFilter, EntityOrderBy, FindOptions, LoadOptions, Repository } from './remult3';
|
|
4
|
+
export interface RepositoryInternal<entityType> {
|
|
5
|
+
createAfterFilter(orderBy: EntityOrderBy<entityType>, lastRow: entityType): Promise<EntityFilter<entityType>>;
|
|
6
|
+
fromJsonArray(jsonItems: any[], loadOptions: LoadOptions<entityType>): Promise<entityType[]>;
|
|
7
|
+
buildEntityDataProviderFindOptions(options: FindOptions<entityType>): Promise<EntityDataProviderFindOptions>;
|
|
8
|
+
translateWhereToFilter(where: EntityFilter<entityType>): Promise<Filter>;
|
|
9
|
+
getCachedById(id: any, doNotLoadIfNotFound: boolean): entityType;
|
|
10
|
+
getCachedByIdAsync(id: any, doNotLoadIfNotFound: boolean): Promise<entityType>;
|
|
11
|
+
addToCache(item: entityType): any;
|
|
12
|
+
}
|
|
13
|
+
export declare function getRepositoryInternals<entityType>(repo: Repository<entityType>): RepositoryInternal<entityType>;
|
|
14
|
+
export declare const getInternalKey = "getInternal";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInternalKey = exports.getRepositoryInternals = void 0;
|
|
4
|
+
function getRepositoryInternals(repo) {
|
|
5
|
+
var x = repo;
|
|
6
|
+
if (typeof x[exports.getInternalKey] === 'function')
|
|
7
|
+
return x[exports.getInternalKey]();
|
|
8
|
+
throw Error('Error getting repository internal from ' + repo);
|
|
9
|
+
}
|
|
10
|
+
exports.getRepositoryInternals = getRepositoryInternals;
|
|
11
|
+
exports.getInternalKey = 'getInternal';
|