effect 4.0.0-beta.97 → 4.0.0-beta.98
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/LayerRef.d.ts +4 -6
- package/dist/LayerRef.d.ts.map +1 -1
- package/dist/LayerRef.js +4 -6
- package/dist/LayerRef.js.map +1 -1
- package/dist/Number.d.ts.map +1 -1
- package/dist/Number.js +28 -10
- package/dist/Number.js.map +1 -1
- package/dist/Schema.d.ts +22 -22
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +36 -33
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +25 -10
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaError.d.ts +53 -0
- package/dist/SchemaError.d.ts.map +1 -0
- package/dist/SchemaError.js +61 -0
- package/dist/SchemaError.js.map +1 -0
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +17 -12
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +186 -224
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +26 -8
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/equivalence.js +1 -2
- package/dist/internal/schema/equivalence.js.map +1 -1
- package/dist/internal/schema/representation.js +1 -3
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.d.ts +0 -13
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +4 -29
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +128 -128
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/cli/CliError.d.ts +8 -16
- package/dist/unstable/cli/CliError.d.ts.map +1 -1
- package/dist/unstable/cli/CliError.js +8 -16
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +4 -3
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +3 -3
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/GlobalFlag.d.ts +6 -8
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
- package/dist/unstable/cli/GlobalFlag.js +6 -6
- package/dist/unstable/cli/GlobalFlag.js.map +1 -1
- package/dist/unstable/cluster/EntityProxyServer.d.ts +1 -1
- package/dist/unstable/cluster/EntityProxyServer.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityProxyServer.js +2 -4
- package/dist/unstable/cluster/EntityProxyServer.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +15 -12
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.d.ts +36 -15
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js +19 -20
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +51 -62
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +68 -58
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +53 -53
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +40 -30
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +165 -164
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +31 -19
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +22 -0
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +31 -0
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.d.ts +55 -30
- package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js +22 -29
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +8 -8
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.js +4 -3
- package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +8 -0
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiTest.d.ts +4 -4
- package/dist/unstable/httpapi/HttpApiTest.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiTest.js +9 -8
- package/dist/unstable/httpapi/HttpApiTest.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +77 -37
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/httpapi/internal/html.js +6 -2
- package/dist/unstable/httpapi/internal/html.js.map +1 -1
- package/dist/unstable/httpapi/internal/mediaType.d.ts +2 -0
- package/dist/unstable/httpapi/internal/mediaType.d.ts.map +1 -0
- package/dist/unstable/httpapi/internal/mediaType.js +7 -0
- package/dist/unstable/httpapi/internal/mediaType.js.map +1 -0
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +16 -12
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/reactivity/Atom.js +1 -1
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +7 -7
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +3 -2
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts +3 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +6 -3
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.js +1 -1
- package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.d.ts +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.js +1 -2
- package/dist/unstable/workflow/WorkflowProxyServer.js.map +1 -1
- package/package.json +1 -1
- package/src/LayerRef.ts +4 -6
- package/src/Number.ts +29 -10
- package/src/Schema.ts +42 -34
- package/src/SchemaAST.ts +25 -13
- package/src/SchemaError.ts +64 -0
- package/src/SchemaGetter.ts +22 -16
- package/src/SchemaRepresentation.ts +165 -202
- package/src/index.ts +10 -0
- package/src/internal/effect.ts +39 -22
- package/src/internal/schema/equivalence.ts +1 -2
- package/src/internal/schema/representation.ts +4 -4
- package/src/internal/schema/schema.ts +4 -37
- package/src/unstable/cli/CliError.ts +24 -16
- package/src/unstable/cli/Command.ts +8 -8
- package/src/unstable/cli/GlobalFlag.ts +22 -33
- package/src/unstable/cluster/EntityProxyServer.ts +15 -17
- package/src/unstable/cluster/internal/entityManager.ts +48 -34
- package/src/unstable/httpapi/HttpApi.ts +72 -47
- package/src/unstable/httpapi/HttpApiBuilder.ts +320 -217
- package/src/unstable/httpapi/HttpApiClient.ts +196 -151
- package/src/unstable/httpapi/HttpApiEndpoint.ts +251 -447
- package/src/unstable/httpapi/HttpApiError.ts +33 -0
- package/src/unstable/httpapi/HttpApiGroup.ts +95 -74
- package/src/unstable/httpapi/HttpApiMiddleware.ts +10 -7
- package/src/unstable/httpapi/HttpApiScalar.ts +15 -12
- package/src/unstable/httpapi/HttpApiSchema.ts +8 -0
- package/src/unstable/httpapi/HttpApiSwagger.ts +2 -2
- package/src/unstable/httpapi/HttpApiTest.ts +15 -14
- package/src/unstable/httpapi/OpenApi.ts +74 -36
- package/src/unstable/httpapi/internal/html.ts +9 -2
- package/src/unstable/httpapi/internal/mediaType.ts +6 -0
- package/src/unstable/persistence/PersistedQueue.ts +16 -14
- package/src/unstable/reactivity/Atom.ts +1 -1
- package/src/unstable/reactivity/AtomHttpApi.ts +164 -162
- package/src/unstable/rpc/RpcServer.ts +10 -4
- package/src/unstable/workflow/DurableDeferred.ts +1 -1
- package/src/unstable/workflow/WorkflowProxyServer.ts +11 -12
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
import * as Arr from "../../Array.ts"
|
|
12
12
|
import type { NonEmptyArray } from "../../Array.ts"
|
|
13
13
|
import * as Context from "../../Context.ts"
|
|
14
|
+
import * as Equal from "../../Equal.ts"
|
|
14
15
|
import { constFalse } from "../../Function.ts"
|
|
16
|
+
import * as internalRecord from "../../internal/record.ts"
|
|
15
17
|
import * as JsonPatch from "../../JsonPatch.ts"
|
|
16
18
|
import { escapeToken } from "../../JsonPointer.ts"
|
|
17
19
|
import * as JsonSchema from "../../JsonSchema.ts"
|
|
@@ -208,7 +210,7 @@ export const annotations: (
|
|
|
208
210
|
transform: Transform
|
|
209
211
|
})
|
|
210
212
|
|
|
211
|
-
const apiCache = new WeakMap<HttpApi.
|
|
213
|
+
const apiCache = new WeakMap<HttpApi.Constraint, OpenAPISpec>()
|
|
212
214
|
|
|
213
215
|
/**
|
|
214
216
|
* This function checks if a given tag exists within the provided context. If
|
|
@@ -246,7 +248,7 @@ function processAnnotation<Services, S, I>(
|
|
|
246
248
|
* @category constructors
|
|
247
249
|
* @since 4.0.0
|
|
248
250
|
*/
|
|
249
|
-
export function fromApi<Id extends string, Groups extends HttpApiGroup.
|
|
251
|
+
export function fromApi<Id extends string, Groups extends HttpApiGroup.Constraint>(
|
|
250
252
|
api: HttpApi.HttpApi<Id, Groups>
|
|
251
253
|
): OpenAPISpec {
|
|
252
254
|
const cached = apiCache.get(api)
|
|
@@ -279,6 +281,8 @@ export function fromApi<Id extends string, Groups extends HttpApiGroup.Any>(
|
|
|
279
281
|
readonly path: ReadonlyArray<string>
|
|
280
282
|
}
|
|
281
283
|
> = []
|
|
284
|
+
const pathOperations = new Set<string>()
|
|
285
|
+
const operationIds = new Set<string>()
|
|
282
286
|
|
|
283
287
|
processAnnotation(api.annotations, Title, (title) => {
|
|
284
288
|
spec.info.title = title
|
|
@@ -331,7 +335,7 @@ export function fromApi<Id extends string, Groups extends HttpApiGroup.Any>(
|
|
|
331
335
|
operationId: Context.getOrElse(
|
|
332
336
|
endpoint.annotations,
|
|
333
337
|
Identifier,
|
|
334
|
-
() => group.topLevel ? endpoint.
|
|
338
|
+
() => group.topLevel ? endpoint.identifier : `${group.identifier}.${endpoint.identifier}`
|
|
335
339
|
),
|
|
336
340
|
parameters: [],
|
|
337
341
|
security: [],
|
|
@@ -341,31 +345,6 @@ export function fromApi<Id extends string, Groups extends HttpApiGroup.Any>(
|
|
|
341
345
|
const path = endpoint.path.replace(/:(\w+)\??/g, "{$1}")
|
|
342
346
|
const method = endpoint.method.toLowerCase() as OpenAPISpecMethodName
|
|
343
347
|
|
|
344
|
-
function processRequestBodies(payloadMap: HttpApiEndpoint.PayloadMap) {
|
|
345
|
-
if (payloadMap.size > 0) {
|
|
346
|
-
const c: OpenApiSpecContent = {}
|
|
347
|
-
let hasContent = false
|
|
348
|
-
payloadMap.forEach(({ encoding, schemas }, contentType) => {
|
|
349
|
-
const filtered = schemas.filter((s) => !HttpApiSchema.isNoContent(s.ast))
|
|
350
|
-
if (filtered.length === 0) return
|
|
351
|
-
hasContent = true
|
|
352
|
-
const asts = filtered.map(SchemaAST.getAST)
|
|
353
|
-
const ast = asts.length === 1 ? asts[0] : new SchemaAST.Union(asts, "anyOf")
|
|
354
|
-
pathOps.push({
|
|
355
|
-
_tag: "schema",
|
|
356
|
-
ast: toEncodingAST(ast, encoding._tag),
|
|
357
|
-
path: ["paths", path, method, "requestBody", "content", contentType, "schema"]
|
|
358
|
-
})
|
|
359
|
-
c[contentType] = {
|
|
360
|
-
schema: {}
|
|
361
|
-
}
|
|
362
|
-
})
|
|
363
|
-
if (hasContent) {
|
|
364
|
-
op.requestBody = { content: c, required: true }
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
348
|
function processResponseBodies(bodies: ResponseBodies, defaultDescription: () => string) {
|
|
370
349
|
for (const [status, { content, descriptions, streamContent }] of bodies) {
|
|
371
350
|
const description = descriptions.size > 0 ? Array.from(descriptions).join(" | ") : defaultDescription()
|
|
@@ -502,15 +481,53 @@ export function fromApi<Id extends string, Groups extends HttpApiGroup.Any>(
|
|
|
502
481
|
name: string,
|
|
503
482
|
security: HttpApiSecurity
|
|
504
483
|
) {
|
|
505
|
-
|
|
484
|
+
const scheme = makeSecurityScheme(security)
|
|
485
|
+
if (!Object.hasOwn(spec.components.securitySchemes, name)) {
|
|
486
|
+
internalRecord.set(spec.components.securitySchemes, name, scheme)
|
|
506
487
|
return
|
|
507
488
|
}
|
|
508
|
-
|
|
489
|
+
if (
|
|
490
|
+
!Equal.equals(
|
|
491
|
+
securitySchemeForComparison(spec.components.securitySchemes[name]),
|
|
492
|
+
securitySchemeForComparison(scheme)
|
|
493
|
+
)
|
|
494
|
+
) {
|
|
495
|
+
throw new globalThis.Error(`Conflicting OpenAPI security scheme: ${name}`)
|
|
496
|
+
}
|
|
509
497
|
}
|
|
510
498
|
|
|
511
499
|
const hasBody = HttpMethod.hasBody(endpoint.method)
|
|
512
500
|
if (hasBody) {
|
|
513
|
-
|
|
501
|
+
const schemasByContentType = new Map<string, {
|
|
502
|
+
readonly encoding: HttpApiSchema.PayloadEncoding
|
|
503
|
+
readonly schemas: Array<Schema.Top>
|
|
504
|
+
}>()
|
|
505
|
+
for (const schema of HttpApiEndpoint.getPayloadSchemas(endpoint)) {
|
|
506
|
+
if (HttpApiSchema.isNoContent(schema.ast)) continue
|
|
507
|
+
const encoding = HttpApiSchema.getPayloadEncoding(schema.ast, endpoint.method)
|
|
508
|
+
const existing = schemasByContentType.get(encoding.contentType)
|
|
509
|
+
if (existing === undefined) {
|
|
510
|
+
schemasByContentType.set(encoding.contentType, { encoding, schemas: [schema] })
|
|
511
|
+
} else {
|
|
512
|
+
existing.schemas.push(schema)
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (schemasByContentType.size > 0) {
|
|
516
|
+
const content: OpenApiSpecContent = {}
|
|
517
|
+
for (const [contentType, { encoding, schemas }] of schemasByContentType) {
|
|
518
|
+
const asts = schemas.map(SchemaAST.getAST)
|
|
519
|
+
const ast = asts.length === 1 ? asts[0] : new SchemaAST.Union(asts, "anyOf")
|
|
520
|
+
pathOps.push({
|
|
521
|
+
_tag: "schema",
|
|
522
|
+
ast: toEncodingAST(ast, encoding._tag),
|
|
523
|
+
path: ["paths", path, method, "requestBody", "content", contentType, "schema"]
|
|
524
|
+
})
|
|
525
|
+
content[contentType] = {
|
|
526
|
+
schema: {}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
op.requestBody = { content, required: true }
|
|
530
|
+
}
|
|
514
531
|
}
|
|
515
532
|
|
|
516
533
|
processParameters(endpoint.params, "path")
|
|
@@ -534,10 +551,6 @@ export function fromApi<Id extends string, Groups extends HttpApiGroup.Any>(
|
|
|
534
551
|
() => "Error"
|
|
535
552
|
)
|
|
536
553
|
|
|
537
|
-
if (!spec.paths[path]) {
|
|
538
|
-
spec.paths[path] = {}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
554
|
processAnnotation(endpoint.annotations, Override, (override) => {
|
|
542
555
|
Object.assign(op, override)
|
|
543
556
|
})
|
|
@@ -545,6 +558,21 @@ export function fromApi<Id extends string, Groups extends HttpApiGroup.Any>(
|
|
|
545
558
|
op = transformFn(op) as OpenAPISpecOperation
|
|
546
559
|
})
|
|
547
560
|
|
|
561
|
+
const pathOperation = `${method} ${path.replace(/\{[^}]+\}/g, "{}")}`
|
|
562
|
+
if (pathOperations.has(pathOperation)) {
|
|
563
|
+
throw new globalThis.Error(`Duplicate OpenAPI operation for ${endpoint.method} ${path}`)
|
|
564
|
+
}
|
|
565
|
+
const operationId = op.operationId
|
|
566
|
+
if (operationId !== undefined) {
|
|
567
|
+
if (operationIds.has(operationId)) {
|
|
568
|
+
throw new globalThis.Error(`Duplicate OpenAPI operationId: ${operationId}`)
|
|
569
|
+
}
|
|
570
|
+
operationIds.add(operationId)
|
|
571
|
+
}
|
|
572
|
+
pathOperations.add(pathOperation)
|
|
573
|
+
if (!spec.paths[path]) {
|
|
574
|
+
spec.paths[path] = {}
|
|
575
|
+
}
|
|
548
576
|
spec.paths[path][method] = op
|
|
549
577
|
}
|
|
550
578
|
})
|
|
@@ -627,7 +655,7 @@ type ResponseBodies = Map<
|
|
|
627
655
|
|
|
628
656
|
const reservedStreamFailureEvent = "effect/httpapi/stream/failure"
|
|
629
657
|
|
|
630
|
-
function extractSuccessResponseBodies(endpoint: HttpApiEndpoint.
|
|
658
|
+
function extractSuccessResponseBodies(endpoint: HttpApiEndpoint.Top): ResponseBodies {
|
|
631
659
|
return extractResponseBodies(
|
|
632
660
|
HttpApiEndpoint.getSuccessSchemas(endpoint),
|
|
633
661
|
HttpApiSchema.getStatusSuccess,
|
|
@@ -814,6 +842,16 @@ const makeSecurityScheme = (security: HttpApiSecurity): OpenAPISecurityScheme =>
|
|
|
814
842
|
}
|
|
815
843
|
}
|
|
816
844
|
|
|
845
|
+
const securitySchemeForComparison = (scheme: OpenAPISecurityScheme): OpenAPISecurityScheme => {
|
|
846
|
+
if (scheme.type === "http") {
|
|
847
|
+
return { ...scheme, scheme: scheme.scheme.toLowerCase() }
|
|
848
|
+
}
|
|
849
|
+
if (scheme.in === "header") {
|
|
850
|
+
return { ...scheme, name: scheme.name.toLowerCase() }
|
|
851
|
+
}
|
|
852
|
+
return scheme
|
|
853
|
+
}
|
|
854
|
+
|
|
817
855
|
/**
|
|
818
856
|
* This model describes the OpenAPI specification (version 3.1.0) returned by
|
|
819
857
|
* {@link fromApi}. It is not intended to describe the entire OpenAPI
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const
|
|
1
|
+
const ESCAPE_SCRIPT_DATA = /</g
|
|
2
2
|
|
|
3
3
|
const ESCAPE_LINE_TERMS = /[\u2028\u2029]/g
|
|
4
4
|
|
|
5
5
|
/** @internal */
|
|
6
6
|
export function escapeJson(spec: unknown): string {
|
|
7
7
|
return JSON.stringify(spec)
|
|
8
|
-
.replace(
|
|
8
|
+
.replace(ESCAPE_SCRIPT_DATA, "\\u003c")
|
|
9
9
|
.replace(ESCAPE_LINE_TERMS, (c) => c === "\u2028" ? "\\u2028" : "\\u2029")
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -16,3 +16,10 @@ export function escape(str: string): string {
|
|
|
16
16
|
.replace(/</g, "<")
|
|
17
17
|
.replace(/>/g, ">")
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
/** @internal */
|
|
21
|
+
export function escapeAttribute(str: string): string {
|
|
22
|
+
return escape(str)
|
|
23
|
+
.replace(/"/g, """)
|
|
24
|
+
.replace(/'/g, "'")
|
|
25
|
+
}
|
|
@@ -170,19 +170,13 @@ export const makeFactory = Effect.gen(function*() {
|
|
|
170
170
|
}
|
|
171
171
|
),
|
|
172
172
|
take: (f, opts) =>
|
|
173
|
-
Effect.
|
|
174
|
-
const scope = yield* Scope.make()
|
|
173
|
+
Effect.scopedWith(Effect.fnUntraced(function*(scope) {
|
|
175
174
|
const item = yield* store.take({
|
|
176
175
|
name: options.name,
|
|
177
176
|
maxAttempts: opts?.maxAttempts ?? 10
|
|
178
|
-
}).pipe(
|
|
179
|
-
Scope.provide(scope),
|
|
180
|
-
restore
|
|
181
|
-
)
|
|
177
|
+
}).pipe(Scope.provide(scope))
|
|
182
178
|
const decoded = yield* decodeUnknown(item.element)
|
|
183
|
-
|
|
184
|
-
yield* Scope.close(scope, exit)
|
|
185
|
-
return yield* exit
|
|
179
|
+
return yield* f(decoded, { id: item.id, attempts: item.attempts })
|
|
186
180
|
}))
|
|
187
181
|
})
|
|
188
182
|
}
|
|
@@ -613,7 +607,9 @@ local key_pending = KEYS[2]
|
|
|
613
607
|
local prefix = ARGV[1]
|
|
614
608
|
|
|
615
609
|
local entries = redis.call("HGETALL", key_pending)
|
|
616
|
-
for
|
|
610
|
+
for i = 1, #entries, 2 do
|
|
611
|
+
local id = entries[i]
|
|
612
|
+
local payload = entries[i + 1]
|
|
617
613
|
local lock_key = prefix .. id .. ":lock"
|
|
618
614
|
local exists = redis.call("EXISTS", lock_key)
|
|
619
615
|
if exists == 0 then
|
|
@@ -673,7 +669,7 @@ redis.call("DEL", key_lock)
|
|
|
673
669
|
redis.call("HDEL", key_pending, id)
|
|
674
670
|
redis.call("RPUSH", key_failed, payload)
|
|
675
671
|
`,
|
|
676
|
-
numberOfKeys:
|
|
672
|
+
numberOfKeys: 3
|
|
677
673
|
}
|
|
678
674
|
)
|
|
679
675
|
|
|
@@ -936,10 +932,12 @@ export const makeStoreSql: (
|
|
|
936
932
|
const elementIds = new Set<number>()
|
|
937
933
|
const refreshLocks: Effect.Effect<void, SqlError> = Effect.suspend((): Effect.Effect<void, SqlError> => {
|
|
938
934
|
if (elementIds.size === 0) return Effect.void
|
|
935
|
+
const ids = Array.from(elementIds)
|
|
939
936
|
return sql`
|
|
940
937
|
UPDATE ${tableNameSql}
|
|
941
938
|
SET acquired_at = ${sqlNow}
|
|
942
|
-
WHERE
|
|
939
|
+
WHERE sequence IN (${sql.literal(ids.join(","))})
|
|
940
|
+
AND acquired_by = ${workerIdSql}
|
|
943
941
|
`
|
|
944
942
|
})
|
|
945
943
|
const complete = (sequence: number, attempts: number) => {
|
|
@@ -1110,7 +1108,7 @@ export const makeStoreSql: (
|
|
|
1110
1108
|
takenLatch.closeUnsafe()
|
|
1111
1109
|
for (let i = 0; i < results.length; i++) {
|
|
1112
1110
|
const element = results[i]
|
|
1113
|
-
|
|
1111
|
+
elementIds.add(element.sequence)
|
|
1114
1112
|
}
|
|
1115
1113
|
yield* Queue.offerAll(queue, results)
|
|
1116
1114
|
yield* takenLatch.await
|
|
@@ -1165,7 +1163,11 @@ export const makeStoreSql: (
|
|
|
1165
1163
|
: retry(element.sequence, element.attempts + 1, cause),
|
|
1166
1164
|
onSuccess: () => complete(element.sequence, element.attempts + 1)
|
|
1167
1165
|
}))
|
|
1168
|
-
)
|
|
1166
|
+
),
|
|
1167
|
+
Effect.map((element) => ({
|
|
1168
|
+
...element,
|
|
1169
|
+
element: JSON.parse(element.element)
|
|
1170
|
+
}))
|
|
1169
1171
|
)
|
|
1170
1172
|
)
|
|
1171
1173
|
})
|
|
@@ -2650,7 +2650,7 @@ export const kvs = <S extends Schema.ConstraintCodec<any, any>, const Mode exten
|
|
|
2650
2650
|
},
|
|
2651
2651
|
(ctx, value: S["Type"]) => {
|
|
2652
2652
|
ctx.set(setAtom, value as any)
|
|
2653
|
-
ctx.setSelf(value)
|
|
2653
|
+
ctx.setSelf(options.mode === "async" ? AsyncResult.success(value) : value)
|
|
2654
2654
|
}
|
|
2655
2655
|
) as any
|
|
2656
2656
|
}
|