@@ -19,7 +19,7 @@ import {
1919} from '#/src/utils.js'
2020import { type SortOptions , sortResults } from '#/src/sort.js'
2121import type { Extension } from '#/src/extensions/index.js'
22- import { OperationError , StrictOperationError } from '#/src/errors.js'
22+ import { OperationError , OperationErrorCodes } from '#/src/errors.js'
2323import { TypedEvent , type Emitter } from 'rettime'
2424
2525let collectionsCreated = 0
@@ -131,16 +131,16 @@ export class Collection<Schema extends StandardSchemaV1> {
131131
132132 if ( validationResult . issues ) {
133133 console . error ( validationResult . issues )
134- throw new InvariantError (
135- 'Failed to create a new record with initial values (%j): does not match the schema' ,
136- initialValues ,
134+ throw new OperationError (
135+ 'Failed to create a new record with initial values (%j): does not match the schema. Please see the schema validation errors above. ' ,
136+ OperationErrorCodes . INVALID_INITIAL_VALUES ,
137137 )
138138 }
139139
140140 let record = validationResult . value as RecordType
141141
142142 invariant . as (
143- OperationError . for ( 'create' , { initialValues } ) ,
143+ OperationError . for ( OperationErrorCodes . INVALID_INITIAL_VALUES ) ,
144144 typeof record === 'object' ,
145145 'Failed to create a record with initial values (%j): expected the record to be an object or an array' ,
146146 initialValues ,
@@ -207,8 +207,7 @@ export class Collection<Schema extends StandardSchemaV1> {
207207 return await Promise . all ( pendingPromises ) . catch ( ( error ) => {
208208 throw new OperationError (
209209 'Failed to execute "createMany" on collection: unexpected error' ,
210- 'createMany' ,
211- { count, initialValuesFactory } ,
210+ OperationErrorCodes . UNEXPECTED_ERROR ,
212211 error ,
213212 )
214213 } )
@@ -232,7 +231,7 @@ export class Collection<Schema extends StandardSchemaV1> {
232231 const firstRecord = this . #records[ 0 ]
233232
234233 invariant . as (
235- StrictOperationError . for ( 'findFirst' , { predicate , options } ) ,
234+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
236235 options ?. strict ? firstRecord != null : true ,
237236 'Failed to execute "findFirst" on collection without a query: the collection is empty' ,
238237 )
@@ -245,7 +244,7 @@ export class Collection<Schema extends StandardSchemaV1> {
245244 ) . next ( ) . value
246245
247246 invariant . as (
248- StrictOperationError . for ( 'findFirst' , { predicate , options } ) ,
247+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
249248 options ?. strict ? result != null : true ,
250249 'Failed to execute "findFirst" on collection: no record found matching the query' ,
251250 )
@@ -277,7 +276,7 @@ export class Collection<Schema extends StandardSchemaV1> {
277276 )
278277
279278 invariant . as (
280- StrictOperationError . for ( 'findMany' , { predicate , options } ) ,
279+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
281280 options ?. strict ? results . length > 0 : true ,
282281 'Failed to execute "findMany" on collection: no records found matching the query' ,
283282 )
@@ -324,7 +323,7 @@ export class Collection<Schema extends StandardSchemaV1> {
324323
325324 if ( prevRecord == null ) {
326325 invariant . as (
327- StrictOperationError . for ( 'update' , { predicate , options } ) ,
326+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
328327 ! options . strict ,
329328 'Failed to execute "update" on collection: no record found matching the query' ,
330329 )
@@ -363,7 +362,7 @@ export class Collection<Schema extends StandardSchemaV1> {
363362
364363 if ( prevRecords . length === 0 ) {
365364 invariant . as (
366- StrictOperationError . for ( 'updateMany' , { predicate , options } ) ,
365+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
367366 ! options . strict ,
368367 'Failed to execute "updateMany" on collection: no records found matching the query' ,
369368 )
@@ -409,7 +408,7 @@ export class Collection<Schema extends StandardSchemaV1> {
409408
410409 if ( record == null ) {
411410 invariant . as (
412- StrictOperationError . for ( 'delete' , { predicate , options } ) ,
411+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
413412 ! options ?. strict ,
414413 'Failed to execute "delete" on collection: no record found matching the query' ,
415414 )
@@ -445,7 +444,7 @@ export class Collection<Schema extends StandardSchemaV1> {
445444
446445 if ( records . length === 0 ) {
447446 invariant . as (
448- StrictOperationError . for ( 'deleteMany' , { predicate , options } ) ,
447+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
449448 ! options ?. strict ,
450449 'Failed to execute "deleteMany" on collection: no records found matching the query' ,
451450 )
0 commit comments