Socket
Socket
Sign inDemoInstall

remult

Package Overview
Dependencies
5
Maintainers
2
Versions
540
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.25.8-exp.2 to 0.25.8-exp.3

4

esm/graphql.js

@@ -907,5 +907,5 @@ import { getRelationFieldInfo } from './internals.js';

if (where.OR) {
result.OR = where.OR.map((where) => translateWhereToRestBody(fields, { where }));
result.OR = where.OR.map((where) => translateWhereToRestBody(fields, { where }).where);
}
return result;
return { where: result };
}

@@ -253,4 +253,4 @@ import { __decorate, __metadata } from "tslib";

.get(this.process((c, req, res, orig) => dataApiFactory(c).httpGet(res, req, () => this.serializeContext(c))))
.put(this.process(async (c, req, res, _, __, orig) => dataApiFactory(c).put(res, '', await this.coreOptions.getRequestBody(orig))))
.delete(this.process(async (c, req, res, orig) => dataApiFactory(c).delete(res, '')))
.put(this.process(async (c, req, res, _, __, orig) => dataApiFactory(c).updateMany(res, req, await this.coreOptions.getRequestBody(orig))))
.delete(this.process(async (c, req, res, _, __, orig) => dataApiFactory(c).deleteMany(res, req, undefined)))
.post(this.process(async (c, req, res, _, __, orig) => dataApiFactory(c).httpPost(res, req, await this.coreOptions.getRequestBody(orig), () => this.serializeContext(c))));

@@ -471,2 +471,13 @@ r.route(myRoute + '/:id')

let apiPath = (spec.paths[this.options.rootPath + '/' + key] = {});
let itemInBody = {
requestBody: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/' + mutationKey,
},
},
},
},
};
let apiPathWithId = (spec.paths[this.options.rootPath + '/' + key + '/{id}'] = {});

