@rlanz/socket 0.0.1-8 → 0.0.1-9
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.
|
@@ -5,7 +5,9 @@ import "../chunk-E6ILCRL3.js";
|
|
|
5
5
|
|
|
6
6
|
// src/assembler_hook.ts
|
|
7
7
|
import fs from "fs";
|
|
8
|
-
import
|
|
8
|
+
import { createRequire } from "module";
|
|
9
|
+
var require2 = createRequire(import.meta.url);
|
|
10
|
+
var ts;
|
|
9
11
|
function quote(value) {
|
|
10
12
|
return `'${value.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
|
|
11
13
|
}
|
|
@@ -144,6 +146,7 @@ function inspectChannel(filePath, importPath) {
|
|
|
144
146
|
function generateSocketRegistry(options = {}) {
|
|
145
147
|
return {
|
|
146
148
|
run(_parent, hooks, indexGenerator) {
|
|
149
|
+
ts ??= require2("typescript");
|
|
147
150
|
const source = options.source ?? "./app/channels";
|
|
148
151
|
const glob = options.glob ?? ["**/*_channel.{ts,js}"];
|
|
149
152
|
const importAlias = appImportAlias(source);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/assembler_hook.ts"],"sourcesContent":["import fs from 'node:fs'\nimport ts from 'typescript'\nimport type { CommonHooks } from '@adonisjs/assembler/types'\nimport type { IndexGeneratorSourceConfig } from '@adonisjs/assembler/types'\nimport { BindableChannelPattern } from './bindable_channel_pattern.js'\n\nexport interface SocketAssemblerHookOptions {\n source?: string\n glob?: string[]\n output?: string\n}\n\ntype Handler = { event: string; method: string }\ntype Channel = {\n pattern: string\n bindablePattern: BindableChannelPattern\n importPath: string\n handlers: Handler[]\n}\ntype SocketAssemblerHook = Extract<CommonHooks['init'][number], { run: (...args: any[]) => any }>\n\nfunction quote(value: string) {\n return `'${value.replaceAll('\\\\', '\\\\\\\\').replaceAll(\"'\", \"\\\\'\")}'`\n}\n\nfunction generatedImportPath(importPath: string): string {\n return importPath.replace(/\\.ts$/, '')\n}\n\nfunction appImportAlias(source: string): string {\n const normalized = source.replace(/^\\.\\//, '')\n if (normalized === 'app') return '#app'\n if (normalized.startsWith('app/')) return `#app/${normalized.slice('app/'.length)}`\n throw new Error('[socket] Channel source must be inside the app directory')\n}\n\nfunction fail(filePath: string, message: string): never {\n throw new Error(`[socket] Cannot generate client types for ${filePath}: ${message}`)\n}\n\nfunction propertyName(node: ts.PropertyName | undefined): string | undefined {\n if (node && (ts.isIdentifier(node) || ts.isStringLiteral(node))) return node.text\n}\n\nfunction isPublic(method: ts.MethodDeclaration) {\n return !method.modifiers?.some(\n (modifier) =>\n modifier.kind === ts.SyntaxKind.PrivateKeyword ||\n modifier.kind === ts.SyntaxKind.ProtectedKeyword\n )\n}\n\nfunction isStatic(member: ts.ClassElement): boolean {\n return (\n ts.canHaveModifiers(member) &&\n !!ts.getModifiers(member)?.some((modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword)\n )\n}\n\nfunction validateHandlerMethod(filePath: string, method: ts.MethodDeclaration, name: string): void {\n const parameters = method.parameters.filter(\n (parameter) => !(ts.isIdentifier(parameter.name) && parameter.name.text === 'this')\n )\n if (parameters.some((parameter) => parameter.dotDotDotToken)) {\n fail(filePath, `handler method ${name} must not use rest parameters`)\n }\n if (parameters.slice(2).some((parameter) => !parameter.questionToken && !parameter.initializer)) {\n fail(filePath, `handler method ${name} must not require parameters after the payload`)\n }\n}\n\nfunction inspectChannel(filePath: string, importPath: string): Channel | string {\n const source = ts.createSourceFile(\n filePath,\n fs.readFileSync(filePath, 'utf8'),\n ts.ScriptTarget.Latest,\n true,\n filePath.endsWith('.js') ? ts.ScriptKind.JS : ts.ScriptKind.TS\n )\n const decoratorImports = new Set<string>()\n const decoratorNamespaces = new Set<string>()\n const baseChannelImports = new Set<string>()\n const socketNamespaces = new Set<string>()\n\n for (const statement of source.statements) {\n if (\n !ts.isImportDeclaration(statement) ||\n !ts.isStringLiteral(statement.moduleSpecifier) ||\n (statement.moduleSpecifier.text !== '@rlanz/socket/decorators' &&\n statement.moduleSpecifier.text !== '@rlanz/socket')\n ) {\n continue\n }\n\n const bindings = statement.importClause?.namedBindings\n if (bindings && ts.isNamedImports(bindings)) {\n for (const binding of bindings.elements) {\n const importedName = (binding.propertyName ?? binding.name).text\n if (\n statement.moduleSpecifier.text === '@rlanz/socket/decorators' &&\n importedName === 'onMessage'\n ) {\n decoratorImports.add(binding.name.text)\n }\n if (statement.moduleSpecifier.text === '@rlanz/socket' && importedName === 'BaseChannel') {\n baseChannelImports.add(binding.name.text)\n }\n }\n } else if (bindings && ts.isNamespaceImport(bindings)) {\n if (statement.moduleSpecifier.text === '@rlanz/socket/decorators') {\n decoratorNamespaces.add(bindings.name.text)\n } else {\n socketNamespaces.add(bindings.name.text)\n }\n }\n }\n\n const classes = source.statements.filter(ts.isClassDeclaration)\n let channelClass = classes.find((node) =>\n node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword)\n )\n\n if (!channelClass) {\n const defaultExport = source.statements.find(\n (node): node is ts.ExportAssignment => ts.isExportAssignment(node) && !node.isExportEquals\n )\n if (defaultExport && ts.isIdentifier(defaultExport.expression)) {\n const defaultClassName = defaultExport.expression.text\n channelClass = classes.find((node) => node.name?.text === defaultClassName)\n }\n }\n if (!channelClass) fail(filePath, 'a default-exported channel class was not found')\n if (channelClass.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AbstractKeyword)) {\n fail(filePath, 'the default-exported channel class must not be abstract')\n }\n\n const extendsType = channelClass.heritageClauses\n ?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword)\n ?.types.at(0)\n const extendsExpression = extendsType?.expression\n const directlyExtendsBaseChannel =\n (extendsExpression &&\n ts.isIdentifier(extendsExpression) &&\n baseChannelImports.has(extendsExpression.text)) ||\n (extendsExpression &&\n ts.isPropertyAccessExpression(extendsExpression) &&\n ts.isIdentifier(extendsExpression.expression) &&\n socketNamespaces.has(extendsExpression.expression.text) &&\n extendsExpression.name.text === 'BaseChannel')\n\n if (!directlyExtendsBaseChannel) {\n return (\n `Omitted ${importPath}: generated contracts do not support channel inheritance; ` +\n 'the default export must directly extend BaseChannel imported from @rlanz/socket.'\n )\n }\n\n const patternMember = channelClass.members.find(\n (member): member is ts.PropertyDeclaration =>\n ts.isPropertyDeclaration(member) &&\n propertyName(member.name) === 'pattern' &&\n !!member.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword)\n )\n if (\n !patternMember ||\n !patternMember.initializer ||\n !ts.isStringLiteral(patternMember.initializer)\n ) {\n return `Omitted ${importPath}: static pattern must be a direct string literal.`\n }\n\n const bindablePattern = BindableChannelPattern.parse(patternMember.initializer.text)\n if (!bindablePattern) {\n return (\n `Omitted ${importPath}: pattern ${quote(patternMember.initializer.text)} is not supported by ` +\n 'generated typing; use literals, required params, a final optional param, or a final wildcard.'\n )\n }\n\n const handlers: Handler[] = []\n for (const method of channelClass.members.filter(ts.isMethodDeclaration)) {\n for (const decorator of ts.getDecorators(method) ?? []) {\n const expression = decorator.expression\n const isImportedDecorator =\n ts.isCallExpression(expression) &&\n ((ts.isIdentifier(expression.expression) &&\n decoratorImports.has(expression.expression.text)) ||\n (ts.isPropertyAccessExpression(expression.expression) &&\n ts.isIdentifier(expression.expression.expression) &&\n decoratorNamespaces.has(expression.expression.expression.text) &&\n expression.expression.name.text === 'onMessage'))\n\n if (!isImportedDecorator || !ts.isCallExpression(expression)) {\n continue\n }\n\n if (isStatic(method)) {\n fail(filePath, '@onMessage cannot generate a contract for a static method')\n }\n\n if (expression.arguments.length !== 1 || !ts.isStringLiteral(expression.arguments[0])) {\n fail(\n filePath,\n `@onMessage on ${propertyName(method.name) ?? '<computed>'} needs a literal event`\n )\n }\n const event = expression.arguments[0].text\n const name = propertyName(method.name)\n if (!name || !ts.isIdentifier(method.name)) fail(filePath, '@onMessage methods must be named')\n if (!isPublic(method)) fail(filePath, `decorated handler method ${name} must be public`)\n validateHandlerMethod(filePath, method, name)\n if (handlers.some((handler) => handler.event === event)) {\n fail(filePath, `event \"${event}\" is mapped more than once`)\n }\n handlers.push({ event, method: name })\n }\n }\n\n return { pattern: patternMember.initializer.text, bindablePattern, importPath, handlers }\n}\n\n/** Registers generation of the application socket registry with AdonisJS Assembler. */\nexport function generateSocketRegistry(\n options: SocketAssemblerHookOptions = {}\n): SocketAssemblerHook {\n return {\n run(_parent, hooks, indexGenerator) {\n const source = options.source ?? './app/channels'\n const glob = options.glob ?? ['**/*_channel.{ts,js}']\n const importAlias = appImportAlias(source)\n\n indexGenerator.add('socketChannels', {\n source,\n glob,\n importAlias,\n output: options.output ?? './.adonisjs/client/socket.ts',\n as(vfs, buffer, _config, helpers) {\n const channels: Channel[] = []\n const diagnostics: string[] = []\n for (const filePath of Object.values(vfs.asList())) {\n const importPath = generatedImportPath(helpers.toImportPath(filePath))\n const inspected = inspectChannel(filePath, importPath)\n if (typeof inspected === 'string') diagnostics.push(inspected)\n else channels.push(inspected)\n }\n\n const patterns = new Set<string>()\n for (const channel of channels) {\n if (patterns.has(channel.bindablePattern.canonicalPattern)) {\n fail(\n channel.importPath,\n `pattern ${quote(channel.pattern)} is declared more than once`\n )\n }\n patterns.add(channel.bindablePattern.canonicalPattern)\n }\n\n for (const diagnostic of diagnostics) buffer.writeLine(`// [socket] ${diagnostic}`)\n if (diagnostics.length) buffer.writeLine('')\n buffer.writeLine('export interface AppSocket {').indent()\n buffer.writeLine('readonly channels: {').indent()\n for (const channel of channels) {\n buffer.writeLine(`readonly ${quote(channel.pattern)}: {`).indent()\n if (channel.bindablePattern.parameters.length === 0) {\n buffer.writeLine('readonly params: undefined')\n } else {\n buffer.writeLine('readonly params: {').indent()\n for (const parameter of channel.bindablePattern.parameters) {\n buffer.writeLine(\n `readonly ${quote(parameter.name)}${parameter.optional ? '?' : ''}: string | number`\n )\n }\n buffer.dedent().writeLine('}')\n }\n buffer.writeLine(\n `readonly channel: typeof import(${quote(channel.importPath)}).default`\n )\n buffer.writeLine('readonly handlers: {').indent()\n for (const handler of channel.handlers) {\n buffer.writeLine(`readonly ${quote(handler.event)}: ${quote(handler.method)}`)\n }\n buffer.dedent().writeLine('}')\n buffer.dedent().writeLine('}')\n }\n buffer.dedent().writeLine('}')\n buffer.dedent().writeLine('}')\n },\n } satisfies IndexGeneratorSourceConfig)\n\n indexGenerator.add('socketServerChannels', {\n source,\n glob,\n importAlias,\n output: './.adonisjs/server/socket_channels.ts',\n as(vfs, buffer, _config, helpers) {\n const filePaths = Object.values(vfs.asList())\n filePaths.forEach((filePath, index) => {\n const importPath = generatedImportPath(helpers.toImportPath(filePath))\n buffer.writeLine(`import Channel${index} from ${quote(importPath)}`)\n })\n if (filePaths.length) buffer.writeLine('')\n buffer.writeLine(\n `export const socketChannels = [${filePaths.map((_filePath, index) => `Channel${index}`).join(', ')}] as const`\n )\n },\n } satisfies IndexGeneratorSourceConfig)\n\n hooks.add('fileChanged', (_relativePath, absolutePath) => {\n return indexGenerator.addFile(absolutePath)\n })\n },\n }\n}\n\nconst socketRegistryHook = generateSocketRegistry()\nconst lazySocketRegistryHook: SocketAssemblerHook['run'] = socketRegistryHook.run\n\nexport default lazySocketRegistryHook\n"],"mappings":";;;;;;AAAA,OAAO,QAAQ;AACf,OAAO,QAAQ;AAoBf,SAAS,MAAM,OAAe;AAC5B,SAAO,IAAI,MAAM,WAAW,MAAM,MAAM,EAAE,WAAW,KAAK,KAAK,CAAC;AAClE;AAEA,SAAS,oBAAoB,YAA4B;AACvD,SAAO,WAAW,QAAQ,SAAS,EAAE;AACvC;AAEA,SAAS,eAAe,QAAwB;AAC9C,QAAM,aAAa,OAAO,QAAQ,SAAS,EAAE;AAC7C,MAAI,eAAe,MAAO,QAAO;AACjC,MAAI,WAAW,WAAW,MAAM,EAAG,QAAO,QAAQ,WAAW,MAAM,OAAO,MAAM,CAAC;AACjF,QAAM,IAAI,MAAM,0DAA0D;AAC5E;AAEA,SAAS,KAAK,UAAkB,SAAwB;AACtD,QAAM,IAAI,MAAM,6CAA6C,QAAQ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AAEA,IAAM,qBAAqB,uBAAuB;AAClD,IAAM,yBAAqD,mBAAmB;AAE9E,IAAO,yBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/assembler_hook.ts"],"sourcesContent":["import fs from 'node:fs'\nimport { createRequire } from 'node:module'\nimport type TypeScript from 'typescript'\nimport type { CommonHooks } from '@adonisjs/assembler/types'\nimport type { IndexGeneratorSourceConfig } from '@adonisjs/assembler/types'\nimport { BindableChannelPattern } from './bindable_channel_pattern.js'\n\nconst require = createRequire(import.meta.url)\nlet ts: typeof TypeScript\n\nexport interface SocketAssemblerHookOptions {\n source?: string\n glob?: string[]\n output?: string\n}\n\ntype Handler = { event: string; method: string }\ntype Channel = {\n pattern: string\n bindablePattern: BindableChannelPattern\n importPath: string\n handlers: Handler[]\n}\ntype SocketAssemblerHook = Extract<CommonHooks['init'][number], { run: (...args: any[]) => any }>\n\nfunction quote(value: string) {\n return `'${value.replaceAll('\\\\', '\\\\\\\\').replaceAll(\"'\", \"\\\\'\")}'`\n}\n\nfunction generatedImportPath(importPath: string): string {\n return importPath.replace(/\\.ts$/, '')\n}\n\nfunction appImportAlias(source: string): string {\n const normalized = source.replace(/^\\.\\//, '')\n if (normalized === 'app') return '#app'\n if (normalized.startsWith('app/')) return `#app/${normalized.slice('app/'.length)}`\n throw new Error('[socket] Channel source must be inside the app directory')\n}\n\nfunction fail(filePath: string, message: string): never {\n throw new Error(`[socket] Cannot generate client types for ${filePath}: ${message}`)\n}\n\nfunction propertyName(node: TypeScript.PropertyName | undefined): string | undefined {\n if (node && (ts.isIdentifier(node) || ts.isStringLiteral(node))) return node.text\n}\n\nfunction isPublic(method: TypeScript.MethodDeclaration) {\n return !method.modifiers?.some(\n (modifier) =>\n modifier.kind === ts.SyntaxKind.PrivateKeyword ||\n modifier.kind === ts.SyntaxKind.ProtectedKeyword\n )\n}\n\nfunction isStatic(member: TypeScript.ClassElement): boolean {\n return (\n ts.canHaveModifiers(member) &&\n !!ts.getModifiers(member)?.some((modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword)\n )\n}\n\nfunction validateHandlerMethod(\n filePath: string,\n method: TypeScript.MethodDeclaration,\n name: string\n): void {\n const parameters = method.parameters.filter(\n (parameter) => !(ts.isIdentifier(parameter.name) && parameter.name.text === 'this')\n )\n if (parameters.some((parameter) => parameter.dotDotDotToken)) {\n fail(filePath, `handler method ${name} must not use rest parameters`)\n }\n if (parameters.slice(2).some((parameter) => !parameter.questionToken && !parameter.initializer)) {\n fail(filePath, `handler method ${name} must not require parameters after the payload`)\n }\n}\n\nfunction inspectChannel(filePath: string, importPath: string): Channel | string {\n const source = ts.createSourceFile(\n filePath,\n fs.readFileSync(filePath, 'utf8'),\n ts.ScriptTarget.Latest,\n true,\n filePath.endsWith('.js') ? ts.ScriptKind.JS : ts.ScriptKind.TS\n )\n const decoratorImports = new Set<string>()\n const decoratorNamespaces = new Set<string>()\n const baseChannelImports = new Set<string>()\n const socketNamespaces = new Set<string>()\n\n for (const statement of source.statements) {\n if (\n !ts.isImportDeclaration(statement) ||\n !ts.isStringLiteral(statement.moduleSpecifier) ||\n (statement.moduleSpecifier.text !== '@rlanz/socket/decorators' &&\n statement.moduleSpecifier.text !== '@rlanz/socket')\n ) {\n continue\n }\n\n const bindings = statement.importClause?.namedBindings\n if (bindings && ts.isNamedImports(bindings)) {\n for (const binding of bindings.elements) {\n const importedName = (binding.propertyName ?? binding.name).text\n if (\n statement.moduleSpecifier.text === '@rlanz/socket/decorators' &&\n importedName === 'onMessage'\n ) {\n decoratorImports.add(binding.name.text)\n }\n if (statement.moduleSpecifier.text === '@rlanz/socket' && importedName === 'BaseChannel') {\n baseChannelImports.add(binding.name.text)\n }\n }\n } else if (bindings && ts.isNamespaceImport(bindings)) {\n if (statement.moduleSpecifier.text === '@rlanz/socket/decorators') {\n decoratorNamespaces.add(bindings.name.text)\n } else {\n socketNamespaces.add(bindings.name.text)\n }\n }\n }\n\n const classes = source.statements.filter(ts.isClassDeclaration)\n let channelClass = classes.find((node) =>\n node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword)\n )\n\n if (!channelClass) {\n const defaultExport = source.statements.find(\n (node): node is TypeScript.ExportAssignment =>\n ts.isExportAssignment(node) && !node.isExportEquals\n )\n if (defaultExport && ts.isIdentifier(defaultExport.expression)) {\n const defaultClassName = defaultExport.expression.text\n channelClass = classes.find((node) => node.name?.text === defaultClassName)\n }\n }\n if (!channelClass) fail(filePath, 'a default-exported channel class was not found')\n if (channelClass.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AbstractKeyword)) {\n fail(filePath, 'the default-exported channel class must not be abstract')\n }\n\n const extendsType = channelClass.heritageClauses\n ?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword)\n ?.types.at(0)\n const extendsExpression = extendsType?.expression\n const directlyExtendsBaseChannel =\n (extendsExpression &&\n ts.isIdentifier(extendsExpression) &&\n baseChannelImports.has(extendsExpression.text)) ||\n (extendsExpression &&\n ts.isPropertyAccessExpression(extendsExpression) &&\n ts.isIdentifier(extendsExpression.expression) &&\n socketNamespaces.has(extendsExpression.expression.text) &&\n extendsExpression.name.text === 'BaseChannel')\n\n if (!directlyExtendsBaseChannel) {\n return (\n `Omitted ${importPath}: generated contracts do not support channel inheritance; ` +\n 'the default export must directly extend BaseChannel imported from @rlanz/socket.'\n )\n }\n\n const patternMember = channelClass.members.find(\n (member): member is TypeScript.PropertyDeclaration =>\n ts.isPropertyDeclaration(member) &&\n propertyName(member.name) === 'pattern' &&\n !!member.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword)\n )\n if (\n !patternMember ||\n !patternMember.initializer ||\n !ts.isStringLiteral(patternMember.initializer)\n ) {\n return `Omitted ${importPath}: static pattern must be a direct string literal.`\n }\n\n const bindablePattern = BindableChannelPattern.parse(patternMember.initializer.text)\n if (!bindablePattern) {\n return (\n `Omitted ${importPath}: pattern ${quote(patternMember.initializer.text)} is not supported by ` +\n 'generated typing; use literals, required params, a final optional param, or a final wildcard.'\n )\n }\n\n const handlers: Handler[] = []\n for (const method of channelClass.members.filter(ts.isMethodDeclaration)) {\n for (const decorator of ts.getDecorators(method) ?? []) {\n const expression = decorator.expression\n const isImportedDecorator =\n ts.isCallExpression(expression) &&\n ((ts.isIdentifier(expression.expression) &&\n decoratorImports.has(expression.expression.text)) ||\n (ts.isPropertyAccessExpression(expression.expression) &&\n ts.isIdentifier(expression.expression.expression) &&\n decoratorNamespaces.has(expression.expression.expression.text) &&\n expression.expression.name.text === 'onMessage'))\n\n if (!isImportedDecorator || !ts.isCallExpression(expression)) {\n continue\n }\n\n if (isStatic(method)) {\n fail(filePath, '@onMessage cannot generate a contract for a static method')\n }\n\n if (expression.arguments.length !== 1 || !ts.isStringLiteral(expression.arguments[0])) {\n fail(\n filePath,\n `@onMessage on ${propertyName(method.name) ?? '<computed>'} needs a literal event`\n )\n }\n const event = expression.arguments[0].text\n const name = propertyName(method.name)\n if (!name || !ts.isIdentifier(method.name)) fail(filePath, '@onMessage methods must be named')\n if (!isPublic(method)) fail(filePath, `decorated handler method ${name} must be public`)\n validateHandlerMethod(filePath, method, name)\n if (handlers.some((handler) => handler.event === event)) {\n fail(filePath, `event \"${event}\" is mapped more than once`)\n }\n handlers.push({ event, method: name })\n }\n }\n\n return { pattern: patternMember.initializer.text, bindablePattern, importPath, handlers }\n}\n\n/** Registers generation of the application socket registry with AdonisJS Assembler. */\nexport function generateSocketRegistry(\n options: SocketAssemblerHookOptions = {}\n): SocketAssemblerHook {\n return {\n run(_parent, hooks, indexGenerator) {\n ts ??= require('typescript') as typeof TypeScript\n\n const source = options.source ?? './app/channels'\n const glob = options.glob ?? ['**/*_channel.{ts,js}']\n const importAlias = appImportAlias(source)\n\n indexGenerator.add('socketChannels', {\n source,\n glob,\n importAlias,\n output: options.output ?? './.adonisjs/client/socket.ts',\n as(vfs, buffer, _config, helpers) {\n const channels: Channel[] = []\n const diagnostics: string[] = []\n for (const filePath of Object.values(vfs.asList())) {\n const importPath = generatedImportPath(helpers.toImportPath(filePath))\n const inspected = inspectChannel(filePath, importPath)\n if (typeof inspected === 'string') diagnostics.push(inspected)\n else channels.push(inspected)\n }\n\n const patterns = new Set<string>()\n for (const channel of channels) {\n if (patterns.has(channel.bindablePattern.canonicalPattern)) {\n fail(\n channel.importPath,\n `pattern ${quote(channel.pattern)} is declared more than once`\n )\n }\n patterns.add(channel.bindablePattern.canonicalPattern)\n }\n\n for (const diagnostic of diagnostics) buffer.writeLine(`// [socket] ${diagnostic}`)\n if (diagnostics.length) buffer.writeLine('')\n buffer.writeLine('export interface AppSocket {').indent()\n buffer.writeLine('readonly channels: {').indent()\n for (const channel of channels) {\n buffer.writeLine(`readonly ${quote(channel.pattern)}: {`).indent()\n if (channel.bindablePattern.parameters.length === 0) {\n buffer.writeLine('readonly params: undefined')\n } else {\n buffer.writeLine('readonly params: {').indent()\n for (const parameter of channel.bindablePattern.parameters) {\n buffer.writeLine(\n `readonly ${quote(parameter.name)}${parameter.optional ? '?' : ''}: string | number`\n )\n }\n buffer.dedent().writeLine('}')\n }\n buffer.writeLine(\n `readonly channel: typeof import(${quote(channel.importPath)}).default`\n )\n buffer.writeLine('readonly handlers: {').indent()\n for (const handler of channel.handlers) {\n buffer.writeLine(`readonly ${quote(handler.event)}: ${quote(handler.method)}`)\n }\n buffer.dedent().writeLine('}')\n buffer.dedent().writeLine('}')\n }\n buffer.dedent().writeLine('}')\n buffer.dedent().writeLine('}')\n },\n } satisfies IndexGeneratorSourceConfig)\n\n indexGenerator.add('socketServerChannels', {\n source,\n glob,\n importAlias,\n output: './.adonisjs/server/socket_channels.ts',\n as(vfs, buffer, _config, helpers) {\n const filePaths = Object.values(vfs.asList())\n filePaths.forEach((filePath, index) => {\n const importPath = generatedImportPath(helpers.toImportPath(filePath))\n buffer.writeLine(`import Channel${index} from ${quote(importPath)}`)\n })\n if (filePaths.length) buffer.writeLine('')\n buffer.writeLine(\n `export const socketChannels = [${filePaths.map((_filePath, index) => `Channel${index}`).join(', ')}] as const`\n )\n },\n } satisfies IndexGeneratorSourceConfig)\n\n hooks.add('fileChanged', (_relativePath, absolutePath) => {\n return indexGenerator.addFile(absolutePath)\n })\n },\n }\n}\n\nconst socketRegistryHook = generateSocketRegistry()\nconst lazySocketRegistryHook: SocketAssemblerHook['run'] = socketRegistryHook.run\n\nexport default lazySocketRegistryHook\n"],"mappings":";;;;;;AAAA,OAAO,QAAQ;AACf,SAAS,qBAAqB;AAM9B,IAAMA,WAAU,cAAc,YAAY,GAAG;AAC7C,IAAI;AAiBJ,SAAS,MAAM,OAAe;AAC5B,SAAO,IAAI,MAAM,WAAW,MAAM,MAAM,EAAE,WAAW,KAAK,KAAK,CAAC;AAClE;AAEA,SAAS,oBAAoB,YAA4B;AACvD,SAAO,WAAW,QAAQ,SAAS,EAAE;AACvC;AAEA,SAAS,eAAe,QAAwB;AAC9C,QAAM,aAAa,OAAO,QAAQ,SAAS,EAAE;AAC7C,MAAI,eAAe,MAAO,QAAO;AACjC,MAAI,WAAW,WAAW,MAAM,EAAG,QAAO,QAAQ,WAAW,MAAM,OAAO,MAAM,CAAC;AACjF,QAAM,IAAI,MAAM,0DAA0D;AAC5E;AAEA,SAAS,KAAK,UAAkB,SAAwB;AACtD,QAAM,IAAI,MAAM,6CAA6C,QAAQ,KAAK,OAAO,EAAE;AACrF;AAEA,SAAS,aAAa,MAA+D;AACnF,MAAI,SAAS,GAAG,aAAa,IAAI,KAAK,GAAG,gBAAgB,IAAI,GAAI,QAAO,KAAK;AAC/E;AAEA,SAAS,SAAS,QAAsC;AACtD,SAAO,CAAC,OAAO,WAAW;AAAA,IACxB,CAAC,aACC,SAAS,SAAS,GAAG,WAAW,kBAChC,SAAS,SAAS,GAAG,WAAW;AAAA,EACpC;AACF;AAEA,SAAS,SAAS,QAA0C;AAC1D,SACE,GAAG,iBAAiB,MAAM,KAC1B,CAAC,CAAC,GAAG,aAAa,MAAM,GAAG,KAAK,CAAC,aAAa,SAAS,SAAS,GAAG,WAAW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7B,mBAAO,OAAO,EAAE,UAAU,GAAG;AAAA,UAC/B;AACA,iBAAO,OAAO,EAAE,UAAU,GAAG;AAC7B,iBAAO,OAAO,EAAE,UAAU,GAAG;AAAA,QAC/B;AAAA,MACF,CAAsC;AAEtC,qBAAe,IAAI,wBAAwB;AAAA,QACzC;AAAA,QACA;AAAA,QACA;AAAA,QACA,QAAQ;AAAA,QACR,GAAG,KAAK,QAAQ,SAAS,SAAS;AAChC,gBAAM,YAAY,OAAO,OAAO,IAAI,OAAO,CAAC;AAC5C,oBAAU,QAAQ,CAAC,UAAU,UAAU;AACrC,kBAAM,aAAa,oBAAoB,QAAQ,aAAa,QAAQ,CAAC;AACrE,mBAAO,UAAU,iBAAiB,KAAK,SAAS,MAAM,UAAU,CAAC,EAAE;AAAA,UACrE,CAAC;AACD,cAAI,UAAU,OAAQ,QAAO,UAAU,EAAE;AACzC,iBAAO;AAAA,YACL,kCAAkC,UAAU,IAAI,CAAC,WAAW,UAAU,UAAU,KAAK,EAAE,EAAE,KAAK,IAAI,CAAC;AAAA,UACrG;AAAA,QACF;AAAA,MACF,CAAsC;AAEtC,YAAM,IAAI,eAAe,CAAC,eAAe,iBAAiB;AACxD,eAAO,eAAe,QAAQ,YAAY;AAAA,MAC5C,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,IAAM,qBAAqB,uBAAuB;AAClD,IAAM,yBAAqD,mBAAmB;AAE9E,IAAO,yBAAQ;","names":["require"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rlanz/socket",
|
|
3
|
-
"version": "0.0.1-
|
|
3
|
+
"version": "0.0.1-9",
|
|
4
4
|
"description": "WebSocket integration for AdonisJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -32,12 +32,11 @@
|
|
|
32
32
|
"build": "npm run compile",
|
|
33
33
|
"clean": "del-cli build",
|
|
34
34
|
"compile": "npm run clean && tsup-node",
|
|
35
|
-
"check:package": "node --import=@poppinss/ts-exec bin/check_package.ts",
|
|
36
35
|
"lint": "oxlint",
|
|
37
36
|
"lint:fix": "oxlint --fix",
|
|
38
37
|
"format": "oxfmt --check .",
|
|
39
38
|
"format:fix": "oxfmt --write .",
|
|
40
|
-
"prepublishOnly": "npm run build
|
|
39
|
+
"prepublishOnly": "npm run build",
|
|
41
40
|
"release": "release-it",
|
|
42
41
|
"test": "node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts",
|
|
43
42
|
"typecheck": "tsc --noEmit",
|