@autobe/compiler 0.26.0 → 0.28.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.
@@ -36,13 +36,14 @@ export const writeRealizeControllers = async (
36
36
  );
37
37
  if (func === undefined || operate === undefined) return method; // unreachable
38
38
 
39
- const auth: AutoBeRealizeAuthorization | undefined =
39
+ const authorization: AutoBeRealizeAuthorization | undefined =
40
40
  operate.authorizationActor
41
41
  ? props.authorizations.find(
42
42
  (d) => d.actor.name === operate.authorizationActor,
43
43
  )
44
44
  : undefined;
45
- if (operate.authorizationActor && auth === undefined) return method; // unreachable
45
+ if (operate.authorizationActor && authorization === undefined)
46
+ return method; // unreachable
46
47
 
47
48
  ctx.importer.external({
48
49
  type: "instance",
@@ -114,51 +115,15 @@ export const writeRealizeControllers = async (
114
115
  method.name,
115
116
  method.questionToken,
116
117
  method.typeParameters,
117
- auth
118
+ authorization
118
119
  ? [
119
- ts.factory.createParameterDeclaration(
120
- [
121
- ts.factory.createDecorator(
122
- ts.factory.createCallExpression(
123
- ts.factory.createIdentifier(
124
- ctx.importer.external({
125
- type: "instance",
126
- library: path
127
- .relative(
128
- ctx.controller.location,
129
- auth.decorator.location,
130
- )
131
- .replaceAll(path.sep, "/")
132
- .split(".ts")[0],
133
- name: auth.decorator.name,
134
- }),
135
- ),
136
- undefined,
137
- [],
138
- ),
139
- ),
140
- ],
141
- undefined,
142
- auth.actor.name,
143
- undefined,
144
- ts.factory.createTypeReferenceNode(
145
- ctx.importer.external({
146
- type: "instance",
147
- library: path
148
- .relative(
149
- ctx.controller.location,
150
- auth.payload.location,
151
- )
152
- .replaceAll(path.sep, "/")
153
- .split(".ts")[0],
154
- name: auth.payload.name,
155
- }),
156
- ),
157
- undefined,
158
- ),
120
+ createAuthorizationParameter(ctx, authorization),
159
121
  ...method.parameters,
160
122
  ]
161
- : method.parameters,
123
+ : operate.authorizationType === "login" ||
124
+ operate.authorizationType === "join"
125
+ ? [createIpParameter(ctx), ...method.parameters]
126
+ : method.parameters,
162
127
  method.type,
163
128
  ts.factory.createBlock([tryCatch]),
164
129
  );
@@ -174,3 +139,69 @@ export const writeRealizeControllers = async (
174
139
  );
175
140
  return Object.fromEntries(entries);
176
141
  };
142
+
143
+ const createAuthorizationParameter = (
144
+ ctx: NestiaMigrateNestMethodProgrammer.IContext,
145
+ authorization: AutoBeRealizeAuthorization,
146
+ ) =>
147
+ ts.factory.createParameterDeclaration(
148
+ [
149
+ ts.factory.createDecorator(
150
+ ts.factory.createCallExpression(
151
+ ts.factory.createIdentifier(
152
+ ctx.importer.external({
153
+ type: "instance",
154
+ library: path
155
+ .relative(
156
+ ctx.controller.location,
157
+ authorization.decorator.location,
158
+ )
159
+ .replaceAll(path.sep, "/")
160
+ .split(".ts")[0],
161
+ name: authorization.decorator.name,
162
+ }),
163
+ ),
164
+ undefined,
165
+ [],
166
+ ),
167
+ ),
168
+ ],
169
+ undefined,
170
+ authorization.actor.name,
171
+ undefined,
172
+ ts.factory.createTypeReferenceNode(
173
+ ctx.importer.external({
174
+ type: "instance",
175
+ library: path
176
+ .relative(ctx.controller.location, authorization.payload.location)
177
+ .replaceAll(path.sep, "/")
178
+ .split(".ts")[0],
179
+ name: authorization.payload.name,
180
+ }),
181
+ ),
182
+ undefined,
183
+ );
184
+
185
+ const createIpParameter = (ctx: NestiaMigrateNestMethodProgrammer.IContext) =>
186
+ ts.factory.createParameterDeclaration(
187
+ [
188
+ ts.factory.createDecorator(
189
+ ts.factory.createCallExpression(
190
+ ts.factory.createIdentifier(
191
+ ctx.importer.external({
192
+ type: "instance",
193
+ library: "@nestjs/common",
194
+ name: "Ip",
195
+ }),
196
+ ),
197
+ undefined,
198
+ [],
199
+ ),
200
+ ),
201
+ ],
202
+ undefined,
203
+ "ip",
204
+ undefined,
205
+ ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
206
+ undefined,
207
+ );