@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.
- package/CHANGELOG.md +39 -0
- package/build/browser/Logger.js +64 -0
- package/build/browser/Logger.js.map +1 -0
- package/build/browser/OacConfig.js +22 -0
- package/build/browser/OacConfig.js.map +1 -0
- package/build/browser/OacContext.js +42 -0
- package/build/browser/OacContext.js.map +1 -0
- package/build/browser/OacDevServer.js +80 -0
- package/build/browser/OacDevServer.js.map +1 -0
- package/build/browser/OacServerContext.js +26 -0
- package/build/browser/OacServerContext.js.map +1 -0
- package/build/browser/applyOntologyAndSeed.js +38 -0
- package/build/browser/applyOntologyAndSeed.js.map +1 -0
- package/build/browser/generateOntologyAssets.js +81 -87
- package/build/browser/generateOntologyAssets.js.map +1 -1
- package/build/browser/index.js +2 -52
- package/build/browser/index.js.map +1 -1
- package/build/browser/ontologyAsCode.js +58 -0
- package/build/browser/ontologyAsCode.js.map +1 -0
- package/build/browser/registerOntologyFullMetadata.js +90 -57
- package/build/browser/registerOntologyFullMetadata.js.map +1 -1
- package/build/browser/syncDirectories.js +11 -34
- package/build/browser/syncDirectories.js.map +1 -1
- package/build/cjs/index.cjs +487 -414
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +20 -6
- package/build/esm/Logger.js +64 -0
- package/build/esm/Logger.js.map +1 -0
- package/build/esm/OacConfig.js +22 -0
- package/build/esm/OacConfig.js.map +1 -0
- package/build/esm/OacContext.js +42 -0
- package/build/esm/OacContext.js.map +1 -0
- package/build/esm/OacDevServer.js +80 -0
- package/build/esm/OacDevServer.js.map +1 -0
- package/build/esm/OacServerContext.js +26 -0
- package/build/esm/OacServerContext.js.map +1 -0
- package/build/esm/applyOntologyAndSeed.js +38 -0
- package/build/esm/applyOntologyAndSeed.js.map +1 -0
- package/build/esm/generateOntologyAssets.js +81 -87
- package/build/esm/generateOntologyAssets.js.map +1 -1
- package/build/esm/index.js +2 -52
- package/build/esm/index.js.map +1 -1
- package/build/esm/ontologyAsCode.js +58 -0
- package/build/esm/ontologyAsCode.js.map +1 -0
- package/build/esm/registerOntologyFullMetadata.js +90 -57
- package/build/esm/registerOntologyFullMetadata.js.map +1 -1
- package/build/esm/syncDirectories.js +11 -34
- package/build/esm/syncDirectories.js.map +1 -1
- package/build/types/Logger.d.ts +18 -0
- package/build/types/Logger.d.ts.map +1 -0
- package/build/types/OacConfig.d.ts +12 -0
- package/build/types/OacConfig.d.ts.map +1 -0
- package/build/types/OacContext.d.ts +12 -0
- package/build/types/OacContext.d.ts.map +1 -0
- package/build/types/OacDevServer.d.ts +10 -0
- package/build/types/OacDevServer.d.ts.map +1 -0
- package/build/types/OacServerContext.d.ts +12 -0
- package/build/types/OacServerContext.d.ts.map +1 -0
- package/build/types/applyOntologyAndSeed.d.ts +3 -0
- package/build/types/applyOntologyAndSeed.d.ts.map +1 -0
- package/build/types/generateOntologyAssets.d.ts +4 -7
- package/build/types/generateOntologyAssets.d.ts.map +1 -1
- package/build/types/index.d.ts +2 -11
- package/build/types/index.d.ts.map +1 -1
- package/build/types/ontologyAsCode.d.ts +7 -0
- package/build/types/ontologyAsCode.d.ts.map +1 -0
- package/build/types/registerOntologyFullMetadata.d.ts.map +1 -1
- package/build/types/syncDirectories.d.ts +1 -1
- package/build/types/syncDirectories.d.ts.map +1 -1
- package/package.json +12 -9
- package/build/browser/FauxFoundryTypes.js +0 -2
- package/build/browser/FauxFoundryTypes.js.map +0 -1
- package/build/browser/FoundryMiddlewareController.js +0 -88
- package/build/browser/FoundryMiddlewareController.js.map +0 -1
- package/build/browser/watchOntologyAsCode.js +0 -69
- package/build/browser/watchOntologyAsCode.js.map +0 -1
- package/build/esm/FauxFoundryTypes.js +0 -2
- package/build/esm/FauxFoundryTypes.js.map +0 -1
- package/build/esm/FoundryMiddlewareController.js +0 -88
- package/build/esm/FoundryMiddlewareController.js.map +0 -1
- package/build/esm/watchOntologyAsCode.js +0 -69
- package/build/esm/watchOntologyAsCode.js.map +0 -1
- package/build/types/FauxFoundryTypes.d.ts +0 -2
- package/build/types/FauxFoundryTypes.d.ts.map +0 -1
- package/build/types/FoundryMiddlewareController.d.ts +0 -14
- package/build/types/FoundryMiddlewareController.d.ts.map +0 -1
- package/build/types/watchOntologyAsCode.d.ts +0 -10
- package/build/types/watchOntologyAsCode.d.ts.map +0 -1
|
@@ -14,6 +14,12 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import { inspect } from "node:util";
|
|
18
|
+
import invariant from "tiny-invariant";
|
|
19
|
+
inspect.defaultOptions = {
|
|
20
|
+
colors: true,
|
|
21
|
+
depth: Infinity
|
|
22
|
+
};
|
|
17
23
|
export function registerOntologyFullMetadata(ontology, ontologyFullMetadata) {
|
|
18
24
|
// Register object types
|
|
19
25
|
Object.values(ontologyFullMetadata.objectTypes).forEach(objectType => {
|
|
@@ -21,7 +27,7 @@ export function registerOntologyFullMetadata(ontology, ontologyFullMetadata) {
|
|
|
21
27
|
});
|
|
22
28
|
// Register action types with implementations
|
|
23
29
|
Object.values(ontologyFullMetadata.actionTypes).forEach(actionType => {
|
|
24
|
-
const implementation = createActionImplementation(actionType);
|
|
30
|
+
const implementation = createActionImplementation(actionType, ontologyFullMetadata);
|
|
25
31
|
const actionTypeWithCamelCaseApiName = {
|
|
26
32
|
...actionType,
|
|
27
33
|
apiName: camelcase(actionType.apiName)
|
|
@@ -39,10 +45,12 @@ export function registerOntologyFullMetadata(ontology, ontologyFullMetadata) {
|
|
|
39
45
|
});
|
|
40
46
|
}
|
|
41
47
|
|
|
48
|
+
// NOTE: The ontology full metadata is not sufficient for doing this properly.
|
|
49
|
+
|
|
42
50
|
/**
|
|
43
51
|
* Creates a fake implementation for an action type based on its operations
|
|
44
52
|
*/
|
|
45
|
-
function createActionImplementation(actionType) {
|
|
53
|
+
function createActionImplementation(actionType, fullMetadata) {
|
|
46
54
|
return (batch, payload) => {
|
|
47
55
|
// Extract parameters from payload
|
|
48
56
|
const params = payload.parameters;
|
|
@@ -53,73 +61,51 @@ function createActionImplementation(actionType) {
|
|
|
53
61
|
case "createObject":
|
|
54
62
|
{
|
|
55
63
|
// Handle create object operation
|
|
56
|
-
const
|
|
57
|
-
const primaryKey = params.primaryKey_;
|
|
64
|
+
const objectType = getObjectTypeForOperation(operation, fullMetadata);
|
|
58
65
|
|
|
59
|
-
//
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
// we don't store the PK with the other properties
|
|
67
|
+
const primaryKeyProp = objectType.objectType.primaryKey;
|
|
68
|
+
const primaryKey = extractAndDelete(params, primaryKeyProp);
|
|
69
|
+
|
|
70
|
+
// Create object data from parameters
|
|
71
|
+
const objectData = paramsToDataValues(params, actionType);
|
|
72
|
+
batch.addObject(objectType.objectType.apiName, primaryKey, objectData);
|
|
73
|
+
|
|
74
|
+
// TODO: this shouldn't send params but the actual object!
|
|
75
|
+
handleObjectLinks(batch, fullMetadata, objectType.objectType.apiName, primaryKey, params);
|
|
68
76
|
break;
|
|
69
77
|
}
|
|
70
78
|
case "modifyObject":
|
|
71
79
|
{
|
|
72
80
|
// Handle modify object operation
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
} else {
|
|
85
|
-
// Default to the parameter name if not found
|
|
86
|
-
objectTypeApiName = operation.objectTypeApiName;
|
|
87
|
-
primaryKey = params.primaryKey_;
|
|
88
|
-
}
|
|
81
|
+
const {
|
|
82
|
+
objectType
|
|
83
|
+
} = getObjectTypeForOperation(operation, fullMetadata);
|
|
84
|
+
const primaryKey = extractAndDelete(params, "objectToModifyParameter");
|
|
85
|
+
const targetObject = batch.getObject(objectType.apiName, primaryKey);
|
|
86
|
+
!targetObject ? process.env.NODE_ENV !== "production" ? invariant(false, `Could not find object ${objectType.apiName} with PK ${primaryKey}`) : invariant(false) : void 0;
|
|
87
|
+
if (objectType.primaryKey in params) {
|
|
88
|
+
// TODO Is this true? Or are you allowed to change the PK value?
|
|
89
|
+
!(params[objectType.primaryKey] === primaryKey) ? process.env.NODE_ENV !== "production" ? invariant(false, `If the primary key is provided, it must match the 'objectToModifyParameter'`) : invariant(false) : void 0;
|
|
90
|
+
// delete the key since we don't store it directly on the object
|
|
91
|
+
delete params[objectType.primaryKey];
|
|
89
92
|
}
|
|
93
|
+
const objectData = paramsToDataValues(params, actionType);
|
|
94
|
+
batch.modifyObject(objectType.apiName, primaryKey, objectData);
|
|
90
95
|
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
for (const [key, value] of Object.entries(params)) {
|
|
94
|
-
if (key !== "primaryKey_" && key !== "objectToModifyParameter") {
|
|
95
|
-
const param = actionType.parameters[key];
|
|
96
|
-
objectData[key] = toDataValue(value, param);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
batch.modifyObject(objectTypeApiName, primaryKey, objectData);
|
|
96
|
+
// TODO: this shouldn't send params but the actual object!
|
|
97
|
+
handleObjectLinks(batch, fullMetadata, objectType.apiName, primaryKey, params);
|
|
100
98
|
break;
|
|
101
99
|
}
|
|
102
100
|
case "deleteObject":
|
|
103
101
|
{
|
|
102
|
+
const {
|
|
103
|
+
objectType
|
|
104
|
+
} = getObjectTypeForOperation(operation, fullMetadata);
|
|
105
|
+
const primaryKey = extractAndDelete(params, "objectToDeleteParameter");
|
|
106
|
+
|
|
104
107
|
// Handle delete object operation
|
|
105
|
-
|
|
106
|
-
let primaryKey;
|
|
107
|
-
if (typeof operation.objectTypeApiName === "string") {
|
|
108
|
-
objectTypeApiName = operation.objectTypeApiName;
|
|
109
|
-
primaryKey = params.primaryKey_;
|
|
110
|
-
} else {
|
|
111
|
-
// If objectTypeApiName is a parameter reference
|
|
112
|
-
const objectToDelete = params[operation.objectTypeApiName];
|
|
113
|
-
if (objectToDelete) {
|
|
114
|
-
objectTypeApiName = objectToDelete.objectTypeApiName || objectToDelete;
|
|
115
|
-
primaryKey = objectToDelete.primaryKeyValue || params.primaryKey_;
|
|
116
|
-
} else {
|
|
117
|
-
// Default to the parameter name if not found
|
|
118
|
-
objectTypeApiName = operation.objectTypeApiName;
|
|
119
|
-
primaryKey = params.primaryKey_;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
batch.deleteObject(objectTypeApiName, primaryKey);
|
|
108
|
+
batch.deleteObject(objectType.apiName, primaryKey);
|
|
123
109
|
break;
|
|
124
110
|
}
|
|
125
111
|
case "createLink":
|
|
@@ -154,6 +140,7 @@ function createActionImplementation(actionType) {
|
|
|
154
140
|
}
|
|
155
141
|
break;
|
|
156
142
|
}
|
|
143
|
+
|
|
157
144
|
// Handle other operation types as needed
|
|
158
145
|
case "createInterfaceObject":
|
|
159
146
|
case "modifyInterfaceObject":
|
|
@@ -167,11 +154,29 @@ function createActionImplementation(actionType) {
|
|
|
167
154
|
}
|
|
168
155
|
};
|
|
169
156
|
}
|
|
157
|
+
function extractAndDelete(obj, key) {
|
|
158
|
+
const value = obj[key];
|
|
159
|
+
delete obj[key];
|
|
160
|
+
return value;
|
|
161
|
+
}
|
|
162
|
+
function getObjectTypeForOperation(operation, fullMetadata) {
|
|
163
|
+
const objectTypeApiName = operation.objectTypeApiName;
|
|
164
|
+
const objectType = fullMetadata.objectTypes[objectTypeApiName];
|
|
165
|
+
!objectType ? process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0;
|
|
166
|
+
return objectType;
|
|
167
|
+
}
|
|
168
|
+
function paramsToDataValues(params, actionType) {
|
|
169
|
+
const objectData = {};
|
|
170
|
+
for (const [key, value] of Object.entries(params)) {
|
|
171
|
+
objectData[key] = toDataValue(value, actionType.parameters[key]);
|
|
172
|
+
}
|
|
173
|
+
return objectData;
|
|
174
|
+
}
|
|
170
175
|
function camelcase(apiName) {
|
|
171
176
|
return apiName.toLowerCase().replace(/[-_]+(.)?/g, (_, chr) => chr ? chr.toUpperCase() : "");
|
|
172
177
|
}
|
|
173
178
|
function toDataValue(value, param) {
|
|
174
|
-
if (param.dataType.type === "
|
|
179
|
+
if (param.dataType.type === "geohash" && typeof value === "string") {
|
|
175
180
|
return latLonStringToGeoJSON(value);
|
|
176
181
|
}
|
|
177
182
|
return value;
|
|
@@ -191,4 +196,32 @@ function latLonStringToGeoJSON(latLonStr) {
|
|
|
191
196
|
coordinates: [lon, lat] // GeoJSON uses [longitude, latitude]
|
|
192
197
|
};
|
|
193
198
|
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Handles linking objects based on parameter values and existing objects
|
|
202
|
+
*/
|
|
203
|
+
function handleObjectLinks(batch, fullMetadata, objectTypeApiName, primaryKey, params) {
|
|
204
|
+
// HACK HACK HACK
|
|
205
|
+
fullMetadata.objectTypes[objectTypeApiName].linkTypes.forEach(link => {
|
|
206
|
+
const cardinality = link.cardinality;
|
|
207
|
+
if (cardinality === "ONE") {
|
|
208
|
+
// This means its a one to many and we are on the one side of the link
|
|
209
|
+
for (const foreignObject of batch.getObjects(link.objectTypeApiName)) {
|
|
210
|
+
if (anyValueMatches(params, foreignObject.__primaryKey)) {
|
|
211
|
+
batch.addLink(objectTypeApiName, primaryKey, link.apiName, link.objectTypeApiName, foreignObject.__primaryKey);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
// This means its a one to many and we are on the many side of the link
|
|
216
|
+
for (const foreignObject of batch.getObjects(link.objectTypeApiName)) {
|
|
217
|
+
if (anyValueMatches(foreignObject, primaryKey)) {
|
|
218
|
+
batch.addLink(objectTypeApiName, primaryKey, link.apiName, link.objectTypeApiName, foreignObject.__primaryKey);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
function anyValueMatches(obj, primaryKey) {
|
|
225
|
+
return Object.values(obj).some(val => val === primaryKey);
|
|
226
|
+
}
|
|
194
227
|
//# sourceMappingURL=registerOntologyFullMetadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerOntologyFullMetadata.js","names":["registerOntologyFullMetadata","ontology","ontologyFullMetadata","Object","values","objectTypes","forEach","objectType","registerObjectType","actionTypes","actionType","implementation","createActionImplementation","actionTypeWithCamelCaseApiName","apiName","camelcase","registerActionType","sharedPropertyTypes","registerSharedPropertyType","queryTypes","query","registerQueryType","interfaceTypes","iface","registerInterfaceType","batch","payload","params","parameters","operation","operations","type","objectTypeApiName","primaryKey","primaryKey_","objectData","key","value","entries","param","toDataValue","addObject","objectToModify","primaryKeyValue","modifyObject","objectToDelete","deleteObject","aSideObjectTypeApiName","bSideObjectTypeApiName","linkTypeApiNameAtoB","aSidePrimaryKey","bSidePrimaryKey","linkedObjectPrimaryKey","addLink","removeLink","Error","toLowerCase","replace","_","chr","toUpperCase","dataType","latLonStringToGeoJSON","latLonStr","lat","lon","split","map","Number","isNaN","coordinates"],"sources":["registerOntologyFullMetadata.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 * as Ontologies from \"@osdk/foundry.ontologies\";\nimport type { FauxActionImpl } from \"./FauxFoundryTypes.js\";\n\nexport function registerOntologyFullMetadata(\n ontology: ReturnType<FauxFoundry[\"getOntology\"]>,\n ontologyFullMetadata: Ontologies.OntologyFullMetadata,\n): void {\n // Register object types\n Object.values(ontologyFullMetadata.objectTypes).forEach((objectType) => {\n ontology.registerObjectType(objectType);\n });\n // Register action types with implementations\n Object.values(ontologyFullMetadata.actionTypes).forEach((actionType) => {\n const implementation = createActionImplementation(actionType);\n const actionTypeWithCamelCaseApiName = {\n ...actionType,\n apiName: camelcase(actionType.apiName),\n };\n ontology.registerActionType(actionTypeWithCamelCaseApiName, implementation);\n });\n Object.values(ontologyFullMetadata.sharedPropertyTypes).forEach(\n (actionType) => {\n ontology.registerSharedPropertyType(actionType);\n },\n );\n Object.values(ontologyFullMetadata.queryTypes).forEach((query) => {\n ontology.registerQueryType(query);\n });\n Object.values(ontologyFullMetadata.interfaceTypes).forEach((iface) => {\n ontology.registerInterfaceType(iface);\n });\n}\n\n/**\n * Creates a fake implementation for an action type based on its operations\n */\nfunction createActionImplementation(\n actionType: Ontologies.ActionTypeV2,\n): FauxActionImpl {\n return (\n batch: {\n addObject: (\n objectType: string,\n primaryKey: string | number | boolean,\n object: Record<string, unknown>,\n ) => void;\n modifyObject: (\n objectType: string,\n primaryKey: string | number | boolean,\n update: Record<string, unknown>,\n ) => void;\n deleteObject: (\n objectType: string,\n primaryKey: string | number | boolean,\n ) => void;\n addLink: (\n leftObjectType: string,\n leftPrimaryKey: string | number | boolean,\n leftLinkName: string,\n rightObjectType: string,\n rightPrimaryKey: string | number | boolean,\n ) => void;\n removeLink: (\n leftObjectType: string,\n leftPrimaryKey: string | number | boolean,\n leftLinkName: string,\n rightObjectType: string,\n rightPrimaryKey: string | number | boolean,\n ) => void;\n },\n payload: {\n parameters: Record<string, any>;\n },\n _ctx: unknown,\n ) => {\n // Extract parameters from payload\n const params = payload.parameters;\n\n // Handle different operation types\n for (const operation of actionType.operations) {\n switch (operation.type) {\n case \"createObject\": {\n // Handle create object operation\n const objectTypeApiName = operation.objectTypeApiName;\n const primaryKey = params.primaryKey_;\n\n // Create object data from parameters, excluding the primary key\n const objectData: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(params)) {\n if (key !== \"primaryKey_\") {\n const param = actionType.parameters[key];\n objectData[key] = toDataValue(value, param);\n }\n }\n\n batch.addObject(objectTypeApiName, primaryKey, objectData);\n break;\n }\n case \"modifyObject\": {\n // Handle modify object operation\n let objectTypeApiName: string;\n let primaryKey: string | number | boolean;\n\n if (typeof operation.objectTypeApiName === \"string\") {\n objectTypeApiName = operation.objectTypeApiName;\n primaryKey = params.primaryKey_;\n } else {\n // If objectTypeApiName is a parameter reference\n const objectToModify = params[operation.objectTypeApiName];\n if (objectToModify) {\n objectTypeApiName = objectToModify.objectTypeApiName\n || objectToModify;\n primaryKey = objectToModify.primaryKeyValue || params.primaryKey_;\n } else {\n // Default to the parameter name if not found\n objectTypeApiName = operation.objectTypeApiName;\n primaryKey = params.primaryKey_;\n }\n }\n\n // Create object data from parameters, excluding the primary key and objectToModifyParameter\n const objectData: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(params)) {\n if (key !== \"primaryKey_\" && key !== \"objectToModifyParameter\") {\n const param = actionType.parameters[key];\n objectData[key] = toDataValue(value, param);\n }\n }\n\n batch.modifyObject(objectTypeApiName, primaryKey, objectData);\n break;\n }\n case \"deleteObject\": {\n // Handle delete object operation\n let objectTypeApiName: string;\n let primaryKey: string | number | boolean;\n\n if (typeof operation.objectTypeApiName === \"string\") {\n objectTypeApiName = operation.objectTypeApiName;\n primaryKey = params.primaryKey_;\n } else {\n // If objectTypeApiName is a parameter reference\n const objectToDelete = params[operation.objectTypeApiName];\n if (objectToDelete) {\n objectTypeApiName = objectToDelete.objectTypeApiName\n || objectToDelete;\n primaryKey = objectToDelete.primaryKeyValue || params.primaryKey_;\n } else {\n // Default to the parameter name if not found\n objectTypeApiName = operation.objectTypeApiName;\n primaryKey = params.primaryKey_;\n }\n }\n\n batch.deleteObject(objectTypeApiName, primaryKey);\n break;\n }\n case \"createLink\": {\n // Handle create link operation\n const aSideObjectTypeApiName = operation.aSideObjectTypeApiName;\n const bSideObjectTypeApiName = operation.bSideObjectTypeApiName;\n const linkTypeApiNameAtoB = operation.linkTypeApiNameAtoB;\n\n // For simplicity, assume we have the primary keys in the parameters\n // In a real implementation, we would need to extract them from the parameters\n const aSidePrimaryKey = params.aSidePrimaryKey || params.primaryKey_;\n const bSidePrimaryKey = params.bSidePrimaryKey\n || params.linkedObjectPrimaryKey;\n\n if (aSidePrimaryKey && bSidePrimaryKey) {\n batch.addLink(\n aSideObjectTypeApiName,\n aSidePrimaryKey,\n linkTypeApiNameAtoB,\n bSideObjectTypeApiName,\n bSidePrimaryKey,\n );\n }\n break;\n }\n case \"deleteLink\": {\n // Handle delete link operation\n const aSideObjectTypeApiName = operation.aSideObjectTypeApiName;\n const bSideObjectTypeApiName = operation.bSideObjectTypeApiName;\n const linkTypeApiNameAtoB = operation.linkTypeApiNameAtoB;\n\n // For simplicity, assume we have the primary keys in the parameters\n // In a real implementation, we would need to extract them from the parameters\n const aSidePrimaryKey = params.aSidePrimaryKey || params.primaryKey_;\n const bSidePrimaryKey = params.bSidePrimaryKey\n || params.linkedObjectPrimaryKey;\n\n if (aSidePrimaryKey && bSidePrimaryKey) {\n batch.removeLink(\n aSideObjectTypeApiName,\n aSidePrimaryKey,\n linkTypeApiNameAtoB,\n bSideObjectTypeApiName,\n bSidePrimaryKey,\n );\n }\n break;\n }\n // Handle other operation types as needed\n case \"createInterfaceObject\":\n case \"modifyInterfaceObject\":\n case \"deleteInterfaceObject\":\n // These operations are not implemented for now\n throw new Error(\n `Operation type ${operation.type} not implemented yet`,\n );\n break;\n default:\n throw new Error(`Unknown operation type: ${(operation as any).type}`);\n }\n }\n };\n}\n\nfunction camelcase(apiName: string): string {\n return apiName\n .toLowerCase()\n .replace(/[-_]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : \"\"));\n}\n\nfunction toDataValue(value: any, param: Ontologies.ActionParameterV2): unknown {\n if (param.dataType.type === \"geoshape\" && typeof value === \"string\") {\n return latLonStringToGeoJSON(value);\n }\n return value;\n}\n\nfunction latLonStringToGeoJSON(latLonStr: string) {\n // Split the string by comma and parse as floats\n const [lat, lon] = latLonStr.split(\",\").map(Number);\n\n // Basic validation\n if (\n isNaN(lat)\n || isNaN(lon)\n || lat < -90\n || lat > 90\n || lon < -180\n || lon > 180\n ) {\n throw new Error(\"Invalid latitude or longitude\");\n }\n\n // Return GeoJSON Point\n return {\n type: \"Point\",\n coordinates: [lon, lat], // GeoJSON uses [longitude, latitude]\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA,OAAO,SAASA,4BAA4BA,CAC1CC,QAAgD,EAChDC,oBAAqD,EAC/C;EACN;EACAC,MAAM,CAACC,MAAM,CAACF,oBAAoB,CAACG,WAAW,CAAC,CAACC,OAAO,CAAEC,UAAU,IAAK;IACtEN,QAAQ,CAACO,kBAAkB,CAACD,UAAU,CAAC;EACzC,CAAC,CAAC;EACF;EACAJ,MAAM,CAACC,MAAM,CAACF,oBAAoB,CAACO,WAAW,CAAC,CAACH,OAAO,CAAEI,UAAU,IAAK;IACtE,MAAMC,cAAc,GAAGC,0BAA0B,CAACF,UAAU,CAAC;IAC7D,MAAMG,8BAA8B,GAAG;MACrC,GAAGH,UAAU;MACbI,OAAO,EAAEC,SAAS,CAACL,UAAU,CAACI,OAAO;IACvC,CAAC;IACDb,QAAQ,CAACe,kBAAkB,CAACH,8BAA8B,EAAEF,cAAc,CAAC;EAC7E,CAAC,CAAC;EACFR,MAAM,CAACC,MAAM,CAACF,oBAAoB,CAACe,mBAAmB,CAAC,CAACX,OAAO,CAC5DI,UAAU,IAAK;IACdT,QAAQ,CAACiB,0BAA0B,CAACR,UAAU,CAAC;EACjD,CACF,CAAC;EACDP,MAAM,CAACC,MAAM,CAACF,oBAAoB,CAACiB,UAAU,CAAC,CAACb,OAAO,CAAEc,KAAK,IAAK;IAChEnB,QAAQ,CAACoB,iBAAiB,CAACD,KAAK,CAAC;EACnC,CAAC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spect","invariant","defaultOptions","colors","depth","Infinity","registerOntologyFullMetadata","ontology","ontologyFullMetadata","Object","values","objectTypes","forEach","objectType","registerObjectType","actionTypes","actionType","implementation","createActionImplementation","actionTypeWithCamelCaseApiName","apiName","camelcase","registerActionType","sharedPropertyTypes","registerSharedPropertyType","queryTypes","query","registerQueryType","interfaceTypes","iface","registerInterfaceType","fullMetadata","batch","payload","params","parameters","operation","operations","type","getObjectTypeForOperation","primaryKeyProp","primaryKey","extractAndDelete","objectData","paramsToDataValues","addObject","handleObjectLinks","targetObject","getObject","process","env","NODE_ENV","modifyObject","deleteObject","aSideObjectTypeApiName","bSideObjectTypeApiName","linkTypeApiNameAtoB","aSidePrimaryKey","primaryKey_","bSidePrimaryKey","linkedObjectPrimaryKey","addLink","removeLink","Error","obj","key","value","objectTypeApiName","entries","toDataValue","toLowerCase","replace","_","chr","toUpperCase","param","dataType","latLonStringToGeoJSON","latLonStr","lat","lon","split","map","Number","isNaN","coordinates","linkTypes","link","cardinality","foreignObject","getObjects","anyValueMatches","__primaryKey","some","val"],"sources":["registerOntologyFullMetadata.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 {\n BaseServerObject,\n FauxActionImpl,\n FauxDataStoreBatch,\n FauxFoundry,\n} from \"@osdk/faux\";\nimport type * as Ontologies from \"@osdk/foundry.ontologies\";\nimport { inspect } from \"node:util\";\nimport invariant from \"tiny-invariant\";\n\ninspect.defaultOptions = {\n colors: true,\n depth: Infinity,\n};\n\nexport function registerOntologyFullMetadata(\n ontology: ReturnType<FauxFoundry[\"getOntology\"]>,\n ontologyFullMetadata: Ontologies.OntologyFullMetadata,\n): void {\n // Register object types\n Object.values(ontologyFullMetadata.objectTypes).forEach((objectType) => {\n ontology.registerObjectType(objectType);\n });\n // Register action types with implementations\n Object.values(ontologyFullMetadata.actionTypes).forEach((actionType) => {\n const implementation = createActionImplementation(\n actionType,\n ontologyFullMetadata,\n );\n const actionTypeWithCamelCaseApiName = {\n ...actionType,\n apiName: camelcase(actionType.apiName),\n };\n ontology.registerActionType(actionTypeWithCamelCaseApiName, implementation);\n });\n Object.values(ontologyFullMetadata.sharedPropertyTypes).forEach(\n (actionType) => {\n ontology.registerSharedPropertyType(actionType);\n },\n );\n Object.values(ontologyFullMetadata.queryTypes).forEach((query) => {\n ontology.registerQueryType(query);\n });\n Object.values(ontologyFullMetadata.interfaceTypes).forEach((iface) => {\n ontology.registerInterfaceType(iface);\n });\n}\n\n// NOTE: The ontology full metadata is not sufficient for doing this properly.\n\n/**\n * Creates a fake implementation for an action type based on its operations\n */\nfunction createActionImplementation(\n actionType: Ontologies.ActionTypeV2,\n fullMetadata: Ontologies.OntologyFullMetadata,\n): FauxActionImpl {\n return (\n batch,\n payload: {\n parameters: Record<string, any>;\n },\n _ctx: unknown,\n ) => {\n // Extract parameters from payload\n const params = payload.parameters;\n\n // Handle different operation types\n for (const operation of actionType.operations) {\n switch (operation.type) {\n case \"createObject\": {\n // Handle create object operation\n const objectType = getObjectTypeForOperation(\n operation,\n fullMetadata,\n );\n\n // we don't store the PK with the other properties\n const primaryKeyProp = objectType.objectType.primaryKey;\n const primaryKey = extractAndDelete(params, primaryKeyProp);\n\n // Create object data from parameters\n const objectData = paramsToDataValues(params, actionType);\n batch.addObject(\n objectType.objectType.apiName,\n primaryKey,\n objectData,\n );\n\n // TODO: this shouldn't send params but the actual object!\n handleObjectLinks(\n batch,\n fullMetadata,\n objectType.objectType.apiName,\n primaryKey,\n params,\n );\n break;\n }\n\n case \"modifyObject\": {\n // Handle modify object operation\n const { objectType } = getObjectTypeForOperation(\n operation,\n fullMetadata,\n );\n\n const primaryKey = extractAndDelete(\n params,\n \"objectToModifyParameter\",\n );\n\n const targetObject = batch.getObject(\n objectType.apiName,\n primaryKey,\n );\n invariant(\n targetObject,\n `Could not find object ${objectType.apiName} with PK ${primaryKey}`,\n );\n\n if (objectType.primaryKey in params) {\n // TODO Is this true? Or are you allowed to change the PK value?\n invariant(\n params[objectType.primaryKey] === primaryKey,\n `If the primary key is provided, it must match the 'objectToModifyParameter'`,\n );\n // delete the key since we don't store it directly on the object\n delete params[objectType.primaryKey];\n }\n\n const objectData = paramsToDataValues(params, actionType);\n batch.modifyObject(objectType.apiName, primaryKey, objectData);\n\n // TODO: this shouldn't send params but the actual object!\n handleObjectLinks(\n batch,\n fullMetadata,\n objectType.apiName,\n primaryKey,\n params,\n );\n\n break;\n }\n\n case \"deleteObject\": {\n const { objectType } = getObjectTypeForOperation(\n operation,\n fullMetadata,\n );\n const primaryKey = extractAndDelete(\n params,\n \"objectToDeleteParameter\",\n );\n\n // Handle delete object operation\n batch.deleteObject(objectType.apiName, primaryKey);\n break;\n }\n\n case \"createLink\": {\n // Handle create link operation\n const aSideObjectTypeApiName = operation.aSideObjectTypeApiName;\n const bSideObjectTypeApiName = operation.bSideObjectTypeApiName;\n const linkTypeApiNameAtoB = operation.linkTypeApiNameAtoB;\n\n // For simplicity, assume we have the primary keys in the parameters\n // In a real implementation, we would need to extract them from the parameters\n const aSidePrimaryKey = params.aSidePrimaryKey || params.primaryKey_;\n const bSidePrimaryKey = params.bSidePrimaryKey\n || params.linkedObjectPrimaryKey;\n\n if (aSidePrimaryKey && bSidePrimaryKey) {\n batch.addLink(\n aSideObjectTypeApiName,\n aSidePrimaryKey,\n linkTypeApiNameAtoB,\n bSideObjectTypeApiName,\n bSidePrimaryKey,\n );\n }\n break;\n }\n\n case \"deleteLink\": {\n // Handle delete link operation\n const aSideObjectTypeApiName = operation.aSideObjectTypeApiName;\n const bSideObjectTypeApiName = operation.bSideObjectTypeApiName;\n const linkTypeApiNameAtoB = operation.linkTypeApiNameAtoB;\n\n // For simplicity, assume we have the primary keys in the parameters\n // In a real implementation, we would need to extract them from the parameters\n const aSidePrimaryKey = params.aSidePrimaryKey || params.primaryKey_;\n const bSidePrimaryKey = params.bSidePrimaryKey\n || params.linkedObjectPrimaryKey;\n\n if (aSidePrimaryKey && bSidePrimaryKey) {\n batch.removeLink(\n aSideObjectTypeApiName,\n aSidePrimaryKey,\n linkTypeApiNameAtoB,\n bSideObjectTypeApiName,\n bSidePrimaryKey,\n );\n }\n break;\n }\n\n // Handle other operation types as needed\n case \"createInterfaceObject\":\n case \"modifyInterfaceObject\":\n case \"deleteInterfaceObject\":\n // These operations are not implemented for now\n throw new Error(\n `Operation type ${operation.type} not implemented yet`,\n );\n break;\n default:\n throw new Error(`Unknown operation type: ${(operation as any).type}`);\n }\n }\n };\n}\n\nfunction extractAndDelete<K extends string, O extends Record<K, any>>(\n obj: O,\n key: K,\n) {\n const value = obj[key];\n delete obj[key];\n return value;\n}\n\nfunction getObjectTypeForOperation(\n operation:\n | Ontologies.CreateObjectRule\n | Ontologies.ModifyObjectRule\n | Ontologies.DeleteObjectRule,\n fullMetadata: Ontologies.OntologyFullMetadata,\n) {\n const objectTypeApiName = operation.objectTypeApiName;\n const objectType = fullMetadata.objectTypes[objectTypeApiName];\n invariant(objectType);\n return objectType;\n}\n\nfunction paramsToDataValues(\n params: Record<string, any>,\n actionType: Ontologies.ActionTypeV2,\n) {\n const objectData: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(params)) {\n objectData[key] = toDataValue(value, actionType.parameters[key]);\n }\n return objectData;\n}\n\nfunction camelcase(apiName: string): string {\n return apiName\n .toLowerCase()\n .replace(/[-_]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : \"\"));\n}\n\nfunction toDataValue(value: any, param: Ontologies.ActionParameterV2): unknown {\n if (param.dataType.type === \"geohash\" && typeof value === \"string\") {\n return latLonStringToGeoJSON(value);\n }\n return value;\n}\n\nfunction latLonStringToGeoJSON(latLonStr: string) {\n // Split the string by comma and parse as floats\n const [lat, lon] = latLonStr.split(\",\").map(Number);\n\n // Basic validation\n if (\n isNaN(lat)\n || isNaN(lon)\n || lat < -90\n || lat > 90\n || lon < -180\n || lon > 180\n ) {\n throw new Error(\"Invalid latitude or longitude\");\n }\n\n // Return GeoJSON Point\n return {\n type: \"Point\",\n coordinates: [lon, lat], // GeoJSON uses [longitude, latitude]\n };\n}\n\n/**\n * Handles linking objects based on parameter values and existing objects\n */\nfunction handleObjectLinks(\n batch: FauxDataStoreBatch,\n fullMetadata: Ontologies.OntologyFullMetadata,\n objectTypeApiName: string,\n primaryKey: string | number | boolean,\n params: Record<string, unknown>,\n): void {\n // HACK HACK HACK\n fullMetadata.objectTypes[objectTypeApiName].linkTypes.forEach(link => {\n const cardinality = link.cardinality;\n\n if (cardinality === \"ONE\") {\n // This means its a one to many and we are on the one side of the link\n for (const foreignObject of batch.getObjects(link.objectTypeApiName)) {\n if (anyValueMatches(params, foreignObject.__primaryKey)) {\n batch.addLink(\n objectTypeApiName,\n primaryKey,\n link.apiName,\n link.objectTypeApiName,\n foreignObject.__primaryKey,\n );\n }\n }\n } else {\n // This means its a one to many and we are on the many side of the link\n for (const foreignObject of batch.getObjects(link.objectTypeApiName)) {\n if (anyValueMatches(foreignObject, primaryKey)) {\n batch.addLink(\n objectTypeApiName,\n primaryKey,\n link.apiName,\n link.objectTypeApiName,\n foreignObject.__primaryKey,\n );\n }\n }\n }\n });\n}\n\nfunction anyValueMatches(\n obj: BaseServerObject | Record<string, unknown>,\n primaryKey: string | number | boolean,\n) {\n return Object.values(obj).some(val => val === primaryKey);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAASA,OAAO,QAAQ,WAAW;AACnC,OAAOC,SAAS,MAAM,gBAAgB;AAEtCD,OAAO,CAACE,cAAc,GAAG;EACv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xBd,KAAyB,EACzBD,YAA6C,EAC7CoC,iBAAyB,EACzB1B,UAAqC,EACrCP,MAA+B,EACzB;EACN;EACAH,YAAY,CAACpB,WAAW,CAACwD,iBAAiB,CAAC,CAACmB,SAAS,CAAC1E,OAAO,CAAC2E,IAAI,IAAI;IACpE,MAAMC,WAAW,GAAGD,IAAI,CAACC,WAAW;IAEpC,IAAIA,WAAW,KAAK,KAAK,EAAE;MACzB;MACA,KAAK,MAAMC,aAAa,IAAIzD,KAAK,CAAC0D,UAAU,CAACH,IAAI,CAACpB,iBAAiB,CAAC,EAAE;QACpE,IAAIwB,eAAe,CAACzD,MAAM,EAAEuD,aAAa,CAACG,YAAY,CAAC,EAAE;UACvD5D,KAAK,CAAC6B,OAAO,CACXM,iBAAiB,EACjB1B,UAAU,EACV8C,IAAI,CAACnE,OAAO,EACZmE,IAAI,CAACpB,iBAAiB,EACtBsB,aAAa,CAACG,YAChB,CAAC;QACH;MACF;IACF,CAAC,MAAM;MACL;MACA,KAAK,MAAMH,aAAa,IAAIzD,KAAK,CAAC0D,UAAU,CAACH,IAAI,CAACpB,iBAAiB,CAAC,EAAE;QACpE,IAAIwB,eAAe,CAACF,aAAa,EAAEhD,UAAU,CAAC,EAAE;UAC9CT,KAAK,CAAC6B,OAAO,CACXM,iBAAiB,EACjB1B,UAAU,EACV8C,IAAI,CAACnE,OAAO,EACZmE,IAAI,CAACpB,iBAAiB,EACtBsB,aAAa,CAACG,YAChB,CAAC;QACH;MACF;IACF;EACF,CAAC,CAAC;AACJ;AAEA,SAASD,eAAeA,CACtB3B,GAA+C,EAC/CvB,UAAqC,EACrC;EACA,OAAOhC,MAAM,CAACC,MAAM,CAACsD,GAAG,CAAC,CAAC6B,IAAI,CAACC,GAAG,IAAIA,GAAG,KAAKrD,UAAU,CAAC;AAC3D","ignoreList":[]}
|
|
@@ -17,17 +17,11 @@
|
|
|
17
17
|
import crypto from "node:crypto";
|
|
18
18
|
import fs from "node:fs";
|
|
19
19
|
import path from "node:path";
|
|
20
|
-
import { NOISY } from "./generateOntologyAssets.js";
|
|
21
|
-
|
|
22
20
|
/**
|
|
23
21
|
* Synchronize directories by copying only changed files and removing obsolete ones
|
|
24
22
|
*/
|
|
25
23
|
export async function syncDirectories(sourceDir, targetDir, logger) {
|
|
26
|
-
|
|
27
|
-
logger.info(`Synchronizing ${sourceDir} to ${targetDir}`, {
|
|
28
|
-
timestamp: true
|
|
29
|
-
});
|
|
30
|
-
}
|
|
24
|
+
logger.debug(`Synchronizing ${sourceDir} to ${targetDir}`);
|
|
31
25
|
|
|
32
26
|
// Ensure target directory exists
|
|
33
27
|
await fs.promises.mkdir(targetDir, {
|
|
@@ -56,16 +50,12 @@ export async function syncDirectories(sourceDir, targetDir, logger) {
|
|
|
56
50
|
});
|
|
57
51
|
await fs.promises.copyFile(sourceFile, targetFile);
|
|
58
52
|
addedCount++;
|
|
59
|
-
logger.
|
|
60
|
-
timestamp: true
|
|
61
|
-
});
|
|
53
|
+
logger.debug(`Added: ${relativeFile}`);
|
|
62
54
|
} else if (isDifferent) {
|
|
63
55
|
// Changed file - update it
|
|
64
56
|
await fs.promises.copyFile(sourceFile, targetFile);
|
|
65
57
|
updatedCount++;
|
|
66
|
-
logger.
|
|
67
|
-
timestamp: true
|
|
68
|
-
});
|
|
58
|
+
logger.debug(`Updated: ${targetFile}`);
|
|
69
59
|
} else {
|
|
70
60
|
// File is unchanged
|
|
71
61
|
unchangedCount++;
|
|
@@ -73,9 +63,7 @@ export async function syncDirectories(sourceDir, targetDir, logger) {
|
|
|
73
63
|
} catch (error) {
|
|
74
64
|
const errorMsg = `Failed to sync ${relativeFile}: ${error instanceof Error ? error.message : String(error)}`;
|
|
75
65
|
errors.push(errorMsg);
|
|
76
|
-
logger.error(errorMsg
|
|
77
|
-
timestamp: true
|
|
78
|
-
});
|
|
66
|
+
logger.error(errorMsg);
|
|
79
67
|
}
|
|
80
68
|
}
|
|
81
69
|
|
|
@@ -86,15 +74,11 @@ export async function syncDirectories(sourceDir, targetDir, logger) {
|
|
|
86
74
|
try {
|
|
87
75
|
await fs.promises.unlink(targetFile);
|
|
88
76
|
removedCount++;
|
|
89
|
-
logger.
|
|
90
|
-
timestamp: true
|
|
91
|
-
});
|
|
77
|
+
logger.debug(`Removed: ${relativeFile}`);
|
|
92
78
|
} catch (error) {
|
|
93
79
|
const errorMsg = `Failed to remove ${relativeFile}: ${error instanceof Error ? error.message : String(error)}`;
|
|
94
80
|
errors.push(errorMsg);
|
|
95
|
-
logger.error(errorMsg
|
|
96
|
-
timestamp: true
|
|
97
|
-
});
|
|
81
|
+
logger.error(errorMsg);
|
|
98
82
|
}
|
|
99
83
|
}
|
|
100
84
|
}
|
|
@@ -103,20 +87,13 @@ export async function syncDirectories(sourceDir, targetDir, logger) {
|
|
|
103
87
|
try {
|
|
104
88
|
await removeEmptyDirectories(targetDir);
|
|
105
89
|
} catch (error) {
|
|
106
|
-
logger.warn(`Failed to clean up empty directories: ${error instanceof Error ? error.message : String(error)}
|
|
107
|
-
timestamp: true
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
if (NOISY) {
|
|
111
|
-
// Log summary
|
|
112
|
-
logger.info(`Sync complete: ${addedCount} added, ${updatedCount} updated, ${removedCount} removed, ${unchangedCount} unchanged`, {
|
|
113
|
-
timestamp: true
|
|
114
|
-
});
|
|
90
|
+
logger.warn(`Failed to clean up empty directories: ${error instanceof Error ? error.message : String(error)}`);
|
|
115
91
|
}
|
|
92
|
+
|
|
93
|
+
// Log summary
|
|
94
|
+
logger.debug(`Sync complete: ${addedCount} added, ${updatedCount} updated, ${removedCount} removed, ${unchangedCount} unchanged`);
|
|
116
95
|
if (errors.length > 0) {
|
|
117
|
-
logger.warn(`Encountered ${errors.length} errors during sync
|
|
118
|
-
timestamp: true
|
|
119
|
-
});
|
|
96
|
+
logger.warn(`Encountered ${errors.length} errors during sync`);
|
|
120
97
|
}
|
|
121
98
|
}
|
|
122
99
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncDirectories.js","names":["crypto","fs","path","NOISY","syncDirectories","sourceDir","targetDir","logger","info","timestamp","promises","mkdir","recursive","sourceFiles","targetFiles","Promise","all","getAllFiles","updatedCount","addedCount","removedCount","unchangedCount","errors","relativeFile","sourceFile","join","targetFile","targetExists","includes","isDifferent","areFilesDifferent","dirname","copyFile","error","errorMsg","Error","message","String","push","unlink","removeEmptyDirectories","warn","length","dir","entries","readdir","withFileTypes","entry","isDirectory","subdir","name","remainingEntries","resolve","rmdir","getFileHash","filePath","content","readFile","createHash","update","digest","sourceHash","targetHash","baseDir","files","fullPath","relativePath","relative","subFiles","isFile"],"sources":["syncDirectories.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 crypto from \"node:crypto\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { Logger } from \"vite\";\nimport { NOISY } from \"./generateOntologyAssets.js\";\n\n/**\n * Synchronize directories by copying only changed files and removing obsolete ones\n */\nexport async function syncDirectories(\n sourceDir: string,\n targetDir: string,\n logger: Logger,\n): Promise<void> {\n if (NOISY) {\n logger.info(`Synchronizing ${sourceDir} to ${targetDir}`, {\n timestamp: true,\n });\n }\n\n // Ensure target directory exists\n await fs.promises.mkdir(targetDir, { recursive: true });\n\n // Get all files in both directories\n const [sourceFiles, targetFiles] = await Promise.all([\n getAllFiles(sourceDir),\n getAllFiles(targetDir),\n ]);\n\n let updatedCount = 0;\n let addedCount = 0;\n let removedCount = 0;\n let unchangedCount = 0;\n const errors: string[] = [];\n\n // Process files from source directory\n for (const relativeFile of sourceFiles) {\n const sourceFile = path.join(sourceDir, relativeFile);\n const targetFile = path.join(targetDir, relativeFile);\n\n try {\n const targetExists = targetFiles.includes(relativeFile);\n const isDifferent = await areFilesDifferent(sourceFile, targetFile);\n\n if (!targetExists) {\n // New file - need to create directory structure\n await fs.promises.mkdir(path.dirname(targetFile), { recursive: true });\n await fs.promises.copyFile(sourceFile, targetFile);\n addedCount++;\n logger.info(`Added: ${relativeFile}`, { timestamp: true });\n } else if (isDifferent) {\n // Changed file - update it\n await fs.promises.copyFile(sourceFile, targetFile);\n updatedCount++;\n logger.info(`Updated: ${targetFile}`, { timestamp: true });\n } else {\n // File is unchanged\n unchangedCount++;\n }\n } catch (error) {\n const errorMsg = `Failed to sync ${relativeFile}: ${\n error instanceof Error ? error.message : String(error)\n }`;\n errors.push(errorMsg);\n logger.error(errorMsg, { timestamp: true });\n }\n }\n\n // Remove files that exist in target but not in source\n for (const relativeFile of targetFiles) {\n if (!sourceFiles.includes(relativeFile)) {\n const targetFile = path.join(targetDir, relativeFile);\n try {\n await fs.promises.unlink(targetFile);\n removedCount++;\n logger.info(`Removed: ${relativeFile}`, { timestamp: true });\n } catch (error) {\n const errorMsg = `Failed to remove ${relativeFile}: ${\n error instanceof Error ? error.message : String(error)\n }`;\n errors.push(errorMsg);\n logger.error(errorMsg, { timestamp: true });\n }\n }\n }\n\n // Clean up empty directories in target\n try {\n await removeEmptyDirectories(targetDir);\n } catch (error) {\n logger.warn(\n `Failed to clean up empty directories: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { timestamp: true },\n );\n }\n\n if (NOISY) {\n // Log summary\n logger.info(\n `Sync complete: ${addedCount} added, ${updatedCount} updated, ${removedCount} removed, ${unchangedCount} unchanged`,\n { timestamp: true },\n );\n }\n\n if (errors.length > 0) {\n logger.warn(`Encountered ${errors.length} errors during sync`, {\n timestamp: true,\n });\n }\n}\n\n/**\n * Remove empty directories recursively\n */\nasync function removeEmptyDirectories(dir: string): Promise<void> {\n try {\n const entries = await fs.promises.readdir(dir, { withFileTypes: true });\n\n // First, recursively clean subdirectories\n for (const entry of entries) {\n if (entry.isDirectory()) {\n const subdir = path.join(dir, entry.name);\n await removeEmptyDirectories(subdir);\n }\n }\n\n // Then check if this directory is now empty\n const remainingEntries = await fs.promises.readdir(dir);\n if (remainingEntries.length === 0) {\n // Don't remove the root target directory itself\n const targetDir = \".osdk/src\";\n if (path.resolve(dir) !== path.resolve(targetDir)) {\n await fs.promises.rmdir(dir);\n }\n }\n } catch (error) {\n // Ignore errors when cleaning up directories\n }\n}\n\n/**\n * Calculate SHA-256 hash of a file's contents\n */\nasync function getFileHash(filePath: string): Promise<string> {\n try {\n const content = await fs.promises.readFile(filePath);\n return crypto.createHash(\"sha256\").update(content).digest(\"hex\");\n } catch (error) {\n // Return empty hash for non-existent files\n return \"\";\n }\n}\n\n/**\n * Check if two files are different by comparing their hashes\n */\nasync function areFilesDifferent(\n sourceFile: string,\n targetFile: string,\n): Promise<boolean> {\n try {\n const [sourceHash, targetHash] = await Promise.all([\n getFileHash(sourceFile),\n getFileHash(targetFile),\n ]);\n return sourceHash !== targetHash || sourceHash === \"\"; // Different if hashes differ or source doesn't exist\n } catch (error) {\n // If we can't compare, assume they're different to be safe\n return true;\n }\n}\n\n/**\n * Recursively get all files in a directory\n */\nasync function getAllFiles(\n dir: string,\n baseDir: string = dir,\n): Promise<string[]> {\n const files: string[] = [];\n\n try {\n const entries = await fs.promises.readdir(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n const relativePath = path.relative(baseDir, fullPath);\n\n if (entry.isDirectory()) {\n const subFiles = await getAllFiles(fullPath, baseDir);\n files.push(...subFiles);\n } else if (entry.isFile()) {\n files.push(relativePath);\n }\n }\n } catch (error) {\n // Directory doesn't exist or can't be read\n }\n\n return files;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,O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E;IACd;IACA,OAAO,IAAI;EACb;AACF;;AAEA;AACA;AACA;AACA,eAAehB,WAAWA,CACxB0B,GAAW,EACXoB,OAAe,GAAGpB,GAAG,EACF;EACnB,MAAMqB,KAAe,GAAG,EAAE;EAE1B,IAAI;IACF,MAAMpB,OAAO,GAAG,MAAM3C,EAAE,CAACS,QAAQ,CAACmC,OAAO,CAACF,GAAG,EAAE;MAAEG,aAAa,EAAE;IAAK,CAAC,CAAC;IAEvE,KAAK,MAAMC,KAAK,IAAIH,OAAO,EAAE;MAC3B,MAAMqB,QAAQ,GAAG/D,IAAI,CAACuB,IAAI,CAACkB,GAAG,EAAEI,KAAK,CAACG,IAAI,CAAC;MAC3C,MAAMgB,YAAY,GAAGhE,IAAI,CAACiE,QAAQ,CAACJ,OAAO,EAAEE,QAAQ,CAAC;MAErD,IAAIlB,KAAK,CAACC,WAAW,CAAC,CAAC,EAAE;QACvB,MAAMoB,QAAQ,GAAG,MAAMnD,WAAW,CAACgD,QAAQ,EAAEF,OAAO,CAAC;QACrDC,KAAK,CAAC1B,IAAI,CAAC,GAAG8B,QAAQ,CAAC;MACzB,CAAC,MAAM,IAAIrB,KAAK,CAACsB,MAAM,CAAC,CAAC,EAAE;QACzBL,KAAK,CAAC1B,IAAI,CAAC4B,YAAY,CAAC;MAC1B;IACF;EACF,CAAC,CAAC,OAAOjC,KAAK,EAAE;IACd;EAAA;EAGF,OAAO+B,KAAK;AACd","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"syncDirectories.js","names":["crypto","fs","path","syncDirectories","sourceDir","targetDir","logger","debug","promises","mkdir","recursive","sourceFiles","targetFiles","Promise","all","getAllFiles","updatedCount","addedCount","removedCount","unchangedCount","errors","relativeFile","sourceFile","join","targetFile","targetExists","includes","isDifferent","areFilesDifferent","dirname","copyFile","error","errorMsg","Error","message","String","push","unlink","removeEmptyDirectories","warn","length","dir","entries","readdir","withFileTypes","entry","isDirectory","subdir","name","remainingEntries","resolve","rmdir","getFileHash","filePath","content","readFile","createHash","update","digest","sourceHash","targetHash","baseDir","files","fullPath","relativePath","relative","subFiles","isFile"],"sources":["syncDirectories.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 crypto from \"node:crypto\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { Logger } from \"./Logger.js\";\n\n/**\n * Synchronize directories by copying only changed files and removing obsolete ones\n */\nexport async function syncDirectories(\n sourceDir: string,\n targetDir: string,\n logger: Logger,\n): Promise<void> {\n logger.debug(`Synchronizing ${sourceDir} to ${targetDir}`);\n\n // Ensure target directory exists\n await fs.promises.mkdir(targetDir, { recursive: true });\n\n // Get all files in both directories\n const [sourceFiles, targetFiles] = await Promise.all([\n getAllFiles(sourceDir),\n getAllFiles(targetDir),\n ]);\n\n let updatedCount = 0;\n let addedCount = 0;\n let removedCount = 0;\n let unchangedCount = 0;\n const errors: string[] = [];\n\n // Process files from source directory\n for (const relativeFile of sourceFiles) {\n const sourceFile = path.join(sourceDir, relativeFile);\n const targetFile = path.join(targetDir, relativeFile);\n\n try {\n const targetExists = targetFiles.includes(relativeFile);\n const isDifferent = await areFilesDifferent(sourceFile, targetFile);\n\n if (!targetExists) {\n // New file - need to create directory structure\n await fs.promises.mkdir(path.dirname(targetFile), { recursive: true });\n await fs.promises.copyFile(sourceFile, targetFile);\n addedCount++;\n logger.debug(`Added: ${relativeFile}`);\n } else if (isDifferent) {\n // Changed file - update it\n await fs.promises.copyFile(sourceFile, targetFile);\n updatedCount++;\n logger.debug(`Updated: ${targetFile}`);\n } else {\n // File is unchanged\n unchangedCount++;\n }\n } catch (error) {\n const errorMsg = `Failed to sync ${relativeFile}: ${\n error instanceof Error ? error.message : String(error)\n }`;\n errors.push(errorMsg);\n logger.error(errorMsg);\n }\n }\n\n // Remove files that exist in target but not in source\n for (const relativeFile of targetFiles) {\n if (!sourceFiles.includes(relativeFile)) {\n const targetFile = path.join(targetDir, relativeFile);\n try {\n await fs.promises.unlink(targetFile);\n removedCount++;\n logger.debug(`Removed: ${relativeFile}`);\n } catch (error) {\n const errorMsg = `Failed to remove ${relativeFile}: ${\n error instanceof Error ? error.message : String(error)\n }`;\n errors.push(errorMsg);\n logger.error(errorMsg);\n }\n }\n }\n\n // Clean up empty directories in target\n try {\n await removeEmptyDirectories(targetDir);\n } catch (error) {\n logger.warn(\n `Failed to clean up empty directories: ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n\n // Log summary\n logger.debug(\n `Sync complete: ${addedCount} added, ${updatedCount} updated, ${removedCount} removed, ${unchangedCount} unchanged`,\n );\n\n if (errors.length > 0) {\n logger.warn(`Encountered ${errors.length} errors during sync`);\n }\n}\n\n/**\n * Remove empty directories recursively\n */\nasync function removeEmptyDirectories(dir: string): Promise<void> {\n try {\n const entries = await fs.promises.readdir(dir, { withFileTypes: true });\n\n // First, recursively clean subdirectories\n for (const entry of entries) {\n if (entry.isDirectory()) {\n const subdir = path.join(dir, entry.name);\n await removeEmptyDirectories(subdir);\n }\n }\n\n // Then check if this directory is now empty\n const remainingEntries = await fs.promises.readdir(dir);\n if (remainingEntries.length === 0) {\n // Don't remove the root target directory itself\n const targetDir = \".osdk/src\";\n if (path.resolve(dir) !== path.resolve(targetDir)) {\n await fs.promises.rmdir(dir);\n }\n }\n } catch (error) {\n // Ignore errors when cleaning up directories\n }\n}\n\n/**\n * Calculate SHA-256 hash of a file's contents\n */\nasync function getFileHash(filePath: string): Promise<string> {\n try {\n const content = await fs.promises.readFile(filePath);\n return crypto.createHash(\"sha256\").update(content).digest(\"hex\");\n } catch (error) {\n // Return empty hash for non-existent files\n return \"\";\n }\n}\n\n/**\n * Check if two files are different by comparing their hashes\n */\nasync function areFilesDifferent(\n sourceFile: string,\n targetFile: string,\n): Promise<boolean> {\n try {\n const [sourceHash, targetHash] = await Promise.all([\n getFileHash(sourceFile),\n getFileHash(targetFile),\n ]);\n return sourceHash !== targetHash || sourceHash === \"\"; // Different if hashes differ or source doesn't exist\n } catch (error) {\n // If we can't compare, assume they're different to be safe\n return true;\n }\n}\n\n/**\n * Recursively get all files in a directory\n */\nasync function getAllFiles(\n dir: string,\n baseDir: string = dir,\n): Promise<string[]> {\n const files: string[] = [];\n\n try {\n const entries = await fs.promises.readdir(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n const relativePath = path.relative(baseDir, fullPath);\n\n if (entry.isDirectory()) {\n const subFiles = await getAllFiles(fullPath, baseDir);\n files.push(...subFiles);\n } else if (entry.isFile()) {\n files.push(relativePath);\n }\n }\n } catch (error) {\n // Directory doesn't exist or can't be read\n }\n\n return files;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,MAAM,MAAM,aAAa;AAChC,OAAOC,EAAE,MAAM,SAAS;AACxB,OAAOC,IAAI,MAAM,WAAW;AAG5B;AACA;AACA;AACA,OAAO,eAAeC,eAAeA,CACnCC,SAAiB,EACjBC,SAAiB,EACjBC,MAAc,EACC;EACfA,MAAM,CAACC,KAAK,CAAC,iBAAiBH,SAAS,OAAOC,SAAS,EAAE,CAAC;;EAE1D;EACA,MAAMJ,EAAE,CAACO,QAAQ,CAACC,KAAK,CAACJ,SAAS,EAAE;IAAEK,SAAS,EAAE;EAAK,CAAC,CAAC;;EAEvD;EACA,MAAM,CAACC,WAAW,EAAEC,WAAW,CAAC,GAAG,MAAMC,OAAO,CAACC,GAAG,CAAC,CACnDC,WAAW,CAACX,SAAS,CAAC,EACtBW,WAAW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1
|
+
import type { Logger as ViteLogger } from "vite";
|
|
2
|
+
export declare enum Level {
|
|
3
|
+
debug = 0,
|
|
4
|
+
info = 1,
|
|
5
|
+
warn = 2,
|
|
6
|
+
error = 3
|
|
7
|
+
}
|
|
8
|
+
export declare class Logger {
|
|
9
|
+
#private;
|
|
10
|
+
constructor({ level, viteLogger }: {
|
|
11
|
+
level: Level | keyof typeof Level
|
|
12
|
+
viteLogger: ViteLogger
|
|
13
|
+
});
|
|
14
|
+
debug(message: string): void;
|
|
15
|
+
info(message: string): void;
|
|
16
|
+
error(message: string): void;
|
|
17
|
+
warn(message: string): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAiBA,cAAc,UAAU,kBAAkB,MAAO;AAEjD,oBAAY,MAAM;CAChB;CACA;CACA;CACA;AACD;AAED,OAAO,cAAM,OAAO;;CAIlB,YACE,EAAE,OAAO,YAGR,EAHsB;EACrB,OAAO,qBAAqB;EAC5B,YAAY;CACb;CAMH,MAAMA;CASN,KAAKA;CAQL,MAAMA;CAQN,KAAKA;AAQN","names":["message: string"],"sources":["../../src/Logger.ts"],"version":3,"file":"Logger.d.ts"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FauxOntology } from "@osdk/faux";
|
|
2
|
+
import type { Level } from "./Logger.js";
|
|
3
|
+
export interface OacConfig {
|
|
4
|
+
hooks?: {
|
|
5
|
+
preSeed?: (fauxOntology: FauxOntology) => Promise<void>
|
|
6
|
+
};
|
|
7
|
+
ontologyDir: string;
|
|
8
|
+
loggerLevel?: keyof typeof Level;
|
|
9
|
+
}
|
|
10
|
+
export declare class OacConfig {
|
|
11
|
+
constructor(config: OacConfig);
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,oBAAoB,YAAa;AAC/C,cAAc,aAAa,aAAc;AAEzC,iBAAiB,UAAU;CACzB,QAAQ;EACN,WAAWA,cAAc,iBAAiB;CAC3C;CACD;CACA,2BAA2B;AAC5B;AAED,OAAO,cAAM,UAAU;CACrB,YAAYC,QAAQ;AAGrB","names":["fauxOntology: FauxOntology","config: OacConfig"],"sources":["../../src/OacConfig.ts"],"version":3,"file":"OacConfig.d.ts"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FauxFoundry } from "@osdk/faux";
|
|
2
|
+
import type { ResolvedConfig } from "vite";
|
|
3
|
+
import { Logger } from "./Logger.js";
|
|
4
|
+
import { OacConfig } from "./OacConfig.js";
|
|
5
|
+
export declare class OacContext extends OacConfig {
|
|
6
|
+
workDir: string;
|
|
7
|
+
logger: Logger;
|
|
8
|
+
serverUrl: string;
|
|
9
|
+
defaultOntologyRid: string;
|
|
10
|
+
constructor(config: OacConfig, resolvedConfig: ResolvedConfig);
|
|
11
|
+
fauxFoundryFactory: () => FauxFoundry;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,SAAS,mBAAmB,YAAa;AAEzC,cAAc,sBAAsB,MAAO;AAC3C,SAA+B,cAAc,aAAc;AAC3D,SAAS,iBAAiB,gBAAiB;AAE3C,OAAO,cAAM,mBAAmB,UAAU;CACxC;CACA,QAAQ;CACR;CACA;CAEA,YAAYA,QAAQ,WAAWC,gBAAgB;CAgB/C,0BAA0B;AAQ3B","names":["config: OacConfig","resolvedConfig: ResolvedConfig"],"sources":["../../src/OacContext.ts"],"version":3,"file":"OacContext.d.ts"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FauxFoundry } from "@osdk/faux";
|
|
2
|
+
import type { ViteDevServer } from "vite";
|
|
3
|
+
import type { OacConfig } from "./OacConfig.js";
|
|
4
|
+
import { OacServerContext } from "./OacServerContext.js";
|
|
5
|
+
export declare class OacDevServer extends OacServerContext {
|
|
6
|
+
#private;
|
|
7
|
+
foundry: FauxFoundry;
|
|
8
|
+
constructor(config: OacConfig, server: ViteDevServer);
|
|
9
|
+
watchOntologyAsCode: () => Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,mBAAwB,YAAa;AAKnD,cAAuB,qBAAqB,MAAO;AAGnD,cAAc,iBAAiB,gBAAiB;AAChD,SAAS,wBAAwB,uBAAwB;AAGzD,OAAO,cAAM,qBAAqB,iBAAiB;;CACjD,SAAS;CAET,YAAYA,QAAQ,WAAWC,QAAQ;CAgCvC,2BAAgC;AA0CjC","names":["config: OacConfig","server: ViteDevServer"],"sources":["../../src/OacDevServer.ts"],"version":3,"file":"OacDevServer.d.ts"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Emittery from "emittery";
|
|
2
|
+
import type { FSWatcher, ViteDevServer } from "vite";
|
|
3
|
+
import type { OacConfig } from "./OacConfig.js";
|
|
4
|
+
import { OacContext } from "./OacContext.js";
|
|
5
|
+
export interface OacServerEvents {
|
|
6
|
+
generatedOntologyAssets: undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare class OacServerContext extends OacContext {
|
|
9
|
+
watcher: FSWatcher;
|
|
10
|
+
emitter: Emittery<OacServerEvents>;
|
|
11
|
+
constructor(config: OacConfig, server: ViteDevServer);
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,OAAO,cAAc,UAAW;AAChC,cAAc,WAAW,qBAAqB,MAAO;AACrD,cAAc,iBAAiB,gBAAiB;AAChD,SAAS,kBAAkB,iBAAkB;AAE7C,iBAAiB,gBAAgB;CAC/B;AACD;AAED,OAAO,cAAM,yBAAyB,WAAW;CAC/C,SAAS;CACT,SAAS,SAAS;CAElB,YAAYA,QAAQ,WAAWC,QAAQ;AAKxC","names":["config: OacConfig","server: ViteDevServer"],"sources":["../../src/OacServerContext.ts"],"version":3,"file":"OacServerContext.d.ts"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,mBAAmB,YAAa;AAM9C,cAAc,kBAAkB,iBAAkB;AAIlD,OAAO,iBAAe,qBACpBA,aAAa,aACbC,KAAK,aACJ","names":["fauxFoundry: FauxFoundry","ctx: OacContext"],"sources":["../../src/applyOntologyAndSeed.ts"],"version":3,"file":"applyOntologyAndSeed.d.ts"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const NOISY: boolean;
|
|
3
|
-
export interface GenerateOntologyAssetsOptions {
|
|
4
|
-
logger: Logger;
|
|
5
|
-
ontologyDir: string;
|
|
6
|
-
}
|
|
1
|
+
import type { OacContext } from "./OacContext.js";
|
|
7
2
|
/**
|
|
8
3
|
* Generate all ontology assets: IR, full metadata, and OSDK.
|
|
9
4
|
* This function contains the core generation logic extracted from watchOntologyAsCode
|
|
10
5
|
* so it can be used both in dev mode (via file watching) and build mode.
|
|
11
6
|
*/
|
|
12
|
-
export declare function generateOntologyAssets(
|
|
7
|
+
export declare function generateOntologyAssets(opts: OacContext): Promise<void>;
|
|
8
|
+
export declare function ontologyIrPath(workDir: string): string;
|
|
9
|
+
export declare function ontologyFullMetadataPath(workDir: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"AAyBA,cAAc,kBAAkB,iBAAkB;;;;;;AAQlD,OAAO,iBAAe,uBACpBA,MAAM,aACL;AAgBH,OAAO,iBAAS,eAAeC;AAI/B,OAAO,iBAAS,yBAAyBA","names":["opts: OacContext","workDir: string"],"sources":["../../src/generateOntologyAssets.ts"],"version":3,"file":"generateOntologyAssets.d.ts"}
|
package/build/types/index.d.ts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Vite plugin for Ontology as Code (OAC) that generates ontology IR, metadata, and OSDK
|
|
5
|
-
* in both development and build modes.
|
|
6
|
-
*/
|
|
7
|
-
export declare function ontologyAsCode(opts: {
|
|
8
|
-
hooks?: {
|
|
9
|
-
preSeed?: (fauxOntology: FauxOntology) => Promise<void>
|
|
10
|
-
}
|
|
11
|
-
}): PluginOption;
|
|
1
|
+
export { OacConfig } from "./OacConfig.js";
|
|
2
|
+
export { ontologyAsCode } from "./ontologyAsCode.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,
|
|
1
|
+
{"mappings":"AAgBA,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB","names":[],"sources":["../../src/index.ts"],"version":3,"file":"index.d.ts"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PluginOption } from "vite";
|
|
2
|
+
import type { OacConfig } from "./OacConfig.js";
|
|
3
|
+
/**
|
|
4
|
+
* Vite plugin for Ontology as Code (OAC) that generates ontology IR, metadata, and OSDK
|
|
5
|
+
* in both development and build modes.
|
|
6
|
+
*/
|
|
7
|
+
export declare function ontologyAsCode(oacConfig: OacConfig): PluginOption;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAiBA,cAAc,oBAAoC,MAAO;AAEzD,cAAc,iBAAiB,gBAAiB;;;;;AAQhD,OAAO,iBAAS,eACdA,WAAW,YACV","names":["oacConfig: OacConfig"],"sources":["../../src/ontologyAsCode.ts"],"version":3,"file":"ontologyAsCode.d.ts"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,
|
|
1
|
+
{"mappings":"AAgBA,cAIE,mBACK,YAAa;AACpB,iBAAiB,gBAAgB,0BAA2B;AAS5D,OAAO,iBAAS,6BACdA,UAAU,WAAW,YAAY,iBACjCC,sBAAsB,WAAW","names":["ontology: ReturnType<FauxFoundry[\"getOntology\"]>","ontologyFullMetadata: Ontologies.OntologyFullMetadata"],"sources":["../../src/registerOntologyFullMetadata.ts"],"version":3,"file":"registerOntologyFullMetadata.d.ts"}
|