@osdk/vite-plugin-oac 0.1.0-beta.0 → 0.1.0-beta.2

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/build/browser/Logger.js +64 -0
  3. package/build/browser/Logger.js.map +1 -0
  4. package/build/browser/OacConfig.js +22 -0
  5. package/build/browser/OacConfig.js.map +1 -0
  6. package/build/browser/OacContext.js +42 -0
  7. package/build/browser/OacContext.js.map +1 -0
  8. package/build/browser/OacDevServer.js +80 -0
  9. package/build/browser/OacDevServer.js.map +1 -0
  10. package/build/browser/OacServerContext.js +26 -0
  11. package/build/browser/OacServerContext.js.map +1 -0
  12. package/build/browser/applyOntologyAndSeed.js +38 -0
  13. package/build/browser/applyOntologyAndSeed.js.map +1 -0
  14. package/build/browser/generateOntologyAssets.js +81 -87
  15. package/build/browser/generateOntologyAssets.js.map +1 -1
  16. package/build/browser/index.js +2 -52
  17. package/build/browser/index.js.map +1 -1
  18. package/build/browser/ontologyAsCode.js +58 -0
  19. package/build/browser/ontologyAsCode.js.map +1 -0
  20. package/build/browser/registerOntologyFullMetadata.js +90 -57
  21. package/build/browser/registerOntologyFullMetadata.js.map +1 -1
  22. package/build/browser/syncDirectories.js +11 -34
  23. package/build/browser/syncDirectories.js.map +1 -1
  24. package/build/cjs/index.cjs +487 -414
  25. package/build/cjs/index.cjs.map +1 -1
  26. package/build/cjs/index.d.cts +20 -6
  27. package/build/esm/Logger.js +64 -0
  28. package/build/esm/Logger.js.map +1 -0
  29. package/build/esm/OacConfig.js +22 -0
  30. package/build/esm/OacConfig.js.map +1 -0
  31. package/build/esm/OacContext.js +42 -0
  32. package/build/esm/OacContext.js.map +1 -0
  33. package/build/esm/OacDevServer.js +80 -0
  34. package/build/esm/OacDevServer.js.map +1 -0
  35. package/build/esm/OacServerContext.js +26 -0
  36. package/build/esm/OacServerContext.js.map +1 -0
  37. package/build/esm/applyOntologyAndSeed.js +38 -0
  38. package/build/esm/applyOntologyAndSeed.js.map +1 -0
  39. package/build/esm/generateOntologyAssets.js +81 -87
  40. package/build/esm/generateOntologyAssets.js.map +1 -1
  41. package/build/esm/index.js +2 -52
  42. package/build/esm/index.js.map +1 -1
  43. package/build/esm/ontologyAsCode.js +58 -0
  44. package/build/esm/ontologyAsCode.js.map +1 -0
  45. package/build/esm/registerOntologyFullMetadata.js +90 -57
  46. package/build/esm/registerOntologyFullMetadata.js.map +1 -1
  47. package/build/esm/syncDirectories.js +11 -34
  48. package/build/esm/syncDirectories.js.map +1 -1
  49. package/build/types/Logger.d.ts +18 -0
  50. package/build/types/Logger.d.ts.map +1 -0
  51. package/build/types/OacConfig.d.ts +12 -0
  52. package/build/types/OacConfig.d.ts.map +1 -0
  53. package/build/types/OacContext.d.ts +12 -0
  54. package/build/types/OacContext.d.ts.map +1 -0
  55. package/build/types/OacDevServer.d.ts +10 -0
  56. package/build/types/OacDevServer.d.ts.map +1 -0
  57. package/build/types/OacServerContext.d.ts +12 -0
  58. package/build/types/OacServerContext.d.ts.map +1 -0
  59. package/build/types/applyOntologyAndSeed.d.ts +3 -0
  60. package/build/types/applyOntologyAndSeed.d.ts.map +1 -0
  61. package/build/types/generateOntologyAssets.d.ts +4 -7
  62. package/build/types/generateOntologyAssets.d.ts.map +1 -1
  63. package/build/types/index.d.ts +2 -11
  64. package/build/types/index.d.ts.map +1 -1
  65. package/build/types/ontologyAsCode.d.ts +7 -0
  66. package/build/types/ontologyAsCode.d.ts.map +1 -0
  67. package/build/types/registerOntologyFullMetadata.d.ts.map +1 -1
  68. package/build/types/syncDirectories.d.ts +1 -1
  69. package/build/types/syncDirectories.d.ts.map +1 -1
  70. package/package.json +12 -9
  71. package/build/browser/FauxFoundryTypes.js +0 -2
  72. package/build/browser/FauxFoundryTypes.js.map +0 -1
  73. package/build/browser/FoundryMiddlewareController.js +0 -88
  74. package/build/browser/FoundryMiddlewareController.js.map +0 -1
  75. package/build/browser/watchOntologyAsCode.js +0 -69
  76. package/build/browser/watchOntologyAsCode.js.map +0 -1
  77. package/build/esm/FauxFoundryTypes.js +0 -2
  78. package/build/esm/FauxFoundryTypes.js.map +0 -1
  79. package/build/esm/FoundryMiddlewareController.js +0 -88
  80. package/build/esm/FoundryMiddlewareController.js.map +0 -1
  81. package/build/esm/watchOntologyAsCode.js +0 -69
  82. package/build/esm/watchOntologyAsCode.js.map +0 -1
  83. package/build/types/FauxFoundryTypes.d.ts +0 -2
  84. package/build/types/FauxFoundryTypes.d.ts.map +0 -1
  85. package/build/types/FoundryMiddlewareController.d.ts +0 -14
  86. package/build/types/FoundryMiddlewareController.d.ts.map +0 -1
  87. package/build/types/watchOntologyAsCode.d.ts +0 -10
  88. package/build/types/watchOntologyAsCode.d.ts.map +0 -1
