@uns-kit/core 0.0.1 → 0.0.3

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.
@@ -174,4 +174,7 @@ export type AppConfig = {
174
174
  })) | undefined;
175
175
  clientId?: string | undefined;
176
176
  };
177
+ devops?: {
178
+ organization: string;
179
+ } | undefined;
177
180
  };
@@ -1,14 +1,56 @@
1
- // scripts/generate-config-artifacts.ts
2
1
  import fs from "node:fs";
3
2
  import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
4
  import { zodToJsonSchema } from "zod-to-json-schema";
5
5
  import { zodToTs, printNode } from "zod-to-ts";
6
- // Import the plain ZodObject (no superRefine)
7
- import { baseSchema } from "../uns-config/config-schema.js";
6
+ import { composeConfigSchema } from "../uns-config/schema-tools.js";
7
+ import { unsCoreSchema } from "../uns-config/uns-core-schema.js";
8
+ import { projectExtrasSchema as coreProjectExtrasSchema } from "../config/project.config.extension.js";
8
9
  function write(filePath, data) {
9
10
  fs.mkdirSync(path.dirname(filePath), { recursive: true });
10
11
  fs.writeFileSync(filePath, data);
11
12
  }
13
+ let tsLoaderReady = false;
14
+ async function ensureTsLoader() {
15
+ if (tsLoaderReady) {
16
+ return;
17
+ }
18
+ tsLoaderReady = true;
19
+ try {
20
+ await import("tsx/esm");
21
+ }
22
+ catch (error) {
23
+ throw new Error("Unable to load TypeScript project.config.extension. Install 'tsx' (e.g. pnpm add -D tsx) or provide a compiled JavaScript file.");
24
+ }
25
+ }
26
+ async function loadProjectExtrasSchema() {
27
+ const base = path.resolve(process.cwd(), "src/config/project.config.extension");
28
+ const extensions = ["", ".ts", ".mts", ".tsx", ".js", ".mjs", ".cjs"];
29
+ for (const ext of extensions) {
30
+ const candidate = ext ? `${base}${ext}` : base;
31
+ if (!fs.existsSync(candidate)) {
32
+ continue;
33
+ }
34
+ const lowerExt = path.extname(candidate).toLowerCase();
35
+ try {
36
+ if (lowerExt === ".ts" || lowerExt === ".mts" || lowerExt === ".tsx") {
37
+ await ensureTsLoader();
38
+ }
39
+ const module = await import(pathToFileURL(candidate).href);
40
+ if (module?.projectExtrasSchema) {
41
+ return module.projectExtrasSchema;
42
+ }
43
+ throw new Error(`Module '${candidate}' does not export projectExtrasSchema.`);
44
+ }
45
+ catch (error) {
46
+ const reason = error instanceof Error ? error.message : String(error);
47
+ throw new Error(`Failed to load project config extension at '${candidate}': ${reason}`);
48
+ }
49
+ }
50
+ return coreProjectExtrasSchema;
51
+ }
52
+ const projectExtrasSchema = await loadProjectExtrasSchema();
53
+ const baseSchema = composeConfigSchema(unsCoreSchema, projectExtrasSchema).strict();
12
54
  // 1) JSON Schema for VS Code $schema
13
55
  const jsonSchema = zodToJsonSchema(baseSchema, "AppConfig");
14
56
  write(path.resolve("config.schema.json"), JSON.stringify(jsonSchema, null, 2));
@@ -18,6 +60,5 @@ const tsContent = "/* Auto-generated. Do not edit by hand. */\n" +
18
60
  "export type AppConfig = " +
19
61
  printNode(node) +
20
62
  "\n";
21
- // Put it wherever you want. You earlier asked for root (beside config-file.ts):
22
- write(path.resolve("./src/app-config.ts"), tsContent);
23
- console.log("Generated config.schema.json and app-config.ts");
63
+ write(path.resolve("./src/config/app-config.ts"), tsContent);
64
+ console.log("Generated config.schema.json and src/config/app-config.ts");
@@ -8,6 +8,7 @@ import * as path from "path";
8
8
  import * as prettier from "prettier";
9
9
  import { CleanOptions, simpleGit } from "simple-git";
