@effect/platform 0.13.12 → 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 +1 -1
- package/Error.d.ts.map +1 -1
- package/Http/Body.d.ts +16 -0
- package/Http/Body.d.ts.map +1 -1
- package/Http/Body.js +7 -1
- package/Http/Body.js.map +1 -1
- package/Http/ClientRequest.d.ts +8 -0
- package/Http/ClientRequest.d.ts.map +1 -1
- package/Http/ClientRequest.js +7 -1
- package/Http/ClientRequest.js.map +1 -1
- package/Http/Etag.d.ts +2 -0
- package/Http/Etag.d.ts.map +1 -1
- package/Http/Etag.js.map +1 -1
- package/Http/ServerResponse.d.ts +5 -0
- package/Http/ServerResponse.d.ts.map +1 -1
- package/Http/ServerResponse.js +8 -2
- package/Http/ServerResponse.js.map +1 -1
- package/KeyValueStore.d.ts +160 -0
- package/KeyValueStore.d.ts.map +1 -0
- package/KeyValueStore.js +58 -0
- package/KeyValueStore.js.map +1 -0
- package/internal/http/body.js +6 -1
- package/internal/http/body.js.map +1 -1
- package/internal/http/clientRequest.js +4 -1
- package/internal/http/clientRequest.js.map +1 -1
- package/internal/http/serverResponse.js +12 -1
- package/internal/http/serverResponse.js.map +1 -1
- package/internal/keyValueStore.d.ts +2 -0
- package/internal/keyValueStore.d.ts.map +1 -0
- package/internal/keyValueStore.js +129 -0
- package/internal/keyValueStore.js.map +1 -0
- package/mjs/Http/Body.mjs +5 -0
- package/mjs/Http/Body.mjs.map +1 -1
- package/mjs/Http/ClientRequest.mjs +5 -0
- package/mjs/Http/ClientRequest.mjs.map +1 -1
- package/mjs/Http/Etag.mjs.map +1 -1
- package/mjs/Http/ServerResponse.mjs +5 -0
- package/mjs/Http/ServerResponse.mjs.map +1 -1
- package/mjs/KeyValueStore.mjs +42 -0
- package/mjs/KeyValueStore.mjs.map +1 -0
- package/mjs/internal/http/body.mjs +4 -0
- package/mjs/internal/http/body.mjs.map +1 -1
- package/mjs/internal/http/clientRequest.mjs +2 -0
- package/mjs/internal/http/clientRequest.mjs.map +1 -1
- package/mjs/internal/http/serverResponse.mjs +10 -0
- package/mjs/internal/http/serverResponse.mjs.map +1 -1
- package/mjs/internal/keyValueStore.mjs +113 -0
- package/mjs/internal/keyValueStore.mjs.map +1 -0
- package/package.json +1 -1
- package/src/Error.ts +1 -1
- package/src/Http/Body.ts +18 -0
- package/src/Http/ClientRequest.ts +9 -0
- package/src/Http/Etag.ts +2 -0
- package/src/Http/ServerResponse.ts +9 -0
- package/src/KeyValueStore.ts +207 -0
- package/src/internal/http/body.ts +6 -1
- package/src/internal/http/clientRequest.ts +6 -0
- package/src/internal/http/serverResponse.ts +21 -0
- package/src/internal/keyValueStore.ts +176 -0
|
@@ -74,6 +74,16 @@ export const file = (path, options) => Effect.map(({
|
|
|
74
74
|
info
|
|
75
75
|
}) => Effect.flatMap(Etag.Generator, generator => generator.fromFileInfo(info)))(Effect.bindTo(Effect.flatMap(FileSystem.FileSystem, fs => fs.stat(path)), "info"))));
|
|
76
76
|
/** @internal */
|
|
77
|
+
export const fileWeb = (file, options) => Effect.flatMap(Etag.Generator, generator => Effect.map(generator.fromFileWeb(file), etag => {
|
|
78
|
+
const body = internalBody.fileWeb(file);
|
|
79
|
+
const headers = {
|
|
80
|
+
...(options?.headers ?? {}),
|
|
81
|
+
etag: Etag.toString(etag),
|
|
82
|
+
"last-modified": new Date(file.lastModified).toUTCString()
|
|
83
|
+
};
|
|
84
|
+
return new ServerResponseImpl(options?.status ?? 200, options?.statusText, headers, body);
|
|
85
|
+
}));
|
|
86
|
+
/** @internal */
|
|
77
87
|
export const urlParams = (body, options) => new ServerResponseImpl(options?.status ?? 200, options?.statusText, options?.headers ?? Headers.empty, internalBody.text(UrlParams.toString(UrlParams.fromInput(body)), "application/x-www-form-urlencoded"));
|
|
78
88
|
/** @internal */
|
|
79
89
|
export const raw = (body, options) => new ServerResponseImpl(options?.status ?? 200, options?.statusText, options?.headers ?? Headers.empty, internalBody.raw(body));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverResponse.mjs","names":["dual","pipeArguments","Effect","FileSystem","Etag","Headers","UrlParams","internalBody","Mime","TypeId","Symbol","for","ServerResponseImpl","constructor","status","statusText","headers","body","contentType","contentLength","newHeaders","toString","pipe","arguments","isServerResponse","u","empty","options","uint8Array","getContentType","text","json","map","unsafeJson","schemaJson","schema","encode","jsonSchema","file","path","etag","info","mtime","_tag","value","toUTCString","bind","fileInfo","getType","undefined","flatMap","Generator","generator","fromFileInfo","bindTo","fs","stat","urlParams","fromInput","raw","formData","stream","setHeader","self","key","set","setHeaders","input","setAll","setStatus","args","setBody","remove"],"sources":["../../../src/internal/http/serverResponse.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,IAAI,QAAc,uBAAuB;AAClD,SAASC,aAAa,QAAQ,uBAAuB;AACrD,OAAO,KAAKC,MAAM,MAAM,mBAAmB;AAE3C,OAAO,KAAKC,UAAU,MAAM,6BAA6B;AAEzD,OAAO,KAAKC,IAAI,MAAM,4BAA4B;AAClD,OAAO,KAAKC,OAAO,MAAM,+BAA+B;AAExD,OAAO,KAAKC,SAAS,MAAM,iCAAiC;AAC5D,OAAO,KAAKC,YAAY,MAAM,qCAAqC;AAGnE,OAAO,KAAKC,IAAI,MAAM,MAAM;AAE5B;AACA,OAAO,MAAMC,MAAM,gBAA0BC,MAAM,CAACC,GAAG,CAAC,sCAAsC,CAA0B;AAExH,MAAMC,kBAAkB;EAGtBC,YACWC,MAAc,EACdC,UAA8B,EACvCC,OAAwB,EACfC,IAAe;IAHf,KAAAH,MAAM,GAANA,MAAM;IACN,KAAAC,UAAU,GAAVA,UAAU;IAEV,KAAAE,IAAI,GAAJA,IAAI;IAEb,IAAI,CAACR,MAAM,CAAC,GAAGA,MAAM;IACrB,IAAIQ,IAAI,CAACC,WAAW,IAAID,IAAI,CAACE,aAAa,EAAE;MAC1C,MAAMC,UAAU,GAAG;QAAE,GAAGJ;MAAO,CAAE;MAC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EAClC,MAAMzB,OAAO,GAA2B;IACtC,IAAIW,OAAO,EAAEX,OAAO,IAAI,EAAE,CAAC;IAC3BwB,IAAI,EAAEpC,IAAI,CAACiB,QAAQ,CAACmB,IAAI;GACzB;EACD,IAAIC,IAAI,CAACC,KAAK,CAACC,IAAI,KAAK,MAAM,EAAE;IAC9B3B,OAAO,CAAC,eAAe,CAAC,GAAGyB,IAAI,CAACC,KAAK,CAACE,KAAK,CAACC,WAAW,EAAE;;EAE3D,OAAO,IAAIjC,kBAAkB,CAC3Be,OAAO,EAAEb,MAAM,IAAI,GAAG,EACtBa,OAAO,EAAEZ,UAAU,EACnBC,OAAO,EACPC,IAAI,CACL;AACH,CAAC,CAAC,CAnBFf,MAAM,CAAC4C,IAAI,CAAC,MAAM,EAAE,CAAC;EAAEL;AAAI,CAAE,KAC3BlC,YAAY,CAACwC,QAAQ,CAACR,IAAI,EAAEE,IAAI,EAAE;EAChCvB,WAAW,EAAEV,IAAI,CAACwC,OAAO,CAACT,IAAI,CAAC,IAAIU,SAAS;EAC5C,GAAGtB;CACJ,CAAC,CAAC,CATLzB,MAAM,CAAC4C,IAAI,CAAC,MAAM,EAAE,CAAC;EAAEL;AAAI,CAAE,KAC3BvC,MAAM,CAACgD,OAAO,CACZ9C,IAAI,CAAC+C,SAAS,EACbC,SAAS,IAAKA,SAAS,CAACC,YAAY,CAACZ,IAAI,CAAC,CAC5C,CAAC,CALJvC,MAAM,CAACoD,MAAM,CAACpD,MAAM,CAACgD,OAAO,CAAC/C,UAAU,CAACA,UAAU,EAAGoD,EAAE,IAAKA,EAAE,CAACC,IAAI,CAACjB,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,GA0BpF;AAEH;AACA,OAAO,MAAMkB,SAAS,GAAGA,
|
|
1
|
+
{"version":3,"file":"serverResponse.mjs","names":["dual","pipeArguments","Effect","FileSystem","Etag","Headers","UrlParams","internalBody","Mime","TypeId","Symbol","for","ServerResponseImpl","constructor","status","statusText","headers","body","contentType","contentLength","newHeaders","toString","pipe","arguments","isServerResponse","u","empty","options","uint8Array","getContentType","text","json","map","unsafeJson","schemaJson","schema","encode","jsonSchema","file","path","etag","info","mtime","_tag","value","toUTCString","bind","fileInfo","getType","undefined","flatMap","Generator","generator","fromFileInfo","bindTo","fs","stat","fileWeb","fromFileWeb","Date","lastModified","urlParams","fromInput","raw","formData","stream","setHeader","self","key","set","setHeaders","input","setAll","setStatus","args","setBody","remove"],"sources":["../../../src/internal/http/serverResponse.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,IAAI,QAAc,uBAAuB;AAClD,SAASC,aAAa,QAAQ,uBAAuB;AACrD,OAAO,KAAKC,MAAM,MAAM,mBAAmB;AAE3C,OAAO,KAAKC,UAAU,MAAM,6BAA6B;AAEzD,OAAO,KAAKC,IAAI,MAAM,4BAA4B;AAClD,OAAO,KAAKC,OAAO,MAAM,+BAA+B;AAExD,OAAO,KAAKC,SAAS,MAAM,iCAAiC;AAC5D,OAAO,KAAKC,YAAY,MAAM,qCAAqC;AAGnE,OAAO,KAAKC,IAAI,MAAM,MAAM;AAE5B;AACA,OAAO,MAAMC,MAAM,gBAA0BC,MAAM,CAACC,GAAG,CAAC,sCAAsC,CAA0B;AAExH,MAAMC,kBAAkB;EAGtBC,YACWC,MAAc,EACdC,UAA8B,EACvCC,OAAwB,EACfC,IAAe;IAHf,KAAAH,MAAM,GAANA,MAAM;IACN,KAAAC,UAAU,GAAVA,UAAU;IAEV,KAAAE,IAAI,GAAJA,IAAI;IAEb,IAAI,CAACR,MAAM,CAAC,GAAGA,MAAM;IACrB,IAAIQ,IAAI,CAACC,WAAW,IAAID,IAAI,CAACE,aAAa,EAAE;MAC1C,MAAMC,UAAU,GAAG;QAAE,GAAGJ;MAAO,CAAE;MACjC,IAAIC,IAAI,CAACC,WAAW,EAAE;QACpBE,UAAU,CAAC,cAAc,CAAC,GAAGH,IAAI,CAACC,WAAW;;MAE/C,IAAID,IAAI,CAACE,aAAa,EAAE;QACtBC,UAAU,C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C,CAAC,CAAC,CAAC,EAAE,CAACP,IAAI,EAAErD,MAAM,EAAEC,UAAU,KAC9D,IAAIH,kBAAkB,CACpBE,MAAM,EACNC,UAAU,EACVoD,IAAI,CAACnD,OAAO,EACZmD,IAAI,CAAClD,IAAI,CACV,CAAC;AAEJ;AACA,OAAO,MAAM0D,OAAO,gBAAG3E,IAAI,CAGzB,CAAC,EAAE,CAACmE,IAAI,EAAElD,IAAI,KAAI;EAClB,IAAID,OAAO,GAAGmD,IAAI,CAACnD,OAAO;EAC1B,IAAIC,IAAI,CAAC0B,IAAI,KAAK,OAAO,EAAE;IACzB3B,OAAO,GAAGX,OAAO,CAACuE,MAAM,CAACvE,OAAO,CAACuE,MAAM,CAAC5D,OAAO,EAAE,cAAc,CAAC,EAAE,gBAAgB,CAAC;;EAErF,OAAO,IAAIJ,kBAAkB,CAC3BuD,IAAI,CAACrD,MAAM,EACXqD,IAAI,CAACpD,UAAU,EACfC,OAAO,EACPC,IAAI,CACL;AACH,CAAC,CAAC"}
|
|
@@ -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;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C,MAAM,CAAC,CAAC,CAAC;EACjG,OAAO;IAAEkD,GAAG;IAAEC;EAAK,CAAW;AAChC,CAAC"}
|
package/package.json
CHANGED
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
|
}
|
package/src/Http/Body.ts
CHANGED
|
@@ -42,6 +42,18 @@ export namespace Body {
|
|
|
42
42
|
readonly contentType?: string
|
|
43
43
|
readonly contentLength?: number
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
* @category models
|
|
49
|
+
*/
|
|
50
|
+
export interface FileLike {
|
|
51
|
+
readonly name: string
|
|
52
|
+
readonly lastModified: number
|
|
53
|
+
readonly size: number
|
|
54
|
+
readonly stream: () => unknown
|
|
55
|
+
readonly type: string
|
|
56
|
+
}
|
|
45
57
|
}
|
|
46
58
|
|
|
47
59
|
/**
|
|
@@ -210,3 +222,9 @@ export const fileInfo: (
|
|
|
210
222
|
info: FileSystem.File.Info,
|
|
211
223
|
options?: FileSystem.StreamOptions & { readonly contentType?: string }
|
|
212
224
|
) => Effect.Effect<FileSystem.FileSystem, PlatformError.PlatformError, Stream> = internal.fileInfo
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @since 1.0.0
|
|
228
|
+
* @category constructors
|
|
229
|
+
*/
|
|
230
|
+
export const fileWeb: (file: Body.FileLike) => Stream = internal.fileWeb
|
|
@@ -357,3 +357,12 @@ export const fileBody: {
|
|
|
357
357
|
options?: FileSystem.StreamOptions & { readonly contentType?: string }
|
|
358
358
|
): Effect.Effect<FileSystem.FileSystem, PlatformError.PlatformError, ClientRequest>
|
|
359
359
|
} = internal.fileBody
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* @since 1.0.0
|
|
363
|
+
* @category combinators
|
|
364
|
+
*/
|
|
365
|
+
export const fileWebBody: {
|
|
366
|
+
(file: Body.Body.FileLike): (self: ClientRequest) => ClientRequest
|
|
367
|
+
(self: ClientRequest, file: Body.Body.FileLike): ClientRequest
|
|
368
|
+
} = internal.fileWebBody
|
package/src/Http/Etag.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import type * as Context from "@effect/data/Context"
|
|
5
5
|
import type * as Effect from "@effect/io/Effect"
|
|
6
6
|
import type * as FileSystem from "@effect/platform/FileSystem"
|
|
7
|
+
import type * as Body from "@effect/platform/Http/Body"
|
|
7
8
|
import * as internal from "@effect/platform/internal/http/etag"
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -55,6 +56,7 @@ export type GeneratorTypeId = typeof GeneratorTypeId
|
|
|
55
56
|
export interface Generator {
|
|
56
57
|
readonly [GeneratorTypeId]: GeneratorTypeId
|
|
57
58
|
readonly fromFileInfo: (info: FileSystem.File.Info) => Effect.Effect<never, never, Etag>
|
|
59
|
+
readonly fromFileWeb: (file: Body.Body.FileLike) => Effect.Effect<never, never, Etag>
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
/**
|
|
@@ -147,6 +147,15 @@ export const file: (
|
|
|
147
147
|
options?: Options & FileSystem.StreamOptions
|
|
148
148
|
) => Effect.Effect<FileSystem.FileSystem | Etag.Generator, PlatformError.PlatformError, ServerResponse> = internal.file
|
|
149
149
|
|
|
150
|
+
/**
|
|
151
|
+
* @since 1.0.0
|
|
152
|
+
* @category constructors
|
|
153
|
+
*/
|
|
154
|
+
export const fileWeb: (
|
|
155
|
+
file: Body.Body.FileLike,
|
|
156
|
+
options?: Options.WithContent
|
|
157
|
+
) => Effect.Effect<Etag.Generator, never, ServerResponse> = internal.fileWeb
|
|
158
|
+
|
|
150
159
|
/**
|
|
151
160
|
* @since 1.0.0
|
|
152
161
|
* @category combinators
|
|
@@ -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
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as Data from "@effect/data/Data"
|
|
2
|
+
import { identity } from "@effect/data/Function"
|
|
2
3
|
import * as Effect from "@effect/io/Effect"
|
|
3
4
|
import type * as PlatformError from "@effect/platform/Error"
|
|
4
5
|
import * as FileSystem from "@effect/platform/FileSystem"
|
|
5
6
|
import type * as Body from "@effect/platform/Http/Body"
|
|
6
7
|
import * as Schema from "@effect/schema/Schema"
|
|
7
|
-
import
|
|
8
|
+
import * as Stream_ from "@effect/stream/Stream"
|
|
8
9
|
|
|
9
10
|
/** @internal */
|
|
10
11
|
export const TypeId: Body.TypeId = Symbol.for(
|
|
@@ -124,6 +125,10 @@ export const fileInfo = (
|
|
|
124
125
|
)
|
|
125
126
|
)
|
|
126
127
|
|
|
128
|
+
/** @internal */
|
|
129
|
+
export const fileWeb = (file: Body.Body.FileLike): Body.Stream =>
|
|
130
|
+
stream(Stream_.fromReadableStream(() => file.stream() as ReadableStream<Uint8Array>, identity), file.type, file.size)
|
|
131
|
+
|
|
127
132
|
class FormDataImpl implements Body.FormData {
|
|
128
133
|
readonly [TypeId]: Body.TypeId
|
|
129
134
|
readonly _tag = "FormData"
|
|
@@ -356,6 +356,12 @@ export const fileBody = dual<
|
|
|
356
356
|
(self, path, options) => Effect.map(internalBody.file(path, options), (body) => setBody(self, body))
|
|
357
357
|
)
|
|
358
358
|
|
|
359
|
+
/** @internal */
|
|
360
|
+
export const fileWebBody = dual<
|
|
361
|
+
(file: Body.Body.FileLike) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest,
|
|
362
|
+
(self: ClientRequest.ClientRequest, file: Body.Body.FileLike) => ClientRequest.ClientRequest
|
|
363
|
+
>(2, (self, file) => setBody(self, internalBody.fileWeb(file)))
|
|
364
|
+
|
|
359
365
|
/** @internal */
|
|
360
366
|
export const schemaBody = <I, A>(schema: Schema.Schema<I, A>): {
|
|
361
367
|
(body: A): (self: ClientRequest.ClientRequest) => Effect.Effect<never, Body.BodyError, ClientRequest.ClientRequest>
|
|
@@ -159,6 +159,27 @@ export const file = (
|
|
|
159
159
|
})
|
|
160
160
|
)
|
|
161
161
|
|
|
162
|
+
/** @internal */
|
|
163
|
+
export const fileWeb = (
|
|
164
|
+
file: Body.Body.FileLike,
|
|
165
|
+
options?: ServerResponse.Options.WithContent
|
|
166
|
+
): Effect.Effect<Etag.Generator, never, ServerResponse.ServerResponse> =>
|
|
167
|
+
Effect.flatMap(Etag.Generator, (generator) =>
|
|
168
|
+
Effect.map(generator.fromFileWeb(file), (etag) => {
|
|
169
|
+
const body = internalBody.fileWeb(file)
|
|
170
|
+
const headers: Record<string, string> = {
|
|
171
|
+
...(options?.headers ?? {}),
|
|
172
|
+
etag: Etag.toString(etag),
|
|
173
|
+
"last-modified": new Date(file.lastModified).toUTCString()
|
|
174
|
+
}
|
|
175
|
+
return new ServerResponseImpl(
|
|
176
|
+
options?.status ?? 200,
|
|
177
|
+
options?.statusText,
|
|
178
|
+
headers,
|
|
179
|
+
body
|
|
180
|
+
)
|
|
181
|
+
}))
|
|
182
|
+
|
|
162
183
|
/** @internal */
|
|
163
184
|
export const urlParams = (
|
|
164
185
|
body: UrlParams.Input,
|