rads-db 3.1.0 → 3.1.4

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/config.cjs CHANGED
@@ -616,13 +616,14 @@ function schemaFromFiles(entitiesDir) {
616
616
  }
617
617
  function schemaFromRadsApi(radsApiUrl) {
618
618
  return async () => {
619
+ if (!radsApiUrl.endsWith("/"))
620
+ radsApiUrl += "/";
619
621
  const url = new URL("radsTunnel", radsApiUrl);
620
622
  const fetchResponse = await fetch(url.href, {
621
623
  method: "POST",
622
624
  headers: { "content-type": "application/json" },
623
625
  body: JSON.stringify({ method: "_schema" })
624
626
  });
625
- console.log("loading", url.href);
626
627
  const schema = await fetchResponse.json();
627
628
  if (!schema) {
628
629
  throw new Error("Could not download schema from the server. Please check the server URL.");
package/dist/config.mjs CHANGED
@@ -608,13 +608,14 @@ function schemaFromFiles(entitiesDir) {
608
608
  }
609
609
  function schemaFromRadsApi(radsApiUrl) {
610
610
  return async () => {
611
+ if (!radsApiUrl.endsWith("/"))
612
+ radsApiUrl += "/";
611
613
  const url = new URL("radsTunnel", radsApiUrl);
612
614
  const fetchResponse = await fetch(url.href, {
613
615
  method: "POST",
614
616
  headers: { "content-type": "application/json" },
615
617
  body: JSON.stringify({ method: "_schema" })
616
618
  });
617
- console.log("loading", url.href);
618
619
  const schema = await fetchResponse.json();
619
620
  if (!schema) {
620
621
  throw new Error("Could not download schema from the server. Please check the server URL.");
package/dist/index.cjs CHANGED
@@ -357,7 +357,9 @@ const computedPresets = {
357
357
  throw new Error('To use "updatedBy" preset, please, provide "context.getUser" to "createRads" call.');
358
358
  return ___default.pick(ctx.getUser(), "id");
359
359
  },
360
- updatedAt: ({ doc, oldDoc }) => {
360
+ updatedAt: ({ doc, oldDoc, ctx }) => {
361
+ if (ctx.isVerifying && oldDoc.updatedAt)
362
+ return oldDoc.updatedAt;
361
363
  return (/* @__PURE__ */ new Date()).toISOString();
362
364
  },
363
365
  autoincrement: () => {
@@ -819,7 +821,7 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
819
821
  if (driverInstance.verifyMany) {
820
822
  return driverInstance.verifyMany(args, ctx);
821
823
  }
822
- ctx = { ...options.context, ...ctx };
824
+ ctx = { ...options.context, ...ctx, isVerifying: true };
823
825
  if (args?.dryRun) {
824
826
  ctx._logs = ctx._logs || [];
825
827
  ctx.dryRun = true;
@@ -1273,13 +1275,13 @@ function keepHistory() {
1273
1275
  };
1274
1276
  }
1275
1277
 
1276
- function createRadsDb(args) {
1278
+ function createRadsDb(dataSourceKey, args) {
1277
1279
  args = { ...args };
1278
- const s = args.schema || _radsDb.schema;
1280
+ const s = args.schema || _radsDb.schemas[dataSourceKey];
1279
1281
  const validators = generateValidators(s);
1280
1282
  return generateMethods(s, validators, args);
1281
1283
  }
1282
- function createRadsDbClient(args) {
1284
+ function createRadsDbClient(dataSourceKey, args) {
1283
1285
  const radsDbArgs = {
1284
1286
  ...args,
1285
1287
  noComputed: true,
@@ -1287,7 +1289,7 @@ function createRadsDbClient(args) {
1287
1289
  keepNulls: true,
1288
1290
  driver: restApi(args?.driver)
1289
1291
  };
1290
- const s = radsDbArgs.schema || _radsDb.schema;
1292
+ const s = radsDbArgs.schema || _radsDb.schemas[dataSourceKey];
1291
1293
  const validators = generateValidators(s);
1292
1294
  return generateMethods(s, validators, radsDbArgs);
1293
1295
  }
package/dist/index.d.ts CHANGED
@@ -26,12 +26,12 @@ declare function cleanUndefinedAndNull(obj: Record<string, any>, isChange?: bool
26
26
  * Creates instance of rads db - object that provides access to all entities.
27
27
  * Intended to be used on the backend. On the client you may want to opt for "createRadsDbClient" instead.
28
28
  * */
29
- declare function createRadsDb(args?: CreateRadsDbArgs): RadsDb;
29
+ declare function createRadsDb<T extends keyof RadsDb>(dataSourceKey: T, args?: CreateRadsDbArgs): RadsDb[T];
30
30
  /**
31
31
  * Creates instance of rads db client - object that provides access to all entities.
32
32
  * Intended to be used on the frontend. Uses "fetch" to communicate with the server's API.
33
- * It is a shortcut for `createRadsDb({ driver: radsRestApi(), noComputed: true, noCustomDrivers: true })`
33
+ * It is a shortcut for `createRadsDb('db', { driver: radsRestApi(), noComputed: true, noCustomDrivers: true })`
34
34
  */
35
- declare function createRadsDbClient(args?: CreateRadsDbClientArgs): RadsDb;
35
+ declare function createRadsDbClient<T extends keyof RadsDb>(dataSourceKey: T, args?: CreateRadsDbClientArgs): RadsDb[T];
36
36
 
37
37
  export { ComputedContext, ComputedDecoratorArgs, CreateRadsDbArgs, CreateRadsDbClientArgs, Driver, DriverConstructor, EntityDecoratorArgs, FieldDecoratorArgs, RadsRequestContext, Schema, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, cleanUndefinedAndNull, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { z, ZodNullable, ZodOptional, ZodLazy, ZodObject, ZodError } from 'zod';
2
2
  import _ from 'lodash';
3
3
  import { v4 } from 'uuid';
4
4
  import createMerge from '@fastify/deepmerge';
5
- import { schema } from '_rads-db';
5
+ import { schemas } from '_rads-db';
6
6
 
7
7
  function generateValidators(schema) {
8
8
  const zodSchemas = {};
@@ -350,7 +350,9 @@ const computedPresets = {
350
350
  throw new Error('To use "updatedBy" preset, please, provide "context.getUser" to "createRads" call.');
351
351
  return _.pick(ctx.getUser(), "id");
352
352
  },
353
- updatedAt: ({ doc, oldDoc }) => {
353
+ updatedAt: ({ doc, oldDoc, ctx }) => {
354
+ if (ctx.isVerifying && oldDoc.updatedAt)
355
+ return oldDoc.updatedAt;
354
356
  return (/* @__PURE__ */ new Date()).toISOString();
355
357
  },
356
358
  autoincrement: () => {
@@ -812,7 +814,7 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
812
814
  if (driverInstance.verifyMany) {
813
815
  return driverInstance.verifyMany(args, ctx);
814
816
  }
815
- ctx = { ...options.context, ...ctx };
817
+ ctx = { ...options.context, ...ctx, isVerifying: true };
816
818
  if (args?.dryRun) {
817
819
  ctx._logs = ctx._logs || [];
818
820
  ctx.dryRun = true;
@@ -1266,13 +1268,13 @@ function keepHistory() {
1266
1268
  };
1267
1269
  }
1268
1270
 
1269
- function createRadsDb(args) {
1271
+ function createRadsDb(dataSourceKey, args) {
1270
1272
  args = { ...args };
1271
- const s = args.schema || schema;
1273
+ const s = args.schema || schemas[dataSourceKey];
1272
1274
  const validators = generateValidators(s);
1273
1275
  return generateMethods(s, validators, args);
1274
1276
  }
1275
- function createRadsDbClient(args) {
1277
+ function createRadsDbClient(dataSourceKey, args) {
1276
1278
  const radsDbArgs = {
1277
1279
  ...args,
1278
1280
  noComputed: true,
@@ -1280,7 +1282,7 @@ function createRadsDbClient(args) {
1280
1282
  keepNulls: true,
1281
1283
  driver: restApi(args?.driver)
1282
1284
  };
1283
- const s = radsDbArgs.schema || schema;
1285
+ const s = radsDbArgs.schema || schemas[dataSourceKey];
1284
1286
  const validators = generateValidators(s);
1285
1287
  return generateMethods(s, validators, radsDbArgs);
1286
1288
  }
@@ -10,7 +10,7 @@ function radsDbVite(options) {
10
10
  name: "rads-db",
11
11
  config(config, env) {},
12
12
  async configResolved(config) {
13
- await (0, _node.generateClient)(options);
13
+ await (0, _node.generateClient)();
14
14
  },
15
15
  configureServer(server) {
16
16
  server.middlewares.use((req, res, next) => {
@@ -6,7 +6,7 @@ export function radsDbVite(options) {
6
6
  config(config, env) {
7
7
  },
8
8
  async configResolved(config) {
9
- await generateClient(options);
9
+ await generateClient();
10
10
  },
11
11
  configureServer(server) {
12
12
  server.middlewares.use((req, res, next) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.1.0",
3
+ "version": "3.1.4",
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": "",