@open-mercato/cache 0.3.2 → 0.4.2-canary-b8ab8f2d43

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 (45) hide show
  1. package/.test-cache.json +4 -0
  2. package/build.mjs +61 -0
  3. package/dist/errors.js +12 -8
  4. package/dist/errors.js.map +7 -0
  5. package/dist/index.js +16 -7
  6. package/dist/index.js.map +7 -0
  7. package/dist/service.js +240 -287
  8. package/dist/service.js.map +7 -0
  9. package/dist/strategies/jsonfile.js +179 -194
  10. package/dist/strategies/jsonfile.js.map +7 -0
  11. package/dist/strategies/memory.js +143 -157
  12. package/dist/strategies/memory.js.map +7 -0
  13. package/dist/strategies/redis.js +292 -359
  14. package/dist/strategies/redis.js.map +7 -0
  15. package/dist/strategies/sqlite.js +164 -191
  16. package/dist/strategies/sqlite.js.map +7 -0
  17. package/dist/tenantContext.js +10 -6
  18. package/dist/tenantContext.js.map +7 -0
  19. package/dist/types.js +1 -1
  20. package/dist/types.js.map +7 -0
  21. package/jest.config.cjs +19 -0
  22. package/package.json +40 -12
  23. package/src/__tests__/memory.strategy.test.ts +15 -7
  24. package/tsconfig.build.json +9 -1
  25. package/tsconfig.json +4 -7
  26. package/watch.mjs +6 -0
  27. package/dist/errors.d.ts +0 -7
  28. package/dist/errors.d.ts.map +0 -1
  29. package/dist/index.d.ts +0 -8
  30. package/dist/index.d.ts.map +0 -1
  31. package/dist/service.d.ts +0 -40
  32. package/dist/service.d.ts.map +0 -1
  33. package/dist/strategies/jsonfile.d.ts +0 -10
  34. package/dist/strategies/jsonfile.d.ts.map +0 -1
  35. package/dist/strategies/memory.d.ts +0 -9
  36. package/dist/strategies/memory.d.ts.map +0 -1
  37. package/dist/strategies/redis.d.ts +0 -5
  38. package/dist/strategies/redis.d.ts.map +0 -1
  39. package/dist/strategies/sqlite.d.ts +0 -13
  40. package/dist/strategies/sqlite.d.ts.map +0 -1
  41. package/dist/tenantContext.d.ts +0 -4
  42. package/dist/tenantContext.d.ts.map +0 -1
  43. package/dist/types.d.ts +0 -86
  44. package/dist/types.d.ts.map +0 -1
  45. package/jest.config.js +0 -19
