@voltro/plugin-flags 0.84.0 → 0.86.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.
@@ -1,70 +1,14 @@
1
1
  # Third-Party Notices — @voltro/plugin-flags
2
2
 
3
- This package depends on the open-source software listed below. Each is the
3
+ This package uses the open-source software listed below. Each is the
4
4
  property of its respective copyright holders and is used under the terms of
5
5
  its license. This file is provided for attribution; it grants no rights in
6
6
  @voltro/plugin-flags itself, which is proprietary (see LICENSE).
7
7
 
8
- Generated from the resolved runtime dependency closure (13 packages).
8
+ Generated from the resolved runtime dependency closure (10 packages).
9
9
 
10
10
  ---
11
11
 
12
- ## @effect/experimental@0.61.1
13
-
14
- License: MIT
15
-
16
- ```
17
- MIT License
18
-
19
- Copyright (c) 2023-present The Contributors
20
-
21
- Permission is hereby granted, free of charge, to any person obtaining a copy
22
- of this software and associated documentation files (the "Software"), to deal
23
- in the Software without restriction, including without limitation the rights
24
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
- copies of the Software, and to permit persons to whom the Software is
26
- furnished to do so, subject to the following conditions:
27
-
28
- The above copyright notice and this permission notice shall be included in all
29
- copies or substantial portions of the Software.
30
-
31
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
- SOFTWARE.
38
- ```
39
-
40
- ## @effect/sql@0.52.1
41
-
42
- License: MIT
43
-
44
- ```
45
- MIT License
46
-
47
- Copyright (c) 2023-present The Contributors
48
-
49
- Permission is hereby granted, free of charge, to any person obtaining a copy
50
- of this software and associated documentation files (the "Software"), to deal
51
- in the Software without restriction, including without limitation the rights
52
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53
- copies of the Software, and to permit persons to whom the Software is
54
- furnished to do so, subject to the following conditions:
55
-
56
- The above copyright notice and this permission notice shall be included in all
57
- copies or substantial portions of the Software.
58
-
59
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
65
- SOFTWARE.
66
- ```
67
-
68
12
  ## @tanstack/devtools-event-client@0.4.4
69
13
 
70
14
  License: MIT
@@ -233,34 +177,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
233
177
  SOFTWARE.
234
178
  ```
235
179
 
236
- ## layerr@3.0.0
237
-
238
- License: MIT
239
-
240
- ```
241
- MIT License
242
-
243
- Copyright (c) 2020 Perry Mitchell
244
-
245
- Permission is hereby granted, free of charge, to any person obtaining a copy
246
- of this software and associated documentation files (the "Software"), to deal
247
- in the Software without restriction, including without limitation the rights
248
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
249
- copies of the Software, and to permit persons to whom the Software is
250
- furnished to do so, subject to the following conditions:
251
-
252
- The above copyright notice and this permission notice shall be included in all
253
- copies or substantial portions of the Software.
254
-
255
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
256
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
257
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
258
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
259
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
260
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
261
- SOFTWARE.
262
- ```
263
-
264
180
  ## typeid-js@1.2.0
265
181
 
266
182
  License: Apache-2.0
@@ -469,14 +385,14 @@ Apache License
469
385
  limitations under the License.
470
386
  ```
471
387
 
472
- ## ulidx@2.4.1
388
+ ## ulid@3.0.2
473
389
 
474
390
  License: MIT
475
391
 
