@flightdev/core 0.6.7
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 +541 -0
- package/dist/actions/index.d.ts +743 -0
- package/dist/actions/index.js +3 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/adapters/index.d.ts +502 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/cache/index.d.ts +191 -0
- package/dist/cache/index.js +3 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/chunk-62HISNA3.js +354 -0
- package/dist/chunk-62HISNA3.js.map +1 -0
- package/dist/chunk-63LWTEDQ.js +341 -0
- package/dist/chunk-63LWTEDQ.js.map +1 -0
- package/dist/chunk-63SCEXD7.js +3 -0
- package/dist/chunk-63SCEXD7.js.map +1 -0
- package/dist/chunk-72MYOTUB.js +667 -0
- package/dist/chunk-72MYOTUB.js.map +1 -0
- package/dist/chunk-7CNW24MQ.js +257 -0
- package/dist/chunk-7CNW24MQ.js.map +1 -0
- package/dist/chunk-7WIEAUJT.js +300 -0
- package/dist/chunk-7WIEAUJT.js.map +1 -0
- package/dist/chunk-7ZZF4ULK.js +259 -0
- package/dist/chunk-7ZZF4ULK.js.map +1 -0
- package/dist/chunk-AE3JTS73.js +222 -0
- package/dist/chunk-AE3JTS73.js.map +1 -0
- package/dist/chunk-AP5NLUSB.js +258 -0
- package/dist/chunk-AP5NLUSB.js.map +1 -0
- package/dist/chunk-C37YQQI7.js +221 -0
- package/dist/chunk-C37YQQI7.js.map +1 -0
- package/dist/chunk-DCLVXFVH.js +225 -0
- package/dist/chunk-DCLVXFVH.js.map +1 -0
- package/dist/chunk-DZMWWDFD.js +223 -0
- package/dist/chunk-DZMWWDFD.js.map +1 -0
- package/dist/chunk-GCQZ4FHI.js +245 -0
- package/dist/chunk-GCQZ4FHI.js.map +1 -0
- package/dist/chunk-IPP44XY6.js +47 -0
- package/dist/chunk-IPP44XY6.js.map +1 -0
- package/dist/chunk-IW7FTQQX.js +267 -0
- package/dist/chunk-IW7FTQQX.js.map +1 -0
- package/dist/chunk-JX4YSCBH.js +428 -0
- package/dist/chunk-JX4YSCBH.js.map +1 -0
- package/dist/chunk-KX6UYWWR.js +229 -0
- package/dist/chunk-KX6UYWWR.js.map +1 -0
- package/dist/chunk-LWVETFJV.js +46 -0
- package/dist/chunk-LWVETFJV.js.map +1 -0
- package/dist/chunk-MCL2MCA2.js +285 -0
- package/dist/chunk-MCL2MCA2.js.map +1 -0
- package/dist/chunk-MZXCF35B.js +205 -0
- package/dist/chunk-MZXCF35B.js.map +1 -0
- package/dist/chunk-NCGPUFWV.js +96 -0
- package/dist/chunk-NCGPUFWV.js.map +1 -0
- package/dist/chunk-OEJMIE2Q.js +351 -0
- package/dist/chunk-OEJMIE2Q.js.map +1 -0
- package/dist/chunk-OYF2OAKS.js +394 -0
- package/dist/chunk-OYF2OAKS.js.map +1 -0
- package/dist/chunk-P6S43FYZ.js +316 -0
- package/dist/chunk-P6S43FYZ.js.map +1 -0
- package/dist/chunk-PL37KFRJ.js +3 -0
- package/dist/chunk-PL37KFRJ.js.map +1 -0
- package/dist/chunk-Q7BS5QC5.js +197 -0
- package/dist/chunk-Q7BS5QC5.js.map +1 -0
- package/dist/chunk-SDYPG3JD.js +288 -0
- package/dist/chunk-SDYPG3JD.js.map +1 -0
- package/dist/chunk-SUG56SZO.js +256 -0
- package/dist/chunk-SUG56SZO.js.map +1 -0
- package/dist/chunk-UVH5XJRP.js +164 -0
- package/dist/chunk-UVH5XJRP.js.map +1 -0
- package/dist/chunk-WZIJKCL3.js +282 -0
- package/dist/chunk-WZIJKCL3.js.map +1 -0
- package/dist/chunk-Y22AMGTM.js +3 -0
- package/dist/chunk-Y22AMGTM.js.map +1 -0
- package/dist/chunk-Z7G23XWU.js +200 -0
- package/dist/chunk-Z7G23XWU.js.map +1 -0
- package/dist/chunk-ZJU5M4IB.js +125 -0
- package/dist/chunk-ZJU5M4IB.js.map +1 -0
- package/dist/chunk-ZVC3ZWLM.js +52 -0
- package/dist/chunk-ZVC3ZWLM.js.map +1 -0
- package/dist/chunk-ZZZML7Y3.js +310 -0
- package/dist/chunk-ZZZML7Y3.js.map +1 -0
- package/dist/client.d.ts +25 -0
- package/dist/client.js +16 -0
- package/dist/client.js.map +1 -0
- package/dist/config/index.d.ts +170 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/errors/index.d.ts +267 -0
- package/dist/errors/index.js +4 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/file-router/index.d.ts +184 -0
- package/dist/file-router/index.js +3 -0
- package/dist/file-router/index.js.map +1 -0
- package/dist/file-router/streaming-hints.d.ts +129 -0
- package/dist/file-router/streaming-hints.js +3 -0
- package/dist/file-router/streaming-hints.js.map +1 -0
- package/dist/handlers/index.d.ts +59 -0
- package/dist/handlers/index.js +3 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/index.d.ts +588 -0
- package/dist/index.js +886 -0
- package/dist/index.js.map +1 -0
- package/dist/islands/index.d.ts +234 -0
- package/dist/islands/index.js +3 -0
- package/dist/islands/index.js.map +1 -0
- package/dist/middleware/index.d.ts +305 -0
- package/dist/middleware/index.js +3 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/react/index.d.ts +73 -0
- package/dist/react/index.js +52 -0
- package/dist/react/index.js.map +1 -0
- package/dist/render/index.d.ts +131 -0
- package/dist/render/index.js +3 -0
- package/dist/render/index.js.map +1 -0
- package/dist/router/index.d.ts +65 -0
- package/dist/router/index.js +3 -0
- package/dist/router/index.js.map +1 -0
- package/dist/rsc/adapters/index.d.ts +8 -0
- package/dist/rsc/adapters/index.js +7 -0
- package/dist/rsc/adapters/index.js.map +1 -0
- package/dist/rsc/adapters/preact.d.ts +97 -0
- package/dist/rsc/adapters/preact.js +3 -0
- package/dist/rsc/adapters/preact.js.map +1 -0
- package/dist/rsc/adapters/react.d.ts +82 -0
- package/dist/rsc/adapters/react.js +3 -0
- package/dist/rsc/adapters/react.js.map +1 -0
- package/dist/rsc/adapters/solid.d.ts +84 -0
- package/dist/rsc/adapters/solid.js +3 -0
- package/dist/rsc/adapters/solid.js.map +1 -0
- package/dist/rsc/adapters/vue.d.ts +80 -0
- package/dist/rsc/adapters/vue.js +3 -0
- package/dist/rsc/adapters/vue.js.map +1 -0
- package/dist/rsc/boundaries.d.ts +182 -0
- package/dist/rsc/boundaries.js +3 -0
- package/dist/rsc/boundaries.js.map +1 -0
- package/dist/rsc/context.d.ts +201 -0
- package/dist/rsc/context.js +3 -0
- package/dist/rsc/context.js.map +1 -0
- package/dist/rsc/index.d.ts +232 -0
- package/dist/rsc/index.js +15 -0
- package/dist/rsc/index.js.map +1 -0
- package/dist/rsc/legacy.d.ts +155 -0
- package/dist/rsc/legacy.js +3 -0
- package/dist/rsc/legacy.js.map +1 -0
- package/dist/rsc/payload.d.ts +262 -0
- package/dist/rsc/payload.js +3 -0
- package/dist/rsc/payload.js.map +1 -0
- package/dist/rsc/plugins/esbuild.d.ts +124 -0
- package/dist/rsc/plugins/esbuild.js +4 -0
- package/dist/rsc/plugins/esbuild.js.map +1 -0
- package/dist/rsc/plugins/index.d.ts +4 -0
- package/dist/rsc/plugins/index.js +6 -0
- package/dist/rsc/plugins/index.js.map +1 -0
- package/dist/rsc/plugins/rollup.d.ts +103 -0
- package/dist/rsc/plugins/rollup.js +4 -0
- package/dist/rsc/plugins/rollup.js.map +1 -0
- package/dist/rsc/renderer.d.ts +162 -0
- package/dist/rsc/renderer.js +5 -0
- package/dist/rsc/renderer.js.map +1 -0
- package/dist/rsc/stream.d.ts +129 -0
- package/dist/rsc/stream.js +3 -0
- package/dist/rsc/stream.js.map +1 -0
- package/dist/rsc/vite-plugin.d.ts +78 -0
- package/dist/rsc/vite-plugin.js +4 -0
- package/dist/rsc/vite-plugin.js.map +1 -0
- package/dist/server/index.d.ts +135 -0
- package/dist/server/index.js +6 -0
- package/dist/server/index.js.map +1 -0
- package/dist/streaming/adapters/index.d.ts +223 -0
- package/dist/streaming/adapters/index.js +3 -0
- package/dist/streaming/adapters/index.js.map +1 -0
- package/dist/streaming/conditional.d.ts +130 -0
- package/dist/streaming/conditional.js +3 -0
- package/dist/streaming/conditional.js.map +1 -0
- package/dist/streaming/index.d.ts +177 -0
- package/dist/streaming/index.js +3 -0
- package/dist/streaming/index.js.map +1 -0
- package/dist/streaming/observability.d.ts +201 -0
- package/dist/streaming/observability.js +4 -0
- package/dist/streaming/observability.js.map +1 -0
- package/dist/streaming/priority.d.ts +103 -0
- package/dist/streaming/priority.js +3 -0
- package/dist/streaming/priority.js.map +1 -0
- package/dist/utils/index.d.ts +42 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +228 -0
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
// src/cache/index.ts
|
|
2
|
+
var jsonSerializer = {
|
|
3
|
+
serialize: (value) => JSON.stringify(value),
|
|
4
|
+
deserialize: (data) => JSON.parse(data)
|
|
5
|
+
};
|
|
6
|
+
var MemoryCacheAdapter = class {
|
|
7
|
+
name = "memory";
|
|
8
|
+
supportsDistributedTags = false;
|
|
9
|
+
store = /* @__PURE__ */ new Map();
|
|
10
|
+
tagIndex = /* @__PURE__ */ new Map();
|
|
11
|
+
maxSize;
|
|
12
|
+
cleanupTimer;
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.maxSize = options.maxSize ?? 0;
|
|
15
|
+
const interval = options.cleanupInterval ?? 6e4;
|
|
16
|
+
if (interval > 0) {
|
|
17
|
+
this.cleanupTimer = setInterval(() => this.cleanup(), interval);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async get(key) {
|
|
21
|
+
const entry = this.store.get(key);
|
|
22
|
+
if (!entry) return void 0;
|
|
23
|
+
if (entry.expiresAt && Date.now() > entry.expiresAt) {
|
|
24
|
+
this.store.delete(key);
|
|
25
|
+
this.removeFromTagIndex(key, entry.tags);
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
return entry;
|
|
29
|
+
}
|
|
30
|
+
async set(key, entry) {
|
|
31
|
+
if (this.maxSize > 0 && this.store.size >= this.maxSize && !this.store.has(key)) {
|
|
32
|
+
const firstKey = this.store.keys().next().value;
|
|
33
|
+
if (firstKey) {
|
|
34
|
+
const evicted = this.store.get(firstKey);
|
|
35
|
+
this.store.delete(firstKey);
|
|
36
|
+
if (evicted?.tags) {
|
|
37
|
+
this.removeFromTagIndex(firstKey, evicted.tags);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
this.store.set(key, entry);
|
|
42
|
+
if (entry.tags) {
|
|
43
|
+
for (const tag of entry.tags) {
|
|
44
|
+
if (!this.tagIndex.has(tag)) {
|
|
45
|
+
this.tagIndex.set(tag, /* @__PURE__ */ new Set());
|
|
46
|
+
}
|
|
47
|
+
this.tagIndex.get(tag).add(key);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async delete(key) {
|
|
52
|
+
const entry = this.store.get(key);
|
|
53
|
+
if (entry?.tags) {
|
|
54
|
+
this.removeFromTagIndex(key, entry.tags);
|
|
55
|
+
}
|
|
56
|
+
return this.store.delete(key);
|
|
57
|
+
}
|
|
58
|
+
async has(key) {
|
|
59
|
+
const entry = await this.get(key);
|
|
60
|
+
return entry !== void 0;
|
|
61
|
+
}
|
|
62
|
+
async clear() {
|
|
63
|
+
this.store.clear();
|
|
64
|
+
this.tagIndex.clear();
|
|
65
|
+
}
|
|
66
|
+
async keys(pattern) {
|
|
67
|
+
const allKeys = Array.from(this.store.keys());
|
|
68
|
+
if (!pattern) return allKeys;
|
|
69
|
+
const regex = new RegExp(pattern.replace(/\*/g, ".*"));
|
|
70
|
+
return allKeys.filter((key) => regex.test(key));
|
|
71
|
+
}
|
|
72
|
+
async getMany(keys) {
|
|
73
|
+
const result = /* @__PURE__ */ new Map();
|
|
74
|
+
for (const key of keys) {
|
|
75
|
+
result.set(key, await this.get(key));
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
async setMany(entries) {
|
|
80
|
+
for (const [key, entry] of entries) {
|
|
81
|
+
await this.set(key, entry);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// In-memory adapter handles tags locally (non-distributed)
|
|
85
|
+
async addToTag(tag, key) {
|
|
86
|
+
if (!this.tagIndex.has(tag)) {
|
|
87
|
+
this.tagIndex.set(tag, /* @__PURE__ */ new Set());
|
|
88
|
+
}
|
|
89
|
+
this.tagIndex.get(tag).add(key);
|
|
90
|
+
}
|
|
91
|
+
async getTagMembers(tag) {
|
|
92
|
+
return Array.from(this.tagIndex.get(tag) ?? []);
|
|
93
|
+
}
|
|
94
|
+
async deleteTag(tag) {
|
|
95
|
+
const members = await this.getTagMembers(tag);
|
|
96
|
+
this.tagIndex.delete(tag);
|
|
97
|
+
return members;
|
|
98
|
+
}
|
|
99
|
+
async close() {
|
|
100
|
+
if (this.cleanupTimer) {
|
|
101
|
+
clearInterval(this.cleanupTimer);
|
|
102
|
+
}
|
|
103
|
+
this.store.clear();
|
|
104
|
+
this.tagIndex.clear();
|
|
105
|
+
}
|
|
106
|
+
async ping() {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
removeFromTagIndex(key, tags) {
|
|
110
|
+
if (!tags) return;
|
|
111
|
+
for (const tag of tags) {
|
|
112
|
+
this.tagIndex.get(tag)?.delete(key);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
cleanup() {
|
|
116
|
+
const now = Date.now();
|
|
117
|
+
for (const [key, entry] of this.store) {
|
|
118
|
+
if (entry.expiresAt && now > entry.expiresAt) {
|
|
119
|
+
this.store.delete(key);
|
|
120
|
+
this.removeFromTagIndex(key, entry.tags);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
function memory(options = {}) {
|
|
126
|
+
return new MemoryCacheAdapter(options);
|
|
127
|
+
}
|
|
128
|
+
function createCache(options = {}) {
|
|
129
|
+
const {
|
|
130
|
+
adapter = new MemoryCacheAdapter(),
|
|
131
|
+
defaultTTL,
|
|
132
|
+
prefix = "",
|
|
133
|
+
trackStats = false
|
|
134
|
+
} = options;
|
|
135
|
+
const localTagIndex = /* @__PURE__ */ new Map();
|
|
136
|
+
const stats = { hits: 0, misses: 0, sets: 0, deletes: 0 };
|
|
137
|
+
function prefixKey(key) {
|
|
138
|
+
return prefix ? `${prefix}:${key}` : key;
|
|
139
|
+
}
|
|
140
|
+
function useDistributedTags() {
|
|
141
|
+
return !!(adapter.supportsDistributedTags && adapter.addToTag && adapter.getTagMembers && adapter.deleteTag);
|
|
142
|
+
}
|
|
143
|
+
async function registerTags(fullKey, tags) {
|
|
144
|
+
if (!tags || tags.length === 0) return;
|
|
145
|
+
if (useDistributedTags()) {
|
|
146
|
+
for (const tag of tags) {
|
|
147
|
+
await adapter.addToTag(tag, fullKey);
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
for (const tag of tags) {
|
|
151
|
+
if (!localTagIndex.has(tag)) {
|
|
152
|
+
localTagIndex.set(tag, /* @__PURE__ */ new Set());
|
|
153
|
+
}
|
|
154
|
+
localTagIndex.get(tag).add(fullKey);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async function getTagMembers(tag) {
|
|
159
|
+
if (useDistributedTags()) {
|
|
160
|
+
return adapter.getTagMembers(tag);
|
|
161
|
+
}
|
|
162
|
+
return Array.from(localTagIndex.get(tag) ?? []);
|
|
163
|
+
}
|
|
164
|
+
async function removeTag(tag) {
|
|
165
|
+
if (useDistributedTags()) {
|
|
166
|
+
await adapter.deleteTag(tag);
|
|
167
|
+
} else {
|
|
168
|
+
localTagIndex.delete(tag);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
async get(key) {
|
|
173
|
+
const entry = await adapter.get(prefixKey(key));
|
|
174
|
+
if (!entry) {
|
|
175
|
+
if (trackStats) stats.misses++;
|
|
176
|
+
return void 0;
|
|
177
|
+
}
|
|
178
|
+
if (trackStats) stats.hits++;
|
|
179
|
+
return entry.value;
|
|
180
|
+
},
|
|
181
|
+
async set(key, value, opts) {
|
|
182
|
+
const ttl = opts?.ttl ?? defaultTTL;
|
|
183
|
+
const now = Date.now();
|
|
184
|
+
const entry = {
|
|
185
|
+
value,
|
|
186
|
+
createdAt: now,
|
|
187
|
+
tags: opts?.tags
|
|
188
|
+
};
|
|
189
|
+
if (ttl) {
|
|
190
|
+
entry.expiresAt = now + ttl * 1e3;
|
|
191
|
+
if (opts?.swr) {
|
|
192
|
+
entry.staleAt = now + (ttl - opts.swr) * 1e3;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const fullKey = prefixKey(key);
|
|
196
|
+
await adapter.set(fullKey, entry);
|
|
197
|
+
await registerTags(fullKey, opts?.tags);
|
|
198
|
+
if (trackStats) stats.sets++;
|
|
199
|
+
},
|
|
200
|
+
async delete(key) {
|
|
201
|
+
const fullKey = prefixKey(key);
|
|
202
|
+
const result = await adapter.delete(fullKey);
|
|
203
|
+
if (trackStats && result) stats.deletes++;
|
|
204
|
+
return result;
|
|
205
|
+
},
|
|
206
|
+
async has(key) {
|
|
207
|
+
return adapter.has(prefixKey(key));
|
|
208
|
+
},
|
|
209
|
+
async clear() {
|
|
210
|
+
await adapter.clear();
|
|
211
|
+
localTagIndex.clear();
|
|
212
|
+
},
|
|
213
|
+
async invalidateTag(tag) {
|
|
214
|
+
const keys = await getTagMembers(tag);
|
|
215
|
+
for (const key of keys) {
|
|
216
|
+
await adapter.delete(key);
|
|
217
|
+
}
|
|
218
|
+
await removeTag(tag);
|
|
219
|
+
},
|
|
220
|
+
async invalidateTags(tags) {
|
|
221
|
+
for (const tag of tags) {
|
|
222
|
+
await this.invalidateTag(tag);
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
async getOrSet(key, factory, opts) {
|
|
226
|
+
const cached2 = await this.get(key);
|
|
227
|
+
if (cached2 !== void 0) {
|
|
228
|
+
return cached2;
|
|
229
|
+
}
|
|
230
|
+
const value = await factory();
|
|
231
|
+
await this.set(key, value, opts);
|
|
232
|
+
return value;
|
|
233
|
+
},
|
|
234
|
+
async getMany(keys) {
|
|
235
|
+
const result = /* @__PURE__ */ new Map();
|
|
236
|
+
if (adapter.getMany) {
|
|
237
|
+
const entries = await adapter.getMany(keys.map(prefixKey));
|
|
238
|
+
for (const [key, entry] of entries) {
|
|
239
|
+
const originalKey = prefix ? key.slice(prefix.length + 1) : key;
|
|
240
|
+
result.set(originalKey, entry?.value);
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
for (const key of keys) {
|
|
244
|
+
result.set(key, await this.get(key));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return result;
|
|
248
|
+
},
|
|
249
|
+
async setMany(entries, opts) {
|
|
250
|
+
const ttl = opts?.ttl ?? defaultTTL;
|
|
251
|
+
const now = Date.now();
|
|
252
|
+
const cacheEntries = /* @__PURE__ */ new Map();
|
|
253
|
+
for (const [key, value] of entries) {
|
|
254
|
+
const entry = {
|
|
255
|
+
value,
|
|
256
|
+
createdAt: now,
|
|
257
|
+
tags: opts?.tags
|
|
258
|
+
};
|
|
259
|
+
if (ttl) {
|
|
260
|
+
entry.expiresAt = now + ttl * 1e3;
|
|
261
|
+
if (opts?.swr) {
|
|
262
|
+
entry.staleAt = now + (ttl - opts.swr) * 1e3;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const fullKey = prefixKey(key);
|
|
266
|
+
cacheEntries.set(fullKey, entry);
|
|
267
|
+
await registerTags(fullKey, opts?.tags);
|
|
268
|
+
}
|
|
269
|
+
if (adapter.setMany) {
|
|
270
|
+
await adapter.setMany(cacheEntries);
|
|
271
|
+
} else {
|
|
272
|
+
for (const [key, entry] of cacheEntries) {
|
|
273
|
+
await adapter.set(key, entry);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (trackStats) stats.sets += entries.size;
|
|
277
|
+
},
|
|
278
|
+
getStats() {
|
|
279
|
+
return trackStats ? { ...stats } : void 0;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function cacheKey(...parts) {
|
|
284
|
+
return parts.filter((p) => p !== void 0).map((p) => String(p)).join(":");
|
|
285
|
+
}
|
|
286
|
+
function cached(cache, fn, options) {
|
|
287
|
+
const { keyFn = (...args) => JSON.stringify(args), ...cacheOpts } = options ?? {};
|
|
288
|
+
return (async (...args) => {
|
|
289
|
+
const key = keyFn(...args);
|
|
290
|
+
return cache.getOrSet(key, () => fn(...args), cacheOpts);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
function dedupe(fn, keyFn = (...args) => JSON.stringify(args)) {
|
|
294
|
+
const pending = /* @__PURE__ */ new Map();
|
|
295
|
+
return (async (...args) => {
|
|
296
|
+
const key = keyFn(...args);
|
|
297
|
+
if (pending.has(key)) {
|
|
298
|
+
return pending.get(key);
|
|
299
|
+
}
|
|
300
|
+
const promise = fn(...args).finally(() => {
|
|
301
|
+
pending.delete(key);
|
|
302
|
+
});
|
|
303
|
+
pending.set(key, promise);
|
|
304
|
+
return promise;
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export { cacheKey, cached, createCache, dedupe, jsonSerializer, memory };
|
|
309
|
+
//# sourceMappingURL=chunk-ZZZML7Y3.js.map
|
|
310
|
+
//# sourceMappingURL=chunk-ZZZML7Y3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cache/index.ts"],"names":["cached"],"mappings":";AA+JO,IAAM,cAAA,GAA6B;AAAA,EACtC,SAAA,EAAW,CAAC,KAAA,KAAU,IAAA,CAAK,UAAU,KAAK,CAAA;AAAA,EAC1C,WAAA,EAAa,CAAI,IAAA,KAAiB,IAAA,CAAK,MAAM,IAAI;AACrD;AAaA,IAAM,qBAAN,MAAi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;AAClB,MAAA,OAAO,OAAA,CAAQ,IAAI,GAAG,CAAA;AAAA,IAC1B;AAEA,IAAA,MAAM,UAAU,EAAA,CAAG,GAAG,IAAI,CAAA,CAAE,QAAQ,MAAM;AACtC,MAAA,OAAA,CAAQ,OAAO,GAAG,CAAA;AAAA,IACtB,CAAC,CAAA;AAED,IAAA,OAAA,CAAQ,GAAA,CAAI,KAAK,OAAO,CAAA;AACxB,IAAA,OAAO,OAAA;AAAA,EACX,CAAA;AACJ","file":"chunk-ZZZML7Y3.js","sourcesContent":["/**\r\n * Flight Cache - Agnostic caching primitives\r\n * \r\n * Flight provides the interface, you choose the implementation.\r\n * Use in-memory, Redis, Cloudflare KV, Upstash, or anything else.\r\n * \r\n * @example\r\n * ```typescript\r\n * import { createCache } from '@flightdev/core';\r\n * import { redis } from '@flightdev/cache-redis';\r\n * \r\n * const cache = createCache({\r\n * adapter: redis({ url: process.env.REDIS_URL }),\r\n * defaultTTL: 3600,\r\n * });\r\n * \r\n * await cache.set('user:1', userData, { tags: ['users'] });\r\n * await cache.invalidateTag('users');\r\n * ```\r\n */\r\n\r\n// ============================================================================\r\n// Types\r\n// ============================================================================\r\n\r\nexport interface CacheOptions {\r\n /** Time-to-live in seconds */\r\n ttl?: number;\r\n /** Cache tags for invalidation */\r\n tags?: string[];\r\n /** Stale-while-revalidate time in seconds */\r\n swr?: number;\r\n}\r\n\r\nexport interface CacheEntry<T> {\r\n /** Cached value */\r\n value: T;\r\n /** When this entry expires (timestamp) */\r\n expiresAt?: number;\r\n /** When this entry becomes stale (timestamp) */\r\n staleAt?: number;\r\n /** Cache tags for invalidation */\r\n tags?: string[];\r\n /** When this entry was created */\r\n createdAt: number;\r\n}\r\n\r\nexport interface Cache {\r\n /** Get a value from cache */\r\n get<T>(key: string): Promise<T | undefined>;\r\n\r\n /** Set a value in cache */\r\n set<T>(key: string, value: T, options?: CacheOptions): Promise<void>;\r\n\r\n /** Delete a value from cache */\r\n delete(key: string): Promise<boolean>;\r\n\r\n /** Check if a key exists */\r\n has(key: string): Promise<boolean>;\r\n\r\n /** Clear all cache entries */\r\n clear(): Promise<void>;\r\n\r\n /** Invalidate entries by tag */\r\n invalidateTag(tag: string): Promise<void>;\r\n\r\n /** Invalidate entries by multiple tags */\r\n invalidateTags(tags: string[]): Promise<void>;\r\n\r\n /** Get or set with a factory function */\r\n getOrSet<T>(\r\n key: string,\r\n factory: () => Promise<T>,\r\n options?: CacheOptions\r\n ): Promise<T>;\r\n\r\n /** Get multiple values at once */\r\n getMany<T>(keys: string[]): Promise<Map<string, T | undefined>>;\r\n\r\n /** Set multiple values at once */\r\n setMany<T>(entries: Map<string, T>, options?: CacheOptions): Promise<void>;\r\n\r\n /** Get cache statistics (if tracking enabled) */\r\n getStats?(): CacheStats | undefined;\r\n}\r\n\r\nexport interface CacheStats {\r\n hits: number;\r\n misses: number;\r\n sets: number;\r\n deletes: number;\r\n}\r\n\r\n/** Adapter interface for external cache providers */\r\nexport interface CacheAdapter {\r\n /** Adapter name for identification */\r\n readonly name: string;\r\n\r\n /** Get an entry from cache */\r\n get<T>(key: string): Promise<CacheEntry<T> | undefined>;\r\n\r\n /** Set an entry in cache */\r\n set<T>(key: string, entry: CacheEntry<T>): Promise<void>;\r\n\r\n /** Delete an entry from cache */\r\n delete(key: string): Promise<boolean>;\r\n\r\n /** Check if key exists */\r\n has(key: string): Promise<boolean>;\r\n\r\n /** Clear all entries */\r\n clear(): Promise<void>;\r\n\r\n /** Get keys matching pattern (optional) */\r\n keys?(pattern?: string): Promise<string[]>;\r\n\r\n /** Get multiple entries at once (optional, for performance) */\r\n getMany?<T>(keys: string[]): Promise<Map<string, CacheEntry<T> | undefined>>;\r\n\r\n /** Set multiple entries at once (optional, for performance) */\r\n setMany?<T>(entries: Map<string, CacheEntry<T>>): Promise<void>;\r\n\r\n // ========================================================================\r\n // Tag operations - For distributed caches, tags MUST be handled by adapter\r\n // ========================================================================\r\n\r\n /** Whether this adapter supports distributed tags natively */\r\n readonly supportsDistributedTags?: boolean;\r\n\r\n /** Add a key to a tag set (for distributed tag management) */\r\n addToTag?(tag: string, key: string): Promise<void>;\r\n\r\n /** Get all keys associated with a tag */\r\n getTagMembers?(tag: string): Promise<string[]>;\r\n\r\n /** Delete a tag and return its members */\r\n deleteTag?(tag: string): Promise<string[]>;\r\n\r\n // ========================================================================\r\n // Lifecycle\r\n // ========================================================================\r\n\r\n /** Close connection (for cleanup) */\r\n close?(): Promise<void>;\r\n\r\n /** Check if adapter is healthy */\r\n ping?(): Promise<boolean>;\r\n}\r\n\r\n// ============================================================================\r\n// Serialization\r\n// ============================================================================\r\n\r\nexport interface Serializer {\r\n serialize(value: unknown): string;\r\n deserialize<T>(data: string): T;\r\n}\r\n\r\n/** Default JSON serializer */\r\nexport const jsonSerializer: Serializer = {\r\n serialize: (value) => JSON.stringify(value),\r\n deserialize: <T>(data: string) => JSON.parse(data) as T,\r\n};\r\n\r\n// ============================================================================\r\n// In-Memory Cache Implementation (Default)\r\n// ============================================================================\r\n\r\nexport interface MemoryCacheAdapterOptions {\r\n /** Maximum number of entries (0 = unlimited) */\r\n maxSize?: number;\r\n /** Cleanup interval in ms (default: 60000) */\r\n cleanupInterval?: number;\r\n}\r\n\r\nclass MemoryCacheAdapter implements CacheAdapter {\r\n readonly name = 'memory';\r\n readonly supportsDistributedTags = false;\r\n\r\n private store = new Map<string, CacheEntry<unknown>>();\r\n private tagIndex = new Map<string, Set<string>>();\r\n private maxSize: number;\r\n private cleanupTimer?: ReturnType<typeof setInterval>;\r\n\r\n constructor(options: MemoryCacheAdapterOptions = {}) {\r\n this.maxSize = options.maxSize ?? 0;\r\n\r\n // Periodic cleanup of expired entries\r\n const interval = options.cleanupInterval ?? 60000;\r\n if (interval > 0) {\r\n this.cleanupTimer = setInterval(() => this.cleanup(), interval);\r\n }\r\n }\r\n\r\n async get<T>(key: string): Promise<CacheEntry<T> | undefined> {\r\n const entry = this.store.get(key) as CacheEntry<T> | undefined;\r\n if (!entry) return undefined;\r\n\r\n // Check if expired\r\n if (entry.expiresAt && Date.now() > entry.expiresAt) {\r\n this.store.delete(key);\r\n this.removeFromTagIndex(key, entry.tags);\r\n return undefined;\r\n }\r\n\r\n return entry;\r\n }\r\n\r\n async set<T>(key: string, entry: CacheEntry<T>): Promise<void> {\r\n // Evict if at max size (simple FIFO eviction)\r\n if (this.maxSize > 0 && this.store.size >= this.maxSize && !this.store.has(key)) {\r\n const firstKey = this.store.keys().next().value;\r\n if (firstKey) {\r\n const evicted = this.store.get(firstKey);\r\n this.store.delete(firstKey);\r\n if (evicted?.tags) {\r\n this.removeFromTagIndex(firstKey, evicted.tags);\r\n }\r\n }\r\n }\r\n\r\n this.store.set(key, entry as CacheEntry<unknown>);\r\n\r\n // Update tag index\r\n if (entry.tags) {\r\n for (const tag of entry.tags) {\r\n if (!this.tagIndex.has(tag)) {\r\n this.tagIndex.set(tag, new Set());\r\n }\r\n this.tagIndex.get(tag)!.add(key);\r\n }\r\n }\r\n }\r\n\r\n async delete(key: string): Promise<boolean> {\r\n const entry = this.store.get(key);\r\n if (entry?.tags) {\r\n this.removeFromTagIndex(key, entry.tags);\r\n }\r\n return this.store.delete(key);\r\n }\r\n\r\n async has(key: string): Promise<boolean> {\r\n const entry = await this.get(key);\r\n return entry !== undefined;\r\n }\r\n\r\n async clear(): Promise<void> {\r\n this.store.clear();\r\n this.tagIndex.clear();\r\n }\r\n\r\n async keys(pattern?: string): Promise<string[]> {\r\n const allKeys = Array.from(this.store.keys());\r\n if (!pattern) return allKeys;\r\n\r\n const regex = new RegExp(pattern.replace(/\\*/g, '.*'));\r\n return allKeys.filter(key => regex.test(key));\r\n }\r\n\r\n async getMany<T>(keys: string[]): Promise<Map<string, CacheEntry<T> | undefined>> {\r\n const result = new Map<string, CacheEntry<T> | undefined>();\r\n for (const key of keys) {\r\n result.set(key, await this.get<T>(key));\r\n }\r\n return result;\r\n }\r\n\r\n async setMany<T>(entries: Map<string, CacheEntry<T>>): Promise<void> {\r\n for (const [key, entry] of entries) {\r\n await this.set(key, entry);\r\n }\r\n }\r\n\r\n // In-memory adapter handles tags locally (non-distributed)\r\n async addToTag(tag: string, key: string): Promise<void> {\r\n if (!this.tagIndex.has(tag)) {\r\n this.tagIndex.set(tag, new Set());\r\n }\r\n this.tagIndex.get(tag)!.add(key);\r\n }\r\n\r\n async getTagMembers(tag: string): Promise<string[]> {\r\n return Array.from(this.tagIndex.get(tag) ?? []);\r\n }\r\n\r\n async deleteTag(tag: string): Promise<string[]> {\r\n const members = await this.getTagMembers(tag);\r\n this.tagIndex.delete(tag);\r\n return members;\r\n }\r\n\r\n async close(): Promise<void> {\r\n if (this.cleanupTimer) {\r\n clearInterval(this.cleanupTimer);\r\n }\r\n this.store.clear();\r\n this.tagIndex.clear();\r\n }\r\n\r\n async ping(): Promise<boolean> {\r\n return true;\r\n }\r\n\r\n private removeFromTagIndex(key: string, tags?: string[]): void {\r\n if (!tags) return;\r\n for (const tag of tags) {\r\n this.tagIndex.get(tag)?.delete(key);\r\n }\r\n }\r\n\r\n private cleanup(): void {\r\n const now = Date.now();\r\n for (const [key, entry] of this.store) {\r\n if (entry.expiresAt && now > entry.expiresAt) {\r\n this.store.delete(key);\r\n this.removeFromTagIndex(key, entry.tags);\r\n }\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Create in-memory cache adapter\r\n */\r\nexport function memory(options: MemoryCacheAdapterOptions = {}): CacheAdapter {\r\n return new MemoryCacheAdapter(options);\r\n}\r\n\r\n// ============================================================================\r\n// Cache Factory\r\n// ============================================================================\r\n\r\nexport interface CreateCacheOptions {\r\n /** Custom cache adapter (defaults to in-memory) */\r\n adapter?: CacheAdapter;\r\n /** Default TTL for all entries (seconds) */\r\n defaultTTL?: number;\r\n /** Key prefix for namespacing */\r\n prefix?: string;\r\n /** Custom serializer (for external adapters) */\r\n serializer?: Serializer;\r\n /** Track cache statistics */\r\n trackStats?: boolean;\r\n}\r\n\r\n/**\r\n * Create a new cache instance\r\n * \r\n * @example\r\n * ```typescript\r\n * // Simple in-memory cache\r\n * const cache = createCache();\r\n * \r\n * // With Redis adapter\r\n * import { redis } from '@flightdev/cache-redis';\r\n * const cache = createCache({\r\n * adapter: redis({ url: 'redis://localhost:6379' }),\r\n * defaultTTL: 3600,\r\n * prefix: 'myapp',\r\n * });\r\n * ```\r\n */\r\nexport function createCache(options: CreateCacheOptions = {}): Cache {\r\n const {\r\n adapter = new MemoryCacheAdapter(),\r\n defaultTTL,\r\n prefix = '',\r\n trackStats = false,\r\n } = options;\r\n\r\n // Local tag index for adapters that don't support distributed tags\r\n const localTagIndex = new Map<string, Set<string>>();\r\n\r\n // Stats tracking\r\n const stats: CacheStats = { hits: 0, misses: 0, sets: 0, deletes: 0 };\r\n\r\n function prefixKey(key: string): string {\r\n return prefix ? `${prefix}:${key}` : key;\r\n }\r\n\r\n function useDistributedTags(): boolean {\r\n return !!(adapter.supportsDistributedTags && adapter.addToTag && adapter.getTagMembers && adapter.deleteTag);\r\n }\r\n\r\n async function registerTags(fullKey: string, tags?: string[]): Promise<void> {\r\n if (!tags || tags.length === 0) return;\r\n\r\n if (useDistributedTags()) {\r\n // Distributed: adapter handles tag storage\r\n for (const tag of tags) {\r\n await adapter.addToTag!(tag, fullKey);\r\n }\r\n } else {\r\n // Local: use in-memory index (for memory adapter or simple adapters)\r\n for (const tag of tags) {\r\n if (!localTagIndex.has(tag)) {\r\n localTagIndex.set(tag, new Set());\r\n }\r\n localTagIndex.get(tag)!.add(fullKey);\r\n }\r\n }\r\n }\r\n\r\n async function getTagMembers(tag: string): Promise<string[]> {\r\n if (useDistributedTags()) {\r\n return adapter.getTagMembers!(tag);\r\n }\r\n return Array.from(localTagIndex.get(tag) ?? []);\r\n }\r\n\r\n async function removeTag(tag: string): Promise<void> {\r\n if (useDistributedTags()) {\r\n await adapter.deleteTag!(tag);\r\n } else {\r\n localTagIndex.delete(tag);\r\n }\r\n }\r\n\r\n return {\r\n async get<T>(key: string): Promise<T | undefined> {\r\n const entry = await adapter.get<T>(prefixKey(key));\r\n\r\n if (!entry) {\r\n if (trackStats) stats.misses++;\r\n return undefined;\r\n }\r\n\r\n if (trackStats) stats.hits++;\r\n\r\n // Check stale-while-revalidate (return stale value, caller should revalidate)\r\n // The value is still returned even if stale - that's the \"while revalidate\" part\r\n return entry.value;\r\n },\r\n\r\n async set<T>(key: string, value: T, opts?: CacheOptions): Promise<void> {\r\n const ttl = opts?.ttl ?? defaultTTL;\r\n const now = Date.now();\r\n\r\n const entry: CacheEntry<T> = {\r\n value,\r\n createdAt: now,\r\n tags: opts?.tags,\r\n };\r\n\r\n if (ttl) {\r\n entry.expiresAt = now + (ttl * 1000);\r\n if (opts?.swr) {\r\n entry.staleAt = now + ((ttl - opts.swr) * 1000);\r\n }\r\n }\r\n\r\n const fullKey = prefixKey(key);\r\n await adapter.set(fullKey, entry);\r\n await registerTags(fullKey, opts?.tags);\r\n\r\n if (trackStats) stats.sets++;\r\n },\r\n\r\n async delete(key: string): Promise<boolean> {\r\n const fullKey = prefixKey(key);\r\n const result = await adapter.delete(fullKey);\r\n if (trackStats && result) stats.deletes++;\r\n return result;\r\n },\r\n\r\n async has(key: string): Promise<boolean> {\r\n return adapter.has(prefixKey(key));\r\n },\r\n\r\n async clear(): Promise<void> {\r\n await adapter.clear();\r\n localTagIndex.clear();\r\n },\r\n\r\n async invalidateTag(tag: string): Promise<void> {\r\n const keys = await getTagMembers(tag);\r\n\r\n for (const key of keys) {\r\n await adapter.delete(key);\r\n }\r\n\r\n await removeTag(tag);\r\n },\r\n\r\n async invalidateTags(tags: string[]): Promise<void> {\r\n for (const tag of tags) {\r\n await this.invalidateTag(tag);\r\n }\r\n },\r\n\r\n async getOrSet<T>(\r\n key: string,\r\n factory: () => Promise<T>,\r\n opts?: CacheOptions\r\n ): Promise<T> {\r\n const cached = await this.get<T>(key);\r\n if (cached !== undefined) {\r\n return cached;\r\n }\r\n\r\n const value = await factory();\r\n await this.set(key, value, opts);\r\n return value;\r\n },\r\n\r\n async getMany<T>(keys: string[]): Promise<Map<string, T | undefined>> {\r\n const result = new Map<string, T | undefined>();\r\n\r\n if (adapter.getMany) {\r\n // Use batch operation if adapter supports it\r\n const entries = await adapter.getMany<T>(keys.map(prefixKey));\r\n for (const [key, entry] of entries) {\r\n const originalKey = prefix ? key.slice(prefix.length + 1) : key;\r\n result.set(originalKey, entry?.value);\r\n }\r\n } else {\r\n // Fallback to individual gets\r\n for (const key of keys) {\r\n result.set(key, await this.get<T>(key));\r\n }\r\n }\r\n\r\n return result;\r\n },\r\n\r\n async setMany<T>(entries: Map<string, T>, opts?: CacheOptions): Promise<void> {\r\n const ttl = opts?.ttl ?? defaultTTL;\r\n const now = Date.now();\r\n\r\n const cacheEntries = new Map<string, CacheEntry<T>>();\r\n\r\n for (const [key, value] of entries) {\r\n const entry: CacheEntry<T> = {\r\n value,\r\n createdAt: now,\r\n tags: opts?.tags,\r\n };\r\n\r\n if (ttl) {\r\n entry.expiresAt = now + (ttl * 1000);\r\n if (opts?.swr) {\r\n entry.staleAt = now + ((ttl - opts.swr) * 1000);\r\n }\r\n }\r\n\r\n const fullKey = prefixKey(key);\r\n cacheEntries.set(fullKey, entry);\r\n await registerTags(fullKey, opts?.tags);\r\n }\r\n\r\n if (adapter.setMany) {\r\n await adapter.setMany(cacheEntries);\r\n } else {\r\n for (const [key, entry] of cacheEntries) {\r\n await adapter.set(key, entry);\r\n }\r\n }\r\n\r\n if (trackStats) stats.sets += entries.size;\r\n },\r\n\r\n getStats() {\r\n return trackStats ? { ...stats } : undefined;\r\n },\r\n };\r\n}\r\n\r\n// ============================================================================\r\n// Cache Utilities\r\n// ============================================================================\r\n\r\n/**\r\n * Create a cache key from multiple parts\r\n * \r\n * @example\r\n * ```typescript\r\n * cacheKey('user', userId, 'profile'); // \"user:123:profile\"\r\n * ```\r\n */\r\nexport function cacheKey(...parts: (string | number | boolean | undefined)[]): string {\r\n return parts\r\n .filter(p => p !== undefined)\r\n .map(p => String(p))\r\n .join(':');\r\n}\r\n\r\n/**\r\n * Wrap a function with caching\r\n * \r\n * @example\r\n * ```typescript\r\n * const getCachedUser = cached(cache, getUser, {\r\n * ttl: 300,\r\n * keyFn: (userId) => `user:${userId}`,\r\n * });\r\n * \r\n * const user = await getCachedUser(123);\r\n * ```\r\n */\r\nexport function cached<T extends (...args: unknown[]) => Promise<unknown>>(\r\n cache: Cache,\r\n fn: T,\r\n options?: CacheOptions & { keyFn?: (...args: Parameters<T>) => string }\r\n): T {\r\n const { keyFn = (...args: unknown[]) => JSON.stringify(args), ...cacheOpts } = options ?? {};\r\n\r\n return (async (...args: Parameters<T>) => {\r\n const key = keyFn(...args);\r\n return cache.getOrSet(key, () => fn(...args) as Promise<unknown>, cacheOpts);\r\n }) as T;\r\n}\r\n\r\n/**\r\n * Create a deduplication wrapper to prevent duplicate concurrent requests\r\n * \r\n * @example\r\n * ```typescript\r\n * const dedupedFetch = dedupe(fetchUser);\r\n * \r\n * // These will share the same request\r\n * const [user1, user2] = await Promise.all([\r\n * dedupedFetch(123),\r\n * dedupedFetch(123),\r\n * ]);\r\n * ```\r\n */\r\nexport function dedupe<T extends (...args: unknown[]) => Promise<unknown>>(\r\n fn: T,\r\n keyFn: (...args: Parameters<T>) => string = (...args) => JSON.stringify(args)\r\n): T {\r\n const pending = new Map<string, Promise<unknown>>();\r\n\r\n return (async (...args: Parameters<T>) => {\r\n const key = keyFn(...args);\r\n\r\n if (pending.has(key)) {\r\n return pending.get(key);\r\n }\r\n\r\n const promise = fn(...args).finally(() => {\r\n pending.delete(key);\r\n });\r\n\r\n pending.set(key, promise);\r\n return promise;\r\n }) as T;\r\n}\r\n"]}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { FlightConfig, FlightUserConfig } from './config/index.js';
|
|
2
|
+
export { Route, RouteMatch, RouteParams, Router, createRouter } from './router/index.js';
|
|
3
|
+
export { Cache, CacheAdapter, CacheEntry, CacheOptions, CacheStats, CreateCacheOptions, Serializer, cacheKey, cached, createCache, dedupe, jsonSerializer, memory } from './cache/index.js';
|
|
4
|
+
export { Middleware, MiddlewareContext, MiddlewareNext, createMiddlewareChain } from './middleware/index.js';
|
|
5
|
+
export { CustomHydrationTrigger, HydrateOptions, HydrationTrigger, IslandConfig, hydrateIslands, registerFlightIslandElement } from './islands/index.js';
|
|
6
|
+
export { BuiltInCondition, DEFAULT_BOT_PATTERNS, StreamingCondition, isBot, isSlowConnection, prefersNoStream, supportsStreaming } from './streaming/conditional.js';
|
|
7
|
+
export { BadRequestError, ErrorBoundaryOptions, FlightError, FlightErrorOptions, FlightErrorProps, ForbiddenError, InternalError, NotFoundError, ResetDetails, UnauthorizedError, clearError, createError, getError, getErrorStatusCode, isFlightError, isForbiddenError as isForbidden, isNotFoundError as isNotFound, isUnauthorizedError as isUnauthorized, showError } from './errors/index.js';
|
|
8
|
+
export { getEnvironment, isBrowser, isDevelopment, isProduction, isServer, isTest } from './utils/index.js';
|
|
9
|
+
import './render/index.js';
|
|
10
|
+
import './adapters/index.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Flight Framework - Core (Browser-Safe Exports)
|
|
14
|
+
*
|
|
15
|
+
* This entry point only exports modules that are safe to use in browser environments.
|
|
16
|
+
* Use this import when building for the client:
|
|
17
|
+
*
|
|
18
|
+
* import { ... } from '@flightdev/core/client';
|
|
19
|
+
*
|
|
20
|
+
* Server-only modules (file-router, prerender, etc.) are NOT included.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
declare const VERSION = "0.0.1";
|
|
24
|
+
|
|
25
|
+
export { VERSION };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { DEFAULT_BOT_PATTERNS, isBot, isSlowConnection, prefersNoStream, supportsStreaming } from './chunk-UVH5XJRP.js';
|
|
2
|
+
export { hydrateIslands, registerFlightIslandElement } from './chunk-IW7FTQQX.js';
|
|
3
|
+
export { createMiddlewareChain } from './chunk-OYF2OAKS.js';
|
|
4
|
+
import './chunk-NCGPUFWV.js';
|
|
5
|
+
export { BadRequestError, FlightError, ForbiddenError, InternalError, NotFoundError, UnauthorizedError, clearError, createError, getError, getErrorStatusCode, isFlightError, isForbiddenError as isForbidden, isNotFoundError as isNotFound, isUnauthorizedError as isUnauthorized, showError } from './chunk-Q7BS5QC5.js';
|
|
6
|
+
import './chunk-PL37KFRJ.js';
|
|
7
|
+
export { getEnvironment, isBrowser, isDevelopment, isProduction, isServer, isTest } from './chunk-LWVETFJV.js';
|
|
8
|
+
export { createRouter } from './chunk-GCQZ4FHI.js';
|
|
9
|
+
export { cacheKey, cached, createCache, dedupe, jsonSerializer, memory } from './chunk-ZZZML7Y3.js';
|
|
10
|
+
|
|
11
|
+
// src/client.ts
|
|
12
|
+
var VERSION = "0.0.1";
|
|
13
|
+
|
|
14
|
+
export { VERSION };
|
|
15
|
+
//# sourceMappingURL=client.js.map
|
|
16
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;AAuGO,IAAM,OAAA,GAAU","file":"client.js","sourcesContent":["/**\r\n * Flight Framework - Core (Browser-Safe Exports)\r\n *\r\n * This entry point only exports modules that are safe to use in browser environments.\r\n * Use this import when building for the client:\r\n *\r\n * import { ... } from '@flightdev/core/client';\r\n *\r\n * Server-only modules (file-router, prerender, etc.) are NOT included.\r\n */\r\n\r\n// Configuration (browser-safe parts only)\r\nexport { type FlightConfig, type FlightUserConfig } from './config/index.js';\r\n\r\n// Router (browser-safe)\r\nexport {\r\n createRouter,\r\n type Route,\r\n type RouteMatch,\r\n type Router,\r\n type RouteParams,\r\n} from './router/index.js';\r\n\r\n// Cache (browser-safe)\r\nexport {\r\n createCache,\r\n memory,\r\n cacheKey,\r\n cached,\r\n dedupe,\r\n jsonSerializer,\r\n type Cache,\r\n type CacheOptions,\r\n type CacheEntry,\r\n type CacheAdapter,\r\n type CacheStats,\r\n type Serializer,\r\n type CreateCacheOptions,\r\n} from './cache/index.js';\r\n\r\n// Middleware (browser-safe)\r\nexport {\r\n createMiddlewareChain,\r\n type Middleware,\r\n type MiddlewareContext,\r\n type MiddlewareNext,\r\n} from './middleware/index.js';\r\n\r\n// Islands (browser-safe hydration)\r\nexport {\r\n hydrateIslands,\r\n registerFlightIslandElement,\r\n type HydrationTrigger,\r\n type CustomHydrationTrigger,\r\n type IslandConfig,\r\n type HydrateOptions,\r\n} from './islands/index.js';\r\n\r\n// Streaming Conditional (browser-safe detection)\r\nexport {\r\n isBot,\r\n prefersNoStream,\r\n isSlowConnection,\r\n supportsStreaming,\r\n DEFAULT_BOT_PATTERNS,\r\n type StreamingCondition,\r\n type BuiltInCondition,\r\n} from './streaming/conditional.js';\r\n\r\n// Error Handling (browser-safe)\r\nexport {\r\n FlightError,\r\n BadRequestError,\r\n UnauthorizedError,\r\n ForbiddenError,\r\n NotFoundError,\r\n InternalError,\r\n createError,\r\n showError,\r\n clearError,\r\n getError,\r\n isFlightError,\r\n isNotFoundError as isNotFound,\r\n isForbiddenError as isForbidden,\r\n isUnauthorizedError as isUnauthorized,\r\n getErrorStatusCode,\r\n type FlightErrorOptions,\r\n type FlightErrorProps,\r\n type ResetDetails,\r\n type ErrorBoundaryOptions,\r\n} from './errors/index.js';\r\n\r\n// Environment Utilities (browser-safe)\r\nexport {\r\n isProduction,\r\n isDevelopment,\r\n isTest,\r\n isServer,\r\n isBrowser,\r\n getEnvironment,\r\n} from './utils/index.js';\r\n\r\n// Version\r\nexport const VERSION = '0.0.1';\r\n"]}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { RenderMode } from '../render/index.js';
|
|
2
|
+
import { FlightAdapter } from '../adapters/index.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Flight Configuration - User configuration system
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Bundler adapter interface.
|
|
10
|
+
* Import the full type from @flightdev/bundler for implementation.
|
|
11
|
+
*/
|
|
12
|
+
interface BundlerAdapter {
|
|
13
|
+
/** Adapter identifier */
|
|
14
|
+
name: string;
|
|
15
|
+
/** Bundler name (vite, esbuild, rolldown, etc.) */
|
|
16
|
+
bundler: string;
|
|
17
|
+
/** Bundler-specific options */
|
|
18
|
+
options?: Record<string, unknown>;
|
|
19
|
+
/** Create dev server */
|
|
20
|
+
createDevServer(config: FlightConfig): Promise<unknown>;
|
|
21
|
+
/** Build for production */
|
|
22
|
+
build(config: FlightConfig): Promise<unknown>;
|
|
23
|
+
}
|
|
24
|
+
/** UI Framework configuration */
|
|
25
|
+
interface UIConfig {
|
|
26
|
+
/** The UI framework to use */
|
|
27
|
+
framework?: 'react' | 'vue' | 'svelte' | 'solid' | 'preact' | 'vanilla' | string;
|
|
28
|
+
/** Framework-specific options */
|
|
29
|
+
options?: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
/** Rendering configuration */
|
|
32
|
+
interface RenderConfig {
|
|
33
|
+
/** Default render mode */
|
|
34
|
+
default?: RenderMode;
|
|
35
|
+
/** Per-route render mode overrides */
|
|
36
|
+
routes?: Record<string, RenderMode>;
|
|
37
|
+
}
|
|
38
|
+
/** Development server options */
|
|
39
|
+
interface DevConfig {
|
|
40
|
+
/** Port to run dev server on */
|
|
41
|
+
port?: number;
|
|
42
|
+
/** Host to bind to */
|
|
43
|
+
host?: string | boolean;
|
|
44
|
+
/** Open browser on start */
|
|
45
|
+
open?: boolean;
|
|
46
|
+
/** HTTPS configuration */
|
|
47
|
+
https?: boolean | {
|
|
48
|
+
key?: string;
|
|
49
|
+
cert?: string;
|
|
50
|
+
};
|
|
51
|
+
/** Proxy configuration */
|
|
52
|
+
proxy?: Record<string, string | {
|
|
53
|
+
target: string;
|
|
54
|
+
changeOrigin?: boolean;
|
|
55
|
+
rewrite?: (path: string) => string;
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
/** Build configuration */
|
|
59
|
+
interface BuildConfig {
|
|
60
|
+
/** Output directory */
|
|
61
|
+
outDir?: string;
|
|
62
|
+
/** Source directory */
|
|
63
|
+
srcDir?: string;
|
|
64
|
+
/** Public assets directory */
|
|
65
|
+
publicDir?: string;
|
|
66
|
+
/** Routes directory */
|
|
67
|
+
routesDir?: string;
|
|
68
|
+
/** Generate sourcemaps */
|
|
69
|
+
sourcemap?: boolean | 'inline' | 'hidden';
|
|
70
|
+
/** Minify output */
|
|
71
|
+
minify?: boolean | 'terser' | 'esbuild';
|
|
72
|
+
/** Target environments */
|
|
73
|
+
target?: string | string[];
|
|
74
|
+
}
|
|
75
|
+
/** Full Flight configuration (resolved) */
|
|
76
|
+
interface FlightConfig {
|
|
77
|
+
/** Root directory */
|
|
78
|
+
root: string;
|
|
79
|
+
/** Deployment adapter */
|
|
80
|
+
adapter: FlightAdapter | null;
|
|
81
|
+
/** Bundler adapter (Vite, esbuild, Rolldown, etc.) */
|
|
82
|
+
bundler: BundlerAdapter | null;
|
|
83
|
+
/** UI framework configuration */
|
|
84
|
+
ui: UIConfig;
|
|
85
|
+
/** Rendering configuration */
|
|
86
|
+
rendering: RenderConfig;
|
|
87
|
+
/** Development server options */
|
|
88
|
+
dev: Required<DevConfig>;
|
|
89
|
+
/** Build configuration */
|
|
90
|
+
build: Required<BuildConfig>;
|
|
91
|
+
/** Bundler-specific configuration (passed to adapter) */
|
|
92
|
+
bundlerOptions?: Record<string, unknown>;
|
|
93
|
+
/** @deprecated Use bundler adapter instead */
|
|
94
|
+
vite?: Record<string, unknown>;
|
|
95
|
+
/** Plugin configurations */
|
|
96
|
+
plugins: FlightPlugin[];
|
|
97
|
+
}
|
|
98
|
+
/** Flight plugin interface */
|
|
99
|
+
interface FlightPlugin {
|
|
100
|
+
/** Plugin name */
|
|
101
|
+
name: string;
|
|
102
|
+
/** Hook into config resolution */
|
|
103
|
+
config?: (config: FlightConfig) => FlightConfig | void | Promise<FlightConfig | void>;
|
|
104
|
+
/** Hook into build start */
|
|
105
|
+
buildStart?: () => void | Promise<void>;
|
|
106
|
+
/** Hook into build end */
|
|
107
|
+
buildEnd?: () => void | Promise<void>;
|
|
108
|
+
/** Hook into dev server start */
|
|
109
|
+
devStart?: () => void | Promise<void>;
|
|
110
|
+
}
|
|
111
|
+
/** User-provided configuration (partial) */
|
|
112
|
+
interface FlightUserConfig {
|
|
113
|
+
/** Root directory (defaults to process.cwd()) */
|
|
114
|
+
root?: string;
|
|
115
|
+
/** Deployment adapter */
|
|
116
|
+
adapter?: FlightAdapter;
|
|
117
|
+
/** Bundler adapter (Vite, esbuild, Rolldown, etc.) */
|
|
118
|
+
bundler?: BundlerAdapter;
|
|
119
|
+
/** UI framework configuration */
|
|
120
|
+
ui?: UIConfig;
|
|
121
|
+
/** Rendering configuration */
|
|
122
|
+
rendering?: RenderConfig;
|
|
123
|
+
/** Development server options */
|
|
124
|
+
dev?: DevConfig;
|
|
125
|
+
/** Build configuration */
|
|
126
|
+
build?: BuildConfig;
|
|
127
|
+
/** Bundler-specific configuration */
|
|
128
|
+
bundlerOptions?: Record<string, unknown>;
|
|
129
|
+
/** @deprecated Use bundler adapter instead */
|
|
130
|
+
vite?: Record<string, unknown>;
|
|
131
|
+
/** Plugins */
|
|
132
|
+
plugins?: FlightPlugin[];
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Define Flight configuration
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* // flight.config.ts
|
|
140
|
+
* import { defineConfig } from '@flightdev/core';
|
|
141
|
+
* import node from '@flightdev/adapter-node';
|
|
142
|
+
*
|
|
143
|
+
* export default defineConfig({
|
|
144
|
+
* adapter: node(),
|
|
145
|
+
* ui: { framework: 'react' },
|
|
146
|
+
* rendering: {
|
|
147
|
+
* default: 'ssr',
|
|
148
|
+
* routes: {
|
|
149
|
+
* '/blog/*': 'ssg',
|
|
150
|
+
* '/app/*': 'csr',
|
|
151
|
+
* },
|
|
152
|
+
* },
|
|
153
|
+
* });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare function defineConfig(config: FlightUserConfig): FlightUserConfig;
|
|
157
|
+
/**
|
|
158
|
+
* Resolve user config to full config with defaults
|
|
159
|
+
*/
|
|
160
|
+
declare function resolveConfig(userConfig?: FlightUserConfig): FlightConfig;
|
|
161
|
+
/**
|
|
162
|
+
* Find the config file in a directory
|
|
163
|
+
*/
|
|
164
|
+
declare function findConfigFile(root: string): Promise<string | null>;
|
|
165
|
+
/**
|
|
166
|
+
* Load configuration from file
|
|
167
|
+
*/
|
|
168
|
+
declare function loadConfig(root?: string): Promise<FlightConfig>;
|
|
169
|
+
|
|
170
|
+
export { type BuildConfig, type BundlerAdapter, type DevConfig, type FlightConfig, type FlightPlugin, type FlightUserConfig, type RenderConfig, type UIConfig, defineConfig, findConfigFile, loadConfig, resolveConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|