-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add remote modeling commands for custom types, page types, and slices #83
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
bdbaa1e
feat: add remote modeling commands for custom types, page types, and …
angeloashmore e59258b
fix: correct Custom Types API URLs and slice command messages
angeloashmore ebb38ec
test: add e2e tests for custom-type, page-type, and slice commands
angeloashmore a90b570
fix: add default slice zone to page type and fix test types
angeloashmore 16d120f
feat: add field management commands for remote modeling
angeloashmore 56a739e
fix: add missing primary field to test slice builder
angeloashmore 9cfd1c4
feat: add field edit command for remote modeling
angeloashmore 8c765e3
feat: move sync logic into Adapter and sync after modeling commands
angeloashmore 11dc23c
feat: replace syncModels with granular adapter methods
angeloashmore 2133b8b
Merge branch 'main' into aa/remote-modeling
angeloashmore cf1f0d6
feat: unify `page-type` and `custom-type` into single `type` command …
angeloashmore 901a0be
feat: add `type edit` command (#106)
angeloashmore ebf788b
feat: add `slice edit` and `slice edit-variation` commands (#107)
angeloashmore 98ed067
feat: add tab management commands (#108)
angeloashmore ae4006a
feat: rename `--in` flag to `--from-slice`/`--from-type` (#110)
angeloashmore 75f5bc9
feat: show fields inline in `view` commands and remove `field list` (…
angeloashmore 68f620f
feat: add `field view` command (#112)
angeloashmore 8d68cd1
feat: consolidate link-related field types (#114)
angeloashmore e23c6f6
feat: improve `content-relationship` help text (#115)
angeloashmore 90227ab
feat: add a consistent table formatter for tabular output (#116)
angeloashmore 774a581
feat: replace name-based model specifiers with IDs (#117)
angeloashmore 29c12b7
Merge branch 'main' into aa/remote-modeling
angeloashmore af8d9d8
refactor: add `getCustomType` and `getSlice` client functions (#124)
angeloashmore ddd0555
feat: add `--field` option to `field add content-relationship` and `f…
angeloashmore 8c60568
Merge branch 'main' into aa/remote-modeling
angeloashmore c3aa214
Merge branch 'main' into aa/remote-modeling
angeloashmore 1903f4b
feat: handle type removal when documents exist (#127)
angeloashmore d94447a
feat: add field reorder command (#129)
angeloashmore 40f71f0
feat: add `--screenshot` option to `slice add-variation` and `slice e…
angeloashmore 2ef8f27
Merge remote-tracking branch 'origin/main' into aa/remote-modeling
angeloashmore a493a7f
fix: misc fixes for remote modeling branch
angeloashmore 400e166
fix: resolve nested field lookup and missing existence check
angeloashmore 0fbc9c3
fix: join field IDs before fallback check in error message
angeloashmore 1e28f9d
fix: allow adding placeholder to fields that lack one and remove unus…
angeloashmore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import type { BooleanField } from "@prismicio/types-internal/lib/customtypes"; | ||
|
|
||
| import { capitalCase } from "change-case"; | ||
|
|
||
| import { getHost, getToken } from "../auth"; | ||
| import { CommandError, createCommand, type CommandConfig } from "../lib/command"; | ||
| import { resolveFieldTarget, resolveModel, TARGET_OPTIONS } from "../models"; | ||
| import { getRepositoryName } from "../project"; | ||
|
|
||
| const config = { | ||
| name: "prismic field add boolean", | ||
| description: "Add a boolean field to a slice or custom type.", | ||
| positionals: { | ||
| id: { description: "Field ID", required: true }, | ||
| }, | ||
| options: { | ||
| ...TARGET_OPTIONS, | ||
| label: { type: "string", description: "Field label" }, | ||
| "default-value": { type: "boolean", description: "Default value" }, | ||
| "true-label": { type: "string", description: "Label for true value" }, | ||
| "false-label": { type: "string", description: "Label for false value" }, | ||
| }, | ||
| } satisfies CommandConfig; | ||
|
|
||
| export default createCommand(config, async ({ positionals, values }) => { | ||
| const [id] = positionals; | ||
| const { | ||
| label, | ||
| "default-value": default_value, | ||
| "true-label": placeholder_true, | ||
| "false-label": placeholder_false, | ||
| repo = await getRepositoryName(), | ||
| } = values; | ||
|
|
||
| const token = await getToken(); | ||
| const host = await getHost(); | ||
| const [fields, saveModel] = await resolveModel(values, { repo, token, host }); | ||
| const [targetFields, fieldId] = resolveFieldTarget(fields, id); | ||
|
|
||
| const field: BooleanField = { | ||
| type: "Boolean", | ||
| config: { | ||
| label: label ?? capitalCase(fieldId), | ||
| default_value, | ||
| placeholder_true, | ||
| placeholder_false, | ||
| }, | ||
| }; | ||
|
|
||
| if (fieldId in targetFields) throw new CommandError(`Field "${id}" already exists.`); | ||
| targetFields[fieldId] = field; | ||
| await saveModel(); | ||
|
|
||
| console.info(`Field added: ${id}`); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Parallel sync may cause race conditions on shared resources
Medium Severity
syncModelsrunssyncSlicesandsyncCustomTypesin parallel viaPromise.all, whereas the old code insync.tsran them sequentially. Both paths invoke adapter callbacks (onSliceCreated,onCustomTypeCreated, etc.) and filesystem operations likecreateSliceIndexFileandaddRoute/updateRoute. If framework-specific adapter implementations modify shared resources (e.g., route config files, shared index files), the concurrent execution could cause race conditions or data corruption that was previously impossible with sequential execution.Reviewed by Cursor Bugbot for commit 1e28f9d. Configure here.