@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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @objectstack/driver-memory@3.0.11 build /home/runner/work/spec/spec/packages/plugins/driver-memory
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
  CLI Building entry: src/index.ts
@@ -10,13 +10,13 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  CJS Build start
13
- ESM dist/index.mjs 47.36 KB
14
- ESM dist/index.mjs.map 94.51 KB
15
- ESM ⚡️ Build success in 173ms
16
- CJS dist/index.js 49.04 KB
17
- CJS dist/index.js.map 94.56 KB
18
- CJS ⚡️ Build success in 176ms
13
+ ESM dist/index.mjs 49.23 KB
14
+ ESM dist/index.mjs.map 97.21 KB
15
+ ESM ⚡️ Build success in 160ms
16
+ CJS dist/index.js 50.91 KB
17
+ CJS dist/index.js.map 97.27 KB
18
+ CJS ⚡️ Build success in 163ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 15528ms
21
- DTS dist/index.d.mts 12.48 KB
22
- DTS dist/index.d.ts 12.48 KB
20
+ DTS ⚡️ Build success in 17419ms
21
+ DTS dist/index.d.mts 13.73 KB
22
+ DTS dist/index.d.ts 13.73 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @objectstack/driver-memory
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [0088830]
8
+ - @objectstack/spec@3.1.0
9
+ - @objectstack/core@3.1.0
10
+
3
11
  ## 3.0.11
4
12
 
5
13
  ### Patch Changes
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 InMemoryDriver = class {
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();