@@ -524,2 +535,69 @@ //https://github.com/2fd/open-api.d.ts

});
apiPath.delete = secure(meta.options.allowApiDelete, true, {
description: 'deletes row of ' +
key +
'. supports filter operators. For more info on filtering [see this article](https://remult.dev/docs/rest-api.html#filter)',
parameters: [...parameters],
responses: {
'400': {
description: 'Error: Bad Request',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/InvalidResponse',
},
},
},
},
'200': {
description: 'returns the number of deleted rows ' + key,
content: {
'application/json': {
schema: {
type: 'object',
properties: {
deleted: {
type: 'number',
},
},
},
},
},
},
},
});
apiPath.put = secure(meta.options.allowApiDelete, true, {
description: 'updates row of ' +
key +
'. supports filter operators. For more info on filtering [see this article](https://remult.dev/docs/rest-api.html#filter)',
parameters: [...parameters],
...itemInBody,
responses: {
'400': {
description: 'Error: Bad Request',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/InvalidResponse',
},
},
},
},
'200': {
description: 'returns the number of updated rows ' + key,
content: {
'application/json': {
schema: {
type: 'object',
properties: {
updated: {
type: 'number',
},
},
},
},
},
},
},
});
let idParameter = {

@@ -532,13 +610,2 @@ name: 'id',

};
let itemInBody = {
requestBody: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/' + mutationKey,
},
},
},
},
};
apiPath.post = secure(meta.options.allowApiInsert, false, {

@@ -545,0 +612,0 @@ //"summary": "insert a " + key,

@@ -36,3 +36,3 @@ import { doTransaction } from './context.js';

case 'updateMany':
return this.updateMany(res, req, body);
return this.updateManyImplementation(res, req, body);
case 'endLiveQuery':

@@ -54,3 +54,3 @@ await this.remult.liveQueryStorage.remove(body.id);

}
async count(response, request, filterBody) {
async count(response, request, body) {
if (!this.repository.metadata.apiReadAllowed) {

@@ -62,3 +62,3 @@ response.forbidden();

response.success({
count: +(await this.repository.count(await this.buildWhere(request, filterBody))),
count: +(await this.repository.count(await this.buildWhere(request, body))),
});

@@ -70,8 +70,10 @@ }

}
async deleteMany(response, request, filterBody) {
async deleteMany(response, request, body) {
try {
let deleted = 0;
let where = await this.buildWhere(request, body);
Filter.throwErrorIfFilterIsEmpty(where, 'deleteMany');
return await doTransaction(this.remult, async () => {
let deleted = 0;
for await (const x of this.repository.query({
where: await this.buildWhere(request, filterBody),
where,
include: this.includeNone(),

@@ -89,3 +91,3 @@ })) {

}
async getArrayImpl(response, request, filterBody) {
async getArrayImpl(response, request, body) {
let findOptions = {

@@ -95,3 +97,3 @@ load: () => [],

};
findOptions.where = await this.buildWhere(request, filterBody);
findOptions.where = await this.buildWhere(request, body);
if (request) {

@@ -155,3 +157,3 @@ let sort = request.get('_sort');

}
async getArray(response, request, filterBody) {
async getArray(response, request, body) {
if (!this.repository.metadata.apiReadAllowed) {

@@ -162,3 +164,3 @@ response.forbidden();

try {
const { r } = await this.getArrayImpl(response, request, filterBody);
const { r } = await this.getArrayImpl(response, request, body);
response.success(r);

@@ -173,3 +175,3 @@ }

}
async liveQuery(response, request, filterBody, serializeContext, queryChannel) {
async liveQuery(response, request, body, serializeContext, queryChannel) {
if (!this.repository.metadata.apiReadAllowed) {

@@ -180,3 +182,3 @@ response.forbidden();

try {
const r = await this.getArrayImpl(response, request, filterBody);
const r = await this.getArrayImpl(response, request, body);
const data = {

@@ -201,3 +203,3 @@ requestJson: await serializeContext(),

}
async buildWhere(request, filterBody) {
async buildWhere(request, body) {
var where = [];

@@ -222,4 +224,4 @@ if (this.repository.metadata.options.apiPrefilter) {

}
if (filterBody)
where.push(Filter.entityFilterFromJson(this.repository.metadata, filterBody));
if (body?.where)
where.push(Filter.entityFilterFromJson(this.repository.metadata, body.where));
return { $and: where };

@@ -260,2 +262,14 @@ }

async updateMany(response, request, body) {
const action = request?.get('__action');
if (action == 'emptyId') {
return this.put(response, '', body);
}
let where = await this.buildWhere(request, body);
Filter.throwErrorIfFilterIsEmpty(where, 'updateMany');
return this.updateManyImplementation(response, request, {
where: undefined,
set: body,
});
}
async updateManyImplementation(response, request, body) {
try {

@@ -265,3 +279,3 @@ return await doTransaction(this.remult, async () => {

for await (const x of this.repository.query({
where: await this.buildWhere(request, body.where),
where: await this.buildWhere(request, body),
include: this.includeNone(),

@@ -268,0 +282,0 @@ })) {

@@ -123,8 +123,8 @@ import { UrlBuilder } from '../../urlBuilder.js';

async deleteMany(where) {
const { run } = this.buildFindRequest({ where }, true);
const { run } = this.buildFindRequest({ where }, 'delete');
return run('deleteMany').then((r) => +r.deleted);
}
async updateMany(where, data) {
const { run } = this.buildFindRequest({ where }, true);
return run('updateMany', { set: this.toJsonOfIncludedKeys(data) }).then((r) => +r.updated);
const { run } = this.buildFindRequest({ where }, 'put');
return run('updateMany', this.toJsonOfIncludedKeys(data)).then((r) => +r.updated);
}

@@ -136,3 +136,5 @@ find(options) {

//@internal
buildFindRequest(options, forcePost = false) {
buildFindRequest(options, method) {
if (!method)
method = 'get';
let url = new UrlBuilder(this.url());

@@ -143,4 +145,3 @@ let filterObject;

filterObject = options.where.toJson(); // options.where.__applyToConsumer(new FilterConsumnerBridgeToUrlBuilder(url));
if (!forcePost &&
addFilterToUrlAndReturnTrueIfSuccessful(filterObject, url))
if (addFilterToUrlAndReturnTrueIfSuccessful(filterObject, url))
filterObject = undefined;

@@ -179,11 +180,8 @@ }

u.add('__action', action);
if (filterObject || forcePost) {
if (!body)
body = filterObject;
else
body = { ...body, where: filterObject };
if (filterObject) {
body = { set: body, where: filterObject };
return this.http().post(u.url, body);
}
else
return this.http().get(u.url);
return this.http()[method](u.url, body);
};

@@ -208,3 +206,4 @@ return {

return this.http()
.put(this.url() + '/' + encodeURIComponent(id), this.toJsonOfIncludedKeys(data))
.put(this.url() +
(id != '' ? '/' + encodeURIComponent(id) : '?__action=emptyId'), this.toJsonOfIncludedKeys(data))
.then((y) => this.translateFromJson(y));

@@ -221,4 +220,7 @@ }

}
delete(id) {
return this.http().delete(this.url() + '/' + encodeURIComponent(id));
async delete(id) {
if (id == '')
await this.deleteMany(Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)));
else
return this.http().delete(this.url() + '/' + encodeURIComponent(id));
}

@@ -225,0 +227,0 @@ insert(data) {

@@ -9,2 +9,33 @@ import { getEntityRef, getEntitySettings } from '../remult3/getEntityRef.js';

apply;
//@internal
static throwErrorIfFilterIsEmpty(where, methodName) {
if (Filter.isFilterEmpty(where)) {
throw {
message: `${methodName}: requires a filter to protect against accidental delete/update of all rows`,
httpStatusCode: 400,
};
}
}
//@internal
static isFilterEmpty(where) {
if (where.$and) {
for (const a of where.$and) {
if (!Filter.isFilterEmpty(a)) {
return false;
}
}
}
if (where.$or) {
for (const a of where.$or) {
if (Filter.isFilterEmpty(a)) {
return true;
}
}
return false;
}
if (Object.keys(where).filter((x) => !['$or', '$and'].includes(x)).length == 0) {
return true;
}
return false;
}
static createCustom(rawFilterTranslator, key = '') {

@@ -11,0 +42,0 @@ let rawFilterInfo = { key: key, rawFilterTranslator };

export {};
//y1 - reconsider adding where to all in case of post - it is a breaking change and no longer required
//y1 - review that with deleteMany, and updateMany I've taken a similar approach to get, that when the filter is complex, we go to post - one reason is that delete doesn't accept a body.
//y1 - should the remult api be deleteMany({id:[1,2]}) or deleteMany({where:{id:[1,2]}})
//p1 - in this video I'll use remult to turn a frontend app to a fullstack app
/*p1 - discuss using delete & put - with url query language for deleteMany and updateMany -
- put & delete, similar to get
- add where to count, deleteMany,updateMany,
- prevent delete all and update all - must have meaningful where.
- try forcing this also in typescript
- protect against deleting of all rows by mistake
- https://github.com/remult/remult/issues/221#issuecomment-2016519746
*/
//y1 - getFields didn't work for kobi in the home component
//y1 - consider replacing all errors with error classes that extend the base Error class
//p1 - document offline support

@@ -15,0 +9,0 @@ //p1 - add section to Fields doc, explaining field type in db

@@ -139,3 +139,3 @@ import { InputTypes } from '../inputTypes.js';

let r = +x;
if (!x)
if (x === null || x === undefined)
return undefined;

@@ -142,0 +142,0 @@ return r;

@@ -1084,8 +1084,6 @@ "use strict";

if (where.OR) {
result.OR = where.OR.map(function (where) {
return translateWhereToRestBody(fields, { where: where });
});
result.OR = where.OR.map(function (where) { return translateWhereToRestBody(fields, { where: where }).where; });
}
return result;
return { where: result };
}
exports.translateWhereToRestBody = translateWhereToRestBody;
{
"name": "remult",
"version": "0.25.8-exp.2",
"version": "0.25.8-exp.3",
"description": "A CRUD framework for full-stack TypeScript",

@@ -5,0 +5,0 @@ "homepage": "https://remult.dev",

@@ -95,2 +95,4 @@ import type { ClassType } from '../classType.js';

* remult.apiClient.httpClient = httpClient;
* @see
* If you want to add headers using angular httpClient, see: https://medium.com/angular-shots/shot-3-how-to-add-http-headers-to-every-request-in-angular-fab3d10edc26
*

@@ -97,0 +99,0 @@ * @example

@@ -13,5 +13,5 @@ import type { Remult } from './context.js';

get(response: DataApiResponse, id: any): Promise<void>;
count(response: DataApiResponse, request: DataApiRequest, filterBody?: any): Promise<void>;
deleteMany(response: DataApiResponse, request: DataApiRequest, filterBody?: any): Promise<void>;
getArrayImpl(response: DataApiResponse, request: DataApiRequest, filterBody: any): Promise<{
count(response: DataApiResponse, request: DataApiRequest, body?: any): Promise<void>;
deleteMany(response: DataApiResponse, request: DataApiRequest, body?: any): Promise<void>;
getArrayImpl(response: DataApiResponse, request: DataApiRequest, body: any): Promise<{
r: any[];

@@ -21,7 +21,11 @@ findOptions: FindOptions<T>;

private includeNone;
getArray(response: DataApiResponse, request: DataApiRequest, filterBody?: any): Promise<void>;
liveQuery(response: DataApiResponse, request: DataApiRequest, filterBody: any, serializeContext: () => Promise<any>, queryChannel: string): Promise<void>;
getArray(response: DataApiResponse, request: DataApiRequest, body?: any): Promise<void>;
liveQuery(response: DataApiResponse, request: DataApiRequest, body: any, serializeContext: () => Promise<any>, queryChannel: string): Promise<void>;
private buildWhere;
private doOnId;
updateMany(response: DataApiResponse, request: DataApiRequest, body?: any): Promise<void>;
updateMany(response: DataApiResponse, request: DataApiRequest, body: any): Promise<void>;
updateManyImplementation(response: DataApiResponse, request: DataApiRequest, body: {
where: any;
set: any;
}): Promise<void>;
actualUpdate(row: any, body: any): Promise<rowHelperImplementation<T>>;

@@ -28,0 +32,0 @@ put(response: DataApiResponse, id: any, body: any): Promise<void>;

@@ -47,3 +47,3 @@ "use strict";

case 3: return [2 /*return*/, this.deleteMany(res, req, body)];
case 4: return [2 /*return*/, this.updateMany(res, req, body)];
case 4: return [2 /*return*/, this.updateManyImplementation(res, req, body)];
case 5: return [4 /*yield*/, this.remult.liveQueryStorage.remove(body.id)];

@@ -79,3 +79,3 @@ case 6:

};
DataApi.prototype.count = function (response, request, filterBody) {
DataApi.prototype.count = function (response, request, body) {
return tslib_1.__awaiter(this, void 0, void 0, function () {

@@ -97,3 +97,3 @@ var _a, _b, _c, _d, err_1;

_d = (_c = this.repository).count;
return [4 /*yield*/, this.buildWhere(request, filterBody)];
return [4 /*yield*/, this.buildWhere(request, body)];
case 2: return [4 /*yield*/, _d.apply(_c, [_f.sent()])];

@@ -113,5 +113,5 @@ case 3:

};
DataApi.prototype.deleteMany = function (response, request, filterBody) {
DataApi.prototype.deleteMany = function (response, request, body) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var err_2;
var deleted_1, where_1, err_2;
var _this = this;

@@ -121,56 +121,53 @@ return tslib_1.__generator(this, function (_a) {

case 0:
_a.trys.push([0, 2, , 3]);
_a.trys.push([0, 3, , 4]);
deleted_1 = 0;
return [4 /*yield*/, this.buildWhere(request, body)];
case 1:
where_1 = _a.sent();
filter_interfaces_js_1.Filter.throwErrorIfFilterIsEmpty(where_1, 'deleteMany');
return [4 /*yield*/, (0, context_js_1.doTransaction)(this.remult, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var deleted, _a, _b, _c, _d, _e, x, e_1_1;
var _f;
var _g, e_1, _h, _j;
return tslib_1.__generator(this, function (_k) {
switch (_k.label) {
var _a, _b, _c, x, e_1_1;
var _d, e_1, _e, _f;
return tslib_1.__generator(this, function (_g) {
switch (_g.label) {
case 0:
deleted = 0;
_k.label = 1;
case 1:
_k.trys.push([1, 8, 9, 14]);
_a = true;
_e = (_d = this.repository).query;
_f = {};
return [4 /*yield*/, this.buildWhere(request, filterBody)];
_g.trys.push([0, 6, 7, 12]);
_a = true, _b = tslib_1.__asyncValues(this.repository.query({
where: where_1,
include: this.includeNone(),
}));
_g.label = 1;
case 1: return [4 /*yield*/, _b.next()];
case 2:
_b = tslib_1.__asyncValues.apply(void 0, [_e.apply(_d, [(_f.where = _k.sent(),
_f.include = this.includeNone(),
_f)])]);
_k.label = 3;
case 3: return [4 /*yield*/, _b.next()];
case 4:
if (!(_c = _k.sent(), _g = _c.done, !_g)) return [3 /*break*/, 7];
_j = _c.value;
if (!(_c = _g.sent(), _d = _c.done, !_d)) return [3 /*break*/, 5];
_f = _c.value;
_a = false;
x = _j;
x = _f;
return [4 /*yield*/, this.actualDelete(x)];
case 5:
_k.sent();
deleted++;
_k.label = 6;
case 3:
_g.sent();
deleted_1++;
_g.label = 4;
case 4:
_a = true;
return [3 /*break*/, 1];
case 5: return [3 /*break*/, 12];
case 6:
_a = true;
return [3 /*break*/, 3];
case 7: return [3 /*break*/, 14];
e_1_1 = _g.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 12];
case 7:
_g.trys.push([7, , 10, 11]);
if (!(!_a && !_d && (_e = _b.return))) return [3 /*break*/, 9];
return [4 /*yield*/, _e.call(_b)];
case 8:
e_1_1 = _k.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 14];
case 9:
_k.trys.push([9, , 12, 13]);
if (!(!_a && !_g && (_h = _b.return))) return [3 /*break*/, 11];
return [4 /*yield*/, _h.call(_b)];
_g.sent();
_g.label = 9;
case 9: return [3 /*break*/, 11];
case 10:
_k.sent();
_k.label = 11;
case 11: return [3 /*break*/, 13];
case 12:
if (e_1) throw e_1.error;
return [7 /*endfinally*/];
case 13: return [7 /*endfinally*/];
case 14:
response.success({ deleted: deleted });
case 11: return [7 /*endfinally*/];
case 12:
response.success({ deleted: deleted_1 });
return [2 /*return*/];

@@ -180,8 +177,8 @@ }

}); })];
case 1: return [2 /*return*/, _a.sent()];
case 2:
case 2: return [2 /*return*/, _a.sent()];
case 3:
err_2 = _a.sent();
response.error(err_2, this.repository.metadata);
return [3 /*break*/, 3];
case 3: return [2 /*return*/];
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}

@@ -191,3 +188,3 @@ });

};
DataApi.prototype.getArrayImpl = function (response, request, filterBody) {
DataApi.prototype.getArrayImpl = function (response, request, body) {
return tslib_1.__awaiter(this, void 0, void 0, function () {

@@ -204,3 +201,3 @@ var findOptions, _a, sort, dir, limit, hasId_1, w, r;

_a = findOptions;
return [4 /*yield*/, this.buildWhere(request, filterBody)];
return [4 /*yield*/, this.buildWhere(request, body)];
case 1:

@@ -292,3 +289,3 @@ _a.where = _b.sent();

};
DataApi.prototype.getArray = function (response, request, filterBody) {
DataApi.prototype.getArray = function (response, request, body) {
return tslib_1.__awaiter(this, void 0, void 0, function () {

@@ -306,3 +303,3 @@ var r, err_3;

_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, this.getArrayImpl(response, request, filterBody)];
return [4 /*yield*/, this.getArrayImpl(response, request, body)];
case 2:

@@ -324,3 +321,3 @@ r = (_a.sent()).r;

};
DataApi.prototype.liveQuery = function (response, request, filterBody, serializeContext, queryChannel) {
DataApi.prototype.liveQuery = function (response, request, body, serializeContext, queryChannel) {
return tslib_1.__awaiter(this, void 0, void 0, function () {

@@ -340,3 +337,3 @@ var r, data, err_4;

_b.trys.push([1, 5, , 6]);
return [4 /*yield*/, this.getArrayImpl(response, request, filterBody)];
return [4 /*yield*/, this.getArrayImpl(response, request, body)];
case 2:

@@ -372,3 +369,3 @@ r = _b.sent();

};
DataApi.prototype.buildWhere = function (request, filterBody) {
DataApi.prototype.buildWhere = function (request, body) {
return tslib_1.__awaiter(this, void 0, void 0, function () {

@@ -403,4 +400,4 @@ var where, _a, _b;

}
if (filterBody)
where.push(filter_interfaces_js_1.Filter.entityFilterFromJson(this.repository.metadata, filterBody));
if (body === null || body === void 0 ? void 0 : body.where)
where.push(filter_interfaces_js_1.Filter.entityFilterFromJson(this.repository.metadata, body.where));
return [2 /*return*/, { $and: where }];

@@ -473,2 +470,24 @@ }

return tslib_1.__awaiter(this, void 0, void 0, function () {
var action, where;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
action = request === null || request === void 0 ? void 0 : request.get('__action');
if (action == 'emptyId') {
return [2 /*return*/, this.put(response, '', body)];
}
return [4 /*yield*/, this.buildWhere(request, body)];
case 1:
where = _a.sent();
filter_interfaces_js_1.Filter.throwErrorIfFilterIsEmpty(where, 'updateMany');
return [2 /*return*/, this.updateManyImplementation(response, request, {
where: undefined,
set: body,
})];
}
});
});
};
DataApi.prototype.updateManyImplementation = function (response, request, body) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var err_6;

@@ -494,3 +513,3 @@ var _this = this;

_f = {};
return [4 /*yield*/, this.buildWhere(request, body.where)];
return [4 /*yield*/, this.buildWhere(request, body)];
case 2:

@@ -497,0 +516,0 @@ _b = tslib_1.__asyncValues.apply(void 0, [_e.apply(_d, [(_f.where = _k.sent(),

@@ -168,3 +168,3 @@ "use strict";

return tslib_1.__generator(this, function (_a) {
run = this.buildFindRequest({ where: where }, true).run;
run = this.buildFindRequest({ where: where }, 'delete').run;
return [2 /*return*/, run('deleteMany').then(function (r) { return +r.deleted; })];

@@ -178,4 +178,4 @@ });

return tslib_1.__generator(this, function (_a) {
run = this.buildFindRequest({ where: where }, true).run;
return [2 /*return*/, run('updateMany', { set: this.toJsonOfIncludedKeys(data) }).then(function (r) { return +r.updated; })];
run = this.buildFindRequest({ where: where }, 'put').run;
return [2 /*return*/, run('updateMany', this.toJsonOfIncludedKeys(data)).then(function (r) { return +r.updated; })];
});

@@ -190,5 +190,6 @@ });

//@internal
RestEntityDataProvider.prototype.buildFindRequest = function (options, forcePost) {
RestEntityDataProvider.prototype.buildFindRequest = function (options, method) {
var _this = this;
if (forcePost === void 0) { forcePost = false; }
if (!method)
method = 'get';
var url = new urlBuilder_js_1.UrlBuilder(this.url());

@@ -199,4 +200,3 @@ var filterObject;

filterObject = options.where.toJson(); // options.where.__applyToConsumer(new FilterConsumnerBridgeToUrlBuilder(url));
if (!forcePost &&
addFilterToUrlAndReturnTrueIfSuccessful(filterObject, url))
if (addFilterToUrlAndReturnTrueIfSuccessful(filterObject, url))
filterObject = undefined;

@@ -235,11 +235,8 @@ }

u.add('__action', action);
if (filterObject || forcePost) {
if (!body)
body = filterObject;
else
body = tslib_1.__assign(tslib_1.__assign({}, body), { where: filterObject });
if (filterObject) {
body = { set: body, where: filterObject };
return _this.http().post(u.url, body);
}
else
return _this.http().get(u.url);
return _this.http()[method](u.url, body);
};

@@ -278,3 +275,4 @@ return {

return this.http()
.put(this.url() + '/' + encodeURIComponent(id), this.toJsonOfIncludedKeys(data))
.put(this.url() +
(id != '' ? '/' + encodeURIComponent(id) : '?__action=emptyId'), this.toJsonOfIncludedKeys(data))
.then(function (y) { return _this.translateFromJson(y); });

@@ -303,3 +301,16 @@ };

RestEntityDataProvider.prototype.delete = function (id) {
return this.http().delete(this.url() + '/' + encodeURIComponent(id));
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(id == '')) return [3 /*break*/, 2];
return [4 /*yield*/, this.deleteMany(filter_interfaces_js_1.Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)))];
case 1:
_a.sent();
return [3 /*break*/, 3];
case 2: return [2 /*return*/, this.http().delete(this.url() + '/' + encodeURIComponent(id))];
case 3: return [2 /*return*/];
}
});
});
};

@@ -306,0 +317,0 @@ RestEntityDataProvider.prototype.insert = function (data) {

@@ -15,2 +15,54 @@ "use strict";

}
//@internal
Filter.throwErrorIfFilterIsEmpty = function (where, methodName) {
if (Filter.isFilterEmpty(where)) {
throw {
message: "".concat(methodName, ": requires a filter to protect against accidental delete/update of all rows"),
httpStatusCode: 400,
};
}
};
//@internal
Filter.isFilterEmpty = function (where) {
var e_1, _a, e_2, _b;
if (where.$and) {
try {
for (var _c = tslib_1.__values(where.$and), _d = _c.next(); !_d.done; _d = _c.next()) {
var a = _d.value;
if (!Filter.isFilterEmpty(a)) {
return false;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_1) throw e_1.error; }
}
}
if (where.$or) {
try {
for (var _e = tslib_1.__values(where.$or), _f = _e.next(); !_f.done; _f = _e.next()) {
var a = _f.value;
if (Filter.isFilterEmpty(a)) {
return true;
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_2) throw e_2.error; }
}
return false;
}
if (Object.keys(where).filter(function (x) { return !['$or', '$and'].includes(x); }).length == 0) {
return true;
}
return false;
};
Filter.createCustom = function (rawFilterTranslator, key) {

@@ -321,3 +373,3 @@ if (key === void 0) { key = ''; }

return new Filter(function (add) {
var e_1, _a;
var e_3, _a;
try {

@@ -329,3 +381,3 @@ for (var values_1 = tslib_1.__values(values), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) {

}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {

@@ -335,3 +387,3 @@ try {

}
finally { if (e_1) throw e_1.error; }
finally { if (e_3) throw e_3.error; }
}

@@ -469,3 +521,3 @@ });

var _this = _super.call(this, function (add) {
var e_2, _a;
var e_4, _a;
try {

@@ -478,3 +530,3 @@ for (var _b = tslib_1.__values(_this.filters), _c = _b.next(); !_c.done; _c = _b.next()) {

}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {

@@ -484,3 +536,3 @@ try {

}
finally { if (e_2) throw e_2.error; }
finally { if (e_4) throw e_4.error; }
}

@@ -605,3 +657,3 @@ }) || this;

function addFilter(operation, theFilter, jsonArray, asString) {
var e_3, _a;
var e_5, _a;
if (jsonArray === void 0) { jsonArray = false; }

@@ -649,3 +701,3 @@ if (asString === void 0) { asString = false; }

}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {

@@ -655,3 +707,3 @@ try {

}
finally { if (e_3) throw e_3.error; }
finally { if (e_5) throw e_5.error; }
}

@@ -730,3 +782,3 @@ }

function separateArrayFromInnerArray(val) {
var e_4, _a;
var e_6, _a;
if (!Array.isArray(val))

@@ -745,3 +797,3 @@ return [val];

}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
catch (e_6_1) { e_6 = { error: e_6_1 }; }
finally {

@@ -751,3 +803,3 @@ try {

}
finally { if (e_4) throw e_4.error; }
finally { if (e_6) throw e_6.error; }
}

@@ -754,0 +806,0 @@ array.push(nonArray);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//y1 - reconsider adding where to all in case of post - it is a breaking change and no longer required
//y1 - review that with deleteMany, and updateMany I've taken a similar approach to get, that when the filter is complex, we go to post - one reason is that delete doesn't accept a body.
//y1 - should the remult api be deleteMany({id:[1,2]}) or deleteMany({where:{id:[1,2]}})
//p1 - in this video I'll use remult to turn a frontend app to a fullstack app
/*p1 - discuss using delete & put - with url query language for deleteMany and updateMany -
- put & delete, similar to get
- add where to count, deleteMany,updateMany,
- prevent delete all and update all - must have meaningful where.
- try forcing this also in typescript
- protect against deleting of all rows by mistake
- https://github.com/remult/remult/issues/221#issuecomment-2016519746
*/
//y1 - getFields didn't work for kobi in the home component
//y1 - consider replacing all errors with error classes that extend the base Error class
//p1 - document offline support

@@ -16,0 +10,0 @@ //p1 - add section to Fields doc, explaining field type in db

@@ -141,3 +141,3 @@ "use strict";

var r = +x;
if (!x)
if (x === null || x === undefined)
return undefined;

@@ -144,0 +144,0 @@ return r;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc