semola 0.5.4 → 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.
Files changed (50) hide show
  1. package/README.md +35 -50
  2. package/dist/lib/api/index.cjs +1 -523
  3. package/dist/lib/api/index.d.cts +1 -271
  4. package/dist/lib/api/index.d.mts +80 -84
  5. package/dist/lib/api/index.mjs +1 -521
  6. package/dist/lib/cache/index.cjs +1 -74
  7. package/dist/lib/cache/index.d.cts +1 -48
  8. package/dist/lib/cache/index.d.mts +3 -24
  9. package/dist/lib/cache/index.mjs +1 -73
  10. package/dist/lib/cron/index.cjs +1 -735
  11. package/dist/lib/cron/index.d.cts +1 -146
  12. package/dist/lib/cron/index.d.mts +99 -36
  13. package/dist/lib/cron/index.mjs +1 -726
  14. package/dist/lib/errors/index.cjs +1 -30
  15. package/dist/lib/errors/index.d.cts +1 -2
  16. package/dist/lib/errors/index.d.mts +12 -1
  17. package/dist/lib/errors/index.mjs +1 -26
  18. package/dist/lib/i18n/index.cjs +1 -42
  19. package/dist/lib/i18n/index.d.cts +1 -28
  20. package/dist/lib/i18n/index.mjs +1 -41
  21. package/dist/lib/logging/index.cjs +1 -387
  22. package/dist/lib/logging/index.d.cts +1 -108
  23. package/dist/lib/logging/index.mjs +1 -374
  24. package/dist/lib/orm/index.cjs +1 -0
  25. package/dist/lib/orm/index.d.cts +1 -0
  26. package/dist/lib/orm/index.d.mts +404 -0
  27. package/dist/lib/orm/index.mjs +1 -0
  28. package/dist/lib/policy/index.cjs +1 -285
  29. package/dist/lib/policy/index.d.cts +1 -77
  30. package/dist/lib/policy/index.mjs +1 -265
  31. package/dist/lib/prompts/index.cjs +6 -769
  32. package/dist/lib/prompts/index.d.cts +1 -96
  33. package/dist/lib/prompts/index.d.mts +12 -33
  34. package/dist/lib/prompts/index.mjs +6 -763
  35. package/dist/lib/pubsub/index.cjs +1 -117
  36. package/dist/lib/pubsub/index.d.cts +1 -41
  37. package/dist/lib/pubsub/index.d.mts +3 -18
  38. package/dist/lib/pubsub/index.mjs +1 -116
  39. package/dist/lib/queue/index.cjs +1 -182
  40. package/dist/lib/queue/index.d.cts +1 -74
  41. package/dist/lib/queue/index.d.mts +11 -4
  42. package/dist/lib/queue/index.mjs +1 -181
  43. package/dist/lib/workflow/index.cjs +1 -534
  44. package/dist/lib/workflow/index.d.cts +1 -85
  45. package/dist/lib/workflow/index.d.mts +76 -11
  46. package/dist/lib/workflow/index.mjs +1 -533
  47. package/dist/rolldown-runtime-CMqjfN_6.cjs +1 -0
  48. package/package.json +17 -5
  49. package/dist/index-BhGNDjPq.d.mts +0 -13
  50. package/dist/index-DxSbeGP-.d.cts +0 -13
@@ -1,5 +1,4 @@
1
1
  //#region src/lib/cache/types.d.ts
