semola 0.6.0 → 0.6.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/README.md +17 -5
- package/dist/lib/api/index.cjs +1 -537
- package/dist/lib/api/index.d.cts +1 -271
- package/dist/lib/api/index.d.mts +80 -84
- package/dist/lib/api/index.mjs +1 -535
- package/dist/lib/cache/index.cjs +1 -99
- package/dist/lib/cache/index.d.cts +1 -27
- package/dist/lib/cache/index.mjs +1 -98
- package/dist/lib/cron/index.cjs +1 -735
- package/dist/lib/cron/index.d.cts +1 -146
- package/dist/lib/cron/index.d.mts +99 -36
- package/dist/lib/cron/index.mjs +1 -726
- package/dist/lib/errors/index.cjs +1 -30
- package/dist/lib/errors/index.d.cts +1 -13
- package/dist/lib/errors/index.mjs +1 -26
- package/dist/lib/i18n/index.cjs +1 -42
- package/dist/lib/i18n/index.d.cts +1 -28
- package/dist/lib/i18n/index.mjs +1 -41
- package/dist/lib/logging/index.cjs +1 -388
- package/dist/lib/logging/index.d.cts +1 -108
- package/dist/lib/logging/index.mjs +1 -374
- package/dist/lib/orm/index.cjs +1 -1642
- package/dist/lib/orm/index.d.cts +1 -402
- package/dist/lib/orm/index.d.mts +4 -2
- package/dist/lib/orm/index.mjs +1 -1630
- package/dist/lib/policy/index.cjs +1 -285
- package/dist/lib/policy/index.d.cts +1 -77
- package/dist/lib/policy/index.mjs +1 -265
- package/dist/lib/prompts/index.cjs +6 -769
- package/dist/lib/prompts/index.d.cts +1 -75
- package/dist/lib/prompts/index.mjs +6 -762
- package/dist/lib/pubsub/index.cjs +1 -141
- package/dist/lib/pubsub/index.d.cts +1 -26
- package/dist/lib/pubsub/index.mjs +1 -140
- package/dist/lib/queue/index.cjs +1 -212
- package/dist/lib/queue/index.d.cts +1 -81
- package/dist/lib/queue/index.mjs +1 -209
- package/dist/lib/workflow/index.cjs +1 -537
- package/dist/lib/workflow/index.d.cts +1 -150
- package/dist/lib/workflow/index.mjs +1 -527
- package/dist/rolldown-runtime-CMqjfN_6.cjs +1 -0
- package/package.json +7 -5
- package/dist/chunk-CKQMccvm.cjs +0 -28
package/dist/lib/cache/index.mjs
CHANGED
|
@@ -1,98 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//#region src/lib/cache/errors.ts
|
|
3
|
-
var CacheError = class extends Error {
|
|
4
|
-
constructor(message) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.name = "CacheError";
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
var InvalidTTLError = class extends Error {
|
|
10
|
-
constructor(message) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.name = "InvalidTTLError";
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
var NotFoundError = class extends Error {
|
|
16
|
-
constructor(message) {
|
|
17
|
-
super(message);
|
|
18
|
-
this.name = "NotFoundError";
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
var SerializationError = class extends Error {
|
|
22
|
-
constructor(message) {
|
|
23
|
-
super(message);
|
|
24
|
-
this.name = "SerializationError";
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var DeserializationError = class extends Error {
|
|
28
|
-
constructor(message) {
|
|
29
|
-
super(message);
|
|
30
|
-
this.name = "DeserializationError";
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/lib/cache/index.ts
|
|
35
|
-
var Cache = class {
|
|
36
|
-
options;
|
|
37
|
-
serialize;
|
|
38
|
-
deserialize;
|
|
39
|
-
constructor(options) {
|
|
40
|
-
this.options = options;
|
|
41
|
-
this.serialize = options.serializer ?? JSON.stringify;
|
|
42
|
-
this.deserialize = options.deserializer ?? ((raw) => JSON.parse(raw));
|
|
43
|
-
}
|
|
44
|
-
async get(key) {
|
|
45
|
-
if (!this.isEnabled) throw new NotFoundError(`Key ${key} not found`);
|
|
46
|
-
const resolvedKey = this.resolveKey(key);
|
|
47
|
-
const [error, value] = await mightThrow(this.options.redis.get(resolvedKey));
|
|
48
|
-
if (error) throw new CacheError(`Unable to get value for key ${key}`);
|
|
49
|
-
if (value === null || value === void 0) throw new NotFoundError(`Key ${key} not found`);
|
|
50
|
-
const [deserializeErr, deserialized] = mightThrowSync(() => this.deserialize(value));
|
|
51
|
-
if (deserializeErr) throw new DeserializationError(`Unable to deserialize value for key ${key}`);
|
|
52
|
-
return deserialized;
|
|
53
|
-
}
|
|
54
|
-
async set(key, value) {
|
|
55
|
-
if (!this.isEnabled) return value;
|
|
56
|
-
const [serializeErr, serialized] = mightThrowSync(() => this.serialize(value));
|
|
57
|
-
if (serializeErr) throw new SerializationError(`Unable to serialize value for key ${key}`);
|
|
58
|
-
if (serialized === null || serialized === void 0) throw new SerializationError(`Unable to serialize value for key ${key}`);
|
|
59
|
-
const [ttlErr, ttl] = mightThrowSync(() => this.resolveTTL(key, value));
|
|
60
|
-
if (ttlErr) throw new InvalidTTLError(`Unable to resolve ttl for key ${key}`);
|
|
61
|
-
if (!this.isTTLValid(ttl)) throw new InvalidTTLError(`Unable to save records with ttl equal to ${ttl}`);
|
|
62
|
-
const resolvedKey = this.resolveKey(key);
|
|
63
|
-
const [setError] = await mightThrow(this.getSetPromise(resolvedKey, serialized, ttl));
|
|
64
|
-
if (setError) throw new CacheError(`Unable to set value for key ${key}`);
|
|
65
|
-
return value;
|
|
66
|
-
}
|
|
67
|
-
async delete(key) {
|
|
68
|
-
if (!this.isEnabled) return 0;
|
|
69
|
-
const resolvedKey = this.resolveKey(key);
|
|
70
|
-
const [error, data] = await mightThrow(this.options.redis.del(resolvedKey));
|
|
71
|
-
if (error) throw new CacheError(`Unable to delete key ${key}`);
|
|
72
|
-
return data;
|
|
73
|
-
}
|
|
74
|
-
get isEnabled() {
|
|
75
|
-
return this.options.enabled !== false;
|
|
76
|
-
}
|
|
77
|
-
resolveKey(key) {
|
|
78
|
-
if (this.options.prefix) return `${this.options.prefix}:${key}`;
|
|
79
|
-
return key;
|
|
80
|
-
}
|
|
81
|
-
resolveTTL(key, value) {
|
|
82
|
-
if (typeof this.options.ttl === "function") return this.options.ttl(key, value);
|
|
83
|
-
return this.options.ttl;
|
|
84
|
-
}
|
|
85
|
-
getSetPromise(key, value, ttl) {
|
|
86
|
-
if (ttl === void 0 || ttl === null) return this.options.redis.set(key, value);
|
|
87
|
-
return this.options.redis.set(key, value, "PX", ttl);
|
|
88
|
-
}
|
|
89
|
-
isTTLValid(ttl) {
|
|
90
|
-
if (ttl === void 0 || ttl === null) return true;
|
|
91
|
-
if (!Number.isFinite(ttl)) return false;
|
|
92
|
-
if (!Number.isInteger(ttl)) return false;
|
|
93
|
-
if (ttl < 0) return false;
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
//#endregion
|
|
98
|
-
export { Cache };
|
|
1
|
+
import{mightThrow as e,mightThrowSync as t}from"../errors/index.mjs";var n=class extends Error{constructor(e){super(e),this.name=`CacheError`}},r=class extends Error{constructor(e){super(e),this.name=`InvalidTTLError`}},i=class extends Error{constructor(e){super(e),this.name=`NotFoundError`}},a=class extends Error{constructor(e){super(e),this.name=`SerializationError`}},o=class extends Error{constructor(e){super(e),this.name=`DeserializationError`}},s=class{options;serialize;deserialize;constructor(e){this.options=e,this.serialize=e.serializer??JSON.stringify,this.deserialize=e.deserializer??(e=>JSON.parse(e))}async get(r){if(!this.isEnabled)throw new i(`Key ${r} not found`);let a=this.resolveKey(r),[s,c]=await e(this.options.redis.get(a));if(s)throw new n(`Unable to get value for key ${r}`);if(c==null)throw new i(`Key ${r} not found`);let[l,u]=t(()=>this.deserialize(c));if(l)throw new o(`Unable to deserialize value for key ${r}`);return u}async set(i,o){if(!this.isEnabled)return o;let[s,c]=t(()=>this.serialize(o));if(s||c==null)throw new a(`Unable to serialize value for key ${i}`);let[l,u]=t(()=>this.resolveTTL(i,o));if(l)throw new r(`Unable to resolve ttl for key ${i}`);if(!this.isTTLValid(u))throw new r(`Unable to save records with ttl equal to ${u}`);let d=this.resolveKey(i),[f]=await e(this.getSetPromise(d,c,u));if(f)throw new n(`Unable to set value for key ${i}`);return o}async delete(t){if(!this.isEnabled)return 0;let r=this.resolveKey(t),[i,a]=await e(this.options.redis.del(r));if(i)throw new n(`Unable to delete key ${t}`);return a}get isEnabled(){return this.options.enabled!==!1}resolveKey(e){return this.options.prefix?`${this.options.prefix}:${e}`:e}resolveTTL(e,t){return typeof this.options.ttl==`function`?this.options.ttl(e,t):this.options.ttl}getSetPromise(e,t,n){return n==null?this.options.redis.set(e,t):this.options.redis.set(e,t,`PX`,n)}isTTLValid(e){return e==null?!0:!(!Number.isFinite(e)||!Number.isInteger(e)||e<0)}};export{s as Cache};
|