@@ -0,0 +1,38 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import * as path from "node:path";
18
+ import { inspect } from "node:util";
19
+ import { applySeed } from "./applySeed.js";
20
+ import { ontologyFullMetadataPath } from "./generateOntologyAssets.js";
21
+ import { registerOntologyFullMetadata } from "./registerOntologyFullMetadata.js";
22
+ import { readJsonFile } from "./utils/readJsonFile.js";
23
+ export async function applyOntologyAndSeed(fauxFoundry, ctx) {
24
+ const ontology = fauxFoundry.getDefaultOntology();
25
+ const ontologyFullMetadata = readJsonFile(ontologyFullMetadataPath(ctx.workDir));
26
+ registerOntologyFullMetadata(ontology, ontologyFullMetadata);
27
+ try {
28
+ if (ctx.hooks?.preSeed) {
29
+ ctx.logger.debug("calling preSeed hook");
30
+ }
31
+ await ctx.hooks?.preSeed?.(ontology);
32
+ } catch (e) {
33
+ ctx.logger.error(`Unhandled error from preSeed hook. Ignoring and continuing. ${inspect(e)}`);
34
+ }
35
+ ctx.logger.debug("applying seed data");
36
+ await applySeed(fauxFoundry, path.resolve(ctx.ontologyDir, "seed.ts"));
37
+ }
38
+ //# sourceMappingURL=applyOntologyAndSeed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyOntologyAndSeed.js","names":["path","inspect","applySeed","ontologyFullMetadataPath","registerOntologyFullMetadata","readJsonFile","applyOntologyAndSeed","fauxFoundry","ctx","ontology","getDefaultOntology","ontologyFullMetadata","workDir","hooks","preSeed","logger","debug","e","error","resolve","ontologyDir"],"sources":["applyOntologyAndSeed.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { FauxFoundry } from \"@osdk/faux\";\nimport type { OntologyFullMetadata } from \"@osdk/foundry.ontologies\";\nimport * as path from \"node:path\";\nimport { inspect } from \"node:util\";\nimport { applySeed } from \"./applySeed.js\";\nimport { ontologyFullMetadataPath } from \"./generateOntologyAssets.js\";\nimport { type OacContext } from \"./OacContext.js\";\nimport { registerOntologyFullMetadata } from \"./registerOntologyFullMetadata.js\";\nimport { readJsonFile } from \"./utils/readJsonFile.js\";\n\nexport async function applyOntologyAndSeed(\n fauxFoundry: FauxFoundry,\n ctx: OacContext,\n): Promise<void> {\n const ontology = fauxFoundry.getDefaultOntology();\n\n const ontologyFullMetadata = readJsonFile<OntologyFullMetadata>(\n ontologyFullMetadataPath(ctx.workDir),\n );\n registerOntologyFullMetadata(ontology, ontologyFullMetadata);\n\n try {\n if (ctx.hooks?.preSeed) {\n ctx.logger.debug(\"calling preSeed hook\");\n }\n\n await ctx.hooks?.preSeed?.(ontology);\n } catch (e) {\n ctx.logger.error(\n `Unhandled error from preSeed hook. Ignoring and continuing. ${\n inspect(e)\n }`,\n );\n }\n\n ctx.logger.debug(\"applying seed data\");\n await applySeed(\n fauxFoundry,\n path.resolve(ctx.ontologyDir, \"seed.ts\"),\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,KAAKA,IAAI,MAAM,WAAW;AACjC,SAASC,OAAO,QAAQ,WAAW;AACnC,SAASC,SAAS,QAAQ,gBAAgB;AAC1C,SAASC,wBAAwB,QAAQ,6BAA6B;AAEtE,SAASC,4BAA4B,QAAQ,mCAAmC;AAChF,SAASC,YAAY,QAAQ,yBAAyB;AAEtD,OAAO,eAAeC,oBAAoBA,CACxCC,WAAwB,EACxBC,GAAe,EACA;EACf,MAAMC,QAAQ,GAAGF,WAAW,CAACG,kBAAkB,CAAC,CAAC;EAEjD,MAAMC,oBAAoB,GAAGN,YAAY,CACvCF,wBAAwB,CAACK,GAAG,CAACI,OAAO,CACtC,CAAC;EACDR,4BAA4B,CAACK,QAAQ,EAAEE,oBAAoB,CAAC;EAE5D,IAAI;IACF,IAAIH,GAAG,CAACK,KAAK,EAAEC,OAAO,EAAE;MACtBN,GAAG,CAACO,MAAM,CAACC,KAAK,CAAC,sBAAsB,CAAC;IAC1C;IAEA,MAAMR,GAAG,CAACK,KAAK,EAAEC,OAAO,GAAGL,QAAQ,CAAC;EACtC,CAAC,CAAC,OAAOQ,CAAC,EAAE;IACVT,GAAG,CAACO,MAAM,CAACG,KAAK,CACd,+DACEjB,OAAO,CAACgB,CAAC,CAAC,EAEd,CAAC;EACH;EAEAT,GAAG,CAACO,MAAM,CAACC,KAAK,CAAC,oBAAoB,CAAC;EACtC,MAAMd,SAAS,CACbK,WAAW,EACXP,IAAI,CAACmB,OAAO,CAACX,GAAG,CAACY,WAAW,EAAE,SAAS,CACzC,CAAC;AACH","ignoreList":[]}
@@ -16,94 +16,91 @@
16
16
 
17
17
  import { OntologyIrToFullMetadataConverter } from "@osdk/generator-converters.ontologyir";
18
18
  import { execa } from "execa";
19
- import fs from "node:fs";
20
- import path from "node:path";
19
+ import * as fs from "node:fs";
20
+ import * as path from "node:path";
21
+ import { inspect } from "node:util";
21
22
  import { syncDirectories } from "./syncDirectories.js";
22
- export const NOISY = false;
23
+
23
24
  /**
24
25
  * Generate all ontology assets: IR, full metadata, and OSDK.
25
26
  * This function contains the core generation logic extracted from watchOntologyAsCode
26
27
  * so it can be used both in dev mode (via file watching) and build mode.
27
28
  */
