New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@luvio/generator-ts

Package Overview
Dependencies
Maintainers
0
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@luvio/generator-ts - npm Package Compare versions

Comparing version 5.2.0 to 5.3.0

200

dist/generator-ts.js

@@ -718,7 +718,2 @@ /**

const NETWORK_COMMAND = {
module: '@luvio/command-network/v1',
exportedSymbol: 'NetworkCommand',
isType: true,
};
const JSON_SCHEMA = {

@@ -729,7 +724,2 @@ module: '@luvio/jsonschema-validate',

};
const CONCRETION = {
module: '@luvio/utils',
exportedSymbol: 'Concretion',
isType: true,
};
const MEDIATYPE_APP_JSON = 'application/json';

@@ -937,3 +927,2 @@ const INPUT_PAYLOAD_MEMBER_NAME = 'inputPayload';

// command
const { service, serviceInfo } = this.networkServiceInfo;
const className = toPascalCase(commandName);

@@ -944,3 +933,6 @@ const builderFunctionName = `build${capitalize(className)}`;

const commandClassTypeName = `${className}Class`;
file.push(code `export const ${schemaConfigConst}: ${JSON_SCHEMA} = ${jsonSchemaFor(configType)};`, code `type ${commandClassTypeName} = typeof ${NETWORK_COMMAND}<${commandConfigType},${this.typeDefinitionFor(outputType)},{${serviceInfo.name}: ${service}}>;`, code `export function ${builderFunctionName}(baseClass: ${commandClassTypeName}): ${CONCRETION}<${commandClassTypeName}>{`, code `return class ${className} extends baseClass{`, this.generateFetch({
const commandNamedServices = this.serviceDependencies.reduce((previous, current, idx) => {
return code `${previous}${idx > 0 ? '&' : ''}${current.namedService}`;
}, code ``);
file.push(code `export const ${schemaConfigConst}: ${JSON_SCHEMA} = ${jsonSchemaFor(configType)};`, code `type BaseType = ${this.commandBaseClass}<${this.typeDefinitionFor(outputType)}, ${commandNamedServices}>;`, code `type BaseConstructorType = typeof ${this.commandBaseClass}<${this.typeDefinitionFor(outputType)},${commandNamedServices}>;`, code `type BaseConstructorParams = ConstructorParameters<BaseConstructorType>;`, code `type ${commandClassTypeName} = new (config: ${commandConfigType}, ...args: BaseConstructorParams) => BaseType;`, code `export function ${builderFunctionName}(baseClass: BaseConstructorType): ${commandClassTypeName}{`, code `return class ${className} extends baseClass{`, code `constructor(private config: ${commandConfigType}, ...args: BaseConstructorParams){super(...args)}`, this.generateClassBody({
...params,

@@ -951,9 +943,10 @@ request,

outputType,
}), '}}');
}), '}};');
return {
method: operation.method,
commandServicesInfo: [serviceInfo],
commandConfigType,
commandClassName: className,
commandClassBuilder: {
serviceDependencies: this.serviceDependencies,
configType: commandConfigType,
baseClass: this.commandBaseClass,
className: className,
classBuilder: {
filename,

@@ -963,3 +956,3 @@ exportedSymbol: builderFunctionName,

},
commandSchemaConfigConst: {
schemaConfigConst: {
filename,

@@ -974,32 +967,29 @@ exportedSymbol: schemaConfigConst,

const WITHERRORS_TYPE$1 = {
module: '@luvio/utils',
exportedSymbol: 'WithErrors',
const NAMED_AURA_NETWORK_SERVICE = {
module: '@luvio/service-aura-network/v1',
exportedSymbol: 'NamedAuraNetworkService',
isType: true,
};
const CONVERT_AURA_RESPONSE_TO_DATA = {
module: '@luvio/runtime',
exportedSymbol: 'convertAuraResponseToData',
isType: false,
};
const AURA_NETWORK_SERVICE = {
module: '@luvio/service-network',
exportedSymbol: 'AuraNetworkService',
isType: true,
};
const AURA_NETWORK_SERVICE_DESCRIPTOR = {
module: '@luvio/service-network',
module: '@luvio/service-aura-network/v1',
exportedSymbol: 'AuraNetworkServiceDescriptor',
isType: true,
};
const AURA_COMMAND_BASE_CLASS = {
module: '@luvio/command-aura-network/v1',
exportedSymbol: 'AuraNetworkCommand',
isType: true,
};
class AuraOperationCommandService extends OperationCommand {
get networkServiceInfo() {
return {
service: AURA_NETWORK_SERVICE,
serviceInfo: {
name: 'auraNetwork',
constructor() {
super(...arguments);
this.serviceDependencies = [
{
version: '1.0',
descriptor: AURA_NETWORK_SERVICE_DESCRIPTOR,
namedService: NAMED_AURA_NETWORK_SERVICE,
name: 'auraNetwork',
},
};
];
this.commandBaseClass = AURA_COMMAND_BASE_CLASS;
}

@@ -1015,6 +1005,5 @@ getInputPayloadParameterName(config) {

}
generateFetch(config) {
generateClassBody(config) {
var _a, _b;
const { endpoint, operation, request, server, hasInputPayload } = config;
const result = code `fetch(): PromiseLike<${WITHERRORS_TYPE$1}<${this.typeDefinitionFor(config.outputType)}>>{`;
const auraControllerName = (_a = endpoint.auraController) === null || _a === void 0 ? void 0 : _a.name;

@@ -1031,7 +1020,9 @@ if (auraControllerName === undefined) {

const auraMethodName = ((_b = operation.auraMethod) === null || _b === void 0 ? void 0 : _b.name) || operation.operationId;
result.push(code `const endpoint = '${auraControllerName}.${auraMethodName}';`);
const result = code ``;
result.push(code `endpoint = '${auraControllerName}.${auraMethodName}';`);
result.push(code `get auraParams(): Record<string, unknown>{`);
// handle uri params, query params and input payload
const queryParameters = getQueryParameterMembers(request === null || request === void 0 ? void 0 : request.queryParameters);
const uriParameters = getParameterMembers(server.uriParameters, endpoint.uriParameters, request === null || request === void 0 ? void 0 : request.uriParameters);
result.push(code `const params:Parameters<${this.networkServiceInfo.service}>[1]={`);
result.push(code `return {`);
[queryParameters, uriParameters].forEach((allParams) => {

@@ -1048,5 +1039,3 @@ allParams.forEach((param) => {

result.push(`};`);
// generate config
result.push(code `const actionConfig:Parameters<${this.networkServiceInfo.service}>[2]={`, `background:false,hotspot:true,longRunning:false,storable:false,`, ``, ``, ` };`);
result.push(code `return ${CONVERT_AURA_RESPONSE_TO_DATA}(this.services.auraNetwork(endpoint,params,actionConfig));}`);
result.push(code `}`);
return result;

@@ -1063,14 +1052,9 @@ }

const HEADER_CONTENT_TYPE = 'Content-Type';
const WITHERRORS_TYPE = {
module: '@luvio/utils',
exportedSymbol: 'WithErrors',
const NAMED_FETCH_SERVICE = {
module: '@luvio/service-fetch-network/v1',
exportedSymbol: 'NamedFetchService',
isType: true,
};
const CONVERT_FETCH_RESPONSE_TO_DATA = {
module: '@luvio/runtime',
exportedSymbol: 'convertFetchResponseToData',
isType: false,
};
const FETCH_SERVICE = {
module: '@luvio/service-network',
module: '@luvio/service-fetch-network/v1',
exportedSymbol: 'FetchService',

@@ -1080,19 +1064,30 @@ isType: true,

const FETCH_SERVICE_DESCRIPTOR = {
module: '@luvio/service-network',
module: '@luvio/service-fetch-network/v1',
exportedSymbol: 'FetchServiceDescriptor',
isType: true,
};
const FETCH_COMMAND_BASE_CLASS = {
module: '@luvio/command-fetch-network/v1',
exportedSymbol: 'FetchNetworkCommand',
isType: true,
};
class FetchOperationCommand extends OperationCommand {
constructor() {
super(...arguments);
this.serviceDependencies = [
{
version: '1.0',
descriptor: FETCH_SERVICE_DESCRIPTOR,
namedService: NAMED_FETCH_SERVICE,
name: 'fetch',
},
];
this.commandBaseClass = FETCH_COMMAND_BASE_CLASS;
}
getInputPayloadParameterName(_config) {
return INPUT_PAYLOAD_MEMBER_NAME;
}
get networkServiceInfo() {
return {
service: FETCH_SERVICE,
serviceInfo: { name: 'fetch', version: '1.0', descriptor: FETCH_SERVICE_DESCRIPTOR },
};
}
generateUrl(config) {
const url = this.processUrl(config);
return code `let url:Parameters<${this.networkServiceInfo.service}>[0]=\`${url}\`;`;
return code `let url:Parameters<${FETCH_SERVICE}>[0]=\`${url}\`;`;
}

@@ -1143,7 +1138,7 @@ generateHeaders(config) {

}
generateFetch(config) {
generateClassBody(config) {
const { request, operation, hasInputPayload } = config;
const result = new Code().push(code `fetch(): PromiseLike<${WITHERRORS_TYPE}<${this.typeDefinitionFor(config.outputType)}>>{`, code `${this.generateUrl(config)}${this.generateQueryParams(config)}${this.generateHeaders(config)}`);
const result = new Code().push(code `get fetchParams(): Parameters<${FETCH_SERVICE}>{`, code `${this.generateUrl(config)}${this.generateQueryParams(config)}${this.generateHeaders(config)}`);
const hasHeaders = getParameterMembers(request === null || request === void 0 ? void 0 : request.headers).length > 0 || hasInputPayload;
result.push(code `const params:Parameters<${this.networkServiceInfo.service}>[1]={`, code `method:'${operation.method.toUpperCase()}',`, code `cache:'no-cache',`);
result.push(code `const params:Parameters<${FETCH_SERVICE}>[1]={`, code `method:'${operation.method.toUpperCase()}',`, code `cache:'no-cache',`);
if (hasHeaders) {

@@ -1156,3 +1151,3 @@ result.push(`headers`);

result.push(`};`);
result.push(code `return ${CONVERT_FETCH_RESPONSE_TO_DATA}(this.services.fetch(url, params));}`);
result.push(code `return [url, params]}`);
return result;

@@ -1203,2 +1198,17 @@ }

};
const AURA_NETWORK_COMMAND_BASE_CLASS_DESCRIPTOR = {
module: '@luvio/command-aura-network/v1',
exportedSymbol: 'AuraNetworkCommandServiceDescriptor',
isType: true,
};
const FETCH_NETWORK_COMMAND_BASE_CLASS_DESCRIPTOR = {
module: '@luvio/command-fetch-network/v1',
exportedSymbol: 'FetchNetworkCommandServiceDescriptor',
isType: true,
};
const INSTRUMENT_COMMAND_DESCRIPTOR = {
module: '@luvio/service-instrument-command/v1',
exportedSymbol: 'InstrumentCommandServiceDescriptor',
isType: true,
};
/**

@@ -1216,11 +1226,21 @@ * An implementation of OperationLwcBindingsService that generates TypeScript adapters type declarations

generateWireAdapterCode(params) {
const { adapterName, commandClassName, commandConfigType, commandSchemaConfigConst, outputTypeDef, commandClassBuilder, } = params;
const declaration = code `export let ${adapterName}:${WIRE_ADAPTER_CONSTRUCTOR}`;
const instantiation = new Code().push(code `const ${commandClassName} = ${commandClassBuilder}(services.networkCommandBaseClass);`, code `${adapterName}=class extends ${COMMAND_WIRE_ADAPTER_CONSTRUCTOR}<${this.typeDefinitionFor(outputTypeDef)}>{`, code `configSchema=${commandSchemaConfigConst};`, code `getCommand(){return new ${commandClassName}(this.config as ${commandConfigType},{},services);}}`);
const { adapterName, className, configType, schemaConfigConst, outputTypeDef, classBuilder, baseClass, } = params;
const declaration = code `export let ${adapterName}:${WIRE_ADAPTER_CONSTRUCTOR}<${configType}, ${this.typeDefinitionFor(outputTypeDef)}, {}>`;
if (!['AuraNetworkCommand', 'FetchNetworkCommand'].some((el) => el === baseClass.exportedSymbol)) {
throw new Error(`Unknown base class ${baseClass.exportedSymbol}`);
}
const instantiation = new Code().push(code `const ${className} = services.instrumentCommand(${classBuilder}(services.${baseClass.exportedSymbol === 'AuraNetworkCommand'
? 'auraNetworkCommandBaseClass'
: 'fetchNetworkCommandBaseClass'}), '${className}');`, code `${adapterName}=class extends ${COMMAND_WIRE_ADAPTER_CONSTRUCTOR}<${this.typeDefinitionFor(outputTypeDef)}, ${configType}>{`, code `configSchema=${schemaConfigConst};`, code `getCommand(){return new ${className}(this.config!,services);}}`);
return { declaration, instantiation };
}
generateImperativeInvokerCode(params) {
const { adapterName, commandClassName, commandClassBuilder, commandConfigType, commandSchemaConfigConst, outputTypeDef, } = params;
const declaration = code `export let ${adapterName}:(config:${commandConfigType})=>PromiseLike<${this.typeDefinitionFor(outputTypeDef)}>`;
const instantiation = new Code().push(code `const ${commandClassName} = ${commandClassBuilder}(services.networkCommandBaseClass);`, code `${adapterName}=${BUILD_ASYNC_IMPERATIVE_INVOKER}<Parameters<typeof ${adapterName}>,${this.typeDefinitionFor(outputTypeDef)}>(`, `({params,assertIsValid})=>{`, `const config=params[0];`, code `const _:<T>(data:unknown,_:${JSON_SCHEMA_TYPE})=>asserts data is T=assertIsValid;`, code `_<${commandConfigType}>(config,${commandSchemaConfigConst});`, code `return new ${commandClassName}(config,{},services);`, `});`);
const { adapterName, className, classBuilder, configType, schemaConfigConst, outputTypeDef, baseClass, } = params;
const declaration = code `export let ${adapterName}:(config:${configType})=>PromiseLike<${this.typeDefinitionFor(outputTypeDef)}>`;
if (!['AuraNetworkCommand', 'FetchNetworkCommand'].some((el) => el === baseClass.exportedSymbol)) {
throw new Error(`Unknown base class ${baseClass.exportedSymbol}`);
}
const instantiation = new Code().push(code `const ${className} = services.instrumentCommand(${classBuilder}(services.${baseClass.exportedSymbol === 'AuraNetworkCommand'
? 'auraNetworkCommandBaseClass'
: 'fetchNetworkCommandBaseClass'}), '${className}');`, code `${adapterName}=${BUILD_ASYNC_IMPERATIVE_INVOKER}<Parameters<typeof ${adapterName}>,${this.typeDefinitionFor(outputTypeDef)}>(`, `({params,assertIsValid})=>{`, `const config=params[0];`, code `const _:<T>(data:unknown,_:${JSON_SCHEMA_TYPE})=>asserts data is T=assertIsValid;`, code `_<${configType}>(config,${schemaConfigConst});`, code `return new ${className}(config,services);`, `});`);
return { declaration, instantiation };

@@ -1235,4 +1255,4 @@ }

for (let commandInfo of commands) {
const { method, commandClassName, commandClassBuilder } = commandInfo;
const adapterName = commandClassName
const { method, className, classBuilder } = commandInfo;
const adapterName = className
.replace(/^(.)/, (_, m) => m.toLowerCase())

@@ -1243,3 +1263,3 @@ .replace(/Command$/, '');

: this.generateImperativeInvokerCode({ adapterName, ...commandInfo });
bindings.push({ adapterName, adapterCode, commandInfo, commandClassBuilder });
bindings.push({ adapterName, adapterCode, commandInfo, classBuilder });
}

@@ -1251,18 +1271,34 @@ let serviceRequirements = {

},
fetchNetworkCommandBaseClass: {
type: 'fetchNetworkCommandBaseClass',
version: '1.0',
},
auraNetworkCommandBaseClass: {
type: 'auraNetworkCommandBaseClass',
version: '1.0',
},
instrumentCommand: {
type: 'instrumentCommand',
version: '1.0',
},
};
let serviceRequirementsCastType = {
networkCommandBaseClass: code `${SERVICE_REQUEST_TYPE}<${NETWORK_COMMAND_BASE_CLASS_DESCRIPTOR}>`,
auraNetworkCommandBaseClass: code `${SERVICE_REQUEST_TYPE}<${AURA_NETWORK_COMMAND_BASE_CLASS_DESCRIPTOR}>`,
fetchNetworkCommandBaseClass: code `${SERVICE_REQUEST_TYPE}<${FETCH_NETWORK_COMMAND_BASE_CLASS_DESCRIPTOR}>`,
instrumentCommand: code `${SERVICE_REQUEST_TYPE}<${INSTRUMENT_COMMAND_DESCRIPTOR}>`,
};
for (let binding of bindings) {
const { adapterCode, commandInfo } = binding;
const { commandServicesInfo } = commandInfo;
const { serviceDependencies } = commandInfo;
// generate adapter declaration
file.push(code `${adapterCode.declaration};`);
commandServicesInfo.forEach((info) => {
if (Object.values(serviceRequirements).every((dep) => dep.type !== info.name || dep.version !== info.version)) {
serviceRequirements[info.name] = {
type: info.name,
version: info.version,
serviceDependencies.forEach((commandDependency) => {
if (Object.values(serviceRequirements).every((dep) => dep.type !== commandDependency.name ||
dep.version !== commandDependency.version)) {
serviceRequirements[commandDependency.name] = {
type: commandDependency.name,
version: commandDependency.version,
};
serviceRequirementsCastType[info.name] = code `${SERVICE_REQUEST_TYPE}<${info.descriptor}>`;
serviceRequirementsCastType[commandDependency.name] = code `${SERVICE_REQUEST_TYPE}<${commandDependency.descriptor}>`;
}

@@ -1269,0 +1305,0 @@ });

@@ -1,2 +0,2 @@

import { type FetchOperationCommandService, OperationCommand, type OperationCommandServiceInfo } from './operation-command';
import { type FetchOperationCommandService, OperationCommand } from './operation-command';
import type { NamedLoggerService } from '@luvio/utils';

@@ -8,6 +8,9 @@ import type { NamedTypeDeclarationService } from '../types';

export declare class AuraOperationCommandService extends OperationCommand implements FetchOperationCommandService {
get networkServiceInfo(): {
service: ImportableReference;
serviceInfo: OperationCommandServiceInfo;
};
serviceDependencies: {
version: "1.0";
descriptor: ImportableReference;
namedService: ImportableReference;
name: string;
}[];
commandBaseClass: ImportableReference;
getInputPayloadParameterName(config: {

@@ -17,3 +20,3 @@ endpoint: EndPoint;

}): string;
generateFetch(config: {
generateClassBody(config: {
api: API;

@@ -20,0 +23,0 @@ endpoint: EndPoint;

import { Code } from '../files';
import { type FetchOperationCommandService, OperationCommand, type OperationCommandServiceInfo } from './operation-command';
import { type FetchOperationCommandService, OperationCommand } from './operation-command';
import type { NamedLoggerService } from '@luvio/utils';

@@ -13,6 +13,9 @@ import type { NamedFileService, ImportableReference } from '../files';

}): string;
get networkServiceInfo(): {
service: ImportableReference;
serviceInfo: OperationCommandServiceInfo;
};
serviceDependencies: {
version: "1.0";
descriptor: ImportableReference;
namedService: ImportableReference;
name: string;
}[];
commandBaseClass: ImportableReference;
generateUrl(config: {

@@ -35,3 +38,3 @@ endpoint: EndPoint;

}): Code | undefined;
generateFetch(config: {
generateClassBody(config: {
api: API;

@@ -38,0 +41,0 @@ endpoint: EndPoint;

@@ -10,13 +10,15 @@ import type { NamedLoggerService, ServiceVersion } from '@luvio/utils';

method: HttpMethod;
commandServicesInfo: ReadonlyArray<OperationCommandServiceInfo>;
commandConfigType: ImportableReference;
commandClassName: string;
commandClassBuilder: ImportableReference;
commandSchemaConfigConst: ImportableReference;
serviceDependencies: ReadonlyArray<ServiceInfo>;
configType: ImportableReference;
className: string;
classBuilder: ImportableReference;
schemaConfigConst: ImportableReference;
outputTypeDef: Type | undefined;
baseClass: ImportableReference;
};
export type OperationCommandServiceInfo = {
name: string;
export type ServiceInfo = {
version: ServiceVersion;
descriptor: ImportableReference;
namedService: ImportableReference;
name: string;
};

@@ -93,12 +95,2 @@ /**

constructor(services: NamedAPIService & NamedFileService & NamedTypeDeclarationService & NamedLoggerService);
typeDefinitionFor(type: Type | undefined): Code;
getServer(endpoint: EndPoint, operation: Operation): Server;
createConfigType(endpoint: EndPoint, operation: Operation, request: Request, server: Server): ObjectType;
encodeParam(name: string, type: Type): string | undefined;
processUrl(config: {
endpoint: EndPoint;
operation: Operation;
request: Request;
server: Server;
}): string;
abstract getInputPayloadParameterName(config: {

@@ -108,3 +100,3 @@ endpoint: EndPoint;

}): string;
abstract generateFetch(config: {
abstract generateClassBody(config: {
api: API;

@@ -118,2 +110,14 @@ endpoint: EndPoint;

}): Code;
abstract get serviceDependencies(): ServiceInfo[];
abstract get commandBaseClass(): ImportableReference;
typeDefinitionFor(type: Type | undefined): Code;
getServer(endpoint: EndPoint, operation: Operation): Server;
createConfigType(endpoint: EndPoint, operation: Operation, request: Request, server: Server): ObjectType;
encodeParam(name: string, type: Type): string | undefined;
processUrl(config: {
endpoint: EndPoint;
operation: Operation;
request: Request;
server: Server;
}): string;
build(params: {

@@ -124,6 +128,2 @@ api: API;

}): OperationCommandInfo;
abstract get networkServiceInfo(): {
service: ImportableReference;
serviceInfo: OperationCommandServiceInfo;
};
}
{
"name": "@luvio/generator-ts",
"version": "5.2.0",
"version": "5.3.0",
"description": "Luvio TypeScript code generation",

@@ -24,9 +24,10 @@ "repository": {

"dependencies": {
"@luvio/model": "^5.2.0",
"@luvio/model": "^5.3.0",
"prettier": "^2.7.1"
},
"devDependencies": {
"@luvio/service-broker": "^5.2.0",
"@luvio/service-network": "^5.2.0",
"@luvio/utils": "^5.2.0",
"@luvio/service-aura-network": "^5.3.0",
"@luvio/service-broker": "^5.3.0",
"@luvio/service-fetch-network": "^5.3.0",
"@luvio/utils": "^5.3.0",
"memfs": "^3.4.13"

@@ -33,0 +34,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc