primitive-admin 1.0.52 → 1.0.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/README.md +38 -10
  2. package/dist/bin/primitive.js +6 -0
  3. package/dist/bin/primitive.js.map +1 -1
  4. package/dist/src/commands/auth.js +16 -6
  5. package/dist/src/commands/auth.js.map +1 -1
  6. package/dist/src/commands/blob-buckets.js +84 -7
  7. package/dist/src/commands/blob-buckets.js.map +1 -1
  8. package/dist/src/commands/catalog.js +3 -3
  9. package/dist/src/commands/catalog.js.map +1 -1
  10. package/dist/src/commands/collections.js +12 -9
  11. package/dist/src/commands/collections.js.map +1 -1
  12. package/dist/src/commands/database-types.js +11 -1
  13. package/dist/src/commands/database-types.js.map +1 -1
  14. package/dist/src/commands/databases.js +197 -74
  15. package/dist/src/commands/databases.js.map +1 -1
  16. package/dist/src/commands/group-type-configs.js +1 -9
  17. package/dist/src/commands/group-type-configs.js.map +1 -1
  18. package/dist/src/commands/groups.js +12 -6
  19. package/dist/src/commands/groups.js.map +1 -1
  20. package/dist/src/commands/guides.d.ts +161 -0
  21. package/dist/src/commands/guides.js +502 -84
  22. package/dist/src/commands/guides.js.map +1 -1
  23. package/dist/src/commands/init.js +77 -45
  24. package/dist/src/commands/init.js.map +1 -1
  25. package/dist/src/commands/integrations.js +2 -2
  26. package/dist/src/commands/integrations.js.map +1 -1
  27. package/dist/src/commands/metadata.d.ts +2 -0
  28. package/dist/src/commands/metadata.js +344 -0
  29. package/dist/src/commands/metadata.js.map +1 -0
  30. package/dist/src/commands/prompts.js +2 -2
  31. package/dist/src/commands/prompts.js.map +1 -1
  32. package/dist/src/commands/rule-sets.d.ts +1 -0
  33. package/dist/src/commands/rule-sets.js +25 -3
  34. package/dist/src/commands/rule-sets.js.map +1 -1
  35. package/dist/src/commands/scripts.d.ts +2 -0
  36. package/dist/src/commands/scripts.js +667 -0
  37. package/dist/src/commands/scripts.js.map +1 -0
  38. package/dist/src/commands/sync.d.ts +212 -16
  39. package/dist/src/commands/sync.js +1688 -287
  40. package/dist/src/commands/sync.js.map +1 -1
  41. package/dist/src/commands/vars.d.ts +8 -0
  42. package/dist/src/commands/vars.js +110 -0
  43. package/dist/src/commands/vars.js.map +1 -0
  44. package/dist/src/commands/webhooks.js +17 -3
  45. package/dist/src/commands/webhooks.js.map +1 -1
  46. package/dist/src/commands/workflows.d.ts +30 -0
  47. package/dist/src/commands/workflows.js +651 -52
  48. package/dist/src/commands/workflows.js.map +1 -1
  49. package/dist/src/lib/api-client.d.ts +123 -19
  50. package/dist/src/lib/api-client.js +128 -4
  51. package/dist/src/lib/api-client.js.map +1 -1
  52. package/dist/src/lib/batch.d.ts +26 -0
  53. package/dist/src/lib/batch.js +32 -0
  54. package/dist/src/lib/batch.js.map +1 -0
  55. package/dist/src/lib/block-layout.d.ts +160 -0
  56. package/dist/src/lib/block-layout.js +451 -0
  57. package/dist/src/lib/block-layout.js.map +1 -0
  58. package/dist/src/lib/codegen-shared/generatedFiles.d.ts +61 -0
  59. package/dist/src/lib/codegen-shared/generatedFiles.js +127 -0
  60. package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -0
  61. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.d.ts +68 -0
  62. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +168 -0
  63. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js.map +1 -0
  64. package/dist/src/lib/config-toml.d.ts +10 -0
  65. package/dist/src/lib/config-toml.js +42 -0
  66. package/dist/src/lib/config-toml.js.map +1 -0
  67. package/dist/src/lib/config.d.ts +16 -0
  68. package/dist/src/lib/config.js +41 -0
  69. package/dist/src/lib/config.js.map +1 -1
  70. package/dist/src/lib/constants.d.ts +9 -0
  71. package/dist/src/lib/constants.js +9 -0
  72. package/dist/src/lib/constants.js.map +1 -1
  73. package/dist/src/lib/csv.d.ts +1 -2
  74. package/dist/src/lib/csv.js +3 -8
  75. package/dist/src/lib/csv.js.map +1 -1
  76. package/dist/src/lib/db-codegen/dbGenerator.d.ts +35 -7
  77. package/dist/src/lib/db-codegen/dbGenerator.js +384 -125
  78. package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -1
  79. package/dist/src/lib/db-codegen/dbNaming.d.ts +29 -0
  80. package/dist/src/lib/db-codegen/dbNaming.js +58 -0
  81. package/dist/src/lib/db-codegen/dbNaming.js.map +1 -1
  82. package/dist/src/lib/db-codegen/dbTemplates.d.ts +114 -5
  83. package/dist/src/lib/db-codegen/dbTemplates.js +163 -16
  84. package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -1
  85. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +7 -3
  86. package/dist/src/lib/db-codegen/dbTsTypes.js +23 -1
  87. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  88. package/dist/src/lib/generated-allowlist.js +52 -0
  89. package/dist/src/lib/generated-allowlist.js.map +1 -1
  90. package/dist/src/lib/init-config.d.ts +13 -0
  91. package/dist/src/lib/init-config.js +21 -2
  92. package/dist/src/lib/init-config.js.map +1 -1
  93. package/dist/src/lib/output.d.ts +42 -5
  94. package/dist/src/lib/output.js +70 -4
  95. package/dist/src/lib/output.js.map +1 -1
  96. package/dist/src/lib/query-operators.d.ts +43 -0
  97. package/dist/src/lib/query-operators.js +80 -0
  98. package/dist/src/lib/query-operators.js.map +1 -0
  99. package/dist/src/lib/template.d.ts +9 -5
  100. package/dist/src/lib/template.js +58 -45
  101. package/dist/src/lib/template.js.map +1 -1
  102. package/dist/src/lib/toml-database-config.d.ts +10 -19
  103. package/dist/src/lib/toml-database-config.js +28 -59
  104. package/dist/src/lib/toml-database-config.js.map +1 -1
  105. package/dist/src/lib/toml-metadata-config.d.ts +147 -0
  106. package/dist/src/lib/toml-metadata-config.js +463 -0
  107. package/dist/src/lib/toml-metadata-config.js.map +1 -0
  108. package/dist/src/lib/toml-native-form.d.ts +46 -0
  109. package/dist/src/lib/toml-native-form.js +78 -0
  110. package/dist/src/lib/toml-native-form.js.map +1 -0
  111. package/dist/src/lib/toml-params-validator.d.ts +34 -0
  112. package/dist/src/lib/toml-params-validator.js +118 -3
  113. package/dist/src/lib/toml-params-validator.js.map +1 -1
  114. package/dist/src/lib/workflow-apply.d.ts +86 -0
  115. package/dist/src/lib/workflow-apply.js +127 -0
  116. package/dist/src/lib/workflow-apply.js.map +1 -0
  117. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.d.ts +129 -0
  118. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js +269 -0
  119. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js.map +1 -0
  120. package/dist/src/lib/workflow-codegen/generator.d.ts +74 -0
  121. package/dist/src/lib/workflow-codegen/generator.js +215 -0
  122. package/dist/src/lib/workflow-codegen/generator.js.map +1 -0
  123. package/dist/src/lib/workflow-codegen/naming.d.ts +33 -0
  124. package/dist/src/lib/workflow-codegen/naming.js +81 -0
  125. package/dist/src/lib/workflow-codegen/naming.js.map +1 -0
  126. package/dist/src/lib/workflow-codegen/schemaToTs.d.ts +64 -0
  127. package/dist/src/lib/workflow-codegen/schemaToTs.js +282 -0
  128. package/dist/src/lib/workflow-codegen/schemaToTs.js.map +1 -0
  129. package/dist/src/lib/workflow-fragments.js +3 -3
  130. package/dist/src/lib/workflow-fragments.js.map +1 -1
  131. package/dist/src/lib/workflow-payload.d.ts +68 -0
  132. package/dist/src/lib/workflow-payload.js +150 -0
  133. package/dist/src/lib/workflow-payload.js.map +1 -0
  134. package/dist/src/lib/workflow-toml-validator.d.ts +1 -1
  135. package/dist/src/lib/workflow-toml-validator.js +37 -1
  136. package/dist/src/lib/workflow-toml-validator.js.map +1 -1
  137. package/dist/src/types/index.d.ts +11 -0
  138. package/dist/src/validators.d.ts +4 -3
  139. package/dist/src/validators.js +6 -5
  140. package/dist/src/validators.js.map +1 -1
  141. package/package.json +5 -3
