effect 4.0.0-beta.35 → 4.0.0-beta.36
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/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +9 -7
- package/dist/Channel.js.map +1 -1
- package/dist/Cron.d.ts +7 -0
- package/dist/Cron.d.ts.map +1 -1
- package/dist/Cron.js +109 -45
- package/dist/Cron.js.map +1 -1
- package/dist/Equivalence.d.ts +52 -0
- package/dist/Equivalence.d.ts.map +1 -1
- package/dist/Equivalence.js +52 -0
- package/dist/Equivalence.js.map +1 -1
- package/dist/LayerMap.d.ts +5 -4
- package/dist/LayerMap.d.ts.map +1 -1
- package/dist/LayerMap.js.map +1 -1
- package/dist/PubSub.d.ts.map +1 -1
- package/dist/PubSub.js +9 -3
- package/dist/PubSub.js.map +1 -1
- package/dist/Schema.d.ts +29 -5
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +20 -0
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaParser.d.ts +29 -0
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +38 -0
- package/dist/SchemaParser.js.map +1 -1
- package/dist/internal/effect.js +3 -2
- package/dist/internal/effect.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +15 -3
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/cli/Prompt.js +146 -13
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +2 -2
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +15 -13
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js +5 -3
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/package.json +1 -1
- package/src/Channel.ts +12 -10
- package/src/Cron.ts +142 -45
- package/src/Equivalence.ts +56 -0
- package/src/LayerMap.ts +7 -5
- package/src/PubSub.ts +13 -5
- package/src/Schema.ts +32 -8
- package/src/SchemaParser.ts +53 -0
- package/src/internal/effect.ts +3 -2
- package/src/unstable/ai/LanguageModel.ts +17 -2
- package/src/unstable/cli/Prompt.ts +147 -14
- package/src/unstable/httpapi/HttpApiEndpoint.ts +2 -2
- package/src/unstable/httpapi/HttpApiMiddleware.ts +36 -20
|
@@ -22,24 +22,26 @@ declare const SecurityTypeId = "~effect/httpapi/HttpApiMiddleware/Security";
|
|
|
22
22
|
* @category guards
|
|
23
23
|
*/
|
|
24
24
|
export declare const isSecurity: (u: AnyService) => u is AnyServiceSecurity;
|
|
25
|
+
type ErrorConstraint = Schema.Top | ReadonlyArray<Schema.Top>;
|
|
26
|
+
type ErrorSchemaFromConstraint<E> = E extends ReadonlyArray<Schema.Top> ? E[number] : E extends Schema.Top ? E : never;
|
|
25
27
|
/**
|
|
26
28
|
* @since 4.0.0
|
|
27
29
|
* @category models
|
|
28
30
|
*/
|
|
29
|
-
export type HttpApiMiddleware<Provides, E extends
|
|
31
|
+
export type HttpApiMiddleware<Provides, E extends ErrorConstraint, Requires> = (httpEffect: Effect.Effect<HttpServerResponse, unhandled, Provides>, options: {
|
|
30
32
|
readonly endpoint: HttpApiEndpoint.AnyWithProps;
|
|
31
33
|
readonly group: HttpApiGroup.AnyWithProps;
|
|
32
|
-
}) => Effect.Effect<HttpServerResponse, unhandled | E["Type"], Requires | HttpRouter.Provided>;
|
|
34
|
+
}) => Effect.Effect<HttpServerResponse, unhandled | ErrorSchemaFromConstraint<E>["Type"], Requires | HttpRouter.Provided>;
|
|
33
35
|
/**
|
|
34
36
|
* @since 4.0.0
|
|
35
37
|
* @category models
|
|
36
38
|
*/
|
|
37
|
-
export type HttpApiMiddlewareSecurity<Security extends Record<string, HttpApiSecurity.HttpApiSecurity>, Provides, E extends
|
|
39
|
+
export type HttpApiMiddlewareSecurity<Security extends Record<string, HttpApiSecurity.HttpApiSecurity>, Provides, E extends ErrorConstraint, Requires> = {
|
|
38
40
|
readonly [K in keyof Security]: (httpEffect: Effect.Effect<HttpServerResponse, unhandled, Provides>, options: {
|
|
39
41
|
readonly credential: HttpApiSecurity.HttpApiSecurity.Type<Security[K]>;
|
|
40
42
|
readonly endpoint: HttpApiEndpoint.AnyWithProps;
|
|
41
43
|
readonly group: HttpApiGroup.AnyWithProps;
|
|
42
|
-
}) => Effect.Effect<HttpServerResponse, unhandled | E["Type"], Requires | HttpRouter.Provided>;
|
|
44
|
+
}) => Effect.Effect<HttpServerResponse, unhandled | ErrorSchemaFromConstraint<E>["Type"], Requires | HttpRouter.Provided>;
|
|
43
45
|
};
|
|
44
46
|
/**
|
|
45
47
|
* @since 4.0.0
|
|
@@ -68,7 +70,7 @@ export interface ForClient<Id> {
|
|
|
68
70
|
export interface AnyService extends ServiceMap.Key<any, any> {
|
|
69
71
|
readonly [TypeId]: typeof TypeId;
|
|
70
72
|
readonly provides: any;
|
|
71
|
-
readonly error: Schema.Top
|
|
73
|
+
readonly error: ReadonlySet<Schema.Top>;
|
|
72
74
|
readonly requiredForClient: boolean;
|
|
73
75
|
readonly "~ClientError": any;
|
|
74
76
|
}
|
|
@@ -88,7 +90,7 @@ export interface AnyId {
|
|
|
88
90
|
readonly [TypeId]: {
|
|
89
91
|
readonly provides: any;
|
|
90
92
|
readonly requires: any;
|
|
91
|
-
readonly error:
|
|
93
|
+
readonly error: ErrorConstraint;
|
|
92
94
|
readonly clientError: any;
|
|
93
95
|
readonly requiredForClient: boolean;
|
|
94
96
|
};
|
|
@@ -124,7 +126,7 @@ export type ErrorSchema<A> = A extends {
|
|
|
124
126
|
readonly [TypeId]: {
|
|
125
127
|
readonly error: infer E;
|
|
126
128
|
};
|
|
127
|
-
} ? E
|
|
129
|
+
} ? ErrorSchemaFromConstraint<E> : never;
|
|
128
130
|
/**
|
|
129
131
|
* @since 4.0.0
|
|
130
132
|
* @category models
|
|
@@ -166,7 +168,7 @@ export type ErrorServicesDecode<A> = ErrorSchema<A>["DecodingServices"];
|
|
|
166
168
|
export type ServiceClass<Self, Id extends string, Config extends {
|
|
167
169
|
requires: any;
|
|
168
170
|
provides: any;
|
|
169
|
-
error:
|
|
171
|
+
error: ErrorConstraint;
|
|
170
172
|
clientError: any;
|
|
171
173
|
requiredForClient: boolean;
|
|
172
174
|
security: Record<string, HttpApiSecurity.HttpApiSecurity>;
|
|
@@ -181,7 +183,7 @@ export type ServiceClass<Self, Id extends string, Config extends {
|
|
|
181
183
|
};
|
|
182
184
|
};
|
|
183
185
|
readonly [TypeId]: typeof TypeId;
|
|
184
|
-
readonly error:
|
|
186
|
+
readonly error: ReadonlySet<Schema.Top>;
|
|
185
187
|
readonly requiredForClient: Config["requiredForClient"];
|
|
186
188
|
readonly "~ClientError": Config["clientError"];
|
|
187
189
|
} & ([keyof Config["security"]] extends [never] ? {} : {
|
|
@@ -200,7 +202,7 @@ export declare const Service: <Self, Config extends {
|
|
|
200
202
|
requires: never;
|
|
201
203
|
provides: never;
|
|
202
204
|
clientError: never;
|
|
203
|
-
}>() => <const Id extends string, Error extends
|
|
205
|
+
}>() => <const Id extends string, const Error extends ErrorConstraint = never, const Security extends Record<string, HttpApiSecurity.HttpApiSecurity> = never, RequiredForClient extends boolean = false>(id: Id, options?: {
|
|
204
206
|
readonly error?: Error | undefined;
|
|
205
207
|
readonly security?: Security | undefined;
|
|
206
208
|
readonly requiredForClient?: RequiredForClient | undefined;
|
|
@@ -237,14 +239,14 @@ export declare const Service: <Self, Config extends {
|
|
|
237
239
|
* @since 4.0.0
|
|
238
240
|
* @category SchemaError transform
|
|
239
241
|
*/
|
|
240
|
-
export declare const layerSchemaErrorTransform: <Id, E extends
|
|
242
|
+
export declare const layerSchemaErrorTransform: <Id, E extends ErrorConstraint, Requires>(service: ServiceMap.Service<Id, HttpApiMiddleware<never, E, Requires>>, transform: (error: Schema.SchemaError, context: {
|
|
241
243
|
readonly endpoint: HttpApiEndpoint.AnyWithProps;
|
|
242
244
|
readonly group: HttpApiGroup.AnyWithProps;
|
|
243
|
-
}) => Effect.Effect<HttpServerResponse, E["Type"] | Schema.SchemaError, Requires | HttpRouter.Provided>) => Layer.Layer<Id>;
|
|
245
|
+
}) => Effect.Effect<HttpServerResponse, ErrorSchemaFromConstraint<E>["Type"] | Schema.SchemaError, Requires | HttpRouter.Provided>) => Layer.Layer<Id>;
|
|
244
246
|
/**
|
|
245
247
|
* @since 4.0.0
|
|
246
248
|
* @category client
|
|
247
249
|
*/
|
|
248
|
-
export declare const layerClient: <Id extends AnyId, S, R, EX = never, RX = never>(tag: ServiceMap.Key<Id, S>, service: HttpApiMiddlewareClient<Id
|
|
250
|
+
export declare const layerClient: <Id extends AnyId, S, R, EX = never, RX = never>(tag: ServiceMap.Key<Id, S>, service: HttpApiMiddlewareClient<Error<Id>, Id[typeof TypeId]["clientError"], R> | Effect.Effect<HttpApiMiddlewareClient<Error<Id>, Id[typeof TypeId]["clientError"], R>, EX, RX>) => Layer.Layer<ForClient<Id>, EX, R | Exclude<RX, Scope>>;
|
|
249
251
|
export {};
|
|
250
252
|
//# sourceMappingURL=HttpApiMiddleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpApiMiddleware.d.ts","sourceRoot":"","sources":["../../../src/unstable/httpapi/HttpApiMiddleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,iBAAiB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAA;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,KAAK,eAAe,MAAM,4BAA4B,CAAA;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,CAAC,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,KAAK,EACxE,KAAK,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAC1B,SACI,uBAAuB,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,MAAM,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,GACvE,MAAM,CAAC,MAAM,CACb,uBAAuB,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,MAAM,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,EACvE,EAAE,EACF,EAAE,CACH,KACF,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,CAgBnD,CAAA"}
|
|
@@ -32,10 +32,8 @@ export const Service = () => (id, options) => {
|
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
self[TypeId] = TypeId;
|
|
35
|
+
self.error = getError(options?.error);
|
|
35
36
|
self.requiredForClient = options?.requiredForClient ?? false;
|
|
36
|
-
if (options?.error !== undefined) {
|
|
37
|
-
self.error = options.error;
|
|
38
|
-
}
|
|
39
37
|
if (options?.security !== undefined) {
|
|
40
38
|
if (Object.keys(options.security).length === 0) {
|
|
41
39
|
throw new Error("HttpApiMiddleware.Service: security object must not be empty");
|
|
@@ -45,6 +43,10 @@ export const Service = () => (id, options) => {
|
|
|
45
43
|
}
|
|
46
44
|
return self;
|
|
47
45
|
};
|
|
46
|
+
function getError(error) {
|
|
47
|
+
if (error === undefined) return new Set();
|
|
48
|
+
return new Set(Array.isArray(error) ? error : [error]);
|
|
49
|
+
}
|
|
48
50
|
/**
|
|
49
51
|
* Implement a middleware Layer that transforms `SchemaError`'s.
|
|
50
52
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpApiMiddleware.js","names":["Effect","Layer","hasProperty","Schema","Scope","ServiceMap","TypeId","SecurityTypeId","isSecurity","u","Service","id","options","Err","globalThis","Error","limit","stackTraceLimit","creationError","self","Object","defineProperty","get","stack","
|
|
1
|
+
{"version":3,"file":"HttpApiMiddleware.js","names":["Effect","Layer","hasProperty","Schema","Scope","ServiceMap","TypeId","SecurityTypeId","isSecurity","u","Service","id","options","Err","globalThis","Error","limit","stackTraceLimit","creationError","self","Object","defineProperty","get","stack","error","getError","requiredForClient","security","undefined","keys","length","Set","Array","isArray","layerSchemaErrorTransform","service","transform","succeed","httpEffect","catch","e","isSchemaError","fail","layerClient","tag","effectServices","gen","services","pipe","omit","middleware","isEffect","makeUnsafe","Map","key","updateServices","requestContext","merge"],"sources":["../../../src/unstable/httpapi/HttpApiMiddleware.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,MAAM,MAAM,iBAAiB;AACzC,OAAO,KAAKC,KAAK,MAAM,gBAAgB;AACvC,SAASC,WAAW,QAAQ,oBAAoB;AAChD,OAAO,KAAKC,MAAM,MAAM,iBAAiB;AACzC,SAASC,KAAK,QAAQ,gBAAgB;AACtC,OAAO,KAAKC,UAAU,MAAM,qBAAqB;AAWjD,MAAMC,MAAM,GAAG,mCAAmC;AAElD,MAAMC,cAAc,GAAG,4CAA4C;AAEnE;;;;AAIA,OAAO,MAAMC,UAAU,GAAIC,CAAa,IAA8BP,WAAW,CAACO,CAAC,EAAEF,cAAc,CAAC;AAiNpG;;;;AAIA,OAAO,MAAMG,OAAO,GAAGA,CAAA,KA2BvB,CACEC,EAAU,EACVC,OAIa,KACX;EACF,MAAMC,GAAG,GAAGC,UAAU,CAACC,KAAY;EACnC,MAAMC,KAAK,GAAGH,GAAG,CAACI,eAAe;EACjCJ,GAAG,CAACI,eAAe,GAAG,CAAC;EACvB,MAAMC,aAAa,GAAG,IAAIL,GAAG,EAAE;EAC/BA,GAAG,CAACI,eAAe,GAAGD,KAAK;EAE3B,MAAMN,OAAQ,SAAQL,UA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AAO,CAAC,GAAGZ,MAAM,CAAC0C,IAAI,CAACF,CAAC,CAAC,CACtE,CACJ;AAEH;;;;AAIA,OAAO,MAAMG,WAAW,GAAGA,CACzBC,GAA0B,EAC1BT,OAMG,KAEHlC,KAAK,CAAC4C,cAAc,CAAC7C,MAAM,CAAC8C,GAAG,CAAC,aAAS;EACvC,MAAMC,QAAQ,GAAG,CAAC,OAAO/C,MAAM,CAAC+C,QAAQ,EAAa,EAAEC,IAAI,CACzD3C,UAAU,CAAC4C,IAAI,CAAC7C,KAAK,CAAC,CACK;EAC7B,MAAM8C,UAAU,GAAGlD,MAAM,CAACmD,QAAQ,CAAChB,OAAO,CAAC,GAAG,OAAOA,OAAO,GAAGA,OAAO;EACtE,OAAO9B,UAAU,CAAC+C,UAAU,CAC1B,IAAIC,GAAG,CAAC,CAAC,CACP,GAAGT,GAAG,CAACU,GAAG,SAAS,EAClB1C,OAAY,IACXZ,MAAM,CAACuD,cAAc,CACnBL,UAAU,CAACtC,OAAO,CAAC,EAClB4C,cAAc,IAAKnD,UAAU,CAACoD,KAAK,CAACV,QAAQ,EAAES,cAAc,CAAC,CAC/D,CACJ,CAAC,CAAC,CACJ;AACH,CAAC,CAAC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
package/src/Channel.ts
CHANGED
|
@@ -4590,17 +4590,19 @@ export const scanEffect: {
|
|
|
4590
4590
|
Effect.map(toTransform(self)(upstream, scope), (pull) => {
|
|
4591
4591
|
let state = initial
|
|
4592
4592
|
let isFirst = true
|
|
4593
|
-
|
|
4594
|
-
isFirst
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
return Effect.map(
|
|
4598
|
-
Effect.flatMap(pull, (a) => f(state, a)),
|
|
4599
|
-
(newState) => {
|
|
4600
|
-
state = newState
|
|
4601
|
-
return state
|
|
4593
|
+
return Effect.suspend(() => {
|
|
4594
|
+
if (isFirst) {
|
|
4595
|
+
isFirst = false
|
|
4596
|
+
return Effect.succeed(state)
|
|
4602
4597
|
}
|
|
4603
|
-
|
|
4598
|
+
return Effect.map(
|
|
4599
|
+
Effect.flatMap(pull, (a) => f(state, a)),
|
|
4600
|
+
(newState) => {
|
|
4601
|
+
state = newState
|
|
4602
|
+
return state
|
|
4603
|
+
}
|
|
4604
|
+
)
|
|
4605
|
+
})
|
|
4604
4606
|
})
|
|
4605
4607
|
))
|
|
4606
4608
|
|
package/src/Cron.ts
CHANGED
|
@@ -100,6 +100,15 @@ export interface Cron extends Pipeable, Equal.Equal, Inspectable {
|
|
|
100
100
|
readonly weekday: number
|
|
101
101
|
}
|
|
102
102
|
/** @internal */
|
|
103
|
+
readonly last: {
|
|
104
|
+
readonly second: number
|
|
105
|
+
readonly minute: number
|
|
106
|
+
readonly hour: number
|
|
107
|
+
readonly day: number
|
|
108
|
+
readonly month: number
|
|
109
|
+
readonly weekday: number
|
|
110
|
+
}
|
|
111
|
+
/** @internal */
|
|
103
112
|
readonly next: {
|
|
104
113
|
readonly second: ReadonlyArray<number | undefined>
|
|
105
114
|
readonly minute: ReadonlyArray<number | undefined>
|
|
@@ -108,6 +117,15 @@ export interface Cron extends Pipeable, Equal.Equal, Inspectable {
|
|
|
108
117
|
readonly month: ReadonlyArray<number | undefined>
|
|
109
118
|
readonly weekday: ReadonlyArray<number | undefined>
|
|
110
119
|
}
|
|
120
|
+
/** @internal */
|
|
121
|
+
readonly prev: {
|
|
122
|
+
readonly second: ReadonlyArray<number | undefined>
|
|
123
|
+
readonly minute: ReadonlyArray<number | undefined>
|
|
124
|
+
readonly hour: ReadonlyArray<number | undefined>
|
|
125
|
+
readonly day: ReadonlyArray<number | undefined>
|
|
126
|
+
readonly month: ReadonlyArray<number | undefined>
|
|
127
|
+
readonly weekday: ReadonlyArray<number | undefined>
|
|
128
|
+
}
|
|
111
129
|
}
|
|
112
130
|
|
|
113
131
|
function toPojo(cron: Cron): Record<string, unknown> {
|
|
@@ -325,31 +343,64 @@ export const make = (values: {
|
|
|
325
343
|
weekday: weekdays[0] ?? 0
|
|
326
344
|
}
|
|
327
345
|
|
|
346
|
+
o.last = {
|
|
347
|
+
second: seconds[seconds.length - 1] ?? 59,
|
|
348
|
+
minute: minutes[minutes.length - 1] ?? 59,
|
|
349
|
+
hour: hours[hours.length - 1] ?? 23,
|
|
350
|
+
day: days[days.length - 1] ?? 31,
|
|
351
|
+
month: (months[months.length - 1] ?? 12) - 1,
|
|
352
|
+
weekday: weekdays[weekdays.length - 1] ?? 6
|
|
353
|
+
}
|
|
354
|
+
|
|
328
355
|
o.next = {
|
|
329
|
-
second:
|
|
330
|
-
minute:
|
|
331
|
-
hour:
|
|
332
|
-
day:
|
|
333
|
-
month:
|
|
334
|
-
weekday:
|
|
356
|
+
second: lookupTable(seconds, 60, "next"),
|
|
357
|
+
minute: lookupTable(minutes, 60, "next"),
|
|
358
|
+
hour: lookupTable(hours, 24, "next"),
|
|
359
|
+
day: lookupTable(days, 32, "next"),
|
|
360
|
+
month: lookupTable(months, 13, "next"),
|
|
361
|
+
weekday: lookupTable(weekdays, 7, "next")
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
o.prev = {
|
|
365
|
+
second: lookupTable(seconds, 60, "prev"),
|
|
366
|
+
minute: lookupTable(minutes, 60, "prev"),
|
|
367
|
+
hour: lookupTable(hours, 24, "prev"),
|
|
368
|
+
day: lookupTable(days, 32, "prev"),
|
|
369
|
+
month: lookupTable(months, 13, "prev"),
|
|
370
|
+
weekday: lookupTable(weekdays, 7, "prev")
|
|
335
371
|
}
|
|
336
372
|
|
|
337
373
|
return o
|
|
338
374
|
}
|
|
339
375
|
|
|
340
|
-
const
|
|
376
|
+
const lookupTable = (
|
|
377
|
+
values: ReadonlyArray<number>,
|
|
378
|
+
size: number,
|
|
379
|
+
dir: "next" | "prev"
|
|
380
|
+
): Array<number | undefined> => {
|
|
341
381
|
const result = new Array(size).fill(undefined)
|
|
342
382
|
if (values.length === 0) {
|
|
343
383
|
return result
|
|
344
384
|
}
|
|
345
385
|
|
|
346
386
|
let current: number | undefined = undefined
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
387
|
+
|
|
388
|
+
if (dir === "next") {
|
|
389
|
+
let index = values.length - 1
|
|
390
|
+
for (let i = size - 1; i >= 0; i--) {
|
|
391
|
+
while (index >= 0 && values[index] >= i) {
|
|
392
|
+
current = values[index--]
|
|
393
|
+
}
|
|
394
|
+
result[i] = current
|
|
395
|
+
}
|
|
396
|
+
} else {
|
|
397
|
+
let index = 0
|
|
398
|
+
for (let i = 0; i < size; i++) {
|
|
399
|
+
while (index < values.length && values[index] <= i) {
|
|
400
|
+
current = values[index++]
|
|
401
|
+
}
|
|
402
|
+
result[i] = current
|
|
351
403
|
}
|
|
352
|
-
result[i] = current
|
|
353
404
|
}
|
|
354
405
|
|
|
355
406
|
return result
|
|
@@ -587,38 +638,61 @@ const daysInMonth = (date: Date): number =>
|
|
|
587
638
|
* @category utils
|
|
588
639
|
*/
|
|
589
640
|
export const next = (cron: Cron, now?: DateTime.DateTime.Input): Date => {
|
|
641
|
+
return stepCron(cron, now, "next")
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Returns the previous scheduled date/time for the given Cron instance.
|
|
646
|
+
*
|
|
647
|
+
* @since 4.0.0
|
|
648
|
+
* @category utils
|
|
649
|
+
*/
|
|
650
|
+
export const prev = (cron: Cron, now?: DateTime.DateTime.Input): Date => {
|
|
651
|
+
return stepCron(cron, now, "prev")
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const stepCron = (cron: Cron, now: DateTime.DateTime.Input | undefined, direction: "next" | "prev"): Date => {
|
|
590
655
|
const tz = Option.getOrUndefined(cron.tz)
|
|
591
656
|
const zoned = dateTime.makeZonedUnsafe(now ?? new Date(), {
|
|
592
657
|
timeZone: tz
|
|
593
658
|
})
|
|
594
659
|
|
|
660
|
+
const reverse = direction === "prev"
|
|
661
|
+
const tick = reverse ? -1 : 1
|
|
662
|
+
const table = cron[direction]
|
|
663
|
+
const boundary = reverse ? cron.last : cron.first
|
|
664
|
+
|
|
665
|
+
const needsStep = reverse ?
|
|
666
|
+
(next: number, current: number) => next < current :
|
|
667
|
+
(next: number, current: number) => next > current
|
|
668
|
+
|
|
595
669
|
const utc = tz !== undefined && dateTime.isTimeZoneNamed(tz) && tz.id === "UTC"
|
|
596
670
|
const adjustDst = utc ? constVoid : (current: Date) => {
|
|
597
671
|
const adjusted = dateTime.makeZonedUnsafe(current, {
|
|
598
672
|
timeZone: zoned.zone,
|
|
599
|
-
adjustForTimeZone: true
|
|
673
|
+
adjustForTimeZone: true,
|
|
674
|
+
disambiguation: reverse ? "later" : undefined
|
|
600
675
|
}).pipe(dateTime.toDate)
|
|
601
676
|
|
|
602
|
-
// TODO: This implementation currently only skips forward when transitioning into daylight savings time.
|
|
603
677
|
const drift = current.getTime() - adjusted.getTime()
|
|
604
|
-
if (drift > 0) {
|
|
605
|
-
current.setTime(current.getTime() + drift)
|
|
678
|
+
if (reverse ? drift !== 0 : drift > 0) {
|
|
679
|
+
current.setTime(reverse ? adjusted.getTime() : current.getTime() + drift)
|
|
606
680
|
}
|
|
607
681
|
}
|
|
608
682
|
|
|
609
683
|
const result = dateTime.mutate(zoned, (current) => {
|
|
610
|
-
current.setUTCSeconds(current.getUTCSeconds() +
|
|
684
|
+
current.setUTCSeconds(current.getUTCSeconds() + tick, 0)
|
|
611
685
|
|
|
612
686
|
for (let i = 0; i < 10_000; i++) {
|
|
613
687
|
if (cron.seconds.size !== 0) {
|
|
614
688
|
const currentSecond = current.getUTCSeconds()
|
|
615
|
-
const nextSecond =
|
|
689
|
+
const nextSecond = table.second[currentSecond]
|
|
616
690
|
if (nextSecond === undefined) {
|
|
617
|
-
current.setUTCMinutes(current.getUTCMinutes() +
|
|
691
|
+
current.setUTCMinutes(current.getUTCMinutes() + tick, boundary.second)
|
|
618
692
|
adjustDst(current)
|
|
619
693
|
continue
|
|
620
694
|
}
|
|
621
|
-
if (nextSecond
|
|
695
|
+
if (needsStep(nextSecond, currentSecond)) {
|
|
622
696
|
current.setUTCSeconds(nextSecond)
|
|
623
697
|
adjustDst(current)
|
|
624
698
|
continue
|
|
@@ -627,14 +701,14 @@ export const next = (cron: Cron, now?: DateTime.DateTime.Input): Date => {
|
|
|
627
701
|
|
|
628
702
|
if (cron.minutes.size !== 0) {
|
|
629
703
|
const currentMinute = current.getUTCMinutes()
|
|
630
|
-
const nextMinute =
|
|
704
|
+
const nextMinute = table.minute[currentMinute]
|
|
631
705
|
if (nextMinute === undefined) {
|
|
632
|
-
current.setUTCHours(current.getUTCHours() +
|
|
706
|
+
current.setUTCHours(current.getUTCHours() + tick, boundary.minute, boundary.second)
|
|
633
707
|
adjustDst(current)
|
|
634
708
|
continue
|
|
635
709
|
}
|
|
636
|
-
if (nextMinute
|
|
637
|
-
current.setUTCMinutes(nextMinute,
|
|
710
|
+
if (needsStep(nextMinute, currentMinute)) {
|
|
711
|
+
current.setUTCMinutes(nextMinute, boundary.second)
|
|
638
712
|
adjustDst(current)
|
|
639
713
|
continue
|
|
640
714
|
}
|
|
@@ -642,40 +716,55 @@ export const next = (cron: Cron, now?: DateTime.DateTime.Input): Date => {
|
|
|
642
716
|
|
|
643
717
|
if (cron.hours.size !== 0) {
|
|
644
718
|
const currentHour = current.getUTCHours()
|
|
645
|
-
const nextHour =
|
|
719
|
+
const nextHour = table.hour[currentHour]
|
|
646
720
|
if (nextHour === undefined) {
|
|
647
|
-
current.setUTCDate(current.getUTCDate() +
|
|
648
|
-
current.setUTCHours(
|
|
721
|
+
current.setUTCDate(current.getUTCDate() + tick)
|
|
722
|
+
current.setUTCHours(boundary.hour, boundary.minute, boundary.second)
|
|
649
723
|
adjustDst(current)
|
|
650
724
|
continue
|
|
651
725
|
}
|
|
652
|
-
if (nextHour
|
|
653
|
-
current.setUTCHours(nextHour,
|
|
726
|
+
if (needsStep(nextHour, currentHour)) {
|
|
727
|
+
current.setUTCHours(nextHour, boundary.minute, boundary.second)
|
|
654
728
|
adjustDst(current)
|
|
655
729
|
continue
|
|
656
730
|
}
|
|
657
731
|
}
|
|
658
732
|
|
|
659
733
|
if (cron.weekdays.size !== 0 || cron.days.size !== 0) {
|
|
660
|
-
let a: number = Infinity
|
|
661
|
-
let b: number = Infinity
|
|
734
|
+
let a: number = reverse ? -Infinity : Infinity
|
|
735
|
+
let b: number = reverse ? -Infinity : Infinity
|
|
662
736
|
|
|
663
737
|
if (cron.weekdays.size !== 0) {
|
|
664
738
|
const currentWeekday = current.getUTCDay()
|
|
665
|
-
const nextWeekday =
|
|
666
|
-
|
|
739
|
+
const nextWeekday = table.weekday[currentWeekday]
|
|
740
|
+
if (nextWeekday === undefined) {
|
|
741
|
+
a = reverse ?
|
|
742
|
+
currentWeekday - 7 + boundary.weekday :
|
|
743
|
+
7 - currentWeekday + boundary.weekday
|
|
744
|
+
} else {
|
|
745
|
+
a = nextWeekday - currentWeekday
|
|
746
|
+
}
|
|
667
747
|
}
|
|
668
748
|
|
|
669
749
|
if (cron.days.size !== 0 && a !== 0) {
|
|
670
750
|
const currentDay = current.getUTCDate()
|
|
671
|
-
const nextDay =
|
|
672
|
-
|
|
751
|
+
const nextDay = table.day[currentDay]
|
|
752
|
+
if (nextDay === undefined) {
|
|
753
|
+
if (reverse) {
|
|
754
|
+
const prevMonthDays = daysInMonth(new Date(Date.UTC(current.getUTCFullYear(), current.getUTCMonth(), 0)))
|
|
755
|
+
b = -(currentDay + (prevMonthDays - boundary.day))
|
|
756
|
+
} else {
|
|
757
|
+
b = daysInMonth(current) - currentDay + boundary.day
|
|
758
|
+
}
|
|
759
|
+
} else {
|
|
760
|
+
b = nextDay - currentDay
|
|
761
|
+
}
|
|
673
762
|
}
|
|
674
763
|
|
|
675
|
-
const addDays = Math.min(a, b)
|
|
764
|
+
const addDays = reverse ? Math.max(a, b) : Math.min(a, b)
|
|
676
765
|
if (addDays !== 0) {
|
|
677
766
|
current.setUTCDate(current.getUTCDate() + addDays)
|
|
678
|
-
current.setUTCHours(
|
|
767
|
+
current.setUTCHours(boundary.hour, boundary.minute, boundary.second)
|
|
679
768
|
adjustDst(current)
|
|
680
769
|
continue
|
|
681
770
|
}
|
|
@@ -683,17 +772,25 @@ export const next = (cron: Cron, now?: DateTime.DateTime.Input): Date => {
|
|
|
683
772
|
|
|
684
773
|
if (cron.months.size !== 0) {
|
|
685
774
|
const currentMonth = current.getUTCMonth() + 1
|
|
686
|
-
const nextMonth =
|
|
775
|
+
const nextMonth = table.month[currentMonth]
|
|
776
|
+
const clampBoundaryDay = (targetMonthIndex: number): number => {
|
|
777
|
+
if (cron.days.size !== 0) {
|
|
778
|
+
return boundary.day
|
|
779
|
+
}
|
|
780
|
+
const maxDayInMonth = daysInMonth(new Date(Date.UTC(current.getUTCFullYear(), targetMonthIndex + 1, 0)))
|
|
781
|
+
return Math.min(boundary.day, maxDayInMonth)
|
|
782
|
+
}
|
|
687
783
|
if (nextMonth === undefined) {
|
|
688
|
-
current.setUTCFullYear(current.getUTCFullYear() +
|
|
689
|
-
current.setUTCMonth(
|
|
690
|
-
current.setUTCHours(
|
|
784
|
+
current.setUTCFullYear(current.getUTCFullYear() + tick)
|
|
785
|
+
current.setUTCMonth(boundary.month, clampBoundaryDay(boundary.month))
|
|
786
|
+
current.setUTCHours(boundary.hour, boundary.minute, boundary.second)
|
|
691
787
|
adjustDst(current)
|
|
692
788
|
continue
|
|
693
789
|
}
|
|
694
|
-
if (nextMonth
|
|
695
|
-
|
|
696
|
-
current.
|
|
790
|
+
if (needsStep(nextMonth, currentMonth)) {
|
|
791
|
+
const targetMonthIndex = nextMonth - 1
|
|
792
|
+
current.setUTCMonth(targetMonthIndex, clampBoundaryDay(targetMonthIndex))
|
|
793
|
+
current.setUTCHours(boundary.hour, boundary.minute, boundary.second)
|
|
697
794
|
adjustDst(current)
|
|
698
795
|
continue
|
|
699
796
|
}
|
|
@@ -702,7 +799,7 @@ export const next = (cron: Cron, now?: DateTime.DateTime.Input): Date => {
|
|
|
702
799
|
return
|
|
703
800
|
}
|
|
704
801
|
|
|
705
|
-
throw new Error("Unable to find
|
|
802
|
+
throw new Error("Unable to find " + direction + " cron date")
|
|
706
803
|
})
|
|
707
804
|
|
|
708
805
|
return dateTime.toDateUtc(result)
|
package/src/Equivalence.ts
CHANGED
|
@@ -1060,3 +1060,59 @@ export function makeReducer<A>() {
|
|
|
1060
1060
|
combineAll
|
|
1061
1061
|
)
|
|
1062
1062
|
}
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* An `Equivalence` instance for `Date` objects.
|
|
1066
|
+
*
|
|
1067
|
+
* Dates are compared by their time value (milliseconds since the Unix epoch),
|
|
1068
|
+
* using {@link Date.prototype.getTime}.
|
|
1069
|
+
*
|
|
1070
|
+
* When to use this:
|
|
1071
|
+
* - When comparing `Date` objects by their exact point in time
|
|
1072
|
+
* - When you need value-based equality instead of reference equality
|
|
1073
|
+
* - When working with collections that contain `Date` values
|
|
1074
|
+
*
|
|
1075
|
+
* Behavior:
|
|
1076
|
+
* - Does not mutate inputs
|
|
1077
|
+
* - Two dates are equivalent if `self.getTime() === that.getTime()`
|
|
1078
|
+
* - Internally uses {@link Number} equivalence
|
|
1079
|
+
* - Different `Date` instances representing the same time are considered equivalent
|
|
1080
|
+
*
|
|
1081
|
+
* **Example**
|
|
1082
|
+
*
|
|
1083
|
+
* ```ts
|
|
1084
|
+
* import { Equivalence } from "effect"
|
|
1085
|
+
*
|
|
1086
|
+
* const d1 = new Date("2020-01-01T00:00:00.000Z")
|
|
1087
|
+
* const d2 = new Date("2020-01-01T00:00:00.000Z")
|
|
1088
|
+
* const d3 = new Date("2021-01-01T00:00:00.000Z")
|
|
1089
|
+
* const invalidDate1 = new Date("foo")
|
|
1090
|
+
* const invalidDate2 = new Date("bar")
|
|
1091
|
+
*
|
|
1092
|
+
* console.log(Equivalence.Date(d1, d2)) // true
|
|
1093
|
+
* console.log(Equivalence.Date(d1, d3)) // false
|
|
1094
|
+
* console.log(Equivalence.Date(invalidDate1, invalidDate2)) // true
|
|
1095
|
+
* console.log(Equivalence.Date(invalidDate1, d1)) // false
|
|
1096
|
+
* ```
|
|
1097
|
+
*
|
|
1098
|
+
* **Example** (Reference vs value equality)
|
|
1099
|
+
*
|
|
1100
|
+
* ```ts
|
|
1101
|
+
* import { Equivalence } from "effect"
|
|
1102
|
+
*
|
|
1103
|
+
* const d1 = new Date(0)
|
|
1104
|
+
* const d2 = new Date(0)
|
|
1105
|
+
*
|
|
1106
|
+
* console.log(d1 === d2) // false (different references)
|
|
1107
|
+
* console.log(Equivalence.Date(d1, d2)) // true (same time value)
|
|
1108
|
+
* ```
|
|
1109
|
+
*
|
|
1110
|
+
* See also: {@link Number}, {@link mapInput}, {@link strictEqual}
|
|
1111
|
+
*
|
|
1112
|
+
* @category instances
|
|
1113
|
+
* @since 4.0.0
|
|
1114
|
+
*/
|
|
1115
|
+
export const Date: Equivalence<Date> = mapInput(
|
|
1116
|
+
Number,
|
|
1117
|
+
(d: Date) => d.getTime()
|
|
1118
|
+
)
|
package/src/LayerMap.ts
CHANGED
|
@@ -12,6 +12,8 @@ import type { Mutable, NoExcessProperties } from "./Types.ts"
|
|
|
12
12
|
|
|
13
13
|
const TypeId = "~effect/LayerMap"
|
|
14
14
|
|
|
15
|
+
type IdleTimeToLiveInput<K> = Duration.Input | ((key: K) => Duration.Input)
|
|
16
|
+
|
|
15
17
|
/**
|
|
16
18
|
* @since 3.14.0
|
|
17
19
|
* @category Models
|
|
@@ -119,7 +121,7 @@ export const make: <
|
|
|
119
121
|
>(
|
|
120
122
|
lookup: (key: K) => L,
|
|
121
123
|
options?: {
|
|
122
|
-
readonly idleTimeToLive?:
|
|
124
|
+
readonly idleTimeToLive?: IdleTimeToLiveInput<K> | undefined
|
|
123
125
|
readonly preloadKeys?: PreloadKeys
|
|
124
126
|
} | undefined
|
|
125
127
|
) => Effect.Effect<
|
|
@@ -129,7 +131,7 @@ export const make: <
|
|
|
129
131
|
> = Effect.fnUntraced(function*<I, K, EL, RL>(
|
|
130
132
|
lookup: (key: K) => Layer.Layer<I, EL, RL>,
|
|
131
133
|
options?: {
|
|
132
|
-
readonly idleTimeToLive?:
|
|
134
|
+
readonly idleTimeToLive?: IdleTimeToLiveInput<K> | undefined
|
|
133
135
|
} | undefined
|
|
134
136
|
) {
|
|
135
137
|
const services = yield* Effect.services<never>()
|
|
@@ -198,7 +200,7 @@ export const fromRecord = <
|
|
|
198
200
|
>(
|
|
199
201
|
layers: Layers,
|
|
200
202
|
options?: {
|
|
201
|
-
readonly idleTimeToLive?:
|
|
203
|
+
readonly idleTimeToLive?: IdleTimeToLiveInput<keyof Layers> | undefined
|
|
202
204
|
readonly preload?: Preload | undefined
|
|
203
205
|
} | undefined
|
|
204
206
|
): Effect.Effect<
|
|
@@ -309,7 +311,7 @@ export const Service = <Self>() =>
|
|
|
309
311
|
| NoExcessProperties<{
|
|
310
312
|
readonly lookup: (key: any) => Layer.Layer<any, any, any>
|
|
311
313
|
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined
|
|
312
|
-
readonly idleTimeToLive?:
|
|
314
|
+
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined
|
|
313
315
|
readonly preloadKeys?:
|
|
314
316
|
| Iterable<Options extends { readonly lookup: (key: infer K) => any } ? K : never>
|
|
315
317
|
| undefined
|
|
@@ -317,7 +319,7 @@ export const Service = <Self>() =>
|
|
|
317
319
|
| NoExcessProperties<{
|
|
318
320
|
readonly layers: Record<string, Layer.Layer<any, any, any>>
|
|
319
321
|
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined
|
|
320
|
-
readonly idleTimeToLive?:
|
|
322
|
+
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined
|
|
321
323
|
readonly preload?: boolean | undefined
|
|
322
324
|
}, Options>
|
|
323
325
|
>(
|