remult 0.24.0-exp.4 → 0.24.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.
@@ -1,2 +1,2 @@
1
- export { PostgresDataProvider, PostgresPool, preparePostgresQueueStorage, PostgresClient, createPostgresConnection, createPostgresDataProvider, PostgresCommandSource, } from './postgres-data-provider';
2
- export { PostgresSchemaBuilder, postgresColumnSyntax } from './schema-builder';
1
+ export * from './postgres-data-provider';
2
+ export * from './schema-builder';
@@ -11,37 +11,26 @@ export interface PostgresClient extends PostgresCommandSource {
11
11
  }
12
12
  export declare class PostgresDataProvider implements SqlImplementation {
13
13
  private pool;
14
- private options?;
15
14
  supportsJsonColumnType: boolean;
16
15
  static getDb(remult?: Remult): ClientBase;
17
16
  entityIsUsedForTheFirstTime(entity: EntityMetadata): Promise<void>;
18
17
  getLimitSqlSyntax(limit: number, offset: number): string;
19
18
  createCommand(): SqlCommand;
20
- constructor(pool: PostgresPool, options?: {
21
- wrapIdentifier?: (name: string) => string;
22
- schema?: string;
23
- });
24
- wrapIdentifier: (name: any) => any;
19
+ constructor(pool: PostgresPool);
25
20
  ensureSchema(entities: EntityMetadata<any>[]): Promise<void>;
26
21
  transaction(action: (dataProvider: SqlImplementation) => Promise<void>): Promise<void>;
27
22
  }
28
23
  export interface PostgresCommandSource {
29
24
  query(queryText: string, values?: any[]): Promise<QueryResult>;
30
25
  }
31
- export declare function createPostgresConnection(options?: Parameters<typeof createPostgresDataProvider>[0]): Promise<SqlDatabase>;
26
+ export declare function createPostgresConnection(options?: {
27
+ connectionString?: string;
28
+ sslInDev?: boolean;
29
+ configuration?: 'heroku' | PoolConfig;
30
+ }): Promise<SqlDatabase>;
32
31
  export declare function createPostgresDataProvider(options?: {
33
32
  connectionString?: string;
34
33
  sslInDev?: boolean;
35
34
  configuration?: 'heroku' | PoolConfig;
36
- wrapIdentifier?: (name: string) => string;
37
- caseInsensitiveIdentifiers?: boolean;
38
- schema?: string;
39
35
  }): Promise<SqlDatabase>;
40
36
  export declare function preparePostgresQueueStorage(sql: SqlDatabase): Promise<import("../server/expressBridge").EntityQueueStorage>;
