rads-db 0.1.111 → 3.0.1
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.cjs +93 -11
- package/dist/index.d.ts +38 -9
- package/dist/index.mjs +91 -11
- package/drivers/restApi.d.ts +1 -11
- package/features/cache.cjs +3 -1
- package/features/cache.mjs +6 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5,11 +5,13 @@ const _ = require('lodash');
|
|
|
5
5
|
const uuid = require('uuid');
|
|
6
6
|
const createMerge = require('@fastify/deepmerge');
|
|
7
7
|
const _radsDb = require('_rads-db');
|
|
8
|
+
const pluralize = require('pluralize');
|
|
8
9
|
|
|
9
10
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
10
11
|
|
|
11
12
|
const ___default = /*#__PURE__*/_interopDefaultCompat(_);
|
|
12
13
|
const createMerge__default = /*#__PURE__*/_interopDefaultCompat(createMerge);
|
|
14
|
+
const pluralize__default = /*#__PURE__*/_interopDefaultCompat(pluralize);
|
|
13
15
|
|
|
14
16
|
function generateValidators(schema) {
|
|
15
17
|
const zodSchemas = {};
|
|
@@ -316,7 +318,7 @@ const computedPresets = {
|
|
|
316
318
|
};
|
|
317
319
|
async function handlePrecomputed(context, docs, ctx) {
|
|
318
320
|
const { schema, typeName, options, db } = context;
|
|
319
|
-
if (options.
|
|
321
|
+
if (options.noComputed)
|
|
320
322
|
return;
|
|
321
323
|
const { precomputedFields, nestedTypeFields, fields } = schema[typeName];
|
|
322
324
|
const computed = options.computed;
|
|
@@ -352,7 +354,7 @@ async function handlePrecomputed(context, docs, ctx) {
|
|
|
352
354
|
}
|
|
353
355
|
async function handleComputed(context, data, ctx) {
|
|
354
356
|
const { schema, typeName, options, db } = context;
|
|
355
|
-
if (options.
|
|
357
|
+
if (options.noComputed)
|
|
356
358
|
return;
|
|
357
359
|
const { computedFields, nestedTypeFields, fields } = schema[typeName];
|
|
358
360
|
const computed = options.computed;
|
|
@@ -977,7 +979,7 @@ function getExistingDriverInstance(entityName, drivers) {
|
|
|
977
979
|
|
|
978
980
|
function generateMethods(schema, validators, options) {
|
|
979
981
|
const drivers = {};
|
|
980
|
-
const opts =
|
|
982
|
+
const opts = normalizeOptions(options);
|
|
981
983
|
const db = {
|
|
982
984
|
_schema: schema,
|
|
983
985
|
_radsUiSlots: getRadsUiSlots(opts.features),
|
|
@@ -991,7 +993,7 @@ function generateMethods(schema, validators, options) {
|
|
|
991
993
|
for (const key in schema) {
|
|
992
994
|
effects[key] = [];
|
|
993
995
|
}
|
|
994
|
-
if (!opts.
|
|
996
|
+
if (!opts.noComputed) {
|
|
995
997
|
verifyComputedPresense(schema, opts.computed, effects);
|
|
996
998
|
}
|
|
997
999
|
verifyEventSourcingSetup(schema, effects);
|
|
@@ -1024,13 +1026,18 @@ function generateMethods(schema, validators, options) {
|
|
|
1024
1026
|
}
|
|
1025
1027
|
return db;
|
|
1026
1028
|
}
|
|
1027
|
-
function getDriverInstance(schema, key, driver,
|
|
1028
|
-
if (!
|
|
1029
|
-
|
|
1029
|
+
function getDriverInstance(schema, key, driver, driverInstances) {
|
|
1030
|
+
if (!driverInstances[key]) {
|
|
1031
|
+
driverInstances[key] = getDriverInstanceInner(schema, key, driver);
|
|
1030
1032
|
}
|
|
1031
|
-
return
|
|
1033
|
+
return driverInstances[key];
|
|
1032
1034
|
}
|
|
1033
|
-
function getDriverInstanceInner(schema, key,
|
|
1035
|
+
function getDriverInstanceInner(schema, key, drivers) {
|
|
1036
|
+
const driverName = schema[key].decorators.entity.driver || "default";
|
|
1037
|
+
const driverConstructor = drivers[driverName];
|
|
1038
|
+
if (!driverConstructor) {
|
|
1039
|
+
throw new Error(`Missing driver "${driverName}" for entity "${key}"`);
|
|
1040
|
+
}
|
|
1034
1041
|
const driverInstance = driverConstructor(schema, key);
|
|
1035
1042
|
addDryRunSupport(driverInstance, key);
|
|
1036
1043
|
async function getAll(args, ctx) {
|
|
@@ -1127,6 +1134,69 @@ function getRadsUiSlots(features) {
|
|
|
1127
1134
|
}
|
|
1128
1135
|
return result;
|
|
1129
1136
|
}
|
|
1137
|
+
function normalizeOptions(options) {
|
|
1138
|
+
let driver = options?.driver;
|
|
1139
|
+
if (!driver)
|
|
1140
|
+
driver = { default: memory() };
|
|
1141
|
+
if (typeof driver === "function")
|
|
1142
|
+
driver = { default: driver };
|
|
1143
|
+
return { computed: {}, features: [], ...options, driver };
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
const restApi = (options) => (schema, entity) => {
|
|
1147
|
+
const opts = {
|
|
1148
|
+
baseUrl: "/api",
|
|
1149
|
+
fetch: globalThis.fetch,
|
|
1150
|
+
getHeaders: () => {
|
|
1151
|
+
return void 0;
|
|
1152
|
+
},
|
|
1153
|
+
...options
|
|
1154
|
+
};
|
|
1155
|
+
const fetch = opts.fetch || global.fetch;
|
|
1156
|
+
async function fetchInner(...args) {
|
|
1157
|
+
const [url, fetchOptions] = args;
|
|
1158
|
+
const response = await fetch(url, fetchOptions);
|
|
1159
|
+
const responseJson = response.status === 204 ? null : await response.json();
|
|
1160
|
+
if (!response.ok) {
|
|
1161
|
+
const msg = responseJson?.message || responseJson?.statusMessage || response.statusText || "Server error.";
|
|
1162
|
+
const err = new Error(msg);
|
|
1163
|
+
if (responseJson?.code)
|
|
1164
|
+
err.code = responseJson?.code;
|
|
1165
|
+
err.fetchResponseJson = responseJson;
|
|
1166
|
+
throw err;
|
|
1167
|
+
}
|
|
1168
|
+
return responseJson;
|
|
1169
|
+
}
|
|
1170
|
+
const pluralEntityName = ___default.lowerFirst(pluralize__default(entity));
|
|
1171
|
+
const instance = {
|
|
1172
|
+
driverName: "restApi",
|
|
1173
|
+
async getMany(args) {
|
|
1174
|
+
args = args || {};
|
|
1175
|
+
const url = `${opts.baseUrl}/${pluralEntityName}`;
|
|
1176
|
+
const fetchOptions = {
|
|
1177
|
+
method: "POST",
|
|
1178
|
+
body: JSON.stringify(args),
|
|
1179
|
+
headers: { "Content-Type": "application/json" }
|
|
1180
|
+
};
|
|
1181
|
+
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders(url, fetchOptions) };
|
|
1182
|
+
return await fetchInner(url, fetchOptions);
|
|
1183
|
+
},
|
|
1184
|
+
async putMany(item) {
|
|
1185
|
+
const url = `${opts.baseUrl}/${pluralEntityName}`;
|
|
1186
|
+
const fetchOptions = {
|
|
1187
|
+
method: "PUT",
|
|
1188
|
+
body: JSON.stringify({ data: item }),
|
|
1189
|
+
headers: { "Content-Type": "application/json" }
|
|
1190
|
+
};
|
|
1191
|
+
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders(url, fetchOptions) };
|
|
1192
|
+
return await fetchInner(url, fetchOptions);
|
|
1193
|
+
},
|
|
1194
|
+
async verifyMany(args, ctx) {
|
|
1195
|
+
throw new Error('Calling "verifyMany" via rest api is not supported for security reasons.');
|
|
1196
|
+
}
|
|
1197
|
+
};
|
|
1198
|
+
return instance;
|
|
1199
|
+
};
|
|
1130
1200
|
|
|
1131
1201
|
function entity(meta) {
|
|
1132
1202
|
return function(classConstructor, _ctx) {
|
|
@@ -1153,15 +1223,27 @@ function computed(meta) {
|
|
|
1153
1223
|
};
|
|
1154
1224
|
}
|
|
1155
1225
|
|
|
1156
|
-
function
|
|
1226
|
+
function createRadsDb(args) {
|
|
1157
1227
|
args = { ...args };
|
|
1158
1228
|
const s = args.schema || _radsDb.schema;
|
|
1159
1229
|
const validators = generateValidators(s);
|
|
1160
1230
|
return generateMethods(s, validators, args);
|
|
1161
1231
|
}
|
|
1232
|
+
function createRadsDbClient(args) {
|
|
1233
|
+
const radsDbArgs = {
|
|
1234
|
+
...args,
|
|
1235
|
+
noComputed: true,
|
|
1236
|
+
noCustomDrivers: true,
|
|
1237
|
+
driver: restApi(args?.driver)
|
|
1238
|
+
};
|
|
1239
|
+
const s = radsDbArgs.schema || _radsDb.schema;
|
|
1240
|
+
const validators = generateValidators(s);
|
|
1241
|
+
return generateMethods(s, validators, radsDbArgs);
|
|
1242
|
+
}
|
|
1162
1243
|
|
|
1163
1244
|
exports.computed = computed;
|
|
1164
|
-
exports.
|
|
1245
|
+
exports.createRadsDb = createRadsDb;
|
|
1246
|
+
exports.createRadsDbClient = createRadsDbClient;
|
|
1165
1247
|
exports.entity = entity;
|
|
1166
1248
|
exports.field = field;
|
|
1167
1249
|
exports.getDriverInstance = getDriverInstance;
|
package/dist/index.d.ts
CHANGED
|
@@ -139,6 +139,8 @@ interface UiDecoratorArgs<T = any> {
|
|
|
139
139
|
iconField?: keyof T;
|
|
140
140
|
/** Search operator that's used in simple search by name. Defaults to 'istartsWith' */
|
|
141
141
|
searchOperator?: 'startsWith' | 'istartsWith' | 'contains' | 'icontains';
|
|
142
|
+
/** Defines section name in rads-ui where this entity will be grouped under */
|
|
143
|
+
group?: string;
|
|
142
144
|
}
|
|
143
145
|
interface EntityDecoratorArgs {
|
|
144
146
|
driver?: string;
|
|
@@ -150,12 +152,26 @@ interface FieldDecoratorArgs {
|
|
|
150
152
|
relation?: Function;
|
|
151
153
|
}
|
|
152
154
|
type DriverConstructor = (schema: Schema, entity: string) => MinimalDriver;
|
|
153
|
-
interface
|
|
155
|
+
interface CreateRadsArgsDrivers {
|
|
156
|
+
default: DriverConstructor;
|
|
157
|
+
[driverName: string]: DriverConstructor;
|
|
158
|
+
}
|
|
159
|
+
interface RestDriverOptions {
|
|
160
|
+
/** @default '/api' */
|
|
161
|
+
baseUrl?: string;
|
|
162
|
+
fetch?: (url: string, options?: {
|
|
163
|
+
body?: any;
|
|
164
|
+
headers?: any;
|
|
165
|
+
method?: string;
|
|
166
|
+
}) => any;
|
|
167
|
+
getHeaders?: (url: string, fetchOptions: RequestInit) => Record<string, string> | undefined;
|
|
168
|
+
}
|
|
169
|
+
interface CreateRadsDbArgs {
|
|
154
170
|
schema?: Schema;
|
|
155
|
-
driver?: DriverConstructor;
|
|
156
|
-
drivers?: Record<string, DriverConstructor>;
|
|
171
|
+
driver?: DriverConstructor | CreateRadsArgsDrivers;
|
|
157
172
|
fileUploadDriver?: FileUploadDriver;
|
|
158
|
-
|
|
173
|
+
noComputed?: boolean;
|
|
174
|
+
noCustomDrivers?: boolean;
|
|
159
175
|
computed?: Record<string, Record<string, Function> | {
|
|
160
176
|
_entity?: {
|
|
161
177
|
compute: Function;
|
|
@@ -166,6 +182,9 @@ interface CreateRadsArgs {
|
|
|
166
182
|
context?: Record<string, any> & Omit<RadsRequestContext, 'dryRun' | 'silent'>;
|
|
167
183
|
features?: RadsFeature[];
|
|
168
184
|
}
|
|
185
|
+
type CreateRadsDbClientArgs = Omit<CreateRadsDbArgs, 'noComputed' | 'noCustomDrivers' | 'driver'> & {
|
|
186
|
+
driver?: RestDriverOptions;
|
|
187
|
+
};
|
|
169
188
|
type Schema = Record<string, TypeDefinition>;
|
|
170
189
|
type SchemaValidators = Record<string, (item: any) => any>;
|
|
171
190
|
interface TypeDefinition {
|
|
@@ -238,7 +257,7 @@ interface ComputedContextGlobal {
|
|
|
238
257
|
db: RadsDb;
|
|
239
258
|
schema: Schema;
|
|
240
259
|
validators: SchemaValidators;
|
|
241
|
-
options:
|
|
260
|
+
options: CreateRadsDbArgs;
|
|
242
261
|
drivers: Record<string, Driver>;
|
|
243
262
|
effects: Record<string, PutEffect[]>;
|
|
244
263
|
}
|
|
@@ -318,7 +337,7 @@ interface RadsUiSlotDefinition {
|
|
|
318
337
|
}
|
|
319
338
|
interface RadsFeature {
|
|
320
339
|
name: string;
|
|
321
|
-
radsUiSlots
|
|
340
|
+
radsUiSlots?: Record<RadsUiSlotName, RadsUiSlotDefinition[]>;
|
|
322
341
|
init?: (db: Record<string, any>, context: ComputedContextGlobal) => void;
|
|
323
342
|
enhanceEntityMethods?: (context: ComputedContext, entityMethodsObj: EntityMethods<any, any, any>) => void;
|
|
324
343
|
beforeGet?: (args: GetArgsAny, ctx: RadsRequestContext, context: ComputedContext) => MaybePromise<any>;
|
|
@@ -340,8 +359,18 @@ declare function field(meta?: FieldDecoratorArgs): (a: any, b?: ClassFieldDecora
|
|
|
340
359
|
declare function precomputed(meta?: ComputedDecoratorArgs): (a: any, b?: ClassFieldDecoratorContext | ClassDecoratorContext) => void;
|
|
341
360
|
declare function computed(meta?: ComputedDecoratorArgs): (a: any, b?: ClassFieldDecoratorContext | ClassDecoratorContext) => void;
|
|
342
361
|
|
|
343
|
-
declare function getDriverInstance(schema: Schema, key: string, driver:
|
|
362
|
+
declare function getDriverInstance(schema: Schema, key: string, driver: CreateRadsArgsDrivers, driverInstances: Record<string, Driver>): Driver;
|
|
344
363
|
|
|
345
|
-
|
|
364
|
+
/**
|
|
365
|
+
* Creates instance of rads db - object that provides access to all entities.
|
|
366
|
+
* Intended to be used on the backend. On the client you may want to opt for "createRadsDbClient" instead.
|
|
367
|
+
* */
|
|
368
|
+
declare function createRadsDb(args?: CreateRadsDbArgs): RadsDb;
|
|
369
|
+
/**
|
|
370
|
+
* Creates instance of rads db client - object that provides access to all entities.
|
|
371
|
+
* Intended to be used on the frontend. Uses "fetch" to communicate with the server's API.
|
|
372
|
+
* It is a shortcut for `createRadsDb({ driver: radsRestApi(), noComputed: true, noCustomDrivers: true })`
|
|
373
|
+
*/
|
|
374
|
+
declare function createRadsDbClient(args?: CreateRadsDbClientArgs): RadsDb;
|
|
346
375
|
|
|
347
|
-
export { Change, ComputedContext, ComputedContextGlobal, ComputedDecoratorArgs,
|
|
376
|
+
export { Change, ComputedContext, ComputedContextGlobal, ComputedDecoratorArgs, CreateRadsArgsDrivers, CreateRadsDbArgs, CreateRadsDbClientArgs, DeepPartial, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, FieldDecoratorArgs, FieldDefinition, FileSystemNode, FileUploadArgs, FileUploadDriver, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, MinimalDriver, PutArgs, PutEffect, RadsFeature, RadsRequestContext, RadsUiSlotDefinition, RadsUiSlotName, RadsVitePluginOptions, Relation, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, VerifyManyArgs, VerifyManyArgsAny, VerifyManyResponse, computed, createRadsDb, createRadsDbClient, entity, field, getDriverInstance, precomputed, ui, validate };
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import _ from 'lodash';
|
|
|
3
3
|
import { v4 } from 'uuid';
|
|
4
4
|
import createMerge from '@fastify/deepmerge';
|
|
5
5
|
import { schema } from '_rads-db';
|
|
6
|
+
import pluralize from 'pluralize';
|
|
6
7
|
|
|
7
8
|
function generateValidators(schema) {
|
|
8
9
|
const zodSchemas = {};
|
|
@@ -309,7 +310,7 @@ const computedPresets = {
|
|
|
309
310
|
};
|
|
310
311
|
async function handlePrecomputed(context, docs, ctx) {
|
|
311
312
|
const { schema, typeName, options, db } = context;
|
|
312
|
-
if (options.
|
|
313
|
+
if (options.noComputed)
|
|
313
314
|
return;
|
|
314
315
|
const { precomputedFields, nestedTypeFields, fields } = schema[typeName];
|
|
315
316
|
const computed = options.computed;
|
|
@@ -345,7 +346,7 @@ async function handlePrecomputed(context, docs, ctx) {
|
|
|
345
346
|
}
|
|
346
347
|
async function handleComputed(context, data, ctx) {
|
|
347
348
|
const { schema, typeName, options, db } = context;
|
|
348
|
-
if (options.
|
|
349
|
+
if (options.noComputed)
|
|
349
350
|
return;
|
|
350
351
|
const { computedFields, nestedTypeFields, fields } = schema[typeName];
|
|
351
352
|
const computed = options.computed;
|
|
@@ -970,7 +971,7 @@ function getExistingDriverInstance(entityName, drivers) {
|
|
|
970
971
|
|
|
971
972
|
function generateMethods(schema, validators, options) {
|
|
972
973
|
const drivers = {};
|
|
973
|
-
const opts =
|
|
974
|
+
const opts = normalizeOptions(options);
|
|
974
975
|
const db = {
|
|
975
976
|
_schema: schema,
|
|
976
977
|
_radsUiSlots: getRadsUiSlots(opts.features),
|
|
@@ -984,7 +985,7 @@ function generateMethods(schema, validators, options) {
|
|
|
984
985
|
for (const key in schema) {
|
|
985
986
|
effects[key] = [];
|
|
986
987
|
}
|
|
987
|
-
if (!opts.
|
|
988
|
+
if (!opts.noComputed) {
|
|
988
989
|
verifyComputedPresense(schema, opts.computed, effects);
|
|
989
990
|
}
|
|
990
991
|
verifyEventSourcingSetup(schema, effects);
|
|
@@ -1017,13 +1018,18 @@ function generateMethods(schema, validators, options) {
|
|
|
1017
1018
|
}
|
|
1018
1019
|
return db;
|
|
1019
1020
|
}
|
|
1020
|
-
function getDriverInstance(schema, key, driver,
|
|
1021
|
-
if (!
|
|
1022
|
-
|
|
1021
|
+
function getDriverInstance(schema, key, driver, driverInstances) {
|
|
1022
|
+
if (!driverInstances[key]) {
|
|
1023
|
+
driverInstances[key] = getDriverInstanceInner(schema, key, driver);
|
|
1023
1024
|
}
|
|
1024
|
-
return
|
|
1025
|
+
return driverInstances[key];
|
|
1025
1026
|
}
|
|
1026
|
-
function getDriverInstanceInner(schema, key,
|
|
1027
|
+
function getDriverInstanceInner(schema, key, drivers) {
|
|
1028
|
+
const driverName = schema[key].decorators.entity.driver || "default";
|
|
1029
|
+
const driverConstructor = drivers[driverName];
|
|
1030
|
+
if (!driverConstructor) {
|
|
1031
|
+
throw new Error(`Missing driver "${driverName}" for entity "${key}"`);
|
|
1032
|
+
}
|
|
1027
1033
|
const driverInstance = driverConstructor(schema, key);
|
|
1028
1034
|
addDryRunSupport(driverInstance, key);
|
|
1029
1035
|
async function getAll(args, ctx) {
|
|
@@ -1120,6 +1126,69 @@ function getRadsUiSlots(features) {
|
|
|
1120
1126
|
}
|
|
1121
1127
|
return result;
|
|
1122
1128
|
}
|
|
1129
|
+
function normalizeOptions(options) {
|
|
1130
|
+
let driver = options?.driver;
|
|
1131
|
+
if (!driver)
|
|
1132
|
+
driver = { default: memory() };
|
|
1133
|
+
if (typeof driver === "function")
|
|
1134
|
+
driver = { default: driver };
|
|
1135
|
+
return { computed: {}, features: [], ...options, driver };
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
const restApi = (options) => (schema, entity) => {
|
|
1139
|
+
const opts = {
|
|
1140
|
+
baseUrl: "/api",
|
|
1141
|
+
fetch: globalThis.fetch,
|
|
1142
|
+
getHeaders: () => {
|
|
1143
|
+
return void 0;
|
|
1144
|
+
},
|
|
1145
|
+
...options
|
|
1146
|
+
};
|
|
1147
|
+
const fetch = opts.fetch || global.fetch;
|
|
1148
|
+
async function fetchInner(...args) {
|
|
1149
|
+
const [url, fetchOptions] = args;
|
|
1150
|
+
const response = await fetch(url, fetchOptions);
|
|
1151
|
+
const responseJson = response.status === 204 ? null : await response.json();
|
|
1152
|
+
if (!response.ok) {
|
|
1153
|
+
const msg = responseJson?.message || responseJson?.statusMessage || response.statusText || "Server error.";
|
|
1154
|
+
const err = new Error(msg);
|
|
1155
|
+
if (responseJson?.code)
|
|
1156
|
+
err.code = responseJson?.code;
|
|
1157
|
+
err.fetchResponseJson = responseJson;
|
|
1158
|
+
throw err;
|
|
1159
|
+
}
|
|
1160
|
+
return responseJson;
|
|
1161
|
+
}
|
|
1162
|
+
const pluralEntityName = _.lowerFirst(pluralize(entity));
|
|
1163
|
+
const instance = {
|
|
1164
|
+
driverName: "restApi",
|
|
1165
|
+
async getMany(args) {
|
|
1166
|
+
args = args || {};
|
|
1167
|
+
const url = `${opts.baseUrl}/${pluralEntityName}`;
|
|
1168
|
+
const fetchOptions = {
|
|
1169
|
+
method: "POST",
|
|
1170
|
+
body: JSON.stringify(args),
|
|
1171
|
+
headers: { "Content-Type": "application/json" }
|
|
1172
|
+
};
|
|
1173
|
+
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders(url, fetchOptions) };
|
|
1174
|
+
return await fetchInner(url, fetchOptions);
|
|
1175
|
+
},
|
|
1176
|
+
async putMany(item) {
|
|
1177
|
+
const url = `${opts.baseUrl}/${pluralEntityName}`;
|
|
1178
|
+
const fetchOptions = {
|
|
1179
|
+
method: "PUT",
|
|
1180
|
+
body: JSON.stringify({ data: item }),
|
|
1181
|
+
headers: { "Content-Type": "application/json" }
|
|
1182
|
+
};
|
|
1183
|
+
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders(url, fetchOptions) };
|
|
1184
|
+
return await fetchInner(url, fetchOptions);
|
|
1185
|
+
},
|
|
1186
|
+
async verifyMany(args, ctx) {
|
|
1187
|
+
throw new Error('Calling "verifyMany" via rest api is not supported for security reasons.');
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
return instance;
|
|
1191
|
+
};
|
|
1123
1192
|
|
|
1124
1193
|
function entity(meta) {
|
|
1125
1194
|
return function(classConstructor, _ctx) {
|
|
@@ -1146,11 +1215,22 @@ function computed(meta) {
|
|
|
1146
1215
|
};
|
|
1147
1216
|
}
|
|
1148
1217
|
|
|
1149
|
-
function
|
|
1218
|
+
function createRadsDb(args) {
|
|
1150
1219
|
args = { ...args };
|
|
1151
1220
|
const s = args.schema || schema;
|
|
1152
1221
|
const validators = generateValidators(s);
|
|
1153
1222
|
return generateMethods(s, validators, args);
|
|
1154
1223
|
}
|
|
1224
|
+
function createRadsDbClient(args) {
|
|
1225
|
+
const radsDbArgs = {
|
|
1226
|
+
...args,
|
|
1227
|
+
noComputed: true,
|
|
1228
|
+
noCustomDrivers: true,
|
|
1229
|
+
driver: restApi(args?.driver)
|
|
1230
|
+
};
|
|
1231
|
+
const s = radsDbArgs.schema || schema;
|
|
1232
|
+
const validators = generateValidators(s);
|
|
1233
|
+
return generateMethods(s, validators, radsDbArgs);
|
|
1234
|
+
}
|
|
1155
1235
|
|
|
1156
|
-
export { computed,
|
|
1236
|
+
export { computed, createRadsDb, createRadsDbClient, entity, field, getDriverInstance, precomputed, ui, validate };
|
package/drivers/restApi.d.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/** @default '/api' */
|
|
3
|
-
baseUrl?: string;
|
|
4
|
-
fetch?: (url: string, options?: {
|
|
5
|
-
body?: any;
|
|
6
|
-
headers?: any;
|
|
7
|
-
method?: string;
|
|
8
|
-
}) => any;
|
|
9
|
-
getHeaders?: (url: string, fetchOptions: RequestInit) => Record<string, string> | undefined;
|
|
10
|
-
}
|
|
11
|
-
declare const _default: (options: RestDriverOptions) => (schema: Schema, entity: string) => MinimalDriver;
|
|
1
|
+
declare const _default: (options?: any) => (schema: Schema, entity: string) => MinimalDriver;
|
|
12
2
|
export default _default;
|
package/features/cache.cjs
CHANGED
|
@@ -56,7 +56,9 @@ var _default = options => {
|
|
|
56
56
|
handle: cacheEntityName,
|
|
57
57
|
handlePlural: `${cacheEntityName}s`
|
|
58
58
|
};
|
|
59
|
-
cacheDrivers[handle] = (0, _radsDb.getDriverInstance)(schema, cacheEntityName,
|
|
59
|
+
cacheDrivers[handle] = (0, _radsDb.getDriverInstance)(schema, cacheEntityName, {
|
|
60
|
+
default: normalizedOptions[typeName].driver
|
|
61
|
+
}, drivers);
|
|
60
62
|
cacheStatus[handle] = {
|
|
61
63
|
preloadStatus: normalizedOptions[typeName].preload ? "neverLoaded" : void 0
|
|
62
64
|
};
|
package/features/cache.mjs
CHANGED
|
@@ -38,7 +38,12 @@ export default (options) => {
|
|
|
38
38
|
handle: cacheEntityName,
|
|
39
39
|
handlePlural: `${cacheEntityName}s`
|
|
40
40
|
};
|
|
41
|
-
cacheDrivers[handle] = getDriverInstance(
|
|
41
|
+
cacheDrivers[handle] = getDriverInstance(
|
|
42
|
+
schema,
|
|
43
|
+
cacheEntityName,
|
|
44
|
+
{ default: normalizedOptions[typeName].driver },
|
|
45
|
+
drivers
|
|
46
|
+
);
|
|
42
47
|
cacheStatus[handle] = { preloadStatus: normalizedOptions[typeName].preload ? "neverLoaded" : void 0 };
|
|
43
48
|
}
|
|
44
49
|
db.cache = {
|