remult 0.23.0-exp.11 → 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.
Files changed (51) hide show
  1. package/esm/graphql.js +6 -0
  2. package/esm/index.d.ts +1 -1
  3. package/esm/internals.d.ts +1 -1
  4. package/esm/internals.js +1 -1
  5. package/esm/remult-express.js +1 -1
  6. package/esm/remult-knex/index.js +2 -1
  7. package/esm/remult-mongo.js +2 -1
  8. package/esm/server/expressBridge.js +1 -1
  9. package/esm/src/column.d.ts +2 -3
  10. package/esm/src/column.js +4 -3
  11. package/esm/src/data-providers/sql-database.js +2 -1
  12. package/esm/src/entity.js +0 -1
  13. package/esm/src/filter/filter-interfaces.js +2 -0
  14. package/esm/src/live-query/LiveQueryClient.js +2 -1
  15. package/esm/src/live-query/SubscriptionChannel.js +3 -2
  16. package/esm/src/remult-proxy.js +6 -4
  17. package/esm/src/remult3/Fields.d.ts +24 -19
  18. package/esm/src/remult3/Fields.js +1 -4
  19. package/esm/src/remult3/RepositoryImplementation.d.ts +2 -11
  20. package/esm/src/remult3/RepositoryImplementation.js +31 -9
  21. package/esm/src/remult3/entity.d.ts +1 -1
  22. package/esm/src/remult3/entity.js +0 -1
  23. package/esm/src/remult3/remult3.d.ts +13 -1
  24. package/esm/src/remult3/repository-internals.d.ts +14 -0
  25. package/esm/src/remult3/repository-internals.js +7 -0
  26. package/graphql.js +9 -1
  27. package/index.d.ts +1 -1
  28. package/internals.d.ts +1 -1
  29. package/internals.js +3 -1
  30. package/package.json +1 -1
  31. package/remult-express.js +1 -1
  32. package/remult-knex/index.js +2 -1
  33. package/remult-mongo.js +2 -1
  34. package/server/expressBridge.js +1 -1
  35. package/src/column.d.ts +2 -3
  36. package/src/column.js +4 -3
  37. package/src/data-providers/sql-database.js +2 -1
  38. package/src/entity.js +0 -1
  39. package/src/filter/filter-interfaces.js +2 -0
  40. package/src/live-query/LiveQueryClient.js +2 -1
  41. package/src/live-query/SubscriptionChannel.js +3 -2
  42. package/src/remult-proxy.js +38 -32
  43. package/src/remult3/Fields.d.ts +24 -19
  44. package/src/remult3/Fields.js +0 -3
  45. package/src/remult3/RepositoryImplementation.d.ts +2 -11
  46. package/src/remult3/RepositoryImplementation.js +30 -8
  47. package/src/remult3/entity.d.ts +1 -1
  48. package/src/remult3/entity.js +0 -1
  49. package/src/remult3/remult3.d.ts +13 -1
  50. package/src/remult3/repository-internals.d.ts +14 -0
  51. package/src/remult3/repository-internals.js +11 -0
package/esm/graphql.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { getRelationInfo } from './internals';
1
2
  import { Remult, remult } from './index';
2
3
  import { DataApi } from './src/data-api';
3
4
  const v2ConnectionAndPagination = false;