@@ -0,0 +1,463 @@
1
+ /**
2
+ * CLI TOML parser / validator / serializer for resource-metadata config
3
+ * surfaces (issue #1304, P-B — CLI/TOML config-sync).
4
+ *
5
+ * Two surfaces, mirroring the "config change ships all three surfaces" rule
6
+ * (CLAUDE.md; same shape as the database type-config helpers in
7
+ * `toml-database-config.ts`):
8
+ *
9
+ * 1. `MetadataCategoryConfig` blocks — a per-`{resourceType, category}`
10
+ * typed-schema + read/write-rule definition. These round-trip through
11
+ * `primitive sync push` / `pull` against the P-A REST API
12
+ * (`metadata-categories` CRUD). One file = one category, using a single
13
+ * `[metadataCategoryConfig]` section so the nested `schema.fields.*`
14
+ * tables serialize cleanly and byte-stably.
15
+ *
16
+ * 2. The declared-access manifest (`[metadata]` + `secrets` blocks) that
17
+ * lives on the owning config surfaces (`CollectionTypeConfig` /
18
+ * `DatabaseTypeConfig` / `WorkflowDefinition`). This module provides the
19
+ * TOML *structure* + *validator* + byte-stable round-trip helpers for the
20
+ * manifest so a bad value is rejected with a clear error. Wiring the
21
+ * manifest onto those config models' sync push/pull (which needs a
22
+ * storage field on each model) is P-C's "persist the manifest on owning
23
+ * configs" work — this module ships the parse/validate/serialize the
24
+ * P-C eval-site folding will call, matching how earlier phases shipped a
25
+ * validated mechanism ahead of its live wiring.
26
+ *
27
+ * All functions here are pure and unit-testable (no network, no filesystem).
28
+ * `validate*` functions return an error string (or `null` when valid) rather
29
+ * than throwing, mirroring `validateCategorySchema` server-side.
30
+ */
31
+ import { stringifyConfigToml } from "./config-toml.js";
32
+ /** Identifier-safe name: letters, digits, underscore; not starting with a digit.
33
+ * Matches the server's `METADATA_KEY_PATTERN`. */
34
+ const IDENTIFIER_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
35
+ /** The key format the `secrets` / `vars` services accept when a value is created
36
+ * (server's `SCALAR_KEY_RE`, secrets/vars service `KEY_REGEX`). A declared
37
+ * scalar-root key that is identifier-safe but does not match this (e.g.
38
+ * lowercase) can never be created via the API, so reject it at manifest-parse
39
+ * time on both ends (issue #1364). */
40
+ const SCALAR_KEY_PATTERN = /^[A-Z][A-Z0-9_]{0,63}$/;
41
+ /** The reserved projected category (computed live from a resource's columns).
42
+ * Matches the server's `RESERVED_PROJECTED_CATEGORY`. */
43
+ export const RESERVED_CATEGORY = "attrs";
44
+ /** The subset of js-bao `FieldOptions` field types the metadata schema accepts.
45
+ * Matches the server's `MetadataFieldType`. */
46
+ const METADATA_FIELD_TYPES = new Set([
47
+ "string",
48
+ "number",
49
+ "boolean",
50
+ "date",
51
+ "id",
52
+ "stringset",
53
+ ]);
54
+ const CATEGORY_SECTION_KEYS = new Set([
55
+ "resourceType",
56
+ "category",
57
+ "schema",
58
+ "readRule",
59
+ "writeRule",
60
+ "description",
61
+ ]);
62
+ /**
63
+ * Normalize a parsed `[metadataCategoryConfig]` TOML section into the REST
64
+ * upsert body. Server-managed fields (`schemaVersion`, `generation`) are never
65
+ * emitted or read here — they'd churn a round-trip.
66
+ */
67
+ export function parseMetadataCategoryToml(tomlData) {
68
+ const section = (tomlData && tomlData.metadataCategoryConfig) || {};
69
+ return {
70
+ resourceType: section.resourceType,
71
+ category: section.category,
72
+ schema: section.schema,
73
+ readRule: section.readRule ?? null,
74
+ writeRule: section.writeRule ?? null,
75
+ description: section.description ?? null,
76
+ // #1420 Phase 2: the manifest lives in the top-level `[metadata]`/`secrets`
77
+ // block (sibling to `[metadataCategoryConfig]`), reusing the shared parser.
78
+ metadataManifest: parseDeclaredAccessManifestToml(tomlData),
79
+ };
80
+ }
81
+ /**
82
+ * Validate a parsed category config (post-{@link parseMetadataCategoryToml}).
83
+ * Returns an error string, or `null` when valid. The server re-validates on
84
+ * write; this is the fast local check so `sync push` fails with a clear
85
+ * message before hitting the network.
86
+ */
87
+ export function validateMetadataCategoryConfig(input) {
88
+ if (!input.resourceType || typeof input.resourceType !== "string") {
89
+ return "metadataCategoryConfig.resourceType is required and must be a string";
90
+ }
91
+ if (!IDENTIFIER_PATTERN.test(input.resourceType)) {
92
+ return `metadataCategoryConfig.resourceType "${input.resourceType}" must be identifier-safe (letters, digits, underscore; not starting with a digit)`;
93
+ }
94
+ if (!input.category || typeof input.category !== "string") {
95
+ return "metadataCategoryConfig.category is required and must be a string";
96
+ }
97
+ if (!IDENTIFIER_PATTERN.test(input.category)) {
98
+ return `metadataCategoryConfig.category "${input.category}" must be identifier-safe (letters, digits, underscore; not starting with a digit)`;
99
+ }
100
+ if (input.category === RESERVED_CATEGORY) {
101
+ return `metadataCategoryConfig.category "${RESERVED_CATEGORY}" is reserved (a projected category computed from the resource's own columns) and cannot be defined`;
102
+ }
103
+ if (input.readRule !== null &&
104
+ input.readRule !== undefined &&
105
+ typeof input.readRule !== "string") {
106
+ return "metadataCategoryConfig.readRule must be a string (a CEL expression)";
107
+ }
108
+ if (input.writeRule !== null &&
109
+ input.writeRule !== undefined &&
110
+ typeof input.writeRule !== "string") {
111
+ return "metadataCategoryConfig.writeRule must be a string (a CEL expression)";
112
+ }
113
+ if (input.description !== null &&
114
+ input.description !== undefined &&
115
+ typeof input.description !== "string") {
116
+ return "metadataCategoryConfig.description must be a string";
117
+ }
118
+ const schemaError = validateCategorySchema(input.schema);
119
+ if (schemaError)
120
+ return schemaError;
121
+ // #1420 Phase 2: local surface-level check on the declared-access manifest;
122
+ // the server re-validates the deep path graph at persist time.
123
+ return validateDeclaredAccessManifest(input.metadataManifest);
124
+ }
125
+ /**
126
+ * Validate the `schema` block is a well-formed js-bao `FieldOptions` map:
127
+ * `{ fields: { <name>: { type, required?, maxLength?, maxCount?, enum? } } }`.
128
+ * Mirrors the server's `validateCategorySchema`.
129
+ */
130
+ export function validateCategorySchema(schema) {
131
+ if (schema === null || typeof schema !== "object" || Array.isArray(schema)) {
132
+ return "metadataCategoryConfig.schema must be a table with a 'fields' map";
133
+ }
134
+ const fields = schema.fields;
135
+ if (fields === null || typeof fields !== "object" || Array.isArray(fields)) {
136
+ return "metadataCategoryConfig.schema.fields must be a table";
137
+ }
138
+ // Reject unknown top-level keys under `schema` (only `fields` is meaningful).
139
+ for (const key of Object.keys(schema)) {
140
+ if (key !== "fields") {
141
+ return `metadataCategoryConfig.schema has an unknown key "${key}" (only "fields" is allowed)`;
142
+ }
143
+ }
144
+ for (const [name, def] of Object.entries(fields)) {
145
+ if (!IDENTIFIER_PATTERN.test(name)) {
146
+ return `schema field name "${name}" must be identifier-safe`;
147
+ }
148
+ if (def === null || typeof def !== "object" || Array.isArray(def)) {
149
+ return `schema field "${name}" must be a table with a "type"`;
150
+ }
151
+ const field = def;
152
+ if (typeof field.type !== "string" || !METADATA_FIELD_TYPES.has(field.type)) {
153
+ return `schema field "${name}" has an invalid type (allowed: ${[
154
+ ...METADATA_FIELD_TYPES,
155
+ ].join(", ")})`;
156
+ }
157
+ if (field.enum !== undefined) {
158
+ if (!Array.isArray(field.enum) ||
159
+ field.enum.some((v) => typeof v !== "string")) {
160
+ return `schema field "${name}" enum must be an array of strings`;
161
+ }
162
+ if (field.type !== "string") {
163
+ return `schema field "${name}" enum is only valid on a "string" field`;
164
+ }
165
+ }
166
+ if (field.maxLength !== undefined && typeof field.maxLength !== "number") {
167
+ return `schema field "${name}" maxLength must be a number`;
168
+ }
169
+ if (field.maxCount !== undefined && typeof field.maxCount !== "number") {
170
+ return `schema field "${name}" maxCount must be a number`;
171
+ }
172
+ if (field.required !== undefined && typeof field.required !== "boolean") {
173
+ return `schema field "${name}" required must be a boolean`;
174
+ }
175
+ }
176
+ return null;
177
+ }
178
+ /**
179
+ * Serialize a category config (as returned by the P-A REST API — `schema` is a
180
+ * parsed object) to byte-stable TOML. Only the authored fields are emitted;
181
+ * server-managed `schemaVersion` / `generation` / `appId` / `categoryKey` are
182
+ * dropped so a pull → push → pull cycle is a no-op.
183
+ *
184
+ * Scalars are inserted before `schema` so `smol-toml` emits them ahead of
185
+ * the nested `[metadataCategoryConfig.schema.fields.*]` tables.
186
+ */
187
+ export function serializeMetadataCategoryConfig(config) {
188
+ const section = {
189
+ resourceType: config.resourceType,
190
+ category: config.category,
191
+ };
192
+ if (config.readRule !== null && config.readRule !== undefined) {
193
+ section.readRule = config.readRule;
194
+ }
195
+ if (config.writeRule !== null && config.writeRule !== undefined) {
196
+ section.writeRule = config.writeRule;
197
+ }
198
+ if (config.description !== null &&
199
+ config.description !== undefined &&
200
+ config.description !== "") {
201
+ section.description = config.description;
202
+ }
203
+ // `schema` may arrive as a parsed object (REST) or a JSON string (defensive).
204
+ let schema = config.schema;
205
+ if (typeof schema === "string") {
206
+ try {
207
+ schema = JSON.parse(schema);
208
+ }
209
+ catch {
210
+ schema = { fields: {} };
211
+ }
212
+ }
213
+ section.schema = schema ?? { fields: {} };
214
+ // #1420 Phase 2: emit the declared-access manifest as a top-level
215
+ // `[metadata]`/`secrets` block (sibling to `[metadataCategoryConfig]`),
216
+ // reusing the shared serializer so it round-trips byte-stable.
217
+ return stringifyConfigToml({
218
+ metadataCategoryConfig: section,
219
+ ...serializeDeclaredAccessManifest(config.metadataManifest),
220
+ });
221
+ }
222
+ // --- Declared-access manifest (`[metadata]` + `secrets` + `vars`) ----------
223
+ //
224
+ // The manifest that lives on an owning config surface. Shape mirrors the
225
+ // server's `MetadataDeclaration` (`src/app-api/helpers/metadata-cel-access.ts`):
226
+ // metadata.self.categories = ["profile"]
227
+ // [metadata.paths.<name>] from|rootFrom, via, type, categories
228
+ // secrets = ["STRIPE_KEY"]
229
+ // vars = ["ADMIN_GROUP_ID"] # non-secret twin of secrets (issue #1364)
230
+ /** Root contexts a `rootFrom` path may start at (caller-supplied subjectless
231
+ * contexts). Mirrors the server's `ROOT_CONTEXT_PREFIXES`
232
+ * (`src/app-api/helpers/metadata-cel-access.ts`). */
233
+ const ROOT_CONTEXT_PREFIXES = ["input", "record", "params"];
234
+ /** The one **server-authenticated** `rootFrom` root — the calling user's id
235
+ * (issue #1362). Unlike the {@link ROOT_CONTEXT_PREFIXES} roots (caller-supplied),
236
+ * `user.userId` binds the authenticated principal, so a rule may read the
237
+ * caller's own metadata (`md.<name>`). Mirrors the server's `CALLER_ROOTFROM`. */
238
+ export const CALLER_ROOTFROM = "user.userId";
239
+ /** The target `type` a {@link CALLER_ROOTFROM} path must declare. `user.userId`
240
+ * names a user, so the path must resolve `user`-typed metadata; a mismatched
241
+ * type would silently query `app#<type>#<userId>` for a resource that isn't the
242
+ * user. Mirrors the server's `CALLER_ROOTFROM_TYPE`. */
243
+ export const CALLER_ROOTFROM_TYPE = "user";
244
+ /**
245
+ * Validate a path's `rootFrom` value together with its declared target `type`
246
+ * (issue #1362), mirroring the server's `validateRootFromPath`
247
+ * (`src/app-api/helpers/metadata-cel-access.ts`). A `rootFrom` is sound when it
248
+ * is either:
249
+ *
250
+ * - a static dotted **caller-supplied** context path rooted at one of
251
+ * {@link ROOT_CONTEXT_PREFIXES} (`input.*`/`record.*`/`params.*`), with at
252
+ * least two segments; or
253
+ * - exactly {@link CALLER_ROOTFROM} (`user.userId`) — the one
254
+ * **server-authenticated** root — in which case the path must also declare
255
+ * `type = "user"` ({@link CALLER_ROOTFROM_TYPE}).
256
+ *
257
+ * Any other `user.*` path is rejected outright — the caller root is a single
258
+ * special case, not a blanket `user.*` namespace (Fork 1 = A). This is the fast
259
+ * local check so `sync push` fails with a clear message before the network call;
260
+ * the server's `validateRootFromPath` re-validates at persist time. Returns a
261
+ * human-readable reason (worded to follow `metadata.paths."<name>" `), or null
262
+ * when sound.
263
+ */
264
+ export function validateRootFromPath(root, type) {
265
+ if (root === CALLER_ROOTFROM) {
266
+ if (type !== CALLER_ROOTFROM_TYPE) {
267
+ return `rootFrom "${CALLER_ROOTFROM}" requires type = "${CALLER_ROOTFROM_TYPE}" (got ${type ? `"${type}"` : "no type"})`;
268
+ }
269
+ return null;
270
+ }
271
+ const prefix = root.split(".")[0];
272
+ if (prefix === "user") {
273
+ return `rootFrom "${root}" is not allowed — the only server-authenticated root is "${CALLER_ROOTFROM}"`;
274
+ }
275
+ const segments = root.split(".");
276
+ const isStaticDotted = segments.length >= 1 && segments.every((s) => IDENTIFIER_PATTERN.test(s));
277
+ if (!isStaticDotted ||
278
+ segments.length < 2 ||
279
+ !ROOT_CONTEXT_PREFIXES.includes(prefix)) {
280
+ return `rootFrom "${root}" must be a static dotted context path rooted at ${ROOT_CONTEXT_PREFIXES.join("/")} or "${CALLER_ROOTFROM}"`;
281
+ }
282
+ return null;
283
+ }
284
+ const MANIFEST_KEYS = new Set(["self", "paths", "secrets", "vars"]);
285
+ const SELF_KEYS = new Set(["categories"]);
286
+ const PATH_KEYS = new Set(["from", "rootFrom", "via", "type", "categories"]);
287
+ /** The declared scalar roots: `secrets` (masked) and `vars` (non-secret). */
288
+ const SCALAR_ROOT_KEYS = [
289
+ { key: "secrets", singular: "secret" },
290
+ { key: "vars", singular: "var" },
291
+ ];
292
+ /**
293
+ * Read the declared-access manifest out of a parsed config TOML: the top-level
294
+ * `[metadata]` table (self + paths) and the `secrets` / `vars` arrays. Returns
295
+ * `null` when none is present (the config declares no metadata/scalar access).
296
+ */
297
+ export function parseDeclaredAccessManifestToml(tomlData) {
298
+ const metadata = tomlData?.metadata;
299
+ const secrets = tomlData?.secrets;
300
+ const vars = tomlData?.vars;
301
+ if (metadata === undefined && secrets === undefined && vars === undefined) {
302
+ return null;
303
+ }
304
+ const manifest = {};
305
+ if (metadata && typeof metadata === "object") {
306
+ if (metadata.self !== undefined) {
307
+ manifest.self = { categories: metadata.self?.categories };
308
+ }
309
+ if (metadata.paths !== undefined) {
310
+ manifest.paths = metadata.paths;
311
+ }
312
+ }
313
+ if (secrets !== undefined) {
314
+ manifest.secrets = secrets;
315
+ }
316
+ if (vars !== undefined) {
317
+ manifest.vars = vars;
318
+ }
319
+ return manifest;
320
+ }
321
+ /**
322
+ * Validate a declared-access manifest structurally. Returns an error string,
323
+ * or `null` when valid. This is the local surface-level check (identifier
324
+ * names, key shape, exactly-one-root per path); the server's
325
+ * `validatePathGraph` still does the deep graph validation (cycles, depth,
326
+ * schema-mismatch) at persist time.
327
+ */
328
+ export function validateDeclaredAccessManifest(manifest) {
329
+ if (manifest === null || manifest === undefined)
330
+ return null;
331
+ if (typeof manifest !== "object" || Array.isArray(manifest)) {
332
+ return "declared-access manifest must be a table";
333
+ }
334
+ // `self`
335
+ if (manifest.self !== undefined) {
336
+ const self = manifest.self;
337
+ if (self === null || typeof self !== "object" || Array.isArray(self)) {
338
+ return "metadata.self must be a table with a 'categories' array";
339
+ }
340
+ for (const key of Object.keys(self)) {
341
+ if (!SELF_KEYS.has(key)) {
342
+ return `metadata.self has an unknown key "${key}" (only "categories" is allowed)`;
343
+ }
344
+ }
345
+ const catError = validateCategoryList(self.categories, "metadata.self");
346
+ if (catError)
347
+ return catError;
348
+ }
349
+ // `paths`
350
+ if (manifest.paths !== undefined) {
351
+ const paths = manifest.paths;
352
+ if (paths === null || typeof paths !== "object" || Array.isArray(paths)) {
353
+ return "metadata.paths must be a table of named path declarations";
354
+ }
355
+ const declaredNodes = new Set(["self", ...Object.keys(paths)]);
356
+ for (const [name, raw] of Object.entries(paths)) {
357
+ if (!IDENTIFIER_PATTERN.test(name)) {
358
+ return `metadata.paths."${name}" name must be identifier-safe`;
359
+ }
360
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
361
+ return `metadata.paths."${name}" must be a table`;
362
+ }
363
+ const p = raw;
364
+ for (const key of Object.keys(p)) {
365
+ if (!PATH_KEYS.has(key)) {
366
+ return `metadata.paths."${name}" has an unknown key "${key}" (allowed: ${[
367
+ ...PATH_KEYS,
368
+ ].join(", ")})`;
369
+ }
370
+ }
371
+ const hasFrom = typeof p.from === "string" && p.from !== "";
372
+ const hasRoot = typeof p.rootFrom === "string" && p.rootFrom !== "";
373
+ if (hasFrom === hasRoot) {
374
+ return `metadata.paths."${name}" must declare exactly one of "from" or "rootFrom"`;
375
+ }
376
+ if (hasFrom) {
377
+ if (!declaredNodes.has(p.from)) {
378
+ return `metadata.paths."${name}" from "${p.from}" references an undeclared node (must be "self" or another declared path)`;
379
+ }
380
+ if (typeof p.via !== "string" || !p.via.includes(".")) {
381
+ return `metadata.paths."${name}" must declare a "via" of the form "<category>.<key>"`;
382
+ }
383
+ }
384
+ else {
385
+ // rootFrom: a caller-supplied static context path
386
+ // (`input.*`/`record.*`/`params.*`) OR the server-authenticated
387
+ // `user.userId` root (which requires `type = "user"`). Mirrors the
388
+ // server's `validateRootFromPath` (issue #1362).
389
+ const rootFrom = p.rootFrom;
390
+ const type = typeof p.type === "string" ? p.type : undefined;
391
+ const rootReason = validateRootFromPath(rootFrom, type);
392
+ if (rootReason) {
393
+ return `metadata.paths."${name}" ${rootReason}`;
394
+ }
395
+ if (p.via !== undefined) {
396
+ return `metadata.paths."${name}" roots at "${rootFrom}" and must not also declare "via"`;
397
+ }
398
+ }
399
+ if (typeof p.type !== "string" || p.type === "") {
400
+ return `metadata.paths."${name}" must declare a target "type" (the resource type)`;
401
+ }
402
+ const catError = validateCategoryList(p.categories, `metadata.paths."${name}"`);
403
+ if (catError)
404
+ return catError;
405
+ }
406
+ }
407
+ // `secrets` / `vars` — the declared scalar roots share one key-list shape.
408
+ for (const { key: rootKey, singular } of SCALAR_ROOT_KEYS) {
409
+ const keys = manifest[rootKey];
410
+ if (keys === undefined)
411
+ continue;
412
+ if (!Array.isArray(keys) || keys.some((s) => typeof s !== "string")) {
413
+ return `${rootKey} must be an array of ${singular} key names (strings)`;
414
+ }
415
+ for (const key of keys) {
416
+ if (!SCALAR_KEY_PATTERN.test(key)) {
417
+ return `${rootKey} key "${key}" must match ^[A-Z][A-Z0-9_]{0,63}$ (uppercase letters, digits, underscores; must start with a letter; max 64 chars)`;
418
+ }
419
+ }
420
+ }
421
+ return null;
422
+ }
423
+ function validateCategoryList(categories, where) {
424
+ if (!Array.isArray(categories) ||
425
+ categories.some((c) => typeof c !== "string")) {
426
+ return `${where}.categories must be an array of category names (strings)`;
427
+ }
428
+ for (const cat of categories) {
429
+ if (cat !== RESERVED_CATEGORY && !IDENTIFIER_PATTERN.test(cat)) {
430
+ return `${where}.categories entry "${cat}" must be identifier-safe`;
431
+ }
432
+ }
433
+ return null;
434
+ }
435
+ /**
436
+ * Serialize a declared-access manifest into the TOML fragment object that
437
+ * merges into an owning config's TOML data (the caller spreads the returned
438
+ * keys alongside the config's own section). Returns `{}` when empty so a
439
+ * config with no declared access emits nothing (byte-stable).
440
+ */
441
+ export function serializeDeclaredAccessManifest(manifest) {
442
+ if (!manifest)
443
+ return {};
444
+ const out = {};
445
+ const metadata = {};
446
+ if (manifest.self && Array.isArray(manifest.self.categories)) {
447
+ metadata.self = { categories: manifest.self.categories };
448
+ }
449
+ if (manifest.paths && Object.keys(manifest.paths).length > 0) {
450
+ metadata.paths = manifest.paths;
451
+ }
452
+ if (Object.keys(metadata).length > 0) {
453
+ out.metadata = metadata;
454
+ }
455
+ if (Array.isArray(manifest.secrets) && manifest.secrets.length > 0) {
456
+ out.secrets = manifest.secrets;
457
+ }
458
+ if (Array.isArray(manifest.vars) && manifest.vars.length > 0) {
459
+ out.vars = manifest.vars;
460
+ }
461
+ return out;
462
+ }
463
+ //# sourceMappingURL=toml-metadata-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toml-metadata-config.js","sourceRoot":"","sources":["../../../src/lib/toml-metadata-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD;mDACmD;AACnD,MAAM,kBAAkB,GAAG,0BAA0B,CAAC;AAEtD;;;;uCAIuC;AACvC,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AAEpD;0DAC0D;AAC1D,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAEzC;gDACgD;AAChD,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,MAAM;IACN,IAAI;IACJ,WAAW;CACZ,CAAC,CAAC;AAkBH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,cAAc;IACd,UAAU;IACV,QAAQ;IACR,UAAU;IACV,WAAW;IACX,aAAa;C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AAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrC,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACnE,GAAG,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;IACjC,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7D,GAAG,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC3B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Neutral TOML-form helpers shared by every config serializer that chooses
3
+ * between a native nested-table form and a legacy JSON-string form.
4
+ *
5
+ * These used to live in `toml-database-config.ts`, but that module owns
6
+ * database-operation config specifically; once workflow-schema serialization
7
+ * also needed `canEmitNative` / `FieldForm` / `classifyInlineFieldForm`
8
+ * (issue #1446), keeping them there made a database-specific module double as a
9
+ * generic TOML utility by accident. They now live here so both callers import
10
+ * from a neutral home. `toml-database-config.ts` re-exports them for backwards
11
+ * compatibility with existing importers.
12
+ */
13
+ export type FieldForm = "native" | "legacy";
14
+ /**
15
+ * Classify a single-line TOML field value (the text after `key = `) as
16
+ * native or legacy form.
17
+ *
18
+ * An inline table (`{ ... }`) or inline array (`[ ... ]`) is native TOML —
19
+ * the structure is written directly, so `sync pull` should re-emit it through
20
+ * the native-emission path rather than collapse it back to an opaque JSON
21
+ * string. A quoted string (`'...'` / `"..."`) is the legacy JSON-string form.
22
+ *
23
+ * This is the fix for issue #1255: previously ANY `definition = <value>`
24
+ * one-liner was classified `legacy`, so an author who wrote the compact
25
+ * inline form `definition = { filter = { "$in" = [1, 2] } }` got an opaque
26
+ * JSON string back on the next pull (churn). Distinguishing the two makes
27
+ * the inline form round-trip stably through the existing native-emission
28
+ * path.
29
+ */
30
+ export declare function classifyInlineFieldForm(rawValue: string): FieldForm;
31
+ /**
32
+ * Recursively check whether a JS value can be represented in TOML **without
33
+ * data loss**. Returns null if OK, a reason string otherwise.
34
+ *
35
+ * This is a data-loss guard, not a "native TOML" gate. The config round-trip
36
+ * serializes with `smol-toml` (TOML 1.0), which handles heterogeneous arrays,
37
+ * so the only values that still can't be emitted are the ones every TOML
38
+ * serializer silently drops:
39
+ * - `null` (TOML has no null — the key would vanish on write).
40
+ * - `undefined` (same — the key would vanish).
41
+ * - arrays containing `null` (the element would vanish, shifting the array).
42
+ *
43
+ * Heterogeneous arrays (mixed TOML types) are representable and are NOT
44
+ * flagged — that fallback was removed in issue #1450.
45
+ */
46
+ export declare function canEmitNative(value: any): string | null;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Neutral TOML-form helpers shared by every config serializer that chooses
3
+ * between a native nested-table form and a legacy JSON-string form.
4
+ *
5
+ * These used to live in `toml-database-config.ts`, but that module owns
6
+ * database-operation config specifically; once workflow-schema serialization
7
+ * also needed `canEmitNative` / `FieldForm` / `classifyInlineFieldForm`
8
+ * (issue #1446), keeping them there made a database-specific module double as a
9
+ * generic TOML utility by accident. They now live here so both callers import
10
+ * from a neutral home. `toml-database-config.ts` re-exports them for backwards
11
+ * compatibility with existing importers.
12
+ */
13
+ /**
14
+ * Classify a single-line TOML field value (the text after `key = `) as
15
+ * native or legacy form.
16
+ *
17
+ * An inline table (`{ ... }`) or inline array (`[ ... ]`) is native TOML —
18
+ * the structure is written directly, so `sync pull` should re-emit it through
19
+ * the native-emission path rather than collapse it back to an opaque JSON
20
+ * string. A quoted string (`'...'` / `"..."`) is the legacy JSON-string form.
21
+ *
22
+ * This is the fix for issue #1255: previously ANY `definition = <value>`
23
+ * one-liner was classified `legacy`, so an author who wrote the compact
24
+ * inline form `definition = { filter = { "$in" = [1, 2] } }` got an opaque
25
+ * JSON string back on the next pull (churn). Distinguishing the two makes
26
+ * the inline form round-trip stably through the existing native-emission
27
+ * path.
28
+ */
29
+ export function classifyInlineFieldForm(rawValue) {
30
+ const trimmed = rawValue.trimStart();
31
+ if (trimmed.startsWith("{") || trimmed.startsWith("["))
32
+ return "native";
33
+ return "legacy";
34
+ }
35
+ /**
36
+ * Recursively check whether a JS value can be represented in TOML **without
37
+ * data loss**. Returns null if OK, a reason string otherwise.
38
+ *
39
+ * This is a data-loss guard, not a "native TOML" gate. The config round-trip
40
+ * serializes with `smol-toml` (TOML 1.0), which handles heterogeneous arrays,
41
+ * so the only values that still can't be emitted are the ones every TOML
42
+ * serializer silently drops:
43
+ * - `null` (TOML has no null — the key would vanish on write).
44
+ * - `undefined` (same — the key would vanish).
45
+ * - arrays containing `null` (the element would vanish, shifting the array).
46
+ *
47
+ * Heterogeneous arrays (mixed TOML types) are representable and are NOT
48
+ * flagged — that fallback was removed in issue #1450.
49
+ */
50
+ export function canEmitNative(value) {
51
+ if (value === null)
52
+ return "value is null";
53
+ if (value === undefined)
54
+ return "value is undefined";
55
+ if (Array.isArray(value)) {
56
+ for (const item of value) {
57
+ if (item === null)
58
+ return "array contains null";
59
+ }
60
+ for (const item of value) {
61
+ const sub = canEmitNative(item);
62
+ if (sub)
63
+ return sub;
64
+ }
65
+ return null;
66
+ }
67
+ if (typeof value === "object") {
68
+ for (const v of Object.values(value)) {
69
+ const sub = canEmitNative(v);
70
+ if (sub)
71
+ return sub;
72
+ }
73
+ return null;
74
+ }
75
+ // primitives: string, number, boolean.
76
+ return null;
77
+ }
78
+ //# sourceMappingURL=toml-native-form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toml-native-form.js","sourceRoot":"","sources":["../../../src/lib/toml-native-form.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAgB;IACtD,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;IACrC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,QAAQ,CAAC;IACxE,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa,CAAC,KAAU;IACtC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,eAAe,CAAC;IAC3C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,oBAAoB,CAAC;IACrD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,IAAI,KAAK,IAAI;gBAAE,OAAO,qBAAqB,CAAC;QAClD,CAAC;QACD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;YAChC,IAAI,GAAG;gBAAE,OAAO,GAAG,CAAC;QACtB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,MAAM,GAAG,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;YAC7B,IAAI,GAAG;gBAAE,OAAO,GAAG,CAAC;QACtB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,uCAAuC;IACvC,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -47,6 +47,33 @@ export interface ValidationResult {
47
47
  * doc-comment for the rationale.
48
48
  */
49
49
  export declare function collectParamRefs(value: any): string[];
50
+ /**
51
+ * Collect bare `params.X` references from a CEL string (issue #1239).
52
+ *
53
+ * Access rules reference operation params with the bare `params.X` form (no
54
+ * `$` prefix), unlike `definition`, which uses `$params.X` (scanned by
55
+ * {@link collectParamRefs}). This helper feeds the operation's `access` CEL
56
+ * and each per-param `access` CEL into the "referenced" set so a param used
57
+ * only by an access rule is not wrongly flagged "declared but not referenced".
58
+ *
59
+ * Supported forms, all whitespace-tolerant:
60
+ * - dot notation: `params.claimedUserId`, `params . claimedUserId`
61
+ * - dot path: `params.config.subField` → first segment `config`
62
+ * - bracket notation: `params["claimedUserId"]`, `params['claimedUserId']`
63
+ *
64
+ * Word-boundary guard: a `params` preceded by an identifier char, `$`, or `.`
65
+ * is NOT a match, so `$params.x` (definition syntax), `myparams.x`, and a
66
+ * dotted member access like `database.metadata.params.userId` are ignored —
67
+ * `params` only counts as the params root when it's a standalone root
68
+ * identifier. To avoid counting a `params.` that merely appears inside a quoted
69
+ * string literal (e.g. `note == "see params.docs"`), bracket keys are scanned
70
+ * first (they legitimately contain quotes), then string literals are stripped
71
+ * before the dot-notation scan.
72
+ *
73
+ * Purely additive: this only grows the referenced set, loosening the soft
74
+ * warning. The blocking `$params` error path is untouched.
75
+ */
76
+ export declare function collectCelParamRefs(cel: any): string[];
50
77
  /**
51
78
  * Normalize a `params` value (object, array, or JSON string) into the
52
79
  * set of declared param names.
@@ -74,6 +101,13 @@ export interface ValidateOptions {
74
101
  name: string;
75
102
  definition: any;
76
103
  params?: any;
104
+ /**
105
+ * The operation-level `access` CEL rule, if any (issue #1239). Params
106
+ * referenced here via bare `params.X` count as "referenced" so they are
107
+ * not wrongly flagged "declared but not referenced". May be null/absent
108
+ * when the operation inherits the type's `defaultAccess`.
109
+ */
110
+ access?: any;
77
111
  }>;
78
112
  }
79
113
  /**