@@ -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,17 @@ 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+
135+ throw new OperationError (
136+ 'Failed to create a new record with initial values: does not match the schema. Please see the schema validation errors above.' ,
137+ OperationErrorCodes . INVALID_INITIAL_VALUES ,
137138 )
138139 }
139140
140141 let record = validationResult . value as RecordType
141142
142143 invariant . as (
143- OperationError . for ( 'create' , { initialValues } ) ,
144+ OperationError . for ( OperationErrorCodes . INVALID_INITIAL_VALUES ) ,
144145 typeof record === 'object' ,
145146 'Failed to create a record with initial values (%j): expected the record to be an object or an array' ,
146147 initialValues ,
@@ -207,8 +208,7 @@ export class Collection<Schema extends StandardSchemaV1> {
207208 return await Promise . all ( pendingPromises ) . catch ( ( error ) => {
208209 throw new OperationError (
209210 'Failed to execute "createMany" on collection: unexpected error' ,
210- 'createMany' ,
211- { count, initialValuesFactory } ,
211+ OperationErrorCodes . UNEXPECTED_ERROR ,
212212 error ,
213213 )
214214 } )
@@ -232,7 +232,7 @@ export class Collection<Schema extends StandardSchemaV1> {
232232 const firstRecord = this . #records[ 0 ]
233233
234234 invariant . as (
235- StrictOperationError . for ( 'findFirst' , { predicate , options } ) ,
235+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
236236 options ?. strict ? firstRecord != null : true ,
237237 'Failed to execute "findFirst" on collection without a query: the collection is empty' ,
238238 )
@@ -245,7 +245,7 @@ export class Collection<Schema extends StandardSchemaV1> {
245245 ) . next ( ) . value
246246
247247 invariant . as (
248- StrictOperationError . for ( 'findFirst' , { predicate , options } ) ,
248+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
249249 options ?. strict ? result != null : true ,
250250 'Failed to execute "findFirst" on collection: no record found matching the query' ,
251251 )
@@ -277,7 +277,7 @@ export class Collection<Schema extends StandardSchemaV1> {
277277 )
278278
279279 invariant . as (
280- StrictOperationError . for ( 'findMany' , { predicate , options } ) ,
280+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
281281 options ?. strict ? results . length > 0 : true ,
282282 'Failed to execute "findMany" on collection: no records found matching the query' ,
283283 )
@@ -324,7 +324,7 @@ export class Collection<Schema extends StandardSchemaV1> {
324324
325325 if ( prevRecord == null ) {
326326 invariant . as (
327- StrictOperationError . for ( 'update' , { predicate , options } ) ,
327+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
328328 ! options . strict ,
329329 'Failed to execute "update" on collection: no record found matching the query' ,
330330 )
@@ -363,7 +363,7 @@ export class Collection<Schema extends StandardSchemaV1> {
363363
364364 if ( prevRecords . length === 0 ) {
365365 invariant . as (
366- StrictOperationError . for ( 'updateMany' , { predicate , options } ) ,
366+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
367367 ! options . strict ,
368368 'Failed to execute "updateMany" on collection: no records found matching the query' ,
369369 )
@@ -409,7 +409,7 @@ export class Collection<Schema extends StandardSchemaV1> {
409409
410410 if ( record == null ) {
411411 invariant . as (
412- StrictOperationError . for ( 'delete' , { predicate , options } ) ,
412+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
413413 ! options ?. strict ,
414414 'Failed to execute "delete" on collection: no record found matching the query' ,
415415 )
@@ -445,7 +445,7 @@ export class Collection<Schema extends StandardSchemaV1> {
445445
446446 if ( records . length === 0 ) {
447447 invariant . as (
448- StrictOperationError . for ( 'deleteMany' , { predicate , options } ) ,
448+ OperationError . for ( OperationErrorCodes . STRICT_QUERY_WITHOUT_RESULTS ) ,
449449 ! options ?. strict ,
450450 'Failed to execute "deleteMany" on collection: no records found matching the query' ,
451451 )
0 commit comments