2
- type CacheError = "CacheError" | "InvalidTTLError" | "NotFoundError";
3
2
  type CacheOptions<T> = {
4
3
  redis: Bun.RedisClient;
5
4
  ttl?: number | ((key: string, value: T) => number);
@@ -7,10 +6,6 @@ type CacheOptions<T> = {
7
6
  prefix?: string;
8
7
  serializer?: (value: T) => string;
9
8
  deserializer?: (raw: string) => T;
10
- onError?: (error: {
11
- type: CacheError;
12
- message: string;
13
- }) => void;
14
9
  };
15
10
  //#endregion
16
11
  //#region src/lib/cache/index.d.ts
@@ -19,25 +14,9 @@ declare class Cache<T> {
19
14
  private serialize;
20
15
  private deserialize;
21
16
  constructor(options: CacheOptions<T>);
22
- get(key: string): Promise<readonly [{
23
- readonly type: "NotFoundError";
24
- readonly message: string;
25
- }, null] | readonly [{
26
- readonly type: "CacheError";
27
- readonly message: string;
28
- }, null] | readonly [null, T]>;
29
- set(key: string, value: T): Promise<readonly [{
30
- readonly type: "CacheError";
31
- readonly message: string;
32
- }, null] | readonly [null, T] | readonly [{
33
- readonly type: "InvalidTTLError";
34
- readonly message: string;
35
- }, null]>;
36
- delete(key: string): Promise<readonly [null, number] | readonly [{
37
- readonly type: "CacheError";
38
- readonly message: string;
39
- }, null]>;
40
- private fail;
17
+ get(key: string): Promise<T>;
18
+ set(key: string, value: T): Promise<T>;
19
+ delete(key: string): Promise<number>;
41
20
  private get isEnabled();
42
21
  private resolveKey;
43
22
  private resolveTTL;
@@ -1,73 +1 @@
1
- import { err, mightThrow, mightThrowSync, ok } from "../errors/index.mjs";
2
- //#region src/lib/cache/index.ts
3
- var Cache = class {
4
- options;
5
- serialize;
6
- deserialize;
7
- constructor(options) {
8
- this.options = options;
9
- this.serialize = options.serializer ?? JSON.stringify;
10
- this.deserialize = options.deserializer ?? ((raw) => JSON.parse(raw));
11
- }
12
- async get(key) {
13
- if (!this.isEnabled) return this.fail("NotFoundError", `Key ${key} not found`);
14
- const resolvedKey = this.resolveKey(key);
15
- const [error, value] = await mightThrow(this.options.redis.get(resolvedKey));
16
- if (error) return this.fail("CacheError", `Unable to get value for key ${key}`);
17
- if (value === null || value === void 0) return this.fail("NotFoundError", `Key ${key} not found`);
18
- const [deserializeErr, deserialized] = mightThrowSync(() => this.deserialize(value));
19
- if (deserializeErr) return this.fail("CacheError", `Unable to deserialize value for key ${key}`);
20
- return ok(deserialized);
21
- }
22
- async set(key, value) {
23
- if (!this.isEnabled) return ok(value);
24
- const [serializeErr, serialized] = mightThrowSync(() => this.serialize(value));
25
- if (serializeErr) return this.fail("CacheError", `Unable to serialize value for key ${key}`);
26
- if (serialized === null || serialized === void 0) return this.fail("CacheError", `Unable to serialize value for key ${key}`);
27
- const [ttlErr, ttl] = mightThrowSync(() => this.resolveTTL(key, value));
28
- if (ttlErr) return this.fail("InvalidTTLError", `Unable to resolve ttl for key ${key}`);
29
- if (!this.isTTLValid(ttl)) return this.fail("InvalidTTLError", `Unable to save records with ttl equal to ${ttl}`);
30
- const resolvedKey = this.resolveKey(key);
31
- const [setError] = await mightThrow(this.getSetPromise(resolvedKey, serialized, ttl));
32
- if (setError) return this.fail("CacheError", `Unable to set value for key ${key}`);
33
- return ok(value);
34
- }
35
- async delete(key) {
36
- if (!this.isEnabled) return ok(0);
37
- const resolvedKey = this.resolveKey(key);
38
- const [error, data] = await mightThrow(this.options.redis.del(resolvedKey));
39
- if (error) return this.fail("CacheError", `Unable to delete key ${key}`);
40
- return ok(data);
41
- }
42
- fail(type, message) {
43
- this.options.onError?.({
44
- type,
45
- message
46
- });
47
- return err(type, message);
48
- }
49
- get isEnabled() {
50
- return this.options.enabled !== false;
51
- }
52
- resolveKey(key) {
53
- if (this.options.prefix) return `${this.options.prefix}:${key}`;
54
- return key;
55
- }
56
- resolveTTL(key, value) {
57
- if (typeof this.options.ttl === "function") return this.options.ttl(key, value);
58
- return this.options.ttl;
59
- }
60
- getSetPromise(key, value, ttl) {
61
- if (ttl === void 0 || ttl === null) return this.options.redis.set(key, value);
62
- return this.options.redis.set(key, value, "PX", ttl);
63
- }
64
- isTTLValid(ttl) {
65
- if (ttl === void 0 || ttl === null) return true;
66
- if (!Number.isFinite(ttl)) return false;
67
- if (!Number.isInteger(ttl)) return false;
68
- if (ttl < 0) return false;
69
- return true;
70
- }
71
- };
72
- //#endregion
73
- 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};