rads-db 3.1.0 → 3.1.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/dist/config.cjs +2 -1
- package/dist/config.mjs +2 -1
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +5 -5
- package/integrations/vite.cjs +1 -1
- package/integrations/vite.mjs +1 -1
- package/package.json +1 -1
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
|
@@ -1273,13 +1273,13 @@ function keepHistory() {
|
|
|
1273
1273
|
};
|
|
1274
1274
|
}
|
|
1275
1275
|
|
|
1276
|
-
function createRadsDb(args) {
|
|
1276
|
+
function createRadsDb(dataSourceKey, args) {
|
|
1277
1277
|
args = { ...args };
|
|
1278
|
-
const s = args.schema || _radsDb.
|
|
1278
|
+
const s = args.schema || _radsDb.schemas[dataSourceKey];
|
|
1279
1279
|
const validators = generateValidators(s);
|
|
1280
1280
|
return generateMethods(s, validators, args);
|
|
1281
1281
|
}
|
|
1282
|
-
function createRadsDbClient(args) {
|
|
1282
|
+
function createRadsDbClient(dataSourceKey, args) {
|
|
1283
1283
|
const radsDbArgs = {
|
|
1284
1284
|
...args,
|
|
1285
1285
|
noComputed: true,
|
|
@@ -1287,7 +1287,7 @@ function createRadsDbClient(args) {
|
|
|
1287
1287
|
keepNulls: true,
|
|
1288
1288
|
driver: restApi(args?.driver)
|
|
1289
1289
|
};
|
|
1290
|
-
const s = radsDbArgs.schema || _radsDb.
|
|
1290
|
+
const s = radsDbArgs.schema || _radsDb.schemas[dataSourceKey];
|
|
1291
1291
|
const validators = generateValidators(s);
|
|
1292
1292
|
return generateMethods(s, validators, radsDbArgs);
|
|
1293
1293
|
}
|
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 {
|
|
5
|
+
import { schemas } from '_rads-db';
|
|
6
6
|
|
|
7
7
|
function generateValidators(schema) {
|
|
8
8
|
const zodSchemas = {};
|
|
@@ -1266,13 +1266,13 @@ function keepHistory() {
|
|
|
1266
1266
|
};
|
|
1267
1267
|
}
|
|
1268
1268
|
|
|
1269
|
-
function createRadsDb(args) {
|
|
1269
|
+
function createRadsDb(dataSourceKey, args) {
|
|
1270
1270
|
args = { ...args };
|
|
1271
|
-
const s = args.schema ||
|
|
1271
|
+
const s = args.schema || schemas[dataSourceKey];
|
|
1272
1272
|
const validators = generateValidators(s);
|
|
1273
1273
|
return generateMethods(s, validators, args);
|
|
1274
1274
|
}
|
|
1275
|
-
function createRadsDbClient(args) {
|
|
1275
|
+
function createRadsDbClient(dataSourceKey, args) {
|
|
1276
1276
|
const radsDbArgs = {
|
|
1277
1277
|
...args,
|
|
1278
1278
|
noComputed: true,
|
|
@@ -1280,7 +1280,7 @@ function createRadsDbClient(args) {
|
|
|
1280
1280
|
keepNulls: true,
|
|
1281
1281
|
driver: restApi(args?.driver)
|
|
1282
1282
|
};
|
|
1283
|
-
const s = radsDbArgs.schema ||
|
|
1283
|
+
const s = radsDbArgs.schema || schemas[dataSourceKey];
|
|
1284
1284
|
const validators = generateValidators(s);
|
|
1285
1285
|
return generateMethods(s, validators, radsDbArgs);
|
|
1286
1286
|
}
|
package/integrations/vite.cjs
CHANGED
|
@@ -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)(
|
|
13
|
+
await (0, _node.generateClient)();
|
|
14
14
|
},
|
|
15
15
|
configureServer(server) {
|
|
16
16
|
server.middlewares.use((req, res, next) => {
|
package/integrations/vite.mjs
CHANGED