@appling/codegen-ash 0.1.3 → 0.1.5
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/README.md +2 -1
- package/out/elixir.d.ts +1 -1
- package/out/elixir.js +4 -3
- package/out/index.js +2 -2
- package/out/scenario-tests.js +1 -1
- package/out/vendors.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -39,7 +39,8 @@ Requires Elixir 1.17 or later and the `igniter_new` archive (`mix archive.instal
|
|
|
39
39
|
| `policy` | `Ash.Policy.Authorizer` policies: `action_type(...)` or `always()` for entity policies, `field_policy` for `fields` (plus a catch-all `field_policy :*`; a calculation it names is public, a derived field without one waits for its calculation task), `action(:name)` for actions and queries; each `\|\|` branch becomes `authorize_if`, a branch with `&&` becomes `forbid_unless` checks followed by `authorize_if`; conditions become `expr` checks with `^actor(...)` and records compared by id. Once the model has a policy, every resource lists the authorizer and denies what no policy covers (a resource without policies gets `policy always()` with `forbid_if always()`), an untranslated condition forbids until written, and resources with jobs get an AshOban bypass |
|
|
40
40
|
| `interface rest` | AshJsonApi routes on the domain (`index` for queries with `default_fields` from picks, `patch` for update actions), served by Phoenix under `/api/json` when the model has pages, otherwise by a JSON:API router that Bandit serves on port 4000 |
|
|
41
41
|
| `page`, `navigation`, `messages` | Phoenix LiveViews with lists, details, AshPhoenix forms and action buttons, navigation links and column labels; models with pages need the `phx_new` archive |
|
|
42
|
-
| `
|
|
42
|
+
| `describe` | `@moduledoc` of resources and embedded resources, `description` of attributes |
|
|
43
|
+
| `does` | a registry task |
|
|
43
44
|
| rules | skipped ExUnit tests in `test/<app>/<module>/<resource>_test.exs` for invariants, policies, transitions and preconditions; invariants that become validations get changeset test bodies where the simulator proves a valid and a violating input, transitions get update changeset bodies on a record struct (AshStateMachine's state check, no database), preconditions that become validations get update changeset bodies asserting their message where the simulator proves them false on that struct, entity policies get `Ash.can?` bodies on an actor struct for actors their `actor.is(...)` checks decide, writing every other body is a registry task |
|
|
44
45
|
| `scenario` | an ExUnit test in `test/<app>/<module>/scenarios_test.exs` with a database sandbox: the given rows through `Ash.Seed.seed!` (samples for required attributes), the actor seeded or built with its roles, the call through `Ash.update` on the action's update action, and asserts for the checks, `fails` and `refused` (`Ash.Error.Forbidden`); a scenario the generated project cannot pass yet (use cases, lists of entities, events, untranslated validations or policies) is a skipped test and a registry task. Actions and transitions a scenario runs get no guessed precondition or transition tests |
|
|
45
46
|
|
package/out/elixir.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare function parentOf(qn: string): string;
|
|
|
12
12
|
export declare function lastOf(qn: string): string;
|
|
13
13
|
/** An Elixir string literal, without interpolation. */
|
|
14
14
|
export declare function elixirString(text: string): string;
|
|
15
|
-
/** The `@moduledoc` lines of a node's `does`
|
|
15
|
+
/** The `@moduledoc` lines of a node's `describe` and `does` texts, a heredoc when they span lines; none without a text. */
|
|
16
16
|
export declare function moduledoc(node: GraphNode): string;
|
|
17
17
|
/** Puts the node's `@moduledoc` first in the module. */
|
|
18
18
|
export declare function withModuledoc(text: string, node: GraphNode): string;
|
package/out/elixir.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { aboutOf } from '@appling/codegen';
|
|
1
2
|
const OPERATORS = { '&&': 'and', '||': 'or' };
|
|
2
3
|
const COMPARE = { '<': 'less_than', '<=': 'less_than_or_equal_to', '>': 'greater_than', '>=': 'greater_than_or_equal_to' };
|
|
3
4
|
const FLIPPED = { '<': '>', '<=': '>=', '>': '<', '>=': '<=', '==': '==', '!=': '!=' };
|
|
@@ -196,10 +197,10 @@ export function lastOf(qn) {
|
|
|
196
197
|
export function elixirString(text) {
|
|
197
198
|
return `"${text.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/#\{/g, '\\#{').replace(/\n/g, '\\n')}"`;
|
|
198
199
|
}
|
|
199
|
-
/** The `@moduledoc` lines of a node's `does`
|
|
200
|
+
/** The `@moduledoc` lines of a node's `describe` and `does` texts, a heredoc when they span lines; none without a text. */
|
|
200
201
|
export function moduledoc(node) {
|
|
201
|
-
const text = node
|
|
202
|
-
if (
|
|
202
|
+
const text = aboutOf(node);
|
|
203
|
+
if (!text)
|
|
203
204
|
return '';
|
|
204
205
|
if (!text.includes('\n'))
|
|
205
206
|
return ` @moduledoc ${elixirString(text)}\n\n`;
|
package/out/index.js
CHANGED
|
@@ -145,8 +145,8 @@ function patchResource(text, entity, context) {
|
|
|
145
145
|
const value = defaultValue(field, context);
|
|
146
146
|
if (value !== undefined)
|
|
147
147
|
text = text.replace(new RegExp(`(\\n([ \\t]*)attribute :${lastOf(field.qn)}, [^\\n]* do\\n)`), `$1$2 default ${value}\n`);
|
|
148
|
-
if (typeof field.data.
|
|
149
|
-
text = text.replace(new RegExp(`(\\n([ \\t]*)attribute :${lastOf(field.qn)}, [^\\n]* do\\n)`), (_, head, indent) => `${head}${indent} description ${elixirString(field.data.
|
|
148
|
+
if (typeof field.data.describe === 'string')
|
|
149
|
+
text = text.replace(new RegExp(`(\\n([ \\t]*)attribute :${lastOf(field.qn)}, [^\\n]* do\\n)`), (_, head, indent) => `${head}${indent} description ${elixirString(field.data.describe)}\n`);
|
|
150
150
|
}
|
|
151
151
|
text = withModuledoc(text, entity);
|
|
152
152
|
const blocks = [
|
package/out/scenario-tests.js
CHANGED
|
@@ -35,7 +35,7 @@ export function scenarioSteps(scenario, context) {
|
|
|
35
35
|
throw error;
|
|
36
36
|
why = error.message;
|
|
37
37
|
}
|
|
38
|
-
const does = typeof scenario.data.
|
|
38
|
+
const does = typeof scenario.data.describe === 'string' && scenario.data.describe.trim() ? ` # ${scenario.data.describe.trim().replace(/\s*\n\s*/g, ' ')}\n` : '';
|
|
39
39
|
const test = body
|
|
40
40
|
? `${does} test ${JSON.stringify(title)} do\n${body.map(l => ` ${l}\n`).join('')} end\n`
|
|
41
41
|
: `${does} @tag skip: ${JSON.stringify(`registry task: ${scenario.qn}`)}\n test ${JSON.stringify(title)}\n`;
|
package/out/vendors.js
CHANGED
|
@@ -27,7 +27,7 @@ export function externalKeySteps(key, context) {
|
|
|
27
27
|
if (existing?.split('\n').includes(`${name}=`))
|
|
28
28
|
return existing;
|
|
29
29
|
const head = existing ?? '# The settings and secrets of the vendors this app needs. Copy to .env and fill in; never commit values.\n';
|
|
30
|
-
const about = `# ${key.data.kind} of ${externalOf(key)}${key.data.
|
|
30
|
+
const about = `# ${key.data.kind} of ${externalOf(key)}${key.data.describe ? `: ${String(key.data.describe).replace(/\s+/g, ' ').trim()}` : ''}`;
|
|
31
31
|
return `${head.trimEnd()}\n\n${about}\n${name}=\n`;
|
|
32
32
|
}
|
|
33
33
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appling/codegen-ash",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Appling code generation extension for Ash",
|
|
5
5
|
"homepage": "https://www.appling.tools/docs/",
|
|
6
6
|
"repository": {
|
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
"out"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@appling/model": "0.1.
|
|
22
|
+
"@appling/model": "0.1.5"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@appling/codegen": "0.1
|
|
25
|
+
"@appling/codegen": "0.2.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@appling/codegen": "0.1
|
|
28
|
+
"@appling/codegen": "0.2.1",
|
|
29
29
|
"@types/node": "^24.19.2",
|
|
30
30
|
"typescript": "7.0.2"
|
|
31
31
|
},
|