primitive-admin 1.0.54 → 1.0.56
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/assets/skill/skills/primitive-platform/SKILL.md +230 -2
- package/dist/bin/primitive.js +3 -1
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/apps.js +54 -2
- package/dist/src/commands/apps.js.map +1 -1
- package/dist/src/commands/database-types.js +4 -4
- package/dist/src/commands/database-types.js.map +1 -1
- package/dist/src/commands/databases.js +35 -14
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/documents.js +77 -0
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/guides.d.ts +15 -12
- package/dist/src/commands/guides.js +22 -15
- package/dist/src/commands/guides.js.map +1 -1
- package/dist/src/commands/metadata.js +48 -3
- package/dist/src/commands/metadata.js.map +1 -1
- package/dist/src/commands/scripts.d.ts +18 -0
- package/dist/src/commands/scripts.js +59 -5
- package/dist/src/commands/scripts.js.map +1 -1
- package/dist/src/commands/settings.d.ts +15 -0
- package/dist/src/commands/settings.js +102 -0
- package/dist/src/commands/settings.js.map +1 -0
- package/dist/src/commands/sync-app-settings.d.ts +115 -0
- package/dist/src/commands/sync-app-settings.js +379 -0
- package/dist/src/commands/sync-app-settings.js.map +1 -0
- package/dist/src/commands/sync.d.ts +134 -19
- package/dist/src/commands/sync.js +1949 -600
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/workflows.js +54 -15
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/lib/api-client.d.ts +29 -1
- package/dist/src/lib/api-client.js +31 -2
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/app-settings-descriptor.d.ts +108 -0
- package/dist/src/lib/app-settings-descriptor.js +254 -0
- package/dist/src/lib/app-settings-descriptor.js.map +1 -0
- package/dist/src/lib/codegen-shared/generatedFiles.d.ts +36 -0
- package/dist/src/lib/codegen-shared/generatedFiles.js +67 -10
- package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -1
- package/dist/src/lib/codegen-shared/prettierStable.d.ts +262 -0
- package/dist/src/lib/codegen-shared/prettierStable.js +610 -0
- package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -0
- package/dist/src/lib/db-codegen/dbGenerator.d.ts +11 -83
- package/dist/src/lib/db-codegen/dbGenerator.js +96 -556
- package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -1
- package/dist/src/lib/db-codegen/dbNaming.d.ts +20 -7
- package/dist/src/lib/db-codegen/dbNaming.js +31 -13
- package/dist/src/lib/db-codegen/dbNaming.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTemplates.d.ts +70 -4
- package/dist/src/lib/db-codegen/dbTemplates.js +244 -70
- package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTsTypes.d.ts +13 -22
- package/dist/src/lib/db-codegen/dbTsTypes.js +33 -28
- package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTypeIR.d.ts +146 -0
- package/dist/src/lib/db-codegen/dbTypeIR.js +517 -0
- package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -0
- package/dist/src/lib/db-codegen/generated-operation-def-descriptor.d.ts +112 -0
- package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js +211 -0
- package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js.map +1 -0
- package/dist/src/lib/generated-allowlist.js +7 -0
- package/dist/src/lib/generated-allowlist.js.map +1 -1
- package/dist/src/lib/platform-owned.d.ts +37 -0
- package/dist/src/lib/platform-owned.js +46 -0
- package/dist/src/lib/platform-owned.js.map +1 -0
- package/dist/src/lib/swift-codegen/dbGenerator.d.ts +100 -0
- package/dist/src/lib/swift-codegen/dbGenerator.js +682 -0
- package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -0
- package/dist/src/lib/swift-codegen/dbSwiftTypes.d.ts +42 -0
- package/dist/src/lib/swift-codegen/dbSwiftTypes.js +100 -0
- package/dist/src/lib/swift-codegen/dbSwiftTypes.js.map +1 -0
- package/dist/src/lib/swift-codegen/generator.d.ts +85 -0
- package/dist/src/lib/swift-codegen/generator.js +266 -0
- package/dist/src/lib/swift-codegen/generator.js.map +1 -0
- package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +72 -0
- package/dist/src/lib/swift-codegen/schemaToSwift.js +644 -0
- package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -0
- package/dist/src/lib/swift-codegen/siblingSymbols.d.ts +90 -0
- package/dist/src/lib/swift-codegen/siblingSymbols.js +152 -0
- package/dist/src/lib/swift-codegen/siblingSymbols.js.map +1 -0
- package/dist/src/lib/swift-codegen/swiftNaming.d.ts +85 -0
- package/dist/src/lib/swift-codegen/swiftNaming.js +198 -0
- package/dist/src/lib/swift-codegen/swiftNaming.js.map +1 -0
- package/dist/src/lib/sync-resource-types.d.ts +437 -0
- package/dist/src/lib/sync-resource-types.js +781 -0
- package/dist/src/lib/sync-resource-types.js.map +1 -0
- package/dist/src/lib/template.d.ts +1 -1
- package/dist/src/lib/template.js +6 -3
- package/dist/src/lib/template.js.map +1 -1
- package/dist/src/lib/toml-metadata-config.js +18 -0
- package/dist/src/lib/toml-metadata-config.js.map +1 -1
- package/dist/src/lib/workflow-apply.js +12 -2
- package/dist/src/lib/workflow-apply.js.map +1 -1
- package/dist/src/lib/workflow-codegen/generator.d.ts +27 -5
- package/dist/src/lib/workflow-codegen/generator.js +214 -68
- package/dist/src/lib/workflow-codegen/generator.js.map +1 -1
- package/dist/src/lib/workflow-codegen/invokerIR.d.ts +83 -0
- package/dist/src/lib/workflow-codegen/invokerIR.js +71 -0
- package/dist/src/lib/workflow-codegen/invokerIR.js.map +1 -0
- package/dist/src/lib/workflow-codegen/schemaToTs.d.ts +17 -1
- package/dist/src/lib/workflow-codegen/schemaToTs.js +59 -38
- package/dist/src/lib/workflow-codegen/schemaToTs.js.map +1 -1
- package/dist/src/lib/workflow-payload.d.ts +19 -0
- package/dist/src/lib/workflow-payload.js +21 -0
- package/dist/src/lib/workflow-payload.js.map +1 -1
- package/dist/src/lib/workflow-toml-validator.d.ts +30 -0
- package/dist/src/lib/workflow-toml-validator.js +206 -0
- package/dist/src/lib/workflow-toml-validator.js.map +1 -1
- package/dist/src/types/index.d.ts +1 -0
- package/package.json +5 -2
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared layout metadata for the per-entity resource types `sync pull` writes
|
|
3
|
+
* into a sync slot (issue #1659).
|
|
4
|
+
*
|
|
5
|
+
* `sync pull` writes one file per server entity and records what it wrote in
|
|
6
|
+
* `.primitive-sync.json` (`SyncState.entities[<slot>]`). Until #1659 it never
|
|
7
|
+
* removed a local file whose entity had disappeared server-side, so the next
|
|
8
|
+
* `sync push` — which treats local TOML as the source of truth — silently
|
|
9
|
+
* re-created the just-deleted entity.
|
|
10
|
+
*
|
|
11
|
+
* This module holds the narrow descriptor the prune pass and `sync diff` share:
|
|
12
|
+
* directory, extension, state slot, key→filename derivation, and the sidecar
|
|
13
|
+
* test-directory block type. The pull write loops deliberately stay as they are
|
|
14
|
+
* — this table is layout metadata, not a write framework.
|
|
15
|
+
*/
|
|
16
|
+
import type { SyncState } from "../types/index.js";
|
|
17
|
+
import type { ApiClient } from "./api-client.js";
|
|
18
|
+
export type SyncEntitySlot = keyof SyncState["entities"];
|
|
19
|
+
export interface SyncResourceType {
|
|
20
|
+
/** Singular name used in pull/diff output, e.g. `"rule-set"`. */
|
|
21
|
+
label: string;
|
|
22
|
+
/** Directory under the sync slot holding this type's files. */
|
|
23
|
+
dir: string;
|
|
24
|
+
/** Extension of this type's files. */
|
|
25
|
+
ext: ".toml" | ".rhai";
|
|
26
|
+
/** Slot in `SyncState.entities` recording what a prior pull managed. */
|
|
27
|
+
stateSlot: SyncEntitySlot;
|
|
28
|
+
/**
|
|
29
|
+
* Entity key → the file basename `sync pull` writes for it. This must match
|
|
30
|
+
* the write side exactly, so prune only ever targets a file pull created.
|
|
31
|
+
*/
|
|
32
|
+
fileFromKey(key: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Block type for the sidecar `<key>.tests/` directory, when the type has one.
|
|
35
|
+
* Pruning an entity also removes its test directory and the matching
|
|
36
|
+
* `entities.testCases` records.
|
|
37
|
+
*/
|
|
38
|
+
testBlockType?: "prompt" | "workflow" | "script";
|
|
39
|
+
/**
|
|
40
|
+
* Whether this type's server listing returns *every* key, so "absent from the
|
|
41
|
+
* listing" really means "gone from the server".
|
|
42
|
+
*
|
|
43
|
+
* Prune deletes files, so a successful fetch is not enough — the response also
|
|
44
|
+
* has to be complete. Two shapes make a listing complete: the cursor-paginating
|
|
45
|
+
* admin endpoints (integrations/webhooks/prompts/workflows — server returns
|
|
46
|
+
* `nextCursor` and `sync pull` drains it with `fetchAll`), and the config
|
|
47
|
+
* listings that drain every DynamoDB page server-side via `queryAllPages`
|
|
48
|
+
* (#1668). Before #1668 the config listings returned a single 100-row page with
|
|
49
|
+
* a 200 and no cursor, so an app past the page boundary got a silently
|
|
50
|
+
* truncated list and prune would have removed files of still-live entities;
|
|
51
|
+
* those types were held at `false`. The server now drains them, so all shipping
|
|
52
|
+
* types are complete.
|
|
53
|
+
*
|
|
54
|
+
* Version-skew assumption (accepted risk): setting a config type `true` assumes
|
|
55
|
+
* the target server carries #1668's drain. The CLI can target an independently
|
|
56
|
+
* versioned environment, so a new CLI against a pre-#1668 server still gets a
|
|
57
|
+
* silently 100-row-truncated listing and prune would delete local files for
|
|
58
|
+
* still-live entities past the page boundary. This is accepted per the sponsor
|
|
59
|
+
* ruling on PR #1689 / issue #1668 rather than gated on a server capability or
|
|
60
|
+
* version marker: the CLI npm publish is coupled to the production deploy (so
|
|
61
|
+
* new-CLI-vs-old-server is a narrow window), the worst case is git-recoverable
|
|
62
|
+
* local file deletion touching nothing server-side, and it only affects apps
|
|
63
|
+
* with >100 entities of one config type — whose `sync pull` was already
|
|
64
|
+
* silently incomplete before this change.
|
|
65
|
+
*
|
|
66
|
+
* The flag remains as a guard: a future type whose listing is not yet complete
|
|
67
|
+
* ships `false` and prune skips it (`listing-incomplete`) until its server side
|
|
68
|
+
* drains.
|
|
69
|
+
*/
|
|
70
|
+
listingComplete: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Rule sets are keyed on disk (and in sync state) by their name with
|
|
74
|
+
* filesystem-hostile characters replaced. Shared by the pull write loop and the
|
|
75
|
+
* prune pass so the two can never derive a different key for the same rule set.
|
|
76
|
+
*/
|
|
77
|
+
export declare function ruleSetFileKey(ruleSet: {
|
|
78
|
+
name?: string;
|
|
79
|
+
ruleSetId?: string;
|
|
80
|
+
}): string;
|
|
81
|
+
/**
|
|
82
|
+
* Every per-entity resource type in a sync slot. `app.toml` and `vars.toml` are
|
|
83
|
+
* root singletons, not per-entity directories, so they are not listed here —
|
|
84
|
+
* var removal is already handled within-file by `sync push` (`planVarsPush`).
|
|
85
|
+
*/
|
|
86
|
+
export declare const SYNC_RESOURCE_TYPES: SyncResourceType[];
|
|
87
|
+
/**
|
|
88
|
+
* Outcome of a server fetch that establishes which entities of a type exist.
|
|
89
|
+
*
|
|
90
|
+
* `sync pull` historically swallowed several list errors with `.catch(() => [])`,
|
|
91
|
+
* which makes a transient 401/500/network error indistinguishable from "the app
|
|
92
|
+
* has none of these". Pruning off that empty list would delete every local file
|
|
93
|
+
* of the type, so prune consumes this explicit outcome instead.
|
|
94
|
+
*/
|
|
95
|
+
export type PresenceOutcome = {
|
|
96
|
+
ok: true;
|
|
97
|
+
serverKeys: string[];
|
|
98
|
+
} | {
|
|
99
|
+
ok: false;
|
|
100
|
+
};
|
|
101
|
+
/** Generic try/catch wrapper for a server fetch, in the ok/error shape. */
|
|
102
|
+
export declare function attemptFetch<T>(fn: () => Promise<T>): Promise<{
|
|
103
|
+
ok: true;
|
|
104
|
+
value: T;
|
|
105
|
+
} | {
|
|
106
|
+
ok: false;
|
|
107
|
+
error: any;
|
|
108
|
+
}>;
|
|
109
|
+
/**
|
|
110
|
+
* A filename must stay inside its type's directory. State is read from a file
|
|
111
|
+
* on disk, so a corrupt or hand-edited `.primitive-sync.json` must never be
|
|
112
|
+
* able to steer an `unlinkSync` outside the sync slot.
|
|
113
|
+
*/
|
|
114
|
+
export declare function isSafeSyncFilename(filename: string): boolean;
|
|
115
|
+
export interface PrunePlan {
|
|
116
|
+
/** Entity keys whose managed file should be removed. */
|
|
117
|
+
keys: string[];
|
|
118
|
+
/** True when no prune runs for this type at all. */
|
|
119
|
+
skipped: boolean;
|
|
120
|
+
/** Why prune was skipped, for the operator-facing warning. */
|
|
121
|
+
skipReason?: "disabled" | "fetch-failed" | "listing-incomplete";
|
|
122
|
+
/**
|
|
123
|
+
* Managed keys whose derived filename is unsafe. Never removed — reported so
|
|
124
|
+
* a corrupt sync state is visible rather than silent.
|
|
125
|
+
*/
|
|
126
|
+
unsafeKeys: string[];
|
|
127
|
+
/**
|
|
128
|
+
* Managed keys absent from the server listing that this plan is NOT pruning
|
|
129
|
+
* (`--no-prune`, or a listing that may be truncated). Their files stay on
|
|
130
|
+
* disk, so the caller must keep their prior state entry — otherwise the key
|
|
131
|
+
* drops out of `entities[<slot>]` and the file silently stops being managed.
|
|
132
|
+
* Empty when presence could not be established at all.
|
|
133
|
+
*/
|
|
134
|
+
unprunedAbsentKeys: string[];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Decide which of a type's managed entity keys should have their local file
|
|
138
|
+
* removed, given the prior sync state and the outcome of this pull's fetch.
|
|
139
|
+
*
|
|
140
|
+
* A key is pruned iff it was **managed** (present in the prior
|
|
141
|
+
* `SyncState.entities[<slot>]`, so a previous pull wrote its file) and is
|
|
142
|
+
* **absent from the server keys** this pull fetched. A local file that was
|
|
143
|
+
* never in prior state was hand-authored — it is left alone and reported by
|
|
144
|
+
* `sync diff` as new.
|
|
145
|
+
*
|
|
146
|
+
* Pure and side-effect-free (the caller owns the `unlinkSync`) so the safety
|
|
147
|
+
* rules are unit-testable without a live server.
|
|
148
|
+
*/
|
|
149
|
+
export declare function planPrune(input: {
|
|
150
|
+
resourceType: SyncResourceType;
|
|
151
|
+
/** Keys from the prior `SyncState.entities[<slot>]`. */
|
|
152
|
+
priorKeys: string[];
|
|
153
|
+
/** Presence of this type's entities server-side, this pull. */
|
|
154
|
+
presence: PresenceOutcome;
|
|
155
|
+
/** False when the operator passed `--no-prune`. */
|
|
156
|
+
enabled: boolean;
|
|
157
|
+
}): PrunePlan;
|
|
158
|
+
/**
|
|
159
|
+
* Copy prior state entries for entities the server listed but this pull did not
|
|
160
|
+
* write (e.g. a script with no active config, or an email template whose detail
|
|
161
|
+
* fetch failed). Without this the entity would drop out of the state slot and
|
|
162
|
+
* look hand-authored to the next pull, so its stale file could never be pruned.
|
|
163
|
+
*/
|
|
164
|
+
export declare function preserveUnwrittenEntries<T>(written: Record<string, T>, prior: Record<string, T> | undefined, serverKeys: string[]): Record<string, T>;
|
|
165
|
+
/**
|
|
166
|
+
* Best-effort check for uncommitted git changes at `path` (a file or a
|
|
167
|
+
* directory). Returns false when git isn't available, the path isn't in a
|
|
168
|
+
* repository, or anything else goes wrong — the caller treats "unknown" as
|
|
169
|
+
* "no local edits", so this never blocks on a non-git checkout.
|
|
170
|
+
*
|
|
171
|
+
* `path` is passed as an argument, never interpolated into a shell string:
|
|
172
|
+
* on the prune path its basename derives from a server entity name, and entity
|
|
173
|
+
* names are free-form (a rule set may legitimately be named ``a`b`` or `a$b`).
|
|
174
|
+
* `execFileSync` runs git directly with no shell, so no name can be read as
|
|
175
|
+
* a command.
|
|
176
|
+
*
|
|
177
|
+
* `includeUntracked` decides whether an untracked file counts as a change:
|
|
178
|
+
* - `true` (default) suits "am I about to overwrite something?" — `sync revert`
|
|
179
|
+
* would clobber an untracked file just the same.
|
|
180
|
+
* - `false` suits "did the operator edit this file?" — an untracked file is the
|
|
181
|
+
* ordinary state of a pulled file in a sync dir that was never committed, and
|
|
182
|
+
* is not evidence of a local edit.
|
|
183
|
+
*/
|
|
184
|
+
export declare function hasUncommittedChanges(path: string, options?: {
|
|
185
|
+
includeUntracked?: boolean;
|
|
186
|
+
}): Promise<boolean>;
|
|
187
|
+
/**
|
|
188
|
+
* The phrase pull and diff both use for an entity that is no longer exported.
|
|
189
|
+
*
|
|
190
|
+
* The plan of record asked for "archived or deleted" on the assumption that
|
|
191
|
+
* archiving drops an entity from the export. It does not: the list endpoints
|
|
192
|
+
* filter by status only when `?status=` is passed and pull never passes it
|
|
193
|
+
* (`listAppPrompts`/`listAppIntegrations` in `src/admin-api.ts`; `fetchAll` in
|
|
194
|
+
* `cli/src/commands/sync.ts`). An archived entity stays in the export and its
|
|
195
|
+
* TOML is rewritten with `status = "archived"`, so it is never pruned. The only
|
|
196
|
+
* way to be absent from the export is to have been deleted.
|
|
197
|
+
*/
|
|
198
|
+
export declare const ABSENT_FROM_EXPORT = "absent from sync export (deleted on server)";
|
|
199
|
+
/** `sync diff` status for a local file whose managed entity is gone. */
|
|
200
|
+
export declare const LOCAL_ONLY_ABSENT = "local only (absent from export)";
|
|
201
|
+
/** `sync diff` status for a local file the operator authored themselves. */
|
|
202
|
+
export declare const LOCAL_ONLY_NEW = "local only";
|
|
203
|
+
/**
|
|
204
|
+
* Classify a local file that has no matching server entity (issue #1659).
|
|
205
|
+
*
|
|
206
|
+
* The two cases look identical on disk but mean opposite things. A key a prior
|
|
207
|
+
* pull managed means the entity was deleted server-side and this stale file
|
|
208
|
+
* will RE-create it on the next push. A key never pulled means the operator
|
|
209
|
+
* authored the file and push creating it is the intent.
|
|
210
|
+
*/
|
|
211
|
+
export declare function classifyLocalOnly(priorEntities: SyncState["entities"] | undefined, slot: SyncEntitySlot, key: string): typeof LOCAL_ONLY_NEW | typeof LOCAL_ONLY_ABSENT;
|
|
212
|
+
export interface PruneResult {
|
|
213
|
+
/** Entity keys whose file was removed — what the "Pruned" count reports. */
|
|
214
|
+
prunedKeys: string[];
|
|
215
|
+
/** Slot-relative paths removed (files and sidecar test directories). */
|
|
216
|
+
removed: string[];
|
|
217
|
+
/** Keys left in place because the file carries uncommitted local edits. */
|
|
218
|
+
keptWithLocalEdits: string[];
|
|
219
|
+
/** `entities.testCases` state keys the pruned blocks owned. */
|
|
220
|
+
removedTestCaseKeys: string[];
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Remove the local files for `keys` (as decided by `planPrune`), along with any
|
|
224
|
+
* sidecar `<key>.tests/` directory.
|
|
225
|
+
*
|
|
226
|
+
* A file with uncommitted git edits is kept and reported instead: the operator
|
|
227
|
+
* may be mid-way through authoring a change they meant to push. Everything
|
|
228
|
+
* removed here is recoverable from the pre-pull snapshot via `sync revert`.
|
|
229
|
+
*/
|
|
230
|
+
export declare function applyPrune(options: {
|
|
231
|
+
configDir: string;
|
|
232
|
+
resourceType: SyncResourceType;
|
|
233
|
+
keys: string[];
|
|
234
|
+
/** `entities.testCases` built by this pull; pruned blocks' records are dropped. */
|
|
235
|
+
testCaseEntities?: Record<string, {
|
|
236
|
+
blockType?: string;
|
|
237
|
+
blockKey?: string;
|
|
238
|
+
}>;
|
|
239
|
+
logger?: (msg: string) => void;
|
|
240
|
+
}): Promise<PruneResult>;
|
|
241
|
+
/** Address a prior-state entry for detail-fetch and delete. */
|
|
242
|
+
export type PruneAddressOf = (key: string, entry: any) => string | undefined;
|
|
243
|
+
/** Read `id` from an id-addressed slot's state entry. */
|
|
244
|
+
export declare const addressById: PruneAddressOf;
|
|
245
|
+
/** Key-addressed slots are addressed by the state key itself. */
|
|
246
|
+
export declare const addressByKey: PruneAddressOf;
|
|
247
|
+
/**
|
|
248
|
+
* Live modified timestamp used by the drift check. Most admin/app detail
|
|
249
|
+
* endpoints serialize `modifiedAt` at the top level (the same field `sync pull`
|
|
250
|
+
* records into state), with `updatedAt` as a defensive fallback. Two detail
|
|
251
|
+
* endpoints nest the entity under a wrapper key and need their own extractors
|
|
252
|
+
* below (`workflowPruneModifiedAt`, `emailTemplatePruneModifiedAt`) so the
|
|
253
|
+
* drift check reads the real timestamp instead of `undefined` — a top-level
|
|
254
|
+
* read there always looks like drift and blocks `--prune` without `--force`.
|
|
255
|
+
*/
|
|
256
|
+
export declare const pruneModifiedAt: (detail: any) => string | undefined;
|
|
257
|
+
/**
|
|
258
|
+
* Workflow detail-read extractor. `getWorkflow` (server `getAppWorkflow`,
|
|
259
|
+
* src/admin-api.ts) returns `{ workflow, draft, revisions, configs }` — the
|
|
260
|
+
* entity and its `modifiedAt` are nested under `workflow`, unlike every other
|
|
261
|
+
* detail endpoint. Read there, not the top level.
|
|
262
|
+
*/
|
|
263
|
+
export declare const workflowPruneModifiedAt: (detail: any) => string | undefined;
|
|
264
|
+
/**
|
|
265
|
+
* Email-template detail-read extractor. `getEmailTemplate` returns
|
|
266
|
+
* `{ emailType, label, hasOverride, override, default, variables }`; the
|
|
267
|
+
* editable copy `sync` manages — and its `modifiedAt` — live under `override`
|
|
268
|
+
* (null when there is no override). `sync pull` likewise records
|
|
269
|
+
* `template.override?.modifiedAt`, so the drift check must read the same path.
|
|
270
|
+
*/
|
|
271
|
+
export declare const emailTemplatePruneModifiedAt: (detail: any) => string | undefined;
|
|
272
|
+
/**
|
|
273
|
+
* How to confirm and delete one resource type during push-prune. Narrow by
|
|
274
|
+
* design (state slot + address + detail-fetch + drift field + delete) rather
|
|
275
|
+
* than widening `SyncResourceType`, which is pull/diff layout metadata.
|
|
276
|
+
*/
|
|
277
|
+
export interface PushPruneSpec {
|
|
278
|
+
/** The layout descriptor (dir/ext/fileFromKey/stateSlot/label/testBlockType). */
|
|
279
|
+
resourceType: SyncResourceType;
|
|
280
|
+
/**
|
|
281
|
+
* Derive the entity key a local managed file declares — the SAME derivation
|
|
282
|
+
* the type's `sync push` loop uses (`<in-file identity> || basename`). Prune
|
|
283
|
+
* collects the set of these across every file in the type's directory and
|
|
284
|
+
* treats a prior-state key as a candidate only when NO local file declares
|
|
285
|
+
* it. This must mirror push exactly: a file renamed but keeping its internal
|
|
286
|
+
* key is still updated by push, so it must NOT be seen as a delete (#1655).
|
|
287
|
+
*/
|
|
288
|
+
keyFromFile: (filePath: string) => string;
|
|
289
|
+
/** Address a prior-state entry for the point read and delete. */
|
|
290
|
+
addressOf: PruneAddressOf;
|
|
291
|
+
/** Point-read the live entity; rejects with `ApiError` status 404 when gone. */
|
|
292
|
+
fetchDetail: (client: ApiClient, appId: string, address: string) => Promise<any>;
|
|
293
|
+
/** Live `modifiedAt` for the drift check. */
|
|
294
|
+
modifiedAtOf: (detail: any) => string | undefined;
|
|
295
|
+
/**
|
|
296
|
+
* Delete the confirmed entity; rejects with `ConflictError` (409) when the
|
|
297
|
+
* entity is still referenced. `null` for a type whose CLI delete surface has
|
|
298
|
+
* not landed yet (metadata-category-configs, gated on #1426): a candidate of
|
|
299
|
+
* such a type is reported "no delete surface yet" rather than deleted.
|
|
300
|
+
*/
|
|
301
|
+
deleteEntity: ((client: ApiClient, appId: string, address: string) => Promise<void>) | null;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Every resource type push-prune can retire. Id-addressed types (integrations,
|
|
305
|
+
* webhooks, cron-triggers, blob-buckets, prompts, workflows, transforms,
|
|
306
|
+
* rule-sets) fetch/delete by the stored id; key-addressed types (database-types,
|
|
307
|
+
* group-type-configs, collection-type-configs, email-templates) by the key.
|
|
308
|
+
*
|
|
309
|
+
* `--force` (the CLI's existing "override baseline drift" flag) only relaxes the
|
|
310
|
+
* drift check — it deliberately does NOT pass a server-side force flag on the
|
|
311
|
+
* delete, so each type's existing 409 dangling-ref guard stays active and a
|
|
312
|
+
* still-referenced entity is reported "blocked", not force-deleted.
|
|
313
|
+
*/
|
|
314
|
+
export declare const PUSH_PRUNE_SPECS: PushPruneSpec[];
|
|
315
|
+
/**
|
|
316
|
+
* The set of entity keys the local managed files of a type declare — collected
|
|
317
|
+
* the way `sync push` derives keys: parse every file in the type's directory
|
|
318
|
+
* and read its declared identity (`<in-file key> || basename`), NOT by assuming
|
|
319
|
+
* the file lives at its canonical `<key>.toml` path.
|
|
320
|
+
*
|
|
321
|
+
* This is the crux of the #1655 destructive-delete fix. `sync push` accepts a
|
|
322
|
+
* managed file at a **noncanonical filename** (e.g. `prompts/custom.toml` with
|
|
323
|
+
* `prompt.key = "greeting"`) and still updates the `greeting` entity. Collecting
|
|
324
|
+
* declared keys — rather than checking whether `greeting.toml` exists — means a
|
|
325
|
+
* renamed-but-same-key file keeps its entity out of the prune set, so prune
|
|
326
|
+
* never deletes an entity push just updated.
|
|
327
|
+
*/
|
|
328
|
+
export declare function collectLocalDeclaredKeys(input: {
|
|
329
|
+
spec: PushPruneSpec;
|
|
330
|
+
configDir: string;
|
|
331
|
+
}): Set<string>;
|
|
332
|
+
/**
|
|
333
|
+
* A managed entity whose local declaration is gone — a candidate for
|
|
334
|
+
* server-side deletion. Pure and side-effect-free: computed from the prior sync
|
|
335
|
+
* state and the filesystem only (no server call), so it is immune to listing
|
|
336
|
+
* truncation.
|
|
337
|
+
*
|
|
338
|
+
* A key is a candidate iff it was in the prior state slot (a prior pull managed
|
|
339
|
+
* it) AND **no** local file in the type's directory declares that key (via
|
|
340
|
+
* {@link collectLocalDeclaredKeys}, mirroring how `sync push` derives keys). A
|
|
341
|
+
* key still declared by some file — even one renamed away from the canonical
|
|
342
|
+
* `<key>.toml` path — is left alone, since `sync push` would update it, not
|
|
343
|
+
* delete it (issue #1655). A file whose key was never in prior state was
|
|
344
|
+
* hand-authored and is left for `sync push` to create; it is never a candidate.
|
|
345
|
+
*/
|
|
346
|
+
export declare function collectPushPruneCandidates(input: {
|
|
347
|
+
spec: PushPruneSpec;
|
|
348
|
+
configDir: string;
|
|
349
|
+
priorEntities: Record<string, any> | undefined;
|
|
350
|
+
}): Array<{
|
|
351
|
+
key: string;
|
|
352
|
+
entry: any;
|
|
353
|
+
}>;
|
|
354
|
+
/**
|
|
355
|
+
* Outcome of the point read that confirms (or denies) a candidate's presence.
|
|
356
|
+
* A flat shape (rather than a discriminated union) because the CLI compiles with
|
|
357
|
+
* `strict: false`, where union narrowing on `ok` does not hold: `detail` is set
|
|
358
|
+
* only when `ok`, `status` only on a failed fetch (`status === 404` ⇒ gone).
|
|
359
|
+
*/
|
|
360
|
+
export interface PushPruneFetch {
|
|
361
|
+
ok: boolean;
|
|
362
|
+
detail?: any;
|
|
363
|
+
status?: number;
|
|
364
|
+
}
|
|
365
|
+
export type PushPruneSkipReason =
|
|
366
|
+
/** State entry has no usable id/key (corrupt or partial state). */
|
|
367
|
+
"no-id"
|
|
368
|
+
/** Type has no CLI delete surface yet (metadata-category-configs, #1426). */
|
|
369
|
+
| "unsupported"
|
|
370
|
+
/** Live `modifiedAt` differs from prior state — edited out-of-band. */
|
|
371
|
+
| "drift"
|
|
372
|
+
/** A non-404 fetch error — presence could not be confirmed. */
|
|
373
|
+
| "unconfirmed";
|
|
374
|
+
export type PushPruneDecision =
|
|
375
|
+
/** Confirmed present and unchanged (or `--force`): delete it. */
|
|
376
|
+
{
|
|
377
|
+
action: "delete";
|
|
378
|
+
address: string;
|
|
379
|
+
serverModifiedAt?: string;
|
|
380
|
+
}
|
|
381
|
+
/** 404: already gone server-side. Drop its stale state, do not delete. */
|
|
382
|
+
| {
|
|
383
|
+
action: "drop-state";
|
|
384
|
+
}
|
|
385
|
+
/** Leave the entity and its prior-state slot intact. */
|
|
386
|
+
| {
|
|
387
|
+
action: "skip";
|
|
388
|
+
reason: PushPruneSkipReason;
|
|
389
|
+
serverModifiedAt?: string;
|
|
390
|
+
};
|
|
391
|
+
/**
|
|
392
|
+
* Decide what to do with one prune candidate, given the point read's outcome.
|
|
393
|
+
* Pure so the safety rules are unit-testable without a live server.
|
|
394
|
+
*
|
|
395
|
+
* Fail-closed throughout: a candidate is deleted ONLY on a successful read whose
|
|
396
|
+
* live `modifiedAt` matches prior state (or under `--force`). A 404 means the
|
|
397
|
+
* work is already done (drop the stale state). Any other read failure, a missing
|
|
398
|
+
* address, or a type without a delete surface leaves everything untouched.
|
|
399
|
+
*/
|
|
400
|
+
export declare function decidePushPruneCandidate(input: {
|
|
401
|
+
spec: PushPruneSpec;
|
|
402
|
+
address: string | undefined;
|
|
403
|
+
priorModifiedAt: string | undefined;
|
|
404
|
+
fetch: PushPruneFetch;
|
|
405
|
+
force: boolean;
|
|
406
|
+
}): PushPruneDecision;
|
|
407
|
+
/**
|
|
408
|
+
* Remove a pruned block's sidecar `<key>.tests/` directory and its
|
|
409
|
+
* `entities.testCases` state records. The main file is already gone (that is
|
|
410
|
+
* what made this a prune candidate), so `applyPrune` above — which bails when
|
|
411
|
+
* the main file is absent — does not clean the sidecar; this does.
|
|
412
|
+
*/
|
|
413
|
+
export declare function removePrunedSidecar(options: {
|
|
414
|
+
configDir: string;
|
|
415
|
+
resourceType: SyncResourceType;
|
|
416
|
+
key: string;
|
|
417
|
+
testCaseEntities?: Record<string, {
|
|
418
|
+
blockType?: string;
|
|
419
|
+
blockKey?: string;
|
|
420
|
+
}>;
|
|
421
|
+
logger?: (msg: string) => void;
|
|
422
|
+
}): {
|
|
423
|
+
removed: string[];
|
|
424
|
+
removedTestCaseKeys: string[];
|
|
425
|
+
};
|
|
426
|
+
/** `sync diff` status for a managed remote entity whose local file is gone. */
|
|
427
|
+
export declare const REMOTE_ONLY_WILL_DELETE = "remote only (will delete with push --prune)";
|
|
428
|
+
/** `sync diff` status for a server entity that was never synced (hand-created). */
|
|
429
|
+
export declare const REMOTE_ONLY_UNMANAGED = "remote only (left alone)";
|
|
430
|
+
/**
|
|
431
|
+
* Classify a "remote only" entity (present server-side, no local file) for
|
|
432
|
+
* `sync diff` (issue #1655). A key the prior pull managed means the operator
|
|
433
|
+
* deleted its local file and `push --prune` will delete the remote entity; a key
|
|
434
|
+
* never synced was authored on the server and is left alone. Prior sync state is
|
|
435
|
+
* the discriminator, exactly as it is for the local-only / pull-prune split.
|
|
436
|
+
*/
|
|
437
|
+
export declare function classifyRemoteOnly(priorEntities: SyncState["entities"] | undefined, slot: SyncEntitySlot, key: string): typeof REMOTE_ONLY_WILL_DELETE | typeof REMOTE_ONLY_UNMANAGED;
|