@objectstack/driver-memory 3.0.11 → 3.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.
- package/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +8 -0
- package/dist/index.d.mts +26 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.js +33 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/memory-driver.ts +51 -1
- package/src/persistence/persistence.test.ts +83 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @objectstack/driver-memory@3.0
|
|
2
|
+
> @objectstack/driver-memory@3.1.0 build /home/runner/work/spec/spec/packages/plugins/driver-memory
|
|
3
3
|
> tsup --config ../../../tsup.config.ts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
[34mCLI[39m Cleaning output folder
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
[34mCJS[39m Build start
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
14
|
-
[32mESM[39m [1mdist/index.mjs.map [22m[
|
|
15
|
-
[32mESM[39m ⚡️ Build success in
|
|
16
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
17
|
-
[32mCJS[39m [1mdist/index.js.map [22m[
|
|
18
|
-
[32mCJS[39m ⚡️ Build success in
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m49.23 KB[39m
|
|
14
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m97.21 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 160ms
|
|
16
|
+
[32mCJS[39m [1mdist/index.js [22m[32m50.91 KB[39m
|
|
17
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m97.27 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 163ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 17419ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m13.73 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m13.73 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -28,7 +28,7 @@ interface InMemoryDriverConfig {
|
|
|
28
28
|
logger?: Logger;
|
|
29
29
|
/**
|
|
30
30
|
* Persistence configuration. Defaults to `'auto'`.
|
|
31
|
-
* - `'auto'` (default) — Auto-detect environment (browser → localStorage, Node.js → file)
|
|
31
|
+
* - `'auto'` (default) — Auto-detect environment (browser → localStorage, Node.js → file, serverless → disabled)
|
|
32
32
|
* - `'file'` — File-system persistence with defaults (Node.js only)
|
|
33
33
|
* - `'local'` — localStorage persistence with defaults (Browser only)
|
|
34
34
|
* - `{ type: 'file', path?: string, autoSaveInterval?: number }` — File-system with options
|
|
@@ -36,6 +36,10 @@ interface InMemoryDriverConfig {
|
|
|
36
36
|
* - `{ type: 'auto', path?: string, key?: string, autoSaveInterval?: number }` — Auto-detect with options
|
|
37
37
|
* - `{ adapter: PersistenceAdapterInterface }` — Custom adapter
|
|
38
38
|
* - `false` — Disable persistence (pure in-memory)
|
|
39
|
+
*
|
|
40
|
+
* ⚠️ In serverless environments (Vercel, AWS Lambda, Netlify, etc.),
|
|
41
|
+
* auto mode disables file persistence to prevent silent data loss.
|
|
42
|
+
* Use `persistence: false` or supply a custom adapter for serverless deployments.
|
|
39
43
|
*/
|
|
40
44
|
persistence?: string | false | {
|
|
41
45
|
type?: 'file' | 'local' | 'auto';
|
|
@@ -208,10 +212,31 @@ declare class InMemoryDriver implements DriverInterface {
|
|
|
208
212
|
* Detect whether the current runtime is a browser environment.
|
|
209
213
|
*/
|
|
210
214
|
private isBrowserEnvironment;
|
|
215
|
+
/**
|
|
216
|
+
* Detect whether the current runtime is a serverless/edge environment.
|
|
217
|
+
*
|
|
218
|
+
* Checks well-known environment variables set by serverless platforms:
|
|
219
|
+
* - `VERCEL` / `VERCEL_ENV` — Vercel Functions / Edge
|
|
220
|
+
* - `AWS_LAMBDA_FUNCTION_NAME` — AWS Lambda
|
|
221
|
+
* - `NETLIFY` — Netlify Functions
|
|
222
|
+
* - `FUNCTIONS_WORKER_RUNTIME` — Azure Functions
|
|
223
|
+
* - `K_SERVICE` — Google Cloud Run / Cloud Functions
|
|
224
|
+
* - `FUNCTION_TARGET` — Google Cloud Functions (Node.js)
|
|
225
|
+
* - `DENO_DEPLOYMENT_ID` — Deno Deploy
|
|
226
|
+
*
|
|
227
|
+
* Returns `false` when `process` or `process.env` is unavailable
|
|
228
|
+
* (e.g. browser or edge runtimes without a Node.js process object).
|
|
229
|
+
*/
|
|
230
|
+
private isServerlessEnvironment;
|
|
231
|
+
private static readonly SERVERLESS_PERSISTENCE_WARNING;
|
|
211
232
|
/**
|
|
212
233
|
* Initialize the persistence adapter based on configuration.
|
|
213
234
|
* Defaults to 'auto' when persistence is not specified.
|
|
214
235
|
* Use `persistence: false` to explicitly disable persistence.
|
|
236
|
+
*
|
|
237
|
+
* In serverless environments (Vercel, AWS Lambda, etc.), auto mode disables
|
|
238
|
+
* file-system persistence and emits a warning. Use `persistence: false` or
|
|
239
|
+
* supply a custom adapter for serverless-safe operation.
|
|
215
240
|
*/
|
|
216
241
|
private initPersistence;
|
|
217
242
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ interface InMemoryDriverConfig {
|
|
|
28
28
|
logger?: Logger;
|
|
29
29
|
/**
|
|
30
30
|
* Persistence configuration. Defaults to `'auto'`.
|
|
31
|
-
* - `'auto'` (default) — Auto-detect environment (browser → localStorage, Node.js → file)
|
|
31
|
+
* - `'auto'` (default) — Auto-detect environment (browser → localStorage, Node.js → file, serverless → disabled)
|
|
32
32
|
* - `'file'` — File-system persistence with defaults (Node.js only)
|
|
33
33
|
* - `'local'` — localStorage persistence with defaults (Browser only)
|
|
34
34
|
* - `{ type: 'file', path?: string, autoSaveInterval?: number }` — File-system with options
|
|
@@ -36,6 +36,10 @@ interface InMemoryDriverConfig {
|
|
|
36
36
|
* - `{ type: 'auto', path?: string, key?: string, autoSaveInterval?: number }` — Auto-detect with options
|
|
37
37
|
* - `{ adapter: PersistenceAdapterInterface }` — Custom adapter
|
|
38
38
|
* - `false` — Disable persistence (pure in-memory)
|
|
39
|
+
*
|
|
40
|
+
* ⚠️ In serverless environments (Vercel, AWS Lambda, Netlify, etc.),
|
|
41
|
+
* auto mode disables file persistence to prevent silent data loss.
|
|
42
|
+
* Use `persistence: false` or supply a custom adapter for serverless deployments.
|
|
39
43
|
*/
|
|
40
44
|
persistence?: string | false | {
|
|
41
45
|
type?: 'file' | 'local' | 'auto';
|
|
@@ -208,10 +212,31 @@ declare class InMemoryDriver implements DriverInterface {
|
|
|
208
212
|
* Detect whether the current runtime is a browser environment.
|
|
209
213
|
*/
|
|
210
214
|
private isBrowserEnvironment;
|
|
215
|
+
/**
|
|
216
|
+
* Detect whether the current runtime is a serverless/edge environment.
|
|
217
|
+
*
|
|
218
|
+
* Checks well-known environment variables set by serverless platforms:
|
|
219
|
+
* - `VERCEL` / `VERCEL_ENV` — Vercel Functions / Edge
|
|
220
|
+
* - `AWS_LAMBDA_FUNCTION_NAME` — AWS Lambda
|
|
221
|
+
* - `NETLIFY` — Netlify Functions
|
|
222
|
+
* - `FUNCTIONS_WORKER_RUNTIME` — Azure Functions
|
|
223
|
+
* - `K_SERVICE` — Google Cloud Run / Cloud Functions
|
|
224
|
+
* - `FUNCTION_TARGET` — Google Cloud Functions (Node.js)
|
|
225
|
+
* - `DENO_DEPLOYMENT_ID` — Deno Deploy
|
|
226
|
+
*
|
|
227
|
+
* Returns `false` when `process` or `process.env` is unavailable
|
|
228
|
+
* (e.g. browser or edge runtimes without a Node.js process object).
|
|
229
|
+
*/
|
|
230
|
+
private isServerlessEnvironment;
|
|
231
|
+
private static readonly SERVERLESS_PERSISTENCE_WARNING;
|
|
211
232
|
/**
|
|
212
233
|
* Initialize the persistence adapter based on configuration.
|
|
213
234
|
* Defaults to 'auto' when persistence is not specified.
|
|
214
235
|
* Use `persistence: false` to explicitly disable persistence.
|
|
236
|
+
*
|
|
237
|
+
* In serverless environments (Vercel, AWS Lambda, etc.), auto mode disables
|
|
238
|
+
* file-system persistence and emits a warning. Use `persistence: false` or
|
|
239
|
+
* supply a custom adapter for serverless-safe operation.
|
|
215
240
|
*/
|
|
216
241
|
private initPersistence;
|
|
217
242
|
}
|
package/dist/index.js
CHANGED
|
@@ -202,7 +202,7 @@ function getValueByPath(obj, path2) {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
// src/memory-driver.ts
|
|
205
|
-
var
|
|
205
|
+
var _InMemoryDriver = class _InMemoryDriver {
|
|
206
206
|
constructor(config) {
|
|
207
207
|
this.name = "com.objectstack.driver.memory";
|
|
208
208
|
this.type = "driver";
|
|
@@ -931,10 +931,36 @@ var InMemoryDriver = class {
|
|
|
931
931
|
isBrowserEnvironment() {
|
|
932
932
|
return typeof globalThis.localStorage !== "undefined";
|
|
933
933
|
}
|
|
934
|
+
/**
|
|
935
|
+
* Detect whether the current runtime is a serverless/edge environment.
|
|
936
|
+
*
|
|
937
|
+
* Checks well-known environment variables set by serverless platforms:
|
|
938
|
+
* - `VERCEL` / `VERCEL_ENV` — Vercel Functions / Edge
|
|
939
|
+
* - `AWS_LAMBDA_FUNCTION_NAME` — AWS Lambda
|
|
940
|
+
* - `NETLIFY` — Netlify Functions
|
|
941
|
+
* - `FUNCTIONS_WORKER_RUNTIME` — Azure Functions
|
|
942
|
+
* - `K_SERVICE` — Google Cloud Run / Cloud Functions
|
|
943
|
+
* - `FUNCTION_TARGET` — Google Cloud Functions (Node.js)
|
|
944
|
+
* - `DENO_DEPLOYMENT_ID` — Deno Deploy
|
|
945
|
+
*
|
|
946
|
+
* Returns `false` when `process` or `process.env` is unavailable
|
|
947
|
+
* (e.g. browser or edge runtimes without a Node.js process object).
|
|
948
|
+
*/
|
|
949
|
+
isServerlessEnvironment() {
|
|
950
|
+
if (typeof globalThis.process === "undefined" || !globalThis.process.env) {
|
|
951
|
+
return false;
|
|
952
|
+
}
|
|
953
|
+
const env = globalThis.process.env;
|
|
954
|
+
return !!(env.VERCEL || env.VERCEL_ENV || env.AWS_LAMBDA_FUNCTION_NAME || env.NETLIFY || env.FUNCTIONS_WORKER_RUNTIME || env.K_SERVICE || env.FUNCTION_TARGET || env.DENO_DEPLOYMENT_ID);
|
|
955
|
+
}
|
|
934
956
|
/**
|
|
935
957
|
* Initialize the persistence adapter based on configuration.
|
|
936
958
|
* Defaults to 'auto' when persistence is not specified.
|
|
937
959
|
* Use `persistence: false` to explicitly disable persistence.
|
|
960
|
+
*
|
|
961
|
+
* In serverless environments (Vercel, AWS Lambda, etc.), auto mode disables
|
|
962
|
+
* file-system persistence and emits a warning. Use `persistence: false` or
|
|
963
|
+
* supply a custom adapter for serverless-safe operation.
|
|
938
964
|
*/
|
|
939
965
|
async initPersistence() {
|
|
940
966
|
const persistence = this.config.persistence === void 0 ? "auto" : this.config.persistence;
|
|
@@ -945,6 +971,8 @@ var InMemoryDriver = class {
|
|
|
945
971
|
const { LocalStoragePersistenceAdapter: LocalStoragePersistenceAdapter2 } = await Promise.resolve().then(() => (init_local_storage_adapter(), local_storage_adapter_exports));
|
|
946
972
|
this.persistenceAdapter = new LocalStoragePersistenceAdapter2();
|
|
947
973
|
this.logger.debug("Auto-detected browser environment, using localStorage persistence");
|
|
974
|
+
} else if (this.isServerlessEnvironment()) {
|
|
975
|
+
this.logger.warn(_InMemoryDriver.SERVERLESS_PERSISTENCE_WARNING);
|
|
948
976
|
} else {
|
|
949
977
|
const { FileSystemPersistenceAdapter: FileSystemPersistenceAdapter2 } = await Promise.resolve().then(() => (init_file_adapter(), file_adapter_exports));
|
|
950
978
|
this.persistenceAdapter = new FileSystemPersistenceAdapter2();
|
|
@@ -969,6 +997,8 @@ var InMemoryDriver = class {
|
|
|
969
997
|
key: persistence.key
|
|
970
998
|
});
|
|
971
999
|
this.logger.debug("Auto-detected browser environment, using localStorage persistence");
|
|
1000
|
+
} else if (this.isServerlessEnvironment()) {
|
|
1001
|
+
this.logger.warn(_InMemoryDriver.SERVERLESS_PERSISTENCE_WARNING);
|
|
972
1002
|
} else {
|
|
973
1003
|
const { FileSystemPersistenceAdapter: FileSystemPersistenceAdapter2 } = await Promise.resolve().then(() => (init_file_adapter(), file_adapter_exports));
|
|
974
1004
|
this.persistenceAdapter = new FileSystemPersistenceAdapter2({
|
|
@@ -995,6 +1025,8 @@ var InMemoryDriver = class {
|
|
|
995
1025
|
}
|
|
996
1026
|
}
|
|
997
1027
|
};
|
|
1028
|
+
_InMemoryDriver.SERVERLESS_PERSISTENCE_WARNING = "Serverless environment detected \u2014 file-system persistence is disabled in auto mode. Data will NOT be persisted across function invocations. Set persistence: false to silence this warning, or provide a custom adapter (e.g. Upstash Redis, Vercel KV) via persistence: { adapter: yourAdapter }.";
|
|
1029
|
+
var InMemoryDriver = _InMemoryDriver;
|
|
998
1030
|
|
|
999
1031
|
// src/index.ts
|
|
1000
1032
|
init_file_adapter();
|