pqb 0.67.0 → 0.67.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/index.d.ts +229 -201
- package/dist/index.js +98 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -56
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +9490 -2
- package/dist/internal.js +17 -0
- package/dist/internal.js.map +1 -1
- package/dist/internal.mjs +17 -1
- package/dist/internal.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let src_index_ts = require("./index.js");
|
|
3
3
|
var OrchidOrmError = class extends Error {};
|
|
4
|
+
var OrchidOrmInternalError = class extends Error {
|
|
5
|
+
#query;
|
|
6
|
+
constructor(query, message, data) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.data = data;
|
|
9
|
+
this.#query = query;
|
|
10
|
+
}
|
|
11
|
+
getQuery() {
|
|
12
|
+
return this.#query;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var CannotMutateReadOnlyTableError = class extends OrchidOrmInternalError {
|
|
16
|
+
constructor(query) {
|
|
17
|
+
super(query, "Cannot mutate a readonly table.");
|
|
18
|
+
}
|
|
19
|
+
};
|
|
4
20
|
Object.defineProperty(exports, "AdapterClass", {
|
|
5
21
|
enumerable: true,
|
|
6
22
|
get: function() {
|
|
@@ -55,6 +71,7 @@ Object.defineProperty(exports, "ByteaColumn", {
|
|
|
55
71
|
return src_index_ts.ByteaColumn;
|
|
56
72
|
}
|
|
57
73
|
});
|
|
74
|
+
exports.CannotMutateReadOnlyTableError = CannotMutateReadOnlyTableError;
|
|
58
75
|
Object.defineProperty(exports, "CidrColumn", {
|
|
59
76
|
enumerable: true,
|
|
60
77
|
get: function() {
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","names":[],"sources":["../src/query/errors.ts"],"sourcesContent":["import { RecordUnknown } from '../utils';\nimport { PickQueryShape } from './pick-query-types';\nimport { IsQuery, Query } from './query';\nimport { queryColumnNameToKey } from './query-columns/query-columns';\n\nexport abstract class OrchidOrmError extends Error {}\n\n/**\n * When we search for a single record, and it is not found, it can either throw an error, or return `undefined`.\n *\n * Unlike other database libraries, `Orchid ORM` decided to throw errors by default when using methods `take`, `find`, `findBy`, `get` and the record is not found.\n * It is a [good practice](https://github.com/goldbergyoni/nodebestpractices/blob/master/sections/errorhandling/centralizedhandling.md) to catch common errors in a centralized place (see [global error handling](https://orchid-orm.netlify.app/guide/error-handling.html#global-error-handling)), and this allows for a more concise code.\n *\n * If it's more suitable to get the `undefined` value instead of throwing, use `takeOptional`, `findOptional`, `findByOptional`, `getOptional` instead.\n */\nexport class NotFoundError extends OrchidOrmError {\n // `#query` is private to prevent it from serializing to not cause problems to test runner reports\n // it is exposed with `getQuery` method which prevents this problem from both Vitest and Jest.\n // Exposing it with `get query()` still leaves the issue in Vitest.\n readonly #query: Query;\n\n constructor(query: IsQuery, message = 'Record is not found') {\n super(message);\n this.#query = query as Query;\n }\n\n getQuery() {\n return this.#query;\n }\n}\n\nexport class OrchidOrmInternalError extends Error {\n // `#query` is private to prevent it from serializing to not cause problems to test runner reports\n // it is exposed with `getQuery` method which prevents this problem from both Vitest and Jest.\n // Exposing it with `get query()` still leaves the issue in Vitest.\n readonly #query: Query;\n\n constructor(\n query: IsQuery,\n message?: string,\n public data?: RecordUnknown,\n ) {\n super(message);\n this.#query = query as Query;\n }\n\n getQuery() {\n return this.#query;\n }\n}\n\nexport type QueryErrorName =\n | 'parseComplete'\n | 'bindComplete'\n | 'closeComplete'\n | 'noData'\n | 'portalSuspended'\n | 'replicationStart'\n | 'emptyQuery'\n | 'copyDone'\n | 'copyData'\n | 'rowDescription'\n | 'parameterDescription'\n | 'parameterStatus'\n | 'backendKeyData'\n | 'notification'\n | 'readyForQuery'\n | 'commandComplete'\n | 'dataRow'\n | 'copyInResponse'\n | 'copyOutResponse'\n | 'authenticationOk'\n | 'authenticationMD5Password'\n | 'authenticationCleartextPassword'\n | 'authenticationSASL'\n | 'authenticationSASLContinue'\n | 'authenticationSASLFinal'\n | 'error'\n | 'notice';\n\nexport abstract class QueryError<\n T extends PickQueryShape = PickQueryShape,\n> extends OrchidOrmInternalError {\n declare message: string;\n declare length?: number;\n declare name: QueryErrorName;\n declare stack: string | undefined;\n code: string | undefined;\n detail: string | undefined;\n severity: string | undefined;\n hint: string | undefined;\n position: string | undefined;\n internalPosition: string | undefined;\n internalQuery: string | undefined;\n where: string | undefined;\n schema: string | undefined;\n table: string | undefined;\n column: string | undefined;\n dataType: string | undefined;\n constraint: string | undefined;\n file: string | undefined;\n line: string | undefined;\n routine: string | undefined;\n\n get isUnique() {\n return this.code === '23505';\n }\n\n #columnsCache?: { [K in keyof T['shape']]?: true };\n get columns() {\n if (this.#columnsCache) return this.#columnsCache;\n\n const columns: { [K in keyof T['shape']]?: true } = {};\n\n if (this.detail) {\n const list = this.detail.match(/\\((.*)\\)=/)?.[1];\n if (list) {\n list.split(', ').forEach((item) => {\n const column = (\n item.startsWith('\"') ? item.slice(1, -1) : item\n ) as keyof T['shape'];\n\n const key =\n queryColumnNameToKey(this.getQuery(), column as string) ?? column;\n columns[key as keyof T['shape']] = true;\n });\n }\n }\n\n return (this.#columnsCache = columns);\n }\n}\n\nexport class MoreThanOneRowError extends OrchidOrmInternalError {\n constructor(query: IsQuery, message?: string) {\n super(query, message);\n }\n}\n\nexport class UnhandledTypeError extends OrchidOrmInternalError {\n constructor(query: IsQuery, value: never) {\n super(query, `Unhandled type: ${JSON.stringify(value)} received`);\n }\n}\n\n/**\n * Error thrown when attempting to nest SQL session scopes.\n * Nested withOptions/$withOptions calls that supply role or setConfig while an outer\n * scope already has SQL session state defined will throw this error.\n */\nexport class NestedSqlSessionError extends OrchidOrmInternalError {\n constructor(query: IsQuery) {\n super(\n query,\n 'Cannot nest SQL session scopes. Outer scope already has role or setConfig defined.',\n );\n }\n}\n"],"mappings":";;AAKA,IAAsB,iBAAtB,cAA6C,MAAM"}
|
|
1
|
+
{"version":3,"file":"internal.js","names":["#query"],"sources":["../src/query/errors.ts"],"sourcesContent":["import { RecordUnknown } from '../utils';\nimport { PickQueryShape } from './pick-query-types';\nimport { IsQuery, Query } from './query';\nimport { queryColumnNameToKey } from './query-columns/query-columns';\n\nexport abstract class OrchidOrmError extends Error {}\n\n/**\n * When we search for a single record, and it is not found, it can either throw an error, or return `undefined`.\n *\n * Unlike other database libraries, `Orchid ORM` decided to throw errors by default when using methods `take`, `find`, `findBy`, `get` and the record is not found.\n * It is a [good practice](https://github.com/goldbergyoni/nodebestpractices/blob/master/sections/errorhandling/centralizedhandling.md) to catch common errors in a centralized place (see [global error handling](https://orchid-orm.netlify.app/guide/error-handling.html#global-error-handling)), and this allows for a more concise code.\n *\n * If it's more suitable to get the `undefined` value instead of throwing, use `takeOptional`, `findOptional`, `findByOptional`, `getOptional` instead.\n */\nexport class NotFoundError extends OrchidOrmError {\n // `#query` is private to prevent it from serializing to not cause problems to test runner reports\n // it is exposed with `getQuery` method which prevents this problem from both Vitest and Jest.\n // Exposing it with `get query()` still leaves the issue in Vitest.\n readonly #query: Query;\n\n constructor(query: IsQuery, message = 'Record is not found') {\n super(message);\n this.#query = query as Query;\n }\n\n getQuery() {\n return this.#query;\n }\n}\n\nexport class OrchidOrmInternalError extends Error {\n // `#query` is private to prevent it from serializing to not cause problems to test runner reports\n // it is exposed with `getQuery` method which prevents this problem from both Vitest and Jest.\n // Exposing it with `get query()` still leaves the issue in Vitest.\n readonly #query: Query;\n\n constructor(\n query: IsQuery,\n message?: string,\n public data?: RecordUnknown,\n ) {\n super(message);\n this.#query = query as Query;\n }\n\n getQuery() {\n return this.#query;\n }\n}\n\nexport type QueryErrorName =\n | 'parseComplete'\n | 'bindComplete'\n | 'closeComplete'\n | 'noData'\n | 'portalSuspended'\n | 'replicationStart'\n | 'emptyQuery'\n | 'copyDone'\n | 'copyData'\n | 'rowDescription'\n | 'parameterDescription'\n | 'parameterStatus'\n | 'backendKeyData'\n | 'notification'\n | 'readyForQuery'\n | 'commandComplete'\n | 'dataRow'\n | 'copyInResponse'\n | 'copyOutResponse'\n | 'authenticationOk'\n | 'authenticationMD5Password'\n | 'authenticationCleartextPassword'\n | 'authenticationSASL'\n | 'authenticationSASLContinue'\n | 'authenticationSASLFinal'\n | 'error'\n | 'notice';\n\nexport abstract class QueryError<\n T extends PickQueryShape = PickQueryShape,\n> extends OrchidOrmInternalError {\n declare message: string;\n declare length?: number;\n declare name: QueryErrorName;\n declare stack: string | undefined;\n code: string | undefined;\n detail: string | undefined;\n severity: string | undefined;\n hint: string | undefined;\n position: string | undefined;\n internalPosition: string | undefined;\n internalQuery: string | undefined;\n where: string | undefined;\n schema: string | undefined;\n table: string | undefined;\n column: string | undefined;\n dataType: string | undefined;\n constraint: string | undefined;\n file: string | undefined;\n line: string | undefined;\n routine: string | undefined;\n\n get isUnique() {\n return this.code === '23505';\n }\n\n #columnsCache?: { [K in keyof T['shape']]?: true };\n get columns() {\n if (this.#columnsCache) return this.#columnsCache;\n\n const columns: { [K in keyof T['shape']]?: true } = {};\n\n if (this.detail) {\n const list = this.detail.match(/\\((.*)\\)=/)?.[1];\n if (list) {\n list.split(', ').forEach((item) => {\n const column = (\n item.startsWith('\"') ? item.slice(1, -1) : item\n ) as keyof T['shape'];\n\n const key =\n queryColumnNameToKey(this.getQuery(), column as string) ?? column;\n columns[key as keyof T['shape']] = true;\n });\n }\n }\n\n return (this.#columnsCache = columns);\n }\n}\n\nexport class MoreThanOneRowError extends OrchidOrmInternalError {\n constructor(query: IsQuery, message?: string) {\n super(query, message);\n }\n}\n\nexport class UnhandledTypeError extends OrchidOrmInternalError {\n constructor(query: IsQuery, value: never) {\n super(query, `Unhandled type: ${JSON.stringify(value)} received`);\n }\n}\n\n/**\n * Error thrown when attempting to nest SQL session scopes.\n * Nested withOptions/$withOptions calls that supply role or setConfig while an outer\n * scope already has SQL session state defined will throw this error.\n */\nexport class NestedSqlSessionError extends OrchidOrmInternalError {\n constructor(query: IsQuery) {\n super(\n query,\n 'Cannot nest SQL session scopes. Outer scope already has role or setConfig defined.',\n );\n }\n}\n\nexport class CannotMutateReadOnlyTableError extends OrchidOrmInternalError {\n constructor(query: IsQuery) {\n super(query, 'Cannot mutate a readonly table.');\n }\n}\n"],"mappings":";;AAKA,IAAsB,iBAAtB,cAA6C,MAAM;AA0BnD,IAAa,yBAAb,cAA4C,MAAM;CAIhD;CAEA,YACE,OACA,SACA,MACA;AACA,QAAM,QAAQ;AAFP,OAAA,OAAA;AAGP,QAAA,QAAc;;CAGhB,WAAW;AACT,SAAO,MAAA;;;AAgHX,IAAa,iCAAb,cAAoD,uBAAuB;CACzE,YAAY,OAAgB;AAC1B,QAAM,OAAO,kCAAkC"}
|
package/dist/internal.mjs
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { AdapterClass, ArrayColumn, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Column, CustomTypeColumn, DateColumn, DecimalColumn, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, Expression, InetColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MoneyColumn, Operators, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryHookUtils, QueryHooks, RawSql, RealColumn, SerialColumn, SmallIntColumn, SmallSerialColumn, StringColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, TransactionAdapterClass, TsQueryColumn, TsVectorColumn, UUIDColumn, UnknownColumn, VarCharColumn, VirtualColumn, XMLColumn, _appendQuery, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnTypes, getDateAsDateFn, getDateAsNumberFn, getDriverErrorCode, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, internalSchemaConfig, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteIdentifier, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, tableDataMethods, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry } from "./index.mjs";
|
|
2
2
|
var OrchidOrmError = class extends Error {};
|
|
3
|
-
|
|
3
|
+
var OrchidOrmInternalError = class extends Error {
|
|
4
|
+
#query;
|
|
5
|
+
constructor(query, message, data) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.data = data;
|
|
8
|
+
this.#query = query;
|
|
9
|
+
}
|
|
10
|
+
getQuery() {
|
|
11
|
+
return this.#query;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var CannotMutateReadOnlyTableError = class extends OrchidOrmInternalError {
|
|
15
|
+
constructor(query) {
|
|
16
|
+
super(query, "Cannot mutate a readonly table.");
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export { AdapterClass, ArrayColumn, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CannotMutateReadOnlyTableError, CidrColumn, CircleColumn, CitextColumn, Column, CustomTypeColumn, DateColumn, DecimalColumn, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, Expression, InetColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MoneyColumn, Operators, OrchidOrmError, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryHookUtils, QueryHooks, RawSql, RealColumn, SerialColumn, SmallIntColumn, SmallSerialColumn, StringColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, TransactionAdapterClass, TsQueryColumn, TsVectorColumn, UUIDColumn, UnknownColumn, VarCharColumn, VirtualColumn, XMLColumn, _appendQuery, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnTypes, getDateAsDateFn, getDateAsNumberFn, getDriverErrorCode, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, internalSchemaConfig, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteIdentifier, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, tableDataMethods, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
|
|
4
20
|
|
|
5
21
|
//# sourceMappingURL=internal.mjs.map
|
package/dist/internal.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.mjs","names":[],"sources":["../src/query/errors.ts"],"sourcesContent":["import { RecordUnknown } from '../utils';\nimport { PickQueryShape } from './pick-query-types';\nimport { IsQuery, Query } from './query';\nimport { queryColumnNameToKey } from './query-columns/query-columns';\n\nexport abstract class OrchidOrmError extends Error {}\n\n/**\n * When we search for a single record, and it is not found, it can either throw an error, or return `undefined`.\n *\n * Unlike other database libraries, `Orchid ORM` decided to throw errors by default when using methods `take`, `find`, `findBy`, `get` and the record is not found.\n * It is a [good practice](https://github.com/goldbergyoni/nodebestpractices/blob/master/sections/errorhandling/centralizedhandling.md) to catch common errors in a centralized place (see [global error handling](https://orchid-orm.netlify.app/guide/error-handling.html#global-error-handling)), and this allows for a more concise code.\n *\n * If it's more suitable to get the `undefined` value instead of throwing, use `takeOptional`, `findOptional`, `findByOptional`, `getOptional` instead.\n */\nexport class NotFoundError extends OrchidOrmError {\n // `#query` is private to prevent it from serializing to not cause problems to test runner reports\n // it is exposed with `getQuery` method which prevents this problem from both Vitest and Jest.\n // Exposing it with `get query()` still leaves the issue in Vitest.\n readonly #query: Query;\n\n constructor(query: IsQuery, message = 'Record is not found') {\n super(message);\n this.#query = query as Query;\n }\n\n getQuery() {\n return this.#query;\n }\n}\n\nexport class OrchidOrmInternalError extends Error {\n // `#query` is private to prevent it from serializing to not cause problems to test runner reports\n // it is exposed with `getQuery` method which prevents this problem from both Vitest and Jest.\n // Exposing it with `get query()` still leaves the issue in Vitest.\n readonly #query: Query;\n\n constructor(\n query: IsQuery,\n message?: string,\n public data?: RecordUnknown,\n ) {\n super(message);\n this.#query = query as Query;\n }\n\n getQuery() {\n return this.#query;\n }\n}\n\nexport type QueryErrorName =\n | 'parseComplete'\n | 'bindComplete'\n | 'closeComplete'\n | 'noData'\n | 'portalSuspended'\n | 'replicationStart'\n | 'emptyQuery'\n | 'copyDone'\n | 'copyData'\n | 'rowDescription'\n | 'parameterDescription'\n | 'parameterStatus'\n | 'backendKeyData'\n | 'notification'\n | 'readyForQuery'\n | 'commandComplete'\n | 'dataRow'\n | 'copyInResponse'\n | 'copyOutResponse'\n | 'authenticationOk'\n | 'authenticationMD5Password'\n | 'authenticationCleartextPassword'\n | 'authenticationSASL'\n | 'authenticationSASLContinue'\n | 'authenticationSASLFinal'\n | 'error'\n | 'notice';\n\nexport abstract class QueryError<\n T extends PickQueryShape = PickQueryShape,\n> extends OrchidOrmInternalError {\n declare message: string;\n declare length?: number;\n declare name: QueryErrorName;\n declare stack: string | undefined;\n code: string | undefined;\n detail: string | undefined;\n severity: string | undefined;\n hint: string | undefined;\n position: string | undefined;\n internalPosition: string | undefined;\n internalQuery: string | undefined;\n where: string | undefined;\n schema: string | undefined;\n table: string | undefined;\n column: string | undefined;\n dataType: string | undefined;\n constraint: string | undefined;\n file: string | undefined;\n line: string | undefined;\n routine: string | undefined;\n\n get isUnique() {\n return this.code === '23505';\n }\n\n #columnsCache?: { [K in keyof T['shape']]?: true };\n get columns() {\n if (this.#columnsCache) return this.#columnsCache;\n\n const columns: { [K in keyof T['shape']]?: true } = {};\n\n if (this.detail) {\n const list = this.detail.match(/\\((.*)\\)=/)?.[1];\n if (list) {\n list.split(', ').forEach((item) => {\n const column = (\n item.startsWith('\"') ? item.slice(1, -1) : item\n ) as keyof T['shape'];\n\n const key =\n queryColumnNameToKey(this.getQuery(), column as string) ?? column;\n columns[key as keyof T['shape']] = true;\n });\n }\n }\n\n return (this.#columnsCache = columns);\n }\n}\n\nexport class MoreThanOneRowError extends OrchidOrmInternalError {\n constructor(query: IsQuery, message?: string) {\n super(query, message);\n }\n}\n\nexport class UnhandledTypeError extends OrchidOrmInternalError {\n constructor(query: IsQuery, value: never) {\n super(query, `Unhandled type: ${JSON.stringify(value)} received`);\n }\n}\n\n/**\n * Error thrown when attempting to nest SQL session scopes.\n * Nested withOptions/$withOptions calls that supply role or setConfig while an outer\n * scope already has SQL session state defined will throw this error.\n */\nexport class NestedSqlSessionError extends OrchidOrmInternalError {\n constructor(query: IsQuery) {\n super(\n query,\n 'Cannot nest SQL session scopes. Outer scope already has role or setConfig defined.',\n );\n }\n}\n"],"mappings":";AAKA,IAAsB,iBAAtB,cAA6C,MAAM"}
|
|
1
|
+
{"version":3,"file":"internal.mjs","names":["#query"],"sources":["../src/query/errors.ts"],"sourcesContent":["import { RecordUnknown } from '../utils';\nimport { PickQueryShape } from './pick-query-types';\nimport { IsQuery, Query } from './query';\nimport { queryColumnNameToKey } from './query-columns/query-columns';\n\nexport abstract class OrchidOrmError extends Error {}\n\n/**\n * When we search for a single record, and it is not found, it can either throw an error, or return `undefined`.\n *\n * Unlike other database libraries, `Orchid ORM` decided to throw errors by default when using methods `take`, `find`, `findBy`, `get` and the record is not found.\n * It is a [good practice](https://github.com/goldbergyoni/nodebestpractices/blob/master/sections/errorhandling/centralizedhandling.md) to catch common errors in a centralized place (see [global error handling](https://orchid-orm.netlify.app/guide/error-handling.html#global-error-handling)), and this allows for a more concise code.\n *\n * If it's more suitable to get the `undefined` value instead of throwing, use `takeOptional`, `findOptional`, `findByOptional`, `getOptional` instead.\n */\nexport class NotFoundError extends OrchidOrmError {\n // `#query` is private to prevent it from serializing to not cause problems to test runner reports\n // it is exposed with `getQuery` method which prevents this problem from both Vitest and Jest.\n // Exposing it with `get query()` still leaves the issue in Vitest.\n readonly #query: Query;\n\n constructor(query: IsQuery, message = 'Record is not found') {\n super(message);\n this.#query = query as Query;\n }\n\n getQuery() {\n return this.#query;\n }\n}\n\nexport class OrchidOrmInternalError extends Error {\n // `#query` is private to prevent it from serializing to not cause problems to test runner reports\n // it is exposed with `getQuery` method which prevents this problem from both Vitest and Jest.\n // Exposing it with `get query()` still leaves the issue in Vitest.\n readonly #query: Query;\n\n constructor(\n query: IsQuery,\n message?: string,\n public data?: RecordUnknown,\n ) {\n super(message);\n this.#query = query as Query;\n }\n\n getQuery() {\n return this.#query;\n }\n}\n\nexport type QueryErrorName =\n | 'parseComplete'\n | 'bindComplete'\n | 'closeComplete'\n | 'noData'\n | 'portalSuspended'\n | 'replicationStart'\n | 'emptyQuery'\n | 'copyDone'\n | 'copyData'\n | 'rowDescription'\n | 'parameterDescription'\n | 'parameterStatus'\n | 'backendKeyData'\n | 'notification'\n | 'readyForQuery'\n | 'commandComplete'\n | 'dataRow'\n | 'copyInResponse'\n | 'copyOutResponse'\n | 'authenticationOk'\n | 'authenticationMD5Password'\n | 'authenticationCleartextPassword'\n | 'authenticationSASL'\n | 'authenticationSASLContinue'\n | 'authenticationSASLFinal'\n | 'error'\n | 'notice';\n\nexport abstract class QueryError<\n T extends PickQueryShape = PickQueryShape,\n> extends OrchidOrmInternalError {\n declare message: string;\n declare length?: number;\n declare name: QueryErrorName;\n declare stack: string | undefined;\n code: string | undefined;\n detail: string | undefined;\n severity: string | undefined;\n hint: string | undefined;\n position: string | undefined;\n internalPosition: string | undefined;\n internalQuery: string | undefined;\n where: string | undefined;\n schema: string | undefined;\n table: string | undefined;\n column: string | undefined;\n dataType: string | undefined;\n constraint: string | undefined;\n file: string | undefined;\n line: string | undefined;\n routine: string | undefined;\n\n get isUnique() {\n return this.code === '23505';\n }\n\n #columnsCache?: { [K in keyof T['shape']]?: true };\n get columns() {\n if (this.#columnsCache) return this.#columnsCache;\n\n const columns: { [K in keyof T['shape']]?: true } = {};\n\n if (this.detail) {\n const list = this.detail.match(/\\((.*)\\)=/)?.[1];\n if (list) {\n list.split(', ').forEach((item) => {\n const column = (\n item.startsWith('\"') ? item.slice(1, -1) : item\n ) as keyof T['shape'];\n\n const key =\n queryColumnNameToKey(this.getQuery(), column as string) ?? column;\n columns[key as keyof T['shape']] = true;\n });\n }\n }\n\n return (this.#columnsCache = columns);\n }\n}\n\nexport class MoreThanOneRowError extends OrchidOrmInternalError {\n constructor(query: IsQuery, message?: string) {\n super(query, message);\n }\n}\n\nexport class UnhandledTypeError extends OrchidOrmInternalError {\n constructor(query: IsQuery, value: never) {\n super(query, `Unhandled type: ${JSON.stringify(value)} received`);\n }\n}\n\n/**\n * Error thrown when attempting to nest SQL session scopes.\n * Nested withOptions/$withOptions calls that supply role or setConfig while an outer\n * scope already has SQL session state defined will throw this error.\n */\nexport class NestedSqlSessionError extends OrchidOrmInternalError {\n constructor(query: IsQuery) {\n super(\n query,\n 'Cannot nest SQL session scopes. Outer scope already has role or setConfig defined.',\n );\n }\n}\n\nexport class CannotMutateReadOnlyTableError extends OrchidOrmInternalError {\n constructor(query: IsQuery) {\n super(query, 'Cannot mutate a readonly table.');\n }\n}\n"],"mappings":";AAKA,IAAsB,iBAAtB,cAA6C,MAAM;AA0BnD,IAAa,yBAAb,cAA4C,MAAM;CAIhD;CAEA,YACE,OACA,SACA,MACA;AACA,QAAM,QAAQ;AAFP,OAAA,OAAA;AAGP,QAAA,QAAc;;CAGhB,WAAW;AACT,SAAO,MAAA;;;AAgHX,IAAa,iCAAb,cAAoD,uBAAuB;CACzE,YAAY,OAAgB;AAC1B,QAAM,OAAO,kCAAkC"}
|