@solidactions/sdk 0.1.0
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/.claude/settings.local.json +7 -0
- package/.clavix/outputs/dbos-http-sdk/full-prd.md +142 -0
- package/.clavix/outputs/dbos-http-sdk/quick-prd.md +12 -0
- package/.clavix/outputs/dbos-http-sdk/tasks.md +630 -0
- package/.clavix/outputs/prompts/dbos-http-api-20260110-033219.md +91 -0
- package/.husky/pre-commit +1 -0
- package/.prettierignore +3 -0
- package/.prettierrc +9 -0
- package/CODE_OF_CONDUCT.md +49 -0
- package/CONTRIBUTING.md +47 -0
- package/LICENSE +21 -0
- package/README.md +172 -0
- package/dist/dbos-config.schema.json +132 -0
- package/dist/schemas/system_db_schema.d.ts +73 -0
- package/dist/schemas/system_db_schema.d.ts.map +1 -0
- package/dist/schemas/system_db_schema.js +3 -0
- package/dist/schemas/system_db_schema.js.map +1 -0
- package/dist/src/adminserver.d.ts +79 -0
- package/dist/src/adminserver.d.ts.map +1 -0
- package/dist/src/adminserver.js +495 -0
- package/dist/src/adminserver.js.map +1 -0
- package/dist/src/authdecorators.d.ts +2 -0
- package/dist/src/authdecorators.d.ts.map +1 -0
- package/dist/src/authdecorators.js +48 -0
- package/dist/src/authdecorators.js.map +1 -0
- package/dist/src/cli/cli.d.ts +9 -0
- package/dist/src/cli/cli.d.ts.map +1 -0
- package/dist/src/cli/cli.js +116 -0
- package/dist/src/cli/cli.js.map +1 -0
- package/dist/src/cli/commands.d.ts +3 -0
- package/dist/src/cli/commands.d.ts.map +1 -0
- package/dist/src/cli/commands.js +46 -0
- package/dist/src/cli/commands.js.map +1 -0
- package/dist/src/client.d.ts +85 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +186 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/conductor/conductor.d.ts +28 -0
- package/dist/src/conductor/conductor.d.ts.map +1 -0
- package/dist/src/conductor/conductor.js +376 -0
- package/dist/src/conductor/conductor.js.map +1 -0
- package/dist/src/conductor/protocol.d.ts +238 -0
- package/dist/src/conductor/protocol.d.ts.map +1 -0
- package/dist/src/conductor/protocol.js +353 -0
- package/dist/src/conductor/protocol.js.map +1 -0
- package/dist/src/config.d.ts +91 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +199 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/context.d.ts +62 -0
- package/dist/src/context.d.ts.map +1 -0
- package/dist/src/context.js +118 -0
- package/dist/src/context.js.map +1 -0
- package/dist/src/database_utils.d.ts +17 -0
- package/dist/src/database_utils.d.ts.map +1 -0
- package/dist/src/database_utils.js +53 -0
- package/dist/src/database_utils.js.map +1 -0
- package/dist/src/datasource.d.ts +109 -0
- package/dist/src/datasource.d.ts.map +1 -0
- package/dist/src/datasource.js +204 -0
- package/dist/src/datasource.js.map +1 -0
- package/dist/src/dbos-executor.d.ts +189 -0
- package/dist/src/dbos-executor.d.ts.map +1 -0
- package/dist/src/dbos-executor.js +817 -0
- package/dist/src/dbos-executor.js.map +1 -0
- package/dist/src/dbos.d.ts +519 -0
- package/dist/src/dbos.d.ts.map +1 -0
- package/dist/src/dbos.js +1282 -0
- package/dist/src/dbos.js.map +1 -0
- package/dist/src/debouncer.d.ts +33 -0
- package/dist/src/debouncer.d.ts.map +1 -0
- package/dist/src/debouncer.js +170 -0
- package/dist/src/debouncer.js.map +1 -0
- package/dist/src/debugpoint.d.ts +26 -0
- package/dist/src/debugpoint.d.ts.map +1 -0
- package/dist/src/debugpoint.js +65 -0
- package/dist/src/debugpoint.js.map +1 -0
- package/dist/src/decorators.d.ts +219 -0
- package/dist/src/decorators.d.ts.map +1 -0
- package/dist/src/decorators.js +873 -0
- package/dist/src/decorators.js.map +1 -0
- package/dist/src/error.d.ts +130 -0
- package/dist/src/error.d.ts.map +1 -0
- package/dist/src/error.js +290 -0
- package/dist/src/error.js.map +1 -0
- package/dist/src/http_client.d.ts +82 -0
- package/dist/src/http_client.d.ts.map +1 -0
- package/dist/src/http_client.js +286 -0
- package/dist/src/http_client.js.map +1 -0
- package/dist/src/http_system_database.d.ts +84 -0
- package/dist/src/http_system_database.d.ts.map +1 -0
- package/dist/src/http_system_database.js +429 -0
- package/dist/src/http_system_database.js.map +1 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +53 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/scheduler/crontab.d.ts +14 -0
- package/dist/src/scheduler/crontab.d.ts.map +1 -0
- package/dist/src/scheduler/crontab.js +308 -0
- package/dist/src/scheduler/crontab.js.map +1 -0
- package/dist/src/scheduler/scheduler.d.ts +41 -0
- package/dist/src/scheduler/scheduler.d.ts.map +1 -0
- package/dist/src/scheduler/scheduler.js +165 -0
- package/dist/src/scheduler/scheduler.js.map +1 -0
- package/dist/src/serialization.d.ts +57 -0
- package/dist/src/serialization.d.ts.map +1 -0
- package/dist/src/serialization.js +306 -0
- package/dist/src/serialization.js.map +1 -0
- package/dist/src/solidactions-executor.d.ts +177 -0
- package/dist/src/solidactions-executor.d.ts.map +1 -0
- package/dist/src/solidactions-executor.js +817 -0
- package/dist/src/solidactions-executor.js.map +1 -0
- package/dist/src/solidactions.d.ts +519 -0
- package/dist/src/solidactions.d.ts.map +1 -0
- package/dist/src/solidactions.js +1284 -0
- package/dist/src/solidactions.js.map +1 -0
- package/dist/src/step.d.ts +16 -0
- package/dist/src/step.d.ts.map +1 -0
- package/dist/src/step.js +3 -0
- package/dist/src/step.js.map +1 -0
- package/dist/src/system_database.d.ts +141 -0
- package/dist/src/system_database.d.ts.map +1 -0
- package/dist/src/system_database.js +25 -0
- package/dist/src/system_database.js.map +1 -0
- package/dist/src/telemetry/collector.d.ts +13 -0
- package/dist/src/telemetry/collector.d.ts.map +1 -0
- package/dist/src/telemetry/collector.js +63 -0
- package/dist/src/telemetry/collector.js.map +1 -0
- package/dist/src/telemetry/exporters.d.ts +13 -0
- package/dist/src/telemetry/exporters.d.ts.map +1 -0
- package/dist/src/telemetry/exporters.js +101 -0
- package/dist/src/telemetry/exporters.js.map +1 -0
- package/dist/src/telemetry/logs.d.ts +52 -0
- package/dist/src/telemetry/logs.d.ts.map +1 -0
- package/dist/src/telemetry/logs.js +287 -0
- package/dist/src/telemetry/logs.js.map +1 -0
- package/dist/src/telemetry/traces.d.ts +52 -0
- package/dist/src/telemetry/traces.d.ts.map +1 -0
- package/dist/src/telemetry/traces.js +150 -0
- package/dist/src/telemetry/traces.js.map +1 -0
- package/dist/src/utils.d.ts +26 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +136 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/wfqueue.d.ts +64 -0
- package/dist/src/wfqueue.d.ts.map +1 -0
- package/dist/src/wfqueue.js +147 -0
- package/dist/src/wfqueue.js.map +1 -0
- package/dist/src/workflow.d.ts +154 -0
- package/dist/src/workflow.d.ts.map +1 -0
- package/dist/src/workflow.js +99 -0
- package/dist/src/workflow.js.map +1 -0
- package/dist/src/workflow_management.d.ts +15 -0
- package/dist/src/workflow_management.d.ts.map +1 -0
- package/dist/src/workflow_management.js +87 -0
- package/dist/src/workflow_management.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/api-schema.md +1441 -0
- package/docs/migration-guide.md +460 -0
- package/docs/phase-14-changes.md +156 -0
- package/docs/solidsteps-ai-prompt.md +534 -0
- package/eslint.config.cjs +50 -0
- package/package.json +84 -0
- package/solidactions-ai-prompt.md +1504 -0
- package/solidactions-config.schema.json +132 -0
- package/solidactions-test-config.yaml +15 -0
|
@@ -0,0 +1,873 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArgName = exports.getRegistrationsForExternal = exports.associateParameterWithExternal = exports.associateMethodWithExternal = exports.associateClassWithExternal = exports.finalizeClassRegistrations = exports.getConfiguredInstance = exports.getOrCreateClassRegistrationByTarget = exports.getClassRegistrationByName = exports.getAllRegisteredFunctions = exports.getAllRegisteredClassNames = exports.getClassRegistration = exports.getNameForClass = exports.wrapSolidActionsFunctionAndRegister = exports.wrapSolidActionsFunctionAndRegisterDec = exports.wrapSolidActionsFunctionAndRegisterByUniqueName = exports.wrapSolidActionsFunctionAndRegisterByTarget = exports.getOrCreateMethodArgsRegistration = exports.getRegisteredOperations = exports.getFunctionRegistrationByName = exports.getFunctionRegistration = exports.registerFunctionWrapper = exports.getRegisteredFunctionName = exports.getRegisteredFunctionClassName = exports.getRegisteredFunctionQualifiedName = exports.getRegisteredFunctionFullName = exports.insertAllMiddleware = exports.registerMiddlewareInstaller = exports.getLifecycleListeners = exports.registerLifecycleCallback = exports.ensureSolidActionsIsLaunched = exports.ensureSolidActionsIsNotLaunched = exports.recordSolidActionsShutdown = exports.recordSolidActionsLaunch = exports.ClassRegistration = exports.ConfiguredInstance = exports.MethodRegistration = exports.SOLIDACTIONS_AUTH = exports.MethodParameter = exports.SolidActionsDataType = void 0;
|
|
4
|
+
const error_1 = require("./error");
|
|
5
|
+
class SolidActionsDataType {
|
|
6
|
+
dataType = 'text';
|
|
7
|
+
length = -1;
|
|
8
|
+
precision = -1;
|
|
9
|
+
scale = -1;
|
|
10
|
+
/** Varchar has length */
|
|
11
|
+
static varchar(length) {
|
|
12
|
+
const dt = new SolidActionsDataType();
|
|
13
|
+
dt.dataType = 'varchar';
|
|
14
|
+
dt.length = length;
|
|
15
|
+
return dt;
|
|
16
|
+
}
|
|
17
|
+
/** Some decimal has precision / scale (as opposed to floating point decimal) */
|
|
18
|
+
static decimal(precision, scale) {
|
|
19
|
+
const dt = new SolidActionsDataType();
|
|
20
|
+
dt.dataType = 'decimal';
|
|
21
|
+
dt.precision = precision;
|
|
22
|
+
dt.scale = scale;
|
|
23
|
+
return dt;
|
|
24
|
+
}
|
|
25
|
+
/** Take type from reflect metadata */
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
27
|
+
static fromArg(arg) {
|
|
28
|
+
if (!arg)
|
|
29
|
+
return undefined;
|
|
30
|
+
const dt = new SolidActionsDataType();
|
|
31
|
+
if (arg === String) {
|
|
32
|
+
dt.dataType = 'text';
|
|
33
|
+
}
|
|
34
|
+
else if (arg === Date) {
|
|
35
|
+
dt.dataType = 'timestamp';
|
|
36
|
+
}
|
|
37
|
+
else if (arg === Number) {
|
|
38
|
+
dt.dataType = 'double';
|
|
39
|
+
}
|
|
40
|
+
else if (arg === Boolean) {
|
|
41
|
+
dt.dataType = 'boolean';
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
dt.dataType = 'json';
|
|
45
|
+
}
|
|
46
|
+
return dt;
|
|
47
|
+
}
|
|
48
|
+
formatAsString() {
|
|
49
|
+
let rv = this.dataType;
|
|
50
|
+
if (this.dataType === 'varchar' && this.length > 0) {
|
|
51
|
+
rv += `(${this.length})`;
|
|
52
|
+
}
|
|
53
|
+
if (this.dataType === 'decimal' && this.precision > 0) {
|
|
54
|
+
if (this.scale > 0) {
|
|
55
|
+
rv += `(${this.precision},${this.scale})`;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
rv += `(${this.precision})`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return rv;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.SolidActionsDataType = SolidActionsDataType;
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
66
|
+
function getArgNames(func) {
|
|
67
|
+
const fstr = func.toString();
|
|
68
|
+
const args = [];
|
|
69
|
+
let currentArgName = '';
|
|
70
|
+
let nestDepth = 0;
|
|
71
|
+
let inSingleQuote = false;
|
|
72
|
+
let inDoubleQuote = false;
|
|
73
|
+
let inBacktick = false;
|
|
74
|
+
let inComment = false;
|
|
75
|
+
let inBlockComment = false;
|
|
76
|
+
let inDefaultValue = false;
|
|
77
|
+
// Extract parameter list from function signature
|
|
78
|
+
const paramStart = fstr.indexOf('(');
|
|
79
|
+
if (paramStart === -1)
|
|
80
|
+
return [];
|
|
81
|
+
const paramStr = fstr.substring(paramStart + 1);
|
|
82
|
+
for (let i = 0; i < paramStr.length; i++) {
|
|
83
|
+
const char = paramStr[i];
|
|
84
|
+
const nextChar = paramStr[i + 1];
|
|
85
|
+
// Handle comments
|
|
86
|
+
if (inBlockComment) {
|
|
87
|
+
if (char === '*' && nextChar === '/') {
|
|
88
|
+
inBlockComment = false;
|
|
89
|
+
i++; // Skip closing '/'
|
|
90
|
+
}
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
else if (inComment) {
|
|
94
|
+
if (char === '\n')
|
|
95
|
+
inComment = false;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
else if (char === '/' && nextChar === '*') {
|
|
99
|
+
inBlockComment = true;
|
|
100
|
+
i++;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
else if (char === '/' && nextChar === '/') {
|
|
104
|
+
inComment = true;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (inComment || inBlockComment)
|
|
108
|
+
continue;
|
|
109
|
+
// Handle quotes (for default values)
|
|
110
|
+
if (char === "'" && !inDoubleQuote && !inBacktick) {
|
|
111
|
+
inSingleQuote = !inSingleQuote;
|
|
112
|
+
}
|
|
113
|
+
else if (char === '"' && !inSingleQuote && !inBacktick) {
|
|
114
|
+
inDoubleQuote = !inDoubleQuote;
|
|
115
|
+
}
|
|
116
|
+
else if (char === '`' && !inSingleQuote && !inDoubleQuote) {
|
|
117
|
+
inBacktick = !inBacktick;
|
|
118
|
+
}
|
|
119
|
+
// Skip anything inside quotes
|
|
120
|
+
if (inSingleQuote || inDoubleQuote || inBacktick) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
// Handle default values
|
|
124
|
+
if (char === '=' && nestDepth === 0) {
|
|
125
|
+
inDefaultValue = true;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
// These can mean default values. Or destructuring (which is a problem)...
|
|
129
|
+
if (char === '(' || char === '{' || char === '[') {
|
|
130
|
+
nestDepth++;
|
|
131
|
+
}
|
|
132
|
+
if (char === ')' || char === '}' || char === ']') {
|
|
133
|
+
if (nestDepth === 0)
|
|
134
|
+
break; // Done
|
|
135
|
+
nestDepth--;
|
|
136
|
+
}
|
|
137
|
+
// Handle rest parameters `...arg`; this is a problem.
|
|
138
|
+
if (char === '.' && nextChar === '.' && paramStr[i + 2] === '.') {
|
|
139
|
+
i += 2; // Skip the other dots
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
// Handle argument separators (`,`) at depth 0
|
|
143
|
+
if (char === ',' && nestDepth === 0) {
|
|
144
|
+
if (currentArgName.trim()) {
|
|
145
|
+
args.push(currentArgName.trim());
|
|
146
|
+
}
|
|
147
|
+
currentArgName = '';
|
|
148
|
+
inDefaultValue = false;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
// Add valid characters to the current argument
|
|
152
|
+
if (!inDefaultValue) {
|
|
153
|
+
currentArgName += char;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Push the last argument if it exists
|
|
157
|
+
if (currentArgName.trim()) {
|
|
158
|
+
if (currentArgName.trim()) {
|
|
159
|
+
args.push(currentArgName.trim());
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return args;
|
|
163
|
+
}
|
|
164
|
+
class MethodParameter {
|
|
165
|
+
name = '';
|
|
166
|
+
index = -1;
|
|
167
|
+
externalRegInfo = new Map();
|
|
168
|
+
getRegisteredInfo(reg) {
|
|
169
|
+
if (!this.externalRegInfo.has(reg)) {
|
|
170
|
+
this.externalRegInfo.set(reg, {});
|
|
171
|
+
}
|
|
172
|
+
return this.externalRegInfo.get(reg);
|
|
173
|
+
}
|
|
174
|
+
get dataType() {
|
|
175
|
+
return this.getRegisteredInfo('type').dataType;
|
|
176
|
+
}
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
178
|
+
initializeBaseType(at) {
|
|
179
|
+
if (!this.externalRegInfo.has('type')) {
|
|
180
|
+
this.externalRegInfo.set('type', {});
|
|
181
|
+
}
|
|
182
|
+
const adt = this.externalRegInfo.get('type');
|
|
183
|
+
adt.dataType = SolidActionsDataType.fromArg(at);
|
|
184
|
+
}
|
|
185
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
186
|
+
constructor(idx, at) {
|
|
187
|
+
this.index = idx;
|
|
188
|
+
this.initializeBaseType(at);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.MethodParameter = MethodParameter;
|
|
192
|
+
exports.SOLIDACTIONS_AUTH = 'auth';
|
|
193
|
+
class MethodRegistration {
|
|
194
|
+
defaults;
|
|
195
|
+
name = '';
|
|
196
|
+
className = '';
|
|
197
|
+
classReg;
|
|
198
|
+
// Interceptors
|
|
199
|
+
onEnter = [];
|
|
200
|
+
addEntryInterceptor(func, seqNum = 10) {
|
|
201
|
+
this.onEnter.push({ seqNum, func });
|
|
202
|
+
this.onEnter.sort((a, b) => a.seqNum - b.seqNum);
|
|
203
|
+
}
|
|
204
|
+
args = [];
|
|
205
|
+
constructor(classReg, origFunc, isInstance) {
|
|
206
|
+
this.classReg = classReg;
|
|
207
|
+
this.origFunction = origFunc;
|
|
208
|
+
this.isInstance = isInstance;
|
|
209
|
+
}
|
|
210
|
+
needInitialized = true;
|
|
211
|
+
isInstance;
|
|
212
|
+
origFunction;
|
|
213
|
+
registeredFunction;
|
|
214
|
+
wrappedFunction = undefined;
|
|
215
|
+
workflowConfig;
|
|
216
|
+
stepConfig;
|
|
217
|
+
regLocation;
|
|
218
|
+
externalRegInfo = new Map();
|
|
219
|
+
getRegisteredInfo(reg) {
|
|
220
|
+
if (!this.externalRegInfo.has(reg)) {
|
|
221
|
+
this.externalRegInfo.set(reg, {});
|
|
222
|
+
}
|
|
223
|
+
return this.externalRegInfo.get(reg);
|
|
224
|
+
}
|
|
225
|
+
getAssignedType() {
|
|
226
|
+
if (this.workflowConfig)
|
|
227
|
+
return 'Workflow';
|
|
228
|
+
if (this.stepConfig)
|
|
229
|
+
return 'Step';
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
getClassName() {
|
|
233
|
+
return this.className || this.classReg.getClassName();
|
|
234
|
+
}
|
|
235
|
+
checkFuncTypeUnassigned(newType) {
|
|
236
|
+
const oldType = this.getAssignedType();
|
|
237
|
+
let error = undefined;
|
|
238
|
+
if (oldType && newType !== oldType) {
|
|
239
|
+
error = `Operation (Name: ${this.getClassName()}.${this.name}) is already registered with a conflicting function type: ${oldType} vs. ${newType}`;
|
|
240
|
+
}
|
|
241
|
+
else if (oldType) {
|
|
242
|
+
error = `Operation (Name: ${this.getClassName()}.${this.name}) is already registered.`;
|
|
243
|
+
}
|
|
244
|
+
if (error) {
|
|
245
|
+
if (this.regLocation) {
|
|
246
|
+
error = error + `\nPrior registration occurred at:\n${this.regLocation.join('\n')}`;
|
|
247
|
+
}
|
|
248
|
+
throw new error_1.SolidActionsConflictingRegistrationError(`${error}`);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
this.regLocation = new StackGrabber().getCleanStack(3);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
setStepConfig(stepCfg) {
|
|
255
|
+
this.checkFuncTypeUnassigned('Step');
|
|
256
|
+
this.stepConfig = stepCfg;
|
|
257
|
+
}
|
|
258
|
+
setWorkflowConfig(wfCfg) {
|
|
259
|
+
this.checkFuncTypeUnassigned('Workflow');
|
|
260
|
+
this.workflowConfig = wfCfg;
|
|
261
|
+
}
|
|
262
|
+
init = false;
|
|
263
|
+
invoke(pthis, args) {
|
|
264
|
+
const f = this.wrappedFunction ?? this.registeredFunction ?? this.origFunction;
|
|
265
|
+
return f.call(pthis, ...args);
|
|
266
|
+
}
|
|
267
|
+
getRequiredRoles() {
|
|
268
|
+
const rr = this.getRegisteredInfo(exports.SOLIDACTIONS_AUTH);
|
|
269
|
+
if (rr?.requiredRole) {
|
|
270
|
+
return rr.requiredRole;
|
|
271
|
+
}
|
|
272
|
+
const drr = this.defaults?.getRegisteredInfo(exports.SOLIDACTIONS_AUTH);
|
|
273
|
+
return drr?.requiredRole || [];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exports.MethodRegistration = MethodRegistration;
|
|
277
|
+
class ConfiguredInstance {
|
|
278
|
+
name;
|
|
279
|
+
constructor(name) {
|
|
280
|
+
if (solidActionsLaunchPoint) {
|
|
281
|
+
console.warn(`ConfiguredInstance '${name}' is being created after SolidActions initialization and was not available for recovery.`);
|
|
282
|
+
}
|
|
283
|
+
this.name = name;
|
|
284
|
+
registerClassInstance(this, name);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Override this method to perform async initialization between construction and `SolidActions.launch()`.
|
|
288
|
+
*/
|
|
289
|
+
initialize() {
|
|
290
|
+
return Promise.resolve();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
exports.ConfiguredInstance = ConfiguredInstance;
|
|
294
|
+
class ClassRegistration {
|
|
295
|
+
name = '';
|
|
296
|
+
needsInitialized = true;
|
|
297
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
298
|
+
ormEntities = [];
|
|
299
|
+
registeredOperationsByName = new Map();
|
|
300
|
+
allRegisteredOperations = new Map();
|
|
301
|
+
configuredInstances = new Map();
|
|
302
|
+
configuredInstanceRegLocs = new Map();
|
|
303
|
+
externalRegInfo = new Map();
|
|
304
|
+
ctor;
|
|
305
|
+
constructor(ctor) {
|
|
306
|
+
this.ctor = ctor;
|
|
307
|
+
}
|
|
308
|
+
getClassName() {
|
|
309
|
+
return this.name || this.ctor?.name || '';
|
|
310
|
+
}
|
|
311
|
+
registerOperationByName(name, reg) {
|
|
312
|
+
const er = this.registeredOperationsByName.get(name);
|
|
313
|
+
if (er && er !== reg) {
|
|
314
|
+
let error = `Operation (Name: ${this.name}.${name}) is already registered.`;
|
|
315
|
+
if (er.regLocation) {
|
|
316
|
+
error = error + `\nPrior registration occurred at:\n${er.regLocation.join('\n')}`;
|
|
317
|
+
}
|
|
318
|
+
throw new error_1.SolidActionsConflictingRegistrationError(`${error}`);
|
|
319
|
+
}
|
|
320
|
+
this.registeredOperationsByName.set(name, reg);
|
|
321
|
+
reg.regLocation = new StackGrabber().getCleanStack(3);
|
|
322
|
+
}
|
|
323
|
+
getRegisteredInfo(reg) {
|
|
324
|
+
if (!this.externalRegInfo.has(reg)) {
|
|
325
|
+
this.externalRegInfo.set(reg, {});
|
|
326
|
+
}
|
|
327
|
+
return this.externalRegInfo.get(reg);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
exports.ClassRegistration = ClassRegistration;
|
|
331
|
+
// #endregion
|
|
332
|
+
// #region Global registration structures and functions
|
|
333
|
+
class StackGrabber extends Error {
|
|
334
|
+
constructor() {
|
|
335
|
+
super('StackGrabber');
|
|
336
|
+
Error.captureStackTrace(this, StackGrabber); // Excludes constructor from the stack
|
|
337
|
+
}
|
|
338
|
+
getCleanStack(frames = 1) {
|
|
339
|
+
return this.stack
|
|
340
|
+
?.split('\n')
|
|
341
|
+
.slice(frames + 1)
|
|
342
|
+
.map((l) => '>>> ' + l.replace(/^\s*at\s*/, '')); // Remove the first lines
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
// Track if SolidActions is launched, and if so, from where
|
|
346
|
+
let solidActionsLaunchPoint = undefined;
|
|
347
|
+
function recordSolidActionsLaunch() {
|
|
348
|
+
solidActionsLaunchPoint = new StackGrabber().getCleanStack(2); // Remove one for record, one for registerAndWrap...
|
|
349
|
+
}
|
|
350
|
+
exports.recordSolidActionsLaunch = recordSolidActionsLaunch;
|
|
351
|
+
function recordSolidActionsShutdown() {
|
|
352
|
+
solidActionsLaunchPoint = undefined;
|
|
353
|
+
}
|
|
354
|
+
exports.recordSolidActionsShutdown = recordSolidActionsShutdown;
|
|
355
|
+
function ensureSolidActionsIsNotLaunched() {
|
|
356
|
+
if (solidActionsLaunchPoint) {
|
|
357
|
+
throw new error_1.SolidActionsConflictingRegistrationError(`SolidActions code is being registered after SolidActions.launch(). SolidActions was launched from:\n${solidActionsLaunchPoint.join('\n')}\n`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
exports.ensureSolidActionsIsNotLaunched = ensureSolidActionsIsNotLaunched;
|
|
361
|
+
function ensureSolidActionsIsLaunched(reason) {
|
|
362
|
+
if (!solidActionsLaunchPoint) {
|
|
363
|
+
throw new TypeError(`\`SolidActions.launch()\` must be called before running ${reason}.`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
exports.ensureSolidActionsIsLaunched = ensureSolidActionsIsLaunched;
|
|
367
|
+
// SolidActions.launch lifecycle listener
|
|
368
|
+
const lifecycleListeners = [];
|
|
369
|
+
function registerLifecycleCallback(lcl) {
|
|
370
|
+
if (!lifecycleListeners.includes(lcl))
|
|
371
|
+
lifecycleListeners.push(lcl);
|
|
372
|
+
}
|
|
373
|
+
exports.registerLifecycleCallback = registerLifecycleCallback;
|
|
374
|
+
function getLifecycleListeners() {
|
|
375
|
+
return lifecycleListeners;
|
|
376
|
+
}
|
|
377
|
+
exports.getLifecycleListeners = getLifecycleListeners;
|
|
378
|
+
// Middleware installers - insert middleware in registered functions prior to launch
|
|
379
|
+
let installedMiddleware = false;
|
|
380
|
+
const middlewareInstallers = [];
|
|
381
|
+
function registerMiddlewareInstaller(i) {
|
|
382
|
+
if (installedMiddleware)
|
|
383
|
+
throw new TypeError('Attempt to provide method middleware after insertion was performed');
|
|
384
|
+
if (!middlewareInstallers.includes(i))
|
|
385
|
+
middlewareInstallers.push(i);
|
|
386
|
+
}
|
|
387
|
+
exports.registerMiddlewareInstaller = registerMiddlewareInstaller;
|
|
388
|
+
function insertAllMiddleware() {
|
|
389
|
+
if (installedMiddleware)
|
|
390
|
+
return;
|
|
391
|
+
installedMiddleware = true;
|
|
392
|
+
const regs = getAllClassRegistrations();
|
|
393
|
+
for (const c of regs) {
|
|
394
|
+
for (const f of c.allRegisteredOperations.values()) {
|
|
395
|
+
for (const i of middlewareInstallers) {
|
|
396
|
+
i.installMiddleware(f);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
exports.insertAllMiddleware = insertAllMiddleware;
|
|
402
|
+
// Registration of functions, and classes
|
|
403
|
+
const functionToRegistration = new Map();
|
|
404
|
+
// Registration of instance, by constructor+name
|
|
405
|
+
function registerClassInstance(inst, instname) {
|
|
406
|
+
const creg = getOrCreateClassRegistrationByTarget(inst.constructor);
|
|
407
|
+
if (creg.configuredInstances.has(instname)) {
|
|
408
|
+
throw new error_1.SolidActionsConflictingRegistrationError(`An instance of class '${inst.constructor.name}' with name '${instname}' was already registered. Earlier registration occurred at:\n${(creg.configuredInstanceRegLocs.get(instname) ?? []).join('\n')}`);
|
|
409
|
+
}
|
|
410
|
+
creg.configuredInstances.set(instname, inst);
|
|
411
|
+
creg.configuredInstanceRegLocs.set(instname, new StackGrabber().getCleanStack(3) ?? []);
|
|
412
|
+
}
|
|
413
|
+
function getRegisteredFunctionFullName(func) {
|
|
414
|
+
let className = '';
|
|
415
|
+
let funcName = func.name ?? '';
|
|
416
|
+
if (functionToRegistration.has(func)) {
|
|
417
|
+
const fr = functionToRegistration.get(func);
|
|
418
|
+
className = fr.getClassName();
|
|
419
|
+
funcName = fr.name;
|
|
420
|
+
}
|
|
421
|
+
return { className, name: funcName };
|
|
422
|
+
}
|
|
423
|
+
exports.getRegisteredFunctionFullName = getRegisteredFunctionFullName;
|
|
424
|
+
function getRegisteredFunctionQualifiedName(func) {
|
|
425
|
+
const fn = getRegisteredFunctionFullName(func);
|
|
426
|
+
return fn.className + '.' + fn.name;
|
|
427
|
+
}
|
|
428
|
+
exports.getRegisteredFunctionQualifiedName = getRegisteredFunctionQualifiedName;
|
|
429
|
+
function getRegisteredFunctionClassName(func) {
|
|
430
|
+
return getRegisteredFunctionFullName(func).className;
|
|
431
|
+
}
|
|
432
|
+
exports.getRegisteredFunctionClassName = getRegisteredFunctionClassName;
|
|
433
|
+
function getRegisteredFunctionName(func) {
|
|
434
|
+
return getRegisteredFunctionFullName(func).name;
|
|
435
|
+
}
|
|
436
|
+
exports.getRegisteredFunctionName = getRegisteredFunctionName;
|
|
437
|
+
function registerFunctionWrapper(func, reg) {
|
|
438
|
+
reg.wrappedFunction = func;
|
|
439
|
+
functionToRegistration.set(func, reg);
|
|
440
|
+
}
|
|
441
|
+
exports.registerFunctionWrapper = registerFunctionWrapper;
|
|
442
|
+
function getFunctionRegistration(func) {
|
|
443
|
+
return functionToRegistration.get(func);
|
|
444
|
+
}
|
|
445
|
+
exports.getFunctionRegistration = getFunctionRegistration;
|
|
446
|
+
function getFunctionRegistrationByName(className, name) {
|
|
447
|
+
const clsreg = getClassRegistrationByName(className, false);
|
|
448
|
+
if (!clsreg)
|
|
449
|
+
return undefined;
|
|
450
|
+
const methReg = clsreg.registeredOperationsByName.get(name);
|
|
451
|
+
if (!methReg)
|
|
452
|
+
return undefined;
|
|
453
|
+
return methReg;
|
|
454
|
+
}
|
|
455
|
+
exports.getFunctionRegistrationByName = getFunctionRegistrationByName;
|
|
456
|
+
function getRegisteredOperations(target) {
|
|
457
|
+
const registeredOperations = [];
|
|
458
|
+
if (typeof target === 'function') {
|
|
459
|
+
// Constructor case
|
|
460
|
+
const classReg = getClassRegistration(target, false);
|
|
461
|
+
classReg.reg?.reg?.allRegisteredOperations?.forEach((m) => registeredOperations.push(m));
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
let current = target;
|
|
465
|
+
while (current) {
|
|
466
|
+
// Walk prototype chain
|
|
467
|
+
registeredOperations.push(...getRegisteredOperations(current.constructor));
|
|
468
|
+
current = Object.getPrototypeOf(current);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return registeredOperations;
|
|
472
|
+
}
|
|
473
|
+
exports.getRegisteredOperations = getRegisteredOperations;
|
|
474
|
+
const methodArgsByFunction = new Map();
|
|
475
|
+
function getOrCreateMethodArgsRegistration(target, funcName, origFunc) {
|
|
476
|
+
let regtarget = target;
|
|
477
|
+
if (regtarget && typeof regtarget !== 'function') {
|
|
478
|
+
regtarget = regtarget.constructor;
|
|
479
|
+
}
|
|
480
|
+
if (!origFunc) {
|
|
481
|
+
origFunc = Object.getOwnPropertyDescriptor(target, funcName).value;
|
|
482
|
+
}
|
|
483
|
+
let mParameters = methodArgsByFunction.get(origFunc);
|
|
484
|
+
if (mParameters === undefined) {
|
|
485
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
486
|
+
let designParamTypes = undefined;
|
|
487
|
+
if (target) {
|
|
488
|
+
function getDesignType(target, key) {
|
|
489
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
|
490
|
+
const getMetadata = Reflect?.getMetadata;
|
|
491
|
+
if (!getMetadata)
|
|
492
|
+
return undefined; // polyfill not present
|
|
493
|
+
return getMetadata('design:paramtypes', target, key); // safe to use
|
|
494
|
+
}
|
|
495
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
496
|
+
designParamTypes = getDesignType(target, funcName);
|
|
497
|
+
}
|
|
498
|
+
if (designParamTypes) {
|
|
499
|
+
mParameters = designParamTypes.map((value, index) => new MethodParameter(index, value));
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
if (origFunc) {
|
|
503
|
+
const argnames = getArgNames(origFunc);
|
|
504
|
+
mParameters = argnames.map((_value, index) => new MethodParameter(index));
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, funcName);
|
|
508
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
509
|
+
const argnames = getArgNames(descriptor?.value);
|
|
510
|
+
mParameters = argnames.map((_value, index) => new MethodParameter(index));
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
methodArgsByFunction.set(origFunc, mParameters);
|
|
514
|
+
}
|
|
515
|
+
return mParameters;
|
|
516
|
+
}
|
|
517
|
+
exports.getOrCreateMethodArgsRegistration = getOrCreateMethodArgsRegistration;
|
|
518
|
+
function getOrCreateMethodRegistration(target, className, propertyKey, name, func) {
|
|
519
|
+
const { classReg, isInstance } = getOrCreateClassRegistration(target, className);
|
|
520
|
+
const fname = name ?? propertyKey.toString();
|
|
521
|
+
const origFunc = functionToRegistration.get(func)?.origFunction ?? func;
|
|
522
|
+
if (!classReg.allRegisteredOperations.has(origFunc)) {
|
|
523
|
+
const reg = new MethodRegistration(classReg, func, isInstance);
|
|
524
|
+
classReg.allRegisteredOperations.set(func, reg);
|
|
525
|
+
}
|
|
526
|
+
const methReg = classReg.allRegisteredOperations.get(func);
|
|
527
|
+
if (methReg.needInitialized) {
|
|
528
|
+
methReg.needInitialized = false;
|
|
529
|
+
methReg.name = fname;
|
|
530
|
+
methReg.className = classReg.name;
|
|
531
|
+
methReg.defaults = classReg;
|
|
532
|
+
methReg.args = getOrCreateMethodArgsRegistration(target, propertyKey, func);
|
|
533
|
+
const argNames = getArgNames(func);
|
|
534
|
+
methReg.args.forEach((e) => {
|
|
535
|
+
if (!e.name) {
|
|
536
|
+
if (e.index < argNames.length) {
|
|
537
|
+
e.name = argNames[e.index];
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
const wrappedMethod = async function (...rawArgs) {
|
|
542
|
+
let validatedArgs = rawArgs;
|
|
543
|
+
for (const vf of methReg.onEnter) {
|
|
544
|
+
validatedArgs = vf.func(methReg, validatedArgs);
|
|
545
|
+
}
|
|
546
|
+
return methReg.origFunction.call(this, ...validatedArgs);
|
|
547
|
+
};
|
|
548
|
+
Object.defineProperty(wrappedMethod, 'name', {
|
|
549
|
+
value: methReg.name,
|
|
550
|
+
});
|
|
551
|
+
methReg.registeredFunction = wrappedMethod;
|
|
552
|
+
functionToRegistration.set(methReg.registeredFunction, methReg);
|
|
553
|
+
functionToRegistration.set(methReg.origFunction, methReg);
|
|
554
|
+
}
|
|
555
|
+
return methReg;
|
|
556
|
+
}
|
|
557
|
+
function wrapSolidActionsFunctionAndRegisterByTarget(target, propertyKey, name, descriptor) {
|
|
558
|
+
if (!descriptor.value) {
|
|
559
|
+
throw Error('Use of decorator when original method is undefined');
|
|
560
|
+
}
|
|
561
|
+
const registration = wrapSolidActionsFunctionAndRegisterByUniqueName(target, undefined, propertyKey, name, descriptor.value);
|
|
562
|
+
descriptor.value = registration.wrappedFunction ?? registration.registeredFunction;
|
|
563
|
+
return { descriptor, registration };
|
|
564
|
+
}
|
|
565
|
+
exports.wrapSolidActionsFunctionAndRegisterByTarget = wrapSolidActionsFunctionAndRegisterByTarget;
|
|
566
|
+
function wrapSolidActionsFunctionAndRegisterByUniqueName(ctorOrProto, className, propertyKey, name, func) {
|
|
567
|
+
ensureSolidActionsIsNotLaunched();
|
|
568
|
+
if (!name) {
|
|
569
|
+
name = typeof propertyKey === 'string' ? propertyKey : propertyKey.toString();
|
|
570
|
+
}
|
|
571
|
+
const freg = getFunctionRegistration(func);
|
|
572
|
+
if (freg) {
|
|
573
|
+
const r = getOrCreateClassRegistration(ctorOrProto, className);
|
|
574
|
+
r.classReg.registerOperationByName(name, freg);
|
|
575
|
+
return freg;
|
|
576
|
+
}
|
|
577
|
+
const registration = getOrCreateMethodRegistration(ctorOrProto, className, propertyKey, name, func);
|
|
578
|
+
const r = getOrCreateClassRegistration(ctorOrProto, className);
|
|
579
|
+
r.classReg.registerOperationByName(name, registration);
|
|
580
|
+
return registration;
|
|
581
|
+
}
|
|
582
|
+
exports.wrapSolidActionsFunctionAndRegisterByUniqueName = wrapSolidActionsFunctionAndRegisterByUniqueName;
|
|
583
|
+
function wrapSolidActionsFunctionAndRegisterDec(target, propertyKey, name, descriptor) {
|
|
584
|
+
if (!descriptor.value) {
|
|
585
|
+
throw Error('Use of decorator when original method is undefined');
|
|
586
|
+
}
|
|
587
|
+
const registration = wrapSolidActionsFunctionAndRegister(target, undefined, propertyKey, name, descriptor.value);
|
|
588
|
+
descriptor.value = registration.wrappedFunction ?? registration.registeredFunction;
|
|
589
|
+
return { descriptor, registration };
|
|
590
|
+
}
|
|
591
|
+
exports.wrapSolidActionsFunctionAndRegisterDec = wrapSolidActionsFunctionAndRegisterDec;
|
|
592
|
+
function wrapSolidActionsFunctionAndRegister(ctorOrProto, className, propertyKey, name, func) {
|
|
593
|
+
ensureSolidActionsIsNotLaunched();
|
|
594
|
+
const freg = getFunctionRegistration(func);
|
|
595
|
+
if (freg) {
|
|
596
|
+
return freg;
|
|
597
|
+
}
|
|
598
|
+
const registration = getOrCreateMethodRegistration(ctorOrProto, className, propertyKey, name, func);
|
|
599
|
+
return registration;
|
|
600
|
+
}
|
|
601
|
+
exports.wrapSolidActionsFunctionAndRegister = wrapSolidActionsFunctionAndRegister;
|
|
602
|
+
const classesByName = new Map();
|
|
603
|
+
const classesByCtor = new Map();
|
|
604
|
+
function getNameForClass(ctor) {
|
|
605
|
+
const reg = getClassRegistration(ctor, false);
|
|
606
|
+
return reg.reg?.name || reg.regTarget.name;
|
|
607
|
+
}
|
|
608
|
+
exports.getNameForClass = getNameForClass;
|
|
609
|
+
function getAllClassRegistrations() {
|
|
610
|
+
const seen = new Set();
|
|
611
|
+
for (const [_cn, c] of classesByName) {
|
|
612
|
+
seen.add(c.reg);
|
|
613
|
+
}
|
|
614
|
+
for (const [_c, c] of classesByCtor) {
|
|
615
|
+
seen.add(c.reg);
|
|
616
|
+
}
|
|
617
|
+
return seen;
|
|
618
|
+
}
|
|
619
|
+
function getClassRegistration(target, create) {
|
|
620
|
+
let regTarget;
|
|
621
|
+
if (typeof target === 'function') {
|
|
622
|
+
// Static method case
|
|
623
|
+
regTarget = target;
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
// Instance method case
|
|
627
|
+
regTarget = target.constructor;
|
|
628
|
+
}
|
|
629
|
+
if (classesByCtor.has(regTarget))
|
|
630
|
+
return { regTarget, reg: classesByCtor.get(regTarget) };
|
|
631
|
+
if (!create)
|
|
632
|
+
return { regTarget };
|
|
633
|
+
classesByCtor.set(regTarget, {
|
|
634
|
+
reg: new ClassRegistration(regTarget),
|
|
635
|
+
name: regTarget.name,
|
|
636
|
+
regloc: new StackGrabber().getCleanStack(1) ?? [],
|
|
637
|
+
});
|
|
638
|
+
return { regTarget, reg: classesByCtor.get(regTarget) };
|
|
639
|
+
}
|
|
640
|
+
exports.getClassRegistration = getClassRegistration;
|
|
641
|
+
function getAllRegisteredClassNames() {
|
|
642
|
+
const cnames = [];
|
|
643
|
+
for (const [cn, _creg] of classesByName) {
|
|
644
|
+
cnames.push(cn);
|
|
645
|
+
}
|
|
646
|
+
return cnames;
|
|
647
|
+
}
|
|
648
|
+
exports.getAllRegisteredClassNames = getAllRegisteredClassNames;
|
|
649
|
+
function getAllRegisteredFunctions() {
|
|
650
|
+
const s = new Set();
|
|
651
|
+
const fregs = [];
|
|
652
|
+
for (const [_f, reg] of functionToRegistration) {
|
|
653
|
+
if (s.has(reg))
|
|
654
|
+
continue;
|
|
655
|
+
fregs.push(reg);
|
|
656
|
+
s.add(reg);
|
|
657
|
+
}
|
|
658
|
+
return fregs;
|
|
659
|
+
}
|
|
660
|
+
exports.getAllRegisteredFunctions = getAllRegisteredFunctions;
|
|
661
|
+
function getClassRegistrationByName(name, create = false) {
|
|
662
|
+
if (!classesByName.has(name) && !create) {
|
|
663
|
+
throw new error_1.SolidActionsNotRegisteredError(name, `Class '${name}' is not registered`);
|
|
664
|
+
}
|
|
665
|
+
if (!classesByName.has(name)) {
|
|
666
|
+
classesByName.set(name, {
|
|
667
|
+
reg: new ClassRegistration(undefined),
|
|
668
|
+
regloc: new StackGrabber().getCleanStack(1) ?? [],
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
const clsReg = classesByName.get(name).reg;
|
|
672
|
+
if (clsReg.needsInitialized) {
|
|
673
|
+
clsReg.name = name;
|
|
674
|
+
clsReg.needsInitialized = false;
|
|
675
|
+
}
|
|
676
|
+
return clsReg;
|
|
677
|
+
}
|
|
678
|
+
exports.getClassRegistrationByName = getClassRegistrationByName;
|
|
679
|
+
function getOrCreateClassRegistrationByTarget(ctor) {
|
|
680
|
+
const existing = getClassRegistration(ctor, true);
|
|
681
|
+
const reg = existing.reg.reg;
|
|
682
|
+
// This registration will need initialized... that happens later
|
|
683
|
+
return reg;
|
|
684
|
+
}
|
|
685
|
+
exports.getOrCreateClassRegistrationByTarget = getOrCreateClassRegistrationByTarget;
|
|
686
|
+
function getOrCreateClassRegistration(target, className) {
|
|
687
|
+
if (!target && className === undefined) {
|
|
688
|
+
className = '';
|
|
689
|
+
}
|
|
690
|
+
let regtarget = undefined;
|
|
691
|
+
let isInstance = false;
|
|
692
|
+
if (target) {
|
|
693
|
+
if (typeof target === 'function') {
|
|
694
|
+
// Static method case
|
|
695
|
+
regtarget = target;
|
|
696
|
+
}
|
|
697
|
+
else {
|
|
698
|
+
// Instance method case
|
|
699
|
+
regtarget = target.constructor;
|
|
700
|
+
isInstance = true;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
// If we have no class name, this might get assigned later. Put in placeholder reg
|
|
704
|
+
if (className === undefined) {
|
|
705
|
+
const reg = getClassRegistration(regtarget, true);
|
|
706
|
+
return { classReg: reg.reg.reg, isInstance, className };
|
|
707
|
+
}
|
|
708
|
+
// If we have no regtarget, this is plain function registration
|
|
709
|
+
if (!regtarget) {
|
|
710
|
+
return { classReg: getClassRegistrationByName(className, true), isInstance: false, className };
|
|
711
|
+
}
|
|
712
|
+
// We have a regtarget and a name ... assign the name
|
|
713
|
+
const reg = getClassRegistration(regtarget, true);
|
|
714
|
+
if (reg.reg.name && reg.reg.name !== className) {
|
|
715
|
+
throw new TypeError(`Attempt to register class under two names: ${reg.reg.name} vs. ${className}`);
|
|
716
|
+
}
|
|
717
|
+
reg.reg.name = className;
|
|
718
|
+
return { classReg: reg.reg.reg, isInstance, className };
|
|
719
|
+
}
|
|
720
|
+
function getConfiguredInstance(clsname, cfgname) {
|
|
721
|
+
const classReg = getClassRegistrationByName(clsname);
|
|
722
|
+
if (!classReg)
|
|
723
|
+
return null;
|
|
724
|
+
return classReg.configuredInstances.get(cfgname) ?? null;
|
|
725
|
+
}
|
|
726
|
+
exports.getConfiguredInstance = getConfiguredInstance;
|
|
727
|
+
function finalizeClassRegistrations() {
|
|
728
|
+
function setName(reg, cname) {
|
|
729
|
+
reg.name = cname;
|
|
730
|
+
reg.needsInitialized = false;
|
|
731
|
+
for (const [_fn, f] of reg.registeredOperationsByName) {
|
|
732
|
+
f.className = cname;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
for (const [cls, reg] of classesByCtor) {
|
|
736
|
+
const cname = reg.name || reg.reg.name || getNameForClass(cls);
|
|
737
|
+
const ereg = classesByName.get(cname);
|
|
738
|
+
if (!ereg) {
|
|
739
|
+
classesByName.set(cname, { reg: reg.reg, ctor: cls, regloc: reg.regloc });
|
|
740
|
+
reg.name = cname;
|
|
741
|
+
setName(reg.reg, cname);
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
if (ereg.ctor && ereg.ctor !== cls) {
|
|
745
|
+
throw new error_1.SolidActionsConflictingRegistrationError(`Class ${cname}(${cls.name}) has been given a name that conflicts with another class ${ereg.ctor?.name}.`);
|
|
746
|
+
}
|
|
747
|
+
if (ereg.reg !== reg.reg) {
|
|
748
|
+
throw new error_1.SolidActionsConflictingRegistrationError(`Class: ${cname}(${cls.name}) has been given a name that was registered directly by name without a class.`);
|
|
749
|
+
}
|
|
750
|
+
classesByName.set(cname, { reg: reg.reg, ctor: cls, regloc: reg.regloc });
|
|
751
|
+
reg.name = cname;
|
|
752
|
+
setName(reg.reg, cname);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
exports.finalizeClassRegistrations = finalizeClassRegistrations;
|
|
756
|
+
// #endregion
|
|
757
|
+
// #region External (event receiver v3)
|
|
758
|
+
function associateClassWithExternal(external, cls) {
|
|
759
|
+
let clsreg = undefined;
|
|
760
|
+
if (typeof cls === 'string') {
|
|
761
|
+
clsreg = getClassRegistrationByName(cls, true);
|
|
762
|
+
}
|
|
763
|
+
else {
|
|
764
|
+
clsreg = getClassRegistration(cls, true).reg.reg;
|
|
765
|
+
}
|
|
766
|
+
return clsreg.getRegisteredInfo(external);
|
|
767
|
+
}
|
|
768
|
+
exports.associateClassWithExternal = associateClassWithExternal;
|
|
769
|
+
/*
|
|
770
|
+
* Associates a SolidActions function or method with an external class or object.
|
|
771
|
+
* Likely, this will be invoking or intercepting the method.
|
|
772
|
+
*/
|
|
773
|
+
function associateMethodWithExternal(external, target, className, funcName, func) {
|
|
774
|
+
const registration = wrapSolidActionsFunctionAndRegister(target, className, funcName, funcName, func);
|
|
775
|
+
if (!registration.externalRegInfo.has(external)) {
|
|
776
|
+
registration.externalRegInfo.set(external, {});
|
|
777
|
+
}
|
|
778
|
+
return { registration, regInfo: registration.externalRegInfo.get(external) };
|
|
779
|
+
}
|
|
780
|
+
exports.associateMethodWithExternal = associateMethodWithExternal;
|
|
781
|
+
/*
|
|
782
|
+
* Associates a SolidActions function or method parameters with an external class or object.
|
|
783
|
+
* Likely, this will be invoking or intercepting the method.
|
|
784
|
+
*/
|
|
785
|
+
function associateParameterWithExternal(external, target, className, funcName, func, paramId) {
|
|
786
|
+
if (!func) {
|
|
787
|
+
func = Object.getOwnPropertyDescriptor(target, funcName).value;
|
|
788
|
+
}
|
|
789
|
+
const registration = wrapSolidActionsFunctionAndRegister(target, className, funcName, funcName, func);
|
|
790
|
+
let param;
|
|
791
|
+
if (typeof paramId === 'number') {
|
|
792
|
+
param = registration.args[paramId];
|
|
793
|
+
}
|
|
794
|
+
else {
|
|
795
|
+
param = registration.args.find((p) => p.name === paramId);
|
|
796
|
+
}
|
|
797
|
+
if (!param)
|
|
798
|
+
return undefined;
|
|
799
|
+
if (!param.externalRegInfo.has(external)) {
|
|
800
|
+
param.externalRegInfo.set(external, {});
|
|
801
|
+
}
|
|
802
|
+
return param.externalRegInfo.get(external);
|
|
803
|
+
}
|
|
804
|
+
exports.associateParameterWithExternal = associateParameterWithExternal;
|
|
805
|
+
function getRegistrationsForExternal(external, cls, funcName) {
|
|
806
|
+
const res = new Array();
|
|
807
|
+
if (cls) {
|
|
808
|
+
let reg = undefined;
|
|
809
|
+
if (typeof cls === 'string') {
|
|
810
|
+
reg = classesByName.get(cls)?.reg;
|
|
811
|
+
}
|
|
812
|
+
else if (typeof cls === 'function') {
|
|
813
|
+
reg = classesByCtor.get(cls)?.reg;
|
|
814
|
+
}
|
|
815
|
+
else if (cls !== undefined && typeof cls === 'object') {
|
|
816
|
+
reg = classesByCtor.get(cls.constructor)?.reg;
|
|
817
|
+
}
|
|
818
|
+
if (reg) {
|
|
819
|
+
if (funcName) {
|
|
820
|
+
const f = reg.registeredOperationsByName.get(funcName);
|
|
821
|
+
if (f) {
|
|
822
|
+
collectRegForFunction(f);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
else {
|
|
826
|
+
collectRegForClass(reg);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
else {
|
|
831
|
+
const seen = getAllClassRegistrations();
|
|
832
|
+
for (const c of seen) {
|
|
833
|
+
collectRegForClass(c);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
return res;
|
|
837
|
+
function collectRegForClass(reg) {
|
|
838
|
+
for (const f of reg.allRegisteredOperations.values()) {
|
|
839
|
+
collectRegForFunction(f);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
function collectRegForFunction(f) {
|
|
843
|
+
const methodConfig = f.externalRegInfo.get(external);
|
|
844
|
+
const classConfig = f.defaults?.externalRegInfo.get(external);
|
|
845
|
+
const paramConfig = [];
|
|
846
|
+
let hasParamConfig = false;
|
|
847
|
+
for (const arg of f.args) {
|
|
848
|
+
if (arg.externalRegInfo.has(external))
|
|
849
|
+
hasParamConfig = true;
|
|
850
|
+
paramConfig.push({
|
|
851
|
+
name: arg.name,
|
|
852
|
+
index: arg.index,
|
|
853
|
+
paramConfig: arg.externalRegInfo.get(external),
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
if (!methodConfig && !classConfig && !hasParamConfig)
|
|
857
|
+
return;
|
|
858
|
+
res.push({ methodReg: f, methodConfig, classConfig: classConfig ?? {}, paramConfig });
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
exports.getRegistrationsForExternal = getRegistrationsForExternal;
|
|
862
|
+
// #endregion
|
|
863
|
+
// #region Parameter decorators
|
|
864
|
+
function ArgName(name) {
|
|
865
|
+
return function (target, propertyKey, parameterIndex) {
|
|
866
|
+
const existingParameters = getOrCreateMethodArgsRegistration(target, propertyKey);
|
|
867
|
+
const curParam = existingParameters[parameterIndex];
|
|
868
|
+
curParam.name = name;
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
exports.ArgName = ArgName;
|
|
872
|
+
// #endregion
|
|
873
|
+
//# sourceMappingURL=decorators.js.map
|