-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding bulk actions to 1.1 #53
Changes from 4 commits
93b6a91
5fa8a4f
45d9d57
6e866dc
9e07b3a
db62515
3357ae8
722ecd8
fb10026
78f048c
0fa395a
493acd0
30fce6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { | ||
ActionError, | ||
Attachment, | ||
BulkActionExecutionOptions, | ||
BulkActionResponseFromOptions, | ||
Edits, | ||
LocalDate, | ||
ObjectSet, | ||
Result, | ||
Timestamp, | ||
} from '@osdk/legacy-client'; | ||
import type { ObjectTypeWithAllPropertyTypes } from '../objects/ObjectTypeWithAllPropertyTypes'; | ||
import type { Person } from '../objects/Person'; | ||
import type { Todo } from '../objects/Todo'; | ||
export interface BulkActions { | ||
/** | ||
* An action which takes different types of parameters | ||
* @param {ObjectSet<Todo>} params.objectSet | ||
* @param {Person | Person["__primaryKey"]} params.object | ||
* @param {string} params.string | ||
* @param {Timestamp} params.time-stamp | ||
* @param {Array<LocalDate>} params.dateArray | ||
* @param {Array<Attachment>} params.attachmentArray | ||
*/ | ||
actionTakesAllParameterTypes<O extends BulkActionExecutionOptions>( | ||
params: { | ||
objectSet: ObjectSet<Todo>; | ||
object?: Person | Person['__primaryKey']; | ||
string: string; | ||
'time-stamp': Timestamp; | ||
dateArray?: Array<LocalDate>; | ||
attachmentArray: Array<Attachment>; | ||
}[], | ||
options?: O, | ||
): Promise<Result<BulkActionResponseFromOptions<O, Edits<Todo, Todo | ObjectTypeWithAllPropertyTypes>>, ActionError>>; | ||
|
||
/** | ||
* Creates a new Todo | ||
*/ | ||
createTodo<O extends BulkActionExecutionOptions>( | ||
options?: O, | ||
): Promise<Result<BulkActionResponseFromOptions<O, Edits<Todo, void>>, ActionError>>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { | ||
ActionError, | ||
BulkActionExecutionOptions, | ||
BulkActionResponseFromOptions, | ||
Edits, | ||
Result, | ||
} from '@osdk/legacy-client'; | ||
import type { Todo } from '../objects/Todo'; | ||
export interface BulkActions { | ||
/** | ||
* Creates Todo | ||
* @param {string} params.Todo | ||
* @param {boolean} params.is_complete | ||
*/ | ||
createTodo<O extends BulkActionExecutionOptions>( | ||
params: { | ||
Todo: string; | ||
is_complete: boolean; | ||
}[], | ||
options?: O, | ||
): Promise<Result<BulkActionResponseFromOptions<O, Edits<Todo, void>>, ActionError>>; | ||
|
||
/** | ||
* Completes Todo | ||
* @param {Todo | Todo["__primaryKey"]} params.Todo | ||
* @param {boolean} params.is_complete | ||
*/ | ||
completeTodo<O extends BulkActionExecutionOptions>( | ||
params: { | ||
Todo: Todo | Todo['__primaryKey']; | ||
is_complete: boolean; | ||
}[], | ||
options?: O, | ||
): Promise<Result<BulkActionResponseFromOptions<O, Edits<void, Todo>>, ActionError>>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2023 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { describe, expect, it } from "vitest"; | ||
import { createMockMinimalFiles } from "../util/test/createMockMinimalFiles"; | ||
import { TodoWireOntology } from "../util/test/TodoWireOntology"; | ||
import { generateBulkActions } from "./generateBulkActions"; | ||
|
||
describe(generateBulkActions, () => { | ||
it("generates bulk action interface", async () => { | ||
const helper = createMockMinimalFiles(); | ||
const BASE_PATH = "/foo"; | ||
|
||
await generateBulkActions( | ||
TodoWireOntology, | ||
helper.minimalFiles, | ||
BASE_PATH, | ||
); | ||
|
||
expect(helper.minimalFiles.writeFile).toBeCalled(); | ||
|
||
expect(helper.getFiles()[`${BASE_PATH}/BulkActions.ts`]) | ||
.toMatchInlineSnapshot(` | ||
"import type { | ||
ActionError, | ||
BulkActionExecutionOptions, | ||
BulkActionResponseFromOptions, | ||
Edits, | ||
Result, | ||
} from '@osdk/legacy-client'; | ||
import type { Todo } from '../objects/Todo'; | ||
export interface BulkActions { | ||
/** | ||
* An action which takes different types of parameters | ||
* @param {Todo | Todo["__primaryKey"]} params.object | ||
*/ | ||
markTodoCompleted<O extends BulkActionExecutionOptions>( | ||
params: { | ||
object?: Todo | Todo['__primaryKey']; | ||
}[], | ||
options?: O, | ||
): Promise<Result<BulkActionResponseFromOptions<O, Edits<void, Todo>>, ActionError>>; | ||
} | ||
" | ||
`); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright 2023 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import path from "node:path"; | ||
import type { MinimalFs } from "../MinimalFs"; | ||
import { getModifiedEntityTypes } from "../shared/getEditedEntities"; | ||
import { formatTs } from "../util/test/formatTs"; | ||
import type { WireOntologyDefinition } from "../WireOntologyDefinition"; | ||
import { getTypeScriptTypeFromDataType } from "./generateActions"; | ||
|
||
export async function generateBulkActions( | ||
ontology: WireOntologyDefinition, | ||
fs: MinimalFs, | ||
outDir: string, | ||
importExt: string = "", | ||
) { | ||
const importedObjects = new Set<string>(); | ||
let actionSignatures: any[] = []; | ||
for (const action of Object.values(ontology.actionTypes)) { | ||
const entries = Object.entries(action.parameters); | ||
|
||
const modifiedEntityTypes = getModifiedEntityTypes(action); | ||
const addedObjects = Array.from(modifiedEntityTypes.addedObjects); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yea I just pulled this from the |
||
const modifiedObjects = Array.from(modifiedEntityTypes.modifiedObjects); | ||
addedObjects.forEach(importedObjects.add, importedObjects); | ||
modifiedObjects.forEach(importedObjects.add, importedObjects); | ||
|
||
let jsDocBlock = ["/**"]; | ||
if (action.description) { | ||
jsDocBlock.push(`* ${action.description}`); | ||
} | ||
|
||
let parameterBlock = ""; | ||
if (entries.length > 0) { | ||
parameterBlock = `params: { \n`; | ||
for ( | ||
const [parameterName, parameterData] of entries | ||
) { | ||
parameterBlock += `"${parameterName}"`; | ||
parameterBlock += parameterData.required ? ": " : "?: "; | ||
const typeScriptType = getTypeScriptTypeFromDataType( | ||
parameterData.dataType, | ||
importedObjects, | ||
); | ||
parameterBlock += `${typeScriptType};\n`; | ||
|
||
jsDocBlock.push( | ||
`* @param {${typeScriptType}} params.${parameterName}`, | ||
); | ||
} | ||
parameterBlock += "}[], "; | ||
} | ||
|
||
jsDocBlock.push(`*/`); | ||
actionSignatures.push( | ||
` | ||
${jsDocBlock.join("\n")} | ||
${action.apiName}<O extends BulkActionExecutionOptions>(${parameterBlock}options?: O): | ||
Promise<Result<BulkActionResponseFromOptions<O, Edits<${ | ||
addedObjects.length > 0 | ||
? addedObjects.join(" | ") | ||
: "void" | ||
}, ${ | ||
modifiedObjects.length > 0 | ||
? modifiedObjects.join(" | ") | ||
: "void" | ||
}>>, ActionError>>; | ||
`, | ||
); | ||
} | ||
|
||
await fs.mkdir(outDir, { recursive: true }); | ||
await fs.writeFile( | ||
path.join(outDir, "BulkActions.ts"), | ||
await formatTs(` | ||
import type { ObjectSet, LocalDate, Timestamp, Attachment, Edits, ActionExecutionOptions, BulkActionExecutionOptions, ActionError, Result, ActionResponseFromOptions, BulkActionResponseFromOptions } from "@osdk/legacy-client"; | ||
${ | ||
Array.from(importedObjects).map(importedObject => | ||
`import type { ${importedObject} } from "../objects/${importedObject}${importExt}";` | ||
).join("\n") | ||
} | ||
export interface BulkActions { | ||
${actionSignatures.join("\n")} | ||
} | ||
`), | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you mention rationale in the PR description as to why we add it at the top level vs within actions, for posterity?