@getstrata/core 0.5.40 → 0.5.42
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/dist/core/cache/simpleCache.d.ts +1 -0
- package/dist/core/cache/simpleCacheStore.d.ts +1 -0
- package/dist/core/database/baseRepository.d.ts +1 -0
- package/dist/core/queue/failedJobRepository.d.ts +1 -0
- package/dist/core/queue/failedJobService.d.ts +1 -0
- package/dist/entries/audit/exportAuditLogs.js +18 -0
- package/dist/entries/auth/sessionGuard.js +443 -0
- package/dist/entries/cache/simpleCache.js +178 -0
- package/dist/entries/cache/simpleCacheStore.js +42 -0
- package/dist/entries/database/baseRepository.js +1388 -0
- package/dist/entries/database/bindConnection.js +22 -0
- package/dist/entries/database/boundConnection.js +19 -0
- package/dist/entries/database/connection.js +12 -0
- package/dist/entries/database/errors.js +128 -0
- package/dist/entries/database/model.js +948 -0
- package/dist/entries/database/query.js +436 -0
- package/dist/entries/database/relationships.js +162 -0
- package/dist/entries/database/table.js +8 -0
- package/dist/entries/database/transaction.js +129 -0
- package/dist/entries/http/authMiddleware.js +47 -0
- package/dist/entries/http/authorizeMiddleware.js +104 -0
- package/dist/entries/http/metricsMiddleware.js +91 -0
- package/dist/entries/http/parseMultipartUpload.js +144 -0
- package/dist/entries/http/securedRouteModelBinding.js +6 -0
- package/dist/entries/http/webErrorResponse.js +443 -0
- package/dist/entries/http/webFormRequest.js +6 -0
- package/dist/entries/jobs/dispatchWebhookJob.js +18 -0
- package/dist/entries/queue/createAppQueue.js +449 -0
- package/dist/entries/queue/failedJobRepository.js +2306 -0
- package/dist/entries/queue/failedJobService.js +3 -0
- package/dist/entries/queue/publicQueue.js +449 -0
- package/dist/entries/queue/queueMetrics.js +449 -0
- package/dist/entries/queue/redisQueue.js +232 -0
- package/dist/entries/security/scimTenantTokens.js +51 -0
- package/dist/entries/tenant/tenantDatabaseScope.js +113 -0
- package/dist/entries/view.js +443 -0
- package/package.json +102 -2
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/core/cache/simpleCache.ts
|
|
3
|
+
class SimpleCache {
|
|
4
|
+
ttlMs;
|
|
5
|
+
maxEntries;
|
|
6
|
+
cache = new Map;
|
|
7
|
+
inflight = new Map;
|
|
8
|
+
tagIndex = new Map;
|
|
9
|
+
keyTags = new Map;
|
|
10
|
+
constructor(ttlMs = 3600000, maxEntries = 100) {
|
|
11
|
+
this.ttlMs = ttlMs;
|
|
12
|
+
this.maxEntries = maxEntries;
|
|
13
|
+
if (!Number.isFinite(ttlMs) || ttlMs < 0) {
|
|
14
|
+
throw new RangeError("ttlMs must be a non-negative number.");
|
|
15
|
+
}
|
|
16
|
+
if (!Number.isInteger(maxEntries) || maxEntries < 1) {
|
|
17
|
+
throw new RangeError("maxEntries must be a positive integer.");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
get(key) {
|
|
21
|
+
return this.getFreshEntry(key)?.value;
|
|
22
|
+
}
|
|
23
|
+
set(key, value, ttlMs) {
|
|
24
|
+
const now = Date.now();
|
|
25
|
+
const resolvedTtlMs = ttlMs ?? this.ttlMs;
|
|
26
|
+
this.cache.set(key, {
|
|
27
|
+
value,
|
|
28
|
+
expiresAt: now + resolvedTtlMs,
|
|
29
|
+
lastAccessedAt: now
|
|
30
|
+
});
|
|
31
|
+
this.evictOverflow();
|
|
32
|
+
}
|
|
33
|
+
async getOrSet(key, loader, ttlMs) {
|
|
34
|
+
this.pruneExpired();
|
|
35
|
+
const cachedEntry = this.getFreshEntry(key);
|
|
36
|
+
if (cachedEntry) {
|
|
37
|
+
return cachedEntry.value;
|
|
38
|
+
}
|
|
39
|
+
const inflightRequest = this.inflight.get(key);
|
|
40
|
+
if (inflightRequest) {
|
|
41
|
+
return inflightRequest;
|
|
42
|
+
}
|
|
43
|
+
const pendingRequest = loader().then((value) => {
|
|
44
|
+
this.set(key, value, ttlMs);
|
|
45
|
+
return value;
|
|
46
|
+
}).finally(() => {
|
|
47
|
+
this.inflight.delete(key);
|
|
48
|
+
});
|
|
49
|
+
this.inflight.set(key, pendingRequest);
|
|
50
|
+
return pendingRequest;
|
|
51
|
+
}
|
|
52
|
+
attachTags(key, tags) {
|
|
53
|
+
if (tags.length === 0) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
let tagsForKey = this.keyTags.get(key);
|
|
57
|
+
if (!tagsForKey) {
|
|
58
|
+
tagsForKey = new Set;
|
|
59
|
+
this.keyTags.set(key, tagsForKey);
|
|
60
|
+
}
|
|
61
|
+
for (const tag of tags) {
|
|
62
|
+
tagsForKey.add(tag);
|
|
63
|
+
let keysForTag = this.tagIndex.get(tag);
|
|
64
|
+
if (!keysForTag) {
|
|
65
|
+
keysForTag = new Set;
|
|
66
|
+
this.tagIndex.set(tag, keysForTag);
|
|
67
|
+
}
|
|
68
|
+
keysForTag.add(key);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
flushTags(tags) {
|
|
72
|
+
const keysToRemove = new Set;
|
|
73
|
+
for (const tag of tags) {
|
|
74
|
+
const keys = this.tagIndex.get(tag);
|
|
75
|
+
if (!keys) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
for (const key of keys) {
|
|
79
|
+
keysToRemove.add(key);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
let removed = 0;
|
|
83
|
+
for (const key of keysToRemove) {
|
|
84
|
+
if (this.invalidate(key)) {
|
|
85
|
+
removed += 1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (const tag of tags) {
|
|
89
|
+
this.tagIndex.delete(tag);
|
|
90
|
+
}
|
|
91
|
+
return removed;
|
|
92
|
+
}
|
|
93
|
+
invalidate(key) {
|
|
94
|
+
const removed = this.cache.delete(key);
|
|
95
|
+
if (removed) {
|
|
96
|
+
this.detachKeyFromTags(key);
|
|
97
|
+
}
|
|
98
|
+
return removed;
|
|
99
|
+
}
|
|
100
|
+
invalidateByPrefix(prefix) {
|
|
101
|
+
let removed = 0;
|
|
102
|
+
for (const key of [...this.cache.keys()]) {
|
|
103
|
+
if (key === prefix || key.startsWith(`${prefix}?`)) {
|
|
104
|
+
if (this.invalidate(key)) {
|
|
105
|
+
removed += 1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return removed;
|
|
110
|
+
}
|
|
111
|
+
clear() {
|
|
112
|
+
this.cache.clear();
|
|
113
|
+
this.inflight.clear();
|
|
114
|
+
this.tagIndex.clear();
|
|
115
|
+
this.keyTags.clear();
|
|
116
|
+
}
|
|
117
|
+
size() {
|
|
118
|
+
this.pruneExpired();
|
|
119
|
+
return this.cache.size;
|
|
120
|
+
}
|
|
121
|
+
detachKeyFromTags(key) {
|
|
122
|
+
const tags = this.keyTags.get(key);
|
|
123
|
+
if (!tags) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
for (const tag of tags) {
|
|
127
|
+
const keys = this.tagIndex.get(tag);
|
|
128
|
+
if (!keys) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
keys.delete(key);
|
|
132
|
+
if (keys.size === 0) {
|
|
133
|
+
this.tagIndex.delete(tag);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
this.keyTags.delete(key);
|
|
137
|
+
}
|
|
138
|
+
getFreshEntry(key) {
|
|
139
|
+
const entry = this.cache.get(key);
|
|
140
|
+
if (!entry) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (entry.expiresAt <= Date.now()) {
|
|
144
|
+
this.invalidate(key);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
entry.lastAccessedAt = Date.now();
|
|
148
|
+
return entry;
|
|
149
|
+
}
|
|
150
|
+
pruneExpired() {
|
|
151
|
+
const now = Date.now();
|
|
152
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
153
|
+
if (entry.expiresAt <= now) {
|
|
154
|
+
this.invalidate(key);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
evictOverflow() {
|
|
159
|
+
while (this.cache.size > this.maxEntries) {
|
|
160
|
+
let oldestKey;
|
|
161
|
+
let oldestAccessTime = Number.POSITIVE_INFINITY;
|
|
162
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
163
|
+
if (entry.lastAccessedAt < oldestAccessTime) {
|
|
164
|
+
oldestAccessTime = entry.lastAccessedAt;
|
|
165
|
+
oldestKey = key;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (!oldestKey) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
this.invalidate(oldestKey);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
var simpleCache_default = SimpleCache;
|
|
176
|
+
export {
|
|
177
|
+
SimpleCache
|
|
178
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/core/cache/simpleCacheStore.ts
|
|
3
|
+
class SimpleCacheStore {
|
|
4
|
+
cache;
|
|
5
|
+
constructor(cache) {
|
|
6
|
+
this.cache = cache;
|
|
7
|
+
}
|
|
8
|
+
get(key) {
|
|
9
|
+
return Promise.resolve(this.cache.get(key));
|
|
10
|
+
}
|
|
11
|
+
set(key, value, ttlMs) {
|
|
12
|
+
this.cache.set(key, value, ttlMs);
|
|
13
|
+
return Promise.resolve();
|
|
14
|
+
}
|
|
15
|
+
getOrSet(key, loader, ttlMs) {
|
|
16
|
+
return this.cache.getOrSet(key, loader, ttlMs);
|
|
17
|
+
}
|
|
18
|
+
attachTags(key, tags) {
|
|
19
|
+
this.cache.attachTags(key, tags);
|
|
20
|
+
return Promise.resolve();
|
|
21
|
+
}
|
|
22
|
+
flushTags(tags) {
|
|
23
|
+
return Promise.resolve(this.cache.flushTags(tags));
|
|
24
|
+
}
|
|
25
|
+
invalidate(key) {
|
|
26
|
+
return Promise.resolve(this.cache.invalidate(key));
|
|
27
|
+
}
|
|
28
|
+
invalidateByPrefix(prefix) {
|
|
29
|
+
return Promise.resolve(this.cache.invalidateByPrefix(prefix));
|
|
30
|
+
}
|
|
31
|
+
clear() {
|
|
32
|
+
this.cache.clear();
|
|
33
|
+
return Promise.resolve();
|
|
34
|
+
}
|
|
35
|
+
size() {
|
|
36
|
+
return Promise.resolve(this.cache.size());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
var simpleCacheStore_default = SimpleCacheStore;
|
|
40
|
+
export {
|
|
41
|
+
SimpleCacheStore
|
|
42
|
+
};
|