@@ -0,0 +1,4 @@
1
+ {
2
+ "entries": {},
3
+ "tagIndex": {}
4
+ }
package/build.mjs ADDED
@@ -0,0 +1,61 @@
1
+ import * as esbuild from 'esbuild'
2
+ import { glob } from 'glob'
3
+ import { readFileSync, writeFileSync, existsSync } from 'node:fs'
4
+ import { dirname, join } from 'node:path'
5
+
6
+ const entryPoints = await glob('src/**/*.ts', {
7
+ ignore: ['**/__tests__/**', '**/*.test.ts']
8
+ })
9
+
10
+ // Plugin to add .js extension to relative imports
11
+ const addJsExtension = {
12
+ name: 'add-js-extension',
13
+ setup(build) {
14
+ build.onEnd(async (result) => {
15
+ if (result.errors.length > 0) return
16
+ const outputFiles = await glob('dist/**/*.js')
17
+ for (const file of outputFiles) {
18
+ const fileDir = dirname(file)
19
+ let content = readFileSync(file, 'utf-8')
20
+ // Add .js to relative imports that don't have an extension
21
+ content = content.replace(
22
+ /from\s+["'](\.[^"']+)["']/g,
23
+ (match, path) => {
24
+ if (path.endsWith('.js') || path.endsWith('.json')) return match
25
+ // Check if it's a directory with index.js
26
+ const resolvedPath = join(fileDir, path)
27
+ if (existsSync(resolvedPath) && existsSync(join(resolvedPath, 'index.js'))) {
28
+ return `from "${path}/index.js"`
29
+ }
30
+ return `from "${path}.js"`
31
+ }
32
+ )
33
+ content = content.replace(
34
+ /import\s*\(\s*["'](\.[^"']+)["']\s*\)/g,
35
+ (match, path) => {
36
+ if (path.endsWith('.js') || path.endsWith('.json')) return match
37
+ // Check if it's a directory with index.js
38
+ const resolvedPath = join(fileDir, path)
39
+ if (existsSync(resolvedPath) && existsSync(join(resolvedPath, 'index.js'))) {
40
+ return `import("${path}/index.js")`
41
+ }
42
+ return `import("${path}.js")`
43
+ }
44
+ )
45
+ writeFileSync(file, content)
46
+ }
47
+ })
48
+ }
49
+ }
50
+
51
+ await esbuild.build({
52
+ entryPoints,
53
+ outdir: 'dist',
54
+ format: 'esm',
55
+ platform: 'node',
56
+ target: 'node18',
57
+ sourcemap: true,
58
+ plugins: [addJsExtension],
59
+ })
60
+
61
+ console.log('cache built successfully')
package/dist/errors.js CHANGED
@@ -1,9 +1,13 @@
1
- export class CacheDependencyUnavailableError extends Error {
2
- constructor(strategy, dependency, originalError) {
3
- super(`Cache strategy "${strategy}" requires dependency "${dependency}" which is not available`);
4
- this.name = 'CacheDependencyUnavailableError';
5
- this.strategy = strategy;
6
- this.dependency = dependency;
7
- this.originalError = originalError;
8
- }
1
+ class CacheDependencyUnavailableError extends Error {
2
+ constructor(strategy, dependency, originalError) {
3
+ super(`Cache strategy "${strategy}" requires dependency "${dependency}" which is not available`);
4
+ this.name = "CacheDependencyUnavailableError";
5
+ this.strategy = strategy;
6
+ this.dependency = dependency;
7
+ this.originalError = originalError;
8
+ }
9
9
  }
10
+ export {
11
+ CacheDependencyUnavailableError
12
+ };
13
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/errors.ts"],
4
+ "sourcesContent": ["export class CacheDependencyUnavailableError extends Error {\n public readonly strategy: string\n public readonly dependency: string\n public readonly originalError?: unknown\n\n constructor(strategy: string, dependency: string, originalError?: unknown) {\n super(`Cache strategy \"${strategy}\" requires dependency \"${dependency}\" which is not available`)\n this.name = 'CacheDependencyUnavailableError'\n this.strategy = strategy\n this.dependency = dependency\n this.originalError = originalError\n }\n}\n\n"],
5
+ "mappings": "AAAO,MAAM,wCAAwC,MAAM;AAAA,EAKzD,YAAY,UAAkB,YAAoB,eAAyB;AACzE,UAAM,mBAAmB,QAAQ,0BAA0B,UAAU,0BAA0B;AAC/F,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,SAAK,aAAa;AAClB,SAAK,gBAAgB;AAAA,EACvB;AACF;",
6
+ "names": []
7
+ }
package/dist/index.js CHANGED
@@ -1,7 +1,16 @@
1
- export * from './types';
2
- export * from './service';
3
- export { createMemoryStrategy } from './strategies/memory';
4
- export { createRedisStrategy } from './strategies/redis';
5
- export { createSqliteStrategy } from './strategies/sqlite';
6
- export { createJsonFileStrategy } from './strategies/jsonfile';
7
- export { runWithCacheTenant, getCurrentCacheTenant } from './tenantContext';
1
+ export * from "./types.js";
2
+ export * from "./service.js";
3
+ import { createMemoryStrategy } from "./strategies/memory.js";
4
+ import { createRedisStrategy } from "./strategies/redis.js";
5
+ import { createSqliteStrategy } from "./strategies/sqlite.js";
6
+ import { createJsonFileStrategy } from "./strategies/jsonfile.js";
7
+ import { runWithCacheTenant, getCurrentCacheTenant } from "./tenantContext.js";
8
+ export {
9
+ createJsonFileStrategy,
10
+ createMemoryStrategy,
11
+ createRedisStrategy,
12
+ createSqliteStrategy,
13
+ getCurrentCacheTenant,
14
+ runWithCacheTenant
15
+ };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["export * from './types'\nexport * from './service'\nexport { createMemoryStrategy } from './strategies/memory'\nexport { createRedisStrategy } from './strategies/redis'\nexport { createSqliteStrategy } from './strategies/sqlite'\nexport { createJsonFileStrategy } from './strategies/jsonfile'\nexport { runWithCacheTenant, getCurrentCacheTenant } from './tenantContext'\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AACrC,SAAS,8BAA8B;AACvC,SAAS,oBAAoB,6BAA6B;",
6
+ "names": []
7
+ }