476
392
  ```
477
- MIT License
393
+ The MIT License (MIT)
478
394
 
479
- Copyright (c) 2021 Perry Mitchell
395
+ Copyright (c) 2017 Alizain Feerasta
480
396
 
481
397
  Permission is hereby granted, free of charge, to any person obtaining a copy
482
398
  of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- import { Either as e, Schema as t } from "effect";
1
+ import { Result as e, Schema as t } from "effect";
2
2
  //#region src/define.ts
3
3
  var n = (e) => typeof e == "object" && !!e && e._voltroTypedFlag === !0, r = (e) => e, i = (n) => {
4
4
  let i = (e) => /* @__PURE__ */ Error(`defineFlag(${JSON.stringify(n.key)}): ${e}`);
@@ -13,17 +13,17 @@ var n = (e) => typeof e == "object" && !!e && e._voltroTypedFlag === !0, r = (e)
13
13
  if (n.offVariant !== void 0 && !o.has(n.offVariant)) throw i(`offVariant ${JSON.stringify(n.offVariant)} is not one of the declared variants`);
14
14
  if (n.rollout !== void 0 && !(Number.isFinite(n.rollout) && n.rollout >= 0 && n.rollout <= 100)) throw i("rollout must be a number in 0..100");
15
15
  if (n.experiment !== void 0 && (typeof n.experiment != "string" || n.experiment.length === 0)) throw i("experiment, when present, must be a non-empty experiment name");
16
- let s = t.decodeUnknownEither(n.value, {
16
+ let s = t.decodeUnknownResult(n.value, {
17
17
  errors: "all",
18
18
  onExcessProperty: "ignore"
19
19
  }), c = (t) => {
20
20
  let n = s(t);
21
- return e.isRight(n) ? {
21
+ return e.isSuccess(n) ? {
22
22
  ok: !0,
23
- value: n.right
23
+ value: n.success
24
24
  } : {
25
25
  ok: !1,
26
- reason: n.left.message
26
+ reason: n.failure.message
27
27
  };
28
28
  }, l = c(n.default);
29
29
  if (!l.ok) throw i(`\`default\` does not satisfy the value Schema: ${l.reason}`);
@@ -76,4 +76,4 @@ var n = (e) => typeof e == "object" && !!e && e._voltroTypedFlag === !0, r = (e)
76
76
  };
77
77
  };
78
78
  //#endregion
79
- export { a as i, o as n, n as r, i as t };
79
+ export { i as defineFlag, o as gateOverride, n as isTypedFlag, a as typedValueOf };
package/dist/errors.d.ts CHANGED
@@ -1,14 +1,13 @@
1
1
  import { Schema } from 'effect';
2
+ import { YieldableError } from 'effect/Cause';
2
3
 
3
4
  /** Raised when a flag-gated call hits a disabled flag. Merged into every
4
5
  * procedure's wire-error union so the client decodes it typed. */
5
6
  export declare class FlagDisabled extends FlagDisabled_base {
6
7
  }
7
8
 
8
- declare const FlagDisabled_base: Schema.TaggedErrorClass<FlagDisabled, "FlagDisabled", {
9
- readonly _tag: Schema.tag<"FlagDisabled">;
10
- } & {
11
- flag: typeof Schema.String;
12
- }>;
9
+ declare const FlagDisabled_base: Schema.Class<FlagDisabled, Schema.TaggedStruct<"FlagDisabled", {
10
+ readonly flag: Schema.String;
11
+ }>, YieldableError>;
13
12
 
14
13
  export { }
