rads-db 3.0.55 → 3.0.57

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/dist/index.d.ts CHANGED
@@ -5,12 +5,12 @@ type MaybePromise$1<T> = Promise<T> | T;
5
5
  type Change<T> = {
6
6
  [K in keyof T]?: T[K] extends any[] ? T[K] : T[K] extends {} ? Change<T[K]> : T[K];
7
7
  };
8
- interface GetManyArgs<EN extends keyof EntityMeta, W> extends GetArgs<EN, W> {
8
+ interface GetManyArgs<EN extends keyof EntityMeta> extends GetArgs<EN> {
9
9
  cursor?: string | null;
10
10
  maxItemCount?: number;
11
11
  orderBy?: string;
12
12
  }
13
- interface VerifyManyArgs<EN extends keyof EntityMeta, W> extends GetManyArgs<EN, W> {
13
+ interface VerifyManyArgs<EN extends keyof EntityMeta> extends GetManyArgs<EN> {
14
14
  recompute?: string[];
15
15
  dryRun?: boolean;
16
16
  }
@@ -24,24 +24,24 @@ interface VerifyManyResponse {
24
24
  toRemove?: any;
25
25
  }[];
26
26
  }
27
- type GetArgsWhere<W> = W & {
28
- _not?: GetArgsWhere<W>;
29
- _and?: GetArgsWhere<W>[];
30
- _or?: GetArgsWhere<W>[];
27
+ type Where<EN extends keyof EntityMeta> = EntityMeta[EN]['whereType'] & {
28
+ _not?: Where<EN>;
29
+ _and?: Where<EN>[];
30
+ _or?: Where<EN>[];
31
31
  };
32
- interface GetArgs<EN extends keyof EntityMeta, W> {
33
- where?: GetArgsWhere<W>;
32
+ interface GetArgs<EN extends keyof EntityMeta> {
33
+ where?: Where<EN>;
34
34
  include?: GetArgsInclude<EN>;
35
35
  }
36
- interface GetAggArgs<EN extends keyof EntityMeta, W> {
37
- where?: GetArgsWhere<W>;
36
+ interface GetAggArgs<EN extends keyof EntityMeta> {
37
+ where?: Where<EN>;
38
38
  agg: GetAggArgsAgg<EN>;
39
39
  }
40
40
  type GetAggArgsAgg<EN extends keyof EntityMeta, F extends string = EntityMeta[EN]['aggregates']> = ('_count' | `${F}_min` | `${F}_max`)[];
41
- type GetManyArgsAny = GetManyArgs<any, any>;
42
- type GetArgsAny = GetArgs<any, any>;
43
- type GetAggArgsAny = GetAggArgs<any, any>;
44
- type VerifyManyArgsAny = VerifyManyArgs<any, any>;
41
+ type GetManyArgsAny = GetManyArgs<any>;
42
+ type GetArgsAny = GetArgs<any>;
43
+ type GetAggArgsAny = GetAggArgs<any>;
44
+ type VerifyManyArgsAny = VerifyManyArgs<any>;
45
45
  type GetArgsInclude<EN extends keyof EntityMeta, R extends keyof EntityMeta[EN]['relations'] = keyof EntityMeta[EN]['relations']> = [R] extends [never] ? {
46
46
  _pick?: EntityMeta[EN]['primitives'][];
47
47
  } : {
@@ -49,18 +49,22 @@ type GetArgsInclude<EN extends keyof EntityMeta, R extends keyof EntityMeta[EN][
49
49
  } & {
50
50
  [K in R]?: GetArgsInclude<EntityMeta[EN]['relations'][K]['entityName']>;
51
51
  };
52
- type GetAggResponse<EN extends keyof EntityMeta, A extends GetAggArgs<EN, any>> = {
52
+ type GetAggResponse<EN extends keyof EntityMeta, A extends GetAggArgs<EN>> = {
53
53
  [K in A['agg'][0]]: K extends '_count' ? number : number | undefined;
54
54
  };
55
- interface GetManyResponse<EN extends keyof EntityMeta, A extends GetArgs<EN, any>> {
55
+ interface GetManyResponse<EN extends keyof EntityMeta, A extends GetArgs<EN>> {
56
56
  nodes: GetResponse<EN, A>[];
57
57
  cursor: string | null;
58
58
  }
59
- type GetResponse<EN extends keyof EntityMeta, A extends GetArgs<EN, any>> = A extends {
59
+ type GetResponse<EN extends keyof EntityMeta, A extends GetArgs<EN>> = A extends {
60
60
  include: any;
61
61
  } ? GetResponseInclude<EN, A['include']> : GetResponseNoInclude<EN>;
62
- type Get<EntityName extends keyof EntityMeta, Include extends GetArgs<EntityName, any>['include'] = {}> = GetResponse<EntityName, {
62
+ type Get<EntityName extends keyof EntityMeta, Include extends keyof EntityMeta[EntityName]['relations'] | GetArgsInclude<EntityName> = {}> = Include extends GetArgsInclude<EntityName> ? GetResponse<EntityName, {
63
63
  include: Include;
64
+ }> : GetResponse<EntityName, {
65
+ include: {
66
+ [K in Include]: {};
67
+ };
64
68
  }>;
65
69
  type RelationData<EN extends keyof EntityMeta, K extends keyof EntityMeta[EN]['relations']> = Pick<EntityMeta[EN]['relations'][K]['entity'], EntityMeta[EN]['relations'][K]['denormFields']>;
66
70
  type KeepArray<TMaybeArray, TType> = NonNullable<TMaybeArray> extends any[] ? TType[] : TType;
@@ -95,20 +99,20 @@ type Put<EntityName extends keyof EntityMeta> = PutArgs<EntityMeta[EntityName]['
95
99
  type DeepKeys<T> = T extends object ? {
96
100
  [K in (string | number) & keyof T]: `${`.${K}` | (`${K}` extends `${number}` ? `[${K}]` : never)}${'' | DeepKeys<T[K]>}`;
97
101
  }[(string | number) & keyof T] : never;
98
- interface EntityMethods<E, EN extends keyof EntityMeta, W> {
102
+ interface EntityMethods<E, EN extends keyof EntityMeta> {
99
103
  /** Returns object with with random UUID as `id` and prefilled default values */
100
104
  construct(): E;
101
105
  /** Used to access underlying mechanism of storage directly.
102
106
  * Warning: bypasses all rads features - schema won't be validated, default values won't be filled, etc. */
103
107
  driver: Driver;
104
- get<A extends GetArgs<EN, W>>(args: A, ctx?: RadsRequestContext): MaybePromise$1<GetResponse<EN, A>>;
105
- getMany<A extends GetManyArgs<EN, W>>(args?: A, ctx?: RadsRequestContext): MaybePromise$1<GetManyResponse<EN, A>>;
106
- getAgg<A extends GetAggArgs<EN, W>>(args: A, ctx?: RadsRequestContext): MaybePromise$1<GetAggResponse<EN, A>>;
107
- getAll<A extends GetManyArgs<EN, W>>(args?: A, ctx?: RadsRequestContext): MaybePromise$1<GetManyResponse<EN, A>['nodes']>;
108
+ get<A extends GetArgs<EN>>(args: A, ctx?: RadsRequestContext): MaybePromise$1<GetResponse<EN, A>>;
109
+ getMany<A extends GetManyArgs<EN>>(args?: A, ctx?: RadsRequestContext): MaybePromise$1<GetManyResponse<EN, A>>;
110
+ getAgg<A extends GetAggArgs<EN>>(args: A, ctx?: RadsRequestContext): MaybePromise$1<GetAggResponse<EN, A>>;
111
+ getAll<A extends GetManyArgs<EN>>(args?: A, ctx?: RadsRequestContext): MaybePromise$1<GetManyResponse<EN, A>['nodes']>;
108
112
  put(data: PutArgs<E>, ctx?: RadsRequestContext): MaybePromise$1<GetResponseNoInclude<EN>>;
109
113
  putMany(data: PutArgs<E>[], ctx?: RadsRequestContext): MaybePromise$1<GetResponseNoInclude<EN>[]>;
110
- verifyMany<A extends VerifyManyArgs<EN, W>>(args?: A, ctx?: RadsRequestContext): MaybePromise$1<VerifyManyResponse>;
111
- verifyAll<A extends VerifyManyArgs<EN, W>>(args?: A, ctx?: RadsRequestContext): MaybePromise$1<Pick<VerifyManyResponse, 'correctCount' | 'incorrectCount'>>;
114
+ verifyMany<A extends VerifyManyArgs<EN>>(args?: A, ctx?: RadsRequestContext): MaybePromise$1<VerifyManyResponse>;
115
+ verifyAll<A extends VerifyManyArgs<EN>>(args?: A, ctx?: RadsRequestContext): MaybePromise$1<Pick<VerifyManyResponse, 'correctCount' | 'incorrectCount'>>;
112
116
  }
113
117
 
114
118
  type MaybePromise<T> = Promise<T> | T;
@@ -404,7 +408,7 @@ interface RadsFeature {
404
408
  name: string;
405
409
  radsUiSlots?: Record<RadsUiSlotName, RadsUiSlotDefinition[]>;
406
410
  init?: (db: Record<string, any>, context: ComputedContextGlobal) => void;
407
- enhanceEntityMethods?: (context: ComputedContext, entityMethodsObj: EntityMethods<any, any, any>) => void;
411
+ enhanceEntityMethods?: (context: ComputedContext, entityMethodsObj: EntityMethods<any, any>) => void;
408
412
  beforeGet?: (args: GetArgsAny, ctx: RadsRequestContext, context: ComputedContext) => MaybePromise<any>;
409
413
  afterGet?: (items: any[], args: GetArgsAny, ctx: RadsRequestContext, context: ComputedContext) => MaybePromise<void>;
410
414
  beforePut?: (items: RadsHookDoc[], ctx: RadsRequestContext, computedContext: ComputedContext) => void;
@@ -444,4 +448,4 @@ declare function createRadsDb(args?: CreateRadsDbArgs): RadsDb;
444
448
  */
445
449
  declare function createRadsDbClient(args?: CreateRadsDbClientArgs): RadsDb;
446
450
 
447
- export { Change, ComputedContext, ComputedContextGlobal, ComputedDecoratorArgs, CreateRadsArgsDrivers, CreateRadsDbArgs, CreateRadsDbArgsNormalized, CreateRadsDbClientArgs, DeepKeys, DeepPartial, DeepPartialWithNulls, DeepPartialWithNullsItem, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, EnumDefinition, FieldDecoratorArgs, FieldDefinition, FileSystemNode, FileUploadArgs, FileUploadDriver, FileUploadResult, GenerateClientNormalizedOptions, GenerateClientOptions, Get, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetArgsWhere, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, MinimalDriver, Put, PutArgs, PutEffect, RadsFeature, RadsHookDoc, RadsRequestContext, RadsUiSlotDefinition, RadsUiSlotName, RadsVitePluginOptions, Relation, RequiredFields, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, VerifyManyArgs, VerifyManyArgsAny, VerifyManyResponse, WhereJsonContains, cleanUndefinedAndNull, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
451
+ export { Change, ComputedContext, ComputedContextGlobal, ComputedDecoratorArgs, CreateRadsArgsDrivers, CreateRadsDbArgs, CreateRadsDbArgsNormalized, CreateRadsDbClientArgs, DeepKeys, DeepPartial, DeepPartialWithNulls, DeepPartialWithNullsItem, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, EnumDefinition, FieldDecoratorArgs, FieldDefinition, FileSystemNode, FileUploadArgs, FileUploadDriver, FileUploadResult, GenerateClientNormalizedOptions, GenerateClientOptions, Get, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, MinimalDriver, Put, PutArgs, PutEffect, RadsFeature, RadsHookDoc, RadsRequestContext, RadsUiSlotDefinition, RadsUiSlotName, RadsVitePluginOptions, Relation, RequiredFields, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, VerifyManyArgs, VerifyManyArgsAny, VerifyManyResponse, Where, WhereJsonContains, cleanUndefinedAndNull, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
@@ -114,6 +114,7 @@ function getIndexDts(schema, options) {
114
114
  }]));
115
115
  entityMeta.push({
116
116
  type: type.name,
117
+ whereType: `${type.name}_Where`,
117
118
  relationsStr: _lodash.default.keys(relations).map(k => `${k}: { entityName: '${relations[k].entity}', entity: ${relations[k].entity}, denormFields: ${relations[k].denormFields} }`),
118
119
  aggregates: fieldsArray.filter(f => f.type === "number" && !f.isArray).map(x => `'${x.name}'`).join(" | "),
119
120
  primitives: fieldsArray.filter(f => !schema[f.type]?.decorators?.entity).map(x => `'${x.name}'`).join(" | ")
@@ -131,6 +132,7 @@ ${whereFields.join("\n")}
131
132
  const entityMetaStr = entityMeta.map(x => `
132
133
  '${x.type}': {
133
134
  type: ${x.type}
135
+ whereType: ${x.whereType}
134
136
  primitives: ${x.primitives || "never"}
135
137
  aggregates: ${x.aggregates || "never"}
136
138
  relations: {${x.relationsStr}}
@@ -107,6 +107,7 @@ export function getIndexDts(schema, options) {
107
107
  );
108
108
  entityMeta.push({
109
109
  type: type.name,
110
+ whereType: `${type.name}_Where`,
110
111
  relationsStr: _.keys(relations).map(
111
112
  (k) => `${k}: { entityName: '${relations[k].entity}', entity: ${relations[k].entity}, denormFields: ${relations[k].denormFields} }`
112
113
  ),
@@ -130,6 +131,7 @@ ${whereFields.join("\n")}
130
131
  (x) => `
131
132
  '${x.type}': {
132
133
  type: ${x.type}
134
+ whereType: ${x.whereType}
133
135
  primitives: ${x.primitives || "never"}
134
136
  aggregates: ${x.aggregates || "never"}
135
137
  relations: {${x.relationsStr}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.0.55",
3
+ "version": "3.0.57",
4
4
  "packageManager": "pnpm@8.6.1",
5
5
  "description": "Say goodbye to boilerplate code and hello to efficient and elegant syntax.",
6
6
  "author": "",