@olane/o-storage 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 (68) hide show
  1. package/README.md +86 -0
  2. package/dist/src/index.d.ts +5 -0
  3. package/dist/src/index.d.ts.map +1 -0
  4. package/dist/src/index.js +4 -0
  5. package/dist/src/interfaces/get-data.response.d.ts +4 -0
  6. package/dist/src/interfaces/get-data.response.d.ts.map +1 -0
  7. package/dist/src/interfaces/get-data.response.js +1 -0
  8. package/dist/src/interfaces/index.d.ts +6 -0
  9. package/dist/src/interfaces/index.d.ts.map +1 -0
  10. package/dist/src/interfaces/index.js +5 -0
  11. package/dist/src/interfaces/placeholder-put.request.d.ts +17 -0
  12. package/dist/src/interfaces/placeholder-put.request.d.ts.map +1 -0
  13. package/dist/src/interfaces/placeholder-put.request.js +7 -0
  14. package/dist/src/interfaces/placeholder-put.response.d.ts +8 -0
  15. package/dist/src/interfaces/placeholder-put.response.d.ts.map +1 -0
  16. package/dist/src/interfaces/placeholder-put.response.js +1 -0
  17. package/dist/src/interfaces/placeholder-value.interface.d.ts +6 -0
  18. package/dist/src/interfaces/placeholder-value.interface.d.ts.map +1 -0
  19. package/dist/src/interfaces/placeholder-value.interface.js +1 -0
  20. package/dist/src/interfaces/put.request.d.ts +16 -0
  21. package/dist/src/interfaces/put.request.d.ts.map +1 -0
  22. package/dist/src/interfaces/put.request.js +7 -0
  23. package/dist/src/methods/placeholder-storage.methods.d.ts +5 -0
  24. package/dist/src/methods/placeholder-storage.methods.d.ts.map +1 -0
  25. package/dist/src/methods/placeholder-storage.methods.js +32 -0
  26. package/dist/src/methods/storage.methods.d.ts +5 -0
  27. package/dist/src/methods/storage.methods.d.ts.map +1 -0
  28. package/dist/src/methods/storage.methods.js +65 -0
  29. package/dist/src/placeholder.tool.d.ts +10 -0
  30. package/dist/src/placeholder.tool.d.ts.map +1 -0
  31. package/dist/src/placeholder.tool.js +76 -0
  32. package/dist/src/providers/dht-storage-provider.tool.d.ts +12 -0
  33. package/dist/src/providers/dht-storage-provider.tool.d.ts.map +1 -0
  34. package/dist/src/providers/dht-storage-provider.tool.js +25 -0
  35. package/dist/src/providers/disk-storage-provider.tool.d.ts +45 -0
  36. package/dist/src/providers/disk-storage-provider.tool.d.ts.map +1 -0
  37. package/dist/src/providers/disk-storage-provider.tool.js +134 -0
  38. package/dist/src/providers/encrypted-storage-provider.tool.d.ts +1 -0
  39. package/dist/src/providers/encrypted-storage-provider.tool.d.ts.map +1 -0
  40. package/dist/src/providers/encrypted-storage-provider.tool.js +63 -0
  41. package/dist/src/providers/index.d.ts +6 -0
  42. package/dist/src/providers/index.d.ts.map +1 -0
  43. package/dist/src/providers/index.js +5 -0
  44. package/dist/src/providers/memory-storage-provider.tool.d.ts +32 -0
  45. package/dist/src/providers/memory-storage-provider.tool.d.ts.map +1 -0
  46. package/dist/src/providers/memory-storage-provider.tool.js +65 -0
  47. package/dist/src/providers/secure-storage-provider.tool.d.ts +25 -0
  48. package/dist/src/providers/secure-storage-provider.tool.d.ts.map +1 -0
  49. package/dist/src/providers/secure-storage-provider.tool.js +72 -0
  50. package/dist/src/providers/storage-provider.tool.d.ts +12 -0
  51. package/dist/src/providers/storage-provider.tool.d.ts.map +1 -0
  52. package/dist/src/providers/storage-provider.tool.js +41 -0
  53. package/dist/src/resolvers/placeholder.resolver.d.ts +6 -0
  54. package/dist/src/resolvers/placeholder.resolver.d.ts.map +1 -0
  55. package/dist/src/resolvers/placeholder.resolver.js +10 -0
  56. package/dist/src/storage.tool.d.ts +12 -0
  57. package/dist/src/storage.tool.d.ts.map +1 -0
  58. package/dist/src/storage.tool.js +46 -0
  59. package/dist/test/basic.spec.d.ts +1 -0
  60. package/dist/test/basic.spec.d.ts.map +1 -0
  61. package/dist/test/basic.spec.js +1 -0
  62. package/dist/test/data/bigfile.d.ts +2 -0
  63. package/dist/test/data/bigfile.d.ts.map +1 -0
  64. package/dist/test/data/bigfile.js +174 -0
  65. package/dist/test/placeholder.spec.d.ts +2 -0
  66. package/dist/test/placeholder.spec.d.ts.map +1 -0
  67. package/dist/test/placeholder.spec.js +61 -0
  68. package/package.json +72 -0