@@ -0,0 +1,81 @@
1
+ //#region src/evaluate.ts
2
+ var e = (e) => typeof e == "boolean" ? { enabled: e } : e, t = (e, t) => {
3
+ let n = 2166136261, r = `${e}:${t}`;
4
+ for (let e = 0; e < r.length; e++) n ^= r.charCodeAt(e), n = Math.imul(n, 16777619);
5
+ return n >>> 0;
6
+ }, n = (e, n) => t(e, n) % 100, r = (e, n) => t(`${e}:variant`, n) % 1e4, i = (e, t) => {
7
+ if (e.subjectIds && !(t.id != null && e.subjectIds.includes(t.id)) || e.tenantIds && !(t.tenantId != null && e.tenantIds.includes(t.tenantId)) || e.subjectTypes && !(t.type != null && e.subjectTypes.includes(t.type))) return !1;
8
+ if (e.metadata) {
9
+ let n = t.metadata ?? {};
10
+ for (let [t, r] of Object.entries(e.metadata)) if (String(n[t]) !== r) return !1;
11
+ }
12
+ return !0;
13
+ }, a = (e) => typeof e == "number" ? e : Date.parse(e), o = (e, t) => (e.rolloutBy === "tenant" ? t.tenantId : t.id) ?? "anon", s = (e, t) => {
14
+ if (e.activateAt != null && t < a(e.activateAt) || e.deactivateAt != null && t >= a(e.deactivateAt)) return { active: !1 };
15
+ if (e.ramp) {
16
+ let { from: n, to: r, startAt: i, endAt: o } = e.ramp, s = a(i), c = a(o);
17
+ if (t <= s) return {
18
+ active: !0,
19
+ rollout: n
20
+ };
21
+ if (t >= c || c <= s) return {
22
+ active: !0,
23
+ rollout: r
24
+ };
25
+ let l = (t - s) / (c - s);
26
+ return {
27
+ active: !0,
28
+ rollout: n + (r - n) * l
29
+ };
30
+ }
31
+ return { active: !0 };
32
+ }, c = (t, n, r, i = Date.now()) => {
33
+ let a = e(n);
34
+ return l(t, a, r, i) ? !a.variants?.length || a.offVariant == null || d(t, a, r).name !== a.offVariant : !1;
35
+ }, l = (e, t, r, a) => {
36
+ if (t.enabled === !1) return !1;
37
+ let c;
38
+ if (t.schedule) {
39
+ let e = s(t.schedule, a);
40
+ if (!e.active) return !1;
41
+ c = e.rollout;
42
+ }
43
+ if (t.targeting && t.targeting.length > 0 && !t.targeting.some((e) => i(e, r))) return !1;
44
+ let l = c ?? t.rollout ?? 100;
45
+ if (l < 100 && l > 0) {
46
+ if (!(n(e, o(t, r)) < l)) return !1;
47
+ } else if (l <= 0) return !1;
48
+ return !0;
49
+ }, u = (e) => {
50
+ let t = e.reduce((e, t) => e + (t.weight ?? 1), 0) || e.length, n = 0;
51
+ return e.map((r, i) => (n += r.weight ?? 1, i === e.length - 1 ? 1e4 : Math.round(n / t * 1e4)));
52
+ }, d = (e, t, n) => {
53
+ let i = t.variants ?? [];
54
+ if (i.length === 0) throw Error(`flag "${e}" has no variants`);
55
+ let a = r(e, o(t, n)), s = u(i);
56
+ for (let e = 0; e < i.length; e++) if (a < s[e]) return i[e];
57
+ return i[i.length - 1];
58
+ }, f = (t, n, r, i = Date.now()) => {
59
+ let a = e(n), o = l(t, a, r, i);
60
+ if (!a.variants || a.variants.length === 0) return {
61
+ name: o ? "on" : "off",
62
+ value: o,
63
+ enabled: o
64
+ };
65
+ let s = d(t, a, r);
66
+ return {
67
+ name: s.name,
68
+ value: s.value,
69
+ enabled: o && s.name !== a.offVariant
70
+ };
71
+ }, p = (e, t, n = Date.now()) => {
72
+ let r = {};
73
+ for (let [i, a] of Object.entries(e)) r[i] = c(i, a, t, n);
74
+ return r;
75
+ }, m = (e, t, n = Date.now()) => {
76
+ let r = {};
77
+ for (let [i, a] of Object.entries(e)) r[i] = f(i, a, t, n);
78
+ return r;
79
+ };
80
+ //#endregion
81
+ export { p as evaluateAll, m as evaluateAllVariants, c as evaluateFlag, s as evaluateSchedule, f as evaluateVariant, d as resolveVariant, e as toDefinition };
@@ -0,0 +1,48 @@
1
+ //#region src/experimentLink.ts
2
+ var e = (e, t) => {
3
+ let n = new Map(t.map((e) => [e.name, e])), r = [];
4
+ for (let t of e) {
5
+ let e = t.experiment;
6
+ if (e === void 0) continue;
7
+ let i = n.get(e);
8
+ if (i === void 0) {
9
+ r.push({
10
+ flag: t.key,
11
+ experiment: e,
12
+ problem: `no experiment named ${JSON.stringify(e)} was passed to flagsPlugin({ experiments }). Pass the defineExperiment() definitions the app declares, or drop the \`experiment\` link.`
13
+ });
14
+ continue;
15
+ }
16
+ (i.variantFrom === void 0 || i.variantFrom === null) && r.push({
17
+ flag: t.key,
18
+ experiment: e,
19
+ problem: `the experiment assigns its own arms (\`subject\` mode), so it would measure a split this flag never served — the two bucketings are independent hashes. Persist the served arm (\`flagVariant(ctx, ${JSON.stringify(t.key)})\`) on the watched table and declare the experiment with \`variantFrom: <that column>\`.`
20
+ }), typeof i.holdout == "number" && i.holdout > 0 && r.push({
21
+ flag: t.key,
22
+ experiment: e,
23
+ problem: `holdout ${i.holdout} is carved at ASSIGNMENT, and this flag does the assigning — the experiment can never place a row there. Declare the holdout as a flag variant instead.`
24
+ });
25
+ let a = new Set(t.variants.map((e) => e.name)), o = new Set(i.variants.map((e) => e.name));
26
+ if (a.size === 0) r.push({
27
+ flag: t.key,
28
+ experiment: e,
29
+ problem: "the flag declares no variants, so it serves one value to everyone and there is nothing to compare."
30
+ });
31
+ else {
32
+ let n = [...a].filter((e) => !o.has(e)), i = [...o].filter((e) => !a.has(e));
33
+ (n.length > 0 || i.length > 0) && r.push({
34
+ flag: t.key,
35
+ experiment: e,
36
+ problem: `the arms disagree — ${n.length > 0 ? `served by the flag but not declared by the experiment: ${n.join(", ")}` : ""}${n.length > 0 && i.length > 0 ? "; " : ""}${i.length > 0 ? `declared by the experiment but never served: ${i.join(", ")}` : ""}. A row assigned to an arm the experiment does not declare is EXCLUDED, so the mismatch shows up as an empty arm rather than an error.`
37
+ });
38
+ }
39
+ }
40
+ return r;
41
+ }, t = (t, n) => {
42
+ let r = e(t, n);
43
+ if (r.length === 0) return;
44
+ let i = r.map((e) => ` · flag "${e.flag}" → experiment "${e.experiment}": ${e.problem}`);
45
+ throw Error(`@voltro/plugin-flags: ${r.length} flag→experiment link problem(s):\n${i.join("\n")}`);
46
+ };
47
+ //#endregion
48
+ export { t as assertFlagExperimentLinks, e as checkFlagExperimentLinks };
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ import { FieldDefinitions } from '@voltro/database';
5
5
  import { Schema } from 'effect';
