workpeg 0.166.0__tar.gz → 0.167.0__tar.gz

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 (166) hide show
  1. {workpeg-0.166.0/src/workpeg.egg-info → workpeg-0.167.0}/PKG-INFO +1 -1
  2. {workpeg-0.166.0 → workpeg-0.167.0}/pyproject.toml +1 -1
  3. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/app.py +33 -0
  4. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/build.py +22 -0
  5. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/compiler/ast_parser.py +54 -0
  6. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/permissions_manifest.py +41 -14
  7. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/scaffold.js +684 -48
  8. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/workpeg-runtime.js +67 -0
  9. {workpeg-0.166.0 → workpeg-0.167.0/src/workpeg.egg-info}/PKG-INFO +1 -1
  10. {workpeg-0.166.0 → workpeg-0.167.0}/LICENSE +0 -0
  11. {workpeg-0.166.0 → workpeg-0.167.0}/MANIFEST.in +0 -0
  12. {workpeg-0.166.0 → workpeg-0.167.0}/README.md +0 -0
  13. {workpeg-0.166.0 → workpeg-0.167.0}/setup.cfg +0 -0
  14. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/__init__.py +0 -0
  15. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/auth.py +0 -0
  16. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/build.py +0 -0
  17. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/builder/__init__.py +0 -0
  18. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/builder/__main__.py +0 -0
  19. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/builder/canonical.py +0 -0
  20. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/builder/envelope.py +0 -0
  21. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/builder/stages.py +0 -0
  22. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/cdn.py +0 -0
  23. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/cli.py +0 -0
  24. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/config.py +0 -0
  25. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/context.py +0 -0
  26. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/create_new.py +0 -0
  27. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/doctor.py +0 -0
  28. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/function_base.py +0 -0
  29. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/function_check.py +0 -0
  30. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/function_envelopes.py +0 -0
  31. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/function_local.py +0 -0
  32. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/listen.py +0 -0
  33. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/project.py +0 -0
  34. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/project_submit.py +0 -0
  35. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/run.py +0 -0
  36. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/runtime.py +0 -0
  37. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/sandbox/__init__.py +0 -0
  38. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/sandbox/docker_driver.py +0 -0
  39. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/sandbox/driver.py +0 -0
  40. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/starter.py +0 -0
  41. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/submit.py +0 -0
  42. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/target_sdk.py +0 -0
  43. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/__init__.py +0 -0
  44. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/agents/AGENTS.md +0 -0
  45. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/agents/CLAUDE.md +0 -0
  46. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/Dockerfile +0 -0
  47. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/LICENSE +0 -0
  48. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/README.md +0 -0
  49. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/app/__init__.py +0 -0
  50. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/app/main.py +0 -0
  51. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/requirements.txt +0 -0
  52. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/wheels/README.txt +0 -0
  53. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/README.md +0 -0
  54. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/function/Dockerfile +0 -0
  55. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/function/app/__init__.py +0 -0
  56. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/function/app/main.py +0 -0
  57. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/function/requirements.txt +0 -0
  58. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/function/wheels/README.txt +0 -0
  59. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/workpeg.json +0 -0
  60. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/app_shell.py +0 -0
  61. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/components.py +0 -0
  62. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/main.py +0 -0
  63. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/pages/__init__.py +0 -0
  64. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/pages/customer.py +0 -0
  65. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/pages/customers.py +0 -0
  66. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/pages/home.py +0 -0
  67. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/pages/not_found.py +0 -0
  68. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/terminal.py +0 -0
  69. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/__init__.py +0 -0
  70. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/actions.py +0 -0
  71. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/actions_manifest.py +0 -0
  72. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/calendar.py +0 -0
  73. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/compiler/__init__.py +0 -0
  74. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/compiler/ir.py +0 -0
  75. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/compiler/js_generator.py +0 -0
  76. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/compiler/rtc_checks.py +0 -0
  77. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/compiler/rtc_tables.py +0 -0
  78. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/create.py +0 -0
  79. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/dates.py +0 -0
  80. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/dev_refused_names.json +0 -0
  81. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/devmode.py +0 -0
  82. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/devserve.py +0 -0
  83. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/devsite.py +0 -0
  84. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/fake_cloud.py +0 -0
  85. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/minify.py +0 -0
  86. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/render_nodes.py +0 -0
  87. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/renderers_manifest.py +0 -0
  88. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/rtc.py +0 -0
  89. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/ai-concurrent-replies.md +0 -0
  90. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/ai-prompt-queue.md +0 -0
  91. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/ai-question-frame.md +0 -0
  92. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/ai-subagent-frame.md +0 -0
  93. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/ai.js +0 -0
  94. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/editor.js +0 -0
  95. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/OFL.txt +0 -0
  96. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-italic-cyrillic-ext.af944491.woff2 +0 -0
  97. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-italic-cyrillic.88be6946.woff2 +0 -0
  98. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-italic-latin-ext.370a8962.woff2 +0 -0
  99. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-italic-latin.7611b95c.woff2 +0 -0
  100. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-italic-vietnamese.8dfcf303.woff2 +0 -0
  101. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-normal-cyrillic-ext.b7a545bb.woff2 +0 -0
  102. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-normal-cyrillic.6129fc85.woff2 +0 -0
  103. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-normal-latin-ext.58a6b173.woff2 +0 -0
  104. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-normal-latin.9b6f5ff4.woff2 +0 -0
  105. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-normal-vietnamese.f689f638.woff2 +0 -0
  106. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/icons.css.gz +0 -0
  107. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/overlay.js +0 -0
  108. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/pegment.css +0 -0
  109. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/rtc.js +0 -0
  110. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/scaffold.py +0 -0
  111. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/scaffold_check.py +0 -0
  112. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/search_manifest.py +0 -0
  113. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/serve.py +0 -0
  114. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/skills_manifest.py +0 -0
  115. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/state.py +0 -0
  116. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/validators.py +0 -0
  117. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/verify.py +0 -0
  118. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/watcher.py +0 -0
  119. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/__init__.py +0 -0
  120. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/base.py +0 -0
  121. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/canvas.py +0 -0
  122. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/display.py +0 -0
  123. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/fields.py +0 -0
  124. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/forms.py +0 -0
  125. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/futures.py +0 -0
  126. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/gestures.py +0 -0
  127. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/interactive.py +0 -0
  128. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/layout.py +0 -0
  129. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/pickers.py +0 -0
  130. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/utils.py +0 -0
  131. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg.egg-info/SOURCES.txt +0 -0
  132. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg.egg-info/dependency_links.txt +0 -0
  133. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg.egg-info/entry_points.txt +0 -0
  134. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg.egg-info/requires.txt +0 -0
  135. {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg.egg-info/top_level.txt +0 -0
  136. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_agents_guide.py +0 -0
  137. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_auth.py +0 -0
  138. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_build.py +0 -0
  139. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_cdn.py +0 -0
  140. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_cdn_publish.py +0 -0
  141. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_changelog.py +0 -0
  142. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_changelog_guard.py +0 -0
  143. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_cli.py +0 -0
  144. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_command_cheatsheet.py +0 -0
  145. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_config.py +0 -0
  146. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_context.py +0 -0
  147. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_create_new.py +0 -0
  148. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_dev_functions_wire.py +0 -0
  149. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_dev_install_example.py +0 -0
  150. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_doctor.py +0 -0
  151. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_function_check.py +0 -0
  152. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_function_envelopes.py +0 -0
  153. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_function_listen.py +0 -0
  154. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_pegfn_base.py +0 -0
  155. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_project_create.py +0 -0
  156. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_project_submit.py +0 -0
  157. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_release_script.py +0 -0
  158. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_run.py +0 -0
  159. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_run_cli.py +0 -0
  160. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_runtime.py +0 -0
  161. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_runtime_invoke_key.py +0 -0
  162. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_submit.py +0 -0
  163. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_target_sdk.py +0 -0
  164. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_utils.py +0 -0
  165. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_version.py +0 -0
  166. {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_watch_pipeline.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: workpeg
3
- Version: 0.166.0
3
+ Version: 0.167.0
4
4
  Summary: Workpeg function runtime and SDK
5
5
  Author-email: Workpeg <support@workpeg.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "workpeg"
7
- version = "0.166.0"
7
+ version = "0.167.0"
8
8
  description = "Workpeg function runtime and SDK"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -910,6 +910,39 @@ class _Workpeg:
910
910
  """
911
911
  return self._unavailable("first_business")
912
912
 
913
+ def request_permission(self, name: str) -> Any:
914
+ """Ask the person, over this Peg, for a permission it declares.
915
+
916
+ ``name`` is a permission in ``workpeg.json``'s ``permissions``, a
917
+ fixed one or the one for all of the Peg's tables (``"table": "*"``),
918
+ which covers every table the Peg has, now or later, so no call names
919
+ a table::
920
+
921
+ async def connect(self):
922
+ outcome = await workpeg.request_permission("instant_answers")
923
+
924
+ Resolves to exactly one of ``"allowed"``, ``"denied"``,
925
+ ``"dismissed"``, ``"needs_admin"`` or ``"unavailable"``, and never
926
+ rejects, so it needs no ``try``. Workpeg draws the question in a
927
+ window of its own over the Peg; the Peg's page cannot read it or
928
+ press its buttons (docs/permissions.md, "Ask while your Peg runs").
929
+ Compiles to ``Workpeg.wpRequestPermission``; never runs in Python.
930
+ """
931
+ return self._unavailable("request_permission")
932
+
933
+ def permission_status(self, name: str) -> Any:
934
+ """What the business decided about a permission this Peg declares,
935
+ without asking anybody.
936
+
937
+ Resolves to ``"allowed"``, ``"denied"``, ``"not_set"`` or
938
+ ``"unavailable"``, never rejects, and draws nothing::
939
+
940
+ status = await workpeg.permission_status("instant_answers")
941
+
942
+ Compiles to ``Workpeg.wpPermissionStatus``; never runs in Python.
943
+ """
944
+ return self._unavailable("permission_status")
945
+
913
946
  # ``*_protected`` variants additionally send the session cookie
914
947
  # (``credentials: "include"``) — the authenticated request, for endpoints
915
948
  # behind a login (the recreation of the React ``fetchProtected`` helper)::
@@ -782,6 +782,7 @@ def build_ui(
782
782
  js = minify_js(js)
783
783
 
784
784
  _assert_parses(js, source)
785
+ _check_permission_calls(parser.permission_calls, source)
785
786
 
786
787
  # Explicit argument wins over everything: that is Workpeg's own build
787
788
  # server saying which peg it is compiling, and it does not take the
@@ -1227,6 +1228,27 @@ def _permissions_section(source: Path) -> "list | None":
1227
1228
  raise ManifestValidationError(f"{config_path}: {refused}") from None
1228
1229
 
1229
1230
 
1231
+ def _check_permission_calls(calls: list, source: Path) -> None:
1232
+ """Each ``workpeg.request_permission`` / ``permission_status`` call with
1233
+ a literal name, checked against the Peg's ``permissions`` (contract
1234
+ D.6), so an author learns at build time that a name is not declared. A
1235
+ name that is not a literal is checked at run time only, by the runtime,
1236
+ scaffold.js and the api. The name in the message passed its pattern in
1237
+ the parser, so echoing it is safe."""
1238
+ if not calls:
1239
+ return
1240
+ from workpeg.ui.search_manifest import ManifestValidationError
1241
+
1242
+ declared = {e["name"] for e in _permissions_section(source) or []}
1243
+ for call in calls:
1244
+ name, method = call["name"], call["method"]
1245
+ if name is None or name in declared:
1246
+ continue
1247
+ raise ManifestValidationError(
1248
+ f'{call["path"]}:{call["line"]}: workpeg.{method}("{name}"): '
1249
+ f'workpeg.json declares no permission named "{name}".')
1250
+
1251
+
1230
1252
  def _actions_section(source: Path) -> "list | None":
1231
1253
  """The Peg's ``actions`` manifest section, from ``workpeg.json``.
1232
1254
 
@@ -178,6 +178,19 @@ _WORKPEG_SESSION_HELPERS = {
178
178
  "first_business": (0, 0, "workpeg.first_business()"),
179
179
  }
180
180
 
181
+ # workpeg.request_permission(name) and workpeg.permission_status(name): ask
182
+ # the person, over the peg, for a permission its manifest declares, or read
183
+ # what was decided (docs/permissions.md, contract D.6). Each compiles to one
184
+ # call into the runtime (Workpeg.wpRequestPermission / wpPermissionStatus),
185
+ # which checks the name again and hands it to scaffold.js. A literal name is
186
+ # checked here and against workpeg.json in build.py; the calls are recorded
187
+ # on ``parser.permission_calls`` for that. An all-tables permission
188
+ # ("table": "*") covers every table of the peg, so no call names a table.
189
+ _WORKPEG_PERMISSION_HELPERS = {
190
+ "request_permission": "workpeg.request_permission(name)",
191
+ "permission_status": "workpeg.permission_status(name)",
192
+ }
193
+
181
194
 
182
195
  def _is_str_const(node: "ast.AST | None") -> bool:
183
196
  """True when *node* is a string literal (an ``ast.Constant`` holding a str)
@@ -1988,6 +2001,10 @@ class ASTParser:
1988
2001
 
1989
2002
  def __init__(self) -> None:
1990
2003
  self._components: dict[str, "ComponentIR | None"] = {}
2004
+ # Every workpeg.request_permission / permission_status call, for the
2005
+ # build to check its literal name against workpeg.json.
2006
+ # Kept across every module of the build (not reset per file).
2007
+ self.permission_calls: list[dict] = []
1991
2008
  # `store.<field>`: a read is only checked once the whole program has
1992
2009
  # been seen, since the field may be declared on the Router in another
1993
2010
  # file or first assigned on a page parsed later. See `_check_store_reads`.
@@ -8644,6 +8661,41 @@ class ASTParser:
8644
8661
  args[index] = self._parse_expr(kw.value, scope)
8645
8662
  return args
8646
8663
 
8664
+ def _parse_workpeg_permission(self, node: ast.Call, scope: frozenset,
8665
+ method: str) -> Any:
8666
+ """``workpeg.request_permission(name)`` and
8667
+ ``workpeg.permission_status(name)``: exactly one positional name and
8668
+ no keyword at all. Both resolve to a word and never reject; the
8669
+ runtime and scaffold.js check the name again, so this is the
8670
+ author's early warning, not the door."""
8671
+ from workpeg.ui.permissions_manifest import PERMISSION_NAME_PATTERN
8672
+
8673
+ if len(node.args) != 1 or isinstance(node.args[0], ast.Starred) \
8674
+ or node.keywords:
8675
+ raise UnsupportedSyntaxError(
8676
+ f"workpeg.{method}(name) takes only the permission's name")
8677
+
8678
+ name_node = node.args[0]
8679
+ name = None
8680
+ if isinstance(name_node, ast.Constant):
8681
+ if not isinstance(name_node.value, str) or not re.fullmatch(
8682
+ PERMISSION_NAME_PATTERN, name_node.value):
8683
+ raise UnsupportedSyntaxError(
8684
+ f"workpeg.{method}() needs a permission name: 1 to 40 "
8685
+ "lower-case letters, digits or underscores, starting "
8686
+ "with a letter")
8687
+ name = name_node.value
8688
+
8689
+ path, line = self._location_of(node)
8690
+ record = {"method": method, "name": name, "path": path, "line": line}
8691
+ if record not in self.permission_calls:
8692
+ self.permission_calls.append(record)
8693
+
8694
+ return {
8695
+ "expr": "workpeg", "method": method, "protected": True,
8696
+ "args": [self._parse_expr(name_node, scope)],
8697
+ }
8698
+
8647
8699
  def _parse_workpeg_call(self, node: ast.Call, scope: frozenset) -> Any:
8648
8700
  """Parse ``workpeg.get/post/put/patch/delete`` — namespaced calls to
8649
8701
  Workpeg's own platform, the inverse of ``http.*``.
@@ -8653,6 +8705,8 @@ class ASTParser:
8653
8705
  platform's API base at runtime.
8654
8706
  """
8655
8707
  method = node.func.attr
8708
+ if method in _WORKPEG_PERMISSION_HELPERS:
8709
+ return self._parse_workpeg_permission(node, scope, method)
8656
8710
  # Tables & Rows helpers (get_tables, add_row, …) take no URL — the
8657
8711
  # business id is read from the page URL at runtime, and the runtime
8658
8712
  # builds the endpoint path from the args.
@@ -9,10 +9,23 @@ business to allow, and why, in one sentence each.
9
9
  "purpose": "Adds each answer to Responses seconds after someone submits it.",
10
10
  "ask": "install",
11
11
  "inbound": {"table": "responses"}
12
+ },
13
+ {
14
+ "name": "all_tables",
15
+ "kind": "inbound",
16
+ "purpose": "Adds each answer to its form's own table as it is submitted.",
17
+ "ask": "runtime",
18
+ "inbound": {"table": "*"}
12
19
  }
