@blazetrails/solid-cache 0.0.0-stage → 0.1.0-alpha0.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 (94) hide show
  1. package/LICENSE +21 -0
  2. package/dist/active-support/cache/solid-cache-store.d.ts +2 -0
  3. package/dist/active-support/cache/solid-cache-store.js +4 -0
  4. package/dist/active-support/cache/solid-cache-store.js.map +1 -0
  5. package/dist/configuration.d.ts +31 -0
  6. package/dist/configuration.js +60 -0
  7. package/dist/configuration.js.map +1 -0
  8. package/dist/connections/sharded.d.ts +16 -0
  9. package/dist/connections/sharded.js +45 -0
  10. package/dist/connections/sharded.js.map +1 -0
  11. package/dist/connections/single.d.ts +12 -0
  12. package/dist/connections/single.js +29 -0
  13. package/dist/connections/single.js.map +1 -0
  14. package/dist/connections/unmanaged.d.ts +10 -0
  15. package/dist/connections/unmanaged.js +24 -0
  16. package/dist/connections/unmanaged.js.map +1 -0
  17. package/dist/connections.d.ts +10 -0
  18. package/dist/connections.js +37 -0
  19. package/dist/connections.js.map +1 -0
  20. package/dist/constants.generated.d.ts +2 -0
  21. package/dist/constants.generated.js +53 -0
  22. package/dist/constants.generated.js.map +1 -0
  23. package/dist/engine.d.ts +19 -0
  24. package/dist/engine.js +59 -0
  25. package/dist/engine.js.map +1 -0
  26. package/dist/entry/encryption.d.ts +10 -0
  27. package/dist/entry/encryption.js +12 -0
  28. package/dist/entry/encryption.js.map +1 -0
  29. package/dist/entry/expiration.d.ts +23 -0
  30. package/dist/entry/expiration.js +53 -0
  31. package/dist/entry/expiration.js.map +1 -0
  32. package/dist/entry/size/estimate.d.ts +38 -0
  33. package/dist/entry/size/estimate.js +91 -0
  34. package/dist/entry/size/estimate.js.map +1 -0
  35. package/dist/entry/size/moving-average-estimate.d.ts +29 -0
  36. package/dist/entry/size/moving-average-estimate.js +55 -0
  37. package/dist/entry/size/moving-average-estimate.js.map +1 -0
  38. package/dist/entry/size.d.ts +16 -0
  39. package/dist/entry/size.js +31 -0
  40. package/dist/entry/size.js.map +1 -0
  41. package/dist/entry.d.ts +55 -0
  42. package/dist/entry.js +137 -0
  43. package/dist/entry.js.map +1 -0
  44. package/dist/expiry-job.d.ts +10 -0
  45. package/dist/expiry-job.js +14 -0
  46. package/dist/expiry-job.js.map +1 -0
  47. package/dist/generators/solid-cache/install/install-generator.d.ts +14 -0
  48. package/dist/generators/solid-cache/install/install-generator.js +60 -0
  49. package/dist/generators/solid-cache/install/install-generator.js.map +1 -0
  50. package/dist/generators/solid-cache/install/templates/config/cache.ts.tt +25 -0
  51. package/dist/generators/solid-cache/install/templates/config/cache.ts.tt.js +23 -0
  52. package/dist/generators/solid-cache/install/templates/db/cache_schema.ts.tt +16 -0
  53. package/dist/generators/solid-cache/install/templates/db/cache_schema.ts.tt.js +12 -0
  54. package/dist/generators/solid-cache/install/templates/db/cache_structure.mysql.sql +56 -0
  55. package/dist/generators/solid-cache/install/templates/db/cache_structure.postgresql.sql +128 -0
  56. package/dist/generators/solid-cache/install/templates/db/cache_structure.sqlite3.sql +6 -0
  57. package/dist/index.d.ts +12 -0
  58. package/dist/index.js +12 -0
  59. package/dist/index.js.map +1 -0
  60. package/dist/maglev-hash.d.ts +38 -0
  61. package/dist/maglev-hash.js +80 -0
  62. package/dist/maglev-hash.js.map +1 -0
  63. package/dist/record.d.ts +12 -0
  64. package/dist/record.js +55 -0
  65. package/dist/record.js.map +1 -0
  66. package/dist/solid-cache.d.ts +27 -0
  67. package/dist/solid-cache.js +11 -0
  68. package/dist/solid-cache.js.map +1 -0
  69. package/dist/store/api.d.ts +52 -0
  70. package/dist/store/api.js +178 -0
  71. package/dist/store/api.js.map +1 -0
  72. package/dist/store/connections.d.ts +38 -0
  73. package/dist/store/connections.js +65 -0
  74. package/dist/store/connections.js.map +1 -0
  75. package/dist/store/entries.d.ts +26 -0
  76. package/dist/store/entries.js +57 -0
  77. package/dist/store/entries.js.map +1 -0
  78. package/dist/store/execution.d.ts +15 -0
  79. package/dist/store/execution.js +53 -0
  80. package/dist/store/execution.js.map +1 -0
  81. package/dist/store/expiry.d.ts +10 -0
  82. package/dist/store/expiry.js +38 -0
  83. package/dist/store/expiry.js.map +1 -0
  84. package/dist/store/failsafe.d.ts +16 -0
  85. package/dist/store/failsafe.js +35 -0
  86. package/dist/store/failsafe.js.map +1 -0
  87. package/dist/store/stats.d.ts +19 -0
  88. package/dist/store/stats.js +29 -0
  89. package/dist/store/stats.js.map +1 -0
  90. package/dist/store.d.ts +69 -0
  91. package/dist/store.js +130 -0
  92. package/dist/store.js.map +1 -0
  93. package/package.json +60 -3
  94. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Dean Marano and Trails contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=solid-cache-store.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { ActiveSupport } from "@blazetrails/activesupport/namespaces";
