@effect/platform 0.13.13 → 0.13.14

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/Error.d.ts CHANGED
@@ -28,7 +28,7 @@ export declare namespace PlatformError {
28
28
  interface Base extends Data.Case {
29
29
  readonly [PlatformErrorTypeId]: typeof PlatformErrorTypeId;
30
30
  readonly _tag: string;
31
- readonly module: "Command" | "FileSystem" | "Path";
31
+ readonly module: "Command" | "FileSystem" | "Path" | "KeyValueStore";
32
32
  readonly method: string;
33
33
  readonly message: string;
34
34
  }
package/Error.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["./src/Error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,IAAI,MAAM,mBAAmB,CAAA;AAG9C;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,OAAO,MAAqC,CAAA;AAE9E;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAA;AAE5D;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,WAAW,CAAA;AAErD;;GAEG;AACH,yBAAiB,aAAa,CAAC;IAC7B;;;OAGG;IACH,UAAiB,IAAK,SAAQ,IAAI,CAAC,IAAI;QACrC,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,OAAO,mBAAmB,CAAA;QAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;QACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,YAAY,GAAG,MAAM,CAAA;QAClD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;QACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KACzB;IAED;;OAEG;IACH,KAAY,cAAc,GAAG,mBAAmB,GAAG,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAA;CAC5E;AAED;;;GAGG;AACH,MAAM,WAAW,WAAY,S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";
5
+ import type * as Option from "@effect/data/Option";
6
+ import type * as Effect from "@effect/io/Effect";
7
+ import type * as Layer from "@effect/io/Layer";
8
+ import type * as PlatformError from "@effect/platform/Error";
9
+ import type * as FileSystem from "@effect/platform/FileSystem";
10
+ import type * as Path from "@effect/platform/Path";
11
+ import type * as ParseResult from "@effect/schema/ParseResult";
12
+ import type * as Schema from "@effect/schema/Schema";
13
+ /**
14
+ * @since 1.0.0
15
+ * @category type id
16
+ */
17
+ export declare const TypeId: unique symbol;
18
+ /**
19
+ * @since 1.0.0
20
+ * @category type id
21
+ */
22
+ export type TypeId = typeof TypeId;
23
+ /**
24
+ * @since 1.0.0
25
+ * @category models
26
+ */
27
+ export interface KeyValueStore {
28
+ readonly [TypeId]: TypeId;
29
+ /**
30
+ * Returns the value of the specified key if it exists.
31
+ */
32
+ readonly get: (key: string) => Effect.Effect<never, PlatformError.PlatformError, Option.Option<string>>;
33
+ /**
34
+ * Sets the value of the specified key.
35
+ */
36
+ readonly set: (key: string, value: string) => Effect.Effect<never, PlatformError.PlatformError, void>;
37
+ /**
38
+ * Removes the specified key.
39
+ */
40
+ readonly remove: (key: string) => Effect.Effect<never, PlatformError.PlatformError, void>;
41
+ /**
42
+ * Removes all entries.
43
+ */
44
+ readonly clear: Effect.Effect<never, PlatformError.PlatformError, void>;
45
+ /**
46
+ * Returns the number of entries.
47
+ */
48
+ readonly size: Effect.Effect<never, PlatformError.PlatformError, number>;
49
+ /**
50
+ * Updates the value of the specified key if it exists.
51
+ */
52
+ readonly modify: (key: string, f: (value: string) => string) => Effect.Effect<never, PlatformError.PlatformError, Option.Option<string>>;
53
+ /**
54
+ * Returns true if the KeyValueStore contains the specified key.
55
+ */
56
+ readonly has: (key: string) => Effect.Effect<never, PlatformError.PlatformError, boolean>;
57
+ /**
58
+ * Checks if the KeyValueStore contains any entries.
59
+ */
60
+ readonly isEmpty: Effect.Effect<never, PlatformError.PlatformError, boolean>;
61
+ /**
62
+ * Create a SchemaStore for the specified schema.
63
+ */
64
+ readonly forSchema: <I, A>(schema: Schema.Schema<I, A>) => SchemaStore<A>;
65
+ }
66
+ /**
67
+ * @since 1.0.0
68
+ */
69
+ export declare namespace KeyValueStore {
70
+ /**
71
+ * @since 1.0.0
72
+ */
73
+ type AnyStore = KeyValueStore | SchemaStore<any>;
74
+ }
75
+ /**
76
+ * @since 1.0.0
77
+ * @category tags
78
+ */
79
+ export declare const KeyValueStore: Context.Tag<KeyValueStore, KeyValueStore>;
80
+ /**
81
+ * @since 1.0.0
82
+ * @category constructors
83
+ */
84
+ export declare const make: (impl: Omit<KeyValueStore, typeof TypeId | "has" | "modify" | "isEmpty" | "forSchema"> & Partial<KeyValueStore>) => KeyValueStore;
85
+ /**
86
+ * @since 1.0.0
87
+ * @category combinators
88
+ */
89
+ export declare const prefix: {
90
+ (prefix: string): <S extends KeyValueStore.AnyStore>(self: S) => S;
91
+ <S extends KeyValueStore.AnyStore>(self: S, prefix: string): S;
92
+ };
93
+ /**
94
+ * @since 1.0.0
95
+ * @category layers
96
+ */
97
+ export declare const layerMemory: Layer.Layer<never, never, KeyValueStore>;
98
+ /**
99
+ * @since 1.0.0
100
+ * @category layers
101
+ */
102
+ export declare const layerFileSystem: (directory: string) => Layer.Layer<FileSystem.FileSystem | Path.Path, PlatformError.PlatformError, KeyValueStore>;
103
+ /**
104
+ * @since 1.0.0
105
+ * @category type id
106
+ */
107
+ export declare const SchemaStoreTypeId: unique symbol;
108
+ /**
109
+ * @since 1.0.0
110
+ * @category type id
111
+ */
112
+ export type SchemaStoreTypeId = typeof SchemaStoreTypeId;
113
+ /**
114
+ * @since 1.0.0
115
+ * @category models
116
+ */
117
+ export interface SchemaStore<A> {
118
+ readonly [SchemaStoreTypeId]: SchemaStoreTypeId;
119
+ /**
120
+ * Returns the value of the specified key if it exists.
121
+ */
122
+ readonly get: (key: string) => Effect.Effect<never, PlatformError.PlatformError | ParseResult.ParseError, Option.Option<A>>;
123
+ /**
124
+ * Sets the value of the specified key.
125
+ */
126
+ readonly set: (key: string, value: A) => Effect.Effect<never, PlatformError.PlatformError | ParseResult.ParseError, void>;
127
+ /**
128
+ * Removes the specified key.
129
+ */
130
+ readonly remove: (key: string) => Effect.Effect<never, PlatformError.PlatformError, void>;
131
+ /**
132
+ * Removes all entries.
133
+ */
134
+ readonly clear: Effect.Effect<never, PlatformError.PlatformError, void>;
135
+ /**
136
+ * Returns the number of entries.
137
+ */
138
+ readonly size: Effect.Effect<never, PlatformError.PlatformError, number>;
139
+ /**
140
+ * Updates the value of the specified key if it exists.
141
+ */
142
+ readonly modify: (key: string, f: (value: A) => A) => Effect.Effect<never, PlatformError.PlatformError | ParseResult.ParseError, Option.Option<A>>;
143
+ /**
144
+ * Returns true if the KeyValueStore contains the specified key.
145
+ */
146
+ readonly has: (key: string) => Effect.Effect<never, PlatformError.PlatformError, boolean>;
147
+ /**
148
+ * Checks if the KeyValueStore contains any entries.
149
+ */
150
+ readonly isEmpty: Effect.Effect<never, PlatformError.PlatformError, boolean>;
151
+ }
152
+ /**
153
+ * @since 1.0.0
154
+ * @category layers
155
+ */
156
+ export declare const layerSchema: <I, A>(schema: Schema.Schema<I, A>, tagIdentifier?: unknown) => {
157
+ readonly tag: Context.Tag<SchemaStore<A>, SchemaStore<A>>;
158
+ readonly layer: Layer.Layer<KeyValueStore, never, SchemaStore<A>>;
159
+ };
160
+ //# sourceMappingURL=KeyValueStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyValueStore.d.ts","sourceRoot":"","sources":["./src/KeyValueStore.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,OAAO,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,KAAK,MAAM,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,KAAK,MAAM,kBAAkB,CAAA;AAC9C,OAAO,KAAK,KAAK,aAAa,MAAM,wBAAwB,CAAA;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defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.prefix = exports.make = exports.layerSchema = exports.layerMemory = exports.layerFileSystem = exports.TypeId = exports.SchemaStoreTypeId = exports.KeyValueStore = void 0;
7
+ var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/internal/keyValueStore"));
8
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
9
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
10
+ /**
11
+ * @since 1.0.0
12
+ * @category type id
13
+ */
14
+ const TypeId = internal.TypeId;
15
+ /**
16
+ * @since 1.0.0
17
+ * @category tags
18
+ */
19
+ exports.TypeId = TypeId;
20
+ const KeyValueStore = internal.keyValueStoreTag;
21
+ /**
22
+ * @since 1.0.0
23
+ * @category constructors
24
+ */
25
+ exports.KeyValueStore = KeyValueStore;
26
+ const make = internal.make;
27
+ /**
28
+ * @since 1.0.0
29
+ * @category combinators
30
+ */
31
+ exports.make = make;
32
+ const prefix = internal.prefix;
33
+ /**
34
+ * @since 1.0.0
35
+ * @category layers
36
+ */
37
+ exports.prefix = prefix;
38
+ const layerMemory = internal.layerMemory;
39
+ /**
40
+ * @since 1.0.0
41
+ * @category layers
42
+ */
43
+ exports.layerMemory = layerMemory;
44
+ const layerFileSystem = internal.layerFileSystem;
45
+ /**
46
+ * @since 1.0.0
47
+ * @category type id
48
+ */
49
+ exports.layerFileSystem = layerFileSystem;
50
+ const SchemaStoreTypeId = internal.SchemaStoreTypeId;
51
+ /**
52
+ * @since 1.0.0
53
+ * @category layers
54
+ */
55
+ exports.SchemaStoreTypeId = SchemaStoreTypeId;
56
+ const layerSchema = internal.layerSchema;
57
+ exports.layerSchema = layerSchema;
58
+ //# sourceMappingURL=KeyValueStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyValueStore.js","names":["internal","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","TypeId","exports","KeyValueStore","keyValueStoreTag","make","prefix","layerMemory","layerFileSystem","SchemaStoreTypeId","layerSchema"],"sources":["./src/KeyValueStore.ts"],"sourcesContent":[null],"mappings":";;;;;;AASA,IAAAA,QAAA,gBAAAC,uBAAA,eAAAC,OAAA;AAAmE,SAAAC,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,C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AAAM,eAAA,GAAAA,eAAA;AAIO,MAAMC,iBAAiB,GAAkBjC,QAAQ,CAACiC,iBAAiB;AA+D1E;;;;AAAAP,OAAA,CAAAO,iBAAA,GAAAA,iBAAA;AAIO,MAAMC,WAAW,GAMpBlC,QAAQ,CAACkC,WAAW;AAAAR,OAAA,CAAAQ,WAAA,GAAAA,WAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=keyValueStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyValueStore.d.ts","sourceRoot":"","sources":["../src/internal/keyValueStore.ts"],"names":[],"mappings":""}
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.prefix = exports.make = exports.layerSchema = exports.layerMemory = exports.layerFileSystem = exports.keyValueStoreTag = exports.TypeId = exports.SchemaStoreTypeId = void 0;
7
+ var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Context"));
8
+ var _Function = /*#__PURE__*/require("@effect/data/Function");
9
+ var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Option"));
10
+ var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Effect"));
11
+ var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Layer"));
12
+ var FileSystem = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/FileSystem"));
13
+ var Path = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/Path"));
14
+ var Schema = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/Schema"));
15
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+ /** @internal */
18
+ const TypeId = /*#__PURE__*/Symbol.for("@effect/platform/KeyValueStore");
19
+ /** @internal */
20
+ exports.TypeId = TypeId;
21
+ const keyValueStoreTag = /*#__PURE__*/Context.Tag(TypeId);
22
+ /** @internal */
23
+ exports.keyValueStoreTag = keyValueStoreTag;
24
+ const make = impl => keyValueStoreTag.of({
25
+ [TypeId]: TypeId,
26
+ has: key => Effect.map(impl.get(key), Option.isSome),
27
+ isEmpty: Effect.map(impl.size, size => size === 0),
28
+ modify: (key, f) => Effect.flatMap(impl.get(key), o => {
29
+ if (Option.isNone(o)) {
30
+ return Effect.succeedNone;
31
+ }
32
+ const newValue = f(o.value);
33
+ return Effect.as(impl.set(key, newValue), Option.some(newValue));
34
+ }),
35
+ forSchema(schema) {
36
+ return makeSchemaStore(this, schema);
37
+ },
38
+ ...impl
39
+ });
40
+ /** @internal */
41
+ exports.make = make;
42
+ const prefix = /*#__PURE__*/(0, _Function.dual)(2, (self, prefix) => ({
43
+ ...self,
44
+ get: key => self.get(`${prefix}${key}`),
45
+ set: (key, value) => self.set(`${prefix}${key}`, value),
46
+ remove: key => self.remove(`${prefix}${key}`),
47
+ has: key => self.has(`${prefix}${key}`),
48
+ modify: (key, f) => self.modify(`${prefix}${key}`, f)
49
+ }));
50
+ /** @internal */
51
+ exports.prefix = prefix;
52
+ const SchemaStoreTypeId = /*#__PURE__*/Symbol.for("@effect/platform/KeyValueStore/SchemaStore");
53
+ /** @internal */
54
+ exports.SchemaStoreTypeId = SchemaStoreTypeId;
55
+ const makeSchemaStore = (store, schema) => {
56
+ const jsonSchema = Schema.compose(Schema.ParseJson, schema);
57
+ const parse = Schema.parse(jsonSchema);
58
+ const encode = Schema.encode(jsonSchema);
59
+ const get = key => Effect.flatMap(store.get(key), Option.match({
60
+ onNone: () => Effect.succeedNone,
61
+ onSome: value => Effect.asSome(parse(value))
62
+ }));
63
+ const set = (key, value) => Effect.flatMap(encode(value), json => store.set(key, json));
64
+ const modify = (key, f) => Effect.flatMap(get(key), o => {
65
+ if (Option.isNone(o)) {
66
+ return Effect.succeedNone;
67
+ }
68
+ const newValue = f(o.value);
69
+ return Effect.as(set(key, newValue), Option.some(newValue));
70
+ });
71
+ return {
72
+ [SchemaStoreTypeId]: SchemaStoreTypeId,
73
+ get,
74
+ set,
75
+ modify,
76
+ remove: store.remove,
77
+ clear: store.clear,
78
+ size: store.size,
79
+ has: store.has,
80
+ isEmpty: store.isEmpty
81
+ };
82
+ };
83
+ /** @internal */
84
+ const layerMemory = /*#__PURE__*/Layer.sync(keyValueStoreTag, () => {
85
+ const store = new Map();
86
+ return make({
87
+ get: key => Effect.sync(() => Option.fromNullable(store.get(key))),
88
+ set: (key, value) => Effect.sync(() => store.set(key, value)),
89
+ remove: key => Effect.sync(() => store.delete(key)),
90
+ clear: Effect.sync(() => store.clear()),
91
+ size: Effect.sync(() => store.size)
92
+ });
93
+ });
94
+ /** @internal */
95
+ exports.layerMemory = layerMemory;
96
+ const layerFileSystem = directory => Layer.effect(keyValueStoreTag, Effect.gen(function* (_) {
97
+ const fs = yield* _(FileSystem.FileSystem);
98
+ const path = yield* _(Path.Path);
99
+ const keyPath = key => path.join(directory, encodeURIComponent(key));
100
+ if (!(yield* _(fs.exists(directory)))) {
101
+ yield* _(fs.makeDirectory(directory, {
102
+ recursive: true
103
+ }));
104
+ }
105
+ return make({
106
+ get: key => Effect.catchTag("SystemError", sysError => sysError.reason === "NotFound" ? Effect.succeed(Option.none()) : Effect.fail(sysError))(Effect.map(fs.readFileString(keyPath(key)), Option.some)),
107
+ set: (key, value) => fs.writeFileString(keyPath(key), value),
108
+ remove: key => fs.remove(keyPath(key)),
109
+ has: key => fs.exists(keyPath(key)),
110
+ clear: Effect.zipRight(fs.remove(directory, {
111
+ recursive: true
112
+ }), fs.makeDirectory(directory, {
113
+ recursive: true
114
+ })),
115
+ size: Effect.map(fs.readDirectory(directory), files => files.length)
116
+ });
117
+ }));
118
+ /** @internal */
119
+ exports.layerFileSystem = layerFileSystem;
120
+ const layerSchema = (schema, tagIdentifier) => {
121
+ const tag = Context.Tag(tagIdentifier);
122
+ const layer = Layer.effect(tag, Effect.map(keyValueStoreTag, store => store.forSchema(schema)));
123
+ return {
124
+ tag,
125
+ layer
126
+ };
127
+ };
128
+ exports.layerSchema = layerSchema;
129
+ //# sourceMappingURL=keyValueStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyValueStore.js","names":["Context","_interopRequireWildcard","require","_Function","Option","Effect","Layer","FileSystem","Path","Schema","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","TypeId","Symbol","for","exports","keyValueStoreTag","Tag","make","impl","of","map","isSome","isEmpty","size","modify","f","flatMap","o","isNone","succeedNone","newValue","value","as","some","forSchema","schema","makeSchemaStore","prefix","dual","self","remove","SchemaStoreTypeId","store","jsonSchema","compose","ParseJson","parse","encode","match","onNone","onSome","asSome","json","clear","layerMemory","sync","Map","fromNullable","delete","layerFileSystem","directory","effect","gen","_","fs","path","keyPath","join","encodeURIComponent","exists","makeDirectory","recursive","catchTag","sysError","reason","succeed","none","fail","readFileString","writeFileString","zipRight","readDirectory","files","length","layerSchema","tagIdentifier","tag","layer"],"sources":["../src/internal/keyValueStore.ts"],"sourcesContent":[null],"mappings":";;;;;;AAAA,IAAAA,OAAA,gBAAAC,uBAAA,eAAAC,OAAA;AACA,IAAAC,SAAA,gBAAAD,OAAA;AACA,IAAAE,MAAA,gBAAAH,uBAAA,eAAAC,OAAA;AACA,IAAAG,MAAA,gBAAAJ,uBAAA,eAAAC,OAAA;AACA,IAAAI,KAAA,gBAAAL,uBAAA,eAAAC,OAAA;AACA,IAAAK,UAAA,gBAAAN,uBAAA,eAAAC,OAAA;AAEA,IAAAM,IAAA,gBAAAP,uBAAA,eAAAC,OAAA;AACA,IAAAO,MAAA,gBAAAR,uBAAA,eAAAC,OAAA;AAA+C,SAAAQ,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAV,wBAAAc,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,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,EAAE,CAACM,aAAa,CAACV,SAAS,EAAE;MAAEW,SAAS,EAAE;IAAI,CAAE,CAAC,CACjD;IACDhD,IAAI,EAAEvC,MAAM,CAACoC,GAAG,CACd4C,EAAE,CAACiB,aAAa,CAACrB,SAAS,CAAC,EAC1BsB,KAAK,IAAKA,KAAK,CAACC,MAAM;GAE1B,CAAC;AACJ,CAAC,CAAC,CACH;AAEH;AAAArE,OAAA,CAAA6C,eAAA,GAAAA,eAAA;AACO,MAAMyB,WAAW,GAAGA,CACzBjD,MAA2B,EAC3BkD,aAAuB,KACrB;EACF,MAAMC,GAAG,GAAG3G,OAAO,CAACqC,GAAG,CAA+BqE,aAAa,CAAC;EACpE,MAAME,KAAK,GAAGtG,KAAK,CAAC4E,MAAM,CAACyB,GAAG,EAAEtG,MAAM,CAACoC,GAAG,CAACL,gBAAgB,EAAG2B,KAAK,IAAKA,KAAK,CAACR,SAAS,CAACC,MAAM,CAAC,CAAC,CAAC;EACjG,OAAO;IAAEmD,GAAG;IAAEC;EAAK,CAAW;AAChC,CAAC;AAAAzE,OAAA,CAAAsE,WAAA,GAAAA,WAAA"}
@@ -0,0 +1,42 @@
1
+ import * as internal from "@effect/platform/internal/keyValueStore";
2
+ /**
3
+ * @since 1.0.0
4
+ * @category type id
5
+ */
6
+ export const TypeId = internal.TypeId;
7
+ /**
8
+ * @since 1.0.0
9
+ * @category tags
10
+ */
11
+ export const KeyValueStore = internal.keyValueStoreTag;
12
+ /**
13
+ * @since 1.0.0
14
+ * @category constructors
15
+ */
16
+ export const make = internal.make;
17
+ /**
18
+ * @since 1.0.0
19
+ * @category combinators
20
+ */
21
+ export const prefix = internal.prefix;
22
+ /**
23
+ * @since 1.0.0
24
+ * @category layers
25
+ */
26
+ export const layerMemory = internal.layerMemory;
27
+ /**
28
+ * @since 1.0.0
29
+ * @category layers
30
+ */
31
+ export const layerFileSystem = internal.layerFileSystem;
32
+ /**
33
+ * @since 1.0.0
34
+ * @category type id
35
+ */
36
+ export const SchemaStoreTypeId = internal.SchemaStoreTypeId;
37
+ /**
38
+ * @since 1.0.0
39
+ * @category layers
40
+ */
41
+ export const layerSchema = internal.layerSchema;
42
+ //# sourceMappingURL=KeyValueStore.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyValueStore.mjs","names":["internal","TypeId","KeyValueStore","keyValueStoreTag","make","prefix","layerMemory","layerFileSystem","SchemaStoreTypeId","layerSchema"],"sources":["../src/KeyValueStore.ts"],"sourcesContent":[null],"mappings":"AASA,OAAO,KAAKA,QAAQ,MAAM,yCAAyC;AAKnE;;;;AAIA,OAAO,MAAMC,MAAM,GAAkBD,QAAQ,CAACC,MAAM;AAyEpD;;;;AAIA,OAAO,MAAMC,aAAa,GAA8CF,QAAQ,CAACG,gBAAgB;AAEjG;;;;AAIA,OAAO,MAAMC,IAAI,GAEIJ,QAAQ,CAACI,IAAI;AAElC;;;;AAIA,OAAO,MAAMC,MAAM,GAGfL,QAAQ,CAACK,MAAM;AAEnB;;;;AAIA,OAAO,MAAMC,WAAW,GAA6CN,QAAQ,CAACM,WAAW;AAEzF;;;;AAIA,OAAO,MAAMC,eAAe,GAG1BP,QAAQ,CAACO,eAAe;AAE1B;;;;AAIA,OAAO,MAAMC,iBAAiB,GAAkBR,QAAQ,CAACQ,iBAAiB;AA+D1E;;;;AAIA,OAAO,MAAMC,WAAW,GAMpBT,QAAQ,CAACS,WAAW"}
@@ -0,0 +1,113 @@
1
+ import * as Context from "@effect/data/Context";
2
+ import { dual } from "@effect/data/Function";
3
+ import * as Option from "@effect/data/Option";
4
+ import * as Effect from "@effect/io/Effect";
5
+ import * as Layer from "@effect/io/Layer";
6
+ import * as FileSystem from "@effect/platform/FileSystem";
7
+ import * as Path from "@effect/platform/Path";
8
+ import * as Schema from "@effect/schema/Schema";
9
+ /** @internal */
10
+ export const TypeId = /*#__PURE__*/Symbol.for("@effect/platform/KeyValueStore");
11
+ /** @internal */
12
+ export const keyValueStoreTag = /*#__PURE__*/Context.Tag(TypeId);
13
+ /** @internal */
14
+ export const make = impl => keyValueStoreTag.of({
15
+ [TypeId]: TypeId,
16
+ has: key => Effect.map(impl.get(key), Option.isSome),
17
+ isEmpty: Effect.map(impl.size, size => size === 0),
18
+ modify: (key, f) => Effect.flatMap(impl.get(key), o => {
19
+ if (Option.isNone(o)) {
20
+ return Effect.succeedNone;
21
+ }
22
+ const newValue = f(o.value);
23
+ return Effect.as(impl.set(key, newValue), Option.some(newValue));
24
+ }),
25
+ forSchema(schema) {
26
+ return makeSchemaStore(this, schema);
27
+ },
28
+ ...impl
29
+ });
30
+ /** @internal */
31
+ export const prefix = /*#__PURE__*/dual(2, (self, prefix) => ({
32
+ ...self,
33
+ get: key => self.get(`${prefix}${key}`),
34
+ set: (key, value) => self.set(`${prefix}${key}`, value),
35
+ remove: key => self.remove(`${prefix}${key}`),
36
+ has: key => self.has(`${prefix}${key}`),
37
+ modify: (key, f) => self.modify(`${prefix}${key}`, f)
38
+ }));
39
+ /** @internal */
40
+ export const SchemaStoreTypeId = /*#__PURE__*/Symbol.for("@effect/platform/KeyValueStore/SchemaStore");
41
+ /** @internal */
42
+ const makeSchemaStore = (store, schema) => {
43
+ const jsonSchema = Schema.compose(Schema.ParseJson, schema);
44
+ const parse = Schema.parse(jsonSchema);
45
+ const encode = Schema.encode(jsonSchema);
46
+ const get = key => Effect.flatMap(store.get(key), Option.match({
47
+ onNone: () => Effect.succeedNone,
48
+ onSome: value => Effect.asSome(parse(value))
49
+ }));
50
+ const set = (key, value) => Effect.flatMap(encode(value), json => store.set(key, json));
51
+ const modify = (key, f) => Effect.flatMap(get(key), o => {
52
+ if (Option.isNone(o)) {
53
+ return Effect.succeedNone;
54
+ }
55
+ const newValue = f(o.value);
56
+ return Effect.as(set(key, newValue), Option.some(newValue));
57
+ });
58
+ return {
59
+ [SchemaStoreTypeId]: SchemaStoreTypeId,
60
+ get,
61
+ set,
62
+ modify,
63
+ remove: store.remove,
64
+ clear: store.clear,
65
+ size: store.size,
66
+ has: store.has,
67
+ isEmpty: store.isEmpty
68
+ };
69
+ };
70
+ /** @internal */
71
+ export const layerMemory = /*#__PURE__*/Layer.sync(keyValueStoreTag, () => {
72
+ const store = new Map();
73
+ return make({
74
+ get: key => Effect.sync(() => Option.fromNullable(store.get(key))),
75
+ set: (key, value) => Effect.sync(() => store.set(key, value)),
76
+ remove: key => Effect.sync(() => store.delete(key)),
77
+ clear: Effect.sync(() => store.clear()),
78
+ size: Effect.sync(() => store.size)
79
+ });
80
+ });
81
+ /** @internal */
82
+ export const layerFileSystem = directory => Layer.effect(keyValueStoreTag, Effect.gen(function* (_) {
83
+ const fs = yield* _(FileSystem.FileSystem);
84
+ const path = yield* _(Path.Path);
85
+ const keyPath = key => path.join(directory, encodeURIComponent(key));
86
+ if (!(yield* _(fs.exists(directory)))) {
87
+ yield* _(fs.makeDirectory(directory, {
88
+ recursive: true
89
+ }));
90
+ }
91
+ return make({
92
+ get: key => Effect.catchTag("SystemError", sysError => sysError.reason === "NotFound" ? Effect.succeed(Option.none()) : Effect.fail(sysError))(Effect.map(fs.readFileString(keyPath(key)), Option.some)),
93
+ set: (key, value) => fs.writeFileString(keyPath(key), value),
94
+ remove: key => fs.remove(keyPath(key)),
95
+ has: key => fs.exists(keyPath(key)),
96
+ clear: Effect.zipRight(fs.remove(directory, {
97
+ recursive: true
98
+ }), fs.makeDirectory(directory, {
99
+ recursive: true
100
+ })),
101
+ size: Effect.map(fs.readDirectory(directory), files => files.length)
102
+ });
103
+ }));
104
+ /** @internal */
105
+ export const layerSchema = (schema, tagIdentifier) => {
106
+ const tag = Context.Tag(tagIdentifier);
107
+ const layer = Layer.effect(tag, Effect.map(keyValueStoreTag, store => store.forSchema(schema)));
108
+ return {
109
+ tag,
110
+ layer
111
+ };
112
+ };
113
+ //# sourceMappingURL=keyValueStore.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyValueStore.mjs","names":["Context","dual","Option","Effect","Layer","FileSystem","Path","Schema","TypeId","Symbol","for","keyValueStoreTag","Tag","make","impl","of","has","key","map","get","isSome","isEmpty","size","modify","f","flatMap","o","isNone","succeedNone","newValue","value","as","set","some","forSchema","schema","makeSchemaStore","prefix","self","remove","SchemaStoreTypeId","store","jsonSchema","compose","ParseJson","parse","encode","match","onNone","onSome","asSome","json","clear","layerMemory","sync","Map","fromNullable","delete","layerFileSystem","directory","effect","gen","_","fs","path","keyPath","join","encodeURIComponent","exists","makeDirectory","recursive","catchTag","sysError","reason","succeed","none","fail","readFileString","writeFileString","zipRight","readDirectory","files","length","layerSchema","tagIdentifier","tag","layer"],"sources":["../../src/internal/keyValueStore.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,OAAO,MAAM,sBAAsB;AAC/C,SAASC,IAAI,QAAc,uBAAuB;AAClD,OAAO,KAAKC,MAAM,MAAM,qBAAqB;AAC7C,OAAO,KAAKC,MAAM,MAAM,mBAAmB;AAC3C,OAAO,KAAKC,KAAK,MAAM,kBAAkB;AACzC,OAAO,KAAKC,UAAU,MAAM,6BAA6B;AAEzD,OAAO,KAAKC,IAAI,MAAM,uBAAuB;AAC7C,OAAO,KAAKC,MAAM,MAAM,uBAAuB;AAE/C;AACA,OAAO,MAAMC,MAAM,gBAAyBC,MAAM,CAACC,GAAG,CACpD,gCAAgC,CACT;AAEzB;AACA,OAAO,MAAMC,gBAAgB,gBAAGX,OAAO,CAACY,GAAG,CAA8BJ,MAAM,CAAC;AAEhF;AACA,OAAO,MAAMK,IAAI,GAImBC,IAAI,IACtCH,gBAAgB,CAACI,EAAE,CAAC;EAClB,CAACP,MAAM,GAAGA,MAAM;EAChBQ,GAAG,EAAGC,GAAG,IAAKd,MAAM,CAACe,GAAG,CAACJ,IAAI,CAACK,GAAG,CAACF,GAAG,CAAC,EAAEf,MAAM,CAACkB,MAAM,CAAC;EACtDC,OAAO,EAAElB,MAAM,CAACe,GAAG,CAACJ,IAAI,CAACQ,IAAI,EAAGA,IAAI,IAAKA,IAAI,KAAK,CAAC,CAAC;EACpD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AAM,CAAC4E,QAAQ,CACpBhB,EAAE,CAACxB,MAAM,CAACoB,SAAS,EAAE;MAAEW,SAAS,EAAE;IAAI,CAAE,CAAC,EACzCP,EAAE,CAACM,aAAa,CAACV,SAAS,EAAE;MAAEW,SAAS,EAAE;IAAI,CAAE,CAAC,CACjD;IACDhD,IAAI,EAAEnB,MAAM,CAACe,GAAG,CACd6C,EAAE,CAACiB,aAAa,CAACrB,SAAS,CAAC,EAC1BsB,KAAK,IAAKA,KAAK,CAACC,MAAM;GAE1B,CAAC;AACJ,CAAC,CAAC,CACH;AAEH;AACA,OAAO,MAAMC,WAAW,GAAGA,CACzBhD,MAA2B,EAC3BiD,aAAuB,KACrB;EACF,MAAMC,GAAG,GAAGrF,OAAO,CAACY,GAAG,CAA+BwE,aAAa,CAAC;EACpE,MAAME,KAAK,GAAGlF,KAAK,CAACwD,MAAM,CAACyB,GAAG,EAAElF,MAAM,CAACe,GAAG,CAACP,gBAAgB,EAAG8B,KAAK,IAAKA,KAAK,CAACP,SAAS,CAACC,MAAM,CAAC,CAAC,CAAC;EACjG,OAAO;IAAEkD,GAAG;IAAEC;EAAK,CAAW;AAChC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/platform",
3
- "version": "0.13.13",
3
+ "version": "0.13.14",
4
4
  "description": "Unified interfaces for common platform-specific services",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/Error.ts CHANGED
@@ -33,7 +33,7 @@ export namespace PlatformError {
33
33
  export interface Base extends Data.Case {
34
34
  readonly [PlatformErrorTypeId]: typeof PlatformErrorTypeId
35
35
  readonly _tag: string
36
- readonly module: "Command" | "FileSystem" | "Path"
36
+ readonly module: "Command" | "FileSystem" | "Path" | "KeyValueStore"
37
37
  readonly method: string
38
38
  readonly message: string
39
39
  }
@@ -0,0 +1,207 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import type * as Context from "@effect/data/Context"
5
+ import type * as Option from "@effect/data/Option"
6
+ import type * as Effect from "@effect/io/Effect"
7
+ import type * as Layer from "@effect/io/Layer"
8
+ import type * as PlatformError from "@effect/platform/Error"
9
+ import type * as FileSystem from "@effect/platform/FileSystem"
10
+ import * as internal from "@effect/platform/internal/keyValueStore"
11
+ import type * as Path from "@effect/platform/Path"
12
+ import type * as ParseResult from "@effect/schema/ParseResult"
13
+ import type * as Schema from "@effect/schema/Schema"
14
+
15
+ /**
16
+ * @since 1.0.0
17
+ * @category type id
18
+ */
19
+ export const TypeId: unique symbol = internal.TypeId
20
+
21
+ /**
22
+ * @since 1.0.0
23
+ * @category type id
24
+ */
25
+ export type TypeId = typeof TypeId
26
+
27
+ /**
28
+ * @since 1.0.0
29
+ * @category models
30
+ */
31
+ export interface KeyValueStore {
32
+ readonly [TypeId]: TypeId
33
+ /**
34
+ * Returns the value of the specified key if it exists.
35
+ */
36
+ readonly get: (key: string) => Effect.Effect<never, PlatformError.PlatformError, Option.Option<string>>
37
+
38
+ /**
39
+ * Sets the value of the specified key.
40
+ */
41
+ readonly set: (key: string, value: string) => Effect.Effect<never, PlatformError.PlatformError, void>
42
+
43
+ /**
44
+ * Removes the specified key.
45
+ */
46
+ readonly remove: (key: string) => Effect.Effect<never, PlatformError.PlatformError, void>
47
+
48
+ /**
49
+ * Removes all entries.
50
+ */
51
+ readonly clear: Effect.Effect<never, PlatformError.PlatformError, void>
52
+
53
+ /**
54
+ * Returns the number of entries.
55
+ */
56
+ readonly size: Effect.Effect<never, PlatformError.PlatformError, number>
57
+
58
+ /**
59
+ * Updates the value of the specified key if it exists.
60
+ */
61
+ readonly modify: (
62
+ key: string,
63
+ f: (value: string) => string
64
+ ) => Effect.Effect<never, PlatformError.PlatformError, Option.Option<string>>
65
+
66
+ /**
67
+ * Returns true if the KeyValueStore contains the specified key.
68
+ */
69
+ readonly has: (key: string) => Effect.Effect<never, PlatformError.PlatformError, boolean>
70
+
71
+ /**
72
+ * Checks if the KeyValueStore contains any entries.
73
+ */
74
+ readonly isEmpty: Effect.Effect<never, PlatformError.PlatformError, boolean>
75
+
76
+ /**
77
+ * Create a SchemaStore for the specified schema.
78
+ */
79
+ readonly forSchema: <I, A>(schema: Schema.Schema<I, A>) => SchemaStore<A>
80
+ }
81
+
82
+ /**
83
+ * @since 1.0.0
84
+ */
85
+ export namespace KeyValueStore {
86
+ /**
87
+ * @since 1.0.0
88
+ */
89
+ export type AnyStore = KeyValueStore | SchemaStore<any>
90
+ }
91
+
92
+ /**
93
+ * @since 1.0.0
94
+ * @category tags
95
+ */
96
+ export const KeyValueStore: Context.Tag<KeyValueStore, KeyValueStore> = internal.keyValueStoreTag
97
+
98
+ /**
99
+ * @since 1.0.0
100
+ * @category constructors
101
+ */
102
+ export const make: (
103
+ impl: Omit<KeyValueStore, typeof TypeId | "has" | "modify" | "isEmpty" | "forSchema"> & Partial<KeyValueStore>
104
+ ) => KeyValueStore = internal.make
105
+
106
+ /**
107
+ * @since 1.0.0
108
+ * @category combinators
109
+ */
110
+ export const prefix: {
111
+ (prefix: string): <S extends KeyValueStore.AnyStore>(self: S) => S
112
+ <S extends KeyValueStore.AnyStore>(self: S, prefix: string): S
113
+ } = internal.prefix
114
+
115
+ /**
116
+ * @since 1.0.0
117
+ * @category layers
118
+ */
119
+ export const layerMemory: Layer.Layer<never, never, KeyValueStore> = internal.layerMemory
120
+
121
+ /**
122
+ * @since 1.0.0
123
+ * @category layers
124
+ */
125
+ export const layerFileSystem: (
126
+ directory: string
127
+ ) => Layer.Layer<FileSystem.FileSystem | Path.Path, PlatformError.PlatformError, KeyValueStore> =
128
+ internal.layerFileSystem
129
+
130
+ /**
131
+ * @since 1.0.0
132
+ * @category type id
133
+ */
134
+ export const SchemaStoreTypeId: unique symbol = internal.SchemaStoreTypeId
135
+
136
+ /**
137
+ * @since 1.0.0
138
+ * @category type id
139
+ */
140
+ export type SchemaStoreTypeId = typeof SchemaStoreTypeId
141
+
142
+ /**
143
+ * @since 1.0.0
144
+ * @category models
145
+ */
146
+ export interface SchemaStore<A> {
147
+ readonly [SchemaStoreTypeId]: SchemaStoreTypeId
148
+ /**
149
+ * Returns the value of the specified key if it exists.
150
+ */
151
+ readonly get: (
152
+ key: string
153
+ ) => Effect.Effect<never, PlatformError.PlatformError | ParseResult.ParseError, Option.Option<A>>
154
+
155
+ /**
156
+ * Sets the value of the specified key.
157
+ */
158
+ readonly set: (
159
+ key: string,
160
+ value: A
161
+ ) => Effect.Effect<never, PlatformError.PlatformError | ParseResult.ParseError, void>
162
+
163
+ /**
164
+ * Removes the specified key.
165
+ */
166
+ readonly remove: (key: string) => Effect.Effect<never, PlatformError.PlatformError, void>
167
+
168
+ /**
169
+ * Removes all entries.
170
+ */
171
+ readonly clear: Effect.Effect<never, PlatformError.PlatformError, void>
172
+
173
+ /**
174
+ * Returns the number of entries.
175
+ */
176
+ readonly size: Effect.Effect<never, PlatformError.PlatformError, number>
177
+
178
+ /**
179
+ * Updates the value of the specified key if it exists.
180
+ */
181
+ readonly modify: (
182
+ key: string,
183
+ f: (value: A) => A
184
+ ) => Effect.Effect<never, PlatformError.PlatformError | ParseResult.ParseError, Option.Option<A>>
185
+
186
+ /**
187
+ * Returns true if the KeyValueStore contains the specified key.
188
+ */
189
+ readonly has: (key: string) => Effect.Effect<never, PlatformError.PlatformError, boolean>
190
+
191
+ /**
192
+ * Checks if the KeyValueStore contains any entries.
193
+ */
194
+ readonly isEmpty: Effect.Effect<never, PlatformError.PlatformError, boolean>
195
+ }
196
+
197
+ /**
198
+ * @since 1.0.0
199
+ * @category layers
200
+ */
201
+ export const layerSchema: <I, A>(
202
+ schema: Schema.Schema<I, A>,
203
+ tagIdentifier?: unknown
204
+ ) => {
205
+ readonly tag: Context.Tag<SchemaStore<A>, SchemaStore<A>>
206
+ readonly layer: Layer.Layer<KeyValueStore, never, SchemaStore<A>>
207
+ } = internal.layerSchema
@@ -0,0 +1,176 @@
1
+ import * as Context from "@effect/data/Context"
2
+ import { dual, pipe } from "@effect/data/Function"
3
+ import * as Option from "@effect/data/Option"
4
+ import * as Effect from "@effect/io/Effect"
5
+ import * as Layer from "@effect/io/Layer"
6
+ import * as FileSystem from "@effect/platform/FileSystem"
7
+ import type * as KeyValueStore from "@effect/platform/KeyValueStore"
8
+ import * as Path from "@effect/platform/Path"
9
+ import * as Schema from "@effect/schema/Schema"
10
+
11
+ /** @internal */
12
+ export const TypeId: KeyValueStore.TypeId = Symbol.for(
13
+ "@effect/platform/KeyValueStore"
14
+ ) as KeyValueStore.TypeId
15
+
16
+ /** @internal */
17
+ export const keyValueStoreTag = Context.Tag<KeyValueStore.KeyValueStore>(TypeId)
18
+
19
+ /** @internal */
20
+ export const make: (
21
+ impl:
22
+ & Omit<KeyValueStore.KeyValueStore, KeyValueStore.TypeId | "has" | "modify" | "isEmpty" | "forSchema">
23
+ & Partial<KeyValueStore.KeyValueStore>
24
+ ) => KeyValueStore.KeyValueStore = (impl) =>
25
+ keyValueStoreTag.of({
26
+ [TypeId]: TypeId,
27
+ has: (key) => Effect.map(impl.get(key), Option.isSome),
28
+ isEmpty: Effect.map(impl.size, (size) => size === 0),
29
+ modify: (key, f) =>
30
+ Effect.flatMap(
31
+ impl.get(key),
32
+ (o) => {
33
+ if (Option.isNone(o)) {
34
+ return Effect.succeedNone
35
+ }
36
+ const newValue = f(o.value)
37
+ return Effect.as(
38
+ impl.set(key, newValue),
39
+ Option.some(newValue)
40
+ )
41
+ }
42
+ ),
43
+ forSchema(schema) {
44
+ return makeSchemaStore(this, schema)
45
+ },
46
+ ...impl
47
+ })
48
+
49
+ /** @internal */
50
+ export const prefix = dual<
51
+ (prefix: string) => <S extends KeyValueStore.KeyValueStore.AnyStore>(self: S) => S,
52
+ <S extends KeyValueStore.KeyValueStore.AnyStore>(self: S, prefix: string) => S
53
+ >(
54
+ 2,
55
+ ((self: KeyValueStore.KeyValueStore, prefix: string): KeyValueStore.KeyValueStore => ({
56
+ ...self,
57
+ get: (key) => self.get(`${prefix}${key}`),
58
+ set: (key, value) => self.set(`${prefix}${key}`, value),
59
+ remove: (key) => self.remove(`${prefix}${key}`),
60
+ has: (key) => self.has(`${prefix}${key}`),
61
+ modify: (key, f) => self.modify(`${prefix}${key}`, f)
62
+ })) as any
63
+ )
64
+
65
+ /** @internal */
66
+ export const SchemaStoreTypeId: KeyValueStore.SchemaStoreTypeId = Symbol.for(
67
+ "@effect/platform/KeyValueStore/SchemaStore"
68
+ ) as KeyValueStore.SchemaStoreTypeId
69
+
70
+ /** @internal */
71
+ const makeSchemaStore = <I, A>(
72
+ store: KeyValueStore.KeyValueStore,
73
+ schema: Schema.Schema<I, A>
74
+ ): KeyValueStore.SchemaStore<A> => {
75
+ const jsonSchema = Schema.compose(Schema.ParseJson, schema)
76
+ const parse = Schema.parse(jsonSchema)
77
+ const encode = Schema.encode(jsonSchema)
78
+
79
+ const get = (key: string) =>
80
+ Effect.flatMap(
81
+ store.get(key),
82
+ Option.match({
83
+ onNone: () => Effect.succeedNone,
84
+ onSome: (value) => Effect.asSome(parse(value))
85
+ })
86
+ )
87
+
88
+ const set = (key: string, value: A) => Effect.flatMap(encode(value), (json) => store.set(key, json))
89
+
90
+ const modify = (key: string, f: (value: A) => A) =>
91
+ Effect.flatMap(
92
+ get(key),
93
+ (o) => {
94
+ if (Option.isNone(o)) {
95
+ return Effect.succeedNone
96
+ }
97
+ const newValue = f(o.value)
98
+ return Effect.as(
99
+ set(key, newValue),
100
+ Option.some(newValue)
101
+ )
102
+ }
103
+ )
104
+
105
+ return {
106
+ [SchemaStoreTypeId]: SchemaStoreTypeId,
107
+ get,
108
+ set,
109
+ modify,
110
+ remove: store.remove,
111
+ clear: store.clear,
112
+ size: store.size,
113
+ has: store.has,
114
+ isEmpty: store.isEmpty
115
+ }
116
+ }
117
+
118
+ /** @internal */
119
+ export const layerMemory = Layer.sync(keyValueStoreTag, () => {
120
+ const store = new Map<string, string>()
121
+
122
+ return make({
123
+ get: (key: string) => Effect.sync(() => Option.fromNullable(store.get(key))),
124
+ set: (key: string, value: string) => Effect.sync(() => store.set(key, value)),
125
+ remove: (key: string) => Effect.sync(() => store.delete(key)),
126
+ clear: Effect.sync(() => store.clear()),
127
+ size: Effect.sync(() => store.size)
128
+ })
129
+ })
130
+
131
+ /** @internal */
132
+ export const layerFileSystem = (directory: string) =>
133
+ Layer.effect(
134
+ keyValueStoreTag,
135
+ Effect.gen(function*(_) {
136
+ const fs = yield* _(FileSystem.FileSystem)
137
+ const path = yield* _(Path.Path)
138
+ const keyPath = (key: string) => path.join(directory, encodeURIComponent(key))
139
+
140
+ if (!(yield* _(fs.exists(directory)))) {
141
+ yield* _(fs.makeDirectory(directory, { recursive: true }))
142
+ }
143
+
144
+ return make({
145
+ get: (key: string) =>
146
+ pipe(
147
+ Effect.map(fs.readFileString(keyPath(key)), Option.some),
148
+ Effect.catchTag(
149
+ "SystemError",
150
+ (sysError) => sysError.reason === "NotFound" ? Effect.succeed(Option.none()) : Effect.fail(sysError)
151
+ )
152
+ ),
153
+ set: (key: string, value: string) => fs.writeFileString(keyPath(key), value),
154
+ remove: (key: string) => fs.remove(keyPath(key)),
155
+ has: (key: string) => fs.exists(keyPath(key)),
156
+ clear: Effect.zipRight(
157
+ fs.remove(directory, { recursive: true }),
158
+ fs.makeDirectory(directory, { recursive: true })
159
+ ),
160
+ size: Effect.map(
161
+ fs.readDirectory(directory),
162
+ (files) => files.length
163
+ )
164
+ })
165
+ })
166
+ )
167
+
168
+ /** @internal */
169
+ export const layerSchema = <I, A>(
170
+ schema: Schema.Schema<I, A>,
171
+ tagIdentifier?: unknown
172
+ ) => {
173
+ const tag = Context.Tag<KeyValueStore.SchemaStore<A>>(tagIdentifier)
174
+ const layer = Layer.effect(tag, Effect.map(keyValueStoreTag, (store) => store.forSchema(schema)))
175
+ return { tag, layer } as const
176
+ }