@afora/core 0.0.8 → 0.0.11
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/README.md +149 -23
- package/dist/adapters.d.ts +25 -0
- package/dist/adapters.js +32 -0
- package/dist/core/application/application.d.ts +30 -0
- package/dist/core/application/application.js +1291 -0
- package/dist/core/application/exceptions.d.ts +17 -0
- package/dist/core/application/exceptions.js +85 -0
- package/dist/core/application/migrate.d.ts +19 -0
- package/dist/core/application/migrate.js +67 -0
- package/dist/core/application/providers.js +108 -0
- package/dist/core/application/registry.js +23 -0
- package/dist/core/application/schema.d.ts +30 -0
- package/dist/core/application/schema.js +398 -0
- package/dist/core/application/start.js +162 -0
- package/dist/core/application/types/application.interface.d.ts +60 -3
- package/dist/core/auth/jwt.d.ts +30 -0
- package/dist/core/auth/jwt.js +200 -0
- package/dist/core/auth/types/jwt.interface.d.ts +74 -0
- package/dist/core/blueprint/blueprint-plugin.js +7 -0
- package/dist/core/blueprint/blueprint.js +146 -0
- package/dist/core/blueprint/callable.js +13 -0
- package/dist/core/blueprint/exceptions.d.ts +5 -0
- package/dist/core/blueprint/exceptions.js +20 -0
- package/dist/core/blueprint/is-blueprint.js +4 -0
- package/dist/core/blueprint/list.js +19 -0
- package/dist/core/blueprint/optional.d.ts +3 -1
- package/dist/core/blueprint/optional.js +69 -0
- package/dist/core/blueprint/record-field.js +14 -0
- package/dist/core/blueprint/slice.js +127 -0
- package/dist/core/blueprint/types/blueprint.interface.d.ts +95 -5
- package/dist/core/blueprint/variant.d.ts +32 -0
- package/dist/core/blueprint/variant.js +72 -0
- package/dist/core/command/command.js +428 -0
- package/dist/core/command/exceptions.js +30 -0
- package/dist/core/command/types/command.interface.d.ts +10 -1
- package/dist/core/entity/abstract-entity.d.ts +24 -0
- package/dist/core/entity/abstract-entity.js +181 -0
- package/dist/core/entity/entity.d.ts +1 -1
- package/dist/core/entity/entity.js +209 -0
- package/dist/core/entity/event.d.ts +39 -0
- package/dist/core/entity/event.js +80 -0
- package/dist/core/entity/exceptions.d.ts +9 -0
- package/dist/core/entity/exceptions.js +27 -0
- package/dist/core/entity/trust.d.ts +24 -0
- package/dist/core/entity/trust.js +7 -0
- package/dist/core/entity/types/entity.interface.d.ts +30 -0
- package/dist/core/entity/version.js +13 -0
- package/dist/core/environment/environment.d.ts +26 -3
- package/dist/core/environment/environment.js +71 -0
- package/dist/core/event-policy/event-policy.js +76 -0
- package/dist/core/event-policy/exceptions.js +12 -0
- package/dist/core/event-policy/publish.js +98 -0
- package/dist/core/event-policy/publishers.js +18 -0
- package/dist/core/event-policy/types/event-policy.interface.d.ts +8 -2
- package/dist/core/exception/enums/exception-layers.js +15 -0
- package/dist/core/exception/exception.d.ts +15 -0
- package/dist/core/exception/exception.js +128 -0
- package/dist/core/exception/exported.js +49 -0
- package/dist/core/exception/guard.d.ts +20 -1
- package/dist/core/exception/guard.js +16 -0
- package/dist/core/exception/types/exception.interface.d.ts +13 -0
- package/dist/core/json.js +19 -0
- package/dist/core/logger/exceptions.js +7 -0
- package/dist/core/logger/logger.d.ts +14 -1
- package/dist/core/logger/logger.js +178 -0
- package/dist/core/openapi/exceptions.js +7 -0
- package/dist/core/openapi/openapi.js +132 -0
- package/dist/core/openapi/types/openapi.interface.d.ts +7 -1
- package/dist/core/output/access.d.ts +16 -0
- package/dist/core/output/access.js +66 -0
- package/dist/core/output/coerce.js +38 -0
- package/dist/core/output/exceptions.d.ts +16 -0
- package/dist/core/output/exceptions.js +22 -0
- package/dist/core/output/http.d.ts +36 -0
- package/dist/core/output/http.js +351 -0
- package/dist/core/output/openapi-sink.d.ts +33 -4
- package/dist/core/output/openapi-sink.js +571 -0
- package/dist/core/output/output.js +192 -0
- package/dist/core/output/problem.js +30 -0
- package/dist/core/output/select.js +28 -0
- package/dist/core/output/stage.d.ts +7 -2
- package/dist/core/output/stage.js +111 -0
- package/dist/core/output/status.d.ts +1 -1
- package/dist/core/output/status.js +52 -0
- package/dist/core/output/types/http.interface.d.ts +134 -0
- package/dist/core/output/types/output.interface.d.ts +49 -5
- package/dist/core/parse/issue.d.ts +28 -3
- package/dist/core/parse/issue.js +31 -0
- package/dist/core/parse/parse.d.ts +16 -0
- package/dist/core/parse/parse.js +323 -0
- package/dist/core/parse/strip.js +48 -0
- package/dist/core/property/abstract-property.d.ts +9 -0
- package/dist/core/property/abstract-property.js +37 -0
- package/dist/core/property/define-property.d.ts +34 -6
- package/dist/core/property/define-property.js +209 -0
- package/dist/core/property/enums/property-states.js +8 -0
- package/dist/core/property/exceptions.js +12 -0
- package/dist/core/property/input.js +10 -0
- package/dist/core/property/is-property.js +3 -0
- package/dist/core/property/lineage.js +8 -0
- package/dist/core/property/property.d.ts +27 -0
- package/dist/core/property/property.js +46 -0
- package/dist/core/property/refine.js +103 -0
- package/dist/core/property/types/property-options.interface.d.ts +10 -0
- package/dist/core/property/types/property-type.interface.d.ts +4 -0
- package/dist/core/record/abstract-record.d.ts +8 -0
- package/dist/core/record/abstract-record.js +307 -0
- package/dist/core/record/exceptions.js +49 -0
- package/dist/core/record/marks.js +7 -0
- package/dist/core/record/mask.js +60 -0
- package/dist/core/record/name.js +23 -0
- package/dist/core/record/plugin-catalog.js +115 -0
- package/dist/core/record/plugin.js +198 -0
- package/dist/core/record/record.js +117 -0
- package/dist/core/record/types/record.interface.d.ts +17 -1
- package/dist/core/repository/cursor.js +83 -0
- package/dist/core/repository/exceptions.d.ts +13 -0
- package/dist/core/repository/exceptions.js +72 -0
- package/dist/core/repository/in-memory.d.ts +2 -2
- package/dist/core/repository/in-memory.js +196 -0
- package/dist/core/repository/migrate.d.ts +20 -0
- package/dist/core/repository/migrate.js +254 -0
- package/dist/core/repository/plan.js +27 -0
- package/dist/core/repository/provider.js +29 -0
- package/dist/core/repository/query.js +153 -0
- package/dist/core/repository/references.js +196 -0
- package/dist/core/repository/repository.d.ts +22 -2
- package/dist/core/repository/repository.js +720 -0
- package/dist/core/repository/state.d.ts +2 -0
- package/dist/core/repository/state.js +138 -0
- package/dist/core/repository/types/query.interface.d.ts +13 -0
- package/dist/core/repository/types/repository.interface.d.ts +50 -5
- package/dist/core/repository/types/schema.interface.d.ts +132 -0
- package/dist/core/repository/upcast.d.ts +64 -0
- package/dist/core/repository/upcast.js +179 -0
- package/dist/core/schema/schema.d.ts +37 -0
- package/dist/core/schema/schema.js +542 -0
- package/dist/core/standard/standard-schema.js +1 -0
- package/dist/core/standard/standard.js +23 -0
- package/dist/core/symbols/demo.d.ts +4 -0
- package/dist/core/symbols/demo.js +1 -0
- package/dist/core/symbols/kind.d.ts +1 -1
- package/dist/core/symbols/kind.js +1 -0
- package/dist/core/symbols/meta.js +1 -0
- package/dist/core/symbols/state.d.ts +5 -0
- package/dist/core/symbols/state.js +1 -0
- package/dist/core/tracing/exceptions.d.ts +4 -0
- package/dist/core/tracing/exceptions.js +7 -0
- package/dist/core/tracing/tracing.d.ts +72 -0
- package/dist/core/tracing/tracing.js +101 -0
- package/dist/core/use-case/access.d.ts +12 -0
- package/dist/core/use-case/access.js +56 -0
- package/dist/core/use-case/decorators.d.ts +40 -0
- package/dist/core/use-case/decorators.js +65 -0
- package/dist/core/use-case/exceptions.d.ts +5 -1
- package/dist/core/use-case/exceptions.js +48 -0
- package/dist/core/use-case/plugin-catalog.js +68 -0
- package/dist/core/use-case/plugin.js +133 -0
- package/dist/core/use-case/route.d.ts +18 -0
- package/dist/core/use-case/route.js +200 -0
- package/dist/core/use-case/scope.d.ts +5 -0
- package/dist/core/use-case/scope.js +4 -0
- package/dist/core/use-case/steps/describe.d.ts +5 -1
- package/dist/core/use-case/steps/describe.js +24 -0
- package/dist/core/use-case/steps/references.js +105 -0
- package/dist/core/use-case/steps/run.js +139 -0
- package/dist/core/use-case/steps/types/check.interface.d.ts +233 -0
- package/dist/core/use-case/steps/types/steps.interface.d.ts +8 -1
- package/dist/core/use-case/steps/validate.js +368 -0
- package/dist/core/use-case/target.js +100 -0
- package/dist/core/use-case/types/access.interface.d.ts +39 -0
- package/dist/core/use-case/types/route.interface.d.ts +86 -0
- package/dist/core/use-case/use-case.d.ts +127 -2
- package/dist/core/use-case/use-case.js +493 -0
- package/dist/experimental.d.ts +18 -1
- package/dist/experimental.js +18 -123
- package/dist/index.d.ts +49 -51
- package/dist/index.js +213 -443
- package/dist/std/blueprint-plugin.js +42 -0
- package/dist/std/blueprint.d.ts +21 -0
- package/dist/std/blueprint.js +3 -0
- package/dist/std/command.js +3 -0
- package/dist/std/entity.d.ts +20 -1
- package/dist/std/entity.js +30 -0
- package/dist/std/event-policies.js +3 -0
- package/dist/std/properties/contact.d.ts +3 -0
- package/dist/std/properties/contact.js +29 -0
- package/dist/std/properties/enum.js +26 -0
- package/dist/std/properties/exceptions.js +14 -0
- package/dist/std/properties/headless.js +45 -0
- package/dist/std/properties/identity.js +28 -0
- package/dist/std/properties/json.js +161 -0
- package/dist/std/properties/password.d.ts +0 -2
- package/dist/std/properties/password.js +79 -0
- package/dist/std/properties/primitives.d.ts +4 -0
- package/dist/std/properties/primitives.js +28 -0
- package/dist/std/properties/time.js +55 -0
- package/dist/std/record-plugins.d.ts +2 -2
- package/dist/std/record-plugins.js +73 -0
- package/dist/std/record.d.ts +20 -1
- package/dist/std/record.js +3 -0
- package/dist/std/resource.d.ts +31 -0
- package/dist/std/resource.js +39 -0
- package/dist/std/runtime.d.ts +6 -0
- package/dist/std/runtime.js +193 -0
- package/dist/std/stages.js +4 -0
- package/dist/std/use-cases/auth.d.ts +5 -1
- package/dist/std/use-cases/auth.js +193 -0
- package/dist/std/use-cases/crud.js +261 -0
- package/dist/std/use-cases/index.d.ts +1 -1
- package/dist/std/use-cases/index.js +12 -0
- package/dist/std/use-cases/lifecycle.js +97 -0
- package/dist/std/use-cases/shared.d.ts +2 -2
- package/dist/std/use-cases/shared.js +232 -0
- package/dist/std/use-cases/types.d.ts +102 -2
- package/dist/std/use-cases/types.js +0 -0
- package/dist/testing/http-provider-contract.d.ts +32 -0
- package/dist/testing/http-provider-contract.js +344 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +3 -944
- package/dist/testing/memory-publisher.js +12 -0
- package/dist/testing/provider-contract.d.ts +26 -1
- package/dist/testing/provider-contract.js +1071 -0
- package/package.json +23 -3
- package/dist/index-qxfkyd6k.js +0 -1721
- package/dist/index-t5qwtyj5.js +0 -8194
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import { isBlueprint } from "../blueprint/is-blueprint.js";
|
|
2
|
+
import { isBlueprintList } from "../blueprint/list.js";
|
|
3
|
+
import { isRecordClass, recordFieldOf } from "../blueprint/record-field.js";
|
|
4
|
+
import { isBlueprintVariant, variantOfValue } from "../blueprint/variant.js";
|
|
5
|
+
import { isEntity } from "../entity/entity.js";
|
|
6
|
+
import {
|
|
7
|
+
isEnvironment
|
|
8
|
+
} from "../environment/environment.js";
|
|
9
|
+
import { ExceptionLayers } from "../exception/enums/exception-layers.js";
|
|
10
|
+
import {
|
|
11
|
+
Exception,
|
|
12
|
+
exceptionOf,
|
|
13
|
+
isDeclaredException
|
|
14
|
+
} from "../exception/exception.js";
|
|
15
|
+
import { guard } from "../exception/guard.js";
|
|
16
|
+
import {
|
|
17
|
+
clock,
|
|
18
|
+
elapsed,
|
|
19
|
+
isLogger,
|
|
20
|
+
isLoggerDeclaration,
|
|
21
|
+
logFailure,
|
|
22
|
+
resolveLogger,
|
|
23
|
+
silentLogger,
|
|
24
|
+
writeLog
|
|
25
|
+
} from "../logger/logger.js";
|
|
26
|
+
import { recordNameOf } from "../record/name.js";
|
|
27
|
+
import { AbstractRepository, isRepository } from "../repository/repository.js";
|
|
28
|
+
import { Kind } from "../symbols/kind.js";
|
|
29
|
+
import {
|
|
30
|
+
endSpan,
|
|
31
|
+
failSpan,
|
|
32
|
+
resolveTracer,
|
|
33
|
+
runInSpan,
|
|
34
|
+
startSpan
|
|
35
|
+
} from "../tracing/tracing.js";
|
|
36
|
+
import { accessDeclarationOf } from "./access.js";
|
|
37
|
+
import { routeDeclarationOf } from "./route.js";
|
|
38
|
+
import { ScopeKey } from "./scope.js";
|
|
39
|
+
import { freezeData } from "./steps/references.js";
|
|
40
|
+
import { executeSteps } from "./steps/run.js";
|
|
41
|
+
import { validateSteps } from "./steps/validate.js";
|
|
42
|
+
export const InvalidUseCaseDeclaration = exceptionOf({
|
|
43
|
+
layer: ExceptionLayers.UseCase,
|
|
44
|
+
name: "InvalidUseCaseDeclaration",
|
|
45
|
+
message: ({ reason }) => reason
|
|
46
|
+
});
|
|
47
|
+
export const UseCaseAlreadyExecuted = exceptionOf({
|
|
48
|
+
layer: ExceptionLayers.UseCase,
|
|
49
|
+
name: "UseCaseAlreadyExecuted",
|
|
50
|
+
message: "A UseCase instance can execute only once."
|
|
51
|
+
});
|
|
52
|
+
export const InvalidUseCaseDependencies = exceptionOf({
|
|
53
|
+
layer: ExceptionLayers.UseCase,
|
|
54
|
+
name: "InvalidUseCaseDependencies",
|
|
55
|
+
message: "Dependency overrides must contain only declared names: functions for use cases, objects of methods for repositories, and valid variables for environments."
|
|
56
|
+
});
|
|
57
|
+
function loggerOfCall(state) {
|
|
58
|
+
return resolveLogger(state.scope?.logger, state.owner);
|
|
59
|
+
}
|
|
60
|
+
const states = new WeakMap;
|
|
61
|
+
function issuesSummaryOf(issues) {
|
|
62
|
+
const [first] = issues;
|
|
63
|
+
if (first === undefined)
|
|
64
|
+
return ".";
|
|
65
|
+
const path = first.path.join(".");
|
|
66
|
+
const more = issues.length > 1 ? ` (and ${issues.length - 1} more)` : "";
|
|
67
|
+
return `: ${path === "" ? "" : `"${path}" `}${first.message}${more}.`;
|
|
68
|
+
}
|
|
69
|
+
function invalidValue(issues, source, phase) {
|
|
70
|
+
throw new Exception({
|
|
71
|
+
layer: ExceptionLayers.UseCase,
|
|
72
|
+
name: phase === "input" ? "InvalidUseCaseInput" : phase === "context" ? "InvalidUseCaseContext" : "InvalidUseCaseResponse",
|
|
73
|
+
source,
|
|
74
|
+
message: `Invalid UseCase ${phase}${issuesSummaryOf(issues)}`,
|
|
75
|
+
details: { issues },
|
|
76
|
+
cause: issues.find((issue) => issue.cause)?.cause
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function collectEvents(blueprint, value, events) {
|
|
80
|
+
const visited = new WeakSet;
|
|
81
|
+
const visit = (field, current) => {
|
|
82
|
+
if (typeof current !== "object" || current === null || visited.has(current))
|
|
83
|
+
return;
|
|
84
|
+
visited.add(current);
|
|
85
|
+
if (isEntity(current))
|
|
86
|
+
events.push(...current.pullEvents());
|
|
87
|
+
if (isBlueprintList(field)) {
|
|
88
|
+
for (const item of current)
|
|
89
|
+
visit(field.item, item);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const shape = isBlueprint(field) ? field : isBlueprintVariant(field) ? isRecordClass(current.constructor) ? current.constructor.blueprint : variantOfValue(field, current) : recordFieldOf(field)?.record.blueprint;
|
|
93
|
+
if (!shape)
|
|
94
|
+
return;
|
|
95
|
+
for (const [key, child] of Object.entries(shape.properties)) {
|
|
96
|
+
visit(child, current[key]);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
visit(blueprint, value);
|
|
100
|
+
}
|
|
101
|
+
function pullEntities(value, Entity, events) {
|
|
102
|
+
for (const item of Array.isArray(value) ? value : [value]) {
|
|
103
|
+
if (isEntity(item) && item instanceof Entity) {
|
|
104
|
+
events.push(...item.pullEvents());
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function methodNamesOf(repository) {
|
|
109
|
+
const names = new Set;
|
|
110
|
+
for (let current = repository;current !== null && current !== AbstractRepository.prototype && current !== Object.prototype; current = Object.getPrototypeOf(current)) {
|
|
111
|
+
for (const name of Object.getOwnPropertyNames(current)) {
|
|
112
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, name);
|
|
113
|
+
if (name !== "constructor" && typeof descriptor?.value === "function") {
|
|
114
|
+
names.add(name);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return [...names];
|
|
119
|
+
}
|
|
120
|
+
function traceUseCase(tracer, state, source) {
|
|
121
|
+
const span = startSpan(tracer, `use-case ${source}`, { "afora.use_case": source }, state.scope?.span);
|
|
122
|
+
if (span === undefined)
|
|
123
|
+
return;
|
|
124
|
+
state.tracer = tracer;
|
|
125
|
+
state.span = span;
|
|
126
|
+
state.childScope = {
|
|
127
|
+
...state.scope,
|
|
128
|
+
providers: state.scope?.providers ?? new Map,
|
|
129
|
+
tracer,
|
|
130
|
+
span
|
|
131
|
+
};
|
|
132
|
+
return span;
|
|
133
|
+
}
|
|
134
|
+
function untrace(state) {
|
|
135
|
+
state.tracer = undefined;
|
|
136
|
+
state.span = undefined;
|
|
137
|
+
state.childScope = undefined;
|
|
138
|
+
}
|
|
139
|
+
async function tracedRepositoryCall(tracer, parent, repository, method, useCase, run) {
|
|
140
|
+
const span = startSpan(tracer, `repository ${repository}.${method}`, {
|
|
141
|
+
"afora.repository": repository,
|
|
142
|
+
"afora.method": method,
|
|
143
|
+
"afora.use_case": useCase
|
|
144
|
+
}, parent);
|
|
145
|
+
try {
|
|
146
|
+
const result = await (span === undefined ? run(undefined) : runInSpan(tracer, span, () => run(span)));
|
|
147
|
+
endSpan(span);
|
|
148
|
+
return result;
|
|
149
|
+
} catch (error) {
|
|
150
|
+
failSpan(span, error, ExceptionLayers.Repository);
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function bindRepository(repository, overrides, state, source) {
|
|
155
|
+
const Entity = repository.entity;
|
|
156
|
+
const repositoryName = recordNameOf(Entity);
|
|
157
|
+
const bound = Object.create(null);
|
|
158
|
+
const view = new Proxy(Object.create(repository), {
|
|
159
|
+
get: (_target, key, receiver) => {
|
|
160
|
+
if (typeof key === "string" && Object.hasOwn(bound, key)) {
|
|
161
|
+
return bound[key];
|
|
162
|
+
}
|
|
163
|
+
if (key === ScopeKey)
|
|
164
|
+
return state.scope;
|
|
165
|
+
const value = Reflect.get(repository, key, receiver);
|
|
166
|
+
return key === "provider" && state.scope ? state.scope.providers.get(value) ?? value : value;
|
|
167
|
+
},
|
|
168
|
+
set: (_target, key, value) => Reflect.set(repository, key, value),
|
|
169
|
+
defineProperty: (_target, key, descriptor) => Reflect.defineProperty(repository, key, descriptor),
|
|
170
|
+
deleteProperty: (_target, key) => Reflect.deleteProperty(repository, key)
|
|
171
|
+
});
|
|
172
|
+
const calls = Object.create(null);
|
|
173
|
+
const nestedView = (span) => new Proxy(view, {
|
|
174
|
+
get: (_target, key, receiver) => typeof key === "string" && Object.hasOwn(calls, key) ? (...args) => calls[key](args, span) : Reflect.get(view, key, receiver)
|
|
175
|
+
});
|
|
176
|
+
const bind = (target, name, receiver) => {
|
|
177
|
+
const method = target[name];
|
|
178
|
+
const call = async (args, parent) => {
|
|
179
|
+
if (!state.active)
|
|
180
|
+
throw new InvalidUseCaseDependencies({ source });
|
|
181
|
+
const started = clock();
|
|
182
|
+
const result = parent === undefined ? await method.apply(receiver, args) : await tracedRepositoryCall(state.tracer, parent, repositoryName, name, source, (span) => method.apply(span !== undefined && receiver === view ? nestedView(span) : receiver, args));
|
|
183
|
+
writeLog(loggerOfCall(state), "debug", "repository", {
|
|
184
|
+
repository: repositoryName,
|
|
185
|
+
method: name,
|
|
186
|
+
useCase: source,
|
|
187
|
+
ms: elapsed(started)
|
|
188
|
+
});
|
|
189
|
+
for (const arg of args)
|
|
190
|
+
pullEntities(arg, Entity, state.events);
|
|
191
|
+
pullEntities(result, Entity, state.events);
|
|
192
|
+
return result;
|
|
193
|
+
};
|
|
194
|
+
calls[name] = call;
|
|
195
|
+
bound[name] = (...args) => call(args, state.span);
|
|
196
|
+
};
|
|
197
|
+
for (const name of methodNamesOf(repository))
|
|
198
|
+
bind(repository, name, view);
|
|
199
|
+
if (overrides) {
|
|
200
|
+
for (const name of new Set([
|
|
201
|
+
...methodNamesOf(repository),
|
|
202
|
+
...methodNamesOf(overrides)
|
|
203
|
+
])) {
|
|
204
|
+
if (typeof overrides[name] === "function") {
|
|
205
|
+
bind(overrides, name, overrides);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
bound.entity = Entity;
|
|
210
|
+
bound.actions = repository.actions;
|
|
211
|
+
return Object.freeze(bound);
|
|
212
|
+
}
|
|
213
|
+
function narrowedContext(Child, parent) {
|
|
214
|
+
if (!Child.context || parent === undefined)
|
|
215
|
+
return;
|
|
216
|
+
const picked = {};
|
|
217
|
+
for (const key of Object.keys(Child.context.properties)) {
|
|
218
|
+
if (Object.hasOwn(parent, key)) {
|
|
219
|
+
picked[key] = parent[key];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return picked;
|
|
223
|
+
}
|
|
224
|
+
function isOverrideOf(dependency, value) {
|
|
225
|
+
if (isLoggerDeclaration(dependency))
|
|
226
|
+
return isLogger(value);
|
|
227
|
+
if (isRepository(dependency) || isEnvironment(dependency)) {
|
|
228
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
229
|
+
}
|
|
230
|
+
return typeof value === "function";
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export class AbstractUseCase {
|
|
234
|
+
input;
|
|
235
|
+
constructor(input, ...args) {
|
|
236
|
+
const declaration = this.constructor;
|
|
237
|
+
const source = declaration.useCaseName;
|
|
238
|
+
const parsed = declaration.blueprint.safeParse(input);
|
|
239
|
+
if (parsed.issues)
|
|
240
|
+
invalidValue(parsed.issues, source, "input");
|
|
241
|
+
this.input = parsed.value;
|
|
242
|
+
const options = args[0];
|
|
243
|
+
const scope = options?.[ScopeKey];
|
|
244
|
+
let context;
|
|
245
|
+
if (declaration.context) {
|
|
246
|
+
const checked = declaration.context.safeParse(options?.context);
|
|
247
|
+
if (checked.issues)
|
|
248
|
+
invalidValue(checked.issues, source, "context");
|
|
249
|
+
context = Object.freeze(checked.value);
|
|
250
|
+
}
|
|
251
|
+
Object.defineProperty(this, "context", {
|
|
252
|
+
value: context,
|
|
253
|
+
enumerable: true
|
|
254
|
+
});
|
|
255
|
+
Object.defineProperty(this, "input", {
|
|
256
|
+
writable: false,
|
|
257
|
+
configurable: false
|
|
258
|
+
});
|
|
259
|
+
const implementation = this.execute;
|
|
260
|
+
if (typeof implementation !== "function") {
|
|
261
|
+
throw new InvalidUseCaseDeclaration({
|
|
262
|
+
source,
|
|
263
|
+
details: { reason: "Implement execute as a prototype method." }
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
const state = {
|
|
267
|
+
context,
|
|
268
|
+
scope,
|
|
269
|
+
started: false,
|
|
270
|
+
active: false,
|
|
271
|
+
events: [],
|
|
272
|
+
dependencies: Object.create(null),
|
|
273
|
+
owner: this.constructor
|
|
274
|
+
};
|
|
275
|
+
states.set(this, state);
|
|
276
|
+
for (const [key, dependency] of Object.entries(declaration.dependencies)) {
|
|
277
|
+
if (isRepository(dependency)) {
|
|
278
|
+
state.dependencies[key] = bindRepository(dependency, undefined, state, source);
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (isLoggerDeclaration(dependency)) {
|
|
282
|
+
Object.defineProperty(state.dependencies, key, {
|
|
283
|
+
get: () => loggerOfCall(state) ?? silentLogger,
|
|
284
|
+
enumerable: true
|
|
285
|
+
});
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (isEnvironment(dependency)) {
|
|
289
|
+
Object.defineProperty(state.dependencies, key, {
|
|
290
|
+
get: () => state.scope?.environments?.get(dependency) ?? dependency.load(),
|
|
291
|
+
enumerable: true
|
|
292
|
+
});
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
const Child = dependency;
|
|
296
|
+
state.dependencies[key] = async (value) => {
|
|
297
|
+
if (!state.active)
|
|
298
|
+
throw new InvalidUseCaseDependencies({ source });
|
|
299
|
+
const child = new Child(value, {
|
|
300
|
+
context: narrowedContext(Child, state.context),
|
|
301
|
+
[ScopeKey]: state.childScope ?? state.scope
|
|
302
|
+
});
|
|
303
|
+
try {
|
|
304
|
+
return await child.execute();
|
|
305
|
+
} finally {
|
|
306
|
+
state.events.push(...child.pullEvents());
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
Object.freeze(state.dependencies);
|
|
311
|
+
Object.defineProperty(this, "execute", {
|
|
312
|
+
value: async (overrides = {}) => {
|
|
313
|
+
if (state.started)
|
|
314
|
+
throw new UseCaseAlreadyExecuted({ source });
|
|
315
|
+
state.started = true;
|
|
316
|
+
const tracer = resolveTracer(state.scope?.tracer, state.owner);
|
|
317
|
+
const span = tracer === undefined ? undefined : traceUseCase(tracer, state, source);
|
|
318
|
+
try {
|
|
319
|
+
if (typeof overrides !== "object" || overrides === null || Array.isArray(overrides) || Reflect.ownKeys(overrides).some((key) => typeof key !== "string" || !Object.hasOwn(declaration.dependencies, key) || !isOverrideOf(declaration.dependencies[key], overrides[key]))) {
|
|
320
|
+
throw new InvalidUseCaseDependencies({ source });
|
|
321
|
+
}
|
|
322
|
+
const replaced = overrides;
|
|
323
|
+
const dependencies = {};
|
|
324
|
+
for (const key of Object.keys(declaration.dependencies)) {
|
|
325
|
+
if (!Object.hasOwn(replaced, key)) {
|
|
326
|
+
dependencies[key] = state.dependencies[key];
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
for (const [key, substitute] of Object.entries(replaced)) {
|
|
330
|
+
const dependency = declaration.dependencies[key];
|
|
331
|
+
if (isRepository(dependency)) {
|
|
332
|
+
dependencies[key] = bindRepository(dependency, substitute, state, source);
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (isLoggerDeclaration(dependency)) {
|
|
336
|
+
dependencies[key] = substitute;
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (isEnvironment(dependency)) {
|
|
340
|
+
const parsed = dependency.blueprint.safeParse(substitute);
|
|
341
|
+
if (parsed.issues)
|
|
342
|
+
throw new InvalidUseCaseDependencies({ source });
|
|
343
|
+
dependencies[key] = Object.freeze(parsed.value);
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
const Child = dependency;
|
|
347
|
+
dependencies[key] = async (value) => {
|
|
348
|
+
if (!state.active)
|
|
349
|
+
throw new InvalidUseCaseDependencies({ source });
|
|
350
|
+
const childSource = Child.useCaseName;
|
|
351
|
+
const input = Child.blueprint.safeParse(value);
|
|
352
|
+
if (input.issues)
|
|
353
|
+
invalidValue(input.issues, childSource, "input");
|
|
354
|
+
const output = Child.response.safeParse(await guard({ layer: ExceptionLayers.UseCase, source: childSource }, () => substitute(input.value)));
|
|
355
|
+
if (output.issues)
|
|
356
|
+
invalidValue(output.issues, childSource, "response");
|
|
357
|
+
collectEvents(Child.response, output.value, state.events);
|
|
358
|
+
return output.value;
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
state.resolved = Object.freeze(dependencies);
|
|
362
|
+
} catch (error) {
|
|
363
|
+
if (tracer !== undefined) {
|
|
364
|
+
failSpan(span, error, ExceptionLayers.UseCase);
|
|
365
|
+
untrace(state);
|
|
366
|
+
}
|
|
367
|
+
throw error;
|
|
368
|
+
}
|
|
369
|
+
state.active = true;
|
|
370
|
+
const started = clock();
|
|
371
|
+
try {
|
|
372
|
+
const result = await guard({ layer: ExceptionLayers.UseCase, source }, () => span === undefined ? implementation.call(this, state.resolved) : runInSpan(tracer, span, () => implementation.call(this, state.resolved)));
|
|
373
|
+
const parsed = declaration.response.safeParse(result);
|
|
374
|
+
if (parsed.issues)
|
|
375
|
+
invalidValue(parsed.issues, source, "response");
|
|
376
|
+
collectEvents(declaration.response, parsed.value, state.events);
|
|
377
|
+
writeLog(loggerOfCall(state), "debug", "use-case", {
|
|
378
|
+
useCase: source,
|
|
379
|
+
outcome: "ok",
|
|
380
|
+
ms: elapsed(started)
|
|
381
|
+
});
|
|
382
|
+
endSpan(span);
|
|
383
|
+
return parsed.value;
|
|
384
|
+
} catch (error) {
|
|
385
|
+
logFailure(loggerOfCall(state), "use-case-failed", { useCase: source, ms: elapsed(started) }, error);
|
|
386
|
+
failSpan(span, error, ExceptionLayers.UseCase);
|
|
387
|
+
throw error;
|
|
388
|
+
} finally {
|
|
389
|
+
state.active = false;
|
|
390
|
+
state.resolved = undefined;
|
|
391
|
+
if (tracer !== undefined)
|
|
392
|
+
untrace(state);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
get dependencies() {
|
|
398
|
+
const state = states.get(this);
|
|
399
|
+
return state?.resolved ?? state?.dependencies;
|
|
400
|
+
}
|
|
401
|
+
pullEvents() {
|
|
402
|
+
return states.get(this)?.events.splice(0) ?? [];
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
export function useCaseOf(settings) {
|
|
406
|
+
const { name, blueprint, response, context } = settings;
|
|
407
|
+
const { description, deprecated = false } = settings;
|
|
408
|
+
const tags = settings.tags === undefined ? [] : settings.tags;
|
|
409
|
+
const errors = settings.errors === undefined ? [] : settings.errors;
|
|
410
|
+
const dependencies = settings.dependencies === undefined ? {} : settings.dependencies;
|
|
411
|
+
if (typeof name !== "string" || !name.trim() || !isBlueprint(blueprint) || blueprint.optional || !isBlueprint(response) || response.optional || typeof dependencies !== "object" || dependencies === null || Array.isArray(dependencies) || Reflect.ownKeys(dependencies).some((key) => typeof key !== "string" || !isDependency(dependencies[key]))) {
|
|
412
|
+
throw new InvalidUseCaseDeclaration({
|
|
413
|
+
source: typeof name === "string" ? name : "useCaseOf",
|
|
414
|
+
details: {
|
|
415
|
+
reason: "Expected a name, input and response blueprints, and UseCase classes, repositories, environments or Logger as dependencies."
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
const invalidSetting = (reason) => {
|
|
420
|
+
throw new InvalidUseCaseDeclaration({ source: name, details: { reason } });
|
|
421
|
+
};
|
|
422
|
+
if (context !== undefined && (!isBlueprint(context) || context.optional)) {
|
|
423
|
+
invalidSetting("Expected context to be a non-optional blueprint.");
|
|
424
|
+
}
|
|
425
|
+
if (description !== undefined && typeof description !== "string") {
|
|
426
|
+
invalidSetting("Expected description to be a string.");
|
|
427
|
+
}
|
|
428
|
+
if (typeof deprecated !== "boolean") {
|
|
429
|
+
invalidSetting("Expected deprecated to be a boolean.");
|
|
430
|
+
}
|
|
431
|
+
if (settings.strictSteps !== undefined && typeof settings.strictSteps !== "boolean") {
|
|
432
|
+
invalidSetting("Expected strictSteps to be a boolean.");
|
|
433
|
+
}
|
|
434
|
+
if (!Array.isArray(tags) || tags.some((tag) => typeof tag !== "string" || tag === "") || new Set(tags).size !== tags.length) {
|
|
435
|
+
invalidSetting("Expected tags to be distinct, non-empty strings.");
|
|
436
|
+
}
|
|
437
|
+
if (!Array.isArray(errors) || !errors.every(isDeclaredException) || new Set(errors).size !== errors.length) {
|
|
438
|
+
invalidSetting("Expected errors to be distinct classes made by exceptionOf.");
|
|
439
|
+
}
|
|
440
|
+
let route;
|
|
441
|
+
if (settings.route !== undefined) {
|
|
442
|
+
const declared = routeDeclarationOf(settings.route, blueprint, response);
|
|
443
|
+
route = typeof declared === "string" ? invalidSetting(declared) : declared;
|
|
444
|
+
}
|
|
445
|
+
let access;
|
|
446
|
+
if (settings.access !== undefined) {
|
|
447
|
+
const declared = accessDeclarationOf(settings.access, blueprint);
|
|
448
|
+
access = typeof declared === "string" ? invalidSetting(declared) : declared;
|
|
449
|
+
}
|
|
450
|
+
if (settings.steps !== undefined) {
|
|
451
|
+
validateSteps({ name, blueprint, context, dependencies, errors }, settings.steps);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
class DeclaredUseCase extends AbstractUseCase {
|
|
455
|
+
static [Kind] = "use-case";
|
|
456
|
+
static useCaseName = name;
|
|
457
|
+
static blueprint = blueprint;
|
|
458
|
+
static response = response;
|
|
459
|
+
static dependencies = Object.freeze({
|
|
460
|
+
...dependencies
|
|
461
|
+
});
|
|
462
|
+
static context = context;
|
|
463
|
+
static description = description;
|
|
464
|
+
static tags = Object.freeze([...tags]);
|
|
465
|
+
static deprecated = deprecated;
|
|
466
|
+
static errors = Object.freeze([
|
|
467
|
+
...errors
|
|
468
|
+
]);
|
|
469
|
+
static route = route;
|
|
470
|
+
static access = access;
|
|
471
|
+
}
|
|
472
|
+
Object.defineProperty(DeclaredUseCase, "name", { value: name });
|
|
473
|
+
if (settings.steps !== undefined) {
|
|
474
|
+
Object.defineProperty(DeclaredUseCase, "steps", {
|
|
475
|
+
value: freezeData(settings.steps)
|
|
476
|
+
});
|
|
477
|
+
Object.defineProperty(DeclaredUseCase.prototype, "execute", {
|
|
478
|
+
value: executeSteps,
|
|
479
|
+
writable: true,
|
|
480
|
+
configurable: true
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
return DeclaredUseCase;
|
|
484
|
+
}
|
|
485
|
+
function isDependency(value) {
|
|
486
|
+
return isUseCaseClass(value) || isRepository(value) || isEnvironment(value) || isLoggerDeclaration(value);
|
|
487
|
+
}
|
|
488
|
+
export function isUseCaseClass(value) {
|
|
489
|
+
return typeof value === "function" && value.prototype instanceof AbstractUseCase && value[Kind] === "use-case" && typeof value.prototype.execute === "function";
|
|
490
|
+
}
|
|
491
|
+
export function isUseCase(value) {
|
|
492
|
+
return value instanceof AbstractUseCase;
|
|
493
|
+
}
|
package/dist/experimental.d.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `@afora/core/experimental`: features that may change in any release. Not
|
|
3
|
-
* covered by the compatibility policy in `VERSIONING.md`.
|
|
3
|
+
* covered by the compatibility policy in `VERSIONING.md`. See
|
|
4
|
+
* `docs/api-tiers.md`.
|
|
4
5
|
*/
|
|
6
|
+
export { InvalidJwtOptions, jwtOf } from "./core/auth/jwt.js";
|
|
7
|
+
export type { DescribedJwtOptions, Jwt, JwtAlgorithm, JwtOptions, JwtSubject, JwtTokenOptions, } from "./core/auth/types/jwt.interface.js";
|
|
5
8
|
export { sliceOf, sliceValue } from "./core/blueprint/slice.js";
|
|
6
9
|
export type { SlicedBlueprint, SlicedValue, SliceMask, ValueMask, } from "./core/blueprint/types/slice.interface.js";
|
|
10
|
+
export { eventPolicyCatalogOf, eventPolicyDescriptionOf, } from "./core/event-policy/event-policy.js";
|
|
11
|
+
export { stageDescriptionOf } from "./core/output/stage.js";
|
|
12
|
+
export { type PropertyLineage, propertyLineageOf, } from "./core/property/lineage.js";
|
|
13
|
+
export { providerDescriptionOf } from "./core/repository/provider.js";
|
|
14
|
+
export { matchesQuery, prepareQuery, sameValue, selectRows, } from "./core/repository/query.js";
|
|
15
|
+
export { useCaseOriginOf } from "./core/use-case/plugin.js";
|
|
16
|
+
export { useCaseTargetOf } from "./core/use-case/target.js";
|
|
17
|
+
export type { UseCaseOriginInfo } from "./core/use-case/types/plugin.interface.js";
|
|
18
|
+
export type { StdTokenOptions } from "./std/use-cases/types.js";
|
|
19
|
+
export type { EntityStorageSettings } from "./core/entity/types/entity.interface.js";
|
|
20
|
+
export type { AbstractPropertyConstructor } from "./core/property/types/abstract-property-constructor.type.js";
|
|
21
|
+
export type { IPropertyCollection } from "./core/property/types/property-collection.type.js";
|
|
22
|
+
export type { RepositoryExists, RepositoryExplain, RepositoryFindCursor, RepositoryFindMany, RepositoryFindPage, RepositoryForEachPage, } from "./core/repository/types/query.interface.js";
|
|
23
|
+
export type { RepositoryCount, RepositoryCreate, RepositoryDelete, RepositoryIncrement, RepositoryRestore, RepositoryUpdate, } from "./core/repository/types/repository.interface.js";
|
package/dist/experimental.js
CHANGED
|
@@ -1,124 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
isRecordClass2,
|
|
4
|
-
recordFieldOf2,
|
|
5
|
-
recordNameOf2,
|
|
6
|
-
listOf2,
|
|
7
|
-
isBlueprintList2,
|
|
8
|
-
AbstractRecord2,
|
|
9
|
-
UndeclaredBlueprintProperty2,
|
|
10
|
-
optionalOf2,
|
|
11
|
-
blueprintFromProperties,
|
|
12
|
-
declareRecord
|
|
13
|
-
} from "./index-qxfkyd6k.js";
|
|
14
|
-
|
|
15
|
-
// src/core/blueprint/slice.ts
|
|
16
|
-
function propertiesOfField(field) {
|
|
17
|
-
if (field === undefined)
|
|
18
|
-
return;
|
|
19
|
-
if (isBlueprintList2(field))
|
|
20
|
-
return propertiesOfField(field.item);
|
|
21
|
-
const record = recordFieldOf2(field);
|
|
22
|
-
if (record)
|
|
23
|
-
return record.record.blueprint.properties;
|
|
24
|
-
return isBlueprint2(field) ? field.properties : undefined;
|
|
25
|
-
}
|
|
26
|
-
function maskOf(selector, against) {
|
|
27
|
-
if (isRecordClass2(selector))
|
|
28
|
-
return maskOf(selector.blueprint, against);
|
|
29
|
-
if (isBlueprint2(selector)) {
|
|
30
|
-
return Object.fromEntries(Object.entries(selector.properties).map(([key, field]) => [key, fieldMaskOf(field, against?.[key])]));
|
|
31
|
-
}
|
|
32
|
-
return selector;
|
|
33
|
-
}
|
|
34
|
-
function fieldMaskOf(field, other) {
|
|
35
|
-
if (isBlueprintList2(field)) {
|
|
36
|
-
return fieldMaskOf(field.item, isBlueprintList2(other) ? other.item : other);
|
|
37
|
-
}
|
|
38
|
-
const record = recordFieldOf2(field);
|
|
39
|
-
if (record) {
|
|
40
|
-
if (record.record === recordFieldOf2(other)?.record)
|
|
41
|
-
return true;
|
|
42
|
-
return maskOf(record.record, propertiesOfField(other));
|
|
43
|
-
}
|
|
44
|
-
if (isBlueprint2(field)) {
|
|
45
|
-
return field === other ? true : maskOf(field, propertiesOfField(other));
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
function sliceCollection(properties, mask, path) {
|
|
50
|
-
const sliced = {};
|
|
51
|
-
for (const [key, selected] of Object.entries(mask)) {
|
|
52
|
-
if (!selected)
|
|
53
|
-
continue;
|
|
54
|
-
if (!Object.hasOwn(properties, key)) {
|
|
55
|
-
throw new UndeclaredBlueprintProperty2({
|
|
56
|
-
source: "blueprint",
|
|
57
|
-
details: { key: path + key }
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
sliced[key] = sliceField(properties[key], selected, path + key);
|
|
61
|
-
}
|
|
62
|
-
return sliced;
|
|
63
|
-
}
|
|
64
|
-
function slicedRecordOf(Original, mask, path) {
|
|
65
|
-
const source = Original.blueprint;
|
|
66
|
-
const blueprint = blueprintFromProperties(source.plugins, sliceCollection(source.properties, mask, `${path}.`));
|
|
67
|
-
const kept = (keys) => keys.filter((key) => Object.hasOwn(blueprint.properties, key));
|
|
68
|
-
const { sensitive, unique, change } = Original.options;
|
|
69
|
-
const Sliced = declareRecord(AbstractRecord2, blueprint, {
|
|
70
|
-
sensitive: kept(sensitive),
|
|
71
|
-
unique: kept(unique),
|
|
72
|
-
change: kept(change)
|
|
73
|
-
}, recordNameOf2(Original));
|
|
74
|
-
Object.defineProperty(Sliced, Symbol.hasInstance, {
|
|
75
|
-
value(value) {
|
|
76
|
-
return Function.prototype[Symbol.hasInstance].call(this, value) || value instanceof Original;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
return Sliced;
|
|
80
|
-
}
|
|
81
|
-
function sliceField(field, selected, path) {
|
|
82
|
-
if (selected === true)
|
|
83
|
-
return field;
|
|
84
|
-
if (isBlueprintList2(field)) {
|
|
85
|
-
const list = listOf2(sliceField(field.item, selected, path), {
|
|
86
|
-
minItems: field.minItems,
|
|
87
|
-
maxItems: field.maxItems
|
|
88
|
-
});
|
|
89
|
-
return field.optional ? optionalOf2(list) : list;
|
|
90
|
-
}
|
|
91
|
-
const record = recordFieldOf2(field);
|
|
92
|
-
if (record) {
|
|
93
|
-
const sliced = slicedRecordOf(record.record, selected, path);
|
|
94
|
-
return record.optional ? optionalOf2(sliced) : sliced;
|
|
95
|
-
}
|
|
96
|
-
if (isBlueprint2(field)) {
|
|
97
|
-
const sliced = blueprintFromProperties(field.plugins, sliceCollection(field.properties, selected, `${path}.`));
|
|
98
|
-
return field.optional ? optionalOf2(sliced) : sliced;
|
|
99
|
-
}
|
|
100
|
-
throw new UndeclaredBlueprintProperty2({
|
|
101
|
-
source: "blueprint",
|
|
102
|
-
details: { key: `${path}.${Object.keys(selected)[0] ?? ""}` }
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
var sliceOf = (blueprint, selector) => blueprintFromProperties(blueprint.plugins, sliceCollection(blueprint.properties, maskOf(selector, blueprint.properties), ""));
|
|
106
|
-
var sliceValue = (value, selector) => pick(value, maskOf(selector));
|
|
107
|
-
function pick(value, mask) {
|
|
108
|
-
if (Array.isArray(value))
|
|
109
|
-
return value.map((item) => pick(item, mask));
|
|
110
|
-
if (typeof value !== "object" || value === null)
|
|
111
|
-
return value;
|
|
112
|
-
const source = isRecordClass2(value.constructor) ? value.toJSON() : value;
|
|
113
|
-
const picked = {};
|
|
114
|
-
for (const [key, selected] of Object.entries(mask)) {
|
|
115
|
-
if (!selected || !Object.hasOwn(source, key))
|
|
116
|
-
continue;
|
|
117
|
-
picked[key] = selected === true ? source[key] : pick(source[key], selected);
|
|
118
|
-
}
|
|
119
|
-
return picked;
|
|
120
|
-
}
|
|
1
|
+
export { InvalidJwtOptions, jwtOf } from "./core/auth/jwt.js";
|
|
2
|
+
export { sliceOf, sliceValue } from "./core/blueprint/slice.js";
|
|
121
3
|
export {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
};
|
|
4
|
+
eventPolicyCatalogOf,
|
|
5
|
+
eventPolicyDescriptionOf
|
|
6
|
+
} from "./core/event-policy/event-policy.js";
|
|
7
|
+
export { stageDescriptionOf } from "./core/output/stage.js";
|
|
8
|
+
export {
|
|
9
|
+
propertyLineageOf
|
|
10
|
+
} from "./core/property/lineage.js";
|
|
11
|
+
export { providerDescriptionOf } from "./core/repository/provider.js";
|
|
12
|
+
export {
|
|
13
|
+
matchesQuery,
|
|
14
|
+
prepareQuery,
|
|
15
|
+
sameValue,
|
|
16
|
+
selectRows
|
|
17
|
+
} from "./core/repository/query.js";
|
|
18
|
+
export { useCaseOriginOf } from "./core/use-case/plugin.js";
|
|
19
|
+
export { useCaseTargetOf } from "./core/use-case/target.js";
|