Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved dynamic types #6

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 50 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@digital-alchemy/type-writer",
"repository": "https://github.com/Digital-Alchemy-TS/type-writer",
"homepage": "https://docs.digital-alchemy.app/Type-Writer",
"version": "0.3.7",
"version": "0.3.8",
"scripts": {
"build": "rm -rf dist/; tsc",
"lint": "eslint src",
Expand All @@ -26,7 +26,7 @@
"license": "MIT",
"dependencies": {
"@digital-alchemy/core": "^0.3.11",
"@digital-alchemy/hass": "^0.3.10",
"@digital-alchemy/hass": "^0.3.13",
"js-yaml": "^4.1.0"
},
"devDependencies": {
Expand All @@ -38,8 +38,8 @@
"@types/mute-stream": "^0.0.4",
"@types/node": "^20.12.7",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "7.6.0",
"@typescript-eslint/parser": "7.6.0",
"@typescript-eslint/eslint-plugin": "7.7.0",
"@typescript-eslint/parser": "7.7.0",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "^2.29.1",
Expand Down
25 changes: 24 additions & 1 deletion src/build.extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,36 @@ export function BuildTypes({
`// This file is generated, and is automatically updated as a npm post install step`,
"// Do not edit this file, it will only affect type definitions, not functional code",
`import { PICK_ENTITY } from "./helpers";`,
``,
`// #MARK: ENTITY_SETUP`,
`export const ENTITY_SETUP = ${JSON.stringify(entitySetup, undefined, " ")};`,
``,
`// #MARK: iCallService`,
typeInterface,
``,
`// #MARK: REGISTRY_SETUP`,
type_writer.identifiers.RegistryDetails(),
``,
`// #MARK: TAreaId`,
type_writer.identifiers.area(),
``,
`// #MARK: TDeviceId`,
type_writer.identifiers.device(),
``,
`// #MARK: TFloorId`,
type_writer.identifiers.floor(),
``,
`// #MARK: TLabelId`,
type_writer.identifiers.label(),
``,
`// #MARK: TZoneId`,
type_writer.identifiers.zone(),
].join(`\n\n`);
``,
`// #MARK: TRawEntityIds`,
type_writer.identifiers.entityIds(entities),
``,
`// #MARK: TRawDomains`,
type_writer.identifiers.domains(entities),
].join(`\n`);
}
}
25 changes: 15 additions & 10 deletions src/i-call-service.extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,22 @@ export async function ICallServiceExtension({

// #MARK: BuildDomain
function buildDomain({ domain, services }: HassServiceDTO) {
return factory.createPropertySignature(
undefined,
factory.createIdentifier(domain),
undefined,
factory.createTypeLiteralNode(
// Create functions based on provided services
// { [...service_name](service_data): Promise<void> }
Object.entries(services)
.sort(([a], [b]) => (a > b ? UP : DOWN))
.map(([key, value]) => buildService(domain, key, value)),
return addSyntheticLeadingComment(
factory.createPropertySignature(
undefined,
factory.createIdentifier(domain),
undefined,
factory.createTypeLiteralNode(
// Create functions based on provided services
// { [...service_name](service_data): Promise<void> }
Object.entries(services)
.sort(([a], [b]) => (a > b ? UP : DOWN))
.map(([key, value]) => buildService(domain, key, value)),
),
),
SyntaxKind.SingleLineCommentTrivia,
`#MARK: ${domain}`,
true,
);
}

Expand Down
Loading
Loading