@stonecrop/stonecrop 0.3.5 → 0.3.7

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/dist/stonecrop.js CHANGED
@@ -16,31 +16,31 @@ ut.prototype = Object.create(Error.prototype, {
16
16
  });
17
17
  const we = class we {
18
18
  /**
19
- * @constructor
20
- * @param {Registry} registry - The immutable registry
21
- * @param {ReturnType<typeof useDataStore>} store - The mutable Pinia store
22
- * @param {Schema} [schema] - (optional) The Stonecrop schema
23
- * @param {ImmutableDoctype['workflow']} [workflow] - (optional) The Stonecrop workflow
24
- * @param {ImmutableDoctype['actions']} [actions] - (optional) The Stonecrop actions
25
- * @returns {Stonecrop} The Stonecrop instance
26
- * @description The Stonecrop constructor initializes a new Stonecrop instance with the given registry, store, schema, workflow, and actions. If a Stonecrop instance has already been created, it returns the existing instance instead of creating a new one.
19
+ * @param registry - The immutable registry
20
+ * @param store - The mutable Pinia store
21
+ * @param schema - The Stonecrop schema
22
+ * @param workflow - The Stonecrop workflow
23
+ * @param actions - The Stonecrop actions
24
+ * @returns The Stonecrop instance with the given registry, store, schema, workflow, and actions. If a Stonecrop instance has already been created, it returns the existing instance instead of creating a new one.
27
25
  * @example
26
+ * ```ts
28
27
  * const registry = new Registry()
29
28
  * const store = useDataStore()
30
- * const stonecrop = new Stonecrop(registry, store, schema, workflow, actions)
29
+ * const stonecrop = new Stonecrop(registry, store)
30
+ * ```
31
31
  */
32
32
  constructor(t, n, r, o, s) {
33
33
  /**
34
- * @property {string} name
35
- * @description The name of the Stonecrop instance
36
- * @example
37
- * 'Stonecrop'
34
+ * The name of the Stonecrop instance
35
+ * @readonly
36
+ *
37
+ * @defaultValue 'Stonecrop'
38
38
  */
39
39
  x(this, "name", "Stonecrop");
40
40
  /**
41
- * @property {Registry} registry
42
- * @description The registry is an immutable collection of doctypes
41
+ * The registry is an immutable collection of doctypes
43
42
  * @example
43
+ * ```ts
44
44
  * {
45
45
  * 'task': {
46
46
  * doctype: 'Task',
@@ -52,14 +52,15 @@ const we = class we {
52
52
  * },
53
53
  * ...
54
54
  * }
55
+ * ```
55
56
  * @see {@link Registry}
56
57
  * @see {@link DoctypeMeta}
57
58
  */
58
59
  x(this, "registry");
59
60
  /**
60
- * @property {Schema} schema - The Stonecrop schema
61
- * @description The schema is a subset of the registry
61
+ * schema - The Stonecrop schema; the schema is a subset of the registry
62
62
  * @example
63
+ * ```ts
63
64
  * {
64
65
  * doctype: 'Task',
65
66
  * schema: {
@@ -68,24 +69,22 @@ const we = class we {
68
69
  * ...
69
70
  * }
70
71
  * }
72
+ * ```
71
73
  * @see {@link Registry}
72
74
  * @see {@link DoctypeMeta}
73
75
  * @see {@link DoctypeMeta.schema}
74
76
  */
75
77
  x(this, "schema");
76
78
  /**
77
- * @property {ImmutableDoctype['workflow']} workflow
78
- * @description The workflow is a subset of the registry
79
+ * The workflow is a subset of the registry
79
80
  */
80
81
  x(this, "workflow");
81
82
  /**
82
- * @property {ImmutableDoctype['actions']} actions
83
- * @description The actions are a subset of the registry
83
+ * The actions are a subset of the registry
84
84
  */
85
85
  x(this, "actions");
86
86
  /**
87
- * @property {ReturnType<typeof useDataStore>} store
88
- * @description The Pinia store that manages the mutable records
87
+ * The Pinia store that manages the mutable records
89
88
  */
90
89
  x(this, "store");
91
90
  if (we._root)
@@ -93,70 +92,73 @@ const we = class we {
93
92
  we._root = this, this.registry = t, this.store = n, this.schema = r, this.workflow = o, this.actions = s;
94
93
  }
95
94
  /**
96
- * @method setup
97
- * @param {DoctypeMeta} doctype - The doctype to setup
98
- * @returns {void}
99
- * @description Sets up the Stonecrop instance with the given doctype
95
+ * Sets up the Stonecrop instance with the given doctype
96
+ * @param doctype - The doctype to setup
100
97
  * @example
98
+ * ```ts
101
99
  * const doctype = await registry.getMeta('Task')
102
100
  * stonecrop.setup(doctype)
101
+ * ```
103
102
  */
104
103
  setup(t) {
105
104
  this.getMeta(t), this.getWorkflow(t), this.getActions(t);
106
105
  }
107
106
  /**
108
- * @method getMeta
109
- * @param {DoctypeMeta} doctype - The doctype to get meta for
110
- * @returns {DoctypeMeta}
111
- * @see {@link DoctypeMeta}
107
+ * Gets the meta for the given doctype
108
+ * @param doctype - The doctype to get meta for
109
+ * @returns The meta for the given doctype
112
110
  * @throws NotImplementedError
113
- * @description Gets the meta for the given doctype
114
111
  * @example
112
+ * ```ts
115
113
  * const doctype = await registry.getMeta('Task')
116
114
  * const meta = stonecrop.getMeta(doctype)
115
+ * ```
116
+ * @see {@link DoctypeMeta}
117
117
  */
118
118
  getMeta(t) {
119
119
  return this.registry.getMeta ? this.registry.getMeta(t.doctype) : new ut(t.doctype);
120
120
  }
121
121
  /**
122
- * @method getWorkflow
123
- * @param {DoctypeMeta} doctype - The doctype to get workflow for
124
- * @returns {void}
125
- * @description Gets the workflow for the given doctype
122
+ * Gets the workflow for the given doctype
123
+ * @param doctype - The doctype to get workflow for
126
124
  * @example
125
+ * ```ts
127
126
  * const doctype = await registry.getMeta('Task')
128
127
  * stonecrop.getWorkflow(doctype)
128
+ * ```
129
129
  */
130
130
  getWorkflow(t) {
131
131
  const n = this.registry.registry[t.slug];
132
132
  this.workflow = n.workflow;
133
133
  }
134
134
  /**
135
- * @method getActions
136
- * @param {DoctypeMeta} doctype - The doctype to get actions for
137
- * @returns {void}
138
- * @description Gets the actions for the given doctype
135
+ * Gets the actions for the given doctype
136
+ * @param doctype - The doctype to get actions for
139
137
  * @example
138
+ * ```ts
140
139
  * const doctype = await registry.getMeta('Task')
141
140
  * stonecrop.getActions(doctype)
141
+ * ```
142
142
  */
143
143
  getActions(t) {
144
144
  const n = this.registry.registry[t.slug];
145
145
  this.actions = n.actions;
146
146
  }
147
147
  /**
148
- * @method getRecords
149
- * @param {DoctypeMeta} doctype - The doctype to get records for
150
- * @param {RequestInit} [filters] - The filters to apply to the records
151
- * @returns {Promise<void>}
152
- * @description Gets the records for the given doctype
148
+ * Gets the records for the given doctype
149
+ * @param doctype - The doctype to get records for
150
+ * @param filters - The filters to apply to the records
153
151
  * @example
152
+ * ```ts
154
153
  * const doctype = await registry.getMeta('Task')
155
154
  * await stonecrop.getRecords(doctype)
155
+ * ```
156
156
  * @example
157
+ * ```ts
157
158
  * const doctype = await registry.getMeta('Task')
158
159
  * const filters = JSON.stringify({ status: 'Open' })
159
160
  * await stonecrop.getRecords(doctype, { body: filters })
161
+ * ```
160
162
  */
161
163
  async getRecords(t, n) {
162
164
  this.store.$patch({ records: [] });
@@ -164,14 +166,14 @@ const we = class we {
164
166
  this.store.$patch({ records: o });
165
167
  }
166
168
  /**
167
- * @method getRecord
168
- * @param {DoctypeMeta} doctype - The doctype to get record for
169
- * @param {string} id - The id of the record to get
170
- * @returns {Promise<void>}
171
- * @description Gets the record for the given doctype and id
169
+ * Gets the record for the given doctype and id
170
+ * @param doctype - The doctype to get record for
171
+ * @param id - The id of the record to get
172
172
  * @example
173
+ * ```ts
173
174
  * const doctype = await registry.getMeta('Task')
174
175
  * await stonecrop.getRecord(doctype, 'TASK-00001')
176
+ * ```
175
177
  */
176
178
  async getRecord(t, n) {
177
179
  this.store.$patch({ record: {} });
@@ -179,24 +181,30 @@ const we = class we {
179
181
  this.store.$patch({ record: o });
180
182
  }
181
183
  /**
182
- * @method runAction
183
- * @param {DoctypeMeta} doctype - The doctype to run action for
184
- * @param {string} action - The action to run
185
- * @param {string[]} [id] - The id(s) of the record(s) to run action on
186
- * @returns {void}
187
- * @description Runs the action for the given doctype and id
184
+ * Runs the action for the given doctype and id
185
+ * @param doctype - The doctype to run action for
186
+ * @param action - The action to run
187
+ * @param id - The id(s) of the record(s) to run action on
188
188
  * @example
189
+ * ```ts
189
190
  * const doctype = await registry.getMeta('Task')
190
191
  * stonecrop.runAction(doctype, 'CREATE')
192
+ * ```
191
193
  * @example
194
+ * ```ts
192
195
  * const doctype = await registry.getMeta('Task')
193
196
  * stonecrop.runAction(doctype, 'UPDATE', ['TASK-00001'])
197
+ * ```
194
198
  * @example
199
+ * ```ts
195
200
  * const doctype = await registry.getMeta('Task')
196
201
  * stonecrop.runAction(doctype, 'DELETE', ['TASK-00001'])
202
+ * ```
197
203
  * @example
204
+ * ```ts
198
205
  * const doctype = await registry.getMeta('Task')
199
206
  * stonecrop.runAction(doctype, 'TRANSITION', ['TASK-00001', 'TASK-00002'])
207
+ * ```
200
208
  */
201
209
  runAction(t, n, r) {
202
210
  const s = this.registry.registry[t.slug].actions.get(n), { initialState: i } = this.workflow;
@@ -206,8 +214,7 @@ const we = class we {
206
214
  }
207
215
  };
208
216
  /**
209
- * @property {Stonecrop} _root
210
- * @description The root Stonecrop instance
217
+ * The root Stonecrop instance
211
218
  */
212
219
  x(we, "_root");
213
220
  let lt = we;
@@ -1190,33 +1197,83 @@ function Mi(e) {
1190
1197
  }), { stonecrop: n, isReady: r };
1191
1198
  }
1192
1199
  class Vi {
1200
+ // TODO: allow different components for different views; probably
1201
+ // should be defined in the schema instead?
1193
1202
  constructor(t, n, r, o, s) {
1203
+ /**
1204
+ * The doctype name
1205
+ * @public
1206
+ * @readonly
1207
+ */
1194
1208
  x(this, "doctype");
1209
+ /**
1210
+ * The doctype schema
1211
+ * @public
1212
+ * @readonly
1213
+ */
1195
1214
  x(this, "schema");
1215
+ /**
1216
+ * The doctype workflow
1217
+ * @public
1218
+ * @readonly
1219
+ */
1196
1220
  x(this, "workflow");
1221
+ /**
1222
+ * The doctype actions
1223
+ * @public
1224
+ * @readonly
1225
+ */
1197
1226
  x(this, "actions");
1198
- // TODO: allow different components for different views; probably
1199
- // should be defined in the schema instead?
1227
+ /**
1228
+ * The doctype component
1229
+ * @public
1230
+ * @readonly
1231
+ */
1200
1232
  x(this, "component");
1201
1233
  this.doctype = t, this.schema = n, this.workflow = r, this.actions = o, this.component = s;
1202
1234
  }
1235
+ /**
1236
+ * Converts the registered doctype to a slug (kebab-case)
1237
+ * @returns The slugified doctype string
1238
+ * @public
1239
+ */
1203
1240
  get slug() {
1204
1241
  return this.doctype.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
1205
1242
  }
1206
- get __typename() {
1207
- return this.doctype;
1208
- }
1209
1243
  }
1210
1244
  const Se = class Se {
1211
1245
  constructor(t, n) {
1246
+ /**
1247
+ * The name of the Registry instance
1248
+ *
1249
+ * @defaultValue 'Registry'
1250
+ */
1212
1251
  x(this, "name");
1252
+ /**
1253
+ * The Vue router instance
1254
+ * @see {@link https://router.vuejs.org/}
1255
+ */
1213
1256
  x(this, "router");
1257
+ /**
1258
+ * The registry property contains a collection of doctypes
1259
+ * @see {@link DoctypeMeta}
1260
+ */
1214
1261
  x(this, "registry");
1262
+ /**
1263
+ * The getMeta function fetches doctype metadata from an API
1264
+ * @see {@link DoctypeMeta}
1265
+ */
1215
1266
  x(this, "getMeta");
1216
1267
  if (Se._root)
1217
1268
  return Se._root;
1218
1269
  Se._root = this, this.name = "Registry", this.router = t, this.registry = {}, this.getMeta = n;
1219
1270
  }
1271
+ /**
1272
+ * Get doctype metadata
1273
+ * @param doctype - The doctype to fetch metadata for
1274
+ * @returns The doctype metadata
1275
+ * @see {@link DoctypeMeta}
1276
+ */
1220
1277
  addDoctype(t) {
1221
1278
  t.doctype in Object.keys(this.registry) || (this.registry[t.slug] = t), this.router.hasRoute(t.doctype) || this.router.addRoute({
1222
1279
  path: `/${t.slug}`,
@@ -1225,6 +1282,9 @@ const Se = class Se {
1225
1282
  });
1226
1283
  }
1227
1284
  };
1285
+ /**
1286
+ * The root Registry instance
1287
+ */
1228
1288
  x(Se, "_root");
1229
1289
  let pt = Se;
1230
1290
  /*!