28
- export async function generateOntologyAssets({
29
- logger,
30
- ontologyDir
31
- }) {
29
+ export async function generateOntologyAssets(opts) {
30
+ const {
31
+ ontologyDir,
32
+ logger
33
+ } = opts;
34
+ await fs.promises.mkdir(opts.workDir, {
35
+ recursive: true
36
+ });
37
+
32
38
  // Ensure the ontology directory exists
33
39
  if (!fs.existsSync(ontologyDir)) {
34
40
  fs.mkdirSync(ontologyDir, {
35
41
  recursive: true
36
42
  });
37
- logger.info("Created .ontology directory", {
38
- timestamp: true
39
- });
43
+ logger.info("Created .ontology directory");
40
44
  }
41
45
 
42
46
  // Generate the assets in sequence
43
- await ontologyJsToIr(logger);
44
- await ontologyIrToFullMetadata(logger);
45
- await fullMetadataToOsdk(logger);
47
+ await ontologyJsToIr(opts);
48
+ await ontologyIrToFullMetadata(opts);
49
+ await fullMetadataToOsdk(opts);
50
+ }
51
+ export function ontologyIrPath(workDir) {
52
+ return path.join(workDir, ".ontology.ir.json");
53
+ }
54
+ export function ontologyFullMetadataPath(workDir) {
55
+ return path.join(workDir, ".ontology.json");
46
56
  }
47
57
 
48
58
  /**
49
59
  * Convert ontology.mjs to IR format using the maker tool
50
60
  */
51
- async function ontologyJsToIr(logger) {
52
- if (NOISY) {
53
- logger.info("Generating Ontology IR", {
54
- timestamp: true
55
- });
56
- }
61
+ async function ontologyJsToIr({
62
+ logger,
63
+ ontologyDir,
64
+ workDir
65
+ }) {
66
+ logger.debug("Generating Ontology IR");
57
67
  const {
58
68
  stdout,
59
69
  stderr,
60
70
  exitCode
61
- } = await execa("pnpm", ["exec", "maker", "-i", ".ontology/ontology.mjs", "-o", ".ontology.ir.json"]);
71
+ } = await execa("pnpm", ["exec", "maker", "-i", `${ontologyDir}/ontology.mts`, "-o", ontologyIrPath(workDir)]);
62
72
  if (exitCode !== 0) {
63
- logger.error(`Ontology IR generation failed with exit code ${exitCode}`, {
64
- timestamp: true
65
- });
73
+ logger.error(`Ontology IR generation failed with exit code ${exitCode}`);
66
74
  if (stderr) {
67
- logger.error(`Command stderr: ${stderr}`, {
68
- timestamp: true
69
- });
75
+ logger.error(`Command stderr: ${stderr}`);
70
76
  }
71
77
  throw new Error(`Failed to generate ontology IR: exit code ${exitCode}`);
72
78
  }
73
79
 
74
80
  // Log stdout for debugging if needed
75
- if (stdout && NOISY) {
76
- logger.info(`Ontology IR generation output: ${stdout}`, {
77
- timestamp: true
78
- });
81
+ if (stdout) {
82
+ logger.debug(`Ontology IR generation output: ${stdout}`);
79
83
  }
80
84
  }
81
85
 
82
86
  /**
83
87
  * Convert IR to full metadata format
84
88
  */
85
- async function ontologyIrToFullMetadata(logger) {
86
- if (NOISY) {
87
- logger.info("Converting IR to Full metadata", {
88
- timestamp: true
89
- });
90
- }
89
+ async function ontologyIrToFullMetadata({
90
+ logger,
91
+ workDir
92
+ }) {
93
+ logger.debug("Converting IR to Full metadata");
91
94
  try {
92
- const irContent = await fs.promises.readFile("./.ontology.ir.json", {
95
+ const irContent = await fs.promises.readFile(ontologyIrPath(workDir), {
93
96
  encoding: "utf-8"
94
97
  });
95
98
  const blockData = JSON.parse(irContent).blockData;
96
99
  const fullMeta = OntologyIrToFullMetadataConverter.getFullMetadataFromIr(blockData);
97
- await fs.promises.writeFile("./.ontology.json", JSON.stringify(fullMeta, null, 2));
98
- if (NOISY) {
99
- logger.info("Successfully converted IR to full metadata", {
100
- timestamp: true
101
- });
102
- }
100
+ await fs.promises.writeFile(ontologyFullMetadataPath(workDir), JSON.stringify(fullMeta, null, 2));
101
+ logger.debug("Successfully converted IR to full metadata");
103
102
  } catch (error) {
104
- logger.error(`Failed to convert IR to full metadata: ${error instanceof Error ? error.message : String(error)}`, {
105
- timestamp: true
106
- });
103
+ logger.error(`Failed to convert IR to full metadata: ${inspect(error)}`);
107
104
  throw error;
108
105
  }
109
106
  }
@@ -111,15 +108,14 @@ async function ontologyIrToFullMetadata(logger) {
111
108
  /**
112
109
  * Generate OSDK from full metadata
113
110
  */
114
- async function fullMetadataToOsdk(logger) {
115
- if (NOISY) {
116
- logger.info("Generating OSDK from full metadata", {
117
- timestamp: true
118
- });
119
- }
111
+ async function fullMetadataToOsdk({
112
+ logger,
113
+ workDir
114
+ }) {
115
+ logger.debug("Generating OSDK from full metadata");
120
116
 
121
117
  // First create a clean temporary directory to generate the SDK into
122
- const tempDir = path.join(process.cwd(), "node_modules", ".tmp", "osdkGeneration");
118
+ const tempDir = path.join(workDir, ".osdkGenerationTmp", "src");
123
119
  await fs.promises.rm(tempDir, {
124
120
  recursive: true,
125
121
  force: true
@@ -127,6 +123,12 @@ async function fullMetadataToOsdk(logger) {
127
123
  await fs.promises.mkdir(tempDir, {
128
124
  recursive: true
129
125
  });
126
+
127
+ // The osdk cli currently mutes package.json files which we don't want in this case
128
+ // so we give it a fake package.json file
129
+ await fs.promises.writeFile(path.join(tempDir, "..", "package.json"), JSON.stringify({}, null, 2), {
130
+ encoding: "utf-8"
131
+ });
130
132
  try {
131
133
  // Then generate the source code for the osdk
132
134
  const tempSrcDir = path.join(tempDir, "src");
@@ -134,35 +136,23 @@ async function fullMetadataToOsdk(logger) {
134
136
  stdout,
135
137
  stderr,
136
138
  exitCode
137
- } = await execa("pnpm", ["exec", "osdk", "unstable", "typescript", "generate", "--outDir", tempSrcDir, "--ontologyPath", ".ontology.json", "--beta", "true", "--packageType", "module", "--version", "dev"]);
138
- if (stdout && NOISY) {
139
- logger.info(`OSDK generation output: ${stdout}`, {
140
- timestamp: true
141
- });
142
- }
139
+ } = await execa("pnpm", ["exec", "osdk", "unstable", "typescript", "generate", "--outDir", tempSrcDir, "--ontologyPath", ontologyFullMetadataPath(workDir), "--beta", "true", "--packageType", "module", "--version", "dev"]);
140
+ logger.debug(`OSDK generation output: ${stdout}`);
143
141
  if (stderr) {
144
- logger.error(`OSDK generation stderr: ${stderr}`, {
145
- timestamp: true
146
- });
142
+ logger.error(`OSDK generation stderr: ${stderr}`);
147
143
  }
148
144
 
149
145
  // Then if it was successful, synchronize the generated code with the target directory
150
146
  if (exitCode === 0) {
147
+ // TODO we should just generate this whole thing into the work dir?
151
148
  const targetDir = ".osdk/src";
152
149
  try {
153
- if (NOISY) {
154
- logger.info("OSDK generation successful, synchronizing with target directory", {
155
- timestamp: true
156
- });
157
- }
150
+ logger.debug("OSDK generation successful, synchronizing with target directory");
158
151
 
159
152
  // Use granular synchronization instead of wholesale replacement
160
153
  await syncDirectories(tempSrcDir, targetDir, logger);
161
- if (NOISY) {
162
- logger.info(`Successfully synchronized ${targetDir} with newly generated code`, {
163
- timestamp: true
164
- });
165
- }
154
+ logger.debug(`Successfully synchronized ${targetDir} with newly generated code`);
155
+ await compileOsdk(logger);
166
156
 
167
157
  // Clean up temporary directory after successful sync
168
158
  await fs.promises.rm(tempDir, {
@@ -170,21 +160,13 @@ async function fullMetadataToOsdk(logger) {
170
160
  force: true
171
161
  });
172
162
  } catch (error) {
173
- logger.error(`Failed to synchronize ${targetDir} directory: ${error instanceof Error ? error.message : String(error)}`, {
174
- timestamp: true
175
- });
176
- logger.error(`Temporary files left at: ${tempDir}`, {
177
- timestamp: true
178
- });
163
+ logger.error(`Failed to synchronize ${targetDir} directory: ${inspect(error)}`);
164
+ logger.error(`Temporary files left at: ${tempDir}`);
179
165
  throw error;
180
166
  }
181
167
  } else {
182
- logger.error(`OSDK generation failed with exit code ${exitCode}`, {
183
- timestamp: true
184
- });
185
- logger.error(`Temporary files left at: ${tempDir}`, {
186
- timestamp: true
187
- });
168
+ logger.error(`OSDK generation failed with exit code ${exitCode}`);
169
+ logger.error(`Temporary files left at: ${tempDir}`);
188
170
  throw new Error(`OSDK generation failed with exit code ${exitCode}`);
189
171
  }
190
172
  } catch (error) {
@@ -195,11 +177,23 @@ async function fullMetadataToOsdk(logger) {
195
177
  force: true
196
178
  });
197
179
  } catch (cleanupError) {
198
- logger.warn(`Failed to clean up temporary directory: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`, {
199
- timestamp: true
200
- });
180
+ logger.warn(`Failed to clean up temporary directory: ${inspect(cleanupError)}`);
201
181
  }
202
182
  throw error;
203
183
  }
204
184
  }
185
+ async function compileOsdk(logger) {
186
+ const {
187
+ stdout,
188
+ stderr,
189
+ exitCode
190
+ } = await execa("pnpm", ["exec", "tsc"], {
191
+ cwd: ".osdk"
192
+ });
193
+ logger.debug(`OSDK generation output: ${stdout}`);
194
+ if (stderr) {
195
+ logger.error(`OSDK generation stderr: ${stderr}`);
196
+ }
197
+ return exitCode;
198
+ }
205
199
  //# sourceMappingURL=generateOntologyAssets.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateOntologyAssets.js","names":["OntologyIrToFullMetadataConverter","execa","fs","path","syncDirectories","NOISY","generateOntologyAssets","logger","ontologyDir","existsSync","mkdirSync","recursive","info","timestamp","ontologyJsToIr","ontologyIrToFullMetadata","fullMetadataToOsdk","stdout","stderr","exitCode","error","Error","irContent","promises","readFile","encoding","blockData","JSON","parse","fullMeta","getFullMetadataFromIr","writeFile","stringify","message","String","tempDir","join","process","cwd","rm","force","mkdir","tempSrcDir","targetDir","cleanupError","warn"],"sources":["generateOntologyAssets.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type OntologyIrOntologyBlockDataV2,\n OntologyIrToFullMetadataConverter,\n} from \"@osdk/generator-converters.ontologyir\";\nimport { execa } from \"execa\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { Logger } from \"vite\";\nimport { syncDirectories } from \"./syncDirectories.js\";\n\nexport const NOISY = false;\n\nexport interface GenerateOntologyAssetsOptions {\n logger: Logger;\n ontologyDir: string;\n}\n\n/**\n * Generate all ontology assets: IR, full metadata, and OSDK.\n * This function contains the core generation logic extracted from watchOntologyAsCode\n * so it can be used both in dev mode (via file watching) and build mode.\n */\nexport async function generateOntologyAssets({\n logger,\n ontologyDir,\n}: GenerateOntologyAssetsOptions): Promise<void> {\n // Ensure the ontology directory exists\n if (!fs.existsSync(ontologyDir)) {\n fs.mkdirSync(ontologyDir, { recursive: true });\n logger.info(\"Created .ontology directory\", { timestamp: true });\n }\n\n // Generate the assets in sequence\n await ontologyJsToIr(logger);\n await ontologyIrToFullMetadata(logger);\n await fullMetadataToOsdk(logger);\n}\n\n/**\n * Convert ontology.mjs to IR format using the maker tool\n */\nasync function ontologyJsToIr(logger: Logger): Promise<void> {\n if (NOISY) {\n logger.info(\"Generating Ontology IR\", { timestamp: true });\n }\n\n const { stdout, stderr, exitCode } = await execa(\"pnpm\", [\n \"exec\",\n \"maker\",\n \"-i\",\n \".ontology/ontology.mjs\",\n \"-o\",\n \".ontology.ir.json\",\n ]);\n\n if (exitCode !== 0) {\n logger.error(`Ontology IR generation failed with exit code ${exitCode}`, {\n timestamp: true,\n });\n if (stderr) {\n logger.error(`Command stderr: ${stderr}`, { timestamp: true });\n }\n throw new Error(`Failed to generate ontology IR: exit code ${exitCode}`);\n }\n\n // Log stdout for debugging if needed\n if (stdout && NOISY) {\n logger.info(`Ontology IR generation output: ${stdout}`, {\n timestamp: true,\n });\n }\n}\n\n/**\n * Convert IR to full metadata format\n */\nasync function ontologyIrToFullMetadata(logger: Logger): Promise<void> {\n if (NOISY) {\n logger.info(\"Converting IR to Full metadata\", { timestamp: true });\n }\n\n try {\n const irContent = await fs.promises.readFile(\"./.ontology.ir.json\", {\n encoding: \"utf-8\",\n });\n const blockData = JSON.parse(irContent)\n .blockData as OntologyIrOntologyBlockDataV2;\n\n const fullMeta = OntologyIrToFullMetadataConverter.getFullMetadataFromIr(\n blockData,\n );\n\n await fs.promises.writeFile(\n \"./.ontology.json\",\n JSON.stringify(fullMeta, null, 2),\n );\n\n if (NOISY) {\n logger.info(\"Successfully converted IR to full metadata\", {\n timestamp: true,\n });\n }\n } catch (error) {\n logger.error(\n `Failed to convert IR to full metadata: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { timestamp: true },\n );\n throw error;\n }\n}\n\n/**\n * Generate OSDK from full metadata\n */\nasync function fullMetadataToOsdk(logger: Logger): Promise<void> {\n if (NOISY) {\n logger.info(\"Generating OSDK from full metadata\", { timestamp: true });\n }\n\n // First create a clean temporary directory to generate the SDK into\n const tempDir = path.join(\n process.cwd(),\n \"node_modules\",\n \".tmp\",\n \"osdkGeneration\",\n );\n await fs.promises.rm(tempDir, { recursive: true, force: true });\n await fs.promises.mkdir(tempDir, { recursive: true });\n\n try {\n // Then generate the source code for the osdk\n const tempSrcDir = path.join(tempDir, \"src\");\n const { stdout, stderr, exitCode } = await execa(\"pnpm\", [\n \"exec\",\n \"osdk\",\n \"unstable\",\n \"typescript\",\n \"generate\",\n \"--outDir\",\n tempSrcDir,\n \"--ontologyPath\",\n \".ontology.json\",\n \"--beta\",\n \"true\",\n \"--packageType\",\n \"module\",\n \"--version\",\n \"dev\",\n ]);\n\n if (stdout && NOISY) {\n logger.info(`OSDK generation output: ${stdout}`, { timestamp: true });\n }\n if (stderr) {\n logger.error(`OSDK generation stderr: ${stderr}`, { timestamp: true });\n }\n\n // Then if it was successful, synchronize the generated code with the target directory\n if (exitCode === 0) {\n const targetDir = \".osdk/src\";\n try {\n if (NOISY) {\n logger.info(\n \"OSDK generation successful, synchronizing with target directory\",\n {\n timestamp: true,\n },\n );\n }\n\n // Use granular synchronization instead of wholesale replacement\n await syncDirectories(tempSrcDir, targetDir, logger);\n\n if (NOISY) {\n logger.info(\n `Successfully synchronized ${targetDir} with newly generated code`,\n {\n timestamp: true,\n },\n );\n }\n\n // Clean up temporary directory after successful sync\n await fs.promises.rm(tempDir, { recursive: true, force: true });\n } catch (error) {\n logger.error(\n `Failed to synchronize ${targetDir} directory: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { timestamp: true },\n );\n logger.error(`Temporary files left at: ${tempDir}`, {\n timestamp: true,\n });\n throw error;\n }\n } else {\n logger.error(`OSDK generation failed with exit code ${exitCode}`, {\n timestamp: true,\n });\n logger.error(`Temporary files left at: ${tempDir}`, { timestamp: true });\n throw new Error(`OSDK generation failed with exit code ${exitCode}`);\n }\n } catch (error) {\n // Make sure to clean up temp directory even if there's an error\n try {\n await fs.promises.rm(tempDir, { recursive: true, force: true });\n } catch (cleanupError) {\n logger.warn(\n `Failed to clean up temporary directory: ${\n cleanupError instanceof Error\n ? cleanupError.message\n : String(cleanupError)\n }`,\n { timestamp: true },\n );\n }\n throw error;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAEEA,iCAAiC,QAC5B,uCAAuC;AAC9C,SAASC,KAAK,QAAQ,OAAO;AAC7B,OAAOC,EAAE,MAAM,SAAS;AACxB,OAAOC,IAAI,MAAM,WAAW;AAE5B,SAASC,eAAe,QAAQ,sBAAs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ACU,YAAY,CAAC,EACxB,EACF;QAAE/B,SAAS,EAAE;MAAK,CACpB,CAAC;IACH;IACA,MAAMO,KAAK;EACb;AACF","ignoreList":[]}
1
+ {"version":3,"file":"generateOntologyAssets.js","names":["OntologyIrToFullMetadataConverter","execa","fs","path","inspect","syncDirectories","generateOntologyAssets","opts","ontologyDir","logger","promises","mkdir","workDir","recursive","existsSync","mkdirSync","info","ontologyJsToIr","ontologyIrToFullMetadata","fullMetadataToOsdk","ontologyIrPath","join","ontologyFullMetadataPath","debug","stdout","stderr","exitCode","error","Error","irContent","readFile","encoding","blockData","JSON","parse","fullMeta","getFullMetadataFromIr","writeFile","stringify","tempDir","rm","force","tempSrcDir","targetDir","compileOsdk","cleanupError","warn","cwd"],"sources":["generateOntologyAssets.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type OntologyIrOntologyBlockDataV2,\n OntologyIrToFullMetadataConverter,\n} from \"@osdk/generator-converters.ontologyir\";\nimport { execa } from \"execa\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { inspect } from \"node:util\";\nimport type { Logger } from \"./Logger.js\";\nimport type { OacContext } from \"./OacContext.js\";\nimport { syncDirectories } from \"./syncDirectories.js\";\n\n/**\n * Generate all ontology assets: IR, full metadata, and OSDK.\n * This function contains the core generation logic extracted from watchOntologyAsCode\n * so it can be used both in dev mode (via file watching) and build mode.\n */\nexport async function generateOntologyAssets(\n opts: OacContext,\n): Promise<void> {\n const { ontologyDir, logger } = opts;\n await fs.promises.mkdir(opts.workDir, { recursive: true });\n\n // Ensure the ontology directory exists\n if (!fs.existsSync(ontologyDir)) {\n fs.mkdirSync(ontologyDir, { recursive: true });\n logger.info(\"Created .ontology directory\");\n }\n\n // Generate the assets in sequence\n await ontologyJsToIr(opts);\n await ontologyIrToFullMetadata(opts);\n await fullMetadataToOsdk(opts);\n}\n\nexport function ontologyIrPath(workDir: string): string {\n return path.join(workDir, \".ontology.ir.json\");\n}\n\nexport function ontologyFullMetadataPath(workDir: string): string {\n return path.join(workDir, \".ontology.json\");\n}\n\n/**\n * Convert ontology.mjs to IR format using the maker tool\n */\nasync function ontologyJsToIr(\n { logger, ontologyDir, workDir }: OacContext,\n): Promise<void> {\n logger.debug(\"Generating Ontology IR\");\n\n const { stdout, stderr, exitCode } = await execa(\"pnpm\", [\n \"exec\",\n \"maker\",\n \"-i\",\n `${ontologyDir}/ontology.mts`,\n \"-o\",\n ontologyIrPath(workDir),\n ]);\n\n if (exitCode !== 0) {\n logger.error(`Ontology IR generation failed with exit code ${exitCode}`);\n if (stderr) {\n logger.error(`Command stderr: ${stderr}`);\n }\n throw new Error(`Failed to generate ontology IR: exit code ${exitCode}`);\n }\n\n // Log stdout for debugging if needed\n if (stdout) {\n logger.debug(`Ontology IR generation output: ${stdout}`);\n }\n}\n\n/**\n * Convert IR to full metadata format\n */\nasync function ontologyIrToFullMetadata(\n { logger, workDir }: OacContext,\n): Promise<void> {\n logger.debug(\"Converting IR to Full metadata\");\n\n try {\n const irContent = await fs.promises.readFile(ontologyIrPath(workDir), {\n encoding: \"utf-8\",\n });\n const blockData = JSON.parse(irContent)\n .blockData as OntologyIrOntologyBlockDataV2;\n\n const fullMeta = OntologyIrToFullMetadataConverter.getFullMetadataFromIr(\n blockData,\n );\n\n await fs.promises.writeFile(\n ontologyFullMetadataPath(workDir),\n JSON.stringify(fullMeta, null, 2),\n );\n\n logger.debug(\"Successfully converted IR to full metadata\");\n } catch (error) {\n logger.error(\n `Failed to convert IR to full metadata: ${inspect(error)}`,\n );\n throw error;\n }\n}\n\n/**\n * Generate OSDK from full metadata\n */\nasync function fullMetadataToOsdk(\n { logger, workDir }: OacContext,\n): Promise<void> {\n logger.debug(\"Generating OSDK from full metadata\");\n\n // First create a clean temporary directory to generate the SDK into\n const tempDir = path.join(\n workDir,\n \".osdkGenerationTmp\",\n \"src\",\n );\n await fs.promises.rm(tempDir, { recursive: true, force: true });\n await fs.promises.mkdir(tempDir, { recursive: true });\n\n // The osdk cli currently mutes package.json files which we don't want in this case\n // so we give it a fake package.json file\n await fs.promises.writeFile(\n path.join(tempDir, \"..\", \"package.json\"),\n JSON.stringify({}, null, 2),\n { encoding: \"utf-8\" },\n );\n\n try {\n // Then generate the source code for the osdk\n const tempSrcDir = path.join(tempDir, \"src\");\n const { stdout, stderr, exitCode } = await execa(\"pnpm\", [\n \"exec\",\n \"osdk\",\n \"unstable\",\n \"typescript\",\n \"generate\",\n \"--outDir\",\n tempSrcDir,\n \"--ontologyPath\",\n ontologyFullMetadataPath(workDir),\n \"--beta\",\n \"true\",\n \"--packageType\",\n \"module\",\n \"--version\",\n \"dev\",\n ]);\n\n logger.debug(`OSDK generation output: ${stdout}`);\n\n if (stderr) {\n logger.error(`OSDK generation stderr: ${stderr}`);\n }\n\n // Then if it was successful, synchronize the generated code with the target directory\n if (exitCode === 0) {\n // TODO we should just generate this whole thing into the work dir?\n const targetDir = \".osdk/src\";\n try {\n logger.debug(\n \"OSDK generation successful, synchronizing with target directory\",\n );\n\n // Use granular synchronization instead of wholesale replacement\n await syncDirectories(tempSrcDir, targetDir, logger);\n\n logger.debug(\n `Successfully synchronized ${targetDir} with newly generated code`,\n );\n\n await compileOsdk(logger);\n\n // Clean up temporary directory after successful sync\n await fs.promises.rm(tempDir, { recursive: true, force: true });\n } catch (error) {\n logger.error(\n `Failed to synchronize ${targetDir} directory: ${inspect(error)}`,\n );\n logger.error(`Temporary files left at: ${tempDir}`);\n throw error;\n }\n } else {\n logger.error(`OSDK generation failed with exit code ${exitCode}`);\n logger.error(`Temporary files left at: ${tempDir}`);\n throw new Error(`OSDK generation failed with exit code ${exitCode}`);\n }\n } catch (error) {\n // Make sure to clean up temp directory even if there's an error\n try {\n await fs.promises.rm(tempDir, { recursive: true, force: true });\n } catch (cleanupError) {\n logger.warn(\n `Failed to clean up temporary directory: ${inspect(cleanupError)}`,\n );\n }\n throw error;\n }\n}\n\nasync function compileOsdk(logger: Logger) {\n const { stdout, stderr, exitCode } = await execa(\"pnpm\", [\n \"exec\",\n \"tsc\",\n ], {\n cwd: \".osdk\",\n });\n\n logger.debug(`OSDK generation output: ${stdout}`);\n\n if (stderr) {\n logger.error(`OSDK generation stderr: ${stderr}`);\n }\n return exitCode;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAEEA,iCAAiC,QAC5B,uCAAuC;AAC9C,SAASC,KAAK,QAAQ,OAAO;AAC7B,OAAO,KAAKC,EAAE,MAAM,SAAS;AAC7B,OAAO,KAAKC,IAAI,MAAM,WAAW;AACjC,SAASC,OAAO,QAAQ,WAAW;AAGnC,SAASC,eAAe,QAAQ,sBAAsB;;AAEtD;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,sBAAsBA,CAC1CC,IAAgB,EACD;EACf,MAAM;IAAEC,WAAW;IAAEC;EAAO,CAAC,GAAGF,IAAI;EACpC,MAAML,EAAE,CAACQ,QAAQ,CAACC,KAAK,CAACJ,IAAI,CAACK,OAAO,EAAE;IAAEC,SAAS,EAAE;EAAK,CAAC,CAAC;;EAE1D;EACA,IAAI,CAACX,EAAE,CAACY,UAAU,CAACN,WAAW,CAAC,EAAE;IAC/BN,EAAE,CAACa,SAAS,CAACP,WAAW,EAAE;MAAEK,SAAS,EAAE;IAAK,CAAC,CAAC;IAC9CJ,MAAM,CAACO,IAAI,CAAC,6BAA6B,CAAC;EAC5C;;EAEA;EACA,MAAMC,cAAc,CAACV,IAAI,CAAC;EAC1B,MAAMW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AAC;QACnD,MAAMZ,KAAK;MACb;IACF,CAAC,MAAM;MACLlB,MAAM,CAACkB,KAAK,CAAC,yCAAyCD,QAAQ,EAAE,CAAC;MACjEjB,MAAM,CAACkB,KAAK,CAAC,4BAA4BY,OAAO,EAAE,CAAC;MACnD,MAAM,IAAIX,KAAK,CAAC,yCAAyCF,QAAQ,EAAE,CAAC;IACtE;EACF,CAAC,CAAC,OAAOC,KAAK,EAAE;IACd;IACA,IAAI;MACF,MAAMzB,EAAE,CAACQ,QAAQ,CAAC8B,EAAE,CAACD,OAAO,EAAE;QAAE1B,SAAS,EAAE,IAAI;QAAE4B,KAAK,EAAE;MAAK,CAAC,CAAC;IACjE,CAAC,CAAC,OAAOI,YAAY,EAAE;MACrBpC,MAAM,CAACqC,IAAI,CACT,2CAA2C1C,OAAO,CAACyC,YAAY,CAAC,EAClE,CAAC;IACH;IACA,MAAMlB,KAAK;EACb;AACF;AAEA,eAAeiB,WAAWA,CAACnC,MAAc,EAAE;EACzC,MAAM;IAAEe,MAAM;IAAEC,MAAM;IAAEC;EAAS,CAAC,GAAG,MAAMzB,KAAK,CAAC,MAAM,EAAE,CACvD,MAAM,EACN,KAAK,CACN,EAAE;IACD8C,GAAG,EAAE;EACP,CAAC,CAAC;EAEFtC,MAAM,CAACc,KAAK,CAAC,2BAA2BC,MAAM,EAAE,CAAC;EAEjD,IAAIC,MAAM,EAAE;IACVhB,MAAM,CAACkB,KAAK,CAAC,2BAA2BF,MAAM,EAAE,CAAC;EACnD;EACA,OAAOC,QAAQ;AACjB","ignoreList":[]}
@@ -14,56 +14,6 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import path from "node:path";
18
- import { FoundryMiddlewareController } from "./FoundryMiddlewareController.js";
19
- import { generateOntologyAssets } from "./generateOntologyAssets.js";
20
- import { watchOntologyAsCode } from "./watchOntologyAsCode.js";
21
-
22
- /**
23
- * Vite plugin for Ontology as Code (OAC) that generates ontology IR, metadata, and OSDK
24
- * in both development and build modes.
25
- */
26
- export function ontologyAsCode(opts) {
27
- const ontologyDir = path.resolve(".ontology");
28
- let config;
29
- return {
30
- name: "oac-vite-plugin",
31
- // eslint-disable-next-line @typescript-eslint/require-await
32
- async configResolved(resolvedConfig) {
33
- config = resolvedConfig;
34
- },
35
- configureServer(server) {
36
- const oacEmitter = watchOntologyAsCode({
37
- watcher: server.watcher,
38
- logger: server.config.logger,
39
- ontologyDir
40
- });
41
- const middlewareUrl = `http${server.config.server.https ? "s" : ""}://localhost:${server.config.server.port}`;
42
- const foundryMiddlewareController = new FoundryMiddlewareController(middlewareUrl, `ri.ontology.main.ontology.00000000-0000-0000-0000-000000000000`, oacEmitter, opts?.hooks);
43
- server.middlewares.use(foundryMiddlewareController.middleware);
44
- },
45
- async buildStart() {
46
- // Generate ontology assets during build
47
- if (config.command === "build") {
48
- config.logger.info("Generating ontology assets for build...", {
49
- timestamp: true
50
- });
51
- try {
52
- await generateOntologyAssets({
53
- logger: config.logger,
54
- ontologyDir
55
- });
56
- config.logger.info("Successfully generated ontology assets for build", {
57
- timestamp: true
58
- });
59
- } catch (error) {
60
- config.logger.error(`Failed to generate ontology assets: ${error instanceof Error ? error.message : String(error)}`, {
61
- timestamp: true
62
- });
63
- throw error;
64
- }
65
- }
66
- }
67
- };
68
- }
17
+ export { OacConfig } from "./OacConfig.js";
18
+ export { ontologyAsCode } from "./ontologyAsCode.js";
69
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["path","FoundryMiddlewareController","generateOntologyAssets","watchOntologyAsCode","ontologyAsCode","opts","ontologyDir","resolve","config","name","configResolved","resolvedConfig","configureServer","server","oacEmitter","watcher","logger","middlewareUrl","https","port","foundryMiddlewareController","hooks","middlewares","use","middleware","buildStart","command","info","timestamp","error","Error","message","String"],"sources":["index.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { FauxOntology } from \"@osdk/faux\";\nimport path from \"node:path\";\nimport type { PluginOption, ResolvedConfig } from \"vite\";\nimport { FoundryMiddlewareController } from \"./FoundryMiddlewareController.js\";\nimport { generateOntologyAssets } from \"./generateOntologyAssets.js\";\nimport { watchOntologyAsCode } from \"./watchOntologyAsCode.js\";\n\n/**\n * Vite plugin for Ontology as Code (OAC) that generates ontology IR, metadata, and OSDK\n * in both development and build modes.\n */\nexport function ontologyAsCode(opts: {\n hooks?: {\n preSeed?: (fauxOntology: FauxOntology) => Promise<void>;\n };\n}): PluginOption {\n const ontologyDir = path.resolve(\".ontology\");\n\n let config: ResolvedConfig;\n\n return {\n name: \"oac-vite-plugin\",\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async configResolved(resolvedConfig) {\n config = resolvedConfig;\n },\n\n configureServer(server) {\n const oacEmitter = watchOntologyAsCode({\n watcher: server.watcher,\n logger: server.config.logger,\n ontologyDir,\n });\n\n const middlewareUrl = `http${\n server.config.server.https ? \"s\" : \"\"\n }://localhost:${server.config.server.port}`;\n\n const foundryMiddlewareController = new FoundryMiddlewareController(\n middlewareUrl,\n `ri.ontology.main.ontology.00000000-0000-0000-0000-000000000000`,\n oacEmitter,\n opts?.hooks,\n );\n\n server.middlewares.use(foundryMiddlewareController.middleware);\n },\n\n async buildStart() {\n // Generate ontology assets during build\n if (config.command === \"build\") {\n config.logger.info(\"Generating ontology assets for build...\", {\n timestamp: true,\n });\n\n try {\n await generateOntologyAssets({\n logger: config.logger,\n ontologyDir,\n });\n\n config.logger.info(\n \"Successfully generated ontology assets for build\",\n { timestamp: true },\n );\n } catch (error) {\n config.logger.error(\n `Failed to generate ontology assets: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { timestamp: true },\n );\n throw error;\n }\n }\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,IAAI,MAAM,WAAW;AAE5B,SAASC,2BAA2B,QAAQ,kCAAkC;AAC9E,SAASC,sBAAsB,QAAQ,6BAA6B;AACpE,SAASC,mBAAmB,QAAQ,0BAA0B;;AAE9D;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAACC,IAI9B,EAAgB;EACf,MAAMC,WAAW,GAAGN,IAAI,CAACO,OAAO,CAAC,WAAW,CAAC;EAE7C,IAAIC,MAAsB;EAE1B,OAAO;IACLC,IAAI,EAAE,iBAAiB;IAEvB;IACA,MAAMC,cAAcA,CAACC,cAAc,EAAE;MACnCH,MAAM,GAAGG,cAAc;IACzB,CAAC;IAEDC,eAAeA,CAACC,MAAM,EAAE;MACtB,MAAMC,UAAU,GAAGX,mBAAmB,CAAC;QACrCY,OAAO,EAAEF,MAAM,CAACE,OAAO;QACvBC,MAAM,EAAEH,MAAM,CAACL,MAAM,CAACQ,MAAM;QAC5BV;MACF,CAAC,CAAC;MAEF,MAAMW,aAAa,GAAG,OACpBJ,MAAM,CAACL,MAAM,CAACK,MAAM,CAACK,KAAK,GAAG,GAAG,GAAG,EAAE,gBACvBL,MAAM,CAACL,MAAM,CAACK,MAAM,CAACM,IAAI,EAAE;MAE3C,MAAMC,2BAA2B,GAAG,IAAInB,2BAA2B,CACjEgB,aAAa,EACb,gEAAgE,EAChEH,UAAU,EACVT,IAAI,EAAEgB,KACR,CAAC;MAEDR,MAAM,CAACS,WAAW,CAACC,GAAG,CAACH,2BAA2B,CAACI,UAAU,CAAC;IAChE,CAAC;IAED,MAAMC,UAAUA,CAAA,EAAG;MACjB;MACA,IAAIjB,MAAM,CAACkB,OAAO,KAAK,OAAO,EAAE;QAC9BlB,MAAM,CAACQ,MAAM,CAACW,IAAI,CAAC,yCAAyC,EAAE;UAC5DC,SAAS,EAAE;QACb,CAAC,CAAC;QAEF,IAAI;UACF,MAAM1B,sBAAsB,CAAC;YAC3Bc,MAAM,EAAER,MAAM,CAACQ,MAAM;YACrBV;UACF,CAAC,CAAC;UAEFE,MAAM,CAACQ,MAAM,CAACW,IAAI,CAChB,kDAAkD,EAClD;YAAEC,SAAS,EAAE;UAAK,CACpB,CAAC;QACH,CAAC,CAAC,OAAOC,KAAK,EAAE;UACdrB,MAAM,CAACQ,MAAM,CAACa,KAAK,CACjB,uCACEA,KAAK,YAAYC,KAAK,GAAGD,KAAK,CAACE,OAAO,GAAGC,MAAM,CAACH,KAAK,CAAC,EACtD,EACF;YAAED,SAAS,EAAE;UAAK,CACpB,CAAC;UACD,MAAMC,KAAK;QACb;MACF;IACF;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["OacConfig","ontologyAsCode"],"sources":["index.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { OacConfig } from \"./OacConfig.js\";\nexport { ontologyAsCode } from \"./ontologyAsCode.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,SAAS,QAAQ,gBAAgB;AAC1C,SAASC,cAAc,QAAQ,qBAAqB","ignoreList":[]}
@@ -0,0 +1,58 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import * as fs from "node:fs";
18
+ import { generateOntologyAssets } from "./generateOntologyAssets.js";
19
+ import { OacContext } from "./OacContext.js";
20
+ import { OacDevServer } from "./OacDevServer.js";
21
+
22
+ /**
23
+ * Vite plugin for Ontology as Code (OAC) that generates ontology IR, metadata, and OSDK
24
+ * in both development and build modes.
25
+ */
26
+ export function ontologyAsCode(oacConfig) {
27
+ let viteConfig;
28
+ return {
29
+ name: "oac-vite-plugin",
30
+ configResolved(resolvedConfig) {
31
+ viteConfig = resolvedConfig;
32
+ },
33
+ async configureServer(server) {
34
+ const oacDevServer = new OacDevServer(oacConfig, server);
35
+
36
+ // We await here so we get a full ontology compile and seed before the webserver starts
37
+ await oacDevServer.watchOntologyAsCode();
38
+ },
39
+ async buildStart() {
40
+ const ctx = new OacContext(oacConfig, viteConfig);
41
+ // Generate ontology assets during build
42
+ if (viteConfig.command === "build") {
43
+ ctx.logger.info("Generating ontology assets for build...");
44
+ try {
45
+ await fs.promises.mkdir(ctx.workDir, {
46
+ recursive: true
47
+ });
48
+ await generateOntologyAssets(ctx);
49
+ ctx.logger.info("Successfully generated ontology assets for build");
50
+ } catch (error) {
51
+ ctx.logger.error(`Failed to generate ontology assets: ${error instanceof Error ? error.message : String(error)}`);
52
+ throw error;
53
+ }
54
+ }
55
+ }
56
+ };
57
+ }
58
+ //# sourceMappingURL=ontologyAsCode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ontologyAsCode.js","names":["fs","generateOntologyAssets","OacContext","OacDevServer","ontologyAsCode","oacConfig","viteConfig","name","configResolved","resolvedConfig","configureServer","server","oacDevServer","watchOntologyAsCode","buildStart","ctx","command","logger","info","promises","mkdir","workDir","recursive","error","Error","message","String"],"sources":["ontologyAsCode.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as fs from \"node:fs\";\nimport type { PluginOption, ResolvedConfig } from \"vite\";\nimport { generateOntologyAssets } from \"./generateOntologyAssets.js\";\nimport type { OacConfig } from \"./OacConfig.js\";\nimport { OacContext } from \"./OacContext.js\";\nimport { OacDevServer } from \"./OacDevServer.js\";\n\n/**\n * Vite plugin for Ontology as Code (OAC) that generates ontology IR, metadata, and OSDK\n * in both development and build modes.\n */\nexport function ontologyAsCode(\n oacConfig: OacConfig,\n): PluginOption {\n let viteConfig: ResolvedConfig;\n\n return {\n name: \"oac-vite-plugin\",\n\n configResolved(resolvedConfig) {\n viteConfig = resolvedConfig;\n },\n\n async configureServer(server) {\n const oacDevServer = new OacDevServer(oacConfig, server);\n\n // We await here so we get a full ontology compile and seed before the webserver starts\n await oacDevServer.watchOntologyAsCode();\n },\n\n async buildStart() {\n const ctx = new OacContext(oacConfig, viteConfig);\n // Generate ontology assets during build\n if (viteConfig.command === \"build\") {\n ctx.logger.info(\"Generating ontology assets for build...\");\n\n try {\n await fs.promises.mkdir(ctx.workDir, { recursive: true });\n await generateOntologyAssets(ctx);\n\n ctx.logger.info(\n \"Successfully generated ontology assets for build\",\n );\n } catch (error) {\n ctx.logger.error(\n `Failed to generate ontology assets: ${\n error instanceof Error ? error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