remult 3.4.2 → 3.5.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/internals.js +1 -0
- package/esm/postgres/postgres-data-provider.js +4 -5
- package/esm/remult-duckdb.js +4 -0
- package/esm/remult-knex/index.js +69 -14
- package/esm/remult-mongo.js +25 -7
- package/esm/remult-sqlite-core.js +4 -1
- package/esm/server/remult-api-server.js +14 -6
- package/esm/src/buildRestDataProvider.js +8 -6
- package/esm/src/context.js +1 -1
- package/esm/src/data-api.js +2 -2
- package/esm/src/data-interfaces.js +2 -1
- package/esm/src/data-providers/array-entity-data-provider.js +9 -4
- package/esm/src/data-providers/rest-data-provider-using-fetch.js +13 -6
- package/esm/src/data-providers/retry.js +11 -6
- package/esm/src/data-providers/sql-database.js +40 -30
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +35 -4
- package/esm/src/filter/filter-interfaces.js +18 -4
- package/esm/src/live-query/SubscriptionChannel.js +13 -8
- package/esm/src/remult-proxy.js +12 -0
- package/esm/src/remult-static.js +2 -0
- package/esm/src/remult3/Fields.js +14 -14
- package/esm/src/remult3/RepositoryImplementation.js +69 -32
- package/esm/src/remult3/remult3.js +2 -0
- package/esm/src/server-action.js +43 -14
- package/esm/src/sort.js +18 -0
- package/index.d.ts +4 -3
- package/internals.d.ts +1 -0
- package/internals.js +3 -1
- package/package.json +41 -1
- package/postgres/postgres-data-provider.d.ts +2 -3
- package/postgres/postgres-data-provider.js +4 -4
- package/remult-duckdb.d.ts +2 -0
- package/remult-duckdb.js +4 -0
- package/remult-knex/index.d.ts +2 -0
- package/remult-knex/index.js +153 -83
- package/remult-mongo.js +28 -7
- package/remult-sqlite-core.d.ts +2 -1
- package/remult-sqlite-core.js +4 -0
- package/server/remult-api-server.d.ts +28 -1
- package/server/remult-api-server.js +19 -12
- package/src/buildRestDataProvider.d.ts +1 -1
- package/src/buildRestDataProvider.js +8 -6
- package/src/column-interfaces.d.ts +5 -1
- package/src/context.js +1 -1
- package/src/data-api.js +2 -2
- package/src/data-interfaces.d.ts +0 -1
- package/src/data-interfaces.js +3 -0
- package/src/data-providers/array-entity-data-provider.js +9 -4
- package/src/data-providers/rest-data-provider-using-fetch.d.ts +1 -1
- package/src/data-providers/rest-data-provider-using-fetch.js +11 -4
- package/src/data-providers/retry.d.ts +4 -1
- package/src/data-providers/retry.js +26 -16
- package/src/data-providers/sql-database.d.ts +7 -3
- package/src/data-providers/sql-database.js +99 -81
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +8 -0
- package/src/filter/filter-consumer-bridge-to-sql-request.js +58 -19
- package/src/filter/filter-interfaces.js +19 -2
- package/src/live-query/SubscriptionChannel.js +16 -10
- package/src/remult-proxy.js +28 -0
- package/src/remult-static.d.ts +4 -0
- package/src/remult-static.js +2 -0
- package/src/remult3/Fields.d.ts +5 -3
- package/src/remult3/Fields.js +24 -13
- package/src/remult3/RepositoryImplementation.d.ts +7 -0
- package/src/remult3/RepositoryImplementation.js +325 -264
- package/src/remult3/remult3.d.ts +68 -5
- package/src/remult3/remult3.js +2 -0
- package/src/server-action.d.ts +34 -2
- package/src/server-action.js +195 -115
- package/src/sort.d.ts +19 -0
- package/src/sort.js +20 -1
- package/src/sql-command.d.ts +2 -1
package/src/remult3/remult3.d.ts
CHANGED
|
@@ -258,15 +258,40 @@ export interface EntityMetadata<entityType = unknown> {
|
|
|
258
258
|
*/
|
|
259
259
|
readonly idMetadata: IdMetadata<entityType>;
|
|
260
260
|
}
|
|
261
|
+
declare const notAFieldMarker: unique symbol;
|
|
262
|
+
/**
|
|
263
|
+
* Marks one property as not a field, e.g. a getter computed from other fields. It's left out of
|
|
264
|
+
* `where`, `orderBy`, `insert`, `fields` and the other field types. Types only.
|
|
265
|
+
*
|
|
266
|
+
* The marker goes on the property, not on the value's class, so the same class can still be
|
|
267
|
+
* stored as a real field elsewhere. A plain `T` still assigns to it, so no casts are needed.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* \@Entity('orders')
|
|
271
|
+
* class Order {
|
|
272
|
+
* \@Fields.integer() priceCents = 0
|
|
273
|
+
* \@Fields.string() priceCurrency = 'USD'
|
|
274
|
+
* get price(): NotAField<Money> {
|
|
275
|
+
* return new Money(this.priceCents, this.priceCurrency)
|
|
276
|
+
* }
|
|
277
|
+
* }
|
|
278
|
+
*
|
|
279
|
+
* // Type error. Without NotAField this typechecks and throws "field not found".
|
|
280
|
+
* repo(Order).find({ where: { price: new Money(100, 'USD') } })
|
|
281
|
+
*/
|
|
282
|
+
export type NotAField<T> = T & {
|
|
283
|
+
readonly [notAFieldMarker]?: true;
|
|
284
|
+
};
|
|
285
|
+
type IsNotAField<V> = 0 extends 1 & V ? false : [NonNullable<V>] extends [never] ? false : typeof notAFieldMarker extends keyof NonNullable<V> ? {} extends Pick<NonNullable<V>, typeof notAFieldMarker> ? true : false : false;
|
|
261
286
|
export declare type MembersOnly<T> = {
|
|
262
|
-
[K in keyof Omit<T, keyof EntityBase> as T[K] extends Function ? never : K extends string ? K : never]: T[K];
|
|
287
|
+
[K in keyof Omit<T, keyof EntityBase> as T[K] extends Function ? never : IsNotAField<T[K]> extends true ? never : K extends string ? K : never]: T[K];
|
|
263
288
|
};
|
|
264
289
|
export declare type idType<entityType> = entityType extends {
|
|
265
290
|
id?: infer U;
|
|
266
291
|
} ? U extends string ? string : U extends number ? number : string | number : string | number;
|
|
267
292
|
export type NumericKeys<T> = {
|
|
268
|
-
[K in keyof T]: T[K] extends number | undefined | null ? K : never;
|
|
269
|
-
}[keyof T];
|
|
293
|
+
[K in keyof MembersOnly<T>]: T[K] extends number | undefined | null ? K : never;
|
|
294
|
+
}[keyof MembersOnly<T>];
|
|
270
295
|
/**
|
|
271
296
|
* Options for performing aggregation on an entity in the repository.
|
|
272
297
|
*
|
|
@@ -420,6 +445,21 @@ export interface Repository<entityType> {
|
|
|
420
445
|
findOne(options?: FindFirstOptions<entityType>): Promise<entityType | undefined>;
|
|
421
446
|
/** returns the items that matches the id. If id is undefined | null, returns null */
|
|
422
447
|
findId(id: idType<entityType>, options?: FindFirstOptionsBase<entityType>): Promise<entityType | undefined | null>;
|
|
448
|
+
/** returns the item that matches the id, and throws an `EntityError` with `httpStatusCode` 404 if no item matches
|
|
449
|
+
* @example
|
|
450
|
+
* const task = await taskRepo.findIdOrThrow(id)
|
|
451
|
+
*/
|
|
452
|
+
findIdOrThrow(id: idType<entityType>, options?: FindFirstOptionsBase<entityType>): Promise<entityType>;
|
|
453
|
+
/** returns the first item that matches the `where` condition, and throws an `EntityError` with `httpStatusCode` 404 if no item matches
|
|
454
|
+
* @example
|
|
455
|
+
* await taskRepo.findFirstOrThrow({ completed: false })
|
|
456
|
+
*/
|
|
457
|
+
findFirstOrThrow(where?: EntityFilter<entityType>, options?: FindFirstOptions<entityType>): Promise<entityType>;
|
|
458
|
+
/** returns the first item that matches the `where` condition, and throws an `EntityError` with `httpStatusCode` 404 if no item matches
|
|
459
|
+
* @example
|
|
460
|
+
* await taskRepo.findOneOrThrow({ where: { completed: false } })
|
|
461
|
+
*/
|
|
462
|
+
findOneOrThrow(options?: FindFirstOptions<entityType>): Promise<entityType>;
|
|
423
463
|
/**
|
|
424
464
|
* Performs an aggregation on the repository's entity type based on the specified options.
|
|
425
465
|
*
|
|
@@ -724,6 +764,9 @@ export interface LiveQueryChangeInfo<entityType> {
|
|
|
724
764
|
* to update the component's state based on the live query changes.
|
|
725
765
|
*
|
|
726
766
|
* @param {entityType[] | undefined} prevState The previous state of the array of result items.
|
|
767
|
+
* @param {{ pos?: 'auto' | 'first' | 'last' }} [options] Controls where added items are placed.
|
|
768
|
+
* `'auto'` (default) keeps the array sorted by the query's `orderBy` (or the entity's `defaultOrderBy`, falling back to `'last'` when neither is set);
|
|
769
|
+
* `'first'` prepends added items; `'last'` appends them.
|
|
727
770
|
* @returns {entityType[]} The updated array of result items after applying the changes.
|
|
728
771
|
*
|
|
729
772
|
* @example
|
|
@@ -738,7 +781,9 @@ export interface LiveQueryChangeInfo<entityType> {
|
|
|
738
781
|
* .subscribe(info => setTasks(info.applyChanges));
|
|
739
782
|
* }, []);
|
|
740
783
|
*/
|
|
741
|
-
applyChanges(prevState: entityType[] | undefined
|
|
784
|
+
applyChanges(prevState: entityType[] | undefined, options?: {
|
|
785
|
+
pos?: 'auto' | 'first' | 'last';
|
|
786
|
+
}): entityType[];
|
|
742
787
|
}
|
|
743
788
|
export interface FindOptions<entityType> extends FindOptionsBase<entityType> {
|
|
744
789
|
/** Number of rows returned. _(Defaults to 100 in the browser)_
|
|
@@ -761,11 +806,26 @@ export interface FindOptions<entityType> extends FindOptionsBase<entityType> {
|
|
|
761
806
|
export declare type EntityOrderBy<entityType> = {
|
|
762
807
|
[Properties in keyof Partial<MembersOnly<entityType>>]?: 'asc' | 'desc';
|
|
763
808
|
};
|
|
809
|
+
/**
|
|
810
|
+
* Fields of a type added to this interface accept `$gt`, `$gte`, `$lt` and
|
|
811
|
+
* `$lte` in an {@link EntityFilter}. The in-memory and JSON providers compare
|
|
812
|
+
* `valueConverter.toJson` output with `<`/`>`, so it has to sort like the
|
|
813
|
+
* values, e.g. `Temporal.Instant.toString()` drops trailing zeros and sorts
|
|
814
|
+
* `00:00:00Z` after `00:00:00.5Z`.
|
|
815
|
+
* @example
|
|
816
|
+
* declare module 'remult' {
|
|
817
|
+
* interface ComparableTypes {
|
|
818
|
+
* instant: Temporal.Instant
|
|
819
|
+
* }
|
|
820
|
+
* }
|
|
821
|
+
*/
|
|
822
|
+
export interface ComparableTypes {
|
|
823
|
+
}
|
|
764
824
|
/**Used to filter the desired result set
|
|
765
825
|
* @see [EntityFilter](http://remult.dev/docs/entityFilter.html)
|
|
766
826
|
*/
|
|
767
827
|
export declare type EntityFilter<entityType> = {
|
|
768
|
-
[Properties in keyof Partial<MembersOnly<entityType>>]?: (Partial<entityType>[Properties] extends number | Date | undefined | null ? ComparisonValueFilter<Partial<entityType>[Properties]> : Partial<entityType>[Properties] extends string | undefined ? Partial<entityType>[Properties] | (ContainsStringValueFilter & ComparisonValueFilter<Partial<entityType>[Properties]>) : Partial<entityType>[Properties] extends boolean | undefined | null ? ValueFilter<boolean> : Partial<entityType>[Properties] extends {
|
|
828
|
+
[Properties in keyof Partial<MembersOnly<entityType>>]?: (Partial<entityType>[Properties] extends number | Date | ComparableTypes[keyof ComparableTypes] | undefined | null ? ComparisonValueFilter<Partial<entityType>[Properties]> : Partial<entityType>[Properties] extends string | undefined ? Partial<entityType>[Properties] | (ContainsStringValueFilter & ComparisonValueFilter<Partial<entityType>[Properties]>) : Partial<entityType>[Properties] extends boolean | undefined | null ? ValueFilter<boolean> : Partial<entityType>[Properties] extends {
|
|
769
829
|
id?: string | number;
|
|
770
830
|
} | undefined ? IdFilter<Partial<entityType>[Properties]> : ValueFilter<Partial<entityType>[Properties]>) | ContainsStringValueFilter;
|
|
771
831
|
} & {
|
|
@@ -1228,4 +1288,7 @@ export declare const flags: {
|
|
|
1228
1288
|
liveQueryKeepAliveMs: number;
|
|
1229
1289
|
/** Version poll while SSE is stale */
|
|
1230
1290
|
liveQueryPollWhenStaleMs: number;
|
|
1291
|
+
/** Client calls reject with an `EntityError` instead of a plain object. On by default in the next major. */
|
|
1292
|
+
clientErrorsAsEntityError: boolean;
|
|
1231
1293
|
};
|
|
1294
|
+
export {};
|
package/src/remult3/remult3.js
CHANGED
|
@@ -25,6 +25,8 @@ exports.flags = {
|
|
|
25
25
|
liveQueryKeepAliveMs: 30000,
|
|
26
26
|
/** Version poll while SSE is stale */
|
|
27
27
|
liveQueryPollWhenStaleMs: 1000,
|
|
28
|
+
/** Client calls reject with an `EntityError` instead of a plain object. On by default in the next major. */
|
|
29
|
+
clientErrorsAsEntityError: false,
|
|
28
30
|
};
|
|
29
31
|
/*p1 - issues in https://stackblitz.com/edit/demo-allow-delete-based-on-other-entity:
|
|
30
32
|
- don't like the ensure schema
|
package/src/server-action.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare abstract class Action<inParam, outParam> implements ActionInterfa
|
|
|
15
15
|
constructor(actionUrl: string, queue: boolean, allowed: AllowedForInstance<any>);
|
|
16
16
|
static apiUrlForJobStatus: string;
|
|
17
17
|
run(pIn: inParam, baseUrl?: string, http?: RestDataProviderHttpProvider): Promise<outParam>;
|
|
18
|
-
doWork: (args: any[], self: any,
|
|
18
|
+
doWork: (args: any[], self: any, caller?: Remult) => Promise<any>;
|
|
19
19
|
protected abstract execute(info: inParam, req: Remult, res: DataApiResponse): Promise<outParam>;
|
|
20
20
|
__register(reg: (url: string, queue: boolean, allowed: AllowedForInstance<any>, what: (data: any, req: Remult, res: DataApiResponse) => void) => void): void;
|
|
21
21
|
}
|
|
@@ -51,6 +51,28 @@ export interface BackendMethodOptions<type> {
|
|
|
51
51
|
blockUser?: boolean;
|
|
52
52
|
paramTypes?: any[] | (() => any[]);
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Sends a backend method's argument list through `args` and its return value through `result`.
|
|
56
|
+
* An `EntityError` thrown from either on the backend reaches the caller.
|
|
57
|
+
*/
|
|
58
|
+
export interface BackendMethodSerializer {
|
|
59
|
+
args: BackendMethodValueSerializer;
|
|
60
|
+
result: BackendMethodValueSerializer;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Turns a value into JSON and back. superjson and oRPC's `StandardRPCSerializer` both fit.
|
|
64
|
+
* Either method may return a promise.
|
|
65
|
+
*/
|
|
66
|
+
export interface BackendMethodValueSerializer {
|
|
67
|
+
serialize(value: unknown, context: BackendMethodSerializerContext): unknown | Promise<unknown>;
|
|
68
|
+
deserialize(value: unknown, context: BackendMethodSerializerContext): unknown | Promise<unknown>;
|
|
69
|
+
}
|
|
70
|
+
export interface BackendMethodSerializerContext {
|
|
71
|
+
/** The `Remult` making the call, so a serializer can rebuild entities with `remult.repo(...)`. */
|
|
72
|
+
remult: Remult;
|
|
73
|
+
/** The options passed to `@BackendMethod`, so a serializer can read settings added to them. */
|
|
74
|
+
options: BackendMethodOptions<unknown>;
|
|
75
|
+
}
|
|
54
76
|
export declare function Controller(key: string): (target: any, context?: any) => any;
|
|
55
77
|
export interface ClassMethodDecoratorContextStub<This = unknown, Value extends (this: This, ...args: any) => any = (this: This, ...args: any) => any> {
|
|
56
78
|
readonly kind: 'method';
|
|
@@ -78,6 +100,16 @@ export interface ClassMethodDecoratorContextStub<This = unknown, Value extends (
|
|
|
78
100
|
* ```
|
|
79
101
|
*/
|
|
80
102
|
export declare function BackendMethod<type = unknown>(options: BackendMethodOptions<type>): (target: any, context: ClassMethodDecoratorContextStub<type> | string, descriptor?: any) => any;
|
|
103
|
+
export declare namespace BackendMethod {
|
|
104
|
+
/**
|
|
105
|
+
* Sends every backend method's arguments and return value through this serializer. Set it in a
|
|
106
|
+
* file that both the frontend and the backend import, or calls break.
|
|
107
|
+
* @example
|
|
108
|
+
* import superjson from 'superjson'
|
|
109
|
+
* BackendMethod.serializer = { args: superjson, result: superjson }
|
|
110
|
+
*/
|
|
111
|
+
let serializer: BackendMethodSerializer | undefined;
|
|
112
|
+
}
|
|
81
113
|
export interface jobWasQueuedResult {
|
|
82
114
|
queuedJobId?: string;
|
|
83
115
|
}
|
|
@@ -96,7 +128,7 @@ export declare function prepareArgsToSend(types: any[], args: any[]): any[];
|
|
|
96
128
|
export declare function prepareReceivedArgs(types: any[], args: any[], remult: Remult, ds: DataProvider, res: DataApiResponse): Promise<any[]>;
|
|
97
129
|
export declare const classBackendMethodsArray: unique symbol;
|
|
98
130
|
export interface ActionInterface {
|
|
99
|
-
doWork: (args: any[], self: any,
|
|
131
|
+
doWork: (args: any[], self: any, caller?: Remult) => Promise<any>;
|
|
100
132
|
__register(reg: (url: string, queue: boolean, allowed: AllowedForInstance<any>, what: (data: any, req: Remult, res: DataApiResponse) => void) => void): void;
|
|
101
133
|
}
|
|
102
134
|
export {};
|