@@ -0,0 +1,134 @@
1
+ import { StorageProviderTool } from './storage-provider.tool.js';
2
+ import { DEFAULT_CONFIG_PATH, oAddress } from '@olane/o-core';
3
+ import fs from 'fs/promises';
4
+ import path from 'path';
5
+ import { STORAGE_PARAMS } from '../methods/storage.methods.js';
6
+ export class DiskStorageProvider extends StorageProviderTool {
7
+ constructor(config) {
8
+ super({
9
+ ...config,
10
+ address: config.address || new oAddress('o://disk'),
11
+ methods: STORAGE_PARAMS,
12
+ description: 'Disk storage provider',
13
+ });
14
+ // Use a default storage directory, can be overridden via config
15
+ this.storageDir =
16
+ config.storageDir || path.join(DEFAULT_CONFIG_PATH, 'storage');
17
+ this.ensureStorageDir();
18
+ }
19
+ /**
20
+ * Ensure the storage directory exists
21
+ */
22
+ async ensureStorageDir() {
23
+ try {
24
+ await fs.access(this.storageDir);
25
+ }
26
+ catch {
27
+ await fs.mkdir(this.storageDir, { recursive: true });
28
+ }
29
+ }
30
+ /**
31
+ * Get the file path for a given key
32
+ */
33
+ getFilePath(key) {
34
+ // Sanitize the key to be filesystem safe
35
+ const sanitizedKey = key.replace(/[^a-zA-Z0-9._-]/g, '_');
36
+ return path.join(this.storageDir, `${sanitizedKey}.json`);
37
+ }
38
+ /**
39
+ * Store data on disk
40
+ * @param key The key to store the data under
41
+ * @param value The data to store
42
+ */
43
+ async _tool_put(request) {
44
+ try {
45
+ await this.ensureStorageDir();
46
+ const { key, value } = request.params;
47
+ const filePath = this.getFilePath(key);
48
+ // Store the data as JSON with metadata
49
+ const data = {
50
+ value: value,
51
+ timestamp: new Date().toISOString(),
52
+ key: key,
53
+ };
54
+ await fs.writeFile(filePath, JSON.stringify(data, null, 2), 'utf8');
55
+ return {
56
+ success: true,
57
+ };
58
+ }
59
+ catch (error) {
60
+ return {
61
+ success: false,
62
+ error: `Failed to store data: ${error instanceof Error ? error.message : 'Unknown error'}`,
63
+ };
64
+ }
65
+ }
66
+ /**
67
+ * Retrieve data from disk
68
+ * @param key The key to retrieve
69
+ * @returns The stored data or null if not found
70
+ */
71
+ async _tool_get(request) {
72
+ const { key } = request.params;
73
+ const filePath = this.getFilePath(key);
74
+ const fileContent = await fs.readFile(filePath, 'utf8');
75
+ const data = JSON.parse(fileContent);
76
+ return data.value;
77
+ }
78
+ /**
79
+ * Delete data from disk
80
+ * @param key The key to delete
81
+ */
82
+ async _tool_delete(request) {
83
+ const { key } = request.params;
84
+ try {
85
+ const filePath = this.getFilePath(key);
86
+ await fs.unlink(filePath);
87
+ return {
88
+ success: true,
89
+ };
90
+ }
91
+ catch (error) {
92
+ const nodeError = error;
93
+ if (nodeError.code === 'ENOENT') {
94
+ // File doesn't exist, consider it already deleted
95
+ return {
96
+ success: true,
97
+ };
98
+ }
99
+ return {
100
+ success: false,
101
+ error: `Failed to delete data: ${error instanceof Error ? error.message : 'Unknown error'}`,
102
+ };
103
+ }
104
+ }
105
+ /**
106
+ * Check if a key exists on disk
107
+ * @param key The key to check
108
+ * @returns Whether the key exists
109
+ */
110
+ async _tool_has(request) {
111
+ const { key } = request.params;
112
+ try {
113
+ const filePath = this.getFilePath(key);
114
+ await fs.access(filePath);
115
+ return {
116
+ success: true,
117
+ data: true,
118
+ };
119
+ }
120
+ catch (error) {
121
+ const nodeError = error;
122
+ if (nodeError.code === 'ENOENT') {
123
+ return {
124
+ success: true,
125
+ data: false,
126
+ };
127
+ }
128
+ return {
129
+ success: false,
130
+ error: `Failed to check if key exists: ${error instanceof Error ? error.message : 'Unknown error'}`,
131
+ };
132
+ }
133
+ }
134
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=encrypted-storage-provider.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encrypted-storage-provider.tool.d.ts","sourceRoot":"","sources":["../../../src/providers/encrypted-storage-provider.tool.ts"],"names":[],"mappings":""}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ // import { ToolResult } from '@olane/o-tool';
3
+ // import { StorageProviderTool } from './storage-provider.tool';
4
+ // import { CoreConfig, oAddress, oRequest } from '@olane/o-core';
5
+ // import { STORAGE_PARAMS } from '../methods/storage.methods';
6
+ // export class EncryptedStorageProvider extends StorageProviderTool {
7
+ // private storage: Map<string, string>;
8
+ // constructor(config: CoreConfig) {
9
+ // super({
10
+ // ...config,
11
+ // address: config.address || new oAddress('o://encrypted'),
12
+ // methods: STORAGE_PARAMS,
13
+ // });
14
+ // this.storage = new Map();
15
+ // }
16
+ // /**
17
+ // * Store data in memory
18
+ // * @param key The key to store the data under
19
+ // * @param value The data to store
20
+ // */
21
+ // async _tool_put(request: oRequest): Promise<ToolResult> {
22
+ // const { key, value } = request.params;
23
+ // this.storage.set(key as string, value as string);
24
+ // return {
25
+ // success: true,
26
+ // };
27
+ // }
28
+ // /**
29
+ // * Retrieve data from memory
30
+ // * @param key The key to retrieve
31
+ // * @returns The stored data or null if not found
32
+ // */
33
+ // async _tool_get(request: oRequest): Promise<ToolResult> {
34
+ // const { key } = request.params;
35
+ // const value = this.storage.get(key as string);
36
+ // return {
37
+ // success: true,
38
+ // data: value,
39
+ // };
40
+ // }
41
+ // /**
42
+ // * Delete data from memory
43
+ // * @param key The key to delete``
44
+ // */
45
+ // async _tool_delete(request: oRequest): Promise<ToolResult> {
46
+ // const { key } = request.params;
47
+ // this.storage.delete(key as string);
48
+ // return {
49
+ // success: true,
50
+ // };
51
+ // }
52
+ // /**
53
+ // * Check if a key exists in memory
54
+ // * @param key The key to check
55
+ // * @returns Whether the key exists
56
+ // */
57
+ // async _tool_has(request: oRequest): Promise<ToolResult> {
58
+ // const { key } = request.params;
59
+ // return {
60
+ // success: this.storage.has(key as string),
61
+ // };
62
+ // }
63
+ // }
@@ -0,0 +1,6 @@
1
+ export * from './disk-storage-provider.tool.js';
2
+ export * from './memory-storage-provider.tool.js';
3
+ export * from './secure-storage-provider.tool.js';
4
+ export * from './storage-provider.tool.js';
5
+ export * from './dht-storage-provider.tool.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './disk-storage-provider.tool.js';
2
+ export * from './memory-storage-provider.tool.js';
3
+ export * from './secure-storage-provider.tool.js';
4
+ export * from './storage-provider.tool.js';
5
+ export * from './dht-storage-provider.tool.js';
@@ -0,0 +1,32 @@
1
+ import { ToolResult } from '@olane/o-tool';
2
+ import { StorageProviderTool } from './storage-provider.tool.js';
3
+ import { CoreConfig, oRequest } from '@olane/o-core';
4
+ import { GetDataResponse } from '../interfaces/get-data.response.js';
5
+ export declare class MemoryStorageProvider extends StorageProviderTool {
6
+ private storage;
7
+ constructor(config: CoreConfig);
8
+ /**
9
+ * Store data in memory
10
+ * @param key The key to store the data under
11
+ * @param value The data to store
12
+ */
13
+ _tool_put(request: oRequest): Promise<ToolResult>;
14
+ /**
15
+ * Retrieve data from memory
16
+ * @param key The key to retrieve
17
+ * @returns The stored data or null if not found
18
+ */
19
+ _tool_get(request: oRequest): Promise<GetDataResponse>;
20
+ /**
21
+ * Delete data from memory
22
+ * @param key The key to delete``
23
+ */
24
+ _tool_delete(request: oRequest): Promise<ToolResult>;
25
+ /**
26
+ * Check if a key exists in memory
27
+ * @param key The key to check
28
+ * @returns Whether the key exists
29
+ */
30
+ _tool_has(request: oRequest): Promise<ToolResult>;
31
+ }
32
+ //# sourceMappingURL=memory-storage-provider.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-storage-provider.tool.d.ts","sourceRoot":"","sources":["../../../src/providers/memory-storage-provider.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAY,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAErE,qBAAa,qBAAsB,SAAQ,mBAAmB;IAC5D,OAAO,CAAC,OAAO,CAAsB;gBACzB,MAAM,EAAE,UAAU;IAU9B;;;;OAIG;IACG,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAQvD;;;;OAIG;IACG,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAa5D;;;OAGG;IACG,YAAY,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAQ1D;;;;OAIG;IACG,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;CAMxD"}
@@ -0,0 +1,65 @@
1
+ import { StorageProviderTool } from './storage-provider.tool.js';
2
+ import { oAddress } from '@olane/o-core';
3
+ import { STORAGE_PARAMS } from '../methods/storage.methods.js';
4
+ export class MemoryStorageProvider extends StorageProviderTool {
5
+ constructor(config) {
6
+ super({
7
+ ...config,
8
+ address: config.address || new oAddress('o://memory'),
9
+ methods: STORAGE_PARAMS,
10
+ description: 'In-memory storage provider',
11
+ });
12
+ this.storage = new Map();
13
+ }
14
+ /**
15
+ * Store data in memory
16
+ * @param key The key to store the data under
17
+ * @param value The data to store
18
+ */
19
+ async _tool_put(request) {
20
+ const { key, value } = request.params;
21
+ this.storage.set(key, value);
22
+ return {
23
+ success: true,
24
+ };
25
+ }
26
+ /**
27
+ * Retrieve data from memory
28
+ * @param key The key to retrieve
29
+ * @returns The stored data or null if not found
30
+ */
31
+ async _tool_get(request) {
32
+ const { key } = request.params;
33
+ const value = this.storage.get(key);
34
+ if (!value) {
35
+ return {
36
+ value: null,
37
+ };
38
+ }
39
+ return {
40
+ value: value,
41
+ };
42
+ }
43
+ /**
44
+ * Delete data from memory
45
+ * @param key The key to delete``
46
+ */
47
+ async _tool_delete(request) {
48
+ const { key } = request.params;
49
+ this.storage.delete(key);
50
+ return {
51
+ success: true,
52
+ };
53
+ }
54
+ /**
55
+ * Check if a key exists in memory
56
+ * @param key The key to check
57
+ * @returns Whether the key exists
58
+ */
59
+ async _tool_has(request) {
60
+ const { key } = request.params;
61
+ return {
62
+ success: this.storage.has(key),
63
+ };
64
+ }
65
+ }
@@ -0,0 +1,25 @@
1
+ import { oToolConfig, ToolResult } from '@olane/o-tool';
2
+ import { oAddress, oRequest } from '@olane/o-core';
3
+ import { GetDataResponse } from '../interfaces/get-data.response.js';
4
+ import { DiskStorageProvider } from './disk-storage-provider.tool.js';
5
+ interface DiskStorageConfig extends oToolConfig {
6
+ storageDir?: string;
7
+ address?: oAddress;
8
+ }
9
+ export declare class SecureStorageProvider extends DiskStorageProvider {
10
+ constructor(config: DiskStorageConfig);
11
+ /**
12
+ * Store data on disk
13
+ * @param key The key to store the data under
14
+ * @param value The data to store
15
+ */
16
+ _tool_put(request: oRequest): Promise<ToolResult>;
17
+ /**
18
+ * Retrieve data from disk
19
+ * @param key The key to retrieve
20
+ * @returns The stored data or null if not found
21
+ */
22
+ _tool_get(request: oRequest): Promise<GetDataResponse>;
23
+ }
24
+ export {};
25
+ //# sourceMappingURL=secure-storage-provider.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-storage-provider.tool.d.ts","sourceRoot":"","sources":["../../../src/providers/secure-storage-provider.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAGtE,UAAU,iBAAkB,SAAQ,WAAW;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB;AAOD,qBAAa,qBAAsB,SAAQ,mBAAmB;gBAChD,MAAM,EAAE,iBAAiB;IASrC;;;;OAIG;IACG,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAoCvD;;;;OAIG;IACG,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;CAsB7D"}
@@ -0,0 +1,72 @@
1
+ import { oAddress } from '@olane/o-core';
2
+ import fs from 'fs/promises';
3
+ import { STORAGE_PARAMS } from '../methods/storage.methods.js';
4
+ import { DiskStorageProvider } from './disk-storage-provider.tool.js';
5
+ export class SecureStorageProvider extends DiskStorageProvider {
6
+ constructor(config) {
7
+ super({
8
+ ...config,
9
+ address: config.address || new oAddress('o://secure-storage'),
10
+ methods: STORAGE_PARAMS,
11
+ description: 'Secure storage provider',
12
+ });
13
+ }
14
+ /**
15
+ * Store data on disk
16
+ * @param key The key to store the data under
17
+ * @param value The data to store
18
+ */
19
+ async _tool_put(request) {
20
+ try {
21
+ await this.ensureStorageDir();
22
+ const { key, value } = request.params;
23
+ const filePath = this.getFilePath(key);
24
+ // encrypt the value
25
+ const response = await this.use(new oAddress('o://encryption'), {
26
+ method: 'encrypt',
27
+ params: {
28
+ value: value,
29
+ },
30
+ });
31
+ const { value: encryptedValue } = response.result.data;
32
+ // Store the data as JSON with metadata
33
+ const data = {
34
+ value: encryptedValue,
35
+ timestamp: new Date().toISOString(),
36
+ key: key,
37
+ };
38
+ await fs.writeFile(filePath, JSON.stringify(data, null, 2), 'utf8');
39
+ return {
40
+ success: true,
41
+ };
42
+ }
43
+ catch (error) {
44
+ return {
45
+ success: false,
46
+ error: `Failed to store data: ${error instanceof Error ? error.message : 'Unknown error'}`,
47
+ };
48
+ }
49
+ }
50
+ /**
51
+ * Retrieve data from disk
52
+ * @param key The key to retrieve
53
+ * @returns The stored data or null if not found
54
+ */
55
+ async _tool_get(request) {
56
+ const { key } = request.params;
57
+ const filePath = this.getFilePath(key);
58
+ const fileContent = await fs.readFile(filePath, 'utf8');
59
+ const { value } = JSON.parse(fileContent);
60
+ // decrypt the value
61
+ const response = await this.use(new oAddress('o://encryption'), {
62
+ method: 'decrypt',
63
+ params: {
64
+ value: value,
65
+ },
66
+ });
67
+ const { value: decryptedValue } = response.result.data;
68
+ return {
69
+ value: decryptedValue,
70
+ };
71
+ }
72
+ }
@@ -0,0 +1,12 @@
1
+ import { oVirtualTool, ToolResult } from '@olane/o-tool';
2
+ import { oAddress, oRequest, oResponse } from '@olane/o-core';
3
+ import { GetDataResponse } from '../interfaces/get-data.response.js';
4
+ export declare abstract class StorageProviderTool extends oVirtualTool {
5
+ abstract _tool_put(request: oRequest): Promise<ToolResult>;
6
+ abstract _tool_get(request: oRequest): Promise<GetDataResponse>;
7
+ abstract _tool_delete(request: oRequest): Promise<ToolResult>;
8
+ abstract _tool_has(request: oRequest): Promise<ToolResult>;
9
+ applyBridgeTransports(address: oAddress, request: oRequest): Promise<oResponse>;
10
+ initialize(): Promise<void>;
11
+ }
12
+ //# sourceMappingURL=storage-provider.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-provider.tool.d.ts","sourceRoot":"","sources":["../../../src/providers/storage-provider.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAa,MAAM,eAAe,CAAC;AACpE,OAAO,EAEL,QAAQ,EACR,QAAQ,EACR,SAAS,EAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAErE,8BAAsB,mBAAoB,SAAQ,YAAY;IAC5D,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAE1D,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAE/D,QAAQ,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAE7D,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAEpD,qBAAqB,CACzB,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,QAAQ,GAChB,OAAO,CAAC,SAAS,CAAC;IAyCf,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAMlC"}
@@ -0,0 +1,41 @@
1
+ import { oVirtualTool } from '@olane/o-tool';
2
+ import { oRequest, StorageResolver, } from '@olane/o-core';
3
+ export class StorageProviderTool extends oVirtualTool {
4
+ async applyBridgeTransports(address, request) {
5
+ this.logger.debug('Applying bridge transports to address: ', address);
6
+ // extract the key from the address
7
+ let key = null;
8
+ let method = 'get';
9
+ const parts = address.toString().split('/');
10
+ const tools = await this.myTools();
11
+ this.logger.debug('Tools: ', tools);
12
+ if (tools.includes(parts[parts.length - 1])) {
13
+ method = parts.pop() || 'get'; // first pop the method
14
+ key = parts.pop(); // then pop the key
15
+ }
16
+ else {
17
+ key = parts.pop();
18
+ }
19
+ this.logger.debug('Determined key + method: ', key, method, request?.params?.method);
20
+ if (!key) {
21
+ throw new Error('Invalid address');
22
+ }
23
+ // restructure the request to include the key
24
+ const req = new oRequest({
25
+ method: method,
26
+ params: {
27
+ ...request.params,
28
+ key,
29
+ method: method,
30
+ },
31
+ id: request.id,
32
+ });
33
+ // call the appropriate method
34
+ const result = await this.execute(req);
35
+ return result;
36
+ }
37
+ async initialize() {
38
+ await super.initialize();
39
+ this.addressResolution.addResolver(new StorageResolver(this.address, this.p2pNode));
40
+ }
41
+ }
@@ -0,0 +1,6 @@
1
+ import { oAnythingResolver } from '@olane/o-core';
2
+ export declare class PlaceholderResolver extends oAnythingResolver {
3
+ get transports(): string[];
4
+ static get transports(): string[];
5
+ }
6
+ //# sourceMappingURL=placeholder.resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placeholder.resolver.d.ts","sourceRoot":"","sources":["../../../src/resolvers/placeholder.resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAIlD,qBAAa,mBAAoB,SAAQ,iBAAiB;IACxD,IAAI,UAAU,IAAI,MAAM,EAAE,CAEzB;IACD,MAAM,KAAK,UAAU,IAAI,MAAM,EAAE,CAEhC;CACF"}
@@ -0,0 +1,10 @@
1
+ import { oAnythingResolver } from '@olane/o-core';
2
+ const placeholderTransports = ['/plan'];
3
+ export class PlaceholderResolver extends oAnythingResolver {
4
+ get transports() {
5
+ return placeholderTransports;
6
+ }
7
+ static get transports() {
8
+ return placeholderTransports;
9
+ }
10
+ }
@@ -0,0 +1,12 @@
1
+ import { oRequest } from '@olane/o-core';
2
+ import { oToolConfig, ToolResult } from '@olane/o-tool';
3
+ import { StorageProviderTool } from './providers/storage-provider.tool.js';
4
+ import { GetDataResponse } from './interfaces/get-data.response.js';
5
+ export declare class StorageTool extends StorageProviderTool {
6
+ constructor(config: oToolConfig);
7
+ _tool_put(request: oRequest): Promise<ToolResult>;
8
+ _tool_get(request: oRequest): Promise<GetDataResponse>;
9
+ _tool_delete(request: oRequest): Promise<ToolResult>;
10
+ _tool_has(request: oRequest): Promise<ToolResult>;
11
+ }
12
+ //# sourceMappingURL=storage.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.tool.d.ts","sourceRoot":"","sources":["../../src/storage.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,QAAQ,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAIpE,qBAAa,WAAY,SAAQ,mBAAmB;gBACtC,MAAM,EAAE,WAAW;IAkCzB,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAKjD,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAItD,YAAY,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAIpD,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;CAGxD"}
@@ -0,0 +1,46 @@
1
+ import { oAddress } from '@olane/o-core';
2
+ import { DiskStorageProvider } from './providers/disk-storage-provider.tool.js';
3
+ import { MemoryStorageProvider } from './providers/memory-storage-provider.tool.js';
4
+ import { StorageProviderTool } from './providers/storage-provider.tool.js';
5
+ import { SecureStorageProvider } from './providers/secure-storage-provider.tool.js';
6
+ import { PlaceholderTool } from './placeholder.tool.js';
7
+ export class StorageTool extends StorageProviderTool {
8
+ constructor(config) {
9
+ super({
10
+ ...config,
11
+ address: new oAddress('o://storage'),
12
+ description: 'Tool to store and retrieve data from the network',
13
+ });
14
+ this.addChildNode(new DiskStorageProvider({
15
+ name: 'disk',
16
+ ...config,
17
+ }));
18
+ this.addChildNode(new MemoryStorageProvider({
19
+ name: 'memory',
20
+ address: new oAddress('o://memory'),
21
+ ...config,
22
+ }));
23
+ this.addChildNode(new SecureStorageProvider({
24
+ name: 'secure',
25
+ address: new oAddress('o://secure'),
26
+ ...config,
27
+ }));
28
+ this.addChildNode(new PlaceholderTool({
29
+ name: 'placeholder storage',
30
+ ...config,
31
+ }));
32
+ }
33
+ async _tool_put(request) {
34
+ // return this.use()
35
+ throw new Error('Not implemented');
36
+ }
37
+ async _tool_get(request) {
38
+ throw new Error('Not implemented');
39
+ }
40
+ async _tool_delete(request) {
41
+ throw new Error('Not implemented');
42
+ }
43
+ async _tool_has(request) {
44
+ throw new Error('Not implemented');
45
+ }
46
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=basic.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic.spec.d.ts","sourceRoot":"","sources":["../../test/basic.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,2 @@
1
+ export declare const bigfile = "\n# \uD83C\uDF0A O-Core: The Future of Distributed AI is Here\n\n[![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)\n[![npm version](https://badge.fury.io/js/%40olane%2Fo-core.svg)](https://badge.fury.io/js/%40olane%2Fo-core)\n[![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)\n\n> **Imagine AI agents that think, plan, and collaborate across a peer-to-peer network\u2014without central servers, without vendor lock-in, without limits.**\n\nO-Core is the foundation for building **decentralized AI networks** where LLM agents operate as autonomous peers, discovering and collaborating with each other to solve complex problems.\n\n## \uD83D\uDE80 Why O-Core Will Change Everything\n\n### \uD83C\uDF10 **True Decentralization**\n- **No Single Point of Failure**: Your AI network runs across distributed nodes\n- **Peer Discovery**: Nodes automatically find and connect to each other via libp2p\n- **Network Resilience**: If one node goes down, others seamlessly take over\n\n### \uD83E\uDDE0 **Intelligent Agent Orchestration**\n- **AI Planning Engine**: Agents autonomously plan multi-step tasks\n- **Context-Aware Routing**: Smart request routing based on capabilities\n- **Self-Organizing Networks**: Nodes discover optimal collaboration patterns\n\n### \u26A1 **Production-Ready Architecture**\n- **Built on libp2p**: Battle-tested P2P networking foundation\n- **TypeScript First**: Type-safe development with excellent IDE support\n- **Metrics & Monitoring**: Built-in Prometheus metrics for observability\n\n---\n\n## \uD83C\uDFAF Core Features\n\n### \uD83E\uDD16 **Autonomous AI Agents**\n\n\n### \uD83C\uDF9B\uFE0F **Flexible Node Types**\n- **Host Nodes**: Full P2P nodes accessible via TCP/IP\n- **Virtual Nodes**: Lightweight in-memory nodes for local processing\n- **Hybrid Networks**: Mix node types for optimal performance\n\n### \uD83D\uDD0D **Intelligent Tool Discovery**\n\n\n---\n\n## \uD83C\uDF1F Real-World Applications\n\n### \uD83C\uDFE2 **Enterprise AI Mesh**\nDeploy AI capabilities across your infrastructure where each service becomes an intelligent agent:\n- Customer service bots that collaborate with analytics agents\n- Content generation that works with fact-checking services\n- Automated workflows that span multiple departments\n\n### \uD83C\uDFE0 **Personal AI Networks**\nBuild your own private AI ecosystem:\n- Home automation agents that learn your preferences\n- Personal assistants that coordinate across devices\n- Local-first AI that never leaves your network\n\n### \uD83C\uDF0D **Community AI Commons**\nParticipate in shared intelligence networks:\n- Researchers sharing specialized AI models\n- Open-source AI tools that anyone can contribute to\n- Collaborative problem-solving at scale\n\n---\n\n## \uD83D\uDE80 Quick Start\n\n\n\n### Create Your First AI Node\n\n\n### Make Your First AI Plan\n\n\n---\n\n## \uD83C\uDFD7\uFE0F Architecture Deep Dive\n\n### \uD83D\uDD17 **Peer-to-Peer Foundation**\nBuilt on **libp2p**, the same networking stack that powers IPFS and Ethereum 2.0:\n- **Content addressing** for deterministic routing\n- **NAT traversal** for real-world connectivity \n- **Pluggable transports** (TCP, WebRTC, WebSockets)\n\n### \uD83E\uDDE0 **AI Planning Layer**\nSmart agents that can:\n- **Analyze intent** and break down complex requests\n- **Discover tools** across the network automatically\n- **Execute multi-step plans** with error recovery\n- **Learn from interactions** via vector storage\n\n### \uD83C\uDF9B\uFE0F **Flexible Deployment**\n- **Docker-ready** with Kubernetes charts\n- **Cloud-agnostic** - runs anywhere\n- **Resource-aware** scaling and discovery\n\n---\n\n## \uD83D\uDEE0\uFE0F Advanced Usage\n\n### Custom Agent Prompts\n\n\n### Network Metrics & Monitoring\n\n// Built-in Prometheus metrics\nconst metrics = node.p2pNode.metrics;\nconsole.log('Active connections:', metrics.getConnectionCount());\nconsole.log('Tool execution success rate:', node.successCount / (node.successCount + node.errorCount));\n\n\n---\n\n## \uD83E\uDD1D Join the Revolution\n\n### \uD83C\uDF1F **For Developers**\n- **Contribute tools** to the global AI network\n- **Build specialized agents** for your domain\n- **Extend the protocol** with new capabilities\n\n### \uD83C\uDFE2 **For Enterprises**\n- **Deploy private AI networks** with zero vendor lock-in\n- **Scale AI horizontally** across your infrastructure\n- **Maintain data sovereignty** while leveraging collective intelligence\n\n### \uD83C\uDF93 **For Researchers**\n- **Experiment with distributed AI** at scale\n- **Share models and tools** with the community\n- **Study emergent behaviors** in AI networks\n\n---\n\n## \uD83D\uDCD6 Documentation & Resources\n\n- **[API Documentation](https://olane-labs.github.io/o-core)**\n- **[Architecture Guide](./docs/ARCHITECTURE.md)**\n- **[Deployment Examples](./examples/)**\n- **[Contributing Guidelines](./CONTRIBUTING.md)**\n\n---\n\n## \uD83C\uDFAF Roadmap\n\n- **Q1 2024**: WebRTC support for browser nodes\n- **Q2 2024**: Built-in model serving capabilities \n- **Q3 2024**: Advanced consensus mechanisms\n- **Q4 2024**: Cross-network protocol bridges\n\n---\n\n## \uD83D\uDCAB The Future is Distributed\n\nO-Core isn't just another AI framework\u2014it's the foundation for an **Internet of Intelligence** where AI agents collaborate as naturally as humans do, but at the speed of light and the scale of the internet.\n\n**Ready to build the future?** \n\n\n**Join our community:**\n- \uD83D\uDC26 [Twitter/X](https://twitter.com/olane_labs)\n- \uD83D\uDCAC [Discord](https://discord.gg/olane)\n- \uD83D\uDCE7 [Newsletter](https://olane.com/newsletter)\n\n---\n\n<div align=\"center\">\n\n**Made with \uD83C\uDF0A by the oLane Team**\n\n*Democratizing AI, one node at a time.*\n\n</div>";
2
+ //# sourceMappingURL=bigfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bigfile.d.ts","sourceRoot":"","sources":["../../../test/data/bigfile.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,wxLA6Kb,CAAC"}