@yedoma-labs/kulyn-flags 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +181 -2
- package/dist/index.cjs +419 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +127 -0
- package/dist/index.d.ts +127 -0
- package/dist/index.js +412 -0
- package/dist/index.js.map +1 -0
- package/package.json +79 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when a flag register or its options are invalid.
|
|
4
|
+
*/
|
|
5
|
+
var FlagRegistryError = class extends Error {
|
|
6
|
+
code;
|
|
7
|
+
/** The offending flag key, when it is known. */
|
|
8
|
+
key;
|
|
9
|
+
constructor(code, message, key) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "FlagRegistryError";
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.key = key;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Thrown by `assertFlagHygiene` when findings match the `failOn` codes.
|
|
18
|
+
*/
|
|
19
|
+
var FlagHygieneError = class extends Error {
|
|
20
|
+
code;
|
|
21
|
+
findings;
|
|
22
|
+
constructor(findings) {
|
|
23
|
+
const lines = findings.map((finding) => ` - [${finding.code}] ${finding.message}`);
|
|
24
|
+
super(`Flag hygiene check failed with ${findings.length} finding(s):\n${lines.join("\n")}`);
|
|
25
|
+
this.name = "FlagHygieneError";
|
|
26
|
+
this.code = findings[0]?.code ?? "UNUSED";
|
|
27
|
+
this.findings = findings;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
// src/dates.ts
|
|
31
|
+
const DAY_MS = 864e5;
|
|
32
|
+
/**
|
|
33
|
+
* `YYYY-MM-DD`, optionally followed by `T HH:MM[:SS[.fraction]]` and a mandatory timezone.
|
|
34
|
+
* Only fixed quantifiers and a single optional group, so matching is linear.
|
|
35
|
+
*/
|
|
36
|
+
const ISO_PATTERN = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?(Z|[+-]\d{2}:\d{2}))?$/;
|
|
37
|
+
function isLeapYear(year) {
|
|
38
|
+
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
39
|
+
}
|
|
40
|
+
function daysInMonth(year, month) {
|
|
41
|
+
return [
|
|
42
|
+
31,
|
|
43
|
+
isLeapYear(year) ? 29 : 28,
|
|
44
|
+
31,
|
|
45
|
+
30,
|
|
46
|
+
31,
|
|
47
|
+
30,
|
|
48
|
+
31,
|
|
49
|
+
31,
|
|
50
|
+
30,
|
|
51
|
+
31,
|
|
52
|
+
30,
|
|
53
|
+
31
|
|
54
|
+
][month - 1] ?? 0;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Parses a strict ISO 8601 date or date-time and returns epoch milliseconds.
|
|
58
|
+
* Returns `undefined` for anything that is not a real calendar date and time.
|
|
59
|
+
*/
|
|
60
|
+
function parseIsoDate(value) {
|
|
61
|
+
if (typeof value !== "string") return;
|
|
62
|
+
const match = ISO_PATTERN.exec(value);
|
|
63
|
+
if (match === null) return;
|
|
64
|
+
const year = Number(match[1]);
|
|
65
|
+
const month = Number(match[2]);
|
|
66
|
+
const day = Number(match[3]);
|
|
67
|
+
if (month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month)) return;
|
|
68
|
+
if (match[4] !== void 0) {
|
|
69
|
+
const hours = Number(match[4]);
|
|
70
|
+
const minutes = Number(match[5]);
|
|
71
|
+
const seconds = match[6] === void 0 ? 0 : Number(match[6]);
|
|
72
|
+
if (hours > 23 || minutes > 59 || seconds > 59) return;
|
|
73
|
+
const offset = match[8];
|
|
74
|
+
if (offset !== void 0 && offset !== "Z") {
|
|
75
|
+
const offsetHours = Number(offset.slice(1, 3));
|
|
76
|
+
const offsetMinutes = Number(offset.slice(4, 6));
|
|
77
|
+
if (offsetHours > 23 || offsetMinutes > 59) return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const time = Date.parse(value);
|
|
81
|
+
return Number.isNaN(time) ? void 0 : time;
|
|
82
|
+
}
|
|
83
|
+
// src/lifetimes.ts
|
|
84
|
+
const FLAG_KINDS = [
|
|
85
|
+
"release",
|
|
86
|
+
"experiment",
|
|
87
|
+
"ops",
|
|
88
|
+
"permission"
|
|
89
|
+
];
|
|
90
|
+
/**
|
|
91
|
+
* Default maximum lifetimes. `permission` flags may live without limit.
|
|
92
|
+
*/
|
|
93
|
+
const DEFAULT_MAX_LIFETIME_DAYS = Object.freeze({
|
|
94
|
+
release: 90,
|
|
95
|
+
experiment: 30,
|
|
96
|
+
ops: 365,
|
|
97
|
+
permission: null
|
|
98
|
+
});
|
|
99
|
+
function isFlagKind(value) {
|
|
100
|
+
return typeof value === "string" && FLAG_KINDS.includes(value);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Merges user overrides into the defaults and validates them.
|
|
104
|
+
*/
|
|
105
|
+
function resolveMaxLifetimeDays(overrides) {
|
|
106
|
+
const resolved = { ...DEFAULT_MAX_LIFETIME_DAYS };
|
|
107
|
+
if (overrides === void 0) return resolved;
|
|
108
|
+
if (typeof overrides !== "object" || overrides === null) throw new FlagRegistryError("INVALID_OPTIONS", "maxLifetimeDays must be an object");
|
|
109
|
+
for (const kind of Object.keys(overrides)) {
|
|
110
|
+
if (!isFlagKind(kind)) throw new FlagRegistryError("INVALID_OPTIONS", `Unknown flag kind in maxLifetimeDays: "${kind}"`);
|
|
111
|
+
const value = overrides[kind];
|
|
112
|
+
if (value === void 0) continue;
|
|
113
|
+
if (value !== null && !(Number.isInteger(value) && value > 0)) throw new FlagRegistryError("INVALID_OPTIONS", `maxLifetimeDays.${kind} must be a positive integer or null, got ${String(value)}`);
|
|
114
|
+
resolved[kind] = value;
|
|
115
|
+
}
|
|
116
|
+
return resolved;
|
|
117
|
+
}
|
|
118
|
+
// src/hygiene.ts
|
|
119
|
+
/** Order of codes in the result when two findings share a key. */
|
|
120
|
+
const CODE_ORDER = [
|
|
121
|
+
"EXPIRED",
|
|
122
|
+
"EXCEEDS_MAX_LIFETIME",
|
|
123
|
+
"UNUSED",
|
|
124
|
+
"UNREGISTERED_USAGE"
|
|
125
|
+
];
|
|
126
|
+
/**
|
|
127
|
+
* Checks a flag register for flags that should be cleaned up.
|
|
128
|
+
*
|
|
129
|
+
* - `EXPIRED`: `now` is at or after `expiresAt`.
|
|
130
|
+
* - `EXCEEDS_MAX_LIFETIME`: the flag lives longer than the configured maximum for its kind.
|
|
131
|
+
* This catches flags registered before a limit was lowered.
|
|
132
|
+
* - `UNUSED`: only when `usedKeys` is given. The key is registered but not used.
|
|
133
|
+
* - `UNREGISTERED_USAGE`: only when `usedKeys` is given. The key is used but not registered.
|
|
134
|
+
*
|
|
135
|
+
* Findings are sorted by key, then by code.
|
|
136
|
+
*/
|
|
137
|
+
function checkFlagHygiene(options) {
|
|
138
|
+
const nowMs = resolveNow(options.now);
|
|
139
|
+
const lifetimes = resolveMaxLifetimeDays(options.maxLifetimeDays);
|
|
140
|
+
const registered = /* @__PURE__ */ new Set();
|
|
141
|
+
const findings = [];
|
|
142
|
+
for (const flag of options.flags) {
|
|
143
|
+
if (registered.has(flag.key)) throw new FlagRegistryError("DUPLICATE_KEY", `Duplicate flag key "${flag.key}"`, flag.key);
|
|
144
|
+
registered.add(flag.key);
|
|
145
|
+
collectLifecycleFindings(flag, nowMs, lifetimes[flag.kind], findings);
|
|
146
|
+
}
|
|
147
|
+
if (options.usedKeys !== void 0) {
|
|
148
|
+
const used = new Set(options.usedKeys);
|
|
149
|
+
for (const key of registered) if (!used.has(key)) findings.push({
|
|
150
|
+
key,
|
|
151
|
+
code: "UNUSED",
|
|
152
|
+
message: `Flag "${key}" is registered but not used`
|
|
153
|
+
});
|
|
154
|
+
for (const key of used) if (!registered.has(key)) findings.push({
|
|
155
|
+
key,
|
|
156
|
+
code: "UNREGISTERED_USAGE",
|
|
157
|
+
message: `Flag "${key}" is used but not registered`
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return findings.sort((a, b) => compareStrings(a.key, b.key) || CODE_ORDER.indexOf(a.code) - CODE_ORDER.indexOf(b.code));
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Throws `FlagHygieneError` if any finding has a code listed in `failOn`.
|
|
164
|
+
* Defaults to all codes. Use it in tests or CI.
|
|
165
|
+
*/
|
|
166
|
+
function assertFlagHygiene(findings, options) {
|
|
167
|
+
const failOn = new Set(options?.failOn ?? CODE_ORDER);
|
|
168
|
+
const failing = findings.filter((finding) => failOn.has(finding.code));
|
|
169
|
+
if (failing.length > 0) throw new FlagHygieneError(failing);
|
|
170
|
+
}
|
|
171
|
+
function collectLifecycleFindings(flag, nowMs, maxDays, findings) {
|
|
172
|
+
if (!isFlagKind(flag.kind)) throw new FlagRegistryError("INVALID_KIND", `Flag "${flag.key}" has invalid kind`, flag.key);
|
|
173
|
+
const createdMs = parseIsoDate(flag.createdAt);
|
|
174
|
+
if (createdMs === void 0) throw new FlagRegistryError("INVALID_DATE", `Flag "${flag.key}" has invalid createdAt`, flag.key);
|
|
175
|
+
if (flag.expiresAt === void 0) return;
|
|
176
|
+
const expiresMs = parseIsoDate(flag.expiresAt);
|
|
177
|
+
if (expiresMs === void 0) throw new FlagRegistryError("INVALID_DATE", `Flag "${flag.key}" has invalid expiresAt`, flag.key);
|
|
178
|
+
if (nowMs >= expiresMs) findings.push({
|
|
179
|
+
key: flag.key,
|
|
180
|
+
code: "EXPIRED",
|
|
181
|
+
message: `Flag "${flag.key}" expired at ${flag.expiresAt}`
|
|
182
|
+
});
|
|
183
|
+
if (maxDays !== null && maxDays !== void 0) {
|
|
184
|
+
const lifetimeMs = expiresMs - createdMs;
|
|
185
|
+
if (lifetimeMs > maxDays * 864e5) findings.push({
|
|
186
|
+
key: flag.key,
|
|
187
|
+
code: "EXCEEDS_MAX_LIFETIME",
|
|
188
|
+
message: `Flag "${flag.key}" (${flag.kind}) lives ${lifetimeMs / DAY_MS} days, the maximum is ${maxDays}`
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function resolveNow(now) {
|
|
193
|
+
if (now === void 0) return Date.now();
|
|
194
|
+
const time = now.getTime();
|
|
195
|
+
if (Number.isNaN(time)) throw new FlagRegistryError("INVALID_OPTIONS", "now is an invalid Date");
|
|
196
|
+
return time;
|
|
197
|
+
}
|
|
198
|
+
function compareStrings(a, b) {
|
|
199
|
+
if (a === b) return 0;
|
|
200
|
+
return a < b ? -1 : 1;
|
|
201
|
+
}
|
|
202
|
+
// src/registry.ts
|
|
203
|
+
const KEY_PATTERN = /^[a-z][a-z0-9-.]{1,79}$/;
|
|
204
|
+
/**
|
|
205
|
+
* Validates a flag register and returns a frozen, normalized copy.
|
|
206
|
+
*
|
|
207
|
+
* Throws `FlagRegistryError` with a `code` for the first invalid entry.
|
|
208
|
+
* A flag kind with a finite maximum lifetime requires `expiresAt`, so that a flag
|
|
209
|
+
* cannot escape the limit by omitting the date.
|
|
210
|
+
*/
|
|
211
|
+
function defineFlags(definitions, options) {
|
|
212
|
+
if (!Array.isArray(definitions)) throw new FlagRegistryError("INVALID_DEFINITION", "defineFlags expects an array of flags");
|
|
213
|
+
const maxLifetimeDays = resolveMaxLifetimeDays(options?.maxLifetimeDays);
|
|
214
|
+
const seen = /* @__PURE__ */ new Set();
|
|
215
|
+
const result = [];
|
|
216
|
+
for (const [index, raw] of definitions.entries()) {
|
|
217
|
+
const flag = validateDefinition(raw, index, maxLifetimeDays);
|
|
218
|
+
if (seen.has(flag.key)) throw new FlagRegistryError("DUPLICATE_KEY", `Duplicate flag key "${flag.key}"`, flag.key);
|
|
219
|
+
seen.add(flag.key);
|
|
220
|
+
result.push(flag);
|
|
221
|
+
}
|
|
222
|
+
return Object.freeze(result);
|
|
223
|
+
}
|
|
224
|
+
function validateDefinition(raw, index, maxLifetimeDays) {
|
|
225
|
+
if (typeof raw !== "object" || raw === null) throw new FlagRegistryError("INVALID_DEFINITION", `Flag at index ${index} is not an object`);
|
|
226
|
+
const record = raw;
|
|
227
|
+
const key = record.key;
|
|
228
|
+
if (typeof key !== "string" || !KEY_PATTERN.test(key)) throw new FlagRegistryError("INVALID_KEY", `Invalid flag key at index ${index}: ${JSON.stringify(key)} (must match ${KEY_PATTERN.source})`, typeof key === "string" ? key : void 0);
|
|
229
|
+
const owner = record.owner;
|
|
230
|
+
if (typeof owner !== "string" || owner.trim() === "") throw new FlagRegistryError("EMPTY_OWNER", `Flag "${key}" has no owner`, key);
|
|
231
|
+
const kind = record.kind;
|
|
232
|
+
if (!isFlagKind(kind)) throw new FlagRegistryError("INVALID_KIND", `Flag "${key}" has invalid kind ${JSON.stringify(kind)}`, key);
|
|
233
|
+
const createdAt = record.createdAt;
|
|
234
|
+
const createdMs = parseIsoDate(createdAt);
|
|
235
|
+
if (createdMs === void 0) throw new FlagRegistryError("INVALID_DATE", `Flag "${key}" has invalid createdAt ${JSON.stringify(createdAt)}`, key);
|
|
236
|
+
const expiresAt = record.expiresAt;
|
|
237
|
+
let expiresMs;
|
|
238
|
+
if (expiresAt !== void 0) {
|
|
239
|
+
expiresMs = parseIsoDate(expiresAt);
|
|
240
|
+
if (expiresMs === void 0) throw new FlagRegistryError("INVALID_DATE", `Flag "${key}" has invalid expiresAt ${JSON.stringify(expiresAt)}`, key);
|
|
241
|
+
if (expiresMs <= createdMs) throw new FlagRegistryError("EXPIRY_NOT_AFTER_CREATION", `Flag "${key}" expires at ${String(expiresAt)}, which is not after createdAt`, key);
|
|
242
|
+
}
|
|
243
|
+
const maxDays = maxLifetimeDays[kind];
|
|
244
|
+
if (maxDays !== null) {
|
|
245
|
+
if (expiresMs === void 0) throw new FlagRegistryError("MISSING_EXPIRY", `Flag "${key}" (${kind}) needs an expiresAt, the maximum lifetime is ${maxDays} days`, key);
|
|
246
|
+
if (expiresMs - createdMs > maxDays * 864e5) throw new FlagRegistryError("EXCEEDS_MAX_LIFETIME", `Flag "${key}" (${kind}) lives longer than the maximum of ${maxDays} days`, key);
|
|
247
|
+
}
|
|
248
|
+
const description = record.description;
|
|
249
|
+
if (description !== void 0 && typeof description !== "string") throw new FlagRegistryError("INVALID_DESCRIPTION", `Flag "${key}" has a non-string description`, key);
|
|
250
|
+
const flag = {
|
|
251
|
+
key,
|
|
252
|
+
owner,
|
|
253
|
+
kind,
|
|
254
|
+
createdAt
|
|
255
|
+
};
|
|
256
|
+
if (expiresAt !== void 0) flag.expiresAt = expiresAt;
|
|
257
|
+
if (description !== void 0) flag.description = description;
|
|
258
|
+
return flag;
|
|
259
|
+
}
|
|
260
|
+
// src/scan.ts
|
|
261
|
+
const DEFAULT_FUNCTIONS = [
|
|
262
|
+
"isEnabled",
|
|
263
|
+
"getFlag",
|
|
264
|
+
"flag",
|
|
265
|
+
"evaluate"
|
|
266
|
+
];
|
|
267
|
+
/** Upper bound for a key literal. Longer literals are ignored. */
|
|
268
|
+
const MAX_LITERAL_LENGTH = 100;
|
|
269
|
+
/**
|
|
270
|
+
* Finds flag keys in source text.
|
|
271
|
+
*
|
|
272
|
+
* Recognized forms, with single or double quotes:
|
|
273
|
+
* - `isEnabled("key")`, `getFlag('key')` and the other configured function names
|
|
274
|
+
* - `flags.key` (identifier-style keys only)
|
|
275
|
+
* - `flags["key"]`
|
|
276
|
+
*
|
|
277
|
+
* Text in comments, and template literals (backticks), are ignored, including `${...}`
|
|
278
|
+
* placeholders in template literals that are not code. Calls inside `${...}` are still scanned.
|
|
279
|
+
* Calls and property access written inside a quoted string (`"isEnabled('x')"`) are ignored,
|
|
280
|
+
* because they are text, not code.
|
|
281
|
+
* This function does not read files. The caller passes the text.
|
|
282
|
+
*
|
|
283
|
+
* Limitations: regex literals containing quotes are not understood. A quote inside a
|
|
284
|
+
* regex literal can hide code on the same line.
|
|
285
|
+
*/
|
|
286
|
+
function findFlagKeysInSource(sourceText, options) {
|
|
287
|
+
const functions = options?.functions ?? DEFAULT_FUNCTIONS;
|
|
288
|
+
const { code, stringRanges } = maskWithStrings(sourceText);
|
|
289
|
+
const keys = /* @__PURE__ */ new Set();
|
|
290
|
+
if (functions.length > 0) {
|
|
291
|
+
const alternation = functions.map(escapeRegExp).join("|");
|
|
292
|
+
const callPattern = new RegExp(String.raw`\b(?:${alternation})\s*\(\s*(["'])([^"'\\\r\n]{1,${MAX_LITERAL_LENGTH}})\1(?=\s*[,)])`, "g");
|
|
293
|
+
for (const match of code.matchAll(callPattern)) {
|
|
294
|
+
if (isInRanges(stringRanges, match.index)) continue;
|
|
295
|
+
const key = match[2];
|
|
296
|
+
if (key !== void 0) keys.add(key);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
for (const match of code.matchAll(/\bflags\.([a-z][a-z0-9]*)(?![\w.-]|\s*\()/g)) {
|
|
300
|
+
if (isInRanges(stringRanges, match.index)) continue;
|
|
301
|
+
const key = match[1];
|
|
302
|
+
if (key !== void 0) keys.add(key);
|
|
303
|
+
}
|
|
304
|
+
const bracketPattern = new RegExp(String.raw`\bflags\s*\[\s*(["'])([^"'\\\r\n]{1,${MAX_LITERAL_LENGTH}})\1\s*\]`, "g");
|
|
305
|
+
for (const match of code.matchAll(bracketPattern)) {
|
|
306
|
+
if (isInRanges(stringRanges, match.index)) continue;
|
|
307
|
+
const key = match[2];
|
|
308
|
+
if (key !== void 0) keys.add(key);
|
|
309
|
+
}
|
|
310
|
+
return keys;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Like `maskNonCode`, and also returns the ranges of quoted string literals as flat
|
|
314
|
+
* `[start, end, start, end, ...]` pairs (end is exclusive), in source order.
|
|
315
|
+
*/
|
|
316
|
+
function maskWithStrings(source) {
|
|
317
|
+
const out = source.split("");
|
|
318
|
+
const n = source.length;
|
|
319
|
+
const stringRanges = [];
|
|
320
|
+
const frames = [{
|
|
321
|
+
kind: "code",
|
|
322
|
+
braces: 0,
|
|
323
|
+
interpolation: false
|
|
324
|
+
}];
|
|
325
|
+
const mask = (from, to) => {
|
|
326
|
+
for (let k = from; k < to; k++) if (out[k] !== "\n" && out[k] !== "\r") out[k] = " ";
|
|
327
|
+
};
|
|
328
|
+
let i = 0;
|
|
329
|
+
while (i < n) {
|
|
330
|
+
const top = frames[frames.length - 1];
|
|
331
|
+
if (top === void 0) break;
|
|
332
|
+
const ch = source[i];
|
|
333
|
+
const next = source[i + 1];
|
|
334
|
+
if (top.kind === "template") {
|
|
335
|
+
if (ch === "\\") {
|
|
336
|
+
mask(i, i + 2);
|
|
337
|
+
i += 2;
|
|
338
|
+
} else if (ch === "`") {
|
|
339
|
+
mask(i, i + 1);
|
|
340
|
+
frames.pop();
|
|
341
|
+
i++;
|
|
342
|
+
} else if (ch === "$" && next === "{") {
|
|
343
|
+
mask(i, i + 2);
|
|
344
|
+
frames.push({
|
|
345
|
+
kind: "code",
|
|
346
|
+
braces: 0,
|
|
347
|
+
interpolation: true
|
|
348
|
+
});
|
|
349
|
+
i += 2;
|
|
350
|
+
} else {
|
|
351
|
+
mask(i, i + 1);
|
|
352
|
+
i++;
|
|
353
|
+
}
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
if (ch === "/" && next === "/") {
|
|
357
|
+
const newline = source.indexOf("\n", i);
|
|
358
|
+
const end = newline === -1 ? n : newline;
|
|
359
|
+
mask(i, end);
|
|
360
|
+
i = end;
|
|
361
|
+
} else if (ch === "/" && next === "*") {
|
|
362
|
+
const close = source.indexOf("*/", i + 2);
|
|
363
|
+
const end = close === -1 ? n : close + 2;
|
|
364
|
+
mask(i, end);
|
|
365
|
+
i = end;
|
|
366
|
+
} else if (ch === "\"" || ch === "'") {
|
|
367
|
+
let j = i + 1;
|
|
368
|
+
while (j < n && source[j] !== ch && source[j] !== "\n") j += source[j] === "\\" ? 2 : 1;
|
|
369
|
+
const end = source[j] === ch ? j + 1 : j;
|
|
370
|
+
stringRanges.push(i, end);
|
|
371
|
+
i = end;
|
|
372
|
+
} else if (ch === "`") {
|
|
373
|
+
mask(i, i + 1);
|
|
374
|
+
frames.push({ kind: "template" });
|
|
375
|
+
i++;
|
|
376
|
+
} else if (ch === "{") {
|
|
377
|
+
top.braces++;
|
|
378
|
+
i++;
|
|
379
|
+
} else if (ch === "}") {
|
|
380
|
+
if (top.interpolation && top.braces === 0) {
|
|
381
|
+
mask(i, i + 1);
|
|
382
|
+
frames.pop();
|
|
383
|
+
} else if (top.braces > 0) top.braces--;
|
|
384
|
+
i++;
|
|
385
|
+
} else i++;
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
code: out.join(""),
|
|
389
|
+
stringRanges
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
/** True when `index` lies in one of the sorted `[start, end)` pairs of `ranges`. */
|
|
393
|
+
function isInRanges(ranges, index) {
|
|
394
|
+
if (index === void 0) return false;
|
|
395
|
+
let lo = 0;
|
|
396
|
+
let hi = ranges.length / 2 - 1;
|
|
397
|
+
while (lo <= hi) {
|
|
398
|
+
const mid = lo + hi >> 1;
|
|
399
|
+
const start = ranges[mid * 2] ?? 0;
|
|
400
|
+
const end = ranges[mid * 2 + 1] ?? 0;
|
|
401
|
+
if (index < start) hi = mid - 1;
|
|
402
|
+
else if (index >= end) lo = mid + 1;
|
|
403
|
+
else return true;
|
|
404
|
+
}
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
function escapeRegExp(value) {
|
|
408
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
409
|
+
}
|
|
410
|
+
export { DEFAULT_MAX_LIFETIME_DAYS, FlagHygieneError, FlagRegistryError, assertFlagHygiene, checkFlagHygiene, defineFlags, findFlagKeysInSource };
|
|
411
|
+
|
|
412
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/errors.ts","../src/dates.ts","../src/lifetimes.ts","../src/hygiene.ts","../src/registry.ts","../src/scan.ts"],"sourcesContent":["import type { HygieneCode, HygieneFinding } from \"./types\";\n\nexport type FlagRegistryErrorCode =\n\t| \"INVALID_DEFINITION\"\n\t| \"INVALID_KEY\"\n\t| \"DUPLICATE_KEY\"\n\t| \"EMPTY_OWNER\"\n\t| \"INVALID_KIND\"\n\t| \"INVALID_DESCRIPTION\"\n\t| \"INVALID_DATE\"\n\t| \"EXPIRY_NOT_AFTER_CREATION\"\n\t| \"MISSING_EXPIRY\"\n\t| \"EXCEEDS_MAX_LIFETIME\"\n\t| \"INVALID_OPTIONS\";\n\n/**\n * Thrown when a flag register or its options are invalid.\n */\nexport class FlagRegistryError extends Error {\n\treadonly code: FlagRegistryErrorCode;\n\t/** The offending flag key, when it is known. */\n\treadonly key: string | undefined;\n\n\tconstructor(code: FlagRegistryErrorCode, message: string, key?: string) {\n\t\tsuper(message);\n\t\tthis.name = \"FlagRegistryError\";\n\t\tthis.code = code;\n\t\tthis.key = key;\n\t}\n}\n\n/**\n * Thrown by `assertFlagHygiene` when findings match the `failOn` codes.\n */\nexport class FlagHygieneError extends Error {\n\treadonly code: HygieneCode;\n\treadonly findings: readonly HygieneFinding[];\n\n\tconstructor(findings: readonly HygieneFinding[]) {\n\t\tconst lines = findings.map((finding) => ` - [${finding.code}] ${finding.message}`);\n\t\tsuper(`Flag hygiene check failed with ${findings.length} finding(s):\\n${lines.join(\"\\n\")}`);\n\t\tthis.name = \"FlagHygieneError\";\n\t\tthis.code = findings[0]?.code ?? \"UNUSED\";\n\t\tthis.findings = findings;\n\t}\n}\n","export const DAY_MS = 86_400_000;\n\n/**\n * `YYYY-MM-DD`, optionally followed by `T HH:MM[:SS[.fraction]]` and a mandatory timezone.\n * Only fixed quantifiers and a single optional group, so matching is linear.\n */\nconst ISO_PATTERN =\n\t/^(\\d{4})-(\\d{2})-(\\d{2})(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{1,9}))?)?(Z|[+-]\\d{2}:\\d{2}))?$/;\n\nfunction isLeapYear(year: number): boolean {\n\treturn (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n}\n\nfunction daysInMonth(year: number, month: number): number {\n\tconst days = [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n\treturn days[month - 1] ?? 0;\n}\n\n/**\n * Parses a strict ISO 8601 date or date-time and returns epoch milliseconds.\n * Returns `undefined` for anything that is not a real calendar date and time.\n */\nexport function parseIsoDate(value: unknown): number | undefined {\n\tif (typeof value !== \"string\") {\n\t\treturn undefined;\n\t}\n\tconst match = ISO_PATTERN.exec(value);\n\tif (match === null) {\n\t\treturn undefined;\n\t}\n\n\tconst year = Number(match[1]);\n\tconst month = Number(match[2]);\n\tconst day = Number(match[3]);\n\tif (month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month)) {\n\t\treturn undefined;\n\t}\n\n\tif (match[4] !== undefined) {\n\t\tconst hours = Number(match[4]);\n\t\tconst minutes = Number(match[5]);\n\t\tconst seconds = match[6] === undefined ? 0 : Number(match[6]);\n\t\tif (hours > 23 || minutes > 59 || seconds > 59) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst offset = match[8];\n\t\tif (offset !== undefined && offset !== \"Z\") {\n\t\t\tconst offsetHours = Number(offset.slice(1, 3));\n\t\t\tconst offsetMinutes = Number(offset.slice(4, 6));\n\t\t\tif (offsetHours > 23 || offsetMinutes > 59) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst time = Date.parse(value);\n\treturn Number.isNaN(time) ? undefined : time;\n}\n","import { FlagRegistryError } from \"./errors\";\nimport type { FlagKind, LifetimeOverrides, MaxLifetimeDays } from \"./types\";\n\nexport const FLAG_KINDS: readonly FlagKind[] = [\"release\", \"experiment\", \"ops\", \"permission\"];\n\n/**\n * Default maximum lifetimes. `permission` flags may live without limit.\n */\nexport const DEFAULT_MAX_LIFETIME_DAYS: MaxLifetimeDays = Object.freeze({\n\trelease: 90,\n\texperiment: 30,\n\tops: 365,\n\tpermission: null,\n});\n\nexport function isFlagKind(value: unknown): value is FlagKind {\n\treturn typeof value === \"string\" && (FLAG_KINDS as readonly string[]).includes(value);\n}\n\n/**\n * Merges user overrides into the defaults and validates them.\n */\nexport function resolveMaxLifetimeDays(overrides: LifetimeOverrides | undefined): MaxLifetimeDays {\n\tconst resolved: Record<FlagKind, number | null> = { ...DEFAULT_MAX_LIFETIME_DAYS };\n\tif (overrides === undefined) {\n\t\treturn resolved;\n\t}\n\tif (typeof overrides !== \"object\" || overrides === null) {\n\t\tthrow new FlagRegistryError(\"INVALID_OPTIONS\", \"maxLifetimeDays must be an object\");\n\t}\n\n\tfor (const kind of Object.keys(overrides)) {\n\t\tif (!isFlagKind(kind)) {\n\t\t\tthrow new FlagRegistryError(\n\t\t\t\t\"INVALID_OPTIONS\",\n\t\t\t\t`Unknown flag kind in maxLifetimeDays: \"${kind}\"`,\n\t\t\t);\n\t\t}\n\t\tconst value = overrides[kind];\n\t\tif (value === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (value !== null && !(Number.isInteger(value) && value > 0)) {\n\t\t\tthrow new FlagRegistryError(\n\t\t\t\t\"INVALID_OPTIONS\",\n\t\t\t\t`maxLifetimeDays.${kind} must be a positive integer or null, got ${String(value)}`,\n\t\t\t);\n\t\t}\n\t\tresolved[kind] = value;\n\t}\n\treturn resolved;\n}\n","import { DAY_MS, parseIsoDate } from \"./dates\";\nimport { FlagHygieneError, FlagRegistryError } from \"./errors\";\nimport { isFlagKind, resolveMaxLifetimeDays } from \"./lifetimes\";\nimport type {\n\tAssertFlagHygieneOptions,\n\tCheckFlagHygieneOptions,\n\tFlagDefinition,\n\tHygieneCode,\n\tHygieneFinding,\n} from \"./types\";\n\n/** Order of codes in the result when two findings share a key. */\nconst CODE_ORDER: readonly HygieneCode[] = [\n\t\"EXPIRED\",\n\t\"EXCEEDS_MAX_LIFETIME\",\n\t\"UNUSED\",\n\t\"UNREGISTERED_USAGE\",\n];\n\n/**\n * Checks a flag register for flags that should be cleaned up.\n *\n * - `EXPIRED`: `now` is at or after `expiresAt`.\n * - `EXCEEDS_MAX_LIFETIME`: the flag lives longer than the configured maximum for its kind.\n * This catches flags registered before a limit was lowered.\n * - `UNUSED`: only when `usedKeys` is given. The key is registered but not used.\n * - `UNREGISTERED_USAGE`: only when `usedKeys` is given. The key is used but not registered.\n *\n * Findings are sorted by key, then by code.\n */\nexport function checkFlagHygiene(options: CheckFlagHygieneOptions): readonly HygieneFinding[] {\n\tconst nowMs = resolveNow(options.now);\n\tconst lifetimes = resolveMaxLifetimeDays(options.maxLifetimeDays);\n\n\tconst registered = new Set<string>();\n\tconst findings: HygieneFinding[] = [];\n\n\tfor (const flag of options.flags) {\n\t\tif (registered.has(flag.key)) {\n\t\t\tthrow new FlagRegistryError(\"DUPLICATE_KEY\", `Duplicate flag key \"${flag.key}\"`, flag.key);\n\t\t}\n\t\tregistered.add(flag.key);\n\t\tcollectLifecycleFindings(flag, nowMs, lifetimes[flag.kind], findings);\n\t}\n\n\tif (options.usedKeys !== undefined) {\n\t\tconst used = new Set(options.usedKeys);\n\t\tfor (const key of registered) {\n\t\t\tif (!used.has(key)) {\n\t\t\t\tfindings.push({\n\t\t\t\t\tkey,\n\t\t\t\t\tcode: \"UNUSED\",\n\t\t\t\t\tmessage: `Flag \"${key}\" is registered but not used`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tfor (const key of used) {\n\t\t\tif (!registered.has(key)) {\n\t\t\t\tfindings.push({\n\t\t\t\t\tkey,\n\t\t\t\t\tcode: \"UNREGISTERED_USAGE\",\n\t\t\t\t\tmessage: `Flag \"${key}\" is used but not registered`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\treturn findings.sort(\n\t\t(a, b) =>\n\t\t\tcompareStrings(a.key, b.key) || CODE_ORDER.indexOf(a.code) - CODE_ORDER.indexOf(b.code),\n\t);\n}\n\n/**\n * Throws `FlagHygieneError` if any finding has a code listed in `failOn`.\n * Defaults to all codes. Use it in tests or CI.\n */\nexport function assertFlagHygiene(\n\tfindings: readonly HygieneFinding[],\n\toptions?: AssertFlagHygieneOptions,\n): void {\n\tconst failOn = new Set<HygieneCode>(options?.failOn ?? CODE_ORDER);\n\tconst failing = findings.filter((finding) => failOn.has(finding.code));\n\tif (failing.length > 0) {\n\t\tthrow new FlagHygieneError(failing);\n\t}\n}\n\nfunction collectLifecycleFindings(\n\tflag: FlagDefinition,\n\tnowMs: number,\n\tmaxDays: number | null | undefined,\n\tfindings: HygieneFinding[],\n): void {\n\tif (!isFlagKind(flag.kind)) {\n\t\tthrow new FlagRegistryError(\"INVALID_KIND\", `Flag \"${flag.key}\" has invalid kind`, flag.key);\n\t}\n\tconst createdMs = parseIsoDate(flag.createdAt);\n\tif (createdMs === undefined) {\n\t\tthrow new FlagRegistryError(\n\t\t\t\"INVALID_DATE\",\n\t\t\t`Flag \"${flag.key}\" has invalid createdAt`,\n\t\t\tflag.key,\n\t\t);\n\t}\n\tif (flag.expiresAt === undefined) {\n\t\treturn;\n\t}\n\tconst expiresMs = parseIsoDate(flag.expiresAt);\n\tif (expiresMs === undefined) {\n\t\tthrow new FlagRegistryError(\n\t\t\t\"INVALID_DATE\",\n\t\t\t`Flag \"${flag.key}\" has invalid expiresAt`,\n\t\t\tflag.key,\n\t\t);\n\t}\n\n\tif (nowMs >= expiresMs) {\n\t\tfindings.push({\n\t\t\tkey: flag.key,\n\t\t\tcode: \"EXPIRED\",\n\t\t\tmessage: `Flag \"${flag.key}\" expired at ${flag.expiresAt}`,\n\t\t});\n\t}\n\n\tif (maxDays !== null && maxDays !== undefined) {\n\t\tconst lifetimeMs = expiresMs - createdMs;\n\t\tif (lifetimeMs > maxDays * DAY_MS) {\n\t\t\tfindings.push({\n\t\t\t\tkey: flag.key,\n\t\t\t\tcode: \"EXCEEDS_MAX_LIFETIME\",\n\t\t\t\tmessage: `Flag \"${flag.key}\" (${flag.kind}) lives ${lifetimeMs / DAY_MS} days, the maximum is ${maxDays}`,\n\t\t\t});\n\t\t}\n\t}\n}\n\nfunction resolveNow(now: Date | undefined): number {\n\tif (now === undefined) {\n\t\treturn Date.now();\n\t}\n\tconst time = now.getTime();\n\tif (Number.isNaN(time)) {\n\t\tthrow new FlagRegistryError(\"INVALID_OPTIONS\", \"now is an invalid Date\");\n\t}\n\treturn time;\n}\n\nfunction compareStrings(a: string, b: string): number {\n\tif (a === b) {\n\t\treturn 0;\n\t}\n\treturn a < b ? -1 : 1;\n}\n","import { DAY_MS, parseIsoDate } from \"./dates\";\nimport { FlagRegistryError } from \"./errors\";\nimport { isFlagKind, resolveMaxLifetimeDays } from \"./lifetimes\";\nimport type { DefineFlagsOptions, FlagDefinition, MaxLifetimeDays } from \"./types\";\n\nconst KEY_PATTERN = /^[a-z][a-z0-9-.]{1,79}$/;\n\n/**\n * Validates a flag register and returns a frozen, normalized copy.\n *\n * Throws `FlagRegistryError` with a `code` for the first invalid entry.\n * A flag kind with a finite maximum lifetime requires `expiresAt`, so that a flag\n * cannot escape the limit by omitting the date.\n */\nexport function defineFlags(\n\tdefinitions: readonly FlagDefinition[],\n\toptions?: DefineFlagsOptions,\n): readonly FlagDefinition[] {\n\tif (!Array.isArray(definitions)) {\n\t\tthrow new FlagRegistryError(\"INVALID_DEFINITION\", \"defineFlags expects an array of flags\");\n\t}\n\tconst maxLifetimeDays = resolveMaxLifetimeDays(options?.maxLifetimeDays);\n\n\tconst seen = new Set<string>();\n\tconst result: FlagDefinition[] = [];\n\tfor (const [index, raw] of definitions.entries()) {\n\t\tconst flag = validateDefinition(raw, index, maxLifetimeDays);\n\t\tif (seen.has(flag.key)) {\n\t\t\tthrow new FlagRegistryError(\"DUPLICATE_KEY\", `Duplicate flag key \"${flag.key}\"`, flag.key);\n\t\t}\n\t\tseen.add(flag.key);\n\t\tresult.push(flag);\n\t}\n\treturn Object.freeze(result);\n}\n\nfunction validateDefinition(\n\traw: unknown,\n\tindex: number,\n\tmaxLifetimeDays: MaxLifetimeDays,\n): FlagDefinition {\n\tif (typeof raw !== \"object\" || raw === null) {\n\t\tthrow new FlagRegistryError(\"INVALID_DEFINITION\", `Flag at index ${index} is not an object`);\n\t}\n\tconst record = raw as Record<string, unknown>;\n\n\tconst key = record.key;\n\tif (typeof key !== \"string\" || !KEY_PATTERN.test(key)) {\n\t\tthrow new FlagRegistryError(\n\t\t\t\"INVALID_KEY\",\n\t\t\t`Invalid flag key at index ${index}: ${JSON.stringify(key)} (must match ${KEY_PATTERN.source})`,\n\t\t\ttypeof key === \"string\" ? key : undefined,\n\t\t);\n\t}\n\n\tconst owner = record.owner;\n\tif (typeof owner !== \"string\" || owner.trim() === \"\") {\n\t\tthrow new FlagRegistryError(\"EMPTY_OWNER\", `Flag \"${key}\" has no owner`, key);\n\t}\n\n\tconst kind = record.kind;\n\tif (!isFlagKind(kind)) {\n\t\tthrow new FlagRegistryError(\n\t\t\t\"INVALID_KIND\",\n\t\t\t`Flag \"${key}\" has invalid kind ${JSON.stringify(kind)}`,\n\t\t\tkey,\n\t\t);\n\t}\n\n\tconst createdAt = record.createdAt;\n\tconst createdMs = parseIsoDate(createdAt);\n\tif (createdMs === undefined) {\n\t\tthrow new FlagRegistryError(\n\t\t\t\"INVALID_DATE\",\n\t\t\t`Flag \"${key}\" has invalid createdAt ${JSON.stringify(createdAt)}`,\n\t\t\tkey,\n\t\t);\n\t}\n\n\tconst expiresAt = record.expiresAt;\n\tlet expiresMs: number | undefined;\n\tif (expiresAt !== undefined) {\n\t\texpiresMs = parseIsoDate(expiresAt);\n\t\tif (expiresMs === undefined) {\n\t\t\tthrow new FlagRegistryError(\n\t\t\t\t\"INVALID_DATE\",\n\t\t\t\t`Flag \"${key}\" has invalid expiresAt ${JSON.stringify(expiresAt)}`,\n\t\t\t\tkey,\n\t\t\t);\n\t\t}\n\t\tif (expiresMs <= createdMs) {\n\t\t\tthrow new FlagRegistryError(\n\t\t\t\t\"EXPIRY_NOT_AFTER_CREATION\",\n\t\t\t\t`Flag \"${key}\" expires at ${String(expiresAt)}, which is not after createdAt`,\n\t\t\t\tkey,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst maxDays = maxLifetimeDays[kind];\n\tif (maxDays !== null) {\n\t\tif (expiresMs === undefined) {\n\t\t\tthrow new FlagRegistryError(\n\t\t\t\t\"MISSING_EXPIRY\",\n\t\t\t\t`Flag \"${key}\" (${kind}) needs an expiresAt, the maximum lifetime is ${maxDays} days`,\n\t\t\t\tkey,\n\t\t\t);\n\t\t}\n\t\tif (expiresMs - createdMs > maxDays * DAY_MS) {\n\t\t\tthrow new FlagRegistryError(\n\t\t\t\t\"EXCEEDS_MAX_LIFETIME\",\n\t\t\t\t`Flag \"${key}\" (${kind}) lives longer than the maximum of ${maxDays} days`,\n\t\t\t\tkey,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst description = record.description;\n\tif (description !== undefined && typeof description !== \"string\") {\n\t\tthrow new FlagRegistryError(\n\t\t\t\"INVALID_DESCRIPTION\",\n\t\t\t`Flag \"${key}\" has a non-string description`,\n\t\t\tkey,\n\t\t);\n\t}\n\n\tconst flag: FlagDefinition = { key, owner, kind, createdAt: createdAt as string };\n\tif (expiresAt !== undefined) {\n\t\tflag.expiresAt = expiresAt as string;\n\t}\n\tif (description !== undefined) {\n\t\tflag.description = description;\n\t}\n\treturn flag;\n}\n","import type { FindFlagKeysOptions } from \"./types\";\n\nconst DEFAULT_FUNCTIONS: readonly string[] = [\"isEnabled\", \"getFlag\", \"flag\", \"evaluate\"];\n\n/** Upper bound for a key literal. Longer literals are ignored. */\nconst MAX_LITERAL_LENGTH = 100;\n\n/**\n * Finds flag keys in source text.\n *\n * Recognized forms, with single or double quotes:\n * - `isEnabled(\"key\")`, `getFlag('key')` and the other configured function names\n * - `flags.key` (identifier-style keys only)\n * - `flags[\"key\"]`\n *\n * Text in comments, and template literals (backticks), are ignored, including `${...}`\n * placeholders in template literals that are not code. Calls inside `${...}` are still scanned.\n * Calls and property access written inside a quoted string (`\"isEnabled('x')\"`) are ignored,\n * because they are text, not code.\n * This function does not read files. The caller passes the text.\n *\n * Limitations: regex literals containing quotes are not understood. A quote inside a\n * regex literal can hide code on the same line.\n */\nexport function findFlagKeysInSource(\n\tsourceText: string,\n\toptions?: FindFlagKeysOptions,\n): Set<string> {\n\tconst functions = options?.functions ?? DEFAULT_FUNCTIONS;\n\tconst { code, stringRanges } = maskWithStrings(sourceText);\n\tconst keys = new Set<string>();\n\n\tif (functions.length > 0) {\n\t\tconst alternation = functions.map(escapeRegExp).join(\"|\");\n\t\t// The literal must be closed by the same quote and be a whole argument, so that\n\t\t// `isEnabled(\"a\" + b)` is not read as the key \"a\".\n\t\tconst callPattern = new RegExp(\n\t\t\tString.raw`\\b(?:${alternation})\\s*\\(\\s*([\"'])([^\"'\\\\\\r\\n]{1,${MAX_LITERAL_LENGTH}})\\1(?=\\s*[,)])`,\n\t\t\t\"g\",\n\t\t);\n\t\tfor (const match of code.matchAll(callPattern)) {\n\t\t\tif (isInRanges(stringRanges, match.index)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst key = match[2];\n\t\t\tif (key !== undefined) {\n\t\t\t\tkeys.add(key);\n\t\t\t}\n\t\t}\n\t}\n\n\t// `flags.key` is only matched for identifier-like keys, and not for method calls like\n\t// `flags.get(` or chained access like `flags.a.b`.\n\tfor (const match of code.matchAll(/\\bflags\\.([a-z][a-z0-9]*)(?![\\w.-]|\\s*\\()/g)) {\n\t\tif (isInRanges(stringRanges, match.index)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst key = match[1];\n\t\tif (key !== undefined) {\n\t\t\tkeys.add(key);\n\t\t}\n\t}\n\n\tconst bracketPattern = new RegExp(\n\t\tString.raw`\\bflags\\s*\\[\\s*([\"'])([^\"'\\\\\\r\\n]{1,${MAX_LITERAL_LENGTH}})\\1\\s*\\]`,\n\t\t\"g\",\n\t);\n\tfor (const match of code.matchAll(bracketPattern)) {\n\t\tif (isInRanges(stringRanges, match.index)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst key = match[2];\n\t\tif (key !== undefined) {\n\t\t\tkeys.add(key);\n\t\t}\n\t}\n\n\treturn keys;\n}\n\ntype Frame = { kind: \"template\" } | { kind: \"code\"; braces: number; interpolation: boolean };\n\n/**\n * Returns `source` with comments and template-literal text replaced by spaces.\n * Newlines are kept, so the output has the same length and line structure.\n * Single- and double-quoted strings are kept, because keys are read from them.\n * Runs in linear time: each character is visited a constant number of times.\n */\nexport function maskNonCode(source: string): string {\n\treturn maskWithStrings(source).code;\n}\n\n/**\n * Like `maskNonCode`, and also returns the ranges of quoted string literals as flat\n * `[start, end, start, end, ...]` pairs (end is exclusive), in source order.\n */\nfunction maskWithStrings(source: string): { code: string; stringRanges: number[] } {\n\tconst out = source.split(\"\");\n\tconst n = source.length;\n\tconst stringRanges: number[] = [];\n\tconst frames: Frame[] = [{ kind: \"code\", braces: 0, interpolation: false }];\n\n\tconst mask = (from: number, to: number): void => {\n\t\tfor (let k = from; k < to; k++) {\n\t\t\tif (out[k] !== \"\\n\" && out[k] !== \"\\r\") {\n\t\t\t\tout[k] = \" \";\n\t\t\t}\n\t\t}\n\t};\n\n\tlet i = 0;\n\twhile (i < n) {\n\t\tconst top = frames[frames.length - 1];\n\t\tif (top === undefined) {\n\t\t\tbreak;\n\t\t}\n\t\tconst ch = source[i];\n\t\tconst next = source[i + 1];\n\n\t\tif (top.kind === \"template\") {\n\t\t\tif (ch === \"\\\\\") {\n\t\t\t\tmask(i, i + 2);\n\t\t\t\ti += 2;\n\t\t\t} else if (ch === \"`\") {\n\t\t\t\tmask(i, i + 1);\n\t\t\t\tframes.pop();\n\t\t\t\ti++;\n\t\t\t} else if (ch === \"$\" && next === \"{\") {\n\t\t\t\tmask(i, i + 2);\n\t\t\t\tframes.push({ kind: \"code\", braces: 0, interpolation: true });\n\t\t\t\ti += 2;\n\t\t\t} else {\n\t\t\t\tmask(i, i + 1);\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (ch === \"/\" && next === \"/\") {\n\t\t\tconst newline = source.indexOf(\"\\n\", i);\n\t\t\tconst end = newline === -1 ? n : newline;\n\t\t\tmask(i, end);\n\t\t\ti = end;\n\t\t} else if (ch === \"/\" && next === \"*\") {\n\t\t\tconst close = source.indexOf(\"*/\", i + 2);\n\t\t\tconst end = close === -1 ? n : close + 2;\n\t\t\tmask(i, end);\n\t\t\ti = end;\n\t\t} else if (ch === '\"' || ch === \"'\") {\n\t\t\t// Strings end at the matching quote or at a line break (unterminated string).\n\t\t\tlet j = i + 1;\n\t\t\twhile (j < n && source[j] !== ch && source[j] !== \"\\n\") {\n\t\t\t\tj += source[j] === \"\\\\\" ? 2 : 1;\n\t\t\t}\n\t\t\tconst end = source[j] === ch ? j + 1 : j;\n\t\t\tstringRanges.push(i, end);\n\t\t\ti = end;\n\t\t} else if (ch === \"`\") {\n\t\t\tmask(i, i + 1);\n\t\t\tframes.push({ kind: \"template\" });\n\t\t\ti++;\n\t\t} else if (ch === \"{\") {\n\t\t\ttop.braces++;\n\t\t\ti++;\n\t\t} else if (ch === \"}\") {\n\t\t\tif (top.interpolation && top.braces === 0) {\n\t\t\t\tmask(i, i + 1);\n\t\t\t\tframes.pop();\n\t\t\t} else if (top.braces > 0) {\n\t\t\t\ttop.braces--;\n\t\t\t}\n\t\t\ti++;\n\t\t} else {\n\t\t\ti++;\n\t\t}\n\t}\n\n\treturn { code: out.join(\"\"), stringRanges };\n}\n\n/** True when `index` lies in one of the sorted `[start, end)` pairs of `ranges`. */\nfunction isInRanges(ranges: readonly number[], index: number | undefined): boolean {\n\tif (index === undefined) {\n\t\treturn false;\n\t}\n\tlet lo = 0;\n\tlet hi = ranges.length / 2 - 1;\n\twhile (lo <= hi) {\n\t\tconst mid = (lo + hi) >> 1;\n\t\tconst start = ranges[mid * 2] ?? 0;\n\t\tconst end = ranges[mid * 2 + 1] ?? 0;\n\t\tif (index < start) {\n\t\t\thi = mid - 1;\n\t\t} else if (index >= end) {\n\t\t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AAI,KAAK,EAAE;EAAG;CAAa;AAC3C;;AAGA,SAAS,WAAW,QAA2B,OAAoC;CAClF,IAAI,UAAU,KAAA,GACb,OAAO;CAER,IAAI,KAAK;CACT,IAAI,KAAK,OAAO,SAAS,IAAI;CAC7B,OAAO,MAAM,IAAI;EAChB,MAAM,MAAO,KAAK,MAAO;EACzB,MAAM,QAAQ,OAAO,MAAM,MAAM;EACjC,MAAM,MAAM,OAAO,MAAM,IAAI,MAAM;EACnC,IAAI,QAAQ,OACX,KAAK,MAAM;OACL,IAAI,SAAS,KACnB,KAAK,MAAM;OAEX,OAAO;CAET;CACA,OAAO;AACR;AAEA,SAAS,aAAa,OAAuB;CAC5C,OAAO,MAAM,QAAQ,uBAAuB,MAAM;AACnD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,82 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yedoma-labs/kulyn-flags",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Feature flag lifecycle registry with owners, expiry dates and CI hygiene checks",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"feature-flags",
|
|
29
|
+
"feature-toggles",
|
|
30
|
+
"flag-lifecycle",
|
|
31
|
+
"tech-debt",
|
|
32
|
+
"dead-flags",
|
|
33
|
+
"ci"
|
|
34
|
+
],
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/yedoma-labs/kulyn-flags"
|
|
38
|
+
},
|
|
39
|
+
"author": "",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"simple-git-hooks": {
|
|
42
|
+
"pre-commit": "pnpm exec lint-staged",
|
|
43
|
+
"pre-push": "pnpm run typecheck && pnpm run test",
|
|
44
|
+
"commit-msg": "pnpm exec commitlint --edit $1"
|
|
45
|
+
},
|
|
46
|
+
"lint-staged": {
|
|
47
|
+
"*.ts": [
|
|
48
|
+
"biome check --write"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@biomejs/biome": "2.6.3",
|
|
53
|
+
"@commitlint/cli": "^21.2.4",
|
|
54
|
+
"@commitlint/config-conventional": "^21.2.4",
|
|
55
|
+
"@semantic-release/changelog": "^7.0.0",
|
|
56
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
57
|
+
"@semantic-release/exec": "^7.1.0",
|
|
58
|
+
"@semantic-release/git": "^11.0.1",
|
|
59
|
+
"@semantic-release/github": "^12.0.10",
|
|
60
|
+
"@semantic-release/npm": "^13.2.0",
|
|
61
|
+
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
62
|
+
"@types/node": "26.6.5",
|
|
63
|
+
"@typescript/typescript6": "^6.0.2",
|
|
64
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
65
|
+
"lint-staged": "^17.6.0",
|
|
66
|
+
"semantic-release": "^25.0.9",
|
|
67
|
+
"simple-git-hooks": "^2.14.0",
|
|
68
|
+
"tsdown": "^0.23.2",
|
|
69
|
+
"typescript": "7.0.2",
|
|
70
|
+
"vitest": "5.0.5"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "tsdown",
|
|
74
|
+
"test": "vitest run",
|
|
75
|
+
"test:watch": "vitest",
|
|
76
|
+
"test:coverage": "vitest run --coverage",
|
|
77
|
+
"lint": "biome check src tests",
|
|
78
|
+
"lint:fix": "biome check --write src tests",
|
|
79
|
+
"format": "biome format --write src tests",
|
|
80
|
+
"typecheck": "tsc --noEmit"
|
|
81
|
+
}
|
|
6
82
|
}
|