rev-dal 0.0.0-stage → 0.2.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/AGENTS.md +242 -0
- package/CONTRIBUTING.md +83 -0
- package/LICENSE +121 -0
- package/README.md +67 -2
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/clone.d.ts +24 -0
- package/dist/lib/clone.d.ts.map +1 -0
- package/dist/lib/clone.js +83 -0
- package/dist/lib/clone.js.map +1 -0
- package/dist/lib/create-model.d.ts +207 -0
- package/dist/lib/create-model.d.ts.map +1 -0
- package/dist/lib/create-model.js +230 -0
- package/dist/lib/create-model.js.map +1 -0
- package/dist/lib/data-access-layer.d.ts +140 -0
- package/dist/lib/data-access-layer.d.ts.map +1 -0
- package/dist/lib/data-access-layer.js +389 -0
- package/dist/lib/data-access-layer.js.map +1 -0
- package/dist/lib/errors.d.ts +139 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +206 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/filter-where.d.ts +199 -0
- package/dist/lib/filter-where.d.ts.map +1 -0
- package/dist/lib/filter-where.js +563 -0
- package/dist/lib/filter-where.js.map +1 -0
- package/dist/lib/ml-string.d.ts +63 -0
- package/dist/lib/ml-string.d.ts.map +1 -0
- package/dist/lib/ml-string.js +331 -0
- package/dist/lib/ml-string.js.map +1 -0
- package/dist/lib/model-factory.d.ts +25 -0
- package/dist/lib/model-factory.d.ts.map +1 -0
- package/dist/lib/model-factory.js +57 -0
- package/dist/lib/model-factory.js.map +1 -0
- package/dist/lib/model-handle.d.ts +67 -0
- package/dist/lib/model-handle.d.ts.map +1 -0
- package/dist/lib/model-handle.js +182 -0
- package/dist/lib/model-handle.js.map +1 -0
- package/dist/lib/model-initializer.d.ts +96 -0
- package/dist/lib/model-initializer.d.ts.map +1 -0
- package/dist/lib/model-initializer.js +182 -0
- package/dist/lib/model-initializer.js.map +1 -0
- package/dist/lib/model-manifest.d.ts +112 -0
- package/dist/lib/model-manifest.d.ts.map +1 -0
- package/dist/lib/model-manifest.js +2 -0
- package/dist/lib/model-manifest.js.map +1 -0
- package/dist/lib/model-registry.d.ts +81 -0
- package/dist/lib/model-registry.d.ts.map +1 -0
- package/dist/lib/model-registry.js +139 -0
- package/dist/lib/model-registry.js.map +1 -0
- package/dist/lib/model-types.d.ts +380 -0
- package/dist/lib/model-types.d.ts.map +1 -0
- package/dist/lib/model-types.js +2 -0
- package/dist/lib/model-types.js.map +1 -0
- package/dist/lib/model.d.ts +503 -0
- package/dist/lib/model.d.ts.map +1 -0
- package/dist/lib/model.js +1423 -0
- package/dist/lib/model.js.map +1 -0
- package/dist/lib/postgres-config.d.ts +3 -0
- package/dist/lib/postgres-config.d.ts.map +1 -0
- package/dist/lib/postgres-config.js +2 -0
- package/dist/lib/postgres-config.js.map +1 -0
- package/dist/lib/query-builder.d.ts +607 -0
- package/dist/lib/query-builder.d.ts.map +1 -0
- package/dist/lib/query-builder.js +1734 -0
- package/dist/lib/query-builder.js.map +1 -0
- package/dist/lib/revision.d.ts +55 -0
- package/dist/lib/revision.d.ts.map +1 -0
- package/dist/lib/revision.js +307 -0
- package/dist/lib/revision.js.map +1 -0
- package/dist/lib/runtime.d.ts +18 -0
- package/dist/lib/runtime.d.ts.map +1 -0
- package/dist/lib/runtime.js +134 -0
- package/dist/lib/runtime.js.map +1 -0
- package/dist/lib/transaction.d.ts +17 -0
- package/dist/lib/transaction.d.ts.map +1 -0
- package/dist/lib/transaction.js +30 -0
- package/dist/lib/transaction.js.map +1 -0
- package/dist/lib/type.d.ts +130 -0
- package/dist/lib/type.d.ts.map +1 -0
- package/dist/lib/type.js +376 -0
- package/dist/lib/type.js.map +1 -0
- package/docs/models.md +406 -0
- package/docs/multilingual-text.md +142 -0
- package/docs/queries.md +374 -0
- package/docs/revisions.md +61 -0
- package/package.json +60 -4
- package/releases/0.2.0.md +18 -0
- package/releases/0.2.1.md +22 -0
- package/releases/0.2.2.md +11 -0
- package/releases/README.md +7 -0
- package/setup-db-grants.sql +51 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes for the PostgreSQL DAL
|
|
3
|
+
*
|
|
4
|
+
* Provides custom error types for database operations.
|
|
5
|
+
*/
|
|
6
|
+
export interface PostgresError extends Error {
|
|
7
|
+
code?: string;
|
|
8
|
+
detail?: string;
|
|
9
|
+
constraint?: string;
|
|
10
|
+
column?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Base DAL error class
|
|
14
|
+
*/
|
|
15
|
+
export declare class DALError extends Error {
|
|
16
|
+
code: string | null;
|
|
17
|
+
constructor(message: string, code?: string | null);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Document not found error
|
|
21
|
+
*/
|
|
22
|
+
export declare class DocumentNotFound extends DALError {
|
|
23
|
+
constructor(message?: string);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Invalid UUID error - for malformed UUID strings
|
|
27
|
+
*/
|
|
28
|
+
export declare class InvalidUUIDError extends DALError {
|
|
29
|
+
constructor(message?: string);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validation error
|
|
33
|
+
*/
|
|
34
|
+
export declare class ValidationError extends DALError {
|
|
35
|
+
field: string | null;
|
|
36
|
+
constructor(message: string, field?: string | null);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Connection error
|
|
40
|
+
*/
|
|
41
|
+
export declare class ConnectionError extends DALError {
|
|
42
|
+
constructor(message?: string);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Transaction error
|
|
46
|
+
*/
|
|
47
|
+
export declare class TransactionError extends DALError {
|
|
48
|
+
constructor(message?: string);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Query error
|
|
52
|
+
*/
|
|
53
|
+
export declare class QueryError extends DALError {
|
|
54
|
+
originalError: unknown;
|
|
55
|
+
constructor(message: string, originalError?: unknown);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Constraint violation error
|
|
59
|
+
*/
|
|
60
|
+
export declare class ConstraintError extends DALError {
|
|
61
|
+
constraint: string | null;
|
|
62
|
+
constructor(message: string, constraint?: string | null);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Revision deleted error
|
|
66
|
+
*
|
|
67
|
+
* Thrown when a requested document has been deleted (see `deleteAllRevisions`).
|
|
68
|
+
*/
|
|
69
|
+
export declare class RevisionDeletedError extends DALError {
|
|
70
|
+
constructor(message?: string);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Revision stale error
|
|
74
|
+
*
|
|
75
|
+
* Thrown when a requested ID refers to an archived (outdated) revision rather
|
|
76
|
+
* than the current one.
|
|
77
|
+
*/
|
|
78
|
+
export declare class RevisionStaleError extends DALError {
|
|
79
|
+
constructor(message?: string);
|
|
80
|
+
}
|
|
81
|
+
export interface RevisionConflictDetails {
|
|
82
|
+
documentId: string | null;
|
|
83
|
+
expectedRevId: string | null;
|
|
84
|
+
currentRevId: string | null;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Revision conflict error
|
|
88
|
+
*
|
|
89
|
+
* Thrown when saving a new revision of a document whose stored revision is no
|
|
90
|
+
* longer the one this copy was loaded from, i.e. someone else saved a revision
|
|
91
|
+
* in the meantime. Nothing is written. Callers decide how to resolve it: show
|
|
92
|
+
* an edit-conflict view, or reload the document and reapply the change.
|
|
93
|
+
*/
|
|
94
|
+
export declare class RevisionConflictError extends DALError {
|
|
95
|
+
documentId: string | null;
|
|
96
|
+
expectedRevId: string | null;
|
|
97
|
+
currentRevId: string | null;
|
|
98
|
+
constructor(message: string, details: RevisionConflictDetails);
|
|
99
|
+
}
|
|
100
|
+
export interface DuplicateSlugPayload {
|
|
101
|
+
slug: {
|
|
102
|
+
name: string | null;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Duplicate slug name error
|
|
107
|
+
*
|
|
108
|
+
* Business logic error thrown when attempting to save a slug that already exists.
|
|
109
|
+
* This abstracts away the database-specific ConstraintError to provide a semantic
|
|
110
|
+
* error that application code can handle without knowing about constraint names.
|
|
111
|
+
*/
|
|
112
|
+
export declare class DuplicateSlugNameError extends DALError {
|
|
113
|
+
payload: DuplicateSlugPayload;
|
|
114
|
+
tableName: string | null;
|
|
115
|
+
constructor(message: string, slugName?: string | null, tableName?: string | null);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Convert PostgreSQL errors to DAL errors
|
|
119
|
+
* @param pgError - PostgreSQL error
|
|
120
|
+
* @returns Converted DAL error
|
|
121
|
+
*/
|
|
122
|
+
export declare function convertPostgreSQLError(pgError: unknown): DALError;
|
|
123
|
+
declare const errors: {
|
|
124
|
+
readonly DALError: typeof DALError;
|
|
125
|
+
readonly DocumentNotFound: typeof DocumentNotFound;
|
|
126
|
+
readonly InvalidUUIDError: typeof InvalidUUIDError;
|
|
127
|
+
readonly ValidationError: typeof ValidationError;
|
|
128
|
+
readonly ConnectionError: typeof ConnectionError;
|
|
129
|
+
readonly TransactionError: typeof TransactionError;
|
|
130
|
+
readonly QueryError: typeof QueryError;
|
|
131
|
+
readonly ConstraintError: typeof ConstraintError;
|
|
132
|
+
readonly RevisionDeletedError: typeof RevisionDeletedError;
|
|
133
|
+
readonly RevisionStaleError: typeof RevisionStaleError;
|
|
134
|
+
readonly RevisionConflictError: typeof RevisionConflictError;
|
|
135
|
+
readonly DuplicateSlugNameError: typeof DuplicateSlugNameError;
|
|
136
|
+
readonly convertPostgreSQLError: typeof convertPostgreSQLError;
|
|
137
|
+
};
|
|
138
|
+
export default errors;
|
|
139
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src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AAmB,SAAQ,QAAQ;gBAClC,OAAO,SAAuB;CAI3C;AAED,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;;;;;;GAOG;AACH,qBAAa,qBAAsB,SAAQ,QAAQ;IACjD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEhB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB;CAO9D;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;KACrB,CAAC;CACH;AAED;;;;;;GAMG;AACH,qBAAa,sBAAuB,SAAQ,QAAQ;IAClD,OAAO,EAAE,oBAAoB,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,GAAG,IAAW,EAAE,SAAS,GAAE,MAAM,GAAG,IAAW;CAU7F;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ,CAqDjE;AAED,QAAA,MAAM,MAAM;;;;;;;;;;;;;;CAcF,CAAC;AAEX,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes for the PostgreSQL DAL
|
|
3
|
+
*
|
|
4
|
+
* Provides custom error types for database operations.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Base DAL error class
|
|
8
|
+
*/
|
|
9
|
+
export class DALError extends Error {
|
|
10
|
+
code;
|
|
11
|
+
constructor(message, code = null) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = new.target.name;
|
|
14
|
+
this.code = code;
|
|
15
|
+
if (typeof Error.captureStackTrace === 'function') {
|
|
16
|
+
Error.captureStackTrace(this, new.target);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Document not found error
|
|
22
|
+
*/
|
|
23
|
+
export class DocumentNotFound extends DALError {
|
|
24
|
+
constructor(message = 'Document not found') {
|
|
25
|
+
super(message, 'DOCUMENT_NOT_FOUND');
|
|
26
|
+
this.name = 'DocumentNotFound';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Invalid UUID error - for malformed UUID strings
|
|
31
|
+
*/
|
|
32
|
+
export class InvalidUUIDError extends DALError {
|
|
33
|
+
constructor(message = 'Invalid UUID format') {
|
|
34
|
+
super(message, 'INVALID_UUID');
|
|
35
|
+
this.name = 'InvalidUUIDError';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Validation error
|
|
40
|
+
*/
|
|
41
|
+
export class ValidationError extends DALError {
|
|
42
|
+
field;
|
|
43
|
+
constructor(message, field = null) {
|
|
44
|
+
super(message, 'VALIDATION_ERROR');
|
|
45
|
+
this.name = 'ValidationError';
|
|
46
|
+
this.field = field;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Connection error
|
|
51
|
+
*/
|
|
52
|
+
export class ConnectionError extends DALError {
|
|
53
|
+
constructor(message = 'Database connection error') {
|
|
54
|
+
super(message, 'CONNECTION_ERROR');
|
|
55
|
+
this.name = 'ConnectionError';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Transaction error
|
|
60
|
+
*/
|
|
61
|
+
export class TransactionError extends DALError {
|
|
62
|
+
constructor(message = 'Transaction error') {
|
|
63
|
+
super(message, 'TRANSACTION_ERROR');
|
|
64
|
+
this.name = 'TransactionError';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Query error
|
|
69
|
+
*/
|
|
70
|
+
export class QueryError extends DALError {
|
|
71
|
+
originalError;
|
|
72
|
+
constructor(message, originalError = null) {
|
|
73
|
+
super(message, 'QUERY_ERROR');
|
|
74
|
+
this.name = 'QueryError';
|
|
75
|
+
this.originalError = originalError;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Constraint violation error
|
|
80
|
+
*/
|
|
81
|
+
export class ConstraintError extends DALError {
|
|
82
|
+
constraint;
|
|
83
|
+
constructor(message, constraint = null) {
|
|
84
|
+
super(message, 'CONSTRAINT_ERROR');
|
|
85
|
+
this.name = 'ConstraintError';
|
|
86
|
+
this.constraint = constraint;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Revision deleted error
|
|
91
|
+
*
|
|
92
|
+
* Thrown when a requested document has been deleted (see `deleteAllRevisions`).
|
|
93
|
+
*/
|
|
94
|
+
export class RevisionDeletedError extends DALError {
|
|
95
|
+
constructor(message = 'Revision has been deleted.') {
|
|
96
|
+
super(message, 'REVISION_DELETED');
|
|
97
|
+
this.name = 'RevisionDeletedError';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Revision stale error
|
|
102
|
+
*
|
|
103
|
+
* Thrown when a requested ID refers to an archived (outdated) revision rather
|
|
104
|
+
* than the current one.
|
|
105
|
+
*/
|
|
106
|
+
export class RevisionStaleError extends DALError {
|
|
107
|
+
constructor(message = 'Outdated revision.') {
|
|
108
|
+
super(message, 'REVISION_STALE');
|
|
109
|
+
this.name = 'RevisionStaleError';
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Revision conflict error
|
|
114
|
+
*
|
|
115
|
+
* Thrown when saving a new revision of a document whose stored revision is no
|
|
116
|
+
* longer the one this copy was loaded from, i.e. someone else saved a revision
|
|
117
|
+
* in the meantime. Nothing is written. Callers decide how to resolve it: show
|
|
118
|
+
* an edit-conflict view, or reload the document and reapply the change.
|
|
119
|
+
*/
|
|
120
|
+
export class RevisionConflictError extends DALError {
|
|
121
|
+
documentId;
|
|
122
|
+
expectedRevId;
|
|
123
|
+
currentRevId;
|
|
124
|
+
constructor(message, details) {
|
|
125
|
+
super(message, 'REVISION_CONFLICT');
|
|
126
|
+
this.name = 'RevisionConflictError';
|
|
127
|
+
this.documentId = details.documentId;
|
|
128
|
+
this.expectedRevId = details.expectedRevId;
|
|
129
|
+
this.currentRevId = details.currentRevId;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Duplicate slug name error
|
|
134
|
+
*
|
|
135
|
+
* Business logic error thrown when attempting to save a slug that already exists.
|
|
136
|
+
* This abstracts away the database-specific ConstraintError to provide a semantic
|
|
137
|
+
* error that application code can handle without knowing about constraint names.
|
|
138
|
+
*/
|
|
139
|
+
export class DuplicateSlugNameError extends DALError {
|
|
140
|
+
payload;
|
|
141
|
+
tableName;
|
|
142
|
+
constructor(message, slugName = null, tableName = null) {
|
|
143
|
+
super(message, 'DUPLICATE_SLUG');
|
|
144
|
+
this.name = 'DuplicateSlugNameError';
|
|
145
|
+
this.payload = {
|
|
146
|
+
slug: {
|
|
147
|
+
name: slugName,
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
this.tableName = tableName;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Convert PostgreSQL errors to DAL errors
|
|
155
|
+
* @param pgError - PostgreSQL error
|
|
156
|
+
* @returns Converted DAL error
|
|
157
|
+
*/
|
|
158
|
+
export function convertPostgreSQLError(pgError) {
|
|
159
|
+
if (pgError instanceof DALError) {
|
|
160
|
+
return pgError;
|
|
161
|
+
}
|
|
162
|
+
if (!pgError || typeof pgError !== 'object') {
|
|
163
|
+
return new DALError('Unknown error');
|
|
164
|
+
}
|
|
165
|
+
const error = pgError;
|
|
166
|
+
const message = typeof error.message === 'string' ? error.message : 'Unknown error';
|
|
167
|
+
// PostgreSQL error codes: https://www.postgresql.org/docs/current/errcodes-appendix.html
|
|
168
|
+
switch (error.code) {
|
|
169
|
+
case '23505': // unique_violation
|
|
170
|
+
return new ConstraintError(`Unique constraint violation: ${error.detail ?? message}`, error.constraint ?? null);
|
|
171
|
+
case '23503': // foreign_key_violation
|
|
172
|
+
return new ConstraintError(`Foreign key constraint violation: ${error.detail ?? message}`, error.constraint ?? null);
|
|
173
|
+
case '23502': // not_null_violation
|
|
174
|
+
return new ValidationError(`Not null constraint violation: ${error.column ?? message}`, error.column ?? null);
|
|
175
|
+
case '23514': // check_violation
|
|
176
|
+
return new ValidationError(`Check constraint violation: ${error.detail ?? message}`, error.constraint ?? null);
|
|
177
|
+
case '08000': // connection_exception
|
|
178
|
+
case '08003': // connection_does_not_exist
|
|
179
|
+
case '08006': // connection_failure
|
|
180
|
+
return new ConnectionError(message);
|
|
181
|
+
case '42P01': // undefined_table
|
|
182
|
+
return new QueryError(`Table does not exist: ${message}`, error);
|
|
183
|
+
case '42703': // undefined_column
|
|
184
|
+
return new QueryError(`Column does not exist: ${message}`, error);
|
|
185
|
+
default:
|
|
186
|
+
// For unknown errors, wrap in a generic QueryError
|
|
187
|
+
return new QueryError(message, error);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const errors = {
|
|
191
|
+
DALError,
|
|
192
|
+
DocumentNotFound,
|
|
193
|
+
InvalidUUIDError,
|
|
194
|
+
ValidationError,
|
|
195
|
+
ConnectionError,
|
|
196
|
+
TransactionError,
|
|
197
|
+
QueryError,
|
|
198
|
+
ConstraintError,
|
|
199
|
+
RevisionDeletedError,
|
|
200
|
+
RevisionStaleError,
|
|
201
|
+
RevisionConflictError,
|
|
202
|
+
DuplicateSlugNameError,
|
|
203
|
+
convertPostgreSQLError,
|
|
204
|
+
};
|
|
205
|
+
export default errors;
|
|
206
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|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G;IACb,QAAQ;IACR,gBAAgB;IAChB,gBAAgB;IAChB,eAAe;IACf,eAAe;IACf,gBAAgB;IAChB,UAAU;IACV,eAAe;IACf,oBAAoB;IACpB,kBAAkB;IAClB,qBAAqB;IACrB,sBAAsB;IACtB,sBAAsB;CACd,CAAC;AAEX,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import type { ModelRuntime } from './model.js';
|
|
2
|
+
import type { InferData, InferInstance, ModelManifest } from './model-manifest.js';
|
|
3
|
+
import type { ChronologicalFeedOptions, ChronologicalFeedPage, DateKeys, DeleteOptions, FilterWhereJoinSpec, FilterWhereLiteral, FilterWhereOperators, FilterWhereQueryBuilder, JsonObject, ModelConstructor, ModelInstance, NumericKeys, ProjectedQuery, RevisionDataRecord, SelectableData } from './model-types.js';
|
|
4
|
+
import QueryBuilder from './query-builder.js';
|
|
5
|
+
/**
|
|
6
|
+
* Shared implementation for the typed {@link ModelConstructor.filterWhere} surface.
|
|
7
|
+
*
|
|
8
|
+
* Every manifest-driven model mixes in the helpers defined here so calling
|
|
9
|
+
* `Model.filterWhere({ ... })` yields a typed builder with revision-aware
|
|
10
|
+
* defaults and a small bag of operator helpers (`Model.ops`).
|
|
11
|
+
*
|
|
12
|
+
* ⚠️ Helpers must be invoked inline where the target field is known:
|
|
13
|
+
* destructuring `const { neq } = Thing.ops` is fine, but avoid caching helper
|
|
14
|
+
* *results* (for example `const isBlocked = neq(id)`). Once detached from the
|
|
15
|
+
* literal, TypeScript can no longer narrow the operator to a specific field,
|
|
16
|
+
* so it will compile even if you later attach it to the wrong column.
|
|
17
|
+
*/
|
|
18
|
+
declare const FILTER_OPERATOR_TOKEN: unique symbol;
|
|
19
|
+
type Predicate = QueryBuilder['_where'][number];
|
|
20
|
+
type OperatorBuilderContext = {
|
|
21
|
+
builder: QueryBuilder;
|
|
22
|
+
field: string | number | symbol;
|
|
23
|
+
mutate: boolean;
|
|
24
|
+
};
|
|
25
|
+
interface InternalFilterOperator<K extends PropertyKey, TValue> {
|
|
26
|
+
readonly [FILTER_OPERATOR_TOKEN]: true;
|
|
27
|
+
readonly __allowedKeys: K;
|
|
28
|
+
readonly value: TValue;
|
|
29
|
+
build(context: OperatorBuilderContext): Predicate | null;
|
|
30
|
+
}
|
|
31
|
+
type RevisionLiteral = FilterWhereLiteral<RevisionDataRecord, FilterWhereOperators<RevisionDataRecord>>;
|
|
32
|
+
/**
|
|
33
|
+
* Generates the operator helper bag exposed via `Model.ops`. The helpers are
|
|
34
|
+
* intentionally minimal for now: `neq` works on any field, `containsAll`
|
|
35
|
+
* targets string-array-backed columns for “must include every element”, and
|
|
36
|
+
* `containsAny` uses the overlap operator until we add richer casts.
|
|
37
|
+
*/
|
|
38
|
+
declare function createOperators<TRecord extends JsonObject>(): FilterWhereOperators<TRecord>;
|
|
39
|
+
/**
|
|
40
|
+
* Typed facade around the legacy `QueryBuilder`. It injects default
|
|
41
|
+
* revision-aware predicates, exposes the fluent DAL surface, and keeps the
|
|
42
|
+
* `PromiseLike` contract so `await Model.filterWhere(...)` call sites work
|
|
43
|
+
* without forcing `.run()`.
|
|
44
|
+
*/
|
|
45
|
+
declare class FilterWhereBuilder<TData extends JsonObject, TVirtual extends JsonObject, TInstance extends ModelInstance<TData, TVirtual>, TRelations extends string> implements FilterWhereQueryBuilder<TData, TVirtual, TInstance, TRelations> {
|
|
46
|
+
private readonly _builder;
|
|
47
|
+
private readonly _hasRevisions;
|
|
48
|
+
private _includeDeleted;
|
|
49
|
+
private _includeStale;
|
|
50
|
+
private _revisionFiltersApplied;
|
|
51
|
+
constructor(builder: QueryBuilder<TData, TVirtual, TInstance, TRelations>, hasRevisions: boolean);
|
|
52
|
+
private _ensureRevisionFilters;
|
|
53
|
+
private _createFieldPredicate;
|
|
54
|
+
private _applyLiteral;
|
|
55
|
+
private _createRevisionFieldPredicate;
|
|
56
|
+
and(literal: FilterWhereLiteral<TData, FilterWhereOperators<TData>>): this;
|
|
57
|
+
or(literal: FilterWhereLiteral<TData, FilterWhereOperators<TData>>): this;
|
|
58
|
+
includeDeleted(): this;
|
|
59
|
+
includeStale(): this;
|
|
60
|
+
includeSensitive(fields: string | string[]): this;
|
|
61
|
+
select<const Fields extends readonly [
|
|
62
|
+
Extract<keyof SelectableData<TData, TInstance>, string>,
|
|
63
|
+
...Extract<keyof SelectableData<TData, TInstance>, string>[]
|
|
64
|
+
]>(...fields: Fields): ProjectedQuery<Pick<SelectableData<TData, TInstance>, Fields[number]>>;
|
|
65
|
+
/**
|
|
66
|
+
* Get all revisions of a document (current + archived) ordered by revision date.
|
|
67
|
+
*
|
|
68
|
+
* This bypasses standard revision filtering to include stale and deleted revisions.
|
|
69
|
+
*
|
|
70
|
+
* @param documentId The document ID to retrieve revisions for
|
|
71
|
+
*/
|
|
72
|
+
getAllRevisions(documentId: string): this;
|
|
73
|
+
/**
|
|
74
|
+
* Find a specific revision by its revision ID within a document's history.
|
|
75
|
+
*
|
|
76
|
+
* @param revId The revision ID to find
|
|
77
|
+
* @param documentId The document ID the revision belongs to
|
|
78
|
+
*/
|
|
79
|
+
getRevisionByRevId(revId: string, documentId: string): this;
|
|
80
|
+
revisionData(literal: RevisionLiteral): this;
|
|
81
|
+
/**
|
|
82
|
+
* Order results by a model column.
|
|
83
|
+
*
|
|
84
|
+
* @param field Field to sort by (camelCase or qualified string)
|
|
85
|
+
* @param direction Sort direction
|
|
86
|
+
*/
|
|
87
|
+
orderBy(field: Extract<keyof TData, string> | string, direction?: 'ASC' | 'DESC'): this;
|
|
88
|
+
/**
|
|
89
|
+
* Order results using a column on a joined relation (through metadata).
|
|
90
|
+
*
|
|
91
|
+
* @param relation Relation key from the manifest
|
|
92
|
+
* @param field Column on the related table (camelCase)
|
|
93
|
+
* @param direction Sort direction
|
|
94
|
+
*/
|
|
95
|
+
orderByRelation(relation: TRelations, field: string, direction?: 'ASC' | 'DESC'): this;
|
|
96
|
+
limit(count: number): this;
|
|
97
|
+
sample(count?: number): Promise<TInstance[]>;
|
|
98
|
+
offset(count: number): this;
|
|
99
|
+
/**
|
|
100
|
+
* Run a chronological feed query against a date-backed field using limit+1 cursor pagination.
|
|
101
|
+
*
|
|
102
|
+
* @param options Cursor pagination options.
|
|
103
|
+
*/
|
|
104
|
+
chronologicalFeed<K extends Extract<DateKeys<TData>, string>>(options: ChronologicalFeedOptions<TData, K>): Promise<ChronologicalFeedPage<NonNullable<TData[K]>, TInstance>>;
|
|
105
|
+
getJoin(joinSpec: FilterWhereJoinSpec<TRelations>): this;
|
|
106
|
+
whereIn(field: Extract<keyof TData, string>, values: unknown[], options?: {
|
|
107
|
+
cast?: string;
|
|
108
|
+
}): this;
|
|
109
|
+
whereRelated(relation: TRelations, field: string, value: unknown, operator?: string): this;
|
|
110
|
+
run(): Promise<TInstance[]>;
|
|
111
|
+
first(): Promise<TInstance | null>;
|
|
112
|
+
count(): Promise<number>;
|
|
113
|
+
average(field: Extract<keyof TData, string>): Promise<number | null>;
|
|
114
|
+
groupBy(fields: string | string[]): this;
|
|
115
|
+
aggregateGrouped(func: 'COUNT' | 'AVG' | 'SUM' | 'MIN' | 'MAX', options?: {
|
|
116
|
+
aggregateField?: string;
|
|
117
|
+
}): Promise<Map<string, number>>;
|
|
118
|
+
/**
|
|
119
|
+
* Atomically increment a numeric column scoped by the current predicates.
|
|
120
|
+
*
|
|
121
|
+
* @param field Numeric model field to increment
|
|
122
|
+
* @param options Configure the increment step and returned columns
|
|
123
|
+
*/
|
|
124
|
+
increment<K extends Extract<NumericKeys<TData>, string>, R extends Extract<keyof TData, string> = K>(field: K, options?: {
|
|
125
|
+
by?: number;
|
|
126
|
+
returning?: R[];
|
|
127
|
+
}): Promise<{
|
|
128
|
+
rowCount: number;
|
|
129
|
+
rows: Array<Pick<TData, R>>;
|
|
130
|
+
}>;
|
|
131
|
+
/**
|
|
132
|
+
* Atomically decrement a numeric column scoped by the current predicates.
|
|
133
|
+
*
|
|
134
|
+
* @param field Numeric model field to decrement
|
|
135
|
+
* @param options Configure the decrement step and returned columns
|
|
136
|
+
*/
|
|
137
|
+
decrement<K extends Extract<NumericKeys<TData>, string>, R extends Extract<keyof TData, string> = K>(field: K, options?: {
|
|
138
|
+
by?: number;
|
|
139
|
+
returning?: R[];
|
|
140
|
+
}): Promise<{
|
|
141
|
+
rowCount: number;
|
|
142
|
+
rows: Array<Pick<TData, R>>;
|
|
143
|
+
}>;
|
|
144
|
+
/**
|
|
145
|
+
* Delete rows matching the current predicates. Models with revision tracking
|
|
146
|
+
* require `{ purge: true }`, which also removes the matched documents'
|
|
147
|
+
* archived revisions; use `deleteAllRevisions(user)` to soft-delete instead.
|
|
148
|
+
*
|
|
149
|
+
* @param options Delete options
|
|
150
|
+
*/
|
|
151
|
+
delete(options?: DeleteOptions): Promise<number>;
|
|
152
|
+
/**
|
|
153
|
+
* Delete the row with the given ID, provided it also matches the current
|
|
154
|
+
* predicates. Same revision rules as {@link FilterWhereBuilder.delete}.
|
|
155
|
+
*
|
|
156
|
+
* @param id Record ID
|
|
157
|
+
* @param options Delete options
|
|
158
|
+
*/
|
|
159
|
+
deleteById(id: string, options?: DeleteOptions): Promise<number>;
|
|
160
|
+
then<TResult1 = TInstance[], TResult2 = never>(onFulfilled?: ((value: TInstance[]) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
161
|
+
catch<TResult = never>(onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<TInstance[] | TResult>;
|
|
162
|
+
finally(onFinally?: (() => void) | null): Promise<TInstance[]>;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Produces the concrete `filterWhere` static bound to a manifest-derived
|
|
166
|
+
* constructor. This stays lightweight so every model gets the same behaviour
|
|
167
|
+
* without bespoke wiring inside the manifest definition itself.
|
|
168
|
+
*
|
|
169
|
+
* @param hasRevisions - Whether the model uses revision tracking
|
|
170
|
+
* @returns A filterWhere method bound to the model type
|
|
171
|
+
*/
|
|
172
|
+
declare function createFilterWhereMethod<TData extends JsonObject, TVirtual extends JsonObject, TInstance extends ModelInstance<TData, TVirtual>, TRelations extends string>(hasRevisions: boolean): (this: ModelConstructor<TData, TVirtual, TInstance, TRelations> & ModelRuntime<TData, TVirtual>, literal: FilterWhereLiteral<TData, FilterWhereOperators<TData>>) => FilterWhereBuilder<TData, TVirtual, TInstance, TRelations>;
|
|
173
|
+
type RelationNames<Manifest extends ModelManifest> = Manifest['relations'] extends readonly (infer Relations)[] ? Relations extends {
|
|
174
|
+
name: infer Name;
|
|
175
|
+
} ? Name extends string ? Name : never : never : never;
|
|
176
|
+
/**
|
|
177
|
+
* Helper consumed by `createModel` so all manifest-based models expose the new
|
|
178
|
+
* statics even before the DAL bootstrap finishes initializing the underlying
|
|
179
|
+
* constructors.
|
|
180
|
+
*
|
|
181
|
+
* @param _manifest - Manifest describing the model being registered
|
|
182
|
+
* @returns Static methods object with filterWhere and ops
|
|
183
|
+
*/
|
|
184
|
+
declare function createFilterWhereStatics<Manifest extends ModelManifest>(_manifest: Manifest): {
|
|
185
|
+
readonly ops: FilterWhereOperators<InferData<Manifest["schema"]>>;
|
|
186
|
+
readonly filterWhere: (this: ModelConstructor<InferData<Manifest["schema"]>, import("./model-manifest.js").InferVirtual<Manifest["schema"]>, InferInstance<Manifest>, RelationNames<Manifest>> & ModelConstructor<InferData<Manifest["schema"]>, import("./model-manifest.js").InferVirtual<Manifest["schema"]>, ModelInstance<InferData<Manifest["schema"]>, import("./model-manifest.js").InferVirtual<Manifest["schema"]>>, string> & typeof import("./model.js").Model & {
|
|
187
|
+
schema: import("./model.js").ModelSchema<TData, TVirtual>;
|
|
188
|
+
tableName: string;
|
|
189
|
+
options?: JsonObject;
|
|
190
|
+
dal: import("./model-types.js").DataAccessLayer;
|
|
191
|
+
_fieldMappings: Map<string, string>;
|
|
192
|
+
_relations: Map<string, import("./model.js").NormalizedRelationConfig>;
|
|
193
|
+
_views: Map<string, import("./model-types.js").ModelViewDefinition<ModelInstance<JsonObject, JsonObject>, JsonObject>>;
|
|
194
|
+
_revisionHandlers?: Partial<Record<"newRevision" | "deleteAllRevisions", (this: import("./model.js").Model<InferData<Manifest["schema"]>, import("./model-manifest.js").InferVirtual<Manifest["schema"]>>, ...args: unknown[]) => unknown>> | undefined;
|
|
195
|
+
}, literal: Partial<InferData<Manifest["schema"]> extends infer T extends JsonObject ? { [K in keyof T]: T[K] | { [P in keyof TOps]: TOps[P] extends (...args: unknown[]) => import("./model-types.js").FilterWhereOperator<infer Keys, infer TValue> ? K extends Keys ? import("./model-types.js").FilterWhereOperator<K, TValue> : never : never; }[keyof TOps]; } : never>) => FilterWhereBuilder<InferData<Manifest["schema"]>, import("./model-manifest.js").InferVirtual<Manifest["schema"]>, InferInstance<Manifest>, RelationNames<Manifest>>;
|
|
196
|
+
};
|
|
197
|
+
export { FILTER_OPERATOR_TOKEN, FilterWhereBuilder, createFilterWhereStatics, createOperators, createFilterWhereMethod, };
|
|
198
|
+
export type { InternalFilterOperator };
|
|
199
|
+
//# sourceMappingURL=filter-where.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-where.d.ts","sourceRoot":"","sources":["../../src/lib/filter-where.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAEb,aAAa,EACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,wBAAwB,EACxB,qBAAqB,EACrB,QAAQ,EACR,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,cAAc,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,YAAwC,MAAM,oBAAoB,CAAC;AAE1E;;;;;;;;;;;;GAYG;AAEH,QAA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