remult 0.26.23 → 0.27.1-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/SseSubscriptionServer.d.ts +3 -4
  2. package/assign.js +1 -2
  3. package/esm/graphql.js +1 -1
  4. package/esm/remult-hono.js +3 -1
  5. package/esm/remult-knex/index.js +3 -1
  6. package/esm/remult-sqlite3.js +4 -1
  7. package/esm/remult-sveltekit.js +1 -0
  8. package/esm/server/index.js +3 -2
  9. package/esm/server/initAsyncHooks.js +3 -3
  10. package/esm/server/remult-admin.js +1 -4
  11. package/esm/server/remult-api-server.js +48 -48
  12. package/esm/src/CompoundIdField.js +9 -9
  13. package/esm/src/data-api.js +1 -1
  14. package/esm/src/data-providers/json-entity-opfs-storage.js +9 -5
  15. package/esm/src/data-providers/sql-database.js +9 -9
  16. package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +3 -1
  17. package/esm/src/filter/filter-interfaces.js +1 -1
  18. package/esm/src/live-query/LiveQueryClient.js +0 -1
  19. package/esm/src/remult-proxy.js +1 -3
  20. package/esm/src/remult-static.js +1 -0
  21. package/esm/src/remult3/Fields.js +15 -7
  22. package/esm/src/remult3/RepositoryImplementation.js +165 -125
  23. package/esm/src/remult3/entity.js +1 -1
  24. package/esm/src/remult3/relation-loader.js +2 -2
  25. package/esm/src/remult3/remult3.js +18 -2
  26. package/esm/src/server-action.js +16 -12
  27. package/esm/src/sort.js +0 -2
  28. package/esm/src/validators.js +3 -3
  29. package/esm/src/valueConverters.js +2 -2
  30. package/graphql.js +3 -4
  31. package/index.js +2 -2
  32. package/live-query/data-provider-live-query-storage.js +6 -6
  33. package/migrations/compare-migration-snapshots.js +48 -49
  34. package/migrations/generate-migrations.js +1 -2
  35. package/migrations/migrate.js +2 -3
  36. package/migrations/migration-types.d.ts +1 -1
  37. package/migrations/migration-types.js +4 -4
  38. package/migrations/update-migrations-ts-file.js +1 -2
  39. package/myLog.js +1 -2
  40. package/package.json +1 -1
  41. package/postgres/postgres-data-provider.d.ts +2 -2
  42. package/postgres/postgres-data-provider.js +5 -5
  43. package/postgres/schema-builder.d.ts +1 -1
  44. package/postgres/schema-builder.js +3 -3
  45. package/remult-express.js +4 -3
  46. package/remult-fastify.js +4 -3
  47. package/remult-fresh.js +1 -2
  48. package/remult-hapi.js +4 -3
  49. package/remult-hono.js +6 -3
  50. package/remult-knex/index.d.ts +2 -2
  51. package/remult-knex/index.js +7 -5
  52. package/remult-mongo.d.ts +1 -1
  53. package/remult-next.d.ts +5 -6
  54. package/remult-next.js +11 -6
  55. package/remult-nuxt.js +1 -2
  56. package/remult-solid-start.js +1 -2
  57. package/remult-sqlite3.js +4 -1
  58. package/remult-sveltekit.d.ts +1 -1
  59. package/remult-sveltekit.js +33 -35
  60. package/server/JsonEntityFileStorage.d.ts +1 -1
  61. package/server/get-remult-admin-html.js +1 -2
  62. package/server/index.js +4 -3
  63. package/server/initAsyncHooks.d.ts +10 -10
  64. package/server/initAsyncHooks.js +5 -2
  65. package/server/initDataProvider.js +1 -2
  66. package/server/initDataProviderOrJson.js +1 -2
  67. package/server/remult-admin.js +3 -7
  68. package/server/remult-api-server.d.ts +21 -21
  69. package/server/remult-api-server.js +55 -48
  70. package/src/CompoundIdField.d.ts +2 -2
  71. package/src/CompoundIdField.js +9 -0
  72. package/src/buildRestDataProvider.d.ts +1 -1
  73. package/src/buildRestDataProvider.js +8 -8
  74. package/src/column-interfaces.d.ts +4 -4
  75. package/src/column-interfaces.js +1 -2
  76. package/src/column.d.ts +4 -4
  77. package/src/column.js +2 -2
  78. package/src/context.d.ts +21 -4
  79. package/src/context.js +5 -5
  80. package/src/data-api.d.ts +4 -4
  81. package/src/data-api.js +4 -4
  82. package/src/data-interfaces.d.ts +1 -1
  83. package/src/data-interfaces.js +1 -2
  84. package/src/data-providers/json-entity-opfs-storage.js +30 -16
  85. package/src/data-providers/rest-data-provider.d.ts +3 -3
  86. package/src/data-providers/rest-data-provider.js +4 -4
  87. package/src/data-providers/sql-database.d.ts +1 -1
  88. package/src/data-providers/sql-database.js +11 -11
  89. package/src/data-providers/web-sql-data-provider.d.ts +2 -2
  90. package/src/entity.d.ts +1 -1
  91. package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +3 -3
  92. package/src/filter/filter-consumer-bridge-to-sql-request.js +21 -19
  93. package/src/filter/filter-interfaces.d.ts +2 -1
  94. package/src/filter/filter-interfaces.js +10 -7
  95. package/src/isOfType.js +2 -3
  96. package/src/live-query/SubscriptionServer.js +95 -97
  97. package/src/remult-proxy.js +1 -3
  98. package/src/remult-static.d.ts +2 -2
  99. package/src/remult-static.js +7 -4
  100. package/src/remult3/Fields.d.ts +17 -17
  101. package/src/remult3/Fields.js +22 -13
  102. package/src/remult3/RepositoryImplementation.d.ts +51 -46
  103. package/src/remult3/RepositoryImplementation.js +421 -368
  104. package/src/remult3/__updateEntityBasedOnWhere.js +1 -2
  105. package/src/remult3/addValidator.d.ts +1 -1
  106. package/src/remult3/addValidator.js +1 -2
  107. package/src/remult3/classDescribers.d.ts +4 -4
  108. package/src/remult3/classDescribers.js +3 -4
  109. package/src/remult3/columnInfo.d.ts +1 -1
  110. package/src/remult3/entity.js +2 -4
  111. package/src/remult3/getEntityRef.js +4 -4
  112. package/src/remult3/relation-loader.d.ts +1 -1
  113. package/src/remult3/relationInfoMember.d.ts +3 -3
  114. package/src/remult3/relationInfoMember.js +4 -5
  115. package/src/remult3/remult3.d.ts +23 -20
  116. package/src/remult3/remult3.js +18 -2
  117. package/src/remult3/repository-internals.d.ts +3 -3
  118. package/src/remult3/repository-internals.js +2 -2
  119. package/src/server-action.d.ts +2 -2
  120. package/src/server-action.js +65 -58
  121. package/src/sort.d.ts +1 -1
  122. package/src/sort.js +0 -2
  123. package/src/sql-command.d.ts +1 -1
  124. package/src/validators.d.ts +1 -1
  125. package/src/validators.js +13 -11
  126. package/src/valueConverters.js +3 -2
