@vaadin/hilla-generator-plugin-push 24.6.5 → 24.7.0-alpha11
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/PushProcessor.js +1 -1
- package/PushProcessor.js.map +2 -2
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js.map +1 -1
- package/package.json +11 -29
package/PushProcessor.js
CHANGED
|
@@ -80,7 +80,7 @@ class PushProcessor {
|
|
|
80
80
|
* @param declaration -
|
|
81
81
|
*/
|
|
82
82
|
#replacePromiseType(declaration) {
|
|
83
|
-
const promiseType = declaration.type.typeArguments
|
|
83
|
+
const [promiseType] = declaration.type.typeArguments;
|
|
84
84
|
const promiseArray = ts.isUnionTypeNode(promiseType) ? promiseType.types[0] : promiseType;
|
|
85
85
|
return ts.factory.createTypeReferenceNode(this.#subscriptionId(), promiseArray.typeArguments);
|
|
86
86
|
}
|
package/PushProcessor.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/PushProcessor.ts"],
|
|
4
|
-
"sourcesContent": ["import createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';\nimport memoize from '@vaadin/hilla-generator-utils/memoize.js';\nimport ts from 'typescript';\n\nconst initParameterTypeName = 'EndpointRequestInit';\n\nexport type EndpointOperations = {\n methodsToPatch: string[];\n removeInitImport: boolean;\n};\n\nexport class PushProcessor {\n readonly #dependencies = new DependencyManager(new PathManager({ extension: '.js' }));\n readonly #operations: EndpointOperations;\n readonly #source: ts.SourceFile;\n readonly #subscriptionId: () => ts.Identifier;\n\n constructor(source: ts.SourceFile, operations: EndpointOperations) {\n this.#operations = operations;\n this.#source = source;\n\n const { imports, paths } = this.#dependencies;\n\n this.#dependencies.imports.fromCode(source);\n this.#subscriptionId = memoize(() =>\n imports.named.add(paths.createBareModulePath('@vaadin/hilla-frontend', false), 'Subscription'),\n );\n }\n\n process(): ts.SourceFile {\n const otherStatements = this.#source.statements\n .filter((statement) => !ts.isImportDeclaration(statement))\n .map((statement) => {\n if (ts.isFunctionDeclaration(statement)) {\n const functionName = statement.name?.text;\n\n // Checks if the method is in the list of methods to patch\n if (functionName && this.#operations.methodsToPatch.includes(functionName)) {\n return this.#updateFunction(statement);\n }\n }\n\n return statement;\n });\n\n let importStatements = this.#dependencies.imports.toCode();\n\n if (this.#operations.removeInitImport) {\n const importHillaFrontend = importStatements.find(\n (statement) =>\n ts.isImportDeclaration(statement) &&\n (statement.moduleSpecifier as ts.StringLiteral).text === '@vaadin/hilla-frontend',\n );\n\n if (importHillaFrontend) {\n const updatedImportStatement = PushProcessor.#removeInitImport(importHillaFrontend as ts.ImportDeclaration);\n\n if (updatedImportStatement) {\n importStatements = importStatements.map((statement) => {\n if (statement === importHillaFrontend) {\n return updatedImportStatement;\n }\n\n return statement;\n });\n }\n }\n }\n\n const updatedStatements: readonly ts.Statement[] = [...importStatements, ...otherStatements];\n\n return createSourceFile(updatedStatements, this.#source.fileName);\n }\n\n static #doesInitParameterExist(parameters: ts.NodeArray<ts.ParameterDeclaration>): boolean {\n const last = parameters[parameters.length - 1];\n const lastType = last.type as ts.TypeReferenceNode;\n const lastTypeName = lastType.typeName as ts.Identifier;\n\n return lastTypeName.text === initParameterTypeName;\n }\n\n static #removeInitImport(importStatement: ts.ImportDeclaration): ts.Statement | undefined {\n const namedImports = importStatement.importClause?.namedBindings;\n if (namedImports && ts.isNamedImports(namedImports)) {\n const updatedElements = namedImports.elements.filter((element) => element.name.text !== 'EndpointRequestInit');\n\n const updatedImportClause = ts.factory.updateImportClause(\n importStatement.importClause,\n false, // FIXME: could be true, but it is false for regular endpoint calls, so sticking to that for now\n undefined,\n ts.factory.createNamedImports(updatedElements),\n );\n\n return ts.factory.updateImportDeclaration(\n importStatement,\n undefined,\n updatedImportClause,\n importStatement.moduleSpecifier,\n undefined,\n );\n }\n\n return undefined;\n }\n\n /**\n * Replace returned `Promise<Array<T>>` by the `Subscription<T>` type\n * @param declaration -\n */\n #replacePromiseType(declaration: ts.FunctionDeclaration) {\n const promiseType = (declaration.type as ts.TypeReferenceNode).typeArguments
|
|
5
|
-
"mappings": "AAAA,OAAO,sBAAsB;AAC7B,OAAO,uBAAuB;AAC9B,OAAO,iBAAiB;AACxB,OAAO,aAAa;AACpB,OAAO,QAAQ;AAEf,MAAM,wBAAwB;AAOvB,MAAM,cAAc;AAAA,EAChB,gBAAgB,IAAI,kBAAkB,IAAI,YAAY,EAAE,WAAW,MAAM,CAAC,CAAC;AAAA,EAC3E;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAuB,YAAgC;AACjE,SAAK,cAAc;AACnB,SAAK,UAAU;AAEf,UAAM,EAAE,SAAS,MAAM,IAAI,KAAK;AAEhC,SAAK,cAAc,QAAQ,SAAS,MAAM;AAC1C,SAAK,kBAAkB;AAAA,MAAQ,MAC7B,QAAQ,MAAM,IAAI,MAAM,qBAAqB,0BAA0B,KAAK,GAAG,cAAc;AAAA,IAC/F;AAAA,EACF;AAAA,EAEA,UAAyB;AACvB,UAAM,kBAAkB,KAAK,QAAQ,WAClC,OAAO,CAAC,cAAc,CAAC,GAAG,oBAAoB,SAAS,CAAC,EACxD,IAAI,CAAC,cAAc;AAClB,UAAI,GAAG,sBAAsB,SAAS,GAAG;AACvC,cAAM,eAAe,UAAU,MAAM;AAGrC,YAAI,gBAAgB,KAAK,YAAY,eAAe,SAAS,YAAY,GAAG;AAC1E,iBAAO,KAAK,gBAAgB,SAAS;AAAA,QACvC;AAAA,MACF;AAEA,aAAO;AAAA,IACT,CAAC;AAEH,QAAI,mBAAmB,KAAK,cAAc,QAAQ,OAAO;AAEzD,QAAI,KAAK,YAAY,kBAAkB;AACrC,YAAM,sBAAsB,iBAAiB;AAAA,QAC3C,CAAC,cACC,GAAG,oBAAoB,SAAS,KAC/B,UAAU,gBAAqC,SAAS;AAAA,MAC7D;AAEA,UAAI,qBAAqB;AACvB,cAAM,yBAAyB,cAAc,kBAAkB,mBAA2C;AAE1G,YAAI,wBAAwB;AAC1B,6BAAmB,iBAAiB,IAAI,CAAC,cAAc;AACrD,gBAAI,cAAc,qBAAqB;AACrC,qBAAO;AAAA,YACT;AAEA,mBAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAA6C,CAAC,GAAG,kBAAkB,GAAG,eAAe;AAE3F,WAAO,iBAAiB,mBAAmB,KAAK,QAAQ,QAAQ;AAAA,EAClE;AAAA,EAEA,OAAO,wBAAwB,YAA4D;AACzF,UAAM,OAAO,WAAW,WAAW,SAAS,CAAC;AAC7C,UAAM,WAAW,KAAK;AACtB,UAAM,eAAe,SAAS;AAE9B,WAAO,aAAa,SAAS;AAAA,EAC/B;AAAA,EAEA,OAAO,kBAAkB,iBAAiE;AACxF,UAAM,eAAe,gBAAgB,cAAc;AACnD,QAAI,gBAAgB,GAAG,eAAe,YAAY,GAAG;AACnD,YAAM,kBAAkB,aAAa,SAAS,OAAO,CAAC,YAAY,QAAQ,KAAK,SAAS,qBAAqB;AAE7G,YAAM,sBAAsB,GAAG,QAAQ;AAAA,QACrC,gBAAgB;AAAA,QAChB;AAAA;AAAA,QACA;AAAA,QACA,GAAG,QAAQ,mBAAmB,eAAe;AAAA,MAC/C;AAEA,aAAO,GAAG,QAAQ;AAAA,QAChB;AAAA,QACA;AAAA,QACA;AAAA,QACA,gBAAgB;AAAA,QAChB;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,oBAAoB,aAAqC;AACvD,UAAM,
|
|
4
|
+
"sourcesContent": ["import createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';\nimport memoize from '@vaadin/hilla-generator-utils/memoize.js';\nimport ts from 'typescript';\n\nconst initParameterTypeName = 'EndpointRequestInit';\n\nexport type EndpointOperations = {\n methodsToPatch: string[];\n removeInitImport: boolean;\n};\n\nexport class PushProcessor {\n readonly #dependencies = new DependencyManager(new PathManager({ extension: '.js' }));\n readonly #operations: EndpointOperations;\n readonly #source: ts.SourceFile;\n readonly #subscriptionId: () => ts.Identifier;\n\n constructor(source: ts.SourceFile, operations: EndpointOperations) {\n this.#operations = operations;\n this.#source = source;\n\n const { imports, paths } = this.#dependencies;\n\n this.#dependencies.imports.fromCode(source);\n this.#subscriptionId = memoize(() =>\n imports.named.add(paths.createBareModulePath('@vaadin/hilla-frontend', false), 'Subscription'),\n );\n }\n\n process(): ts.SourceFile {\n const otherStatements = this.#source.statements\n .filter((statement) => !ts.isImportDeclaration(statement))\n .map((statement) => {\n if (ts.isFunctionDeclaration(statement)) {\n const functionName = statement.name?.text;\n\n // Checks if the method is in the list of methods to patch\n if (functionName && this.#operations.methodsToPatch.includes(functionName)) {\n return this.#updateFunction(statement);\n }\n }\n\n return statement;\n });\n\n let importStatements = this.#dependencies.imports.toCode();\n\n if (this.#operations.removeInitImport) {\n const importHillaFrontend = importStatements.find(\n (statement) =>\n ts.isImportDeclaration(statement) &&\n (statement.moduleSpecifier as ts.StringLiteral).text === '@vaadin/hilla-frontend',\n );\n\n if (importHillaFrontend) {\n const updatedImportStatement = PushProcessor.#removeInitImport(importHillaFrontend as ts.ImportDeclaration);\n\n if (updatedImportStatement) {\n importStatements = importStatements.map((statement) => {\n if (statement === importHillaFrontend) {\n return updatedImportStatement;\n }\n\n return statement;\n });\n }\n }\n }\n\n const updatedStatements: readonly ts.Statement[] = [...importStatements, ...otherStatements];\n\n return createSourceFile(updatedStatements, this.#source.fileName);\n }\n\n static #doesInitParameterExist(parameters: ts.NodeArray<ts.ParameterDeclaration>): boolean {\n const last = parameters[parameters.length - 1];\n const lastType = last.type as ts.TypeReferenceNode;\n const lastTypeName = lastType.typeName as ts.Identifier;\n\n return lastTypeName.text === initParameterTypeName;\n }\n\n static #removeInitImport(importStatement: ts.ImportDeclaration): ts.Statement | undefined {\n const namedImports = importStatement.importClause?.namedBindings;\n if (namedImports && ts.isNamedImports(namedImports)) {\n const updatedElements = namedImports.elements.filter((element) => element.name.text !== 'EndpointRequestInit');\n\n const updatedImportClause = ts.factory.updateImportClause(\n importStatement.importClause,\n false, // FIXME: could be true, but it is false for regular endpoint calls, so sticking to that for now\n undefined,\n ts.factory.createNamedImports(updatedElements),\n );\n\n return ts.factory.updateImportDeclaration(\n importStatement,\n undefined,\n updatedImportClause,\n importStatement.moduleSpecifier,\n undefined,\n );\n }\n\n return undefined;\n }\n\n /**\n * Replace returned `Promise<Array<T>>` by the `Subscription<T>` type\n * @param declaration -\n */\n #replacePromiseType(declaration: ts.FunctionDeclaration) {\n const [promiseType] = (declaration.type as ts.TypeReferenceNode).typeArguments!;\n const promiseArray = (ts.isUnionTypeNode(promiseType) ? promiseType.types[0] : promiseType) as ts.TypeReferenceNode;\n\n return ts.factory.createTypeReferenceNode(this.#subscriptionId(), promiseArray.typeArguments);\n }\n\n #updateFunction(declaration: ts.FunctionDeclaration): ts.FunctionDeclaration {\n const { parameters } = declaration;\n const doesInitParameterExist = PushProcessor.#doesInitParameterExist(parameters);\n\n return ts.factory.createFunctionDeclaration(\n undefined, // no async\n declaration.asteriskToken,\n declaration.name,\n declaration.typeParameters,\n // Remove the `init` parameter\n doesInitParameterExist ? parameters.slice(0, -1) : parameters,\n this.#replacePromiseType(declaration),\n PushProcessor.#updateFunctionBody(declaration, doesInitParameterExist),\n );\n }\n\n static #updateFunctionBody(declaration: ts.FunctionDeclaration, doesInitParameterExist: boolean): ts.Block {\n const returnStatement = declaration.body!.statements[0] as ts.ReturnStatement;\n const { arguments: args, expression, typeArguments } = returnStatement.expression! as ts.CallExpression;\n const call = expression as ts.PropertyAccessExpression;\n\n return ts.factory.createBlock([\n ts.factory.createReturnStatement(\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n call.expression,\n // `subscribe` instead of `call`\n ts.factory.createIdentifier('subscribe'),\n ),\n typeArguments,\n // remove the `init` parameter\n doesInitParameterExist ? args.slice(0, -1) : args,\n ),\n ),\n ]);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,sBAAsB;AAC7B,OAAO,uBAAuB;AAC9B,OAAO,iBAAiB;AACxB,OAAO,aAAa;AACpB,OAAO,QAAQ;AAEf,MAAM,wBAAwB;AAOvB,MAAM,cAAc;AAAA,EAChB,gBAAgB,IAAI,kBAAkB,IAAI,YAAY,EAAE,WAAW,MAAM,CAAC,CAAC;AAAA,EAC3E;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAuB,YAAgC;AACjE,SAAK,cAAc;AACnB,SAAK,UAAU;AAEf,UAAM,EAAE,SAAS,MAAM,IAAI,KAAK;AAEhC,SAAK,cAAc,QAAQ,SAAS,MAAM;AAC1C,SAAK,kBAAkB;AAAA,MAAQ,MAC7B,QAAQ,MAAM,IAAI,MAAM,qBAAqB,0BAA0B,KAAK,GAAG,cAAc;AAAA,IAC/F;AAAA,EACF;AAAA,EAEA,UAAyB;AACvB,UAAM,kBAAkB,KAAK,QAAQ,WAClC,OAAO,CAAC,cAAc,CAAC,GAAG,oBAAoB,SAAS,CAAC,EACxD,IAAI,CAAC,cAAc;AAClB,UAAI,GAAG,sBAAsB,SAAS,GAAG;AACvC,cAAM,eAAe,UAAU,MAAM;AAGrC,YAAI,gBAAgB,KAAK,YAAY,eAAe,SAAS,YAAY,GAAG;AAC1E,iBAAO,KAAK,gBAAgB,SAAS;AAAA,QACvC;AAAA,MACF;AAEA,aAAO;AAAA,IACT,CAAC;AAEH,QAAI,mBAAmB,KAAK,cAAc,QAAQ,OAAO;AAEzD,QAAI,KAAK,YAAY,kBAAkB;AACrC,YAAM,sBAAsB,iBAAiB;AAAA,QAC3C,C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AAG,QAAQ,wBAAwB,KAAK,gBAAgB,GAAG,aAAa,aAAa;AAAA,EAC9F;AAAA,EAEA,gBAAgB,aAA6D;AAC3E,UAAM,EAAE,WAAW,IAAI;AACvB,UAAM,yBAAyB,cAAc,wBAAwB,UAAU;AAE/E,WAAO,GAAG,QAAQ;AAAA,MAChB;AAAA;AAAA,MACA,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,YAAY;AAAA;AAAA,MAEZ,yBAAyB,WAAW,MAAM,GAAG,EAAE,IAAI;AAAA,MACnD,KAAK,oBAAoB,WAAW;AAAA,MACpC,cAAc,oBAAoB,aAAa,sBAAsB;AAAA,IACvE;AAAA,EACF;AAAA,EAEA,OAAO,oBAAoB,aAAqC,wBAA2C;AACzG,UAAM,kBAAkB,YAAY,KAAM,WAAW,CAAC;AACtD,UAAM,EAAE,WAAW,MAAM,YAAY,cAAc,IAAI,gBAAgB;AACvE,UAAM,OAAO;AAEb,WAAO,GAAG,QAAQ,YAAY;AAAA,MAC5B,GAAG,QAAQ;AAAA,QACT,GAAG,QAAQ;AAAA,UACT,GAAG,QAAQ;AAAA,YACT,KAAK;AAAA;AAAA,YAEL,GAAG,QAAQ,iBAAiB,WAAW;AAAA,UACzC;AAAA,UACA;AAAA;AAAA,UAEA,yBAAyB,KAAK,MAAM,GAAG,EAAE,IAAI;AAAA,QAC/C;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Plugin from '@vaadin/hilla-generator-core/Plugin.js';
|
|
2
|
-
import type SharedStorage from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
2
|
+
import type { SharedStorage } from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
3
3
|
export default class PushPlugin extends Plugin {
|
|
4
4
|
#private;
|
|
5
5
|
['constructor']: typeof PushPlugin;
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wCAAwC,CAAC;AAC5D,OAAO,KAAK,aAAa,MAAM,+CAA+C,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wCAAwC,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AAanF,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,MAAM;;IA+BpC,CAAC,aAAa,CAAC,EAAE,OAAO,UAAU,CAAC;IAE3C,IAAa,IAAI,IAAI,MAAM,CAE1B;IAGc,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAa9D"}
|
package/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport type SharedStorage from '@vaadin/hilla-generator-core/SharedStorage.js';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { ReadonlyObjectDeep } from 'type-fest/source/readonly-deep';\nimport { type EndpointOperations, PushProcessor } from './PushProcessor.js';\n\ntype ExtendedMediaTypeSchema = Readonly<{ 'x-class-name': string }> &\n ReadonlyObjectDeep<OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject>;\n\nconst classesToReplace: readonly string[] = [\n 'com.vaadin.hilla.runtime.transfertypes.Flux',\n 'com.vaadin.hilla.runtime.transfertypes.EndpointSubscription',\n];\n\nexport default class PushPlugin extends Plugin {\n /**\n * Collects methods that must be patched by checking their `x-class-name` value\n */\n static #collectPatchableMethods(paths: ReadonlyObjectDeep<OpenAPIV3.PathsObject>) {\n return Object.entries(paths).reduce((acc, [key, path]) => {\n const response = path?.post?.responses[200] as ReadonlyObjectDeep<OpenAPIV3.ResponseObject> | undefined;\n const schema = response?.content?.['application/json']?.schema as ExtendedMediaTypeSchema | undefined;\n const className = schema?.['x-class-name'];\n const [, endpoint, method] = key.split('/');\n\n if (className && classesToReplace.includes(className)) {\n if (acc.has(endpoint)) {\n acc.get(endpoint)!.methodsToPatch.push(method);\n } else {\n acc.set(endpoint, { methodsToPatch: [method], removeInitImport: true });\n }\n } else {\n // Not all methods will be patched, let's keep the init import\n // eslint-disable-next-line no-lonely-if\n if (acc.has(endpoint)) {\n acc.get(endpoint)!.removeInitImport = false;\n } else {\n acc.set(endpoint, { methodsToPatch: [], removeInitImport: false });\n }\n }\n\n return acc;\n }, new Map<string, EndpointOperations>());\n }\n\n declare ['constructor']: typeof PushPlugin;\n\n override get path(): string {\n return import.meta.url;\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n override async execute(storage: SharedStorage): Promise<void> {\n const { api, sources } = storage;\n const endpointMethodMap = this.constructor.#collectPatchableMethods(api.paths);\n\n for (let i = 0; i < sources.length; i++) {\n const { fileName } = sources[i];\n const endpoint = fileName.substring(0, fileName.indexOf('.ts'));\n\n if (endpointMethodMap.has(endpoint)) {\n sources[i] = new PushProcessor(sources[i], endpointMethodMap.get(endpoint)!).process();\n }\n }\n }\n}\n"],
|
|
4
|
+
"sourcesContent": ["import Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport type { SharedStorage } from '@vaadin/hilla-generator-core/SharedStorage.js';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { ReadonlyObjectDeep } from 'type-fest/source/readonly-deep';\nimport { type EndpointOperations, PushProcessor } from './PushProcessor.js';\n\ntype ExtendedMediaTypeSchema = Readonly<{ 'x-class-name': string }> &\n ReadonlyObjectDeep<OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject>;\n\nconst classesToReplace: readonly string[] = [\n 'com.vaadin.hilla.runtime.transfertypes.Flux',\n 'com.vaadin.hilla.runtime.transfertypes.EndpointSubscription',\n];\n\nexport default class PushPlugin extends Plugin {\n /**\n * Collects methods that must be patched by checking their `x-class-name` value\n */\n static #collectPatchableMethods(paths: ReadonlyObjectDeep<OpenAPIV3.PathsObject>) {\n return Object.entries(paths).reduce((acc, [key, path]) => {\n const response = path?.post?.responses[200] as ReadonlyObjectDeep<OpenAPIV3.ResponseObject> | undefined;\n const schema = response?.content?.['application/json']?.schema as ExtendedMediaTypeSchema | undefined;\n const className = schema?.['x-class-name'];\n const [, endpoint, method] = key.split('/');\n\n if (className && classesToReplace.includes(className)) {\n if (acc.has(endpoint)) {\n acc.get(endpoint)!.methodsToPatch.push(method);\n } else {\n acc.set(endpoint, { methodsToPatch: [method], removeInitImport: true });\n }\n } else {\n // Not all methods will be patched, let's keep the init import\n // eslint-disable-next-line no-lonely-if\n if (acc.has(endpoint)) {\n acc.get(endpoint)!.removeInitImport = false;\n } else {\n acc.set(endpoint, { methodsToPatch: [], removeInitImport: false });\n }\n }\n\n return acc;\n }, new Map<string, EndpointOperations>());\n }\n\n declare ['constructor']: typeof PushPlugin;\n\n override get path(): string {\n return import.meta.url;\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n override async execute(storage: SharedStorage): Promise<void> {\n const { api, sources } = storage;\n const endpointMethodMap = this.constructor.#collectPatchableMethods(api.paths);\n\n for (let i = 0; i < sources.length; i++) {\n const { fileName } = sources[i];\n const endpoint = fileName.substring(0, fileName.indexOf('.ts'));\n\n if (endpointMethodMap.has(endpoint)) {\n sources[i] = new PushProcessor(sources[i], endpointMethodMap.get(endpoint)!).process();\n }\n }\n }\n}\n"],
|
|
5
5
|
"mappings": "AAAA,OAAO,YAAY;AAInB,SAAkC,qBAAqB;AAKvD,MAAM,mBAAsC;AAAA,EAC1C;AAAA,EACA;AACF;AAEA,MAAO,mBAAiC,OAAO;AAAA;AAAA;AAAA;AAAA,EAI7C,OAAO,yBAAyB,OAAkD;AAChF,WAAO,OAAO,QAAQ,KAAK,EAAE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;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/hilla-generator-plugin-push",
|
|
3
|
-
"version": "24.
|
|
3
|
+
"version": "24.7.0-alpha11",
|
|
4
4
|
"description": "A Hilla TypeScript Generator plugin to add push support",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
"build:copy": "cd src && copyfiles **/*.d.ts ..",
|
|
16
16
|
"lint": "eslint src test",
|
|
17
17
|
"lint:fix": "eslint src test --fix",
|
|
18
|
-
"test": "
|
|
19
|
-
"test:
|
|
20
|
-
"test:
|
|
18
|
+
"test": "vitest --run",
|
|
19
|
+
"test:coverage": "vitest --run --coverage",
|
|
20
|
+
"test:update": "vitest --run --update",
|
|
21
|
+
"test:watch": "vitest",
|
|
21
22
|
"typecheck": "tsc --noEmit"
|
|
22
23
|
},
|
|
23
24
|
"exports": {
|
|
@@ -51,30 +52,11 @@
|
|
|
51
52
|
"access": "public"
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
|
-
"@vaadin/hilla-generator-core": "24.
|
|
55
|
-
"@vaadin/hilla-generator-plugin-client": "24.
|
|
56
|
-
"@vaadin/hilla-generator-utils": "24.
|
|
57
|
-
"fast-deep-equal": "
|
|
58
|
-
"openapi-types": "
|
|
59
|
-
"typescript": "5.7.
|
|
60
|
-
},
|
|
61
|
-
"devDependencies": {
|
|
62
|
-
"@types/chai": "^4.3.6",
|
|
63
|
-
"@types/mocha": "^10.0.2",
|
|
64
|
-
"@types/node": "^20.7.1",
|
|
65
|
-
"@types/sinon": "^10.0.17",
|
|
66
|
-
"@types/sinon-chai": "^3.2.10",
|
|
67
|
-
"@vaadin/hilla-generator-core": "24.6.5",
|
|
68
|
-
"@vaadin/hilla-generator-plugin-client": "24.6.5",
|
|
69
|
-
"c8": "^10.1.2",
|
|
70
|
-
"chai": "^4.3.10",
|
|
71
|
-
"concurrently": "^8.2.1",
|
|
72
|
-
"copyfiles": "^2.4.1",
|
|
73
|
-
"mocha": "^10.8.2",
|
|
74
|
-
"monocart-coverage-reports": "^2.11.5",
|
|
75
|
-
"pino": "^8.21.0",
|
|
76
|
-
"sinon": "^16.1.3",
|
|
77
|
-
"sinon-chai": "^3.7.0",
|
|
78
|
-
"type-fest": "^4.3.2"
|
|
55
|
+
"@vaadin/hilla-generator-core": "24.7.0-alpha11",
|
|
56
|
+
"@vaadin/hilla-generator-plugin-client": "24.7.0-alpha11",
|
|
57
|
+
"@vaadin/hilla-generator-utils": "24.7.0-alpha11",
|
|
58
|
+
"fast-deep-equal": "3.1.3",
|
|
59
|
+
"openapi-types": "12.1.3",
|
|
60
|
+
"typescript": "5.7.3"
|
|
79
61
|
}
|
|
80
62
|
}
|