@@ -447,6 +448,11 @@ Select a dedicated page.`,
447
448
  }
448
449
  const whereTypeFields = [];
449
450
  for (const f of meta.fields) {
451
+ const ri = getRelationInfo(f.options);
452
+ // let's not consider toMany relations for now
453
+ if (ri?.type === 'toMany') {
454
+ break;
455
+ }
450
456
  if (f.options.includeInApi === false)
451
457
  continue;
452
458
  let type = 'String';
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';
@@ -1,5 +1,5 @@
1
1
  export { getRelationInfo } from './src/remult3/relationInfoMember';
2
- export { decorateColumnSettings } from './src/remult3/RepositoryImplementation';
2
+ export { decorateColumnSettings, controllerRefImpl, getControllerRef, } from './src/remult3/RepositoryImplementation';
3
3
  export { getEntitySettings } from './src/remult3/getEntityRef';
4
4
  export { __updateEntityBasedOnWhere } from './src/filter/filter-interfaces';
5
5
  export { actionInfo } from './src/server-action-info';
package/esm/internals.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { getRelationInfo } from './src/remult3/relationInfoMember';
2
- export { decorateColumnSettings } from './src/remult3/RepositoryImplementation';
2
+ export { decorateColumnSettings, controllerRefImpl, getControllerRef, } from './src/remult3/RepositoryImplementation';
3
3
  export { getEntitySettings } from './src/remult3/getEntityRef';
4
4
  export { __updateEntityBasedOnWhere } from './src/filter/filter-interfaces';
5
5
  export { actionInfo } from './src/server-action-info';
@@ -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
- // [ ]- add with remult promise
24
+ // [ ] V1.5 add with remult promise
25
25
  });
26
26
  }
@@ -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
  }
@@ -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
  }
@@ -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: RepositoryImplementation<T>, isReferenceRelation: any);
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,2 +1 @@
1
1
  export {};
2
- //[ ] make lazy only on field and not in Field Options
@@ -602,3 +602,5 @@ export function __updateEntityBasedOnWhere(entityDefs, where, r) {
602
602
  });
603
603
  }
604
604
  }
605
+ // toRaw of default remult threw and exception
606
+ // toRaw didn't respect
@@ -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];
@@ -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))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, valueType | undefined>, c?: any) => void;
11
- static json<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, valueType | undefined>, c?: any) => void;
12
- static dateOnly<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, Date | undefined>, c?: any) => void;
13
- static date<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, Date | undefined>, c?: any) => void;
14
- static integer<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, number | undefined>, c?: any) => void;
15
- static autoIncrement<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, number | undefined>, c?: any) => void;
16
- static number<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, number | undefined>, c?: any) => void;
17
- static createdAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, Date | undefined>, c?: any) => void;
18
- static updatedAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, Date | undefined>, c?: any) => void;
19
- static uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, string | undefined>, c?: any) => void;
20
- static cuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, string | undefined>, c?: any) => void;
21
- static string<entityType = any>(...options: (StringFieldOptions<entityType> | ((options: StringFieldOptions<entityType>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, string | undefined>, c?: any) => void;
22
- static boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, boolean | undefined>, c?: any) => 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
- static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: RelationOptions<entityType, toEntityType, entityType> | keyof entityType): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, toEntityType>, c?: any) => void;
26
- static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: (RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>> & {
27
- fromEntityType?: ClassType<entityType>;
28
- }) | keyof toEntityType): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, any>, c?: any) => void;
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, } from './RepositoryImplementation';
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
- opt.orderBy = Sort.translateOrderByToSort(this.metadata, options.orderBy);
354
- opt.limit = options.limit;
355
- opt.page = options.page;
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
- if (rel.type === 'toMany' && !options.field && !options.fields) {
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 (!options.field && !options.fields) {
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
- //[ ] should be changed to be based on data provider
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 './RepositoryImplementation';
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<fromEntity, toEntity>;
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,7 @@
1
+ export function getRepositoryInternals(repo) {
2
+ const x = repo;
3
+ if (typeof x[getInternalKey] === 'function')
4
+ return x[getInternalKey]();
5
+ throw Error('Error getting repository internal from ' + repo);
6
+ }
7
+ export const getInternalKey = 'getInternal';
package/graphql.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.translateWhereToRestBody = exports.remultGraphql = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ var internals_1 = require("./internals");
5
6
  var index_1 = require("./index");
6
7
  var data_api_1 = require("./src/data-api");
7
8
  var v2ConnectionAndPagination = false;
@@ -522,6 +523,11 @@ function remultGraphql(options) {
522
523
  }
523
524
  var whereTypeFields = [];
524
525
  var _loop_2 = function (f) {
526
+ var ri = (0, internals_1.getRelationInfo)(f.options);
527
+ // let's not consider toMany relations for now
528
+ if ((ri === null || ri === void 0 ? void 0 : ri.type) === 'toMany') {
529
+ return "break";
530
+ }
525
531
  if (f.options.includeInApi === false)
526
532
  return "continue";
527
533
  var type = 'String';
@@ -634,7 +640,9 @@ function remultGraphql(options) {
634
640
  try {
635
641
  for (var _s = (e_6 = void 0, tslib_1.__values(meta.fields)), _t = _s.next(); !_t.done; _t = _s.next()) {
636
642
  var f = _t.value;
637
- _loop_2(f);
643
+ var state_1 = _loop_2(f);
644
+ if (state_1 === "break")
645
+ break;
638
646
  }
639
647
  }
640
648
  catch (e_6_1) { e_6 = { error: e_6_1 }; }
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/internals.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { getRelationInfo } from './src/remult3/relationInfoMember';
2
- export { decorateColumnSettings } from './src/remult3/RepositoryImplementation';
2
+ export { decorateColumnSettings, controllerRefImpl, getControllerRef, } from './src/remult3/RepositoryImplementation';
3
3
  export { getEntitySettings } from './src/remult3/getEntityRef';
4
4
  export { __updateEntityBasedOnWhere } from './src/filter/filter-interfaces';
5
5
  export { actionInfo } from './src/server-action-info';
package/internals.js CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.actionInfo = exports.__updateEntityBasedOnWhere = exports.getEntitySettings = exports.decorateColumnSettings = exports.getRelationInfo = void 0;
3
+ exports.actionInfo = exports.__updateEntityBasedOnWhere = exports.getEntitySettings = exports.getControllerRef = exports.controllerRefImpl = exports.decorateColumnSettings = exports.getRelationInfo = void 0;
4
4
  var relationInfoMember_1 = require("./src/remult3/relationInfoMember");
5
5
  Object.defineProperty(exports, "getRelationInfo", { enumerable: true, get: function () { return relationInfoMember_1.getRelationInfo; } });
6
6
  var RepositoryImplementation_1 = require("./src/remult3/RepositoryImplementation");
7
7
  Object.defineProperty(exports, "decorateColumnSettings", { enumerable: true, get: function () { return RepositoryImplementation_1.decorateColumnSettings; } });
8
+ Object.defineProperty(exports, "controllerRefImpl", { enumerable: true, get: function () { return RepositoryImplementation_1.controllerRefImpl; } });
9
+ Object.defineProperty(exports, "getControllerRef", { enumerable: true, get: function () { return RepositoryImplementation_1.getControllerRef; } });
8
10
  var getEntityRef_1 = require("./src/remult3/getEntityRef");
9
11
  Object.defineProperty(exports, "getEntitySettings", { enumerable: true, get: function () { return getEntityRef_1.getEntitySettings; } });
10
12
  var filter_interfaces_1 = require("./src/filter/filter-interfaces");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.23.0-exp.11",
3
+ "version": "0.23.0-exp.14",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "types": "index.d.ts",
6
6
  "module": "esm/index.js",
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
- // [ ]- add with remult promise
31
+ // [ ] V1.5 add with remult promise
32
32
  });
33
33
  }
34
34
  exports.remultExpress = remultExpress;