@@ -1,10 +1,9 @@
1
- /// <reference types="node" />
2
1
  import type { GenericResponse } from './server/index.js';
3
2
  import type { Remult } from './src/context.js';
4
3
  import type { SubscriptionServer } from './src/live-query/SubscriptionServer.js';
5
4
  export declare class SseSubscriptionServer implements SubscriptionServer {
6
5
  private canUserConnectToChannel?;
7
- constructor(canUserConnectToChannel?: (channel: string, remult: Remult) => boolean);
6
+ constructor(canUserConnectToChannel?: ((channel: string, remult: Remult) => boolean) | undefined);
8
7
  publishMessage<T>(channel: string, message: any): Promise<void>;
9
8
  }
10
9
  export interface ResponseRequiredForSSE {
@@ -15,11 +14,11 @@ export interface ResponseRequiredForSSE {
15
14
  export declare class clientConnection {
16
15
  response: GenericResponse & ResponseRequiredForSSE;
17
16
  channels: Record<string, boolean>;
18
- timeOutRef: NodeJS.Timeout;
17
+ timeOutRef?: NodeJS.Timeout;
19
18
  close(): void;
20
19
  closed: boolean;
21
20
  write(eventData: string, eventType?: string): void;
22
- connectionId: any;
21
+ connectionId: string;
23
22
  constructor(response: GenericResponse & ResponseRequiredForSSE);
24
23
  sendLiveMessage(): void;
25
24
  }
package/assign.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assign = void 0;
3
+ exports.assign = assign;
4
4
  function assign(item, valuesToSet) {
5
5
  if (valuesToSet)
6
6
  Object.assign(item, valuesToSet);
7
7
  return item;
8
8
  }
9
- exports.assign = assign;
package/esm/graphql.js CHANGED
@@ -976,7 +976,7 @@ export function translateWhereToRestBody(fields, { where }) {
976
976
  }
977
977
  }
978
978
  if (where.OR) {
979
- result.OR = where.OR.map((where) => translateWhereToRestBody(fields, { where }).where);
979
+ result.OR = where.OR.map((where) => translateWhereToRestBody(fields, { where })?.where);
980
980
  }
981
981
  return { where: result };
982
982
  }
