@townco/secret 0.1.126 → 0.1.128

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@townco/secret",
3
- "version": "0.1.126",
3
+ "version": "0.1.128",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -21,11 +21,11 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@1password/connect": "^1.4.2",
24
- "@townco/env": "0.1.76"
24
+ "@townco/env": "0.1.78"
25
25
  },
26
26
  "devDependencies": {
27
- "@townco/core": "0.0.104",
28
- "@townco/tsconfig": "0.1.123",
27
+ "@townco/core": "0.0.106",
28
+ "@townco/tsconfig": "0.1.125",
29
29
  "@types/bun": "^1.3.1"
30
30
  }
31
31
  }
@@ -1,107 +0,0 @@
1
- /**
2
- * Represents a line in an .env file
3
- */
4
- type EnvLine =
5
- | {
6
- type: "comment";
7
- content: string;
8
- }
9
- | {
10
- type: "blank";
11
- }
12
- | {
13
- type: "entry";
14
- key: string;
15
- value: string;
16
- raw: string;
17
- };
18
- /**
19
- * A data structure that represents a parsed .env file while preserving
20
- * all original content including comments, blank lines, and order.
21
- */
22
- export declare class EnvFile {
23
- private lines;
24
- constructor(lines?: EnvLine[]);
25
- /**
26
- * Parse a .env file string into an EnvFile structure
27
- */
28
- static parse(content: string): EnvFile;
29
- /**
30
- * Serialize the EnvFile back to a string
31
- */
32
- toString(): string;
33
- /**
34
- * Get all entries as a key-value record
35
- */
36
- toRecord(): Record<string, string>;
37
- /**
38
- * Find an entry line by key
39
- */
40
- private findEntry;
41
- /**
42
- * Find the index of an entry by key
43
- */
44
- private findEntryIndex;
45
- /**
46
- * Create an entry line from key and value
47
- */
48
- private createEntry;
49
- /**
50
- * Normalize a value by ensuring it's properly quoted
51
- */
52
- private normalizeValue;
53
- /**
54
- * Find the insertion index for a new entry (before the final blank line if present)
55
- */
56
- private findInsertionIndex;
57
- /**
58
- * Get the value for a specific key
59
- */
60
- get(key: string): string | undefined;
61
- /**
62
- * Set a value for a key. If the key exists, updates it in place.
63
- * If it doesn't exist, appends it above the final newline (if present).
64
- * Values are always double quoted.
65
- */
66
- set(key: string, value: string): this;
67
- /**
68
- * Delete a key-value entry
69
- */
70
- delete(key: string): this;
71
- /**
72
- * Check if a key exists
73
- */
74
- has(key: string): boolean;
75
- /**
76
- * Get all keys
77
- */
78
- keys(): string[];
79
- /**
80
- * Iterate over all entries
81
- */
82
- entries(): IterableIterator<[string, string]>;
83
- /**
84
- * Apply a function to all entries and return a new EnvFile
85
- */
86
- map(fn: (key: string, value: string) => [string, string]): EnvFile;
87
- /**
88
- * Filter entries based on a predicate
89
- */
90
- filter(fn: (key: string, value: string) => boolean): EnvFile;
91
- /**
92
- * Add a comment line
93
- */
94
- addComment(content: string): this;
95
- /**
96
- * Add a blank line
97
- */
98
- addBlank(): this;
99
- /**
100
- * Get the raw lines array for custom operations
101
- */
102
- getLines(): readonly EnvLine[];
103
- /**
104
- * Create a clone of this EnvFile
105
- */
106
- clone(): EnvFile;
107
- }
package/dist/env-file.js DELETED
@@ -1,205 +0,0 @@
1
- /**
2
- * A data structure that represents a parsed .env file while preserving
3
- * all original content including comments, blank lines, and order.
4
- */
5
- export class EnvFile {
6
- lines;
7
- constructor(lines = []) {
8
- this.lines = lines;
9
- }
10
- /**
11
- * Parse a .env file string into an EnvFile structure
12
- */
13
- static parse(content) {
14
- const lines = content.split("\n").map((line) => {
15
- const trimmed = line.trim();
16
- if (trimmed === "") {
17
- return { type: "blank" };
18
- }
19
- if (trimmed.startsWith("#")) {
20
- return { type: "comment", content: line };
21
- }
22
- const equalsIndex = line.indexOf("=");
23
- if (equalsIndex === -1) {
24
- // Malformed line, treat as comment
25
- return { type: "comment", content: line };
26
- }
27
- const key = line.substring(0, equalsIndex).trim();
28
- const value = line.substring(equalsIndex + 1);
29
- return { type: "entry", key, value, raw: line };
30
- });
31
- return new EnvFile(lines);
32
- }
33
- /**
34
- * Serialize the EnvFile back to a string
35
- */
36
- toString() {
37
- return this.lines
38
- .map((line) => {
39
- switch (line.type) {
40
- case "blank":
41
- return "";
42
- case "comment":
43
- return line.content;
44
- case "entry":
45
- return line.raw;
46
- default:
47
- throw new Error(`Unknown line type`);
48
- }
49
- })
50
- .join("\n");
51
- }
52
- /**
53
- * Get all entries as a key-value record
54
- */
55
- toRecord() {
56
- return Object.fromEntries(this.entries());
57
- }
58
- /**
59
- * Find an entry line by key
60
- */
61
- findEntry(key) {
62
- const line = this.lines.find((l) => l.type === "entry" && l.key === key);
63
- return line;
64
- }
65
- /**
66
- * Find the index of an entry by key
67
- */
68
- findEntryIndex(key) {
69
- return this.lines.findIndex((l) => l.type === "entry" && l.key === key);
70
- }
71
- /**
72
- * Create an entry line from key and value
73
- */
74
- createEntry(key, value) {
75
- const quotedValue = this.normalizeValue(value);
76
- return {
77
- type: "entry",
78
- key,
79
- value: quotedValue,
80
- raw: `${key}=${quotedValue}`,
81
- };
82
- }
83
- /**
84
- * Normalize a value by ensuring it's properly quoted
85
- */
86
- normalizeValue(value) {
87
- // Strip existing quotes if present, then add quotes
88
- const unquoted = value.startsWith('"') && value.endsWith('"') ? value.slice(1, -1) : value;
89
- return `"${unquoted}"`;
90
- }
91
- /**
92
- * Find the insertion index for a new entry (before the final blank line if present)
93
- */
94
- findInsertionIndex() {
95
- const lastLine = this.lines[this.lines.length - 1];
96
- return lastLine?.type === "blank"
97
- ? this.lines.length - 1
98
- : this.lines.length;
99
- }
100
- /**
101
- * Get the value for a specific key
102
- */
103
- get(key) {
104
- return this.findEntry(key)?.value;
105
- }
106
- /**
107
- * Set a value for a key. If the key exists, updates it in place.
108
- * If it doesn't exist, appends it above the final newline (if present).
109
- * Values are always double quoted.
110
- */
111
- set(key, value) {
112
- const index = this.findEntryIndex(key);
113
- const entry = this.createEntry(key, value);
114
- if (index !== -1) {
115
- this.lines[index] = entry;
116
- }
117
- else {
118
- this.lines.splice(this.findInsertionIndex(), 0, entry);
119
- }
120
- return this;
121
- }
122
- /**
123
- * Delete a key-value entry
124
- */
125
- delete(key) {
126
- this.lines = this.lines.filter((l) => !(l.type === "entry" && l.key === key));
127
- return this;
128
- }
129
- /**
130
- * Check if a key exists
131
- */
132
- has(key) {
133
- return this.findEntry(key) !== undefined;
134
- }
135
- /**
136
- * Get all keys
137
- */
138
- keys() {
139
- return this.lines
140
- .filter((l) => l.type === "entry")
141
- .map((l) => l.key);
142
- }
143
- /**
144
- * Iterate over all entries
145
- */
146
- *entries() {
147
- for (const line of this.lines) {
148
- if (line.type === "entry") {
149
- yield [line.key, line.value];
150
- }
151
- }
152
- }
153
- /**
154
- * Apply a function to all entries and return a new EnvFile
155
- */
156
- map(fn) {
157
- const newLines = this.lines.map((line) => {
158
- if (line.type === "entry") {
159
- const [newKey, newValue] = fn(line.key, line.value);
160
- return this.createEntry(newKey, newValue);
161
- }
162
- return line;
163
- });
164
- return new EnvFile(newLines);
165
- }
166
- /**
167
- * Filter entries based on a predicate
168
- */
169
- filter(fn) {
170
- const newLines = this.lines.filter((line) => {
171
- if (line.type === "entry") {
172
- return fn(line.key, line.value);
173
- }
174
- return true; // Keep comments and blank lines
175
- });
176
- return new EnvFile(newLines);
177
- }
178
- /**
179
- * Add a comment line
180
- */
181
- addComment(content) {
182
- const comment = content.startsWith("#") ? content : `# ${content}`;
183
- this.lines.push({ type: "comment", content: comment });
184
- return this;
185
- }
186
- /**
187
- * Add a blank line
188
- */
189
- addBlank() {
190
- this.lines.push({ type: "blank" });
191
- return this;
192
- }
193
- /**
194
- * Get the raw lines array for custom operations
195
- */
196
- getLines() {
197
- return this.lines;
198
- }
199
- /**
200
- * Create a clone of this EnvFile
201
- */
202
- clone() {
203
- return new EnvFile([...this.lines]);
204
- }
205
- }