memorio 4.9.35 → 5.1.0

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 (82) hide show
  1. package/AGENTS.md +3 -3
  2. package/README.md +95 -516
  3. package/SECURITY.md +159 -33
  4. package/SUMMARY.md +59 -45
  5. package/adr/001-state-proxy-model.md +95 -0
  6. package/adr/002-observer-semantics.md +179 -0
  7. package/adr/003-deep-mutation-semantics.md +128 -0
  8. package/adr/004-array-mutation-semantics.md +127 -0
  9. package/adr/005-scheduler-contract.md +148 -0
  10. package/adr/006-context-isolation.md +91 -0
  11. package/adr/007-mutation-records.md +117 -0
  12. package/adr/008-transactions.md +105 -0
  13. package/adr/009-history-model.md +109 -0
  14. package/adr/README.md +46 -0
  15. package/adr/template.md +48 -0
  16. package/bin/cli.js +68 -0
  17. package/examples/basic.ts +115 -115
  18. package/examples/browser-vanilla.html +358 -358
  19. package/examples/cache.ts +72 -72
  20. package/examples/cross-platform-guards.ts +57 -57
  21. package/examples/history.ts +104 -0
  22. package/examples/idb.ts +109 -109
  23. package/examples/multi-tenant-context.ts +44 -44
  24. package/examples/node-server.ts +308 -308
  25. package/examples/observer.ts +60 -60
  26. package/examples/platform.ts +115 -115
  27. package/examples/react-app.tsx +362 -362
  28. package/examples/react-observer.tsx +63 -63
  29. package/examples/semantic-memory.ts +60 -60
  30. package/examples/session-advanced.ts +91 -91
  31. package/examples/sqlite-batched-writes.ts +57 -57
  32. package/examples/state-advanced.ts +89 -89
  33. package/examples/store-advanced.ts +117 -117
  34. package/examples/sync.ts +90 -0
  35. package/examples/typed-and-schema.ts +102 -100
  36. package/examples/useObserver.tsx +140 -141
  37. package/global.cjs +5733 -0
  38. package/global.d.ts +8 -0
  39. package/global.js +5667 -0
  40. package/index.cjs +2202 -1041
  41. package/index.d.ts +2 -0
  42. package/index.js +2178 -1040
  43. package/llms.txt +113 -8
  44. package/markdown/AUDIT-REPORT.md +134 -0
  45. package/markdown/CACHE.md +191 -0
  46. package/markdown/DEVTOOLS.md +128 -0
  47. package/markdown/DISPATCH.md +176 -0
  48. package/markdown/HISTORY.md +198 -0
  49. package/markdown/IDB.md +177 -0
  50. package/markdown/IMPORT.md +152 -0
  51. package/markdown/INSPECT.md +122 -0
  52. package/markdown/LOGGER.md +153 -0
  53. package/markdown/MEMORY-ATTACHMENT.md +95 -0
  54. package/markdown/MEMORY.md +161 -0
  55. package/markdown/OBSERVER.md +208 -0
  56. package/markdown/PLATFORM.md +277 -0
  57. package/markdown/REDUX.md +54 -0
  58. package/markdown/SCHEMA.md +175 -0
  59. package/markdown/SESSION.md +164 -0
  60. package/markdown/SQLITE.md +189 -0
  61. package/markdown/STATE.md +159 -0
  62. package/markdown/STORE.md +170 -0
  63. package/markdown/SYNC.md +318 -0
  64. package/markdown/TYPED.md +164 -0
  65. package/markdown/USEOBSERVER.md +256 -0
  66. package/modules/redux.cjs +701 -177
  67. package/modules/redux.cjs.map +1 -1
  68. package/modules/redux.js +701 -177
  69. package/modules/redux.js.map +1 -1
  70. package/package.json +26 -4
  71. package/types/broadcast.d.ts +61 -0
  72. package/types/computed.d.ts +96 -0
  73. package/types/encryption.d.ts +129 -0
  74. package/types/env.d.ts +19 -9
  75. package/types/exports.d.ts +29 -0
  76. package/types/history.d.ts +13 -1
  77. package/types/memorio.d.ts +25 -6
  78. package/types/mutation.d.ts +75 -0
  79. package/types/security.d.ts +67 -0
  80. package/types/session.d.ts +23 -5
  81. package/types/store.d.ts +19 -3
  82. package/vsix/memorio.vsix +0 -0
