sharetribe-flex-build-sdk 1.16.11 → 1.17.0
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 +7 -1
- package/dist/cjs/edn-process.d.ts +13 -30
- package/dist/cjs/edn-process.d.ts.map +1 -1
- package/dist/cjs/edn-process.js +148 -50
- package/dist/cjs/edn-process.js.map +1 -1
- package/dist/cjs/types.d.ts +4 -2
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/edn-process.d.ts +13 -30
- package/dist/esm/edn-process.d.ts.map +1 -1
- package/dist/esm/edn-process.js +148 -50
- package/dist/esm/edn-process.js.map +1 -1
- package/dist/esm/types.d.ts +4 -2
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -98,13 +98,19 @@ await deleteAlias(apiKey, marketplace, 'my-process', 'release');
|
|
|
98
98
|
import { parseProcessFile, serializeProcess } from 'sharetribe-flex-build-sdk';
|
|
99
99
|
|
|
100
100
|
// Parse a process.edn file
|
|
101
|
-
const process = parseProcessFile('./process.edn');
|
|
101
|
+
const process = parseProcessFile('./ext/transaction-processes/default-booking/process.edn');
|
|
102
102
|
console.log(process.name, process.states, process.transitions);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Sharetribe's process files declare neither `:name` nor `:states`, so `parseProcessFile` takes the name from the directory holding the file and derives the states from the transitions' `:from` and `:to`. Keywords come back with their namespace and without the leading colon, so a transition is `transition/accept` and an action is `action/privileged-set-line-items`. `from` and `actor` are absent on the transitions that have no `:from` or no `:actor`, which is every initial transition and every time-based one.
|
|
103
106
|
|
|
107
|
+
```typescript
|
|
104
108
|
// Serialize back to EDN format
|
|
105
109
|
const ednString = serializeProcess(process);
|
|
106
110
|
```
|
|
107
111
|
|
|
112
|
+
`serializeProcess` writes a simplified EDN form that keeps only the names: it drops `:privileged?`, action configs, `:at` and everything else a real process carries. Do not push its output to a marketplace. To deploy a process, push the file's own text.
|
|
113
|
+
|
|
108
114
|
### Make API Calls
|
|
109
115
|
|
|
110
116
|
```typescript
|
|
@@ -1,39 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Process.edn file parser
|
|
3
3
|
*
|
|
4
|
-
* Parses transaction process definitions from EDN format
|
|
4
|
+
* Parses transaction process definitions from EDN format.
|
|
5
|
+
*
|
|
6
|
+
* Written against the process.edn files Sharetribe actually ships, which are
|
|
7
|
+
* `{:format :v3 :transitions [...] :notifications [...]}` maps. They declare
|
|
8
|
+
* neither `:name` nor `:states`: the name comes from the directory holding the
|
|
9
|
+
* file, and the states are whatever the transitions' `:from` and `:to` name.
|
|
10
|
+
* That is why this module derives both rather than reading them off the map.
|
|
5
11
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
in: string[];
|
|
9
|
-
out: string[];
|
|
10
|
-
}
|
|
11
|
-
export interface ProcessTransition {
|
|
12
|
-
name: string;
|
|
13
|
-
from: string;
|
|
14
|
-
to: string;
|
|
15
|
-
actor: string;
|
|
16
|
-
privileged?: boolean;
|
|
17
|
-
actions?: Array<{
|
|
18
|
-
name: string;
|
|
19
|
-
config?: unknown;
|
|
20
|
-
}>;
|
|
21
|
-
}
|
|
22
|
-
export interface ProcessNotification {
|
|
23
|
-
name: string;
|
|
24
|
-
on: string;
|
|
25
|
-
to: string;
|
|
26
|
-
template: string;
|
|
27
|
-
}
|
|
28
|
-
export interface ProcessDefinition {
|
|
29
|
-
name: string;
|
|
30
|
-
version?: number;
|
|
31
|
-
states: ProcessState[];
|
|
32
|
-
transitions: ProcessTransition[];
|
|
33
|
-
notifications: ProcessNotification[];
|
|
34
|
-
}
|
|
12
|
+
import type { ProcessAction, ProcessDefinition, ProcessNotification, ProcessState, ProcessTransition } from './types.js';
|
|
13
|
+
export type { ProcessAction, ProcessDefinition, ProcessNotification, ProcessState, ProcessTransition, };
|
|
35
14
|
/**
|
|
36
15
|
* Parses a process.edn file
|
|
16
|
+
*
|
|
17
|
+
* @param filePath - Path to the process.edn file
|
|
18
|
+
* @returns The process, named after the directory holding the file, with its
|
|
19
|
+
* states derived from its transitions
|
|
37
20
|
*/
|
|
38
21
|
export declare function parseProcessFile(filePath: string): ProcessDefinition;
|
|
39
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edn-process.d.ts","sourceRoot":"","sources":["../../src/edn-process.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"edn-process.d.ts","sourceRoot":"","sources":["../../src/edn-process.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,GAClB,CAAC;AA8GF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CA0CpE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAOnE"}
|
package/dist/cjs/edn-process.js
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Process.edn file parser
|
|
4
4
|
*
|
|
5
|
-
* Parses transaction process definitions from EDN format
|
|
5
|
+
* Parses transaction process definitions from EDN format.
|
|
6
|
+
*
|
|
7
|
+
* Written against the process.edn files Sharetribe actually ships, which are
|
|
8
|
+
* `{:format :v3 :transitions [...] :notifications [...]}` maps. They declare
|
|
9
|
+
* neither `:name` nor `:states`: the name comes from the directory holding the
|
|
10
|
+
* file, and the states are whatever the transitions' `:from` and `:to` name.
|
|
11
|
+
* That is why this module derives both rather than reading them off the map.
|
|
6
12
|
*/
|
|
7
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -12,70 +18,162 @@ exports.parseProcessFile = parseProcessFile;
|
|
|
12
18
|
exports.serializeProcess = serializeProcess;
|
|
13
19
|
const jsedn_1 = __importDefault(require("jsedn"));
|
|
14
20
|
const node_fs_1 = require("node:fs");
|
|
21
|
+
const node_path_1 = require("node:path");
|
|
22
|
+
const NAME = jsedn_1.default.kw(':name');
|
|
23
|
+
const TRANSITIONS = jsedn_1.default.kw(':transitions');
|
|
24
|
+
const NOTIFICATIONS = jsedn_1.default.kw(':notifications');
|
|
25
|
+
const FROM = jsedn_1.default.kw(':from');
|
|
26
|
+
const TO = jsedn_1.default.kw(':to');
|
|
27
|
+
const ACTOR = jsedn_1.default.kw(':actor');
|
|
28
|
+
const PRIVILEGED = jsedn_1.default.kw(':privileged?');
|
|
29
|
+
const ACTIONS = jsedn_1.default.kw(':actions');
|
|
30
|
+
const CONFIG = jsedn_1.default.kw(':config');
|
|
31
|
+
const ON = jsedn_1.default.kw(':on');
|
|
32
|
+
const TEMPLATE = jsedn_1.default.kw(':template');
|
|
33
|
+
/**
|
|
34
|
+
* Reads one key off an EDN map, or undefined when the map does not carry it.
|
|
35
|
+
*
|
|
36
|
+
* jsedn's `Map.prototype.at` throws the bare string "key does not exist" for a
|
|
37
|
+
* missing key, so every read has to be guarded by `exists` first.
|
|
38
|
+
*/
|
|
39
|
+
function fieldOf(map, key) {
|
|
40
|
+
if (!(map instanceof jsedn_1.default.Map))
|
|
41
|
+
return undefined;
|
|
42
|
+
return map.exists(key) ? map.at(key) : undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Unwraps an EDN vector or list into a plain array.
|
|
46
|
+
*
|
|
47
|
+
* jsedn parses `[...]` into its own Vector class wrapping an internal `val`
|
|
48
|
+
* array, so `Array.isArray` is false for every collection in a process file.
|
|
49
|
+
*/
|
|
50
|
+
function itemsOf(value) {
|
|
51
|
+
if (value instanceof jsedn_1.default.Vector || value instanceof jsedn_1.default.List)
|
|
52
|
+
return value.val;
|
|
53
|
+
if (Array.isArray(value))
|
|
54
|
+
return value;
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Renders an EDN keyword as a string, keeping its namespace and dropping the
|
|
59
|
+
* leading colon: `:transition/accept` becomes `transition/accept`. Keeping the
|
|
60
|
+
* namespace is what lets a notification's `:on` be compared with a transition's
|
|
61
|
+
* `:name` without either one losing what kind of thing it names.
|
|
62
|
+
*/
|
|
63
|
+
function keywordToString(value) {
|
|
64
|
+
if (value instanceof jsedn_1.default.Keyword)
|
|
65
|
+
return value.val.replace(/^:/, '');
|
|
66
|
+
if (typeof value === 'string')
|
|
67
|
+
return value;
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
15
70
|
/**
|
|
16
|
-
* Converts EDN
|
|
71
|
+
* Converts an arbitrary EDN value into plain JavaScript, so an action's
|
|
72
|
+
* `:config` reaches the caller as data rather than as jsedn internals.
|
|
17
73
|
*/
|
|
18
|
-
function
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
74
|
+
function toPlain(value) {
|
|
75
|
+
if (value instanceof jsedn_1.default.Keyword)
|
|
76
|
+
return keywordToString(value);
|
|
77
|
+
if (value instanceof jsedn_1.default.Symbol)
|
|
78
|
+
return value.val;
|
|
79
|
+
if (value instanceof jsedn_1.default.Vector || value instanceof jsedn_1.default.List) {
|
|
80
|
+
return value.val.map(toPlain);
|
|
21
81
|
}
|
|
22
|
-
|
|
82
|
+
if (value instanceof jsedn_1.default.Set)
|
|
83
|
+
return value.val.map(toPlain);
|
|
84
|
+
if (value instanceof jsedn_1.default.Map) {
|
|
85
|
+
const plain = {};
|
|
86
|
+
value.keys.forEach((key, index) => {
|
|
87
|
+
const name = keywordToString(key) ?? String(key);
|
|
88
|
+
plain[name] = toPlain(value.vals[index]);
|
|
89
|
+
});
|
|
90
|
+
return plain;
|
|
91
|
+
}
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Parses one transition's `:actions` into `{ name, config }` entries, skipping
|
|
96
|
+
* anything that is not a map carrying a `:name`.
|
|
97
|
+
*/
|
|
98
|
+
function parseActions(value) {
|
|
99
|
+
const actions = [];
|
|
100
|
+
for (const item of itemsOf(value)) {
|
|
101
|
+
const name = keywordToString(fieldOf(item, NAME));
|
|
102
|
+
if (name === undefined)
|
|
103
|
+
continue;
|
|
104
|
+
const config = fieldOf(item, CONFIG);
|
|
105
|
+
actions.push(config === undefined ? { name } : { name, config: toPlain(config) });
|
|
106
|
+
}
|
|
107
|
+
return actions;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Builds the state list from the transitions, the way Sharetribe does: a state
|
|
111
|
+
* exists because some transition names it, `in` holds the transitions arriving
|
|
112
|
+
* at it and `out` the transitions leaving it. States are ordered by first
|
|
113
|
+
* mention, so the initial state of the process comes first.
|
|
114
|
+
*/
|
|
115
|
+
function deriveStates(transitions) {
|
|
116
|
+
const states = new Map();
|
|
117
|
+
const stateNamed = (name) => {
|
|
118
|
+
const existing = states.get(name);
|
|
119
|
+
if (existing)
|
|
120
|
+
return existing;
|
|
121
|
+
const created = { name, in: [], out: [] };
|
|
122
|
+
states.set(name, created);
|
|
123
|
+
return created;
|
|
124
|
+
};
|
|
125
|
+
for (const transition of transitions) {
|
|
126
|
+
if (transition.from)
|
|
127
|
+
stateNamed(transition.from).out.push(transition.name);
|
|
128
|
+
if (transition.to)
|
|
129
|
+
stateNamed(transition.to).in.push(transition.name);
|
|
130
|
+
}
|
|
131
|
+
return [...states.values()];
|
|
23
132
|
}
|
|
24
133
|
/**
|
|
25
134
|
* Parses a process.edn file
|
|
135
|
+
*
|
|
136
|
+
* @param filePath - Path to the process.edn file
|
|
137
|
+
* @returns The process, named after the directory holding the file, with its
|
|
138
|
+
* states derived from its transitions
|
|
26
139
|
*/
|
|
27
140
|
function parseProcessFile(filePath) {
|
|
28
141
|
const content = (0, node_fs_1.readFileSync)(filePath, 'utf-8');
|
|
29
142
|
const parsed = jsedn_1.default.parse(content);
|
|
30
|
-
// Extract process data from EDN map
|
|
31
|
-
const nameKw = jsedn_1.default.kw(':name');
|
|
32
|
-
const statesKw = jsedn_1.default.kw(':states');
|
|
33
|
-
const transitionsKw = jsedn_1.default.kw(':transitions');
|
|
34
|
-
const notificationsKw = jsedn_1.default.kw(':notifications');
|
|
35
|
-
const name = ednKeywordToString(parsed.at(nameKw));
|
|
36
|
-
const statesData = parsed.at(statesKw) || [];
|
|
37
|
-
const transitionsData = parsed.at(transitionsKw) || [];
|
|
38
|
-
const notificationsData = parsed.at(notificationsKw) || [];
|
|
39
|
-
// Parse states
|
|
40
|
-
const states = [];
|
|
41
|
-
if (Array.isArray(statesData)) {
|
|
42
|
-
for (const state of statesData) {
|
|
43
|
-
states.push({
|
|
44
|
-
name: ednKeywordToString(state.at(jsedn_1.default.kw(':name'))),
|
|
45
|
-
in: (state.at(jsedn_1.default.kw(':in')) || []).map(ednKeywordToString),
|
|
46
|
-
out: (state.at(jsedn_1.default.kw(':out')) || []).map(ednKeywordToString),
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// Parse transitions
|
|
51
143
|
const transitions = [];
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
144
|
+
for (const item of itemsOf(fieldOf(parsed, TRANSITIONS))) {
|
|
145
|
+
const name = keywordToString(fieldOf(item, NAME));
|
|
146
|
+
if (name === undefined)
|
|
147
|
+
continue;
|
|
148
|
+
const transition = {
|
|
149
|
+
name,
|
|
150
|
+
to: keywordToString(fieldOf(item, TO)) ?? '',
|
|
151
|
+
privileged: fieldOf(item, PRIVILEGED) === true,
|
|
152
|
+
actions: parseActions(fieldOf(item, ACTIONS)),
|
|
153
|
+
};
|
|
154
|
+
const from = keywordToString(fieldOf(item, FROM));
|
|
155
|
+
if (from !== undefined)
|
|
156
|
+
transition.from = from;
|
|
157
|
+
const actor = keywordToString(fieldOf(item, ACTOR));
|
|
158
|
+
if (actor !== undefined)
|
|
159
|
+
transition.actor = actor;
|
|
160
|
+
transitions.push(transition);
|
|
63
161
|
}
|
|
64
|
-
// Parse notifications
|
|
65
162
|
const notifications = [];
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
163
|
+
for (const item of itemsOf(fieldOf(parsed, NOTIFICATIONS))) {
|
|
164
|
+
const name = keywordToString(fieldOf(item, NAME));
|
|
165
|
+
if (name === undefined)
|
|
166
|
+
continue;
|
|
167
|
+
notifications.push({
|
|
168
|
+
name,
|
|
169
|
+
on: keywordToString(fieldOf(item, ON)) ?? '',
|
|
170
|
+
to: keywordToString(fieldOf(item, TO)) ?? '',
|
|
171
|
+
template: keywordToString(fieldOf(item, TEMPLATE)) ?? '',
|
|
172
|
+
});
|
|
75
173
|
}
|
|
76
174
|
return {
|
|
77
|
-
name,
|
|
78
|
-
states,
|
|
175
|
+
name: (0, node_path_1.basename)((0, node_path_1.dirname)((0, node_path_1.resolve)(filePath))),
|
|
176
|
+
states: deriveStates(transitions),
|
|
79
177
|
transitions,
|
|
80
178
|
notifications,
|
|
81
179
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edn-process.js","sourceRoot":"","sources":["../../src/edn-process.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"edn-process.js","sourceRoot":"","sources":["../../src/edn-process.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;AAwIH,4CA0CC;AAKD,4CAOC;AA5LD,kDAAwB;AACxB,qCAAuC;AACvC,yCAAuD;AAiBvD,MAAM,IAAI,GAAG,eAAG,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AAC7B,MAAM,WAAW,GAAG,eAAG,CAAC,EAAE,CAAC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AAC,IAAI,CAAC,cAAc,CAAC;iBACzJ,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC;mBAC7H,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC;AAC7J,CAAC"}
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -12,9 +12,11 @@ export interface ProcessAction {
|
|
|
12
12
|
}
|
|
13
13
|
export interface ProcessTransition {
|
|
14
14
|
name: string;
|
|
15
|
-
|
|
15
|
+
/** Absent on the transitions that start a process */
|
|
16
|
+
from?: string;
|
|
16
17
|
to: string;
|
|
17
|
-
actor
|
|
18
|
+
/** Absent on time-based transitions, which carry an `:at` instead of an actor */
|
|
19
|
+
actor?: string;
|
|
18
20
|
privileged?: boolean;
|
|
19
21
|
actions?: ProcessAction[];
|
|
20
22
|
}
|
package/dist/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,GAAG,EAAE,MAAM,EAAE,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,GAAG,EAAE,MAAM,EAAE,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,iFAAiF;IACjF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,WAAW,EAAE,iBAAiB,EAAE,CAAC;IACjC,aAAa,EAAE,mBAAmB,EAAE,CAAC;CACtC"}
|
|
@@ -1,39 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Process.edn file parser
|
|
3
3
|
*
|
|
4
|
-
* Parses transaction process definitions from EDN format
|
|
4
|
+
* Parses transaction process definitions from EDN format.
|
|
5
|
+
*
|
|
6
|
+
* Written against the process.edn files Sharetribe actually ships, which are
|
|
7
|
+
* `{:format :v3 :transitions [...] :notifications [...]}` maps. They declare
|
|
8
|
+
* neither `:name` nor `:states`: the name comes from the directory holding the
|
|
9
|
+
* file, and the states are whatever the transitions' `:from` and `:to` name.
|
|
10
|
+
* That is why this module derives both rather than reading them off the map.
|
|
5
11
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
in: string[];
|
|
9
|
-
out: string[];
|
|
10
|
-
}
|
|
11
|
-
export interface ProcessTransition {
|
|
12
|
-
name: string;
|
|
13
|
-
from: string;
|
|
14
|
-
to: string;
|
|
15
|
-
actor: string;
|
|
16
|
-
privileged?: boolean;
|
|
17
|
-
actions?: Array<{
|
|
18
|
-
name: string;
|
|
19
|
-
config?: unknown;
|
|
20
|
-
}>;
|
|
21
|
-
}
|
|
22
|
-
export interface ProcessNotification {
|
|
23
|
-
name: string;
|
|
24
|
-
on: string;
|
|
25
|
-
to: string;
|
|
26
|
-
template: string;
|
|
27
|
-
}
|
|
28
|
-
export interface ProcessDefinition {
|
|
29
|
-
name: string;
|
|
30
|
-
version?: number;
|
|
31
|
-
states: ProcessState[];
|
|
32
|
-
transitions: ProcessTransition[];
|
|
33
|
-
notifications: ProcessNotification[];
|
|
34
|
-
}
|
|
12
|
+
import type { ProcessAction, ProcessDefinition, ProcessNotification, ProcessState, ProcessTransition } from './types.js';
|
|
13
|
+
export type { ProcessAction, ProcessDefinition, ProcessNotification, ProcessState, ProcessTransition, };
|
|
35
14
|
/**
|
|
36
15
|
* Parses a process.edn file
|
|
16
|
+
*
|
|
17
|
+
* @param filePath - Path to the process.edn file
|
|
18
|
+
* @returns The process, named after the directory holding the file, with its
|
|
19
|
+
* states derived from its transitions
|
|
37
20
|
*/
|
|
38
21
|
export declare function parseProcessFile(filePath: string): ProcessDefinition;
|
|
39
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edn-process.d.ts","sourceRoot":"","sources":["../../src/edn-process.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"edn-process.d.ts","sourceRoot":"","sources":["../../src/edn-process.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,GAClB,CAAC;AA8GF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CA0CpE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAOnE"}
|
package/dist/esm/edn-process.js
CHANGED
|
@@ -1,74 +1,172 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Process.edn file parser
|
|
3
3
|
*
|
|
4
|
-
* Parses transaction process definitions from EDN format
|
|
4
|
+
* Parses transaction process definitions from EDN format.
|
|
5
|
+
*
|
|
6
|
+
* Written against the process.edn files Sharetribe actually ships, which are
|
|
7
|
+
* `{:format :v3 :transitions [...] :notifications [...]}` maps. They declare
|
|
8
|
+
* neither `:name` nor `:states`: the name comes from the directory holding the
|
|
9
|
+
* file, and the states are whatever the transitions' `:from` and `:to` name.
|
|
10
|
+
* That is why this module derives both rather than reading them off the map.
|
|
5
11
|
*/
|
|
6
12
|
import edn from 'jsedn';
|
|
7
13
|
import { readFileSync } from 'node:fs';
|
|
14
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
15
|
+
const NAME = edn.kw(':name');
|
|
16
|
+
const TRANSITIONS = edn.kw(':transitions');
|
|
17
|
+
const NOTIFICATIONS = edn.kw(':notifications');
|
|
18
|
+
const FROM = edn.kw(':from');
|
|
19
|
+
const TO = edn.kw(':to');
|
|
20
|
+
const ACTOR = edn.kw(':actor');
|
|
21
|
+
const PRIVILEGED = edn.kw(':privileged?');
|
|
22
|
+
const ACTIONS = edn.kw(':actions');
|
|
23
|
+
const CONFIG = edn.kw(':config');
|
|
24
|
+
const ON = edn.kw(':on');
|
|
25
|
+
const TEMPLATE = edn.kw(':template');
|
|
26
|
+
/**
|
|
27
|
+
* Reads one key off an EDN map, or undefined when the map does not carry it.
|
|
28
|
+
*
|
|
29
|
+
* jsedn's `Map.prototype.at` throws the bare string "key does not exist" for a
|
|
30
|
+
* missing key, so every read has to be guarded by `exists` first.
|
|
31
|
+
*/
|
|
32
|
+
function fieldOf(map, key) {
|
|
33
|
+
if (!(map instanceof edn.Map))
|
|
34
|
+
return undefined;
|
|
35
|
+
return map.exists(key) ? map.at(key) : undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Unwraps an EDN vector or list into a plain array.
|
|
39
|
+
*
|
|
40
|
+
* jsedn parses `[...]` into its own Vector class wrapping an internal `val`
|
|
41
|
+
* array, so `Array.isArray` is false for every collection in a process file.
|
|
42
|
+
*/
|
|
43
|
+
function itemsOf(value) {
|
|
44
|
+
if (value instanceof edn.Vector || value instanceof edn.List)
|
|
45
|
+
return value.val;
|
|
46
|
+
if (Array.isArray(value))
|
|
47
|
+
return value;
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Renders an EDN keyword as a string, keeping its namespace and dropping the
|
|
52
|
+
* leading colon: `:transition/accept` becomes `transition/accept`. Keeping the
|
|
53
|
+
* namespace is what lets a notification's `:on` be compared with a transition's
|
|
54
|
+
* `:name` without either one losing what kind of thing it names.
|
|
55
|
+
*/
|
|
56
|
+
function keywordToString(value) {
|
|
57
|
+
if (value instanceof edn.Keyword)
|
|
58
|
+
return value.val.replace(/^:/, '');
|
|
59
|
+
if (typeof value === 'string')
|
|
60
|
+
return value;
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
8
63
|
/**
|
|
9
|
-
* Converts EDN
|
|
64
|
+
* Converts an arbitrary EDN value into plain JavaScript, so an action's
|
|
65
|
+
* `:config` reaches the caller as data rather than as jsedn internals.
|
|
10
66
|
*/
|
|
11
|
-
function
|
|
12
|
-
if (
|
|
13
|
-
return
|
|
67
|
+
function toPlain(value) {
|
|
68
|
+
if (value instanceof edn.Keyword)
|
|
69
|
+
return keywordToString(value);
|
|
70
|
+
if (value instanceof edn.Symbol)
|
|
71
|
+
return value.val;
|
|
72
|
+
if (value instanceof edn.Vector || value instanceof edn.List) {
|
|
73
|
+
return value.val.map(toPlain);
|
|
14
74
|
}
|
|
15
|
-
|
|
75
|
+
if (value instanceof edn.Set)
|
|
76
|
+
return value.val.map(toPlain);
|
|
77
|
+
if (value instanceof edn.Map) {
|
|
78
|
+
const plain = {};
|
|
79
|
+
value.keys.forEach((key, index) => {
|
|
80
|
+
const name = keywordToString(key) ?? String(key);
|
|
81
|
+
plain[name] = toPlain(value.vals[index]);
|
|
82
|
+
});
|
|
83
|
+
return plain;
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Parses one transition's `:actions` into `{ name, config }` entries, skipping
|
|
89
|
+
* anything that is not a map carrying a `:name`.
|
|
90
|
+
*/
|
|
91
|
+
function parseActions(value) {
|
|
92
|
+
const actions = [];
|
|
93
|
+
for (const item of itemsOf(value)) {
|
|
94
|
+
const name = keywordToString(fieldOf(item, NAME));
|
|
95
|
+
if (name === undefined)
|
|
96
|
+
continue;
|
|
97
|
+
const config = fieldOf(item, CONFIG);
|
|
98
|
+
actions.push(config === undefined ? { name } : { name, config: toPlain(config) });
|
|
99
|
+
}
|
|
100
|
+
return actions;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Builds the state list from the transitions, the way Sharetribe does: a state
|
|
104
|
+
* exists because some transition names it, `in` holds the transitions arriving
|
|
105
|
+
* at it and `out` the transitions leaving it. States are ordered by first
|
|
106
|
+
* mention, so the initial state of the process comes first.
|
|
107
|
+
*/
|
|
108
|
+
function deriveStates(transitions) {
|
|
109
|
+
const states = new Map();
|
|
110
|
+
const stateNamed = (name) => {
|
|
111
|
+
const existing = states.get(name);
|
|
112
|
+
if (existing)
|
|
113
|
+
return existing;
|
|
114
|
+
const created = { name, in: [], out: [] };
|
|
115
|
+
states.set(name, created);
|
|
116
|
+
return created;
|
|
117
|
+
};
|
|
118
|
+
for (const transition of transitions) {
|
|
119
|
+
if (transition.from)
|
|
120
|
+
stateNamed(transition.from).out.push(transition.name);
|
|
121
|
+
if (transition.to)
|
|
122
|
+
stateNamed(transition.to).in.push(transition.name);
|
|
123
|
+
}
|
|
124
|
+
return [...states.values()];
|
|
16
125
|
}
|
|
17
126
|
/**
|
|
18
127
|
* Parses a process.edn file
|
|
128
|
+
*
|
|
129
|
+
* @param filePath - Path to the process.edn file
|
|
130
|
+
* @returns The process, named after the directory holding the file, with its
|
|
131
|
+
* states derived from its transitions
|
|
19
132
|
*/
|
|
20
133
|
export function parseProcessFile(filePath) {
|
|
21
134
|
const content = readFileSync(filePath, 'utf-8');
|
|
22
135
|
const parsed = edn.parse(content);
|
|
23
|
-
// Extract process data from EDN map
|
|
24
|
-
const nameKw = edn.kw(':name');
|
|
25
|
-
const statesKw = edn.kw(':states');
|
|
26
|
-
const transitionsKw = edn.kw(':transitions');
|
|
27
|
-
const notificationsKw = edn.kw(':notifications');
|
|
28
|
-
const name = ednKeywordToString(parsed.at(nameKw));
|
|
29
|
-
const statesData = parsed.at(statesKw) || [];
|
|
30
|
-
const transitionsData = parsed.at(transitionsKw) || [];
|
|
31
|
-
const notificationsData = parsed.at(notificationsKw) || [];
|
|
32
|
-
// Parse states
|
|
33
|
-
const states = [];
|
|
34
|
-
if (Array.isArray(statesData)) {
|
|
35
|
-
for (const state of statesData) {
|
|
36
|
-
states.push({
|
|
37
|
-
name: ednKeywordToString(state.at(edn.kw(':name'))),
|
|
38
|
-
in: (state.at(edn.kw(':in')) || []).map(ednKeywordToString),
|
|
39
|
-
out: (state.at(edn.kw(':out')) || []).map(ednKeywordToString),
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
// Parse transitions
|
|
44
136
|
const transitions = [];
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
137
|
+
for (const item of itemsOf(fieldOf(parsed, TRANSITIONS))) {
|
|
138
|
+
const name = keywordToString(fieldOf(item, NAME));
|
|
139
|
+
if (name === undefined)
|
|
140
|
+
continue;
|
|
141
|
+
const transition = {
|
|
142
|
+
name,
|
|
143
|
+
to: keywordToString(fieldOf(item, TO)) ?? '',
|
|
144
|
+
privileged: fieldOf(item, PRIVILEGED) === true,
|
|
145
|
+
actions: parseActions(fieldOf(item, ACTIONS)),
|
|
146
|
+
};
|
|
147
|
+
const from = keywordToString(fieldOf(item, FROM));
|
|
148
|
+
if (from !== undefined)
|
|
149
|
+
transition.from = from;
|
|
150
|
+
const actor = keywordToString(fieldOf(item, ACTOR));
|
|
151
|
+
if (actor !== undefined)
|
|
152
|
+
transition.actor = actor;
|
|
153
|
+
transitions.push(transition);
|
|
56
154
|
}
|
|
57
|
-
// Parse notifications
|
|
58
155
|
const notifications = [];
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
156
|
+
for (const item of itemsOf(fieldOf(parsed, NOTIFICATIONS))) {
|
|
157
|
+
const name = keywordToString(fieldOf(item, NAME));
|
|
158
|
+
if (name === undefined)
|
|
159
|
+
continue;
|
|
160
|
+
notifications.push({
|
|
161
|
+
name,
|
|
162
|
+
on: keywordToString(fieldOf(item, ON)) ?? '',
|
|
163
|
+
to: keywordToString(fieldOf(item, TO)) ?? '',
|
|
164
|
+
template: keywordToString(fieldOf(item, TEMPLATE)) ?? '',
|
|
165
|
+
});
|
|
68
166
|
}
|
|
69
167
|
return {
|
|
70
|
-
name,
|
|
71
|
-
states,
|
|
168
|
+
name: basename(dirname(resolve(filePath))),
|
|
169
|
+
states: deriveStates(transitions),
|
|
72
170
|
transitions,
|
|
73
171
|
notifications,
|
|
74
172
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edn-process.js","sourceRoot":"","sources":["../../src/edn-process.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"edn-process.js","sourceRoot":"","sources":["../../src/edn-process.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,GAAG,MAAM,OAAO,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAiBvD,MAAM,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AAC7B,MAAM,WAAW,GAAG,GAAG,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC;AAC3C,MAAM,aAAa,GAAG,GAAG,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC;AAC/C,MAAM,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AAC7B,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AACzB,MAAM,KAAK,GAAG,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AAC/B,MAAM,UAAU,GAAG,GAAG,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC;AAC1C,MAAM,OAAO,GAAG,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;AACnC,MAAM,MAAM,GAAG,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;AACjC,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AACzB,MAAM,QAAQ,GAAG,GAAG,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;AAErC;;;;;GAKG;AACH,SAA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,MAAM,EAAE,YAAY,CAAC,WAAW,CAAC;QACjC,WAAW;QACX,aAAa;KACd,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA0B;IACzD,kDAAkD;IAClD,+DAA+D;IAC/D,OAAO,WAAW,OAAO,CAAC,IAAI;YACpB,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;iBACzJ,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC;mBAC7H,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC;AAC7J,CAAC"}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -12,9 +12,11 @@ export interface ProcessAction {
|
|
|
12
12
|
}
|
|
13
13
|
export interface ProcessTransition {
|
|
14
14
|
name: string;
|
|
15
|
-
|
|
15
|
+
/** Absent on the transitions that start a process */
|
|
16
|
+
from?: string;
|
|
16
17
|
to: string;
|
|
17
|
-
actor
|
|
18
|
+
/** Absent on time-based transitions, which carry an `:at` instead of an actor */
|
|
19
|
+
actor?: string;
|
|
18
20
|
privileged?: boolean;
|
|
19
21
|
actions?: ProcessAction[];
|
|
20
22
|
}
|
package/dist/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,GAAG,EAAE,MAAM,EAAE,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,GAAG,EAAE,MAAM,EAAE,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,iFAAiF;IACjF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAmB;IAClC,IAA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