13
20
  ]
14
21
  ```
15
22
 
23
+ ``"ask": "runtime"`` is never asked at install: the Peg's own code asks
24
+ with ``workpeg.request_permission(name)``. ``"table": "*"`` is an entry for
25
+ ALL of the Peg's own tables in the business, the ones it has now and the ones
26
+ it creates later, under one grant and one key. Any ``ask`` suits it, since it
27
+ never waits for a table. A Peg may declare one, beside its fixed entries.
28
+
16
29
  The api validates the same section with the same rules, in the same order,
17
30
  with the same words (``app/core/peg_permissions.py``), and never trusts this
18
31
  build: the manifest is unsigned. The build refuses what the api would refuse
@@ -37,7 +50,8 @@ PERMISSION_NAME_PATTERN = r"^[a-z][a-z0-9_]{0,39}\Z"
37
50
  PERMISSION_ALIAS_PATTERN = r"^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$"
38
51
  PURPOSE_URL_PATTERN = r"(?i)(://|www\.|@|[a-z0-9-]+\.[a-z]{2,})"
39
52
  REFUSED_CATEGORIES = ("Cc", "Cf", "Co", "Cs", "Zl", "Zp")
40
- PERMISSION_ASK = ("install", "settings")
53
+ PERMISSION_ASK = ("install", "settings", "runtime")
54
+ PERMISSION_ALL_TABLES = "*"
41
55
 
42
56
  MSG_NOT_A_LIST = '"permissions" must be a list of objects.'
43
57
  MSG_TOO_MANY = ('"permissions" lists {count} entries; a peg may declare at '
@@ -64,12 +78,17 @@ MSG_PURPOSE_CONTROL = ('permissions[{index}].purpose holds an invisible or '
64
78
  'control character (U+{code}).')
65
79
  MSG_PURPOSE_URL = ('permissions[{index}].purpose must not hold a web '
66
80
  'address, an email address or a domain name.')
67
- MSG_BAD_ASK = 'permissions[{index}].ask must be "install" or "settings".'
81
+ MSG_BAD_ASK = ('permissions[{index}].ask must be "install", "settings" or '
82
+ '"runtime".')
68
83
  MSG_BAD_INBOUND = ('permissions[{index}].inbound must be '
69
- '{{"table": "<table alias>"}}.')
70
- MSG_BAD_ALIAS = ('permissions[{index}].inbound.table must be a table alias: '
71
- '1 to 64 letters, digits, dots, dashes or underscores, '
72
- 'starting with a letter or digit.')
84
+ '{{"table": "<table alias>"}} or {{"table": "*"}}.')
85
+ MSG_BAD_ALIAS = ('permissions[{index}].inbound.table must be a table alias '
86
+ '(1 to 64 letters, digits, dots, dashes or underscores, '
87
+ 'starting with a letter or digit) or "*" for all of the '
88
+ 'peg\'s own tables.')
89
+ MSG_SAME_ALL_TABLES = ('permissions[{index}] is a second inbound permission '
90
+ 'for all of the peg\'s tables; a peg may declare '
91
+ 'one.')
73
92
  MSG_SAME_TABLE = ('permissions[{index}] asks for inbound on "{table}" again; '
74
93
  'a peg may declare one inbound permission per table.')
75
94
 
@@ -119,6 +138,7 @@ def validate_permissions(value):
119
138
  _fail(MSG_TOO_MANY, count=len(value), max=MAX_PERMISSIONS)
120
139
  names = set()
121
140
  tables = set()
141
+ all_tables = False
122
142
  out = []
123
143
  for index, entry in enumerate(value):
124
144
  if not isinstance(entry, dict):
@@ -163,14 +183,21 @@ def validate_permissions(value):
163
183
  if not isinstance(params, dict) or set(params) != {"table"}:
164
184
  _fail(MSG_BAD_INBOUND, index=index)
165
185
  table = params["table"]
166
- # fullmatch, as the api does: the pattern's ``$`` alone would let a
167
- # trailing newline through.
168
- if not isinstance(table, str) \
169
- or not re.fullmatch(PERMISSION_ALIAS_PATTERN, table):
170
- _fail(MSG_BAD_ALIAS, index=index)
171
- if table.lower() in tables:
172
- _fail(MSG_SAME_TABLE, index=index, table=table)
173
- tables.add(table.lower())
186
+ if isinstance(table, str) and table == PERMISSION_ALL_TABLES:
187
+ # All of the peg's own tables, now and later, under one grant.
188
+ # It never waits for a table, so any ``ask`` suits it.
189
+ if all_tables:
190
+ _fail(MSG_SAME_ALL_TABLES, index=index)
191
+ all_tables = True
192
+ else:
193
+ # fullmatch, as the api does: the pattern's ``$`` alone would
194
+ # let a trailing newline through.
195
+ if not isinstance(table, str) \
196
+ or not re.fullmatch(PERMISSION_ALIAS_PATTERN, table):
197
+ _fail(MSG_BAD_ALIAS, index=index)
198
+ if table.lower() in tables:
199
+ _fail(MSG_SAME_TABLE, index=index, table=table)
200
+ tables.add(table.lower())
174
201
 
175
202
  out.append({"name": name, "kind": kind, "purpose": purpose,
176
203
  "ask": ask, kind: {"table": table}})