@@ -18,6 +18,7 @@ export function remultHono(options) {
18
18
  }),
19
19
  url: c.req.url,
20
20
  on: (e, do1) => {
21
+ ;
21
22
  c['_tempOnClose'](() => do1());
22
23
  // c.req.on('close', do1)
23
24
  },
@@ -78,7 +79,8 @@ export function remultHono(options) {
78
79
  res(streamSSE(c, (s) => {
79
80
  sse = s;
80
81
  return new Promise((res) => {
81
- c['_tempOnClose'] = (x) => sse.onAbort(() => x);
82
+ ;
83
+ c['_tempOnClose'] = (x) => sse.onAbort(() => x());
82
84
  });
83
85
  }));
84
86
  },
@@ -91,8 +91,10 @@ export class KnexDataProvider {
91
91
  };
92
92
  }
93
93
  static async filterToRaw(entity, condition, wrapIdentifier) {
94
+ if (!wrapIdentifier)
95
+ wrapIdentifier = (x) => x;
94
96
  const repo = getRepository(entity);
95
- var b = new FilterConsumerBridgeToKnexRequest(await dbNamesOfWithForceSqlExpression(repo.metadata, (x) => x), wrapIdentifier);
97
+ var b = new FilterConsumerBridgeToKnexRequest(await dbNamesOfWithForceSqlExpression(repo.metadata, wrapIdentifier), wrapIdentifier ?? wrapIdentifier);
96
98
  b._addWhere = false;
97
99
  await (await getRepositoryInternals(repo)._translateWhereToFilter(condition)).__applyToConsumer(b);
98
100
  let r = await b.resolveWhere();
@@ -20,7 +20,10 @@ class Sqlite3Command {
20
20
  if (err)
21
21
  error(err);
22
22
  else
23
- resolve(new Sqlite3SqlResult([this.lastID]));
23
+ resolve(new Sqlite3SqlResult([
24
+ //@ts-expect-error last id comes from sql lite as a lastId member of the function this
25
+ this.lastID,
26
+ ]));
24
27
  });
25
28
  }
26
29
  else
