remult
Advanced tools
Comparing version 0.25.8-exp.1 to 0.25.8-exp.2
@@ -8,2 +8,14 @@ import path from 'path'; | ||
import { initDataProvider } from '../server/initDataProvider.js'; | ||
/** | ||
* Generates migration scripts based on changes in entities. | ||
* | ||
* @param options - Configuration options for generating migrations. | ||
* @param options.entities - An array of entity classes to be included in the migration. | ||
* @param options.dataProvider - The data provider instance or a function returning a promise of the data provider. | ||
* @param options.migrationsFolder - (Optional) The path to the folder where migration scripts will be stored. Default is 'src/server/migrations'. | ||
* @param options.snapshotFile - (Optional) The path to the file where the snapshot of the last known state will be stored. Default is 'migrations-snapshot.json' in the `migrationsFolder`. | ||
* @param options.migrationsTSFile - (Optional) The path to the TypeScript file where the generated migrations will be written. Default is 'migrations.ts' in the `migrationsFolder`. | ||
* @param options.endConnection - (Optional) Determines whether to close the database connection after generating migrations. Default is true. | ||
* @see [Migrations](http://remult.dev/docs/migrations.html) | ||
*/ | ||
export async function generateMigrations(options) { | ||
@@ -10,0 +22,0 @@ const migrationDir = options.migrationsFolder || |
@@ -6,2 +6,12 @@ import { __decorate, __metadata } from "tslib"; | ||
import { cast, isOfType } from '../src/isOfType.js'; | ||
/** | ||
* Applies migration scripts to update the database schema. | ||
* | ||
* @param options - Configuration options for applying migrations. | ||
* @param options.migrations - An object containing the migration scripts, each keyed by a unique identifier. | ||
* @param options.dataProvider - The data provider instance or a function returning a promise of the data provider. | ||
* @param options.migrationsTable - (Optional) The name of the table that tracks applied migrations. Default is '__remult_migrations_version'. | ||
* @param options.endConnection - (Optional) Determines whether to close the database connection after applying migrations. Default is true. | ||
* @see [Migrations](http://remult.dev/docs/migrations.html) | ||
*/ | ||
export async function migrate(options) { | ||
@@ -8,0 +18,0 @@ let migrationTableName = options.migrationsTable || '__remult_migrations_version'; |
@@ -11,4 +11,4 @@ import { remult as defaultRemult } from '../src/remult-proxy.js'; | ||
supportsJsonColumnType = true; | ||
static getDb(remult) { | ||
const r = (remult || defaultRemult).dataProvider; | ||
static getDb(dataProvider) { | ||
const r = (dataProvider || defaultRemult.dataProvider); | ||
if (!r._getSourceSql) | ||
@@ -15,0 +15,0 @@ throw 'the data provider is not an SqlDatabase'; |
@@ -44,4 +44,4 @@ import { dbNamesOf, isDbReadonly, shouldCreateEntity, shouldNotCreateField, } from '../src/filter/filter-consumer-bridge-to-sql-request.js'; | ||
} | ||
static getDb(remult) { | ||
const r = (remult || remultContext).dataProvider; | ||
static getDb(dataProvider) { | ||
const r = (dataProvider || remultContext.dataProvider); | ||
if (!r.knex) | ||
@@ -48,0 +48,0 @@ throw 'the data provider is not an KnexDataProvider'; |
@@ -19,4 +19,4 @@ import { ObjectId, } from 'mongodb'; | ||
disableTransactions = false; | ||
static getDb(remult) { | ||
const r = (remult || remultContext).dataProvider; | ||
static getDb(dataProvider) { | ||
const r = (dataProvider || remultContext.dataProvider); | ||
if (!r.db) | ||
@@ -23,0 +23,0 @@ throw 'the data provider is not a MongoDataProvider'; |
@@ -16,2 +16,3 @@ import { __decorate, __metadata } from "tslib"; | ||
import remultAdminHtml from './remult-admin.js'; | ||
import { isOfType } from '../src/isOfType.js'; | ||
export function createRemultServerCore(options, serverCoreOptions) { | ||
@@ -289,3 +290,3 @@ if (!options) { | ||
let myReq = new ExpressRequestBridgeToDataApiRequest(genReq); | ||
let myRes = new ExpressResponseBridgeToDataApiResponse(origRes, req); | ||
let myRes = new ExpressResponseBridgeToDataApiResponse(origRes, req, this.options.error); | ||
try { | ||
@@ -320,3 +321,3 @@ await this.runWithRemult(async (remult) => { | ||
catch (err) { | ||
myRes.error(serializeError(err)); | ||
myRes.error(err, undefined); | ||
} | ||
@@ -679,4 +680,5 @@ }; | ||
req; | ||
handleError; | ||
forbidden() { | ||
this.setStatus(403).end(); | ||
this.error({ message: 'Forbidden' }, undefined, 403); | ||
} | ||
@@ -686,5 +688,6 @@ setStatus(status) { | ||
} | ||
constructor(r, req) { | ||
constructor(r, req, handleError) { | ||
this.r = r; | ||
this.req = req; | ||
this.handleError = handleError; | ||
} | ||
@@ -702,18 +705,49 @@ progress(progress) { } | ||
notFound() { | ||
this.setStatus(404).end(); | ||
this.error({ message: 'Forbidden' }, undefined, 404); | ||
} | ||
error(data) { | ||
data = serializeError(data); | ||
console.error({ | ||
message: data.message, | ||
stack: data.stack?.split('\n'), | ||
url: this.req?.url, | ||
method: this.req?.method, | ||
async error(exception, entity, httpStatusCode) { | ||
let data = serializeError(exception); | ||
if (!httpStatusCode) { | ||
if (data.httpStatusCode) { | ||
httpStatusCode = data.httpStatusCode; | ||
} | ||
else if (isOfType(exception, 'isForbiddenError') && | ||
exception.isForbiddenError) { | ||
httpStatusCode = 403; | ||
} | ||
else if (data.modelState) { | ||
httpStatusCode = 400; | ||
} | ||
else { | ||
httpStatusCode = 500; | ||
} | ||
} | ||
let responseSent = false; | ||
const sendError = (httpStatusCode, body) => { | ||
if (responseSent) { | ||
throw Error('Error response already sent'); | ||
} | ||
responseSent = true; | ||
console.error({ | ||
message: body.message, | ||
httpStatusCode, | ||
stack: data.stack?.split('\n'), | ||
url: this.req?.url, | ||
method: this.req?.method, | ||
}); | ||
this.setStatus(httpStatusCode).json(body); | ||
}; | ||
await this.handleError?.({ | ||
httpStatusCode, | ||
req: this.req, | ||
entity, | ||
exception, | ||
responseBody: data, | ||
sendError, | ||
}); | ||
this.setStatus(400).json(data); | ||
if (!responseSent) { | ||
sendError(httpStatusCode, data); | ||
} | ||
} | ||
} | ||
function throwError() { | ||
throw 'Invalid'; | ||
} | ||
class inProcessQueueHandler { | ||
@@ -720,0 +754,0 @@ storage; |
@@ -64,3 +64,3 @@ import { doTransaction } from './context.js'; | ||
catch (err) { | ||
response.error(err); | ||
response.error(err, this.repository.metadata); | ||
} | ||
@@ -83,3 +83,3 @@ } | ||
catch (err) { | ||
response.error(err); | ||
response.error(err, this.repository.metadata); | ||
} | ||
@@ -164,3 +164,3 @@ } | ||
else | ||
response.error(err); | ||
response.error(err, this.repository.metadata); | ||
} | ||
@@ -191,3 +191,3 @@ } | ||
else | ||
response.error(err); | ||
response.error(err, this.repository.metadata); | ||
} | ||
@@ -239,3 +239,6 @@ } | ||
else if (r.length > 1) | ||
response.error({ message: 'id is not unique' }); | ||
response.error({ | ||
message: `id "${id}" is not unique for entity ` + | ||
this.repository.metadata.key, | ||
}, this.repository.metadata, 500); | ||
else | ||
@@ -246,3 +249,3 @@ await what(r[0]); | ||
catch (err) { | ||
response.error(err); | ||
response.error(err, this.repository.metadata); | ||
} | ||
@@ -265,3 +268,3 @@ } | ||
catch (err) { | ||
response.error(err); | ||
response.error(err, this.repository.metadata); | ||
} | ||
@@ -323,3 +326,3 @@ } | ||
else | ||
response.error(err); | ||
response.error(err, this.repository.metadata); | ||
} | ||
@@ -326,0 +329,0 @@ } |
@@ -13,4 +13,4 @@ import { CompoundIdField } from '../CompoundIdField.js'; | ||
sql; | ||
static getDb(remult) { | ||
const r = (remult || defaultRemult).dataProvider; | ||
static getDb(dataProvider) { | ||
const r = (dataProvider || defaultRemult.dataProvider); | ||
if (isOfType(r, 'createCommand')) | ||
@@ -17,0 +17,0 @@ return r; |
export {}; | ||
//p1 - migrations - in docs empesize that mysql doesn't support transactions in ddl, in docs empesize destroy for knex - // await dataProvider.knex.destroy() | ||
//https://gitkraken.dev/link/dnNjb2RlOi8vZWFtb2Rpby5naXRsZW5zL2xpbmsvci9mMDgzMWU0OWIyODJkMDlkNTA0NTcxYjYwNmUzNTMwODQ3NGIwY2M2L2YvcHJvamVjdHMvcGxheS13aXRoLW1pZ3JhdGlvbnMvc3JjL3NlcnZlci9idWlsZC1taWdyYXRpb25zLnRzP3VybD1odHRwcyUzQSUyRiUyRmdpdGh1Yi5jb20lMkZyZW11bHQlMkZyZW11bHQuZ2l0?origin=gitlens | ||
/*p1 - processError in remult express | ||
- Should we merge (notFound,error,forbidden) into one method in `DataApiResponse` type? | ||
https://gitkraken.dev/link/dnNjb2RlOi8vZWFtb2Rpby5naXRsZW5zL2xpbmsvci9mMDgzMWU0OWIyODJkMDlkNTA0NTcxYjYwNmUzNTMwODQ3NGIwY2M2L2YvcHJvamVjdHMvY29yZS9zcmMvZGF0YS1hcGkudHM%2FdXJsPWh0dHBzJTNBJTJGJTJGZ2l0aHViLmNvbSUyRnJlbXVsdCUyRnJlbXVsdC5naXQ%3D?origin=gitlens | ||
- The api of the `processError` should recieve an `ErrorInfo` object and return an `ErrorInfo` object? or should it return something more in the line, | ||
of httpStatus and errorBody. - currently the `serializeError` method is used to build the response | ||
https://gitkraken.dev/link/dnNjb2RlOi8vZWFtb2Rpby5naXRsZW5zL2xpbmsvci9mMDgzMWU0OWIyODJkMDlkNTA0NTcxYjYwNmUzNTMwODQ3NGIwY2M2L2YvcHJvamVjdHMvY29yZS9zcmMvZGF0YS1hcGkudHM%2FdXJsPWh0dHBzJTNBJTJGJTJGZ2l0aHViLmNvbSUyRnJlbXVsdCUyRnJlbXVsdC5naXQmbGluZXM9NDI1?origin=gitlens | ||
- I think there should be a way to throw a forbidden exception | ||
*/ | ||
//p1 - cleanup root directory of reult | ||
//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 | ||
- 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 | ||
- protect against deleting of all rows by mistake | ||
- https://github.com/remult/remult/issues/221#issuecomment-2016519746 | ||
*/ | ||
/*p1 - I want to change the signature of getDb from getting optional remult, to getting optional dataProvider. | ||
In most cases you will not send anything - and it'll be by default remult.dataProvider. | ||
I just findmyself creating remults to extract the data provider :) | ||
*/ | ||
//y1 - getFields didn't work for kobi in the home component | ||
//p1 - document offline support | ||
//p1 - add section to Fields doc, explaining field type in db | ||
@@ -32,0 +16,0 @@ //p1 - add section about union type |
@@ -68,3 +68,3 @@ import 'reflect-metadata'; | ||
else | ||
res.error(err); | ||
res.error(err, undefined); | ||
} | ||
@@ -249,3 +249,3 @@ }); | ||
else | ||
res.error(err); | ||
res.error(err, undefined); | ||
} | ||
@@ -252,0 +252,0 @@ }); |
import type { DataProvider } from '../index.js'; | ||
/** | ||
* Generates migration scripts based on changes in entities. | ||
* | ||
* @param options - Configuration options for generating migrations. | ||
* @param options.entities - An array of entity classes to be included in the migration. | ||
* @param options.dataProvider - The data provider instance or a function returning a promise of the data provider. | ||
* @param options.migrationsFolder - (Optional) The path to the folder where migration scripts will be stored. Default is 'src/server/migrations'. | ||
* @param options.snapshotFile - (Optional) The path to the file where the snapshot of the last known state will be stored. Default is 'migrations-snapshot.json' in the `migrationsFolder`. | ||
* @param options.migrationsTSFile - (Optional) The path to the TypeScript file where the generated migrations will be written. Default is 'migrations.ts' in the `migrationsFolder`. | ||
* @param options.endConnection - (Optional) Determines whether to close the database connection after generating migrations. Default is true. | ||
* @see [Migrations](http://remult.dev/docs/migrations.html) | ||
*/ | ||
export declare function generateMigrations(options: { | ||
@@ -3,0 +15,0 @@ entities: any[]; |
@@ -12,2 +12,14 @@ "use strict"; | ||
var initDataProvider_js_1 = require("../server/initDataProvider.js"); | ||
/** | ||
* Generates migration scripts based on changes in entities. | ||
* | ||
* @param options - Configuration options for generating migrations. | ||
* @param options.entities - An array of entity classes to be included in the migration. | ||
* @param options.dataProvider - The data provider instance or a function returning a promise of the data provider. | ||
* @param options.migrationsFolder - (Optional) The path to the folder where migration scripts will be stored. Default is 'src/server/migrations'. | ||
* @param options.snapshotFile - (Optional) The path to the file where the snapshot of the last known state will be stored. Default is 'migrations-snapshot.json' in the `migrationsFolder`. | ||
* @param options.migrationsTSFile - (Optional) The path to the TypeScript file where the generated migrations will be written. Default is 'migrations.ts' in the `migrationsFolder`. | ||
* @param options.endConnection - (Optional) Determines whether to close the database connection after generating migrations. Default is true. | ||
* @see [Migrations](http://remult.dev/docs/migrations.html) | ||
*/ | ||
function generateMigrations(options) { | ||
@@ -14,0 +26,0 @@ return tslib_1.__awaiter(this, void 0, void 0, function () { |
import { type DataProvider } from '../index.js'; | ||
import type { Migrations } from './migration-types.js'; | ||
/** | ||
* Applies migration scripts to update the database schema. | ||
* | ||
* @param options - Configuration options for applying migrations. | ||
* @param options.migrations - An object containing the migration scripts, each keyed by a unique identifier. | ||
* @param options.dataProvider - The data provider instance or a function returning a promise of the data provider. | ||
* @param options.migrationsTable - (Optional) The name of the table that tracks applied migrations. Default is '__remult_migrations_version'. | ||
* @param options.endConnection - (Optional) Determines whether to close the database connection after applying migrations. Default is true. | ||
* @see [Migrations](http://remult.dev/docs/migrations.html) | ||
*/ | ||
export declare function migrate(options: { | ||
@@ -4,0 +14,0 @@ migrations: Migrations; |
@@ -9,2 +9,12 @@ "use strict"; | ||
var isOfType_js_1 = require("../src/isOfType.js"); | ||
/** | ||
* Applies migration scripts to update the database schema. | ||
* | ||
* @param options - Configuration options for applying migrations. | ||
* @param options.migrations - An object containing the migration scripts, each keyed by a unique identifier. | ||
* @param options.dataProvider - The data provider instance or a function returning a promise of the data provider. | ||
* @param options.migrationsTable - (Optional) The name of the table that tracks applied migrations. Default is '__remult_migrations_version'. | ||
* @param options.endConnection - (Optional) Determines whether to close the database connection after applying migrations. Default is true. | ||
* @see [Migrations](http://remult.dev/docs/migrations.html) | ||
*/ | ||
function migrate(options) { | ||
@@ -11,0 +21,0 @@ return tslib_1.__awaiter(this, void 0, void 0, function () { |
@@ -14,2 +14,22 @@ import type { EntityMetadata, FieldMetadata } from '../index.js'; | ||
} | ||
/** | ||
* Represents a set of migrations, each identified by a unique number. | ||
* | ||
* Each migration function takes a `MigrationUtils` object as a parameter, which provides utility methods for executing SQL statements and other migration-related operations. | ||
* | ||
* Migrations are executed in a transaction, meaning that all changes within a single migration are either fully applied or fully rolled back in case of an error. This ensures the consistency of the database state. | ||
* | ||
* Note: Some databases, like MySQL, do not support rolling back structural changes (e.g., table creation or alteration) as part of a transaction. Developers should be aware of this when designing migrations for such databases. | ||
* | ||
* @example | ||
* export const migrations: Migrations = { | ||
* 1: async ({ sql }) => { | ||
* await sql(`CREATE TABLE example (id SERIAL PRIMARY KEY, name VARCHAR(255))`); | ||
* }, | ||
* 2: async ({ sql }) => { | ||
* await sql(`ALTER TABLE example ADD COLUMN description TEXT`); | ||
* }, | ||
* }; | ||
* @see [Migrations](http://remult.dev/docs/migrations.html) | ||
*/ | ||
export type Migrations = Record<number, (utils: MigrationUtils) => Promise<unknown>>; | ||
@@ -16,0 +36,0 @@ export type MigrationUtils = { |
{ | ||
"name": "remult", | ||
"version": "0.25.8-exp.1", | ||
"version": "0.25.8-exp.2", | ||
"description": "A CRUD framework for full-stack TypeScript", | ||
@@ -5,0 +5,0 @@ "homepage": "https://remult.dev", |
import type { ClientBase, PoolConfig, QueryResult } from 'pg'; | ||
import { Remult } from '../src/context.js'; | ||
import { SqlDatabase } from '../src/data-providers/sql-database.js'; | ||
@@ -7,2 +6,3 @@ import type { EntityMetadata } from '../src/remult3/remult3.js'; | ||
import type { CanBuildMigrations, MigrationBuilder, MigrationCode } from '../migrations/migration-types.js'; | ||
import type { DataProvider } from '../index.js'; | ||
export interface PostgresPool extends PostgresCommandSource { | ||
@@ -19,3 +19,3 @@ connect(): Promise<PostgresClient>; | ||
supportsJsonColumnType: boolean; | ||
static getDb(remult?: Remult): ClientBase; | ||
static getDb(dataProvider?: DataProvider): ClientBase; | ||
entityIsUsedForTheFirstTime(entity: EntityMetadata): Promise<void>; | ||
@@ -22,0 +22,0 @@ getLimitSqlSyntax(limit: number, offset: number): string; |
@@ -34,4 +34,4 @@ "use strict"; | ||
} | ||
PostgresDataProvider.getDb = function (remult) { | ||
var r = (remult || remult_proxy_js_1.remult).dataProvider; | ||
PostgresDataProvider.getDb = function (dataProvider) { | ||
var r = (dataProvider || remult_proxy_js_1.remult.dataProvider); | ||
if (!r._getSourceSql) | ||
@@ -38,0 +38,0 @@ throw 'the data provider is not an SqlDatabase'; |
@@ -16,3 +16,3 @@ import type { Knex } from 'knex'; | ||
execute(sql: string): Promise<SqlResult>; | ||
static getDb(remult?: Remult): Knex<any, any[]>; | ||
static getDb(dataProvider?: DataProvider): Knex<any, any[]>; | ||
wrapIdentifier: (name: string) => string; | ||
@@ -19,0 +19,0 @@ getEntityDataProvider(entity: EntityMetadata<any>): EntityDataProvider; |
@@ -71,4 +71,4 @@ "use strict"; | ||
}; | ||
KnexDataProvider.getDb = function (remult) { | ||
var r = (remult || remult_proxy_js_1.remult).dataProvider; | ||
KnexDataProvider.getDb = function (dataProvider) { | ||
var r = (dataProvider || remult_proxy_js_1.remult.dataProvider); | ||
if (!r.knex) | ||
@@ -75,0 +75,0 @@ throw 'the data provider is not an KnexDataProvider'; |
import { type ClientSession, type Db, type MongoClient } from 'mongodb'; | ||
import type { DataProvider, EntityDataProvider, EntityFilter, EntityMetadata, Remult } from './index.js'; | ||
import type { DataProvider, EntityDataProvider, EntityFilter, EntityMetadata } from './index.js'; | ||
import type { RepositoryOverloads } from './src/remult3/RepositoryImplementation.js'; | ||
@@ -13,3 +13,3 @@ export declare class MongoDataProvider implements DataProvider { | ||
disableTransactions: boolean; | ||
static getDb(remult?: Remult): { | ||
static getDb(dataProvider?: DataProvider): { | ||
db: Db; | ||
@@ -16,0 +16,0 @@ session: ClientSession; |
@@ -20,4 +20,4 @@ "use strict"; | ||
} | ||
MongoDataProvider.getDb = function (remult) { | ||
var r = (remult || remult_proxy_js_1.remult).dataProvider; | ||
MongoDataProvider.getDb = function (dataProvider) { | ||
var r = (dataProvider || remult_proxy_js_1.remult.dataProvider); | ||
if (!r.db) | ||
@@ -24,0 +24,0 @@ throw 'the data provider is not a MongoDataProvider'; |
@@ -58,2 +58,23 @@ import type { ClassType } from '../classType.js'; | ||
queueStorage?: QueueStorage; | ||
/** | ||
* This method is called whenever there is an error in the API lifecycle. | ||
* | ||
* @param info - Information about the error. | ||
* @param info.req - The request object. | ||
* @param info.entity - (Optional) The entity metadata associated with the error, if applicable. | ||
* @param info.exception - (Optional) The exception object or error that occurred. | ||
* @param info.httpStatusCode - The HTTP status code. | ||
* @param info.responseBody - The body of the response. | ||
* @param info.sendError - A method to send a custom error response. Call this method with the desired HTTP status code and response body. | ||
* | ||
* @returns A promise that resolves when the error handling is complete. | ||
* @example | ||
* export const api = remultExpress({ | ||
* error: async (e) => { | ||
* if (e.httpStatusCode == 500) { | ||
* e.sendError(500, { message: "An error occurred" }) | ||
* } | ||
* } | ||
* }) | ||
*/ | ||
error?: (info: { | ||
@@ -60,0 +81,0 @@ req: RequestType; |
import type { Remult } from './context.js'; | ||
import type { ErrorInfo } from './data-interfaces.js'; | ||
import type { FindOptions, Repository } from './remult3/remult3.js'; | ||
import type { EntityMetadata, FindOptions, Repository } from './remult3/remult3.js'; | ||
import type { rowHelperImplementation } from './remult3/RepositoryImplementation.js'; | ||
@@ -36,3 +36,3 @@ export declare class DataApi<T = any> { | ||
notFound(): void; | ||
error(data: ErrorInfo): void; | ||
error(data: ErrorInfo, entity: EntityMetadata | undefined, statusCode?: number | undefined): void; | ||
forbidden(): void; | ||
@@ -39,0 +39,0 @@ progress(progress: number): void; |
@@ -103,3 +103,3 @@ "use strict"; | ||
err_1 = _f.sent(); | ||
response.error(err_1); | ||
response.error(err_1, this.repository.metadata); | ||
return [3 /*break*/, 5]; | ||
@@ -179,3 +179,3 @@ case 5: return [2 /*return*/]; | ||
err_2 = _a.sent(); | ||
response.error(err_2); | ||
response.error(err_2, this.repository.metadata); | ||
return [3 /*break*/, 3]; | ||
@@ -309,3 +309,3 @@ case 3: return [2 /*return*/]; | ||
else | ||
response.error(err_3); | ||
response.error(err_3, this.repository.metadata); | ||
return [3 /*break*/, 4]; | ||
@@ -356,3 +356,3 @@ case 4: return [2 /*return*/]; | ||
else | ||
response.error(err_4); | ||
response.error(err_4, this.repository.metadata); | ||
return [3 /*break*/, 6]; | ||
@@ -436,3 +436,6 @@ case 6: return [2 /*return*/]; | ||
if (!(r.length > 1)) return [3 /*break*/, 2]; | ||
response.error({ message: 'id is not unique' }); | ||
response.error({ | ||
message: "id \"".concat(id, "\" is not unique for entity ") + | ||
this.repository.metadata.key, | ||
}, this.repository.metadata, 500); | ||
return [3 /*break*/, 4]; | ||
@@ -452,3 +455,3 @@ case 2: return [4 /*yield*/, what(r[0])]; | ||
err_5 = _c.sent(); | ||
response.error(err_5); | ||
response.error(err_5, this.repository.metadata); | ||
return [3 /*break*/, 6]; | ||
@@ -528,3 +531,3 @@ case 6: return [2 /*return*/]; | ||
err_6 = _a.sent(); | ||
response.error(err_6); | ||
response.error(err_6, this.repository.metadata); | ||
return [3 /*break*/, 3]; | ||
@@ -700,3 +703,3 @@ case 3: return [2 /*return*/]; | ||
else | ||
response.error(err_7); | ||
response.error(err_7, this.repository.metadata); | ||
return [3 /*break*/, 6]; | ||
@@ -703,0 +706,0 @@ case 6: return [2 /*return*/]; |
import type { DataProvider, EntityDataProvider } from '../data-interfaces.js'; | ||
import type { HasWrapIdentifier, SqlCommand, SqlCommandFactory, SqlCommandWithParameters, SqlImplementation, SqlResult } from '../sql-command.js'; | ||
import type { Remult } from '../context.js'; | ||
import type { CustomSqlFilterBuilderFunction, EntityDbNamesBase } from '../filter/filter-consumer-bridge-to-sql-request.js'; | ||
@@ -10,3 +9,3 @@ import type { EntityFilter, EntityMetadata } from '../remult3/remult3.js'; | ||
private sql; | ||
static getDb(remult?: Remult): SqlDatabase; | ||
static getDb(dataProvider?: DataProvider): SqlDatabase; | ||
createCommand(): SqlCommand; | ||
@@ -13,0 +12,0 @@ execute(sql: string): Promise<SqlResult>; |
@@ -28,4 +28,4 @@ "use strict"; | ||
} | ||
SqlDatabase.getDb = function (remult) { | ||
var r = (remult || remult_proxy_js_1.remult).dataProvider; | ||
SqlDatabase.getDb = function (dataProvider) { | ||
var r = (dataProvider || remult_proxy_js_1.remult.dataProvider); | ||
if ((0, isOfType_js_1.isOfType)(r, 'createCommand')) | ||
@@ -32,0 +32,0 @@ return r; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//p1 - migrations - in docs empesize that mysql doesn't support transactions in ddl, in docs empesize destroy for knex - // await dataProvider.knex.destroy() | ||
//https://gitkraken.dev/link/dnNjb2RlOi8vZWFtb2Rpby5naXRsZW5zL2xpbmsvci9mMDgzMWU0OWIyODJkMDlkNTA0NTcxYjYwNmUzNTMwODQ3NGIwY2M2L2YvcHJvamVjdHMvcGxheS13aXRoLW1pZ3JhdGlvbnMvc3JjL3NlcnZlci9idWlsZC1taWdyYXRpb25zLnRzP3VybD1odHRwcyUzQSUyRiUyRmdpdGh1Yi5jb20lMkZyZW11bHQlMkZyZW11bHQuZ2l0?origin=gitlens | ||
/*p1 - processError in remult express | ||
- Should we merge (notFound,error,forbidden) into one method in `DataApiResponse` type? | ||
https://gitkraken.dev/link/dnNjb2RlOi8vZWFtb2Rpby5naXRsZW5zL2xpbmsvci9mMDgzMWU0OWIyODJkMDlkNTA0NTcxYjYwNmUzNTMwODQ3NGIwY2M2L2YvcHJvamVjdHMvY29yZS9zcmMvZGF0YS1hcGkudHM%2FdXJsPWh0dHBzJTNBJTJGJTJGZ2l0aHViLmNvbSUyRnJlbXVsdCUyRnJlbXVsdC5naXQ%3D?origin=gitlens | ||
- The api of the `processError` should recieve an `ErrorInfo` object and return an `ErrorInfo` object? or should it return something more in the line, | ||
of httpStatus and errorBody. - currently the `serializeError` method is used to build the response | ||
https://gitkraken.dev/link/dnNjb2RlOi8vZWFtb2Rpby5naXRsZW5zL2xpbmsvci9mMDgzMWU0OWIyODJkMDlkNTA0NTcxYjYwNmUzNTMwODQ3NGIwY2M2L2YvcHJvamVjdHMvY29yZS9zcmMvZGF0YS1hcGkudHM%2FdXJsPWh0dHBzJTNBJTJGJTJGZ2l0aHViLmNvbSUyRnJlbXVsdCUyRnJlbXVsdC5naXQmbGluZXM9NDI1?origin=gitlens | ||
- I think there should be a way to throw a forbidden exception | ||
*/ | ||
//p1 - cleanup root directory of reult | ||
//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 | ||
- 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 | ||
- protect against deleting of all rows by mistake | ||
- https://github.com/remult/remult/issues/221#issuecomment-2016519746 | ||
*/ | ||
/*p1 - I want to change the signature of getDb from getting optional remult, to getting optional dataProvider. | ||
In most cases you will not send anything - and it'll be by default remult.dataProvider. | ||
I just findmyself creating remults to extract the data provider :) | ||
*/ | ||
//y1 - getFields didn't work for kobi in the home component | ||
//p1 - document offline support | ||
//p1 - add section to Fields doc, explaining field type in db | ||
@@ -33,0 +17,0 @@ //p1 - add section about union type |
@@ -101,3 +101,3 @@ "use strict"; | ||
else | ||
res.error(err_1); | ||
res.error(err_1, undefined); | ||
return [3 /*break*/, 3]; | ||
@@ -385,3 +385,3 @@ case 3: return [2 /*return*/]; | ||
else | ||
res.error(err_3); | ||
res.error(err_3, undefined); | ||
return [3 /*break*/, 4]; | ||
@@ -388,0 +388,0 @@ case 4: return [2 /*return*/]; |
Sorry, the diff of this file is too big to display
4926073
49055