2
+ import { Store } from "../../store.js";
3
+ ActiveSupport.Cache.SolidCacheStore = Store;
4
+ //# sourceMappingURL=solid-cache-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solid-cache-store.js","sourceRoot":"","sources":["../../../lib/active-support/cache/solid-cache-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,aAAa,CAAC,KAAK,CAAC,eAAe,GAAG,KAAK,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { type EncryptsOptions } from "@blazetrails/activerecord/encryption";
2
+ type ConnectsTo = {
3
+ shards?: Record<string, Record<string, string>>;
4
+ } & Record<string, unknown>;
5
+ export declare class Configuration {
6
+ readonly storeOptions: Record<string, unknown>;
7
+ connectsTo: ConnectsTo | null;
8
+ readonly executor: unknown;
9
+ readonly sizeEstimateSamples: number;
10
+ readonly encrypt: unknown;
11
+ readonly encryptionContextProperties: EncryptsOptions | null;
12
+ constructor({ storeOptions, database, databases, connectsTo, executor, encrypt, encryptionContextProperties, sizeEstimateSamples, }?: {
13
+ storeOptions?: Record<string, unknown>;
14
+ database?: string | null;
15
+ databases?: string | string[] | null;
16
+ connectsTo?: ConnectsTo | null;
17
+ executor?: unknown;
18
+ encrypt?: unknown;
19
+ encryptionContextProperties?: EncryptsOptions | null;
20
+ sizeEstimateSamples?: number;
21
+ });
22
+ isSharded(): Record<string, Record<string, string>> | null | undefined;
23
+ shardKeys(): string[];
24
+ isEncrypt(): boolean;
25
+ /** @internal */
26
+ private setConnectsTo;
27
+ /** @internal */
28
+ private defaultEncryptionContextProperties;
29
+ }
30
+ export {};
31
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1,60 @@
1
+ import { Encryptor } from "@blazetrails/activerecord/encryption";
2
+ import { MessagePackMessageSerializer } from "@blazetrails/activerecord/encryption/message-pack-message-serializer";
3
+ import { isPresent } from "@blazetrails/activesupport";
4
+ import { ArgumentError, rbFArray } from "@blazetrails/ruby-compat";
5
+ export class Configuration {
6
+ storeOptions;
7
+ connectsTo;
8
+ executor;
9
+ sizeEstimateSamples;
10
+ encrypt;
11
+ encryptionContextProperties;
12
+ constructor({ storeOptions = {}, database = null, databases = null, connectsTo = null, executor = null, encrypt = false, encryptionContextProperties = null, sizeEstimateSamples = 10_000, } = {}) {
13
+ this.storeOptions = storeOptions;
14
+ this.sizeEstimateSamples = sizeEstimateSamples;
15
+ this.executor = executor;
16
+ this.encrypt = encrypt;
17
+ this.encryptionContextProperties = encryptionContextProperties;
18
+ if (this.isEncrypt()) {
19
+ this.encryptionContextProperties ??= this.defaultEncryptionContextProperties();
20
+ }
21
+ this.setConnectsTo({ database, databases, connectsTo });
22
+ }
23
+ isSharded() {
24
+ return this.connectsTo && this.connectsTo.shards;
25
+ }
26
+ shardKeys() {
27
+ return this.isSharded() ? Object.keys(this.connectsTo.shards) : [];
28
+ }
29
+ isEncrypt() {
30
+ return isPresent(this.encrypt);
31
+ }
32
+ /** @internal */
33
+ setConnectsTo({ database, databases, connectsTo, }) {
34
+ if ([database, databases, connectsTo].filter((x) => x != null).length > 1) {
35
+ throw new ArgumentError("You can only specify one of :database, :databases, or :connects_to");
36
+ }
37
+ if (database) {
38
+ this.connectsTo = { shards: { [database]: { writing: database } } };
39
+ }
40
+ else if (databases) {
41
+ this.connectsTo = {
42
+ shards: Object.fromEntries(rbFArray(databases).map((database) => [database, { writing: database }])),
43
+ };
44
+ }
45
+ else if (connectsTo) {
46
+ this.connectsTo = connectsTo;
47
+ }
48
+ else {
49
+ this.connectsTo = null;
50
+ }
51
+ }
52
+ /** @internal */
53
+ defaultEncryptionContextProperties() {
54
+ return {
55
+ encryptor: new Encryptor({ compress: false }),
56
+ messageSerializer: new MessagePackMessageSerializer(),
57
+ };
58
+ }
59
+ }
60
+ //# sourceMappingURL=configuration.js.map
@@ -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C,iBAAiB,EAAE,IAAI,4BAA4B,EAAE;SACtD,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import { type Enumerator } from "@blazetrails/ruby-compat";
2
+ import { MaglevHash } from "../maglev-hash.js";
3
+ export declare class Sharded {
4
+ readonly names: string[];
5
+ readonly nodes: string[] | null;
6
+ readonly consistentHash: MaglevHash;
7
+ constructor(names: string[]);
8
+ withEach(block?: () => unknown): Promise<void> | Enumerator;
9
+ with<T>(name: string, block: () => T): T;
10
+ withConnectionFor<T>(key: unknown, block: () => T): T;
11
+ assign<K>(keys: K[]): Map<string, K[]>;
12
+ count(): number;
13
+ /** @internal */
14
+ private shardFor;
15
+ }
16
+ //# sourceMappingURL=sharded.d.ts.map
@@ -0,0 +1,45 @@
1
+ import { toEnum } from "@blazetrails/ruby-compat";
2
+ import { MaglevHash } from "../maglev-hash.js";
3
+ import { Record } from "../record.js";
4
+ export class Sharded {
5
+ names;
6
+ nodes = null;
7
+ consistentHash;
8
+ constructor(names) {
9
+ this.names = names;
10
+ this.consistentHash = new MaglevHash(names);
11
+ }
12
+ withEach(block) {
13
+ if (!block)
14
+ return toEnum(this, "withEach");
15
+ return (async () => {
16
+ for (const name of this.names)
17
+ await this.with(name, block);
18
+ })();
19
+ }
20
+ with(name, block) {
21
+ return Record.withShard(name, block);
22
+ }
23
+ withConnectionFor(key, block) {
24
+ return this.with(this.shardFor(key), block);
25
+ }
26
+ assign(keys) {
27
+ const groups = new Map();
28
+ for (const key of keys) {
29
+ const shard = this.shardFor(key != null && typeof key === "object" && "key" in key ? key.key : key);
30
+ let group = groups.get(shard);
31
+ if (!group)
32
+ groups.set(shard, (group = []));
33
+ group.push(key);
34
+ }
35
+ return groups;
36
+ }
37
+ count() {
38
+ return this.names.length;
39
+ }
40
+ /** @internal */
41
+ shardFor(key) {
42
+ return this.consistentHash.node(key);
43
+ }
44
+ }
45
+ //# sourceMappingURL=sharded.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CACvE,CAAC;YACF,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAC9B,IAAI,CAAC,KAAK;gBAAE,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC;YAC5C,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED,gBAAgB;IACR,QAAQ,CAAC,GAAY;QAC3B,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ import { type Enumerator } from "@blazetrails/ruby-compat";
2
+ export declare class Single {
3
+ readonly name: string;
4
+ constructor(name: string);
5
+ withEach<T>(block?: () => T): T | Enumerator;
6
+ with<T>(name: string, block: () => T): T;
7
+ withConnectionFor<T>(_key: unknown, block: () => T): T;
8
+ assign<K>(keys: K[]): Map<string, K[]>;
9
+ count(): number;
10
+ get names(): string[];
11
+ }
12
+ //# sourceMappingURL=single.d.ts.map
@@ -0,0 +1,29 @@
1
+ import { toEnum } from "@blazetrails/ruby-compat";
2
+ import { Record } from "../record.js";
3
+ export class Single {
4
+ name;
5
+ constructor(name) {
6
+ this.name = name;
7
+ }
8
+ withEach(block) {
9
+ if (!block)
10
+ return toEnum(this, "withEach");
11
+ return this.with(this.name, block);
12
+ }
13
+ with(name, block) {
14
+ return Record.withShard(name, block);
15
+ }
16
+ withConnectionFor(_key, block) {
17
+ return this.with(this.name, block);
18
+ }
19
+ assign(keys) {
20
+ return new Map([[this.name, keys]]);
21
+ }
22
+ count() {
23
+ return 1;
24
+ }
25
+ get names() {
26
+ return [this.name];
27
+ }
28
+ }
29
+ //# sourceMappingURL=single.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"single.js","sourceRoot":"","sources":["../../lib/connections/single.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmB,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,OAAO,MAAM;IACR,IAAI,CAAS;IAEtB,YAAY,IAAY;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,QAAQ,CAAI,KAAe;QACzB,IAAI,CAAC,KAAK;YAAE,OAAO,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAE5C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,IAAI,CAAI,IAAY,EAAE,KAAc;QAClC,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,iBAAiB,CAAI,IAAa,EAAE,KAAc;QAChD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,CAAI,IAAS;QACjB,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IAED,KAAK;QACH,OAAO,CAAC,CAAC;IACX,CAAC;IAED,IAAI,KAAK;QACP,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import { type Enumerator } from "@blazetrails/ruby-compat";
2
+ export declare class Unmanaged {
3
+ withEach<T>(block?: () => T): T | Enumerator;
4
+ with<T>(_name: unknown, block: () => T): T;
5
+ withConnectionFor<T>(_key: unknown, block: () => T): T;
6
+ assign<K>(keys: K[]): Map<string, K[]>;
7
+ count(): number;
8
+ get names(): string[];
9
+ }
10
+ //# sourceMappingURL=unmanaged.d.ts.map
@@ -0,0 +1,24 @@
1
+ import { toEnum } from "@blazetrails/ruby-compat";
2
+ export class Unmanaged {
3
+ withEach(block) {
4
+ if (!block)
5
+ return toEnum(this, "withEach");
6
+ return block();
7
+ }
8
+ with(_name, block) {
9
+ return block();
10
+ }
11
+ withConnectionFor(_key, block) {
12
+ return block();
13
+ }
14
+ assign(keys) {
15
+ return new Map([["default", keys]]);
16
+ }
17
+ count() {
18
+ return 1;
19
+ }
20
+ get names() {
21
+ return ["default"];
22
+ }
23
+ }
24
+ //# sourceMappingURL=unmanaged.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unmanaged.js","sourceRoot":"","sources":["../../lib/connections/unmanaged.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmB,MAAM,0BAA0B,CAAC;AAEnE,MAAM,OAAO,SAAS;IACpB,QAAQ,CAAI,KAAe;QACzB,IAAI,CAAC,KAAK;YAAE,OAAO,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAE5C,OAAO,KAAK,EAAE,CAAC;IACjB,CAAC;IAED,IAAI,CAAI,KAAc,EAAE,KAAc;QACpC,OAAO,KAAK,EAAE,CAAC;IACjB,CAAC;IAED,iBAAiB,CAAI,IAAa,EAAE,KAAc;QAChD,OAAO,KAAK,EAAE,CAAC;IACjB,CAAC;IAED,MAAM,CAAI,IAAS;QACjB,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IAED,KAAK;QACH,OAAO,CAAC,CAAC;IACX,CAAC;IAED,IAAI,KAAK;QACP,OAAO,CAAC,SAAS,CAAC,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import { Sharded } from "./connections/sharded.js";
2
+ import { Single } from "./connections/single.js";
3
+ import { Unmanaged } from "./connections/unmanaged.js";
4
+ export declare const Connections: {
5
+ Sharded: typeof Sharded;
6
+ Single: typeof Single;
7
+ Unmanaged: typeof Unmanaged;
8
+ fromConfig(options: string[] | null | undefined): Sharded | Single | Unmanaged;
9
+ };
10
+ //# sourceMappingURL=connections.d.ts.map
@@ -0,0 +1,37 @@
1
+ import { isPresent, pluralize } from "@blazetrails/activesupport";
2
+ import { ArgumentError, constSet } from "@blazetrails/ruby-compat";
3
+ import { Sharded } from "./connections/sharded.js";
4
+ import { Single } from "./connections/single.js";
5
+ import { Unmanaged } from "./connections/unmanaged.js";
6
+ import { SolidCache } from "./solid-cache.js";
7
+ export const Connections = {
8
+ Sharded,
9
+ Single,
10
+ Unmanaged,
11
+ fromConfig(options) {
12
+ if (isPresent(options) || SolidCache.configuration.isSharded()) {
13
+ let names;
14
+ if (options == null) {
15
+ names = SolidCache.configuration.shardKeys();
16
+ }
17
+ else if (Array.isArray(options)) {
18
+ names = options.map((option) => String(option));
19
+ }
20
+ const unknownShards = names.filter((name) => !SolidCache.configuration.shardKeys().includes(name));
21
+ if (unknownShards.length > 0) {
22
+ throw new ArgumentError(`Unknown ${pluralize("shard", unknownShards)}: ${unknownShards.join(", ")}`);
23
+ }
24
+ if (names.length === 1) {
25
+ return new Single(names[0]);
26
+ }
27
+ else {
28
+ return new Sharded(names);
29
+ }
30
+ }
31
+ else {
32
+ return new Unmanaged();
33
+ }
34
+ },
35
+ };
36
+ constSet(SolidCache, "Connections", Connections);
37
+ //# sourceMappingURL=connections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connections.js","sourceRoot":"","sources":["../lib/connections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,yB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IAAI,SAAS,EAAE,CAAC;QACzB,CAAC;IACH,CAAC;CACF,CAAC;AAEF,QAAQ,CAAC,UAAU,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=constants.generated.d.ts.map
@@ -0,0 +1,53 @@
1
+ import { defineConstants } from "@blazetrails/ruby-compat";
2
+ import * as m0 from "./configuration.js";
3
+ import * as m1 from "./connections.js";
4
+ import * as m2 from "./connections/sharded.js";
5
+ import * as m3 from "./connections/single.js";
6
+ import * as m4 from "./connections/unmanaged.js";
7
+ import * as m5 from "./engine.js";
8
+ import * as m6 from "./entry.js";
9
+ import * as m7 from "./entry/encryption.js";
10
+ import * as m8 from "./entry/expiration.js";
11
+ import * as m9 from "./entry/size.js";
12
+ import * as m10 from "./entry/size/estimate.js";
13
+ import * as m11 from "./entry/size/moving-average-estimate.js";
14
+ import * as m12 from "./expiry-job.js";
15
+ import * as m13 from "./maglev-hash.js";
16
+ import * as m14 from "./record.js";
17
+ import * as m15 from "./store.js";
18
+ import * as m16 from "./store/api.js";
19
+ import * as m17 from "./store/connections.js";
20
+ import * as m18 from "./store/entries.js";
21
+ import * as m19 from "./store/execution.js";
22
+ import * as m20 from "./store/expiry.js";
23
+ import * as m21 from "./store/failsafe.js";
24
+ import * as m22 from "./store/stats.js";
25
+ defineConstants([
26
+ [m0, "Configuration", "SolidCache::Configuration"],
27
+ [m1, "Connections", "SolidCache::Connections"],
28
+ [m2, "Sharded", "SolidCache::Connections::Sharded"],
29
+ [m3, "Single", "SolidCache::Connections::Single"],
30
+ [m4, "Unmanaged", "SolidCache::Connections::Unmanaged"],
31
+ [m5, "Engine", "SolidCache::Engine"],
32
+ [m6, "Entry", "SolidCache::Entry"],
33
+ [m7, "Encryption", "SolidCache::Entry::Encryption"],
34
+ [m8, "Expiration", "SolidCache::Entry::Expiration"],
35
+ [m8, "ClassMethods", "SolidCache::Entry::Expiration::ClassMethods"],
36
+ [m9, "Size", "SolidCache::Entry::Size"],
37
+ [m9, "ClassMethods", "SolidCache::Entry::Size::ClassMethods"],
38
+ [m10, "Estimate", "SolidCache::Entry::Size::Estimate"],
39
+ [m11, "MovingAverageEstimate", "SolidCache::Entry::Size::MovingAverageEstimate"],
40
+ [m12, "ExpiryJob", "SolidCache::ExpiryJob"],
41
+ [m13, "MaglevHash", "SolidCache::MaglevHash"],
42
+ [m13, "Preferences", "SolidCache::MaglevHash::Preferences"],
43
+ [m14, "Record", "SolidCache::Record"],
44
+ [m15, "Store", "SolidCache::Store"],
45
+ [m16, "Api", "SolidCache::Store::Api"],
46
+ [m17, "Connections", "SolidCache::Store::Connections"],
47
+ [m18, "Entries", "SolidCache::Store::Entries"],
48
+ [m19, "Execution", "SolidCache::Store::Execution"],
49
+ [m20, "Expiry", "SolidCache::Store::Expiry"],
50
+ [m21, "Failsafe", "SolidCache::Store::Failsafe"],
51
+ [m22, "Stats", "SolidCache::Store::Stats"],
52
+ ]);
53
+ //# sourceMappingURL=constants.generated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.generated.js","sourceRoot":"","sources":["../lib/constants.generated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO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,mCAAmC,CAAC;IACtD,CAAC,GAAG,EAAE,uBAAuB,EAAE,gDAAgD,CAAC;IAChF,CAAC,GAAG,EAAE,WAAW,EAAE,uBAAuB,CAAC;IAC3C,CAAC,GAAG,EAAE,YAAY,EAAE,wBAAwB,CAAC;IAC7C,CAAC,GAAG,EAAE,aAAa,EAAE,qCAAqC,CAAC;IAC3D,CAAC,GAAG,EAAE,QAAQ,EAAE,oBAAoB,CAAC;IACrC,CAAC,GAAG,EAAE,OAAO,EAAE,mBAAmB,CAAC;IACnC,CAAC,GAAG,EAAE,KAAK,EAAE,wBAAwB,CAAC;IACtC,CAAC,GAAG,EAAE,aAAa,EAAE,gCAAgC,CAAC;IACtD,CAAC,GAAG,EAAE,SAAS,EAAE,4BAA4B,CAAC;IAC9C,CAAC,GAAG,EAAE,WAAW,EAAE,8BAA8B,CAAC;IAClD,CAAC,GAAG,EAAE,QAAQ,EAAE,2BAA2B,CAAC;IAC5C,CAAC,GAAG,EAAE,UAAU,EAAE,6BAA6B,CAAC;IAChD,CAAC,GAAG,EAAE,OAAO,EAAE,0BAA0B,CAAC;CAC3C,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { OrderedOptions } from "@blazetrails/activesupport";
2
+ import { Engine as TrailsEngine } from "@blazetrails/trailties/engine";
3
+ export interface SolidCacheConfig extends OrderedOptions {
4
+ executor?: unknown;
5
+ connectsTo?: unknown;
6
+ sizeEstimateSamples?: number;
7
+ encrypt?: unknown;
8
+ encryptionContextProperties?: unknown;
9
+ keyHashStage?: unknown;
10
+ }
11
+ declare module "@blazetrails/trailties/trailtie/configuration" {
12
+ interface Configuration {
13
+ solidCache: SolidCacheConfig;
14
+ }
15
+ }
16
+ /** @inventedArm connectsTo — PERMANENT */
17
+ export declare class Engine extends TrailsEngine {
18
+ }
19
+ //# sourceMappingURL=engine.d.ts.map
package/dist/engine.js ADDED
@@ -0,0 +1,59 @@
1
+ import { deprecator, OrderedOptions, TopLevel } from "@blazetrails/activesupport";
2
+ import { constSet, env, File, Pathname } from "@blazetrails/ruby-compat";
3
+ import { Configuration } from "./configuration.js";
4
+ import { Engine as TrailsEngine } from "@blazetrails/trailties/engine";
5
+ import { Record } from "./record.js";
6
+ import { SolidCache } from "./solid-cache.js";
7
+ import { Store } from "./store.js";
8
+ /** @inventedArm connectsTo — PERMANENT */
9
+ export class Engine extends TrailsEngine {
10
+ static {
11
+ constSet(SolidCache, "Engine", this);
12
+ TrailsEngine.register(this, import.meta.dirname);
13
+ this.isolateNamespace(SolidCache);
14
+ this.config.set("solidCache", new OrderedOptions());
15
+ this.initializer("solid_cache.config", { before: "initialize_cache" }, async (app) => {
16
+ const configPaths = ["config/cache", "config/solid_cache"];
17
+ for (const path of configPaths) {
18
+ app.paths().add(path, { with: env.SOLID_CACHE_CONFIG ?? `${path}.ts` });
19
+ }
20
+ let configPathname;
21
+ for (const path of configPaths) {
22
+ const pathname = new Pathname(app.config.paths().get(path).first());
23
+ if (await File.isExistAsync(pathname.toString())) {
24
+ configPathname = pathname;
25
+ break;
26
+ }
27
+ }
28
+ const options = configPathname
29
+ ? (await app.configFor(configPathname)).toH()
30
+ : {};
31
+ const config = this.config.solidCache;
32
+ if (config.connectsTo != null && config.connectsTo !== false)
33
+ options.connectsTo = config.connectsTo;
34
+ if (config.sizeEstimateSamples != null)
35
+ options.sizeEstimateSamples = config.sizeEstimateSamples;
36
+ if (config.encrypt != null && config.encrypt !== false)
37
+ options.encrypt = config.encrypt;
38
+ if (config.encryptionContextProperties != null &&
39
+ config.encryptionContextProperties !== false) {
40
+ options.encryptionContextProperties = config.encryptionContextProperties;
41
+ }
42
+ SolidCache.configuration = new Configuration(options);
43
+ if (config.keyHashStage != null && config.keyHashStage !== false) {
44
+ deprecator().warn("config.solid_cache.key_hash_stage is deprecated and has no effect.");
45
+ }
46
+ if (SolidCache.configuration.connectsTo) {
47
+ await Record.connectsTo(SolidCache.configuration.connectsTo);
48
+ }
49
+ });
50
+ this.initializer("solid_cache.app_executor", { before: "run_prepare_callbacks" }, (app) => {
51
+ SolidCache.executor = this.config.solidCache.executor || app.executor;
52
+ });
53
+ this.config.afterInitialize(() => {
54
+ if (TopLevel.Trails.cache instanceof Store)
55
+ TopLevel.Trails.cache.setupBang();
56
+ });
57
+ }
58
+ }
59
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../lib/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAiBnC,0CAA0C;AAC1C,MAAM,OAAO,MAAO,SAAQ,YAAY;IACtC;QACE,QAAQ,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QAErC,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QAEjD,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAElC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,cAAc,EAAE,CAAC,CAAC;QAEpD,IAAI,CAAC,WAAW,CACd,oBAAoB,EACpB,EAAE,MAAM,EAAE,kBAAkB,EAAE,EAC9B,KAAK,EAAE,GAAgB,EAAE,EAAE;YACzB,MAAM,WAAW,GAAG,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAC;YAE3D,KAAK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,KAAK,EAC5C,CAAC;gBACD,OAAO,CAAC,2BAA2B,GAAG,MAAM,CAAC,2BAA2B,CAAC;YAC3E,CAAC;YAED,UAAU,CAAC,aAAa,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;YAEtD,IAAI,MAAM,CAAC,YAAY,IAAI,IAAI,IAAI,MAAM,CAAC,YAAY,KAAK,KAAK,EAAE,CAAC;gBACjE,UAAU,EAAE,CAAC,IAAI,CAAC,oEAAoE,CAAC,CAAC;YAC1F,CAAC;YAED,IAAI,UAAU,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC;gBACxC,MAAM,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC,CACF,CAAC;QAEF,IAAI,CAAC,WAAW,CACd,0BAA0B,EAC1B,EAAE,MAAM,EAAE,uBAAuB,EAAE,EACnC,CAAC,GAA0B,EAAE,EAAE;YAC7B,UAAU,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC;QACxE,CAAC,CACF,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE;YAC/B,IAAI,QAAQ,CAAC,MAAO,CAAC,KAAK,YAAY,KAAK;gBAAE,QAAQ,CAAC,MAAO,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QAClF,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import type { EncryptsOptions } from "@blazetrails/activerecord/encryption";
2
+ import { included } from "@blazetrails/activesupport";
3
+ import { classModule } from "@blazetrails/ruby-compat";
4
+ export declare class Encryption {
5
+ static readonly [classModule] = true;
6
+ static [included](base: {
7
+ encrypts(...args: Array<string | EncryptsOptions>): void;
8
+ }): void;
9
+ }
10
+ //# sourceMappingURL=encryption.d.ts.map
@@ -0,0 +1,12 @@
1
+ import { included } from "@blazetrails/activesupport";
2
+ import { classModule } from "@blazetrails/ruby-compat";
3
+ import { SolidCache } from "../solid-cache.js";
4
+ export class Encryption {
5
+ static [classModule] = true;
6
+ static [included](base) {
7
+ if (SolidCache.configuration.isEncrypt()) {
8
+ base.encrypts("value", { ...SolidCache.configuration.encryptionContextProperties });
9
+ }
10
+ }
11
+ }
12
+ //# sourceMappingURL=encryption.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../lib/entry/encryption.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,MAAM,OAAO,UAAU;IACrB,MAAM,CAAU,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;IAErC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAkE;QAClF,IAAI,UAAU,CAAC,aAAa,CAAC,SAAS,EAAE,EAAE,CAAC;YACzC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,GAAG,UAAU,CAAC,aAAa,CAAC,2BAA2B,EAAE,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ import { classModule } from "@blazetrails/ruby-compat";
2
+ import type { Entry } from "../entry.js";
3
+ type MaxOptions = {
4
+ maxAge: unknown;
5
+ maxEntries: unknown;
6
+ maxSize: unknown;
7
+ };
8
+ export declare class ClassMethods {
9
+ static expire(this: typeof Entry, count: number, { maxAge, maxEntries, maxSize }: MaxOptions): Promise<number | undefined>;
10
+ /** @internal */
11
+ static isCacheFull(this: typeof Entry, { maxEntries, maxSize }: {
12
+ maxEntries: unknown;
13
+ maxSize: unknown;
14
+ }): Promise<boolean>;
15
+ /** @internal */
16
+ static expiryCandidateIds(this: typeof Entry, count: number, { maxAge, maxEntries, maxSize }: MaxOptions): Promise<unknown[]>;
17
+ }
18
+ export declare class Expiration {
19
+ static readonly [classModule] = true;
20
+ static ClassMethods: typeof ClassMethods;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=expiration.d.ts.map
@@ -0,0 +1,53 @@
1
+ import { Concern, extend, seconds } from "@blazetrails/activesupport";
2
+ import { ARRAY_METHOD_TABLE, classModule, cmp } from "@blazetrails/ruby-compat";
3
+ export class ClassMethods {
4
+ static async expire(count, { maxAge, maxEntries, maxSize }) {
5
+ const ids = await this.expiryCandidateIds(count, { maxAge, maxEntries, maxSize });
6
+ if (ids.length > 0) {
7
+ return await this.delete(ids);
8
+ }
9
+ }
10
+ /** @internal */
11
+ static async isCacheFull({ maxEntries, maxSize }) {
12
+ if (maxEntries != null &&
13
+ maxEntries !== false &&
14
+ maxEntries < Number(await this.idRange())) {
15
+ return true;
16
+ }
17
+ else if (maxSize != null &&
18
+ maxSize !== false &&
19
+ maxSize < (await this.estimatedSize())) {
20
+ return true;
21
+ }
22
+ else {
23
+ return false;
24
+ }
25
+ }
26
+ /** @internal */
27
+ static async expiryCandidateIds(count, { maxAge, maxEntries, maxSize }) {
28
+ const cacheFull = await this.isCacheFull({ maxEntries, maxSize });
29
+ if (!(cacheFull || (maxAge != null && maxAge !== false)))
30
+ return [];
31
+ const retrieveCount = count * 3;
32
+ return await this.uncached(async () => {
33
+ const candidates = this.order("id").limit(retrieveCount);
34
+ let candidateIds;
35
+ if (cacheFull) {
36
+ candidateIds = await candidates.pluck("id");
37
+ }
38
+ else {
39
+ const minCreatedAt = seconds(Number(maxAge)).ago();
40
+ candidateIds = (await candidates.pluck("id", "created_at"))
41
+ .filter(([, createdAt]) => cmp(createdAt, minCreatedAt) < 0)
42
+ .map(([id]) => id);
43
+ }
44
+ return ARRAY_METHOD_TABLE.sample(candidateIds, count);
45
+ });
46
+ }
47
+ }
48
+ export class Expiration {
49
+ static [classModule] = true;
50
+ }
51
+ extend(Expiration, Concern);
52
+ Object.defineProperty(Expiration, "ClassMethods", { value: ClassMethods });
53
+ //# sourceMappingURL=expiration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expiration.js","sourceRoot":"","sources":["../../lib/entry/expiration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAKhF,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,KAAK,CAAC,MAAM,CAEjB,KAAa,EACb,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAc;QAE3C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;QAClF,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACnB,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED,gBAAgB;IAChB,MAAM,CAAC,KAAK,CAAC,WAAW,CAEtB,EAAE,UAAU,EAAE,OAAO,EAA6C;QAElE,IACE,UAAU,IAAI,IAAI;YAClB,UAAU,KAAK,KAAK;YACnB,UAAqB,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC,EACrD,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,IACL,OAAO,IAAI,IAAI;YACf,OAAO,KAAK,KAAK;YAChB,OAAkB,GAAG,CAAC,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,EAClD,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,gBAAgB;IAChB,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAE7B,KAAa,EACb,EAAE,MAAM,EAA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