41
- export declare class PostgresSchemaWrapper implements PostgresPool {
42
- private pool;
43
- private schema;
44
- constructor(pool: PostgresPool, schema: string);
45
- connect(): Promise<PostgresClient>;
46
- query(queryText: string, values?: any[]): Promise<QueryResult>;
47
- }
@@ -1,5 +1,5 @@
1
- import { readBody } from 'h3';
2
- import { createRemultServer, } from './server/index.js';
1
+ import { readBody, setResponseStatus } from 'h3';
2
+ import { createRemultServer } from './server/index.js';
3
3
  export function remultNuxt(options) {
4
4
  const result = createRemultServer(options, {
5
5
  buildGenericRequestInfo: (event) => {
@@ -36,14 +36,16 @@ export function remultNuxt(options) {
36
36
  });
37
37
  }
38
38
  if (r) {
39
+ if (r.statusCode !== 200)
40
+ setResponseStatus(event, r.statusCode);
39
41
  return r.data;
40
42
  }
41
43
  };
42
44
  return Object.assign(handler, {
43
45
  getRemult: (req) => result.getRemult(req),
44
46
  openApiDoc: (options) => result.openApiDoc(options),
45
- withRemult(event, what) {
46
- return result.withRemultAsync(event, what);
47
+ withRemult(request, what) {
48
+ return result.withRemultAsync(request, what);
47
49
  },
48
50
  });
49
51
  }
@@ -120,8 +120,7 @@ export interface FieldMetadata<valueType = any, entityType = any> {
120
120
  * Task == taskRepo.metadata.fields.title.target //will return true
121
121
  */
122
122
  readonly target: ClassType<valueType>;
123
- /**
124
- * @deprecated Returns the dbName - based on it's `dbName` option and it's `sqlExpression` option */
123
+ /** Returns the dbName - based on it's `dbName` option and it's `sqlExpression` option */
125
124
  getDbName(): Promise<string>;
126
125
  /** Indicates if this field is based on a server express */
127
126
  readonly isServerExpression: boolean;
@@ -14,6 +14,7 @@ export declare class DataApi<T = any> {
14
14
  r: any[];
15
15
  findOptions: FindOptions<T>;
16
16
  }>;
17
+ private includeNone;
17
18
  getArray(response: DataApiResponse, request: DataApiRequest, filterBody?: any): Promise<void>;
18
19
  liveQuery(response: DataApiResponse, request: DataApiRequest, filterBody: any, serializeContext: () => Promise<any>, queryChannel: string): Promise<void>;
19
20
  private buildWhere;
@@ -1,7 +1,7 @@
1
1
  import type { DataProvider, EntityDataProvider } from '../data-interfaces';
2
2
  import type { SqlCommand, SqlCommandWithParameters, SqlImplementation, SqlResult } from '../sql-command';
3
3
  import type { Remult } from '../context';
4
- import type { CustomSqlFilterBuilderFunction, EntityDbNamesBase } from '../filter/filter-consumer-bridge-to-sql-request';
4
+ import type { CustomSqlFilterBuilderFunction } from '../filter/filter-consumer-bridge-to-sql-request';
5
5
  import type { EntityFilter, EntityMetadata } from '../remult3/remult3';
6
6
  import type { RepositoryOverloads } from '../remult3/RepositoryImplementation';
7
7
  export declare class SqlDatabase implements DataProvider {
@@ -9,12 +9,11 @@ export declare class SqlDatabase implements DataProvider {
9
9
  static getDb(remult?: Remult): SqlDatabase;
10
10
  createCommand(): SqlCommand;
11
11
  execute(sql: string): Promise<SqlResult>;
12
- wrapIdentifier: (name: string) => string;
13
12
  ensureSchema(entities: EntityMetadata<any>[]): Promise<void>;
14
13
  getEntityDataProvider(entity: EntityMetadata): EntityDataProvider;
15
14
  transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
16
15
  static rawFilter(build: CustomSqlFilterBuilderFunction): EntityFilter<any>;
17
- static filterToRaw<entityType>(repo: RepositoryOverloads<entityType>, condition: EntityFilter<entityType>, sqlCommand?: SqlCommandWithParameters, dbNames?: EntityDbNamesBase): Promise<string>;
16
+ static filterToRaw<entityType>(repo: RepositoryOverloads<entityType>, condition: EntityFilter<entityType>, sqlCommand?: SqlCommandWithParameters): Promise<string>;
18
17
  /**
19
18
  * `false` _(default)_ - No logging
20
19
  *
@@ -1,6 +1,6 @@
1
1
  import type { FieldMetadata } from '../column-interfaces';
2
2
  import type { EntityMetadataOverloads, RepositoryOverloads } from '../remult3/RepositoryImplementation';
3
- import type { EntityFilter, EntityMetadata, MembersOnly } from '../remult3/remult3';
3
+ import type { EntityFilter, MembersOnly } from '../remult3/remult3';
4
4
  import type { SqlCommandWithParameters } from '../sql-command';
5
5
  import type { Filter, FilterConsumer } from './filter-interfaces';
6
6
  export declare class FilterConsumerBridgeToSqlRequest implements FilterConsumer {
@@ -48,6 +48,4 @@ export declare type EntityDbNamesBase = {
48
48
  export declare type EntityDbNames<entityType> = {
49
49
  [Properties in keyof Required<MembersOnly<entityType>>]: string;
50
50
  } & EntityDbNamesBase;
51
- export declare function dbNamesOf<entityType>(repo: EntityMetadataOverloads<entityType>, wrapIdentifier?: (name: string) => string): Promise<EntityDbNames<entityType>>;
52
- export declare function entityDbName(metadata: EntityMetadata, wrapIdentifier?: (name: string) => string): Promise<string>;
53
- export declare function fieldDbName(f: FieldMetadata, meta: EntityMetadata, wrapIdentifier?: (name: string) => string): Promise<string>;
51
+ export declare function dbNamesOf<entityType>(repo: EntityMetadataOverloads<entityType>): Promise<EntityDbNames<entityType>>;
@@ -1,5 +1,5 @@
1
1
  import type { FieldMetadata } from '../column-interfaces';
2
- import type { Remult } from '../context';
2
+ import { Remult } from '../context';
3
3
  import type { EntityFilter, EntityMetadata } from '../remult3/remult3';
4
4
  export declare class Filter {
5
5
  private apply;
@@ -142,6 +142,7 @@ export class Relations {
142
142
  ? {}
143
143
  : options);
144
144
  if (!op.field && !op.fields && !op.findOptions)
145
+ //@ts-ignore
145
146
  return Field(toEntityType, {
146
147
  ...op,
147
148
  //@ts-ignore
@@ -180,9 +180,9 @@ export declare class FieldRefImplementation<entityType, valueType> implements Fi
180
180
  validate(): Promise<boolean>;
181
181
  }
182
182
  export declare const CaptionTransformer: {
183
- transformCaption: (remult: Remult, key: string, caption: string, entityMetaData: EntityMetadata<any>) => string;
183
+ transformCaption: (remult: Remult, key: string, caption: string) => string;
184
184
  };
185
- export declare function buildCaption(caption: string | ((remult: Remult) => string), key: string, remult: Remult, metaData: EntityMetadata<any>): string;
185
+ export declare function buildCaption(caption: string | ((remult: Remult) => string), key: string, remult: Remult): string;
186
186
  export declare class columnDefsImpl implements FieldMetadata {
187
187
  private settings;
188
188
  private entityDefs;
@@ -200,6 +200,7 @@ export declare class columnDefsImpl implements FieldMetadata {
200
200
  valueConverter: Required<ValueConverter<any>>;
201
201
  allowNull: boolean;
202
202
  caption: string;
203
+ get dbName(): any;
203
204
  inputType: string;
204
205
  key: string;
205
206
  get dbReadOnly(): boolean;
@@ -219,6 +220,7 @@ declare class EntityFullInfo<T> implements EntityMetadata<T> {
219
220
  apiDeleteAllowed(item: T): boolean;
220
221
  apiInsertAllowed(item: T): boolean;
221
222
  getEntityMetadataWithoutBreakingTheEntity(item: T): EntityRef<T>;
223
+ dbNamePromise: Promise<string>;
222
224
  getDbName(): Promise<string>;
223
225
  idMetadata: IdMetadata<T>;
224
226
  fields: FieldsMetadata<T>;
@@ -177,11 +177,21 @@ export class RepositoryImplementation {
177
177
  return x;
178
178
  }
179
179
  async delete(item) {
180
+ const ref = getEntityRef(item, false);
181
+ if (ref)
182
+ return ref.delete();
180
183
  if (typeof item === 'string' || typeof item === 'number')
181
- return this.edp.delete(item);
182
- else {
183
- return this.getRefForExistingRow(item, undefined).delete();
184
- }
184
+ if (this.dataProvider.isProxy)
185
+ return this.edp.delete(item);
186
+ else {
187
+ let ref2 = await this.findId(item);
188
+ if (ref2)
189
+ return await getEntityRef(ref2).delete();
190
+ }
191
+ let ref2 = this.getRefForExistingRow(item, undefined);
192
+ if (!this.dataProvider.isProxy)
193
+ await ref2.reload();
194
+ return ref2.delete();
185
195
  }
186
196
  async insert(entity) {
187
197
  if (Array.isArray(entity)) {
@@ -211,8 +211,7 @@ export interface EntityMetadata<entityType = any> {
211
211
  * }
212
212
  */
213
213
  apiInsertAllowed(item?: entityType): boolean;
214
- /**
215
- * @deprecated Returns the dbName - based on it's `dbName` option and it's `sqlExpression` option */
214
+ /** Returns the dbName - based on it's `dbName` option and it's `sqlExpression` option */
216
215
  getDbName(): Promise<string>;
217
216
  /** Metadata for the Entity's id */
218
217
  readonly idMetadata: IdMetadata<entityType>;
@@ -7,11 +7,13 @@ export {};
7
7
  //p1 - v - add schema option to create postgres data provider
8
8
  /*p1 - V - with remult async for remultexpress
9
9
  //y1 - lint tests (reference to js)
10
+ //p1 - V Operator '>' cannot be applied to types 'Number' and 'number'.ts(2365) - change fields to <entityType,number> (now it's Number)
11
+ //p1 - V Field(()=>String) - doesn't play nice with strict mode - it prevents people from extending basic types
10
12
  //p1 - V withRemult function Add a with remult to Remult! - there is an existing one called Remult.run
11
13
  //p1 - V - dbname to metadata consider making dbname in the field metadata options - non optional, so it'll be clear that it always have value - something like require the specific key - or move it to the metadata field
12
14
  //p1 - V - getEntityRefClone What I would like is to make a copy of the item (without getting it from the server again)
13
15
  //p1 - V find one i had a question about find first's different syntax from find that confused a user
14
-
16
+ //p1 - https://dexie.org/
15
17
  rename V - withremultpromise to that withRemultAsync
16
18
  expose live query storage in remult
17
19
 
@@ -62,8 +64,6 @@ remult.apiClient.url='localhost:3007/api
62
64
  //y2 - discuss a default date formatter
63
65
  //y2 - add some api testing framework for user unit tests (will help with codesandbox based discussions)
64
66
  //y2 - live query refresh of view on table update
65
- //y2 - Operator '>' cannot be applied to types 'Number' and 'number'.ts(2365) - change fields to <entityType,number> (now it's Number)
66
- //y2 - Field(()=>String) - doesn't play nice with strict mode - it prevents people from extending basic types
67
67
  //y2 - livequery for findfirst (@JY)
68
68
  //y2 - #239 - (@JY) add a way to get from fieldMetadata back to entity repo (like we have in fieldRef)
69
69
  //p2 - constraints (@JY)
@@ -6,7 +6,6 @@ export interface SqlImplementation {
6
6
  entityIsUsedForTheFirstTime(entity: EntityMetadata): Promise<void>;
7
7
  ensureSchema?(entities: EntityMetadata[]): Promise<void>;
8
8
  supportsJsonColumnType?: boolean;
9
- wrapIdentifier?(name: string): string;
10
9
  }
11
10
  export interface SqlCommand extends SqlCommandWithParameters {
12
11
  execute(sql: string): Promise<SqlResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.24.0-exp.4",
3
+ "version": "0.24.0",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "homepage": "https://remult.dev",
6
6
  "repository": {
package/remult-nuxt.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { H3Event } from 'h3';
2
- import { RemultServerCore, RemultServerOptions, RemultServer } from './server/index.js';
2
+ import type { RemultServerCore, RemultServerOptions, RemultServer } from './server/index.js';
3
3
  export declare function remultNuxt(options: RemultServerOptions<H3Event>): RemultNuxtServer;
4
4
  export type RemultNuxtServer = RemultServerCore<H3Event> & ((event: H3Event) => Promise<any>) & {
5
5
  withRemult: RemultServer<H3Event>['withRemultAsync'];
package/remult-nuxt.js CHANGED
@@ -57,6 +57,8 @@ function remultNuxt(options) {
57
57
  _a.label = 3;
58
58
  case 3:
59
59
  if (r) {
60
+ if (r.statusCode !== 200)
61
+ (0, h3_1.setResponseStatus)(event, r.statusCode);
60
62
  return [2 /*return*/, r.data];
61
63
  }
62
64
  return [2 /*return*/];
@@ -66,8 +68,8 @@ function remultNuxt(options) {
66
68
  return Object.assign(handler, {
67
69
  getRemult: function (req) { return result.getRemult(req); },
68
70
  openApiDoc: function (options) { return result.openApiDoc(options); },
69
- withRemult: function (event, what) {
70
- return result.withRemultAsync(event, what);
71
+ withRemult: function (request, what) {
72
+ return result.withRemultAsync(request, what);
71
73
  },
72
74
  });
73
75
  }
@@ -10,9 +10,9 @@ export declare class Fields {
10
10
  static json<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
11
11
  static dateOnly<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
12
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>;
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
16
  static createdAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
17
17
  static updatedAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
18
18
  static uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
@@ -126,7 +126,7 @@ export declare class Relations {
126
126
  * @Fields.string((options,remult) => options.includeInApi = true)
127
127
  * title='';
128
128
  */
129
- export declare function Field<entityType = any, valueType = any>(valueType: (() => ClassType<valueType>) | undefined, ...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, context: ClassFieldDecoratorContextStub<entityType, valueType | undefined> | string, c?: any) => void;
129
+ export declare function Field<entityType = any, valueType = any>(valueType: (() => valueType extends number ? Number : valueType extends string ? String : valueType extends boolean ? Boolean : ClassType<valueType>) | undefined, ...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, context: ClassFieldDecoratorContextStub<entityType, valueType | undefined> | string, c?: any) => void;
130
130
  export interface StringFieldOptions<entityType = any> extends FieldOptions<entityType, string> {
131
131
  maxLength?: number;
132
132
  }
@@ -211,6 +211,7 @@ var Relations = /** @class */ (function () {
211
211
  ? {}
212
212
  : options);
213
213
  if (!op.field && !op.fields && !op.findOptions)
214
+ //@ts-ignore
214
215
  return Field(toEntityType, tslib_1.__assign(tslib_1.__assign({}, op), (_a = {}, _a[relationInfoMember_js_1.relationInfoMember] = {
215
216
  //field,
216
217
  toType: toEntityType,
@@ -234,13 +234,31 @@ var RepositoryImplementation = /** @class */ (function () {
234
234
  };
235
235
  RepositoryImplementation.prototype.delete = function (item) {
236
236
  return tslib_1.__awaiter(this, void 0, void 0, function () {
237
+ var ref, ref2_1, ref2;
237
238
  return tslib_1.__generator(this, function (_a) {
238
- if (typeof item === 'string' || typeof item === 'number')
239
- return [2 /*return*/, this.edp.delete(item)];
240
- else {
241
- return [2 /*return*/, this.getRefForExistingRow(item, undefined).delete()];
239
+ switch (_a.label) {
240
+ case 0:
241
+ ref = (0, getEntityRef_js_1.getEntityRef)(item, false);
242
+ if (ref)
243
+ return [2 /*return*/, ref.delete()];
244
+ if (!(typeof item === 'string' || typeof item === 'number')) return [3 /*break*/, 4];
245
+ if (!this.dataProvider.isProxy) return [3 /*break*/, 1];
246
+ return [2 /*return*/, this.edp.delete(item)];
247
+ case 1: return [4 /*yield*/, this.findId(item)];
248
+ case 2:
249
+ ref2_1 = _a.sent();
250
+ if (!ref2_1) return [3 /*break*/, 4];
251
+ return [4 /*yield*/, (0, getEntityRef_js_1.getEntityRef)(ref2_1).delete()];
252
+ case 3: return [2 /*return*/, _a.sent()];
253
+ case 4:
254
+ ref2 = this.getRefForExistingRow(item, undefined);
255
+ if (!!this.dataProvider.isProxy) return [3 /*break*/, 6];
256
+ return [4 /*yield*/, ref2.reload()];
257
+ case 5:
258
+ _a.sent();
259
+ _a.label = 6;
260
+ case 6: return [2 /*return*/, ref2.delete()];
242
261
  }
243
- return [2 /*return*/];
244
262
  });
245
263
  });
246
264
  };
@@ -8,11 +8,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  //p1 - v - add schema option to create postgres data provider
9
9
  /*p1 - V - with remult async for remultexpress
10
10
  //y1 - lint tests (reference to js)
11
+ //p1 - V Operator '>' cannot be applied to types 'Number' and 'number'.ts(2365) - change fields to <entityType,number> (now it's Number)
12
+ //p1 - V Field(()=>String) - doesn't play nice with strict mode - it prevents people from extending basic types
11
13
  //p1 - V withRemult function Add a with remult to Remult! - there is an existing one called Remult.run
12
14
  //p1 - V - dbname to metadata consider making dbname in the field metadata options - non optional, so it'll be clear that it always have value - something like require the specific key - or move it to the metadata field
13
15
  //p1 - V - getEntityRefClone What I would like is to make a copy of the item (without getting it from the server again)
14
16
  //p1 - V find one i had a question about find first's different syntax from find that confused a user
15
-
17
+ //p1 - https://dexie.org/
16
18
  rename V - withremultpromise to that withRemultAsync
17
19
  expose live query storage in remult
18
20
 
@@ -63,8 +65,6 @@ remult.apiClient.url='localhost:3007/api
63
65
  //y2 - discuss a default date formatter
64
66
  //y2 - add some api testing framework for user unit tests (will help with codesandbox based discussions)
65
67
  //y2 - live query refresh of view on table update
66
- //y2 - Operator '>' cannot be applied to types 'Number' and 'number'.ts(2365) - change fields to <entityType,number> (now it's Number)
67
- //y2 - Field(()=>String) - doesn't play nice with strict mode - it prevents people from extending basic types
68
68
  //y2 - livequery for findfirst (@JY)
69
69
  //y2 - #239 - (@JY) add a way to get from fieldMetadata back to entity repo (like we have in fieldRef)
70
70
  //p2 - constraints (@JY)