@@ -0,0 +1,67 @@
1
+ /*!
2
+ memorio
3
+ Copyright (c) 2025 Dario Passariello <dariopassariello@gmail.com>
4
+ Licensed under MIT License, see
5
+ dario.passariello.ca
6
+ */
7
+
8
+ type Permission = 'read' | 'write' | 'delete' | 'admin'
9
+
10
+ interface AccessRule {
11
+ pattern: string | ((key: string, userId?: string) => boolean)
12
+ permissions: Permission[]
13
+ }
14
+
15
+ type AccessRulesMap = Map<string | ((key: string, userId?: string) => boolean), Permission[]>
16
+
17
+ interface AuditEntry {
18
+ timestamp: number
19
+ action: 'set' | 'get' | 'delete' | 'hydrate' | 'remove' | 'clearAll'
20
+ key: string
21
+ userId?: string
22
+ success: boolean
23
+ error?: string
24
+ }
25
+
26
+ interface ConsentRecord {
27
+ id: string
28
+ purpose: string
29
+ granted: boolean
30
+ timestamp: number
31
+ }
32
+
33
+ type ConsentsMap = Map<string, ConsentRecord[]>
34
+
35
+ interface _security {
36
+ safeRandomUUID: () => string
37
+ safeRegexTest: (pattern: string, key: string) => boolean
38
+
39
+ addAccessRule: (rules: AccessRulesMap, pattern: string | ((key: string, userId?: string) => boolean), perms: Permission[]) => AccessRulesMap
40
+ hasPermission: (rules: AccessRulesMap, key: string, action: Permission, userId?: string) => boolean
41
+
42
+ isAuditActive: () => boolean
43
+ setAuditLogger: (logger: (entry: AuditEntry) => void) => void
44
+ logAudit: (entry: Partial<AuditEntry>) => void
45
+
46
+ sanitizeValue: (value: unknown) => unknown
47
+ validateKey: (key: string) => boolean
48
+
49
+ recordConsent: (consents: ConsentsMap, userId: string, purpose: string, granted: boolean) => ConsentRecord
50
+ hasConsent: (consents: ConsentsMap, userId: string, purpose: string) => boolean
51
+ revokeConsent: (consents: ConsentsMap, userId: string, purpose: string) => ConsentRecord | null
52
+ getConsents: (consents: ConsentsMap, userId: string) => ConsentRecord[]
53
+ exportUserData: (consents: ConsentsMap, userId: string) => { userId: string; exportedAt: number; consents: ConsentRecord[] }
54
+ deleteUserData: (consents: ConsentsMap, userId: string) => { success: boolean; deletedConsents: number }
55
+ }
56
+
57
+ declare var security: _security
58
+ type security = _security
59
+
60
+ export {
61
+ Permission,
62
+ AccessRule,
63
+ AccessRulesMap,
64
+ AuditEntry,
65
+ ConsentRecord,
66
+ ConsentsMap
67
+ }
@@ -10,24 +10,42 @@ interface _session {
10
10
  *
11
11
  * @example
12
12
  * session.set("test","example") // or Array, Object, Number, Functions...
13
+ * session.set("test", value, { encrypt: key }) // encrypt at rest
13
14
  *
14
15
  * @since memorio 0.0.1
15
16
  * @param name The String as name to define the session.
16
17
  * @param param The information taht you want to session (Any).
17
- * @return boolean
18
- */
19
- set: (name: string, value: any) => void
18
+ * @param opts Optional { encrypt: key } to encrypt before storage.
19
+ * @return boolean | Promise<boolean>
20
+ */
21
+ set: (name: string, value: any, opts?: { encrypt?: any }) => boolean | Promise<boolean>
22
+
23
+ /**
24
+ * Configure session-wide behavior.
25
+ *
26
+ * @example
27
+ * session.config({ encryptionKey: derivedKey })
28
+ * session.config({ onError: (err, ctx) => console.error(err, ctx) })
29
+ * session.config({ maxObjectSize: 5 * 1024 * 1024 })
30
+ * session.config({ maxTotalSize: 50 * 1024 * 1024 })
31
+ *
32
+ * @since memorio 5.0
33
+ * @param opts { encryptionKey, onError, maxObjectSize, maxTotalSize }
34
+ */
35
+ config: (opts: { encryptionKey?: any; onError?: (err: unknown, ctx: { operation: string }) => void; maxObjectSize?: number; maxTotalSize?: number }) => void
20
36
 
21
37
  /**
22
38
  * Have back the data from a session.
23
39
  *
24
40
  * @example
25
41
  * session.get("test")
42
+ * session.get("test", { decrypt: key }) // decrypt an encrypted envelope
26
43
  *
27
44
  * @since memorio 0.0.1
28
45
  * @param name The String as name to define the session.
29
- */
30
- get: (name: string) => any
46
+ * @param opts Optional { decrypt: key } to decrypt an encrypted envelope.
47
+ */
48
+ get: (name: string, opts?: { decrypt?: any }) => any
31
49
 
32
50
  /**
33
51
  * Delete an existing session:
package/types/store.d.ts CHANGED
@@ -14,18 +14,34 @@ interface _store {
14
14
  * @param value The information you want to store. Functions are blocked for security.
15
15
  * @return void
16
16
  */
17
- set: (name: string, value: any) => void
17
+ set: (name: string, value: any, opts?: { encrypt?: any }) => boolean | Promise<boolean>
18
+
19
+ /**
20
+ * Configure store-wide behavior.
21
+ *
22
+ * @example
23
+ * store.config({ encryptionKey: derivedKey })
24
+ * store.config({ onError: (err, ctx) => console.error(err, ctx) })
25
+ * store.config({ maxObjectSize: 5 * 1024 * 1024 })
26
+ * store.config({ maxTotalSize: 50 * 1024 * 1024 })
27
+ *
28
+ * @since memorio 5.0
29
+ * @param opts { encryptionKey, onError, maxObjectSize, maxTotalSize }
30
+ */
31
+ config: (opts: { encryptionKey?: any; onError?: (err: unknown, ctx: { operation: string }) => void; maxObjectSize?: number; maxTotalSize?: number }) => void
18
32
 
19
33
  /**
20
- * Have back the data from a store.
34
+ * Gets a value from storage.
21
35
  *
22
36
  * @example
23
37
  * store.get("test")
38
+ * store.get("test", { decrypt: key }) // decrypt an encrypted envelope
24
39
  *
25
40
  * @since memorio 0.0.1
26
41
  * @param name The String as name to define the store.
42
+ * @param opts Optional { decrypt: key } to decrypt an encrypted envelope.
27
43
  */
28
- get: (name: string) => any
44
+ get: (name: string, opts?: { decrypt?: any }) => any
29
45
 
30
46
  /**
31
47
  * Delete an existing store:
Binary file