@@ -6,6 +6,7 @@ export function remultSveltekit(options) {
6
6
  method: event.request.method,
7
7
  on: (e, do1) => {
8
8
  if (e === 'close') {
9
+ ;
9
10
  event.locals['_tempOnClose'] = do1;
10
11
  }
11
12
  },
@@ -1,12 +1,13 @@
1
- import { createRemultServerCore } from './remult-api-server.js';
1
+ import { createRemultServerCore, } from './remult-api-server.js';
2
2
  import { initAsyncHooks } from './initAsyncHooks.js';
3
+ import { cast } from '../src/isOfType.js';
3
4
  export { SseSubscriptionServer } from '../SseSubscriptionServer.js';
4
5
  export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-query-storage.js';
5
6
  export { JsonEntityFileStorage, JsonFileDataProvider, } from './JsonEntityFileStorage.js';
6
7
  export function createRemultServer(options, serverCoreOptions) {
7
8
  initAsyncHooks();
8
9
  return createRemultServerCore(options, serverCoreOptions || {
9
- buildGenericRequestInfo: (req) => req,
10
+ buildGenericRequestInfo: (req) => cast(req, 'method'),
10
11
  getRequestBody: async (req) => req.body,
11
12
  });
12
13
  }
@@ -18,7 +18,7 @@ export function initAsyncHooks() {
18
18
  }
19
19
  export class AsyncLocalStorageBridgeToRemultAsyncLocalStorageCoreImpl {
20
20
  asyncLocalStorage = new AsyncLocalStorage();
21
- wasImplemented;
21
+ wasImplemented = 'yes';
22
22
  run(store, callback) {
23
23
  let r;
24
24
  this.asyncLocalStorage.run(store, () => {
@@ -44,7 +44,7 @@ const ignoreInStack = [
44
44
  'RemultServerImplementation.runWithRemult',
45
45
  ];
46
46
  export class SequentialRemultAsyncLocalStorageCore {
47
- wasImplemented;
47
+ wasImplemented = 'yes';
48
48
  async run(store, callback) {
49
49
  let log = (msg) => { };
50
50
  if (false) {
@@ -87,7 +87,7 @@ export class SequentialRemultAsyncLocalStorageCore {
87
87
  currentValue;
88
88
  }
89
89
  export class StubRemultAsyncLocalStorageCore {
90
- wasImplemented;
90
+ wasImplemented = 'yes';
91
91
  async run(store, callback) {
92
92
  this.currentValue = store;
93
93
  return await callback();
@@ -3,10 +3,7 @@ import { Filter } from '../src/filter/filter-interfaces.js';
3
3
  import { getHtml } from './get-remult-admin-html.js';
4
4
  import { getValueList } from '../src/remult3/RepositoryImplementation.js';
5
5
  export default function remultAdminHtml(options) {
6
- let optionsFromServer = { ...options };
7
- //@ts-ignore
8
- delete optionsFromServer.entities;
9
- delete optionsFromServer.remult;
6
+ let { remult, entities, ...optionsFromServer } = { ...options };
10
7
  return getHtml().replace('<!--PLACE_HERE-->', `<script >const entities = ${JSON.stringify(buildEntityInfo(options))}
11
8
  const optionsFromServer = ${JSON.stringify(optionsFromServer)}
12
9
  </script>`);
@@ -15,40 +15,38 @@ import remultAdminHtml from './remult-admin.js';
15
15
  import { isOfType } from '../src/isOfType.js';
16
16
  import { initDataProviderOrJson } from './initDataProviderOrJson.js';
17
17
  export function createRemultServerCore(options, serverCoreOptions) {
18
- if (!options) {
19
- options = {};
18
+ const safeOptions = options ?? {};
19
+ if (!safeOptions.subscriptionServer) {
20
+ safeOptions.subscriptionServer = new SseSubscriptionServer();
20
21
  }
21
- if (!options.subscriptionServer) {
22
- options.subscriptionServer = new SseSubscriptionServer();
23
- }
24
- if (options.logApiEndPoints === undefined)
25
- options.logApiEndPoints = true;
22
+ if (safeOptions.logApiEndPoints === undefined)
23
+ safeOptions.logApiEndPoints = true;
26
24
  remultStatic.actionInfo.runningOnServer = true;
27
- if (options.defaultGetLimit) {
28
- DataApi.defaultGetLimit = options.defaultGetLimit;
25
+ if (safeOptions.defaultGetLimit) {
26
+ DataApi.defaultGetLimit = safeOptions.defaultGetLimit;
29
27
  }
30
- if (!options.queueStorage) {
31
- options.queueStorage = new InMemoryQueueStorage();
28
+ if (!safeOptions.queueStorage) {
29
+ safeOptions.queueStorage = new InMemoryQueueStorage();
32
30
  }
33
- let dataProvider = initDataProviderOrJson(options.dataProvider);
31
+ let dataProvider = initDataProviderOrJson(safeOptions.dataProvider);
34
32
  remultStatic.defaultDataProvider = () => dataProvider;
35
- if (options.ensureSchema === undefined)
36
- options.ensureSchema = true;
33
+ if (safeOptions.ensureSchema === undefined)
34
+ safeOptions.ensureSchema = true;
37
35
  RemultAsyncLocalStorage.enable();
38
36
  {
39
37
  let allControllers = [];
40
- if (!options.entities)
41
- options.entities = [...remultStatic.allEntities];
42
- if (options.entities)
43
- allControllers.push(...options.entities);
44
- if (options.controllers)
45
- allControllers.push(...options.controllers);
46
- options.controllers = allControllers;
38
+ if (!safeOptions.entities)
39
+ safeOptions.entities = [...remultStatic.allEntities];
40
+ if (safeOptions.entities)
41
+ allControllers.push(...safeOptions.entities);
42
+ if (safeOptions.controllers)
43
+ allControllers.push(...safeOptions.controllers);
44
+ safeOptions.controllers = allControllers;
47
45
  }
48
- if (options.rootPath === undefined)
49
- options.rootPath = '/api';
46
+ if (safeOptions.rootPath === undefined)
47
+ safeOptions.rootPath = '/api';
50
48
  remultStatic.actionInfo.runningOnServer = true;
51
- let bridge = new RemultServerImplementation(new inProcessQueueHandler(options.queueStorage), options, dataProvider, serverCoreOptions);
49
+ let bridge = new RemultServerImplementation(new inProcessQueueHandler(safeOptions.queueStorage), safeOptions, dataProvider, serverCoreOptions);
52
50
  return bridge;
53
51
  }
54
52
  /* @internal*/
@@ -223,7 +221,7 @@ export class RemultServerImplementation {
223
221
  ;
224
222
  remult.subscriptionServer.openHttpServerStream(origReq, origRes);
225
223
  }));
226
- r.route(streamPath + '/subscribe').post(this.process(async (remult, req, res, reqInfo, origRes, origReq) => {
224
+ r.route(streamPath + '/subscribe').post(this.process(async (remult, _2, res, _, _1, origReq) => {
227
225
  const body = remult.subscriptionServer.subscribeToChannel(await this.coreOptions.getRequestBody(origReq), res, remult);
228
226
  }));
229
227
  r.route(streamPath + '/unsubscribe').post(this.process(async (remult, req, res, reqInfo, origRes, origReq) => {
@@ -284,14 +282,12 @@ export class RemultServerImplementation {
284
282
  x.liveQueryStorage = this.liveQueryStorage;
285
283
  return await what(x);
286
284
  }, {
287
- dataProvider,
285
+ dataProvider: dataProvider,
288
286
  });
289
287
  }
290
288
  process(what) {
291
289
  return async (req, origRes) => {
292
- const genReq = req
293
- ? this.coreOptions.buildGenericRequestInfo(req)
294
- : undefined;
290
+ const genReq = req ? this.coreOptions.buildGenericRequestInfo(req) : {};
295
291
  if (req) {
296
292
  if (!genReq.query) {
297
293
  genReq.query = req['_tempQuery'];
@@ -300,13 +296,14 @@ export class RemultServerImplementation {
300
296
  genReq.params = req['_tempParams'];
301
297
  }
302
298
  let myReq = new RequestBridgeToDataApiRequest(genReq);
303
- let myRes = new ResponseBridgeToDataApiResponse(origRes, req, this.options.error);
299
+ let myRes = new ResponseBridgeToDataApiResponse(origRes, req, genReq, this.options.error);
304
300
  try {
305
301
  if (remultStatic.asyncContext.isInInitRequest())
306
302
  return await what(remultStatic.asyncContext.getStore().remult, myReq, myRes, genReq, origRes, req);
307
303
  else
308
304
  await this.runWithRemult(async (remult) => {
309
305
  if (req) {
306
+ remult.context.request = req;
310
307
  remultStatic.asyncContext.setInInitRequest(true);
311
308
  try {
312
309
  let user;
@@ -767,6 +764,7 @@ class RequestBridgeToDataApiRequest {
767
764
  class ResponseBridgeToDataApiResponse {
768
765
  r;
769
766
  req;
767
+ genReq;
770
768
  handleError;
771
769
  forbidden() {
772
770
  this.error({ message: 'Forbidden' }, undefined, 403);
@@ -774,9 +772,10 @@ class ResponseBridgeToDataApiResponse {
774
772
  setStatus(status) {
775
773
  return this.r.status(status);
776
774
  }
777
- constructor(r, req, handleError) {
775
+ constructor(r, req, genReq, handleError) {
778
776
  this.r = r;
779
777
  this.req = req;
778
+ this.genReq = genReq;
780
779
  this.handleError = handleError;
781
780
  }
782
781
  progress(progress) { }
@@ -819,8 +818,8 @@ class ResponseBridgeToDataApiResponse {
819
818
  message: body.message,
820
819
  httpStatusCode,
821
820
  stack: data.stack?.split('\n'),
822
- url: this.req?.url,
823
- method: this.req?.method,
821
+ url: this.genReq?.url,
822
+ method: this.genReq?.method,
824
823
  });
825
824
  this.setStatus(httpStatusCode).json(body);
826
825
  };
@@ -911,7 +910,7 @@ export class EntityQueueStorage {
911
910
  return (this.sync = this.sync.then(() => what()));
912
911
  }
913
912
  async getJobInfo(queuedJobId) {
914
- let q = await this.repo.findId(queuedJobId);
913
+ let q = (await this.repo.findId(queuedJobId));
915
914
  let lastProgress = undefined;
916
915
  return {
917
916
  userId: q.userId,
@@ -1009,8 +1008,9 @@ export class RouteImplementation {
1009
1008
  res({ statusCode });
1010
1009
  }
1011
1010
  flush() {
1012
- if (gRes.flush)
1011
+ if (isOfType(gRes, 'flush')) {
1013
1012
  gRes.flush();
1013
+ }
1014
1014
  }
1015
1015
  statusCode = 200;
1016
1016
  json(data) {
@@ -1047,7 +1047,7 @@ export class RouteImplementation {
1047
1047
  }
1048
1048
  middleware(origReq, res, next) {
1049
1049
  const req = this.coreOptions.buildGenericRequestInfo(origReq);
1050
- let theUrl = req.url;
1050
+ let theUrl = req.url?.toString() || '';
1051
1051
  if (theUrl.startsWith('/'))
1052
1052
  //next sends a partial url '/api/tasks' and not the full url
1053
1053
  theUrl = 'http://stam' + theUrl;
@@ -1107,22 +1107,22 @@ export class RouteImplementation {
1107
1107
  }
1108
1108
  }
1109
1109
  let JobsInQueueEntity = class JobsInQueueEntity extends IdEntity {
1110
- userId;
1111
- url;
1110
+ userId = '';
1111
+ url = '';
1112
1112
  submitTime;
1113
1113
  doneTime;
1114
- result;
1115
- done;
1116
- error;
1117
- progress;
1114
+ result = '';
1115
+ done = false;
1116
+ error = false;
1117
+ progress = 0;
1118
1118
  };
1119
1119
  __decorate([
1120
1120
  Fields.string(),
1121
- __metadata("design:type", String)
1121
+ __metadata("design:type", Object)
1122
1122
  ], JobsInQueueEntity.prototype, "userId", void 0);
1123
1123
  __decorate([
1124
1124
  Fields.string(),
1125
- __metadata("design:type", String)
1125
+ __metadata("design:type", Object)
1126
1126
  ], JobsInQueueEntity.prototype, "url", void 0);
1127
1127
  __decorate([
1128
1128
  Fields.date(),
@@ -1134,19 +1134,19 @@ __decorate([
1134
1134
  ], JobsInQueueEntity.prototype, "doneTime", void 0);
1135
1135
  __decorate([
1136
1136
  Fields.string(),
1137
- __metadata("design:type", String)
1137
+ __metadata("design:type", Object)
1138
1138
  ], JobsInQueueEntity.prototype, "result", void 0);
1139
1139
  __decorate([
1140
1140
  Fields.boolean(),
1141
- __metadata("design:type", Boolean)
1141
+ __metadata("design:type", Object)
1142
1142
  ], JobsInQueueEntity.prototype, "done", void 0);
1143
1143
  __decorate([
1144
1144
  Fields.boolean(),
1145
- __metadata("design:type", Boolean)
1145
+ __metadata("design:type", Object)
1146
1146
  ], JobsInQueueEntity.prototype, "error", void 0);
1147
1147
  __decorate([
1148
1148
  Fields.number(),
1149
- __metadata("design:type", Number)
1149
+ __metadata("design:type", Object)
1150
1150
  ], JobsInQueueEntity.prototype, "progress", void 0);
1151
1151
  JobsInQueueEntity = __decorate([
1152
1152
  Entity(undefined, {
@@ -36,19 +36,19 @@ export class CompoundIdField {
36
36
  });
37
37
  return r;
38
38
  }
39
- options;
39
+ options = {};
40
40
  get valueConverter() {
41
41
  throw new Error('cant get value converter of compound id');
42
42
  }
43
43
  target;
44
- readonly;
45
- allowNull;
46
- dbReadOnly;
47
- isServerExpression;
48
- key;
49
- caption;
50
- inputType;
51
- dbName;
44
+ readonly = true;
45
+ allowNull = false;
46
+ dbReadOnly = false;
47
+ isServerExpression = false;
48
+ key = '';
49
+ caption = '';
50
+ inputType = '';
51
+ dbName = '';
52
52
  valueType;
53
53
  isEqualTo(value) {
54
54
  let result = {};
@@ -286,7 +286,7 @@ export class DataApi {
286
286
  async updateManyImplementation(response, request, body) {
287
287
  try {
288
288
  let where = await this.buildWhere(request, body);
289
- Filter.throwErrorIfFilterIsEmpty(where, 'deleteMany');
289
+ Filter.throwErrorIfFilterIsEmpty(where, 'updateMany');
290
290
  return await doTransaction(this.remult, async () => {
291
291
  let updated = 0;
292
292
  for await (const x of this.repository.query({
@@ -2,17 +2,21 @@ export class JsonEntityOpfsStorage {
2
2
  //@internal
3
3
  opfsRoot;
4
4
  async getItem(entityDbName) {
5
- if (!this.opfsRoot) {
6
- this.opfsRoot = await navigator.storage.getDirectory();
7
- }
8
- const opfsFile = await this.opfsRoot.getFileHandle(entityDbName + '.json', {
5
+ const opfsFile = await (await this.init()).getFileHandle(entityDbName + '.json', {
9
6
  create: true,
10
7
  });
11
8
  const readable = await opfsFile.getFile();
12
9
  return await readable.text();
13
10
  }
11
+ //@internal
12
+ async init() {
13
+ if (!this.opfsRoot) {
14
+ this.opfsRoot = await navigator.storage.getDirectory();
15
+ }
16
+ return this.opfsRoot;
17
+ }
14
18
  async setItem(entityDbName, json) {
15
- const opfsFile = await this.opfsRoot.getFileHandle(entityDbName + '.json', {
19
+ const opfsFile = await await (await this.init()).getFileHandle(entityDbName + '.json', {
16
20
  create: true,
17
21
  });
18
22
  const writable = await opfsFile.createWritable();
@@ -193,16 +193,16 @@ export class SqlDatabase {
193
193
  }
194
194
  const icons = new Map([
195
195
  // CRUD
196
- ['INSERT', '⚪'],
197
- ['SELECT', '🔵'],
198
- ['UPDATE', '🟣'],
199
- ['DELETE', '🟤'],
196
+ ['INSERT', '⚪'], // Used to insert new data into a database.
197
+ ['SELECT', '🔵'], // Used to select data from a database and retrieve it.
198
+ ['UPDATE', '🟣'], // Used to update existing data within a database.
199
+ ['DELETE', '🟤'], // Used to delete existing data from a database.
200
200
  // Additional
201
- ['CREATE', '🟩'],
202
- ['ALTER', '🟨'],
203
- ['DROP', '🟥'],
204
- ['TRUNCATE', '⬛'],
205
- ['GRANT', '🟪'],
201
+ ['CREATE', '🟩'], // Used to create a new table, or database.
202
+ ['ALTER', '🟨'], // Used to modify an existing database object, such as a table.
203
+ ['DROP', '🟥'], // Used to delete an entire table or database.
204
+ ['TRUNCATE', '⬛'], // Used to remove all records from a table, including all spaces allocated for the records are removed.
205
+ ['GRANT', '🟪'], // Used to give a specific user permission to perform certain tasks.
206
206
  ['REVOKE', '🟫'], // Used to take back permissions from a user.
207
207
  ]);
208
208
  class LogSQLCommand {
@@ -211,7 +211,7 @@ export function isDbReadonly(field, dbNames) {
211
211
  (field.options.sqlExpression && field.dbName != dbNames.$dbNameOf(field)));
212
212
  }
213
213
  export function shouldNotCreateField(field, dbNames) {
214
- return (field.isServerExpression ||
214
+ return Boolean(field.isServerExpression ||
215
215
  (field.options.sqlExpression && field.dbName != dbNames.$dbNameOf(field)));
216
216
  }
217
217
  export function shouldCreateEntity(entity, e) {
@@ -255,6 +255,7 @@ async function internalDbNamesOf(repo, wrapIdentifierOrOptions, forceSqlExpressi
255
255
  else if (options.tableName === true) {
256
256
  r = result.$entityName + '.' + r;
257
257
  }
258
+ ;
258
259
  result[field.key] = r;
259
260
  }
260
261
  return result;
@@ -287,6 +288,7 @@ export async function fieldDbName(f, meta, wrapIdentifier = (x) => x, forceSqlEx
287
288
  return "recursive sqlExpression call for field '" + f.key + "'. ";
288
289
  }
289
290
  try {
291
+ ;
290
292
  f[sqlExpressionInProgressKey] = true;
291
293
  result = await f.options.sqlExpression(meta);
292
294
  f.options.sqlExpression = () => result;
@@ -285,8 +285,8 @@ export class Filter {
285
285
  this.__applyToConsumer(r);
286
286
  return r.result;
287
287
  }
288
- //@internal
289
288
  static async translateCustomWhere(r, entity, remult) {
289
+ // Used in hagai
290
290
  let f = new customTranslator(async (filterKey, custom) => {
291
291
  let r = [];
292
292
  for (const key in entity.entityType) {
@@ -185,7 +185,6 @@ export class LiveQueryClient {
185
185
  }
186
186
  }
187
187
  class MessageChannel {
188
- id;
189
188
  unsubscribe = () => { };
190
189
  async handle(message) {
191
190
  for (const l of this.listeners) {
@@ -73,9 +73,7 @@ export class RemultProxy {
73
73
  },
74
74
  //@ts-ignore
75
75
  [getInternalKey]() {
76
- return self
77
- .remultFactory()
78
- .repo(...args)[getInternalKey]();
76
+ return self.remultFactory().repo(...args)[getInternalKey]();
79
77
  },
80
78
  relations: (args2) => self
81
79
  .remultFactory()
@@ -24,6 +24,7 @@ let x = {
24
24
  if ((typeof process !== 'undefined' &&
25
25
  process.env['IGNORE_GLOBAL_REMULT_IN_TESTS']) ||
26
26
  typeof globalThis[remultStaticKey] === 'undefined') {
27
+ ;
27
28
  globalThis[remultStaticKey] = x;
28
29
  x.remultFactory = () => defaultFactory();
29
30
  }
@@ -6,6 +6,7 @@ import { Validators, createValueValidator, getEnumValues, } from '../validators.
6
6
  import { relationInfoMemberInOptions } from './relationInfoMember.js';
7
7
  import { remultStatic } from '../remult-static.js';
8
8
  import { addValidator } from './addValidator.js';
9
+ import { isOfType } from '../isOfType.js';
9
10
  const validateNumber = createValueValidator((x) => {
10
11
  return !isNaN(x) && isFinite(x);
11
12
  });
@@ -98,7 +99,7 @@ export class Fields {
98
99
  },
99
100
  }, ...options);
100
101
  }
101
- // static id<entityType = any>(
102
+ // static id<entityType = unknown>(
102
103
  // options?: FieldOptions<entityType, string> & { idFactory?: () => string },
103
104
  // ): ClassFieldDecorator<entityType, string | undefined> {
104
105
  // let buildId = options?.idFactory ?? createId
@@ -148,12 +149,13 @@ export class Fields {
148
149
  }
149
150
  static enum(enumType, ...options) {
150
151
  let valueConverter;
151
- return Field(() =>
152
+ return Field(
152
153
  //@ts-ignore
153
- enumType(), {
154
+ () => enumType(), {
154
155
  validate: (entity, event) => Validators.enum(enumType())(entity, event),
155
156
  [fieldOptionalValuesFunctionKey]: () => getEnumValues(enumType()),
156
157
  }, ...options, (options) => {
158
+ ;
157
159
  options[fieldOptionalValuesFunctionKey] = () => getEnumValues(enumType());
158
160
  if (valueConverter === undefined) {
159
161
  let enumObj = enumType();
@@ -273,11 +275,17 @@ export function Field(valueType, ...options) {
273
275
  if (r.required) {
274
276
  r.validate = addValidator(r.validate, Validators.required, true);
275
277
  }
276
- if (r.maxLength) {
277
- r.validate = addValidator(r.validate, Validators.maxLength(r.maxLength));
278
+ if (isOfType(r, 'maxLength')) {
279
+ let z = r;
280
+ if (z.maxLength) {
281
+ z.validate = addValidator(z.validate, Validators.maxLength(z.maxLength));
282
+ }
278
283
  }
279
- if (r.minLength) {
280
- r.validate = addValidator(r.validate, Validators.minLength(r.minLength));
284
+ if (isOfType(r, 'minLength')) {
285
+ let z = r;
286
+ if (z.minLength) {
287
+ z.validate = addValidator(z.validate, Validators.minLength(z.minLength));
288
+ }
281
289
  }
282
290
  if (!r.valueType && valueType) {
283
291
  r.valueType = valueType();