convex-verify 1.1.0 → 1.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/README.md +148 -80
- package/dist/core/index.d.mts +14 -55
- package/dist/core/index.d.ts +14 -55
- package/dist/core/index.js +492 -92
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +491 -92
- package/dist/core/index.mjs.map +1 -1
- package/dist/index.d.mts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.js +378 -271
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +378 -267
- package/dist/index.mjs.map +1 -1
- package/dist/types-B8ZkLuJ2.d.mts +141 -0
- package/dist/types-B8ZkLuJ2.d.ts +141 -0
- package/dist/utils/index.d.mts +3 -2
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/verifyConfig-CTrtqMr_.d.ts +94 -0
- package/dist/verifyConfig-Kn3Ikj00.d.mts +94 -0
- package/package.json +1 -16
- package/dist/configs/index.d.mts +0 -51
- package/dist/configs/index.d.ts +0 -51
- package/dist/configs/index.js +0 -38
- package/dist/configs/index.js.map +0 -1
- package/dist/configs/index.mjs +0 -11
- package/dist/configs/index.mjs.map +0 -1
- package/dist/plugin-BOb1Kw1A.d.ts +0 -47
- package/dist/plugin-DlsboiCF.d.mts +0 -47
- package/dist/plugins/index.d.mts +0 -85
- package/dist/plugins/index.d.ts +0 -85
- package/dist/plugins/index.js +0 -312
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/index.mjs +0 -284
- package/dist/plugins/index.mjs.map +0 -1
- package/dist/transforms/index.d.mts +0 -38
- package/dist/transforms/index.d.ts +0 -38
- package/dist/transforms/index.js +0 -46
- package/dist/transforms/index.js.map +0 -1
- package/dist/transforms/index.mjs +0 -19
- package/dist/transforms/index.mjs.map +0 -1
- package/dist/types-DvJMYubf.d.mts +0 -151
- package/dist/types-DvJMYubf.d.ts +0 -151
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { DataModelFromSchemaDefinition, SchemaDefinition, GenericDocument, WithoutSystemFields, Indexes, NamedTableInfo } from 'convex/server';
|
|
2
|
-
|
|
3
|
-
type Prettify<T> = {
|
|
4
|
-
[K in keyof T]: T[K];
|
|
5
|
-
} & {};
|
|
6
|
-
type MakeOptional<T, K extends PropertyKey> = Prettify<Omit<T, K & keyof T> & Partial<Pick<T, K & keyof T>>>;
|
|
7
|
-
/**
|
|
8
|
-
* Base interface that all config functions should return.
|
|
9
|
-
* Each config type can have its own `verify` signature and additional properties.
|
|
10
|
-
*/
|
|
11
|
-
type BaseConfigReturn = {
|
|
12
|
-
config: Record<string, any>;
|
|
13
|
-
};
|
|
14
|
-
type OnFailArgs<D extends GenericDocument> = {
|
|
15
|
-
uniqueColumn?: {
|
|
16
|
-
conflictingColumn: keyof D;
|
|
17
|
-
existingData: D;
|
|
18
|
-
};
|
|
19
|
-
uniqueRow?: {
|
|
20
|
-
existingData: D | null;
|
|
21
|
-
};
|
|
22
|
-
editableColumn?: {
|
|
23
|
-
removedColumns: string[];
|
|
24
|
-
filteredData: Partial<WithoutSystemFields<D>>;
|
|
25
|
-
};
|
|
26
|
-
requiredColumn?: {
|
|
27
|
-
missingColumn: keyof D;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
type OnFailCallback<D extends GenericDocument> = (args: OnFailArgs<D>) => void;
|
|
31
|
-
type DMGeneric = DataModelFromSchemaDefinition<SchemaDefinition<any, boolean>>;
|
|
32
|
-
type DefaultValuesConfigData<DM extends DMGeneric> = {
|
|
33
|
-
[K in keyof DM]?: {
|
|
34
|
-
[column in keyof WithoutSystemFields<DM[K]['document']>]?: DM[K]['document'][column];
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Base options shared by all index-based config entries.
|
|
39
|
-
* Individual extensions can extend this with their own options.
|
|
40
|
-
*/
|
|
41
|
-
type IndexConfigBaseOptions = {
|
|
42
|
-
/** Additional identifiers to check if the existing row is the same document being updated */
|
|
43
|
-
identifiers?: string[];
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* A config entry that can be either:
|
|
47
|
-
* - A string (index name) for shorthand
|
|
48
|
-
* - An object with `index` and additional options
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```ts
|
|
52
|
-
* // These are equivalent:
|
|
53
|
-
* 'by_username'
|
|
54
|
-
* { index: 'by_username' }
|
|
55
|
-
*
|
|
56
|
-
* // With options:
|
|
57
|
-
* { index: 'by_username', identifiers: ['_id', 'userId'] }
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
type IndexConfigEntry<DM extends DMGeneric, K extends keyof DM, Options extends IndexConfigBaseOptions = IndexConfigBaseOptions> = keyof Indexes<NamedTableInfo<DM, K>> | ({
|
|
61
|
-
index: keyof Indexes<NamedTableInfo<DM, K>>;
|
|
62
|
-
identifiers?: (keyof NamedTableInfo<DM, K>['document'])[];
|
|
63
|
-
} & Omit<Options, 'identifiers'>);
|
|
64
|
-
/**
|
|
65
|
-
* Normalized form of an index config entry (always an object)
|
|
66
|
-
*/
|
|
67
|
-
type NormalizedIndexConfig<Options extends IndexConfigBaseOptions = IndexConfigBaseOptions> = {
|
|
68
|
-
index: string;
|
|
69
|
-
identifiers: string[];
|
|
70
|
-
} & Omit<Options, 'identifiers'>;
|
|
71
|
-
/**
|
|
72
|
-
* Normalize a config entry to always have index and identifiers.
|
|
73
|
-
* Works for both string shorthand and full object configs.
|
|
74
|
-
*/
|
|
75
|
-
declare function normalizeIndexConfigEntry<Options extends IndexConfigBaseOptions = IndexConfigBaseOptions>(entry: string | ({
|
|
76
|
-
index: string;
|
|
77
|
-
identifiers?: string[];
|
|
78
|
-
} & Omit<Options, 'identifiers'>), defaultIdentifiers?: string[]): NormalizedIndexConfig<Options>;
|
|
79
|
-
type UniqueRowConfigOptions = IndexConfigBaseOptions & {
|
|
80
|
-
queryExistingWithNullish?: boolean;
|
|
81
|
-
};
|
|
82
|
-
type UniqueRowConfigEntry<DM extends DMGeneric, K extends keyof DM> = IndexConfigEntry<DM, K, UniqueRowConfigOptions>;
|
|
83
|
-
type UniqueRowConfigData<DM extends DMGeneric> = {
|
|
84
|
-
[K in keyof DM]?: UniqueRowConfigEntry<DM, K>[];
|
|
85
|
-
};
|
|
86
|
-
type UniqueColumnConfigOptions = IndexConfigBaseOptions;
|
|
87
|
-
type UniqueColumnConfigEntry<DM extends DMGeneric, K extends keyof DM> = IndexConfigEntry<DM, K, UniqueColumnConfigOptions>;
|
|
88
|
-
type UniqueColumnConfigData<DM extends DMGeneric> = {
|
|
89
|
-
[K in keyof DM]?: UniqueColumnConfigEntry<DM, K>[];
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* Loose input types that accept any return from config functions.
|
|
93
|
-
* We use loose types here to avoid complex generic matching,
|
|
94
|
-
* then extract the specific config types using conditional types.
|
|
95
|
-
*/
|
|
96
|
-
type DefaultValuesInput = {
|
|
97
|
-
_type: 'defaultValues';
|
|
98
|
-
verify: (tableName: any, data: any) => Promise<any>;
|
|
99
|
-
config: Record<string, Record<string, any>> | (() => Record<string, Record<string, any>> | Promise<Record<string, Record<string, any>>>);
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Loose input type for protectedColumnsConfig return value.
|
|
103
|
-
*/
|
|
104
|
-
type ProtectedColumnsInput = {
|
|
105
|
-
_type: 'protectedColumns';
|
|
106
|
-
config: Record<string, string[]>;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Config input for verifyConfig.
|
|
110
|
-
*
|
|
111
|
-
* - `defaultValues`: Transform config that makes fields optional (affects types)
|
|
112
|
-
* - `protectedColumns`: Columns that cannot be patched (affects patch() types)
|
|
113
|
-
* Extension-specific options are added by `verifyConfig`.
|
|
114
|
-
*/
|
|
115
|
-
type VerifyConfigInput = {
|
|
116
|
-
defaultValues?: DefaultValuesInput;
|
|
117
|
-
protectedColumns?: ProtectedColumnsInput;
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Extract the config type from defaultValues.config.
|
|
121
|
-
* Handles both direct object and function forms.
|
|
122
|
-
*/
|
|
123
|
-
type ExtractDefaultValuesConfig<VC> = VC extends {
|
|
124
|
-
defaultValues: {
|
|
125
|
-
config: infer C;
|
|
126
|
-
};
|
|
127
|
-
} ? C extends () => infer R ? Awaited<R> : C : Record<string, never>;
|
|
128
|
-
/**
|
|
129
|
-
* Compute which keys should be optional for a given table based on all configs.
|
|
130
|
-
* Currently only defaultValues affects optionality.
|
|
131
|
-
*/
|
|
132
|
-
type OptionalKeysForTable<VC, TN> = TN extends keyof ExtractDefaultValuesConfig<VC> ? keyof ExtractDefaultValuesConfig<VC>[TN] : never;
|
|
133
|
-
/**
|
|
134
|
-
* Helper to check if a key exists in a type
|
|
135
|
-
*/
|
|
136
|
-
type HasKey<T, K extends PropertyKey> = K extends keyof T ? true : false;
|
|
137
|
-
/**
|
|
138
|
-
* Extract the config type from protectedColumns.config
|
|
139
|
-
*/
|
|
140
|
-
type ExtractProtectedColumnsConfig<VC> = VC extends {
|
|
141
|
-
protectedColumns: {
|
|
142
|
-
config: infer C;
|
|
143
|
-
};
|
|
144
|
-
} ? C : Record<string, never>;
|
|
145
|
-
/**
|
|
146
|
-
* Get protected column keys for a specific table.
|
|
147
|
-
* Returns the column names that should be omitted from patch() input.
|
|
148
|
-
*/
|
|
149
|
-
type ProtectedKeysForTable<VC, TN> = TN extends keyof ExtractProtectedColumnsConfig<VC> ? ExtractProtectedColumnsConfig<VC>[TN] extends readonly (infer K)[] ? K : never : never;
|
|
150
|
-
|
|
151
|
-
export { type BaseConfigReturn as B, type DefaultValuesConfigData as D, type ExtractDefaultValuesConfig as E, type HasKey as H, type IndexConfigBaseOptions as I, type MakeOptional as M, type NormalizedIndexConfig as N, type OnFailArgs as O, type Prettify as P, type UniqueRowConfigData as U, type VerifyConfigInput as V, type OnFailCallback as a, type OptionalKeysForTable as b, type ExtractProtectedColumnsConfig as c, type ProtectedKeysForTable as d, type UniqueRowConfigEntry as e, type UniqueRowConfigOptions as f, type UniqueColumnConfigData as g, type UniqueColumnConfigEntry as h, type UniqueColumnConfigOptions as i, type IndexConfigEntry as j, type DMGeneric as k, type DefaultValuesInput as l, type ProtectedColumnsInput as m, normalizeIndexConfigEntry as n };
|
package/dist/types-DvJMYubf.d.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { DataModelFromSchemaDefinition, SchemaDefinition, GenericDocument, WithoutSystemFields, Indexes, NamedTableInfo } from 'convex/server';
|
|
2
|
-
|
|
3
|
-
type Prettify<T> = {
|
|
4
|
-
[K in keyof T]: T[K];
|
|
5
|
-
} & {};
|
|
6
|
-
type MakeOptional<T, K extends PropertyKey> = Prettify<Omit<T, K & keyof T> & Partial<Pick<T, K & keyof T>>>;
|
|
7
|
-
/**
|
|
8
|
-
* Base interface that all config functions should return.
|
|
9
|
-
* Each config type can have its own `verify` signature and additional properties.
|
|
10
|
-
*/
|
|
11
|
-
type BaseConfigReturn = {
|
|
12
|
-
config: Record<string, any>;
|
|
13
|
-
};
|
|
14
|
-
type OnFailArgs<D extends GenericDocument> = {
|
|
15
|
-
uniqueColumn?: {
|
|
16
|
-
conflictingColumn: keyof D;
|
|
17
|
-
existingData: D;
|
|
18
|
-
};
|
|
19
|
-
uniqueRow?: {
|
|
20
|
-
existingData: D | null;
|
|
21
|
-
};
|
|
22
|
-
editableColumn?: {
|
|
23
|
-
removedColumns: string[];
|
|
24
|
-
filteredData: Partial<WithoutSystemFields<D>>;
|
|
25
|
-
};
|
|
26
|
-
requiredColumn?: {
|
|
27
|
-
missingColumn: keyof D;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
type OnFailCallback<D extends GenericDocument> = (args: OnFailArgs<D>) => void;
|
|
31
|
-
type DMGeneric = DataModelFromSchemaDefinition<SchemaDefinition<any, boolean>>;
|
|
32
|
-
type DefaultValuesConfigData<DM extends DMGeneric> = {
|
|
33
|
-
[K in keyof DM]?: {
|
|
34
|
-
[column in keyof WithoutSystemFields<DM[K]['document']>]?: DM[K]['document'][column];
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Base options shared by all index-based config entries.
|
|
39
|
-
* Individual extensions can extend this with their own options.
|
|
40
|
-
*/
|
|
41
|
-
type IndexConfigBaseOptions = {
|
|
42
|
-
/** Additional identifiers to check if the existing row is the same document being updated */
|
|
43
|
-
identifiers?: string[];
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* A config entry that can be either:
|
|
47
|
-
* - A string (index name) for shorthand
|
|
48
|
-
* - An object with `index` and additional options
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```ts
|
|
52
|
-
* // These are equivalent:
|
|
53
|
-
* 'by_username'
|
|
54
|
-
* { index: 'by_username' }
|
|
55
|
-
*
|
|
56
|
-
* // With options:
|
|
57
|
-
* { index: 'by_username', identifiers: ['_id', 'userId'] }
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
type IndexConfigEntry<DM extends DMGeneric, K extends keyof DM, Options extends IndexConfigBaseOptions = IndexConfigBaseOptions> = keyof Indexes<NamedTableInfo<DM, K>> | ({
|
|
61
|
-
index: keyof Indexes<NamedTableInfo<DM, K>>;
|
|
62
|
-
identifiers?: (keyof NamedTableInfo<DM, K>['document'])[];
|
|
63
|
-
} & Omit<Options, 'identifiers'>);
|
|
64
|
-
/**
|
|
65
|
-
* Normalized form of an index config entry (always an object)
|
|
66
|
-
*/
|
|
67
|
-
type NormalizedIndexConfig<Options extends IndexConfigBaseOptions = IndexConfigBaseOptions> = {
|
|
68
|
-
index: string;
|
|
69
|
-
identifiers: string[];
|
|
70
|
-
} & Omit<Options, 'identifiers'>;
|
|
71
|
-
/**
|
|
72
|
-
* Normalize a config entry to always have index and identifiers.
|
|
73
|
-
* Works for both string shorthand and full object configs.
|
|
74
|
-
*/
|
|
75
|
-
declare function normalizeIndexConfigEntry<Options extends IndexConfigBaseOptions = IndexConfigBaseOptions>(entry: string | ({
|
|
76
|
-
index: string;
|
|
77
|
-
identifiers?: string[];
|
|
78
|
-
} & Omit<Options, 'identifiers'>), defaultIdentifiers?: string[]): NormalizedIndexConfig<Options>;
|
|
79
|
-
type UniqueRowConfigOptions = IndexConfigBaseOptions & {
|
|
80
|
-
queryExistingWithNullish?: boolean;
|
|
81
|
-
};
|
|
82
|
-
type UniqueRowConfigEntry<DM extends DMGeneric, K extends keyof DM> = IndexConfigEntry<DM, K, UniqueRowConfigOptions>;
|
|
83
|
-
type UniqueRowConfigData<DM extends DMGeneric> = {
|
|
84
|
-
[K in keyof DM]?: UniqueRowConfigEntry<DM, K>[];
|
|
85
|
-
};
|
|
86
|
-
type UniqueColumnConfigOptions = IndexConfigBaseOptions;
|
|
87
|
-
type UniqueColumnConfigEntry<DM extends DMGeneric, K extends keyof DM> = IndexConfigEntry<DM, K, UniqueColumnConfigOptions>;
|
|
88
|
-
type UniqueColumnConfigData<DM extends DMGeneric> = {
|
|
89
|
-
[K in keyof DM]?: UniqueColumnConfigEntry<DM, K>[];
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* Loose input types that accept any return from config functions.
|
|
93
|
-
* We use loose types here to avoid complex generic matching,
|
|
94
|
-
* then extract the specific config types using conditional types.
|
|
95
|
-
*/
|
|
96
|
-
type DefaultValuesInput = {
|
|
97
|
-
_type: 'defaultValues';
|
|
98
|
-
verify: (tableName: any, data: any) => Promise<any>;
|
|
99
|
-
config: Record<string, Record<string, any>> | (() => Record<string, Record<string, any>> | Promise<Record<string, Record<string, any>>>);
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Loose input type for protectedColumnsConfig return value.
|
|
103
|
-
*/
|
|
104
|
-
type ProtectedColumnsInput = {
|
|
105
|
-
_type: 'protectedColumns';
|
|
106
|
-
config: Record<string, string[]>;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Config input for verifyConfig.
|
|
110
|
-
*
|
|
111
|
-
* - `defaultValues`: Transform config that makes fields optional (affects types)
|
|
112
|
-
* - `protectedColumns`: Columns that cannot be patched (affects patch() types)
|
|
113
|
-
* Extension-specific options are added by `verifyConfig`.
|
|
114
|
-
*/
|
|
115
|
-
type VerifyConfigInput = {
|
|
116
|
-
defaultValues?: DefaultValuesInput;
|
|
117
|
-
protectedColumns?: ProtectedColumnsInput;
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Extract the config type from defaultValues.config.
|
|
121
|
-
* Handles both direct object and function forms.
|
|
122
|
-
*/
|
|
123
|
-
type ExtractDefaultValuesConfig<VC> = VC extends {
|
|
124
|
-
defaultValues: {
|
|
125
|
-
config: infer C;
|
|
126
|
-
};
|
|
127
|
-
} ? C extends () => infer R ? Awaited<R> : C : Record<string, never>;
|
|
128
|
-
/**
|
|
129
|
-
* Compute which keys should be optional for a given table based on all configs.
|
|
130
|
-
* Currently only defaultValues affects optionality.
|
|
131
|
-
*/
|
|
132
|
-
type OptionalKeysForTable<VC, TN> = TN extends keyof ExtractDefaultValuesConfig<VC> ? keyof ExtractDefaultValuesConfig<VC>[TN] : never;
|
|
133
|
-
/**
|
|
134
|
-
* Helper to check if a key exists in a type
|
|
135
|
-
*/
|
|
136
|
-
type HasKey<T, K extends PropertyKey> = K extends keyof T ? true : false;
|
|
137
|
-
/**
|
|
138
|
-
* Extract the config type from protectedColumns.config
|
|
139
|
-
*/
|
|
140
|
-
type ExtractProtectedColumnsConfig<VC> = VC extends {
|
|
141
|
-
protectedColumns: {
|
|
142
|
-
config: infer C;
|
|
143
|
-
};
|
|
144
|
-
} ? C : Record<string, never>;
|
|
145
|
-
/**
|
|
146
|
-
* Get protected column keys for a specific table.
|
|
147
|
-
* Returns the column names that should be omitted from patch() input.
|
|
148
|
-
*/
|
|
149
|
-
type ProtectedKeysForTable<VC, TN> = TN extends keyof ExtractProtectedColumnsConfig<VC> ? ExtractProtectedColumnsConfig<VC>[TN] extends readonly (infer K)[] ? K : never : never;
|
|
150
|
-
|
|
151
|
-
export { type BaseConfigReturn as B, type DefaultValuesConfigData as D, type ExtractDefaultValuesConfig as E, type HasKey as H, type IndexConfigBaseOptions as I, type MakeOptional as M, type NormalizedIndexConfig as N, type OnFailArgs as O, type Prettify as P, type UniqueRowConfigData as U, type VerifyConfigInput as V, type OnFailCallback as a, type OptionalKeysForTable as b, type ExtractProtectedColumnsConfig as c, type ProtectedKeysForTable as d, type UniqueRowConfigEntry as e, type UniqueRowConfigOptions as f, type UniqueColumnConfigData as g, type UniqueColumnConfigEntry as h, type UniqueColumnConfigOptions as i, type IndexConfigEntry as j, type DMGeneric as k, type DefaultValuesInput as l, type ProtectedColumnsInput as m, normalizeIndexConfigEntry as n };
|