6
6
  import { Table } from '@voltro/database';
7
7
  import { VoltroPlugin } from '@voltro/protocol';
8
+ import { YieldableError } from 'effect/Cause';
8
9
 
9
10
  /** `TypedFlag` with the value type erased — what the plugin and the registry
10
11
  * hold. Sound because `TypedFlag` is covariant in `A` (see the annotation). */
@@ -78,9 +79,9 @@ export declare const DEFAULT_FLAG_USAGE_FLUSH_MS = 300000;
78
79
  * a duplicate variant name, an `offVariant` naming no variant, a non-positive
79
80
  * weight, a rollout outside 0..100.
80
81
  */
81
- export declare const defineFlag: <S extends Schema.Schema.AnyNoContext>(spec: DefineFlagSpec<S>) => TypedFlag<Schema.Schema.Type<S>>;
82
+ export declare const defineFlag: <S extends Schema.Top>(spec: DefineFlagSpec<S>) => TypedFlag<Schema.Schema.Type<S>>;
82
83
 
83
- export declare interface DefineFlagSpec<S extends Schema.Schema.AnyNoContext> {
84
+ export declare interface DefineFlagSpec<S extends Schema.Top> {
84
85
  /** The flag key — `dotted.camelCase`, matching the `flags: { … }` record. */
85
86
  readonly key: string;
86
87
  /** The value Schema. Everything else in this spec is checked against it. */
@@ -254,11 +255,9 @@ export declare interface FlagDefinition {
254
255
  export declare class FlagDisabled extends FlagDisabled_base {
255
256
  }
256
257
 
257
- declare const FlagDisabled_base: Schema.TaggedErrorClass<FlagDisabled, "FlagDisabled", {
258
- readonly _tag: Schema.tag<"FlagDisabled">;
259
- } & {
260
- flag: typeof Schema.String;
261
- }>;
258
+ declare const FlagDisabled_base: Schema.Class<FlagDisabled, Schema.TaggedStruct<"FlagDisabled", {
259
+ readonly flag: Schema.String;
260
+ }>, YieldableError>;
262
261
 
263
262
  export declare interface FlagExperimentLinkProblem {
264
263
  readonly flag: string;