asasvirtuais 2.2.7 → 2.2.9

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "asasvirtuais",
3
3
  "type": "module",
4
- "version": "2.2.7",
4
+ "version": "2.2.9",
5
5
  "description": "React form and action management utilities",
6
6
  "directories": {
7
7
  "packages": "./packages"
@@ -31,7 +31,7 @@ export function indexedInterface<Schema extends DatabaseSchema>(
31
31
 
32
32
  const db = new Dexie(dbName)
33
33
 
34
-
34
+
35
35
  // Dynamically define the database schema for Dexie from the Zod schema.
36
36
  // It marks 'id' as the primary key and indexes all other top-level readable fields.
37
37
  const dexieSchema = Object.fromEntries(
@@ -49,7 +49,7 @@ export function indexedInterface<Schema extends DatabaseSchema>(
49
49
  type GenericReadable = z.infer<Schema[keyof Schema]['readable']>
50
50
  type GenericWritable = z.infer<Schema[keyof Schema]['writable']>
51
51
 
52
- return {
52
+ const methods = {
53
53
  async find({ table, id }) {
54
54
  if (!table) throw new Error('Table name must be provided.')
55
55
  const result = await db.table(table).get(id)
@@ -124,13 +124,13 @@ export function indexedInterface<Schema extends DatabaseSchema>(
124
124
  if (updatedCount === 0) {
125
125
  throw new Error(`Record with id ${id} not found in ${table}, cannot update.`)
126
126
  }
127
- const result = await this.find({ table, id })
127
+ const result = await methods.find({ table, id })
128
128
  return result as GenericReadable
129
129
  },
130
130
 
131
131
  async remove({ table, id }) {
132
132
  if (!table) throw new Error('Table name must be provided.')
133
- const record = await this.find({ table, id })
133
+ const record = await methods.find({ table, id })
134
134
  if (!record) {
135
135
  throw new Error(`Record with id ${id} not found in ${table}, cannot remove.`)
136
136
  }
@@ -138,4 +138,6 @@ export function indexedInterface<Schema extends DatabaseSchema>(
138
138
  return record as GenericReadable
139
139
  },
140
140
  } as TableInterface<GenericReadable, GenericWritable>
141
+
142
+ return methods
141
143
  }
@@ -186,12 +186,14 @@ export function FilterForm<TSchema extends TableSchema>({
186
186
  schema,
187
187
  table,
188
188
  defaults,
189
+ autoTrigger,
189
190
  onSuccess,
190
191
  children,
191
192
  }: {
192
193
  schema: TSchema
193
194
  table: string
194
195
  defaults?: Partial<ListProps<z.infer<TSchema['readable']>>>
196
+ autoTrigger?: boolean
195
197
  onSuccess?: (result: z.infer<TSchema['readable']>[]) => void
196
198
  children: React.ReactNode | (
197
199
  (props: ReturnType<typeof useActionProvider<ListProps<z.infer<TSchema['readable']>>, z.infer<TSchema['readable']>[]>>
@@ -217,7 +219,7 @@ export function FilterForm<TSchema extends TableSchema>({
217
219
  defaults={(defaults || { query: {} }) as ListProps<Readable>}
218
220
  >
219
221
  {fields => (
220
- <ActionProvider<ListProps<Readable>, Readable[]> action={callback} params={fields.fields}>
222
+ <ActionProvider<ListProps<Readable>, Readable[]> action={callback} params={fields.fields} autoTrigger={autoTrigger}>
221
223
  {typeof children === 'function' ? (
222
224
  form => children({ ...form, ...fields })
223
225
  ) : (
@@ -249,7 +251,7 @@ export function useUpdateForm<TSchema extends TableSchema>(schema: TSchema) {
249
251
  }
250
252
  }
251
253
 
252
- export function useFiltersForm<TSchema extends TableSchema>(schema: TSchema) {
254
+ export function useFilterForm<TSchema extends TableSchema>(schema: TSchema) {
253
255
  return {
254
256
  ...useFields<z.infer<TSchema['readable']>>(),
255
257
  ...useAction<z.infer<TSchema['readable']>,