@vllnt/convex-flags 0.1.0-canary.bf53746 → 0.1.0
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 +84 -25
- package/dist/client/index.d.ts +62 -16
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +54 -15
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +30 -4
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/_generated/api.d.ts +19 -1
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js +16 -0
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +174 -24
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/_generated/server.d.ts +12 -0
- package/dist/component/_generated/server.d.ts.map +1 -1
- package/dist/component/_generated/server.js +2 -0
- package/dist/component/_generated/server.js.map +1 -1
- package/dist/component/convex.config.d.ts.map +1 -1
- package/dist/component/mutations.d.ts +90 -5
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +144 -10
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/queries.d.ts +90 -13
- package/dist/component/queries.d.ts.map +1 -1
- package/dist/component/queries.js +58 -12
- package/dist/component/queries.js.map +1 -1
- package/dist/component/schema.d.ts +138 -4
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +7 -1
- package/dist/component/schema.js.map +1 -1
- package/dist/component/validators.d.ts +354 -14
- package/dist/component/validators.d.ts.map +1 -1
- package/dist/component/validators.js +57 -6
- package/dist/component/validators.js.map +1 -1
- package/dist/react/index.d.ts +29 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +35 -0
- package/dist/react/index.js.map +1 -0
- package/dist/shared.d.ts +102 -4
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +126 -3
- package/dist/shared.js.map +1 -1
- package/package.json +36 -18
- package/src/client/index.ts +145 -20
- package/src/client/types.ts +48 -4
- package/src/component/_generated/api.ts +19 -1
- package/src/component/_generated/component.ts +259 -23
- package/src/component/_generated/server.ts +13 -0
- package/src/component/mutations.ts +160 -19
- package/src/component/queries.ts +74 -12
- package/src/component/schema.ts +7 -1
- package/src/component/validators.ts +87 -6
- package/src/react/index.test.ts +52 -0
- package/src/react/index.ts +69 -0
- package/src/shared.ts +235 -4
- package/src/status-backward-compat.test.ts +51 -0
|
@@ -7,51 +7,201 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import type { FunctionReference } from "convex/server";
|
|
10
|
-
type FlagDoc = {
|
|
11
|
-
_id: string;
|
|
12
|
-
_creationTime: number;
|
|
13
|
-
key: string;
|
|
14
|
-
description?: string;
|
|
15
|
-
value: boolean;
|
|
16
|
-
createdAt: number;
|
|
17
|
-
updatedAt: number;
|
|
18
|
-
};
|
|
19
|
-
type FlagEvaluation = {
|
|
20
|
-
value: boolean;
|
|
21
|
-
reason: string;
|
|
22
|
-
};
|
|
23
10
|
/**
|
|
24
11
|
* A utility for referencing a Convex component's exposed API.
|
|
25
12
|
*
|
|
26
|
-
* Useful when expecting a parameter like `components.
|
|
13
|
+
* Useful when expecting a parameter like `components.myComponent`.
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```ts
|
|
16
|
+
* async function myFunction(ctx: QueryCtx, component: ComponentApi) {
|
|
17
|
+
* return ctx.runQuery(component.someFile.someQuery, { ...args });
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
27
20
|
*/
|
|
28
21
|
export type ComponentApi<Name extends string | undefined = string | undefined> = {
|
|
29
22
|
mutations: {
|
|
30
|
-
|
|
23
|
+
archive: FunctionReference<"mutation", "internal", {
|
|
31
24
|
key: string;
|
|
32
|
-
|
|
25
|
+
}, null, Name>;
|
|
26
|
+
clearOverride: FunctionReference<"mutation", "internal", {
|
|
27
|
+
key: string;
|
|
28
|
+
subjectRef: string;
|
|
29
|
+
}, null, Name>;
|
|
30
|
+
define: FunctionReference<"mutation", "internal", {
|
|
33
31
|
description?: string;
|
|
32
|
+
key: string;
|
|
33
|
+
rollout?: {
|
|
34
|
+
by?: string;
|
|
35
|
+
splits: Array<{
|
|
36
|
+
value: boolean | string | number;
|
|
37
|
+
weight: number;
|
|
38
|
+
}>;
|
|
39
|
+
};
|
|
40
|
+
rules?: Array<{
|
|
41
|
+
conditions: Array<{
|
|
42
|
+
attribute: string;
|
|
43
|
+
op: "eq" | "neq" | "in" | "nin" | "contains" | "gt" | "gte" | "lt" | "lte";
|
|
44
|
+
values: Array<boolean | string | number>;
|
|
45
|
+
}>;
|
|
46
|
+
rollout?: {
|
|
47
|
+
by?: string;
|
|
48
|
+
splits: Array<{
|
|
49
|
+
value: boolean | string | number;
|
|
50
|
+
weight: number;
|
|
51
|
+
}>;
|
|
52
|
+
};
|
|
53
|
+
value?: boolean | string | number;
|
|
54
|
+
}>;
|
|
55
|
+
value: boolean | string | number;
|
|
56
|
+
variants?: Array<{
|
|
57
|
+
label?: string;
|
|
58
|
+
value: boolean | string | number;
|
|
59
|
+
}>;
|
|
34
60
|
}, string, Name>;
|
|
35
|
-
|
|
61
|
+
disable: FunctionReference<"mutation", "internal", {
|
|
36
62
|
key: string;
|
|
37
63
|
}, null, Name>;
|
|
38
|
-
|
|
64
|
+
enable: FunctionReference<"mutation", "internal", {
|
|
39
65
|
key: string;
|
|
40
66
|
}, null, Name>;
|
|
41
67
|
remove: FunctionReference<"mutation", "internal", {
|
|
42
68
|
key: string;
|
|
43
69
|
}, null, Name>;
|
|
70
|
+
restore: FunctionReference<"mutation", "internal", {
|
|
71
|
+
key: string;
|
|
72
|
+
}, null, Name>;
|
|
73
|
+
setOverride: FunctionReference<"mutation", "internal", {
|
|
74
|
+
key: string;
|
|
75
|
+
subjectRef: string;
|
|
76
|
+
value: boolean | string | number;
|
|
77
|
+
}, null, Name>;
|
|
78
|
+
update: FunctionReference<"mutation", "internal", {
|
|
79
|
+
description?: string;
|
|
80
|
+
key: string;
|
|
81
|
+
rollout?: {
|
|
82
|
+
by?: string;
|
|
83
|
+
splits: Array<{
|
|
84
|
+
value: boolean | string | number;
|
|
85
|
+
weight: number;
|
|
86
|
+
}>;
|
|
87
|
+
};
|
|
88
|
+
rules?: Array<{
|
|
89
|
+
conditions: Array<{
|
|
90
|
+
attribute: string;
|
|
91
|
+
op: "eq" | "neq" | "in" | "nin" | "contains" | "gt" | "gte" | "lt" | "lte";
|
|
92
|
+
values: Array<boolean | string | number>;
|
|
93
|
+
}>;
|
|
94
|
+
rollout?: {
|
|
95
|
+
by?: string;
|
|
96
|
+
splits: Array<{
|
|
97
|
+
value: boolean | string | number;
|
|
98
|
+
weight: number;
|
|
99
|
+
}>;
|
|
100
|
+
};
|
|
101
|
+
value?: boolean | string | number;
|
|
102
|
+
}>;
|
|
103
|
+
value?: boolean | string | number;
|
|
104
|
+
variants?: Array<{
|
|
105
|
+
label?: string;
|
|
106
|
+
value: boolean | string | number;
|
|
107
|
+
}>;
|
|
108
|
+
}, null, Name>;
|
|
44
109
|
};
|
|
45
110
|
queries: {
|
|
111
|
+
all: FunctionReference<"query", "internal", {
|
|
112
|
+
context?: {
|
|
113
|
+
attributes?: Record<string, boolean | string | number>;
|
|
114
|
+
subjectRef?: string;
|
|
115
|
+
};
|
|
116
|
+
}, Record<string, {
|
|
117
|
+
reason: "flag" | "rule" | "rollout" | "override" | "disabled" | "default" | "unknown";
|
|
118
|
+
value: boolean | string | number;
|
|
119
|
+
}>, Name>;
|
|
120
|
+
evaluate: FunctionReference<"query", "internal", {
|
|
121
|
+
context?: {
|
|
122
|
+
attributes?: Record<string, boolean | string | number>;
|
|
123
|
+
subjectRef?: string;
|
|
124
|
+
};
|
|
125
|
+
default?: boolean | string | number;
|
|
126
|
+
key: string;
|
|
127
|
+
}, {
|
|
128
|
+
reason: "flag" | "rule" | "rollout" | "override" | "disabled" | "default" | "unknown";
|
|
129
|
+
value: boolean | string | number;
|
|
130
|
+
}, Name>;
|
|
46
131
|
get: FunctionReference<"query", "internal", {
|
|
47
132
|
key: string;
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
|
|
133
|
+
}, null | {
|
|
134
|
+
_creationTime: number;
|
|
135
|
+
_id: string;
|
|
136
|
+
createdAt: number;
|
|
137
|
+
description?: string;
|
|
138
|
+
key: string;
|
|
139
|
+
rollout?: {
|
|
140
|
+
by?: string;
|
|
141
|
+
splits: Array<{
|
|
142
|
+
value: boolean | string | number;
|
|
143
|
+
weight: number;
|
|
144
|
+
}>;
|
|
145
|
+
};
|
|
146
|
+
rules?: Array<{
|
|
147
|
+
conditions: Array<{
|
|
148
|
+
attribute: string;
|
|
149
|
+
op: "eq" | "neq" | "in" | "nin" | "contains" | "gt" | "gte" | "lt" | "lte";
|
|
150
|
+
values: Array<boolean | string | number>;
|
|
151
|
+
}>;
|
|
152
|
+
rollout?: {
|
|
153
|
+
by?: string;
|
|
154
|
+
splits: Array<{
|
|
155
|
+
value: boolean | string | number;
|
|
156
|
+
weight: number;
|
|
157
|
+
}>;
|
|
158
|
+
};
|
|
159
|
+
value?: boolean | string | number;
|
|
160
|
+
}>;
|
|
161
|
+
status: "active" | "archived";
|
|
162
|
+
updatedAt: number;
|
|
163
|
+
value: boolean | string | number;
|
|
164
|
+
variants?: Array<{
|
|
165
|
+
label?: string;
|
|
166
|
+
value: boolean | string | number;
|
|
167
|
+
}>;
|
|
168
|
+
}, Name>;
|
|
169
|
+
list: FunctionReference<"query", "internal", {}, Array<{
|
|
170
|
+
_creationTime: number;
|
|
171
|
+
_id: string;
|
|
172
|
+
createdAt: number;
|
|
173
|
+
description?: string;
|
|
51
174
|
key: string;
|
|
52
|
-
|
|
53
|
-
|
|
175
|
+
rollout?: {
|
|
176
|
+
by?: string;
|
|
177
|
+
splits: Array<{
|
|
178
|
+
value: boolean | string | number;
|
|
179
|
+
weight: number;
|
|
180
|
+
}>;
|
|
181
|
+
};
|
|
182
|
+
rules?: Array<{
|
|
183
|
+
conditions: Array<{
|
|
184
|
+
attribute: string;
|
|
185
|
+
op: "eq" | "neq" | "in" | "nin" | "contains" | "gt" | "gte" | "lt" | "lte";
|
|
186
|
+
values: Array<boolean | string | number>;
|
|
187
|
+
}>;
|
|
188
|
+
rollout?: {
|
|
189
|
+
by?: string;
|
|
190
|
+
splits: Array<{
|
|
191
|
+
value: boolean | string | number;
|
|
192
|
+
weight: number;
|
|
193
|
+
}>;
|
|
194
|
+
};
|
|
195
|
+
value?: boolean | string | number;
|
|
196
|
+
}>;
|
|
197
|
+
status: "active" | "archived";
|
|
198
|
+
updatedAt: number;
|
|
199
|
+
value: boolean | string | number;
|
|
200
|
+
variants?: Array<{
|
|
201
|
+
label?: string;
|
|
202
|
+
value: boolean | string | number;
|
|
203
|
+
}>;
|
|
204
|
+
}>, Name>;
|
|
54
205
|
};
|
|
55
206
|
};
|
|
56
|
-
export {};
|
|
57
207
|
//# sourceMappingURL=component.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/component.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/component.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,CAAC,IAAI,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,IAC3E;IACE,SAAS,EAAE;QACT,OAAO,EAAE,iBAAiB,CACxB,UAAU,EACV,UAAU,EACV;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,EACf,IAAI,EACJ,IAAI,CACL,CAAC;QACF,aAAa,EAAE,iBAAiB,CAC9B,UAAU,EACV,UAAU,EACV;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,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C,CAAC;gBACH,OAAO,CAAC,EAAE;oBACR,EAAE,CAAC,EAAE,MAAM,CAAC;oBACZ,MAAM,EAAE,KAAK,CAAC;wBACZ,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;wBACjC,MAAM,EAAE,MAAM,CAAC;qBAChB,CAAC,CAAC;iBACJ,CAAC;gBACF,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;aACnC,CAAC,CAAC;YACH,MAAM,EAAE,QAAQ,GAAG,UAAU,CAAC;YAC9B,SAAS,EAAE,MAAM,CAAC;YAClB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;YACjC,QAAQ,CAAC,EAAE,KAAK,CAAC;gBACf,KAAK,CAAC,EAAE,MAAM,CAAC;gBACf,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;aAClC,CAAC,CAAC;SACJ,CAAC,EACF,IAAI,CACL,CAAC;KACH,CAAC;CACH,CAAC"}
|
|
@@ -8,6 +8,16 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { ActionBuilder, HttpActionBuilder, MutationBuilder, QueryBuilder, GenericActionCtx, GenericMutationCtx, GenericQueryCtx, GenericDatabaseReader, GenericDatabaseWriter } from "convex/server";
|
|
10
10
|
import type { DataModel } from "./dataModel.js";
|
|
11
|
+
/**
|
|
12
|
+
* Typesafe environment variables.
|
|
13
|
+
*
|
|
14
|
+
* This includes platform-provided env vars and any variables declared in
|
|
15
|
+
* `convex.config.ts`.
|
|
16
|
+
*/
|
|
17
|
+
type Env = {
|
|
18
|
+
readonly CONVEX_CLOUD_URL: string;
|
|
19
|
+
readonly CONVEX_SITE_URL: string;
|
|
20
|
+
};
|
|
11
21
|
/**
|
|
12
22
|
* Define a query in this Convex app's public API.
|
|
13
23
|
*
|
|
@@ -75,6 +85,7 @@ export declare const internalAction: ActionBuilder<DataModel, "internal">;
|
|
|
75
85
|
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
|
|
76
86
|
*/
|
|
77
87
|
export declare const httpAction: HttpActionBuilder;
|
|
88
|
+
export declare const env: Env;
|
|
78
89
|
/**
|
|
79
90
|
* A set of services for use within Convex query functions.
|
|
80
91
|
*
|
|
@@ -118,4 +129,5 @@ export type DatabaseReader = GenericDatabaseReader<DataModel>;
|
|
|
118
129
|
* for the guarantees Convex provides your functions.
|
|
119
130
|
*/
|
|
120
131
|
export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
|
|
132
|
+
export {};
|
|
121
133
|
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/server.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,eAAe,CAAC;AAUvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,EAAE,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAgB,CAAC;AAErE;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,SAAS,EAAE,UAAU,CACxC,CAAC;AAEvB;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,SAAS,EAAE,QAAQ,CAAmB,CAAC;AAE9E;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,SAAS,EAAE,UAAU,CAC3C,CAAC;AAE1B;;;;;;;;;;GAUG;AACH,eAAO,MAAM,MAAM,EAAE,aAAa,CAAC,SAAS,EAAE,QAAQ,CAAiB,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC,SA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GAOG;AACH,MAAM,MAAM,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;AAExD;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;AAE9D;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -75,4 +75,6 @@ export const internalAction = internalActionGeneric;
|
|
|
75
75
|
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
|
|
76
76
|
*/
|
|
77
77
|
export const httpAction = httpActionGeneric;
|
|
78
|
+
export const env = globalThis
|
|
79
|
+
.process.env;
|
|
78
80
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/component/_generated/server.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAaH,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/component/_generated/server.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAaH,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAcvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAsC,YAAY,CAAC;AAErE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GACxB,oBAAoB,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAyC,eAAe,CAAC;AAE9E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,uBAAuB,CAAC;AAE1B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,MAAM,GAAuC,aAAa,CAAC;AAExE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,qBAAqB,CAAC;AAExB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAsB,iBAAiB,CAAC;AAC/D,MAAM,CAAC,MAAM,GAAG,GAAS,UAAmD;KACzE,OAAO,CAAC,GAAG,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convex.config.d.ts","sourceRoot":"","sources":["../../src/component/convex.config.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,SAAS,sDAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"convex.config.d.ts","sourceRoot":"","sources":["../../src/component/convex.config.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,SAAS,sDAA2B,CAAC;eAM5B,SAAS"}
|
|
@@ -1,19 +1,104 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Create a flag, or fully replace its definition if the key already exists
|
|
3
|
+
* (value, description, variants, rules, rollout). Status is preserved on update.
|
|
4
|
+
*/
|
|
2
5
|
export declare const define: import("convex/server").RegisteredMutation<"public", {
|
|
3
6
|
description?: string | undefined;
|
|
4
7
|
key: string;
|
|
5
|
-
|
|
8
|
+
rollout?: {
|
|
9
|
+
by?: string | undefined;
|
|
10
|
+
splits: {
|
|
11
|
+
value: string | number | boolean;
|
|
12
|
+
weight: number;
|
|
13
|
+
}[];
|
|
14
|
+
} | undefined;
|
|
15
|
+
rules?: {
|
|
16
|
+
conditions: {
|
|
17
|
+
attribute: string;
|
|
18
|
+
op: "contains" | "eq" | "gt" | "gte" | "in" | "lt" | "lte" | "neq" | "nin";
|
|
19
|
+
values: (string | number | boolean)[];
|
|
20
|
+
}[];
|
|
21
|
+
rollout?: {
|
|
22
|
+
by?: string | undefined;
|
|
23
|
+
splits: {
|
|
24
|
+
value: string | number | boolean;
|
|
25
|
+
weight: number;
|
|
26
|
+
}[];
|
|
27
|
+
} | undefined;
|
|
28
|
+
value?: string | number | boolean | undefined;
|
|
29
|
+
}[] | undefined;
|
|
30
|
+
value: string | number | boolean;
|
|
31
|
+
variants?: {
|
|
32
|
+
label?: string | undefined;
|
|
33
|
+
value: string | number | boolean;
|
|
34
|
+
}[] | undefined;
|
|
6
35
|
}, Promise<import("convex/values").GenericId<"flags">>>;
|
|
7
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Partially update a flag: patch ONLY the fields supplied (the opposite of
|
|
38
|
+
* `define`, which fully replaces). Omitted fields are left untouched, so
|
|
39
|
+
* re-sending one field never wipes rules/rollout/variants.
|
|
40
|
+
*/
|
|
41
|
+
export declare const update: import("convex/server").RegisteredMutation<"public", {
|
|
42
|
+
description?: string | undefined;
|
|
43
|
+
key: string;
|
|
44
|
+
rollout?: {
|
|
45
|
+
by?: string | undefined;
|
|
46
|
+
splits: {
|
|
47
|
+
value: string | number | boolean;
|
|
48
|
+
weight: number;
|
|
49
|
+
}[];
|
|
50
|
+
} | undefined;
|
|
51
|
+
rules?: {
|
|
52
|
+
conditions: {
|
|
53
|
+
attribute: string;
|
|
54
|
+
op: "contains" | "eq" | "gt" | "gte" | "in" | "lt" | "lte" | "neq" | "nin";
|
|
55
|
+
values: (string | number | boolean)[];
|
|
56
|
+
}[];
|
|
57
|
+
rollout?: {
|
|
58
|
+
by?: string | undefined;
|
|
59
|
+
splits: {
|
|
60
|
+
value: string | number | boolean;
|
|
61
|
+
weight: number;
|
|
62
|
+
}[];
|
|
63
|
+
} | undefined;
|
|
64
|
+
value?: string | number | boolean | undefined;
|
|
65
|
+
}[] | undefined;
|
|
66
|
+
value?: string | number | boolean | undefined;
|
|
67
|
+
variants?: {
|
|
68
|
+
label?: string | undefined;
|
|
69
|
+
value: string | number | boolean;
|
|
70
|
+
}[] | undefined;
|
|
71
|
+
}, Promise<null>>;
|
|
72
|
+
/** Turn a boolean flag on (set its value to `true`). */
|
|
8
73
|
export declare const enable: import("convex/server").RegisteredMutation<"public", {
|
|
9
74
|
key: string;
|
|
10
75
|
}, Promise<null>>;
|
|
11
|
-
/** Turn a flag off (set its value to `false`). */
|
|
76
|
+
/** Turn a boolean flag off (set its value to `false`). */
|
|
12
77
|
export declare const disable: import("convex/server").RegisteredMutation<"public", {
|
|
13
78
|
key: string;
|
|
14
79
|
}, Promise<null>>;
|
|
15
|
-
/**
|
|
80
|
+
/** Archive a flag: reversible retirement. Evaluation skips targeting and serves
|
|
81
|
+
* the flag's base value with reason `disabled`. */
|
|
82
|
+
export declare const archive: import("convex/server").RegisteredMutation<"public", {
|
|
83
|
+
key: string;
|
|
84
|
+
}, Promise<null>>;
|
|
85
|
+
/** Restore an archived flag to active. */
|
|
86
|
+
export declare const restore: import("convex/server").RegisteredMutation<"public", {
|
|
87
|
+
key: string;
|
|
88
|
+
}, Promise<null>>;
|
|
89
|
+
/** Permanently delete a flag and any per-subject overrides it owns. */
|
|
16
90
|
export declare const remove: import("convex/server").RegisteredMutation<"public", {
|
|
17
91
|
key: string;
|
|
18
92
|
}, Promise<null>>;
|
|
93
|
+
/** Force a flag's value for one subject. The flag must exist. */
|
|
94
|
+
export declare const setOverride: import("convex/server").RegisteredMutation<"public", {
|
|
95
|
+
key: string;
|
|
96
|
+
subjectRef: string;
|
|
97
|
+
value: string | number | boolean;
|
|
98
|
+
}, Promise<null>>;
|
|
99
|
+
/** Clear a subject's override for a flag. No-op if none exists. */
|
|
100
|
+
export declare const clearOverride: import("convex/server").RegisteredMutation<"public", {
|
|
101
|
+
key: string;
|
|
102
|
+
subjectRef: string;
|
|
103
|
+
}, Promise<null>>;
|
|
19
104
|
//# sourceMappingURL=mutations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uDAoCjB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkCjB,CAAC;AAUH,wDAAwD;AACxD,eAAO,MAAM,MAAM;;iBAOjB,CAAC;AAEH,0DAA0D;AAC1D,eAAO,MAAM,OAAO;;iBAOlB,CAAC;AAcH;mDACmD;AACnD,eAAO,MAAM,OAAO;;iBAOlB,CAAC;AAEH,0CAA0C;AAC1C,eAAO,MAAM,OAAO;;iBAOlB,CAAC;AAEH,uEAAuE;AACvE,eAAO,MAAM,MAAM;;iBAkBjB,CAAC;AAEH,iEAAiE;AACjE,eAAO,MAAM,WAAW;;;;iBA0BtB,CAAC;AAEH,mEAAmE;AACnE,eAAO,MAAM,aAAa;;;iBAexB,CAAC"}
|
|
@@ -1,26 +1,41 @@
|
|
|
1
1
|
import { v } from "convex/values";
|
|
2
2
|
import { mutation } from "./_generated/server.js";
|
|
3
|
+
import { rollout, rule, variant, variantValue } from "./validators.js";
|
|
3
4
|
async function findByKey(ctx, key) {
|
|
4
5
|
return await ctx.db
|
|
5
6
|
.query("flags")
|
|
6
7
|
.withIndex("by_key", (q) => q.eq("key", key))
|
|
7
8
|
.unique();
|
|
8
9
|
}
|
|
9
|
-
/**
|
|
10
|
+
/** Throws the component's single code-tagged error. Returns `never` so callers
|
|
11
|
+
* narrow the flag to non-null after the guard. */
|
|
12
|
+
function flagNotFound() {
|
|
13
|
+
throw new Error("FLAG_NOT_FOUND");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create a flag, or fully replace its definition if the key already exists
|
|
17
|
+
* (value, description, variants, rules, rollout). Status is preserved on update.
|
|
18
|
+
*/
|
|
10
19
|
export const define = mutation({
|
|
11
20
|
args: {
|
|
12
21
|
key: v.string(),
|
|
13
|
-
value:
|
|
22
|
+
value: variantValue,
|
|
14
23
|
description: v.optional(v.string()),
|
|
24
|
+
variants: v.optional(v.array(variant)),
|
|
25
|
+
rules: v.optional(v.array(rule)),
|
|
26
|
+
rollout: v.optional(rollout),
|
|
15
27
|
},
|
|
16
28
|
returns: v.id("flags"),
|
|
17
29
|
handler: async (ctx, args) => {
|
|
18
30
|
const now = Date.now();
|
|
19
31
|
const existing = await findByKey(ctx, args.key);
|
|
20
32
|
if (existing !== null) {
|
|
21
|
-
await ctx.db.patch(existing._id, {
|
|
33
|
+
await ctx.db.patch("flags", existing._id, {
|
|
22
34
|
value: args.value,
|
|
23
35
|
description: args.description,
|
|
36
|
+
variants: args.variants,
|
|
37
|
+
rules: args.rules,
|
|
38
|
+
rollout: args.rollout,
|
|
24
39
|
updatedAt: now,
|
|
25
40
|
});
|
|
26
41
|
return existing._id;
|
|
@@ -29,19 +44,63 @@ export const define = mutation({
|
|
|
29
44
|
key: args.key,
|
|
30
45
|
value: args.value,
|
|
31
46
|
description: args.description,
|
|
47
|
+
variants: args.variants,
|
|
48
|
+
rules: args.rules,
|
|
49
|
+
rollout: args.rollout,
|
|
50
|
+
status: "active",
|
|
32
51
|
createdAt: now,
|
|
33
52
|
updatedAt: now,
|
|
34
53
|
});
|
|
35
54
|
},
|
|
36
55
|
});
|
|
56
|
+
/**
|
|
57
|
+
* Partially update a flag: patch ONLY the fields supplied (the opposite of
|
|
58
|
+
* `define`, which fully replaces). Omitted fields are left untouched, so
|
|
59
|
+
* re-sending one field never wipes rules/rollout/variants.
|
|
60
|
+
*/
|
|
61
|
+
export const update = mutation({
|
|
62
|
+
args: {
|
|
63
|
+
key: v.string(),
|
|
64
|
+
value: v.optional(variantValue),
|
|
65
|
+
description: v.optional(v.string()),
|
|
66
|
+
variants: v.optional(v.array(variant)),
|
|
67
|
+
rules: v.optional(v.array(rule)),
|
|
68
|
+
rollout: v.optional(rollout),
|
|
69
|
+
},
|
|
70
|
+
returns: v.null(),
|
|
71
|
+
handler: async (ctx, args) => {
|
|
72
|
+
const flag = await findByKey(ctx, args.key);
|
|
73
|
+
if (flag === null) {
|
|
74
|
+
flagNotFound();
|
|
75
|
+
}
|
|
76
|
+
const patch = { updatedAt: Date.now() };
|
|
77
|
+
if (args.value !== undefined) {
|
|
78
|
+
patch.value = args.value;
|
|
79
|
+
}
|
|
80
|
+
if (args.description !== undefined) {
|
|
81
|
+
patch.description = args.description;
|
|
82
|
+
}
|
|
83
|
+
if (args.variants !== undefined) {
|
|
84
|
+
patch.variants = args.variants;
|
|
85
|
+
}
|
|
86
|
+
if (args.rules !== undefined) {
|
|
87
|
+
patch.rules = args.rules;
|
|
88
|
+
}
|
|
89
|
+
if (args.rollout !== undefined) {
|
|
90
|
+
patch.rollout = args.rollout;
|
|
91
|
+
}
|
|
92
|
+
await ctx.db.patch("flags", flag._id, patch);
|
|
93
|
+
return null;
|
|
94
|
+
},
|
|
95
|
+
});
|
|
37
96
|
async function setValue(ctx, key, value) {
|
|
38
97
|
const flag = await findByKey(ctx, key);
|
|
39
98
|
if (flag === null) {
|
|
40
|
-
|
|
99
|
+
flagNotFound();
|
|
41
100
|
}
|
|
42
|
-
await ctx.db.patch(flag._id, { value, updatedAt: Date.now() });
|
|
101
|
+
await ctx.db.patch("flags", flag._id, { value, updatedAt: Date.now() });
|
|
43
102
|
}
|
|
44
|
-
/** Turn a flag on (set its value to `true`). */
|
|
103
|
+
/** Turn a boolean flag on (set its value to `true`). */
|
|
45
104
|
export const enable = mutation({
|
|
46
105
|
args: { key: v.string() },
|
|
47
106
|
returns: v.null(),
|
|
@@ -50,7 +109,7 @@ export const enable = mutation({
|
|
|
50
109
|
return null;
|
|
51
110
|
},
|
|
52
111
|
});
|
|
53
|
-
/** Turn a flag off (set its value to `false`). */
|
|
112
|
+
/** Turn a boolean flag off (set its value to `false`). */
|
|
54
113
|
export const disable = mutation({
|
|
55
114
|
args: { key: v.string() },
|
|
56
115
|
returns: v.null(),
|
|
@@ -59,16 +118,91 @@ export const disable = mutation({
|
|
|
59
118
|
return null;
|
|
60
119
|
},
|
|
61
120
|
});
|
|
62
|
-
|
|
121
|
+
async function setStatus(ctx, key, status) {
|
|
122
|
+
const flag = await findByKey(ctx, key);
|
|
123
|
+
if (flag === null) {
|
|
124
|
+
flagNotFound();
|
|
125
|
+
}
|
|
126
|
+
await ctx.db.patch("flags", flag._id, { status, updatedAt: Date.now() });
|
|
127
|
+
}
|
|
128
|
+
/** Archive a flag: reversible retirement. Evaluation skips targeting and serves
|
|
129
|
+
* the flag's base value with reason `disabled`. */
|
|
130
|
+
export const archive = mutation({
|
|
131
|
+
args: { key: v.string() },
|
|
132
|
+
returns: v.null(),
|
|
133
|
+
handler: async (ctx, args) => {
|
|
134
|
+
await setStatus(ctx, args.key, "archived");
|
|
135
|
+
return null;
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
/** Restore an archived flag to active. */
|
|
139
|
+
export const restore = mutation({
|
|
140
|
+
args: { key: v.string() },
|
|
141
|
+
returns: v.null(),
|
|
142
|
+
handler: async (ctx, args) => {
|
|
143
|
+
await setStatus(ctx, args.key, "active");
|
|
144
|
+
return null;
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
/** Permanently delete a flag and any per-subject overrides it owns. */
|
|
63
148
|
export const remove = mutation({
|
|
64
149
|
args: { key: v.string() },
|
|
65
150
|
returns: v.null(),
|
|
66
151
|
handler: async (ctx, args) => {
|
|
67
152
|
const flag = await findByKey(ctx, args.key);
|
|
68
153
|
if (flag === null) {
|
|
69
|
-
|
|
154
|
+
flagNotFound();
|
|
155
|
+
}
|
|
156
|
+
const overrides = await ctx.db
|
|
157
|
+
.query("overrides")
|
|
158
|
+
.withIndex("by_key_subject", (q) => q.eq("key", args.key))
|
|
159
|
+
.collect();
|
|
160
|
+
for (const override of overrides) {
|
|
161
|
+
await ctx.db.delete("overrides", override._id);
|
|
162
|
+
}
|
|
163
|
+
await ctx.db.delete("flags", flag._id);
|
|
164
|
+
return null;
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
/** Force a flag's value for one subject. The flag must exist. */
|
|
168
|
+
export const setOverride = mutation({
|
|
169
|
+
args: { key: v.string(), subjectRef: v.string(), value: variantValue },
|
|
170
|
+
returns: v.null(),
|
|
171
|
+
handler: async (ctx, args) => {
|
|
172
|
+
const flag = await findByKey(ctx, args.key);
|
|
173
|
+
if (flag === null) {
|
|
174
|
+
flagNotFound();
|
|
175
|
+
}
|
|
176
|
+
const existing = await ctx.db
|
|
177
|
+
.query("overrides")
|
|
178
|
+
.withIndex("by_key_subject", (q) => q.eq("key", args.key).eq("subjectRef", args.subjectRef))
|
|
179
|
+
.unique();
|
|
180
|
+
if (existing !== null) {
|
|
181
|
+
await ctx.db.patch("overrides", existing._id, { value: args.value });
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
await ctx.db.insert("overrides", {
|
|
185
|
+
key: args.key,
|
|
186
|
+
subjectRef: args.subjectRef,
|
|
187
|
+
value: args.value,
|
|
188
|
+
createdAt: Date.now(),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return null;
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
/** Clear a subject's override for a flag. No-op if none exists. */
|
|
195
|
+
export const clearOverride = mutation({
|
|
196
|
+
args: { key: v.string(), subjectRef: v.string() },
|
|
197
|
+
returns: v.null(),
|
|
198
|
+
handler: async (ctx, args) => {
|
|
199
|
+
const existing = await ctx.db
|
|
200
|
+
.query("overrides")
|
|
201
|
+
.withIndex("by_key_subject", (q) => q.eq("key", args.key).eq("subjectRef", args.subjectRef))
|
|
202
|
+
.unique();
|
|
203
|
+
if (existing !== null) {
|
|
204
|
+
await ctx.db.delete("overrides", existing._id);
|
|
70
205
|
}
|
|
71
|
-
await ctx.db.delete(flag._id);
|
|
72
206
|
return null;
|
|
73
207
|
},
|
|
74
208
|
});
|