@aglyn/aglyn 1.0.0-beta.221 → 1.0.0-beta.222
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/package.json +15 -11
- package/src/lib/app-utils/agent-openapi.js +1 -1
- package/src/lib/app-utils/agent-openapi.js.map +1 -1
- package/src/lib/app-utils/analytics-events.d.ts +3 -2
- package/src/lib/app-utils/analytics-events.js +3 -2
- package/src/lib/app-utils/analytics-events.js.map +1 -1
- package/src/lib/app-utils/api-plugins.d.ts +30 -0
- package/src/lib/app-utils/api-plugins.js +24 -1
- package/src/lib/app-utils/api-plugins.js.map +1 -1
- package/src/lib/app-utils/author-html.d.ts +1 -1
- package/src/lib/app-utils/author-html.js.map +1 -1
- package/src/lib/app-utils/bandwidth-cap.d.ts +12 -1
- package/src/lib/app-utils/bandwidth-cap.js +17 -1
- package/src/lib/app-utils/bandwidth-cap.js.map +1 -1
- package/src/lib/app-utils/compose-reusable-components.d.ts +19 -0
- package/src/lib/app-utils/compose-reusable-components.js +116 -26
- package/src/lib/app-utils/compose-reusable-components.js.map +1 -1
- package/src/lib/app-utils/console-routes.d.ts +4 -0
- package/src/lib/app-utils/console-routes.js +3 -0
- package/src/lib/app-utils/console-routes.js.map +1 -1
- package/src/lib/app-utils/contacts.d.ts +71 -0
- package/src/lib/app-utils/contacts.js +55 -0
- package/src/lib/app-utils/contacts.js.map +1 -1
- package/src/lib/app-utils/contexts.d.ts +1 -0
- package/src/lib/app-utils/contexts.js +1 -0
- package/src/lib/app-utils/contexts.js.map +1 -1
- package/src/lib/app-utils/crm-email-templates.js +21 -4
- package/src/lib/app-utils/crm-email-templates.js.map +1 -1
- package/src/lib/app-utils/crm-kinds.d.ts +2 -0
- package/src/lib/app-utils/crm-kinds.js +1 -0
- package/src/lib/app-utils/crm-kinds.js.map +1 -1
- package/src/lib/app-utils/crm.d.ts +1199 -67
- package/src/lib/app-utils/crm.js +1951 -310
- package/src/lib/app-utils/crm.js.map +1 -1
- package/src/lib/app-utils/csv-import.d.ts +10 -38
- package/src/lib/app-utils/csv-import.js +17 -42
- package/src/lib/app-utils/csv-import.js.map +1 -1
- package/src/lib/app-utils/csv.d.ts +32 -11
- package/src/lib/app-utils/csv.js +43 -5
- package/src/lib/app-utils/csv.js.map +1 -1
- package/src/lib/app-utils/default-site.d.ts +116 -0
- package/src/lib/app-utils/default-site.js +1024 -0
- package/src/lib/app-utils/default-site.js.map +1 -0
- package/src/lib/app-utils/docs-help.generated.d.ts +22 -22
- package/src/lib/app-utils/docs-help.generated.js +44 -10
- package/src/lib/app-utils/docs-help.generated.js.map +1 -1
- package/src/lib/app-utils/docs-index.generated.js +738 -150
- package/src/lib/app-utils/docs-index.generated.js.map +1 -1
- package/src/lib/app-utils/draft-placeholders.d.ts +76 -0
- package/src/lib/app-utils/draft-placeholders.js +115 -0
- package/src/lib/app-utils/draft-placeholders.js.map +1 -0
- package/src/lib/app-utils/entity-picker-context.d.ts +19 -15
- package/src/lib/app-utils/entity-picker-context.js +4 -4
- package/src/lib/app-utils/entity-picker-context.js.map +1 -1
- package/src/lib/app-utils/expand-repeatables.d.ts +66 -10
- package/src/lib/app-utils/expand-repeatables.js +88 -14
- package/src/lib/app-utils/expand-repeatables.js.map +1 -1
- package/src/lib/app-utils/forms.d.ts +33 -22
- package/src/lib/app-utils/forms.js +47 -28
- package/src/lib/app-utils/forms.js.map +1 -1
- package/src/lib/app-utils/full-use-cost.d.ts +277 -0
- package/src/lib/app-utils/full-use-cost.js +421 -0
- package/src/lib/app-utils/full-use-cost.js.map +1 -0
- package/src/lib/app-utils/health-report.js +11 -0
- package/src/lib/app-utils/health-report.js.map +1 -1
- package/src/lib/app-utils/llms-txt.d.ts +20 -0
- package/src/lib/app-utils/llms-txt.js +7 -1
- package/src/lib/app-utils/llms-txt.js.map +1 -1
- package/src/lib/app-utils/media-asset-facts.d.ts +16 -1
- package/src/lib/app-utils/media-asset-facts.js +40 -13
- package/src/lib/app-utils/media-asset-facts.js.map +1 -1
- package/src/lib/app-utils/media-bandwidth.d.ts +52 -0
- package/src/lib/app-utils/media-bandwidth.js +94 -0
- package/src/lib/app-utils/media-bandwidth.js.map +1 -0
- package/src/lib/app-utils/media-ref.d.ts +241 -33
- package/src/lib/app-utils/media-ref.js +324 -43
- package/src/lib/app-utils/media-ref.js.map +1 -1
- package/src/lib/app-utils/media-src.d.ts +8 -8
- package/src/lib/app-utils/media-src.js +27 -11
- package/src/lib/app-utils/media-src.js.map +1 -1
- package/src/lib/app-utils/media-takedown-reach.d.ts +4 -1
- package/src/lib/app-utils/media-takedown-reach.js +6 -3
- package/src/lib/app-utils/media-takedown-reach.js.map +1 -1
- package/src/lib/app-utils/notifications.d.ts +1 -1
- package/src/lib/app-utils/notifications.js +2 -0
- package/src/lib/app-utils/notifications.js.map +1 -1
- package/src/lib/app-utils/organizations.d.ts +51 -2
- package/src/lib/app-utils/organizations.js +56 -3
- package/src/lib/app-utils/organizations.js.map +1 -1
- package/src/lib/app-utils/page-record-sources.d.ts +87 -0
- package/src/lib/app-utils/page-record-sources.js +53 -0
- package/src/lib/app-utils/page-record-sources.js.map +1 -0
- package/src/lib/app-utils/paid-media-source.d.ts +3 -7
- package/src/lib/app-utils/paid-media-source.js +5 -19
- package/src/lib/app-utils/paid-media-source.js.map +1 -1
- package/src/lib/app-utils/person-erasure.d.ts +5 -2
- package/src/lib/app-utils/person-erasure.js.map +1 -1
- package/src/lib/app-utils/picklists.d.ts +187 -0
- package/src/lib/app-utils/picklists.js +320 -0
- package/src/lib/app-utils/picklists.js.map +1 -0
- package/src/lib/app-utils/plan-entitlements.d.ts +220 -50
- package/src/lib/app-utils/plan-entitlements.js +309 -115
- package/src/lib/app-utils/plan-entitlements.js.map +1 -1
- package/src/lib/app-utils/realm-host-surface.generated.js +2 -0
- package/src/lib/app-utils/realm-host-surface.generated.js.map +1 -1
- package/src/lib/app-utils/release-flags.d.ts +1 -1
- package/src/lib/app-utils/release-flags.js +11 -0
- package/src/lib/app-utils/release-flags.js.map +1 -1
- package/src/lib/app-utils/rendered-widths.d.ts +121 -0
- package/src/lib/app-utils/rendered-widths.js +211 -0
- package/src/lib/app-utils/rendered-widths.js.map +1 -0
- package/src/lib/app-utils/repeat-sources.d.ts +2 -1
- package/src/lib/app-utils/repeat-sources.js.map +1 -1
- package/src/lib/app-utils/screen-route.d.ts +154 -36
- package/src/lib/app-utils/screen-route.js +185 -40
- package/src/lib/app-utils/screen-route.js.map +1 -1
- package/src/lib/app-utils/seo-audit.d.ts +11 -1
- package/src/lib/app-utils/seo-audit.js +33 -13
- package/src/lib/app-utils/seo-audit.js.map +1 -1
- package/src/lib/app-utils/seo-keywords.d.ts +11 -0
- package/src/lib/app-utils/seo-keywords.js +19 -5
- package/src/lib/app-utils/seo-keywords.js.map +1 -1
- package/src/lib/app-utils/seo-page-facts.d.ts +47 -4
- package/src/lib/app-utils/seo-page-facts.js +136 -31
- package/src/lib/app-utils/seo-page-facts.js.map +1 -1
- package/src/lib/app-utils/seo-site-scan.d.ts +42 -4
- package/src/lib/app-utils/seo-site-scan.js +113 -12
- package/src/lib/app-utils/seo-site-scan.js.map +1 -1
- package/src/lib/app-utils/server.d.ts +5 -4
- package/src/lib/app-utils/server.js +14 -5
- package/src/lib/app-utils/server.js.map +1 -1
- package/src/lib/app-utils/site-icon-set.d.ts +195 -0
- package/src/lib/app-utils/site-icon-set.js +351 -0
- package/src/lib/app-utils/site-icon-set.js.map +1 -0
- package/src/lib/app-utils/site-interactions.d.ts +101 -4
- package/src/lib/app-utils/site-interactions.js +120 -4
- package/src/lib/app-utils/site-interactions.js.map +1 -1
- package/src/lib/app-utils/starter-template-nodes.d.ts +7 -0
- package/src/lib/app-utils/starter-template-nodes.js +3 -0
- package/src/lib/app-utils/starter-template-nodes.js.map +1 -1
- package/src/lib/app-utils/starter-templates.d.ts +5 -19
- package/src/lib/app-utils/starter-templates.js +5 -49
- package/src/lib/app-utils/starter-templates.js.map +1 -1
- package/src/lib/app-utils/transfer-launcher-context.d.ts +136 -0
- package/src/lib/app-utils/transfer-launcher-context.js +23 -0
- package/src/lib/app-utils/transfer-launcher-context.js.map +1 -0
- package/src/lib/app-utils/transfer-resume-import.d.ts +39 -0
- package/src/lib/app-utils/transfer-resume-import.js +128 -0
- package/src/lib/app-utils/transfer-resume-import.js.map +1 -0
- package/src/lib/app-utils/upgrade-proposal.d.ts +66 -0
- package/src/lib/app-utils/upgrade-proposal.js +95 -0
- package/src/lib/app-utils/upgrade-proposal.js.map +1 -0
- package/src/lib/app-utils/utc-month.d.ts +33 -0
- package/src/lib/app-utils/utc-month.js +35 -0
- package/src/lib/app-utils/utc-month.js.map +1 -0
- package/src/lib/app-utils/visitor-record-ceiling.d.ts +4 -4
- package/src/lib/app-utils/visitor-record-ceiling.js +4 -4
- package/src/lib/app-utils/visitor-record-ceiling.js.map +1 -1
- package/src/lib/app-utils/wire-nodes.d.ts +39 -19
- package/src/lib/app-utils/wire-nodes.js +120 -34
- package/src/lib/app-utils/wire-nodes.js.map +1 -1
- package/src/lib/data-transfer/access.d.ts +74 -0
- package/src/lib/data-transfer/access.js +93 -0
- package/src/lib/data-transfer/access.js.map +1 -0
- package/src/lib/data-transfer/derive.d.ts +246 -0
- package/src/lib/data-transfer/derive.js +1007 -0
- package/src/lib/data-transfer/derive.js.map +1 -0
- package/src/lib/data-transfer/export-file.d.ts +46 -0
- package/src/lib/data-transfer/export-file.js +146 -0
- package/src/lib/data-transfer/export-file.js.map +1 -0
- package/src/lib/data-transfer/field-catalog.d.ts +134 -0
- package/src/lib/data-transfer/field-catalog.js +278 -0
- package/src/lib/data-transfer/field-catalog.js.map +1 -0
- package/src/lib/data-transfer/header-match.d.ts +129 -0
- package/src/lib/data-transfer/header-match.js +367 -0
- package/src/lib/data-transfer/header-match.js.map +1 -0
- package/src/lib/data-transfer/index.d.ts +34 -0
- package/src/lib/data-transfer/index.js +40 -0
- package/src/lib/data-transfer/index.js.map +1 -0
- package/src/lib/data-transfer/job.d.ts +190 -0
- package/src/lib/data-transfer/job.js +229 -0
- package/src/lib/data-transfer/job.js.map +1 -0
- package/src/lib/data-transfer/lookup.d.ts +45 -0
- package/src/lib/data-transfer/lookup.js +71 -0
- package/src/lib/data-transfer/lookup.js.map +1 -0
- package/src/lib/data-transfer/match.d.ts +99 -0
- package/src/lib/data-transfer/match.js +244 -0
- package/src/lib/data-transfer/match.js.map +1 -0
- package/src/lib/data-transfer/package-plan.d.ts +205 -0
- package/src/lib/data-transfer/package-plan.js +475 -0
- package/src/lib/data-transfer/package-plan.js.map +1 -0
- package/src/lib/data-transfer/package.d.ts +181 -0
- package/src/lib/data-transfer/package.js +426 -0
- package/src/lib/data-transfer/package.js.map +1 -0
- package/src/lib/data-transfer/picklist-map.d.ts +139 -0
- package/src/lib/data-transfer/picklist-map.js +271 -0
- package/src/lib/data-transfer/picklist-map.js.map +1 -0
- package/src/lib/data-transfer/plan.d.ts +176 -0
- package/src/lib/data-transfer/plan.js +451 -0
- package/src/lib/data-transfer/plan.js.map +1 -0
- package/src/lib/data-transfer/policy.d.ts +170 -0
- package/src/lib/data-transfer/policy.js +378 -0
- package/src/lib/data-transfer/policy.js.map +1 -0
- package/src/lib/data-transfer/resource.d.ts +211 -0
- package/src/lib/data-transfer/resource.js +241 -0
- package/src/lib/data-transfer/resource.js.map +1 -0
- package/src/lib/data-transfer/review.d.ts +70 -0
- package/src/lib/data-transfer/review.js +233 -0
- package/src/lib/data-transfer/review.js.map +1 -0
- package/src/lib/data-transfer/similarity.d.ts +40 -0
- package/src/lib/data-transfer/similarity.js +106 -0
- package/src/lib/data-transfer/similarity.js.map +1 -0
- package/src/lib/data-transfer/site-package.d.ts +365 -0
- package/src/lib/data-transfer/site-package.js +1077 -0
- package/src/lib/data-transfer/site-package.js.map +1 -0
- package/src/lib/data-transfer/source.d.ts +74 -0
- package/src/lib/data-transfer/source.js +293 -0
- package/src/lib/data-transfer/source.js.map +1 -0
- package/src/lib/data-transfer/transfer-api.d.ts +898 -0
- package/src/lib/data-transfer/transfer-api.js +107 -0
- package/src/lib/data-transfer/transfer-api.js.map +1 -0
- package/src/lib/foundation/definitions/org-billing.types.d.ts +31 -0
- package/src/lib/foundation/definitions/org-billing.types.js.map +1 -1
- package/src/lib/foundation/definitions/organization.types.d.ts +42 -1
- package/src/lib/foundation/definitions/organization.types.js.map +1 -1
- package/src/lib/foundation/definitions/platform.types.d.ts +6 -4
- package/src/lib/foundation/definitions/platform.types.js.map +1 -1
- package/src/lib/foundation/index.d.ts +1 -1
- package/src/lib/foundation/index.js.map +1 -1
- package/src/lib/plugin-manager/feature-plugins.d.ts +91 -2
- package/src/lib/plugin-manager/feature-plugins.js +48 -3
- package/src/lib/plugin-manager/feature-plugins.js.map +1 -1
- package/src/lib/plugin-manager/first-party-plugins.generated.d.ts +50 -0
- package/src/lib/plugin-manager/first-party-plugins.generated.js +1129 -28
- package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
- package/src/lib/plugin-manager/index.d.ts +0 -1
- package/src/lib/plugin-manager/index.js +0 -1
- package/src/lib/plugin-manager/index.js.map +1 -1
- package/src/lib/plugin-manager/interaction-recipes.d.ts +142 -0
- package/src/lib/plugin-manager/interaction-recipes.js +104 -0
- package/src/lib/plugin-manager/interaction-recipes.js.map +1 -0
- package/src/lib/plugin-manager/interaction-step-checks.d.ts +66 -0
- package/src/lib/plugin-manager/interaction-step-checks.js +86 -0
- package/src/lib/plugin-manager/interaction-step-checks.js.map +1 -0
- package/src/lib/plugin-manager/plugin-artifact-types.d.ts +235 -0
- package/src/lib/plugin-manager/plugin-artifact-types.js +99 -0
- package/src/lib/plugin-manager/plugin-artifact-types.js.map +1 -0
- package/src/lib/plugin-manager/plugin-contact-capture.d.ts +8 -0
- package/src/lib/plugin-manager/plugin-contact-capture.js.map +1 -1
- package/src/lib/plugin-manager/plugin-conversion-credit.d.ts +216 -0
- package/src/lib/plugin-manager/plugin-conversion-credit.js +91 -0
- package/src/lib/plugin-manager/plugin-conversion-credit.js.map +1 -0
- package/src/lib/plugin-manager/plugin-entity-pickers.d.ts +83 -0
- package/src/lib/plugin-manager/plugin-entity-pickers.js +87 -0
- package/src/lib/plugin-manager/plugin-entity-pickers.js.map +1 -0
- package/src/lib/plugin-manager/plugin-host-resources.d.ts +6 -0
- package/src/lib/plugin-manager/plugin-host-resources.js +6 -1
- package/src/lib/plugin-manager/plugin-host-resources.js.map +1 -1
- package/src/lib/plugin-manager/plugin-intake-gates.d.ts +75 -0
- package/src/lib/plugin-manager/plugin-intake-gates.js +49 -0
- package/src/lib/plugin-manager/plugin-intake-gates.js.map +1 -0
- package/src/lib/plugin-manager/plugin-jobs.d.ts +5 -5
- package/src/lib/plugin-manager/plugin-jobs.js +7 -7
- package/src/lib/plugin-manager/plugin-jobs.js.map +1 -1
- package/src/lib/plugin-manager/plugin-live-paths.d.ts +70 -0
- package/src/lib/plugin-manager/plugin-live-paths.js +66 -0
- package/src/lib/plugin-manager/plugin-live-paths.js.map +1 -0
- package/src/lib/plugin-manager/plugin-org-erasure.d.ts +3 -2
- package/src/lib/plugin-manager/plugin-org-erasure.js +30 -5
- package/src/lib/plugin-manager/plugin-org-erasure.js.map +1 -1
- package/src/lib/plugin-manager/plugin-person-erasure.d.ts +68 -9
- package/src/lib/plugin-manager/plugin-person-erasure.js +196 -51
- package/src/lib/plugin-manager/plugin-person-erasure.js.map +1 -1
- package/src/lib/plugin-manager/plugin-person-records.d.ts +275 -0
- package/src/lib/plugin-manager/plugin-person-records.js +107 -0
- package/src/lib/plugin-manager/plugin-person-records.js.map +1 -0
- package/src/lib/plugin-manager/plugin-record-counts.d.ts +76 -0
- package/src/lib/plugin-manager/plugin-record-counts.js +49 -0
- package/src/lib/plugin-manager/plugin-record-counts.js.map +1 -0
- package/src/lib/plugin-manager/plugin-record-email-state.d.ts +26 -0
- package/src/lib/plugin-manager/plugin-record-email-state.js +16 -0
- package/src/lib/plugin-manager/plugin-record-email-state.js.map +1 -1
- package/src/lib/plugin-manager/plugin-record-index.d.ts +10 -0
- package/src/lib/plugin-manager/plugin-record-index.js.map +1 -1
- package/src/lib/plugin-manager/plugin-record-lists.d.ts +86 -6
- package/src/lib/plugin-manager/plugin-record-lists.js +42 -5
- package/src/lib/plugin-manager/plugin-record-lists.js.map +1 -1
- package/src/lib/plugin-manager/plugin-record-origin.d.ts +79 -0
- package/src/lib/plugin-manager/plugin-record-origin.js +46 -0
- package/src/lib/plugin-manager/plugin-record-origin.js.map +1 -0
- package/src/lib/plugin-manager/plugin-record-pages.d.ts +37 -0
- package/src/lib/plugin-manager/plugin-record-pages.js +52 -0
- package/src/lib/plugin-manager/plugin-record-pages.js.map +1 -0
- package/src/lib/plugin-manager/plugin-record-timeline.d.ts +60 -0
- package/src/lib/plugin-manager/plugin-record-timeline.js +16 -0
- package/src/lib/plugin-manager/plugin-record-timeline.js.map +1 -1
- package/src/lib/plugin-manager/plugin-resource-drafts.d.ts +5 -5
- package/src/lib/plugin-manager/plugin-resource-drafts.js.map +1 -1
- package/src/lib/plugin-manager/plugin-revocations.d.ts +64 -0
- package/src/lib/plugin-manager/plugin-revocations.js +47 -0
- package/src/lib/plugin-manager/plugin-revocations.js.map +1 -0
- package/src/lib/plugin-manager/plugin-send-tallies.d.ts +69 -0
- package/src/lib/plugin-manager/plugin-send-tallies.js +45 -0
- package/src/lib/plugin-manager/plugin-send-tallies.js.map +1 -0
- package/src/lib/plugin-manager/plugin-site-bundle.d.ts +40 -0
- package/src/lib/plugin-manager/plugin-site-bundle.js +4 -0
- package/src/lib/plugin-manager/plugin-site-bundle.js.map +1 -1
- package/src/lib/plugin-manager/plugin-site-export.d.ts +57 -1
- package/src/lib/plugin-manager/plugin-site-export.js +23 -10
- package/src/lib/plugin-manager/plugin-site-export.js.map +1 -1
- package/src/lib/plugin-manager/plugin-sitemap-readers.d.ts +146 -0
- package/src/lib/plugin-manager/plugin-sitemap-readers.js +110 -0
- package/src/lib/plugin-manager/plugin-sitemap-readers.js.map +1 -0
- package/src/lib/plugin-manager/plugin-transfer-resources.d.ts +714 -0
- package/src/lib/plugin-manager/plugin-transfer-resources.js +443 -0
- package/src/lib/plugin-manager/plugin-transfer-resources.js.map +1 -0
- package/src/lib/plugin-manager/plugin-usage-axes.d.ts +54 -5
- package/src/lib/plugin-manager/plugin-usage-axes.js +11 -3
- package/src/lib/plugin-manager/plugin-usage-axes.js.map +1 -1
- package/src/lib/plugin-manager/plugin-user-erasure.js +9 -1
- package/src/lib/plugin-manager/plugin-user-erasure.js.map +1 -1
- package/src/lib/plugin-manager/plugin-visitor-doors.d.ts +104 -0
- package/src/lib/plugin-manager/plugin-visitor-doors.js +108 -0
- package/src/lib/plugin-manager/plugin-visitor-doors.js.map +1 -0
- package/src/lib/plugin-manager/realm-host-aglyn.generated.js +2 -0
- package/src/lib/plugin-manager/realm-host-aglyn.generated.js.map +1 -1
- package/src/lib/plugin-manager/repeat-rows.d.ts +5 -6
- package/src/lib/plugin-manager/repeat-rows.js.map +1 -1
- package/src/lib/app-utils/actions.d.ts +0 -310
- package/src/lib/app-utils/actions.js +0 -506
- package/src/lib/app-utils/actions.js.map +0 -1
- package/src/lib/app-utils/automation-placeholders.d.ts +0 -72
- package/src/lib/app-utils/automation-placeholders.js +0 -207
- package/src/lib/app-utils/automation-placeholders.js.map +0 -1
- package/src/lib/app-utils/dataset-models.d.ts +0 -339
- package/src/lib/app-utils/dataset-models.js +0 -722
- package/src/lib/app-utils/dataset-models.js.map +0 -1
- package/src/lib/app-utils/datasets.d.ts +0 -171
- package/src/lib/app-utils/datasets.js +0 -227
- package/src/lib/app-utils/datasets.js.map +0 -1
- package/src/lib/app-utils/form-abuse-ceiling.d.ts +0 -146
- package/src/lib/app-utils/form-abuse-ceiling.js +0 -158
- package/src/lib/app-utils/form-abuse-ceiling.js.map +0 -1
- package/src/lib/plugin-manager/order-fulfilment.d.ts +0 -142
- package/src/lib/plugin-manager/order-fulfilment.js +0 -104
- package/src/lib/plugin-manager/order-fulfilment.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/dataset-models.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\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 { validateCustomFieldValue } from '../plugin-manager/custom-fields'\nimport { type DatasetFieldEntry, humanizeDatasetFieldId } from './datasets'\n\n/**\n * Dataset models (AGL-177): the runtime promotion of the type-level\n * blueprint in `libs/shared/data/types/src/lib/dod.ts` (kept as the\n * referenced design doc — this module is the single runtime source of\n * truth). A model lives on the dataset doc\n * (`orgs/{orgId}/datasets/{id}.model`) and drives the typed editor, import\n * and site-restore validation, and every record write — the console, `/v1`,\n * a bound form's submission and an automation step — through the shared\n * `validateDocument`/`coerceDocumentValues` pair so they can't disagree. The\n * form and the automation step reach the pair through\n * `prepareDatasetRecordWrite` (AGL-2773).\n *\n * Storage conventions (Firestore-safe): timestamps as epoch millis\n * numbers, coordinates as `{ latitude, longitude }`, `sorted` as arrays,\n * `map` as plain objects, references as target-document id strings.\n */\n\n/** dod.ts `FT.Tag` vocabulary plus `reference` (AGL-180 builds on it). */\nexport type DatasetFieldType =\n | 'bool'\n | 'bytes'\n | 'timestamp'\n | 'float'\n | 'int32'\n | 'int64'\n | 'nil'\n | 'text'\n | 'coordinates'\n | 'map'\n | 'sorted'\n | 'reference'\n\nexport const DATASET_FIELD_TYPES: DatasetFieldType[] = [\n 'text',\n 'bool',\n 'int32',\n 'int64',\n 'float',\n 'timestamp',\n 'coordinates',\n 'map',\n 'sorted',\n 'bytes',\n 'nil',\n 'reference',\n]\n\n/** Display names, mirroring dod.ts `lbl`. */\nexport const DATASET_FIELD_TYPE_LABELS: Record<DatasetFieldType, string> = {\n text: 'Text',\n bool: 'Boolean',\n int32: 'Integer',\n int64: 'Big integer',\n float: 'Number',\n timestamp: 'Date & time',\n coordinates: 'Coordinates',\n map: 'Map',\n sorted: 'List',\n bytes: 'Bytes',\n nil: 'Null',\n reference: 'Reference',\n}\n\n/**\n * Plain-JSON validation vocabulary (the dod.ts `Eval` shape, extended\n * with min/max and options, serialized flat instead of enum-keyed).\n */\nexport interface DatasetFieldValidation {\n required?: boolean\n /** Source of a RegExp applied to text values. */\n regex?: string\n /** Numbers/timestamps: value bound. Text: length bound. */\n min?: number\n max?: number\n /** Enum: value must be one of these (text fields). */\n options?: string[]\n}\n\nexport interface DatasetFieldDefinition {\n /**\n * Human-facing display label only. The stable reference id is the KEY in\n * `DatasetModel.fields` (and `order`), NOT this name — bindings resolve\n * `{{item.<fieldId>}}` against that key. The default id is derived from\n * this name once at creation but is user-overridable (AGL-578); renaming\n * the label afterwards never changes the id.\n */\n name: string\n type: DatasetFieldType\n /**\n * Plugin-declared custom type riding this base type (AGL-434) — see\n * plugin-manager/custom-fields. Unknown names degrade to the base type.\n */\n customType?: string\n description?: string\n required?: boolean\n /** Default applied by editors when creating documents; never coerced. */\n default?: unknown\n validation?: DatasetFieldValidation\n /**\n * Reference fields (AGL-180): target collection + display field id.\n * `multiple` stores a `sorted` array of FKeys (small-cardinality\n * many-to-many per the dod.ts guidance); `onDelete` is the referenced-\n * document delete policy (default `setNull` — never cascade in v2).\n */\n reference?: {\n datasetId: string\n displayFieldId?: string\n multiple?: boolean\n onDelete?: 'restrict' | 'setNull'\n }\n}\n\nexport interface DatasetModel {\n fields: Record<string, DatasetFieldDefinition>\n /** Field ids in display order. */\n order: string[]\n}\n\n/**\n * Migration shim (v1 → v2): datasets created before models carry flat\n * `fields: string[]` — derive a model where every column is an optional\n * text field whose id is the column name, so the editor and AGL-103\n * bindings keep working on unmigrated docs during rollout.\n */\nexport function deriveModelFromFields(fields: string[]): DatasetModel {\n const model: DatasetModel = { fields: {}, order: [] }\n for (const name of fields) {\n // Raw snake_case ids read as titles in table headers and pickers;\n // the id stays the stable key (AGL-558).\n model.fields[name] = { name: humanizeDatasetFieldId(name), type: 'text' }\n model.order.push(name)\n }\n return model\n}\n\n/**\n * Model from quick-creator entries (AGL-558): stable slug ids with the\n * human display names preserved — \"Roast preference\" → id\n * `roast_preference`, name \"Roast preference\".\n */\nexport function modelFromFieldEntries(\n entries: readonly DatasetFieldEntry[],\n): DatasetModel {\n const model: DatasetModel = { fields: {}, order: [] }\n for (const entry of entries) {\n model.fields[entry.id] = { name: entry.name, type: 'text' }\n model.order.push(entry.id)\n }\n return model\n}\n\n/** The dataset's model, deriving one from v1 `fields` when absent. */\nexport function effectiveDatasetModel(dataset: {\n model?: DatasetModel\n fields?: string[]\n}): DatasetModel {\n if (dataset.model?.fields && dataset.model.order?.length) {\n return dataset.model\n }\n return deriveModelFromFields(dataset.fields ?? [])\n}\n\nconst isFiniteNumber = (value: unknown): value is number =>\n typeof value === 'number' && Number.isFinite(value)\n\n/**\n * Validates a document's values against a model, returning fieldId →\n * human-readable error (empty object = valid). Values are expected in\n * storage form (see the module doc); use `coerceDocumentValues` first\n * when starting from user input strings.\n */\nexport function validateDocument(\n model: DatasetModel,\n values: Record<string, unknown>,\n): Record<string, string> {\n const errors: Record<string, string> = {}\n for (const fieldId of model.order) {\n const field = model.fields[fieldId]\n if (!field) continue\n const value = values[fieldId]\n const required = field.required || field.validation?.required\n if (value == null || value === '') {\n if (required) errors[fieldId] = `${field.name} is required`\n continue\n }\n const rules = field.validation ?? {}\n switch (field.type) {\n case 'text': {\n if (typeof value !== 'string') {\n errors[fieldId] = `${field.name} must be text`\n break\n }\n if (rules.min != null && value.length < rules.min) {\n errors[fieldId] = `${field.name} must be at least ${rules.min} characters`\n } else if (rules.max != null && value.length > rules.max) {\n errors[fieldId] = `${field.name} must be at most ${rules.max} characters`\n } else if (rules.regex) {\n try {\n if (!new RegExp(rules.regex).test(value)) {\n errors[fieldId] = `${field.name} has an invalid format`\n }\n } catch {\n // Broken pattern in the model never blocks writes.\n }\n }\n if (\n !errors[fieldId] &&\n rules.options?.length &&\n !rules.options.includes(value)\n ) {\n errors[fieldId] = `${field.name} must be one of: ${rules.options.join(', ')}`\n }\n break\n }\n case 'bool':\n if (typeof value !== 'boolean') {\n errors[fieldId] = `${field.name} must be true or false`\n }\n break\n case 'int32':\n case 'int64':\n if (!isFiniteNumber(value) || !Number.isInteger(value)) {\n errors[fieldId] = `${field.name} must be a whole number`\n break\n }\n if (rules.min != null && value < rules.min) {\n errors[fieldId] = `${field.name} must be ≥ ${rules.min}`\n } else if (rules.max != null && value > rules.max) {\n errors[fieldId] = `${field.name} must be ≤ ${rules.max}`\n }\n break\n case 'float':\n case 'timestamp':\n if (!isFiniteNumber(value)) {\n errors[fieldId] =\n field.type === 'timestamp'\n ? `${field.name} must be a date`\n : `${field.name} must be a number`\n break\n }\n if (rules.min != null && value < rules.min) {\n errors[fieldId] = `${field.name} must be ≥ ${rules.min}`\n } else if (rules.max != null && value > rules.max) {\n errors[fieldId] = `${field.name} must be ≤ ${rules.max}`\n }\n break\n case 'coordinates': {\n const coordinates = value as { latitude?: unknown; longitude?: unknown }\n if (\n !isFiniteNumber(coordinates?.latitude) ||\n !isFiniteNumber(coordinates?.longitude) ||\n Math.abs(coordinates.latitude) > 90 ||\n Math.abs(coordinates.longitude) > 180\n ) {\n errors[fieldId] = `${field.name} must be valid coordinates`\n }\n break\n }\n case 'sorted':\n if (!Array.isArray(value)) {\n errors[fieldId] = `${field.name} must be a list`\n }\n break\n case 'map':\n if (typeof value !== 'object' || Array.isArray(value)) {\n errors[fieldId] = `${field.name} must be a map`\n }\n break\n case 'reference':\n if (field.reference?.multiple) {\n if (\n !Array.isArray(value) ||\n value.some((entry) => typeof entry !== 'string' || !entry)\n ) {\n errors[fieldId] = `${field.name} must reference documents`\n }\n } else if (typeof value !== 'string' || !value) {\n errors[fieldId] = `${field.name} must reference a document`\n }\n break\n case 'bytes':\n case 'nil':\n break\n }\n }\n // Custom field types (AGL-434): plugin validators run after the base\n // checks, only on fields that passed them.\n for (const fieldId of model.order) {\n const field = model.fields[fieldId]\n if (!field?.customType || errors[fieldId]) continue\n const customError = validateCustomFieldValue(\n field.customType,\n values[fieldId],\n )\n if (customError) errors[fieldId] = `${field.name}: ${customError}`\n }\n return errors\n}\n\n/** Storage value → grid display string (AGL-179). */\nexport function formatDatasetValue(\n field: DatasetFieldDefinition,\n value: unknown,\n): string {\n if (value == null || value === '') return ''\n switch (field.type) {\n case 'bool':\n return value === true ? '✓' : value === false ? '—' : String(value)\n case 'timestamp':\n return isFiniteNumber(value)\n ? new Date(value).toISOString().slice(0, 16).replace('T', ' ')\n : String(value)\n case 'coordinates': {\n const coordinates = value as { latitude?: number; longitude?: number }\n return isFiniteNumber(coordinates?.latitude) &&\n isFiniteNumber(coordinates?.longitude)\n ? `${coordinates.latitude}, ${coordinates.longitude}`\n : String(value)\n }\n case 'sorted':\n return Array.isArray(value) ? value.join(', ') : String(value)\n case 'map':\n try {\n return JSON.stringify(value)\n } catch {\n return String(value)\n }\n default:\n return String(value)\n }\n}\n\n/**\n * Storage value → form-input string (AGL-179): the inverse of\n * `coerceDocumentValues` for populating type-appropriate inputs\n * (timestamps as `datetime-local` values, coordinates as \"lat, lon\").\n */\nexport function datasetValueToInput(\n field: DatasetFieldDefinition,\n value: unknown,\n): string {\n if (value == null) return ''\n if (field.type === 'timestamp' && isFiniteNumber(value)) {\n return new Date(value).toISOString().slice(0, 16)\n }\n if (field.type === 'bool') {\n return value === true ? 'true' : value === false ? 'false' : String(value)\n }\n if (field.type === 'coordinates' || field.type === 'sorted') {\n return formatDatasetValue(field, value)\n }\n if (field.type === 'map') return formatDatasetValue(field, value)\n return String(value)\n}\n\nconst BOOL_TRUE_WORDS = new Set(['true', 'yes', 'on', '1'])\nconst BOOL_FALSE_WORDS = new Set(['false', 'no', 'off', '0'])\n\n/**\n * Coerces user-input strings (form fields, CSV cells) into storage form\n * per the field type. Unparseable input is passed through untouched so\n * `validateDocument` reports it instead of silently mangling it.\n */\nexport function coerceDocumentValues(\n model: DatasetModel,\n input: Record<string, unknown>,\n): Record<string, unknown> {\n const values: Record<string, unknown> = {}\n for (const fieldId of model.order) {\n const field = model.fields[fieldId]\n const raw = input[fieldId]\n if (!field || raw == null || raw === '') continue\n if (typeof raw !== 'string') {\n values[fieldId] = raw\n continue\n }\n switch (field.type) {\n case 'bool': {\n // The words a form control or a CSV cell says yes and no with: a\n // lone checkbox posts `on`, a spreadsheet exports `TRUE` or `1`.\n const word = raw.trim().toLowerCase()\n values[fieldId] = BOOL_TRUE_WORDS.has(word)\n ? true\n : BOOL_FALSE_WORDS.has(word)\n ? false\n : raw\n break\n }\n case 'int32':\n case 'int64': {\n const parsed = Number(raw)\n values[fieldId] = Number.isInteger(parsed) ? parsed : raw\n break\n }\n case 'float': {\n const parsed = Number(raw)\n values[fieldId] = Number.isFinite(parsed) ? parsed : raw\n break\n }\n case 'timestamp': {\n const millis = Date.parse(raw)\n values[fieldId] = Number.isFinite(millis) ? millis : raw\n break\n }\n case 'coordinates': {\n const [latitude, longitude] = raw.split(',').map((part) => Number(part.trim()))\n values[fieldId] =\n Number.isFinite(latitude) && Number.isFinite(longitude)\n ? { latitude, longitude }\n : raw\n break\n }\n case 'sorted':\n values[fieldId] = raw\n .split(',')\n .map((part) => part.trim())\n .filter(Boolean)\n break\n case 'map':\n try {\n values[fieldId] = JSON.parse(raw)\n } catch {\n values[fieldId] = raw\n }\n break\n case 'reference':\n values[fieldId] = field.reference?.multiple\n ? raw\n .split(',')\n .map((part) => part.trim())\n .filter(Boolean)\n : raw\n break\n default:\n values[fieldId] = raw\n }\n }\n return values\n}\n\n/**\n * Every reference id a record holds, flattened out of its `reference` fields\n * into one de-duplicated list.\n *\n * A reference field stores either a single target id or — when\n * `reference.multiple` is set — an array of them, and a model may declare\n * several. Both shapes flatten into the same list because the question asked\n * of it is never \"which field\", it is \"does this record still point at that\n * document\".\n *\n * Fields are read from `order` UNIONED with the keys of `fields`. Every other\n * pass over a model walks `order` alone, which is right for anything the user\n * sees — but a reference declared without a display slot still holds a real\n * FKey, and an integrity index that skipped it would under-report.\n */\nexport function datasetReferencedIds(\n model: DatasetModel,\n values: Record<string, unknown> | undefined,\n): string[] {\n const ids = new Set<string>()\n const fieldIds = new Set([\n ...(model.order ?? []),\n ...Object.keys(model.fields ?? {}),\n ])\n for (const fieldId of fieldIds) {\n if (model.fields?.[fieldId]?.type !== 'reference') continue\n const stored = values?.[fieldId]\n for (const entry of Array.isArray(stored) ? stored : [stored]) {\n const id = typeof entry === 'string' ? entry.trim() : ''\n if (id) ids.add(id)\n }\n }\n return [...ids]\n}\n\n/**\n * The integrity index a record write carries, so referential integrity can be\n * decided by a QUERY rather than by the rows a listener happened to fetch.\n *\n * Deleting a record has to answer \"is anything still pointing at this?\", and\n * `restrict` refuses the delete on a yes while `setNull` strips the FKey. That\n * question cannot be asked where the answer is stored: dataset fields are\n * user-defined, so `records.values` carries a deliberate index exemption in\n * `cloud/firebase-firestore.indexes.json` — auto-indexing an unbounded map\n * blows Firestore's per-document index-entry limit — and\n * `where('values.<fieldId>', '==', id)` is therefore FAILED_PRECONDITION.\n * Reading a page of records and filtering them in the browser answers only for\n * the rows in that page, which is a browse window standing in for a\n * correctness check: a reference held outside it reads as no reference at all,\n * the delete proceeds, and `restrict` silently fails to restrict.\n *\n * `referencedIds` is that same reference, denormalized to a top-level array\n * Firestore will index, so one `array-contains` reaches every record.\n *\n * ⚠️ OMITTED when a record references nothing, rather than written as `[]`.\n * `isNotEmpty` is served as `!= null` and an empty array is not null, so a\n * record stamped `[]` answers \"holds a reference\" for a dataset that holds\n * none.\n *\n * ⚠️ Spread this at EVERY write that sets a record's `values`. A write that\n * sets values without it leaves the index describing the PREVIOUS values, and\n * a stale integrity index is the exact failure it exists to prevent — with the\n * UI reporting the record as safe to delete. On a merging write use\n * `datasetIntegrityUpdate` instead: omission leaves a stale array in place\n * where clearing the last reference has to remove the field.\n */\nexport function datasetIntegrityFields(\n model: DatasetModel,\n values: Record<string, unknown> | undefined,\n): {\n referencedIds?: string[]\n filterKeys?: string[]\n filterValues?: DatasetFilterValues\n} {\n const referencedIds = datasetReferencedIds(model, values)\n // The records table's filter fields (`datasetFilterKeys`,\n // `datasetFilterValues`) travel on the same writes for the same reason: a\n // record written without them is invisible to every filter the query\n // serves. Omitted when empty, like `referencedIds`.\n const filterKeys = datasetFilterKeys(model, values)\n const filterValues = datasetFilterValues(model, values)\n return {\n ...(referencedIds.length ? { referencedIds } : {}),\n ...(filterKeys.length ? { filterKeys } : {}),\n ...(Object.keys(filterValues).length ? { filterValues } : {}),\n }\n}\n\n/**\n * `datasetIntegrityFields` for a MERGING write (`update`, `set` with\n * `mergeFields`), where leaving the field out preserves what is stored\n * rather than clearing it.\n *\n * A record whose last reference is cleared has to have the field REMOVED, or\n * it goes on answering the `array-contains` for a document it no longer points\n * at — a `restrict` that refuses a delete nothing is holding. `clear` is the\n * caller's delete sentinel: `deleteField()` in the web SDK,\n * `FieldValue.delete()` in the Admin SDK. It is passed in rather than imported\n * because this module is shared by both and must stay SDK-free. The filter\n * fields are cleared the same way, so a record emptied of every filterable\n * value stops answering the filters its old values did.\n *\n * ⚠️ `filterValues` is a MAP, and it is written WHOLE: `update` and\n * `mergeFields` replace a field outright, so a value cleared since the last\n * write leaves the map with it. `set(…, { merge: true })` does NOT — it merges\n * maps key by key and would keep the cleared value answering its old\n * equality — so a record write never uses it; list the fields in\n * `mergeFields` instead.\n */\nexport function datasetIntegrityUpdate<TClear>(\n model: DatasetModel,\n values: Record<string, unknown> | undefined,\n clear: TClear,\n): {\n referencedIds: string[] | TClear\n filterKeys: string[] | TClear\n filterValues: DatasetFilterValues | TClear\n} {\n const referencedIds = datasetReferencedIds(model, values)\n const filterKeys = datasetFilterKeys(model, values)\n const filterValues = datasetFilterValues(model, values)\n return {\n referencedIds: referencedIds.length ? referencedIds : clear,\n filterKeys: filterKeys.length ? filterKeys : clear,\n filterValues: Object.keys(filterValues).length ? filterValues : clear,\n }\n}\n\n/**\n * A dataset record's FILTER TOKENS: every word-level question the records\n * table can ask of a record, flattened into one array of strings Firestore\n * indexes on its own. Its twin, {@link datasetFilterValues}, holds the\n * equalities.\n *\n * ## Why these fields, and not the values\n *\n * A record's fields live under `values`, a user-defined, unbounded map that\n * the index configuration exempts from indexing — auto-indexing it can exceed\n * Firestore's per-document index-entry limit — so `where('values.<field>', …)`\n * is refused. A composite index per dataset would need an admin call per\n * dataset, runs into the project's composite-index cap, and is deleted by the\n * next `firestore:indexes` deploy of a file that does not list it.\n *\n * `filterKeys` and `filterValues` need none of that. Firestore's AUTOMATIC\n * single-field indexes serve `where('filterKeys', 'array-contains', token)`\n * and `where('filterValues.<field>', '==', value)`, and every automatic index\n * ends in the document name — so any number of those equalities and ONE\n * `array-contains`, under `orderBy(documentId())`, compose by index merging,\n * with no composite index and no index deploy, on any dataset of any project\n * (AGL-3321).\n *\n * ## The token grammar\n *\n * `f:<fieldId>=<value>` a field equals a value. Enum (a text field with\n * `validation.options`) values are kept exactly;\n * plain text is lower-cased, trimmed and clipped to\n * {@link DATASET_FILTER_VALUE_MAX} characters;\n * booleans are `true`/`false`; numbers are\n * `String(number)`; a `sorted` list contributes one\n * token per member.\n * `f:<fieldId>^<prefix>` a word of a plain text field starts with this.\n * `s:<prefix>` a word of ANY text value (enums and list members\n * included) starts with this — the quick search.\n *\n * Timestamps, references, maps, bytes, coordinates and nil fields carry no\n * field tokens: a timestamp is asked in ranges, which one token cannot serve,\n * and the rest are not asked about by value.\n *\n * The array is sorted, de-duplicated and capped at\n * {@link DATASET_FILTER_KEYS_MAX}. Past the cap, the `=` tokens are kept\n * first, then the per-field word prefixes, then the search prefixes, so a\n * very long record loses search reach before it loses exact matches.\n */\nexport const DATASET_FILTER_KEYS_MAX = 500\n\n/** Plain text values are clipped to this many characters in an `=` token. */\nexport const DATASET_FILTER_VALUE_MAX = 64\n/** Word prefixes run from 1 to this many characters. */\nexport const DATASET_FILTER_PREFIX_MAX = 12\n/** Only the first this-many words of a value contribute prefixes. */\nexport const DATASET_FILTER_WORDS_MAX = 40\n\n/** One clause of the records table's filter: `{ field, op, value }`. */\nexport interface DatasetFilterClause {\n field: string\n op: string\n value: string\n}\n\n/**\n * The words of a text value: split on anything that is not a letter or a\n * digit, lower-cased, at most {@link DATASET_FILTER_WORDS_MAX} of them.\n */\nexport function datasetFilterWords(text: string): string[] {\n return String(text)\n .toLowerCase()\n .split(/[^\\p{L}\\p{N}]+/u)\n .filter(Boolean)\n .slice(0, DATASET_FILTER_WORDS_MAX)\n}\n\n/** A word's prefixes, 1 to {@link DATASET_FILTER_PREFIX_MAX} characters. */\nfunction prefixes(word: string): string[] {\n const chars = Array.from(word).slice(0, DATASET_FILTER_PREFIX_MAX)\n return chars.map((_char, at) => chars.slice(0, at + 1).join(''))\n}\n\n/** A word clipped the way its stored prefixes are. */\nfunction clipWord(word: string): string {\n return Array.from(word).slice(0, DATASET_FILTER_PREFIX_MAX).join('')\n}\n\nconst isEnum = (field: DatasetFieldDefinition): boolean =>\n field.type === 'text' && (field.validation?.options?.length ?? 0) > 0\n\nconst isNumeric = (field: DatasetFieldDefinition): boolean =>\n field.type === 'int32' || field.type === 'int64' || field.type === 'float'\n\n/**\n * A stored value as text, or null. Numbers are accepted because a form or an\n * automation stores every value as text and an import may do the reverse.\n */\nfunction asText(value: unknown): string | null {\n if (typeof value === 'string') return value\n if (typeof value === 'number' && Number.isFinite(value)) return String(value)\n return null\n}\n\n/**\n * Plain text as its stored key — its `=` token's value and its\n * `filterValues` entry: lower-cased, trimmed, clipped to\n * {@link DATASET_FILTER_VALUE_MAX} characters. What the records table asks a\n * typed value to equal.\n */\nexport function datasetFilterTextKey(value: string): string {\n return Array.from(value.trim().toLowerCase())\n .slice(0, DATASET_FILTER_VALUE_MAX)\n .join('')\n}\nconst textKey = datasetFilterTextKey\n\n/** A stored number (or its text form) as its `=` token's value. */\nfunction numberKey(value: unknown): string | null {\n const number =\n typeof value === 'number'\n ? value\n : typeof value === 'string' && value.trim() !== ''\n ? Number(value)\n : Number.NaN\n return Number.isFinite(number) ? String(number) : null\n}\n\n/** A stored boolean (or its text form) as its `=` token's value. */\nfunction boolKey(value: unknown): string | null {\n if (typeof value === 'boolean') return String(value)\n if (value === 'true' || value === 'false') return value\n return null\n}\n\n/** Every field a model declares, in display order and then the rest. */\nfunction modelFieldIds(model: DatasetModel): string[] {\n return [...new Set([...(model.order ?? []), ...Object.keys(model.fields ?? {})])]\n}\n\n/** The tokens described in {@link DATASET_FILTER_KEYS_MAX}'s comment. */\nexport function datasetFilterKeys(\n model: DatasetModel,\n values: Record<string, unknown> | undefined,\n): string[] {\n const exact: string[] = []\n const fieldWords: string[] = []\n const search: string[] = []\n const searchable = (text: string) => {\n for (const word of datasetFilterWords(text)) {\n for (const prefix of prefixes(word)) search.push(`s:${prefix}`)\n }\n }\n for (const fieldId of modelFieldIds(model)) {\n const field = model.fields?.[fieldId]\n const stored = values?.[fieldId]\n if (!field || stored == null) continue\n if (field.type === 'text') {\n const text = asText(stored)\n if (text == null || !text.trim()) continue\n if (isEnum(field)) {\n exact.push(`f:${fieldId}=${text}`)\n } else {\n exact.push(`f:${fieldId}=${textKey(text)}`)\n for (const word of datasetFilterWords(text)) {\n for (const prefix of prefixes(word)) {\n fieldWords.push(`f:${fieldId}^${prefix}`)\n }\n }\n }\n searchable(text)\n } else if (field.type === 'bool') {\n const key = boolKey(stored)\n if (key) exact.push(`f:${fieldId}=${key}`)\n } else if (isNumeric(field)) {\n const key = numberKey(stored)\n if (key) exact.push(`f:${fieldId}=${key}`)\n } else if (field.type === 'sorted') {\n for (const member of Array.isArray(stored) ? stored : [stored]) {\n const text = asText(member)?.trim()\n if (!text) continue\n exact.push(`f:${fieldId}=${text}`)\n searchable(text)\n }\n }\n }\n const kept = [...new Set([...exact, ...fieldWords, ...search])].slice(\n 0,\n DATASET_FILTER_KEYS_MAX,\n )\n return kept.sort()\n}\n\n/** A record's `filterValues`: field id → the value an equality asks for. */\nexport type DatasetFilterValues = Record<string, string | number | boolean>\n\n/**\n * Field ids a query can name as `filterValues.<id>`. A path string splits on\n * `.`, and the SDKs refuse `~ * / [ ]` in one; the model editor allows only\n * letters, digits and underscores, but a v1 dataset's column names were\n * never checked. Backticks are refused too, as the escape a path would need.\n */\nconst FILTER_VALUE_ID = /^[^.~*/[\\]`]+$/\n\n/**\n * The query path of a field's `filterValues` entry, or null for a field id\n * no path can name — such a field is stamped no entry, and the records table\n * offers it no equality (its `contains`, served by `filterKeys`, stands).\n */\nexport function datasetFilterValuePath(fieldId: string): string | null {\n return FILTER_VALUE_ID.test(fieldId) && !/^__.*__$/.test(fieldId)\n ? `filterValues.${fieldId}`\n : null\n}\n\n/**\n * A dataset record's FILTER VALUES: `{ [fieldId]: value }`, one scalar per\n * field an equality can be asked of, so the records table puts every\n * equality on its query (AGL-3321).\n *\n * enum text (`validation.options`) the value exactly, as its `=` token;\n * plain text {@link datasetFilterTextKey};\n * bool a boolean;\n * int32 / int64 / float a number.\n *\n * A form or an automation stores every value as text, so `'19.50'` is the\n * number 19.5 and `'true'` the boolean, as in {@link datasetFilterKeys}.\n * Fields with no value, and timestamps, lists, references, maps, bytes,\n * coordinates and nil fields, carry no entry: a list is asked by member\n * (`f:<id>=<member>` in `filterKeys`), and the rest are not asked about by\n * value.\n *\n * ## What it costs\n *\n * Unlike `values`, this map is NOT exempt from indexing — that is its whole\n * point. Each entry is a scalar and costs two automatic index entries\n * (ascending, descending), so a record costs at most two per model field —\n * bounded by the model's field count (the `/v1` API caps a model at 100\n * fields), far inside Firestore's 40,000 entries per document, where\n * `values` was unbounded because a `map` or `sorted` value may hold anything.\n */\nexport function datasetFilterValues(\n model: DatasetModel,\n values: Record<string, unknown> | undefined,\n): DatasetFilterValues {\n const out: DatasetFilterValues = {}\n for (const fieldId of modelFieldIds(model)) {\n const field = model.fields?.[fieldId]\n const stored = values?.[fieldId]\n if (!field || stored == null || !datasetFilterValuePath(fieldId)) continue\n if (field.type === 'text') {\n const text = asText(stored)\n if (text == null || !text.trim()) continue\n out[fieldId] = isEnum(field) ? text : textKey(text)\n } else if (field.type === 'bool') {\n const key = boolKey(stored)\n if (key) out[fieldId] = key === 'true'\n } else if (isNumeric(field)) {\n const key = numberKey(stored)\n if (key) out[fieldId] = Number(key)\n }\n }\n return out\n}\n\n/**\n * The `filterKeys` token a word-level clause asks for, or null when it is\n * not one:\n *\n * - plain text `contains` → the `^` token of the value's FIRST word, so a\n * `contains` is a word-prefix match, not a mid-string one, and one word\n * of several is asked (the records table says so);\n * - list `contains` (and `equals`) → the member's `=` token;\n * - enum, boolean, number and plain text `equals` → the `=` token of the\n * value. The records table asks these of `filterValues` instead, which\n * composes with a `contains`; the token remains what the quick search and\n * older readers match.\n * - everything else — ranges, dates, `isEmpty`, `isAnyOf`, negations — null.\n *\n * `clause.field` is the field id. The operator names are the grid's: a\n * select's `equals`, a number's `=`, a boolean's `is`, a list's `contains`.\n */\nexport function datasetFilterToken(\n model: DatasetModel,\n clause: DatasetFilterClause,\n): string | null {\n const field = model.fields?.[clause.field]\n if (!field) return null\n const { op } = clause\n const value = String(clause.value ?? '')\n if (!value.trim()) return null\n const equals = op === 'equals' || op === '=' || op === 'is'\n if (field.type === 'text') {\n if (isEnum(field)) return equals ? `f:${clause.field}=${value}` : null\n if (equals) return `f:${clause.field}=${textKey(value)}`\n if (op === 'contains') {\n const [first] = datasetFilterWords(value)\n return first ? `f:${clause.field}^${clipWord(first)}` : null\n }\n return null\n }\n if (field.type === 'bool') {\n const key = boolKey(value.trim())\n return equals && key ? `f:${clause.field}=${key}` : null\n }\n if (isNumeric(field)) {\n const key = numberKey(value)\n return equals && key ? `f:${clause.field}=${key}` : null\n }\n if (field.type === 'sorted') {\n return equals || op === 'contains' ? `f:${clause.field}=${value.trim()}` : null\n }\n return null\n}\n\n/**\n * The quick-search token for one typed word, or null for a word with no\n * letters or digits. A word with punctuation inside it is asked by its first\n * run — split the search text with {@link datasetFilterWords} to ask for\n * every run.\n */\nexport function datasetSearchToken(word: string): string | null {\n const [first] = datasetFilterWords(word)\n return first ? `s:${clipWord(first)}` : null\n}\n"],"names":["validateCustomFieldValue","humanizeDatasetFieldId","DATASET_FIELD_TYPES","DATASET_FIELD_TYPE_LABELS","text","bool","int32","int64","float","timestamp","coordinates","map","sorted","bytes","nil","reference","deriveModelFromFields","fields","model","order","name","type","push","modelFromFieldEntries","entries","entry","id","effectiveDatasetModel","dataset","length","isFiniteNumber","value","Number","isFinite","validateDocument","values","errors","fieldId","field","required","validation","rules","min","max","regex","RegExp","test","options","includes","join","isInteger","latitude","longitude","Math","abs","Array","isArray","multiple","some","customType","customError","formatDatasetValue","String","Date","toISOString","slice","replace","JSON","stringify","datasetValueToInput","BOOL_TRUE_WORDS","Set","BOOL_FALSE_WORDS","coerceDocumentValues","input","raw","word","trim","toLowerCase","has","parsed","millis","parse","split","part","filter","Boolean","datasetReferencedIds","ids","fieldIds","Object","keys","stored","add","datasetIntegrityFields","referencedIds","filterKeys","datasetFilterKeys","filterValues","datasetFilterValues","datasetIntegrityUpdate","clear","DATASET_FILTER_KEYS_MAX","DATASET_FILTER_VALUE_MAX","DATASET_FILTER_PREFIX_MAX","DATASET_FILTER_WORDS_MAX","datasetFilterWords","prefixes","chars","from","_char","at","clipWord","isEnum","isNumeric","asText","datasetFilterTextKey","textKey","numberKey","number","NaN","boolKey","modelFieldIds","exact","fieldWords","search","searchable","prefix","key","member","kept","sort","FILTER_VALUE_ID","datasetFilterValuePath","out","datasetFilterToken","clause","op","equals","first","datasetSearchToken"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,wBAAwB,QAAQ,qCAAiC;AAC1E,SAAiCC,sBAAsB,QAAQ,gBAAY;AAkC3E,OAAO,MAAMC,sBAA0C;IACrD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED,2CAA2C,GAC3C,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|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Datasets (AGL-102): tabular data at `orgs/{orgId}/datasets/{id}` with a
|
|
19
|
-
* `records` subcollection, edited in the console Data card and consumed by
|
|
20
|
-
* repeatable components (AGL-103) via `{{item.field}}` bindings.
|
|
21
|
-
*/
|
|
22
|
-
import { type DatasetModel } from './dataset-models';
|
|
23
|
-
/** Dataset field name: starts with a letter; letters/digits/underscores. */
|
|
24
|
-
export declare const DATASET_FIELD_PATTERN: RegExp;
|
|
25
|
-
export interface HostDataset {
|
|
26
|
-
$id?: string;
|
|
27
|
-
displayName?: string;
|
|
28
|
-
/** Column names, in display order (v1; superseded by `model`). */
|
|
29
|
-
fields?: string[];
|
|
30
|
-
/** Typed model (AGL-177); when absent, derive from `fields`. */
|
|
31
|
-
model?: import('./dataset-models').DatasetModel;
|
|
32
|
-
/** dod.ts Schema.Name shape (AGL-178). */
|
|
33
|
-
names?: {
|
|
34
|
-
singular?: string;
|
|
35
|
-
plural?: string;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Which sites may see this dataset (AGL-1037). Absent = org-wide, until
|
|
39
|
-
* the AGL-1040 backfill stamps it. See `app-utils/scope-tokens`.
|
|
40
|
-
*/
|
|
41
|
-
visibleTo?: import('../foundation').ScopeToken[];
|
|
42
|
-
}
|
|
43
|
-
export interface HostDatasetRecord {
|
|
44
|
-
$id?: string;
|
|
45
|
-
/**
|
|
46
|
-
* Field → value, in storage form per the field's type (see
|
|
47
|
-
* `dataset-models`). Rows written by a form or an automation step before
|
|
48
|
-
* AGL-2773 hold every value as text; readers accept both.
|
|
49
|
-
*/
|
|
50
|
-
values?: Record<string, unknown>;
|
|
51
|
-
/** Row position in the editor and in repeated output. */
|
|
52
|
-
order?: number;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* A human field entry from the quick creator: the stable id plus the
|
|
56
|
-
* display name shown in table headers and bindings pickers (AGL-558).
|
|
57
|
-
*/
|
|
58
|
-
export interface DatasetFieldEntry {
|
|
59
|
-
id: string;
|
|
60
|
-
name: string;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Stable field id from a human name: "Roast preference" → "roast_preference".
|
|
64
|
-
* Mirrors DATASET_FIELD_PATTERN; returns '' when nothing salvageable.
|
|
65
|
-
*/
|
|
66
|
-
export declare function slugifyDatasetFieldId(name: string): string;
|
|
67
|
-
/**
|
|
68
|
-
* Default reference id for a new field (AGL-578): the `slugifyDatasetFieldId`
|
|
69
|
-
* slug, suffixed (`_2`, `_3`, …) to stay unique within the dataset. `taken`
|
|
70
|
-
* holds the ids already in use (compared case-insensitively). Returns '' when
|
|
71
|
-
* the name yields nothing valid. The user can override the result.
|
|
72
|
-
*/
|
|
73
|
-
export declare function defaultDatasetFieldId(name: string, taken: ReadonlySet<string>): string;
|
|
74
|
-
/**
|
|
75
|
-
* Validate a user-entered reference id (AGL-578): non-empty, matches
|
|
76
|
-
* `DATASET_FIELD_PATTERN`, and unique within the dataset (`taken` = ids already
|
|
77
|
-
* used, compared case-insensitively). Returns an error message, or null when
|
|
78
|
-
* the id is usable.
|
|
79
|
-
*/
|
|
80
|
-
export declare function validateDatasetFieldId(id: string, taken: ReadonlySet<string>): string | null;
|
|
81
|
-
/** Display fallback for raw ids: "roast_preference" → "Roast preference". */
|
|
82
|
-
export declare function humanizeDatasetFieldId(id: string): string;
|
|
83
|
-
/**
|
|
84
|
-
* Parses a comma/newline separated list of HUMAN field names into
|
|
85
|
-
* {id, name} entries — "Roast preference" keeps its pretty name and gets
|
|
86
|
-
* the stable id `roast_preference` (AGL-558). Plain snake_case keys
|
|
87
|
-
* still work and pick up a humanized display name. Duplicate ids and
|
|
88
|
-
* unsalvageable entries are dropped rather than failing the set.
|
|
89
|
-
*/
|
|
90
|
-
export declare function parseDatasetFieldEntries(input: string): DatasetFieldEntry[];
|
|
91
|
-
/**
|
|
92
|
-
* Parses a comma/newline separated field list into valid unique names;
|
|
93
|
-
* invalid entries are dropped rather than failing the whole set.
|
|
94
|
-
*/
|
|
95
|
-
export declare function parseDatasetFields(input: string): string[];
|
|
96
|
-
/** Record values restricted to the dataset's declared fields. */
|
|
97
|
-
export declare function sanitizeRecordValues(fields: string[], input: Record<string, unknown> | null | undefined): Record<string, string>;
|
|
98
|
-
/**
|
|
99
|
-
* The submitted values a dataset write would store, picked by field id and
|
|
100
|
-
* left as they arrived (AGL-556). With a `fieldMap` (submitted key → stable
|
|
101
|
-
* model fieldId), mapped values land under the mapped fieldId — so renamed
|
|
102
|
-
* schema fields keep receiving data — and entries whose fieldId isn't in the
|
|
103
|
-
* model are dropped. Submitted keys without a mapping (and calls without a
|
|
104
|
-
* map) fall back to the legacy name-intersection against the model's field
|
|
105
|
-
* ids, matching `sanitizeRecordValues`.
|
|
106
|
-
*/
|
|
107
|
-
export declare function pickDatasetRecordInput(dataset: {
|
|
108
|
-
model?: DatasetModel;
|
|
109
|
-
fields?: string[];
|
|
110
|
-
}, input: Record<string, unknown> | null | undefined, fieldMap?: Record<string, string> | null): Record<string, unknown>;
|
|
111
|
-
/** A dataset record write, checked against the dataset's model. */
|
|
112
|
-
export interface DatasetRecordWrite {
|
|
113
|
-
/**
|
|
114
|
-
* The model fields this write supplied a value for, before coercion. Empty
|
|
115
|
-
* means nothing submitted matched a field of the dataset.
|
|
116
|
-
*/
|
|
117
|
-
matched: string[];
|
|
118
|
-
/**
|
|
119
|
-
* The values to store, in storage form (see `dataset-models`): numbers,
|
|
120
|
-
* booleans, epoch millis and so on per the field's type. For a merge, the
|
|
121
|
-
* existing values with this write's laid over them.
|
|
122
|
-
*/
|
|
123
|
-
values: Record<string, unknown>;
|
|
124
|
-
/** fieldId → the reason it was refused. Empty when the write may land. */
|
|
125
|
-
errors: Record<string, string>;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* A record write from a form submission or an automation step, coerced and
|
|
129
|
-
* validated against the dataset's model (AGL-2773, option B).
|
|
130
|
-
*
|
|
131
|
-
* These writes used to store `String(value)` for every field and check
|
|
132
|
-
* nothing, so a form could put `abc` in a number column and skip a required
|
|
133
|
-
* one. They now run the same `coerceDocumentValues` + `validateDocument` pair
|
|
134
|
-
* the console and `/v1` do: a value is stored in its field's type, and a
|
|
135
|
-
* record with any refused field is not written at all. The caller decides
|
|
136
|
-
* what a refusal costs — a form keeps the Inbox submission, a run records a
|
|
137
|
-
* failed step.
|
|
138
|
-
*
|
|
139
|
-
* `existing` makes it a merge (update-or-append's update leg): this write's
|
|
140
|
-
* values are laid over the stored ones, and only the fields THIS write
|
|
141
|
-
* supplied are held to the model. A stored row written as text before this
|
|
142
|
-
* change keeps its text values and is not refused for them — the reads have
|
|
143
|
-
* always rendered them, and a merge that touched `email` must not fail over a
|
|
144
|
-
* legacy `price` of `"12"` it never sent.
|
|
145
|
-
*
|
|
146
|
-
* Custom field types validate only once registered: call
|
|
147
|
-
* `ensureDeclaredCustomFieldTypes(model)` before this on a server path.
|
|
148
|
-
*/
|
|
149
|
-
export declare function prepareDatasetRecordWrite(dataset: {
|
|
150
|
-
model?: DatasetModel;
|
|
151
|
-
fields?: string[];
|
|
152
|
-
}, input: Record<string, unknown> | null | undefined, options?: {
|
|
153
|
-
fieldMap?: Record<string, string> | null;
|
|
154
|
-
existing?: Record<string, unknown> | null;
|
|
155
|
-
}): DatasetRecordWrite;
|
|
156
|
-
/**
|
|
157
|
-
* A refused write's errors as one line, in the model's field order:
|
|
158
|
-
* `Stars must be a whole number; Email is required`.
|
|
159
|
-
*/
|
|
160
|
-
export declare function describeDatasetRecordErrors(errors: Record<string, string>): string;
|
|
161
|
-
/**
|
|
162
|
-
* The name a dataset is shown under: `displayName`, which is what every create
|
|
163
|
-
* path writes (AGL-536), then the pre-migration `name`. Blank when the document
|
|
164
|
-
* carries neither.
|
|
165
|
-
*/
|
|
166
|
-
export declare function datasetDisplayName(dataset: {
|
|
167
|
-
displayName?: unknown;
|
|
168
|
-
name?: unknown;
|
|
169
|
-
} | null | undefined): string;
|
|
170
|
-
/** Records sorted by their editor order (then id for stability). */
|
|
171
|
-
export declare function sortDatasetRecords<T extends HostDatasetRecord>(records: T[]): T[];
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
-
/**
|
|
3
|
-
* @license
|
|
4
|
-
* Copyright 2026 Aglyn LLC
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/ /**
|
|
18
|
-
* Datasets (AGL-102): tabular data at `orgs/{orgId}/datasets/{id}` with a
|
|
19
|
-
* `records` subcollection, edited in the console Data card and consumed by
|
|
20
|
-
* repeatable components (AGL-103) via `{{item.field}}` bindings.
|
|
21
|
-
*/ import { coerceDocumentValues, effectiveDatasetModel, validateDocument } from "./dataset-models.js";
|
|
22
|
-
/** Dataset field name: starts with a letter; letters/digits/underscores. */ export const DATASET_FIELD_PATTERN = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
23
|
-
/**
|
|
24
|
-
* Stable field id from a human name: "Roast preference" → "roast_preference".
|
|
25
|
-
* Mirrors DATASET_FIELD_PATTERN; returns '' when nothing salvageable.
|
|
26
|
-
*/ export function slugifyDatasetFieldId(name) {
|
|
27
|
-
const slug = name.trim().toLowerCase().replace(/[\s-]+/g, '_').replace(/[^a-z0-9_]/g, '').replace(/^[0-9_]+/, '').replace(/_+$/, '');
|
|
28
|
-
return DATASET_FIELD_PATTERN.test(slug) ? slug : '';
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Default reference id for a new field (AGL-578): the `slugifyDatasetFieldId`
|
|
32
|
-
* slug, suffixed (`_2`, `_3`, …) to stay unique within the dataset. `taken`
|
|
33
|
-
* holds the ids already in use (compared case-insensitively). Returns '' when
|
|
34
|
-
* the name yields nothing valid. The user can override the result.
|
|
35
|
-
*/ export function defaultDatasetFieldId(name, taken) {
|
|
36
|
-
const base = slugifyDatasetFieldId(name);
|
|
37
|
-
if (!base) return '';
|
|
38
|
-
const used = new Set([
|
|
39
|
-
...taken
|
|
40
|
-
].map((id)=>id.toLowerCase()));
|
|
41
|
-
let candidate = base;
|
|
42
|
-
let suffix = 2;
|
|
43
|
-
while(used.has(candidate.toLowerCase()))candidate = `${base}_${suffix++}`;
|
|
44
|
-
return candidate;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Validate a user-entered reference id (AGL-578): non-empty, matches
|
|
48
|
-
* `DATASET_FIELD_PATTERN`, and unique within the dataset (`taken` = ids already
|
|
49
|
-
* used, compared case-insensitively). Returns an error message, or null when
|
|
50
|
-
* the id is usable.
|
|
51
|
-
*/ export function validateDatasetFieldId(id, taken) {
|
|
52
|
-
const trimmed = id.trim();
|
|
53
|
-
if (!trimmed) return 'A reference ID is required';
|
|
54
|
-
if (!DATASET_FIELD_PATTERN.test(trimmed)) return 'Start with a letter; use only letters, numbers, and underscores';
|
|
55
|
-
const used = new Set([
|
|
56
|
-
...taken
|
|
57
|
-
].map((existing)=>existing.toLowerCase()));
|
|
58
|
-
if (used.has(trimmed.toLowerCase())) return 'Another field already uses this reference ID';
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
/** Display fallback for raw ids: "roast_preference" → "Roast preference". */ export function humanizeDatasetFieldId(id) {
|
|
62
|
-
const words = id.replace(/_/g, ' ').trim();
|
|
63
|
-
return words ? words.charAt(0).toUpperCase() + words.slice(1) : id;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Parses a comma/newline separated list of HUMAN field names into
|
|
67
|
-
* {id, name} entries — "Roast preference" keeps its pretty name and gets
|
|
68
|
-
* the stable id `roast_preference` (AGL-558). Plain snake_case keys
|
|
69
|
-
* still work and pick up a humanized display name. Duplicate ids and
|
|
70
|
-
* unsalvageable entries are dropped rather than failing the set.
|
|
71
|
-
*/ export function parseDatasetFieldEntries(input) {
|
|
72
|
-
const seen = new Set();
|
|
73
|
-
const entries = [];
|
|
74
|
-
for (const raw of input.split(/[,\n]/)){
|
|
75
|
-
const trimmed = raw.trim();
|
|
76
|
-
if (!trimmed) continue;
|
|
77
|
-
const id = slugifyDatasetFieldId(trimmed);
|
|
78
|
-
if (!id || seen.has(id)) continue;
|
|
79
|
-
seen.add(id);
|
|
80
|
-
entries.push({
|
|
81
|
-
id,
|
|
82
|
-
name: DATASET_FIELD_PATTERN.test(trimmed) ? humanizeDatasetFieldId(trimmed) : trimmed
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return entries;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Parses a comma/newline separated field list into valid unique names;
|
|
89
|
-
* invalid entries are dropped rather than failing the whole set.
|
|
90
|
-
*/ export function parseDatasetFields(input) {
|
|
91
|
-
const seen = new Set();
|
|
92
|
-
const fields = [];
|
|
93
|
-
for (const raw of input.split(/[,\n]/)){
|
|
94
|
-
const name = raw.trim();
|
|
95
|
-
if (!DATASET_FIELD_PATTERN.test(name)) continue;
|
|
96
|
-
const key = name.toLowerCase();
|
|
97
|
-
if (seen.has(key)) continue;
|
|
98
|
-
seen.add(key);
|
|
99
|
-
fields.push(name);
|
|
100
|
-
}
|
|
101
|
-
return fields;
|
|
102
|
-
}
|
|
103
|
-
/** Record values restricted to the dataset's declared fields. */ export function sanitizeRecordValues(fields, input) {
|
|
104
|
-
const values = {};
|
|
105
|
-
for (const field of fields){
|
|
106
|
-
const value = input == null ? void 0 : input[field];
|
|
107
|
-
if (value == null) continue;
|
|
108
|
-
values[field] = String(value);
|
|
109
|
-
}
|
|
110
|
-
return values;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* The submitted values a dataset write would store, picked by field id and
|
|
114
|
-
* left as they arrived (AGL-556). With a `fieldMap` (submitted key → stable
|
|
115
|
-
* model fieldId), mapped values land under the mapped fieldId — so renamed
|
|
116
|
-
* schema fields keep receiving data — and entries whose fieldId isn't in the
|
|
117
|
-
* model are dropped. Submitted keys without a mapping (and calls without a
|
|
118
|
-
* map) fall back to the legacy name-intersection against the model's field
|
|
119
|
-
* ids, matching `sanitizeRecordValues`.
|
|
120
|
-
*/ export function pickDatasetRecordInput(dataset, input, fieldMap) {
|
|
121
|
-
const model = effectiveDatasetModel(dataset);
|
|
122
|
-
const map = fieldMap != null ? fieldMap : {};
|
|
123
|
-
const values = {};
|
|
124
|
-
for (const fieldId of model.order){
|
|
125
|
-
if (!model.fields[fieldId]) continue;
|
|
126
|
-
// A submitted key with an explicit mapping never doubles as a
|
|
127
|
-
// name-match — the mapping decides where it lands.
|
|
128
|
-
if (fieldId in map) continue;
|
|
129
|
-
const value = input == null ? void 0 : input[fieldId];
|
|
130
|
-
if (value == null) continue;
|
|
131
|
-
values[fieldId] = value;
|
|
132
|
-
}
|
|
133
|
-
for (const [submittedKey, fieldId] of Object.entries(map)){
|
|
134
|
-
if (typeof fieldId !== 'string' || !model.fields[fieldId]) continue;
|
|
135
|
-
const value = input == null ? void 0 : input[submittedKey];
|
|
136
|
-
if (value == null) continue;
|
|
137
|
-
values[fieldId] = value;
|
|
138
|
-
}
|
|
139
|
-
return values;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* A text field takes what an event payload carries as a number or a boolean
|
|
143
|
-
* as the text it reads as, which is what these writes always stored.
|
|
144
|
-
*/ function asTextInput(model, picked) {
|
|
145
|
-
const values = {};
|
|
146
|
-
for (const [fieldId, value] of Object.entries(picked)){
|
|
147
|
-
var _model_fields_fieldId;
|
|
148
|
-
const type = (_model_fields_fieldId = model.fields[fieldId]) == null ? void 0 : _model_fields_fieldId.type;
|
|
149
|
-
values[fieldId] = (type === 'text' || type === 'reference') && (typeof value === 'number' || typeof value === 'boolean') ? String(value) : value;
|
|
150
|
-
}
|
|
151
|
-
return values;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* A record write from a form submission or an automation step, coerced and
|
|
155
|
-
* validated against the dataset's model (AGL-2773, option B).
|
|
156
|
-
*
|
|
157
|
-
* These writes used to store `String(value)` for every field and check
|
|
158
|
-
* nothing, so a form could put `abc` in a number column and skip a required
|
|
159
|
-
* one. They now run the same `coerceDocumentValues` + `validateDocument` pair
|
|
160
|
-
* the console and `/v1` do: a value is stored in its field's type, and a
|
|
161
|
-
* record with any refused field is not written at all. The caller decides
|
|
162
|
-
* what a refusal costs — a form keeps the Inbox submission, a run records a
|
|
163
|
-
* failed step.
|
|
164
|
-
*
|
|
165
|
-
* `existing` makes it a merge (update-or-append's update leg): this write's
|
|
166
|
-
* values are laid over the stored ones, and only the fields THIS write
|
|
167
|
-
* supplied are held to the model. A stored row written as text before this
|
|
168
|
-
* change keeps its text values and is not refused for them — the reads have
|
|
169
|
-
* always rendered them, and a merge that touched `email` must not fail over a
|
|
170
|
-
* legacy `price` of `"12"` it never sent.
|
|
171
|
-
*
|
|
172
|
-
* Custom field types validate only once registered: call
|
|
173
|
-
* `ensureDeclaredCustomFieldTypes(model)` before this on a server path.
|
|
174
|
-
*/ export function prepareDatasetRecordWrite(dataset, input, options = {}) {
|
|
175
|
-
const model = effectiveDatasetModel(dataset);
|
|
176
|
-
const picked = pickDatasetRecordInput(dataset, input, options.fieldMap);
|
|
177
|
-
const matched = Object.keys(picked);
|
|
178
|
-
const coerced = coerceDocumentValues(model, asTextInput(model, picked));
|
|
179
|
-
if (!options.existing) {
|
|
180
|
-
return {
|
|
181
|
-
matched,
|
|
182
|
-
values: coerced,
|
|
183
|
-
errors: validateDocument(model, coerced)
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
const values = _extends({}, options.existing, coerced);
|
|
187
|
-
const errors = {};
|
|
188
|
-
for (const [fieldId, error] of Object.entries(validateDocument(model, values))){
|
|
189
|
-
if (fieldId in coerced) errors[fieldId] = error;
|
|
190
|
-
}
|
|
191
|
-
return {
|
|
192
|
-
matched,
|
|
193
|
-
values,
|
|
194
|
-
errors
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* A refused write's errors as one line, in the model's field order:
|
|
199
|
-
* `Stars must be a whole number; Email is required`.
|
|
200
|
-
*/ export function describeDatasetRecordErrors(errors) {
|
|
201
|
-
return Object.values(errors).join('; ');
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* The name a dataset is shown under: `displayName`, which is what every create
|
|
205
|
-
* path writes (AGL-536), then the pre-migration `name`. Blank when the document
|
|
206
|
-
* carries neither.
|
|
207
|
-
*/ export function datasetDisplayName(dataset) {
|
|
208
|
-
for (const candidate of [
|
|
209
|
-
dataset == null ? void 0 : dataset.displayName,
|
|
210
|
-
dataset == null ? void 0 : dataset.name
|
|
211
|
-
]){
|
|
212
|
-
if (typeof candidate === 'string' && candidate.trim()) {
|
|
213
|
-
return candidate.trim();
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
return '';
|
|
217
|
-
}
|
|
218
|
-
/** Records sorted by their editor order (then id for stability). */ export function sortDatasetRecords(records) {
|
|
219
|
-
return [
|
|
220
|
-
...records
|
|
221
|
-
].sort((a, b)=>{
|
|
222
|
-
var _a_order, _b_order, _a_$id, _b_$id;
|
|
223
|
-
return ((_a_order = a.order) != null ? _a_order : Number.MAX_SAFE_INTEGER) - ((_b_order = b.order) != null ? _b_order : Number.MAX_SAFE_INTEGER) || String((_a_$id = a.$id) != null ? _a_$id : '').localeCompare(String((_b_$id = b.$id) != null ? _b_$id : ''));
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
//# sourceMappingURL=datasets.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/datasets.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\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\n/**\n * Datasets (AGL-102): tabular data at `orgs/{orgId}/datasets/{id}` with a\n * `records` subcollection, edited in the console Data card and consumed by\n * repeatable components (AGL-103) via `{{item.field}}` bindings.\n */\n\nimport {\n coerceDocumentValues,\n type DatasetModel,\n effectiveDatasetModel,\n validateDocument,\n} from './dataset-models'\n\n/** Dataset field name: starts with a letter; letters/digits/underscores. */\nexport const DATASET_FIELD_PATTERN = /^[A-Za-z][A-Za-z0-9_]*$/\n\nexport interface HostDataset {\n $id?: string\n displayName?: string\n /** Column names, in display order (v1; superseded by `model`). */\n fields?: string[]\n /** Typed model (AGL-177); when absent, derive from `fields`. */\n model?: import('./dataset-models').DatasetModel\n /** dod.ts Schema.Name shape (AGL-178). */\n names?: { singular?: string; plural?: string }\n /**\n * Which sites may see this dataset (AGL-1037). Absent = org-wide, until\n * the AGL-1040 backfill stamps it. See `app-utils/scope-tokens`.\n */\n visibleTo?: import('../foundation').ScopeToken[]\n}\n\nexport interface HostDatasetRecord {\n $id?: string\n /**\n * Field → value, in storage form per the field's type (see\n * `dataset-models`). Rows written by a form or an automation step before\n * AGL-2773 hold every value as text; readers accept both.\n */\n values?: Record<string, unknown>\n /** Row position in the editor and in repeated output. */\n order?: number\n}\n\n/**\n * A human field entry from the quick creator: the stable id plus the\n * display name shown in table headers and bindings pickers (AGL-558).\n */\nexport interface DatasetFieldEntry {\n id: string\n name: string\n}\n\n/**\n * Stable field id from a human name: \"Roast preference\" → \"roast_preference\".\n * Mirrors DATASET_FIELD_PATTERN; returns '' when nothing salvageable.\n */\nexport function slugifyDatasetFieldId(name: string): string {\n const slug = name\n .trim()\n .toLowerCase()\n .replace(/[\\s-]+/g, '_')\n .replace(/[^a-z0-9_]/g, '')\n .replace(/^[0-9_]+/, '')\n .replace(/_+$/, '')\n return DATASET_FIELD_PATTERN.test(slug) ? slug : ''\n}\n\n/**\n * Default reference id for a new field (AGL-578): the `slugifyDatasetFieldId`\n * slug, suffixed (`_2`, `_3`, …) to stay unique within the dataset. `taken`\n * holds the ids already in use (compared case-insensitively). Returns '' when\n * the name yields nothing valid. The user can override the result.\n */\nexport function defaultDatasetFieldId(\n name: string,\n taken: ReadonlySet<string>,\n): string {\n const base = slugifyDatasetFieldId(name)\n if (!base) return ''\n const used = new Set([...taken].map((id) => id.toLowerCase()))\n let candidate = base\n let suffix = 2\n while (used.has(candidate.toLowerCase())) candidate = `${base}_${suffix++}`\n return candidate\n}\n\n/**\n * Validate a user-entered reference id (AGL-578): non-empty, matches\n * `DATASET_FIELD_PATTERN`, and unique within the dataset (`taken` = ids already\n * used, compared case-insensitively). Returns an error message, or null when\n * the id is usable.\n */\nexport function validateDatasetFieldId(\n id: string,\n taken: ReadonlySet<string>,\n): string | null {\n const trimmed = id.trim()\n if (!trimmed) return 'A reference ID is required'\n if (!DATASET_FIELD_PATTERN.test(trimmed))\n return 'Start with a letter; use only letters, numbers, and underscores'\n const used = new Set([...taken].map((existing) => existing.toLowerCase()))\n if (used.has(trimmed.toLowerCase()))\n return 'Another field already uses this reference ID'\n return null\n}\n\n/** Display fallback for raw ids: \"roast_preference\" → \"Roast preference\". */\nexport function humanizeDatasetFieldId(id: string): string {\n const words = id.replace(/_/g, ' ').trim()\n return words ? words.charAt(0).toUpperCase() + words.slice(1) : id\n}\n\n/**\n * Parses a comma/newline separated list of HUMAN field names into\n * {id, name} entries — \"Roast preference\" keeps its pretty name and gets\n * the stable id `roast_preference` (AGL-558). Plain snake_case keys\n * still work and pick up a humanized display name. Duplicate ids and\n * unsalvageable entries are dropped rather than failing the set.\n */\nexport function parseDatasetFieldEntries(input: string): DatasetFieldEntry[] {\n const seen = new Set<string>()\n const entries: DatasetFieldEntry[] = []\n for (const raw of input.split(/[,\\n]/)) {\n const trimmed = raw.trim()\n if (!trimmed) continue\n const id = slugifyDatasetFieldId(trimmed)\n if (!id || seen.has(id)) continue\n seen.add(id)\n entries.push({\n id,\n name: DATASET_FIELD_PATTERN.test(trimmed)\n ? humanizeDatasetFieldId(trimmed)\n : trimmed,\n })\n }\n return entries\n}\n\n/**\n * Parses a comma/newline separated field list into valid unique names;\n * invalid entries are dropped rather than failing the whole set.\n */\nexport function parseDatasetFields(input: string): string[] {\n const seen = new Set<string>()\n const fields: string[] = []\n for (const raw of input.split(/[,\\n]/)) {\n const name = raw.trim()\n if (!DATASET_FIELD_PATTERN.test(name)) continue\n const key = name.toLowerCase()\n if (seen.has(key)) continue\n seen.add(key)\n fields.push(name)\n }\n return fields\n}\n\n/** Record values restricted to the dataset's declared fields. */\nexport function sanitizeRecordValues(\n fields: string[],\n input: Record<string, unknown> | null | undefined,\n): Record<string, string> {\n const values: Record<string, string> = {}\n for (const field of fields) {\n const value = input?.[field]\n if (value == null) continue\n values[field] = String(value)\n }\n return values\n}\n\n/**\n * The submitted values a dataset write would store, picked by field id and\n * left as they arrived (AGL-556). With a `fieldMap` (submitted key → stable\n * model fieldId), mapped values land under the mapped fieldId — so renamed\n * schema fields keep receiving data — and entries whose fieldId isn't in the\n * model are dropped. Submitted keys without a mapping (and calls without a\n * map) fall back to the legacy name-intersection against the model's field\n * ids, matching `sanitizeRecordValues`.\n */\nexport function pickDatasetRecordInput(\n dataset: { model?: DatasetModel; fields?: string[] },\n input: Record<string, unknown> | null | undefined,\n fieldMap?: Record<string, string> | null,\n): Record<string, unknown> {\n const model = effectiveDatasetModel(dataset)\n const map = fieldMap ?? {}\n const values: Record<string, unknown> = {}\n for (const fieldId of model.order) {\n if (!model.fields[fieldId]) continue\n // A submitted key with an explicit mapping never doubles as a\n // name-match — the mapping decides where it lands.\n if (fieldId in map) continue\n const value = input?.[fieldId]\n if (value == null) continue\n values[fieldId] = value\n }\n for (const [submittedKey, fieldId] of Object.entries(map)) {\n if (typeof fieldId !== 'string' || !model.fields[fieldId]) continue\n const value = input?.[submittedKey]\n if (value == null) continue\n values[fieldId] = value\n }\n return values\n}\n\n/** A dataset record write, checked against the dataset's model. */\nexport interface DatasetRecordWrite {\n /**\n * The model fields this write supplied a value for, before coercion. Empty\n * means nothing submitted matched a field of the dataset.\n */\n matched: string[]\n /**\n * The values to store, in storage form (see `dataset-models`): numbers,\n * booleans, epoch millis and so on per the field's type. For a merge, the\n * existing values with this write's laid over them.\n */\n values: Record<string, unknown>\n /** fieldId → the reason it was refused. Empty when the write may land. */\n errors: Record<string, string>\n}\n\n/**\n * A text field takes what an event payload carries as a number or a boolean\n * as the text it reads as, which is what these writes always stored.\n */\nfunction asTextInput(\n model: DatasetModel,\n picked: Record<string, unknown>,\n): Record<string, unknown> {\n const values: Record<string, unknown> = {}\n for (const [fieldId, value] of Object.entries(picked)) {\n const type = model.fields[fieldId]?.type\n values[fieldId] =\n (type === 'text' || type === 'reference') &&\n (typeof value === 'number' || typeof value === 'boolean')\n ? String(value)\n : value\n }\n return values\n}\n\n/**\n * A record write from a form submission or an automation step, coerced and\n * validated against the dataset's model (AGL-2773, option B).\n *\n * These writes used to store `String(value)` for every field and check\n * nothing, so a form could put `abc` in a number column and skip a required\n * one. They now run the same `coerceDocumentValues` + `validateDocument` pair\n * the console and `/v1` do: a value is stored in its field's type, and a\n * record with any refused field is not written at all. The caller decides\n * what a refusal costs — a form keeps the Inbox submission, a run records a\n * failed step.\n *\n * `existing` makes it a merge (update-or-append's update leg): this write's\n * values are laid over the stored ones, and only the fields THIS write\n * supplied are held to the model. A stored row written as text before this\n * change keeps its text values and is not refused for them — the reads have\n * always rendered them, and a merge that touched `email` must not fail over a\n * legacy `price` of `\"12\"` it never sent.\n *\n * Custom field types validate only once registered: call\n * `ensureDeclaredCustomFieldTypes(model)` before this on a server path.\n */\nexport function prepareDatasetRecordWrite(\n dataset: { model?: DatasetModel; fields?: string[] },\n input: Record<string, unknown> | null | undefined,\n options: {\n fieldMap?: Record<string, string> | null\n existing?: Record<string, unknown> | null\n } = {},\n): DatasetRecordWrite {\n const model = effectiveDatasetModel(dataset)\n const picked = pickDatasetRecordInput(dataset, input, options.fieldMap)\n const matched = Object.keys(picked)\n const coerced = coerceDocumentValues(model, asTextInput(model, picked))\n if (!options.existing) {\n return {\n matched,\n values: coerced,\n errors: validateDocument(model, coerced),\n }\n }\n const values = { ...options.existing, ...coerced }\n const errors: Record<string, string> = {}\n for (const [fieldId, error] of Object.entries(\n validateDocument(model, values),\n )) {\n if (fieldId in coerced) errors[fieldId] = error\n }\n return { matched, values, errors }\n}\n\n/**\n * A refused write's errors as one line, in the model's field order:\n * `Stars must be a whole number; Email is required`.\n */\nexport function describeDatasetRecordErrors(\n errors: Record<string, string>,\n): string {\n return Object.values(errors).join('; ')\n}\n\n/**\n * The name a dataset is shown under: `displayName`, which is what every create\n * path writes (AGL-536), then the pre-migration `name`. Blank when the document\n * carries neither.\n */\nexport function datasetDisplayName(\n dataset: { displayName?: unknown; name?: unknown } | null | undefined,\n): string {\n for (const candidate of [dataset?.displayName, dataset?.name]) {\n if (typeof candidate === 'string' && candidate.trim()) {\n return candidate.trim()\n }\n }\n return ''\n}\n\n/** Records sorted by their editor order (then id for stability). */\nexport function sortDatasetRecords<T extends HostDatasetRecord>(\n records: T[],\n): T[] {\n return [...records].sort(\n (a, b) =>\n (a.order ?? Number.MAX_SAFE_INTEGER) -\n (b.order ?? Number.MAX_SAFE_INTEGER) ||\n String(a.$id ?? '').localeCompare(String(b.$id ?? '')),\n )\n}\n"],"names":["coerceDocumentValues","effectiveDatasetModel","validateDocument","DATASET_FIELD_PATTERN","slugifyDatasetFieldId","name","slug","trim","toLowerCase","replace","test","defaultDatasetFieldId","taken","base","used","Set","map","id","candidate","suffix","has","validateDatasetFieldId","trimmed","existing","humanizeDatasetFieldId","words","charAt","toUpperCase","slice","parseDatasetFieldEntries","input","seen","entries","raw","split","add","push","parseDatasetFields","fields","key","sanitizeRecordValues","values","field","value","String","pickDatasetRecordInput","dataset","fieldMap","model","fieldId","order","submittedKey","Object","asTextInput","picked","type","prepareDatasetRecordWrite","options","matched","keys","coerced","errors","error","describeDatasetRecordErrors","join","datasetDisplayName","displayName","sortDatasetRecords","records","sort","a","b","Number","MAX_SAFE_INTEGER","$id","localeCompare"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;CAIC,GAED,SACEA,oBAAoB,EAEpBC,qBAAqB,EACrBC,gBAAgB,QACX,sBAAkB;AAEzB,0EAA0E,GAC1E,OAAO,MAAMC,wBAAwB,0BAAyB;AAuC9D;;;CAGC,GACD,OAAO,SAASC,sBAAsBC,IAAY;IAChD,MAAMC,OAAOD,KACVE,IAAI,GACJC,WAAW,GACXC,OAAO,CAAC,WAAW,KACnBA,OAAO,CAAC,eAAe,IACvBA,OAAO,CAAC,YAAY,IACpBA,OAAO,CAAC,OAAO;IAClB,OAAON,sBAAsBO,IAAI,CAACJ,QAAQA,OAAO;AACnD;AAEA;;;;;CAKC,GACD,OAAO,SAASK,sBACdN,IAAY,EACZO,KAA0B;IAE1B,MAAMC,OAAOT,sBAAsBC;IACnC,IAAI,CAACQ,MAAM,OA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