10
10
  import util from "util";
11
+ import { ConfigFile } from "../config-file.js";
11
12
  import { basePath } from "../base-path.js";
12
13
  const rl = readline.createInterface({
13
14
  input: process.stdin,
@@ -17,7 +18,17 @@ const question = util.promisify(rl.question).bind(rl);
17
18
  const git = simpleGit("./").clean(CleanOptions.FORCE);
18
19
  const packageJsonPath = path.join(basePath, "package.json");
19
20
  const unsLibraryPath = path.join(basePath, "uns-library.json");
20
- const orgUrl = "https://sijit@dev.azure.com/sijit";
21
+ let azureOrganization = "sijit";
22
+ try {
23
+ const appConfig = ConfigFile.loadRawConfig();
24
+ azureOrganization = appConfig.devops?.organization?.trim() || azureOrganization;
25
+ }
26
+ catch (error) {
27
+ // Use default organization when config.json is missing
28
+ }
29
+ const orgUrl = `https://${azureOrganization}@dev.azure.com/${azureOrganization}`;
30
+ const orgBaseUrl = `https://dev.azure.com/${azureOrganization}`;
31
+ const tokensUrl = `${orgBaseUrl}/_usersSettings/tokens`;
21
32
  const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
22
33
  const repoName = packageJson.name;
23
34
  const version = packageJson.version;
@@ -57,7 +68,7 @@ async function main() {
57
68
  }
58
69
  }
59
70
  if (!token) {
60
- token = await question(`Please enter your PAT, you can create one at [https://dev.azure.com/sijit/_usersSettings/tokens]: `);
71
+ token = await question(`Please enter your PAT, you can create one at [${tokensUrl}]: `);
61
72
  const authHandler = azdev.getPersonalAccessTokenHandler(token);
62
73
  const connection = new azdev.WebApi(orgUrl, authHandler);
63
74
  try {
@@ -153,5 +164,5 @@ async function createPullRequest(tag) {
153
164
  };
154
165
  gitApi.createPullRequest(gitPullRequestToCreate, repoId, project);
155
166
  console.log(chalk.green.bold(` ... OK`));
156
- console.log(`Pull request created at ` + chalk.green.bold(`[https://dev.azure.com/sijit/${project}/_git/${repoName}/pullrequests]`));
167
+ console.log(`Pull request created at ` + chalk.green.bold(`[${orgBaseUrl}/${project}/_git/${repoName}/pullrequests]`));
157
168
  }
@@ -481,6 +481,13 @@ export declare const unsCoreSchema: z.ZodObject<{
481
481
  };
482
482
  clientId?: string;
483
483
  }>;
484
+ devops: z.ZodOptional<z.ZodObject<{
485
+ organization: z.ZodString;
486
+ }, "strict", z.ZodTypeAny, {
487
+ organization?: string;
488
+ }, {
489
+ organization?: string;
490
+ }>>;
484
491
  }, "strict", z.ZodTypeAny, {
485
492
  uns?: {
486
493
  handover?: boolean;
@@ -591,6 +598,9 @@ export declare const unsCoreSchema: z.ZodObject<{
591
598
  };
592
599
  clientId?: string;
593
600
  };
601
+ devops?: {
602
+ organization?: string;
603
+ };
594
604
  }, {
595
605
  uns?: {
596
606
  handover?: boolean;
@@ -701,5 +711,8 @@ export declare const unsCoreSchema: z.ZodObject<{
701
711
  };
702
712
  clientId?: string;
703
713
  };
714
+ devops?: {
715
+ organization?: string;
716
+ };
704
717
  }>;
705
718
  export type UnsCore = z.infer<typeof unsCoreSchema>;
@@ -22,4 +22,7 @@ export const unsCoreSchema = z.object({
22
22
  input: mqttChannelSchema.optional(),
23
23
  output: mqttChannelSchema.optional(),
24
24
  infra: mqttChannelSchema,
25
+ devops: z.object({
26
+ organization: z.string().min(1),
27
+ }).strict().optional(),
25
28
  }).strict();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uns-kit/core",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Core utilities and runtime building blocks for UNS-based realtime transformers.",
5
5
  "type": "module",
6
6
  "license": "MIT",